micro509 0.18.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/CHANGELOG.md +88 -1
  2. package/dist/crypto/crypto.d.ts +11 -2
  3. package/dist/crypto/crypto.js +30 -17
  4. package/dist/crypto/crypto.js.map +1 -1
  5. package/dist/crypto.d.ts +2 -2
  6. package/dist/der/der.js.map +1 -1
  7. package/dist/index.d.ts +6 -5
  8. package/dist/internal/asn1/asn1.js +10 -2
  9. package/dist/internal/asn1/asn1.js.map +1 -1
  10. package/dist/internal/asn1/ber.js.map +1 -1
  11. package/dist/internal/asn1/decode-refusal.js.map +1 -1
  12. package/dist/internal/asn1/der.js.map +1 -1
  13. package/dist/internal/asn1/oids.js.map +1 -1
  14. package/dist/internal/crypto/algorithm-names.js.map +1 -1
  15. package/dist/internal/crypto/ecdsa.js.map +1 -1
  16. package/dist/internal/crypto/hash.js.map +1 -1
  17. package/dist/internal/crypto/pbes2.js.map +1 -1
  18. package/dist/internal/crypto/prime-ec.js.map +1 -1
  19. package/dist/internal/crypto/rsa-pss.js.map +1 -1
  20. package/dist/internal/crypto/sig-verify.d.ts +40 -0
  21. package/dist/internal/crypto/sig-verify.js +152 -65
  22. package/dist/internal/crypto/sig-verify.js.map +1 -1
  23. package/dist/internal/crypto/signing.js.map +1 -1
  24. package/dist/internal/jose/base64url.js.map +1 -1
  25. package/dist/internal/jose/json-data.js.map +1 -1
  26. package/dist/internal/jose/strict-json.js.map +1 -1
  27. package/dist/internal/shared/base64.js.map +1 -1
  28. package/dist/internal/shared/dn.js.map +1 -1
  29. package/dist/internal/shared/idna.js.map +1 -1
  30. package/dist/internal/shared/ip.js.map +1 -1
  31. package/dist/internal/shared/mailbox.js.map +1 -1
  32. package/dist/internal/shared/punycode.js.map +1 -1
  33. package/dist/internal/shared/uri-host.js.map +1 -1
  34. package/dist/internal/verify/name-constraints-engine.js.map +1 -1
  35. package/dist/internal/verify/policy-engine.js.map +1 -1
  36. package/dist/internal/verify/spki-distrust.js.map +1 -1
  37. package/dist/internal/verify/verify-path.js +222 -116
  38. package/dist/internal/verify/verify-path.js.map +1 -1
  39. package/dist/internal/x509/directory-name.js.map +1 -1
  40. package/dist/internal/x509/extension-bits.js.map +1 -1
  41. package/dist/internal/x509/extension-errors.js.map +1 -1
  42. package/dist/internal/x509/extension-registry.js.map +1 -1
  43. package/dist/internal/x509/general-name-profile.js.map +1 -1
  44. package/dist/internal/x509/general-name.js.map +1 -1
  45. package/dist/internal/x509/name-fields.js.map +1 -1
  46. package/dist/internal/x509/or-address.js.map +1 -1
  47. package/dist/jose/base64url.js.map +1 -1
  48. package/dist/jose/errors.js.map +1 -1
  49. package/dist/jose/jwe.js.map +1 -1
  50. package/dist/jose/jwks.js.map +1 -1
  51. package/dist/jose/jws.js.map +1 -1
  52. package/dist/jose/jwt.js.map +1 -1
  53. package/dist/jose/remote-jwks.js.map +1 -1
  54. package/dist/kdf/argon2-arithmetic.js.map +1 -1
  55. package/dist/kdf/argon2-core.js.map +1 -1
  56. package/dist/kdf/argon2-memory.js.map +1 -1
  57. package/dist/kdf/argon2-portable.js.map +1 -1
  58. package/dist/kdf/argon2.js.map +1 -1
  59. package/dist/keys/keys.js.map +1 -1
  60. package/dist/pem/pem.js.map +1 -1
  61. package/dist/pkcs/pfx.js.map +1 -1
  62. package/dist/pkcs/pkcs12-mac.js +1 -1
  63. package/dist/pkcs/pkcs12-mac.js.map +1 -1
  64. package/dist/pkcs/pkcs7.d.ts +10 -0
  65. package/dist/pkcs/pkcs7.js +106 -88
  66. package/dist/pkcs/pkcs7.js.map +1 -1
  67. package/dist/result/result.js.map +1 -1
  68. package/dist/revocation/chain.d.ts +67 -13
  69. package/dist/revocation/chain.js +429 -301
  70. package/dist/revocation/chain.js.map +1 -1
  71. package/dist/revocation/crl.d.ts +65 -11
  72. package/dist/revocation/crl.js +492 -202
  73. package/dist/revocation/crl.js.map +1 -1
  74. package/dist/revocation/ocsp.d.ts +79 -24
  75. package/dist/revocation/ocsp.js +417 -231
  76. package/dist/revocation/ocsp.js.map +1 -1
  77. package/dist/revocation/revocation.d.ts +68 -13
  78. package/dist/revocation/revocation.js +194 -73
  79. package/dist/revocation/revocation.js.map +1 -1
  80. package/dist/revocation.d.ts +4 -4
  81. package/dist/ssh/ssh.js.map +1 -1
  82. package/dist/ssh/wire.js.map +1 -1
  83. package/dist/verify/identity.d.ts +2 -2
  84. package/dist/verify/identity.js +2 -2
  85. package/dist/verify/identity.js.map +1 -1
  86. package/dist/verify/verify.d.ts +84 -32
  87. package/dist/verify/verify.js +221 -171
  88. package/dist/verify/verify.js.map +1 -1
  89. package/dist/verify.d.ts +3 -2
  90. package/dist/x509/certificate.js.map +1 -1
  91. package/dist/x509/csr.js.map +1 -1
  92. package/dist/x509/extensions.js.map +1 -1
  93. package/dist/x509/fingerprint.js.map +1 -1
  94. package/dist/x509/name-text.js.map +1 -1
  95. package/dist/x509/name.js.map +1 -1
  96. package/dist/x509/parse.d.ts +6 -2
  97. package/dist/x509/parse.js +121 -121
  98. package/dist/x509/parse.js.map +1 -1
  99. package/package.json +11 -11
@@ -1,18 +1,19 @@
1
- import { childrenOf as e, decodeNonNegativeIntegerBigInt as t, decodeNonNegativeIntegerNumber as n, decodeObjectIdentifier as r, decodeString as i, extractBitStringValue as a, hexToBytes as o, parseTime as s, requireElement as c, toArrayBuffer as l, toHex as u } from "../internal/asn1/asn1.js";
2
- import { decodeFailureResult as d, decodeRefusalOf as f } from "../internal/asn1/decode-refusal.js";
3
- import { bitString as p, concatBytes as m, enumeratedFromNumber as h, explicitContext as g, generalizedTime as _, integer as v, nullValue as y, objectIdentifier as b, octetString as x, readElement as S, readRootElement as C, readSequenceChildren as w, sequence as T, tlv as E } from "../internal/asn1/der.js";
4
- import { OIDS as D } from "../internal/asn1/oids.js";
5
- import { describeHashAlgorithm as O, describeSignatureAlgorithm as k } from "../internal/crypto/algorithm-names.js";
6
- import { getVerifySignatureConfigResult as A, verifySignedDataDetailed as j } from "../internal/crypto/sig-verify.js";
7
- import { encodeAlgorithmIdentifier as M, getSignatureAlgorithm as N, signBytes as P } from "../internal/crypto/signing.js";
8
- import { getCrypto as F } from "../internal/crypto/webcrypto.js";
9
- import { base64Encode as I } from "../internal/shared/base64.js";
10
- import { compareDistinguishedNames as L } from "../internal/shared/dn.js";
11
- import { pemDecodeOrThrow as R, pemEncode as z } from "../pem/pem.js";
12
- import { DECODE_REFUSAL_CODES as B, failureResult as V, rethrowIfInvariant as H, successResult as U, throwMicro509Error as W } from "../result/result.js";
13
- import { assertCrlMaxAge as G, checkCertificateRevocationAgainstCrl as K, coversAllDistributionPointReasons as q, parseCertificateRevocationListDerOrThrow as J, parseCertificateRevocationListPemOrThrow as Y } from "./crl.js";
14
- import { verifyCertificateChain as X } from "../verify/verify.js";
15
- import { parseCertificateDerOrThrow as Z, parseCertificateFromSource as Q } from "../x509/parse.js";
1
+ import { childrenOf as e, decodeNonNegativeIntegerBigInt as t, decodeNonNegativeIntegerNumber as n, decodeObjectIdentifier as r, decodeString as i, extractBitStringValue as a, hexToBytes as o, parseTime as s, requireElement as c, signatureBits as l, toArrayBuffer as u, toHex as d } from "../internal/asn1/asn1.js";
2
+ import { decodeFailureResult as f, decodeRefusalOf as p } from "../internal/asn1/decode-refusal.js";
3
+ import { bitString as m, concatBytes as h, enumeratedFromNumber as g, explicitContext as _, generalizedTime as v, integer as y, nullValue as b, objectIdentifier as x, octetString as S, readElement as C, readRootElement as w, readSequenceChildren as T, sequence as E, tlv as D } from "../internal/asn1/der.js";
4
+ import { OIDS as O } from "../internal/asn1/oids.js";
5
+ import { describeHashAlgorithm as k, describeSignatureAlgorithm as A } from "../internal/crypto/algorithm-names.js";
6
+ import { callerVerification as ee, getVerifySignatureConfigResult as j, resolveSignatureVerifiers as M, verifySignedDataDetailed as N } from "../internal/crypto/sig-verify.js";
7
+ import { encodeAlgorithmIdentifier as P, getSignatureAlgorithm as F, signBytes as I } from "../internal/crypto/signing.js";
8
+ import { getCrypto as L } from "../internal/crypto/webcrypto.js";
9
+ import { base64Encode as R } from "../internal/shared/base64.js";
10
+ import { compareDistinguishedNames as z } from "../internal/shared/dn.js";
11
+ import { anchorWorkingKey as te, carriesTrustAnchorKey as ne, certificateWorkingKey as B, pathWorkingKey as V, withWorkingParameters as H, workingParametersAt as U } from "../internal/verify/verify-path.js";
12
+ import { pemDecodeOrThrow as W, pemEncode as G } from "../pem/pem.js";
13
+ import { DECODE_REFUSAL_CODES as K, failureResult as q, rethrowIfInvariant as J, successResult as Y, throwMicro509Error as X } from "../result/result.js";
14
+ import { assertClockSkew as re, assertCrlMaxAge as ie, checkCertificateRevocationAgainstCrlsBy as ae, coversAllDistributionPointReasons as oe, distinctSignedCrls as Z, normalizeCrl as se } from "./crl.js";
15
+ import { trustAnchorFromCertificate as Q, verifyCertificateChain as ce } from "../verify/verify.js";
16
+ import { parseCertificateDerOrThrow as $, parseCertificateFromSource as le } from "../x509/parse.js";
16
17
  // src/revocation/ocsp.ts
17
18
  /**
18
19
  * Full OCSP lifecycle: build requests, create/parse/verify/validate responses.
@@ -25,7 +26,7 @@ import { parseCertificateDerOrThrow as Z, parseCertificateFromSource as Q } from
25
26
  */
26
27
  /** Throws a {@link ResultError} for an OCSP encoder input-validation failure. */
27
28
  function throwOcspEncoderError(e, t) {
28
- W(e, t);
29
+ X(e, t);
29
30
  }
30
31
  function assertOcspDate(e, t) {
31
32
  e !== void 0 && Number.isNaN(e.getTime()) && throwOcspEncoderError("invalid_date", `${t} must be a valid date`);
@@ -33,6 +34,19 @@ function assertOcspDate(e, t) {
33
34
  function assertOcspRevocationReasonCode(e) {
34
35
  e !== void 0 && !(Number.isSafeInteger(e) && e >= 0) && throwOcspEncoderError("invalid_revocation_reason_code", "revocationReasonCode must be a non-negative integer");
35
36
  }
37
+ function ocspKeyOf(e) {
38
+ return e.kind === "certificate" ? e.certificate : e.trustAnchor;
39
+ }
40
+ /** The name and key a CertID for `issuer` hashes (RFC 6960 §4.1.1). */
41
+ function certIdIssuerKey(e) {
42
+ return e.kind === "certificate" ? e.certificate : {
43
+ ...e.trustAnchor,
44
+ subject: e.certificateIssuer
45
+ };
46
+ }
47
+ function ocspCertificateOf(e) {
48
+ return e.kind === "certificate" ? e.certificate : void 0;
49
+ }
36
50
  /**
37
51
  * Builds a DER-encoded OCSP request containing one or more CertID entries
38
52
  * and an optional nonce extension.
@@ -53,20 +67,20 @@ async function createOcspRequest(e) {
53
67
  let t = e.hashAlgorithm ?? "SHA-256", n = [];
54
68
  for (let r of e.requests) {
55
69
  let e = normalizeCertificate(r.certificate), i = normalizeCertificate(r.issuerCertificate);
56
- n.push(T([await encodeOcspCertId(e, i, t)]));
70
+ n.push(E([await encodeOcspCertId(e, i, t)]));
57
71
  }
58
- let r = [T(n)];
59
- e.nonce !== void 0 && r.push(g(2, T([T([b(D.ocspNonce), x(x(e.nonce))])])));
60
- let i = T([T(r)]);
72
+ let r = [E(n)];
73
+ e.nonce !== void 0 && r.push(_(2, E([E([x(O.ocspNonce), S(S(e.nonce))])])));
74
+ let i = E([E(r)]);
61
75
  return {
62
76
  der: i,
63
- pem: z("OCSP REQUEST", i),
64
- base64: I(i)
77
+ pem: G("OCSP REQUEST", i),
78
+ base64: R(i)
65
79
  };
66
80
  }
67
81
  /** Throwing core for {@linkcode parseOcspRequestDer}. */
68
82
  function parseOcspRequestDerOrThrow(t) {
69
- let n = w(t, { maxDepth: 64 });
83
+ let n = T(t, { maxDepth: 64 });
70
84
  if (n.length < 1 || n.length > 2) throw Error("Malformed OCSP request");
71
85
  let r = c(n[0], "tbsRequest"), i = n[1];
72
86
  if (i !== void 0 && i.tag !== 160) throw Error("Malformed OCSP request");
@@ -105,7 +119,7 @@ function skipOcspRequestorName(e, t, n) {
105
119
  }
106
120
  /** Decodes a PEM-encoded OCSP request (`-----BEGIN OCSP REQUEST-----`). */
107
121
  function parseOcspRequestPemOrThrow(e) {
108
- return parseOcspRequestDerOrThrow(R("OCSP REQUEST", e));
122
+ return parseOcspRequestDerOrThrow(W("OCSP REQUEST", e));
109
123
  }
110
124
  /**
111
125
  * Decodes a DER-encoded OCSP request into a structured {@linkcode ParsedOcspRequest}.
@@ -115,9 +129,9 @@ function parseOcspRequestPemOrThrow(e) {
115
129
  */
116
130
  function parseOcspRequestDer(e) {
117
131
  try {
118
- return U(parseOcspRequestDerOrThrow(e));
132
+ return Y(parseOcspRequestDerOrThrow(e));
119
133
  } catch (e) {
120
- return H(e), d(e, B, "Malformed OCSP request");
134
+ return J(e), f(e, K, "Malformed OCSP request");
121
135
  }
122
136
  }
123
137
  /**
@@ -128,53 +142,53 @@ function parseOcspRequestDer(e) {
128
142
  */
129
143
  function parseOcspRequestPem(e) {
130
144
  try {
131
- return U(parseOcspRequestPemOrThrow(e));
145
+ return Y(parseOcspRequestPemOrThrow(e));
132
146
  } catch (e) {
133
- return H(e), d(e, B, "Malformed OCSP request");
147
+ return J(e), f(e, K, "Malformed OCSP request");
134
148
  }
135
149
  }
136
150
  /** Throwing core for {@linkcode parseOcspResponseDer}. */
137
151
  function parseOcspResponseDerOrThrow(t) {
138
- let i = w(t, { maxDepth: 64 });
152
+ let i = T(t, { maxDepth: 64 });
139
153
  if (i.length < 1 || i.length > 2) throw Error("Malformed OCSP response");
140
- let o = c(i[0], "responseStatus");
141
- if (o.tag !== 10) throw Error("responseStatus must use ENUMERATED");
142
- let s = ocspResponseStatusFromCode(n(o.value, "OCSP responseStatus")), l = i[1];
143
- if (l === void 0) return {
154
+ let a = c(i[0], "responseStatus");
155
+ if (a.tag !== 10) throw Error("responseStatus must use ENUMERATED");
156
+ let o = ocspResponseStatusFromCode(n(a.value, "OCSP responseStatus")), s = i[1];
157
+ if (s === void 0) return {
144
158
  der: new Uint8Array(t),
145
- responseStatus: s
159
+ responseStatus: o
146
160
  };
147
- if (l.tag !== 160) throw Error("Malformed OCSP response");
148
- let u = e(t, l), d = c(u[0], "responseBytes");
161
+ if (s.tag !== 160) throw Error("Malformed OCSP response");
162
+ let u = e(t, s), d = c(u[0], "responseBytes");
149
163
  if (u.length !== 1 || d.tag !== 48) throw Error("Malformed OCSP response");
150
164
  let f = e(t, d);
151
165
  if (f.length !== 2) throw Error("responseBytes must contain responseType and response");
152
166
  let p = c(f[0], "responseType"), m = c(f[1], "response");
153
167
  if (m.tag !== 4) throw Error("response must use OCTET STRING");
154
168
  let h = r(p.value);
155
- if (h !== D.ocspBasicResponse) return {
169
+ if (h !== O.ocspBasicResponse) return {
156
170
  der: new Uint8Array(t),
157
- responseStatus: s,
171
+ responseStatus: o,
158
172
  responseTypeOid: h
159
173
  };
160
- let g = m.value, _ = w(g);
174
+ let g = m.value, _ = T(g);
161
175
  if (_.length < 3 || _.length > 4) throw Error("Malformed BasicOCSPResponse");
162
176
  let v = c(_[0], "responseData"), y = c(_[1], "signatureAlgorithm"), b = c(_[2], "signatureValue"), x = _[3];
163
177
  if (x !== void 0 && x.tag !== 160) throw Error("Malformed BasicOCSPResponse");
164
- let S = e(g, y), C = r(c(S[0], "signatureAlgorithm OID").value), T = S[1], E = T === void 0 ? void 0 : g.slice(T.start - T.headerLength, T.end), O = g.slice(v.start - v.headerLength, v.end), A = parseSignedOcspResponseData(O);
178
+ let S = e(g, y), C = r(c(S[0], "signatureAlgorithm OID").value), w = S[1], E = w === void 0 ? void 0 : g.slice(w.start - w.headerLength, w.end), D = g.slice(v.start - v.headerLength, v.end), k = parseSignedOcspResponseData(D);
165
179
  return {
166
180
  der: new Uint8Array(t),
167
- responseStatus: s,
181
+ responseStatus: o,
168
182
  responseTypeOid: h,
169
- responseDataDer: O,
170
- responderId: A.responderId,
183
+ responseDataDer: D,
184
+ responderId: k.responderId,
171
185
  signatureAlgorithmOid: C,
172
186
  ...E === void 0 ? {} : { signatureAlgorithmParametersDer: E },
173
- signatureAlgorithmName: k(C, E),
174
- signatureValue: a(b),
175
- producedAt: A.producedAt,
176
- responses: A.responses,
177
- ...A.nonce === void 0 ? {} : { nonce: A.nonce },
187
+ signatureAlgorithmName: A(C, E),
188
+ ...l(b),
189
+ producedAt: k.producedAt,
190
+ responses: k.responses,
191
+ ...k.nonce === void 0 ? {} : { nonce: k.nonce },
178
192
  ...x?.tag === 160 ? { certificates: parseEmbeddedCertificates(g, x) } : {}
179
193
  };
180
194
  }
@@ -194,7 +208,7 @@ function parseOcspResponseDerOrThrow(t) {
194
208
  * ```
195
209
  */
196
210
  function parseOcspResponsePemOrThrow(e) {
197
- return parseOcspResponseDerOrThrow(R("OCSP RESPONSE", e));
211
+ return parseOcspResponseDerOrThrow(W("OCSP RESPONSE", e));
198
212
  }
199
213
  /**
200
214
  * Decodes a DER-encoded OCSP response into a structured {@linkcode ParsedOcspResponse}.
@@ -204,9 +218,9 @@ function parseOcspResponsePemOrThrow(e) {
204
218
  */
205
219
  function parseOcspResponseDer(e) {
206
220
  try {
207
- return U(parseOcspResponseDerOrThrow(e));
221
+ return Y(parseOcspResponseDerOrThrow(e));
208
222
  } catch (e) {
209
- return H(e), d(e, B, "Malformed OCSP response");
223
+ return J(e), f(e, K, "Malformed OCSP response");
210
224
  }
211
225
  }
212
226
  /**
@@ -217,9 +231,9 @@ function parseOcspResponseDer(e) {
217
231
  */
218
232
  function parseOcspResponsePem(e) {
219
233
  try {
220
- return U(parseOcspResponsePemOrThrow(e));
234
+ return Y(parseOcspResponsePemOrThrow(e));
221
235
  } catch (e) {
222
- return H(e), d(e, B, "Malformed OCSP response");
236
+ return J(e), f(e, K, "Malformed OCSP response");
223
237
  }
224
238
  }
225
239
  /**
@@ -250,8 +264,8 @@ function parseOcspResponsePem(e) {
250
264
  * ```
251
265
  */
252
266
  async function createOcspResponse(e) {
253
- let t = normalizeCertificate(e.signerCertificate), n = N(e.signerPrivateKey);
254
- A(n.algorithmOid, n.parameters, t.publicKeyAlgorithmOid, t.publicKeyParametersOid, "signer").ok || throwOcspEncoderError("signer_certificate_key_mismatch", "signerCertificate must carry a public key that verifies the signer key algorithm");
267
+ let t = normalizeCertificate(e.signerCertificate), n = F(e.signerPrivateKey);
268
+ j(n.algorithmOid, n.parameters, t.publicKeyAlgorithmOid, t.publicKeyParametersOid, "signer").ok || throwOcspEncoderError("signer_certificate_key_mismatch", "signerCertificate must carry a public key that verifies the signer key algorithm");
255
269
  let r = e.producedAt ?? /* @__PURE__ */ new Date();
256
270
  assertOcspDate(r, "producedAt");
257
271
  let i = e.hashAlgorithm ?? "SHA-256", a = [];
@@ -261,22 +275,22 @@ async function createOcspResponse(e) {
261
275
  a.push(await encodeSingleResponse(e, n, t, i));
262
276
  }
263
277
  let o = await digestBytes("SHA-1", extractSubjectPublicKeyBytes(t.subjectPublicKeyInfoDer)), s = [
264
- g(2, x(o)),
265
- _(r),
266
- T(a)
278
+ _(2, S(o)),
279
+ v(r),
280
+ E(a)
267
281
  ];
268
- e.nonce !== void 0 && s.push(g(1, T([T([b(D.ocspNonce), x(x(e.nonce))])])));
269
- let c = T(s), l = await P(e.signerPrivateKey, n, c), u = e.includedCertificates === void 0 ? [] : await Promise.all(e.includedCertificates.map(normalizeCertificate)), d = [
282
+ e.nonce !== void 0 && s.push(_(1, E([E([x(O.ocspNonce), S(S(e.nonce))])])));
283
+ let c = E(s), l = await I(e.signerPrivateKey, n, c), u = e.includedCertificates === void 0 ? [] : await Promise.all(e.includedCertificates.map(normalizeCertificate)), d = [
270
284
  c,
271
- M(n),
272
- p(l)
285
+ P(n),
286
+ m(l)
273
287
  ];
274
- u.length > 0 && d.push(g(0, T(u.map((e) => e.der))));
275
- let f = T(d), m = T([E(10, Uint8Array.of(0)), g(0, T([b(D.ocspBasicResponse), x(f)]))]);
288
+ u.length > 0 && d.push(_(0, E(u.map((e) => e.der))));
289
+ let f = E(d), p = E([D(10, Uint8Array.of(0)), _(0, E([x(O.ocspBasicResponse), S(f)]))]);
276
290
  return {
277
- der: m,
278
- pem: z("OCSP RESPONSE", m),
279
- base64: I(m)
291
+ der: p,
292
+ pem: G("OCSP RESPONSE", p),
293
+ base64: R(p)
280
294
  };
281
295
  }
282
296
  /**
@@ -285,33 +299,41 @@ async function createOcspResponse(e) {
285
299
  * Does **not** check responder binding, freshness, or nonce — use
286
300
  * {@linkcode validateOcspResponse} for full validation.
287
301
  */
288
- async function verifyOcspResponseSignature(e, t) {
289
- let n;
302
+ async function verifyOcspResponseSignature(e, t, n = {}) {
303
+ return await verifyOcspResponseSignatureWith(e, t, ee(n.signatureVerifiers));
304
+ }
305
+ async function verifyOcspResponseSignatureWith(e, t, n) {
306
+ let r;
290
307
  try {
291
- n = normalizeOcspResponse(e);
308
+ r = normalizeOcspResponse(e);
292
309
  } catch (e) {
293
- let t = f(e, B);
294
- return t === void 0 ? verifyOcspResponseFailureResult("signature_invalid", "OCSP response signed content is malformed") : verifyOcspResponseFailureResult(t.code, t.message);
310
+ let t = p(e, K);
311
+ return t === void 0 ? verifyOcspResponseFailureResult("malformed", "OCSP response signed content is malformed") : verifyOcspResponseFailureResult(t.code, t.message);
295
312
  }
296
- if (n.responseDataDer === void 0 || n.signatureAlgorithmOid === void 0 || n.signatureValue === void 0) return verifyOcspResponseFailureResult("signature_invalid", "OCSP response is not signed");
297
- let r;
313
+ if (r.responseDataDer === void 0 || r.signatureAlgorithmOid === void 0 || r.signatureValue === void 0) return verifyOcspResponseFailureResult("signature_invalid", "OCSP response is not signed");
314
+ let i;
298
315
  try {
299
- r = normalizeCertificate(t);
316
+ i = normalizeCertificate(t);
300
317
  } catch (e) {
301
- let t = f(e, B);
302
- return t === void 0 ? verifyOcspResponseFailureResult("signature_invalid", "OCSP signer certificate input is malformed") : verifyOcspResponseFailureResult(t.code, t.message);
318
+ let t = p(e, K);
319
+ return t === void 0 ? verifyOcspResponseFailureResult("malformed", "OCSP signer certificate input is malformed") : verifyOcspResponseFailureResult(t.code, t.message);
303
320
  }
304
- let i;
321
+ return await verifyOcspResponseSignatureByKey(r, i, n);
322
+ }
323
+ /** Verifies the signature of a parsed OCSP response with `signer`'s public key. */
324
+ async function verifyOcspResponseSignatureByKey(e, t, n) {
325
+ if (e.responseDataDer === void 0 || e.signatureAlgorithmOid === void 0 || e.signatureValue === void 0) return verifyOcspResponseFailureResult("signature_invalid", "OCSP response is not signed");
326
+ let r;
305
327
  try {
306
- i = await j(n.signatureAlgorithmOid, n.signatureAlgorithmParametersDer, r.publicKeyAlgorithmOid, r.publicKeyParametersOid, r.subjectPublicKeyInfoDer, n.signatureValue, n.responseDataDer);
328
+ r = await N(e.signatureAlgorithmOid, e.signatureAlgorithmParametersDer, t.publicKeyAlgorithmOid, t.publicKeyParametersOid, t.subjectPublicKeyInfoDer, e.signatureValue, e.signatureValueUnusedBits ?? 0, e.responseDataDer, n);
307
329
  } catch (e) {
308
- let t = f(e, B);
330
+ let t = p(e, K);
309
331
  return t === void 0 ? verifyOcspResponseFailureResult("signature_invalid", "OCSP response signature verification failed") : verifyOcspResponseFailureResult(t.code, t.message);
310
332
  }
311
- return i.ok ? i.valid ? {
333
+ return r.ok ? r.valid ? {
312
334
  ok: !0,
313
- value: n
314
- } : verifyOcspResponseFailureResult("signature_invalid", "OCSP response signature does not verify") : i.code === "verification_error" ? verifyOcspResponseFailureResult("signature_invalid", "OCSP response signature verification failed") : verifyOcspResponseFailureResult("signature_invalid", "OCSP response signature uses unsupported algorithm parameters");
335
+ value: e
336
+ } : verifyOcspResponseFailureResult("signature_invalid", "OCSP response signature does not verify") : r.code === "verification_error" ? verifyOcspResponseFailureResult("signature_invalid", "OCSP response signature verification failed") : verifyOcspResponseFailureResult("signature_invalid", "OCSP response signature uses unsupported algorithm parameters");
315
337
  }
316
338
  /**
317
339
  * Full OCSP response validation: response status check, signature verification,
@@ -335,90 +357,230 @@ async function verifyOcspResponseSignature(e, t) {
335
357
  * ```
336
358
  */
337
359
  async function validateOcspResponse(e) {
338
- G(e.responderRevocationCrlMaxAgeMs);
339
- let t;
360
+ return await validateOcspResponseWith(e, { verifiers: M(e.signatureVerifiers) });
361
+ }
362
+ /**
363
+ * {@linkcode validateOcspResponse} with resolved caller verifiers and the
364
+ * issuer's working key.
365
+ *
366
+ * @internal
367
+ */
368
+ async function validateOcspResponseWith(e, t) {
369
+ return await validateOcspResponseBy(e, {
370
+ kind: "certificate",
371
+ certificate: e.issuerCertificate
372
+ }, t);
373
+ }
374
+ /**
375
+ * {@linkcode validateOcspResponse} for a certificate that `issuer` issued,
376
+ * which may be a bare trust anchor.
377
+ *
378
+ * @internal
379
+ */
380
+ async function validateOcspResponseBy(e, t, n) {
381
+ let r = {
382
+ ...e,
383
+ at: e.at ?? /* @__PURE__ */ new Date()
384
+ };
385
+ ie(r.responderRevocationCrlMaxAgeMs), re(r.clockSkewMs);
386
+ let i;
340
387
  try {
341
- t = normalizeOcspResponse(e.response);
388
+ i = normalizeOcspResponse(r.response);
342
389
  } catch (e) {
343
- let t = f(e, B);
344
- return t === void 0 ? validateOcspResponseFailureResult("signature_invalid", "OCSP response signed content is malformed") : validateOcspResponseFailureResult(t.code, t.message);
345
- }
346
- if (t.responseStatus !== "successful") return validateOcspResponseFailureResult("response_status_invalid", `OCSP response status is ${t.responseStatus}`);
347
- let n = await normalizeOcspValidationInput(e, t);
348
- if (!n.ok) return n;
349
- let { issuer: r, trustedResponders: i, signer: a } = n, o = await verifyOcspResponseSignature(t, a);
350
- if (!o.ok) return validateOcspResponseFailureResult(o.code, o.message);
351
- let s = await validateOcspResponderAuthorization(e, t, r, a, i);
352
- if (s !== void 0) return s;
353
- let c = e.at ?? /* @__PURE__ */ new Date(), l = e.clockSkewMs ?? 0, u = await validateOcspResponseFreshness(t, r, {
354
- at: c,
355
- skew: l,
356
- profile: e.profile ?? "rfc6960"
390
+ let t = p(e, K);
391
+ return t === void 0 ? validateOcspResponseFailureResult("malformed", "OCSP response signed content is malformed") : validateOcspResponseFailureResult(t.code, t.message);
392
+ }
393
+ if (i.responseStatus !== "successful") return validateOcspResponseFailureResult("response_status_invalid", `OCSP response status is ${i.responseStatus}`);
394
+ let a = await normalizeOcspValidationInput(r, t, i);
395
+ if (!a.ok) return a;
396
+ let { issuer: o, trustedResponders: s, signer: c } = a, l = n.issuerWorkingKey ?? (o.kind === "certificate" ? B(o.certificate) : te(o.trustAnchor)), u = {
397
+ ...n,
398
+ issuerWorkingKey: l,
399
+ deltaBudget: n.deltaBudget ?? { remaining: 32 }
400
+ }, d = await classifyOcspResponder(r, i, o, c, s, u), f = await verifyOcspResponseSignatureByKey(i, ocspKeyOf(c), {
401
+ verifiers: n.verifiers,
402
+ workingParameters: { parametersDer: responderWorkingParameters(d, l) }
357
403
  });
358
- if (u !== void 0) return u;
359
- if (hasDuplicateOcspResponseCertificateSerial(t.responses ?? [])) return validateOcspResponseFailureResult("signature_invalid", "OCSP response contains multiple status entries for the same certificate");
360
- if (e.request !== void 0) {
361
- let n = validateOcspRequestCoverage(e.request, t);
362
- if (n !== void 0) return n;
404
+ if (!f.ok) return validateOcspResponseFailureResult(f.code, f.message);
405
+ let m = await validateOcspResponderAuthorization(r, i, d, u);
406
+ if (m !== void 0) return m;
407
+ let h = r.at ?? /* @__PURE__ */ new Date(), g = r.clockSkewMs ?? 0, _ = await validateOcspResponseFreshness(i, certIdIssuerKey(o), {
408
+ at: h,
409
+ skew: g,
410
+ profile: r.profile ?? "rfc6960"
411
+ });
412
+ if (_ !== void 0) return _;
413
+ if (hasDuplicateOcspResponseCertificateSerial(i.responses ?? [])) return validateOcspResponseFailureResult("signature_invalid", "OCSP response contains multiple status entries for the same certificate");
414
+ if (r.request !== void 0) {
415
+ let e = validateOcspRequestCoverage(r.request, i);
416
+ if (e !== void 0) return e;
363
417
  }
364
418
  return {
365
419
  ok: !0,
366
- value: t
420
+ value: i
367
421
  };
368
422
  }
369
423
  /** Re-parses OCSP validation certificates and resolves the response signer. */
370
- async function normalizeOcspValidationInput(e, t) {
371
- let n;
424
+ async function normalizeOcspValidationInput(e, t, n) {
425
+ let r;
372
426
  try {
373
- n = normalizeCertificate(e.issuerCertificate);
427
+ r = t.kind === "certificate" ? {
428
+ kind: "certificate",
429
+ certificate: normalizeCertificate(t.certificate)
430
+ } : t;
374
431
  } catch (e) {
375
- let t = f(e, B);
376
- return t === void 0 ? validateOcspResponseFailureResult("signature_invalid", "issuer certificate input is malformed") : validateOcspResponseFailureResult(t.code, t.message);
432
+ let t = p(e, K);
433
+ return t === void 0 ? validateOcspResponseFailureResult("malformed", "issuer certificate input is malformed") : validateOcspResponseFailureResult(t.code, t.message);
377
434
  }
378
435
  try {
379
- let r = (e.trustedOcspResponders ?? []).map(normalizeCertificate), i = await resolveOcspResponderCertificate(e, t, r);
436
+ let i = (e.trustedOcspResponders ?? []).map(normalizeCertificate), a = await resolveOcspResponderCertificate(e, t, n, i);
380
437
  return {
381
438
  ok: !0,
382
- parsedResponse: t,
383
- issuer: n,
384
- trustedResponders: r,
385
- signer: normalizeCertificate(i)
439
+ parsedResponse: n,
440
+ issuer: r,
441
+ trustedResponders: i,
442
+ signer: a === void 0 ? r : {
443
+ kind: "certificate",
444
+ certificate: normalizeCertificate(a)
445
+ }
386
446
  };
387
447
  } catch (e) {
388
- let t = f(e, B);
389
- return t === void 0 ? validateOcspResponseFailureResult("signature_invalid", "OCSP responder certificate input is malformed") : validateOcspResponseFailureResult(t.code, t.message);
448
+ let t = p(e, K);
449
+ return t === void 0 ? validateOcspResponseFailureResult("malformed", "OCSP responder certificate input is malformed") : validateOcspResponseFailureResult(t.code, t.message);
390
450
  }
391
451
  }
392
- /** Selects the responder certificate from explicit, embedded, trusted, or issuer inputs. */
393
- async function resolveOcspResponderCertificate(e, t, n) {
394
- return e.responderCertificate ?? await findMatchingOcspResponderCertificate(t.certificates, t.responderId) ?? await findMatchingOcspResponderCertificate(n, t.responderId) ?? t.certificates?.[0] ?? e.issuerCertificate;
395
- }
396
- async function validateOcspResponderAuthorization(e, t, n, r, i) {
397
- let a = await safeValidateOcspResponderIdBinding(t, r);
398
- if (!a.ok) return a;
399
- let o = i.some((e) => isSameOcspCertificate(r, e));
400
- if (!(isSameOcspCertificate(r, n) || o)) return await validateDelegatedOcspResponder(e, t, n, r);
452
+ /**
453
+ * Selects the responder certificate from explicit, embedded, trusted, or issuer
454
+ * inputs. `undefined` means the bare trust anchor issuer signed the response
455
+ * with its own key.
456
+ */
457
+ async function resolveOcspResponderCertificate(e, t, n, r) {
458
+ let i = e.responderCertificate ?? await findMatchingOcspResponderCertificate(n.certificates, n.responderId) ?? await findMatchingOcspResponderCertificate(r, n.responderId);
459
+ if (i !== void 0) return i;
460
+ if (t.kind === "certificate") return n.certificates?.[0] ?? t.certificate;
461
+ let a = n.responderId;
462
+ return a === void 0 || await matchesOcspResponderId(a, t.trustAnchor) ? void 0 : n.certificates?.[0];
463
+ }
464
+ async function classifyOcspResponder(e, t, n, r, i, a) {
465
+ if (r.kind === "trust_anchor" || isOcspIssuer(r.certificate, n)) return {
466
+ kind: "issuer",
467
+ signer: r
468
+ };
469
+ let o = r.certificate;
470
+ return i.some((e) => isSameOcspCertificate(o, e)) ? {
471
+ kind: "trusted",
472
+ certificate: o
473
+ } : {
474
+ kind: "delegated",
475
+ certificate: o,
476
+ path: await validateDelegatedResponderPath(e, t, n, o, a)
477
+ };
401
478
  }
402
- async function safeValidateOcspResponderIdBinding(e, t) {
403
- try {
404
- return await validateOcspResponderIdBinding(e.responderId, t);
405
- } catch (e) {
406
- let t = f(e, B);
407
- return t === void 0 ? validateOcspResponseFailureResult("signature_invalid", "OCSP responder certificate input is malformed") : validateOcspResponseFailureResult(t.code, t.message);
479
+ /**
480
+ * The key parameters a responder's signature verifies with: the issuer's
481
+ * working key, a trusted responder's own or inherited parameters, or those its
482
+ * delegated path gives it.
483
+ */
484
+ function responderWorkingParameters(e, t) {
485
+ return e.kind === "issuer" ? t.parametersDer : e.kind === "delegated" && e.path.ok ? e.path.parametersDer : U([e.certificate], 0, 0, t);
486
+ }
487
+ async function validateOcspResponderAuthorization(e, t, n, r) {
488
+ let i = await validateOcspResponderIdBinding(t.responderId, n.kind === "issuer" ? ocspKeyOf(n.signer) : n.certificate);
489
+ if (!i.ok) return i;
490
+ if (n.kind !== "delegated") return;
491
+ if (!n.path.ok) return n.path;
492
+ let a = await validateDelegatedOcspResponder(e, n.path.issuer, n.certificate, {
493
+ ...r,
494
+ issuerWorkingKey: n.path.issuerWorkingKey
495
+ });
496
+ if (a !== void 0) return a;
497
+ for (let t of n.path.caCertificates) {
498
+ let n = await checkDelegatedResponderRevocation(t.certificate, t.issuer, e, {
499
+ ...r,
500
+ issuerWorkingKey: t.issuerWorkingKey
501
+ });
502
+ if (!n.ok) return n;
408
503
  }
409
504
  }
410
- async function validateDelegatedOcspResponder(e, t, n, r) {
411
- let i = e.allowChainedResponderCertificate === !0;
412
- if (!i && !isDirectlyIssuedByOcspIssuer(r, n)) return validateOcspResponseFailureResult("responder_chain_invalid", "Delegated OCSP responder must be directly issued by issuer certificate");
413
- if (!(await X({
505
+ /**
506
+ * Whether `signer` is the issuer itself: the issuer certificate, or a
507
+ * certificate carrying the bare trust anchor's name and key.
508
+ */
509
+ function isOcspIssuer(e, t) {
510
+ return t.kind === "certificate" ? isSameOcspCertificate(e, t.certificate) : ne(e, t.trustAnchor);
511
+ }
512
+ /**
513
+ * Validates a delegated responder's certification path below `issuer`, which
514
+ * starts from the issuer's working key (RFC 5280 §6.1.4 (e)), and returns the
515
+ * parameters that path gives the responder's key.
516
+ */
517
+ async function validateDelegatedResponderPath(e, t, n, r, i) {
518
+ let a = i.issuerWorkingKey, o = e.allowChainedResponderCertificate === !0;
519
+ if (!o && !isDirectlyIssuedByOcspIssuer(r, ocspKeyOf(n))) return validateOcspResponseFailureResult("responder_chain_invalid", "Delegated OCSP responder must be directly issued by issuer certificate");
520
+ let s = await ce({
414
521
  leaf: r.der,
415
- intermediates: i ? buildOcspResponderIntermediates(t.certificates, r, n) : [],
416
- roots: [n.der],
417
- ...e.at === void 0 ? {} : { at: e.at }
418
- })).ok) return validateOcspResponseFailureResult("responder_chain_invalid", "OCSP responder certificate chain does not validate");
419
- if (r.extendedKeyUsage === void 0 || !r.extendedKeyUsage.includes("ocspSigning")) return validateOcspResponseFailureResult("ocsp_signing_missing", "Delegated OCSP responder lacks ocspSigning EKU");
420
- let a = await checkDelegatedResponderRevocation(r, n, e);
421
- return a.ok ? void 0 : a;
522
+ intermediates: o ? buildOcspResponderIntermediates(t.certificates, r, ocspCertificateOf(n)) : [],
523
+ ...delegatedPathStart(n, a),
524
+ ...e.at === void 0 ? {} : { at: e.at },
525
+ ...e.signatureVerifiers !== void 0 && { signatureVerifiers: e.signatureVerifiers },
526
+ ...i.distrustedSpkiSha256 !== void 0 && { distrustedSpkiSha256: i.distrustedSpkiSha256 }
527
+ });
528
+ if (!s.ok) return validateOcspResponseFailureResult("responder_chain_invalid", "OCSP responder certificate chain does not validate");
529
+ let [c, ...l] = responderPathLinks(s.value, n, a);
530
+ return {
531
+ ok: !0,
532
+ parametersDer: V(s.value, 0).parametersDer,
533
+ issuer: c?.issuer ?? n,
534
+ issuerWorkingKey: c?.issuerWorkingKey ?? a,
535
+ caCertificates: l
536
+ };
537
+ }
538
+ /**
539
+ * Each certificate of a delegated responder's validated path below the OCSP
540
+ * issuer, with the next certificate as its issuer and the OCSP issuer above
541
+ * the last.
542
+ */
543
+ function responderPathLinks(e, t, n) {
544
+ return (e.anchorCertificateInChain ? e.chain.slice(0, -1) : e.chain).map((r, i) => {
545
+ let a = e.chain[i + 1];
546
+ return a === void 0 ? {
547
+ certificate: r,
548
+ issuer: t,
549
+ issuerWorkingKey: n
550
+ } : {
551
+ certificate: r,
552
+ issuer: {
553
+ kind: "certificate",
554
+ certificate: a
555
+ },
556
+ issuerWorkingKey: V(e, i + 1)
557
+ };
558
+ });
559
+ }
560
+ /**
561
+ * Where a delegated responder's path starts: the issuer certificate as root,
562
+ * or trust anchor information carrying the issuer's working key when the
563
+ * issuer inherits its parameters or is a bare anchor.
564
+ */
565
+ function delegatedPathStart(e, t) {
566
+ if (e.kind === "trust_anchor") return {
567
+ roots: [],
568
+ trustAnchors: [e.trustAnchor]
569
+ };
570
+ let n = B(e.certificate).parametersDer, r = t.parametersDer;
571
+ return r === void 0 || n !== void 0 && sameDer(n, r) ? { roots: [e.certificate.der] } : {
572
+ roots: [],
573
+ trustAnchors: [H(Q(e.certificate), r)]
574
+ };
575
+ }
576
+ function sameDer(e, t) {
577
+ return e.length === t.length && e.every((e, n) => e === t[n]);
578
+ }
579
+ /** The ocspSigning and revocation checks on a delegated responder whose path validated. */
580
+ async function validateDelegatedOcspResponder(e, t, n, r) {
581
+ if (n.extendedKeyUsage === void 0 || !n.extendedKeyUsage.includes("ocspSigning")) return validateOcspResponseFailureResult("ocsp_signing_missing", "Delegated OCSP responder lacks ocspSigning EKU");
582
+ let i = await checkDelegatedResponderRevocation(n, t, e, r);
583
+ return i.ok ? void 0 : i;
422
584
  }
423
585
  /** Checks response-level and per-certificate OCSP timestamps against the validation time. */
424
586
  async function validateOcspResponseFreshness(e, t, n) {
@@ -447,8 +609,8 @@ function validateOcspRequestCoverage(e, t) {
447
609
  try {
448
610
  n = normalizeOcspRequest(e);
449
611
  } catch (e) {
450
- let t = f(e, B);
451
- return t === void 0 ? validateOcspResponseFailureResult("request_mismatch", "OCSP request input is malformed") : validateOcspResponseFailureResult(t.code, t.message);
612
+ let t = p(e, K);
613
+ return t === void 0 ? validateOcspResponseFailureResult("malformed", "OCSP request input is malformed") : validateOcspResponseFailureResult(t.code, t.message);
452
614
  }
453
615
  return n.nonce !== void 0 && n.nonce !== t.nonce ? validateOcspResponseFailureResult("nonce_mismatch", "OCSP response nonce does not match request nonce") : validateOcspRequestIdCoverage(new Set(n.requests.map((e) => serializeCertId(e))), new Set((t.responses ?? []).map((e) => serializeCertId(e.certId))), t.responses ?? []);
454
616
  }
@@ -458,11 +620,11 @@ function validateOcspRequestIdCoverage(e, t, n) {
458
620
  }
459
621
  /** Builds a `VerifyOcspResponseSignatureFailureResult`. */
460
622
  function verifyOcspResponseFailureResult(e, t) {
461
- return V(e, t);
623
+ return q(e, t);
462
624
  }
463
625
  /** Builds a `ValidateOcspResponseFailureResult`. */
464
626
  function validateOcspResponseFailureResult(e, t) {
465
- return V(e, t);
627
+ return q(e, t);
466
628
  }
467
629
  /**
468
630
  * Reports whether a certificate carries the `id-pkix-ocsp-nocheck` extension
@@ -473,50 +635,74 @@ function validateOcspResponseFailureResult(e, t) {
473
635
  function hasOcspNoCheckExtension(e) {
474
636
  return carriesOcspNoCheck(normalizeCertificate(e));
475
637
  }
638
+ /** The RFC 9608 §4 exemption a certificate parsed from its signed DER carries. */
639
+ function revocationSkipReasonOf(e) {
640
+ return e.noRevAvail === !0 ? "no_rev_avail" : carriesOcspNoCheck(e) ? "ocsp_nocheck" : void 0;
641
+ }
476
642
  /** Whether a parsed certificate carries `id-pkix-ocsp-nocheck` with its NULL value. */
477
643
  function carriesOcspNoCheck(e) {
478
- return e.extensions.some((e) => e.oid === D.ocspNoCheck && e.valueHex === "0500");
644
+ return e.extensions.some((e) => e.oid === O.ocspNoCheck && e.valueHex === "0500");
479
645
  }
480
- /** Parses a CRL from PEM string, DER bytes, or an already-parsed CRL. */
481
- function parseResponderCrlFromSource(e) {
482
- return typeof e == "object" && "issuer" in e ? e : typeof e == "string" ? Y(e) : J(e);
646
+ /** The CRLs among `sources` that parse, split into complete and delta CRLs. */
647
+ function partitionResponderCrls(e) {
648
+ let t = [], n = [];
649
+ for (let r of e) {
650
+ let e;
651
+ try {
652
+ e = se(r);
653
+ } catch {
654
+ continue;
655
+ }
656
+ (e.baseCrlNumber === void 0 ? t : n).push(e);
657
+ }
658
+ return {
659
+ complete: Z(t),
660
+ delta: Z(n)
661
+ };
483
662
  }
484
- function responderCrlCheck(e, t, n) {
663
+ function responderCrlCheck(e) {
485
664
  return {
486
- certificate: e,
487
- issuerCertificate: t,
488
- at: n.at ?? /* @__PURE__ */ new Date(),
489
- ...n.responderRevocationCrlMaxAgeMs === void 0 ? {} : { maxAgeMs: n.responderRevocationCrlMaxAgeMs },
490
- ...n.clockSkewMs === void 0 ? {} : { clockSkewMs: n.clockSkewMs },
491
- ...n.responderRevocationUnrecognizedReasonCode === void 0 ? {} : { unrecognizedReasonCode: n.responderRevocationUnrecognizedReasonCode }
665
+ at: e.at ?? /* @__PURE__ */ new Date(),
666
+ ...e.responderRevocationCrlMaxAgeMs === void 0 ? {} : { maxAgeMs: e.responderRevocationCrlMaxAgeMs },
667
+ ...e.clockSkewMs === void 0 ? {} : { clockSkewMs: e.clockSkewMs },
668
+ ...e.responderRevocationUnrecognizedReasonCode === void 0 ? {} : { unrecognizedReasonCode: e.responderRevocationUnrecognizedReasonCode },
669
+ ...e.responderRevocationUnreadSupersededDeltaCrls === void 0 ? {} : { unreadSupersededDeltaCrls: e.responderRevocationUnreadSupersededDeltaCrls }
492
670
  };
493
671
  }
672
+ /** The responder revocation outcome that `policy` and the responder's own extensions settle before any CRL is read. */
673
+ function responderRevocationSettledWithoutCrls(e, t) {
674
+ if (t === "skip") return { ok: !0 };
675
+ let n = revocationSkipReasonOf(e);
676
+ return n === "no_rev_avail" ? t === "require-evidence" ? validateOcspResponseFailureResult("responder_revocation_unknown", "Delegated OCSP responder carries noRevAvail, which no CRL lists") : { ok: !0 } : n === "ocsp_nocheck" && t !== "require-evidence" ? { ok: !0 } : void 0;
677
+ }
494
678
  /**
495
679
  * Applies the delegated-responder revocation policy (RFC 6960 §4.2.2.2.1).
496
680
  * See {@linkcode OcspResponderRevocationPolicy} for the policy semantics.
497
681
  */
498
- async function checkDelegatedResponderRevocation(e, t, n) {
499
- let r = n.responderRevocationPolicy ?? "honor-nocheck";
500
- if (r === "skip" || r === "honor-nocheck" && hasOcspNoCheckExtension(e)) return { ok: !0 };
501
- let i = responderCrlCheck(e, t, n), a = /* @__PURE__ */ new Set(), o = !1;
502
- for (let e of n.responderRevocationCrls ?? []) {
503
- let t;
504
- try {
505
- t = parseResponderCrlFromSource(e);
506
- } catch {
682
+ async function checkDelegatedResponderRevocation(e, t, n, r) {
683
+ let i = n.responderRevocationPolicy ?? "nocheck-or-evidence", a = responderRevocationSettledWithoutCrls(e, i);
684
+ if (a !== void 0) return a;
685
+ let o = responderCrlCheck(n), s = {
686
+ verifiers: r.verifiers,
687
+ workingParameters: { parametersDer: r.issuerWorkingKey.parametersDer }
688
+ }, c = partitionResponderCrls(n.responderRevocationCrls ?? []), l = /* @__PURE__ */ new Set(), u = !1, d = !1;
689
+ for (let n of c.complete) {
690
+ let i = await ae(e, n, c.delta, t, o, s, [r.deltaBudget]);
691
+ if (i.kind === "unsettled") {
692
+ d = !0;
507
693
  continue;
508
694
  }
509
- let n = await K({
510
- ...i,
511
- crl: t
512
- });
513
- if (!n.ok) o ||= n.code === "reason_code_unrecognized";
695
+ let a = i.result;
696
+ if (!a.ok) u ||= a.code === "reason_code_unrecognized";
514
697
  else {
515
- if (n.value.status === "revoked") return validateOcspResponseFailureResult("responder_revoked", "Delegated OCSP responder certificate is revoked");
516
- for (let e of n.value.coveredReasons) a.add(e);
698
+ if (a.value.status === "revoked") return validateOcspResponseFailureResult("responder_revoked", "Delegated OCSP responder certificate is revoked");
699
+ for (let e of a.value.coveredReasons) l.add(e);
517
700
  }
518
701
  }
519
- return o ? validateOcspResponseFailureResult("responder_revocation_unknown", "Delegated OCSP responder carries an unrecognized CRL reason code") : q(a) || r === "honor-nocheck" ? { ok: !0 } : validateOcspResponseFailureResult("responder_revocation_unknown", "Delegated OCSP responder revocation status could not be established");
702
+ return u ? validateOcspResponseFailureResult("responder_revocation_unknown", "Delegated OCSP responder carries an unrecognized CRL reason code") : d ? validateOcspResponseFailureResult("responder_revocation_unknown", "A delta CRL for the delegated OCSP responder could not settle its status") : oe(l) || i === "honor-nocheck" && !hasCriticalCrlDistributionPoints(e) ? { ok: !0 } : validateOcspResponseFailureResult("responder_revocation_unknown", "Delegated OCSP responder revocation status could not be established");
703
+ }
704
+ function hasCriticalCrlDistributionPoints(e) {
705
+ return e.extensions.some((e) => e.oid === O.cRLDistributionPoints && e.critical);
520
706
  }
521
707
  /** Accepts PEM, DER, or already-parsed OCSP response and returns a parsed response. */
522
708
  function normalizeOcspResponse(e) {
@@ -533,7 +719,7 @@ function normalizeOcspRequest(e) {
533
719
  throw Error("OCSP request input is malformed");
534
720
  }
535
721
  function parseSignedOcspResponseData(t) {
536
- let r = w(t);
722
+ let r = T(t);
537
723
  if (r.length < 3 || r.length > 5) throw Error("Malformed OCSP responseData");
538
724
  let i = 0;
539
725
  if (r[i]?.tag === 160) {
@@ -569,31 +755,31 @@ async function validateOcspResponderIdBinding(e, t) {
569
755
  }
570
756
  /** Returns `true` if the certificate matches the responder ID (subject name or key hash). */
571
757
  async function matchesOcspResponderId(e, t) {
572
- return e.type === "byName" ? compareOcspResponderNames(e.name, t.subject) : u(await digestBytes("SHA-1", extractSubjectPublicKeyBytes(t.subjectPublicKeyInfoDer))) === e.keyHashHex;
758
+ return e.type === "byName" ? compareOcspResponderNames(e.name, t.subject) : d(await digestBytes("SHA-1", extractSubjectPublicKeyBytes(t.subjectPublicKeyInfoDer))) === e.keyHashHex;
573
759
  }
574
760
  /** Identity check — same serial, issuer, subject, and SPKI. */
575
761
  function isSameOcspCertificate(e, t) {
576
- return e.serialNumberHex === t.serialNumberHex && L(e.issuer, t.issuer) && L(e.subject, t.subject) && e.subjectPublicKeyInfoDer.length === t.subjectPublicKeyInfoDer.length && e.subjectPublicKeyInfoDer.every((e, n) => e === t.subjectPublicKeyInfoDer[n]);
762
+ return e.serialNumberHex === t.serialNumberHex && z(e.issuer, t.issuer) && z(e.subject, t.subject) && e.subjectPublicKeyInfoDer.length === t.subjectPublicKeyInfoDer.length && e.subjectPublicKeyInfoDer.every((e, n) => e === t.subjectPublicKeyInfoDer[n]);
577
763
  }
578
764
  /** Returns `true` if `signer` was directly issued by `issuer` (name + AKI match). */
579
765
  function isDirectlyIssuedByOcspIssuer(e, t) {
580
- return !(!L(e.issuer, t.subject) || e.authorityKeyIdentifier !== void 0 && t.subjectKeyIdentifier !== void 0 && e.authorityKeyIdentifier !== t.subjectKeyIdentifier);
766
+ return !(!z(e.issuer, t.subject) || e.authorityKeyIdentifier !== void 0 && t.subjectKeyIdentifier !== void 0 && e.authorityKeyIdentifier !== t.subjectKeyIdentifier);
581
767
  }
582
768
  /** Filters embedded certificates to produce an intermediate chain (excluding signer and issuer). */
583
769
  function buildOcspResponderIntermediates(e, t, n) {
584
770
  if (e === void 0) return [];
585
771
  let r = [];
586
- for (let i of e) isSameOcspCertificate(i, t) || isSameOcspCertificate(i, n) || r.push(i.der);
772
+ for (let i of e) isSameOcspCertificate(i, t) || n !== void 0 && isSameOcspCertificate(i, n) || r.push(i.der);
587
773
  return r;
588
774
  }
589
775
  /** DER-encodes a CertID SEQUENCE (hashAlgorithm, issuerNameHash, issuerKeyHash, serialNumber). */
590
776
  async function encodeOcspCertId(e, t, n) {
591
- let r = n === "SHA-1" ? D.sha1 : D.sha256, i = await buildParsedOcspCertId(r, t, e.serialNumberHex);
592
- return T([
593
- T([b(r), y()]),
594
- x(o(i.issuerNameHashHex)),
595
- x(o(i.issuerKeyHashHex)),
596
- v(o(i.serialNumberHex))
777
+ let r = n === "SHA-1" ? O.sha1 : O.sha256, i = await buildParsedOcspCertId(r, t, e.serialNumberHex);
778
+ return E([
779
+ E([x(r), b()]),
780
+ S(o(i.issuerNameHashHex)),
781
+ S(o(i.issuerKeyHashHex)),
782
+ y(o(i.serialNumberHex))
597
783
  ]);
598
784
  }
599
785
  /** Computes issuer name/key hashes for a CertID given the hash algorithm OID and issuer certificate. */
@@ -601,41 +787,41 @@ async function buildParsedOcspCertId(e, t, n) {
601
787
  let r = ocspHashAlgorithmFromOid(e);
602
788
  return {
603
789
  hashAlgorithmOid: e,
604
- hashAlgorithmName: O(e),
605
- issuerNameHashHex: u(await digestBytes(r, o(t.subject.derHex))),
606
- issuerKeyHashHex: u(await digestBytes(r, extractSubjectPublicKeyBytes(t.subjectPublicKeyInfoDer))),
790
+ hashAlgorithmName: k(e),
791
+ issuerNameHashHex: d(await digestBytes(r, o(t.subject.derHex))),
792
+ issuerKeyHashHex: d(await digestBytes(r, extractSubjectPublicKeyBytes(t.subjectPublicKeyInfoDer))),
607
793
  serialNumberHex: n
608
794
  };
609
795
  }
610
796
  /** Hashes `bytes` with the given WebCrypto algorithm name. */
611
797
  async function digestBytes(e, t) {
612
- return new Uint8Array(await F().subtle.digest(e, l(t)));
798
+ return new Uint8Array(await L().subtle.digest(e, u(t)));
613
799
  }
614
800
  /** DER-encodes a SingleResponse (certId, certStatus, thisUpdate, optional nextUpdate). */
615
801
  async function encodeSingleResponse(e, t, n, r) {
616
802
  let i = await encodeOcspCertId(e, t, r), a = encodeOcspCertStatus(n);
617
- return T([
803
+ return E([
618
804
  i,
619
805
  a,
620
- _(n.thisUpdate ?? /* @__PURE__ */ new Date()),
621
- ...n.nextUpdate === void 0 ? [] : [g(0, _(n.nextUpdate))]
806
+ v(n.thisUpdate ?? /* @__PURE__ */ new Date()),
807
+ ...n.nextUpdate === void 0 ? [] : [_(0, v(n.nextUpdate))]
622
808
  ]);
623
809
  }
624
810
  /** DER-encodes the CertStatus CHOICE (good [0], revoked [1], unknown [2]). */
625
811
  function encodeOcspCertStatus(e) {
626
812
  switch (e.certStatus) {
627
- case "good": return E(128, /* @__PURE__ */ new Uint8Array());
628
- case "unknown": return E(130, /* @__PURE__ */ new Uint8Array());
813
+ case "good": return D(128, /* @__PURE__ */ new Uint8Array());
814
+ case "unknown": return D(130, /* @__PURE__ */ new Uint8Array());
629
815
  case "revoked": {
630
- let t = [_(e.revokedAt ?? e.thisUpdate ?? /* @__PURE__ */ new Date())];
631
- return e.revocationReasonCode !== void 0 && t.push(g(0, h(e.revocationReasonCode))), E(161, m(t));
816
+ let t = [v(e.revokedAt ?? e.thisUpdate ?? /* @__PURE__ */ new Date())];
817
+ return e.revocationReasonCode !== void 0 && t.push(_(0, g(e.revocationReasonCode))), D(161, h(t));
632
818
  }
633
819
  default: throw Error(`Unhandled CertStatus type: ${String(e)}`);
634
820
  }
635
821
  }
636
822
  /** Accepts PEM, DER, or already-parsed certificate and returns a parsed certificate. */
637
823
  function normalizeCertificate(e) {
638
- return hasParsedCertificateShape(e) ? Z(new Uint8Array(e.der)) : Q(e);
824
+ return hasParsedCertificateShape(e) ? $(new Uint8Array(e.der)) : le(e);
639
825
  }
640
826
  /** Type guard: distinguishes a `ParsedCertificate` from raw `Uint8Array`. */
641
827
  function hasParsedCertificateShape(e) {
@@ -643,7 +829,7 @@ function hasParsedCertificateShape(e) {
643
829
  }
644
830
  /** Decodes a DER-encoded CertID SEQUENCE into a {@linkcode ParsedOcspCertId}. */
645
831
  function parseOcspCertId(t) {
646
- let n = C(t, { maxDepth: 64 });
832
+ let n = w(t, { maxDepth: 64 });
647
833
  if (n.tag !== 48) throw Error("CertID must use SEQUENCE");
648
834
  let i = e(t, n);
649
835
  if (i.length !== 4) throw Error("CertID must contain hashAlgorithm, issuerNameHash, issuerKeyHash, and serialNumber");
@@ -654,14 +840,14 @@ function parseOcspCertId(t) {
654
840
  let s = c(o[0], "hashAlgorithm OID"), l = r(s.value);
655
841
  if (c(i[1], "issuerNameHash").tag !== 4) throw Error("issuerNameHash must use OCTET STRING");
656
842
  if (c(i[2], "issuerKeyHash").tag !== 4) throw Error("issuerKeyHash must use OCTET STRING");
657
- let d = c(i[3], "serialNumber");
658
- if (d.tag !== 2) throw Error("serialNumber must use INTEGER");
843
+ let u = c(i[3], "serialNumber");
844
+ if (u.tag !== 2) throw Error("serialNumber must use INTEGER");
659
845
  return {
660
846
  hashAlgorithmOid: l,
661
- hashAlgorithmName: O(l),
662
- issuerNameHashHex: u(c(i[1], "issuerNameHash").value),
663
- issuerKeyHashHex: u(c(i[2], "issuerKeyHash").value),
664
- serialNumberHex: u(d.value)
847
+ hashAlgorithmName: k(l),
848
+ issuerNameHashHex: d(c(i[1], "issuerNameHash").value),
849
+ issuerKeyHashHex: d(c(i[2], "issuerKeyHash").value),
850
+ serialNumberHex: d(u.value)
665
851
  };
666
852
  }
667
853
  /** Decodes a SingleResponse from its ASN.1 element within the ResponseData. */
@@ -718,7 +904,7 @@ function parseOcspResponderId(t, n) {
718
904
  if (i.value.length !== 20) throw Error("ResponderID byKey must be a 20-byte SHA-1 KeyHash");
719
905
  return {
720
906
  type: "byKeyHash",
721
- keyHashHex: u(i.value)
907
+ keyHashHex: d(i.value)
722
908
  };
723
909
  }
724
910
  case 161:
@@ -740,7 +926,7 @@ function parseResponderName(t, n) {
740
926
  for (let t of e.attributes) i.push(t), t.key !== void 0 && a[t.key] === void 0 && (a[t.key] = t.value);
741
927
  }
742
928
  return {
743
- derHex: u(t.slice(n.start - n.headerLength, n.end)),
929
+ derHex: d(t.slice(n.start - n.headerLength, n.end)),
744
930
  rdns: r,
745
931
  attributes: i,
746
932
  values: a
@@ -763,7 +949,7 @@ function parseResponderNameAttributeSet(t, n) {
763
949
  a.push(p), d !== void 0 && o[d] === void 0 && (o[d] = f);
764
950
  }
765
951
  return {
766
- derHex: u(t.slice(n.start - n.headerLength, n.end)),
952
+ derHex: d(t.slice(n.start - n.headerLength, n.end)),
767
953
  attributes: a,
768
954
  values: o
769
955
  };
@@ -815,18 +1001,18 @@ function prepareOcspNameCompareString(e) {
815
1001
  /** Maps a directory attribute type OID (X.520 `id-at` arc plus the legacy PKCS #9 emailAddress) to its friendly key name for responder name parsing. */
816
1002
  function responderNameKeyFromOid(e) {
817
1003
  switch (e) {
818
- case D.commonName: return "commonName";
819
- case D.surname: return "surname";
820
- case D.serialNumber: return "serialNumber";
821
- case D.countryName: return "country";
822
- case D.localityName: return "locality";
823
- case D.stateOrProvinceName: return "state";
824
- case D.streetAddress: return "street";
825
- case D.organizationName: return "organization";
826
- case D.organizationalUnitName: return "organizationalUnit";
827
- case D.title: return "title";
828
- case D.givenName: return "givenName";
829
- case D.emailAddress: return "emailAddress";
1004
+ case O.commonName: return "commonName";
1005
+ case O.surname: return "surname";
1006
+ case O.serialNumber: return "serialNumber";
1007
+ case O.countryName: return "country";
1008
+ case O.localityName: return "locality";
1009
+ case O.stateOrProvinceName: return "state";
1010
+ case O.streetAddress: return "street";
1011
+ case O.organizationName: return "organization";
1012
+ case O.organizationalUnitName: return "organizationalUnit";
1013
+ case O.title: return "title";
1014
+ case O.givenName: return "givenName";
1015
+ case O.emailAddress: return "emailAddress";
830
1016
  default: return;
831
1017
  }
832
1018
  }
@@ -843,10 +1029,10 @@ function parseOcspNonceFromExtensions(t, n) {
843
1029
  o.add(a);
844
1030
  let l = c(i[i.length - 1], "extnValue");
845
1031
  if (l.tag !== 4) throw Error("OCSP extension value must use OCTET STRING");
846
- if (a !== D.ocspNonce) continue;
847
- let d = C(l.value, { maxDepth: 64 });
848
- if (d.tag !== 4) throw Error("OCSP nonce extension value must use OCTET STRING");
849
- s = u(d.value);
1032
+ if (a !== O.ocspNonce) continue;
1033
+ let u = w(l.value, { maxDepth: 64 });
1034
+ if (u.tag !== 4) throw Error("OCSP nonce extension value must use OCTET STRING");
1035
+ s = d(u.value);
850
1036
  }
851
1037
  return s;
852
1038
  }
@@ -856,14 +1042,14 @@ function parseEmbeddedCertificates(t, n) {
856
1042
  if (i === void 0 || i.tag !== 48) throw Error("Malformed BasicOCSPResponse certs");
857
1043
  let a = i.start;
858
1044
  for (; a < i.end;) {
859
- let e = S(t, a);
860
- r.push(Z(t.slice(a, e.end))), a = e.end;
1045
+ let e = C(t, a);
1046
+ r.push($(t.slice(a, e.end))), a = e.end;
861
1047
  }
862
1048
  return r;
863
1049
  }
864
1050
  /** Extracts the raw public key bytes (without BIT STRING padding byte) from SPKI DER. */
865
1051
  function extractSubjectPublicKeyBytes(t) {
866
- let n = e(t, S(t)), r = c(n[1], "subjectPublicKey BIT STRING");
1052
+ let n = e(t, C(t)), r = c(n[1], "subjectPublicKey BIT STRING");
867
1053
  if (r.tag !== 3) throw Error("SPKI missing subjectPublicKey BIT STRING");
868
1054
  return r.value.slice(1);
869
1055
  }
@@ -932,8 +1118,8 @@ function normalizeHex(e) {
932
1118
  /** Maps a hash algorithm OID to the WebCrypto algorithm name. Throws on unsupported OIDs. */
933
1119
  function ocspHashAlgorithmFromOid(e) {
934
1120
  switch (e) {
935
- case D.sha1: return "SHA-1";
936
- case D.sha256: return "SHA-256";
1121
+ case O.sha1: return "SHA-1";
1122
+ case O.sha256: return "SHA-256";
937
1123
  default: throw Error(`Unsupported OCSP hash algorithm OID: ${e}`);
938
1124
  }
939
1125
  }
@@ -946,6 +1132,6 @@ function serializeCertId(e) {
946
1132
  e.serialNumberHex
947
1133
  ].join(":");
948
1134
  }
949
- export { carriesOcspNoCheck, createOcspRequest, createOcspResponse, hasOcspNoCheckExtension, parseOcspRequestDer, parseOcspRequestDerOrThrow, parseOcspRequestPem, parseOcspRequestPemOrThrow, parseOcspResponseDer, parseOcspResponseDerOrThrow, parseOcspResponsePem, parseOcspResponsePemOrThrow, validateOcspResponse, verifyOcspResponseSignature };
1135
+ export { carriesOcspNoCheck, createOcspRequest, createOcspResponse, hasOcspNoCheckExtension, parseOcspRequestDer, parseOcspRequestDerOrThrow, parseOcspRequestPem, parseOcspRequestPemOrThrow, parseOcspResponseDer, parseOcspResponseDerOrThrow, parseOcspResponsePem, parseOcspResponsePemOrThrow, revocationSkipReasonOf, validateOcspResponse, validateOcspResponseBy, validateOcspResponseWith, verifyOcspResponseSignature };
950
1136
 
951
1137
  //# sourceMappingURL=ocsp.js.map