diff options
Diffstat (limited to 'docs/x509/tutorial.rst')
-rw-r--r-- | docs/x509/tutorial.rst | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/docs/x509/tutorial.rst b/docs/x509/tutorial.rst index bcaec809..4caa90b5 100644 --- a/docs/x509/tutorial.rst +++ b/docs/x509/tutorial.rst @@ -37,7 +37,7 @@ are the most common types of keys on the web right now): ... backend=default_backend() ... ) >>> # Write our key to disk for safe keeping - >>> with open("path/to/store/key.pem") as f: + >>> with open("path/to/store/key.pem", "w") as f: ... f.write(key.private_bytes( ... encoding=serialization.Encoding.PEM, ... format=serialization.PrivateFormat.TraditionalOpenSSL, @@ -57,14 +57,15 @@ a few details: .. code-block:: pycon >>> from cryptography import x509 + >>> from cryptography.x509.oid import NameOID >>> # Generate a CSR >>> csr = x509.CertificateSigningRequestBuilder().subject_name(x509.Name([ ... # Provide various details about who we are. - ... x509.NameAttribute(x509.OID_COUNTRY_NAME, u"US"), - ... x509.NameAttribute(x509.OID_STATE_OR_PROVINCE_NAME, u"CA"), - ... x509.NameAttribute(x509.OID_LOCALITY_NAME, u"San Francisco"), - ... x509.NameAttribute(x509.OID_ORGANIZATION_NAME, u"My Company"), - ... x509.NameAttribute(x509.COMMON_NAME, u"mysite.com"), + ... x509.NameAttribute(NameOID.COUNTRY_NAME, u"US"), + ... x509.NameAttribute(NameOID.STATE_OR_PROVINCE_NAME, u"CA"), + ... x509.NameAttribute(NameOID.LOCALITY_NAME, u"San Francisco"), + ... x509.NameAttribute(NameOID.ORGANIZATION_NAME, u"My Company"), + ... x509.NameAttribute(NameOID.COMMON_NAME, u"mysite.com"), ... ])).add_extension(x509.SubjectAlternativeName([ ... # Describe what sites we want this certificate for. ... x509.DNSName(u"mysite.com"), @@ -73,7 +74,7 @@ a few details: ... # Sign the CSR with our private key. ... ])).sign(key, hashes.SHA256(), default_backend()) >>> # Write our CSR out to disk. - >>> with open("path/to/csr.pem") as f: + >>> with open("path/to/csr.pem", "w") as f: ... f.write(csr.public_bytes(serialization.Encoding.PEM)) Now we can give our CSR to a CA, who will give a certificate to us in return. |