X.509 Reference
Loading Certificates
- cryptography.x509.load_pem_x509_certificate(data)
Added in version 0.7.
Deserialize a certificate from PEM encoded data. PEM certificates are base64 decoded and have delimiters that look like
-----BEGIN CERTIFICATE-----
.- Parameters:
data (bytes) – The PEM encoded certificate data.
- Returns:
An instance of
Certificate
.
>>> from cryptography import x509 >>> cert = x509.load_pem_x509_certificate(pem_data) >>> cert.serial_number 2
- cryptography.x509.load_pem_x509_certificates(data)
Added in version 39.0.0.
Deserialize one or more certificates from PEM encoded data.
This is like
load_pem_x509_certificate()
, but allows for loading multiple certificates (as adjacent PEMs) at once.- Parameters:
data (bytes) – One or more PEM-encoded certificates.
- Returns:
list of
Certificate
- Raises:
ValueError – If there isn’t at least one certificate, or if any certificate is malformed.
- cryptography.x509.load_der_x509_certificate(data)
Added in version 0.7.
Deserialize a certificate from DER encoded data. DER is a binary format and is commonly found in files with the
.cer
extension (although file extensions are not a guarantee of encoding type).- Parameters:
data (bytes) – The DER encoded certificate data.
- Returns:
An instance of
Certificate
.
Loading Certificate Revocation Lists
- cryptography.x509.load_pem_x509_crl(data)
Added in version 1.1.
Deserialize a certificate revocation list (CRL) from PEM encoded data. PEM requests are base64 decoded and have delimiters that look like
-----BEGIN X509 CRL-----
.- Parameters:
data (bytes) – The PEM encoded request data.
- Returns:
An instance of
CertificateRevocationList
.
>>> from cryptography import x509 >>> from cryptography.hazmat.primitives import hashes >>> crl = x509.load_pem_x509_crl(pem_crl_data) >>> isinstance(crl.signature_hash_algorithm, hashes.SHA256) True
- cryptography.x509.load_der_x509_crl(data)
Added in version 1.1.
Deserialize a certificate revocation list (CRL) from DER encoded data. DER is a binary format.
- Parameters:
data (bytes) – The DER encoded request data.
- Returns:
An instance of
CertificateRevocationList
.
Loading Certificate Signing Requests
- cryptography.x509.load_pem_x509_csr(data)
Added in version 0.9.
Deserialize a certificate signing request (CSR) from PEM encoded data. PEM requests are base64 decoded and have delimiters that look like
-----BEGIN CERTIFICATE REQUEST-----
. This format is also known as PKCS#10.- Parameters:
data (bytes) – The PEM encoded request data.
- Returns:
An instance of
CertificateSigningRequest
.
>>> from cryptography import x509 >>> from cryptography.hazmat.primitives import hashes >>> csr = x509.load_pem_x509_csr(pem_req_data) >>> isinstance(csr.signature_hash_algorithm, hashes.SHA256) True
- cryptography.x509.load_der_x509_csr(data)
Added in version 0.9.
Deserialize a certificate signing request (CSR) from DER encoded data. DER is a binary format and is not commonly used with CSRs.
- Parameters:
data (bytes) – The DER encoded request data.
- Returns:
An instance of
CertificateSigningRequest
.
X.509 Certificate Object
- class cryptography.x509.Certificate
Added in version 0.7.
- version
- Type:
The certificate version as an enumeration. Version 3 certificates are the latest version and also the only type you should see in practice.
- Raises:
cryptography.x509.InvalidVersion – If the version in the certificate is not a known
X.509 version
.
>>> cert.version <Version.v3: 2>
- fingerprint(algorithm)
- Parameters:
algorithm – The
HashAlgorithm
that will be used to generate the fingerprint.- Return bytes:
The fingerprint using the supplied hash algorithm, as bytes.
>>> from cryptography.hazmat.primitives import hashes >>> cert.fingerprint(hashes.SHA256()) b'\x86\xd2\x187Gc\xfc\xe7}[+E9\x8d\xb4\x8f\x10\xe5S\xda\x18u\xbe}a\x03\x08[\xac\xa04?'
- public_key()
The public key associated with the certificate.
- Returns:
One of
CertificatePublicKeyTypes
.
>>> from cryptography.hazmat.primitives.asymmetric import rsa >>> public_key = cert.public_key() >>> isinstance(public_key, rsa.RSAPublicKey) True
- public_key_algorithm_oid
Added in version 43.0.0.
- Type:
Returns the
ObjectIdentifier
of the public key algorithm found inside the certificate. This will be one of the OIDs fromPublicKeyAlgorithmOID
.>>> cert.public_key_algorithm_oid <ObjectIdentifier(oid=1.2.840.113549.1.1.1, name=rsaEncryption)>
- not_valid_before
- Type:
Warning
This property is deprecated and will be removed in a future version. Please switch to the timezone-aware variant
not_valid_before_utc()
.A naïve datetime representing the beginning of the validity period for the certificate in UTC. This value is inclusive.
>>> cert.not_valid_before datetime.datetime(2010, 1, 1, 8, 30)
- not_valid_before_utc
Added in version 42.0.0.
- Type:
A timezone-aware datetime representing the beginning of the validity period for the certificate in UTC. This value is inclusive.
>>> cert.not_valid_before_utc datetime.datetime(2010, 1, 1, 8, 30, tzinfo=datetime.timezone.utc)
- not_valid_after
- Type:
Warning
This property is deprecated and will be removed in a future version. Please switch to the timezone-aware variant
not_valid_after_utc()
.A naïve datetime representing the end of the validity period for the certificate in UTC. This value is inclusive.
>>> cert.not_valid_after datetime.datetime(2030, 12, 31, 8, 30)
- not_valid_after_utc
Added in version 42.0.0.
- Type:
A timezone-aware datetime representing the end of the validity period for the certificate in UTC. This value is inclusive.
>>> cert.not_valid_after_utc datetime.datetime(2030, 12, 31, 8, 30, tzinfo=datetime.timezone.utc)
- signature_hash_algorithm
- Type:
Returns the
HashAlgorithm
which was used in signing this certificate. Can beNone
if signature did not use separate hash (ED25519
,ED448
).>>> from cryptography.hazmat.primitives import hashes >>> isinstance(cert.signature_hash_algorithm, hashes.SHA256) True
- signature_algorithm_oid
Added in version 1.6.
- Type:
Returns the
ObjectIdentifier
of the signature algorithm used to sign the certificate. This will be one of the OIDs fromSignatureAlgorithmOID
.>>> cert.signature_algorithm_oid <ObjectIdentifier(oid=1.2.840.113549.1.1.11, name=sha256WithRSAEncryption)>
- signature_algorithm_parameters
Added in version 41.0.0.
Returns the parameters of the signature algorithm used to sign the certificate. For RSA signatures it will return either a
PKCS1v15
orPSS
object.For ECDSA signatures it will return an
ECDSA
.For EdDSA and DSA signatures it will return
None
.These objects can be used to verify signatures on the certificate.
>>> from cryptography.hazmat.primitives.asymmetric import padding >>> pss_cert = x509.load_pem_x509_certificate(rsa_pss_pem_cert) >>> isinstance(pss_cert.signature_algorithm_parameters, padding.PSS) True
- extensions
- Type:
The extensions encoded in the certificate.
- Raises:
cryptography.x509.DuplicateExtension – If more than one extension of the same type is found within the certificate.
cryptography.x509.UnsupportedGeneralNameType – If an extension contains a general name that is not supported.
>>> for ext in cert.extensions: ... print(ext) <Extension(oid=<ObjectIdentifier(oid=2.5.29.35, name=authorityKeyIdentifier)>, critical=False, value=<AuthorityKeyIdentifier(key_identifier=b'\xe4}_\xd1\\\x95\x86\x08,\x05\xae\xbeu\xb6e\xa7\xd9]\xa8f', authority_cert_issuer=None, authority_cert_serial_number=None)>)> <Extension(oid=<ObjectIdentifier(oid=2.5.29.14, name=subjectKeyIdentifier)>, critical=False, value=<SubjectKeyIdentifier(digest=b'X\x01\x84$\x1b\xbc+R\x94J=\xa5\x10r\x14Q\xf5\xaf:\xc9')>)> <Extension(oid=<ObjectIdentifier(oid=2.5.29.15, name=keyUsage)>, critical=True, value=<KeyUsage(digital_signature=False, content_commitment=False, key_encipherment=False, data_encipherment=False, key_agreement=False, key_cert_sign=True, crl_sign=True, encipher_only=False, decipher_only=False)>)> <Extension(oid=<ObjectIdentifier(oid=2.5.29.32, name=certificatePolicies)>, critical=False, value=<CertificatePolicies([<PolicyInformation(policy_identifier=<ObjectIdentifier(oid=2.16.840.1.101.3.2.1.48.1, name=Unknown OID)>, policy_qualifiers=None)>])>)> <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
- tbs_certificate_bytes
Added in version 1.2.
- type:
bytes
The DER encoded bytes payload (as defined by RFC 5280) that is hashed and then signed by the private key of the certificate’s issuer. This data may be used to validate a signature, but use extreme caution as certificate validation is a complex problem that involves much more than just signature checks.
To validate the signature on a certificate you can do the following. Note: This only verifies that the certificate was signed with the private key associated with the public key provided and does not perform any of the other checks needed for secure certificate validation. Additionally, this example will only work for RSA public keys with
PKCS1v15
signatures, and so it can’t be used for general purpose signature verification.>>> from cryptography.hazmat.primitives.serialization import load_pem_public_key >>> from cryptography.hazmat.primitives.asymmetric import padding >>> issuer_public_key = load_pem_public_key(pem_issuer_public_key) >>> cert_to_check = x509.load_pem_x509_certificate(pem_data_to_check) >>> issuer_public_key.verify( ... cert_to_check.signature, ... cert_to_check.tbs_certificate_bytes, ... # Depends on the algorithm used to create the certificate ... padding.PKCS1v15(), ... cert_to_check.signature_hash_algorithm, ... )
An
InvalidSignature
exception will be raised if the signature fails to verify.
- verify_directly_issued_by(issuer)
Added in version 40.0.0.
- Parameters:
issuer (
Certificate
) – The issuer certificate to check against.
Warning
This method verifies that the certificate issuer name matches the issuer subject name and that the certificate is signed by the issuer’s private key. No other validation is performed. Callers are responsible for performing any additional validations required for their use case (e.g. checking the validity period, whether the signer is allowed to issue certificates, that the issuing certificate has a strong public key, etc).
Validates that the certificate is signed by the provided issuer and that the issuer’s subject name matches the issuer name of the certificate.
- Returns:
None
- Raises:
ValueError – If the issuer name on the certificate does not match the subject name of the issuer or the signature algorithm is unsupported.
TypeError – If the issuer does not have a supported public key type.
cryptography.exceptions.InvalidSignature – If the signature fails to verify.
- tbs_precertificate_bytes
Added in version 38.0.0.
- Type:
- Raises:
ValueError – If the certificate doesn’t have the expected Certificate Transparency extensions.
The DER encoded bytes payload (as defined by RFC 6962) that is hashed and then signed by the private key of the pre-certificate’s issuer. This data may be used to validate a Signed Certificate Timestamp’s signature, but use extreme caution as SCT validation is a complex problem that involves much more than just signature checks.
This method is primarily useful in the context of programs that interact with and verify the products of Certificate Transparency logs, as specified in RFC 6962. If you are not directly interacting with a Certificate Transparency log, this method unlikely to be what you want. To make unintentional misuse less likely, it raises a
ValueError
if the underlying certificate does not contain the expected Certificate Transparency extensions.
X.509 CRL (Certificate Revocation List) Object
- class cryptography.x509.CertificateRevocationList
Added in version 1.0.
A CertificateRevocationList is an object representing a list of revoked certificates. The object is iterable and will yield the RevokedCertificate objects stored in this CRL.
>>> len(crl) 1 >>> revoked_certificate = crl[0] >>> type(revoked_certificate) <class '...RevokedCertificate'> >>> for r in crl: ... print(r.serial_number) 0
- fingerprint(algorithm)
- Parameters:
algorithm – The
HashAlgorithm
that will be used to generate the fingerprint.- Return bytes:
The fingerprint using the supplied hash algorithm, as bytes.
>>> from cryptography.hazmat.primitives import hashes >>> crl.fingerprint(hashes.SHA256()) b'\xe3\x1d\xb5P\x18\x9ed\x9f\x16O\x9dm\xc1>\x8c\xca\xb1\xc6x?T\x9f\xe9t_\x1d\x8dF8V\xf78'
- get_revoked_certificate_by_serial_number(serial_number)
Added in version 2.3.
- Parameters:
serial_number – The serial as a Python integer.
- Returns:
RevokedCertificate
if theserial_number
is present in the CRL orNone
if it is not.
- signature_hash_algorithm
- Type:
Returns the
HashAlgorithm
which was used in signing this CRL. Can beNone
if signature did not use separate hash (ED25519
,ED448
).>>> from cryptography.hazmat.primitives import hashes >>> isinstance(crl.signature_hash_algorithm, hashes.SHA256) True
- signature_algorithm_oid
Added in version 1.6.
- Type:
Returns the
ObjectIdentifier
of the signature algorithm used to sign the CRL. This will be one of the OIDs fromSignatureAlgorithmOID
.>>> crl.signature_algorithm_oid <ObjectIdentifier(oid=1.2.840.113549.1.1.11, name=sha256WithRSAEncryption)>
- signature_algorithm_parameters
Added in version 42.0.0.
Returns the parameters of the signature algorithm used to sign the certificate revocation list. For RSA signatures it will return either a
PKCS1v15
orPSS
object.For ECDSA signatures it will return an
ECDSA
.For EdDSA and DSA signatures it will return
None
.These objects can be used to verify the CRL signature.
- next_update
- Type:
Warning
This property is deprecated and will be removed in a future version. Please switch to the timezone-aware variant
next_update_utc()
.A naïve datetime representing when the next update to this CRL is expected.
>>> crl.next_update datetime.datetime(2016, 1, 1, 0, 0)
- next_update_utc
Added in version 42.0.0.
- Type:
A timezone-aware datetime representing when the next update to this CRL is expected.
>>> crl.next_update_utc datetime.datetime(2016, 1, 1, 0, 0, tzinfo=datetime.timezone.utc)
- last_update
- Type:
Warning
This property is deprecated and will be removed in a future version. Please switch to the timezone-aware variant
last_update_utc()
.A naïve datetime representing when this CRL was last updated.
>>> crl.last_update datetime.datetime(2015, 1, 1, 0, 0)
- last_update_utc
Added in version 42.0.0.
- Type:
A timezone-aware datetime representing when this CRL was last updated.
>>> crl.last_update_utc datetime.datetime(2015, 1, 1, 0, 0, tzinfo=datetime.timezone.utc)
- extensions
- Type:
The extensions encoded in the CRL.
- tbs_certlist_bytes
Added in version 1.2.
- Type:
The DER encoded bytes payload (as defined by RFC 5280) that is hashed and then signed by the private key of the CRL’s issuer. This data may be used to validate a signature, but use extreme caution as CRL validation is a complex problem that involves much more than just signature checks.
X.509 Certificate Builder
- class cryptography.x509.CertificateBuilder[source]
Added in version 1.0.
>>> from cryptography import x509 >>> from cryptography.hazmat.primitives import hashes >>> from cryptography.hazmat.primitives.asymmetric import rsa >>> from cryptography.x509.oid import NameOID >>> import datetime >>> one_day = datetime.timedelta(1, 0, 0) >>> private_key = rsa.generate_private_key( ... public_exponent=65537, ... key_size=2048, ... ) >>> public_key = private_key.public_key() >>> builder = x509.CertificateBuilder() >>> builder = builder.subject_name(x509.Name([ ... x509.NameAttribute(NameOID.COMMON_NAME, 'cryptography.io'), ... ])) >>> builder = builder.issuer_name(x509.Name([ ... x509.NameAttribute(NameOID.COMMON_NAME, 'cryptography.io'), ... ])) >>> builder = builder.not_valid_before(datetime.datetime.today() - one_day) >>> builder = builder.not_valid_after(datetime.datetime.today() + (one_day * 30)) >>> builder = builder.serial_number(x509.random_serial_number()) >>> builder = builder.public_key(public_key) >>> builder = builder.add_extension( ... x509.SubjectAlternativeName( ... [x509.DNSName('cryptography.io')] ... ), ... critical=False ... ) >>> builder = builder.add_extension( ... x509.BasicConstraints(ca=False, path_length=None), critical=True, ... ) >>> certificate = builder.sign( ... private_key=private_key, algorithm=hashes.SHA256(), ... ) >>> isinstance(certificate, x509.Certificate) True
- issuer_name(name)[source]
Sets the issuer’s distinguished name.
- Parameters:
name – The
Name
that describes the issuer (CA).
- subject_name(name)[source]
Sets the subject’s distinguished name.
- Parameters:
name – The
Name
that describes the subject.
- public_key(public_key)[source]
Sets the subject’s public key.
- Parameters:
public_key – The subject’s public key. This can be one of
CertificatePublicKeyTypes
.
- serial_number(serial_number)[source]
Sets the certificate’s serial number (an integer). The CA’s policy determines how it attributes serial numbers to certificates. This number must uniquely identify the certificate given the issuer. CABForum Guidelines require entropy in the serial number to provide protection against hash collision attacks. For more information on secure random number generation, see Random number generation.
- Parameters:
serial_number – Integer number that will be used by the CA to identify this certificate (most notably during certificate revocation checking). Users should consider using
random_serial_number()
when possible.
- not_valid_before(time)[source]
Sets the certificate’s activation time. This is the time from which clients can start trusting the certificate. It may be different from the time at which the certificate was created.
- Parameters:
time – The
datetime.datetime
object (in UTC) that marks the activation time for the certificate. The certificate may not be trusted clients if it is used before this time.
- not_valid_after(time)[source]
Sets the certificate’s expiration time. This is the time from which clients should no longer trust the certificate. The CA’s policy will determine how long the certificate should remain in use.
- Parameters:
time – The
datetime.datetime
object (in UTC) that marks the expiration time for the certificate. The certificate may not be trusted clients if it is used after this time.
- add_extension(extval, critical)[source]
Adds an X.509 extension to the certificate.
- Parameters:
extval – An extension conforming to the
ExtensionType
interface.critical – Set to
True
if the extension must be understood and handled by whoever reads the certificate.
- sign(private_key, algorithm, *, rsa_padding=None)[source]
Sign the certificate using the CA’s private key.
- Parameters:
private_key – The key that will be used to sign the certificate, one of
CertificateIssuerPrivateKeyTypes
.algorithm – The
HashAlgorithm
that will be used to generate the signature. This must beNone
if theprivate_key
is anEd25519PrivateKey
or anEd448PrivateKey
and an instance of aHashAlgorithm
otherwise.rsa_padding (
None
,PKCS1v15
, orPSS
) –Added in version 41.0.0.
This is a keyword-only argument. If
private_key
is anRSAPrivateKey
then this can be set to eitherPKCS1v15
orPSS
to sign with those respective paddings. If this isNone
then RSA keys will default toPKCS1v15
padding. All other key types must not pass a value other thanNone
.
- Returns:
X.509 CSR (Certificate Signing Request) Object
- class cryptography.x509.CertificateSigningRequest
Added in version 0.9.
- public_key()
The public key associated with the request.
- Returns:
One of
CertificatePublicKeyTypes
.
>>> from cryptography.hazmat.primitives.asymmetric import rsa >>> public_key = csr.public_key() >>> isinstance(public_key, rsa.RSAPublicKey) True
- public_key_algorithm_oid
Added in version 43.0.0.
- Type:
Returns the
ObjectIdentifier
of the public key algorithm found inside the certificate. This will be one of the OIDs fromPublicKeyAlgorithmOID
.>>> csr.public_key_algorithm_oid <ObjectIdentifier(oid=1.2.840.113549.1.1.1, name=rsaEncryption)>
- signature_hash_algorithm
- Type:
Returns the
HashAlgorithm
which was used in signing this request. Can beNone
if signature did not use separate hash (ED25519
,ED448
).>>> from cryptography.hazmat.primitives import hashes >>> isinstance(csr.signature_hash_algorithm, hashes.SHA256) True
- signature_algorithm_oid
Added in version 1.6.
- Type:
Returns the
ObjectIdentifier
of the signature algorithm used to sign the request. This will be one of the OIDs fromSignatureAlgorithmOID
.>>> csr.signature_algorithm_oid <ObjectIdentifier(oid=1.2.840.113549.1.1.11, name=sha256WithRSAEncryption)>
- signature_algorithm_parameters
Added in version 42.0.0.
Returns the parameters of the signature algorithm used to sign the certificate signing request. For RSA signatures it will return either a
PKCS1v15
orPSS
object.For ECDSA signatures it will return an
ECDSA
.For EdDSA and DSA signatures it will return
None
.These objects can be used to verify signatures on the signing request.
- extensions
- Type:
The extensions encoded in the certificate signing request.
- Raises:
cryptography.x509.DuplicateExtension – If more than one extension of the same type is found within the certificate signing request.
cryptography.x509.UnsupportedGeneralNameType – If an extension contains a general name that is not supported.
- attributes
Added in version 36.0.0.
- Type:
The attributes encoded in the certificate signing request.
- public_bytes(encoding)
Added in version 1.0.
- Parameters:
encoding – The
Encoding
that will be used to serialize the certificate request.- Return bytes:
The data that can be written to a file or sent over the network to be signed by the certificate authority.
- signature
Added in version 1.2.
- Type:
The bytes of the certificate signing request’s signature.
- tbs_certrequest_bytes
Added in version 1.2.
- Type:
The DER encoded bytes payload (as defined by RFC 2986) that is hashed and then signed by the private key (corresponding to the public key embedded in the CSR). This data may be used to validate the CSR signature.
- is_signature_valid
Added in version 1.3.
Returns True if the CSR signature is correct, False otherwise.
X.509 Certificate Revocation List Builder
- class cryptography.x509.CertificateRevocationListBuilder[source]
Added in version 1.2.
>>> from cryptography import x509 >>> from cryptography.hazmat.primitives import hashes >>> from cryptography.hazmat.primitives.asymmetric import rsa >>> from cryptography.x509.oid import NameOID >>> import datetime >>> one_day = datetime.timedelta(1, 0, 0) >>> private_key = rsa.generate_private_key( ... public_exponent=65537, ... key_size=2048, ... ) >>> builder = x509.CertificateRevocationListBuilder() >>> builder = builder.issuer_name(x509.Name([ ... x509.NameAttribute(NameOID.COMMON_NAME, 'cryptography.io CA'), ... ])) >>> builder = builder.last_update(datetime.datetime.today()) >>> builder = builder.next_update(datetime.datetime.today() + one_day) >>> revoked_cert = x509.RevokedCertificateBuilder().serial_number( ... 333 ... ).revocation_date( ... datetime.datetime.today() ... ).build() >>> builder = builder.add_revoked_certificate(revoked_cert) >>> crl = builder.sign( ... private_key=private_key, algorithm=hashes.SHA256(), ... ) >>> len(crl) 1
- issuer_name(name)[source]
Sets the issuer’s distinguished name.
- Parameters:
name – The
Name
that describes the issuer (CA).
- last_update(time)[source]
Sets this CRL’s activation time. This is the time from which clients can start trusting this CRL. It may be different from the time at which this CRL was created. This is also known as the
thisUpdate
time.- Parameters:
time – The
datetime.datetime
object (in UTC) that marks the activation time for this CRL. The CRL may not be trusted if it is used before this time.
- next_update(time)[source]
Sets this CRL’s next update time. This is the time by which a new CRL will be issued. The CA is allowed to issue a new CRL before this date, however clients are not required to check for it.
- Parameters:
time – The
datetime.datetime
object (in UTC) that marks the next update time for this CRL.
- add_extension(extval, critical)[source]
Adds an X.509 extension to this CRL.
- Parameters:
extval – An extension with the
ExtensionType
interface.critical – Set to
True
if the extension must be understood and handled by whoever reads the CRL.
- add_revoked_certificate(revoked_certificate)[source]
Adds a revoked certificate to this CRL.
- Parameters:
revoked_certificate – An instance of
RevokedCertificate
. These can be obtained from an existing CRL or created withRevokedCertificateBuilder
.
- sign(private_key, algorithm, *, rsa_padding=None)[source]
Sign this CRL using the CA’s private key.
- Parameters:
private_key – The private key that will be used to sign the certificate, one of
CertificateIssuerPrivateKeyTypes
.algorithm – The
HashAlgorithm
that will be used to generate the signature. This must beNone
if theprivate_key
is anEd25519PrivateKey
or anEd448PrivateKey
and an instance of aHashAlgorithm
otherwise.rsa_padding (
None
,PKCS1v15
, orPSS
) –Added in version 42.0.0.
This is a keyword-only argument. If
private_key
is anRSAPrivateKey
then this can be set to eitherPKCS1v15
orPSS
to sign with those respective paddings. If this isNone
then RSA keys will default toPKCS1v15
padding. All other key types must not pass a value other thanNone
.
- Returns:
X.509 Revoked Certificate Object
- class cryptography.x509.RevokedCertificate[source]
Added in version 1.0.
- serial_number
- Type:
An integer representing the serial number of the revoked certificate.
>>> revoked_certificate.serial_number 0
- revocation_date
- Type:
Warning
This property is deprecated and will be removed in a future version. Please switch to the timezone-aware variant
revocation_date_utc()
.A naïve datetime representing the date this certificates was revoked.
>>> revoked_certificate.revocation_date datetime.datetime(2015, 1, 1, 0, 0)
- revocation_date_utc
Added in version 42.0.0.
- Type:
A timezone-aware datetime representing the date this certificates was revoked.
>>> revoked_certificate.revocation_date_utc datetime.datetime(2015, 1, 1, 0, 0, tzinfo=datetime.timezone.utc)
- extensions
- Type:
The extensions encoded in the revoked certificate.
>>> for ext in revoked_certificate.extensions: ... print(ext) <Extension(oid=<ObjectIdentifier(oid=2.5.29.24, name=invalidityDate)>, critical=False, value=<InvalidityDate(invalidity_date=2015-01-01 00:00:00)>)> <Extension(oid=<ObjectIdentifier(oid=2.5.29.21, name=cRLReason)>, critical=False, value=<CRLReason(reason=ReasonFlags.key_compromise)>)>
X.509 Revoked Certificate Builder
- class cryptography.x509.RevokedCertificateBuilder[source]
This class is used to create
RevokedCertificate
objects that can be used with theCertificateRevocationListBuilder
.Added in version 1.2.
>>> from cryptography import x509 >>> import datetime >>> builder = x509.RevokedCertificateBuilder() >>> builder = builder.revocation_date(datetime.datetime.today()) >>> builder = builder.serial_number(3333) >>> revoked_certificate = builder.build() >>> isinstance(revoked_certificate, x509.RevokedCertificate) True
- serial_number(serial_number)[source]
Sets the revoked certificate’s serial number.
- Parameters:
serial_number – Integer number that is used to identify the revoked certificate.
- revocation_date(time)[source]
Sets the certificate’s revocation date.
- Parameters:
time – The
datetime.datetime
object (in UTC) that marks the revocation time for the certificate.
- add_extension(extval, critical)[source]
Adds an X.509 extension to this revoked certificate.
- Parameters:
extval – An instance of one of the CRL entry extensions.
critical – Set to
True
if the extension must be understood and handled.
X.509 CSR (Certificate Signing Request) Builder Object
- class cryptography.x509.CertificateSigningRequestBuilder[source]
Added in version 1.0.
>>> from cryptography import x509 >>> from cryptography.hazmat.primitives import hashes >>> from cryptography.hazmat.primitives.asymmetric import rsa >>> from cryptography.x509.oid import AttributeOID, NameOID >>> private_key = rsa.generate_private_key( ... public_exponent=65537, ... key_size=2048, ... ) >>> builder = x509.CertificateSigningRequestBuilder() >>> builder = builder.subject_name(x509.Name([ ... x509.NameAttribute(NameOID.COMMON_NAME, 'cryptography.io'), ... ])) >>> builder = builder.add_extension( ... x509.BasicConstraints(ca=False, path_length=None), critical=True, ... ) >>> builder = builder.add_attribute( ... AttributeOID.CHALLENGE_PASSWORD, b"changeit" ... ) >>> request = builder.sign( ... private_key, hashes.SHA256() ... ) >>> isinstance(request, x509.CertificateSigningRequest) True
- add_extension(extension, critical)[source]
- Parameters:
extension – An extension conforming to the
ExtensionType
interface.critical – Set to True if the extension must be understood and handled by whoever reads the certificate.
- Returns:
- add_attribute(oid, value)[source]
Added in version 3.0.
- Parameters:
oid – An
ObjectIdentifier
instance.value (bytes) – The value of the attribute.
- Returns:
- sign(private_key, algorithm, *, rsa_padding=None)[source]
- Parameters:
private_key – The private key that will be used to sign the request. When the request is signed by a certificate authority, the private key’s associated public key will be stored in the resulting certificate. One of
CertificateIssuerPrivateKeyTypes
.algorithm – The
HashAlgorithm
that will be used to generate the request signature. This must beNone
if theprivate_key
is anEd25519PrivateKey
or anEd448PrivateKey
and an instance of aHashAlgorithm
otherwise.rsa_padding (
None
,PKCS1v15
, orPSS
) –Added in version 42.0.0.
This is a keyword-only argument. If
private_key
is anRSAPrivateKey
then this can be set to eitherPKCS1v15
orPSS
to sign with those respective paddings. If this isNone
then RSA keys will default toPKCS1v15
padding. All other key types must not pass a value other thanNone
.
- Returns:
A new
CertificateSigningRequest
.
- class cryptography.x509.Name[source]
Added in version 0.8.
An X509 Name is an ordered list of attributes. The object is iterable to get every attribute or you can use
Name.get_attributes_for_oid()
to obtain the specific type you want. Names are sometimes represented as a slash or comma delimited string (e.g./CN=mydomain.com/O=My Org/C=US
orCN=mydomain.com,O=My Org,C=US
).Technically, a Name is a list of sets of attributes, called Relative Distinguished Names or RDNs, although multi-valued RDNs are rarely encountered. The iteration order of values within a multi-valued RDN is preserved. If you need to handle multi-valued RDNs, the
rdns
property gives access to an ordered list ofRelativeDistinguishedName
objects.A Name can be initialized with an iterable of
NameAttribute
(the common case where each RDN has a single attribute) or an iterable ofRelativeDistinguishedName
objects (in the rare case of multi-valued RDNs).>>> len(cert.subject) 3 >>> for attribute in cert.subject: ... print(attribute) <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value='US')> <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value='Test Certificates 2011')> <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value='Good CA')>
- rdns
Added in version 1.6.
- Type:
list of
RelativeDistinguishedName
- classmethod from_rfc4514_string(data, attr_name_overrides=None)[source]
- Parameters:
- Returns:
A
Name
parsed fromdata
.
>>> x509.Name.from_rfc4514_string("CN=cryptography.io") <Name(CN=cryptography.io)> >>> x509.Name.from_rfc4514_string("E=pyca@cryptography.io", {"E": NameOID.EMAIL_ADDRESS}) <Name(1.2.840.113549.1.9.1=pyca@cryptography.io)>
- get_attributes_for_oid(oid)[source]
- Parameters:
oid – An
ObjectIdentifier
instance.- Returns:
A list of
NameAttribute
instances that match the OID provided. If nothing matches an empty list will be returned.
>>> cert.subject.get_attributes_for_oid(NameOID.COMMON_NAME) [<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value='Good CA')>]
- rfc4514_string(attr_name_overrides=None)[source]
Added in version 2.5.
Changed in version 36.0.0: Added
attr_name_overrides
parameter.Format the given name as a RFC 4514 Distinguished Name string, for example
CN=mydomain.com,O=My Org,C=US
.By default, attributes
CN
,L
,ST
,O
,OU
,C
,STREET
,DC
,UID
are represented by their short name. Unrecognized attributes are formatted as dotted OID strings.Example:
>>> name = x509.Name([ ... x509.NameAttribute(NameOID.EMAIL_ADDRESS, "santa@north.pole"), ... x509.NameAttribute(NameOID.COMMON_NAME, "Santa Claus"), ... ]) >>> name.rfc4514_string() 'CN=Santa Claus,1.2.840.113549.1.9.1=santa@north.pole' >>> name.rfc4514_string({NameOID.EMAIL_ADDRESS: "E"}) 'CN=Santa Claus,E=santa@north.pole'
- Parameters:
attr_name_overrides (Dict-like mapping from
ObjectIdentifier
tostr
) – Specify custom OID to name mappings, which can be used to match vendor-specific extensions. SeeNameOID
for common attribute OIDs.- Return type:
- class cryptography.x509.Version[source]
Added in version 0.7.
An enumeration for X.509 versions.
- v1
For version 1 X.509 certificates.
- v3
For version 3 X.509 certificates.
- class cryptography.x509.NameAttribute[source]
Added in version 0.8.
An X.509 name consists of a list of
RelativeDistinguishedName
instances, which consist of a set ofNameAttribute
instances.- oid
- Type:
The attribute OID.
- value
- Type:
str
orbytes
The value of the attribute. This will generally be a
str
, the only times it can be abytes
is whenoid
isX500_UNIQUE_IDENTIFIER
.
- rfc4514_attribute_name
Added in version 35.0.0.
- Type:
The RFC 4514 short attribute name (for example “CN”), or the OID dotted string if a short name is unavailable.
- rfc4514_string(attr_name_overrides=None)[source]
Added in version 2.5.
Changed in version 36.0.0: Added
attr_name_overrides
parameter.- Return str:
Format the given attribute as a RFC 4514 Distinguished Name string.
- Parameters:
attr_name_overrides (Dict-like mapping from
ObjectIdentifier
tostr
) – Specify custom OID to name mappings, which can be used to match vendor-specific extensions.
- class cryptography.x509.RelativeDistinguishedName(attributes)[source]
Added in version 1.6.
A relative distinguished name is a non-empty set of name attributes. The object is iterable to get every attribute, preserving the original order. Passing duplicate attributes to the constructor raises
ValueError
.- get_attributes_for_oid(oid)[source]
- Parameters:
oid – An
ObjectIdentifier
instance.- Returns:
A list of
NameAttribute
instances that match the OID provided. The list should contain zero or one values.
- rfc4514_string(attr_name_overrides=None)[source]
Added in version 2.5.
Changed in version 36.0.0: Added
attr_name_overrides
parameter.- Return str:
Format the given RDN set as a RFC 4514 Distinguished Name string.
- Parameters:
attr_name_overrides (Dict-like mapping from
ObjectIdentifier
tostr
) – Specify custom OID to name mappings, which can be used to match vendor-specific extensions.
- class cryptography.x509.ObjectIdentifier
Added in version 0.8.
Object identifiers (frequently seen abbreviated as OID) identify the type of a value (see:
NameAttribute
).
General Name Classes
- class cryptography.x509.GeneralName[source]
Added in version 0.9.
This is the generic interface that all the following classes are registered against.
- class cryptography.x509.RFC822Name(value)[source]
Added in version 0.9.
This corresponds to an email address. For example,
user@example.com
.- Parameters:
value – The email address. If the address contains an internationalized domain name then it must be encoded to an A-label string before being passed.
- Raises:
ValueError – If the provided string is not an A-label.
- class cryptography.x509.DNSName(value)[source]
Added in version 0.9.
This corresponds to a domain name. For example,
cryptography.io
.
- class cryptography.x509.DirectoryName(value)[source]
Added in version 0.9.
This corresponds to a directory name.
- class cryptography.x509.UniformResourceIdentifier(value)[source]
Added in version 0.9.
This corresponds to a uniform resource identifier. For example,
https://cryptography.io
.- Parameters:
value – The URI. If it contains an internationalized domain name then it must be encoded to an A-label string before being passed.
- Raises:
ValueError – If the provided string is not an A-label.
- class cryptography.x509.IPAddress(value)[source]
Added in version 0.9.
This corresponds to an IP address.
- value
- Type:
X.509 Extensions
- class cryptography.x509.Extensions[source]
Added in version 0.9.
An X.509 Extensions instance is an ordered list of extensions. The object is iterable to get every extension.
- get_extension_for_oid(oid)[source]
- Parameters:
oid – An
ObjectIdentifier
instance.- Returns:
An instance of
Extension
.- Raises:
cryptography.x509.ExtensionNotFound – If the certificate does not have the extension requested.
>>> from cryptography.x509.oid import ExtensionOID >>> cert.extensions.get_extension_for_oid(ExtensionOID.BASIC_CONSTRAINTS) <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
- get_extension_for_class(extclass)[source]
Added in version 1.1.
- Parameters:
extclass – An extension class.
- Returns:
An instance of
Extension
.- Raises:
cryptography.x509.ExtensionNotFound – If the certificate does not have the extension requested.
>>> from cryptography import x509 >>> cert.extensions.get_extension_for_class(x509.BasicConstraints) <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
- class cryptography.x509.Extension[source]
Added in version 0.9.
- oid
- Type:
One of the
ExtensionOID
OIDs.
- critical
- Type:
Determines whether a given extension is critical or not. RFC 5280 requires that “A certificate-using system MUST reject the certificate if it encounters a critical extension it does not recognize or a critical extension that contains information that it cannot process”.
- value
Returns an instance of the extension type corresponding to the OID.
- class cryptography.x509.ExtensionType[source]
Added in version 1.0.
This is the interface against which all the following extension types are registered.
- oid
- Type:
Returns the OID associated with the given extension type.
- class cryptography.x509.KeyUsage(digital_signature, content_commitment, key_encipherment, data_encipherment, key_agreement, key_cert_sign, crl_sign, encipher_only, decipher_only)[source]
Added in version 0.9.
The key usage extension defines the purpose of the key contained in the certificate. The usage restriction might be employed when a key that could be used for more than one operation is to be restricted.
- digital_signature
- Type:
This purpose is set to true when the subject public key is used for verifying digital signatures, other than signatures on certificates (
key_cert_sign
) and CRLs (crl_sign
).
- content_commitment
- Type:
This purpose is set to true when the subject public key is used for verifying digital signatures, other than signatures on certificates (
key_cert_sign
) and CRLs (crl_sign
). It is used to provide a non-repudiation service that protects against the signing entity falsely denying some action. In the case of later conflict, a reliable third party may determine the authenticity of the signed data. This was callednon_repudiation
in older revisions of the X.509 specification.
- key_encipherment
- Type:
This purpose is set to true when the subject public key is used for enciphering private or secret keys.
- data_encipherment
- Type:
This purpose is set to true when the subject public key is used for directly enciphering raw user data without the use of an intermediate symmetric cipher.
- key_agreement
- Type:
This purpose is set to true when the subject public key is used for key agreement. For example, when a Diffie-Hellman key is to be used for key management, then this purpose is set to true.
- key_cert_sign
- Type:
This purpose is set to true when the subject public key is used for verifying signatures on public key certificates. If this purpose is set to true then
ca
must be true in theBasicConstraints
extension.
- crl_sign
- Type:
This purpose is set to true when the subject public key is used for verifying signatures on certificate revocation lists.
- encipher_only
- Type:
When this purposes is set to true and the
key_agreement
purpose is also set, the subject public key may be used only for enciphering data while performing key agreement.- Raises:
ValueError – This is raised if accessed when
key_agreement
is false.
- decipher_only
- Type:
When this purposes is set to true and the
key_agreement
purpose is also set, the subject public key may be used only for deciphering data while performing key agreement.- Raises:
ValueError – This is raised if accessed when
key_agreement
is false.
- class cryptography.x509.BasicConstraints(ca, path_length)[source]
Added in version 0.9.
Basic constraints is an X.509 extension type that defines whether a given certificate is allowed to sign additional certificates and what path length restrictions may exist.
- oid
Added in version 1.0.
- Type:
Returns
BASIC_CONSTRAINTS
.
- path_length
- Type:
int or None
The maximum path length for certificates subordinate to this certificate. This attribute only has meaning if
ca
is true. Ifca
is true then a path length of None means there’s no restriction on the number of subordinate CAs in the certificate chain. If it is zero or greater then it defines the maximum length for a subordinate CA’s certificate chain. For example, apath_length
of 1 means the certificate can sign a subordinate CA, but the subordinate CA is not allowed to create subordinates withca
set to true.
- class cryptography.x509.ExtendedKeyUsage(usages)[source]
Added in version 0.9.
This extension indicates one or more purposes for which the certified public key may be used, in addition to or in place of the basic purposes indicated in the key usage extension. The object is iterable to obtain the list of
ExtendedKeyUsageOID
OIDs present.- Parameters:
usages (list) – A list of
ExtendedKeyUsageOID
OIDs.
- oid
Added in version 1.0.
- Type:
Returns
EXTENDED_KEY_USAGE
.
- class cryptography.x509.OCSPNoCheck[source]
Added in version 1.0.
This presence of this extension indicates that an OCSP client can trust a responder for the lifetime of the responder’s certificate. CAs issuing such a certificate should realize that a compromise of the responder’s key is as serious as the compromise of a CA key used to sign CRLs, at least for the validity period of this certificate. CA’s may choose to issue this type of certificate with a very short lifetime and renew it frequently. This extension is only relevant when the certificate is an authorized OCSP responder.
- oid
Added in version 1.0.
- Type:
Returns
OCSP_NO_CHECK
.
- class cryptography.x509.TLSFeature(features)[source]
Added in version 2.1.
The TLS Feature extension is defined in RFC 7633 and is used in certificates for OCSP Must-Staple. The object is iterable to get every element.
- Parameters:
features (list) – A list of features to enable from the
TLSFeatureType
enum. At this time onlystatus_request
orstatus_request_v2
are allowed.
- oid
- Type:
Returns
TLS_FEATURE
.
- class cryptography.x509.TLSFeatureType[source]
Added in version 2.1.
An enumeration of TLS Feature types.
- class cryptography.x509.NameConstraints(permitted_subtrees, excluded_subtrees)[source]
Added in version 1.0.
The name constraints extension, which only has meaning in a CA certificate, defines a name space within which all subject names in certificates issued beneath the CA certificate must (or must not) be in. For specific details on the way this extension should be processed see RFC 5280.
- oid
Added in version 1.0.
- Type:
Returns
NAME_CONSTRAINTS
.
- permitted_subtrees
- Type:
list of
GeneralName
objects or None
The set of permitted name patterns. If a name matches this and an element in
excluded_subtrees
it is invalid. At least one ofpermitted_subtrees
andexcluded_subtrees
will be non-None.
- excluded_subtrees
- Type:
list of
GeneralName
objects or None
Any name matching a restriction in the
excluded_subtrees
field is invalid regardless of information appearing in thepermitted_subtrees
. At least one ofpermitted_subtrees
andexcluded_subtrees
will be non-None.
- class cryptography.x509.AuthorityKeyIdentifier(key_identifier, authority_cert_issuer, authority_cert_serial_number)[source]
Added in version 0.9.
The authority key identifier extension provides a means of identifying the public key corresponding to the private key used to sign a certificate. This extension is typically used to assist in determining the appropriate certificate chain. For more information about generation and use of this extension see RFC 5280 Section 4.2.1.1.
- oid
Added in version 1.0.
- Type:
Returns
AUTHORITY_KEY_IDENTIFIER
.
- key_identifier
- Type:
A value derived from the public key used to verify the certificate’s signature.
- authority_cert_issuer
- Type:
A list of
GeneralName
instances or None
The
GeneralName
(one or multiple) of the issuer’s issuer.
- classmethod from_issuer_public_key(public_key)[source]
Added in version 1.0.
Note
This method should be used if the issuer certificate does not contain a
SubjectKeyIdentifier
. Otherwise, usefrom_issuer_subject_key_identifier()
.Creates a new AuthorityKeyIdentifier instance using the public key provided to generate the appropriate digest. This should be the issuer’s public key. The resulting object will contain
key_identifier
, butauthority_cert_issuer
andauthority_cert_serial_number
will be None. The generatedkey_identifier
is the SHA1 hash of thesubjectPublicKey
ASN.1 bit string. This is the first recommendation in RFC 5280 section 4.2.1.2.- Parameters:
public_key – One of
CertificateIssuerPublicKeyTypes
.
>>> from cryptography import x509 >>> issuer_cert = x509.load_pem_x509_certificate(pem_data) >>> x509.AuthorityKeyIdentifier.from_issuer_public_key(issuer_cert.public_key()) <AuthorityKeyIdentifier(key_identifier=b'X\x01\x84$\x1b\xbc+R\x94J=\xa5\x10r\x14Q\xf5\xaf:\xc9', authority_cert_issuer=None, authority_cert_serial_number=None)>
- classmethod from_issuer_subject_key_identifier(ski)[source]
Added in version 1.3.
Note
This method should be used if the issuer certificate contains a
SubjectKeyIdentifier
. Otherwise, usefrom_issuer_public_key()
.Creates a new AuthorityKeyIdentifier instance using the SubjectKeyIdentifier from the issuer certificate. The resulting object will contain
key_identifier
, butauthority_cert_issuer
andauthority_cert_serial_number
will be None.- Parameters:
ski – The
SubjectKeyIdentifier
from the issuer certificate.
>>> from cryptography import x509 >>> issuer_cert = x509.load_pem_x509_certificate(pem_data) >>> ski_ext = issuer_cert.extensions.get_extension_for_class(x509.SubjectKeyIdentifier) >>> x509.AuthorityKeyIdentifier.from_issuer_subject_key_identifier(ski_ext.value) <AuthorityKeyIdentifier(key_identifier=b'X\x01\x84$\x1b\xbc+R\x94J=\xa5\x10r\x14Q\xf5\xaf:\xc9', authority_cert_issuer=None, authority_cert_serial_number=None)>
- class cryptography.x509.SubjectKeyIdentifier(digest)[source]
Added in version 0.9.
The subject key identifier extension provides a means of identifying certificates that contain a particular public key.
- oid
Added in version 1.0.
- Type:
Returns
SUBJECT_KEY_IDENTIFIER
.
- classmethod from_public_key(public_key)[source]
Added in version 1.0.
Creates a new SubjectKeyIdentifier instance using the public key provided to generate the appropriate digest. This should be the public key that is in the certificate. The generated digest is the SHA1 hash of the
subjectPublicKey
ASN.1 bit string. This is the first recommendation in RFC 5280 section 4.2.1.2.- Parameters:
public_key – One of
CertificatePublicKeyTypes
.
>>> from cryptography import x509 >>> csr = x509.load_pem_x509_csr(pem_req_data) >>> x509.SubjectKeyIdentifier.from_public_key(csr.public_key()) <SubjectKeyIdentifier(digest=b'\x8c"\x98\xe2\xb5\xbf]\xe8*2\xf8\xd2\'?\x00\xd2\xc7#\xe4c')>
- class cryptography.x509.SubjectAlternativeName(general_names)[source]
Added in version 0.9.
Subject alternative name is an X.509 extension that provides a list of general name instances that provide a set of identities for which the certificate is valid. The object is iterable to get every element.
- Parameters:
general_names (list) – A list of
GeneralName
instances.
- oid
Added in version 1.0.
- Type:
Returns
SUBJECT_ALTERNATIVE_NAME
.
- get_values_for_type(type)[source]
- Parameters:
type – A
GeneralName
instance. This is one of the general name classes.- Returns:
A list of values extracted from the matched general names. The type of the returned values depends on the
GeneralName
.
>>> from cryptography import x509 >>> from cryptography.hazmat.primitives import hashes >>> from cryptography.x509.oid import ExtensionOID >>> cert = x509.load_pem_x509_certificate(cryptography_cert_pem) >>> # Get the subjectAltName extension from the certificate >>> ext = cert.extensions.get_extension_for_oid(ExtensionOID.SUBJECT_ALTERNATIVE_NAME) >>> # Get the dNSName entries from the SAN extension >>> ext.value.get_values_for_type(x509.DNSName) ['www.cryptography.io', 'cryptography.io']
- class cryptography.x509.IssuerAlternativeName(general_names)[source]
Added in version 1.0.
Issuer alternative name is an X.509 extension that provides a list of general name instances that provide a set of identities for the certificate issuer. The object is iterable to get every element.
- Parameters:
general_names (list) – A list of
GeneralName
instances.
- oid
Added in version 1.0.
- Type:
Returns
ISSUER_ALTERNATIVE_NAME
.
- get_values_for_type(type)[source]
- Parameters:
type – A
GeneralName
instance. This is one of the general name classes.- Returns:
A list of values extracted from the matched general names.
- class cryptography.x509.PrecertificateSignedCertificateTimestamps(scts)[source]
Added in version 2.0.
This extension contains
SignedCertificateTimestamp
instances which were issued for the pre-certificate corresponding to this certificate. These can be used to verify that the certificate is included in a public Certificate Transparency log.It is an iterable containing one or more
SignedCertificateTimestamp
objects.- Parameters:
scts (list) – A
list
ofSignedCertificateTimestamp
objects.
- oid
- Type:
- class cryptography.x509.PrecertPoison[source]
Added in version 2.4.
This extension indicates that the certificate should not be treated as a certificate for the purposes of validation, but is instead for submission to a certificate transparency log in order to obtain SCTs which will be embedded in a
PrecertificateSignedCertificateTimestamps
extension on the final certificate.- oid
- Type:
Returns
PRECERT_POISON
.
- class cryptography.x509.SignedCertificateTimestamps(scts)[source]
Added in version 3.0.
This extension contains
SignedCertificateTimestamp
instances. These can be used to verify that the certificate is included in a public Certificate Transparency log. This extension is only found in OCSP responses. For SCTs in an X.509 certificate seePrecertificateSignedCertificateTimestamps
.It is an iterable containing one or more
SignedCertificateTimestamp
objects.- Parameters:
scts (list) – A
list
ofSignedCertificateTimestamp
objects.
- oid
- Type:
Returns
SIGNED_CERTIFICATE_TIMESTAMPS
.
- class cryptography.x509.DeltaCRLIndicator(crl_number)[source]
Added in version 2.1.
The delta CRL indicator is a CRL extension that identifies a CRL as being a delta CRL. Delta CRLs contain updates to revocation information previously distributed, rather than all the information that would appear in a complete CRL.
- Parameters:
crl_number (int) – The CRL number of the complete CRL that the delta CRL is updating.
- oid
- Type:
Returns
DELTA_CRL_INDICATOR
.
- class cryptography.x509.AuthorityInformationAccess(descriptions)[source]
Added in version 0.9.
The authority information access extension indicates how to access information and services for the issuer of the certificate in which the extension appears. Information and services may include online validation services (such as OCSP) and issuer data. It is an iterable, containing one or more
AccessDescription
instances.- Parameters:
descriptions (list) – A list of
AccessDescription
objects.
- oid
Added in version 1.0.
- Type:
Returns
AUTHORITY_INFORMATION_ACCESS
.
- class cryptography.x509.SubjectInformationAccess(descriptions)[source]
Added in version 3.0.
The subject information access extension indicates how to access information and services for the subject of the certificate in which the extension appears. When the subject is a CA, information and services may include certificate validation services and CA policy data. When the subject is an end entity, the information describes the type of services offered and how to access them. It is an iterable, containing one or more
AccessDescription
instances.- Parameters:
descriptions (list) – A list of
AccessDescription
objects.
- oid
- Type:
Returns
SUBJECT_INFORMATION_ACCESS
.
- class cryptography.x509.AccessDescription(access_method, access_location)[source]
Added in version 0.9.
- access_method
- Type:
The access method defines what the
access_location
means. It must beOCSP
orCA_ISSUERS
when used withAuthorityInformationAccess
orCA_REPOSITORY
when used withSubjectInformationAccess
.If it is
OCSP
the access location will be where to obtain OCSP information for the certificate. If it isCA_ISSUERS
the access location will provide additional information about the issuing certificate. Finally, if it isCA_REPOSITORY
the access location will be the location of the CA’s repository.
- access_location
- Type:
Where to access the information defined by the access method.
- class cryptography.x509.FreshestCRL(distribution_points)[source]
Added in version 2.1.
The freshest CRL extension (also known as Delta CRL Distribution Point) identifies how delta CRL information is obtained. It is an iterable, containing one or more
DistributionPoint
instances.- Parameters:
distribution_points (list) – A list of
DistributionPoint
instances.
- oid
- Type:
Returns
FRESHEST_CRL
.
- class cryptography.x509.CRLDistributionPoints(distribution_points)[source]
Added in version 0.9.
The CRL distribution points extension identifies how CRL information is obtained. It is an iterable, containing one or more
DistributionPoint
instances.- Parameters:
distribution_points (list) – A list of
DistributionPoint
instances.
- oid
Added in version 1.0.
- Type:
Returns
CRL_DISTRIBUTION_POINTS
.
- class cryptography.x509.DistributionPoint(full_name, relative_name, reasons, crl_issuer)[source]
Added in version 0.9.
- full_name
- Type:
list of
GeneralName
instances or None
This field describes methods to retrieve the CRL. At most one of
full_name
orrelative_name
will be non-None.
- relative_name
- Type:
RelativeDistinguishedName
or None
This field describes methods to retrieve the CRL relative to the CRL issuer. At most one of
full_name
orrelative_name
will be non-None.Changed in version 1.6: Changed from
Name
toRelativeDistinguishedName
.
- crl_issuer
- Type:
list of
GeneralName
instances or None
Information about the issuer of the CRL.
- reasons
- Type:
frozenset of
ReasonFlags
or None
The reasons a given distribution point may be used for when performing revocation checks.
- class cryptography.x509.ReasonFlags[source]
Added in version 0.9.
An enumeration for CRL reasons.
- unspecified
It is unspecified why the certificate was revoked. This reason cannot be used as a reason flag in a
DistributionPoint
.
- key_compromise
This reason indicates that the private key was compromised.
- ca_compromise
This reason indicates that the CA issuing the certificate was compromised.
- affiliation_changed
This reason indicates that the subject’s name or other information has changed.
- superseded
This reason indicates that a certificate has been superseded.
- cessation_of_operation
This reason indicates that the certificate is no longer required.
- certificate_hold
This reason indicates that the certificate is on hold.
- privilege_withdrawn
This reason indicates that the privilege granted by this certificate have been withdrawn.
- aa_compromise
When an attribute authority has been compromised.
- remove_from_crl
This reason indicates that the certificate was on hold and should be removed from the CRL. This reason cannot be used as a reason flag in a
DistributionPoint
.
- class cryptography.x509.InhibitAnyPolicy(skip_certs)[source]
Added in version 1.0.
The inhibit
anyPolicy
extension indicates that the special OIDANY_POLICY
, is not considered an explicit match for otherCertificatePolicies
except when it appears in an intermediate self-issued CA certificate. The value indicates the number of additional non-self-issued certificates that may appear in the path beforeANY_POLICY
is no longer permitted. For example, a value of one indicates thatANY_POLICY
may be processed in certificates issued by the subject of this certificate, but not in additional certificates in the path.- oid
Added in version 1.0.
- Type:
Returns
INHIBIT_ANY_POLICY
.
- class cryptography.x509.PolicyConstraints[source]
Added in version 1.3.
The policy constraints extension is used to inhibit policy mapping or require that each certificate in a chain contain an acceptable policy identifier. For more information about the use of this extension see RFC 5280.
- oid
- Type:
Returns
POLICY_CONSTRAINTS
.
- require_explicit_policy
- Type:
int or None
If this field is not None, the value indicates the number of additional certificates that may appear in the chain before an explicit policy is required for the entire path. When an explicit policy is required, it is necessary for all certificates in the chain to contain an acceptable policy identifier in the certificate policies extension. An acceptable policy identifier is the identifier of a policy required by the user of the certification path or the identifier of a policy that has been declared equivalent through policy mapping.
- inhibit_policy_mapping
- Type:
int or None
If this field is not None, the value indicates the number of additional certificates that may appear in the chain before policy mapping is no longer permitted. For example, a value of one indicates that policy mapping may be processed in certificates issued by the subject of this certificate, but not in additional certificates in the chain.
- class cryptography.x509.CRLNumber(crl_number)[source]
Added in version 1.2.
The CRL number is a CRL extension that conveys a monotonically increasing sequence number for a given CRL scope and CRL issuer. This extension allows users to easily determine when a particular CRL supersedes another CRL. RFC 5280 requires that this extension be present in conforming CRLs.
- oid
- Type:
Returns
CRL_NUMBER
.
- class cryptography.x509.IssuingDistributionPoint(full_name, relative_name, only_contains_user_certs, only_contains_ca_certs, only_some_reasons, indirect_crl, only_contains_attribute_certs)[source]
Added in version 2.5.
Issuing distribution point is a CRL extension that identifies the CRL distribution point and scope for a particular CRL. It indicates whether the CRL covers revocation for end entity certificates only, CA certificates only, attribute certificates only, or a limited set of reason codes. For specific details on the way this extension should be processed see RFC 5280.
- oid
- Type:
Returns
ISSUING_DISTRIBUTION_POINT
.
- only_contains_user_certs
- Type:
Set to
True
if the CRL this extension is embedded within only contains information about user certificates.
- only_contains_ca_certs
- Type:
Set to
True
if the CRL this extension is embedded within only contains information about CA certificates.
- indirect_crl
- Type:
Set to
True
if the CRL this extension is embedded within includes certificates issued by one or more authorities other than the CRL issuer.
- only_contains_attribute_certs
- Type:
Set to
True
if the CRL this extension is embedded within only contains information about attribute certificates.
- only_some_reasons
- Type:
frozenset of
ReasonFlags
or None
The reasons for which the issuing distribution point is valid. None indicates that it is valid for all reasons.
- full_name
- Type:
list of
GeneralName
instances or None
This field describes methods to retrieve the CRL. At most one of
full_name
orrelative_name
will be non-None.
- relative_name
- Type:
RelativeDistinguishedName
or None
This field describes methods to retrieve the CRL relative to the CRL issuer. At most one of
full_name
orrelative_name
will be non-None.
- class cryptography.x509.UnrecognizedExtension[source]
Added in version 1.2.
A generic extension class used to hold the raw value of extensions that
cryptography
does not know how to parse. This can also be used when creating new certificates, CRLs, or OCSP requests and responses to encode extensions thatcryptography
does not know how to generate.- oid
- Type:
Returns the OID associated with this extension.
- class cryptography.x509.MSCertificateTemplate(template_id, major_version, minor_version)[source]
Added in version 41.0.0.
The Microsoft certificate template extension is a proprietary Microsoft PKI extension that is used to provide information about the template associated with the certificate.
- oid
- Type:
Returns
MS_CERTIFICATE_TEMPLATE
.
- template_id
- Type:
- class cryptography.x509.CertificatePolicies(policies)[source]
Added in version 0.9.
The certificate policies extension is an iterable, containing one or more
PolicyInformation
instances.- Parameters:
policies (list) – A list of
PolicyInformation
instances.
As an example of how
CertificatePolicies
might be used, if you wanted to check if a certificated contained the CAB Forum’s “domain-validated” policy, you might write code like:def contains_domain_validated(policies): return any( policy.policy_identifier.dotted_string == "2.23.140.1.2.1" for policy in policies )
- oid
Added in version 1.0.
- Type:
Returns
CERTIFICATE_POLICIES
.
- class cryptography.x509.Admissions(authority, admissions)[source]
Added in version 44.0.0.
The admissions extension contains information on registration and professional admission, as specified by Common PKI v2. It is an iterable, containing one or more
Admission
instances.- oid
- Type:
Returns
ADMISSIONS
.
- authority
- Type:
GeneralName
or None
An optional identifier of the institution who granted the admissions. This serves as the default value for the admission authority in a single
Admission
if it is not specified there.
Certificate Policies Classes
These classes may be present within a CertificatePolicies
instance.
- class cryptography.x509.PolicyInformation(policy_identifier, policy_qualifiers)[source]
Added in version 0.9.
Contains a policy identifier and an optional list of qualifiers.
- policy_identifier
- Type:
- policy_qualifiers
- Type:
A list consisting of
str
and/orUserNotice
objects. If the value isstr
it is a pointer to the practice statement published by the certificate authority. If it is a user notice it is meant for display to the relying party when the certificate is used.
- class cryptography.x509.UserNotice(notice_reference, explicit_text)[source]
Added in version 0.9.
User notices are intended for display to a relying party when a certificate is used. In practice, few if any UIs expose this data and it is a rarely encoded component.
- notice_reference
- Type:
NoticeReference
or None
The notice reference field names an organization and identifies, by number, a particular statement prepared by that organization.
- class cryptography.x509.NoticeReference(organization, notice_numbers)[source]
Notice reference can name an organization and provide information about notices related to the certificate. For example, it might identify the organization name and notice number 1. Application software could have a notice file containing the current set of notices for the named organization; the application would then extract the notice text from the file and display it. In practice this is rarely seen.
Added in version 0.9.
Admissions Classes
These classes may be present within an Admissions
instance.
- class cryptography.x509.Admission(admission_authority, naming_authority, profession_infos)[source]
Added in version 44.0.0.
Contains professional information and optionally the authorization information.
- admission_authority
- Type:
GeneralName
or None
An optional identifier of the institution who granted the admission.
- naming_authority
- Type:
NamingAuthority
or None
An optional identifier of the institution who is administering the information of the professions in this admission. This serves as the default value for the naming authority in a single
ProfessionInfo
if it is not specified there.
- profession_infos
- Type:
An information on the professions that are part of this admission. This is a list of
ProfessionInfo
objects.
- class cryptography.x509.ProfessionInfo(naming_authority, profession_items, profession_oids, registration_number, add_profession_info)[source]
Added in version 44.0.0.
Contains the information for a single profession in the admission.
- naming_authority
- Type:
NamingAuthority
or None
An optional identifier of the institution who is administering the information of this profession.
- profession_oids
- Type:
list or None
An optional list of
ObjectIdentifier
elements. Each element in the list corresponds to the resp. text string in theprofession_items
list.
- class cryptography.x509.NamingAuthority(id, url, text)[source]
Added in version 44.0.0.
Identifies an institution who is responsible for the administration of title registers in an admission. The naming authority can be identified by an object identifier in the field
id
, by the text in the fieldtext
, by a URL address in the fieldurl
, or by a combination of them.- id
- Type:
ObjectIdentifier
or None
CRL Entry Extensions
These extensions are only valid within a RevokedCertificate
object.
- class cryptography.x509.CertificateIssuer(general_names)[source]
Added in version 1.2.
The certificate issuer is an extension that is only valid inside
RevokedCertificate
objects. If theindirectCRL
property of the parent CRL’s IssuingDistributionPoint extension is set, then this extension identifies the certificate issuer associated with the revoked certificate. The object is iterable to get every element.- Parameters:
general_names (list) – A list of
GeneralName
instances.
- oid
- Type:
Returns
CERTIFICATE_ISSUER
.
- get_values_for_type(type)[source]
- Parameters:
type – A
GeneralName
instance. This is one of the general name classes.- Returns:
A list of values extracted from the matched general names. The type of the returned values depends on the
GeneralName
.
- class cryptography.x509.CRLReason(reason)[source]
Added in version 1.2.
CRL reason (also known as
reasonCode
) is an extension that is only valid insideRevokedCertificate
objects. It identifies a reason for the certificate revocation.- Parameters:
reason – An element from
ReasonFlags
.
- oid
- Type:
Returns
CRL_REASON
.
- reason
- Type:
An element from
ReasonFlags
- class cryptography.x509.InvalidityDate(invalidity_date)[source]
Added in version 1.2.
Invalidity date is an extension that is only valid inside
RevokedCertificate
objects. It provides the date on which it is known or suspected that the private key was compromised or that the certificate otherwise became invalid. This date may be earlier than the revocation date in the CRL entry, which is the date at which the CA processed the revocation.- Parameters:
invalidity_date – The
datetime.datetime
when it is known or suspected that the private key was compromised.
- oid
- Type:
Returns
INVALIDITY_DATE
.
- invalidity_date
- Type:
- invalidity_date_utc
Added in version 43.0.0.
- Type:
The invalidity date in UTC as a timezone-aware datetime object.
OCSP Extensions
- class cryptography.x509.OCSPNonce(nonce)[source]
Added in version 2.4.
OCSP nonce is an extension that is only valid inside
OCSPRequest
andOCSPResponse
objects. The nonce cryptographically binds a request and a response to prevent replay attacks. In practice nonces are rarely used in OCSP due to the desire to precompute OCSP responses at large scale.
- class cryptography.x509.OCSPAcceptableResponses(response)[source]
Added in version 41.0.0.
OCSP acceptable responses is an extension that is only valid inside
OCSPRequest
objects. This allows an OCSP client to tell the server what types of responses it supports. In practice this is rarely used, because there is only one kind of OCSP response in wide use.- oid
- Type:
Returns
ACCEPTABLE_RESPONSES
.
X.509 Request Attributes
- class cryptography.x509.Attributes[source]
Added in version 36.0.0.
An Attributes instance is an ordered list of attributes. The object is iterable to get every attribute. Each returned element is an
Attribute
.- get_attribute_for_oid(oid)[source]
Added in version 36.0.0.
- Parameters:
oid – An
ObjectIdentifier
instance.- Returns:
The
Attribute
or an exception if not found.- Raises:
cryptography.x509.AttributeNotFound – If the request does not have the attribute requested.
Object Identifiers
X.509 elements are frequently identified by ObjectIdentifier
instances. The following common OIDs are available as constants.
- class cryptography.x509.oid.NameOID[source]
These OIDs are typically seen in X.509 names.
Added in version 1.0.
- COMMON_NAME
Corresponds to the dotted string
"2.5.4.3"
. Historically the domain name would be encoded here for server certificates. RFC 2818 deprecates this practice and names of that type should now be located in aSubjectAlternativeName
extension.
- COUNTRY_NAME
Corresponds to the dotted string
"2.5.4.6"
.
- LOCALITY_NAME
Corresponds to the dotted string
"2.5.4.7"
.
- STATE_OR_PROVINCE_NAME
Corresponds to the dotted string
"2.5.4.8"
.
- STREET_ADDRESS
Added in version 1.6.
Corresponds to the dotted string
"2.5.4.9"
.
- ORGANIZATION_IDENTIFIER
Added in version 42.0.0.
Corresponds to the dotted string
"2.5.4.97"
.
- ORGANIZATION_NAME
Corresponds to the dotted string
"2.5.4.10"
.
- ORGANIZATIONAL_UNIT_NAME
Corresponds to the dotted string
"2.5.4.11"
.
- SERIAL_NUMBER
Corresponds to the dotted string
"2.5.4.5"
. This is distinct from the serial number of the certificate itself (which can be obtained withserial_number
).
- SURNAME
Corresponds to the dotted string
"2.5.4.4"
.
- GIVEN_NAME
Corresponds to the dotted string
"2.5.4.42"
.
- TITLE
Corresponds to the dotted string
"2.5.4.12"
.
- INITIALS
Added in version 41.0.0.
Corresponds to the dotted string
"2.5.4.43"
.
- GENERATION_QUALIFIER
Corresponds to the dotted string
"2.5.4.44"
.
- X500_UNIQUE_IDENTIFIER
Added in version 1.6.
Corresponds to the dotted string
"2.5.4.45"
.
- DN_QUALIFIER
Corresponds to the dotted string
"2.5.4.46"
. This specifies disambiguating information to add to the relative distinguished name of an entry. See RFC 2256.
- PSEUDONYM
Corresponds to the dotted string
"2.5.4.65"
.
- USER_ID
Added in version 1.6.
Corresponds to the dotted string
"0.9.2342.19200300.100.1.1"
.
- DOMAIN_COMPONENT
Corresponds to the dotted string
"0.9.2342.19200300.100.1.25"
. A string holding one component of a domain name. See RFC 4519.
- EMAIL_ADDRESS
Corresponds to the dotted string
"1.2.840.113549.1.9.1"
.
- JURISDICTION_COUNTRY_NAME
Corresponds to the dotted string
"1.3.6.1.4.1.311.60.2.1.3"
.
- JURISDICTION_LOCALITY_NAME
Corresponds to the dotted string
"1.3.6.1.4.1.311.60.2.1.1"
.
- JURISDICTION_STATE_OR_PROVINCE_NAME
Corresponds to the dotted string
"1.3.6.1.4.1.311.60.2.1.2"
.
- BUSINESS_CATEGORY
Corresponds to the dotted string
"2.5.4.15"
.
- POSTAL_ADDRESS
Added in version 1.6.
Corresponds to the dotted string
"2.5.4.16"
.
- POSTAL_CODE
Added in version 1.6.
Corresponds to the dotted string
"2.5.4.17"
.
- UNSTRUCTURED_NAME
Added in version 3.0.
Corresponds to the dotted string
"1.2.840.113549.1.9.2"
.
- class cryptography.x509.oid.SignatureAlgorithmOID[source]
Added in version 1.0.
- RSA_WITH_MD5
Corresponds to the dotted string
"1.2.840.113549.1.1.4"
. This is an MD5 digest signed by an RSA key.
- RSA_WITH_SHA1
Corresponds to the dotted string
"1.2.840.113549.1.1.5"
. This is a SHA1 digest signed by an RSA key.
- RSA_WITH_SHA224
Corresponds to the dotted string
"1.2.840.113549.1.1.14"
. This is a SHA224 digest signed by an RSA key.
- RSA_WITH_SHA256
Corresponds to the dotted string
"1.2.840.113549.1.1.11"
. This is a SHA256 digest signed by an RSA key.
- RSA_WITH_SHA384
Corresponds to the dotted string
"1.2.840.113549.1.1.12"
. This is a SHA384 digest signed by an RSA key.
- RSA_WITH_SHA512
Corresponds to the dotted string
"1.2.840.113549.1.1.13"
. This is a SHA512 digest signed by an RSA key.
- RSA_WITH_SHA3_224
Corresponds to the dotted string
"2.16.840.1.101.3.4.3.13"
. This is a SHA3-224 digest signed by an RSA key.
- RSA_WITH_SHA3_256
Corresponds to the dotted string
"2.16.840.1.101.3.4.3.14"
. This is a SHA3-256 digest signed by an RSA key.
- RSA_WITH_SHA3_384
Corresponds to the dotted string
"2.16.840.1.101.3.4.3.15"
. This is a SHA3-384 digest signed by an RSA key.
- RSA_WITH_SHA3_512
Corresponds to the dotted string
"2.16.840.1.101.3.4.3.16"
. This is a SHA3-512 digest signed by an RSA key.
- RSASSA_PSS
Added in version 2.3.
Corresponds to the dotted string
"1.2.840.113549.1.1.10"
. This is signed by an RSA key using the Probabilistic Signature Scheme (PSS) padding from RFC 4055. The hash function and padding are defined by signature algorithm parameters.
- ECDSA_WITH_SHA1
Corresponds to the dotted string
"1.2.840.10045.4.1"
. This is a SHA1 digest signed by an ECDSA key.
- ECDSA_WITH_SHA224
Corresponds to the dotted string
"1.2.840.10045.4.3.1"
. This is a SHA224 digest signed by an ECDSA key.
- ECDSA_WITH_SHA256
Corresponds to the dotted string
"1.2.840.10045.4.3.2"
. This is a SHA256 digest signed by an ECDSA key.
- ECDSA_WITH_SHA384
Corresponds to the dotted string
"1.2.840.10045.4.3.3"
. This is a SHA384 digest signed by an ECDSA key.
- ECDSA_WITH_SHA512
Corresponds to the dotted string
"1.2.840.10045.4.3.4"
. This is a SHA512 digest signed by an ECDSA key.
- ECDSA_WITH_SHA3_224
Corresponds to the dotted string
"2.16.840.1.101.3.4.3.9"
. This is a SHA3-224 digest signed by an ECDSA key.
- ECDSA_WITH_SHA3_256
Corresponds to the dotted string
"2.16.840.1.101.3.4.3.10"
. This is a SHA3-256 digest signed by an ECDSA key.
- ECDSA_WITH_SHA3_384
Corresponds to the dotted string
"2.16.840.1.101.3.4.3.11"
. This is a SHA3-384 digest signed by an ECDSA key.
- ECDSA_WITH_SHA3_512
Corresponds to the dotted string
"2.16.840.1.101.3.4.3.12"
. This is a SHA3-512 digest signed by an ECDSA key.
- DSA_WITH_SHA1
Corresponds to the dotted string
"1.2.840.10040.4.3"
. This is a SHA1 digest signed by a DSA key.
- DSA_WITH_SHA224
Corresponds to the dotted string
"2.16.840.1.101.3.4.3.1"
. This is a SHA224 digest signed by a DSA key.
- DSA_WITH_SHA256
Corresponds to the dotted string
"2.16.840.1.101.3.4.3.2"
. This is a SHA256 digest signed by a DSA key.
- DSA_WITH_SHA384
Added in version 36.0.0.
Corresponds to the dotted string
"2.16.840.1.101.3.4.3.3"
. This is a SHA384 digest signed by a DSA key.
- DSA_WITH_SHA512
Added in version 36.0.0.
Corresponds to the dotted string
"2.16.840.1.101.3.4.3.4"
. This is a SHA512 digest signed by a DSA key.
- ED25519
Added in version 2.8.
Corresponds to the dotted string
"1.3.101.112"
. This is a signature using an ed25519 key.
- ED448
Added in version 2.8.
Corresponds to the dotted string
"1.3.101.113"
. This is a signature using an ed448 key.
- class cryptography.x509.oid.ExtendedKeyUsageOID[source]
Added in version 1.0.
- SERVER_AUTH
Corresponds to the dotted string
"1.3.6.1.5.5.7.3.1"
. This is used to denote that a certificate may be used for TLS web server authentication.
- CLIENT_AUTH
Corresponds to the dotted string
"1.3.6.1.5.5.7.3.2"
. This is used to denote that a certificate may be used for TLS web client authentication.
- CODE_SIGNING
Corresponds to the dotted string
"1.3.6.1.5.5.7.3.3"
. This is used to denote that a certificate may be used for code signing.
- EMAIL_PROTECTION
Corresponds to the dotted string
"1.3.6.1.5.5.7.3.4"
. This is used to denote that a certificate may be used for email protection.
- TIME_STAMPING
Corresponds to the dotted string
"1.3.6.1.5.5.7.3.8"
. This is used to denote that a certificate may be used for time stamping.
- OCSP_SIGNING
Corresponds to the dotted string
"1.3.6.1.5.5.7.3.9"
. This is used to denote that a certificate may be used for signing OCSP responses.
- ANY_EXTENDED_KEY_USAGE
Added in version 2.0.
Corresponds to the dotted string
"2.5.29.37.0"
. This is used to denote that a certificate may be used for _any_ purposes. However, RFC 5280 additionally notes that applications that require the presence of a particular purpose _MAY_ reject certificates that include theanyExtendedKeyUsage
OID but not the particular OID expected for the application. Therefore, the presence of this OID does not mean a given application will accept the certificate for all purposes.
- SMARTCARD_LOGON
Added in version 35.0.0.
Corresponds to the dotted string
"1.3.6.1.4.1.311.20.2.2"
. This is used to denote that a certificate may be used forPKINIT
access on Windows.
- KERBEROS_PKINIT_KDC
Added in version 35.0.0.
Corresponds to the dotted string
"1.3.6.1.5.2.3.5"
. This is used to denote that a certificate may be used as a Kerberos domain controller certificate authorizingPKINIT
access. For more information see RFC 4556.
- class cryptography.x509.oid.AuthorityInformationAccessOID[source]
Added in version 1.0.
- OCSP
Corresponds to the dotted string
"1.3.6.1.5.5.7.48.1"
. Used as the identifier for OCSP data inAccessDescription
objects.
- CA_ISSUERS
Corresponds to the dotted string
"1.3.6.1.5.5.7.48.2"
. Used as the identifier for CA issuer data inAccessDescription
objects.
- class cryptography.x509.oid.SubjectInformationAccessOID[source]
Added in version 3.0.
- CA_REPOSITORY
Corresponds to the dotted string
"1.3.6.1.5.5.7.48.5"
. Used as the identifier for CA repository data inAccessDescription
objects.
- class cryptography.x509.oid.CertificatePoliciesOID[source]
Added in version 1.0.
- CPS_QUALIFIER
Corresponds to the dotted string
"1.3.6.1.5.5.7.2.1"
.
- CPS_USER_NOTICE
Corresponds to the dotted string
"1.3.6.1.5.5.7.2.2"
.
- ANY_POLICY
Corresponds to the dotted string
"2.5.29.32.0"
.
- class cryptography.x509.oid.ExtensionOID[source]
Added in version 1.0.
- BASIC_CONSTRAINTS
Corresponds to the dotted string
"2.5.29.19"
. The identifier for theBasicConstraints
extension type.
- KEY_USAGE
Corresponds to the dotted string
"2.5.29.15"
. The identifier for theKeyUsage
extension type.
- SUBJECT_ALTERNATIVE_NAME
Corresponds to the dotted string
"2.5.29.17"
. The identifier for theSubjectAlternativeName
extension type.
- ISSUER_ALTERNATIVE_NAME
Corresponds to the dotted string
"2.5.29.18"
. The identifier for theIssuerAlternativeName
extension type.
- SUBJECT_KEY_IDENTIFIER
Corresponds to the dotted string
"2.5.29.14"
. The identifier for theSubjectKeyIdentifier
extension type.
- NAME_CONSTRAINTS
Corresponds to the dotted string
"2.5.29.30"
. The identifier for theNameConstraints
extension type.
- CRL_DISTRIBUTION_POINTS
Corresponds to the dotted string
"2.5.29.31"
. The identifier for theCRLDistributionPoints
extension type.
- CERTIFICATE_POLICIES
Corresponds to the dotted string
"2.5.29.32"
. The identifier for theCertificatePolicies
extension type.
- AUTHORITY_KEY_IDENTIFIER
Corresponds to the dotted string
"2.5.29.35"
. The identifier for theAuthorityKeyIdentifier
extension type.
- EXTENDED_KEY_USAGE
Corresponds to the dotted string
"2.5.29.37"
. The identifier for theExtendedKeyUsage
extension type.
- AUTHORITY_INFORMATION_ACCESS
Corresponds to the dotted string
"1.3.6.1.5.5.7.1.1"
. The identifier for theAuthorityInformationAccess
extension type.
- SUBJECT_INFORMATION_ACCESS
Added in version 3.0.
Corresponds to the dotted string
"1.3.6.1.5.5.7.1.11"
. The identifier for theSubjectInformationAccess
extension type.
- INHIBIT_ANY_POLICY
Corresponds to the dotted string
"2.5.29.54"
. The identifier for theInhibitAnyPolicy
extension type.
- OCSP_NO_CHECK
Corresponds to the dotted string
"1.3.6.1.5.5.7.48.1.5"
. The identifier for theOCSPNoCheck
extension type.
- TLS_FEATURE
Corresponds to the dotted string
"1.3.6.1.5.5.7.1.24"
. The identifier for theTLSFeature
extension type.
- CRL_NUMBER
Corresponds to the dotted string
"2.5.29.20"
. The identifier for theCRLNumber
extension type. This extension only has meaning for certificate revocation lists.
- DELTA_CRL_INDICATOR
Added in version 2.1.
Corresponds to the dotted string
"2.5.29.27"
. The identifier for theDeltaCRLIndicator
extension type. This extension only has meaning for certificate revocation lists.
- PRECERT_SIGNED_CERTIFICATE_TIMESTAMPS
Added in version 1.9.
Corresponds to the dotted string
"1.3.6.1.4.1.11129.2.4.2"
.
- PRECERT_POISON
Added in version 2.4.
Corresponds to the dotted string
"1.3.6.1.4.1.11129.2.4.3"
.
- SIGNED_CERTIFICATE_TIMESTAMPS
Added in version 3.0.
Corresponds to the dotted string
"1.3.6.1.4.1.11129.2.4.5"
.
- POLICY_CONSTRAINTS
Corresponds to the dotted string
"2.5.29.36"
. The identifier for thePolicyConstraints
extension type.
- FRESHEST_CRL
Corresponds to the dotted string
"2.5.29.46"
. The identifier for theFreshestCRL
extension type.
- ISSUING_DISTRIBUTION_POINT
Added in version 2.4.
Corresponds to the dotted string
"2.5.29.28"
.
- POLICY_MAPPINGS
Corresponds to the dotted string
"2.5.29.33"
.
- SUBJECT_DIRECTORY_ATTRIBUTES
Corresponds to the dotted string
"2.5.29.9"
.
- MS_CERTIFICATE_TEMPLATE
Added in version 41.0.0.
Corresponds to the dotted string
"1.3.6.1.4.1.311.21.7"
.
- ADMISSIONS
Added in version 44.0.0.
Corresponds to the dotted string
"1.3.36.8.3.3"
.
- class cryptography.x509.oid.CRLEntryExtensionOID[source]
Added in version 1.2.
- CERTIFICATE_ISSUER
Corresponds to the dotted string
"2.5.29.29"
.
- CRL_REASON
Corresponds to the dotted string
"2.5.29.21"
.
- INVALIDITY_DATE
Corresponds to the dotted string
"2.5.29.24"
.
- class cryptography.x509.oid.OCSPExtensionOID[source]
Added in version 2.4.
- NONCE
Corresponds to the dotted string
"1.3.6.1.5.5.7.48.1.2"
.
- ACCEPTABLE_RESPONSES
Added in version 41.0.0.
Corresponds to the dotted string
"1.3.6.1.5.5.7.48.1.4"
.
- class cryptography.x509.oid.AttributeOID[source]
Added in version 3.0.
- CHALLENGE_PASSWORD
Corresponds to the dotted string
"1.2.840.113549.1.9.7"
.
- UNSTRUCTURED_NAME
Corresponds to the dotted string
"1.2.840.113549.1.9.2"
.
- class cryptography.x509.oid.PublicKeyAlgorithmOID[source]
Added in version 43.0.0.
- DSA
Corresponds to the dotted string
"1.2.840.10040.4.1"
. This is aDSAPublicKey
public key.
- EC_PUBLIC_KEY
Corresponds to the dotted string
"1.2.840.10045.2.1"
. This is aEllipticCurvePublicKey
public key.
- RSAES_PKCS1_v1_5
Corresponds to the dotted string
"1.2.840.113549.1.1.1"
. This is aRSAPublicKey
public key withPKCS1v15
padding.
- RSASSA_PSS
Corresponds to the dotted string
"1.2.840.113549.1.1.10"
. This is aRSAPublicKey
public key withPSS
padding.
- X25519
Corresponds to the dotted string
"1.3.101.110"
. This is aX25519PublicKey
public key.
- X448
Corresponds to the dotted string
"1.3.101.111"
. This is aX448PublicKey
public key.
- ED25519
Corresponds to the dotted string
"1.3.101.112"
. This is aEd25519PublicKey
public key.
- ED448
Corresponds to the dotted string
"1.3.101.113"
. This is aEd448PublicKey
public key.
Helper Functions
Exceptions
- class cryptography.x509.InvalidVersion[source]
This is raised when an X.509 certificate has an invalid version number.
- class cryptography.x509.DuplicateExtension[source]
This is raised when more than one X.509 extension of the same type is found within a certificate.
- oid
- Type:
Returns the OID.
- class cryptography.x509.ExtensionNotFound[source]
This is raised when calling
Extensions.get_extension_for_oid()
with an extension OID that is not present in the certificate.- oid
- Type:
Returns the OID.
- class cryptography.x509.AttributeNotFound[source]
This is raised when calling
Attributes.get_attribute_for_oid()
with an attribute OID that is not present in the request.- oid
- Type:
Returns the OID.
- class cryptography.x509.UnsupportedGeneralNameType[source]
This is raised when a certificate contains an unsupported general name type in an extension.
- type
- Type:
The integer value of the unsupported type. The complete list of types can be found in RFC 5280 Section 4.2.1.6.