Reputation: 979
Using below code snippet I am able to get CRL object from a CRL certificate:
import OpenSSL
with open('/Users/goutamdas/Desktop/Certificate/My_Certs/crl_ocsp.pem', 'r') as _crl_file:
crl = "".join(_crl_file.readlines())
print(crl)
crl_object = OpenSSL.crypto.load_crl(OpenSSL.crypto.FILETYPE_PEM, crl)
print("obj: ", crl_object)
Now I want to parse the below 2 dates from this CRL file, and looks like OpenSSL don't provide any relative method to extract. Any suggestion how I can do this.
Last Update: Sep 17 18:01:34 2018 GMT
Next Update: Oct 17 18:01:34 2018 GMT
Upvotes: 1
Views: 1152
Reputation: 17383
The classes exposed via pyopenssl
are limited, you are often better off switching to the more powerful classes from the cryptography
module, which is used under the hood. For example, for CRLs, you can get access to the class cryptography.x509.CertificateRevocationList
, via the to_cryptography()
method documented here. It exposes the attributes you are looking for. Continuing with what you did:
ccrl_object = crl_object.to_cryptography()
print(ccrl_object.last_update)
print(ccrl_object.next_update)
yields something along the lines of
2005-02-06 12:00:00
2005-02-05 12:00:00
Upvotes: 1