Skip to content

Commit a0fdbba

Browse files
Speed up happy path for cert issuer CRL extn
This is another dramatic improvement in processing time for large CRLs. Speedups of about 2.5x measured.
1 parent d6550e4 commit a0fdbba

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

pyhanko_certvalidator/revinfo/validate_crl.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from typing import Dict, List, Optional, Set, Tuple, Union
77

88
from asn1crypto import cms, crl, x509
9+
from asn1crypto.crl import CRLEntryExtensionId
910
from cryptography.exceptions import InvalidSignature
1011

1112
from pyhanko_certvalidator._state import ValProcState
@@ -1387,9 +1388,20 @@ def find_cert_in_list(
13871388
cert_serial = cert['ac_info']['serial_number'].dump()
13881389

13891390
last_issuer_name = crl_authority_name
1391+
1392+
cert_issuer_extension_id = CRLEntryExtensionId('certificate_issuer').dump()
1393+
13901394
for revoked_cert in revoked_certificates:
1391-
if revoked_cert.issuer_name:
1392-
last_issuer_name = revoked_cert.issuer_name
1395+
# This looks like a hack, but we have to look up the certificate_issuer
1396+
# extension for every entry, since its value remains in effect for
1397+
# future entries as well! (and PKITS has a test case for that...)
1398+
# Since parsing those extensions every time is expensive for large CRLs,
1399+
# we guard it with a dumb heuristic check: does the binary encoding
1400+
# of that extension's OID appear anywhere in the entry's payload?
1401+
# If not, we move on. If it does appear, we parse the extensions.
1402+
if cert_issuer_extension_id in revoked_cert.dump():
1403+
if revoked_cert.issuer_name:
1404+
last_issuer_name = revoked_cert.issuer_name
13931405
if revoked_cert['user_certificate'].dump() != cert_serial:
13941406
continue
13951407
if last_issuer_name != cert_issuer_name:

0 commit comments

Comments
 (0)