micro509 0.9.0 → 0.11.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 (111) hide show
  1. package/dist/index.d.ts +5 -4
  2. package/dist/index.js +16 -15
  3. package/dist/internal/asn1/asn1.js +145 -186
  4. package/dist/internal/asn1/asn1.js.map +1 -0
  5. package/dist/internal/asn1/der.js +210 -227
  6. package/dist/internal/asn1/der.js.map +1 -0
  7. package/dist/internal/asn1/oids.js +297 -101
  8. package/dist/internal/asn1/oids.js.map +1 -0
  9. package/dist/internal/asn1/oids2.js +69 -0
  10. package/dist/internal/asn1/oids2.js.map +1 -0
  11. package/dist/internal/crypto/algorithm-names.js +37 -35
  12. package/dist/internal/crypto/algorithm-names.js.map +1 -0
  13. package/dist/internal/crypto/ecdsa.js +25 -28
  14. package/dist/internal/crypto/ecdsa.js.map +1 -0
  15. package/dist/internal/crypto/hash.js +56 -117
  16. package/dist/internal/crypto/hash.js.map +1 -0
  17. package/dist/internal/crypto/pbes2.js +122 -133
  18. package/dist/internal/crypto/pbes2.js.map +1 -0
  19. package/dist/internal/crypto/rsa-pss.js +118 -124
  20. package/dist/internal/crypto/rsa-pss.js.map +1 -0
  21. package/dist/internal/crypto/sig-verify.js +87 -99
  22. package/dist/internal/crypto/sig-verify.js.map +1 -0
  23. package/dist/internal/crypto/signing.d.ts +12 -8
  24. package/dist/internal/crypto/signing.js +53 -55
  25. package/dist/internal/crypto/signing.js.map +1 -0
  26. package/dist/internal/crypto/webcrypto.js +5 -3
  27. package/dist/internal/crypto/webcrypto.js.map +1 -0
  28. package/dist/internal/shared/base64.js +10 -9
  29. package/dist/internal/shared/base64.js.map +1 -0
  30. package/dist/internal/shared/dn.js +50 -57
  31. package/dist/internal/shared/dn.js.map +1 -0
  32. package/dist/internal/shared/ip.js +43 -53
  33. package/dist/internal/shared/ip.js.map +1 -0
  34. package/dist/internal/verify/name-constraints-engine.js +211 -239
  35. package/dist/internal/verify/name-constraints-engine.js.map +1 -0
  36. package/dist/internal/verify/policy-engine.js +228 -247
  37. package/dist/internal/verify/policy-engine.js.map +1 -0
  38. package/dist/internal/verify/verify-path.js +213 -228
  39. package/dist/internal/verify/verify-path.js.map +1 -0
  40. package/dist/internal/x509/extension-bits.js +62 -59
  41. package/dist/internal/x509/extension-bits.js.map +1 -0
  42. package/dist/internal/x509/extension-registry.js +133 -164
  43. package/dist/internal/x509/extension-registry.js.map +1 -0
  44. package/dist/internal/x509/name-fields.js +35 -41
  45. package/dist/internal/x509/name-fields.js.map +1 -0
  46. package/dist/keys/keys.d.ts +583 -547
  47. package/dist/keys/keys.js +519 -431
  48. package/dist/keys/keys.js.map +1 -0
  49. package/dist/keys.js +2 -2
  50. package/dist/pem/pem.d.ts +46 -46
  51. package/dist/pem/pem.js +62 -81
  52. package/dist/pem/pem.js.map +1 -0
  53. package/dist/pem.js +2 -2
  54. package/dist/pkcs/pfx.d.ts +96 -80
  55. package/dist/pkcs/pfx.js +191 -231
  56. package/dist/pkcs/pfx.js.map +1 -0
  57. package/dist/pkcs/pkcs12-mac.d.ts +20 -18
  58. package/dist/pkcs/pkcs12-mac.js +90 -111
  59. package/dist/pkcs/pkcs12-mac.js.map +1 -0
  60. package/dist/pkcs/pkcs7.d.ts +118 -69
  61. package/dist/pkcs/pkcs7.js +401 -443
  62. package/dist/pkcs/pkcs7.js.map +1 -0
  63. package/dist/pkcs.d.ts +2 -2
  64. package/dist/pkcs.js +4 -4
  65. package/dist/result/result.d.ts +37 -32
  66. package/dist/result/result.js +46 -44
  67. package/dist/result/result.js.map +1 -0
  68. package/dist/result.js +2 -2
  69. package/dist/revocation/chain.d.ts +138 -119
  70. package/dist/revocation/chain.js +248 -281
  71. package/dist/revocation/chain.js.map +1 -0
  72. package/dist/revocation/crl.d.ts +125 -123
  73. package/dist/revocation/crl.js +653 -745
  74. package/dist/revocation/crl.js.map +1 -0
  75. package/dist/revocation/ocsp.d.ts +183 -177
  76. package/dist/revocation/ocsp.js +579 -636
  77. package/dist/revocation/ocsp.js.map +1 -0
  78. package/dist/revocation/revocation.d.ts +26 -26
  79. package/dist/revocation/revocation.js +104 -125
  80. package/dist/revocation/revocation.js.map +1 -0
  81. package/dist/revocation.js +5 -5
  82. package/dist/verify/identity.d.ts +42 -42
  83. package/dist/verify/identity.js +158 -167
  84. package/dist/verify/identity.js.map +1 -0
  85. package/dist/verify/name-constraints.d.ts +7 -7
  86. package/dist/verify/policy.d.ts +10 -10
  87. package/dist/verify/verify.d.ts +163 -163
  88. package/dist/verify/verify.js +396 -392
  89. package/dist/verify/verify.js.map +1 -0
  90. package/dist/verify.js +3 -3
  91. package/dist/x509/certificate.d.ts +117 -117
  92. package/dist/x509/certificate.js +51 -60
  93. package/dist/x509/certificate.js.map +1 -0
  94. package/dist/x509/csr.d.ts +25 -25
  95. package/dist/x509/csr.js +26 -30
  96. package/dist/x509/csr.js.map +1 -0
  97. package/dist/x509/extensions.d.ts +228 -184
  98. package/dist/x509/extensions.js +175 -200
  99. package/dist/x509/extensions.js.map +1 -0
  100. package/dist/x509/fingerprint.d.ts +55 -0
  101. package/dist/x509/fingerprint.js +55 -0
  102. package/dist/x509/fingerprint.js.map +1 -0
  103. package/dist/x509/name.d.ts +94 -93
  104. package/dist/x509/name.js +30 -29
  105. package/dist/x509/name.js.map +1 -0
  106. package/dist/x509/parse.d.ts +288 -185
  107. package/dist/x509/parse.js +762 -677
  108. package/dist/x509/parse.js.map +1 -0
  109. package/dist/x509.d.ts +3 -2
  110. package/dist/x509.js +7 -6
  111. package/package.json +79 -41
@@ -1,13 +1,13 @@
1
- import { OIDS } from "../internal/asn1/oids.js";
2
- import { errorResult, indexedErrorResult, indexedMicro509Error, micro509Error } from "../result/result.js";
3
- import { parseIpAddressToBytes } from "../internal/shared/ip.js";
4
- import { parseCertificateDerOrThrow, parseCertificateSigningRequestDerOrThrow, parseCertificateSigningRequestPemOrThrow } from "../x509/parse.js";
5
- import { verifySignedDataDetailed } from "../internal/crypto/sig-verify.js";
6
- import { createNameConstraintValidationState, evaluateNameConstraints } from "../internal/verify/name-constraints-engine.js";
7
- import { createPolicyValidationState, evaluatePolicyChain } from "../internal/verify/policy-engine.js";
8
- import { buildChainInternal, countCaCertificatesBelowParsed, isSelfIssued, isWithinValidity, loadCertificates, loadSingleCertificate, verifyCertificateSignature } from "../internal/verify/verify-path.js";
9
- import { checkChainRevocation } from "../revocation/chain.js";
10
- import { matchServiceIdentity } from "./identity.js";
1
+ import { OIDS as e } from "../internal/asn1/oids2.js";
2
+ import { errorResult as t, indexedErrorResult as n, indexedMicro509Error as r, micro509Error as i } from "../result/result.js";
3
+ import { parseIpAddressToBytes as a } from "../internal/shared/ip.js";
4
+ import { parseCertificateDerOrThrow as o, parseCertificateSigningRequestDerOrThrow as s, parseCertificateSigningRequestPemOrThrow as c } from "../x509/parse.js";
5
+ import { verifySignedDataDetailed as l } from "../internal/crypto/sig-verify.js";
6
+ import { createNameConstraintValidationState as u, evaluateNameConstraints as d } from "../internal/verify/name-constraints-engine.js";
7
+ import { createPolicyValidationState as f, evaluatePolicyChain as p } from "../internal/verify/policy-engine.js";
8
+ import { authorityKeyIdentifierMismatch as m, buildChainInternal as h, countCaCertificatesBelowParsed as g, isSelfIssued as _, isWithinValidity as v, loadCertificates as y, loadSingleCertificate as b, verifyCertificateSignature as x } from "../internal/verify/verify-path.js";
9
+ import { matchServiceIdentity as S } from "./identity.js";
10
+ import { checkChainRevocation as C } from "../revocation/chain.js";
11
11
  //#region src/verify/verify.ts
12
12
  /**
13
13
  * Public certificate and CSR verification APIs.
@@ -52,7 +52,7 @@ import { matchServiceIdentity } from "./identity.js";
52
52
  * - `certificate_revoked` — revocation evidence confirms a chain certificate is revoked.
53
53
  * - `revocation_indeterminate` — revocation status could not be determined under a hard-fail policy.
54
54
  */
55
- const VERIFY_ERROR_CODES = [
55
+ const w = [
56
56
  "no_trusted_root",
57
57
  "issuer_not_found",
58
58
  "signature_invalid",
@@ -75,26 +75,20 @@ const VERIFY_ERROR_CODES = [
75
75
  "unsupported_signature_algorithm_parameters",
76
76
  "certificate_revoked",
77
77
  "revocation_indeterminate"
78
- ];
79
- /**
80
- * OIDs of extensions this verifier processes during path validation.
81
- * Per RFC 5280 §6.1, certificates with unrecognized critical extensions
82
- * that are not in this set must be rejected.
83
- */
84
- const PROCESSED_EXTENSION_OIDS = /* @__PURE__ */ new Set([
85
- OIDS.basicConstraints,
86
- OIDS.keyUsage,
87
- OIDS.extendedKeyUsage,
88
- OIDS.subjectAltName,
89
- OIDS.nameConstraints,
90
- OIDS.authorityKeyIdentifier,
91
- OIDS.subjectKeyIdentifier,
92
- OIDS.authorityInfoAccess,
93
- OIDS.cRLDistributionPoints,
94
- OIDS.certificatePolicies,
95
- OIDS.policyMappings,
96
- OIDS.policyConstraints,
97
- OIDS.inhibitAnyPolicy
78
+ ], T = /* @__PURE__ */ new Set([
79
+ e.basicConstraints,
80
+ e.keyUsage,
81
+ e.extendedKeyUsage,
82
+ e.subjectAltName,
83
+ e.nameConstraints,
84
+ e.authorityKeyIdentifier,
85
+ e.subjectKeyIdentifier,
86
+ e.authorityInfoAccess,
87
+ e.cRLDistributionPoints,
88
+ e.certificatePolicies,
89
+ e.policyMappings,
90
+ e.policyConstraints,
91
+ e.inhibitAnyPolicy
98
92
  ]);
99
93
  /**
100
94
  * Discovers and signature-verifies a candidate certification path from a
@@ -102,37 +96,25 @@ const PROCESSED_EXTENSION_OIDS = /* @__PURE__ */ new Set([
102
96
  * time, constraints, or leaf policy — use {@linkcode validateCandidatePath}
103
97
  * for that, or {@linkcode verifyCertificateChain} for the all-in-one API.
104
98
  */
105
- async function buildCandidatePathRaw(input) {
106
- let leaf;
107
- let intermediates;
108
- let roots;
99
+ async function buildCandidatePathRaw(e) {
100
+ let t, n, r;
109
101
  try {
110
- leaf = loadSingleCertificate(input.leaf);
111
- intermediates = loadCertificates(input.intermediates ?? []);
112
- roots = loadCertificates(input.roots);
113
- } catch (error) {
114
- return failure("issuer_not_found", "certificate source is malformed or leaf source does not contain exactly one certificate", 0, detail({ actual: error instanceof Error ? error.message : "certificate source is malformed" }));
102
+ t = b(e.leaf), n = y(e.intermediates ?? []), r = y(e.roots);
103
+ } catch (e) {
104
+ return failure("issuer_not_found", "certificate source is malformed or leaf source does not contain exactly one certificate", 0, detail({ actual: e instanceof Error ? e.message : "certificate source is malformed" }));
115
105
  }
116
- const anchors = input.trustAnchors ?? [];
117
- const at = input.at ?? /* @__PURE__ */ new Date();
118
- const buildResult = await buildChainInternal(leaf, intermediates, roots, anchors, at, {
106
+ let i = e.trustAnchors ?? [], a = e.at ?? /* @__PURE__ */ new Date(), o = await h(t, n, r, i, a, {
119
107
  failure,
120
108
  detail
121
- });
122
- const chain = buildResult.chain;
123
- if (!buildResult.foundTrustedRoot) {
124
- if (buildResult.failure !== void 0) return buildResult.failure;
125
- if (buildResult.missingIssuerAt !== void 0) return failure("issuer_not_found", "issuer certificate not found", buildResult.missingIssuerAt, buildFailureDetails(chain, buildResult.missingIssuerAt));
126
- return failure("no_trusted_root", "no trusted root found", void 0, detail({ chainCommonNames: chain.map((certificate) => certificate.subject.values.commonName ?? "<unnamed>") }));
127
- }
128
- const root = chain[chain.length - 1];
129
- if (root === void 0) return failure("no_trusted_root", "no trusted root found");
130
- return {
131
- ok: true,
109
+ }), s = o.chain;
110
+ if (!o.foundTrustedRoot) return o.failure === void 0 ? o.missingIssuerAt === void 0 ? failure("no_trusted_root", "no trusted root found", void 0, detail({ chainCommonNames: s.map((e) => e.subject.values.commonName ?? "<unnamed>") })) : failure("issuer_not_found", "issuer certificate not found", o.missingIssuerAt, buildFailureDetails(s, o.missingIssuerAt)) : o.failure;
111
+ let c = s[s.length - 1];
112
+ return c === void 0 ? failure("no_trusted_root", "no trusted root found") : {
113
+ ok: !0,
132
114
  value: {
133
- leaf,
134
- chain,
135
- root
115
+ leaf: t,
116
+ chain: s,
117
+ root: c
136
118
  }
137
119
  };
138
120
  }
@@ -158,9 +140,9 @@ async function buildCandidatePathRaw(input) {
158
140
  * }
159
141
  * ```
160
142
  */
161
- async function buildCandidatePath(input) {
162
- const result = await buildCandidatePathRaw(input);
163
- return result.ok ? result : verifyFailureResult(result);
143
+ async function buildCandidatePath(e) {
144
+ let t = await buildCandidatePathRaw(e);
145
+ return t.ok ? t : verifyFailureResult(t);
164
146
  }
165
147
  /**
166
148
  * Validates a pre-built candidate path: time window, critical extensions,
@@ -170,87 +152,115 @@ async function buildCandidatePath(input) {
170
152
  * The chain must be in leaf-to-root order. The root (last entry) is
171
153
  * assumed trusted and not re-verified.
172
154
  */
173
- async function validateCandidatePathRaw(input) {
174
- const chain = input.chain;
175
- const at = input.at ?? /* @__PURE__ */ new Date();
176
- const validationStateResult = buildValidationState(input, chain.length);
177
- if (!validationStateResult.ok) return validationStateResult;
178
- const leaf = chain[0];
179
- if (leaf === void 0) return failure("issuer_not_found", "chain is empty", 0);
180
- if (chain.length === 1 && isSelfIssued(leaf)) {
181
- if (input.allowSelfSignedLeaf !== true) return failure("self_signed_leaf_not_allowed", "self-signed leaf not allowed", 0, detail({ subjectCommonName: leaf.subject.values.commonName }));
155
+ async function validateCandidatePathRaw(e) {
156
+ let t = e.chain, n = e.at ?? /* @__PURE__ */ new Date(), r = buildValidationState(e, t.length);
157
+ if (!r.ok) return r;
158
+ let i = t[0];
159
+ if (i === void 0) return failure("issuer_not_found", "chain is empty", 0);
160
+ let a = validateSelfSignedLeafAllowed(i, t.length, e);
161
+ if (a !== void 0) return a;
162
+ let o = await validatePathCertificates(t, n);
163
+ if (o !== void 0) return o;
164
+ let s = validatePathLengthConstraints(t);
165
+ if (s !== void 0) return s;
166
+ let c = validatePolicyAndNameConstraints(t, r.value);
167
+ return c.ok ? validateLeaf(i, e, c.policyValidation) : c;
168
+ }
169
+ function validateSelfSignedLeafAllowed(e, t, n) {
170
+ if (!(t !== 1 || !_(e) || n.allowSelfSignedLeaf === !0)) return failure("self_signed_leaf_not_allowed", "self-signed leaf not allowed", 0, detail({ subjectCommonName: e.subject.values.commonName }));
171
+ }
172
+ /** Validates every certificate and issuer relationship in a candidate path. */
173
+ async function validatePathCertificates(e, t) {
174
+ for (let n = 0; n < e.length; n += 1) {
175
+ let r = e[n];
176
+ if (r === void 0) return failure("issuer_not_found", "chain element missing", n);
177
+ let i = validateCertificateAtPathIndex(r, n, t);
178
+ if (i !== void 0) return i;
179
+ let a = await validatePathIssuerAtIndex(e, r, n);
180
+ if (a !== void 0) return a;
182
181
  }
183
- for (let index = 0; index < chain.length; index += 1) {
184
- const current = chain[index];
185
- if (current === void 0) return failure("issuer_not_found", "chain element missing", index);
186
- if (!isWithinValidity(current, at)) return failure("certificate_expired", "certificate not valid at requested time", index, detail({
187
- subjectCommonName: current.subject.values.commonName,
188
- expected: describeDateTime(at),
189
- actual: `${describeDateTime(current.notBefore)}..${describeDateTime(current.notAfter)}`
190
- }));
191
- const unprocessedCritical = findUnprocessedCriticalExtension(current);
192
- if (unprocessedCritical !== void 0) return failure("unrecognized_critical_extension", `certificate contains unrecognized critical extension ${unprocessedCritical}`, index, detail({
193
- subjectCommonName: current.subject.values.commonName,
194
- actual: unprocessedCritical
195
- }));
196
- if (index === chain.length - 1) continue;
197
- const issuer = chain[index + 1];
198
- if (issuer === void 0) return failure("issuer_not_found", "issuer missing", index);
199
- const signatureResult = await verifyCertificateSignature(current, issuer);
200
- if (!signatureResult.ok) return failure(signatureResult.code, signatureResult.reason, index, detail({
201
- subjectCommonName: current.subject.values.commonName,
202
- issuerCommonName: issuer.subject.values.commonName,
203
- actual: signatureResult.reason
204
- }));
205
- if (!signatureResult.valid) return failure("signature_invalid", "certificate signature does not verify", index, detail({
206
- subjectCommonName: current.subject.values.commonName,
207
- issuerCommonName: issuer.subject.values.commonName
208
- }));
209
- if (issuer.basicConstraints?.ca !== true) return failure("ca_required", "issuer must be a CA certificate", index + 1, detail({ subjectCommonName: issuer.subject.values.commonName }));
210
- if (issuer.keyUsage !== void 0 && !issuer.keyUsage.flags.includes("keyCertSign")) return failure("key_cert_sign_required", "issuer missing keyCertSign", index + 1, detail({ subjectCommonName: issuer.subject.values.commonName }));
211
- if (current.authorityKeyIdentifier !== void 0 && issuer.subjectKeyIdentifier !== void 0 && current.authorityKeyIdentifier !== issuer.subjectKeyIdentifier) return failure("authority_key_identifier_mismatch", "authorityKeyIdentifier does not match issuer subjectKeyIdentifier", index, detail({
212
- subjectCommonName: current.subject.values.commonName,
213
- issuerCommonName: issuer.subject.values.commonName,
214
- expected: issuer.subjectKeyIdentifier,
215
- actual: current.authorityKeyIdentifier
216
- }));
217
- }
218
- for (let index = 1; index < chain.length; index += 1) {
219
- const current = chain[index];
220
- if (current === void 0) return failure("issuer_not_found", "chain element missing", index);
221
- const maxCaBelow = countCaCertificatesBelowParsed(chain, index);
222
- const pathLength = current.basicConstraints?.pathLength;
223
- if (isNonNegativeInteger(pathLength) && maxCaBelow > pathLength) return failure("path_length_exceeded", "path length constraint exceeded", index, detail({
224
- subjectCommonName: current.subject.values.commonName,
225
- expected: String(pathLength),
226
- actual: String(maxCaBelow)
227
- }));
182
+ }
183
+ async function validatePathIssuerAtIndex(e, t, n) {
184
+ if (n === e.length - 1) return;
185
+ let r = e[n + 1];
186
+ return r === void 0 ? failure("issuer_not_found", "issuer missing", n) : await validateIssuerAtPathIndex(t, r, n);
187
+ }
188
+ function validatePathLengthConstraints(e) {
189
+ for (let t = 1; t < e.length; t += 1) {
190
+ let n = e[t];
191
+ if (n === void 0) return failure("issuer_not_found", "chain element missing", t);
192
+ let r = g(e, t), i = n.basicConstraints?.pathLength;
193
+ if (isNonNegativeInteger(i) && r > i) return pathLengthExceededFailure(n, t, i, r);
228
194
  }
229
- const policyResult = evaluatePolicyChain(chain, validationStateResult.value.policy);
230
- if (!policyResult.ok) return failure(policyResult.error.code, policyResult.error.message, 0, detail({
231
- expected: policyResult.error.details?.expected,
232
- actual: policyResult.error.details?.actual
195
+ }
196
+ function pathLengthExceededFailure(e, t, n, r) {
197
+ return failure("path_length_exceeded", "path length constraint exceeded", t, detail({
198
+ subjectCommonName: e.subject.values.commonName,
199
+ expected: String(n),
200
+ actual: String(r)
201
+ }));
202
+ }
203
+ function validatePolicyAndNameConstraints(e, t) {
204
+ let n = p(e, t.policy);
205
+ if (!n.ok) return failure(n.error.code, n.error.message, 0, detail({
206
+ expected: n.error.details?.expected,
207
+ actual: n.error.details?.actual
208
+ }));
209
+ let r = d(e, t.nameConstraints);
210
+ return r.ok ? {
211
+ ok: !0,
212
+ policyValidation: n.value
213
+ } : r;
214
+ }
215
+ function validateCertificateAtPathIndex(e, t, n) {
216
+ if (!v(e, n)) return failure("certificate_expired", "certificate not valid at requested time", t, detail({
217
+ subjectCommonName: e.subject.values.commonName,
218
+ expected: describeDateTime(n),
219
+ actual: `${describeDateTime(e.notBefore)}..${describeDateTime(e.notAfter)}`
220
+ }));
221
+ let r = findUnprocessedCriticalExtension(e);
222
+ if (r !== void 0) return failure("unrecognized_critical_extension", `certificate contains unrecognized critical extension ${r}`, t, detail({
223
+ subjectCommonName: e.subject.values.commonName,
224
+ actual: r
225
+ }));
226
+ }
227
+ async function validateIssuerAtPathIndex(e, t, n) {
228
+ let r = await x(e, t);
229
+ return r.ok ? r.valid ? validateIssuerConstraintsAtPathIndex(e, t, n) : failure("signature_invalid", "certificate signature does not verify", n, detail({
230
+ subjectCommonName: e.subject.values.commonName,
231
+ issuerCommonName: t.subject.values.commonName
232
+ })) : failure(r.code, r.reason, n, detail({
233
+ subjectCommonName: e.subject.values.commonName,
234
+ issuerCommonName: t.subject.values.commonName,
235
+ actual: r.reason
236
+ }));
237
+ }
238
+ function validateIssuerConstraintsAtPathIndex(e, t, n) {
239
+ if (t.basicConstraints?.ca !== !0) return failure("ca_required", "issuer must be a CA certificate", n + 1, detail({ subjectCommonName: t.subject.values.commonName }));
240
+ if (t.keyUsage !== void 0 && !t.keyUsage.flags.includes("keyCertSign")) return failure("key_cert_sign_required", "issuer missing keyCertSign", n + 1, detail({ subjectCommonName: t.subject.values.commonName }));
241
+ if (m(e, t)) return failure("authority_key_identifier_mismatch", "authorityKeyIdentifier does not match issuer subjectKeyIdentifier", n, detail({
242
+ subjectCommonName: e.subject.values.commonName,
243
+ issuerCommonName: t.subject.values.commonName,
244
+ expected: t.subjectKeyIdentifier,
245
+ actual: e.authorityKeyIdentifier
233
246
  }));
234
- const nameConstraintResult = evaluateNameConstraints(chain, validationStateResult.value.nameConstraints);
235
- if (!nameConstraintResult.ok) return nameConstraintResult;
236
- return validateLeaf(leaf, input, policyResult.value);
237
247
  }
238
248
  /**
239
249
  * Validates a pre-built certificate chain for time, constraints, policy, and
240
250
  * optionally leaf purpose. Wrap the result of {@linkcode buildCandidatePath}.
241
251
  */
242
- async function validateCandidatePath(input) {
243
- let normalizedChain;
252
+ async function validateCandidatePath(e) {
253
+ let t;
244
254
  try {
245
- normalizedChain = normalizeValidationChain(input.chain);
246
- } catch (error) {
247
- return verifyFailureResult(failure("signature_invalid", "certificate input is malformed", 0, detail({ actual: error instanceof Error ? error.message : "certificate input is malformed" })));
255
+ t = normalizeValidationChain(e.chain);
256
+ } catch (e) {
257
+ return verifyFailureResult(failure("signature_invalid", "certificate input is malformed", 0, detail({ actual: e instanceof Error ? e.message : "certificate input is malformed" })));
248
258
  }
249
- const result = await validateCandidatePathRaw({
250
- ...input,
251
- chain: normalizedChain
259
+ let n = await validateCandidatePathRaw({
260
+ ...e,
261
+ chain: t
252
262
  });
253
- return result.ok ? validateCandidatePathSuccessResult(result.policyValidation) : verifyFailureResult(result);
263
+ return n.ok ? validateCandidatePathSuccessResult(n.policyValidation) : verifyFailureResult(n);
254
264
  }
255
265
  /**
256
266
  * All-in-one certificate chain verification: builds a candidate path then
@@ -275,56 +285,62 @@ async function validateCandidatePath(input) {
275
285
  * }
276
286
  * ```
277
287
  */
278
- async function verifyCertificateChain(input) {
279
- const buildResult = await buildCandidatePath({
280
- leaf: input.leaf,
281
- roots: input.roots,
282
- ...input.intermediates !== void 0 && { intermediates: input.intermediates },
283
- ...input.trustAnchors !== void 0 && { trustAnchors: input.trustAnchors },
284
- ...input.at !== void 0 && { at: input.at }
288
+ async function verifyCertificateChain(e) {
289
+ let t = await buildCandidatePath({
290
+ leaf: e.leaf,
291
+ roots: e.roots,
292
+ ...e.intermediates !== void 0 && { intermediates: e.intermediates },
293
+ ...e.trustAnchors !== void 0 && { trustAnchors: e.trustAnchors },
294
+ ...e.at !== void 0 && { at: e.at }
285
295
  });
286
- if (!buildResult.ok) return buildResult;
287
- const validateResult = await validateCandidatePath({
288
- chain: buildResult.value.chain,
289
- ...input.at !== void 0 && { at: input.at },
290
- ...input.purpose !== void 0 && { purpose: input.purpose },
291
- ...copyValidationInputs(input),
292
- ...input.allowSelfSignedLeaf !== void 0 && { allowSelfSignedLeaf: input.allowSelfSignedLeaf }
296
+ if (!t.ok) return t;
297
+ let n = await validateCandidatePath({
298
+ chain: t.value.chain,
299
+ ...e.at !== void 0 && { at: e.at },
300
+ ...e.purpose !== void 0 && { purpose: e.purpose },
301
+ ...copyValidationInputs(e),
302
+ ...e.allowSelfSignedLeaf !== void 0 && { allowSelfSignedLeaf: e.allowSelfSignedLeaf }
293
303
  });
294
- if (!validateResult.ok) return validateResult;
295
- if (input.serviceIdentity !== void 0) {
296
- const serviceIdentityResult = validateServiceIdentity(buildResult.value.leaf, input.serviceIdentity);
297
- if (!serviceIdentityResult.ok) return verifyFailureResult(serviceIdentityResult);
304
+ if (!n.ok) return n;
305
+ if (e.serviceIdentity !== void 0) {
306
+ let n = validateServiceIdentity(t.value.leaf, e.serviceIdentity);
307
+ if (!n.ok) return verifyFailureResult(n);
298
308
  }
299
- if (input.revocation !== void 0) {
300
- const revocationResult = await checkChainRevocation({
301
- chain: buildResult.value.chain,
302
- ...input.revocation.crls !== void 0 ? { crls: input.revocation.crls } : {},
303
- ...input.revocation.ocspResponses !== void 0 ? { ocspResponses: input.revocation.ocspResponses } : {},
304
- ...input.revocation.extraCertificates !== void 0 ? { extraCertificates: input.revocation.extraCertificates } : {},
305
- ...input.revocation.trustedOcspResponders !== void 0 ? { trustedOcspResponders: input.revocation.trustedOcspResponders } : {},
306
- ...input.revocation.policy !== void 0 ? { policy: input.revocation.policy } : {},
307
- ...input.at !== void 0 ? { at: input.at } : {}
308
- });
309
- if (revocationResult.value.decision === "deny") {
310
- const firstRevoked = revocationResult.value.summary.revokedCertificates[0];
311
- if (firstRevoked !== void 0) return verifyFailureResult(failure("certificate_revoked", `certificate revoked: ${firstRevoked.subject.values.commonName ?? "unknown"}`, void 0, detail({ subjectCommonName: firstRevoked.subject.values.commonName })));
312
- const firstIndeterminate = revocationResult.value.summary.indeterminateCertificates[0];
313
- const indeterminateReasons = revocationResult.value.certificates.find((c) => c.status === "indeterminate")?.indeterminateReasons;
314
- return verifyFailureResult(failure("revocation_indeterminate", `revocation status indeterminate: ${firstIndeterminate?.subject.values.commonName ?? "unknown"}`, void 0, detail({
315
- subjectCommonName: firstIndeterminate?.subject.values.commonName,
316
- actual: indeterminateReasons?.join(", ")
317
- })));
318
- }
309
+ if (e.revocation !== void 0) {
310
+ let n = await validateVerifiedChainRevocation(e, t.value.chain);
311
+ if (n !== void 0) return n;
319
312
  }
320
313
  return {
321
- ok: true,
314
+ ok: !0,
322
315
  value: {
323
- ...buildResult.value,
324
- policyValidation: validateResult.value.policyValidation
316
+ ...t.value,
317
+ policyValidation: n.value.policyValidation
325
318
  }
326
319
  };
327
320
  }
321
+ /** Applies optional revocation evidence to an otherwise verified certificate chain. */
322
+ async function validateVerifiedChainRevocation(e, t) {
323
+ if (e.revocation === void 0) return;
324
+ let n = await C({
325
+ chain: t,
326
+ ...e.revocation.crls === void 0 ? {} : { crls: e.revocation.crls },
327
+ ...e.revocation.ocspResponses === void 0 ? {} : { ocspResponses: e.revocation.ocspResponses },
328
+ ...e.revocation.extraCertificates === void 0 ? {} : { extraCertificates: e.revocation.extraCertificates },
329
+ ...e.revocation.trustedOcspResponders === void 0 ? {} : { trustedOcspResponders: e.revocation.trustedOcspResponders },
330
+ ...e.revocation.policy === void 0 ? {} : { policy: e.revocation.policy },
331
+ ...e.at === void 0 ? {} : { at: e.at }
332
+ });
333
+ return n.value.decision === "deny" ? revocationFailureResult(n.value) : void 0;
334
+ }
335
+ function revocationFailureResult(e) {
336
+ let t = e.summary.revokedCertificates[0];
337
+ if (t !== void 0) return verifyFailureResult(failure("certificate_revoked", `certificate revoked: ${t.subject.values.commonName ?? "unknown"}`, void 0, detail({ subjectCommonName: t.subject.values.commonName })));
338
+ let n = e.summary.indeterminateCertificates[0], r = e.certificates.find((e) => e.status === "indeterminate")?.indeterminateReasons;
339
+ return verifyFailureResult(failure("revocation_indeterminate", `revocation status indeterminate: ${n?.subject.values.commonName ?? "unknown"}`, void 0, detail({
340
+ subjectCommonName: n?.subject.values.commonName,
341
+ actual: r?.join(", ")
342
+ })));
343
+ }
328
344
  /**
329
345
  * Verifies the self-signature of a PKCS#10 certificate signing request.
330
346
  *
@@ -341,31 +357,29 @@ async function verifyCertificateChain(input) {
341
357
  * }
342
358
  * ```
343
359
  */
344
- async function verifyCertificateSigningRequest(input) {
345
- let parsed;
360
+ async function verifyCertificateSigningRequest(e) {
361
+ let t;
346
362
  try {
347
- parsed = typeof input === "string" ? parseCertificateSigningRequestPemOrThrow(input) : parseCertificateSigningRequestDerOrThrow(new Uint8Array(input));
348
- } catch (error) {
349
- return verifyRequestFailureResult("signature_invalid", "certificate request input is malformed", detail({ actual: error instanceof Error ? error.message : "certificate request input is malformed" }));
363
+ t = typeof e == "string" ? c(e) : s(new Uint8Array(e));
364
+ } catch (e) {
365
+ return verifyRequestFailureResult("signature_invalid", "certificate request input is malformed", detail({ actual: e instanceof Error ? e.message : "certificate request input is malformed" }));
350
366
  }
351
- let signatureResult;
367
+ let n;
352
368
  try {
353
- signatureResult = await verifySignedDataDetailed(parsed.signatureAlgorithmOid, parsed.signatureAlgorithmParametersDer, parsed.publicKeyAlgorithmOid, parsed.publicKeyParametersOid, parsed.subjectPublicKeyInfoDer, parsed.signatureValue, parsed.certificationRequestInfoDer);
354
- } catch (error) {
369
+ n = await l(t.signatureAlgorithmOid, t.signatureAlgorithmParametersDer, t.publicKeyAlgorithmOid, t.publicKeyParametersOid, t.subjectPublicKeyInfoDer, t.signatureValue, t.certificationRequestInfoDer);
370
+ } catch (e) {
355
371
  return verifyRequestFailureResult("signature_invalid", "certificate request input is malformed", detail({
356
- subjectCommonName: parsed.subject.values.commonName,
357
- actual: error instanceof Error ? error.message : "certificate request input is malformed"
372
+ subjectCommonName: t.subject.values.commonName,
373
+ actual: e instanceof Error ? e.message : "certificate request input is malformed"
358
374
  }));
359
375
  }
360
- if (!signatureResult.ok) return verifyRequestFailureResult(signatureResult.code === "verification_error" ? "signature_invalid" : signatureResult.code, signatureResult.reason, detail({
361
- subjectCommonName: parsed.subject.values.commonName,
362
- actual: signatureResult.reason
376
+ return n.ok ? n.valid ? {
377
+ ok: !0,
378
+ value: t
379
+ } : verifyRequestFailureResult("signature_invalid", "certificate request signature does not verify", detail({ subjectCommonName: t.subject.values.commonName })) : verifyRequestFailureResult(n.code === "verification_error" ? "signature_invalid" : n.code, n.reason, detail({
380
+ subjectCommonName: t.subject.values.commonName,
381
+ actual: n.reason
363
382
  }));
364
- if (!signatureResult.valid) return verifyRequestFailureResult("signature_invalid", "certificate request signature does not verify", detail({ subjectCommonName: parsed.subject.values.commonName }));
365
- return {
366
- ok: true,
367
- value: parsed
368
- };
369
383
  }
370
384
  /**
371
385
  * Standalone EKU check against a verified certificate chain.
@@ -382,51 +396,50 @@ async function verifyCertificateSigningRequest(input) {
382
396
  * }
383
397
  * ```
384
398
  */
385
- function checkExtendedKeyUsage(chain, purpose) {
386
- let normalizedChain;
399
+ function checkExtendedKeyUsage(e, t) {
400
+ let n;
387
401
  try {
388
- normalizedChain = normalizeValidationChain(chain);
402
+ n = normalizeValidationChain(e);
389
403
  } catch {
390
404
  return ekuCheckFailureResult("leaf_eku_missing", "certificate input is malformed", 0);
391
405
  }
392
- const leaf = normalizedChain[0];
393
- if (leaf === void 0) return ekuCheckFailureResult("leaf_eku_missing", "chain is empty", 0);
394
- if (leaf.extendedKeyUsage !== void 0 && !leaf.extendedKeyUsage.includes(purpose)) return ekuCheckFailureResult("leaf_eku_missing", `leaf certificate does not include EKU ${purpose}`, 0);
395
- for (let index = 1; index < normalizedChain.length; index += 1) {
396
- const intermediate = normalizedChain[index];
397
- if (intermediate === void 0) continue;
398
- if (intermediate.extendedKeyUsage !== void 0 && !intermediate.extendedKeyUsage.includes(purpose)) return ekuCheckFailureResult("intermediate_eku_constraint", `intermediate CA at index ${String(index)} constrains EKU and does not include ${purpose}`, index);
406
+ let r = n[0];
407
+ if (r === void 0) return ekuCheckFailureResult("leaf_eku_missing", "chain is empty", 0);
408
+ if (r.extendedKeyUsage !== void 0 && !r.extendedKeyUsage.includes(t)) return ekuCheckFailureResult("leaf_eku_missing", `leaf certificate does not include EKU ${t}`, 0);
409
+ for (let e = 1; e < n.length; e += 1) {
410
+ let r = n[e];
411
+ if (r !== void 0 && r.extendedKeyUsage !== void 0 && !r.extendedKeyUsage.includes(t)) return ekuCheckFailureResult("intermediate_eku_constraint", `intermediate CA at index ${String(e)} constrains EKU and does not include ${t}`, e);
399
412
  }
400
413
  return {
401
- ok: true,
414
+ ok: !0,
402
415
  value: void 0
403
416
  };
404
417
  }
405
418
  /** Extracts a {@linkcode TrustAnchor} from a parsed certificate, copying the subject, SPKI, and key identifiers. */
406
- function trustAnchorFromCertificate(certificate) {
407
- let normalizedCertificate;
419
+ function trustAnchorFromCertificate(e) {
420
+ let t;
408
421
  try {
409
- normalizedCertificate = reparseCertificateForTrust(certificate);
422
+ t = reparseCertificateForTrust(e);
410
423
  } catch {
411
- throw new Error("certificate input is malformed");
424
+ throw Error("certificate input is malformed");
412
425
  }
413
426
  return {
414
- subject: normalizedCertificate.subject,
415
- subjectPublicKeyInfoDer: normalizedCertificate.subjectPublicKeyInfoDer,
416
- publicKeyAlgorithmOid: normalizedCertificate.publicKeyAlgorithmOid,
417
- ...normalizedCertificate.publicKeyParametersOid === void 0 ? {} : { publicKeyParametersOid: normalizedCertificate.publicKeyParametersOid },
418
- ...normalizedCertificate.subjectKeyIdentifier === void 0 ? {} : { subjectKeyIdentifier: normalizedCertificate.subjectKeyIdentifier }
427
+ subject: t.subject,
428
+ subjectPublicKeyInfoDer: t.subjectPublicKeyInfoDer,
429
+ publicKeyAlgorithmOid: t.publicKeyAlgorithmOid,
430
+ ...t.publicKeyParametersOid === void 0 ? {} : { publicKeyParametersOid: t.publicKeyParametersOid },
431
+ ...t.subjectKeyIdentifier === void 0 ? {} : { subjectKeyIdentifier: t.subjectKeyIdentifier }
419
432
  };
420
433
  }
421
434
  /** Extracts defined optional fields from a base input for safe forwarding. */
422
- function baseChainInput(input) {
435
+ function baseChainInput(e) {
423
436
  return {
424
- leaf: input.leaf,
425
- roots: input.roots,
426
- ...input.intermediates !== void 0 && { intermediates: input.intermediates },
427
- ...input.trustAnchors !== void 0 && { trustAnchors: input.trustAnchors },
428
- ...input.at !== void 0 && { at: input.at },
429
- ...copyValidationInputs(input)
437
+ leaf: e.leaf,
438
+ roots: e.roots,
439
+ ...e.intermediates !== void 0 && { intermediates: e.intermediates },
440
+ ...e.trustAnchors !== void 0 && { trustAnchors: e.trustAnchors },
441
+ ...e.at !== void 0 && { at: e.at },
442
+ ...copyValidationInputs(e)
430
443
  };
431
444
  }
432
445
  /**
@@ -448,14 +461,14 @@ function baseChainInput(input) {
448
461
  * }
449
462
  * ```
450
463
  */
451
- async function validateForTlsServer(input) {
452
- const result = await verifyChainForExtendedKeyUsageProfile(input, "serverAuth");
453
- if (!result.ok) return result;
454
- if (input.serviceIdentity !== void 0) {
455
- const serviceIdentityResult = validateServiceIdentity(result.value.leaf, input.serviceIdentity);
456
- if (!serviceIdentityResult.ok) return verifyFailureResult(serviceIdentityResult);
464
+ async function validateForTlsServer(e) {
465
+ let t = await verifyChainForExtendedKeyUsageProfile(e, "serverAuth");
466
+ if (!t.ok) return t;
467
+ if (e.serviceIdentity !== void 0) {
468
+ let n = validateServiceIdentity(t.value.leaf, e.serviceIdentity);
469
+ if (!n.ok) return verifyFailureResult(n);
457
470
  }
458
- return result;
471
+ return t;
459
472
  }
460
473
  /**
461
474
  * Validates a certificate chain for TLS client use:
@@ -471,8 +484,8 @@ async function validateForTlsServer(input) {
471
484
  * });
472
485
  * ```
473
486
  */
474
- function validateForTlsClient(input) {
475
- return verifyChainForExtendedKeyUsageProfile(input, "clientAuth");
487
+ function validateForTlsClient(e) {
488
+ return verifyChainForExtendedKeyUsageProfile(e, "clientAuth");
476
489
  }
477
490
  /**
478
491
  * Validates a certificate chain for code signing:
@@ -488,8 +501,8 @@ function validateForTlsClient(input) {
488
501
  * });
489
502
  * ```
490
503
  */
491
- function validateForCodeSigning(input) {
492
- return verifyChainForExtendedKeyUsageProfile(input, "codeSigning");
504
+ function validateForCodeSigning(e) {
505
+ return verifyChainForExtendedKeyUsageProfile(e, "codeSigning");
493
506
  }
494
507
  /**
495
508
  * Validates a certificate chain for CA use:
@@ -505,260 +518,251 @@ function validateForCodeSigning(input) {
505
518
  * });
506
519
  * ```
507
520
  */
508
- function validateForCa(input) {
521
+ function validateForCa(e) {
509
522
  return verifyCertificateChain({
510
- ...baseChainInput(input),
523
+ ...baseChainInput(e),
511
524
  purpose: "ca"
512
525
  });
513
526
  }
514
527
  /** Enforces purpose-specific constraints on the leaf certificate (CA flag or EKU). */
515
- function validateLeaf(leaf, input, policyValidation) {
516
- const purpose = input.purpose;
517
- if (purpose !== void 0) {
518
- if (purpose === "ca") {
519
- if (leaf.basicConstraints?.ca !== true) return failure("ca_required", "leaf is not a CA certificate", 0, detail({ subjectCommonName: leaf.subject.values.commonName }));
520
- } else if (leaf.extendedKeyUsage !== void 0 && !leaf.extendedKeyUsage.includes(purpose)) return failure("extended_key_usage_invalid", `leaf missing EKU ${purpose}`, 0, detail({
521
- subjectCommonName: leaf.subject.values.commonName,
522
- expected: purpose,
523
- actual: leaf.extendedKeyUsage.map(formatEku).join(",")
528
+ function validateLeaf(e, t, n) {
529
+ let r = t.purpose;
530
+ if (r !== void 0) {
531
+ if (r === "ca") {
532
+ if (e.basicConstraints?.ca !== !0) return failure("ca_required", "leaf is not a CA certificate", 0, detail({ subjectCommonName: e.subject.values.commonName }));
533
+ } else if (e.extendedKeyUsage !== void 0 && !e.extendedKeyUsage.includes(r)) return failure("extended_key_usage_invalid", `leaf missing EKU ${r}`, 0, detail({
534
+ subjectCommonName: e.subject.values.commonName,
535
+ expected: r,
536
+ actual: e.extendedKeyUsage.map(formatEku).join(",")
524
537
  }));
525
538
  }
526
539
  return {
527
- ok: true,
528
- policyValidation
540
+ ok: !0,
541
+ policyValidation: n
529
542
  };
530
543
  }
531
544
  /** Matches the leaf's SAN against the requested service identity. */
532
- function validateServiceIdentity(leaf, serviceIdentity) {
533
- const malformedInput = validateServiceIdentityInput(serviceIdentity);
534
- if (!malformedInput.ok) return malformedInput;
535
- const result = matchServiceIdentity({
536
- certificate: reparseCertificateForTrust(leaf),
537
- serviceIdentity
545
+ function validateServiceIdentity(e, t) {
546
+ let n = validateServiceIdentityInput(t);
547
+ if (!n.ok) return n;
548
+ let r = S({
549
+ certificate: reparseCertificateForTrust(e),
550
+ serviceIdentity: t
538
551
  });
539
- if (result.ok) return { ok: true };
540
- const error = result.error;
541
- if (error.code === "service_identity_mismatch") return {
542
- ok: false,
552
+ if (r.ok) return { ok: !0 };
553
+ let i = r.error;
554
+ return i.code === "service_identity_mismatch" ? {
555
+ ok: !1,
543
556
  code: "subject_alt_name_mismatch",
544
- message: error.message,
557
+ message: i.message,
545
558
  index: 0,
546
- ...error.details === void 0 ? {} : { details: error.details }
547
- };
548
- if (error.code !== "subject_alt_name_mismatch" && error.code !== "common_name_fallback_suppressed") return failure("subject_alt_name_mismatch", "service identity input is malformed", 0, detail({
549
- expected: serviceIdentity.value,
550
- actual: error.code
551
- }));
552
- return {
553
- ok: false,
554
- code: error.code,
555
- message: error.message,
559
+ ...i.details === void 0 ? {} : { details: i.details }
560
+ } : i.code !== "subject_alt_name_mismatch" && i.code !== "common_name_fallback_suppressed" ? failure("subject_alt_name_mismatch", "service identity input is malformed", 0, detail({
561
+ expected: t.value,
562
+ actual: i.code
563
+ })) : {
564
+ ok: !1,
565
+ code: i.code,
566
+ message: i.message,
556
567
  index: 0,
557
- ...error.details === void 0 ? {} : { details: error.details }
568
+ ...i.details === void 0 ? {} : { details: i.details }
558
569
  };
559
570
  }
560
- function validateServiceIdentityInput(serviceIdentity) {
561
- if (!isRecord(serviceIdentity)) return failure("subject_alt_name_mismatch", "service identity input is malformed", 0);
562
- if (serviceIdentity.type !== "dns" && serviceIdentity.type !== "ip" && serviceIdentity.type !== "uri" && serviceIdentity.type !== "srv") return failure("subject_alt_name_mismatch", "service identity input is malformed", 0, detail({ actual: String(serviceIdentity.type) }));
563
- if (typeof serviceIdentity.value !== "string") return failure("subject_alt_name_mismatch", "service identity input is malformed", 0, detail({ actual: serviceIdentity.type }));
564
- if (serviceIdentity.type === "ip") try {
565
- parseIpAddressToBytes(serviceIdentity.value);
571
+ function validateServiceIdentityInput(e) {
572
+ if (!isRecord(e)) return failure("subject_alt_name_mismatch", "service identity input is malformed", 0);
573
+ if (e.type !== "dns" && e.type !== "ip" && e.type !== "uri" && e.type !== "srv") return failure("subject_alt_name_mismatch", "service identity input is malformed", 0, detail({ actual: String(e.type) }));
574
+ if (typeof e.value != "string") return failure("subject_alt_name_mismatch", "service identity input is malformed", 0, detail({ actual: e.type }));
575
+ if (e.type === "ip") try {
576
+ a(e.value);
566
577
  } catch {
567
578
  return failure("subject_alt_name_mismatch", "service identity input is malformed", 0, detail({
568
- expected: serviceIdentity.value,
579
+ expected: e.value,
569
580
  actual: "ip"
570
581
  }));
571
582
  }
572
- return { ok: true };
583
+ return { ok: !0 };
573
584
  }
574
585
  /** Applies an EKU check to a successfully verified chain and maps failures to verify error codes. */
575
- function applyEkuCheck(result, purpose) {
576
- const ekuCheck = checkExtendedKeyUsage(result.value.chain, purpose);
577
- if (!ekuCheck.ok) return verifyFailureResult(failure(ekuCheck.code === "leaf_eku_missing" ? "extended_key_usage_invalid" : "intermediate_eku_constraint", ekuCheck.message, ekuCheck.index));
578
- return result;
586
+ function applyEkuCheck(e, t) {
587
+ let n = checkExtendedKeyUsage(e.value.chain, t);
588
+ return n.ok ? e : verifyFailureResult(failure(n.code === "leaf_eku_missing" ? "extended_key_usage_invalid" : "intermediate_eku_constraint", n.message, n.index));
579
589
  }
580
590
  /** Verifies a chain then checks that all certificates permit the given EKU purpose. */
581
- async function verifyChainForExtendedKeyUsageProfile(input, purpose) {
582
- const result = await verifyCertificateChain(baseChainInput(input));
583
- if (!result.ok) return result;
584
- return applyEkuCheck(result, purpose);
591
+ async function verifyChainForExtendedKeyUsageProfile(e, t) {
592
+ let n = await verifyCertificateChain(baseChainInput(e));
593
+ return n.ok ? applyEkuCheck(n, t) : n;
585
594
  }
586
595
  /** Returns the OID of the first critical extension not in {@linkcode PROCESSED_EXTENSION_OIDS}, or `undefined`. */
587
- function findUnprocessedCriticalExtension(certificate) {
588
- for (const extension of certificate.extensions) if (extension.critical && !PROCESSED_EXTENSION_OIDS.has(extension.oid)) return extension.oid;
596
+ function findUnprocessedCriticalExtension(e) {
597
+ for (let t of e.extensions) if (t.critical && !T.has(t.oid)) return t.oid;
589
598
  }
590
599
  /** Constructs a {@linkcode VerifyChainFailure} with the given code, message, optional chain index, and details. */
591
- function failure(code, message, index, details) {
600
+ function failure(e, t, n, i) {
592
601
  return {
593
- ok: false,
594
- ...indexedMicro509Error(code, message, index, details)
602
+ ok: !1,
603
+ ...r(e, t, n, i)
595
604
  };
596
605
  }
597
606
  /** Wraps a {@linkcode VerifyChainFailure} into the standard indexed error result shape. */
598
- function verifyFailureResult(error) {
599
- return indexedErrorResult(error);
607
+ function verifyFailureResult(e) {
608
+ return n(e);
600
609
  }
601
610
  /** Wraps a policy outcome into the validate-candidate-path success result shape. */
602
- function validateCandidatePathSuccessResult(policyValidation) {
611
+ function validateCandidatePathSuccessResult(e) {
603
612
  return {
604
- ok: true,
605
- value: { policyValidation }
613
+ ok: !0,
614
+ value: { policyValidation: e }
606
615
  };
607
616
  }
608
617
  /** Describes a date in ISO format, or `'<invalid date>'` if invalid. */
609
- function describeDateTime(value) {
610
- return Number.isNaN(value.getTime()) ? "<invalid date>" : value.toISOString();
618
+ function describeDateTime(e) {
619
+ return Number.isNaN(e.getTime()) ? "<invalid date>" : e.toISOString();
611
620
  }
612
- function normalizeValidationChain(chain) {
613
- return chain.map(reparseCertificateForTrust);
621
+ function normalizeValidationChain(e) {
622
+ return e.map(reparseCertificateForTrust);
614
623
  }
615
- function reparseCertificateForTrust(certificate) {
616
- return parseCertificateDerOrThrow(new Uint8Array(certificate.der));
624
+ function reparseCertificateForTrust(e) {
625
+ return o(new Uint8Array(e.der));
617
626
  }
618
627
  /** Returns `true` if the value is a non-negative integer (including zero). */
619
- function isNonNegativeInteger(value) {
620
- return value !== void 0 && Number.isInteger(value) && value >= 0;
628
+ function isNonNegativeInteger(e) {
629
+ return e !== void 0 && Number.isInteger(e) && e >= 0;
621
630
  }
622
631
  /** Constructs a CSR verification failure result. */
623
- function verifyRequestFailureResult(code, message, details) {
624
- return errorResult({
625
- ok: false,
626
- ...micro509Error(code, message, details)
632
+ function verifyRequestFailureResult(e, n, r) {
633
+ return t({
634
+ ok: !1,
635
+ ...i(e, n, r)
627
636
  });
628
637
  }
629
638
  /** Constructs an EKU check failure result at the given chain index. */
630
- function ekuCheckFailureResult(code, message, index) {
631
- return indexedErrorResult({
632
- ok: false,
633
- ...indexedMicro509Error(code, message, index),
634
- index
639
+ function ekuCheckFailureResult(e, t, i) {
640
+ return n({
641
+ ok: !1,
642
+ ...r(e, t, i),
643
+ index: i
635
644
  });
636
645
  }
637
646
  /** Merges flat and nested policy fields, with nested taking precedence. */
638
- function resolvePolicyValidationInput(input) {
639
- const flatInitialPolicySet = normalizeInitialPolicySet(input.initialPolicySet);
640
- const nestedInitialPolicySet = normalizeInitialPolicySet(input.policy?.initialPolicySet);
647
+ function resolvePolicyValidationInput(e) {
648
+ let t = normalizeInitialPolicySet(e.initialPolicySet), n = normalizeInitialPolicySet(e.policy?.initialPolicySet);
641
649
  return {
642
- ...flatInitialPolicySet === void 0 ? {} : { initialPolicySet: flatInitialPolicySet },
643
- ...input.requireExplicitPolicy === void 0 ? {} : { requireExplicitPolicy: input.requireExplicitPolicy },
644
- ...input.inhibitPolicyMapping === void 0 ? {} : { inhibitPolicyMapping: input.inhibitPolicyMapping },
645
- ...input.inhibitAnyPolicy === void 0 ? {} : { inhibitAnyPolicy: input.inhibitAnyPolicy },
646
- ...nestedInitialPolicySet === void 0 ? {} : { initialPolicySet: nestedInitialPolicySet },
647
- ...input.policy?.requireExplicitPolicy === void 0 ? {} : { requireExplicitPolicy: input.policy.requireExplicitPolicy },
648
- ...input.policy?.inhibitPolicyMapping === void 0 ? {} : { inhibitPolicyMapping: input.policy.inhibitPolicyMapping },
649
- ...input.policy?.inhibitAnyPolicy === void 0 ? {} : { inhibitAnyPolicy: input.policy.inhibitAnyPolicy }
650
+ ...t === void 0 ? {} : { initialPolicySet: t },
651
+ ...e.requireExplicitPolicy === void 0 ? {} : { requireExplicitPolicy: e.requireExplicitPolicy },
652
+ ...e.inhibitPolicyMapping === void 0 ? {} : { inhibitPolicyMapping: e.inhibitPolicyMapping },
653
+ ...e.inhibitAnyPolicy === void 0 ? {} : { inhibitAnyPolicy: e.inhibitAnyPolicy },
654
+ ...n === void 0 ? {} : { initialPolicySet: n },
655
+ ...e.policy?.requireExplicitPolicy === void 0 ? {} : { requireExplicitPolicy: e.policy.requireExplicitPolicy },
656
+ ...e.policy?.inhibitPolicyMapping === void 0 ? {} : { inhibitPolicyMapping: e.policy.inhibitPolicyMapping },
657
+ ...e.policy?.inhibitAnyPolicy === void 0 ? {} : { inhibitAnyPolicy: e.policy.inhibitAnyPolicy }
650
658
  };
651
659
  }
652
660
  /** Merges flat and nested name-constraint fields, with nested taking precedence. */
653
- function resolveInitialNameConstraintsInput(input) {
661
+ function resolveInitialNameConstraintsInput(e) {
654
662
  return {
655
- ...input.permittedSubtrees === void 0 ? {} : { permittedSubtrees: input.permittedSubtrees },
656
- ...input.excludedSubtrees === void 0 ? {} : { excludedSubtrees: input.excludedSubtrees },
657
- ...input.nameConstraints?.permittedSubtrees === void 0 ? {} : { permittedSubtrees: input.nameConstraints.permittedSubtrees },
658
- ...input.nameConstraints?.excludedSubtrees === void 0 ? {} : { excludedSubtrees: input.nameConstraints.excludedSubtrees }
663
+ ...e.permittedSubtrees === void 0 ? {} : { permittedSubtrees: e.permittedSubtrees },
664
+ ...e.excludedSubtrees === void 0 ? {} : { excludedSubtrees: e.excludedSubtrees },
665
+ ...e.nameConstraints?.permittedSubtrees === void 0 ? {} : { permittedSubtrees: e.nameConstraints.permittedSubtrees },
666
+ ...e.nameConstraints?.excludedSubtrees === void 0 ? {} : { excludedSubtrees: e.nameConstraints.excludedSubtrees }
659
667
  };
660
668
  }
661
669
  /** Extracts the resolved policy and name-constraint inputs for forwarding. */
662
- function copyValidationInputs(input) {
663
- const policy = resolvePolicyValidationInput(input);
664
- const nameConstraints = resolveInitialNameConstraintsInput(input);
670
+ function copyValidationInputs(e) {
671
+ let t = resolvePolicyValidationInput(e), n = resolveInitialNameConstraintsInput(e);
665
672
  return {
666
- ...hasPolicyValidationInput(policy) ? { policy } : {},
667
- ...hasInitialNameConstraintsInput(nameConstraints) ? { nameConstraints } : {}
673
+ ...hasPolicyValidationInput(t) ? { policy: t } : {},
674
+ ...hasInitialNameConstraintsInput(n) ? { nameConstraints: n } : {}
668
675
  };
669
676
  }
670
677
  /** Returns `true` if any policy validation field is defined. */
671
- function hasPolicyValidationInput(input) {
672
- return input.initialPolicySet !== void 0 || input.requireExplicitPolicy !== void 0 || input.inhibitPolicyMapping !== void 0 || input.inhibitAnyPolicy !== void 0;
678
+ function hasPolicyValidationInput(e) {
679
+ return e.initialPolicySet !== void 0 || e.requireExplicitPolicy !== void 0 || e.inhibitPolicyMapping !== void 0 || e.inhibitAnyPolicy !== void 0;
673
680
  }
674
681
  /** Returns `true` if any initial name constraint field is defined. */
675
- function hasInitialNameConstraintsInput(input) {
676
- return input.permittedSubtrees !== void 0 || input.excludedSubtrees !== void 0;
682
+ function hasInitialNameConstraintsInput(e) {
683
+ return e.permittedSubtrees !== void 0 || e.excludedSubtrees !== void 0;
677
684
  }
678
685
  /** Constructs failure details with subject/issuer CNs and full chain CN list. */
679
- function buildFailureDetails(chain, index) {
680
- const certificate = chain[index];
686
+ function buildFailureDetails(e, t) {
687
+ let n = e[t];
681
688
  return detail({
682
- subjectCommonName: certificate?.subject.values.commonName,
683
- issuerCommonName: certificate?.issuer.values.commonName,
684
- chainCommonNames: chain.map((entry) => entry.subject.values.commonName ?? "<unnamed>")
689
+ subjectCommonName: n?.subject.values.commonName,
690
+ issuerCommonName: n?.issuer.values.commonName,
691
+ chainCommonNames: e.map((e) => e.subject.values.commonName ?? "<unnamed>")
685
692
  });
686
693
  }
687
694
  /** Formats an EKU value as a human-readable string (name or raw OID). */
688
- function formatEku(value) {
689
- return typeof value === "string" ? value : value.value;
695
+ function formatEku(e) {
696
+ return typeof e == "string" ? e : e.value;
690
697
  }
691
698
  /** Strips `undefined` values from a loose input to produce a clean {@linkcode VerifyFailureDetails}. */
692
- function detail(input) {
699
+ function detail(e) {
693
700
  return {
694
- ...input.subjectCommonName === void 0 ? {} : { subjectCommonName: input.subjectCommonName },
695
- ...input.issuerCommonName === void 0 ? {} : { issuerCommonName: input.issuerCommonName },
696
- ...input.expected === void 0 ? {} : { expected: input.expected },
697
- ...input.actual === void 0 ? {} : { actual: input.actual },
698
- ...input.chainCommonNames === void 0 ? {} : { chainCommonNames: input.chainCommonNames },
699
- ...input.presentedIdentifierTypes === void 0 ? {} : { presentedIdentifierTypes: input.presentedIdentifierTypes },
700
- ...input.commonNameFallbackReason === void 0 ? {} : { commonNameFallbackReason: input.commonNameFallbackReason }
701
+ ...e.subjectCommonName === void 0 ? {} : { subjectCommonName: e.subjectCommonName },
702
+ ...e.issuerCommonName === void 0 ? {} : { issuerCommonName: e.issuerCommonName },
703
+ ...e.expected === void 0 ? {} : { expected: e.expected },
704
+ ...e.actual === void 0 ? {} : { actual: e.actual },
705
+ ...e.chainCommonNames === void 0 ? {} : { chainCommonNames: e.chainCommonNames },
706
+ ...e.presentedIdentifierTypes === void 0 ? {} : { presentedIdentifierTypes: e.presentedIdentifierTypes },
707
+ ...e.commonNameFallbackReason === void 0 ? {} : { commonNameFallbackReason: e.commonNameFallbackReason }
701
708
  };
702
709
  }
703
710
  /** Initializes policy and name-constraint validation state for a chain walk. */
704
- function buildValidationState(input, chainLength) {
705
- const policy = createPolicyValidationState(resolvePolicyValidationInput(input), chainLength);
706
- const initialNameConstraintsValidation = validateInitialNameConstraintsInput(resolveInitialNameConstraintsInput(input));
707
- if (!initialNameConstraintsValidation.ok) return initialNameConstraintsValidation;
708
- return {
709
- ok: true,
711
+ function buildValidationState(e, t) {
712
+ let n = f(resolvePolicyValidationInput(e), t), r = validateInitialNameConstraintsInput(resolveInitialNameConstraintsInput(e));
713
+ return r.ok ? {
714
+ ok: !0,
710
715
  value: {
711
- policy,
712
- nameConstraints: createNameConstraintValidationState(initialNameConstraintsValidation.value)
716
+ policy: n,
717
+ nameConstraints: u(r.value)
713
718
  }
714
- };
715
- }
716
- function normalizeInitialPolicySet(initialPolicySet) {
717
- if (initialPolicySet === void 0 || initialPolicySet === "any") return initialPolicySet;
718
- if (!Array.isArray(initialPolicySet)) return [];
719
- return initialPolicySet.every((policyIdentifier) => typeof policyIdentifier === "string") ? initialPolicySet : [];
720
- }
721
- function validateInitialNameConstraintsInput(input) {
722
- const permittedValidation = validateInitialNameConstraintSubtrees(input.permittedSubtrees, "permittedSubtrees");
723
- if (!permittedValidation.ok) return permittedValidation;
724
- const excludedValidation = validateInitialNameConstraintSubtrees(input.excludedSubtrees, "excludedSubtrees");
725
- if (!excludedValidation.ok) return excludedValidation;
726
- return {
727
- ok: true,
728
- value: input
729
- };
730
- }
731
- function validateInitialNameConstraintSubtrees(subtrees, label) {
732
- if (subtrees === void 0) return { ok: true };
733
- if (!Array.isArray(subtrees)) return invalidInitialNameConstraintsFailure(label);
734
- for (const subtree of subtrees) {
735
- const invalidForm = describeInvalidInitialNameConstraintForm(subtree);
736
- if (invalidForm !== void 0) return invalidInitialNameConstraintsFailure(invalidForm);
719
+ } : r;
720
+ }
721
+ function normalizeInitialPolicySet(e) {
722
+ if (e !== void 0) return e === "any" || Array.isArray(e) && e.every((e) => typeof e == "string") ? e : [];
723
+ }
724
+ function validateInitialNameConstraintsInput(e) {
725
+ let t = validateInitialNameConstraintSubtrees(e.permittedSubtrees, "permittedSubtrees");
726
+ if (!t.ok) return t;
727
+ let n = validateInitialNameConstraintSubtrees(e.excludedSubtrees, "excludedSubtrees");
728
+ return n.ok ? {
729
+ ok: !0,
730
+ value: e
731
+ } : n;
732
+ }
733
+ function validateInitialNameConstraintSubtrees(e, t) {
734
+ if (e === void 0) return { ok: !0 };
735
+ if (!Array.isArray(e)) return invalidInitialNameConstraintsFailure(t);
736
+ for (let t of e) {
737
+ let e = describeInvalidInitialNameConstraintForm(t);
738
+ if (e !== void 0) return invalidInitialNameConstraintsFailure(e);
737
739
  }
738
- return { ok: true };
740
+ return { ok: !0 };
739
741
  }
740
- function describeInvalidInitialNameConstraintForm(subtree) {
741
- if (!isRecord(subtree)) return "invalid subtree";
742
- const base = subtree.base;
743
- if (!isRecord(base) || typeof base.type !== "string") return "invalid subtree";
744
- switch (base.type) {
742
+ function describeInvalidInitialNameConstraintForm(e) {
743
+ if (!isRecord(e)) return "invalid subtree";
744
+ let t = e.base;
745
+ if (!isRecord(t) || typeof t.type != "string") return "invalid subtree";
746
+ switch (t.type) {
745
747
  case "dns":
746
748
  case "email":
747
- case "uri": return typeof base.value === "string" ? void 0 : base.type;
748
- case "directoryName": return typeof base.derHex === "string" ? void 0 : base.type;
749
- case "ip": return base.addressBytes instanceof Uint8Array && base.maskBytes instanceof Uint8Array ? void 0 : base.type;
749
+ case "uri": return typeof t.value == "string" ? void 0 : t.type;
750
+ case "directoryName": return typeof t.derHex == "string" ? void 0 : t.type;
751
+ case "ip": return t.addressBytes instanceof Uint8Array && t.maskBytes instanceof Uint8Array ? void 0 : t.type;
750
752
  case "otherName":
751
753
  case "x400Address":
752
754
  case "ediPartyName":
753
- case "registeredID": return base.type;
754
- default: return base.type;
755
+ case "registeredID": return t.type;
756
+ default: return t.type;
755
757
  }
756
758
  }
757
- function invalidInitialNameConstraintsFailure(actual) {
758
- return failure("unsupported_initial_name_constraints", "initial name constraints use unsupported or malformed forms", void 0, detail({ actual }));
759
+ function invalidInitialNameConstraintsFailure(e) {
760
+ return failure("unsupported_initial_name_constraints", "initial name constraints use unsupported or malformed forms", void 0, detail({ actual: e }));
759
761
  }
760
- function isRecord(value) {
761
- return typeof value === "object" && value !== null;
762
+ function isRecord(e) {
763
+ return typeof e == "object" && !!e;
762
764
  }
763
765
  //#endregion
764
- export { VERIFY_ERROR_CODES, buildCandidatePath, checkExtendedKeyUsage, trustAnchorFromCertificate, validateCandidatePath, validateForCa, validateForCodeSigning, validateForTlsClient, validateForTlsServer, verifyCertificateChain, verifyCertificateSigningRequest };
766
+ export { w as VERIFY_ERROR_CODES, buildCandidatePath, checkExtendedKeyUsage, trustAnchorFromCertificate, validateCandidatePath, validateForCa, validateForCodeSigning, validateForTlsClient, validateForTlsServer, verifyCertificateChain, verifyCertificateSigningRequest };
767
+
768
+ //# sourceMappingURL=verify.js.map