Search code examples
pythoncryptographypython-cryptography

Obtain int CRL Number from CRL using Cryptography Library


I'm playing around with the cryptography library in Python and I have a CRL object. Here is the setup:

from cryptography import x509
from cryptography.hazmat.backends import default_backend
from cryptography.x509.oid import ExtensionOID, NameOID, AuthorityInformationAccessOID

# Need to set default backend for cryptography as our version is low:
default_backend = default_backend()

crl_file = path_to/some_crl_file.crl

crl = x509.load_pem_x509_crl(crl_file, default_backend)
print(crl.extensions)

I receive the following output of extensions:

<Extensions([<Extension(oid=<ObjectIdentifier(oid=2.5.29.20, name=cRLNumber)>, critical=False, value=<CRLNumber(17)>)>, <Extension(oid=<ObjectIdentifier(oid=2.5.29.35, name=authorityKeyIdentifier)>, critical=False, value=<AuthorityKeyIdentifier(key_identifier=b"\xe4\xaf+&q\x1a+H'\x85/Rf,\xef\xf0\x89\x13q>", authority_cert_issuer=None, authority_cert_serial_number=None)>)>])>

I then get the CRL Number with the following:

print(crl.extensions.get_extension_for_oid(ExtensionOID.CRL_NUMBER).value)

This outputs <CRLNumber(17)>. How do I get it so that I receive the int value of 17 from this?


Solution

  • I swear someone answered this and I responded, but maybe I dreamed it up.

    Anywho. I took another look into this and resolved it with the following:

    print(crl.extensions.get_extension_for_oid(ExtensionOID.CRL_NUMBER).value.crl_number)

    I needed to add the .crl_number at the end of value.