micro509 0.14.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/CHANGELOG.md +2064 -0
  2. package/README.md +105 -225
  3. package/dist/crypto/crypto.d.ts +42 -11
  4. package/dist/crypto/crypto.js +53 -22
  5. package/dist/crypto/crypto.js.map +1 -1
  6. package/dist/crypto.d.ts +2 -2
  7. package/dist/crypto.js +1 -2
  8. package/dist/der/der.d.ts +41 -33
  9. package/dist/der/der.js +26 -24
  10. package/dist/der/der.js.map +1 -1
  11. package/dist/index.d.ts +10 -10
  12. package/dist/index.js +19 -19
  13. package/dist/internal/asn1/asn1.d.ts +3 -6
  14. package/dist/internal/asn1/asn1.js +343 -43
  15. package/dist/internal/asn1/asn1.js.map +1 -1
  16. package/dist/internal/asn1/ber.js +146 -0
  17. package/dist/internal/asn1/ber.js.map +1 -0
  18. package/dist/internal/asn1/decode-refusal.js +29 -0
  19. package/dist/internal/asn1/decode-refusal.js.map +1 -0
  20. package/dist/internal/asn1/der.d.ts +38 -41
  21. package/dist/internal/asn1/der.js +131 -52
  22. package/dist/internal/asn1/der.js.map +1 -1
  23. package/dist/internal/asn1/oids.js +83 -53
  24. package/dist/internal/asn1/oids.js.map +1 -1
  25. package/dist/internal/asn1/oids2.js +1 -2
  26. package/dist/internal/asn1/oids2.js.map +1 -1
  27. package/dist/internal/crypto/algorithm-names.js +1 -2
  28. package/dist/internal/crypto/algorithm-names.js.map +1 -1
  29. package/dist/internal/crypto/ecdsa.js +13 -8
  30. package/dist/internal/crypto/ecdsa.js.map +1 -1
  31. package/dist/internal/crypto/hash.js +1 -2
  32. package/dist/internal/crypto/hash.js.map +1 -1
  33. package/dist/internal/crypto/pbes2.d.ts +24 -11
  34. package/dist/internal/crypto/pbes2.js +79 -26
  35. package/dist/internal/crypto/pbes2.js.map +1 -1
  36. package/dist/internal/crypto/rsa-pss.js +46 -44
  37. package/dist/internal/crypto/rsa-pss.js.map +1 -1
  38. package/dist/internal/crypto/sig-verify.d.ts +4 -7
  39. package/dist/internal/crypto/sig-verify.js +107 -60
  40. package/dist/internal/crypto/sig-verify.js.map +1 -1
  41. package/dist/internal/crypto/signing.d.ts +1 -4
  42. package/dist/internal/crypto/signing.js +28 -29
  43. package/dist/internal/crypto/signing.js.map +1 -1
  44. package/dist/internal/crypto/webcrypto.js +1 -2
  45. package/dist/internal/crypto/webcrypto.js.map +1 -1
  46. package/dist/internal/shared/base64.js +1 -2
  47. package/dist/internal/shared/base64.js.map +1 -1
  48. package/dist/internal/shared/dn.d.ts +3 -6
  49. package/dist/internal/shared/dn.js +99 -53
  50. package/dist/internal/shared/dn.js.map +1 -1
  51. package/dist/internal/shared/idna-tables.js +7217 -0
  52. package/dist/internal/shared/idna-tables.js.map +1 -0
  53. package/dist/internal/shared/idna.js +296 -0
  54. package/dist/internal/shared/idna.js.map +1 -0
  55. package/dist/internal/shared/ip.d.ts +4 -7
  56. package/dist/internal/shared/ip.js +1 -2
  57. package/dist/internal/shared/ip.js.map +1 -1
  58. package/dist/internal/shared/mailbox.js +26 -0
  59. package/dist/internal/shared/mailbox.js.map +1 -0
  60. package/dist/internal/shared/punycode.js +101 -0
  61. package/dist/internal/shared/punycode.js.map +1 -0
  62. package/dist/internal/shared/rfc3454-tables.js +1 -2
  63. package/dist/internal/shared/rfc3454-tables.js.map +1 -1
  64. package/dist/internal/shared/rfc4518-tables.js +119 -0
  65. package/dist/internal/shared/rfc4518-tables.js.map +1 -0
  66. package/dist/internal/shared/uri-host.js +102 -0
  67. package/dist/internal/shared/uri-host.js.map +1 -0
  68. package/dist/internal/verify/name-constraints-engine.js +246 -131
  69. package/dist/internal/verify/name-constraints-engine.js.map +1 -1
  70. package/dist/internal/verify/policy-engine.js +6 -21
  71. package/dist/internal/verify/policy-engine.js.map +1 -1
  72. package/dist/internal/verify/verify-path.d.ts +1 -4
  73. package/dist/internal/verify/verify-path.js +267 -131
  74. package/dist/internal/verify/verify-path.js.map +1 -1
  75. package/dist/internal/x509/directory-name.js +1 -2
  76. package/dist/internal/x509/directory-name.js.map +1 -1
  77. package/dist/internal/x509/extension-bits.js +2 -3
  78. package/dist/internal/x509/extension-bits.js.map +1 -1
  79. package/dist/internal/x509/extension-errors.d.ts +1 -4
  80. package/dist/internal/x509/extension-errors.js +1 -2
  81. package/dist/internal/x509/extension-errors.js.map +1 -1
  82. package/dist/internal/x509/extension-registry.js +107 -89
  83. package/dist/internal/x509/extension-registry.js.map +1 -1
  84. package/dist/internal/x509/general-name-profile.js +129 -0
  85. package/dist/internal/x509/general-name-profile.js.map +1 -0
  86. package/dist/internal/x509/general-name-tags.js +1 -2
  87. package/dist/internal/x509/general-name-tags.js.map +1 -1
  88. package/dist/internal/x509/general-name.js +128 -42
  89. package/dist/internal/x509/general-name.js.map +1 -1
  90. package/dist/internal/x509/name-fields.js +1 -2
  91. package/dist/internal/x509/name-fields.js.map +1 -1
  92. package/dist/internal/x509/or-address.js +217 -0
  93. package/dist/internal/x509/or-address.js.map +1 -0
  94. package/dist/keys/keys.d.ts +112 -97
  95. package/dist/keys/keys.js +211 -204
  96. package/dist/keys/keys.js.map +1 -1
  97. package/dist/keys.d.ts +3 -3
  98. package/dist/pem/pem.d.ts +14 -17
  99. package/dist/pem/pem.js +16 -17
  100. package/dist/pem/pem.js.map +1 -1
  101. package/dist/pem.js +1 -2
  102. package/dist/pkcs/pfx.d.ts +57 -32
  103. package/dist/pkcs/pfx.js +209 -173
  104. package/dist/pkcs/pfx.js.map +1 -1
  105. package/dist/pkcs/pkcs12-mac.d.ts +104 -27
  106. package/dist/pkcs/pkcs12-mac.js +266 -79
  107. package/dist/pkcs/pkcs12-mac.js.map +1 -1
  108. package/dist/pkcs/pkcs7.d.ts +43 -37
  109. package/dist/pkcs/pkcs7.js +218 -217
  110. package/dist/pkcs/pkcs7.js.map +1 -1
  111. package/dist/pkcs.d.ts +4 -3
  112. package/dist/result/result.d.ts +27 -20
  113. package/dist/result/result.js +8 -3
  114. package/dist/result/result.js.map +1 -1
  115. package/dist/result.d.ts +2 -2
  116. package/dist/result.js +1 -2
  117. package/dist/revocation/chain.d.ts +101 -23
  118. package/dist/revocation/chain.js +436 -182
  119. package/dist/revocation/chain.js.map +1 -1
  120. package/dist/revocation/crl.d.ts +131 -67
  121. package/dist/revocation/crl.js +444 -323
  122. package/dist/revocation/crl.js.map +1 -1
  123. package/dist/revocation/ocsp.d.ts +94 -59
  124. package/dist/revocation/ocsp.js +331 -293
  125. package/dist/revocation/ocsp.js.map +1 -1
  126. package/dist/revocation/revocation.d.ts +47 -35
  127. package/dist/revocation/revocation.js +88 -57
  128. package/dist/revocation/revocation.js.map +1 -1
  129. package/dist/revocation.d.ts +3 -3
  130. package/dist/verify/identity.d.ts +16 -19
  131. package/dist/verify/identity.js +118 -89
  132. package/dist/verify/identity.js.map +1 -1
  133. package/dist/verify/name-constraints.d.ts +1 -4
  134. package/dist/verify/policy.d.ts +9 -7
  135. package/dist/verify/verify.d.ts +84 -46
  136. package/dist/verify/verify.js +300 -152
  137. package/dist/verify/verify.js.map +1 -1
  138. package/dist/verify.d.ts +2 -2
  139. package/dist/x509/certificate.d.ts +20 -21
  140. package/dist/x509/certificate.js +62 -46
  141. package/dist/x509/certificate.js.map +1 -1
  142. package/dist/x509/csr.d.ts +5 -7
  143. package/dist/x509/csr.js +10 -11
  144. package/dist/x509/csr.js.map +1 -1
  145. package/dist/x509/extensions.d.ts +154 -66
  146. package/dist/x509/extensions.js +317 -151
  147. package/dist/x509/extensions.js.map +1 -1
  148. package/dist/x509/fingerprint.d.ts +4 -7
  149. package/dist/x509/fingerprint.js +1 -2
  150. package/dist/x509/fingerprint.js.map +1 -1
  151. package/dist/x509/name-text.d.ts +7 -9
  152. package/dist/x509/name-text.js +18 -4
  153. package/dist/x509/name-text.js.map +1 -1
  154. package/dist/x509/name.d.ts +9 -11
  155. package/dist/x509/name.js +18 -19
  156. package/dist/x509/name.js.map +1 -1
  157. package/dist/x509/parse.d.ts +84 -69
  158. package/dist/x509/parse.js +421 -400
  159. package/dist/x509/parse.js.map +1 -1
  160. package/dist/x509.d.ts +2 -2
  161. package/package.json +76 -59
@@ -1,8 +1,20 @@
1
- import { parseCertificateFromSource as e } from "../x509/parse.js";
2
- import { checkCertificateRevocationAgainstCrl as t, coversAllDistributionPointReasons as n, parseCertificateRevocationListDerOrThrow as r, parseCertificateRevocationListPemOrThrow as i, revocationReasonFromCode as a } from "./crl.js";
3
- import { verifyCertificateChain as o } from "../verify/verify.js";
4
- import { parseOcspResponseDerOrThrow as s, parseOcspResponsePemOrThrow as c, validateOcspResponse as l } from "./ocsp.js";
5
- //#region src/revocation/chain.ts
1
+ import { DECODE_REFUSAL_CODES as e } from "../result/result.js";
2
+ import { decodeRefusalOf as t } from "../internal/asn1/decode-refusal.js";
3
+ import { toHex as n } from "../internal/asn1/asn1.js";
4
+ import { parseCertificateDer as r, parseCertificateFromSource as i } from "../x509/parse.js";
5
+ import { assertCrlMaxAge as a, authenticateCrl as o, checkCertificateRevocationAgainstCrl as s, checkRevocationAgainstAuthenticatedCrl as c, coversAllDistributionPointReasons as l, isCrlApplicableTo as u, isCurrentDeltaCrl as d, normalizeCrl as f, revocationReasonFromCode as p } from "./crl.js";
6
+ import { verifyCertificateChain as m } from "../verify/verify.js";
7
+ import { carriesOcspNoCheck as h, parseOcspResponseDerOrThrow as g, parseOcspResponsePemOrThrow as _, validateOcspResponse as v } from "./ocsp.js";
8
+ // src/revocation/chain.ts
9
+ /**
10
+ * Chain-level revocation orchestration.
11
+ *
12
+ * Evaluates CRL and OCSP evidence for an entire validated certificate chain,
13
+ * implementing the revocation checking portion of RFC 5280 §6.3.
14
+ *
15
+ * @see {@link https://datatracker.ietf.org/doc/html/rfc5280#section-6.3 | RFC 5280 §6.3 CRL Validation}
16
+ * @module
17
+ */
6
18
  /**
7
19
  * Granular reasons why revocation status could not be determined.
8
20
  *
@@ -14,9 +26,18 @@ import { parseOcspResponseDerOrThrow as s, parseOcspResponsePemOrThrow as c, val
14
26
  * `reason_scope_mismatch`, `indirect_crl_scope_mismatch`, `reason_coverage_incomplete`
15
27
  * - **Signer trust**: `crl_signer_not_found`, `crl_signer_not_authorized`,
16
28
  * `crl_signer_revoked`, `crl_signer_indeterminate`, and OCSP equivalents
17
- * - **Freshness**: `crl_expired`, `ocsp_response_expired`
29
+ * - **Freshness**: `crl_expired`, `ocsp_response_expired`,
30
+ * `ocsp_next_update_missing`
31
+ * - **Delta CRL**: `delta_crl_unusable` when an authenticated, current delta
32
+ * CRL cannot settle the status, `delta_crl_retry_limit_exceeded` when delta
33
+ * CRL candidates remain after the attempt limit. Either one outranks a
34
+ * `good` verdict from other evidence.
35
+ * - **Reason code**: `crl_reason_code_unrecognized` and
36
+ * `ocsp_reason_code_unrecognized` when evidence revokes the certificate with
37
+ * an unrecognized CRLReason under `unrecognizedReasonCode: 'reject'`. Either
38
+ * one outranks a `good` verdict from other evidence.
18
39
  */
19
- const u = [
40
+ const y = [
20
41
  "no_applicable_crl",
21
42
  "no_applicable_ocsp",
22
43
  "distribution_point_mismatch",
@@ -34,20 +55,19 @@ const u = [
34
55
  "ocsp_responder_indeterminate",
35
56
  "crl_expired",
36
57
  "ocsp_response_expired",
37
- "ocsp_status_unknown"
58
+ "ocsp_next_update_missing",
59
+ "ocsp_status_unknown",
60
+ "delta_crl_unusable",
61
+ "delta_crl_retry_limit_exceeded",
62
+ "crl_reason_code_unrecognized",
63
+ "ocsp_reason_code_unrecognized"
38
64
  ];
39
65
  /**
40
- * Parses a CRL from various source formats.
41
- */
42
- function parseCrlFromSource(e) {
43
- return typeof e == "object" && "issuer" in e ? e : typeof e == "string" ? i(e) : r(e);
44
- }
45
- /**
46
66
  * Parses a certificate from various source formats, returning undefined on failure.
47
67
  */
48
- function parseCertificateSafe(t) {
68
+ function parseCertificateSafe(e) {
49
69
  try {
50
- return e(t);
70
+ return i(e);
51
71
  } catch {
52
72
  return;
53
73
  }
@@ -105,7 +125,7 @@ async function crlSignerChainsToAnchor(e, t, n, r) {
105
125
  let t = parseCertificateSafe(e);
106
126
  t !== void 0 && addCandidate(t);
107
127
  }
108
- return (await o({
128
+ return (await m({
109
129
  leaf: e.der,
110
130
  intermediates: a.map((e) => e.der),
111
131
  roots: [i.der],
@@ -152,16 +172,17 @@ function findSignerIssuer(e, t) {
152
172
  * Checks if a CRL signer certificate is revoked by examining available CRLs.
153
173
  * Recursively validates the CRL signer of any CRL used to check revocation.
154
174
  */
155
- async function checkSignerRevocation(e, t, r) {
156
- let i = r.chain.some((e) => sameCertificate(e, t)), a = /* @__PURE__ */ new Set();
157
- for (let n of r.crls) {
158
- let i = await checkSignerAgainstCrl(e, t, n, r);
159
- if (i.kind === "revoked") return "resolved-revoked";
160
- for (let e of i.reasons) a.add(e);
175
+ async function checkSignerRevocation(e, t, n) {
176
+ let r = n.chain.some((e) => sameCertificate(e, t)), i = /* @__PURE__ */ new Set(), a = !1;
177
+ for (let r of n.crls) {
178
+ let o = await checkSignerAgainstCrl(e, t, r, n);
179
+ if (o.kind === "revoked") return "resolved-revoked";
180
+ if (o.kind === "unrecognized_reason") a = !0;
181
+ else for (let e of o.reasons) i.add(e);
161
182
  }
162
- return n(a) || i ? "resolved-valid" : "resolved-indeterminate";
183
+ return a ? "resolved-indeterminate" : l(i) || r ? "resolved-valid" : "resolved-indeterminate";
163
184
  }
164
- const d = {
185
+ const b = {
165
186
  kind: "reasons",
166
187
  reasons: []
167
188
  };
@@ -170,23 +191,26 @@ const d = {
170
191
  * apply, or is itself signed by a signer that is not known good yields no
171
192
  * evidence rather than a verdict.
172
193
  */
173
- async function checkSignerAgainstCrl(e, n, r, i) {
174
- let a;
194
+ async function checkSignerAgainstCrl(e, t, n, r) {
195
+ let i;
175
196
  try {
176
- a = parseCrlFromSource(r);
197
+ i = f(n);
177
198
  } catch {
178
- return d;
199
+ return b;
179
200
  }
180
- let o = await t({
201
+ let a = await s({
181
202
  certificate: e,
182
- issuerCertificate: n,
183
- crl: a,
184
- at: i.at
203
+ issuerCertificate: t,
204
+ crl: i,
205
+ at: r.at,
206
+ ...r.crlMaxAgeMs === void 0 ? {} : { maxAgeMs: r.crlMaxAgeMs },
207
+ ...r.clockSkewMs === void 0 ? {} : { clockSkewMs: r.clockSkewMs },
208
+ unrecognizedReasonCode: r.unrecognizedReasonCode
185
209
  });
186
- return o.ok ? o.value.status === "revoked" ? { kind: "revoked" } : await validateCrlSigner(n, i) === "resolved-valid" ? {
210
+ return a.ok ? a.value.status === "revoked" ? { kind: "revoked" } : await validateCrlSigner(t, r) === "resolved-valid" ? {
187
211
  kind: "reasons",
188
- reasons: o.value.coveredReasons
189
- } : d : d;
212
+ reasons: a.value.coveredReasons
213
+ } : b : a.code === "reason_code_unrecognized" ? { kind: "unrecognized_reason" } : b;
190
214
  }
191
215
  /** Builds the `revoked` CertificateRevocationStatus for a CRL hit. */
192
216
  function buildCrlRevokedStatus(e, t, n, r, i) {
@@ -206,18 +230,107 @@ function buildCrlRevokedStatus(e, t, n, r, i) {
206
230
  }
207
231
  /** Parses an OCSP response from PEM string or DER bytes. */
208
232
  function parseOcspResponseFromSource(e) {
209
- return typeof e == "string" ? c(e) : s(e);
233
+ return typeof e == "string" ? _(e) : g(e);
234
+ }
235
+ function evidenceParseError(n, r) {
236
+ return {
237
+ kind: "parse_error",
238
+ code: t(n, e)?.code ?? "malformed",
239
+ message: n instanceof Error ? n.message : r
240
+ };
241
+ }
242
+ /** Parses one OCSP source and locates the entry for the certificate under evaluation. */
243
+ function findApplicableOcspResponse(e, t) {
244
+ let n;
245
+ try {
246
+ n = parseOcspResponseFromSource(e);
247
+ } catch (e) {
248
+ return {
249
+ kind: "parse_error",
250
+ error: evidenceParseError(e, "OCSP response parse failed")
251
+ };
252
+ }
253
+ let r = (n.responses ?? []).find((e) => normalizeHex(e.certId.serialNumberHex) === normalizeHex(t.serialNumberHex));
254
+ return r === void 0 ? { kind: "not_applicable" } : {
255
+ kind: "applicable",
256
+ parsed: n,
257
+ entry: r
258
+ };
259
+ }
260
+ /** Returns the later of two evidence timestamps, tolerating an empty accumulator. */
261
+ function laterEvidenceDate(e, t) {
262
+ return e === void 0 || t.getTime() > e.getTime() ? t : e;
263
+ }
264
+ /** Builds a definitive OCSP-revoked status from a validated response entry. */
265
+ function buildOcspRevokedStatus(e, t, n, r) {
266
+ return {
267
+ certificate: e,
268
+ status: "revoked",
269
+ source: {
270
+ kind: "ocsp",
271
+ thisUpdate: t
272
+ },
273
+ revocationInfo: {
274
+ revocationDate: n,
275
+ ...r === void 0 ? {} : { reason: r }
276
+ }
277
+ };
278
+ }
279
+ /** Classifies one fully validated OCSP entry for aggregation. */
280
+ function classifyValidatedOcspEntry(e, t, n) {
281
+ if (t.certStatus === "good") return {
282
+ kind: "good",
283
+ thisUpdate: t.thisUpdate
284
+ };
285
+ if (t.certStatus === "unknown") return { kind: "unknown" };
286
+ let r = p(t.revocationReasonCode);
287
+ if (n === "reject" && typeof r == "object") return { kind: "unrecognized_reason" };
288
+ let i = buildOcspRevokedStatus(e, t.thisUpdate, t.revokedAt, r);
289
+ return r === "certificateHold" ? {
290
+ kind: "hold",
291
+ evidence: {
292
+ status: i,
293
+ thisUpdate: t.thisUpdate
294
+ }
295
+ } : {
296
+ kind: "revoked",
297
+ status: i
298
+ };
299
+ }
300
+ /** Builds the definitive OCSP-good result or the accumulated indeterminate result. */
301
+ function finalizeOcspEvidence(e, t, n, r) {
302
+ return t === void 0 ? (n.size === 0 && n.add("no_applicable_ocsp"), {
303
+ status: {
304
+ certificate: e,
305
+ status: "indeterminate",
306
+ indeterminateReasons: [...n]
307
+ },
308
+ executionErrors: r
309
+ }) : {
310
+ status: {
311
+ certificate: e,
312
+ status: "good",
313
+ source: {
314
+ kind: "ocsp",
315
+ thisUpdate: t
316
+ }
317
+ },
318
+ executionErrors: r
319
+ };
210
320
  }
211
321
  /** Maps a {@linkcode validateOcspResponse} failure code to an indeterminate reason. */
212
322
  function ocspIndeterminateReasonFromFailure(e) {
213
323
  switch (e) {
214
324
  case "stale_response": return "ocsp_response_expired";
325
+ case "next_update_missing": return "ocsp_next_update_missing";
215
326
  case "responder_id_mismatch":
216
327
  case "responder_chain_invalid":
217
328
  case "ocsp_signing_missing": return "ocsp_responder_not_authorized";
218
329
  case "responder_revoked": return "ocsp_responder_revoked";
219
330
  case "signature_invalid":
220
- case "responder_revocation_unknown": return "ocsp_responder_indeterminate";
331
+ case "responder_revocation_unknown":
332
+ case "unsupported":
333
+ case "limit_exceeded": return "ocsp_responder_indeterminate";
221
334
  case "response_status_invalid":
222
335
  case "issuer_mismatch":
223
336
  case "nonce_mismatch":
@@ -226,39 +339,48 @@ function ocspIndeterminateReasonFromFailure(e) {
226
339
  }
227
340
  }
228
341
  /** Validation failures worth retrying with an explicit responder certificate. */
229
- const f = /* @__PURE__ */ new Set([
342
+ const x = /* @__PURE__ */ new Set([
230
343
  "signature_invalid",
231
344
  "responder_id_mismatch",
232
345
  "responder_chain_invalid",
233
- "ocsp_signing_missing"
346
+ "ocsp_signing_missing",
347
+ "unsupported",
348
+ "limit_exceeded"
234
349
  ]);
235
350
  /**
236
351
  * Validates an OCSP response, retrying with caller-provided extra certificates
237
352
  * as explicit responder certificates when embedded discovery fails.
238
353
  */
239
354
  async function validateOcspResponseWithResponderFallback(e, t, n, r) {
240
- let i = {
355
+ let i = n.trustedOcspResponders?.filter((e) => {
356
+ let n = parseCertificateSafe(e.issuerCertificate);
357
+ return n !== void 0 && sameCertificate(n, t);
358
+ }).map((e) => e.responderCertificate), a = {
241
359
  issuerCertificate: t,
242
360
  at: r,
243
- ...n.trustedOcspResponders === void 0 ? {} : { trustedOcspResponders: n.trustedOcspResponders },
361
+ ...i === void 0 ? {} : { trustedOcspResponders: i },
244
362
  ...n.policy?.ocspResponderRevocation === void 0 ? {} : { responderRevocationPolicy: n.policy.ocspResponderRevocation },
245
- ...n.crls === void 0 ? {} : { responderRevocationCrls: n.crls }
246
- }, a = await l({
363
+ ...n.crls === void 0 ? {} : { responderRevocationCrls: n.crls },
364
+ ...n.policy?.crlMaxAgeMs === void 0 ? {} : { responderRevocationCrlMaxAgeMs: n.policy.crlMaxAgeMs },
365
+ ...n.policy?.clockSkewMs === void 0 ? {} : { clockSkewMs: n.policy.clockSkewMs },
366
+ ...n.policy?.ocspProfile === void 0 ? {} : { profile: n.policy.ocspProfile },
367
+ ...n.policy?.unrecognizedReasonCode === void 0 ? {} : { responderRevocationUnrecognizedReasonCode: n.policy.unrecognizedReasonCode }
368
+ }, o = await v({
247
369
  response: e,
248
- ...i
370
+ ...a
249
371
  });
250
- if (a.ok || !f.has(a.code)) return a;
372
+ if (o.ok || !x.has(o.code)) return o;
251
373
  for (let t of n.extraCertificates ?? []) {
252
374
  let n = parseCertificateSafe(t);
253
375
  if (n === void 0) continue;
254
- let r = await l({
376
+ let r = await v({
255
377
  response: e,
256
- ...i,
378
+ ...a,
257
379
  responderCertificate: n
258
380
  });
259
381
  if (r.ok) return r;
260
382
  }
261
- return a;
383
+ return o;
262
384
  }
263
385
  /**
264
386
  * Evaluates OCSP evidence for a single certificate (RFC 6960).
@@ -270,64 +392,42 @@ async function validateOcspResponseWithResponderFallback(e, t, n, r) {
270
392
  * sufficient to attribute the entry to `cert`.
271
393
  */
272
394
  async function evaluateOcspEvidence(e, t, n) {
273
- let { ocspResponses: r = [], at: i = /* @__PURE__ */ new Date() } = n, o = [], s = /* @__PURE__ */ new Set();
274
- for (let c of r) {
275
- let r;
276
- try {
277
- r = parseOcspResponseFromSource(c);
278
- } catch (e) {
279
- o.push({
280
- kind: "parse_error",
281
- message: e instanceof Error ? e.message : "OCSP response parse failed"
282
- });
395
+ let { ocspResponses: r = [], at: i = /* @__PURE__ */ new Date() } = n, a = [], o = {
396
+ reasons: /* @__PURE__ */ new Set(),
397
+ sawUnrecognizedReason: !1
398
+ };
399
+ for (let s of r) {
400
+ let r = findApplicableOcspResponse(s, e);
401
+ if (r.kind === "parse_error") {
402
+ a.push(r.error);
283
403
  continue;
284
404
  }
285
- let l = (r.responses ?? []).find((t) => normalizeHex(t.certId.serialNumberHex) === normalizeHex(e.serialNumberHex));
286
- if (l === void 0) continue;
287
- let u = await validateOcspResponseWithResponderFallback(r, t, n, i);
288
- if (!u.ok) {
289
- s.add(ocspIndeterminateReasonFromFailure(u.code));
405
+ if (r.kind === "not_applicable") continue;
406
+ let c = await validateOcspResponseWithResponderFallback(r.parsed, t, n, i);
407
+ if (!c.ok) {
408
+ o.reasons.add(ocspIndeterminateReasonFromFailure(c.code));
290
409
  continue;
291
410
  }
292
- if (l.certStatus === "revoked") {
293
- let t = a(l.revocationReasonCode);
294
- return {
295
- status: {
296
- certificate: e,
297
- status: "revoked",
298
- source: {
299
- kind: "ocsp",
300
- thisUpdate: l.thisUpdate
301
- },
302
- revocationInfo: {
303
- revocationDate: l.revokedAt ?? l.thisUpdate,
304
- ...t === void 0 ? {} : { reason: t }
305
- }
306
- },
307
- executionErrors: o
308
- };
309
- }
310
- if (l.certStatus === "good") return {
311
- status: {
312
- certificate: e,
313
- status: "good",
314
- source: {
315
- kind: "ocsp",
316
- thisUpdate: l.thisUpdate
317
- }
318
- },
319
- executionErrors: o
411
+ let l = classifyValidatedOcspEntry(e, r.entry, n.policy?.unrecognizedReasonCode ?? "revoked");
412
+ if (l.kind === "revoked") return {
413
+ status: l.status,
414
+ executionErrors: a
320
415
  };
321
- s.add("ocsp_status_unknown");
416
+ recordOcspEvidence(o, l);
322
417
  }
323
- return s.size === 0 && s.add("no_applicable_ocsp"), {
324
- status: {
325
- certificate: e,
326
- status: "indeterminate",
327
- indeterminateReasons: [...s]
328
- },
329
- executionErrors: o
330
- };
418
+ return settleOcspEvidence(e, o, a);
419
+ }
420
+ function recordOcspEvidence(e, t) {
421
+ t.kind === "good" ? e.freshestGoodThisUpdate = laterEvidenceDate(e.freshestGoodThisUpdate, t.thisUpdate) : t.kind === "hold" ? (e.freshestHold === void 0 || t.evidence.thisUpdate.getTime() > e.freshestHold.thisUpdate.getTime()) && (e.freshestHold = t.evidence) : t.kind === "unrecognized_reason" ? e.sawUnrecognizedReason = !0 : e.reasons.add("ocsp_status_unknown");
422
+ }
423
+ /** The OCSP verdict once no response revoked the certificate outright. */
424
+ function settleOcspEvidence(e, t, n) {
425
+ if (t.sawUnrecognizedReason) return t.reasons.add("ocsp_reason_code_unrecognized"), finalizeOcspEvidence(e, void 0, t.reasons, n);
426
+ let { freshestGoodThisUpdate: r, freshestHold: i } = t;
427
+ return i !== void 0 && (r === void 0 || r.getTime() <= i.thisUpdate.getTime()) ? {
428
+ status: i.status,
429
+ executionErrors: n
430
+ } : finalizeOcspEvidence(e, r, t.reasons, n);
331
431
  }
332
432
  /**
333
433
  * Runs each candidate signer through the full pipeline for one base CRL:
@@ -338,101 +438,231 @@ async function evaluateOcspEvidence(e, t, n) {
338
438
  * evidence into `state`.
339
439
  */
340
440
  async function resolveBaseCrlAgainstSigners(e) {
341
- let { cert: t, baseCrl: n, applicableDelta: r, crlThisUpdate: i, issuer: a, extraCertificates: o, chain: s, at: c, signerCtx: l, state: u } = e;
342
- for (let e of collectCrlSignerCandidates(n, a, o, s)) {
343
- let a = await checkCrlWithIssuer(t, n, r, e, c);
344
- if (!a.ok) continue;
345
- if (!await crlSignerChainsToAnchor(e, s, o, c)) {
346
- u.sawCrlSignerNotAuthorized = !0;
441
+ let { cert: t, baseCrl: n, deltaCandidates: r, issuer: i, extraCertificates: a, chain: o, at: s, crlMaxAgeMs: c, clockSkewMs: l, unrecognizedReasonCode: u, signerCtx: d, deltaBudget: f, state: p } = e, m = { remaining: S };
442
+ for (let e of collectCrlSignerCandidates(n, i, a, o)) {
443
+ let i = await checkCrlAgainstDeltaCandidates({
444
+ cert: t,
445
+ baseCrl: n,
446
+ deltaCandidates: r,
447
+ candidate: e,
448
+ at: s,
449
+ crlMaxAgeMs: c,
450
+ clockSkewMs: l,
451
+ unrecognizedReasonCode: u,
452
+ budgets: [m, f],
453
+ state: p
454
+ });
455
+ if (i.kind === "unusable_base") continue;
456
+ if (!await crlSignerChainsToAnchor(e, o, a, s)) {
457
+ p.sawCrlSignerNotAuthorized = !0;
347
458
  continue;
348
459
  }
349
- let d = await validateCrlSigner(e, l);
350
- if (d === "resolved-revoked") {
351
- u.sawCrlSignerRevoked = !0;
460
+ let h = await validateCrlSigner(e, d);
461
+ if (h === "resolved-revoked") {
462
+ p.sawCrlSignerRevoked = !0;
352
463
  continue;
353
464
  }
354
- if (d === "resolved-indeterminate") {
355
- u.sawCrlSignerIndeterminate = !0;
465
+ if (h === "resolved-indeterminate") {
466
+ p.sawCrlSignerIndeterminate = !0;
356
467
  continue;
357
468
  }
358
- if (a.value.status === "revoked") return buildCrlRevokedStatus(t, e, i, a.value.revocationDate, a.value.reasonCode);
359
- recordGoodCrlEvidence(u, e, i, a.value.coveredReasons);
469
+ if (i.kind === "reason_code_unrecognized") {
470
+ p.sawUnrecognizedReasonCode = !0;
471
+ return;
472
+ }
473
+ if (i.kind === "delta_unusable") {
474
+ p.sawDeltaCrlUnusable = !0;
475
+ return;
476
+ }
477
+ if (i.kind === "retry_limit") {
478
+ p.sawDeltaCrlRetryLimit = !0;
479
+ return;
480
+ }
481
+ let { checked: g, crlThisUpdate: _ } = i;
482
+ if (g.value.status === "revoked") return buildCrlRevokedStatus(t, e, _, g.value.revocationDate, g.value.reasonCode);
483
+ recordGoodCrlEvidence(p, e, _, g.value.coveredReasons);
360
484
  return;
361
485
  }
362
486
  }
363
- async function evaluateCrlEvidence(e, t, r, i) {
364
- let { crls: a = [], extraCertificates: o = [], chain: s = [], at: c = /* @__PURE__ */ new Date() } = r, l = {
487
+ async function evaluateCrlEvidence(e, t, n, r, i) {
488
+ let { crls: a = [], extraCertificates: o = [], chain: s = [], at: c = /* @__PURE__ */ new Date() } = n, d = {
365
489
  executionErrors: [],
366
490
  coveredReasons: /* @__PURE__ */ new Set(),
367
491
  sawCrlSignerRevoked: !1,
368
492
  sawCrlSignerIndeterminate: !1,
369
493
  sawCrlSignerNotAuthorized: !1,
494
+ sawStaleCrl: !1,
495
+ sawDeltaCrlUnusable: !1,
496
+ sawDeltaCrlRetryLimit: !1,
497
+ sawUnrecognizedReasonCode: !1,
370
498
  sawGood: !1
371
- }, u = parseCrlEvidenceSources(a, l.executionErrors), d = u.filter((e) => e.baseCrlNumber === void 0), f = u.filter((e) => e.baseCrlNumber !== void 0);
372
- for (let n of d) {
373
- let r = findApplicableDeltaCrl(n, f), a = await resolveBaseCrlAgainstSigners({
499
+ }, f = parseCrlEvidenceSources(a, d.executionErrors), p = distinctSignedCrls(f.filter((t) => t.baseCrlNumber === void 0 && u(e, t))), m = distinctSignedCrls(f.filter((e) => e.baseCrlNumber !== void 0)), h = n.policy?.crlMaxAgeMs, g = n.policy?.clockSkewMs;
500
+ for (let a of p) {
501
+ let l = await resolveBaseCrlAgainstSigners({
374
502
  cert: e,
375
- baseCrl: n,
376
- applicableDelta: r,
377
- crlThisUpdate: r !== void 0 && r.thisUpdate.getTime() > n.thisUpdate.getTime() ? r.thisUpdate : n.thisUpdate,
503
+ baseCrl: a,
504
+ deltaCandidates: rankApplicableDeltaCrls(a, m, c, g ?? 0, h),
378
505
  issuer: t,
379
506
  extraCertificates: o,
380
507
  chain: s,
381
508
  at: c,
382
- signerCtx: i,
383
- state: l
509
+ crlMaxAgeMs: h,
510
+ clockSkewMs: g,
511
+ unrecognizedReasonCode: n.policy?.unrecognizedReasonCode ?? "revoked",
512
+ signerCtx: r,
513
+ deltaBudget: i,
514
+ state: d
384
515
  });
385
- if (a !== void 0) return {
386
- status: a,
387
- executionErrors: l.executionErrors
516
+ if (l !== void 0) return {
517
+ status: l,
518
+ executionErrors: d.executionErrors
388
519
  };
389
520
  }
390
- return l.sawGood && l.freshestGood !== void 0 ? n(l.coveredReasons) ? {
521
+ let _ = blockingCrlIndeterminateReasons(d);
522
+ return _.length > 0 ? {
523
+ status: {
524
+ certificate: e,
525
+ status: "indeterminate",
526
+ indeterminateReasons: _
527
+ },
528
+ executionErrors: d.executionErrors
529
+ } : d.sawGood && d.freshestGood !== void 0 ? l(d.coveredReasons) ? {
391
530
  status: {
392
531
  certificate: e,
393
532
  status: "good",
394
533
  source: {
395
534
  kind: "crl",
396
- signerCertificate: l.freshestGood.signer,
397
- thisUpdate: l.freshestGood.thisUpdate
535
+ signerCertificate: d.freshestGood.signer,
536
+ thisUpdate: d.freshestGood.thisUpdate
398
537
  }
399
538
  },
400
- executionErrors: l.executionErrors
539
+ executionErrors: d.executionErrors
401
540
  } : {
402
541
  status: {
403
542
  certificate: e,
404
543
  status: "indeterminate",
405
544
  indeterminateReasons: ["reason_coverage_incomplete"]
406
545
  },
407
- executionErrors: l.executionErrors
546
+ executionErrors: d.executionErrors
408
547
  } : {
409
548
  status: {
410
549
  certificate: e,
411
550
  status: "indeterminate",
412
- indeterminateReasons: [crlUnavailableReason(l)]
551
+ indeterminateReasons: [crlUnavailableReason(d)]
413
552
  },
414
- executionErrors: l.executionErrors
553
+ executionErrors: d.executionErrors
415
554
  };
416
555
  }
556
+ /** CRL conditions that keep the status indeterminate despite `good` evidence. */
557
+ function blockingCrlIndeterminateReasons(e) {
558
+ return [
559
+ ...e.sawDeltaCrlUnusable ? ["delta_crl_unusable"] : [],
560
+ ...e.sawDeltaCrlRetryLimit ? ["delta_crl_retry_limit_exceeded"] : [],
561
+ ...e.sawUnrecognizedReasonCode ? ["crl_reason_code_unrecognized"] : []
562
+ ];
563
+ }
417
564
  /** Most specific indeterminate reason when no CRL yielded a usable verdict. */
418
565
  function crlUnavailableReason(e) {
419
- return e.sawCrlSignerRevoked ? "crl_signer_revoked" : e.sawCrlSignerNotAuthorized ? "crl_signer_not_authorized" : e.sawCrlSignerIndeterminate ? "crl_signer_indeterminate" : "no_applicable_crl";
566
+ return e.sawCrlSignerRevoked ? "crl_signer_revoked" : e.sawCrlSignerNotAuthorized ? "crl_signer_not_authorized" : e.sawCrlSignerIndeterminate ? "crl_signer_indeterminate" : e.sawStaleCrl ? "crl_expired" : "no_applicable_crl";
420
567
  }
421
568
  /** Parses complete and delta CRL evidence while retaining source provenance. */
422
569
  function parseCrlEvidenceSources(e, t) {
423
570
  let n = [];
424
571
  for (let r of e) try {
425
- n.push(parseCrlFromSource(r));
572
+ n.push(f(r));
426
573
  } catch (e) {
427
- t.push({
428
- kind: "parse_error",
429
- message: e instanceof Error ? e.message : "CRL parse failed"
430
- });
574
+ t.push(evidenceParseError(e, "CRL parse failed"));
431
575
  }
432
576
  return n;
433
577
  }
434
- function findApplicableDeltaCrl(e, t) {
435
- return t.find((t) => t.issuer.derHex === e.issuer.derHex && t.baseCrlNumber !== void 0 && e.crlNumber !== void 0 && BigInt(t.baseCrlNumber) <= BigInt(e.crlNumber));
578
+ /** `crls` without repeats of the same signed content and signature. */
579
+ function distinctSignedCrls(e) {
580
+ let t = /* @__PURE__ */ new Set();
581
+ return e.filter((e) => {
582
+ let r = [
583
+ e.signatureAlgorithmOid,
584
+ n(e.signatureAlgorithmParametersDer ?? /* @__PURE__ */ new Uint8Array()),
585
+ n(e.signatureValue),
586
+ n(e.tbsCertListDer)
587
+ ].join(":");
588
+ return !t.has(r) && (t.add(r), !0);
589
+ });
590
+ }
591
+ /** Every delta CRL that can update `baseCrl`, newest first, in the order to try authenticating them. */
592
+ function rankApplicableDeltaCrls(e, t, n, r, i) {
593
+ let a = e.crlNumber;
594
+ return a === void 0 ? [] : t.filter((t) => t.issuer.derHex === e.issuer.derHex && t.baseCrlNumber !== void 0 && t.baseCrlNumber <= a && t.crlNumber !== void 0 && t.crlNumber > a && t.thisUpdate.getTime() >= e.thisUpdate.getTime() && d(t, n, r, i)).sort((e, t) => isNewerDeltaCrl(e, t) ? -1 : +!!isNewerDeltaCrl(t, e));
595
+ }
596
+ const S = 4;
597
+ /**
598
+ * Authenticates `baseCrl` with `candidate` once, then checks it with each
599
+ * ranked delta CRL while the budgets last, and alone once every delta CRL is
600
+ * rejected. A delta CRL that passes authentication, freshness, compatibility
601
+ * and applicability ends the search.
602
+ */
603
+ async function checkCrlAgainstDeltaCandidates(e) {
604
+ let { cert: t, baseCrl: n, deltaCandidates: r, candidate: i, at: a, crlMaxAgeMs: s, clockSkewMs: l, unrecognizedReasonCode: u, budgets: d, state: f } = e, p = await o(n, i);
605
+ if (!p.ok) return { kind: "unusable_base" };
606
+ let m = {
607
+ certificate: t,
608
+ issuerCertificate: i,
609
+ crl: p.value,
610
+ at: a,
611
+ ...s === void 0 ? {} : { maxAgeMs: s },
612
+ ...l === void 0 ? {} : { clockSkewMs: l },
613
+ unrecognizedReasonCode: u
614
+ };
615
+ for (let e of r) {
616
+ let r = takeDeltaCrlAttempt(d) ? settleAuthenticatedCrlOutcome(await c(t, p.value, {
617
+ ...m,
618
+ deltaCrl: e
619
+ }), laterEvidenceDate(n.thisUpdate, e.thisUpdate), f) : { kind: "retry_limit" };
620
+ if (r !== void 0) {
621
+ if (r.kind === "delta_unusable") return irremovableRevocation(t, r.complete, a, n.thisUpdate) ?? r;
622
+ if (r.kind === "retry_limit") {
623
+ let e = await c(t, p.value, m);
624
+ return (e.kind === "checked" ? irremovableRevocation(t, e.result, a, n.thisUpdate) : void 0) ?? r;
625
+ }
626
+ return r;
627
+ }
628
+ }
629
+ return settleAuthenticatedCrlOutcome(await c(t, p.value, m), n.thisUpdate, f) ?? { kind: "unusable_base" };
630
+ }
631
+ /**
632
+ * The base CRL's revocation of `cert` in `complete` when no delta CRL could
633
+ * remove it at `at`. RFC 5280 §5.3.1 lets removeFromCRL clear only a
634
+ * certificateHold entry or a certificate that has expired.
635
+ */
636
+ function irremovableRevocation(e, t, n, r) {
637
+ if (!(e.notAfter.getTime() < n.getTime() || !t.ok || t.value.status !== "revoked" || t.value.reasonCode === "certificateHold")) return {
638
+ kind: "checked",
639
+ checked: t,
640
+ crlThisUpdate: r
641
+ };
642
+ }
643
+ /** Spends one delta CRL check from every budget, or none when any is empty. */
644
+ function takeDeltaCrlAttempt(e) {
645
+ if (e.some((e) => e.remaining <= 0)) return !1;
646
+ for (let t of e) --t.remaining;
647
+ return !0;
648
+ }
649
+ /** Maps one staged CRL check to the search outcome, or `undefined` to try the next delta CRL. */
650
+ function settleAuthenticatedCrlOutcome(e, t, n) {
651
+ if (e.kind === "delta_unresolved") return {
652
+ kind: "delta_unusable",
653
+ complete: e.complete
654
+ };
655
+ let r = e.kind === "checked" ? e.result : e.failure;
656
+ if (!r.ok && r.code === "stale_crl" && (n.sawStaleCrl = !0), !r.ok && r.code === "reason_code_unrecognized") return { kind: "reason_code_unrecognized" };
657
+ if (e.kind !== "delta_rejected") return r.ok ? {
658
+ kind: "checked",
659
+ checked: r,
660
+ crlThisUpdate: t
661
+ } : { kind: "unusable_base" };
662
+ }
663
+ function isNewerDeltaCrl(e, t) {
664
+ let n = e.thisUpdate.getTime(), r = t.thisUpdate.getTime();
665
+ return n === r ? (e.crlNumber ?? 0n) > (t.crlNumber ?? 0n) : n > r;
436
666
  }
437
667
  /** The direct issuer first, then deduplicated indirect CRL-issuer candidates. */
438
668
  function collectCrlSignerCandidates(e, t, n, r) {
@@ -440,15 +670,6 @@ function collectCrlSignerCandidates(e, t, n, r) {
440
670
  for (let t of findIndirectCrlIssuers(e, n, r)) i.some((e) => sameCertificate(e, t)) || i.push(t);
441
671
  return i;
442
672
  }
443
- function checkCrlWithIssuer(e, n, r, i, a) {
444
- return t({
445
- certificate: e,
446
- issuerCertificate: i,
447
- crl: n,
448
- ...r === void 0 ? {} : { deltaCrl: r },
449
- at: a
450
- });
451
- }
452
673
  function recordGoodCrlEvidence(e, t, n, r) {
453
674
  e.sawGood = !0, (e.freshestGood === void 0 || n.getTime() > e.freshestGood.thisUpdate.getTime()) && (e.freshestGood = {
454
675
  signer: t,
@@ -456,6 +677,13 @@ function recordGoodCrlEvidence(e, t, n, r) {
456
677
  });
457
678
  for (let t of r) e.coveredReasons.add(t);
458
679
  }
680
+ /** Indeterminate reasons that keep other evidence from settling the status as `good`. */
681
+ const C = /* @__PURE__ */ new Set([
682
+ "delta_crl_unusable",
683
+ "delta_crl_retry_limit_exceeded",
684
+ "crl_reason_code_unrecognized",
685
+ "ocsp_reason_code_unrecognized"
686
+ ]);
459
687
  /**
460
688
  * Evaluates revocation status for a single certificate by combining OCSP and
461
689
  * CRL evidence.
@@ -464,36 +692,49 @@ function recordGoodCrlEvidence(e, t, n, r) {
464
692
  * either source wins regardless of {@linkcode RevocationPolicy.prefer}
465
693
  * (fail-closed). Otherwise the preferred source's `good` verdict is reported —
466
694
  * for `'best-available'` the source with the later evidence `thisUpdate` wins,
467
- * ties favoring OCSP. If neither source is definitive, indeterminate reasons
468
- * from both are merged.
695
+ * ties favoring OCSP. An indeterminate reason in
696
+ * {@linkcode GOOD_BLOCKING_REASONS} from either source outranks a `good`
697
+ * verdict. If neither source is definitive, indeterminate reasons from both
698
+ * are merged.
469
699
  */
470
- async function evaluateCertificateRevocation(e, t, n, r) {
471
- let i = n.policy?.prefer ?? "best-available", a = await evaluateOcspEvidence(e, t, n), o = await evaluateCrlEvidence(e, t, n, r), s = [...a.executionErrors, ...o.executionErrors], c = i === "crl" ? [o, a] : i === "ocsp" ? [a, o] : [a, o].sort((e, t) => (t.status.source?.thisUpdate?.getTime() ?? 0) - (e.status.source?.thisUpdate?.getTime() ?? 0)), l = c.find((e) => e.status.status === "revoked");
472
- if (l !== void 0) return {
473
- status: l.status,
474
- executionErrors: s
475
- };
476
- let u = c.find((e) => e.status.status === "good");
700
+ async function evaluateCertificateRevocation(e, t, n, r, i) {
701
+ let a = n.policy?.prefer ?? "best-available", o = await evaluateOcspEvidence(e, t, n), s = await evaluateCrlEvidence(e, t, n, r, i), c = [...o.executionErrors, ...s.executionErrors], l = a === "crl" ? [s, o] : a === "ocsp" ? [o, s] : [o, s].sort((e, t) => (t.status.source?.thisUpdate?.getTime() ?? 0) - (e.status.source?.thisUpdate?.getTime() ?? 0)), u = l.find((e) => e.status.status === "revoked");
477
702
  if (u !== void 0) return {
478
703
  status: u.status,
479
- executionErrors: s
704
+ executionErrors: c
705
+ };
706
+ let d = l.find((e) => e.status.status === "good"), f = [s, o].some((e) => e.status.indeterminateReasons?.some((e) => C.has(e)));
707
+ if (d !== void 0 && !f) return {
708
+ status: d.status,
709
+ executionErrors: c
480
710
  };
481
- let d = /* @__PURE__ */ new Set();
482
- for (let e of c) for (let t of e.status.indeterminateReasons ?? []) d.add(t);
711
+ let p = /* @__PURE__ */ new Set();
712
+ for (let e of l) for (let t of e.status.indeterminateReasons ?? []) p.add(t);
483
713
  return {
484
714
  status: {
485
715
  certificate: e,
486
716
  status: "indeterminate",
487
- indeterminateReasons: [...d]
717
+ indeterminateReasons: [...p]
488
718
  },
489
- executionErrors: s
719
+ executionErrors: c
490
720
  };
491
721
  }
492
722
  /**
723
+ * RFC 9608 §4: path validation skips RFC 5280 §6.1.3 step (a)(3) for a
724
+ * certificate carrying noRevAvail or id-pkix-ocsp-nocheck, read from its
725
+ * signed DER.
726
+ */
727
+ function revocationSkipReason(e) {
728
+ let t = r(e.der);
729
+ if (t.ok) return t.value.noRevAvail === !0 ? "no_rev_avail" : h(t.value) ? "ocsp_nocheck" : void 0;
730
+ }
731
+ /**
493
732
  * Checks revocation status for all certificates in a validated chain.
494
733
  *
495
734
  * Evaluates CRL and OCSP evidence against each certificate (except the trust
496
- * anchor), applies the revocation policy, and returns a unified decision.
735
+ * anchor), applies the revocation policy, and returns a unified decision. A
736
+ * certificate carrying noRevAvail or id-pkix-ocsp-nocheck is reported as
737
+ * `skipped` without consulting evidence (RFC 9608 §4).
497
738
  *
498
739
  * @example
499
740
  * ```ts
@@ -509,7 +750,9 @@ async function evaluateCertificateRevocation(e, t, n, r) {
509
750
  * ```
510
751
  */
511
752
  async function checkChainRevocation(e) {
512
- let { chain: t, policy: n, crls: r = [], extraCertificates: i = [], at: a = /* @__PURE__ */ new Date() } = e, o = n?.mode ?? "hard-fail";
753
+ let { chain: t, policy: n, crls: r = [], extraCertificates: i = [], at: o = /* @__PURE__ */ new Date() } = e;
754
+ a(n?.crlMaxAgeMs);
755
+ let s = n?.mode ?? "hard-fail";
513
756
  if (t.length === 0) return {
514
757
  ok: !0,
515
758
  value: {
@@ -521,34 +764,45 @@ async function checkChainRevocation(e) {
521
764
  certificates: []
522
765
  }
523
766
  };
524
- let s = {
767
+ let c = {
525
768
  cache: /* @__PURE__ */ new Map(),
526
769
  chain: t,
527
770
  crls: r,
528
771
  extraCertificates: i,
529
- at: a
530
- }, c = t.slice(0, -1), l = [], u = [], d = [], f = [];
531
- for (let n = 0; n < c.length; n++) {
532
- let r = c[n], i = t[n + 1];
772
+ at: o,
773
+ crlMaxAgeMs: n?.crlMaxAgeMs,
774
+ clockSkewMs: n?.clockSkewMs,
775
+ unrecognizedReasonCode: n?.unrecognizedReasonCode ?? "revoked"
776
+ }, l = { remaining: 32 }, u = t.slice(0, -1), d = [], f = [], p = [], m = [];
777
+ for (let n = 0; n < u.length; n++) {
778
+ let r = u[n], i = t[n + 1];
533
779
  if (r === void 0 || i === void 0) continue;
534
- let { status: a, executionErrors: o } = await evaluateCertificateRevocation(r, i, e, s);
535
- l.push(a), f.push(...o), a.status === "revoked" ? u.push(r) : a.status === "indeterminate" && d.push(r);
780
+ let a = revocationSkipReason(r);
781
+ if (a !== void 0) {
782
+ d.push({
783
+ certificate: r,
784
+ status: "skipped",
785
+ skipReason: a
786
+ });
787
+ continue;
788
+ }
789
+ let { status: o, executionErrors: s } = await evaluateCertificateRevocation(r, i, e, c, l);
790
+ d.push(o), m.push(...s), o.status === "revoked" ? f.push(r) : o.status === "indeterminate" && p.push(r);
536
791
  }
537
- let p = u.length > 0, m = d.length > 0;
792
+ let h = f.length > 0, g = p.length > 0;
538
793
  return {
539
794
  ok: !0,
540
795
  value: {
541
- decision: p || m && o === "hard-fail" ? "deny" : "allow",
796
+ decision: h || g && s === "hard-fail" ? "deny" : "allow",
542
797
  summary: {
543
- revokedCertificates: u,
544
- indeterminateCertificates: d
798
+ revokedCertificates: f,
799
+ indeterminateCertificates: p
545
800
  },
546
- certificates: l,
547
- ...f.length > 0 ? { executionErrors: f } : {}
801
+ certificates: d,
802
+ ...m.length > 0 ? { executionErrors: m } : {}
548
803
  }
549
804
  };
550
805
  }
551
- //#endregion
552
- export { u as REVOCATION_INDETERMINATE_REASONS, checkChainRevocation };
806
+ export { y as REVOCATION_INDETERMINATE_REASONS, checkChainRevocation };
553
807
 
554
808
  //# sourceMappingURL=chain.js.map