micro509 0.12.0 → 0.14.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.
- package/README.md +78 -30
- package/dist/crypto/crypto.d.ts +73 -0
- package/dist/crypto/crypto.js +74 -0
- package/dist/crypto/crypto.js.map +1 -0
- package/dist/crypto.d.ts +4 -0
- package/dist/crypto.js +2 -0
- package/dist/der/der.d.ts +127 -0
- package/dist/der/der.js +171 -0
- package/dist/der/der.js.map +1 -0
- package/dist/der.d.ts +4 -0
- package/dist/der.js +4 -0
- package/dist/index.d.ts +13 -9
- package/dist/index.js +17 -15
- package/dist/internal/asn1/asn1.d.ts +20 -0
- package/dist/internal/asn1/asn1.js +80 -37
- package/dist/internal/asn1/asn1.js.map +1 -1
- package/dist/internal/asn1/der.d.ts +173 -0
- package/dist/internal/asn1/der.js +116 -38
- package/dist/internal/asn1/der.js.map +1 -1
- package/dist/internal/asn1/oids.js +7 -1
- package/dist/internal/asn1/oids2.js +9 -2
- package/dist/internal/asn1/oids2.js.map +1 -1
- package/dist/internal/crypto/algorithm-names.js +4 -0
- package/dist/internal/crypto/algorithm-names.js.map +1 -1
- package/dist/internal/crypto/pbes2.d.ts +38 -0
- package/dist/internal/crypto/pbes2.js +9 -10
- package/dist/internal/crypto/pbes2.js.map +1 -1
- package/dist/internal/crypto/rsa-pss.js +2 -0
- package/dist/internal/crypto/rsa-pss.js.map +1 -1
- package/dist/internal/crypto/sig-verify.d.ts +31 -0
- package/dist/internal/crypto/sig-verify.js +10 -8
- package/dist/internal/crypto/sig-verify.js.map +1 -1
- package/dist/internal/shared/base64.js +7 -1
- package/dist/internal/shared/base64.js.map +1 -1
- package/dist/internal/shared/dn.d.ts +16 -0
- package/dist/internal/shared/dn.js +149 -12
- package/dist/internal/shared/dn.js.map +1 -1
- package/dist/internal/shared/ip.d.ts +69 -0
- package/dist/internal/shared/ip.js +18 -1
- package/dist/internal/shared/ip.js.map +1 -1
- package/dist/internal/shared/rfc3454-tables.js +1782 -0
- package/dist/internal/shared/rfc3454-tables.js.map +1 -0
- package/dist/internal/verify/name-constraints-engine.js +47 -15
- package/dist/internal/verify/name-constraints-engine.js.map +1 -1
- package/dist/internal/verify/policy-engine.js +85 -94
- package/dist/internal/verify/policy-engine.js.map +1 -1
- package/dist/internal/verify/verify-path.d.ts +7 -0
- package/dist/internal/verify/verify-path.js +49 -45
- package/dist/internal/verify/verify-path.js.map +1 -1
- package/dist/internal/x509/directory-name.js +24 -0
- package/dist/internal/x509/directory-name.js.map +1 -0
- package/dist/internal/x509/extension-bits.js +14 -11
- package/dist/internal/x509/extension-bits.js.map +1 -1
- package/dist/internal/x509/extension-errors.d.ts +6 -0
- package/dist/internal/x509/extension-errors.js +20 -0
- package/dist/internal/x509/extension-errors.js.map +1 -0
- package/dist/internal/x509/extension-registry.js +113 -55
- package/dist/internal/x509/extension-registry.js.map +1 -1
- package/dist/internal/x509/general-name-tags.js +28 -0
- package/dist/internal/x509/general-name-tags.js.map +1 -0
- package/dist/internal/x509/general-name.js +97 -0
- package/dist/internal/x509/general-name.js.map +1 -0
- package/dist/internal/x509/name-fields.js +20 -10
- package/dist/internal/x509/name-fields.js.map +1 -1
- package/dist/keys/keys.d.ts +16 -2
- package/dist/keys/keys.js +311 -170
- package/dist/keys/keys.js.map +1 -1
- package/dist/keys.d.ts +3 -2
- package/dist/keys.js +3 -2
- package/dist/pem/pem.d.ts +3 -2
- package/dist/pem/pem.js +112 -30
- package/dist/pem/pem.js.map +1 -1
- package/dist/pkcs/pkcs12-mac.js +3 -3
- package/dist/pkcs/pkcs12-mac.js.map +1 -1
- package/dist/pkcs/pkcs7.d.ts +85 -21
- package/dist/pkcs/pkcs7.js +261 -186
- package/dist/pkcs/pkcs7.js.map +1 -1
- package/dist/pkcs.d.ts +2 -2
- package/dist/result/result.d.ts +18 -10
- package/dist/result/result.js +20 -12
- package/dist/result/result.js.map +1 -1
- package/dist/result.d.ts +2 -2
- package/dist/result.js +2 -2
- package/dist/revocation/chain.js +154 -103
- package/dist/revocation/chain.js.map +1 -1
- package/dist/revocation/crl.d.ts +13 -2
- package/dist/revocation/crl.js +415 -236
- package/dist/revocation/crl.js.map +1 -1
- package/dist/revocation/ocsp.d.ts +58 -17
- package/dist/revocation/ocsp.js +186 -174
- package/dist/revocation/ocsp.js.map +1 -1
- package/dist/revocation/revocation.d.ts +4 -4
- package/dist/revocation/revocation.js +48 -30
- package/dist/revocation/revocation.js.map +1 -1
- package/dist/revocation.d.ts +4 -4
- package/dist/revocation.js +5 -5
- package/dist/verify/identity.d.ts +2 -1
- package/dist/verify/identity.js +2 -1
- package/dist/verify/identity.js.map +1 -1
- package/dist/verify/policy.d.ts +6 -1
- package/dist/verify/verify.d.ts +18 -3
- package/dist/verify/verify.js +66 -41
- package/dist/verify/verify.js.map +1 -1
- package/dist/verify.d.ts +2 -1
- package/dist/verify.js +4 -3
- package/dist/x509/certificate.d.ts +36 -13
- package/dist/x509/certificate.js +36 -19
- package/dist/x509/certificate.js.map +1 -1
- package/dist/x509/csr.d.ts +6 -3
- package/dist/x509/extensions.d.ts +59 -22
- package/dist/x509/extensions.js +384 -117
- package/dist/x509/extensions.js.map +1 -1
- package/dist/x509/name-text.js +2 -0
- package/dist/x509/name-text.js.map +1 -1
- package/dist/x509/name.d.ts +8 -5
- package/dist/x509/name.js +17 -12
- package/dist/x509/name.js.map +1 -1
- package/dist/x509/parse.d.ts +104 -18
- package/dist/x509/parse.js +127 -163
- package/dist/x509/parse.js.map +1 -1
- package/dist/x509.d.ts +8 -5
- package/dist/x509.js +10 -8
- package/package.json +52 -34
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chain.js","names":[],"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 type {\n\tCrlSource,\n\tParsedCertificateRevocationList,\n\tRevocationReason,\n} from '#micro509/revocation/crl';\nimport {\n\tcheckCertificateRevocationAgainstCrl,\n\tparseCertificateRevocationListDerOrThrow,\n\tparseCertificateRevocationListPemOrThrow,\n\trevocationReasonFromCode,\n} from '#micro509/revocation/crl';\nimport type {\n\tOcspResponderRevocationPolicy,\n\tParsedOcspResponse,\n\tValidateOcspResponseFailure,\n\tValidateOcspResponseResult,\n} from '#micro509/revocation/ocsp';\nimport {\n\tparseOcspResponseDerOrThrow,\n\tparseOcspResponsePemOrThrow,\n\tvalidateOcspResponse,\n} from '#micro509/revocation/ocsp';\nimport type { RevocationCertificateSource } from '#micro509/revocation/revocation';\nimport type { ParsedCertificate } from '#micro509/x509/parse';\nimport { 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/**\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}\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). A response signed by one of these is accepted without\n\t * delegated-responder issuance, EKU, and revocation checks.\n\t */\n\treadonly trustedOcspResponders?: readonly RevocationCertificateSource[];\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 */\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 specific\n\t'ocsp_status_unknown',\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?: RevocationReason;\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\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 interface RevocationExecutionError {\n\t/** Error category. */\n\treadonly kind: 'parse_error' | '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 CRL from various source formats.\n */\nfunction parseCrlFromSource(source: CrlSource): ParsedCertificateRevocationList {\n\tif (typeof source === 'object' && 'issuer' in source) {\n\t\treturn source;\n\t}\n\tif (typeof source === 'string') {\n\t\treturn parseCertificateRevocationListPemOrThrow(source);\n\t}\n\treturn parseCertificateRevocationListDerOrThrow(source);\n}\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 * Searches for a certificate that could have signed the given CRL.\n * Matches by AKI/SKI or issuer/subject DN.\n */\nfunction findIndirectCrlIssuer(\n\tcrl: ParsedCertificateRevocationList,\n\textraCertificates: readonly RevocationCertificateSource[],\n\tchain: readonly ParsedCertificate[],\n): ParsedCertificate | undefined {\n\t// Combine extra certs with chain certs for searching\n\t// Chain certs are already parsed; extra certs may need parsing\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\n\t// First pass: prefer AKI/SKI match (more specific)\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\treturn candidate;\n\t\t\t}\n\t\t}\n\t}\n\n\t// Second pass: fall back to DN match\n\tfor (const candidate of candidates) {\n\t\tif (crl.issuer.derHex === candidate.subject.derHex) {\n\t\t\treturn candidate;\n\t\t}\n\t}\n\n\treturn undefined;\n}\n\n/** Lowercases a hex string for bytewise comparison. */\nfunction normalizeHex(value: string): string {\n\treturn value.toLowerCase();\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}\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// Try each CRL to check signer's revocation\n\tfor (const crlSource of ctx.crls) {\n\t\tlet crl: ParsedCertificateRevocationList;\n\t\ttry {\n\t\t\tcrl = parseCrlFromSource(crlSource);\n\t\t} catch {\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Check if this CRL can provide revocation info for the signer\n\t\tconst result = await checkCertificateRevocationAgainstCrl({\n\t\t\tcertificate: signer,\n\t\t\tissuerCertificate: issuer,\n\t\t\tcrl,\n\t\t\tat: ctx.at,\n\t\t});\n\n\t\tif (result.ok) {\n\t\t\tif (result.value.status === 'revoked') {\n\t\t\t\treturn 'resolved-revoked';\n\t\t\t}\n\t\t\tif (result.value.status === 'good') {\n\t\t\t\t// Before accepting this result, validate the CRL's signer\n\t\t\t\t// The CRL's signer is the issuer we just used\n\t\t\t\tconst crlSignerStatus = await validateCrlSigner(issuer, ctx);\n\t\t\t\tif (crlSignerStatus === 'resolved-valid') {\n\t\t\t\t\treturn 'resolved-valid';\n\t\t\t\t}\n\t\t\t\t// If CRL signer is revoked or indeterminate, can't trust this result\n\t\t\t}\n\t\t}\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/** Builds the `revoked` CertificateRevocationStatus for a CRL hit. */\nfunction buildCrlRevokedStatus(\n\tcert: ParsedCertificate,\n\tsigner: ParsedCertificate,\n\tthisUpdate: Date,\n\trevocationDate: Date,\n\treasonCode?: RevocationReason,\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\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\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 '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\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}\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]);\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 shared = {\n\t\tissuerCertificate: issuer,\n\t\tat,\n\t\t...(input.trustedOcspResponders !== undefined\n\t\t\t? { trustedOcspResponders: input.trustedOcspResponders }\n\t\t\t: {}),\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};\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 reasons = new Set<RevocationIndeterminateReason>();\n\n\tfor (const source of ocspResponses) {\n\t\tlet parsed: ParsedOcspResponse;\n\t\ttry {\n\t\t\tparsed = parseOcspResponseFromSource(source);\n\t\t} catch (e) {\n\t\t\texecutionErrors.push({\n\t\t\t\tkind: 'parse_error',\n\t\t\t\tmessage: e instanceof Error ? e.message : 'OCSP response parse failed',\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst entry = (parsed.responses ?? []).find(\n\t\t\t(single) =>\n\t\t\t\tnormalizeHex(single.certId.serialNumberHex) === normalizeHex(cert.serialNumberHex),\n\t\t);\n\t\tif (entry === undefined) {\n\t\t\tcontinue; // Response does not cover this certificate\n\t\t}\n\n\t\tconst validation = await validateOcspResponseWithResponderFallback(parsed, issuer, input, at);\n\t\tif (!validation.ok) {\n\t\t\treasons.add(ocspIndeterminateReasonFromFailure(validation.code));\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (entry.certStatus === 'revoked') {\n\t\t\tconst reason = revocationReasonFromCode(entry.revocationReasonCode);\n\t\t\treturn {\n\t\t\t\tstatus: {\n\t\t\t\t\tcertificate: cert,\n\t\t\t\t\tstatus: 'revoked',\n\t\t\t\t\tsource: { kind: 'ocsp', thisUpdate: entry.thisUpdate },\n\t\t\t\t\trevocationInfo: {\n\t\t\t\t\t\trevocationDate: entry.revokedAt ?? entry.thisUpdate,\n\t\t\t\t\t\t...(reason !== undefined ? { reason } : {}),\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\texecutionErrors,\n\t\t\t};\n\t\t}\n\t\tif (entry.certStatus === 'good') {\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: { kind: 'ocsp', thisUpdate: entry.thisUpdate },\n\t\t\t\t},\n\t\t\t\texecutionErrors,\n\t\t\t};\n\t\t}\n\t\treasons.add('ocsp_status_unknown');\n\t}\n\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/**\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.\nconst ALL_REASON_FLAGS: readonly string[] = [\n\t'keyCompromise',\n\t'cACompromise',\n\t'affiliationChanged',\n\t'superseded',\n\t'cessationOfOperation',\n\t'certificateHold',\n\t'privilegeWithdrawn',\n\t'aACompromise',\n];\n\ninterface CrlEvidenceState {\n\treadonly executionErrors: RevocationExecutionError[];\n\treadonly coveredReasons: Set<string>;\n\tsawCrlSignerRevoked: boolean;\n\tsawCrlSignerIndeterminate: boolean;\n\tsawGood: boolean;\n\tfreshestGood?: { readonly signer: ParsedCertificate; readonly thisUpdate: Date };\n}\n\ninterface ApplicableCrlCheck {\n\treadonly result: Awaited<ReturnType<typeof checkCertificateRevocationAgainstCrl>>;\n\treadonly signer: ParsedCertificate;\n}\n\nasync function evaluateCrlEvidence(\n\tcert: ParsedCertificate,\n\tissuer: ParsedCertificate,\n\tinput: CheckChainRevocationInput,\n\tsignerCtx: SignerValidationContext,\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\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 = parsedCrls.filter((crl) => crl.baseCrlNumber === undefined);\n\tconst deltaCrls = parsedCrls.filter((crl) => crl.baseCrlNumber !== undefined);\n\n\t// Process base CRLs (optionally paired with delta CRLs)\n\tfor (const baseCrl of baseCrls) {\n\t\tconst applicableDelta = findApplicableDeltaCrl(baseCrl, deltaCrls);\n\t\tconst checked = await checkCrlWithAvailableIssuers(\n\t\t\tcert,\n\t\t\tbaseCrl,\n\t\t\tapplicableDelta,\n\t\t\tissuer,\n\t\t\textraCertificates,\n\t\t\tchain,\n\t\t\tat,\n\t\t);\n\t\tif (!checked.result.ok) {\n\t\t\tcontinue; // CRL doesn't apply to this certificate\n\t\t}\n\n\t\t// Validate CRL signer is not revoked before accepting result\n\t\tconst signerStatus = await validateCrlSigner(checked.signer, signerCtx);\n\t\tif (signerStatus === 'resolved-revoked') {\n\t\t\tstate.sawCrlSignerRevoked = true;\n\t\t\tcontinue; // CRL signer revoked — can't trust this CRL\n\t\t}\n\t\tif (signerStatus === 'resolved-indeterminate') {\n\t\t\tstate.sawCrlSignerIndeterminate = true;\n\t\t\tcontinue; // CRL signer status unknown — try other CRLs\n\t\t}\n\n\t\t// Evidence freshness: an applied delta CRL supersedes its base\n\t\tconst crlThisUpdate =\n\t\t\tapplicableDelta !== undefined &&\n\t\t\tapplicableDelta.thisUpdate.getTime() > baseCrl.thisUpdate.getTime()\n\t\t\t\t? applicableDelta.thisUpdate\n\t\t\t\t: baseCrl.thisUpdate;\n\n\t\t// CRL is valid — check result\n\t\tif (checked.result.value.status === 'revoked') {\n\t\t\t// Immediately return revoked status\n\t\t\treturn {\n\t\t\t\tstatus: buildCrlRevokedStatus(\n\t\t\t\t\tcert,\n\t\t\t\t\tchecked.signer,\n\t\t\t\t\tcrlThisUpdate,\n\t\t\t\t\tchecked.result.value.revocationDate,\n\t\t\t\t\tchecked.result.value.reasonCode,\n\t\t\t\t),\n\t\t\t\texecutionErrors: state.executionErrors,\n\t\t\t};\n\t\t}\n\n\t\t// Status is 'good' — track which reasons this CRL covers\n\t\trecordGoodCrlEvidence(state, checked.signer, crlThisUpdate, baseCrl);\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 = ALL_REASON_FLAGS.every((r) => state.coveredReasons.has(r));\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\t// No applicable CRL found — determine most appropriate indeterminate reason\n\tconst reasons: RevocationIndeterminateReason[] = [];\n\tif (state.sawCrlSignerRevoked) {\n\t\treasons.push('crl_signer_revoked');\n\t} else if (state.sawCrlSignerIndeterminate) {\n\t\treasons.push('crl_signer_indeterminate');\n\t} else {\n\t\treasons.push('no_applicable_crl');\n\t}\n\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: state.executionErrors,\n\t};\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(parseCrlFromSource(crlSource));\n\t\t} catch (e) {\n\t\t\texecutionErrors.push({\n\t\t\t\tkind: 'parse_error',\n\t\t\t\tmessage: e instanceof Error ? e.message : 'CRL parse failed',\n\t\t\t});\n\t\t}\n\t}\n\treturn parsedCrls;\n}\n\nfunction findApplicableDeltaCrl(\n\tbaseCrl: ParsedCertificateRevocationList,\n\tdeltaCrls: readonly ParsedCertificateRevocationList[],\n): ParsedCertificateRevocationList | undefined {\n\treturn deltaCrls.find(\n\t\t(deltaCrl) =>\n\t\t\tdeltaCrl.issuer.derHex === baseCrl.issuer.derHex &&\n\t\t\tdeltaCrl.baseCrlNumber !== undefined &&\n\t\t\tbaseCrl.crlNumber !== undefined &&\n\t\t\tBigInt(deltaCrl.baseCrlNumber) <= BigInt(baseCrl.crlNumber),\n\t);\n}\n\n/** Evaluates a CRL against each available issuer until applicable evidence is found. */\nasync function checkCrlWithAvailableIssuers(\n\tcert: ParsedCertificate,\n\tbaseCrl: ParsedCertificateRevocationList,\n\tapplicableDelta: ParsedCertificateRevocationList | undefined,\n\tissuer: ParsedCertificate,\n\textraCertificates: readonly RevocationCertificateSource[],\n\tchain: readonly ParsedCertificate[],\n\tat: Date,\n): Promise<ApplicableCrlCheck> {\n\tconst direct = await checkCrlWithIssuer(cert, baseCrl, applicableDelta, issuer, at);\n\tif (direct.ok) {\n\t\treturn { result: direct, signer: issuer };\n\t}\n\tconst indirectIssuer = findIndirectCrlIssuer(baseCrl, extraCertificates, chain);\n\tif (indirectIssuer === undefined || sameCertificate(indirectIssuer, issuer)) {\n\t\treturn { result: direct, signer: issuer };\n\t}\n\treturn {\n\t\tresult: await checkCrlWithIssuer(cert, baseCrl, applicableDelta, indirectIssuer, at),\n\t\tsigner: indirectIssuer,\n\t};\n}\n\nfunction checkCrlWithIssuer(\n\tcert: ParsedCertificate,\n\tcrl: ParsedCertificateRevocationList,\n\tdeltaCrl: ParsedCertificateRevocationList | undefined,\n\tcrlIssuer: ParsedCertificate,\n\tat: Date,\n): ReturnType<typeof checkCertificateRevocationAgainstCrl> {\n\treturn checkCertificateRevocationAgainstCrl({\n\t\tcertificate: cert,\n\t\tissuerCertificate: crlIssuer,\n\t\tcrl,\n\t\t...(deltaCrl !== undefined ? { deltaCrl } : {}),\n\t\tat,\n\t});\n}\n\nfunction recordGoodCrlEvidence(\n\tstate: CrlEvidenceState,\n\tsigner: ParsedCertificate,\n\tthisUpdate: Date,\n\tbaseCrl: ParsedCertificateRevocationList,\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 baseCrl.issuingDistributionPoint?.onlySomeReasons?.flags ??\n\t\tALL_REASON_FLAGS) {\n\t\tstate.coveredReasons.add(reason);\n\t}\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. If neither source is definitive, indeterminate reasons\n * from both are merged.\n */\nasync function evaluateCertificateRevocation(\n\tcert: ParsedCertificate,\n\tissuer: ParsedCertificate,\n\tinput: CheckChainRevocationInput,\n\tsignerCtx: SignerValidationContext,\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);\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\tif (good !== undefined) {\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// 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.\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\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};\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 { status, executionErrors } = await evaluateCertificateRevocation(\n\t\t\tcert,\n\t\t\tissuer,\n\t\t\tinput,\n\t\t\tsignerCtx,\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":";;;;;;;;;;;;;;;;;AA8HA,MAAa,IAAmC;CAE/C;CACA;CAEA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CAEA;AACD;;;;AAoIA,SAAS,mBAAmB,GAAoD;CAO/E,OANI,OAAO,KAAW,YAAY,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EAAE,WAAQ,uBAAoB,MAAM,8BACzC,GACA,GACA,GACA,CACD;EAIA,AAHA,EAAa,KAAK,CAAM,GACxB,EAAmB,KAAK,GAAG,CAAe,GAEtC,EAAO,WAAW,YACrB,EAAoB,KAAK,CAAI,IACnB,EAAO,WAAW,mBAC5B,EAA0B,KAAK,CAAI;CAErC;CAGA,IAAM,IAAa,EAAoB,SAAS,GAC1C,IAAmB,EAA0B,SAAS;CAO5D,OAAO;EACN,IAAI;EACJ,OAAO;GACN,UATiC,KAEhC,KAAoB,MAAS,cAD7B,SAGC;GAMF,SAAS;IAAE;IAAqB;GAA0B;GAC1D;GACA,GAAI,EAAmB,SAAS,IAAI,EAAE,iBAAiB,EAAmB,IAAI,CAAC;EAChF;CACD;AACD"}
|
|
1
|
+
{"version":3,"file":"chain.js","names":["_exhaustive"],"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 type {\n\tCrlSource,\n\tParsedCertificateRevocationList,\n\tRevocationReason,\n} from '#micro509/revocation/crl';\nimport {\n\tcheckCertificateRevocationAgainstCrl,\n\tcoversAllDistributionPointReasons,\n\tparseCertificateRevocationListDerOrThrow,\n\tparseCertificateRevocationListPemOrThrow,\n\trevocationReasonFromCode,\n} from '#micro509/revocation/crl';\nimport type {\n\tOcspResponderRevocationPolicy,\n\tParsedOcspResponse,\n\tValidateOcspResponseFailure,\n\tValidateOcspResponseResult,\n} from '#micro509/revocation/ocsp';\nimport {\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 { 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/**\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}\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). A response signed by one of these is accepted without\n\t * delegated-responder issuance, EKU, and revocation checks.\n\t */\n\treadonly trustedOcspResponders?: readonly RevocationCertificateSource[];\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 */\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 specific\n\t'ocsp_status_unknown',\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?: RevocationReason;\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\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 interface RevocationExecutionError {\n\t/** Error category. */\n\treadonly kind: 'parse_error' | '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 CRL from various source formats.\n */\nfunction parseCrlFromSource(source: CrlSource): ParsedCertificateRevocationList {\n\tif (typeof source === 'object' && 'issuer' in source) {\n\t\treturn source;\n\t}\n\tif (typeof source === 'string') {\n\t\treturn parseCertificateRevocationListPemOrThrow(source);\n\t}\n\treturn parseCertificateRevocationListDerOrThrow(source);\n}\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}\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\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\tfor (const reason of outcome.reasons) {\n\t\t\tcoveredReasons.add(reason);\n\t\t}\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, or the reasons it covers. */\ntype SignerCrlOutcome =\n\t| { readonly kind: 'revoked' }\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 = parseCrlFromSource(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});\n\tif (!result.ok) {\n\t\treturn 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?: RevocationReason,\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\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\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 '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\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]);\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 shared = {\n\t\tissuerCertificate: issuer,\n\t\tat,\n\t\t...(input.trustedOcspResponders !== undefined\n\t\t\t? { trustedOcspResponders: input.trustedOcspResponders }\n\t\t\t: {}),\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};\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 reasons = new Set<RevocationIndeterminateReason>();\n\n\tfor (const source of ocspResponses) {\n\t\tlet parsed: ParsedOcspResponse;\n\t\ttry {\n\t\t\tparsed = parseOcspResponseFromSource(source);\n\t\t} catch (e) {\n\t\t\texecutionErrors.push({\n\t\t\t\tkind: 'parse_error',\n\t\t\t\tmessage: e instanceof Error ? e.message : 'OCSP response parse failed',\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst entry = (parsed.responses ?? []).find(\n\t\t\t(single) =>\n\t\t\t\tnormalizeHex(single.certId.serialNumberHex) === normalizeHex(cert.serialNumberHex),\n\t\t);\n\t\tif (entry === undefined) {\n\t\t\tcontinue; // Response does not cover this certificate\n\t\t}\n\n\t\tconst validation = await validateOcspResponseWithResponderFallback(parsed, issuer, input, at);\n\t\tif (!validation.ok) {\n\t\t\treasons.add(ocspIndeterminateReasonFromFailure(validation.code));\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (entry.certStatus === 'revoked') {\n\t\t\tconst reason = revocationReasonFromCode(entry.revocationReasonCode);\n\t\t\treturn {\n\t\t\t\tstatus: {\n\t\t\t\t\tcertificate: cert,\n\t\t\t\t\tstatus: 'revoked',\n\t\t\t\t\tsource: { kind: 'ocsp', thisUpdate: entry.thisUpdate },\n\t\t\t\t\trevocationInfo: {\n\t\t\t\t\t\trevocationDate: entry.revokedAt ?? entry.thisUpdate,\n\t\t\t\t\t\t...(reason !== undefined ? { reason } : {}),\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\texecutionErrors,\n\t\t\t};\n\t\t}\n\t\tif (entry.certStatus === 'good') {\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: { kind: 'ocsp', thisUpdate: entry.thisUpdate },\n\t\t\t\t},\n\t\t\t\texecutionErrors,\n\t\t\t};\n\t\t}\n\t\treasons.add('ocsp_status_unknown');\n\t}\n\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/**\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\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 applicableDelta: ParsedCertificateRevocationList | undefined;\n\treadonly crlThisUpdate: Date;\n\treadonly issuer: ParsedCertificate;\n\treadonly extraCertificates: readonly RevocationCertificateSource[];\n\treadonly chain: readonly ParsedCertificate[];\n\treadonly at: Date;\n\treadonly signerCtx: SignerValidationContext;\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\tapplicableDelta,\n\t\tcrlThisUpdate,\n\t\tissuer,\n\t\textraCertificates,\n\t\tchain,\n\t\tat,\n\t\tsignerCtx,\n\t\tstate,\n\t} = params;\n\tfor (const candidate of collectCrlSignerCandidates(baseCrl, issuer, extraCertificates, chain)) {\n\t\tconst checked = await checkCrlWithIssuer(cert, baseCrl, applicableDelta, candidate, at);\n\t\tif (!checked.ok) {\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 (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): 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\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 = parsedCrls.filter((crl) => crl.baseCrlNumber === undefined);\n\tconst deltaCrls = parsedCrls.filter((crl) => crl.baseCrlNumber !== undefined);\n\n\t// Process base CRLs (optionally paired with delta CRLs)\n\tfor (const baseCrl of baseCrls) {\n\t\tconst applicableDelta = findApplicableDeltaCrl(baseCrl, deltaCrls);\n\t\t// Evidence freshness: an applied delta CRL supersedes its base\n\t\tconst crlThisUpdate =\n\t\t\tapplicableDelta !== undefined &&\n\t\t\tapplicableDelta.thisUpdate.getTime() > baseCrl.thisUpdate.getTime()\n\t\t\t\t? applicableDelta.thisUpdate\n\t\t\t\t: baseCrl.thisUpdate;\n\t\tconst revoked = await resolveBaseCrlAgainstSigners({\n\t\t\tcert,\n\t\t\tbaseCrl,\n\t\t\tapplicableDelta,\n\t\t\tcrlThisUpdate,\n\t\t\tissuer,\n\t\t\textraCertificates,\n\t\t\tchain,\n\t\t\tat,\n\t\t\tsignerCtx,\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\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/** 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\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(parseCrlFromSource(crlSource));\n\t\t} catch (e) {\n\t\t\texecutionErrors.push({\n\t\t\t\tkind: 'parse_error',\n\t\t\t\tmessage: e instanceof Error ? e.message : 'CRL parse failed',\n\t\t\t});\n\t\t}\n\t}\n\treturn parsedCrls;\n}\n\nfunction findApplicableDeltaCrl(\n\tbaseCrl: ParsedCertificateRevocationList,\n\tdeltaCrls: readonly ParsedCertificateRevocationList[],\n): ParsedCertificateRevocationList | undefined {\n\treturn deltaCrls.find(\n\t\t(deltaCrl) =>\n\t\t\tdeltaCrl.issuer.derHex === baseCrl.issuer.derHex &&\n\t\t\tdeltaCrl.baseCrlNumber !== undefined &&\n\t\t\tbaseCrl.crlNumber !== undefined &&\n\t\t\tBigInt(deltaCrl.baseCrlNumber) <= BigInt(baseCrl.crlNumber),\n\t);\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 checkCrlWithIssuer(\n\tcert: ParsedCertificate,\n\tcrl: ParsedCertificateRevocationList,\n\tdeltaCrl: ParsedCertificateRevocationList | undefined,\n\tcrlIssuer: ParsedCertificate,\n\tat: Date,\n): ReturnType<typeof checkCertificateRevocationAgainstCrl> {\n\treturn checkCertificateRevocationAgainstCrl({\n\t\tcertificate: cert,\n\t\tissuerCertificate: crlIssuer,\n\t\tcrl,\n\t\t...(deltaCrl !== undefined ? { deltaCrl } : {}),\n\t\tat,\n\t});\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/**\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. If neither source is definitive, indeterminate reasons\n * from both are merged.\n */\nasync function evaluateCertificateRevocation(\n\tcert: ParsedCertificate,\n\tissuer: ParsedCertificate,\n\tinput: CheckChainRevocationInput,\n\tsignerCtx: SignerValidationContext,\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);\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\tif (good !== undefined) {\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// 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.\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\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};\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 { status, executionErrors } = await evaluateCertificateRevocation(\n\t\t\tcert,\n\t\t\tissuer,\n\t\t\tinput,\n\t\t\tsignerCtx,\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":";;;;;;;;;;;;;;;;;;AAiIA,MAAa,IAAmC;CAE/C;CACA;CAEA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CAEA;AACD;;;;AAoIA,SAAS,mBAAmB,GAAoD;CAO/E,OANI,OAAO,KAAW,YAAY,YAAY,IACtC,IAEJ,OAAO,KAAW,WACd,EAAyC,CAAM,IAEhD,EAAyC,CAAM;AACvD;;;;AAKA,SAAS,qBAAqB,GAAoE;CACjG,IAAI;EACH,OAAO,EAA2B,CAAM;CACzC,QAAQ;EACP;CACD;AACD;;;;;AAMA,SAAS,gBAAgB,GAAsB,GAA+B;CAC7E,IAAI,EAAE,IAAI,WAAW,EAAE,IAAI,QAAQ,OAAO;CAC1C,KAAK,IAAI,IAAI,GAAG,IAAI,EAAE,IAAI,QAAQ,KACjC,IAAI,EAAE,IAAI,OAAO,EAAE,IAAI,IAAI,OAAO;CAEnC,OAAO;AACR;;;;;;;AAQA,SAAS,uBACR,GACA,GACA,GAC+B;CAC/B,IAAM,IAAoC,CAAC;CAC3C,KAAK,IAAM,KAAU,GAAmB;EACvC,IAAM,IAAS,qBAAqB,CAAM;EAC1C,AAAI,MAAW,KAAA,KACd,EAAa,KAAK,CAAM;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;CACD;AACD"}
|
package/dist/revocation/crl.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ErrorResult, Micro509Error } from "../result/result.js";
|
|
2
2
|
import { NameInput } from "../x509/name.js";
|
|
3
|
-
import { DistributionPoint, GeneralName, IssuingDistributionPoint } from "../x509/extensions.js";
|
|
3
|
+
import { DistributionPoint, DistributionPointReason, GeneralName, IssuingDistributionPoint } from "../x509/extensions.js";
|
|
4
4
|
import { ParsedCertificate, ParsedDistributionPoint, ParsedIssuingDistributionPoint, ParsedName } from "../x509/parse.js";
|
|
5
5
|
//#region src/revocation/crl.d.ts
|
|
6
6
|
/**
|
|
@@ -203,6 +203,13 @@ interface CheckCertificateRevocationAgainstCrlGoodValue {
|
|
|
203
203
|
readonly status: "good";
|
|
204
204
|
/** The validated CRL that was checked. */
|
|
205
205
|
readonly crl: ParsedCertificateRevocationList;
|
|
206
|
+
/**
|
|
207
|
+
* Revocation reasons this check covered, the RFC 5280 §6.3.3 (d)
|
|
208
|
+
* interim_reasons_mask: the matched distribution point's reasons intersected
|
|
209
|
+
* with the CRL's `onlySomeReasons`, either alone when the other is absent,
|
|
210
|
+
* or every reason when both are.
|
|
211
|
+
*/
|
|
212
|
+
readonly coveredReasons: readonly DistributionPointReason[];
|
|
206
213
|
}
|
|
207
214
|
/** Success value when the certificate is found as revoked in the CRL. */
|
|
208
215
|
interface CheckCertificateRevocationAgainstCrlRevokedValue {
|
|
@@ -340,6 +347,10 @@ declare function checkCertificateRevocationAgainstCrl(input: CheckCertificateRev
|
|
|
340
347
|
* CRL's revoked entries. Does **not** validate the CRL or check applicability.
|
|
341
348
|
*/
|
|
342
349
|
declare function isCertificateRevoked(certificateSerialNumber: Uint8Array | string, crl: ParsedCertificateRevocationList): boolean;
|
|
350
|
+
/** Machine-readable reason a CRL encoder rejected its construction input. */
|
|
351
|
+
type CrlEncoderErrorCode = "distribution_point_full_name_empty" | "issuer_distinguished_name_empty";
|
|
352
|
+
/** Maps an integer CRLReason code back to its {@linkcode RevocationReason} string, or `undefined` for unknown codes. */
|
|
353
|
+
declare function revocationReasonFromCode(code: number | undefined): RevocationReason | undefined;
|
|
343
354
|
//#endregion
|
|
344
|
-
export { CertificateRevocationListMaterial, CheckCertificateRevocationAgainstCrlErrorCode, CheckCertificateRevocationAgainstCrlFailure, CheckCertificateRevocationAgainstCrlFailureDetails, CheckCertificateRevocationAgainstCrlGoodValue, CheckCertificateRevocationAgainstCrlInput, CheckCertificateRevocationAgainstCrlResult, CheckCertificateRevocationAgainstCrlRevokedValue, CheckCertificateRevocationAgainstCrlValue, CreateCertificateRevocationListInput, CrlApplicabilityFailureReason, CrlCertificateSource, CrlSource, ParseCertificateRevocationListErrorCode, ParseCertificateRevocationListFailure, ParseCertificateRevocationListResult, ParsedCertificateRevocationList, ParsedRevokedCertificate, RevocationReason, RevokedCertificateInput, ValidateCertificateRevocationListFailure, ValidateCertificateRevocationListInput, ValidateCertificateRevocationListResult, VerifyCertificateRevocationListSignatureFailure, VerifyCertificateRevocationListSignatureResult, checkCertificateRevocationAgainstCrl, createCertificateRevocationList, isCertificateRevoked, parseCertificateRevocationListDer, parseCertificateRevocationListDerOrThrow, parseCertificateRevocationListPem, parseCertificateRevocationListPemOrThrow, validateCertificateRevocationList, verifyCertificateRevocationListSignature };
|
|
355
|
+
export { CertificateRevocationListMaterial, CheckCertificateRevocationAgainstCrlErrorCode, CheckCertificateRevocationAgainstCrlFailure, CheckCertificateRevocationAgainstCrlFailureDetails, CheckCertificateRevocationAgainstCrlGoodValue, CheckCertificateRevocationAgainstCrlInput, CheckCertificateRevocationAgainstCrlResult, CheckCertificateRevocationAgainstCrlRevokedValue, CheckCertificateRevocationAgainstCrlValue, CreateCertificateRevocationListInput, CrlApplicabilityFailureReason, CrlCertificateSource, CrlEncoderErrorCode, CrlSource, ParseCertificateRevocationListErrorCode, ParseCertificateRevocationListFailure, ParseCertificateRevocationListResult, ParsedCertificateRevocationList, ParsedRevokedCertificate, RevocationReason, RevokedCertificateInput, ValidateCertificateRevocationListFailure, ValidateCertificateRevocationListInput, ValidateCertificateRevocationListResult, VerifyCertificateRevocationListSignatureFailure, VerifyCertificateRevocationListSignatureResult, checkCertificateRevocationAgainstCrl, createCertificateRevocationList, isCertificateRevoked, parseCertificateRevocationListDer, parseCertificateRevocationListDerOrThrow, parseCertificateRevocationListPem, parseCertificateRevocationListPemOrThrow, revocationReasonFromCode, validateCertificateRevocationList, verifyCertificateRevocationListSignature };
|
|
345
356
|
//# sourceMappingURL=crl.d.ts.map
|