micro509 0.18.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/CHANGELOG.md +88 -1
  2. package/dist/crypto/crypto.d.ts +11 -2
  3. package/dist/crypto/crypto.js +30 -17
  4. package/dist/crypto/crypto.js.map +1 -1
  5. package/dist/crypto.d.ts +2 -2
  6. package/dist/der/der.js.map +1 -1
  7. package/dist/index.d.ts +6 -5
  8. package/dist/internal/asn1/asn1.js +10 -2
  9. package/dist/internal/asn1/asn1.js.map +1 -1
  10. package/dist/internal/asn1/ber.js.map +1 -1
  11. package/dist/internal/asn1/decode-refusal.js.map +1 -1
  12. package/dist/internal/asn1/der.js.map +1 -1
  13. package/dist/internal/asn1/oids.js.map +1 -1
  14. package/dist/internal/crypto/algorithm-names.js.map +1 -1
  15. package/dist/internal/crypto/ecdsa.js.map +1 -1
  16. package/dist/internal/crypto/hash.js.map +1 -1
  17. package/dist/internal/crypto/pbes2.js.map +1 -1
  18. package/dist/internal/crypto/prime-ec.js.map +1 -1
  19. package/dist/internal/crypto/rsa-pss.js.map +1 -1
  20. package/dist/internal/crypto/sig-verify.d.ts +40 -0
  21. package/dist/internal/crypto/sig-verify.js +152 -65
  22. package/dist/internal/crypto/sig-verify.js.map +1 -1
  23. package/dist/internal/crypto/signing.js.map +1 -1
  24. package/dist/internal/jose/base64url.js.map +1 -1
  25. package/dist/internal/jose/json-data.js.map +1 -1
  26. package/dist/internal/jose/strict-json.js.map +1 -1
  27. package/dist/internal/shared/base64.js.map +1 -1
  28. package/dist/internal/shared/dn.js.map +1 -1
  29. package/dist/internal/shared/idna.js.map +1 -1
  30. package/dist/internal/shared/ip.js.map +1 -1
  31. package/dist/internal/shared/mailbox.js.map +1 -1
  32. package/dist/internal/shared/punycode.js.map +1 -1
  33. package/dist/internal/shared/uri-host.js.map +1 -1
  34. package/dist/internal/verify/name-constraints-engine.js.map +1 -1
  35. package/dist/internal/verify/policy-engine.js.map +1 -1
  36. package/dist/internal/verify/spki-distrust.js.map +1 -1
  37. package/dist/internal/verify/verify-path.js +222 -116
  38. package/dist/internal/verify/verify-path.js.map +1 -1
  39. package/dist/internal/x509/directory-name.js.map +1 -1
  40. package/dist/internal/x509/extension-bits.js.map +1 -1
  41. package/dist/internal/x509/extension-errors.js.map +1 -1
  42. package/dist/internal/x509/extension-registry.js.map +1 -1
  43. package/dist/internal/x509/general-name-profile.js.map +1 -1
  44. package/dist/internal/x509/general-name.js.map +1 -1
  45. package/dist/internal/x509/name-fields.js.map +1 -1
  46. package/dist/internal/x509/or-address.js.map +1 -1
  47. package/dist/jose/base64url.js.map +1 -1
  48. package/dist/jose/errors.js.map +1 -1
  49. package/dist/jose/jwe.js.map +1 -1
  50. package/dist/jose/jwks.js.map +1 -1
  51. package/dist/jose/jws.js.map +1 -1
  52. package/dist/jose/jwt.js.map +1 -1
  53. package/dist/jose/remote-jwks.js.map +1 -1
  54. package/dist/kdf/argon2-arithmetic.js.map +1 -1
  55. package/dist/kdf/argon2-core.js.map +1 -1
  56. package/dist/kdf/argon2-memory.js.map +1 -1
  57. package/dist/kdf/argon2-portable.js.map +1 -1
  58. package/dist/kdf/argon2.js.map +1 -1
  59. package/dist/keys/keys.js.map +1 -1
  60. package/dist/pem/pem.js.map +1 -1
  61. package/dist/pkcs/pfx.js.map +1 -1
  62. package/dist/pkcs/pkcs12-mac.js +1 -1
  63. package/dist/pkcs/pkcs12-mac.js.map +1 -1
  64. package/dist/pkcs/pkcs7.d.ts +10 -0
  65. package/dist/pkcs/pkcs7.js +106 -88
  66. package/dist/pkcs/pkcs7.js.map +1 -1
  67. package/dist/result/result.js.map +1 -1
  68. package/dist/revocation/chain.d.ts +67 -13
  69. package/dist/revocation/chain.js +429 -301
  70. package/dist/revocation/chain.js.map +1 -1
  71. package/dist/revocation/crl.d.ts +65 -11
  72. package/dist/revocation/crl.js +492 -202
  73. package/dist/revocation/crl.js.map +1 -1
  74. package/dist/revocation/ocsp.d.ts +79 -24
  75. package/dist/revocation/ocsp.js +417 -231
  76. package/dist/revocation/ocsp.js.map +1 -1
  77. package/dist/revocation/revocation.d.ts +68 -13
  78. package/dist/revocation/revocation.js +194 -73
  79. package/dist/revocation/revocation.js.map +1 -1
  80. package/dist/revocation.d.ts +4 -4
  81. package/dist/ssh/ssh.js.map +1 -1
  82. package/dist/ssh/wire.js.map +1 -1
  83. package/dist/verify/identity.d.ts +2 -2
  84. package/dist/verify/identity.js +2 -2
  85. package/dist/verify/identity.js.map +1 -1
  86. package/dist/verify/verify.d.ts +84 -32
  87. package/dist/verify/verify.js +221 -171
  88. package/dist/verify/verify.js.map +1 -1
  89. package/dist/verify.d.ts +3 -2
  90. package/dist/x509/certificate.js.map +1 -1
  91. package/dist/x509/csr.js.map +1 -1
  92. package/dist/x509/extensions.js.map +1 -1
  93. package/dist/x509/fingerprint.js.map +1 -1
  94. package/dist/x509/name-text.js.map +1 -1
  95. package/dist/x509/name.js.map +1 -1
  96. package/dist/x509/parse.d.ts +6 -2
  97. package/dist/x509/parse.js +121 -121
  98. package/dist/x509/parse.js.map +1 -1
  99. package/package.json +11 -11
@@ -1 +1 @@
1
- {"version":3,"file":"chain.js","names":["_exhaustive","REVOCATION_INDETERMINATE_REASONS","parseCertificateFromSource","source","a","b","i","parsedExtras","extraCertificates","parsed","candidates","chain","matches","existing","candidate","crl","value","c","signer","trustAnchor","pool","index","certificate","verifyCertificateChain","cert","key","cached","ctx","signerIssuer","signerRevocation","issuerInChain","issuer","coveredReasons","sawUnrecognizedReason","crlSource","outcome","reason","coversAllDistributionPointReasons","SIGNER_CRL_NO_EVIDENCE","normalizeCrl","result","checkCertificateRevocationAgainstCrl","reasonCode","parseOcspResponsePemOrThrow","parseOcspResponseDerOrThrow","decodeRefusalOf","error","DECODE_REFUSAL_CODES","fallbackMessage","entry","single","current","revocationReasonFromCode","unrecognizedReasonCode","status","freshestGoodThisUpdate","reasons","code","OCSP_RESPONDER_FAILURE_CODES","trustedOcspResponders","input","trustedIssuer","trusted","shared","primary","validateOcspResponse","responder","retry","executionErrors","state","ocspResponses","applicable","validation","at","evidence","freshestHold","params","baseBudget","DELTA_CRL_ATTEMPTS_PER_BASE","baseCrl","resolved","deltaBudget","signerStatus","signerCtx","checked","crlThisUpdate","parsedCrls","crls","baseCrls","isCrlApplicableTo","deltaCrls","crlMaxAgeMs","clockSkewMs","revoked","blockingReasons","seen","toHex","baseCrlNumber","deltaCrl","isCurrentDeltaCrl","left","right","authenticated","authenticateCrl","deltaCandidates","settled","budgets","checkRevocationAgainstAuthenticatedCrl","alone","complete","budget","candidateTime","currentTime","indirect","thisUpdate","GOOD_BLOCKING_REASONS","prefer","ocsp","ordered","evaluation","good","blocked","signed","parseCertificateDer","carriesOcspNoCheck","policy","mode","certsToCheck","certificates","revokedCertificates","indeterminateCertificates","allExecutionErrors","skipReason","hasRevoked","hasIndeterminate"],"sources":["../../src/revocation/chain.ts"],"sourcesContent":["/**\n * Chain-level revocation orchestration.\n *\n * Evaluates CRL and OCSP evidence for an entire validated certificate chain,\n * implementing the revocation checking portion of RFC 5280 §6.3.\n *\n * @see {@link https://datatracker.ietf.org/doc/html/rfc5280#section-6.3 | RFC 5280 §6.3 CRL Validation}\n * @module\n */\n\nimport { toHex } from '#micro509/internal/asn1/asn1';\nimport { DECODE_REFUSAL_CODES, decodeRefusalOf } from '#micro509/internal/asn1/decode-refusal';\nimport type { DecodeFailureCode } from '#micro509/result/result';\nimport type {\n\tAuthenticatedCrlCheckOutcome,\n\tCrlSource,\n\tParsedCertificateRevocationList,\n\tParsedRevocationReason,\n\tUnrecognizedReasonCodePolicy,\n} from '#micro509/revocation/crl';\nimport {\n\tassertCrlMaxAge,\n\tauthenticateCrl,\n\tcheckCertificateRevocationAgainstCrl,\n\tcheckRevocationAgainstAuthenticatedCrl,\n\tcoversAllDistributionPointReasons,\n\tisCrlApplicableTo,\n\tisCurrentDeltaCrl,\n\tnormalizeCrl,\n\trevocationReasonFromCode,\n} from '#micro509/revocation/crl';\nimport type {\n\tOcspResponderRevocationPolicy,\n\tParsedOcspResponse,\n\tParsedOcspSingleResponse,\n\tValidateOcspResponseFailure,\n\tValidateOcspResponseInput,\n\tValidateOcspResponseResult,\n} from '#micro509/revocation/ocsp';\nimport {\n\tcarriesOcspNoCheck,\n\tparseOcspResponseDerOrThrow,\n\tparseOcspResponsePemOrThrow,\n\tvalidateOcspResponse,\n} from '#micro509/revocation/ocsp';\nimport type { RevocationCertificateSource } from '#micro509/revocation/revocation';\nimport { verifyCertificateChain } from '#micro509/verify/verify';\nimport type { DistributionPointReason } from '#micro509/x509/extensions';\nimport type { ParsedCertificate } from '#micro509/x509/parse';\nimport { parseCertificateDer, parseCertificateFromSource } from '#micro509/x509/parse';\n\nexport type { CrlSource };\n\n// Input Types\n\n/**\n * OCSP response in any supported format.\n *\n * Accepts PEM string or DER bytes. Used for\n * {@linkcode CheckChainRevocationInput.ocspResponses}.\n */\nexport type OcspResponseSource = string | Uint8Array;\n\n/** A locally trusted OCSP responder bound to the CA scope it may serve. */\nexport interface TrustedOcspResponder {\n\t/** Certificate of the CA for whose certificates the responder is trusted. */\n\treadonly issuerCertificate: RevocationCertificateSource;\n\t/** Responder certificate trusted within that issuer's scope. */\n\treadonly responderCertificate: RevocationCertificateSource;\n}\n\n/**\n * Revocation checking policy for {@linkcode checkChainRevocation}.\n *\n * Controls how indeterminate results (missing evidence, expired CRLs) affect\n * the final {@linkcode CheckChainRevocationValue.decision | decision}.\n */\nexport interface RevocationPolicy {\n\t/**\n\t * How to handle indeterminate status.\n\t *\n\t * - `'hard-fail'`: indeterminate certificates cause denial (default)\n\t * - `'soft-fail'`: indeterminate certificates are allowed — an explicit\n\t * availability/compatibility choice\n\t *\n\t * Revocation checking itself is opt-in: no check runs unless evidence is\n\t * supplied. Once it is, indeterminate status denies by default.\n\t */\n\treadonly mode?: 'soft-fail' | 'hard-fail';\n\t/**\n\t * Evidence preference when multiple sources are available.\n\t *\n\t * Both evidence kinds are always evaluated, and a validated `revoked`\n\t * verdict from either source wins regardless of preference (fail-closed).\n\t * Preference only decides which source's `good` verdict is reported when\n\t * both yield one.\n\t *\n\t * - `'best-available'`: the source with the fresher evidence — the later\n\t * `thisUpdate` on the validated OCSP entry or CRL — is reported; ties\n\t * favor OCSP (default)\n\t * - `'ocsp'`: prefer OCSP over CRL\n\t * - `'crl'`: prefer CRL over OCSP\n\t */\n\treadonly prefer?: 'ocsp' | 'crl' | 'best-available';\n\t/**\n\t * Revocation policy for delegated OCSP responder certificates\n\t * (RFC 6960 §4.2.2.2.1). Supplied CRLs double as responder revocation\n\t * evidence. Defaults to `'honor-nocheck'`.\n\t */\n\treadonly ocspResponderRevocation?: OcspResponderRevocationPolicy;\n\t/**\n\t * Maximum age of a CRL's `thisUpdate` at the evaluation time, in\n\t * milliseconds. An older CRL yields no evidence even when it carries no\n\t * `nextUpdate`. Applies to CRLs for chain certificates, CRL signers and\n\t * delegated OCSP responders. Unbounded by default, in which case a CRL\n\t * without `nextUpdate` yields no evidence. RFC 5280 §3.3 leaves the\n\t * required recency of revocation data to local policy.\n\t */\n\treadonly crlMaxAgeMs?: number;\n\t/**\n\t * Clock-skew tolerance in milliseconds for CRL and OCSP `thisUpdate`/\n\t * `nextUpdate` checks. It also widens `crlMaxAgeMs` by the same amount.\n\t * Defaults to `0`.\n\t */\n\treadonly clockSkewMs?: number;\n\t/**\n\t * OCSP client profile for every OCSP response. See\n\t * {@linkcode ValidateOcspResponseInput.profile}. `'rfc9919'` turns a\n\t * response without `nextUpdate` into `ocsp_next_update_missing`. Defaults\n\t * to `'rfc6960'`.\n\t */\n\treadonly ocspProfile?: ValidateOcspResponseInput['profile'];\n\t/**\n\t * Treatment of CRL entries and OCSP responses whose CRLReason is\n\t * unrecognized, including the CRLs for CRL signers and delegated OCSP\n\t * responders. See {@linkcode UnrecognizedReasonCodePolicy}. `'reject'`\n\t * makes that evidence yield `crl_reason_code_unrecognized` or\n\t * `ocsp_reason_code_unrecognized`, which outranks a `good` verdict from\n\t * other evidence. Defaults to `'revoked'`.\n\t */\n\treadonly unrecognizedReasonCode?: UnrecognizedReasonCodePolicy;\n}\n\n/** Input for {@linkcode checkChainRevocation}. */\nexport interface CheckChainRevocationInput {\n\t/** Validated certificate chain (leaf first, root last). */\n\treadonly chain: readonly ParsedCertificate[];\n\t/** CRLs to evaluate. */\n\treadonly crls?: readonly CrlSource[];\n\t/** OCSP responses to evaluate. */\n\treadonly ocspResponses?: readonly OcspResponseSource[];\n\t/** Extra certs for indirect CRL issuers / delegated OCSP responders. */\n\treadonly extraCertificates?: readonly RevocationCertificateSource[];\n\t/**\n\t * Explicitly trusted OCSP responder certificates (RFC 6960 §4.2.2.2\n\t * criterion 1), each bound to the issuing CA for which it is authorized.\n\t * A response signed by a matching responder is accepted without delegated-\n\t * responder issuance, EKU, and revocation checks only in that issuer scope.\n\t */\n\treadonly trustedOcspResponders?: readonly TrustedOcspResponder[];\n\t/** Evaluation time. Defaults to `new Date()`. */\n\treadonly at?: Date;\n\t/** Revocation policy. */\n\treadonly policy?: RevocationPolicy;\n}\n\n// Output Types\n\n/**\n * Granular reasons why revocation status could not be determined.\n *\n * Returned in {@linkcode CertificateRevocationStatus}'s `indeterminateReasons`\n * when `status` is `'indeterminate'`. Grouped by category:\n *\n * - **Evidence not found**: `no_applicable_crl`, `no_applicable_ocsp`\n * - **Scope mismatch**: `distribution_point_mismatch`, `issuer_name_mismatch`,\n * `reason_scope_mismatch`, `indirect_crl_scope_mismatch`, `reason_coverage_incomplete`\n * - **Signer trust**: `crl_signer_not_found`, `crl_signer_not_authorized`,\n * `crl_signer_revoked`, `crl_signer_indeterminate`, and OCSP equivalents\n * - **Freshness**: `crl_expired`, `ocsp_response_expired`,\n * `ocsp_next_update_missing`\n * - **Delta CRL**: `delta_crl_unusable` when an authenticated, current delta\n * CRL cannot settle the status, `delta_crl_retry_limit_exceeded` when delta\n * CRL candidates remain after the attempt limit. Either one outranks a\n * `good` verdict from other evidence.\n * - **Reason code**: `crl_reason_code_unrecognized` and\n * `ocsp_reason_code_unrecognized` when evidence revokes the certificate with\n * an unrecognized CRLReason under `unrecognizedReasonCode: 'reject'`. Either\n * one outranks a `good` verdict from other evidence.\n */\nexport const REVOCATION_INDETERMINATE_REASONS = [\n\t// Evidence not found\n\t'no_applicable_crl',\n\t'no_applicable_ocsp',\n\t// Scope issues\n\t'distribution_point_mismatch',\n\t'issuer_name_mismatch',\n\t'reason_scope_mismatch',\n\t'indirect_crl_scope_mismatch',\n\t'reason_coverage_incomplete',\n\t// Signer trust issues\n\t'crl_signer_not_found',\n\t'crl_signer_not_authorized',\n\t'crl_signer_revoked',\n\t'crl_signer_indeterminate',\n\t'ocsp_responder_not_found',\n\t'ocsp_responder_not_authorized',\n\t'ocsp_responder_revoked',\n\t'ocsp_responder_indeterminate',\n\t// Freshness\n\t'crl_expired',\n\t'ocsp_response_expired',\n\t'ocsp_next_update_missing',\n\t// OCSP specific\n\t'ocsp_status_unknown',\n\t// Delta CRL\n\t'delta_crl_unusable',\n\t'delta_crl_retry_limit_exceeded',\n\t// Reason code\n\t'crl_reason_code_unrecognized',\n\t'ocsp_reason_code_unrecognized',\n] as const;\n\n/** See the doc comment above {@linkcode REVOCATION_INDETERMINATE_REASONS}. */\nexport type RevocationIndeterminateReason = (typeof REVOCATION_INDETERMINATE_REASONS)[number];\n\n/**\n * Identifies the source of revocation evidence.\n *\n * Included in {@linkcode CertificateRevocationStatus}'s `source` when status is\n * `'good'` or `'revoked'` to indicate which CRL or OCSP response provided the answer.\n */\nexport interface RevocationSource {\n\t/** Whether evidence came from a CRL or OCSP response. */\n\treadonly kind: 'crl' | 'ocsp';\n\t/** Certificate that signed the evidence (CRL issuer or OCSP responder). */\n\treadonly signerCertificate?: ParsedCertificate;\n\t/** Identifier for debugging (e.g., CRL issuer DN or OCSP responder URL). */\n\treadonly evidenceIdentifier?: string;\n\t/**\n\t * `thisUpdate` of the evidence backing the verdict — the OCSP single\n\t * response entry or the freshest contributing CRL (an applied delta CRL\n\t * supersedes its base). This is the timestamp `'best-available'` compares.\n\t */\n\treadonly thisUpdate?: Date;\n}\n\n/**\n * Revocation evaluation result for a single certificate.\n *\n * One entry per certificate in {@linkcode CheckChainRevocationValue.certificates}.\n * The trust anchor is excluded (never checked for revocation).\n */\nexport type CertificateRevocationStatus =\n\t| {\n\t\t\t/** The certificate that was evaluated. */\n\t\t\treadonly certificate: ParsedCertificate;\n\t\t\t/** Evidence confirms the certificate is not revoked. */\n\t\t\treadonly status: 'good';\n\t\t\t/** Evidence that produced the verdict. */\n\t\t\treadonly source: RevocationSource;\n\t\t\t/** Never present on a `good` verdict. */\n\t\t\treadonly indeterminateReasons?: undefined;\n\t\t\t/** Never present on a `good` verdict. */\n\t\t\treadonly revocationInfo?: undefined;\n\t }\n\t| {\n\t\t\t/** The certificate that was evaluated. */\n\t\t\treadonly certificate: ParsedCertificate;\n\t\t\t/** Evidence confirms the certificate is revoked. */\n\t\t\treadonly status: 'revoked';\n\t\t\t/** Evidence that produced the verdict. */\n\t\t\treadonly source: RevocationSource;\n\t\t\t/** Revocation details from the CRL entry or OCSP response. */\n\t\t\treadonly revocationInfo: {\n\t\t\t\t/** When the certificate was revoked. */\n\t\t\t\treadonly revocationDate: Date;\n\t\t\t\t/** RFC 5280 CRLReason code, if provided by the CRL/OCSP response. */\n\t\t\t\treadonly reason?: ParsedRevocationReason;\n\t\t\t};\n\t\t\t/** Never present on a `revoked` verdict. */\n\t\t\treadonly indeterminateReasons?: undefined;\n\t }\n\t| {\n\t\t\t/** The certificate that was evaluated. */\n\t\t\treadonly certificate: ParsedCertificate;\n\t\t\t/** Revocation status could not be determined. */\n\t\t\treadonly status: 'indeterminate';\n\t\t\t/** Why status could not be determined. */\n\t\t\treadonly indeterminateReasons: readonly RevocationIndeterminateReason[];\n\t\t\t/** Never present on an `indeterminate` verdict. */\n\t\t\treadonly source?: undefined;\n\t\t\t/** Never present on an `indeterminate` verdict. */\n\t\t\treadonly revocationInfo?: undefined;\n\t }\n\t| {\n\t\t\t/** The certificate that was evaluated. */\n\t\t\treadonly certificate: ParsedCertificate;\n\t\t\t/** Revocation checking does not apply to the certificate (RFC 9608 §4). */\n\t\t\treadonly status: 'skipped';\n\t\t\t/**\n\t\t\t * The extension that exempts the certificate: `'no_rev_avail'` for\n\t\t\t * noRevAvail (RFC 9608 §2) or `'ocsp_nocheck'` for id-pkix-ocsp-nocheck.\n\t\t\t */\n\t\t\treadonly skipReason: 'no_rev_avail' | 'ocsp_nocheck';\n\t\t\t/** Never present on a `skipped` verdict. */\n\t\t\treadonly source?: undefined;\n\t\t\t/** Never present on a `skipped` verdict. */\n\t\t\treadonly indeterminateReasons?: undefined;\n\t\t\t/** Never present on a `skipped` verdict. */\n\t\t\treadonly revocationInfo?: undefined;\n\t };\n\n/**\n * Errors encountered while processing revocation evidence.\n *\n * Distinct from {@linkcode RevocationIndeterminateReason}: execution errors are\n * code failures (malformed CRL, unsupported extension) rather than evaluation\n * outcomes (CRL doesn't cover this certificate).\n *\n * Collected in {@linkcode CheckChainRevocationValue.executionErrors}.\n */\nexport type RevocationExecutionError = RevocationParseError | RevocationProcessingError;\n\n/** Revocation evidence that did not parse. */\nexport interface RevocationParseError {\n\t/** Error category. */\n\treadonly kind: 'parse_error';\n\t/** `malformed`, or the refusal for evidence micro509 does not decode. */\n\treadonly code: DecodeFailureCode;\n\t/** Human-readable error description. */\n\treadonly message: string;\n\t/** Which evidence caused the error (e.g., CRL issuer DN). */\n\treadonly evidenceIdentifier?: string;\n}\n\n/** Revocation evidence that parsed but could not be processed. */\nexport interface RevocationProcessingError {\n\t/** Error category. */\n\treadonly kind: 'unsupported_extension' | 'internal_error';\n\t/** Human-readable error description. */\n\treadonly message: string;\n\t/** Which evidence caused the error (e.g., CRL issuer DN). */\n\treadonly evidenceIdentifier?: string;\n}\n\n/**\n * Detailed revocation check results.\n *\n * Returned as {@linkcode CheckChainRevocationResult.value} from\n * {@linkcode checkChainRevocation}. Contains both the policy decision and\n * detailed per-certificate findings for debugging.\n */\nexport interface CheckChainRevocationValue {\n\t/**\n\t * Final policy decision based on {@linkcode RevocationPolicy}.\n\t *\n\t * - `'allow'`: chain passes revocation check\n\t * - `'deny'`: chain fails (revoked certificate or hard-fail on indeterminate)\n\t */\n\treadonly decision: 'allow' | 'deny';\n\t/** Quick-access summary of problematic certificates. */\n\treadonly summary: {\n\t\t/** Certificates confirmed as revoked. */\n\t\treadonly revokedCertificates: readonly ParsedCertificate[];\n\t\t/** Certificates whose status could not be determined. */\n\t\treadonly indeterminateCertificates: readonly ParsedCertificate[];\n\t};\n\t/** Per-certificate evaluation results. See {@linkcode CertificateRevocationStatus}. */\n\treadonly certificates: readonly CertificateRevocationStatus[];\n\t/** Evidence that could not be processed. See {@linkcode RevocationExecutionError}. */\n\treadonly executionErrors?: readonly RevocationExecutionError[];\n}\n\n/** Result type for {@linkcode checkChainRevocation}. */\nexport type CheckChainRevocationResult = {\n\treadonly ok: true;\n\treadonly value: CheckChainRevocationValue;\n};\n\n// Helpers\n\n/**\n * Parses a certificate from various source formats, returning undefined on failure.\n */\nfunction parseCertificateSafe(source: RevocationCertificateSource): ParsedCertificate | undefined {\n\ttry {\n\t\treturn parseCertificateFromSource(source);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * Compares two certificates by DER bytes for identity.\n * Reference equality fails when same cert is parsed from different sources.\n */\nfunction sameCertificate(a: ParsedCertificate, b: ParsedCertificate): boolean {\n\tif (a.der.length !== b.der.length) return false;\n\tfor (let i = 0; i < a.der.length; i++) {\n\t\tif (a.der[i] !== b.der[i]) return false;\n\t}\n\treturn true;\n}\n\n/**\n * Yields every certificate that could have signed the given CRL, AKI/SKI\n * matches before DN matches. All candidates are returned so a certificate whose\n * subject DN collides with the genuine CRL issuer cannot shadow it: each is\n * tried against the CRL signature and its own path to the trust anchor.\n */\nfunction findIndirectCrlIssuers(\n\tcrl: ParsedCertificateRevocationList,\n\textraCertificates: readonly RevocationCertificateSource[],\n\tchain: readonly ParsedCertificate[],\n): readonly ParsedCertificate[] {\n\tconst parsedExtras: ParsedCertificate[] = [];\n\tfor (const source of extraCertificates) {\n\t\tconst parsed = parseCertificateSafe(source);\n\t\tif (parsed !== undefined) {\n\t\t\tparsedExtras.push(parsed);\n\t\t}\n\t}\n\n\tconst candidates = [...parsedExtras, ...chain];\n\tconst matches: ParsedCertificate[] = [];\n\tconst push = (candidate: ParsedCertificate): void => {\n\t\tif (!matches.some((existing) => sameCertificate(existing, candidate))) {\n\t\t\tmatches.push(candidate);\n\t\t}\n\t};\n\n\tif (crl.authorityKeyIdentifier !== undefined) {\n\t\tfor (const candidate of candidates) {\n\t\t\tif (\n\t\t\t\tcandidate.subjectKeyIdentifier !== undefined &&\n\t\t\t\tnormalizeHex(crl.authorityKeyIdentifier) === normalizeHex(candidate.subjectKeyIdentifier)\n\t\t\t) {\n\t\t\t\tpush(candidate);\n\t\t\t}\n\t\t}\n\t}\n\tfor (const candidate of candidates) {\n\t\tif (crl.issuer.derHex === candidate.subject.derHex) {\n\t\t\tpush(candidate);\n\t\t}\n\t}\n\n\treturn matches;\n}\n\n/** Lowercases a hex string for bytewise comparison. */\nfunction normalizeHex(value: string): string {\n\treturn value.toLowerCase();\n}\n\n/**\n * RFC 5280 §6.3.3(f): confirms the CRL issuer certificate has a valid\n * certification path to the same trust anchor as the certificate under test. A\n * signer already inside the validated chain is authorized by construction. The\n * path check runs without revocation to avoid unbounded recursion.\n */\nasync function crlSignerChainsToAnchor(\n\tsigner: ParsedCertificate,\n\tchain: readonly ParsedCertificate[],\n\textraCertificates: readonly RevocationCertificateSource[],\n\tat: Date,\n): Promise<boolean> {\n\tif (chain.some((c) => sameCertificate(c, signer))) {\n\t\treturn true;\n\t}\n\tconst trustAnchor = chain[chain.length - 1];\n\tif (trustAnchor === undefined) {\n\t\treturn false;\n\t}\n\t// The signer's issuer may be a validated chain certificate (a delegated\n\t// signer issued by an intermediate), so pool the non-anchor chain members\n\t// with the extras. Exclude the signer and the anchor.\n\tconst pool: ParsedCertificate[] = [];\n\tconst addCandidate = (parsed: ParsedCertificate): void => {\n\t\tif (sameCertificate(parsed, signer) || sameCertificate(parsed, trustAnchor)) {\n\t\t\treturn;\n\t\t}\n\t\tif (!pool.some((existing) => sameCertificate(existing, parsed))) {\n\t\t\tpool.push(parsed);\n\t\t}\n\t};\n\tfor (let index = 0; index < chain.length - 1; index += 1) {\n\t\tconst certificate = chain[index];\n\t\tif (certificate !== undefined) {\n\t\t\taddCandidate(certificate);\n\t\t}\n\t}\n\tfor (const source of extraCertificates) {\n\t\tconst parsed = parseCertificateSafe(source);\n\t\tif (parsed !== undefined) {\n\t\t\taddCandidate(parsed);\n\t\t}\n\t}\n\tconst result = await verifyCertificateChain({\n\t\tleaf: signer.der,\n\t\tintermediates: pool.map((certificate) => certificate.der),\n\t\troots: [trustAnchor.der],\n\t\tat,\n\t});\n\treturn result.ok;\n}\n\n// CRL Signer Validation (RFC 5280 §6.3.3)\n\n/**\n * State machine for CRL signer validation with memoization.\n * - `visiting`: Currently being checked (cycle detection)\n * - `resolved-valid`: Signer is not revoked\n * - `resolved-revoked`: Signer is revoked\n * - `resolved-indeterminate`: Can't determine signer status\n */\ntype SignerValidationState =\n\t| 'visiting'\n\t| 'resolved-valid'\n\t| 'resolved-revoked'\n\t| 'resolved-indeterminate';\n\n/** Context for CRL signer validation with memoization cache. */\ninterface SignerValidationContext {\n\treadonly cache: Map<string, SignerValidationState>;\n\treadonly chain: readonly ParsedCertificate[];\n\treadonly crls: readonly CrlSource[];\n\treadonly extraCertificates: readonly RevocationCertificateSource[];\n\treadonly at: Date;\n\treadonly crlMaxAgeMs: number | undefined;\n\treadonly clockSkewMs: number | undefined;\n\treadonly unrecognizedReasonCode: UnrecognizedReasonCodePolicy;\n}\n\n/**\n * Builds a unique cache key for a certificate.\n * Uses issuer DN + serial number which uniquely identifies a cert.\n */\nfunction certCacheKey(cert: ParsedCertificate): string {\n\treturn `${cert.issuer.derHex}:${cert.serialNumberHex}`;\n}\n\n/**\n * Validates that a CRL signer certificate is not revoked.\n * Uses memoization to avoid redundant checks and detect cycles.\n */\nasync function validateCrlSigner(\n\tsigner: ParsedCertificate,\n\tctx: SignerValidationContext,\n): Promise<SignerValidationState> {\n\t// Use issuer+serial as cache key (unique per certificate)\n\tconst key = certCacheKey(signer);\n\tconst cached = ctx.cache.get(key);\n\n\t// Cycle detection: if we're already visiting this signer, it's indeterminate\n\tif (cached === 'visiting') {\n\t\treturn 'resolved-indeterminate';\n\t}\n\n\t// Return cached result if already resolved\n\tif (cached !== undefined) {\n\t\treturn cached;\n\t}\n\n\t// Mark as visiting before recursive checks\n\tctx.cache.set(key, 'visiting');\n\n\t// Trust anchor (last in chain) is trusted by definition\n\tconst trustAnchor = ctx.chain[ctx.chain.length - 1];\n\tif (trustAnchor !== undefined && sameCertificate(signer, trustAnchor)) {\n\t\tctx.cache.set(key, 'resolved-valid');\n\t\treturn 'resolved-valid';\n\t}\n\n\t// If signer is in the validated chain, it's trusted\n\t// (Chain was already validated before revocation checking)\n\tconst isInChain = ctx.chain.some((c) => sameCertificate(c, signer));\n\tif (isInChain) {\n\t\tctx.cache.set(key, 'resolved-valid');\n\t\treturn 'resolved-valid';\n\t}\n\n\t// Signer is not in chain — need to check its revocation status\n\t// Find signer's issuer to perform revocation check\n\tconst signerIssuer = findSignerIssuer(signer, ctx);\n\tif (signerIssuer === undefined) {\n\t\tctx.cache.set(key, 'resolved-indeterminate');\n\t\treturn 'resolved-indeterminate';\n\t}\n\n\t// Check signer's revocation status (recursive)\n\tconst signerRevocation = await checkSignerRevocation(signer, signerIssuer, ctx);\n\tctx.cache.set(key, signerRevocation);\n\treturn signerRevocation;\n}\n\n/**\n * Finds the issuer certificate for a CRL signer.\n * Searches the chain and extraCertificates by AKI/SKI or DN matching.\n */\nfunction findSignerIssuer(\n\tsigner: ParsedCertificate,\n\tctx: SignerValidationContext,\n): ParsedCertificate | undefined {\n\t// Parse extra certificates\n\tconst parsedExtras: ParsedCertificate[] = [];\n\tfor (const source of ctx.extraCertificates) {\n\t\tconst parsed = parseCertificateSafe(source);\n\t\tif (parsed !== undefined) {\n\t\t\tparsedExtras.push(parsed);\n\t\t}\n\t}\n\n\tconst candidates = [...ctx.chain, ...parsedExtras];\n\n\tfor (const candidate of candidates) {\n\t\t// Match by AKI → SKI (preferred, more specific)\n\t\tif (\n\t\t\tsigner.authorityKeyIdentifier !== undefined &&\n\t\t\tcandidate.subjectKeyIdentifier !== undefined &&\n\t\t\tnormalizeHex(signer.authorityKeyIdentifier) === normalizeHex(candidate.subjectKeyIdentifier)\n\t\t) {\n\t\t\treturn candidate;\n\t\t}\n\n\t\t// Match by issuer DN → subject DN\n\t\tif (signer.issuer.derHex === candidate.subject.derHex) {\n\t\t\treturn candidate;\n\t\t}\n\t}\n\n\treturn undefined;\n}\n\n/**\n * Checks if a CRL signer certificate is revoked by examining available CRLs.\n * Recursively validates the CRL signer of any CRL used to check revocation.\n */\nasync function checkSignerRevocation(\n\tsigner: ParsedCertificate,\n\tissuer: ParsedCertificate,\n\tctx: SignerValidationContext,\n): Promise<SignerValidationState> {\n\t// If the signer's issuer is in the validated chain, the signer is trusted\n\t// by virtue of being issued by a trusted CA. We only need to check if\n\t// it's explicitly revoked, not prove \"good\" status.\n\tconst issuerInChain = ctx.chain.some((c) => sameCertificate(c, issuer));\n\n\t// A `good` from one CRL does not end the search: a later CRL may report the\n\t// signer revoked, and a revoked verdict from any CRL wins.\n\tconst coveredReasons = new Set<string>();\n\tlet sawUnrecognizedReason = false;\n\tfor (const crlSource of ctx.crls) {\n\t\tconst outcome = await checkSignerAgainstCrl(signer, issuer, crlSource, ctx);\n\t\tif (outcome.kind === 'revoked') {\n\t\t\treturn 'resolved-revoked';\n\t\t}\n\t\tif (outcome.kind === 'unrecognized_reason') {\n\t\t\tsawUnrecognizedReason = true;\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const reason of outcome.reasons) {\n\t\t\tcoveredReasons.add(reason);\n\t\t}\n\t}\n\tif (sawUnrecognizedReason) {\n\t\treturn 'resolved-indeterminate';\n\t}\n\tif (coversAllDistributionPointReasons(coveredReasons)) {\n\t\treturn 'resolved-valid';\n\t}\n\n\t// If the signer's issuer is in the chain and we found no revocation,\n\t// trust the signer (issued by trusted CA, no evidence of revocation)\n\tif (issuerInChain) {\n\t\treturn 'resolved-valid';\n\t}\n\n\treturn 'resolved-indeterminate';\n}\n\n/** What one CRL settles about a signer: a revoked verdict, an entry `unrecognizedReasonCode: 'reject'` refuses, or the reasons it covers. */\ntype SignerCrlOutcome =\n\t| { readonly kind: 'revoked' }\n\t| { readonly kind: 'unrecognized_reason' }\n\t| { readonly kind: 'reasons'; readonly reasons: readonly DistributionPointReason[] };\n\nconst SIGNER_CRL_NO_EVIDENCE = {\n\tkind: 'reasons',\n\treasons: [],\n} as const satisfies SignerCrlOutcome;\n\n/**\n * Evaluates one CRL against a signer. A CRL that does not parse, does not\n * apply, or is itself signed by a signer that is not known good yields no\n * evidence rather than a verdict.\n */\nasync function checkSignerAgainstCrl(\n\tsigner: ParsedCertificate,\n\tissuer: ParsedCertificate,\n\tcrlSource: CrlSource,\n\tctx: SignerValidationContext,\n): Promise<SignerCrlOutcome> {\n\tlet crl: ParsedCertificateRevocationList;\n\ttry {\n\t\tcrl = normalizeCrl(crlSource);\n\t} catch {\n\t\treturn SIGNER_CRL_NO_EVIDENCE;\n\t}\n\tconst result = await checkCertificateRevocationAgainstCrl({\n\t\tcertificate: signer,\n\t\tissuerCertificate: issuer,\n\t\tcrl,\n\t\tat: ctx.at,\n\t\t...(ctx.crlMaxAgeMs === undefined ? {} : { maxAgeMs: ctx.crlMaxAgeMs }),\n\t\t...(ctx.clockSkewMs === undefined ? {} : { clockSkewMs: ctx.clockSkewMs }),\n\t\tunrecognizedReasonCode: ctx.unrecognizedReasonCode,\n\t});\n\tif (!result.ok) {\n\t\treturn result.code === 'reason_code_unrecognized'\n\t\t\t? { kind: 'unrecognized_reason' }\n\t\t\t: SIGNER_CRL_NO_EVIDENCE;\n\t}\n\tif (result.value.status === 'revoked') {\n\t\treturn { kind: 'revoked' };\n\t}\n\t// The CRL's signer is the issuer just used, and it must itself be good.\n\treturn (await validateCrlSigner(issuer, ctx)) === 'resolved-valid'\n\t\t? { kind: 'reasons', reasons: result.value.coveredReasons }\n\t\t: SIGNER_CRL_NO_EVIDENCE;\n}\n\n/** Builds the `revoked` CertificateRevocationStatus for a CRL hit. */\nfunction buildCrlRevokedStatus(\n\tcert: ParsedCertificate,\n\tsigner: ParsedCertificate,\n\tthisUpdate: Date,\n\trevocationDate: Date,\n\treasonCode?: ParsedRevocationReason,\n): CertificateRevocationStatus {\n\treturn {\n\t\tcertificate: cert,\n\t\tstatus: 'revoked',\n\t\tsource: { kind: 'crl', signerCertificate: signer, thisUpdate },\n\t\trevocationInfo: {\n\t\t\trevocationDate,\n\t\t\t...(reasonCode !== undefined ? { reason: reasonCode } : {}),\n\t\t},\n\t};\n}\n\n// OCSP Evidence Evaluation (RFC 6960)\n\n/** Per-certificate evidence evaluation outcome shared by the CRL and OCSP evaluators. */\ninterface EvidenceEvaluation {\n\treadonly status: CertificateRevocationStatus;\n\treadonly executionErrors: readonly RevocationExecutionError[];\n}\n\ninterface OcspHoldEvidence {\n\treadonly status: CertificateRevocationStatus;\n\treadonly thisUpdate: Date;\n}\n\ntype ClassifiedOcspEvidence =\n\t| { readonly kind: 'good'; readonly thisUpdate: Date }\n\t| { readonly kind: 'hold'; readonly evidence: OcspHoldEvidence }\n\t| { readonly kind: 'revoked'; readonly status: CertificateRevocationStatus }\n\t| { readonly kind: 'unknown' }\n\t| { readonly kind: 'unrecognized_reason' };\n\ntype ApplicableOcspResponse =\n\t| {\n\t\t\treadonly kind: 'applicable';\n\t\t\treadonly parsed: ParsedOcspResponse;\n\t\t\treadonly entry: ParsedOcspSingleResponse;\n\t }\n\t| { readonly kind: 'parse_error'; readonly error: RevocationParseError }\n\t| { readonly kind: 'not_applicable' };\n\n/** Parses an OCSP response from PEM string or DER bytes. */\nfunction parseOcspResponseFromSource(source: OcspResponseSource): ParsedOcspResponse {\n\tif (typeof source === 'string') {\n\t\treturn parseOcspResponsePemOrThrow(source);\n\t}\n\treturn parseOcspResponseDerOrThrow(source);\n}\n\nfunction evidenceParseError(error: unknown, fallbackMessage: string): RevocationParseError {\n\treturn {\n\t\tkind: 'parse_error',\n\t\tcode: decodeRefusalOf(error, DECODE_REFUSAL_CODES)?.code ?? 'malformed',\n\t\tmessage: error instanceof Error ? error.message : fallbackMessage,\n\t};\n}\n\n/** Parses one OCSP source and locates the entry for the certificate under evaluation. */\nfunction findApplicableOcspResponse(\n\tsource: OcspResponseSource,\n\tcert: ParsedCertificate,\n): ApplicableOcspResponse {\n\tlet parsed: ParsedOcspResponse;\n\ttry {\n\t\tparsed = parseOcspResponseFromSource(source);\n\t} catch (error) {\n\t\treturn { kind: 'parse_error', error: evidenceParseError(error, 'OCSP response parse failed') };\n\t}\n\tconst entry = (parsed.responses ?? []).find(\n\t\t(single) => normalizeHex(single.certId.serialNumberHex) === normalizeHex(cert.serialNumberHex),\n\t);\n\treturn entry === undefined ? { kind: 'not_applicable' } : { kind: 'applicable', parsed, entry };\n}\n\n/** Returns the later of two evidence timestamps, tolerating an empty accumulator. */\nfunction laterEvidenceDate(current: Date | undefined, candidate: Date): Date {\n\treturn current === undefined || candidate.getTime() > current.getTime() ? candidate : current;\n}\n\n/** Builds a definitive OCSP-revoked status from a validated response entry. */\nfunction buildOcspRevokedStatus(\n\tcert: ParsedCertificate,\n\tthisUpdate: Date,\n\trevocationDate: Date,\n\treason: ParsedRevocationReason | undefined,\n): CertificateRevocationStatus {\n\treturn {\n\t\tcertificate: cert,\n\t\tstatus: 'revoked',\n\t\tsource: { kind: 'ocsp', thisUpdate },\n\t\trevocationInfo: {\n\t\t\trevocationDate,\n\t\t\t...(reason !== undefined ? { reason } : {}),\n\t\t},\n\t};\n}\n\n/** Classifies one fully validated OCSP entry for aggregation. */\nfunction classifyValidatedOcspEntry(\n\tcert: ParsedCertificate,\n\tentry: ParsedOcspSingleResponse,\n\tunrecognizedReasonCode: UnrecognizedReasonCodePolicy,\n): ClassifiedOcspEvidence {\n\tif (entry.certStatus === 'good') {\n\t\treturn { kind: 'good', thisUpdate: entry.thisUpdate };\n\t}\n\tif (entry.certStatus === 'unknown') {\n\t\treturn { kind: 'unknown' };\n\t}\n\tconst reason = revocationReasonFromCode(entry.revocationReasonCode);\n\tif (unrecognizedReasonCode === 'reject' && typeof reason === 'object') {\n\t\treturn { kind: 'unrecognized_reason' };\n\t}\n\tconst status = buildOcspRevokedStatus(cert, entry.thisUpdate, entry.revokedAt, reason);\n\treturn reason === 'certificateHold'\n\t\t? { kind: 'hold', evidence: { status, thisUpdate: entry.thisUpdate } }\n\t\t: { kind: 'revoked', status };\n}\n\n/** Builds the definitive OCSP-good result or the accumulated indeterminate result. */\nfunction finalizeOcspEvidence(\n\tcert: ParsedCertificate,\n\tfreshestGoodThisUpdate: Date | undefined,\n\treasons: Set<RevocationIndeterminateReason>,\n\texecutionErrors: readonly RevocationExecutionError[],\n): EvidenceEvaluation {\n\tif (freshestGoodThisUpdate !== undefined) {\n\t\treturn {\n\t\t\tstatus: {\n\t\t\t\tcertificate: cert,\n\t\t\t\tstatus: 'good',\n\t\t\t\tsource: { kind: 'ocsp', thisUpdate: freshestGoodThisUpdate },\n\t\t\t},\n\t\t\texecutionErrors,\n\t\t};\n\t}\n\tif (reasons.size === 0) {\n\t\treasons.add('no_applicable_ocsp');\n\t}\n\treturn {\n\t\tstatus: {\n\t\t\tcertificate: cert,\n\t\t\tstatus: 'indeterminate',\n\t\t\tindeterminateReasons: [...reasons],\n\t\t},\n\t\texecutionErrors,\n\t};\n}\n\n/** Maps a {@linkcode validateOcspResponse} failure code to an indeterminate reason. */\nfunction ocspIndeterminateReasonFromFailure(\n\tcode: ValidateOcspResponseFailure['code'],\n): RevocationIndeterminateReason {\n\tswitch (code) {\n\t\tcase 'stale_response':\n\t\t\treturn 'ocsp_response_expired';\n\t\tcase 'next_update_missing':\n\t\t\treturn 'ocsp_next_update_missing';\n\t\tcase 'responder_id_mismatch':\n\t\tcase 'responder_chain_invalid':\n\t\tcase 'ocsp_signing_missing':\n\t\t\treturn 'ocsp_responder_not_authorized';\n\t\tcase 'responder_revoked':\n\t\t\treturn 'ocsp_responder_revoked';\n\t\tcase 'signature_invalid':\n\t\tcase 'responder_revocation_unknown':\n\t\tcase 'unsupported':\n\t\tcase 'limit_exceeded':\n\t\t\treturn 'ocsp_responder_indeterminate';\n\t\tcase 'response_status_invalid':\n\t\tcase 'issuer_mismatch':\n\t\tcase 'nonce_mismatch':\n\t\tcase 'request_mismatch':\n\t\t\treturn 'no_applicable_ocsp';\n\t\tdefault: {\n\t\t\tconst _exhaustive: never = code;\n\t\t\tthrow new Error(`Unhandled ValidateOcspResponse failure code: ${String(_exhaustive)}`);\n\t\t}\n\t}\n}\n\n/** Validation failures worth retrying with an explicit responder certificate. */\nconst OCSP_RESPONDER_FAILURE_CODES: ReadonlySet<ValidateOcspResponseFailure['code']> = new Set([\n\t'signature_invalid',\n\t'responder_id_mismatch',\n\t'responder_chain_invalid',\n\t'ocsp_signing_missing',\n\t'unsupported',\n\t'limit_exceeded',\n]);\n\n/**\n * Validates an OCSP response, retrying with caller-provided extra certificates\n * as explicit responder certificates when embedded discovery fails.\n */\nasync function validateOcspResponseWithResponderFallback(\n\tresponse: ParsedOcspResponse,\n\tissuer: ParsedCertificate,\n\tinput: CheckChainRevocationInput,\n\tat: Date,\n): Promise<ValidateOcspResponseResult> {\n\tconst trustedOcspResponders = input.trustedOcspResponders\n\t\t?.filter((trusted) => {\n\t\t\tconst trustedIssuer = parseCertificateSafe(trusted.issuerCertificate);\n\t\t\treturn trustedIssuer !== undefined && sameCertificate(trustedIssuer, issuer);\n\t\t})\n\t\t.map((trusted) => trusted.responderCertificate);\n\tconst shared = {\n\t\tissuerCertificate: issuer,\n\t\tat,\n\t\t...(trustedOcspResponders !== undefined ? { trustedOcspResponders } : {}),\n\t\t...(input.policy?.ocspResponderRevocation !== undefined\n\t\t\t? { responderRevocationPolicy: input.policy.ocspResponderRevocation }\n\t\t\t: {}),\n\t\t// Chain-level CRLs double as responder revocation evidence\n\t\t...(input.crls !== undefined ? { responderRevocationCrls: input.crls } : {}),\n\t\t...(input.policy?.crlMaxAgeMs !== undefined\n\t\t\t? { responderRevocationCrlMaxAgeMs: input.policy.crlMaxAgeMs }\n\t\t\t: {}),\n\t\t...(input.policy?.clockSkewMs !== undefined ? { clockSkewMs: input.policy.clockSkewMs } : {}),\n\t\t...(input.policy?.ocspProfile !== undefined ? { profile: input.policy.ocspProfile } : {}),\n\t\t...(input.policy?.unrecognizedReasonCode !== undefined\n\t\t\t? { responderRevocationUnrecognizedReasonCode: input.policy.unrecognizedReasonCode }\n\t\t\t: {}),\n\t};\n\tconst primary = await validateOcspResponse({ response, ...shared });\n\tif (primary.ok || !OCSP_RESPONDER_FAILURE_CODES.has(primary.code)) {\n\t\treturn primary;\n\t}\n\tfor (const source of input.extraCertificates ?? []) {\n\t\tconst responder = parseCertificateSafe(source);\n\t\tif (responder === undefined) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst retry = await validateOcspResponse({\n\t\t\tresponse,\n\t\t\t...shared,\n\t\t\tresponderCertificate: responder,\n\t\t});\n\t\tif (retry.ok) {\n\t\t\treturn retry;\n\t\t}\n\t}\n\treturn primary;\n}\n\n/**\n * Evaluates OCSP evidence for a single certificate (RFC 6960).\n *\n * Every response is fully validated — signature, responder binding and\n * authorization, and freshness — via {@linkcode validateOcspResponse} before\n * its status entry is trusted. Issuer binding of each CertID is enforced by\n * the validator, so a serial-number match on a validated response is\n * sufficient to attribute the entry to `cert`.\n */\nasync function evaluateOcspEvidence(\n\tcert: ParsedCertificate,\n\tissuer: ParsedCertificate,\n\tinput: CheckChainRevocationInput,\n): Promise<EvidenceEvaluation> {\n\tconst { ocspResponses = [], at = new Date() } = input;\n\tconst executionErrors: RevocationExecutionError[] = [];\n\tconst state: OcspEvidenceState = { reasons: new Set(), sawUnrecognizedReason: false };\n\n\tfor (const source of ocspResponses) {\n\t\tconst applicable = findApplicableOcspResponse(source, cert);\n\t\tif (applicable.kind === 'parse_error') {\n\t\t\texecutionErrors.push(applicable.error);\n\t\t\tcontinue;\n\t\t}\n\t\tif (applicable.kind === 'not_applicable') {\n\t\t\tcontinue; // Response does not cover this certificate\n\t\t}\n\n\t\tconst validation = await validateOcspResponseWithResponderFallback(\n\t\t\tapplicable.parsed,\n\t\t\tissuer,\n\t\t\tinput,\n\t\t\tat,\n\t\t);\n\t\tif (!validation.ok) {\n\t\t\tstate.reasons.add(ocspIndeterminateReasonFromFailure(validation.code));\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst evidence = classifyValidatedOcspEntry(\n\t\t\tcert,\n\t\t\tapplicable.entry,\n\t\t\tinput.policy?.unrecognizedReasonCode ?? 'revoked',\n\t\t);\n\t\tif (evidence.kind === 'revoked') {\n\t\t\treturn {\n\t\t\t\tstatus: evidence.status,\n\t\t\t\texecutionErrors,\n\t\t\t};\n\t\t}\n\t\trecordOcspEvidence(state, evidence);\n\t}\n\n\treturn settleOcspEvidence(cert, state, executionErrors);\n}\n\n/** What the non-revoked OCSP entries for one certificate established. */\ninterface OcspEvidenceState {\n\treadonly reasons: Set<RevocationIndeterminateReason>;\n\tfreshestGoodThisUpdate?: Date;\n\tfreshestHold?: OcspHoldEvidence;\n\tsawUnrecognizedReason: boolean;\n}\n\nfunction recordOcspEvidence(\n\tstate: OcspEvidenceState,\n\tevidence: Exclude<ClassifiedOcspEvidence, { readonly kind: 'revoked' }>,\n): void {\n\tif (evidence.kind === 'good') {\n\t\tstate.freshestGoodThisUpdate = laterEvidenceDate(\n\t\t\tstate.freshestGoodThisUpdate,\n\t\t\tevidence.thisUpdate,\n\t\t);\n\t\treturn;\n\t}\n\tif (evidence.kind === 'hold') {\n\t\tif (\n\t\t\tstate.freshestHold === undefined ||\n\t\t\tevidence.evidence.thisUpdate.getTime() > state.freshestHold.thisUpdate.getTime()\n\t\t) {\n\t\t\tstate.freshestHold = evidence.evidence;\n\t\t}\n\t\treturn;\n\t}\n\tif (evidence.kind === 'unrecognized_reason') {\n\t\tstate.sawUnrecognizedReason = true;\n\t\treturn;\n\t}\n\tstate.reasons.add('ocsp_status_unknown');\n}\n\n/** The OCSP verdict once no response revoked the certificate outright. */\nfunction settleOcspEvidence(\n\tcert: ParsedCertificate,\n\tstate: OcspEvidenceState,\n\texecutionErrors: readonly RevocationExecutionError[],\n): EvidenceEvaluation {\n\tif (state.sawUnrecognizedReason) {\n\t\tstate.reasons.add('ocsp_reason_code_unrecognized');\n\t\treturn finalizeOcspEvidence(cert, undefined, state.reasons, executionErrors);\n\t}\n\tconst { freshestGoodThisUpdate, freshestHold } = state;\n\tif (\n\t\tfreshestHold !== undefined &&\n\t\t(freshestGoodThisUpdate === undefined ||\n\t\t\tfreshestGoodThisUpdate.getTime() <= freshestHold.thisUpdate.getTime())\n\t) {\n\t\treturn { status: freshestHold.status, executionErrors };\n\t}\n\treturn finalizeOcspEvidence(cert, freshestGoodThisUpdate, state.reasons, executionErrors);\n}\n\n/**\n * Evaluates revocation status for a single certificate using available CRLs.\n * Returns both status and any execution errors encountered.\n *\n * Tries the chain issuer first; if that fails, searches extraCertificates\n * and chain for an indirect CRL issuer that matches the CRL's AKI or issuer DN.\n *\n * Also validates that CRL signers are not revoked (RFC 5280 §6.3.3).\n */\n// RFC 5280 ReasonFlags — all possible revocation reasons that CRLs can cover.\ninterface CrlEvidenceState {\n\treadonly executionErrors: RevocationExecutionError[];\n\treadonly coveredReasons: Set<string>;\n\tsawCrlSignerRevoked: boolean;\n\tsawCrlSignerIndeterminate: boolean;\n\tsawCrlSignerNotAuthorized: boolean;\n\tsawStaleCrl: boolean;\n\tsawDeltaCrlUnusable: boolean;\n\tsawDeltaCrlRetryLimit: boolean;\n\tsawUnrecognizedReasonCode: boolean;\n\tsawGood: boolean;\n\tfreshestGood?: { readonly signer: ParsedCertificate; readonly thisUpdate: Date };\n}\n\n/** Inputs for resolving one base CRL against its candidate signers. */\ninterface BaseCrlResolution {\n\treadonly cert: ParsedCertificate;\n\treadonly baseCrl: ParsedCertificateRevocationList;\n\treadonly deltaCandidates: readonly ParsedCertificateRevocationList[];\n\treadonly issuer: ParsedCertificate;\n\treadonly extraCertificates: readonly RevocationCertificateSource[];\n\treadonly chain: readonly ParsedCertificate[];\n\treadonly at: Date;\n\treadonly crlMaxAgeMs: number | undefined;\n\treadonly clockSkewMs: number | undefined;\n\treadonly unrecognizedReasonCode: UnrecognizedReasonCodePolicy;\n\treadonly signerCtx: SignerValidationContext;\n\treadonly deltaBudget: DeltaCrlBudget;\n\treadonly state: CrlEvidenceState;\n}\n\n/**\n * Runs each candidate signer through the full pipeline for one base CRL:\n * signature/applicability, RFC 5280 §6.3.3(f) path to the anchor, then signer\n * revocation. A candidate that verifies the signature but fails a later step\n * does not shadow a subsequent usable signer, so the search continues. Returns\n * a revoked status when one is found; otherwise records good or diagnostic\n * evidence into `state`.\n */\nasync function resolveBaseCrlAgainstSigners(\n\tparams: BaseCrlResolution,\n): Promise<ReturnType<typeof buildCrlRevokedStatus> | undefined> {\n\tconst {\n\t\tcert,\n\t\tbaseCrl,\n\t\tdeltaCandidates,\n\t\tissuer,\n\t\textraCertificates,\n\t\tchain,\n\t\tat,\n\t\tcrlMaxAgeMs,\n\t\tclockSkewMs,\n\t\tunrecognizedReasonCode,\n\t\tsignerCtx,\n\t\tdeltaBudget,\n\t\tstate,\n\t} = params;\n\tconst baseBudget = { remaining: DELTA_CRL_ATTEMPTS_PER_BASE };\n\tfor (const candidate of collectCrlSignerCandidates(baseCrl, issuer, extraCertificates, chain)) {\n\t\tconst resolved = await checkCrlAgainstDeltaCandidates({\n\t\t\tcert,\n\t\t\tbaseCrl,\n\t\t\tdeltaCandidates,\n\t\t\tcandidate,\n\t\t\tat,\n\t\t\tcrlMaxAgeMs,\n\t\t\tclockSkewMs,\n\t\t\tunrecognizedReasonCode,\n\t\t\tbudgets: [baseBudget, deltaBudget],\n\t\t\tstate,\n\t\t});\n\t\tif (resolved.kind === 'unusable_base') {\n\t\t\tcontinue;\n\t\t}\n\t\tif (!(await crlSignerChainsToAnchor(candidate, chain, extraCertificates, at))) {\n\t\t\tstate.sawCrlSignerNotAuthorized = true;\n\t\t\tcontinue;\n\t\t}\n\t\tconst signerStatus = await validateCrlSigner(candidate, signerCtx);\n\t\tif (signerStatus === 'resolved-revoked') {\n\t\t\tstate.sawCrlSignerRevoked = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (signerStatus === 'resolved-indeterminate') {\n\t\t\tstate.sawCrlSignerIndeterminate = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (resolved.kind === 'reason_code_unrecognized') {\n\t\t\tstate.sawUnrecognizedReasonCode = true;\n\t\t\treturn undefined;\n\t\t}\n\t\tif (resolved.kind === 'delta_unusable') {\n\t\t\tstate.sawDeltaCrlUnusable = true;\n\t\t\treturn undefined;\n\t\t}\n\t\tif (resolved.kind === 'retry_limit') {\n\t\t\tstate.sawDeltaCrlRetryLimit = true;\n\t\t\treturn undefined;\n\t\t}\n\t\tconst { checked, crlThisUpdate } = resolved;\n\t\tif (checked.value.status === 'revoked') {\n\t\t\treturn buildCrlRevokedStatus(\n\t\t\t\tcert,\n\t\t\t\tcandidate,\n\t\t\t\tcrlThisUpdate,\n\t\t\t\tchecked.value.revocationDate,\n\t\t\t\tchecked.value.reasonCode,\n\t\t\t);\n\t\t}\n\t\trecordGoodCrlEvidence(state, candidate, crlThisUpdate, checked.value.coveredReasons);\n\t\treturn undefined;\n\t}\n\treturn undefined;\n}\n\nasync function evaluateCrlEvidence(\n\tcert: ParsedCertificate,\n\tissuer: ParsedCertificate,\n\tinput: CheckChainRevocationInput,\n\tsignerCtx: SignerValidationContext,\n\tdeltaBudget: DeltaCrlBudget,\n): Promise<EvidenceEvaluation> {\n\tconst { crls = [], extraCertificates = [], chain = [], at = new Date() } = input;\n\tconst state: CrlEvidenceState = {\n\t\texecutionErrors: [],\n\t\tcoveredReasons: new Set(),\n\t\tsawCrlSignerRevoked: false,\n\t\tsawCrlSignerIndeterminate: false,\n\t\tsawCrlSignerNotAuthorized: false,\n\t\tsawStaleCrl: false,\n\t\tsawDeltaCrlUnusable: false,\n\t\tsawDeltaCrlRetryLimit: false,\n\t\tsawUnrecognizedReasonCode: false,\n\t\tsawGood: false,\n\t};\n\n\t// Parse all CRLs and separate base CRLs from delta CRLs\n\tconst parsedCrls = parseCrlEvidenceSources(crls, state.executionErrors);\n\n\tconst baseCrls = distinctSignedCrls(\n\t\tparsedCrls.filter((crl) => crl.baseCrlNumber === undefined && isCrlApplicableTo(cert, crl)),\n\t);\n\tconst deltaCrls = distinctSignedCrls(parsedCrls.filter((crl) => crl.baseCrlNumber !== undefined));\n\n\t// Process base CRLs (optionally paired with delta CRLs)\n\tconst crlMaxAgeMs = input.policy?.crlMaxAgeMs;\n\tconst clockSkewMs = input.policy?.clockSkewMs;\n\tfor (const baseCrl of baseCrls) {\n\t\tconst revoked = await resolveBaseCrlAgainstSigners({\n\t\t\tcert,\n\t\t\tbaseCrl,\n\t\t\tdeltaCandidates: rankApplicableDeltaCrls(\n\t\t\t\tbaseCrl,\n\t\t\t\tdeltaCrls,\n\t\t\t\tat,\n\t\t\t\tclockSkewMs ?? 0,\n\t\t\t\tcrlMaxAgeMs,\n\t\t\t),\n\t\t\tissuer,\n\t\t\textraCertificates,\n\t\t\tchain,\n\t\t\tat,\n\t\t\tcrlMaxAgeMs,\n\t\t\tclockSkewMs,\n\t\t\tunrecognizedReasonCode: input.policy?.unrecognizedReasonCode ?? 'revoked',\n\t\t\tsignerCtx,\n\t\t\tdeltaBudget,\n\t\t\tstate,\n\t\t});\n\t\tif (revoked !== undefined) {\n\t\t\treturn { status: revoked, executionErrors: state.executionErrors };\n\t\t}\n\t}\n\n\tconst blockingReasons = blockingCrlIndeterminateReasons(state);\n\tif (blockingReasons.length > 0) {\n\t\treturn {\n\t\t\tstatus: { certificate: cert, status: 'indeterminate', indeterminateReasons: blockingReasons },\n\t\t\texecutionErrors: state.executionErrors,\n\t\t};\n\t}\n\n\t// Return 'good' only if we saw at least one good result AND all reasons are covered\n\tif (state.sawGood && state.freshestGood !== undefined) {\n\t\tconst allReasonsCovered = coversAllDistributionPointReasons(state.coveredReasons);\n\t\tif (allReasonsCovered) {\n\t\t\treturn {\n\t\t\t\tstatus: {\n\t\t\t\t\tcertificate: cert,\n\t\t\t\t\tstatus: 'good',\n\t\t\t\t\tsource: {\n\t\t\t\t\t\tkind: 'crl',\n\t\t\t\t\t\tsignerCertificate: state.freshestGood.signer,\n\t\t\t\t\t\tthisUpdate: state.freshestGood.thisUpdate,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\texecutionErrors: state.executionErrors,\n\t\t\t};\n\t\t}\n\t\t// Not all reasons covered — indeterminate\n\t\treturn {\n\t\t\tstatus: {\n\t\t\t\tcertificate: cert,\n\t\t\t\tstatus: 'indeterminate',\n\t\t\t\tindeterminateReasons: ['reason_coverage_incomplete'],\n\t\t\t},\n\t\t\texecutionErrors: state.executionErrors,\n\t\t};\n\t}\n\n\treturn {\n\t\tstatus: {\n\t\t\tcertificate: cert,\n\t\t\tstatus: 'indeterminate',\n\t\t\tindeterminateReasons: [crlUnavailableReason(state)],\n\t\t},\n\t\texecutionErrors: state.executionErrors,\n\t};\n}\n\n/** CRL conditions that keep the status indeterminate despite `good` evidence. */\nfunction blockingCrlIndeterminateReasons(\n\tstate: CrlEvidenceState,\n): readonly RevocationIndeterminateReason[] {\n\treturn [\n\t\t...(state.sawDeltaCrlUnusable ? (['delta_crl_unusable'] as const) : []),\n\t\t...(state.sawDeltaCrlRetryLimit ? (['delta_crl_retry_limit_exceeded'] as const) : []),\n\t\t...(state.sawUnrecognizedReasonCode ? (['crl_reason_code_unrecognized'] as const) : []),\n\t];\n}\n\n/** Most specific indeterminate reason when no CRL yielded a usable verdict. */\nfunction crlUnavailableReason(state: CrlEvidenceState): RevocationIndeterminateReason {\n\tif (state.sawCrlSignerRevoked) {\n\t\treturn 'crl_signer_revoked';\n\t}\n\tif (state.sawCrlSignerNotAuthorized) {\n\t\treturn 'crl_signer_not_authorized';\n\t}\n\tif (state.sawCrlSignerIndeterminate) {\n\t\treturn 'crl_signer_indeterminate';\n\t}\n\tif (state.sawStaleCrl) {\n\t\treturn 'crl_expired';\n\t}\n\treturn 'no_applicable_crl';\n}\n\n/** Parses complete and delta CRL evidence while retaining source provenance. */\nfunction parseCrlEvidenceSources(\n\tcrls: readonly CrlSource[],\n\texecutionErrors: RevocationExecutionError[],\n): readonly ParsedCertificateRevocationList[] {\n\tconst parsedCrls: ParsedCertificateRevocationList[] = [];\n\tfor (const crlSource of crls) {\n\t\ttry {\n\t\t\tparsedCrls.push(normalizeCrl(crlSource));\n\t\t} catch (error) {\n\t\t\texecutionErrors.push(evidenceParseError(error, 'CRL parse failed'));\n\t\t}\n\t}\n\treturn parsedCrls;\n}\n\n/** `crls` without repeats of the same signed content and signature. */\nfunction distinctSignedCrls(\n\tcrls: readonly ParsedCertificateRevocationList[],\n): readonly ParsedCertificateRevocationList[] {\n\tconst seen = new Set<string>();\n\treturn crls.filter((crl) => {\n\t\tconst key = [\n\t\t\tcrl.signatureAlgorithmOid,\n\t\t\ttoHex(crl.signatureAlgorithmParametersDer ?? new Uint8Array()),\n\t\t\ttoHex(crl.signatureValue),\n\t\t\ttoHex(crl.tbsCertListDer),\n\t\t].join(':');\n\t\tif (seen.has(key)) {\n\t\t\treturn false;\n\t\t}\n\t\tseen.add(key);\n\t\treturn true;\n\t});\n}\n\n/** Every delta CRL that can update `baseCrl`, newest first, in the order to try authenticating them. */\nfunction rankApplicableDeltaCrls(\n\tbaseCrl: ParsedCertificateRevocationList,\n\tdeltaCrls: readonly ParsedCertificateRevocationList[],\n\tat: Date,\n\tclockSkewMs: number,\n\tcrlMaxAgeMs: number | undefined,\n): readonly ParsedCertificateRevocationList[] {\n\tconst baseCrlNumber = baseCrl.crlNumber;\n\tif (baseCrlNumber === undefined) {\n\t\treturn [];\n\t}\n\treturn deltaCrls\n\t\t.filter(\n\t\t\t(deltaCrl) =>\n\t\t\t\tdeltaCrl.issuer.derHex === baseCrl.issuer.derHex &&\n\t\t\t\tdeltaCrl.baseCrlNumber !== undefined &&\n\t\t\t\tdeltaCrl.baseCrlNumber <= baseCrlNumber &&\n\t\t\t\tdeltaCrl.crlNumber !== undefined &&\n\t\t\t\tdeltaCrl.crlNumber > baseCrlNumber &&\n\t\t\t\tdeltaCrl.thisUpdate.getTime() >= baseCrl.thisUpdate.getTime() &&\n\t\t\t\tisCurrentDeltaCrl(deltaCrl, at, clockSkewMs, crlMaxAgeMs),\n\t\t)\n\t\t.sort((left, right) =>\n\t\t\tisNewerDeltaCrl(left, right) ? -1 : isNewerDeltaCrl(right, left) ? 1 : 0,\n\t\t);\n}\n\n/** Delta CRL checks left to spend. */\ninterface DeltaCrlBudget {\n\tremaining: number;\n}\n\nconst DELTA_CRL_ATTEMPTS_PER_BASE = 4;\nconst DELTA_CRL_ATTEMPTS_PER_CHAIN = 32;\n\ninterface DeltaCandidateCheck {\n\treadonly cert: ParsedCertificate;\n\treadonly baseCrl: ParsedCertificateRevocationList;\n\treadonly deltaCandidates: readonly ParsedCertificateRevocationList[];\n\treadonly candidate: ParsedCertificate;\n\treadonly at: Date;\n\treadonly crlMaxAgeMs: number | undefined;\n\treadonly clockSkewMs: number | undefined;\n\treadonly unrecognizedReasonCode: UnrecognizedReasonCodePolicy;\n\treadonly budgets: readonly DeltaCrlBudget[];\n\treadonly state: CrlEvidenceState;\n}\n\ntype DeltaCandidateOutcome =\n\t| {\n\t\t\treadonly kind: 'checked';\n\t\t\treadonly checked: Extract<\n\t\t\t\tAwaited<ReturnType<typeof checkCertificateRevocationAgainstCrl>>,\n\t\t\t\t{ readonly ok: true }\n\t\t\t>;\n\t\t\treadonly crlThisUpdate: Date;\n\t }\n\t| { readonly kind: 'unusable_base' }\n\t| { readonly kind: 'reason_code_unrecognized' }\n\t| {\n\t\t\treadonly kind: 'delta_unusable';\n\t\t\treadonly complete: Awaited<ReturnType<typeof checkCertificateRevocationAgainstCrl>>;\n\t }\n\t| { readonly kind: 'retry_limit' };\n\n/**\n * Authenticates `baseCrl` with `candidate` once, then checks it with each\n * ranked delta CRL while the budgets last, and alone once every delta CRL is\n * rejected. A delta CRL that passes authentication, freshness, compatibility\n * and applicability ends the search.\n */\nasync function checkCrlAgainstDeltaCandidates(\n\tparams: DeltaCandidateCheck,\n): Promise<DeltaCandidateOutcome> {\n\tconst {\n\t\tcert,\n\t\tbaseCrl,\n\t\tdeltaCandidates,\n\t\tcandidate,\n\t\tat,\n\t\tcrlMaxAgeMs,\n\t\tclockSkewMs,\n\t\tunrecognizedReasonCode,\n\t\tbudgets,\n\t\tstate,\n\t} = params;\n\tconst authenticated = await authenticateCrl(baseCrl, candidate);\n\tif (!authenticated.ok) {\n\t\treturn { kind: 'unusable_base' };\n\t}\n\tconst input = {\n\t\tcertificate: cert,\n\t\tissuerCertificate: candidate,\n\t\tcrl: authenticated.value,\n\t\tat,\n\t\t...(crlMaxAgeMs === undefined ? {} : { maxAgeMs: crlMaxAgeMs }),\n\t\t...(clockSkewMs === undefined ? {} : { clockSkewMs }),\n\t\tunrecognizedReasonCode,\n\t};\n\tfor (const deltaCrl of deltaCandidates) {\n\t\tconst settled = takeDeltaCrlAttempt(budgets)\n\t\t\t? settleAuthenticatedCrlOutcome(\n\t\t\t\t\tawait checkRevocationAgainstAuthenticatedCrl(cert, authenticated.value, {\n\t\t\t\t\t\t...input,\n\t\t\t\t\t\tdeltaCrl,\n\t\t\t\t\t}),\n\t\t\t\t\tlaterEvidenceDate(baseCrl.thisUpdate, deltaCrl.thisUpdate),\n\t\t\t\t\tstate,\n\t\t\t\t)\n\t\t\t: ({ kind: 'retry_limit' } as const);\n\t\tif (settled === undefined) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (settled.kind === 'delta_unusable') {\n\t\t\treturn irremovableRevocation(cert, settled.complete, at, baseCrl.thisUpdate) ?? settled;\n\t\t}\n\t\tif (settled.kind === 'retry_limit') {\n\t\t\tconst alone = await checkRevocationAgainstAuthenticatedCrl(cert, authenticated.value, input);\n\t\t\treturn (\n\t\t\t\t(alone.kind === 'checked'\n\t\t\t\t\t? irremovableRevocation(cert, alone.result, at, baseCrl.thisUpdate)\n\t\t\t\t\t: undefined) ?? settled\n\t\t\t);\n\t\t}\n\t\treturn settled;\n\t}\n\treturn (\n\t\tsettleAuthenticatedCrlOutcome(\n\t\t\tawait checkRevocationAgainstAuthenticatedCrl(cert, authenticated.value, input),\n\t\t\tbaseCrl.thisUpdate,\n\t\t\tstate,\n\t\t) ?? { kind: 'unusable_base' }\n\t);\n}\n\n/**\n * The base CRL's revocation of `cert` in `complete` when no delta CRL could\n * remove it at `at`. RFC 5280 §5.3.1 lets removeFromCRL clear only a\n * certificateHold entry or a certificate that has expired.\n */\nfunction irremovableRevocation(\n\tcert: ParsedCertificate,\n\tcomplete: Awaited<ReturnType<typeof checkCertificateRevocationAgainstCrl>>,\n\tat: Date,\n\tcrlThisUpdate: Date,\n): DeltaCandidateOutcome | undefined {\n\tif (\n\t\tcert.notAfter.getTime() < at.getTime() ||\n\t\t!complete.ok ||\n\t\tcomplete.value.status !== 'revoked' ||\n\t\tcomplete.value.reasonCode === 'certificateHold'\n\t) {\n\t\treturn undefined;\n\t}\n\treturn { kind: 'checked', checked: complete, crlThisUpdate };\n}\n\n/** Spends one delta CRL check from every budget, or none when any is empty. */\nfunction takeDeltaCrlAttempt(budgets: readonly DeltaCrlBudget[]): boolean {\n\tif (budgets.some((budget) => budget.remaining <= 0)) {\n\t\treturn false;\n\t}\n\tfor (const budget of budgets) {\n\t\tbudget.remaining -= 1;\n\t}\n\treturn true;\n}\n\n/** Maps one staged CRL check to the search outcome, or `undefined` to try the next delta CRL. */\nfunction settleAuthenticatedCrlOutcome(\n\toutcome: AuthenticatedCrlCheckOutcome,\n\tcrlThisUpdate: Date,\n\tstate: CrlEvidenceState,\n): DeltaCandidateOutcome | undefined {\n\tif (outcome.kind === 'delta_unresolved') {\n\t\treturn { kind: 'delta_unusable', complete: outcome.complete };\n\t}\n\tconst result = outcome.kind === 'checked' ? outcome.result : outcome.failure;\n\tif (!result.ok && result.code === 'stale_crl') {\n\t\tstate.sawStaleCrl = true;\n\t}\n\tif (!result.ok && result.code === 'reason_code_unrecognized') {\n\t\treturn { kind: 'reason_code_unrecognized' };\n\t}\n\tif (outcome.kind === 'delta_rejected') {\n\t\treturn undefined;\n\t}\n\treturn result.ok\n\t\t? { kind: 'checked', checked: result, crlThisUpdate }\n\t\t: { kind: 'unusable_base' };\n}\n\nfunction isNewerDeltaCrl(\n\tcandidate: ParsedCertificateRevocationList,\n\tcurrent: ParsedCertificateRevocationList,\n): boolean {\n\tconst candidateTime = candidate.thisUpdate.getTime();\n\tconst currentTime = current.thisUpdate.getTime();\n\tif (candidateTime !== currentTime) return candidateTime > currentTime;\n\treturn (candidate.crlNumber ?? 0n) > (current.crlNumber ?? 0n);\n}\n\n/** The direct issuer first, then deduplicated indirect CRL-issuer candidates. */\nfunction collectCrlSignerCandidates(\n\tbaseCrl: ParsedCertificateRevocationList,\n\tissuer: ParsedCertificate,\n\textraCertificates: readonly RevocationCertificateSource[],\n\tchain: readonly ParsedCertificate[],\n): readonly ParsedCertificate[] {\n\tconst candidates: ParsedCertificate[] = [issuer];\n\tfor (const indirect of findIndirectCrlIssuers(baseCrl, extraCertificates, chain)) {\n\t\tif (!candidates.some((existing) => sameCertificate(existing, indirect))) {\n\t\t\tcandidates.push(indirect);\n\t\t}\n\t}\n\treturn candidates;\n}\n\nfunction recordGoodCrlEvidence(\n\tstate: CrlEvidenceState,\n\tsigner: ParsedCertificate,\n\tthisUpdate: Date,\n\tcoveredReasons: readonly DistributionPointReason[],\n): void {\n\tstate.sawGood = true;\n\tif (\n\t\tstate.freshestGood === undefined ||\n\t\tthisUpdate.getTime() > state.freshestGood.thisUpdate.getTime()\n\t) {\n\t\tstate.freshestGood = { signer, thisUpdate };\n\t}\n\tfor (const reason of coveredReasons) {\n\t\tstate.coveredReasons.add(reason);\n\t}\n}\n\n/** Indeterminate reasons that keep other evidence from settling the status as `good`. */\nconst GOOD_BLOCKING_REASONS: ReadonlySet<RevocationIndeterminateReason> = new Set([\n\t'delta_crl_unusable',\n\t'delta_crl_retry_limit_exceeded',\n\t'crl_reason_code_unrecognized',\n\t'ocsp_reason_code_unrecognized',\n]);\n\n/**\n * Evaluates revocation status for a single certificate by combining OCSP and\n * CRL evidence.\n *\n * Both evidence kinds are always evaluated: a validated `revoked` verdict from\n * either source wins regardless of {@linkcode RevocationPolicy.prefer}\n * (fail-closed). Otherwise the preferred source's `good` verdict is reported —\n * for `'best-available'` the source with the later evidence `thisUpdate` wins,\n * ties favoring OCSP. An indeterminate reason in\n * {@linkcode GOOD_BLOCKING_REASONS} from either source outranks a `good`\n * verdict. If neither source is definitive, indeterminate reasons from both\n * are merged.\n */\nasync function evaluateCertificateRevocation(\n\tcert: ParsedCertificate,\n\tissuer: ParsedCertificate,\n\tinput: CheckChainRevocationInput,\n\tsignerCtx: SignerValidationContext,\n\tdeltaBudget: DeltaCrlBudget,\n): Promise<EvidenceEvaluation> {\n\tconst prefer = input.policy?.prefer ?? 'best-available';\n\tconst ocsp = await evaluateOcspEvidence(cert, issuer, input);\n\tconst crl = await evaluateCrlEvidence(cert, issuer, input, signerCtx, deltaBudget);\n\tconst executionErrors = [...ocsp.executionErrors, ...crl.executionErrors];\n\n\t// 'best-available' ranks by evidence freshness; the sort is stable, so\n\t// equal (or absent) thisUpdate keeps OCSP first.\n\tconst ordered =\n\t\tprefer === 'crl'\n\t\t\t? [crl, ocsp]\n\t\t\t: prefer === 'ocsp'\n\t\t\t\t? [ocsp, crl]\n\t\t\t\t: [ocsp, crl].sort(\n\t\t\t\t\t\t(a, b) =>\n\t\t\t\t\t\t\t(b.status.source?.thisUpdate?.getTime() ?? 0) -\n\t\t\t\t\t\t\t(a.status.source?.thisUpdate?.getTime() ?? 0),\n\t\t\t\t\t);\n\tconst revoked = ordered.find((evaluation) => evaluation.status.status === 'revoked');\n\tif (revoked !== undefined) {\n\t\treturn { status: revoked.status, executionErrors };\n\t}\n\tconst good = ordered.find((evaluation) => evaluation.status.status === 'good');\n\tconst blocked = [crl, ocsp].some((evaluation) =>\n\t\tevaluation.status.indeterminateReasons?.some((reason) => GOOD_BLOCKING_REASONS.has(reason)),\n\t);\n\tif (good !== undefined && !blocked) {\n\t\treturn { status: good.status, executionErrors };\n\t}\n\n\tconst reasons = new Set<RevocationIndeterminateReason>();\n\tfor (const evaluation of ordered) {\n\t\tfor (const reason of evaluation.status.indeterminateReasons ?? []) {\n\t\t\treasons.add(reason);\n\t\t}\n\t}\n\treturn {\n\t\tstatus: {\n\t\t\tcertificate: cert,\n\t\t\tstatus: 'indeterminate',\n\t\t\tindeterminateReasons: [...reasons],\n\t\t},\n\t\texecutionErrors,\n\t};\n}\n\n/**\n * RFC 9608 §4: path validation skips RFC 5280 §6.1.3 step (a)(3) for a\n * certificate carrying noRevAvail or id-pkix-ocsp-nocheck, read from its\n * signed DER.\n */\nfunction revocationSkipReason(\n\tcertificate: ParsedCertificate,\n): 'no_rev_avail' | 'ocsp_nocheck' | undefined {\n\tconst signed = parseCertificateDer(certificate.der);\n\tif (!signed.ok) return undefined;\n\tif (signed.value.noRevAvail === true) return 'no_rev_avail';\n\treturn carriesOcspNoCheck(signed.value) ? 'ocsp_nocheck' : undefined;\n}\n\n// Function\n\n/**\n * Checks revocation status for all certificates in a validated chain.\n *\n * Evaluates CRL and OCSP evidence against each certificate (except the trust\n * anchor), applies the revocation policy, and returns a unified decision. A\n * certificate carrying noRevAvail or id-pkix-ocsp-nocheck is reported as\n * `skipped` without consulting evidence (RFC 9608 §4).\n *\n * @example\n * ```ts\n * const result = await checkChainRevocation({\n * chain: validatedChain,\n * crls: [crl1, crl2],\n * ocspResponses: [ocspResponseDer],\n * policy: { mode: 'hard-fail' },\n * });\n * if (result.value.decision === 'deny') {\n * console.log('Revocation check failed');\n * }\n * ```\n */\nexport async function checkChainRevocation(\n\tinput: CheckChainRevocationInput,\n): Promise<CheckChainRevocationResult> {\n\tconst { chain, policy, crls = [], extraCertificates = [], at = new Date() } = input;\n\tassertCrlMaxAge(policy?.crlMaxAgeMs);\n\tconst mode = policy?.mode ?? 'hard-fail';\n\n\t// Empty chain → allow\n\tif (chain.length === 0) {\n\t\treturn {\n\t\t\tok: true,\n\t\t\tvalue: {\n\t\t\t\tdecision: 'allow',\n\t\t\t\tsummary: { revokedCertificates: [], indeterminateCertificates: [] },\n\t\t\t\tcertificates: [],\n\t\t\t},\n\t\t};\n\t}\n\n\t// Create signer validation context with memoization cache\n\t// This cache is shared across all certificate checks in this chain evaluation\n\tconst signerCtx: SignerValidationContext = {\n\t\tcache: new Map(),\n\t\tchain,\n\t\tcrls,\n\t\textraCertificates,\n\t\tat,\n\t\tcrlMaxAgeMs: policy?.crlMaxAgeMs,\n\t\tclockSkewMs: policy?.clockSkewMs,\n\t\tunrecognizedReasonCode: policy?.unrecognizedReasonCode ?? 'revoked',\n\t};\n\tconst deltaBudget: DeltaCrlBudget = { remaining: DELTA_CRL_ATTEMPTS_PER_CHAIN };\n\n\t// Skip trust anchor (last cert) — it's the trust base\n\tconst certsToCheck = chain.slice(0, -1);\n\tconst certificates: CertificateRevocationStatus[] = [];\n\tconst revokedCertificates: ParsedCertificate[] = [];\n\tconst indeterminateCertificates: ParsedCertificate[] = [];\n\tconst allExecutionErrors: RevocationExecutionError[] = [];\n\n\tfor (let i = 0; i < certsToCheck.length; i++) {\n\t\tconst cert = certsToCheck[i];\n\t\tconst issuer = chain[i + 1]; // Next cert in chain is the issuer\n\t\tif (cert === undefined || issuer === undefined) {\n\t\t\tcontinue; // Should never happen given loop bounds\n\t\t}\n\n\t\tconst skipReason = revocationSkipReason(cert);\n\t\tif (skipReason !== undefined) {\n\t\t\tcertificates.push({ certificate: cert, status: 'skipped', skipReason });\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst { status, executionErrors } = await evaluateCertificateRevocation(\n\t\t\tcert,\n\t\t\tissuer,\n\t\t\tinput,\n\t\t\tsignerCtx,\n\t\t\tdeltaBudget,\n\t\t);\n\t\tcertificates.push(status);\n\t\tallExecutionErrors.push(...executionErrors);\n\n\t\tif (status.status === 'revoked') {\n\t\t\trevokedCertificates.push(cert);\n\t\t} else if (status.status === 'indeterminate') {\n\t\t\tindeterminateCertificates.push(cert);\n\t\t}\n\t}\n\n\t// Apply policy\n\tconst hasRevoked = revokedCertificates.length > 0;\n\tconst hasIndeterminate = indeterminateCertificates.length > 0;\n\tconst decision: 'allow' | 'deny' = hasRevoked\n\t\t? 'deny'\n\t\t: hasIndeterminate && mode === 'hard-fail'\n\t\t\t? 'deny'\n\t\t\t: 'allow';\n\n\treturn {\n\t\tok: true,\n\t\tvalue: {\n\t\t\tdecision,\n\t\t\tsummary: { revokedCertificates, indeterminateCertificates },\n\t\t\tcertificates,\n\t\t\t...(allExecutionErrors.length > 0 ? { executionErrors: allExecutionErrors } : {}),\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8LA,MAAaC,IAAmC;CAE/C;CACA;CAEA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CAEA;CAEA;CACA;CAEA;CACA;AACD;;;;AAoKA,SAAS,qBAAqB,GAAoE;CACjG,IAAI;EACH,OAAOC,EAA2BC,CAAM;CACzC,QAAQ;EACP;CACD;AACD;;;;;AAMA,SAAS,gBAAgB,GAAsB,GAA+B;CAC7E,IAAIC,EAAE,IAAI,WAAWC,EAAE,IAAI,QAAQ,OAAO;CAC1C,KAAK,IAAIC,IAAI,GAAGA,IAAIF,EAAE,IAAI,QAAQ,KACjC,IAAIA,EAAE,IAAIE,OAAOD,EAAE,IAAIC,IAAI,OAAO;CAEnC,OAAO;AACR;;;;;;;AAQA,SAAS,uBACR,GACA,GACA,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2E,EAAoB,KAAKzG,CAAI,IACnB8B,EAAO,WAAW,mBAC5B4E,EAA0B,KAAK1G,CAAI;CAErC;CAGA,IAAM6G,IAAaJ,EAAoB,SAAS,GAC1CK,IAAmBJ,EAA0B,SAAS;CAO5D,OAAO;EACN,IAAI;EACJ,OAAO;GACN,UATiCG,KAEhCC,KAAoBR,MAAS,cAD7B,SAGC;GAMF,SAAS;IAAE;IAAqB;GAA0B;GAC1D;GACA,GAAIK,EAAmB,SAAS,IAAI,EAAE,iBAAiBA,EAAmB,IAAI,CAAC;EAChF;CACD;AACD"}
1
+ {"version":3,"file":"chain.js","names":["_exhaustive","DECODE_REFUSAL_CODES","toHex","decodeRefusalOf","resolveSignatureVerifiers","compareDistinguishedNames","createSpkiDistrustCheck","anchorWorkingKey","carriesTrustAnchorKey","certificateWorkingKey","pathWorkingKey","workingParametersAt","assertClockSkew","assertCrlMaxAge","authenticateCrl","checkCertificateRevocationAgainstCrlsBy","coversAllDistributionPointReasons","distinctSignedCrls","isCrlApplicableTo","normalizeCrl","revocationReasonFromCode","parseOcspResponseDerOrThrow","parseOcspResponsePemOrThrow","revocationSkipReasonOf","validateOcspResponseBy","verifyCertificateChain","parseCertificateDer","parseCertificateFromSource","a","b","certificate","trustAnchor","signer","REVOCATION_INDETERMINATE_REASONS","source","i","crl","extraCertificates","chain","parsedExtras","parsed","candidates","matches","candidate","existing","value","at","ctx","c","pool","index","result","path","member","key","issuer","known","anchorKey","top","cert","cached","signerIssuer","signerRevocation","status","issuerStatus","coveredReasons","sawUnsettledEvidence","crls","deltaCrls","outcome","reason","SIGNER_CRL_NO_EVIDENCE","authority","budgets","selfSigned","subject","point","name","thisUpdate","revocationDate","reasonCode","error","fallbackMessage","entry","single","current","unrecognizedReasonCode","freshestGoodThisUpdate","reasons","executionErrors","code","OCSP_RESPONDER_FAILURE_CODES","policy","response","input","signerCtx","context","trustedOcspResponders","trusted","trustedIssuer","ocspIssuer","shared","primary","responder","retry","ocspResponses","state","applicable","validation","evidence","freshestHold","params","baseCrl","crlMaxAgeMs","clockSkewMs","deltaBudget","authorized","verification","resolved","verdict","NEXT_CRL_SIGNER_CANDIDATE","signerStatus","revoked","parsedCrls","baseCrls","blockingReasons","crlSource","unreadSupersededDeltaCrls","indirect","GOOD_BLOCKING_REASONS","prefer","ocsp","ordered","evaluation","good","blocked","next","signed","verifiers","pathKeys","chainKeys","mode","certificates","revokedCertificates","indeterminateCertificates","allExecutionErrors","skipReason","hasRevoked","hasIndeterminate"],"sources":["../../src/revocation/chain.ts"],"sourcesContent":["/**\n * Chain-level revocation orchestration.\n *\n * Evaluates CRL and OCSP evidence for an entire validated certificate chain,\n * implementing the revocation checking portion of RFC 5280 §6.3.\n *\n * @see {@link https://datatracker.ietf.org/doc/html/rfc5280#section-6.3 | RFC 5280 §6.3 CRL Validation}\n * @module\n */\n\nimport { toHex } from '#micro509/internal/asn1/asn1';\nimport { DECODE_REFUSAL_CODES, decodeRefusalOf } from '#micro509/internal/asn1/decode-refusal';\nimport type {\n\tCallerVerification,\n\tSignatureVerifier,\n\tSignatureVerifiers,\n} from '#micro509/internal/crypto/sig-verify';\nimport { resolveSignatureVerifiers } from '#micro509/internal/crypto/sig-verify';\nimport { compareDistinguishedNames } from '#micro509/internal/shared/dn';\nimport { createSpkiDistrustCheck } from '#micro509/internal/verify/spki-distrust';\nimport type { WorkingPublicKey } from '#micro509/internal/verify/verify-path';\nimport {\n\tanchorWorkingKey,\n\tcarriesTrustAnchorKey,\n\tcertificateWorkingKey,\n\tpathWorkingKey,\n\tworkingParametersAt,\n} from '#micro509/internal/verify/verify-path';\nimport type { DecodeFailureCode } from '#micro509/result/result';\nimport type {\n\tCrlSource,\n\tcheckCertificateRevocationAgainstCrl,\n\tDeltaCrlBudget,\n\tParsedCertificateRevocationList,\n\tParsedRevocationReason,\n\tSupersededDeltaCrlPolicy,\n\tUnrecognizedReasonCodePolicy,\n} from '#micro509/revocation/crl';\nimport {\n\tassertClockSkew,\n\tassertCrlMaxAge,\n\tauthenticateCrl,\n\tcheckCertificateRevocationAgainstCrlsBy,\n\tcoversAllDistributionPointReasons,\n\tDELTA_CRL_ATTEMPTS_PER_CALL,\n\tdistinctSignedCrls,\n\tisCrlApplicableTo,\n\tnormalizeCrl,\n\trevocationReasonFromCode,\n} from '#micro509/revocation/crl';\nimport type {\n\tOcspResponderRevocationPolicy,\n\tParsedOcspResponse,\n\tParsedOcspSingleResponse,\n\tRevocationSkipReason,\n\tValidateOcspResponseFailure,\n\tValidateOcspResponseInput,\n\tValidateOcspResponseResult,\n} from '#micro509/revocation/ocsp';\nimport {\n\tparseOcspResponseDerOrThrow,\n\tparseOcspResponsePemOrThrow,\n\trevocationSkipReasonOf,\n\tvalidateOcspResponseBy,\n} from '#micro509/revocation/ocsp';\nimport type { RevocationCertificateSource } from '#micro509/revocation/revocation';\nimport type { CandidatePath, TrustAnchor } from '#micro509/verify/verify';\nimport { verifyCertificateChain } from '#micro509/verify/verify';\nimport type { DistributionPointReason } from '#micro509/x509/extensions';\nimport type { ParsedCertificate } from '#micro509/x509/parse';\nimport { parseCertificateDer, parseCertificateFromSource } from '#micro509/x509/parse';\n\nexport type { CrlSource };\n\n// Input Types\n\n/**\n * OCSP response in any supported format.\n *\n * Accepts PEM string or DER bytes. Used for\n * {@linkcode CheckChainRevocationInput.ocspResponses}.\n */\nexport type OcspResponseSource = string | Uint8Array;\n\n/** A locally trusted OCSP responder bound to the CA scope it may serve. */\nexport interface TrustedOcspResponder {\n\t/** Certificate of the CA for whose certificates the responder is trusted. */\n\treadonly issuerCertificate: RevocationCertificateSource;\n\t/** Responder certificate trusted within that issuer's scope. */\n\treadonly responderCertificate: RevocationCertificateSource;\n}\n\n/**\n * Revocation checking policy for {@linkcode checkChainRevocation}.\n *\n * Controls how indeterminate results (missing evidence, expired CRLs) affect\n * the final {@linkcode CheckChainRevocationValue.decision | decision}.\n */\nexport interface RevocationPolicy {\n\t/**\n\t * How to handle indeterminate status.\n\t *\n\t * - `'hard-fail'`: indeterminate certificates cause denial (default)\n\t * - `'soft-fail'`: indeterminate certificates are allowed — an explicit\n\t * availability/compatibility choice\n\t *\n\t * Revocation checking itself is opt-in: no check runs unless evidence is\n\t * supplied. Once it is, indeterminate status denies by default.\n\t */\n\treadonly mode?: 'soft-fail' | 'hard-fail';\n\t/**\n\t * Evidence preference when multiple sources are available.\n\t *\n\t * Both evidence kinds are always evaluated, and a validated `revoked`\n\t * verdict from either source wins regardless of preference (fail-closed).\n\t * Preference only decides which source's `good` verdict is reported when\n\t * both yield one.\n\t *\n\t * - `'best-available'`: the source with the fresher evidence — the later\n\t * `thisUpdate` on the validated OCSP entry or CRL — is reported; ties\n\t * favor OCSP (default)\n\t * - `'ocsp'`: prefer OCSP over CRL\n\t * - `'crl'`: prefer CRL over OCSP\n\t */\n\treadonly prefer?: 'ocsp' | 'crl' | 'best-available';\n\t/**\n\t * Revocation policy for delegated OCSP responder certificates\n\t * (RFC 6960 §4.2.2.2.1). Supplied CRLs double as responder revocation\n\t * evidence. Defaults to `'nocheck-or-evidence'`.\n\t */\n\treadonly ocspResponderRevocation?: OcspResponderRevocationPolicy;\n\t/**\n\t * Maximum age of a CRL's `thisUpdate` at the evaluation time, in\n\t * milliseconds. An older CRL, or one without `nextUpdate` when this is\n\t * unset, settles only a revocation other than certificateHold of an\n\t * unexpired certificate (RFC 5280 §5.3.1). Applies to CRLs for chain\n\t * certificates, CRL signers and delegated OCSP responders. Unbounded by\n\t * default. RFC 5280 §3.3 leaves the required recency of revocation data to\n\t * local policy.\n\t */\n\treadonly crlMaxAgeMs?: number;\n\t/**\n\t * Clock-skew tolerance in milliseconds for CRL and OCSP `thisUpdate`/\n\t * `nextUpdate` checks. It also widens `crlMaxAgeMs` by the same amount.\n\t * Defaults to `0`. Throws `RangeError` when negative or not finite.\n\t */\n\treadonly clockSkewMs?: number;\n\t/**\n\t * OCSP client profile for every OCSP response. See\n\t * {@linkcode ValidateOcspResponseInput.profile}. `'rfc9919'` turns a\n\t * response without `nextUpdate` into `ocsp_next_update_missing`. Defaults\n\t * to `'rfc6960'`.\n\t */\n\treadonly ocspProfile?: ValidateOcspResponseInput['profile'];\n\t/**\n\t * Treatment of CRL entries and OCSP responses whose CRLReason is\n\t * unrecognized, including the CRLs for CRL signers and delegated OCSP\n\t * responders. See {@linkcode UnrecognizedReasonCodePolicy}. `'reject'`\n\t * makes that evidence yield `crl_reason_code_unrecognized` or\n\t * `ocsp_reason_code_unrecognized`, which outranks a `good` verdict from\n\t * other evidence. Defaults to `'revoked'`.\n\t */\n\treadonly unrecognizedReasonCode?: UnrecognizedReasonCodePolicy;\n\t/**\n\t * Whether a CRL that a delegated CRL signer signed may establish that\n\t * signer's own status. RFC 5280 §6.3.3 (f) and X.509 (2019) §9.1.5 leave\n\t * it open.\n\t *\n\t * - `'delegated'`: only when the signer's cRLDistributionPoints names the\n\t * signer as cRLIssuer, the delegation PKITS 4.14.30 validates (default)\n\t * - `'any'`: any such CRL that covers the signer, such as one under its\n\t * issuer's name signed with the signer's separate CRL key\n\t *\n\t * A revocation of the signer in such a CRL counts under either value.\n\t */\n\treadonly crlSignerSelfEvidence?: 'delegated' | 'any';\n\t/**\n\t * Treatment of delta CRLs that the attempt limits leave unread although\n\t * one already read supersedes them, for the chain, its CRL signers and its\n\t * delegated OCSP responders. See {@linkcode SupersededDeltaCrlPolicy}.\n\t * Defaults to `'indeterminate'`.\n\t */\n\treadonly unreadSupersededDeltaCrls?: SupersededDeltaCrlPolicy;\n}\n\n/** Input for {@linkcode checkChainRevocation}. */\nexport interface CheckChainRevocationInput {\n\t/** Validated certificate chain (leaf first, root last). */\n\treadonly chain: readonly ParsedCertificate[];\n\t/** CRLs to evaluate. */\n\treadonly crls?: readonly CrlSource[];\n\t/** OCSP responses to evaluate. */\n\treadonly ocspResponses?: readonly OcspResponseSource[];\n\t/** Extra certs for indirect CRL issuers / delegated OCSP responders. */\n\treadonly extraCertificates?: readonly RevocationCertificateSource[];\n\t/**\n\t * Explicitly trusted OCSP responder certificates (RFC 6960 §4.2.2.2\n\t * criterion 1), each bound to the issuing CA for which it is authorized.\n\t * A response signed by a matching responder is accepted without delegated-\n\t * responder issuance, EKU, and revocation checks only in that issuer scope.\n\t */\n\treadonly trustedOcspResponders?: readonly TrustedOcspResponder[];\n\t/** Evaluation time. Defaults to `new Date()`. */\n\treadonly at?: Date;\n\t/** Revocation policy. */\n\treadonly policy?: RevocationPolicy;\n\t/**\n\t * Caller verifiers for signature algorithms micro509 does not verify through\n\t * WebCrypto, keyed by dotted-decimal signature algorithm OID, for CRL and OCSP\n\t * signatures and the signer paths checked here. A CRL or OCSP signer inside\n\t * `chain` verifies with the key parameters it inherits along `chain`\n\t * (RFC 5280 §6.1.4 (e)). A key that micro509 verifies natively, a key that is\n\t * no OID, or a value that is no function throws `RangeError`.\n\t */\n\treadonly signatureVerifiers?: SignatureVerifiers;\n\t/**\n\t * SHA-256 hashes of complete DER SubjectPublicKeyInfo values to distrust in\n\t * the certification paths of CRL signers and delegated OCSP responders\n\t * outside `chain`. Supply 64 hexadecimal characters per hash\n\t * (case-insensitive, no separators). Defaults to an empty list. Malformed\n\t * entries throw RangeError. A signer whose path carries one yields no\n\t * evidence.\n\t */\n\treadonly distrustedSpkiSha256?: readonly string[];\n\t/**\n\t * The bare trust anchor that issued the last certificate of `chain`, when\n\t * the path ends below one (RFC 5280 §6.1.1 (d)). The last certificate is\n\t * then certificate 1 of the path and is checked too (RFC 5280 §6.1.3\n\t * (a)(3)), with the anchor as its issuer: its key signs CRLs and OCSP\n\t * responses and certifies delegated signers (X.509 (2019) §7.5). Omitted,\n\t * the last certificate of `chain` is the trust anchor and is not checked. A\n\t * chain that ends with the anchor's own certificate, or whose last\n\t * certificate the anchor did not issue, throws `RangeError`.\n\t */\n\treadonly trustAnchor?: TrustAnchor;\n}\n\n/**\n * The issuer of a certificate under check: the next certificate of the chain,\n * or the bare trust anchor above it.\n */\ntype RevocationIssuer =\n\t| { readonly kind: 'certificate'; readonly certificate: ParsedCertificate }\n\t| { readonly kind: 'trust_anchor'; readonly trustAnchor: TrustAnchor };\n\nfunction sameIssuer(a: RevocationIssuer, b: RevocationIssuer): boolean {\n\tif (a.kind === 'certificate' && b.kind === 'certificate') {\n\t\treturn sameCertificate(a.certificate, b.certificate);\n\t}\n\treturn a.kind === 'trust_anchor' && b.kind === 'trust_anchor' && a.trustAnchor === b.trustAnchor;\n}\n\n/** `certificate` as an issuer: the bare trust anchor when it carries the anchor's name and key. */\nfunction issuerOf(\n\tcertificate: ParsedCertificate,\n\ttrustAnchor: TrustAnchor | undefined,\n): RevocationIssuer {\n\treturn trustAnchor !== undefined && carriesTrustAnchorKey(certificate, trustAnchor)\n\t\t? { kind: 'trust_anchor', trustAnchor }\n\t\t: { kind: 'certificate', certificate };\n}\n\n/** The certificate that signed CRL or OCSP evidence, for its `source`. */\nfunction signerCertificateOf(\n\tsigner: RevocationIssuer,\n): { readonly signerCertificate: ParsedCertificate } | Record<never, never> {\n\treturn signer.kind === 'certificate' ? { signerCertificate: signer.certificate } : {};\n}\n\n// Output Types\n\n/**\n * Granular reasons why revocation status could not be determined.\n *\n * Returned in {@linkcode CertificateRevocationStatus}'s `indeterminateReasons`\n * when `status` is `'indeterminate'`. Grouped by category:\n *\n * - **Evidence not found**: `no_applicable_crl`, `no_applicable_ocsp`\n * - **Scope mismatch**: `distribution_point_mismatch`, `issuer_name_mismatch`,\n * `reason_scope_mismatch`, `indirect_crl_scope_mismatch`, `reason_coverage_incomplete`\n * - **Signer trust**: `crl_signer_not_found`, `crl_signer_not_authorized`,\n * `crl_signer_revoked`, `crl_signer_indeterminate`, and OCSP equivalents\n * - **Freshness**: `crl_expired`, `ocsp_response_expired`,\n * `ocsp_next_update_missing`\n * - **Delta CRL**: `delta_crl_unusable` when an authenticated, current delta\n * CRL cannot settle the status, `delta_crl_retry_limit_exceeded` when the\n * attempt limits leave a delta CRL candidate unread that counts under\n * `unreadSupersededDeltaCrls`. Either one outranks a\n * `good` verdict from other evidence.\n * - **Reason code**: `crl_reason_code_unrecognized` and\n * `ocsp_reason_code_unrecognized` when evidence revokes the certificate with\n * an unrecognized CRLReason under `unrecognizedReasonCode: 'reject'`. Either\n * one outranks a `good` verdict from other evidence.\n */\nexport const REVOCATION_INDETERMINATE_REASONS = [\n\t// Evidence not found\n\t'no_applicable_crl',\n\t'no_applicable_ocsp',\n\t// Scope issues\n\t'distribution_point_mismatch',\n\t'issuer_name_mismatch',\n\t'reason_scope_mismatch',\n\t'indirect_crl_scope_mismatch',\n\t'reason_coverage_incomplete',\n\t// Signer trust issues\n\t'crl_signer_not_found',\n\t'crl_signer_not_authorized',\n\t'crl_signer_revoked',\n\t'crl_signer_indeterminate',\n\t'ocsp_responder_not_found',\n\t'ocsp_responder_not_authorized',\n\t'ocsp_responder_revoked',\n\t'ocsp_responder_indeterminate',\n\t// Freshness\n\t'crl_expired',\n\t'ocsp_response_expired',\n\t'ocsp_next_update_missing',\n\t// OCSP specific\n\t'ocsp_status_unknown',\n\t// Delta CRL\n\t'delta_crl_unusable',\n\t'delta_crl_retry_limit_exceeded',\n\t// Reason code\n\t'crl_reason_code_unrecognized',\n\t'ocsp_reason_code_unrecognized',\n] as const;\n\n/** See the doc comment above {@linkcode REVOCATION_INDETERMINATE_REASONS}. */\nexport type RevocationIndeterminateReason = (typeof REVOCATION_INDETERMINATE_REASONS)[number];\n\n/**\n * Identifies the source of revocation evidence.\n *\n * Included in {@linkcode CertificateRevocationStatus}'s `source` when status is\n * `'good'` or `'revoked'` to indicate which CRL or OCSP response provided the answer.\n */\nexport interface RevocationSource {\n\t/** Whether evidence came from a CRL or OCSP response. */\n\treadonly kind: 'crl' | 'ocsp';\n\t/** Certificate that signed the evidence (CRL issuer or OCSP responder). */\n\treadonly signerCertificate?: ParsedCertificate;\n\t/** Identifier for debugging (e.g., CRL issuer DN or OCSP responder URL). */\n\treadonly evidenceIdentifier?: string;\n\t/**\n\t * `thisUpdate` of the evidence backing the verdict — the OCSP single\n\t * response entry or the freshest contributing CRL (an applied delta CRL\n\t * supersedes its base). This is the timestamp `'best-available'` compares.\n\t */\n\treadonly thisUpdate?: Date;\n}\n\n/**\n * Revocation evaluation result for a single certificate.\n *\n * One entry per certificate in {@linkcode CheckChainRevocationValue.certificates}.\n * The trust anchor is excluded (never checked for revocation).\n */\nexport type CertificateRevocationStatus =\n\t| {\n\t\t\t/** The certificate that was evaluated. */\n\t\t\treadonly certificate: ParsedCertificate;\n\t\t\t/** Evidence confirms the certificate is not revoked. */\n\t\t\treadonly status: 'good';\n\t\t\t/** Evidence that produced the verdict. */\n\t\t\treadonly source: RevocationSource;\n\t\t\t/** Never present on a `good` verdict. */\n\t\t\treadonly indeterminateReasons?: undefined;\n\t\t\t/** Never present on a `good` verdict. */\n\t\t\treadonly revocationInfo?: undefined;\n\t }\n\t| {\n\t\t\t/** The certificate that was evaluated. */\n\t\t\treadonly certificate: ParsedCertificate;\n\t\t\t/** Evidence confirms the certificate is revoked. */\n\t\t\treadonly status: 'revoked';\n\t\t\t/** Evidence that produced the verdict. */\n\t\t\treadonly source: RevocationSource;\n\t\t\t/** Revocation details from the CRL entry or OCSP response. */\n\t\t\treadonly revocationInfo: {\n\t\t\t\t/** When the certificate was revoked. */\n\t\t\t\treadonly revocationDate: Date;\n\t\t\t\t/** RFC 5280 CRLReason code, if provided by the CRL/OCSP response. */\n\t\t\t\treadonly reason?: ParsedRevocationReason;\n\t\t\t};\n\t\t\t/** Never present on a `revoked` verdict. */\n\t\t\treadonly indeterminateReasons?: undefined;\n\t }\n\t| {\n\t\t\t/** The certificate that was evaluated. */\n\t\t\treadonly certificate: ParsedCertificate;\n\t\t\t/** Revocation status could not be determined. */\n\t\t\treadonly status: 'indeterminate';\n\t\t\t/** Why status could not be determined. */\n\t\t\treadonly indeterminateReasons: readonly RevocationIndeterminateReason[];\n\t\t\t/** Never present on an `indeterminate` verdict. */\n\t\t\treadonly source?: undefined;\n\t\t\t/** Never present on an `indeterminate` verdict. */\n\t\t\treadonly revocationInfo?: undefined;\n\t }\n\t| {\n\t\t\t/** The certificate that was evaluated. */\n\t\t\treadonly certificate: ParsedCertificate;\n\t\t\t/** Revocation checking does not apply to the certificate (RFC 9608 §4). */\n\t\t\treadonly status: 'skipped';\n\t\t\t/**\n\t\t\t * The extension that exempts the certificate: `'no_rev_avail'` for\n\t\t\t * noRevAvail (RFC 9608 §2) or `'ocsp_nocheck'` for id-pkix-ocsp-nocheck.\n\t\t\t */\n\t\t\treadonly skipReason: RevocationSkipReason;\n\t\t\t/** Never present on a `skipped` verdict. */\n\t\t\treadonly source?: undefined;\n\t\t\t/** Never present on a `skipped` verdict. */\n\t\t\treadonly indeterminateReasons?: undefined;\n\t\t\t/** Never present on a `skipped` verdict. */\n\t\t\treadonly revocationInfo?: undefined;\n\t };\n\n/**\n * Errors encountered while processing revocation evidence.\n *\n * Distinct from {@linkcode RevocationIndeterminateReason}: execution errors are\n * code failures (malformed CRL, unsupported extension) rather than evaluation\n * outcomes (CRL doesn't cover this certificate).\n *\n * Collected in {@linkcode CheckChainRevocationValue.executionErrors}.\n */\nexport type RevocationExecutionError = RevocationParseError | RevocationProcessingError;\n\n/** Revocation evidence that did not parse. */\nexport interface RevocationParseError {\n\t/** Error category. */\n\treadonly kind: 'parse_error';\n\t/** `malformed`, or the refusal for evidence micro509 does not decode. */\n\treadonly code: DecodeFailureCode;\n\t/** Human-readable error description. */\n\treadonly message: string;\n\t/** Which evidence caused the error (e.g., CRL issuer DN). */\n\treadonly evidenceIdentifier?: string;\n}\n\n/** Revocation evidence that parsed but could not be processed. */\nexport interface RevocationProcessingError {\n\t/** Error category. */\n\treadonly kind: 'unsupported_extension' | 'internal_error';\n\t/** Human-readable error description. */\n\treadonly message: string;\n\t/** Which evidence caused the error (e.g., CRL issuer DN). */\n\treadonly evidenceIdentifier?: string;\n}\n\n/**\n * Detailed revocation check results.\n *\n * Returned as {@linkcode CheckChainRevocationResult.value} from\n * {@linkcode checkChainRevocation}. Contains both the policy decision and\n * detailed per-certificate findings for debugging.\n */\nexport interface CheckChainRevocationValue {\n\t/**\n\t * Final policy decision based on {@linkcode RevocationPolicy}.\n\t *\n\t * - `'allow'`: chain passes revocation check\n\t * - `'deny'`: chain fails (revoked certificate or hard-fail on indeterminate)\n\t */\n\treadonly decision: 'allow' | 'deny';\n\t/** Quick-access summary of problematic certificates. */\n\treadonly summary: {\n\t\t/** Certificates confirmed as revoked. */\n\t\treadonly revokedCertificates: readonly ParsedCertificate[];\n\t\t/** Certificates whose status could not be determined. */\n\t\treadonly indeterminateCertificates: readonly ParsedCertificate[];\n\t};\n\t/** Per-certificate evaluation results. See {@linkcode CertificateRevocationStatus}. */\n\treadonly certificates: readonly CertificateRevocationStatus[];\n\t/** Evidence that could not be processed. See {@linkcode RevocationExecutionError}. */\n\treadonly executionErrors?: readonly RevocationExecutionError[];\n}\n\n/** Result type for {@linkcode checkChainRevocation}. */\nexport type CheckChainRevocationResult = {\n\treadonly ok: true;\n\treadonly value: CheckChainRevocationValue;\n};\n\n// Helpers\n\n/**\n * Parses a certificate from various source formats, returning undefined on failure.\n */\nfunction parseCertificateSafe(source: RevocationCertificateSource): ParsedCertificate | undefined {\n\ttry {\n\t\treturn parseCertificateFromSource(source);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * Compares two certificates by DER bytes for identity.\n * Reference equality fails when same cert is parsed from different sources.\n */\nfunction sameCertificate(a: ParsedCertificate, b: ParsedCertificate): boolean {\n\tif (a.der.length !== b.der.length) return false;\n\tfor (let i = 0; i < a.der.length; i++) {\n\t\tif (a.der[i] !== b.der[i]) return false;\n\t}\n\treturn true;\n}\n\n/**\n * Yields every certificate that could have signed the given CRL, AKI/SKI\n * matches before DN matches. All candidates are returned so a certificate whose\n * subject DN collides with the genuine CRL issuer cannot shadow it: each is\n * tried against the CRL signature and its own path to the trust anchor.\n */\nfunction findIndirectCrlIssuers(\n\tcrl: ParsedCertificateRevocationList,\n\textraCertificates: readonly RevocationCertificateSource[],\n\tchain: readonly ParsedCertificate[],\n): readonly ParsedCertificate[] {\n\tconst parsedExtras: ParsedCertificate[] = [];\n\tfor (const source of extraCertificates) {\n\t\tconst parsed = parseCertificateSafe(source);\n\t\tif (parsed !== undefined) {\n\t\t\tparsedExtras.push(parsed);\n\t\t}\n\t}\n\n\tconst candidates = [...parsedExtras, ...chain];\n\tconst matches: ParsedCertificate[] = [];\n\tconst push = (candidate: ParsedCertificate): void => {\n\t\tif (!matches.some((existing) => sameCertificate(existing, candidate))) {\n\t\t\tmatches.push(candidate);\n\t\t}\n\t};\n\n\tif (crl.authorityKeyIdentifier !== undefined) {\n\t\tfor (const candidate of candidates) {\n\t\t\tif (\n\t\t\t\tcandidate.subjectKeyIdentifier !== undefined &&\n\t\t\t\tnormalizeHex(crl.authorityKeyIdentifier) === normalizeHex(candidate.subjectKeyIdentifier)\n\t\t\t) {\n\t\t\t\tpush(candidate);\n\t\t\t}\n\t\t}\n\t}\n\tfor (const candidate of candidates) {\n\t\tif (crl.issuer.derHex === candidate.subject.derHex) {\n\t\t\tpush(candidate);\n\t\t}\n\t}\n\n\treturn matches;\n}\n\n/** Lowercases a hex string for bytewise comparison. */\nfunction normalizeHex(value: string): string {\n\treturn value.toLowerCase();\n}\n\n/**\n * RFC 5280 §6.3.3(f): confirms the CRL issuer certificate has a valid\n * certification path to the same trust anchor as the certificate under test. A\n * signer already inside the validated chain is authorized by construction. The\n * path check runs without revocation to avoid unbounded recursion.\n */\nasync function crlSignerChainsToAnchor(\n\tcandidate: RevocationIssuer,\n\tchain: readonly ParsedCertificate[],\n\textraCertificates: readonly RevocationCertificateSource[],\n\tat: Date,\n\tctx: SignerValidationContext,\n): Promise<boolean> {\n\tif (candidate.kind === 'trust_anchor') {\n\t\treturn true;\n\t}\n\tconst signer = candidate.certificate;\n\tif (chain.some((c) => sameCertificate(c, signer))) {\n\t\treturn true;\n\t}\n\tif (ctx.trustAnchor !== undefined) {\n\t\treturn await chainsToBareAnchor(signer, chain, extraCertificates, at, ctx.trustAnchor, ctx);\n\t}\n\tconst trustAnchor = chain[chain.length - 1];\n\tif (trustAnchor === undefined) {\n\t\treturn false;\n\t}\n\t// The signer's issuer may be a validated chain certificate (a delegated\n\t// signer issued by an intermediate), so pool the non-anchor chain members\n\t// with the extras. Exclude the signer and the anchor.\n\tconst pool: ParsedCertificate[] = [];\n\tconst addCandidate = (parsed: ParsedCertificate): void => {\n\t\tif (sameCertificate(parsed, signer) || sameCertificate(parsed, trustAnchor)) {\n\t\t\treturn;\n\t\t}\n\t\tif (!pool.some((existing) => sameCertificate(existing, parsed))) {\n\t\t\tpool.push(parsed);\n\t\t}\n\t};\n\tfor (let index = 0; index < chain.length - 1; index += 1) {\n\t\tconst certificate = chain[index];\n\t\tif (certificate !== undefined) {\n\t\t\taddCandidate(certificate);\n\t\t}\n\t}\n\tfor (const source of extraCertificates) {\n\t\tconst parsed = parseCertificateSafe(source);\n\t\tif (parsed !== undefined) {\n\t\t\taddCandidate(parsed);\n\t\t}\n\t}\n\tconst result = await verifyCertificateChain({\n\t\tleaf: signer.der,\n\t\tintermediates: pool.map((certificate) => certificate.der),\n\t\troots: [trustAnchor.der],\n\t\tat,\n\t\t...signerPathOptions(ctx),\n\t});\n\tif (result.ok) recordPathKeys(result.value, ctx);\n\treturn result.ok;\n}\n\n/**\n * Remembers the working key (RFC 5280 §6.1.4 (e)) and the issuer that a\n * signer's validated path gives each of its certificates outside the checked\n * chain.\n */\nfunction recordPathKeys(path: CandidatePath, ctx: SignerValidationContext): void {\n\tpath.chain.forEach((certificate, index) => {\n\t\tif (ctx.chain.some((member) => sameCertificate(member, certificate))) return;\n\t\tconst key = certCacheKey(certificate);\n\t\tctx.pathKeys.set(key, pathWorkingKey(path, index));\n\t\tconst issuer = path.chain[index + 1];\n\t\tif (issuer !== undefined) {\n\t\t\tctx.pathIssuers.set(key, issuerOf(issuer, ctx.trustAnchor));\n\t\t} else if (!path.anchorCertificateInChain) {\n\t\t\tctx.pathIssuers.set(key, { kind: 'trust_anchor', trustAnchor: path.trustAnchor });\n\t\t}\n\t});\n}\n\n/**\n * {@linkcode crlSignerChainsToAnchor} below a bare trust anchor: every chain\n * certificate is a candidate intermediate, and the anchor ends the path.\n */\nasync function chainsToBareAnchor(\n\tsigner: ParsedCertificate,\n\tchain: readonly ParsedCertificate[],\n\textraCertificates: readonly RevocationCertificateSource[],\n\tat: Date,\n\ttrustAnchor: TrustAnchor,\n\tctx: SignerValidationContext,\n): Promise<boolean> {\n\tconst pool: ParsedCertificate[] = [];\n\tfor (const parsed of [...chain, ...extraCertificates.flatMap(parsedOrEmpty)]) {\n\t\tif (!sameCertificate(parsed, signer) && !pool.some((known) => sameCertificate(known, parsed))) {\n\t\t\tpool.push(parsed);\n\t\t}\n\t}\n\tconst result = await verifyCertificateChain({\n\t\tleaf: signer.der,\n\t\tintermediates: pool.map((certificate) => certificate.der),\n\t\troots: [],\n\t\ttrustAnchors: [trustAnchor],\n\t\tat,\n\t\t...signerPathOptions(ctx),\n\t});\n\tif (result.ok) recordPathKeys(result.value, ctx);\n\treturn result.ok;\n}\n\n/** The caller's verifiers and distrust for a signer's certification path. */\nfunction signerPathOptions(ctx: SignerValidationContext): {\n\treadonly signatureVerifiers?: SignatureVerifiers;\n\treadonly distrustedSpkiSha256?: readonly string[];\n} {\n\treturn {\n\t\t...(ctx.signatureVerifiers !== undefined && { signatureVerifiers: ctx.signatureVerifiers }),\n\t\t...(ctx.distrustedSpkiSha256 !== undefined && {\n\t\t\tdistrustedSpkiSha256: ctx.distrustedSpkiSha256,\n\t\t}),\n\t};\n}\n\nfunction parsedOrEmpty(source: RevocationCertificateSource): readonly ParsedCertificate[] {\n\tconst parsed = parseCertificateSafe(source);\n\treturn parsed === undefined ? [] : [parsed];\n}\n\n// CRL Signer Validation (RFC 5280 §6.3.3)\n\n/**\n * State machine for CRL signer validation with memoization.\n * - `visiting`: Currently being checked (cycle detection)\n * - `resolved-valid`: Signer is not revoked\n * - `resolved-revoked`: Signer is revoked\n * - `resolved-indeterminate`: Can't determine signer status\n */\ntype SignerValidationState =\n\t| 'visiting'\n\t| 'resolved-valid'\n\t| 'resolved-revoked'\n\t| 'resolved-indeterminate';\n\n/** Context for CRL signer validation with memoization cache. */\ninterface SignerValidationContext {\n\treadonly cache: Map<string, SignerValidationState>;\n\treadonly chain: readonly ParsedCertificate[];\n\treadonly crls: readonly CrlSource[];\n\treadonly extraCertificates: readonly RevocationCertificateSource[];\n\treadonly at: Date;\n\treadonly crlMaxAgeMs: number | undefined;\n\treadonly clockSkewMs: number | undefined;\n\treadonly unrecognizedReasonCode: UnrecognizedReasonCodePolicy;\n\treadonly crlSignerSelfEvidence: NonNullable<RevocationPolicy['crlSignerSelfEvidence']>;\n\treadonly unreadSupersededDeltaCrls: SupersededDeltaCrlPolicy;\n\treadonly signatureVerifiers: SignatureVerifiers | undefined;\n\treadonly distrustedSpkiSha256: readonly string[] | undefined;\n\treadonly verifiers: ReadonlyMap<string, SignatureVerifier>;\n\t/** Delta CRL checks left for the whole chain. */\n\treadonly deltaBudget: DeltaCrlBudget;\n\t/** The RFC 5280 §6.1 working key of a CRL or OCSP signer. */\n\treadonly workingKeyOf: (certificate: ParsedCertificate) => WorkingPublicKey;\n\t/** Working keys of signers outside the chain, from their validated paths. */\n\treadonly pathKeys: Map<string, WorkingPublicKey>;\n\t/** Issuers of signers outside the chain, from their validated paths. */\n\treadonly pathIssuers: Map<string, RevocationIssuer>;\n\t/** The bare trust anchor above the chain, when it ends below one. */\n\treadonly trustAnchor: TrustAnchor | undefined;\n}\n\n/** Caller verification for a signature by `signer`, with its working key parameters. */\nfunction signerVerification(\n\tctx: SignerValidationContext,\n\tsigner: RevocationIssuer,\n): CallerVerification {\n\treturn {\n\t\tverifiers: ctx.verifiers,\n\t\tworkingParameters: {\n\t\t\tparametersDer:\n\t\t\t\tsigner.kind === 'trust_anchor'\n\t\t\t\t\t? anchorWorkingKey(signer.trustAnchor).parametersDer\n\t\t\t\t\t: ctx.workingKeyOf(signer.certificate).parametersDer,\n\t\t},\n\t};\n}\n\n/**\n * Working keys along `chain`: a member inherits key parameters from the members\n * above it (RFC 5280 §6.1.4 (e)); any other certificate keeps its own.\n */\nfunction chainWorkingKeys(\n\tchain: readonly ParsedCertificate[],\n\tanchorKey: WorkingPublicKey | undefined,\n): (certificate: ParsedCertificate) => WorkingPublicKey {\n\tconst top = chain[chain.length - 1];\n\treturn (certificate) => {\n\t\tconst index = chain.findIndex((member) => sameCertificate(member, certificate));\n\t\tif (top === undefined || index < 0) return certificateWorkingKey(certificate);\n\t\treturn {\n\t\t\talgorithmOid: certificate.publicKeyAlgorithmOid,\n\t\t\tparametersDer:\n\t\t\t\tanchorKey === undefined\n\t\t\t\t\t? workingParametersAt(chain, index, chain.length - 2, certificateWorkingKey(top))\n\t\t\t\t\t: workingParametersAt(chain, index, chain.length - 1, anchorKey),\n\t\t};\n\t};\n}\n\n/** A cache key for a certificate: its DER, so two certificates never share one. */\nfunction certCacheKey(cert: ParsedCertificate): string {\n\treturn toHex(cert.der);\n}\n\n/**\n * Validates that a CRL signer certificate is not revoked.\n * Uses memoization to avoid redundant checks and detect cycles.\n */\nasync function validateCrlSigner(\n\tcandidate: RevocationIssuer,\n\tctx: SignerValidationContext,\n): Promise<SignerValidationState> {\n\tif (candidate.kind === 'trust_anchor') {\n\t\treturn 'resolved-valid';\n\t}\n\tconst signer = candidate.certificate;\n\tconst key = certCacheKey(signer);\n\tconst cached = ctx.cache.get(key);\n\n\t// Cycle detection: if we're already visiting this signer, it's indeterminate\n\tif (cached === 'visiting') {\n\t\treturn 'resolved-indeterminate';\n\t}\n\n\t// Return cached result if already resolved\n\tif (cached !== undefined) {\n\t\treturn cached;\n\t}\n\n\t// Mark as visiting before recursive checks\n\tctx.cache.set(key, 'visiting');\n\n\t// If signer is in the validated chain, it's trusted\n\t// (Chain was already validated before revocation checking)\n\tconst isInChain = ctx.chain.some((c) => sameCertificate(c, signer));\n\tif (isInChain) {\n\t\tctx.cache.set(key, 'resolved-valid');\n\t\treturn 'resolved-valid';\n\t}\n\n\tconst signerIssuer = ctx.pathIssuers.get(key);\n\tif (signerIssuer === undefined) {\n\t\tctx.cache.set(key, 'resolved-indeterminate');\n\t\treturn 'resolved-indeterminate';\n\t}\n\n\tconst signerRevocation =\n\t\trevocationSkipReason(signer) === undefined\n\t\t\t? await checkSignerRevocation(signer, signerIssuer, ctx)\n\t\t\t: 'resolved-valid';\n\tconst status =\n\t\tsignerRevocation === 'resolved-valid'\n\t\t\t? statusBelow(await validateCrlSigner(signerIssuer, ctx))\n\t\t\t: signerRevocation;\n\tctx.cache.set(key, status);\n\treturn status;\n}\n\n/**\n * A good or exempt signer's status once its issuer's is known: RFC 5280\n * §6.3.3 (f) validates the whole path of a CRL issuer, so an issuer that is\n * not known good leaves the signer indeterminate. RFC 9608 §4 exempts only the\n * certificate carrying noRevAvail or id-pkix-ocsp-nocheck.\n */\nfunction statusBelow(issuerStatus: SignerValidationState): SignerValidationState {\n\treturn issuerStatus === 'resolved-valid' ? 'resolved-valid' : 'resolved-indeterminate';\n}\n\n/**\n * Checks if a CRL signer certificate is revoked by examining available CRLs.\n * Recursively validates the CRL signer of any CRL used to check revocation.\n */\nasync function checkSignerRevocation(\n\tsigner: ParsedCertificate,\n\tissuer: RevocationIssuer,\n\tctx: SignerValidationContext,\n): Promise<SignerValidationState> {\n\t// A `good` from one CRL does not end the search: a later CRL may report the\n\t// signer revoked, and a revoked verdict from any CRL wins.\n\tconst coveredReasons = new Set<string>();\n\tlet sawUnsettledEvidence = false;\n\tconst crls = distinctSignedCrls(\n\t\tctx.crls.flatMap((source) => {\n\t\t\ttry {\n\t\t\t\treturn [normalizeCrl(source)];\n\t\t\t} catch {\n\t\t\t\treturn [];\n\t\t\t}\n\t\t}),\n\t);\n\tconst deltaCrls = crls.filter((crl) => crl.baseCrlNumber !== undefined);\n\tfor (const crl of crls) {\n\t\tif (crl.baseCrlNumber !== undefined) continue;\n\t\tconst outcome = await checkSignerAgainstCrlAuthorities(signer, issuer, crl, deltaCrls, ctx);\n\t\tif (outcome.kind === 'revoked') {\n\t\t\treturn 'resolved-revoked';\n\t\t}\n\t\tif (outcome.kind === 'unrecognized_reason' || outcome.kind === 'unsettled_delta') {\n\t\t\tsawUnsettledEvidence = true;\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const reason of outcome.reasons) {\n\t\t\tcoveredReasons.add(reason);\n\t\t}\n\t}\n\tif (sawUnsettledEvidence) {\n\t\treturn 'resolved-indeterminate';\n\t}\n\treturn coversAllDistributionPointReasons(coveredReasons)\n\t\t? 'resolved-valid'\n\t\t: 'resolved-indeterminate';\n}\n\n/**\n * What one CRL settles about a signer: a revoked verdict, an entry\n * `unrecognizedReasonCode: 'reject'` refuses, a delta CRL that cannot settle\n * the status, or the reasons it covers.\n */\ntype SignerCrlOutcome =\n\t| { readonly kind: 'revoked' }\n\t| { readonly kind: 'unrecognized_reason' }\n\t| { readonly kind: 'unsettled_delta' }\n\t| { readonly kind: 'reasons'; readonly reasons: readonly DistributionPointReason[] };\n\nconst SIGNER_CRL_NO_EVIDENCE = {\n\tkind: 'reasons',\n\treasons: [],\n} as const satisfies SignerCrlOutcome;\n\n/**\n * Evaluates one CRL against a signer with each key that may have signed it:\n * the signer's issuer, then an indirect CRL issuer whose path validates, the\n * signer itself included. The first key whose check yields evidence settles\n * the CRL.\n */\nasync function checkSignerAgainstCrlAuthorities(\n\tsigner: ParsedCertificate,\n\tissuer: RevocationIssuer,\n\tcrl: ParsedCertificateRevocationList,\n\tdeltaCrls: readonly ParsedCertificateRevocationList[],\n\tctx: SignerValidationContext,\n): Promise<SignerCrlOutcome> {\n\tfor (const authority of collectCrlSignerCandidates(\n\t\tcrl,\n\t\tissuer,\n\t\tctx.extraCertificates,\n\t\tctx.chain,\n\t\tctx.trustAnchor,\n\t)) {\n\t\tif (\n\t\t\t!sameIssuer(authority, issuer) &&\n\t\t\t!(await crlSignerChainsToAnchor(authority, ctx.chain, ctx.extraCertificates, ctx.at, ctx))\n\t\t) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst outcome = await checkSignerAgainstCrl(signer, authority, crl, deltaCrls, ctx, [\n\t\t\tctx.deltaBudget,\n\t\t]);\n\t\tif (outcome.kind !== 'reasons' || outcome.reasons.length > 0) return outcome;\n\t}\n\treturn SIGNER_CRL_NO_EVIDENCE;\n}\n\n/**\n * Evaluates one CRL against a signer. A CRL that does not parse or does not\n * apply yields no evidence. Its `good` needs a CRL signer known good, and its\n * revocation one not known revoked. A CRL the signer itself signed vouches\n * for it as `crlSignerSelfEvidence` allows.\n */\nasync function checkSignerAgainstCrl(\n\tsigner: ParsedCertificate,\n\tissuer: RevocationIssuer,\n\tcrl: ParsedCertificateRevocationList,\n\tdeltaCrls: readonly ParsedCertificateRevocationList[],\n\tctx: SignerValidationContext,\n\tbudgets: readonly DeltaCrlBudget[],\n): Promise<SignerCrlOutcome> {\n\tconst outcome = await checkCertificateRevocationAgainstCrlsBy(\n\t\tsigner,\n\t\tcrl,\n\t\tdeltaCrls,\n\t\tissuer,\n\t\t{\n\t\t\tat: ctx.at,\n\t\t\t...(ctx.crlMaxAgeMs === undefined ? {} : { maxAgeMs: ctx.crlMaxAgeMs }),\n\t\t\t...(ctx.clockSkewMs === undefined ? {} : { clockSkewMs: ctx.clockSkewMs }),\n\t\t\tunrecognizedReasonCode: ctx.unrecognizedReasonCode,\n\t\t\tunreadSupersededDeltaCrls: ctx.unreadSupersededDeltaCrls,\n\t\t},\n\t\tsignerVerification(ctx, issuer),\n\t\tbudgets,\n\t);\n\tif (outcome.kind === 'unsettled') {\n\t\treturn { kind: 'unsettled_delta' };\n\t}\n\tconst result = outcome.result;\n\tif (!result.ok) {\n\t\treturn result.code === 'reason_code_unrecognized'\n\t\t\t? { kind: 'unrecognized_reason' }\n\t\t\t: SIGNER_CRL_NO_EVIDENCE;\n\t}\n\tconst selfSigned = issuer.kind === 'certificate' && sameCertificate(issuer.certificate, signer);\n\tif (selfSigned && ctx.crlSignerSelfEvidence === 'delegated' && !delegatesOwnStatus(signer)) {\n\t\treturn result.value.status === 'revoked' ? { kind: 'revoked' } : SIGNER_CRL_NO_EVIDENCE;\n\t}\n\tconst issuerStatus = selfSigned ? 'resolved-valid' : await validateCrlSigner(issuer, ctx);\n\tif (result.value.status === 'revoked') {\n\t\treturn issuerStatus === 'resolved-revoked' ? SIGNER_CRL_NO_EVIDENCE : { kind: 'revoked' };\n\t}\n\treturn issuerStatus === 'resolved-valid'\n\t\t? { kind: 'reasons', reasons: result.value.coveredReasons }\n\t\t: SIGNER_CRL_NO_EVIDENCE;\n}\n\n/** Whether `signer`'s cRLDistributionPoints names `signer` itself as cRLIssuer. */\nfunction delegatesOwnStatus(signer: ParsedCertificate): boolean {\n\tconst subject = signer.subject.derHex.toLowerCase();\n\treturn (signer.crlDistributionPoints ?? []).some(\n\t\t(point) =>\n\t\t\tpoint.crlIssuer?.some(\n\t\t\t\t(name) => name.type === 'directoryName' && name.derHex.toLowerCase() === subject,\n\t\t\t) === true,\n\t);\n}\n\n/** Builds the `revoked` CertificateRevocationStatus for a CRL hit. */\nfunction buildCrlRevokedStatus(\n\tcert: ParsedCertificate,\n\tsigner: RevocationIssuer,\n\tthisUpdate: Date,\n\trevocationDate: Date,\n\treasonCode?: ParsedRevocationReason,\n): CertificateRevocationStatus {\n\treturn {\n\t\tcertificate: cert,\n\t\tstatus: 'revoked',\n\t\tsource: { kind: 'crl', ...signerCertificateOf(signer), thisUpdate },\n\t\trevocationInfo: {\n\t\t\trevocationDate,\n\t\t\t...(reasonCode !== undefined ? { reason: reasonCode } : {}),\n\t\t},\n\t};\n}\n\n// OCSP Evidence Evaluation (RFC 6960)\n\n/** Per-certificate evidence evaluation outcome shared by the CRL and OCSP evaluators. */\ninterface EvidenceEvaluation {\n\treadonly status: CertificateRevocationStatus;\n\treadonly executionErrors: readonly RevocationExecutionError[];\n}\n\ninterface OcspHoldEvidence {\n\treadonly status: CertificateRevocationStatus;\n\treadonly thisUpdate: Date;\n}\n\ntype ClassifiedOcspEvidence =\n\t| { readonly kind: 'good'; readonly thisUpdate: Date }\n\t| { readonly kind: 'hold'; readonly evidence: OcspHoldEvidence }\n\t| { readonly kind: 'revoked'; readonly status: CertificateRevocationStatus }\n\t| { readonly kind: 'unknown' }\n\t| { readonly kind: 'unrecognized_reason' };\n\ntype ApplicableOcspResponse =\n\t| {\n\t\t\treadonly kind: 'applicable';\n\t\t\treadonly parsed: ParsedOcspResponse;\n\t\t\treadonly entry: ParsedOcspSingleResponse;\n\t }\n\t| { readonly kind: 'parse_error'; readonly error: RevocationParseError }\n\t| { readonly kind: 'not_applicable' };\n\n/** Parses an OCSP response from PEM string or DER bytes. */\nfunction parseOcspResponseFromSource(source: OcspResponseSource): ParsedOcspResponse {\n\tif (typeof source === 'string') {\n\t\treturn parseOcspResponsePemOrThrow(source);\n\t}\n\treturn parseOcspResponseDerOrThrow(source);\n}\n\nfunction evidenceParseError(error: unknown, fallbackMessage: string): RevocationParseError {\n\treturn {\n\t\tkind: 'parse_error',\n\t\tcode: decodeRefusalOf(error, DECODE_REFUSAL_CODES)?.code ?? 'malformed',\n\t\tmessage: error instanceof Error ? error.message : fallbackMessage,\n\t};\n}\n\n/** Parses one OCSP source and locates the entry for the certificate under evaluation. */\nfunction findApplicableOcspResponse(\n\tsource: OcspResponseSource,\n\tcert: ParsedCertificate,\n): ApplicableOcspResponse {\n\tlet parsed: ParsedOcspResponse;\n\ttry {\n\t\tparsed = parseOcspResponseFromSource(source);\n\t} catch (error) {\n\t\treturn { kind: 'parse_error', error: evidenceParseError(error, 'OCSP response parse failed') };\n\t}\n\tconst entry = (parsed.responses ?? []).find(\n\t\t(single) => normalizeHex(single.certId.serialNumberHex) === normalizeHex(cert.serialNumberHex),\n\t);\n\treturn entry === undefined ? { kind: 'not_applicable' } : { kind: 'applicable', parsed, entry };\n}\n\n/** Returns the later of two evidence timestamps, tolerating an empty accumulator. */\nfunction laterEvidenceDate(current: Date | undefined, candidate: Date): Date {\n\treturn current === undefined || candidate.getTime() > current.getTime() ? candidate : current;\n}\n\n/** Builds a definitive OCSP-revoked status from a validated response entry. */\nfunction buildOcspRevokedStatus(\n\tcert: ParsedCertificate,\n\tthisUpdate: Date,\n\trevocationDate: Date,\n\treason: ParsedRevocationReason | undefined,\n): CertificateRevocationStatus {\n\treturn {\n\t\tcertificate: cert,\n\t\tstatus: 'revoked',\n\t\tsource: { kind: 'ocsp', thisUpdate },\n\t\trevocationInfo: {\n\t\t\trevocationDate,\n\t\t\t...(reason !== undefined ? { reason } : {}),\n\t\t},\n\t};\n}\n\n/** Classifies one fully validated OCSP entry for aggregation. */\nfunction classifyValidatedOcspEntry(\n\tcert: ParsedCertificate,\n\tentry: ParsedOcspSingleResponse,\n\tunrecognizedReasonCode: UnrecognizedReasonCodePolicy,\n): ClassifiedOcspEvidence {\n\tif (entry.certStatus === 'good') {\n\t\treturn { kind: 'good', thisUpdate: entry.thisUpdate };\n\t}\n\tif (entry.certStatus === 'unknown') {\n\t\treturn { kind: 'unknown' };\n\t}\n\tconst reason = revocationReasonFromCode(entry.revocationReasonCode);\n\tif (unrecognizedReasonCode === 'reject' && typeof reason === 'object') {\n\t\treturn { kind: 'unrecognized_reason' };\n\t}\n\tconst status = buildOcspRevokedStatus(cert, entry.thisUpdate, entry.revokedAt, reason);\n\treturn reason === 'certificateHold'\n\t\t? { kind: 'hold', evidence: { status, thisUpdate: entry.thisUpdate } }\n\t\t: { kind: 'revoked', status };\n}\n\n/** Builds the definitive OCSP-good result or the accumulated indeterminate result. */\nfunction finalizeOcspEvidence(\n\tcert: ParsedCertificate,\n\tfreshestGoodThisUpdate: Date | undefined,\n\treasons: Set<RevocationIndeterminateReason>,\n\texecutionErrors: readonly RevocationExecutionError[],\n): EvidenceEvaluation {\n\tif (freshestGoodThisUpdate !== undefined) {\n\t\treturn {\n\t\t\tstatus: {\n\t\t\t\tcertificate: cert,\n\t\t\t\tstatus: 'good',\n\t\t\t\tsource: { kind: 'ocsp', thisUpdate: freshestGoodThisUpdate },\n\t\t\t},\n\t\t\texecutionErrors,\n\t\t};\n\t}\n\tif (reasons.size === 0) {\n\t\treasons.add('no_applicable_ocsp');\n\t}\n\treturn {\n\t\tstatus: {\n\t\t\tcertificate: cert,\n\t\t\tstatus: 'indeterminate',\n\t\t\tindeterminateReasons: [...reasons],\n\t\t},\n\t\texecutionErrors,\n\t};\n}\n\n/** Maps a {@linkcode validateOcspResponse} failure code to an indeterminate reason. */\nfunction ocspIndeterminateReasonFromFailure(\n\tcode: ValidateOcspResponseFailure['code'],\n): RevocationIndeterminateReason {\n\tswitch (code) {\n\t\tcase 'stale_response':\n\t\t\treturn 'ocsp_response_expired';\n\t\tcase 'next_update_missing':\n\t\t\treturn 'ocsp_next_update_missing';\n\t\tcase 'responder_id_mismatch':\n\t\tcase 'responder_chain_invalid':\n\t\tcase 'ocsp_signing_missing':\n\t\t\treturn 'ocsp_responder_not_authorized';\n\t\tcase 'responder_revoked':\n\t\t\treturn 'ocsp_responder_revoked';\n\t\tcase 'signature_invalid':\n\t\tcase 'responder_revocation_unknown':\n\t\tcase 'malformed':\n\t\tcase 'unsupported':\n\t\tcase 'limit_exceeded':\n\t\t\treturn 'ocsp_responder_indeterminate';\n\t\tcase 'response_status_invalid':\n\t\tcase 'issuer_mismatch':\n\t\tcase 'nonce_mismatch':\n\t\tcase 'request_mismatch':\n\t\t\treturn 'no_applicable_ocsp';\n\t\tdefault: {\n\t\t\tconst _exhaustive: never = code;\n\t\t\tthrow new Error(`Unhandled ValidateOcspResponse failure code: ${String(_exhaustive)}`);\n\t\t}\n\t}\n}\n\n/** Validation failures worth retrying with an explicit responder certificate. */\nconst OCSP_RESPONDER_FAILURE_CODES: ReadonlySet<ValidateOcspResponseFailure['code']> = new Set([\n\t'signature_invalid',\n\t'responder_id_mismatch',\n\t'responder_chain_invalid',\n\t'ocsp_signing_missing',\n\t'malformed',\n\t'unsupported',\n\t'limit_exceeded',\n]);\n\n/** The {@linkcode validateOcspResponse} options that a chain's `policy` sets. */\nfunction ocspPolicyOptions(policy: RevocationPolicy | undefined) {\n\treturn {\n\t\t...(policy?.ocspResponderRevocation !== undefined\n\t\t\t? { responderRevocationPolicy: policy.ocspResponderRevocation }\n\t\t\t: {}),\n\t\t...(policy?.crlMaxAgeMs !== undefined\n\t\t\t? { responderRevocationCrlMaxAgeMs: policy.crlMaxAgeMs }\n\t\t\t: {}),\n\t\t...(policy?.clockSkewMs !== undefined ? { clockSkewMs: policy.clockSkewMs } : {}),\n\t\t...(policy?.ocspProfile !== undefined ? { profile: policy.ocspProfile } : {}),\n\t\t...(policy?.unrecognizedReasonCode !== undefined\n\t\t\t? { responderRevocationUnrecognizedReasonCode: policy.unrecognizedReasonCode }\n\t\t\t: {}),\n\t\t...(policy?.unreadSupersededDeltaCrls !== undefined\n\t\t\t? { responderRevocationUnreadSupersededDeltaCrls: policy.unreadSupersededDeltaCrls }\n\t\t\t: {}),\n\t};\n}\n\n/**\n * Validates an OCSP response, retrying with caller-provided extra certificates\n * as explicit responder certificates when embedded discovery fails.\n */\nasync function validateOcspResponseWithResponderFallback(\n\tresponse: ParsedOcspResponse,\n\tcert: ParsedCertificate,\n\tissuer: RevocationIssuer,\n\tinput: CheckChainRevocationInput,\n\tat: Date,\n\tsignerCtx: SignerValidationContext,\n): Promise<ValidateOcspResponseResult> {\n\tconst context = {\n\t\tverifiers: signerCtx.verifiers,\n\t\tissuerWorkingKey:\n\t\t\tissuer.kind === 'certificate'\n\t\t\t\t? signerCtx.workingKeyOf(issuer.certificate)\n\t\t\t\t: anchorWorkingKey(issuer.trustAnchor),\n\t\tdeltaBudget: signerCtx.deltaBudget,\n\t\t...(signerCtx.distrustedSpkiSha256 !== undefined && {\n\t\t\tdistrustedSpkiSha256: signerCtx.distrustedSpkiSha256,\n\t\t}),\n\t};\n\tconst trustedOcspResponders = input.trustedOcspResponders\n\t\t?.filter((trusted) => {\n\t\t\tconst trustedIssuer = parseCertificateSafe(trusted.issuerCertificate);\n\t\t\tif (trustedIssuer === undefined) return false;\n\t\t\treturn issuer.kind === 'certificate'\n\t\t\t\t? sameCertificate(trustedIssuer, issuer.certificate)\n\t\t\t\t: carriesTrustAnchorKey(trustedIssuer, issuer.trustAnchor);\n\t\t})\n\t\t.map((trusted) => trusted.responderCertificate);\n\tconst ocspIssuer =\n\t\tissuer.kind === 'certificate' ? issuer : { ...issuer, certificateIssuer: cert.issuer };\n\tconst shared = {\n\t\tat,\n\t\t...(trustedOcspResponders !== undefined ? { trustedOcspResponders } : {}),\n\t\t...ocspPolicyOptions(input.policy),\n\t\t// Chain-level CRLs double as responder revocation evidence\n\t\t...(input.crls !== undefined ? { responderRevocationCrls: input.crls } : {}),\n\t\t...(input.signatureVerifiers !== undefined\n\t\t\t? { signatureVerifiers: input.signatureVerifiers }\n\t\t\t: {}),\n\t};\n\tconst primary = await validateOcspResponseBy({ response, ...shared }, ocspIssuer, context);\n\tif (primary.ok || !OCSP_RESPONDER_FAILURE_CODES.has(primary.code)) {\n\t\treturn primary;\n\t}\n\tfor (const source of input.extraCertificates ?? []) {\n\t\tconst responder = parseCertificateSafe(source);\n\t\tif (responder === undefined) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst retry = await validateOcspResponseBy(\n\t\t\t{ response, ...shared, responderCertificate: responder },\n\t\t\tocspIssuer,\n\t\t\tcontext,\n\t\t);\n\t\tif (retry.ok || !OCSP_RESPONDER_FAILURE_CODES.has(retry.code)) {\n\t\t\treturn retry;\n\t\t}\n\t}\n\treturn primary;\n}\n\n/**\n * Evaluates OCSP evidence for a single certificate (RFC 6960).\n *\n * Every response is fully validated — signature, responder binding and\n * authorization, and freshness — via {@linkcode validateOcspResponse} before\n * its status entry is trusted. Issuer binding of each CertID is enforced by\n * the validator, so a serial-number match on a validated response is\n * sufficient to attribute the entry to `cert`.\n */\nasync function evaluateOcspEvidence(\n\tcert: ParsedCertificate,\n\tissuer: RevocationIssuer,\n\tinput: CheckChainRevocationInput,\n\tsignerCtx: SignerValidationContext,\n): Promise<EvidenceEvaluation> {\n\tconst { ocspResponses = [], at = new Date() } = input;\n\tconst executionErrors: RevocationExecutionError[] = [];\n\tconst state: OcspEvidenceState = { reasons: new Set(), sawUnrecognizedReason: false };\n\n\tfor (const source of ocspResponses) {\n\t\tconst applicable = findApplicableOcspResponse(source, cert);\n\t\tif (applicable.kind === 'parse_error') {\n\t\t\texecutionErrors.push(applicable.error);\n\t\t\tcontinue;\n\t\t}\n\t\tif (applicable.kind === 'not_applicable') {\n\t\t\tcontinue; // Response does not cover this certificate\n\t\t}\n\n\t\tconst validation = await validateOcspResponseWithResponderFallback(\n\t\t\tapplicable.parsed,\n\t\t\tcert,\n\t\t\tissuer,\n\t\t\tinput,\n\t\t\tat,\n\t\t\tsignerCtx,\n\t\t);\n\t\tif (!validation.ok) {\n\t\t\tstate.reasons.add(ocspIndeterminateReasonFromFailure(validation.code));\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst evidence = classifyValidatedOcspEntry(\n\t\t\tcert,\n\t\t\tapplicable.entry,\n\t\t\tinput.policy?.unrecognizedReasonCode ?? 'revoked',\n\t\t);\n\t\tif (evidence.kind === 'revoked') {\n\t\t\treturn {\n\t\t\t\tstatus: evidence.status,\n\t\t\t\texecutionErrors,\n\t\t\t};\n\t\t}\n\t\trecordOcspEvidence(state, evidence);\n\t}\n\n\treturn settleOcspEvidence(cert, state, executionErrors);\n}\n\n/** What the non-revoked OCSP entries for one certificate established. */\ninterface OcspEvidenceState {\n\treadonly reasons: Set<RevocationIndeterminateReason>;\n\tfreshestGoodThisUpdate?: Date;\n\tfreshestHold?: OcspHoldEvidence;\n\tsawUnrecognizedReason: boolean;\n}\n\nfunction recordOcspEvidence(\n\tstate: OcspEvidenceState,\n\tevidence: Exclude<ClassifiedOcspEvidence, { readonly kind: 'revoked' }>,\n): void {\n\tif (evidence.kind === 'good') {\n\t\tstate.freshestGoodThisUpdate = laterEvidenceDate(\n\t\t\tstate.freshestGoodThisUpdate,\n\t\t\tevidence.thisUpdate,\n\t\t);\n\t\treturn;\n\t}\n\tif (evidence.kind === 'hold') {\n\t\tif (\n\t\t\tstate.freshestHold === undefined ||\n\t\t\tevidence.evidence.thisUpdate.getTime() > state.freshestHold.thisUpdate.getTime()\n\t\t) {\n\t\t\tstate.freshestHold = evidence.evidence;\n\t\t}\n\t\treturn;\n\t}\n\tif (evidence.kind === 'unrecognized_reason') {\n\t\tstate.sawUnrecognizedReason = true;\n\t\treturn;\n\t}\n\tstate.reasons.add('ocsp_status_unknown');\n}\n\n/** The OCSP verdict once no response revoked the certificate outright. */\nfunction settleOcspEvidence(\n\tcert: ParsedCertificate,\n\tstate: OcspEvidenceState,\n\texecutionErrors: readonly RevocationExecutionError[],\n): EvidenceEvaluation {\n\tif (state.sawUnrecognizedReason) {\n\t\tstate.reasons.add('ocsp_reason_code_unrecognized');\n\t\treturn finalizeOcspEvidence(cert, undefined, state.reasons, executionErrors);\n\t}\n\tconst { freshestGoodThisUpdate, freshestHold } = state;\n\tif (\n\t\tfreshestHold !== undefined &&\n\t\t(freshestGoodThisUpdate === undefined ||\n\t\t\tfreshestGoodThisUpdate.getTime() <= freshestHold.thisUpdate.getTime())\n\t) {\n\t\treturn { status: freshestHold.status, executionErrors };\n\t}\n\treturn finalizeOcspEvidence(cert, freshestGoodThisUpdate, state.reasons, executionErrors);\n}\n\n/**\n * Evaluates revocation status for a single certificate using available CRLs.\n * Returns both status and any execution errors encountered.\n *\n * Tries the chain issuer first; if that fails, searches extraCertificates\n * and chain for an indirect CRL issuer that matches the CRL's AKI or issuer DN.\n *\n * Also validates that CRL signers are not revoked (RFC 5280 §6.3.3).\n */\n// RFC 5280 ReasonFlags — all possible revocation reasons that CRLs can cover.\ninterface CrlEvidenceState {\n\treadonly executionErrors: RevocationExecutionError[];\n\treadonly coveredReasons: Set<string>;\n\tsawCrlSignerRevoked: boolean;\n\tsawCrlSignerIndeterminate: boolean;\n\tsawCrlSignerNotAuthorized: boolean;\n\tsawStaleCrl: boolean;\n\tsawDeltaCrlUnusable: boolean;\n\tsawDeltaCrlRetryLimit: boolean;\n\tsawUnrecognizedReasonCode: boolean;\n\tsawGood: boolean;\n\tfreshestGood?: { readonly signer: RevocationIssuer; readonly thisUpdate: Date };\n}\n\n/** Inputs for resolving one base CRL against its candidate signers. */\ninterface BaseCrlResolution {\n\treadonly cert: ParsedCertificate;\n\treadonly baseCrl: ParsedCertificateRevocationList;\n\treadonly deltaCrls: readonly ParsedCertificateRevocationList[];\n\treadonly issuer: RevocationIssuer;\n\treadonly extraCertificates: readonly RevocationCertificateSource[];\n\treadonly chain: readonly ParsedCertificate[];\n\treadonly at: Date;\n\treadonly crlMaxAgeMs: number | undefined;\n\treadonly clockSkewMs: number | undefined;\n\treadonly unrecognizedReasonCode: UnrecognizedReasonCodePolicy;\n\treadonly signerCtx: SignerValidationContext;\n\treadonly deltaBudget: DeltaCrlBudget;\n\treadonly state: CrlEvidenceState;\n}\n\n/**\n * Runs each candidate signer through the full pipeline for one base CRL:\n * signature/applicability, RFC 5280 §6.3.3(f) path to the anchor, then signer\n * revocation. A candidate that verifies the signature but fails a later step\n * does not shadow a subsequent usable signer, so the search continues. A\n * revocation stands from a signer whose own status is indeterminate, while\n * `good` needs a signer known good. Returns a revoked status when one is\n * found; otherwise records good or diagnostic evidence into `state`.\n */\nasync function resolveBaseCrlAgainstSigners(\n\tparams: BaseCrlResolution,\n): Promise<ReturnType<typeof buildCrlRevokedStatus> | undefined> {\n\tconst {\n\t\tcert,\n\t\tbaseCrl,\n\t\tdeltaCrls,\n\t\tissuer,\n\t\textraCertificates,\n\t\tchain,\n\t\tat,\n\t\tcrlMaxAgeMs,\n\t\tclockSkewMs,\n\t\tunrecognizedReasonCode,\n\t\tsignerCtx,\n\t\tdeltaBudget,\n\t\tstate,\n\t} = params;\n\tfor (const candidate of collectCrlSignerCandidates(\n\t\tbaseCrl,\n\t\tissuer,\n\t\textraCertificates,\n\t\tchain,\n\t\tsignerCtx.trustAnchor,\n\t)) {\n\t\tconst authorized = await crlSignerChainsToAnchor(\n\t\t\tcandidate,\n\t\t\tchain,\n\t\t\textraCertificates,\n\t\t\tat,\n\t\t\tsignerCtx,\n\t\t);\n\t\tconst verification = signerVerification(signerCtx, candidate);\n\t\tif (!authorized) {\n\t\t\tstate.sawCrlSignerNotAuthorized ||= (\n\t\t\t\tawait authenticateCrl(baseCrl, candidate, verification)\n\t\t\t).ok;\n\t\t\tcontinue;\n\t\t}\n\t\tconst resolved = await checkCrlAgainstDeltaCandidates({\n\t\t\tcert,\n\t\t\tbaseCrl,\n\t\t\tdeltaCrls,\n\t\t\tcandidate,\n\t\t\tat,\n\t\t\tcrlMaxAgeMs,\n\t\t\tclockSkewMs,\n\t\t\tunrecognizedReasonCode,\n\t\t\tunreadSupersededDeltaCrls: signerCtx.unreadSupersededDeltaCrls,\n\t\t\tbudgets: [deltaBudget],\n\t\t\tstate,\n\t\t\tverification,\n\t\t});\n\t\tif (resolved.kind === 'unusable_base') {\n\t\t\tcontinue;\n\t\t}\n\t\tconst verdict = settleCrlSignerCandidate(\n\t\t\tcert,\n\t\t\tcandidate,\n\t\t\tresolved,\n\t\t\tawait validateCrlSigner(candidate, signerCtx),\n\t\t\tstate,\n\t\t);\n\t\tif (verdict.kind === 'done') return verdict.status;\n\t}\n\treturn undefined;\n}\n\n/** Whether a base CRL's search ends with one signer candidate, and the revoked status it found. */\ntype CrlSignerCandidateVerdict =\n\t| { readonly kind: 'next' }\n\t| { readonly kind: 'done'; readonly status: CertificateRevocationStatus | undefined };\n\nconst NEXT_CRL_SIGNER_CANDIDATE = { kind: 'next' } as const satisfies CrlSignerCandidateVerdict;\n\n/**\n * Settles one authorized signer candidate's outcome for a base CRL by the\n * signer's own status. A revocation stands from a signer whose status is\n * indeterminate, while `good` needs a signer known good.\n */\nfunction settleCrlSignerCandidate(\n\tcert: ParsedCertificate,\n\tcandidate: RevocationIssuer,\n\tresolved: Exclude<DeltaCandidateOutcome, { readonly kind: 'unusable_base' }>,\n\tsignerStatus: SignerValidationState,\n\tstate: CrlEvidenceState,\n): CrlSignerCandidateVerdict {\n\tif (signerStatus === 'resolved-revoked') {\n\t\tstate.sawCrlSignerRevoked = true;\n\t\treturn NEXT_CRL_SIGNER_CANDIDATE;\n\t}\n\tconst revoked = revokedCrlStatus(cert, candidate, resolved);\n\tif (signerStatus === 'resolved-indeterminate') {\n\t\tstate.sawCrlSignerIndeterminate = true;\n\t\treturn revoked === undefined ? NEXT_CRL_SIGNER_CANDIDATE : { kind: 'done', status: revoked };\n\t}\n\tif (resolved.kind === 'reason_code_unrecognized') {\n\t\tstate.sawUnrecognizedReasonCode = true;\n\t} else if (resolved.kind === 'delta_unusable') {\n\t\tstate.sawDeltaCrlUnusable = true;\n\t} else if (resolved.kind === 'retry_limit') {\n\t\tstate.sawDeltaCrlRetryLimit = true;\n\t} else if (resolved.checked.value.status === 'good') {\n\t\trecordGoodCrlEvidence(\n\t\t\tstate,\n\t\t\tcandidate,\n\t\t\tresolved.crlThisUpdate,\n\t\t\tresolved.checked.value.coveredReasons,\n\t\t);\n\t}\n\treturn { kind: 'done', status: revoked };\n}\n\n/** The revoked status `resolved` reports for `cert`, signed by `signer`. */\nfunction revokedCrlStatus(\n\tcert: ParsedCertificate,\n\tsigner: RevocationIssuer,\n\tresolved: DeltaCandidateOutcome,\n): CertificateRevocationStatus | undefined {\n\treturn resolved.kind === 'checked' && resolved.checked.value.status === 'revoked'\n\t\t? buildCrlRevokedStatus(\n\t\t\t\tcert,\n\t\t\t\tsigner,\n\t\t\t\tresolved.crlThisUpdate,\n\t\t\t\tresolved.checked.value.revocationDate,\n\t\t\t\tresolved.checked.value.reasonCode,\n\t\t\t)\n\t\t: undefined;\n}\n\nasync function evaluateCrlEvidence(\n\tcert: ParsedCertificate,\n\tissuer: RevocationIssuer,\n\tinput: CheckChainRevocationInput,\n\tsignerCtx: SignerValidationContext,\n\tdeltaBudget: DeltaCrlBudget,\n): Promise<EvidenceEvaluation> {\n\tconst { crls = [], extraCertificates = [], chain = [], at = new Date() } = input;\n\tconst state: CrlEvidenceState = {\n\t\texecutionErrors: [],\n\t\tcoveredReasons: new Set(),\n\t\tsawCrlSignerRevoked: false,\n\t\tsawCrlSignerIndeterminate: false,\n\t\tsawCrlSignerNotAuthorized: false,\n\t\tsawStaleCrl: false,\n\t\tsawDeltaCrlUnusable: false,\n\t\tsawDeltaCrlRetryLimit: false,\n\t\tsawUnrecognizedReasonCode: false,\n\t\tsawGood: false,\n\t};\n\n\t// Parse all CRLs and separate base CRLs from delta CRLs\n\tconst parsedCrls = parseCrlEvidenceSources(crls, state.executionErrors);\n\n\tconst baseCrls = distinctSignedCrls(\n\t\tparsedCrls.filter((crl) => crl.baseCrlNumber === undefined && isCrlApplicableTo(cert, crl)),\n\t);\n\tconst deltaCrls = distinctSignedCrls(parsedCrls.filter((crl) => crl.baseCrlNumber !== undefined));\n\n\t// Process base CRLs (optionally paired with delta CRLs)\n\tconst crlMaxAgeMs = input.policy?.crlMaxAgeMs;\n\tconst clockSkewMs = input.policy?.clockSkewMs;\n\tfor (const baseCrl of baseCrls) {\n\t\tconst revoked = await resolveBaseCrlAgainstSigners({\n\t\t\tcert,\n\t\t\tbaseCrl,\n\t\t\tdeltaCrls,\n\t\t\tissuer,\n\t\t\textraCertificates,\n\t\t\tchain,\n\t\t\tat,\n\t\t\tcrlMaxAgeMs,\n\t\t\tclockSkewMs,\n\t\t\tunrecognizedReasonCode: input.policy?.unrecognizedReasonCode ?? 'revoked',\n\t\t\tsignerCtx,\n\t\t\tdeltaBudget,\n\t\t\tstate,\n\t\t});\n\t\tif (revoked !== undefined) {\n\t\t\treturn { status: revoked, executionErrors: state.executionErrors };\n\t\t}\n\t}\n\n\tconst blockingReasons = blockingCrlIndeterminateReasons(state);\n\tif (blockingReasons.length > 0) {\n\t\treturn {\n\t\t\tstatus: { certificate: cert, status: 'indeterminate', indeterminateReasons: blockingReasons },\n\t\t\texecutionErrors: state.executionErrors,\n\t\t};\n\t}\n\n\t// Return 'good' only if we saw at least one good result AND all reasons are covered\n\tif (state.sawGood && state.freshestGood !== undefined) {\n\t\tconst allReasonsCovered = coversAllDistributionPointReasons(state.coveredReasons);\n\t\tif (allReasonsCovered) {\n\t\t\treturn {\n\t\t\t\tstatus: {\n\t\t\t\t\tcertificate: cert,\n\t\t\t\t\tstatus: 'good',\n\t\t\t\t\tsource: {\n\t\t\t\t\t\tkind: 'crl',\n\t\t\t\t\t\t...signerCertificateOf(state.freshestGood.signer),\n\t\t\t\t\t\tthisUpdate: state.freshestGood.thisUpdate,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\texecutionErrors: state.executionErrors,\n\t\t\t};\n\t\t}\n\t\t// Not all reasons covered — indeterminate\n\t\treturn {\n\t\t\tstatus: {\n\t\t\t\tcertificate: cert,\n\t\t\t\tstatus: 'indeterminate',\n\t\t\t\tindeterminateReasons: ['reason_coverage_incomplete'],\n\t\t\t},\n\t\t\texecutionErrors: state.executionErrors,\n\t\t};\n\t}\n\n\treturn {\n\t\tstatus: {\n\t\t\tcertificate: cert,\n\t\t\tstatus: 'indeterminate',\n\t\t\tindeterminateReasons: [crlUnavailableReason(state)],\n\t\t},\n\t\texecutionErrors: state.executionErrors,\n\t};\n}\n\n/** CRL conditions that keep the status indeterminate despite `good` evidence. */\nfunction blockingCrlIndeterminateReasons(\n\tstate: CrlEvidenceState,\n): readonly RevocationIndeterminateReason[] {\n\treturn [\n\t\t...(state.sawDeltaCrlUnusable ? (['delta_crl_unusable'] as const) : []),\n\t\t...(state.sawDeltaCrlRetryLimit ? (['delta_crl_retry_limit_exceeded'] as const) : []),\n\t\t...(state.sawUnrecognizedReasonCode ? (['crl_reason_code_unrecognized'] as const) : []),\n\t];\n}\n\n/** Most specific indeterminate reason when no CRL yielded a usable verdict. */\nfunction crlUnavailableReason(state: CrlEvidenceState): RevocationIndeterminateReason {\n\tif (state.sawCrlSignerRevoked) {\n\t\treturn 'crl_signer_revoked';\n\t}\n\tif (state.sawCrlSignerNotAuthorized) {\n\t\treturn 'crl_signer_not_authorized';\n\t}\n\tif (state.sawCrlSignerIndeterminate) {\n\t\treturn 'crl_signer_indeterminate';\n\t}\n\tif (state.sawStaleCrl) {\n\t\treturn 'crl_expired';\n\t}\n\treturn 'no_applicable_crl';\n}\n\n/** Parses complete and delta CRL evidence while retaining source provenance. */\nfunction parseCrlEvidenceSources(\n\tcrls: readonly CrlSource[],\n\texecutionErrors: RevocationExecutionError[],\n): readonly ParsedCertificateRevocationList[] {\n\tconst parsedCrls: ParsedCertificateRevocationList[] = [];\n\tfor (const crlSource of crls) {\n\t\ttry {\n\t\t\tparsedCrls.push(normalizeCrl(crlSource));\n\t\t} catch (error) {\n\t\t\texecutionErrors.push(evidenceParseError(error, 'CRL parse failed'));\n\t\t}\n\t}\n\treturn parsedCrls;\n}\n\ninterface DeltaCandidateCheck {\n\treadonly cert: ParsedCertificate;\n\treadonly baseCrl: ParsedCertificateRevocationList;\n\treadonly deltaCrls: readonly ParsedCertificateRevocationList[];\n\treadonly candidate: RevocationIssuer;\n\treadonly at: Date;\n\treadonly crlMaxAgeMs: number | undefined;\n\treadonly clockSkewMs: number | undefined;\n\treadonly unrecognizedReasonCode: UnrecognizedReasonCodePolicy;\n\treadonly unreadSupersededDeltaCrls: SupersededDeltaCrlPolicy;\n\treadonly budgets: readonly DeltaCrlBudget[];\n\treadonly state: CrlEvidenceState;\n\treadonly verification: CallerVerification;\n}\n\ntype DeltaCandidateOutcome =\n\t| {\n\t\t\treadonly kind: 'checked';\n\t\t\treadonly checked: Extract<\n\t\t\t\tAwaited<ReturnType<typeof checkCertificateRevocationAgainstCrl>>,\n\t\t\t\t{ readonly ok: true }\n\t\t\t>;\n\t\t\treadonly crlThisUpdate: Date;\n\t }\n\t| { readonly kind: 'unusable_base' }\n\t| { readonly kind: 'reason_code_unrecognized' }\n\t| { readonly kind: 'delta_unusable' }\n\t| { readonly kind: 'retry_limit' };\n\n/**\n * Checks `baseCrl`, signed by `candidate`, and its delta CRLs through\n * {@linkcode checkCertificateRevocationAgainstCrlsBy}, which every CRL\n * consumer shares, and maps the outcome to the chain's evidence.\n */\nasync function checkCrlAgainstDeltaCandidates(\n\tparams: DeltaCandidateCheck,\n): Promise<DeltaCandidateOutcome> {\n\tconst {\n\t\tcert,\n\t\tbaseCrl,\n\t\tdeltaCrls,\n\t\tcandidate,\n\t\tat,\n\t\tcrlMaxAgeMs,\n\t\tclockSkewMs,\n\t\tunrecognizedReasonCode,\n\t\tunreadSupersededDeltaCrls,\n\t\tbudgets,\n\t\tstate,\n\t\tverification,\n\t} = params;\n\tconst outcome = await checkCertificateRevocationAgainstCrlsBy(\n\t\tcert,\n\t\tbaseCrl,\n\t\tdeltaCrls,\n\t\tcandidate,\n\t\t{\n\t\t\tat,\n\t\t\t...(crlMaxAgeMs === undefined ? {} : { maxAgeMs: crlMaxAgeMs }),\n\t\t\t...(clockSkewMs === undefined ? {} : { clockSkewMs }),\n\t\t\tunrecognizedReasonCode,\n\t\t\tunreadSupersededDeltaCrls,\n\t\t},\n\t\tverification,\n\t\tbudgets,\n\t);\n\tif (outcome.kind === 'unsettled') {\n\t\treturn outcome.reason === 'retry_limit' ? { kind: 'retry_limit' } : { kind: 'delta_unusable' };\n\t}\n\tconst result = outcome.result;\n\tif (!result.ok) {\n\t\tif (result.code === 'stale_crl') state.sawStaleCrl = true;\n\t\treturn result.code === 'reason_code_unrecognized'\n\t\t\t? { kind: 'reason_code_unrecognized' }\n\t\t\t: { kind: 'unusable_base' };\n\t}\n\treturn {\n\t\tkind: 'checked',\n\t\tchecked: result,\n\t\tcrlThisUpdate:\n\t\t\toutcome.deltaCrl === undefined\n\t\t\t\t? baseCrl.thisUpdate\n\t\t\t\t: laterEvidenceDate(baseCrl.thisUpdate, outcome.deltaCrl.thisUpdate),\n\t};\n}\n\n/** The direct issuer first, then deduplicated indirect CRL-issuer candidates. */\nfunction collectCrlSignerCandidates(\n\tbaseCrl: ParsedCertificateRevocationList,\n\tissuer: RevocationIssuer,\n\textraCertificates: readonly RevocationCertificateSource[],\n\tchain: readonly ParsedCertificate[],\n\ttrustAnchor: TrustAnchor | undefined,\n): readonly RevocationIssuer[] {\n\tconst candidates: RevocationIssuer[] = [issuer];\n\tconst push = (candidate: RevocationIssuer): void => {\n\t\tif (!candidates.some((existing) => sameIssuer(existing, candidate))) {\n\t\t\tcandidates.push(candidate);\n\t\t}\n\t};\n\tfor (const indirect of findIndirectCrlIssuers(baseCrl, extraCertificates, chain)) {\n\t\tpush(issuerOf(indirect, trustAnchor));\n\t}\n\tif (trustAnchor !== undefined && compareDistinguishedNames(baseCrl.issuer, trustAnchor.subject)) {\n\t\tpush({ kind: 'trust_anchor', trustAnchor });\n\t}\n\treturn candidates;\n}\n\nfunction recordGoodCrlEvidence(\n\tstate: CrlEvidenceState,\n\tsigner: RevocationIssuer,\n\tthisUpdate: Date,\n\tcoveredReasons: readonly DistributionPointReason[],\n): void {\n\tstate.sawGood = true;\n\tif (\n\t\tstate.freshestGood === undefined ||\n\t\tthisUpdate.getTime() > state.freshestGood.thisUpdate.getTime()\n\t) {\n\t\tstate.freshestGood = { signer, thisUpdate };\n\t}\n\tfor (const reason of coveredReasons) {\n\t\tstate.coveredReasons.add(reason);\n\t}\n}\n\n/** Indeterminate reasons that keep other evidence from settling the status as `good`. */\nconst GOOD_BLOCKING_REASONS: ReadonlySet<RevocationIndeterminateReason> = new Set([\n\t'delta_crl_unusable',\n\t'delta_crl_retry_limit_exceeded',\n\t'crl_reason_code_unrecognized',\n\t'ocsp_reason_code_unrecognized',\n]);\n\n/**\n * Evaluates revocation status for a single certificate by combining OCSP and\n * CRL evidence.\n *\n * Both evidence kinds are always evaluated: a validated `revoked` verdict from\n * either source wins regardless of {@linkcode RevocationPolicy.prefer}\n * (fail-closed). Otherwise the preferred source's `good` verdict is reported —\n * for `'best-available'` the source with the later evidence `thisUpdate` wins,\n * ties favoring OCSP. An indeterminate reason in\n * {@linkcode GOOD_BLOCKING_REASONS} from either source outranks a `good`\n * verdict. If neither source is definitive, indeterminate reasons from both\n * are merged.\n */\nasync function evaluateCertificateRevocation(\n\tcert: ParsedCertificate,\n\tissuer: RevocationIssuer,\n\tinput: CheckChainRevocationInput,\n\tsignerCtx: SignerValidationContext,\n\tdeltaBudget: DeltaCrlBudget,\n): Promise<EvidenceEvaluation> {\n\tconst prefer = input.policy?.prefer ?? 'best-available';\n\tconst ocsp = await evaluateOcspEvidence(cert, issuer, input, signerCtx);\n\tconst crl = await evaluateCrlEvidence(cert, issuer, input, signerCtx, deltaBudget);\n\tconst executionErrors = [...ocsp.executionErrors, ...crl.executionErrors];\n\n\t// 'best-available' ranks by evidence freshness; the sort is stable, so\n\t// equal (or absent) thisUpdate keeps OCSP first.\n\tconst ordered =\n\t\tprefer === 'crl'\n\t\t\t? [crl, ocsp]\n\t\t\t: prefer === 'ocsp'\n\t\t\t\t? [ocsp, crl]\n\t\t\t\t: [ocsp, crl].sort(\n\t\t\t\t\t\t(a, b) =>\n\t\t\t\t\t\t\t(b.status.source?.thisUpdate?.getTime() ?? 0) -\n\t\t\t\t\t\t\t(a.status.source?.thisUpdate?.getTime() ?? 0),\n\t\t\t\t\t);\n\tconst revoked = ordered.find((evaluation) => evaluation.status.status === 'revoked');\n\tif (revoked !== undefined) {\n\t\treturn { status: revoked.status, executionErrors };\n\t}\n\tconst good = ordered.find((evaluation) => evaluation.status.status === 'good');\n\tconst blocked = [crl, ocsp].some((evaluation) =>\n\t\tevaluation.status.indeterminateReasons?.some((reason) => GOOD_BLOCKING_REASONS.has(reason)),\n\t);\n\tif (good !== undefined && !blocked) {\n\t\treturn { status: good.status, executionErrors };\n\t}\n\n\tconst reasons = new Set<RevocationIndeterminateReason>();\n\tfor (const evaluation of ordered) {\n\t\tfor (const reason of evaluation.status.indeterminateReasons ?? []) {\n\t\t\treasons.add(reason);\n\t\t}\n\t}\n\treturn {\n\t\tstatus: {\n\t\t\tcertificate: cert,\n\t\t\tstatus: 'indeterminate',\n\t\t\tindeterminateReasons: [...reasons],\n\t\t},\n\t\texecutionErrors,\n\t};\n}\n\n/**\n * @throws RangeError when `trustAnchor` did not issue the last certificate of\n * `chain`, or that certificate is the anchor's own.\n */\nfunction assertIssuedByTrustAnchor(\n\tchain: readonly ParsedCertificate[],\n\ttrustAnchor: TrustAnchor | undefined,\n): void {\n\tconst top = chain[chain.length - 1];\n\tif (trustAnchor === undefined || top === undefined) return;\n\tif (carriesTrustAnchorKey(top, trustAnchor)) {\n\t\tthrow new RangeError('chain ends with the trust anchor certificate; omit it or trustAnchor');\n\t}\n\tif (!compareDistinguishedNames(top.issuer, trustAnchor.subject)) {\n\t\tthrow new RangeError('trustAnchor does not name the issuer of the last chain certificate');\n\t}\n}\n\n/** The issuer of `chain[index]`: the next chain certificate, or the bare anchor above the last. */\nfunction issuerAt(\n\tchain: readonly ParsedCertificate[],\n\tindex: number,\n\ttrustAnchor: TrustAnchor | undefined,\n): RevocationIssuer | undefined {\n\tconst next = chain[index + 1];\n\tif (next !== undefined) return { kind: 'certificate', certificate: next };\n\treturn trustAnchor === undefined ? undefined : { kind: 'trust_anchor', trustAnchor };\n}\n\n/**\n * Each certificate of `chain` that has an issuer, with that issuer. Without\n * `trustAnchor` the last certificate is the anchor and has none.\n */\nfunction certificatesWithIssuers(\n\tchain: readonly ParsedCertificate[],\n\ttrustAnchor: TrustAnchor | undefined,\n): readonly { readonly cert: ParsedCertificate; readonly issuer: RevocationIssuer }[] {\n\treturn chain.flatMap((cert, index) => {\n\t\tconst issuer = issuerAt(chain, index, trustAnchor);\n\t\treturn issuer === undefined ? [] : [{ cert, issuer }];\n\t});\n}\n\n/**\n * RFC 9608 §4: path validation skips RFC 5280 §6.1.3 step (a)(3) for a\n * certificate carrying noRevAvail or id-pkix-ocsp-nocheck, read from its\n * signed DER.\n */\nfunction revocationSkipReason(certificate: ParsedCertificate): RevocationSkipReason | undefined {\n\tconst signed = parseCertificateDer(certificate.der);\n\treturn signed.ok ? revocationSkipReasonOf(signed.value) : undefined;\n}\n\n// Function\n\n/**\n * Checks revocation status for all certificates in a validated chain.\n *\n * Evaluates CRL and OCSP evidence against each certificate (except the trust\n * anchor at the end of `chain`; with `trustAnchor`, every certificate), applies\n * the revocation policy, and returns a unified decision. A\n * certificate carrying noRevAvail or id-pkix-ocsp-nocheck is reported as\n * `skipped` without consulting evidence (RFC 9608 §4).\n *\n * @example\n * ```ts\n * const result = await checkChainRevocation({\n * chain: validatedChain,\n * crls: [crl1, crl2],\n * ocspResponses: [ocspResponseDer],\n * policy: { mode: 'hard-fail' },\n * });\n * if (result.value.decision === 'deny') {\n * console.log('Revocation check failed');\n * }\n * ```\n */\nexport async function checkChainRevocation(\n\tinput: CheckChainRevocationInput,\n): Promise<CheckChainRevocationResult> {\n\treturn await checkChainRevocationAt({ ...input, at: input.at ?? new Date() });\n}\n\n/**\n * The signer validation state shared by every certificate check of one\n * {@linkcode checkChainRevocation} call, with its delta CRL budget and the\n * caller's distrust list as it stood when the call began.\n */\nfunction signerValidationContext(\n\tinput: CheckChainRevocationInput & { readonly at: Date },\n\tverifiers: ReadonlyMap<string, SignatureVerifier>,\n): SignerValidationContext {\n\tconst { chain, policy } = input;\n\tconst pathKeys = new Map<string, WorkingPublicKey>();\n\tconst chainKeys = chainWorkingKeys(\n\t\tchain,\n\t\tinput.trustAnchor === undefined ? undefined : anchorWorkingKey(input.trustAnchor),\n\t);\n\treturn {\n\t\tcache: new Map(),\n\t\tchain,\n\t\tcrls: input.crls ?? [],\n\t\textraCertificates: input.extraCertificates ?? [],\n\t\tat: input.at,\n\t\tcrlMaxAgeMs: policy?.crlMaxAgeMs,\n\t\tclockSkewMs: policy?.clockSkewMs,\n\t\tunrecognizedReasonCode: policy?.unrecognizedReasonCode ?? 'revoked',\n\t\tcrlSignerSelfEvidence: policy?.crlSignerSelfEvidence ?? 'delegated',\n\t\tunreadSupersededDeltaCrls: policy?.unreadSupersededDeltaCrls ?? 'indeterminate',\n\t\tsignatureVerifiers: input.signatureVerifiers,\n\t\tdistrustedSpkiSha256:\n\t\t\tinput.distrustedSpkiSha256 === undefined ? undefined : [...input.distrustedSpkiSha256],\n\t\tverifiers,\n\t\tdeltaBudget: { remaining: DELTA_CRL_ATTEMPTS_PER_CALL },\n\t\tworkingKeyOf: (certificate) =>\n\t\t\tpathKeys.get(certCacheKey(certificate)) ?? chainKeys(certificate),\n\t\tpathKeys,\n\t\tpathIssuers: new Map(),\n\t\ttrustAnchor: input.trustAnchor,\n\t};\n}\n\n/** {@linkcode checkChainRevocation} with its evaluation time resolved once for every check. */\nasync function checkChainRevocationAt(\n\tinput: CheckChainRevocationInput & { readonly at: Date },\n): Promise<CheckChainRevocationResult> {\n\tconst { chain, policy } = input;\n\tassertCrlMaxAge(policy?.crlMaxAgeMs);\n\tassertClockSkew(policy?.clockSkewMs);\n\tconst verifiers = resolveSignatureVerifiers(input.signatureVerifiers);\n\tcreateSpkiDistrustCheck(input.distrustedSpkiSha256);\n\tassertIssuedByTrustAnchor(chain, input.trustAnchor);\n\tconst mode = policy?.mode ?? 'hard-fail';\n\n\t// Empty chain → allow\n\tif (chain.length === 0) {\n\t\treturn {\n\t\t\tok: true,\n\t\t\tvalue: {\n\t\t\t\tdecision: 'allow',\n\t\t\t\tsummary: { revokedCertificates: [], indeterminateCertificates: [] },\n\t\t\t\tcertificates: [],\n\t\t\t},\n\t\t};\n\t}\n\n\tconst signerCtx = signerValidationContext(input, verifiers);\n\tconst deltaBudget = signerCtx.deltaBudget;\n\n\tconst certificates: CertificateRevocationStatus[] = [];\n\tconst revokedCertificates: ParsedCertificate[] = [];\n\tconst indeterminateCertificates: ParsedCertificate[] = [];\n\tconst allExecutionErrors: RevocationExecutionError[] = [];\n\n\tfor (const { cert, issuer } of certificatesWithIssuers(chain, input.trustAnchor)) {\n\t\tconst skipReason = revocationSkipReason(cert);\n\t\tif (skipReason !== undefined) {\n\t\t\tcertificates.push({ certificate: cert, status: 'skipped', skipReason });\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst { status, executionErrors } = await evaluateCertificateRevocation(\n\t\t\tcert,\n\t\t\tissuer,\n\t\t\tinput,\n\t\t\tsignerCtx,\n\t\t\tdeltaBudget,\n\t\t);\n\t\tcertificates.push(status);\n\t\tallExecutionErrors.push(...executionErrors);\n\n\t\tif (status.status === 'revoked') {\n\t\t\trevokedCertificates.push(cert);\n\t\t} else if (status.status === 'indeterminate') {\n\t\t\tindeterminateCertificates.push(cert);\n\t\t}\n\t}\n\n\t// Apply policy\n\tconst hasRevoked = revokedCertificates.length > 0;\n\tconst hasIndeterminate = indeterminateCertificates.length > 0;\n\tconst decision: 'allow' | 'deny' = hasRevoked\n\t\t? 'deny'\n\t\t: hasIndeterminate && mode === 'hard-fail'\n\t\t\t? 'deny'\n\t\t\t: 'allow';\n\n\treturn {\n\t\tok: true,\n\t\tvalue: {\n\t\t\tdecision,\n\t\t\tsummary: { revokedCertificates, indeterminateCertificates },\n\t\t\tcertificates,\n\t\t\t...(allExecutionErrors.length > 0 ? { executionErrors: allExecutionErrors } : {}),\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAqPA,SAAS,WAAW4B,GAAqBC,GAA8B;CAItE,OAHID,EAAE,SAAS,iBAAiBC,EAAE,SAAS,gBACnC,gBAAgBD,EAAE,aAAaC,EAAE,WAAW,IAE7CD,EAAE,SAAS,kBAAkBC,EAAE,SAAS,kBAAkBD,EAAE,gBAAgBC,EAAE;AACtF;;AAGA,SAAS,SACRC,GACAC,GACmB;CACnB,OAAOA,MAAgB,KAAA,KAAavB,EAAsBsB,GAAaC,CAAW,IAC/E;EAAE,MAAM;EAAgBA;CAAY,IACpC;EAAE,MAAM;EAAeD;CAAY;AACvC;;AAGA,SAAS,oBACRE,GAC2E;CAC3E,OAAOA,EAAO,SAAS,gBAAgB,EAAE,mBAAmBA,EAAO,YAAY,IAAI,CAAC;AACrF;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,MAAaC,IAAmC;CAE/C;CACA;CAEA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CAEA;CAEA;CACA;CAEA;CACA;AACD;;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