micro509 0.13.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 (165) hide show
  1. package/CHANGELOG.md +2064 -0
  2. package/README.md +111 -183
  3. package/dist/crypto/crypto.d.ts +104 -0
  4. package/dist/crypto/crypto.js +105 -0
  5. package/dist/crypto/crypto.js.map +1 -0
  6. package/dist/crypto.d.ts +4 -0
  7. package/dist/crypto.js +1 -0
  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 +18 -14
  12. package/dist/index.js +19 -17
  13. package/dist/internal/asn1/asn1.d.ts +3 -6
  14. package/dist/internal/asn1/asn1.js +355 -44
  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 +42 -43
  21. package/dist/internal/asn1/der.js +148 -56
  22. package/dist/internal/asn1/der.js.map +1 -1
  23. package/dist/internal/asn1/oids.js +90 -54
  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 +5 -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 +51 -0
  34. package/dist/internal/crypto/pbes2.js +86 -34
  35. package/dist/internal/crypto/pbes2.js.map +1 -1
  36. package/dist/internal/crypto/rsa-pss.js +48 -44
  37. package/dist/internal/crypto/rsa-pss.js.map +1 -1
  38. package/dist/internal/crypto/sig-verify.d.ts +28 -0
  39. package/dist/internal/crypto/sig-verify.js +111 -62
  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 +8 -3
  47. package/dist/internal/shared/base64.js.map +1 -1
  48. package/dist/internal/shared/dn.d.ts +13 -0
  49. package/dist/internal/shared/dn.js +101 -48
  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 +66 -0
  56. package/dist/internal/shared/ip.js +19 -3
  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 +4 -0
  73. package/dist/internal/verify/verify-path.js +264 -128
  74. package/dist/internal/verify/verify-path.js.map +1 -1
  75. package/dist/internal/x509/directory-name.js +23 -0
  76. package/dist/internal/x509/directory-name.js.map +1 -0
  77. package/dist/internal/x509/extension-bits.js +15 -13
  78. package/dist/internal/x509/extension-bits.js.map +1 -1
  79. package/dist/internal/x509/extension-errors.d.ts +3 -0
  80. package/dist/internal/x509/extension-errors.js +19 -0
  81. package/dist/internal/x509/extension-errors.js.map +1 -0
  82. package/dist/internal/x509/extension-registry.js +157 -81
  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 +27 -0
  87. package/dist/internal/x509/general-name-tags.js.map +1 -0
  88. package/dist/internal/x509/general-name.js +183 -0
  89. package/dist/internal/x509/general-name.js.map +1 -0
  90. package/dist/internal/x509/name-fields.js +21 -12
  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 +124 -95
  95. package/dist/keys/keys.js +362 -214
  96. package/dist/keys/keys.js.map +1 -1
  97. package/dist/keys.d.ts +3 -2
  98. package/dist/keys.js +3 -2
  99. package/dist/pem/pem.d.ts +17 -19
  100. package/dist/pem/pem.js +122 -41
  101. package/dist/pem/pem.js.map +1 -1
  102. package/dist/pem.js +1 -2
  103. package/dist/pkcs/pfx.d.ts +57 -32
  104. package/dist/pkcs/pfx.js +209 -173
  105. package/dist/pkcs/pfx.js.map +1 -1
  106. package/dist/pkcs/pkcs12-mac.d.ts +104 -27
  107. package/dist/pkcs/pkcs12-mac.js +266 -79
  108. package/dist/pkcs/pkcs12-mac.js.map +1 -1
  109. package/dist/pkcs/pkcs7.d.ts +123 -53
  110. package/dist/pkcs/pkcs7.js +314 -238
  111. package/dist/pkcs/pkcs7.js.map +1 -1
  112. package/dist/pkcs.d.ts +5 -4
  113. package/dist/result/result.d.ts +43 -28
  114. package/dist/result/result.js +27 -14
  115. package/dist/result/result.js.map +1 -1
  116. package/dist/result.d.ts +2 -2
  117. package/dist/result.js +1 -2
  118. package/dist/revocation/chain.d.ts +101 -23
  119. package/dist/revocation/chain.js +456 -206
  120. package/dist/revocation/chain.js.map +1 -1
  121. package/dist/revocation/crl.d.ts +140 -65
  122. package/dist/revocation/crl.js +691 -391
  123. package/dist/revocation/crl.js.map +1 -1
  124. package/dist/revocation/ocsp.d.ts +145 -69
  125. package/dist/revocation/ocsp.js +347 -297
  126. package/dist/revocation/ocsp.js.map +1 -1
  127. package/dist/revocation/revocation.d.ts +48 -36
  128. package/dist/revocation/revocation.js +112 -63
  129. package/dist/revocation/revocation.js.map +1 -1
  130. package/dist/revocation.d.ts +5 -5
  131. package/dist/revocation.js +5 -5
  132. package/dist/verify/identity.d.ts +18 -20
  133. package/dist/verify/identity.js +120 -90
  134. package/dist/verify/identity.js.map +1 -1
  135. package/dist/verify/name-constraints.d.ts +1 -4
  136. package/dist/verify/policy.d.ts +15 -8
  137. package/dist/verify/verify.d.ts +86 -46
  138. package/dist/verify/verify.js +309 -143
  139. package/dist/verify/verify.js.map +1 -1
  140. package/dist/verify.d.ts +3 -2
  141. package/dist/verify.js +4 -3
  142. package/dist/x509/certificate.d.ts +50 -28
  143. package/dist/x509/certificate.js +69 -36
  144. package/dist/x509/certificate.js.map +1 -1
  145. package/dist/x509/csr.d.ts +9 -8
  146. package/dist/x509/csr.js +10 -11
  147. package/dist/x509/csr.js.map +1 -1
  148. package/dist/x509/extensions.d.ts +207 -82
  149. package/dist/x509/extensions.js +561 -128
  150. package/dist/x509/extensions.js.map +1 -1
  151. package/dist/x509/fingerprint.d.ts +4 -7
  152. package/dist/x509/fingerprint.js +1 -2
  153. package/dist/x509/fingerprint.js.map +1 -1
  154. package/dist/x509/name-text.d.ts +7 -9
  155. package/dist/x509/name-text.js +20 -4
  156. package/dist/x509/name-text.js.map +1 -1
  157. package/dist/x509/name.d.ts +15 -14
  158. package/dist/x509/name.js +23 -19
  159. package/dist/x509/name.js.map +1 -1
  160. package/dist/x509/parse.d.ts +165 -64
  161. package/dist/x509/parse.js +444 -459
  162. package/dist/x509/parse.js.map +1 -1
  163. package/dist/x509.d.ts +8 -5
  164. package/dist/x509.js +10 -8
  165. package/package.json +90 -65
@@ -1,8 +1,20 @@
1
- import { parseCertificateFromSource as e } from "../x509/parse.js";
2
- import { checkCertificateRevocationAgainstCrl as t, parseCertificateRevocationListDerOrThrow as n, parseCertificateRevocationListPemOrThrow as r, revocationReasonFromCode as i } from "./crl.js";
3
- import { verifyCertificateChain as a } from "../verify/verify.js";
4
- import { parseOcspResponseDerOrThrow as o, parseOcspResponsePemOrThrow as s, validateOcspResponse as c } 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 o, parseOcspResponsePemOrThrow as s, 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 l = [
40
+ const y = [
20
41
  "no_applicable_crl",
21
42
  "no_applicable_ocsp",
22
43
  "distribution_point_mismatch",
@@ -34,20 +55,19 @@ const l = [
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" ? r(e) : n(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
  }
@@ -94,8 +114,8 @@ async function crlSignerChainsToAnchor(e, t, n, r) {
94
114
  if (t.some((t) => sameCertificate(t, e))) return !0;
95
115
  let i = t[t.length - 1];
96
116
  if (i === void 0) return !1;
97
- let o = [], addCandidate = (t) => {
98
- sameCertificate(t, e) || sameCertificate(t, i) || o.some((e) => sameCertificate(e, t)) || o.push(t);
117
+ let a = [], addCandidate = (t) => {
118
+ sameCertificate(t, e) || sameCertificate(t, i) || a.some((e) => sameCertificate(e, t)) || a.push(t);
99
119
  };
100
120
  for (let e = 0; e < t.length - 1; e += 1) {
101
121
  let n = t[e];
@@ -105,9 +125,9 @@ 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 a({
128
+ return (await m({
109
129
  leaf: e.der,
110
- intermediates: o.map((e) => e.der),
130
+ intermediates: a.map((e) => e.der),
111
131
  roots: [i.der],
112
132
  at: r
113
133
  })).ok;
@@ -152,27 +172,45 @@ 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, n, r) {
156
- let i = r.chain.some((e) => sameCertificate(e, n));
157
- for (let i of r.crls) {
158
- let a;
159
- try {
160
- a = parseCrlFromSource(i);
161
- } catch {
162
- continue;
163
- }
164
- let o = await t({
165
- certificate: e,
166
- issuerCertificate: n,
167
- crl: a,
168
- at: r.at
169
- });
170
- if (o.ok) {
171
- if (o.value.status === "revoked") return "resolved-revoked";
172
- if (o.value.status === "good" && await validateCrlSigner(n, r) === "resolved-valid") return "resolved-valid";
173
- }
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);
174
182
  }
175
- return i ? "resolved-valid" : "resolved-indeterminate";
183
+ return a ? "resolved-indeterminate" : l(i) || r ? "resolved-valid" : "resolved-indeterminate";
184
+ }
185
+ const b = {
186
+ kind: "reasons",
187
+ reasons: []
188
+ };
189
+ /**
190
+ * Evaluates one CRL against a signer. A CRL that does not parse, does not
191
+ * apply, or is itself signed by a signer that is not known good yields no
192
+ * evidence rather than a verdict.
193
+ */
194
+ async function checkSignerAgainstCrl(e, t, n, r) {
195
+ let i;
196
+ try {
197
+ i = f(n);
198
+ } catch {
199
+ return b;
200
+ }
201
+ let a = await s({
202
+ certificate: e,
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
209
+ });
210
+ return a.ok ? a.value.status === "revoked" ? { kind: "revoked" } : await validateCrlSigner(t, r) === "resolved-valid" ? {
211
+ kind: "reasons",
212
+ reasons: a.value.coveredReasons
213
+ } : b : a.code === "reason_code_unrecognized" ? { kind: "unrecognized_reason" } : b;
176
214
  }
177
215
  /** Builds the `revoked` CertificateRevocationStatus for a CRL hit. */
178
216
  function buildCrlRevokedStatus(e, t, n, r, i) {
@@ -192,58 +230,157 @@ function buildCrlRevokedStatus(e, t, n, r, i) {
192
230
  }
193
231
  /** Parses an OCSP response from PEM string or DER bytes. */
194
232
  function parseOcspResponseFromSource(e) {
195
- return typeof e == "string" ? s(e) : o(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
+ };
196
320
  }
197
321
  /** Maps a {@linkcode validateOcspResponse} failure code to an indeterminate reason. */
198
322
  function ocspIndeterminateReasonFromFailure(e) {
199
323
  switch (e) {
200
324
  case "stale_response": return "ocsp_response_expired";
325
+ case "next_update_missing": return "ocsp_next_update_missing";
201
326
  case "responder_id_mismatch":
202
327
  case "responder_chain_invalid":
203
328
  case "ocsp_signing_missing": return "ocsp_responder_not_authorized";
204
329
  case "responder_revoked": return "ocsp_responder_revoked";
205
330
  case "signature_invalid":
206
- case "responder_revocation_unknown": return "ocsp_responder_indeterminate";
331
+ case "responder_revocation_unknown":
332
+ case "unsupported":
333
+ case "limit_exceeded": return "ocsp_responder_indeterminate";
207
334
  case "response_status_invalid":
208
335
  case "issuer_mismatch":
209
336
  case "nonce_mismatch":
210
337
  case "request_mismatch": return "no_applicable_ocsp";
338
+ default: throw Error(`Unhandled ValidateOcspResponse failure code: ${String(e)}`);
211
339
  }
212
340
  }
213
341
  /** Validation failures worth retrying with an explicit responder certificate. */
214
- const u = /* @__PURE__ */ new Set([
342
+ const x = /* @__PURE__ */ new Set([
215
343
  "signature_invalid",
216
344
  "responder_id_mismatch",
217
345
  "responder_chain_invalid",
218
- "ocsp_signing_missing"
346
+ "ocsp_signing_missing",
347
+ "unsupported",
348
+ "limit_exceeded"
219
349
  ]);
220
350
  /**
221
351
  * Validates an OCSP response, retrying with caller-provided extra certificates
222
352
  * as explicit responder certificates when embedded discovery fails.
223
353
  */
224
354
  async function validateOcspResponseWithResponderFallback(e, t, n, r) {
225
- 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 = {
226
359
  issuerCertificate: t,
227
360
  at: r,
228
- ...n.trustedOcspResponders === void 0 ? {} : { trustedOcspResponders: n.trustedOcspResponders },
361
+ ...i === void 0 ? {} : { trustedOcspResponders: i },
229
362
  ...n.policy?.ocspResponderRevocation === void 0 ? {} : { responderRevocationPolicy: n.policy.ocspResponderRevocation },
230
- ...n.crls === void 0 ? {} : { responderRevocationCrls: n.crls }
231
- }, a = await c({
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({
232
369
  response: e,
233
- ...i
370
+ ...a
234
371
  });
235
- if (a.ok || !u.has(a.code)) return a;
372
+ if (o.ok || !x.has(o.code)) return o;
236
373
  for (let t of n.extraCertificates ?? []) {
237
374
  let n = parseCertificateSafe(t);
238
375
  if (n === void 0) continue;
239
- let r = await c({
376
+ let r = await v({
240
377
  response: e,
241
- ...i,
378
+ ...a,
242
379
  responderCertificate: n
243
380
  });
244
381
  if (r.ok) return r;
245
382
  }
246
- return a;
383
+ return o;
247
384
  }
248
385
  /**
249
386
  * Evaluates OCSP evidence for a single certificate (RFC 6960).
@@ -255,84 +392,43 @@ async function validateOcspResponseWithResponderFallback(e, t, n, r) {
255
392
  * sufficient to attribute the entry to `cert`.
256
393
  */
257
394
  async function evaluateOcspEvidence(e, t, n) {
258
- let { ocspResponses: r = [], at: a = /* @__PURE__ */ new Date() } = n, o = [], s = /* @__PURE__ */ new Set();
259
- for (let c of r) {
260
- let r;
261
- try {
262
- r = parseOcspResponseFromSource(c);
263
- } catch (e) {
264
- o.push({
265
- kind: "parse_error",
266
- message: e instanceof Error ? e.message : "OCSP response parse failed"
267
- });
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);
268
403
  continue;
269
404
  }
270
- let l = (r.responses ?? []).find((t) => normalizeHex(t.certId.serialNumberHex) === normalizeHex(e.serialNumberHex));
271
- if (l === void 0) continue;
272
- let u = await validateOcspResponseWithResponderFallback(r, t, n, a);
273
- if (!u.ok) {
274
- 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));
275
409
  continue;
276
410
  }
277
- if (l.certStatus === "revoked") {
278
- let t = i(l.revocationReasonCode);
279
- return {
280
- status: {
281
- certificate: e,
282
- status: "revoked",
283
- source: {
284
- kind: "ocsp",
285
- thisUpdate: l.thisUpdate
286
- },
287
- revocationInfo: {
288
- revocationDate: l.revokedAt ?? l.thisUpdate,
289
- ...t === void 0 ? {} : { reason: t }
290
- }
291
- },
292
- executionErrors: o
293
- };
294
- }
295
- if (l.certStatus === "good") return {
296
- status: {
297
- certificate: e,
298
- status: "good",
299
- source: {
300
- kind: "ocsp",
301
- thisUpdate: l.thisUpdate
302
- }
303
- },
304
- 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
305
415
  };
306
- s.add("ocsp_status_unknown");
416
+ recordOcspEvidence(o, l);
307
417
  }
308
- return s.size === 0 && s.add("no_applicable_ocsp"), {
309
- status: {
310
- certificate: e,
311
- status: "indeterminate",
312
- indeterminateReasons: [...s]
313
- },
314
- executionErrors: o
315
- };
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);
316
431
  }
317
- /**
318
- * Evaluates revocation status for a single certificate using available CRLs.
319
- * Returns both status and any execution errors encountered.
320
- *
321
- * Tries the chain issuer first; if that fails, searches extraCertificates
322
- * and chain for an indirect CRL issuer that matches the CRL's AKI or issuer DN.
323
- *
324
- * Also validates that CRL signers are not revoked (RFC 5280 §6.3.3).
325
- */
326
- const d = [
327
- "keyCompromise",
328
- "cACompromise",
329
- "affiliationChanged",
330
- "superseded",
331
- "cessationOfOperation",
332
- "certificateHold",
333
- "privilegeWithdrawn",
334
- "aACompromise"
335
- ];
336
432
  /**
337
433
  * Runs each candidate signer through the full pipeline for one base CRL:
338
434
  * signature/applicability, RFC 5280 §6.3.3(f) path to the anchor, then signer
@@ -342,101 +438,231 @@ const d = [
342
438
  * evidence into `state`.
343
439
  */
344
440
  async function resolveBaseCrlAgainstSigners(e) {
345
- let { cert: t, baseCrl: n, applicableDelta: r, crlThisUpdate: i, issuer: a, extraCertificates: o, chain: s, at: c, signerCtx: l, state: u } = e;
346
- for (let e of collectCrlSignerCandidates(n, a, o, s)) {
347
- let a = await checkCrlWithIssuer(t, n, r, e, c);
348
- if (!a.ok) continue;
349
- if (!await crlSignerChainsToAnchor(e, s, o, c)) {
350
- 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;
351
458
  continue;
352
459
  }
353
- let d = await validateCrlSigner(e, l);
354
- if (d === "resolved-revoked") {
355
- u.sawCrlSignerRevoked = !0;
460
+ let h = await validateCrlSigner(e, d);
461
+ if (h === "resolved-revoked") {
462
+ p.sawCrlSignerRevoked = !0;
356
463
  continue;
357
464
  }
358
- if (d === "resolved-indeterminate") {
359
- u.sawCrlSignerIndeterminate = !0;
465
+ if (h === "resolved-indeterminate") {
466
+ p.sawCrlSignerIndeterminate = !0;
360
467
  continue;
361
468
  }
362
- if (a.value.status === "revoked") return buildCrlRevokedStatus(t, e, i, a.value.revocationDate, a.value.reasonCode);
363
- recordGoodCrlEvidence(u, e, i, n);
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);
364
484
  return;
365
485
  }
366
486
  }
367
- async function evaluateCrlEvidence(e, t, n, r) {
368
- let { crls: i = [], extraCertificates: a = [], chain: o = [], at: s = /* @__PURE__ */ new Date() } = n, c = {
487
+ async function evaluateCrlEvidence(e, t, n, r, i) {
488
+ let { crls: a = [], extraCertificates: o = [], chain: s = [], at: c = /* @__PURE__ */ new Date() } = n, d = {
369
489
  executionErrors: [],
370
490
  coveredReasons: /* @__PURE__ */ new Set(),
371
491
  sawCrlSignerRevoked: !1,
372
492
  sawCrlSignerIndeterminate: !1,
373
493
  sawCrlSignerNotAuthorized: !1,
494
+ sawStaleCrl: !1,
495
+ sawDeltaCrlUnusable: !1,
496
+ sawDeltaCrlRetryLimit: !1,
497
+ sawUnrecognizedReasonCode: !1,
374
498
  sawGood: !1
375
- }, l = parseCrlEvidenceSources(i, c.executionErrors), u = l.filter((e) => e.baseCrlNumber === void 0), f = l.filter((e) => e.baseCrlNumber !== void 0);
376
- for (let n of u) {
377
- let i = findApplicableDeltaCrl(n, f), l = 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({
378
502
  cert: e,
379
- baseCrl: n,
380
- applicableDelta: i,
381
- crlThisUpdate: i !== void 0 && i.thisUpdate.getTime() > n.thisUpdate.getTime() ? i.thisUpdate : n.thisUpdate,
503
+ baseCrl: a,
504
+ deltaCandidates: rankApplicableDeltaCrls(a, m, c, g ?? 0, h),
382
505
  issuer: t,
383
- extraCertificates: a,
384
- chain: o,
385
- at: s,
506
+ extraCertificates: o,
507
+ chain: s,
508
+ at: c,
509
+ crlMaxAgeMs: h,
510
+ clockSkewMs: g,
511
+ unrecognizedReasonCode: n.policy?.unrecognizedReasonCode ?? "revoked",
386
512
  signerCtx: r,
387
- state: c
513
+ deltaBudget: i,
514
+ state: d
388
515
  });
389
516
  if (l !== void 0) return {
390
517
  status: l,
391
- executionErrors: c.executionErrors
518
+ executionErrors: d.executionErrors
392
519
  };
393
520
  }
394
- return c.sawGood && c.freshestGood !== void 0 ? d.every((e) => c.coveredReasons.has(e)) ? {
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) ? {
395
530
  status: {
396
531
  certificate: e,
397
532
  status: "good",
398
533
  source: {
399
534
  kind: "crl",
400
- signerCertificate: c.freshestGood.signer,
401
- thisUpdate: c.freshestGood.thisUpdate
535
+ signerCertificate: d.freshestGood.signer,
536
+ thisUpdate: d.freshestGood.thisUpdate
402
537
  }
403
538
  },
404
- executionErrors: c.executionErrors
539
+ executionErrors: d.executionErrors
405
540
  } : {
406
541
  status: {
407
542
  certificate: e,
408
543
  status: "indeterminate",
409
544
  indeterminateReasons: ["reason_coverage_incomplete"]
410
545
  },
411
- executionErrors: c.executionErrors
546
+ executionErrors: d.executionErrors
412
547
  } : {
413
548
  status: {
414
549
  certificate: e,
415
550
  status: "indeterminate",
416
- indeterminateReasons: [crlUnavailableReason(c)]
551
+ indeterminateReasons: [crlUnavailableReason(d)]
417
552
  },
418
- executionErrors: c.executionErrors
553
+ executionErrors: d.executionErrors
419
554
  };
420
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
+ }
421
564
  /** Most specific indeterminate reason when no CRL yielded a usable verdict. */
422
565
  function crlUnavailableReason(e) {
423
- 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";
424
567
  }
425
568
  /** Parses complete and delta CRL evidence while retaining source provenance. */
426
569
  function parseCrlEvidenceSources(e, t) {
427
570
  let n = [];
428
571
  for (let r of e) try {
429
- n.push(parseCrlFromSource(r));
572
+ n.push(f(r));
430
573
  } catch (e) {
431
- t.push({
432
- kind: "parse_error",
433
- message: e instanceof Error ? e.message : "CRL parse failed"
434
- });
574
+ t.push(evidenceParseError(e, "CRL parse failed"));
435
575
  }
436
576
  return n;
437
577
  }
438
- function findApplicableDeltaCrl(e, t) {
439
- 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;
440
666
  }
441
667
  /** The direct issuer first, then deduplicated indirect CRL-issuer candidates. */
442
668
  function collectCrlSignerCandidates(e, t, n, r) {
@@ -444,22 +670,20 @@ function collectCrlSignerCandidates(e, t, n, r) {
444
670
  for (let t of findIndirectCrlIssuers(e, n, r)) i.some((e) => sameCertificate(e, t)) || i.push(t);
445
671
  return i;
446
672
  }
447
- function checkCrlWithIssuer(e, n, r, i, a) {
448
- return t({
449
- certificate: e,
450
- issuerCertificate: i,
451
- crl: n,
452
- ...r === void 0 ? {} : { deltaCrl: r },
453
- at: a
454
- });
455
- }
456
673
  function recordGoodCrlEvidence(e, t, n, r) {
457
674
  e.sawGood = !0, (e.freshestGood === void 0 || n.getTime() > e.freshestGood.thisUpdate.getTime()) && (e.freshestGood = {
458
675
  signer: t,
459
676
  thisUpdate: n
460
677
  });
461
- for (let t of r.issuingDistributionPoint?.onlySomeReasons?.flags ?? d) e.coveredReasons.add(t);
678
+ for (let t of r) e.coveredReasons.add(t);
462
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
+ ]);
463
687
  /**
464
688
  * Evaluates revocation status for a single certificate by combining OCSP and
465
689
  * CRL evidence.
@@ -468,36 +692,49 @@ function recordGoodCrlEvidence(e, t, n, r) {
468
692
  * either source wins regardless of {@linkcode RevocationPolicy.prefer}
469
693
  * (fail-closed). Otherwise the preferred source's `good` verdict is reported —
470
694
  * for `'best-available'` the source with the later evidence `thisUpdate` wins,
471
- * ties favoring OCSP. If neither source is definitive, indeterminate reasons
472
- * 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.
473
699
  */
474
- async function evaluateCertificateRevocation(e, t, n, r) {
475
- 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");
476
- if (l !== void 0) return {
477
- status: l.status,
478
- executionErrors: s
479
- };
480
- 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");
481
702
  if (u !== void 0) return {
482
703
  status: u.status,
483
- executionErrors: s
704
+ executionErrors: c
484
705
  };
485
- let d = /* @__PURE__ */ new Set();
486
- for (let e of c) for (let t of e.status.indeterminateReasons ?? []) d.add(t);
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
710
+ };
711
+ let p = /* @__PURE__ */ new Set();
712
+ for (let e of l) for (let t of e.status.indeterminateReasons ?? []) p.add(t);
487
713
  return {
488
714
  status: {
489
715
  certificate: e,
490
716
  status: "indeterminate",
491
- indeterminateReasons: [...d]
717
+ indeterminateReasons: [...p]
492
718
  },
493
- executionErrors: s
719
+ executionErrors: c
494
720
  };
495
721
  }
496
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
+ /**
497
732
  * Checks revocation status for all certificates in a validated chain.
498
733
  *
499
734
  * Evaluates CRL and OCSP evidence against each certificate (except the trust
500
- * 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).
501
738
  *
502
739
  * @example
503
740
  * ```ts
@@ -513,7 +750,9 @@ async function evaluateCertificateRevocation(e, t, n, r) {
513
750
  * ```
514
751
  */
515
752
  async function checkChainRevocation(e) {
516
- 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";
517
756
  if (t.length === 0) return {
518
757
  ok: !0,
519
758
  value: {
@@ -525,34 +764,45 @@ async function checkChainRevocation(e) {
525
764
  certificates: []
526
765
  }
527
766
  };
528
- let s = {
767
+ let c = {
529
768
  cache: /* @__PURE__ */ new Map(),
530
769
  chain: t,
531
770
  crls: r,
532
771
  extraCertificates: i,
533
- at: a
534
- }, c = t.slice(0, -1), l = [], u = [], d = [], f = [];
535
- for (let n = 0; n < c.length; n++) {
536
- 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];
537
779
  if (r === void 0 || i === void 0) continue;
538
- let { status: a, executionErrors: o } = await evaluateCertificateRevocation(r, i, e, s);
539
- 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);
540
791
  }
541
- let p = u.length > 0, m = d.length > 0;
792
+ let h = f.length > 0, g = p.length > 0;
542
793
  return {
543
794
  ok: !0,
544
795
  value: {
545
- decision: p || m && o === "hard-fail" ? "deny" : "allow",
796
+ decision: h || g && s === "hard-fail" ? "deny" : "allow",
546
797
  summary: {
547
- revokedCertificates: u,
548
- indeterminateCertificates: d
798
+ revokedCertificates: f,
799
+ indeterminateCertificates: p
549
800
  },
550
- certificates: l,
551
- ...f.length > 0 ? { executionErrors: f } : {}
801
+ certificates: d,
802
+ ...m.length > 0 ? { executionErrors: m } : {}
552
803
  }
553
804
  };
554
805
  }
555
- //#endregion
556
- export { l as REVOCATION_INDETERMINATE_REASONS, checkChainRevocation };
806
+ export { y as REVOCATION_INDETERMINATE_REASONS, checkChainRevocation };
557
807
 
558
808
  //# sourceMappingURL=chain.js.map