import os import asn1crypto.core from asn1crypto import crl from asn1crypto.crl import TbsCertList, CertificateList def fix_certificate_list(in_list): ''' some certificate lists take a long time to dump(), but this appears to fix the problem ''' tbslist = TbsCertList() if not isinstance(in_list['tbs_cert_list']['version'], asn1crypto.core.Void): tbslist['version'] = in_list['tbs_cert_list']['version'] tbslist['signature'] = in_list['tbs_cert_list']['signature'] tbslist['issuer'] = in_list['tbs_cert_list']['issuer'] tbslist['this_update'] = in_list['tbs_cert_list']['this_update'] if not isinstance(in_list['tbs_cert_list']['next_update'], asn1crypto.core.Void): tbslist['next_update'] = in_list['tbs_cert_list']['next_update'] if not isinstance(in_list['tbs_cert_list']['revoked_certificates'], asn1crypto.core.Void): tbslist['revoked_certificates'] = in_list['tbs_cert_list']['revoked_certificates'] if not isinstance(in_list['tbs_cert_list']['crl_extensions'], asn1crypto.core.Void): tbslist['crl_extensions'] = in_list['tbs_cert_list']['crl_extensions'] outlist = CertificateList() outlist['tbs_cert_list'] = tbslist outlist['signature_algorithm'] = in_list['signature_algorithm'] outlist['signature'] = in_list['signature'] return outlist print("load") certificate_list = None with open('source.crl', 'rb') as f: slow_list = crl.CertificateList.load(f.read()) fast_list = fix_certificate_list(slow_list) print("dump fast_list") print(len(fast_list['tbs_cert_list'].dump())) print("done") print("dump slow_list") print(len(slow_list['tbs_cert_list'].dump())) print("done")