micro509 0.17.1 → 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 (183) hide show
  1. package/CHANGELOG.md +165 -6
  2. package/dist/crypto/crypto.d.ts +12 -4
  3. package/dist/crypto/crypto.js +30 -17
  4. package/dist/crypto/crypto.js.map +1 -1
  5. package/dist/crypto.d.ts +8 -2
  6. package/dist/der/der.d.ts +14 -4
  7. package/dist/der/der.js +19 -19
  8. package/dist/der/der.js.map +1 -1
  9. package/dist/der.d.ts +26 -2
  10. package/dist/der.js +4 -4
  11. package/dist/index.d.ts +84 -16
  12. package/dist/index.js +19 -19
  13. package/dist/internal/asn1/asn1.d.ts +1 -2
  14. package/dist/internal/asn1/asn1.js +10 -2
  15. package/dist/internal/asn1/asn1.js.map +1 -1
  16. package/dist/internal/asn1/ber.js.map +1 -1
  17. package/dist/internal/asn1/decode-refusal.js.map +1 -1
  18. package/dist/internal/asn1/der.d.ts +1 -2
  19. package/dist/internal/asn1/der.js.map +1 -1
  20. package/dist/internal/asn1/oids.js +71 -353
  21. package/dist/internal/asn1/oids.js.map +1 -1
  22. package/dist/internal/asn1/oids.json.js +357 -0
  23. package/dist/internal/asn1/oids.json.js.map +1 -0
  24. package/dist/internal/crypto/algorithm-names.js +1 -1
  25. package/dist/internal/crypto/algorithm-names.js.map +1 -1
  26. package/dist/internal/crypto/ecdsa.js.map +1 -1
  27. package/dist/internal/crypto/hash.js.map +1 -1
  28. package/dist/internal/crypto/pbes2.d.ts +1 -2
  29. package/dist/internal/crypto/pbes2.js +70 -70
  30. package/dist/internal/crypto/pbes2.js.map +1 -1
  31. package/dist/internal/crypto/prime-ec.js +37 -0
  32. package/dist/internal/crypto/prime-ec.js.map +1 -0
  33. package/dist/internal/crypto/rsa-pss.js +50 -50
  34. package/dist/internal/crypto/rsa-pss.js.map +1 -1
  35. package/dist/internal/crypto/sig-verify.d.ts +41 -2
  36. package/dist/internal/crypto/sig-verify.js +125 -38
  37. package/dist/internal/crypto/sig-verify.js.map +1 -1
  38. package/dist/internal/crypto/signing.d.ts +1 -2
  39. package/dist/internal/crypto/signing.js +26 -26
  40. package/dist/internal/crypto/signing.js.map +1 -1
  41. package/dist/internal/jose/base64url.js.map +1 -1
  42. package/dist/internal/jose/json-data.js +108 -0
  43. package/dist/internal/jose/json-data.js.map +1 -0
  44. package/dist/internal/jose/strict-json.d.ts +1 -2
  45. package/dist/internal/jose/strict-json.js.map +1 -1
  46. package/dist/internal/shared/base64.js.map +1 -1
  47. package/dist/internal/shared/dn.d.ts +1 -2
  48. package/dist/internal/shared/dn.js +1 -1
  49. package/dist/internal/shared/dn.js.map +1 -1
  50. package/dist/internal/shared/idna.js.map +1 -1
  51. package/dist/internal/shared/ip.d.ts +1 -2
  52. package/dist/internal/shared/ip.js.map +1 -1
  53. package/dist/internal/shared/mailbox.js.map +1 -1
  54. package/dist/internal/shared/punycode.js.map +1 -1
  55. package/dist/internal/shared/uri-host.js.map +1 -1
  56. package/dist/internal/verify/name-constraints-engine.js +64 -64
  57. package/dist/internal/verify/name-constraints-engine.js.map +1 -1
  58. package/dist/internal/verify/policy-engine.js +1 -1
  59. package/dist/internal/verify/policy-engine.js.map +1 -1
  60. package/dist/internal/verify/spki-distrust.js.map +1 -1
  61. package/dist/internal/verify/verify-path.d.ts +1 -2
  62. package/dist/internal/verify/verify-path.js +234 -128
  63. package/dist/internal/verify/verify-path.js.map +1 -1
  64. package/dist/internal/x509/directory-name.js +10 -10
  65. package/dist/internal/x509/directory-name.js.map +1 -1
  66. package/dist/internal/x509/extension-bits.js.map +1 -1
  67. package/dist/internal/x509/extension-errors.d.ts +1 -2
  68. package/dist/internal/x509/extension-errors.js.map +1 -1
  69. package/dist/internal/x509/extension-registry.js +18 -18
  70. package/dist/internal/x509/extension-registry.js.map +1 -1
  71. package/dist/internal/x509/general-name-profile.js +9 -9
  72. package/dist/internal/x509/general-name-profile.js.map +1 -1
  73. package/dist/internal/x509/general-name.js +32 -32
  74. package/dist/internal/x509/general-name.js.map +1 -1
  75. package/dist/internal/x509/name-fields.js +1 -1
  76. package/dist/internal/x509/name-fields.js.map +1 -1
  77. package/dist/internal/x509/or-address.js.map +1 -1
  78. package/dist/jose/base64url.d.ts +4 -0
  79. package/dist/jose/base64url.js +14 -0
  80. package/dist/jose/base64url.js.map +1 -0
  81. package/dist/jose/errors.d.ts +9 -3
  82. package/dist/jose/errors.js.map +1 -1
  83. package/dist/jose/jwe.d.ts +64 -0
  84. package/dist/jose/jwe.js +188 -0
  85. package/dist/jose/jwe.js.map +1 -0
  86. package/dist/jose/jwks.d.ts +38 -10
  87. package/dist/jose/jwks.js +156 -96
  88. package/dist/jose/jwks.js.map +1 -1
  89. package/dist/jose/jws.d.ts +8 -6
  90. package/dist/jose/jws.js +216 -170
  91. package/dist/jose/jws.js.map +1 -1
  92. package/dist/jose/jwt.d.ts +8 -2
  93. package/dist/jose/jwt.js +98 -98
  94. package/dist/jose/jwt.js.map +1 -1
  95. package/dist/jose/remote-jwks.d.ts +1 -2
  96. package/dist/jose/remote-jwks.js +106 -108
  97. package/dist/jose/remote-jwks.js.map +1 -1
  98. package/dist/jose.d.ts +15 -4
  99. package/dist/jose.js +7 -5
  100. package/dist/kdf/argon2-arithmetic.js.map +1 -1
  101. package/dist/kdf/argon2-core.js.map +1 -1
  102. package/dist/kdf/argon2-memory.js.map +1 -1
  103. package/dist/kdf/argon2-portable.js.map +1 -1
  104. package/dist/kdf/argon2.d.ts +7 -2
  105. package/dist/kdf/argon2.js.map +1 -1
  106. package/dist/kdf.d.ts +6 -0
  107. package/dist/keys/keys.d.ts +31 -6
  108. package/dist/keys/keys.js +315 -233
  109. package/dist/keys/keys.js.map +1 -1
  110. package/dist/keys.d.ts +11 -2
  111. package/dist/keys.js +2 -2
  112. package/dist/pem/pem.d.ts +1 -2
  113. package/dist/pem/pem.js +40 -25
  114. package/dist/pem/pem.js.map +1 -1
  115. package/dist/pem.d.ts +6 -0
  116. package/dist/pkcs/pfx.d.ts +2 -3
  117. package/dist/pkcs/pfx.js +142 -142
  118. package/dist/pkcs/pfx.js.map +1 -1
  119. package/dist/pkcs/pkcs12-mac.d.ts +1 -2
  120. package/dist/pkcs/pkcs12-mac.js +122 -122
  121. package/dist/pkcs/pkcs12-mac.js.map +1 -1
  122. package/dist/pkcs/pkcs7.d.ts +24 -3
  123. package/dist/pkcs/pkcs7.js +294 -256
  124. package/dist/pkcs/pkcs7.js.map +1 -1
  125. package/dist/pkcs.d.ts +10 -1
  126. package/dist/pkcs.js +4 -4
  127. package/dist/result/result.d.ts +1 -2
  128. package/dist/result/result.js.map +1 -1
  129. package/dist/result.d.ts +6 -0
  130. package/dist/revocation/chain.d.ts +69 -16
  131. package/dist/revocation/chain.js +431 -303
  132. package/dist/revocation/chain.js.map +1 -1
  133. package/dist/revocation/crl.d.ts +67 -14
  134. package/dist/revocation/crl.js +656 -366
  135. package/dist/revocation/crl.js.map +1 -1
  136. package/dist/revocation/ocsp.d.ts +78 -24
  137. package/dist/revocation/ocsp.js +622 -436
  138. package/dist/revocation/ocsp.js.map +1 -1
  139. package/dist/revocation/revocation.d.ts +68 -14
  140. package/dist/revocation/revocation.js +195 -74
  141. package/dist/revocation/revocation.js.map +1 -1
  142. package/dist/revocation.d.ts +14 -5
  143. package/dist/revocation.js +4 -4
  144. package/dist/ssh/ssh.d.ts +2 -3
  145. package/dist/ssh/ssh.js +165 -170
  146. package/dist/ssh/ssh.js.map +1 -1
  147. package/dist/ssh/wire.d.ts +1 -2
  148. package/dist/ssh/wire.js +10 -10
  149. package/dist/ssh/wire.js.map +1 -1
  150. package/dist/ssh.d.ts +8 -0
  151. package/dist/verify/identity.d.ts +3 -4
  152. package/dist/verify/identity.js +33 -33
  153. package/dist/verify/identity.js.map +1 -1
  154. package/dist/verify/name-constraints.d.ts +9 -2
  155. package/dist/verify/policy.d.ts +9 -2
  156. package/dist/verify/verify.d.ts +85 -34
  157. package/dist/verify/verify.js +276 -226
  158. package/dist/verify/verify.js.map +1 -1
  159. package/dist/verify.d.ts +12 -2
  160. package/dist/x509/certificate.d.ts +4 -5
  161. package/dist/x509/certificate.js +40 -40
  162. package/dist/x509/certificate.js.map +1 -1
  163. package/dist/x509/csr.d.ts +3 -4
  164. package/dist/x509/csr.js +15 -15
  165. package/dist/x509/csr.js.map +1 -1
  166. package/dist/x509/extensions.d.ts +1 -2
  167. package/dist/x509/extensions.js +165 -165
  168. package/dist/x509/extensions.js.map +1 -1
  169. package/dist/x509/fingerprint.d.ts +1 -2
  170. package/dist/x509/fingerprint.js.map +1 -1
  171. package/dist/x509/name-text.d.ts +1 -2
  172. package/dist/x509/name-text.js.map +1 -1
  173. package/dist/x509/name.d.ts +1 -2
  174. package/dist/x509/name.js +15 -15
  175. package/dist/x509/name.js.map +1 -1
  176. package/dist/x509/parse.d.ts +9 -6
  177. package/dist/x509/parse.js +394 -394
  178. package/dist/x509/parse.js.map +1 -1
  179. package/dist/x509.d.ts +17 -4
  180. package/dist/x509.js +8 -8
  181. package/package.json +32 -33
  182. package/dist/internal/asn1/oids2.js +0 -75
  183. package/dist/internal/asn1/oids2.js.map +0 -1
@@ -1,21 +1,21 @@
1
- import { DECODE_REFUSAL_CODES as e, errorResult as t, indexedErrorResult as n, indexedMicro509Error as r, micro509Error as i } from "../result/result.js";
2
- import { decodeRefusalOf as a, rethrowDecodeRefusal as o } from "../internal/asn1/decode-refusal.js";
3
- import { canonicalizeOid as s } from "../internal/asn1/asn1.js";
4
- import { OIDS as c } from "../internal/asn1/oids2.js";
5
- import { verifySignedDataDetailed as l } from "../internal/crypto/sig-verify.js";
6
- import { asciiLowercase as u, domainToAscii as d } from "../internal/shared/idna.js";
7
- import { parseIpAddressToBytes as f } from "../internal/shared/ip.js";
8
- import { presentedSmtpUtf8MailboxDomain as p } from "../internal/shared/mailbox.js";
9
- import { normalizeLabelSeparators as m, parsePresentedSrvName as h, parseSrvNameRestriction as g, parseUriNameConstraint as _ } from "../internal/x509/general-name-profile.js";
10
- import { compareDistinguishedNames as v } from "../internal/shared/dn.js";
11
- import { parseCertificateDerOrThrow as y, parseCertificateSigningRequestDerOrThrow as b, parseCertificateSigningRequestPemOrThrow as x } from "../x509/parse.js";
12
- import { assertCrlMaxAge as S } from "../revocation/crl.js";
13
- import { createNameConstraintValidationState as C, evaluateNameConstraints as w } from "../internal/verify/name-constraints-engine.js";
14
- import { createPolicyValidationState as T, evaluatePolicyChain as E } from "../internal/verify/policy-engine.js";
15
- import { createSpkiDistrustCheck as D } from "../internal/verify/spki-distrust.js";
16
- import { assertPathBuildingChecks as O, authorityKeyIdentifierMismatch as k, buildChainInternal as A, countCaCertificatesBelowParsed as j, isSelfIssued as M, isWithinValidity as N, loadCertificates as P, loadSingleCertificate as F, verifyCertificateSignature as I } from "../internal/verify/verify-path.js";
17
- import { matchServiceIdentity as L } from "./identity.js";
18
- import { checkChainRevocation as R } from "../revocation/chain.js";
1
+ import { canonicalizeOid as e } from "../internal/asn1/asn1.js";
2
+ import { decodeRefusalOf as t, rethrowDecodeRefusal as n } from "../internal/asn1/decode-refusal.js";
3
+ import { OIDS as r } from "../internal/asn1/oids.js";
4
+ import { callerVerification as i, resolveSignatureVerifiers as a, verifySignedDataDetailed as o } from "../internal/crypto/sig-verify.js";
5
+ import { compareDistinguishedNames as s } from "../internal/shared/dn.js";
6
+ import { asciiLowercase as c, domainToAscii as l } from "../internal/shared/idna.js";
7
+ import { parseIpAddressToBytes as u } from "../internal/shared/ip.js";
8
+ import { presentedSmtpUtf8MailboxDomain as d } from "../internal/shared/mailbox.js";
9
+ import { createNameConstraintValidationState as f, evaluateNameConstraints as p } from "../internal/verify/name-constraints-engine.js";
10
+ import { createPolicyValidationState as m, evaluatePolicyChain as h } from "../internal/verify/policy-engine.js";
11
+ import { createSpkiDistrustCheck as g } from "../internal/verify/spki-distrust.js";
12
+ import { anchorWorkingKey as _, assertPathBuildingChecks as v, authorityKeyIdentifierMismatch as y, buildChainInternal as b, carriesTrustAnchorKey as x, certificateWorkingKey as S, countCaCertificatesBelowParsed as C, isSelfIssued as w, isWithinValidity as T, loadCertificates as E, loadSingleCertificate as D, signatureChecksWith as O, verifyCertificateSignature as k, workingParametersAt as A } from "../internal/verify/verify-path.js";
13
+ import { normalizeLabelSeparators as j, parsePresentedSrvName as M, parseSrvNameRestriction as N, parseUriNameConstraint as P } from "../internal/x509/general-name-profile.js";
14
+ import { DECODE_REFUSAL_CODES as F, errorResult as I, indexedErrorResult as L, indexedMicro509Error as R, micro509Error as z } from "../result/result.js";
15
+ import { checkChainRevocation as B } from "../revocation/chain.js";
16
+ import { assertClockSkew as V, assertCrlMaxAge as H } from "../revocation/crl.js";
17
+ import { matchServiceIdentity as U } from "./identity.js";
18
+ import { parseCertificateDerOrThrow as W, parseCertificateSigningRequestDerOrThrow as G, parseCertificateSigningRequestPemOrThrow as K } from "../x509/parse.js";
19
19
  // src/verify/verify.ts
20
20
  /**
21
21
  * Public certificate and CSR verification APIs.
@@ -64,30 +64,31 @@ import { checkChainRevocation as R } from "../revocation/chain.js";
64
64
  * - `public_key_distrusted` — a certificate or bare trust anchor uses an explicitly distrusted SHA-256 SPKI.
65
65
  * - `certificate_revoked` — revocation evidence confirms a chain certificate is revoked.
66
66
  * - `revocation_indeterminate` — revocation status could not be determined under a hard-fail policy.
67
+ * - `malformed` — a certificate source does not decode as a certificate, or the leaf source holds other than exactly one.
67
68
  * - `unsupported` — a certificate source holds a construct micro509 does not decode (see `ParseCertificateErrorCode`).
68
69
  * - `limit_exceeded` — a certificate source exceeds a micro509 decoding limit (see `ParseCertificateErrorCode`).
69
70
  */
70
- const z = /* @__PURE__ */ "no_trusted_root.issuer_not_found.signature_invalid.certificate_expired.ca_required.key_cert_sign_required.path_length_exceeded.path_building_limit_exceeded.authority_key_identifier_mismatch.extended_key_usage_invalid.subject_alt_name_mismatch.common_name_fallback_suppressed.self_signed_leaf_not_allowed.unrecognized_critical_extension.no_rev_avail_conflict.display_text_oversized.intermediate_eku_constraint.explicit_policy_required.initial_policy_set_not_satisfied.unsupported_initial_name_constraints.unsupported_name_constraints.name_constraints_violated.unsupported_signature_algorithm_parameters.ec_domain_parameters_missing.public_key_distrusted.certificate_revoked.revocation_indeterminate.unsupported.limit_exceeded".split("."), B = /* @__PURE__ */ new Set([
71
- c.basicConstraints,
72
- c.keyUsage,
73
- c.extendedKeyUsage,
74
- c.subjectAltName,
75
- c.issuerAltName,
76
- c.nameConstraints,
77
- c.authorityKeyIdentifier,
78
- c.subjectKeyIdentifier,
79
- c.authorityInfoAccess,
80
- c.cRLDistributionPoints,
81
- c.certificatePolicies,
82
- c.policyMappings,
83
- c.policyConstraints,
84
- c.inhibitAnyPolicy,
85
- c.noRevAvail
71
+ const q = /* @__PURE__ */ "no_trusted_root.issuer_not_found.signature_invalid.certificate_expired.ca_required.key_cert_sign_required.path_length_exceeded.path_building_limit_exceeded.authority_key_identifier_mismatch.extended_key_usage_invalid.subject_alt_name_mismatch.common_name_fallback_suppressed.self_signed_leaf_not_allowed.unrecognized_critical_extension.no_rev_avail_conflict.display_text_oversized.intermediate_eku_constraint.explicit_policy_required.initial_policy_set_not_satisfied.unsupported_initial_name_constraints.unsupported_name_constraints.name_constraints_violated.unsupported_signature_algorithm_parameters.ec_domain_parameters_missing.public_key_distrusted.certificate_revoked.revocation_indeterminate.malformed.unsupported.limit_exceeded".split("."), J = /* @__PURE__ */ new Set([
72
+ r.basicConstraints,
73
+ r.keyUsage,
74
+ r.extendedKeyUsage,
75
+ r.subjectAltName,
76
+ r.issuerAltName,
77
+ r.nameConstraints,
78
+ r.authorityKeyIdentifier,
79
+ r.subjectKeyIdentifier,
80
+ r.authorityInfoAccess,
81
+ r.cRLDistributionPoints,
82
+ r.certificatePolicies,
83
+ r.policyMappings,
84
+ r.policyConstraints,
85
+ r.inhibitAnyPolicy,
86
+ r.noRevAvail
86
87
  ]);
87
88
  function loadCertificatePool(e, t) {
88
89
  let n = [];
89
90
  for (let [r, i] of e.entries()) try {
90
- n.push(...P([i]));
91
+ n.push(...E([i]));
91
92
  } catch (e) {
92
93
  return certificateSourceFailure(e, {
93
94
  kind: t,
@@ -99,10 +100,10 @@ function loadCertificatePool(e, t) {
99
100
  certificates: n
100
101
  };
101
102
  }
102
- function certificateSourceFailure(t, n) {
103
- let r = a(t, e);
104
- return r === void 0 ? failure("issuer_not_found", "certificate source is malformed or leaf source does not contain exactly one certificate", 0, detail({
105
- actual: t instanceof Error ? t.message : "certificate source is malformed",
103
+ function certificateSourceFailure(e, n) {
104
+ let r = t(e, F);
105
+ return r === void 0 ? failure("malformed", "certificate source is malformed or leaf source does not contain exactly one certificate", 0, detail({
106
+ actual: e instanceof Error ? e.message : "certificate source is malformed",
106
107
  source: n
107
108
  })) : failure(r.code, r.message, 0, detail({
108
109
  actual: r.message,
@@ -116,41 +117,47 @@ function certificateSourceFailure(t, n) {
116
117
  * for that, or {@linkcode verifyCertificateChain} for the all-in-one API.
117
118
  */
118
119
  async function buildCandidatePathRaw(e) {
119
- O(e.maxPathBuildingChecks);
120
- let t = D(e.distrustedSpkiSha256), n;
120
+ v(e.maxPathBuildingChecks);
121
+ let t = g(e.distrustedSpkiSha256), n = O(a(e.signatureVerifiers)), r;
121
122
  try {
122
- n = F(e.leaf);
123
+ r = D(e.leaf);
123
124
  } catch (e) {
124
125
  return certificateSourceFailure(e, void 0);
125
126
  }
126
- let r = loadCertificatePool(e.intermediates ?? [], "intermediates");
127
- if (!r.ok) return r;
128
- let i = loadCertificatePool(e.roots, "roots");
127
+ let i = loadCertificatePool(e.intermediates ?? [], "intermediates");
129
128
  if (!i.ok) return i;
130
- let a = e.trustAnchors ?? [], o = e.at ?? /* @__PURE__ */ new Date(), s = await A(n, r.certificates, i.certificates, a, o, {
129
+ let o = loadCertificatePool(e.roots, "roots");
130
+ if (!o.ok) return o;
131
+ let s = e.trustAnchors ?? [], c = e.at ?? /* @__PURE__ */ new Date(), l = await b(r, i.certificates, o.certificates, s, c, {
131
132
  failure,
132
133
  detail
133
- }, void 0, e.maxPathBuildingChecks, t), c = s.chain;
134
- if (!s.foundTrustedRoot) return s.failure === void 0 ? s.missingIssuerAt === void 0 ? failure("no_trusted_root", "no trusted root found", void 0, detail({ chainCommonNames: c.map((e) => e.subject.values.commonName ?? "<unnamed>") })) : failure("issuer_not_found", "issuer certificate not found", s.missingIssuerAt, buildFailureDetails(c, s.missingIssuerAt)) : s.failure;
135
- let l = c[c.length - 1];
136
- return l === void 0 ? failure("no_trusted_root", "no trusted root found") : {
134
+ }, n, e.maxPathBuildingChecks, t), u = l.chain;
135
+ if (!l.foundTrustedRoot) return l.failure === void 0 ? l.missingIssuerAt === void 0 ? failure("no_trusted_root", "no trusted root found", void 0, detail({ chainCommonNames: u.map((e) => e.subject.values.commonName ?? "<unnamed>") })) : failure("issuer_not_found", "issuer certificate not found", l.missingIssuerAt, buildFailureDetails(u, l.missingIssuerAt)) : l.failure;
136
+ let d = u[u.length - 1];
137
+ return d === void 0 ? failure("no_trusted_root", "no trusted root found") : {
137
138
  ok: !0,
138
139
  value: {
139
- leaf: n,
140
- chain: c,
141
- root: l,
142
- anchorCertificateInChain: s.anchorCertificateInChain ?? !0,
143
- ...s.trustAnchor !== void 0 && { trustAnchor: s.trustAnchor }
140
+ leaf: r,
141
+ chain: u,
142
+ root: d,
143
+ ...l.trustAnchor === void 0 ? { anchorCertificateInChain: !0 } : {
144
+ anchorCertificateInChain: !1,
145
+ trustAnchor: l.trustAnchor
146
+ }
144
147
  }
145
148
  };
146
149
  }
147
150
  /**
148
151
  * Builds a signature-verified path from a leaf certificate to a trusted root.
149
152
  *
150
- * Parses the supplied certificates, walks the issuer chain, signature-checks
151
- * each link, and returns the first valid path. Does not enforce time, constraints,
152
- * or leaf purpose — call {@linkcode validateCandidatePath} or use the all-in-one
153
- * {@linkcode verifyCertificateChain} for full validation.
153
+ * Parses the supplied certificates, walks the issuer chain, and returns the
154
+ * first path whose links pass. Each link checks the signature, the issuer's
155
+ * validity period, CA and keyCertSign constraints, path length, and key
156
+ * identifiers. {@linkcode validateCandidatePath} checks the leaf's validity
157
+ * period, unrecognized critical extensions, certificate policies, name
158
+ * constraints, and leaf purpose. The all-in-one
159
+ * {@linkcode verifyCertificateChain} also checks service identity and
160
+ * revocation.
154
161
  *
155
162
  * @example
156
163
  * ```ts
@@ -179,22 +186,25 @@ async function buildCandidatePath(e) {
179
186
  * assumed trusted and not re-verified.
180
187
  */
181
188
  async function validateCandidatePathRaw(e) {
182
- let t = D(e.distrustedSpkiSha256);
189
+ let t = g(e.distrustedSpkiSha256);
183
190
  if (e.distrustedSpkiSha256?.length && e.anchorCertificateInChain === !1 && e.trustAnchor === void 0) throw RangeError("trustAnchor is required to check distrust on a path with a bare anchor");
184
191
  let n = e.chain, r = await validatePathDistrust(e, t);
185
192
  if (r !== void 0) return r;
186
- let i = e.at ?? /* @__PURE__ */ new Date(), a = buildValidationState(e, n.length);
187
- if (!a.ok) return a;
188
- let o = n[0];
189
- if (o === void 0) return failure("issuer_not_found", "chain is empty", 0);
190
- let s = await validateSelfSignedLeafAllowed(o, n.length, e);
191
- if (s !== void 0) return s;
192
- let c = await validatePathCertificates(n, i, e.rejectOversizedDisplayText === !0);
193
- if (c !== void 0) return c;
194
- let l = validatePathLengthConstraints(n);
195
- if (l !== void 0) return l;
196
- let u = validatePolicyAndNameConstraints(n, a.value, e.anchorCertificateInChain ?? !0);
197
- return u.ok ? validateLeaf(o, e, u.policyValidation) : u;
193
+ let i = e.at ?? /* @__PURE__ */ new Date(), o = buildValidationState(e, n.length);
194
+ if (!o.ok) return o;
195
+ let s = n[0];
196
+ if (s === void 0) return failure("issuer_not_found", "chain is empty", 0);
197
+ let c = a(e.signatureVerifiers), l = pathWorkingParameters(n, e), u = await validateSelfSignedLeafAllowed(s, n.length, e, {
198
+ verifiers: c,
199
+ workingParameters: { parametersDer: l(0) }
200
+ });
201
+ if (u !== void 0) return u;
202
+ let d = await validatePathCertificates(n, i, e.rejectOversizedDisplayText === !0, c, l);
203
+ if (d !== void 0) return d;
204
+ let f = validatePathLengthConstraints(n);
205
+ if (f !== void 0) return f;
206
+ let p = validatePolicyAndNameConstraints(n, o.value, e.anchorCertificateInChain ?? !0);
207
+ return p.ok ? validateLeaf(s, e, p.policyValidation) : p;
198
208
  }
199
209
  /** Checks signed certificate SPKIs and the separately supplied bare anchor. */
200
210
  async function validatePathDistrust(e, t) {
@@ -202,7 +212,7 @@ async function validatePathDistrust(e, t) {
202
212
  for (let [n, r] of e.chain.entries()) {
203
213
  let e;
204
214
  try {
205
- e = y(r.der);
215
+ e = W(r.der);
206
216
  } catch (e) {
207
217
  return {
208
218
  ...certificateSourceFailure(e, void 0),
@@ -221,25 +231,46 @@ async function validatePathDistrust(e, t) {
221
231
  }
222
232
  }
223
233
  }
224
- /** RFC 5280 §3.2 makes a self-issued certificate self-signed only when the public key it binds verifies its signature. */
225
- async function validateSelfSignedLeafAllowed(e, t, n) {
226
- if (t !== 1 || !M(e) || n.allowSelfSignedLeaf === !0) return;
227
- let r = await I(e, e);
228
- if (r.ok && r.valid) return failure("self_signed_leaf_not_allowed", "self-signed leaf not allowed", 0, detail({ subjectCommonName: e.subject.values.commonName }));
234
+ /**
235
+ * RFC 5280 §3.2 makes a self-issued certificate self-signed only when the
236
+ * public key it binds verifies its signature, with the parameters its path
237
+ * gives that key (RFC 5280 §6.1.4 (e)).
238
+ */
239
+ async function validateSelfSignedLeafAllowed(e, t, n, r) {
240
+ if (t !== 1 || !w(e) || n.allowSelfSignedLeaf === !0) return;
241
+ let i = await k(e, e, r);
242
+ if (i.ok && i.valid) return failure("self_signed_leaf_not_allowed", "self-signed leaf not allowed", 0, detail({ subjectCommonName: e.subject.values.commonName }));
243
+ }
244
+ /**
245
+ * RFC 5280 §6.1.2 (g)-(i) and §6.1.4 (e)-(f) along `chain`: the working key
246
+ * parameters for the issuer at each index. The terminal certificate or the bare
247
+ * anchor initializes them.
248
+ */
249
+ function pathWorkingParameters(e, t) {
250
+ let n = e[e.length - 1];
251
+ if (t.anchorCertificateInChain === !1 || n === void 0) {
252
+ let n = t.trustAnchor === void 0 ? {
253
+ algorithmOid: "",
254
+ parametersDer: void 0
255
+ } : _(t.trustAnchor);
256
+ return (t) => A(e, t, e.length - 1, n);
257
+ }
258
+ let r = S(n);
259
+ return (t) => A(e, t, e.length - 2, r);
229
260
  }
230
261
  /** Validates every certificate and issuer relationship in a candidate path. */
231
- async function validatePathCertificates(e, t, n) {
232
- for (let r = 0; r < e.length; r += 1) {
233
- let i = e[r];
234
- if (i === void 0) return failure("issuer_not_found", "chain element missing", r);
235
- let a = validateCertificateAtPathIndex(i, r, t);
236
- if (a !== void 0) return a;
262
+ async function validatePathCertificates(e, t, n, r, i) {
263
+ for (let a = 0; a < e.length; a += 1) {
264
+ let o = e[a];
265
+ if (o === void 0) return failure("issuer_not_found", "chain element missing", a);
266
+ let s = validateCertificateAtPathIndex(o, a, t);
267
+ if (s !== void 0) return s;
237
268
  if (n) {
238
- let e = validateDisplayTextAtPathIndex(i, r);
269
+ let e = validateDisplayTextAtPathIndex(o, a);
239
270
  if (e !== void 0) return e;
240
271
  }
241
- let o = await validatePathIssuerAtIndex(e, i, r);
242
- if (o !== void 0) return o;
272
+ let c = await validatePathIssuerAtIndex(e, o, a, r, i);
273
+ if (c !== void 0) return c;
243
274
  }
244
275
  }
245
276
  /** RFC 5280 §4.2.1.4 bounds a DisplayText at 200 characters; PKITS 4.8.19 lets the application reject a longer explicitText. */
@@ -263,16 +294,16 @@ function validateDisplayTextAtPathIndex(e, t) {
263
294
  }));
264
295
  }
265
296
  }
266
- async function validatePathIssuerAtIndex(e, t, n) {
297
+ async function validatePathIssuerAtIndex(e, t, n, r, i) {
267
298
  if (n === e.length - 1) return;
268
- let r = e[n + 1];
269
- return r === void 0 ? failure("issuer_not_found", "issuer missing", n) : await validateIssuerAtPathIndex(t, r, n);
299
+ let a = e[n + 1];
300
+ return a === void 0 ? failure("issuer_not_found", "issuer missing", n) : await validateIssuerAtPathIndex(t, a, n, r, i(n + 1));
270
301
  }
271
302
  function validatePathLengthConstraints(e) {
272
303
  for (let t = 1; t < e.length; t += 1) {
273
304
  let n = e[t];
274
305
  if (n === void 0) return failure("issuer_not_found", "chain element missing", t);
275
- let r = j(e, t), i = n.basicConstraints?.pathLength;
306
+ let r = C(e, t), i = n.basicConstraints?.pathLength;
276
307
  if (isNonNegativeInteger(i) && r > i) return pathLengthExceededFailure(n, t, i, r);
277
308
  }
278
309
  }
@@ -284,19 +315,19 @@ function pathLengthExceededFailure(e, t, n, r) {
284
315
  }));
285
316
  }
286
317
  function validatePolicyAndNameConstraints(e, t, n) {
287
- let r = E(e, t.policy, n);
318
+ let r = h(e, t.policy, n);
288
319
  if (!r.ok) return failure(r.error.code, r.error.message, 0, detail({
289
320
  expected: r.error.details?.expected,
290
321
  actual: r.error.details?.actual
291
322
  }));
292
- let i = w(e, t.nameConstraints);
323
+ let i = p(e, t.nameConstraints);
293
324
  return i.ok ? {
294
325
  ok: !0,
295
326
  policyValidation: r.value
296
327
  } : i;
297
328
  }
298
329
  function validateCertificateAtPathIndex(e, t, n) {
299
- if (!N(e, n)) return failure("certificate_expired", "certificate not valid at requested time", t, detail({
330
+ if (!T(e, n)) return failure("certificate_expired", "certificate not valid at requested time", t, detail({
300
331
  subjectCommonName: e.subject.values.commonName,
301
332
  expected: describeDateTime(n),
302
333
  actual: `${describeDateTime(e.notBefore)}..${describeDateTime(e.notAfter)}`
@@ -320,7 +351,7 @@ function findNoRevAvailConflict(e) {
320
351
  if (e.noRevAvail === !0) {
321
352
  if (e.basicConstraints?.ca === !0) return "basicConstraints cA TRUE";
322
353
  if (e.crlDistributionPoints !== void 0) return "cRLDistributionPoints";
323
- if (e.extensions.some((e) => e.oid === c.freshestCRL)) return "freshestCRL";
354
+ if (e.extensions.some((e) => e.oid === r.freshestCRL)) return "freshestCRL";
324
355
  if (e.authorityInfoAccess?.some((e) => e.method === "ocsp") === !0) return "an id-ad-ocsp authorityInfoAccess entry";
325
356
  }
326
357
  }
@@ -330,31 +361,34 @@ function findNoRevAvailConflict(e) {
330
361
  * parameters are not present.
331
362
  */
332
363
  function validateEcDomainParametersAtPathIndex(e, t) {
333
- if (e.publicKeyAlgorithmOid === c.ecPublicKey && e.publicKeyParametersOid === void 0) return failure("ec_domain_parameters_missing", "elliptic curve public key carries no namedCurve domain parameters", t, detail({
364
+ if (e.publicKeyAlgorithmOid === r.ecPublicKey && e.publicKeyParametersOid === void 0) return failure("ec_domain_parameters_missing", "elliptic curve public key carries no namedCurve domain parameters", t, detail({
334
365
  subjectCommonName: e.subject.values.commonName,
335
366
  expected: "namedCurve OBJECT IDENTIFIER",
336
367
  actual: e.publicKeyAlgorithmParametersDer === void 0 ? "absent" : `tag 0x${(e.publicKeyAlgorithmParametersDer[0] ?? 0).toString(16).padStart(2, "0")}`
337
368
  }));
338
369
  }
339
- async function validateIssuerAtPathIndex(e, t, n) {
340
- if (!v(e.issuer, t.subject)) return failure("issuer_not_found", "issuer distinguished name does not match the candidate issuer subject", n, detail({
370
+ async function validateIssuerAtPathIndex(e, t, n, r, i) {
371
+ if (!s(e.issuer, t.subject)) return failure("issuer_not_found", "issuer distinguished name does not match the candidate issuer subject", n, detail({
341
372
  subjectCommonName: e.subject.values.commonName,
342
373
  issuerCommonName: t.subject.values.commonName
343
374
  }));
344
- let r = await I(e, t);
345
- return r.ok ? r.valid ? validateIssuerConstraintsAtPathIndex(e, t, n) : failure("signature_invalid", "certificate signature does not verify", n, detail({
375
+ let a = await k(e, t, {
376
+ verifiers: r,
377
+ workingParameters: { parametersDer: i }
378
+ });
379
+ return a.ok ? a.valid ? validateIssuerConstraintsAtPathIndex(e, t, n) : failure("signature_invalid", "certificate signature does not verify", n, detail({
346
380
  subjectCommonName: e.subject.values.commonName,
347
381
  issuerCommonName: t.subject.values.commonName
348
- })) : failure(r.code, r.reason, n, detail({
382
+ })) : failure(a.code, a.reason, n, detail({
349
383
  subjectCommonName: e.subject.values.commonName,
350
384
  issuerCommonName: t.subject.values.commonName,
351
- actual: r.reason
385
+ actual: a.reason
352
386
  }));
353
387
  }
354
388
  function validateIssuerConstraintsAtPathIndex(e, t, n) {
355
389
  if (t.basicConstraints?.ca !== !0) return failure("ca_required", "issuer must be a CA certificate", n + 1, detail({ subjectCommonName: t.subject.values.commonName }));
356
390
  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 }));
357
- if (k(e, t)) return failure("authority_key_identifier_mismatch", "authorityKeyIdentifier does not match issuer subjectKeyIdentifier", n, detail({
391
+ if (y(e, t)) return failure("authority_key_identifier_mismatch", "authorityKeyIdentifier does not match issuer subjectKeyIdentifier", n, detail({
358
392
  subjectCommonName: e.subject.values.commonName,
359
393
  issuerCommonName: t.subject.values.commonName,
360
394
  expected: t.subjectKeyIdentifier,
@@ -365,14 +399,14 @@ function validateIssuerConstraintsAtPathIndex(e, t, n) {
365
399
  * Validates a pre-built certificate chain for time, constraints, policy, and
366
400
  * optionally leaf purpose. Wrap the result of {@linkcode buildCandidatePath}.
367
401
  */
368
- async function validateCandidatePath(t) {
369
- let n = normalizeValidationChain(t.chain);
402
+ async function validateCandidatePath(e) {
403
+ let n = normalizeValidationChain(e.chain);
370
404
  if (!n.ok) {
371
- let { error: t, index: r } = n, i = a(t, e);
372
- return verifyFailureResult(i === void 0 ? failure("signature_invalid", "certificate input is malformed", r, detail({ actual: t instanceof Error ? t.message : "certificate input is malformed" })) : failure(i.code, i.message, r, detail({ actual: i.message })));
405
+ let { error: e, index: r } = n, i = t(e, F);
406
+ return verifyFailureResult(i === void 0 ? failure("malformed", "certificate input is malformed", r, detail({ actual: e instanceof Error ? e.message : "certificate input is malformed" })) : failure(i.code, i.message, r, detail({ actual: i.message })));
373
407
  }
374
408
  let r = await validateCandidatePathRaw({
375
- ...t,
409
+ ...e,
376
410
  chain: n.chain
377
411
  });
378
412
  return r.ok ? validateCandidatePathSuccessResult(r.policyValidation) : verifyFailureResult(r);
@@ -384,6 +418,12 @@ async function validateCandidatePath(t) {
384
418
  * Equivalent to calling {@linkcode buildCandidatePath} followed by
385
419
  * {@linkcode validateCandidatePath} (plus identity matching when configured).
386
420
  *
421
+ * Success authenticates the certification path of `leaf`. Authenticating a
422
+ * remote peer also takes the transport's proof that the peer holds the leaf's
423
+ * private key: pass the certificate the handshake authenticated as `leaf`,
424
+ * the rest of the peer's chain as `intermediates`, and apply authorization to
425
+ * `value.leaf`.
426
+ *
387
427
  * @example
388
428
  * ```ts
389
429
  * import { verifyCertificateChain } from 'micro509';
@@ -401,59 +441,80 @@ async function validateCandidatePath(t) {
401
441
  * ```
402
442
  */
403
443
  async function verifyCertificateChain(e) {
404
- let t = e.distrustedSpkiSha256 === void 0 ? void 0 : [...e.distrustedSpkiSha256];
405
- S(e.revocation?.policy?.crlMaxAgeMs);
406
- let n = await buildCandidatePath({
407
- leaf: e.leaf,
408
- roots: e.roots,
409
- ...e.intermediates !== void 0 && { intermediates: e.intermediates },
410
- ...e.trustAnchors !== void 0 && { trustAnchors: e.trustAnchors },
411
- ...e.at !== void 0 && { at: e.at },
412
- ...e.maxPathBuildingChecks !== void 0 && { maxPathBuildingChecks: e.maxPathBuildingChecks },
413
- ...t !== void 0 && { distrustedSpkiSha256: t }
414
- });
415
- if (!n.ok) return n;
416
- let r = await validateCandidatePath({
417
- chain: n.value.chain,
418
- anchorCertificateInChain: n.value.anchorCertificateInChain,
419
- ...n.value.trustAnchor !== void 0 && { trustAnchor: n.value.trustAnchor },
420
- ...t !== void 0 && { distrustedSpkiSha256: t },
421
- ...e.at !== void 0 && { at: e.at },
422
- ...e.purpose !== void 0 && { purpose: e.purpose },
423
- ...copyValidationInputs(e),
424
- ...e.allowSelfSignedLeaf !== void 0 && { allowSelfSignedLeaf: e.allowSelfSignedLeaf },
425
- ...e.rejectOversizedDisplayText !== void 0 && { rejectOversizedDisplayText: e.rejectOversizedDisplayText }
426
- });
444
+ let t = {
445
+ ...e,
446
+ at: e.at ?? /* @__PURE__ */ new Date()
447
+ }, n = t.distrustedSpkiSha256 === void 0 ? void 0 : [...t.distrustedSpkiSha256];
448
+ H(t.revocation?.policy?.crlMaxAgeMs), V(t.revocation?.policy?.clockSkewMs);
449
+ let r = await buildCandidatePath(chainBuildInput(t, n));
427
450
  if (!r.ok) return r;
428
- if (e.serviceIdentity !== void 0) {
429
- let t = validateServiceIdentity(n.value.leaf, e.serviceIdentity);
430
- if (!t.ok) return verifyFailureResult(t);
451
+ let i = await validateCandidatePath({
452
+ chain: r.value.chain,
453
+ anchorCertificateInChain: r.value.anchorCertificateInChain,
454
+ ...r.value.trustAnchor !== void 0 && { trustAnchor: r.value.trustAnchor },
455
+ ...n !== void 0 && { distrustedSpkiSha256: n },
456
+ ...t.signatureVerifiers !== void 0 && { signatureVerifiers: t.signatureVerifiers },
457
+ ...t.at !== void 0 && { at: t.at },
458
+ ...t.purpose !== void 0 && { purpose: t.purpose },
459
+ ...copyValidationInputs(t),
460
+ ...t.allowSelfSignedLeaf !== void 0 && { allowSelfSignedLeaf: t.allowSelfSignedLeaf },
461
+ ...t.rejectOversizedDisplayText !== void 0 && { rejectOversizedDisplayText: t.rejectOversizedDisplayText }
462
+ });
463
+ if (!i.ok) return i;
464
+ if (t.serviceIdentity !== void 0) {
465
+ let e = validateServiceIdentity(r.value.leaf, t.serviceIdentity);
466
+ if (!e.ok) return verifyFailureResult(e);
431
467
  }
432
- if (e.revocation !== void 0) {
433
- let t = await validateVerifiedChainRevocation(e, n.value.chain);
434
- if (t !== void 0) return t;
468
+ if (t.revocation !== void 0) {
469
+ let e = await validateVerifiedChainRevocation(t, r.value, n);
470
+ if (e !== void 0) return e;
435
471
  }
436
472
  return {
437
473
  ok: !0,
438
474
  value: {
439
- ...n.value,
440
- policyValidation: r.value.policyValidation
475
+ ...r.value,
476
+ policyValidation: i.value.policyValidation
441
477
  }
442
478
  };
443
479
  }
480
+ /** The path-building half of a {@linkcode VerifyCertificateChainInput}. */
481
+ function chainBuildInput(e, t) {
482
+ return {
483
+ leaf: e.leaf,
484
+ roots: e.roots,
485
+ ...e.intermediates !== void 0 && { intermediates: e.intermediates },
486
+ ...e.trustAnchors !== void 0 && { trustAnchors: e.trustAnchors },
487
+ ...e.at !== void 0 && { at: e.at },
488
+ ...e.maxPathBuildingChecks !== void 0 && { maxPathBuildingChecks: e.maxPathBuildingChecks },
489
+ ...e.signatureVerifiers !== void 0 && { signatureVerifiers: e.signatureVerifiers },
490
+ ...t !== void 0 && { distrustedSpkiSha256: t }
491
+ };
492
+ }
493
+ /**
494
+ * The bare anchor that issued the last certificate of `path`. A path that ends
495
+ * with the anchor's own certificate has none: that certificate is the anchor,
496
+ * which revocation checking leaves out.
497
+ */
498
+ function revocationTrustAnchor(e) {
499
+ let t = e.chain[e.chain.length - 1];
500
+ if (e.trustAnchor !== void 0 && t !== void 0) return x(t, e.trustAnchor) ? void 0 : e.trustAnchor;
501
+ }
444
502
  /** Applies optional revocation evidence to an otherwise verified certificate chain. */
445
- async function validateVerifiedChainRevocation(e, t) {
503
+ async function validateVerifiedChainRevocation(e, t, n) {
446
504
  if (e.revocation === void 0) return;
447
- let n = await R({
448
- chain: t,
505
+ let r = revocationTrustAnchor(t), i = await B({
506
+ chain: t.chain,
507
+ ...r !== void 0 && { trustAnchor: r },
449
508
  ...e.revocation.crls === void 0 ? {} : { crls: e.revocation.crls },
450
509
  ...e.revocation.ocspResponses === void 0 ? {} : { ocspResponses: e.revocation.ocspResponses },
451
510
  ...e.revocation.extraCertificates === void 0 ? {} : { extraCertificates: e.revocation.extraCertificates },
452
511
  ...e.revocation.trustedOcspResponders === void 0 ? {} : { trustedOcspResponders: e.revocation.trustedOcspResponders },
453
512
  ...e.revocation.policy === void 0 ? {} : { policy: e.revocation.policy },
454
- ...e.at === void 0 ? {} : { at: e.at }
513
+ ...e.at === void 0 ? {} : { at: e.at },
514
+ ...e.signatureVerifiers === void 0 ? {} : { signatureVerifiers: e.signatureVerifiers },
515
+ ...n === void 0 ? {} : { distrustedSpkiSha256: n }
455
516
  });
456
- return n.value.decision === "deny" ? revocationFailureResult(n.value) : void 0;
517
+ return i.value.decision === "deny" ? revocationFailureResult(i.value) : void 0;
457
518
  }
458
519
  function revocationFailureResult(e) {
459
520
  let t = e.summary.revokedCertificates[0];
@@ -485,33 +546,21 @@ function revocationFailureIndex(e, t) {
485
546
  * }
486
547
  * ```
487
548
  */
488
- async function verifyCertificateSigningRequest(t) {
489
- let n;
490
- try {
491
- n = typeof t == "string" ? x(t) : b(new Uint8Array(t));
492
- } catch (t) {
493
- let n = a(t, e);
494
- return n === void 0 ? verifyRequestFailureResult("signature_invalid", "certificate request input is malformed", detail({ actual: t instanceof Error ? t.message : "certificate request input is malformed" })) : verifyRequestFailureResult(n.code, n.message, detail({ actual: n.message }));
495
- }
496
- let r;
549
+ async function verifyCertificateSigningRequest(e, n = {}) {
550
+ let r = i(n.signatureVerifiers), a;
497
551
  try {
498
- r = await l(n.signatureAlgorithmOid, n.signatureAlgorithmParametersDer, n.publicKeyAlgorithmOid, n.publicKeyParametersOid, n.subjectPublicKeyInfoDer, n.signatureValue, n.certificationRequestInfoDer);
499
- } catch (t) {
500
- let r = a(t, e);
501
- return r === void 0 ? verifyRequestFailureResult("signature_invalid", "certificate request input is malformed", detail({
502
- subjectCommonName: n.subject.values.commonName,
503
- actual: t instanceof Error ? t.message : "certificate request input is malformed"
504
- })) : verifyRequestFailureResult(r.code, r.message, detail({
505
- subjectCommonName: n.subject.values.commonName,
506
- actual: r.message
507
- }));
552
+ a = typeof e == "string" ? K(e) : G(new Uint8Array(e));
553
+ } catch (e) {
554
+ let n = t(e, F);
555
+ return n === void 0 ? verifyRequestFailureResult("malformed", "certificate request input is malformed", detail({ actual: e instanceof Error ? e.message : "certificate request input is malformed" })) : verifyRequestFailureResult(n.code, n.message, detail({ actual: n.message }));
508
556
  }
509
- return r.ok ? r.valid ? {
557
+ let s = await o(a.signatureAlgorithmOid, a.signatureAlgorithmParametersDer, a.publicKeyAlgorithmOid, a.publicKeyParametersOid, a.subjectPublicKeyInfoDer, a.signatureValue, a.signatureValueUnusedBits, a.certificationRequestInfoDer, r);
558
+ return s.ok ? s.valid ? {
510
559
  ok: !0,
511
- value: n
512
- } : verifyRequestFailureResult("signature_invalid", "certificate request signature does not verify", detail({ subjectCommonName: n.subject.values.commonName })) : verifyRequestFailureResult(r.code === "verification_error" ? "signature_invalid" : r.code, r.reason, detail({
513
- subjectCommonName: n.subject.values.commonName,
514
- actual: r.reason
560
+ value: a
561
+ } : verifyRequestFailureResult("signature_invalid", "certificate request signature does not verify", detail({ subjectCommonName: a.subject.values.commonName })) : verifyRequestFailureResult(s.code === "verification_error" ? "signature_invalid" : s.code, s.reason, detail({
562
+ subjectCommonName: a.subject.values.commonName,
563
+ actual: s.reason
515
564
  }));
516
565
  }
517
566
  /**
@@ -529,15 +578,15 @@ async function verifyCertificateSigningRequest(t) {
529
578
  * }
530
579
  * ```
531
580
  */
532
- function checkExtendedKeyUsage(t, n) {
533
- let r = normalizeValidationChain(t);
581
+ function checkExtendedKeyUsage(e, n) {
582
+ let r = normalizeValidationChain(e);
534
583
  if (!r.ok) {
535
- let t = a(r.error, e);
536
- return t === void 0 ? ekuCheckFailureResult("leaf_eku_missing", "certificate input is malformed", r.index) : ekuCheckFailureResult(t.code, t.message, r.index);
584
+ let e = t(r.error, F);
585
+ return e === void 0 ? ekuCheckFailureResult("malformed", "certificate input is malformed", r.index) : ekuCheckFailureResult(e.code, e.message, r.index);
537
586
  }
538
- let i = r.chain, o = i[0];
539
- if (o === void 0) return ekuCheckFailureResult("leaf_eku_missing", "chain is empty", 0);
540
- if (o.extendedKeyUsage !== void 0 && !o.extendedKeyUsage.includes(n)) return ekuCheckFailureResult("leaf_eku_missing", `leaf certificate does not include EKU ${n}`, 0);
587
+ let i = r.chain, a = i[0];
588
+ if (a === void 0) return ekuCheckFailureResult("leaf_eku_missing", "chain is empty", 0);
589
+ if (a.extendedKeyUsage !== void 0 && !a.extendedKeyUsage.includes(n)) return ekuCheckFailureResult("leaf_eku_missing", `leaf certificate does not include EKU ${n}`, 0);
541
590
  for (let e = 1; e < i.length; e += 1) {
542
591
  let t = i[e];
543
592
  if (t !== void 0 && t.extendedKeyUsage !== void 0 && !t.extendedKeyUsage.includes(n)) return ekuCheckFailureResult("intermediate_eku_constraint", `intermediate CA at index ${String(e)} constrains EKU and does not include ${n}`, e);
@@ -548,19 +597,19 @@ function checkExtendedKeyUsage(t, n) {
548
597
  };
549
598
  }
550
599
  /** Extracts a {@linkcode TrustAnchor} from a parsed certificate, copying the subject, SPKI, and key identifiers. */
551
- function trustAnchorFromCertificate(t) {
552
- let n;
600
+ function trustAnchorFromCertificate(e) {
601
+ let t;
553
602
  try {
554
- n = reparseCertificateForTrust(t);
555
- } catch (t) {
556
- throw o(t, e), Error("certificate input is malformed");
603
+ t = reparseCertificateForTrust(e);
604
+ } catch (e) {
605
+ throw n(e, F), Error("certificate input is malformed");
557
606
  }
558
607
  return {
559
- subject: n.subject,
560
- subjectPublicKeyInfoDer: n.subjectPublicKeyInfoDer,
561
- publicKeyAlgorithmOid: n.publicKeyAlgorithmOid,
562
- ...n.publicKeyParametersOid === void 0 ? {} : { publicKeyParametersOid: n.publicKeyParametersOid },
563
- ...n.subjectKeyIdentifier === void 0 ? {} : { subjectKeyIdentifier: n.subjectKeyIdentifier }
608
+ subject: t.subject,
609
+ subjectPublicKeyInfoDer: t.subjectPublicKeyInfoDer,
610
+ publicKeyAlgorithmOid: t.publicKeyAlgorithmOid,
611
+ ...t.publicKeyParametersOid === void 0 ? {} : { publicKeyParametersOid: t.publicKeyParametersOid },
612
+ ...t.subjectKeyIdentifier === void 0 ? {} : { subjectKeyIdentifier: t.subjectKeyIdentifier }
564
613
  };
565
614
  }
566
615
  /** Extracts defined optional fields from a base input for safe forwarding. */
@@ -573,6 +622,7 @@ function baseChainInput(e) {
573
622
  ...e.at !== void 0 && { at: e.at },
574
623
  ...e.maxPathBuildingChecks !== void 0 && { maxPathBuildingChecks: e.maxPathBuildingChecks },
575
624
  ...e.distrustedSpkiSha256 !== void 0 && { distrustedSpkiSha256: e.distrustedSpkiSha256 },
625
+ ...e.signatureVerifiers !== void 0 && { signatureVerifiers: e.signatureVerifiers },
576
626
  ...copyValidationInputs(e)
577
627
  };
578
628
  }
@@ -679,7 +729,7 @@ function validateLeaf(e, t, n) {
679
729
  function validateServiceIdentity(e, t) {
680
730
  let n = validateServiceIdentityInput(t);
681
731
  if (!n.ok) return n;
682
- let r = L({
732
+ let r = U({
683
733
  certificate: reparseCertificateForTrust(e),
684
734
  serviceIdentity: t
685
735
  });
@@ -691,7 +741,7 @@ function validateServiceIdentity(e, t) {
691
741
  message: i.message,
692
742
  index: 0,
693
743
  ...i.details === void 0 ? {} : { details: i.details }
694
- } : i.code !== "subject_alt_name_mismatch" && i.code !== "common_name_fallback_suppressed" && i.code !== "unsupported" && i.code !== "limit_exceeded" ? failure("subject_alt_name_mismatch", "service identity input is malformed", 0, detail({
744
+ } : i.code !== "subject_alt_name_mismatch" && i.code !== "common_name_fallback_suppressed" && i.code !== "malformed" && i.code !== "unsupported" && i.code !== "limit_exceeded" ? failure("subject_alt_name_mismatch", "service identity input is malformed", 0, detail({
695
745
  expected: t.value,
696
746
  actual: i.code
697
747
  })) : {
@@ -703,13 +753,13 @@ function validateServiceIdentity(e, t) {
703
753
  };
704
754
  }
705
755
  function validateServiceIdentityInput(e) {
706
- if (!isRecord(e)) return failure("subject_alt_name_mismatch", "service identity input is malformed", 0);
707
- 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) }));
708
- if (typeof e.value != "string") return failure("subject_alt_name_mismatch", "service identity input is malformed", 0, detail({ actual: e.type }));
756
+ if (!isRecord(e)) return failure("malformed", "service identity input is malformed", 0);
757
+ if (e.type !== "dns" && e.type !== "ip" && e.type !== "uri" && e.type !== "srv") return failure("malformed", "service identity input is malformed", 0, detail({ actual: String(e.type) }));
758
+ if (typeof e.value != "string") return failure("malformed", "service identity input is malformed", 0, detail({ actual: e.type }));
709
759
  if (e.type === "ip") try {
710
- f(e.value);
760
+ u(e.value);
711
761
  } catch {
712
- return failure("subject_alt_name_mismatch", "service identity input is malformed", 0, detail({
762
+ return failure("malformed", "service identity input is malformed", 0, detail({
713
763
  expected: e.value,
714
764
  actual: "ip"
715
765
  }));
@@ -728,9 +778,9 @@ async function verifyChainForExtendedKeyUsageProfile(e, t) {
728
778
  }
729
779
  /** Returns the OID of the first critical extension not in {@linkcode PROCESSED_EXTENSION_OIDS}, or `undefined`. */
730
780
  function findUnprocessedCriticalExtension(e) {
731
- for (let t of e.extensions) if (t.critical && (!B.has(t.oid) || t.oid === c.subjectAltName && e.subjectAltNames?.some(isUninterpretedGeneralName) === !0)) return t.oid;
781
+ for (let t of e.extensions) if (t.critical && (!J.has(t.oid) || t.oid === r.subjectAltName && e.subjectAltNames?.some(isUninterpretedGeneralName) === !0)) return t.oid;
732
782
  }
733
- const V = /* @__PURE__ */ new Set([
783
+ const Y = /* @__PURE__ */ new Set([
734
784
  "otherName",
735
785
  "upn",
736
786
  "krb5PrincipalName",
@@ -740,21 +790,21 @@ const V = /* @__PURE__ */ new Set([
740
790
  ]);
741
791
  function isUninterpretedGeneralName(e) {
742
792
  switch (e.type) {
743
- case "srv": return h(u(e.value)) === void 0;
744
- case "smtpUtf8Mailbox": return p(e.value) === void 0;
745
- default: return V.has(e.type);
793
+ case "srv": return M(c(e.value)) === void 0;
794
+ case "smtpUtf8Mailbox": return d(e.value) === void 0;
795
+ default: return Y.has(e.type);
746
796
  }
747
797
  }
748
798
  /** Constructs a {@linkcode VerifyChainFailure} with the given code, message, optional chain index, and details. */
749
- function failure(e, t, n, i) {
799
+ function failure(e, t, n, r) {
750
800
  return {
751
801
  ok: !1,
752
- ...r(e, t, n, i)
802
+ ...R(e, t, n, r)
753
803
  };
754
804
  }
755
805
  /** Wraps a {@linkcode VerifyChainFailure} into the standard indexed error result shape. */
756
806
  function verifyFailureResult(e) {
757
- return n(e);
807
+ return L(e);
758
808
  }
759
809
  /** Wraps a policy outcome into the validate-candidate-path success result shape. */
760
810
  function validateCandidatePathSuccessResult(e) {
@@ -784,28 +834,28 @@ function normalizeValidationChain(e) {
784
834
  };
785
835
  }
786
836
  function reparseCertificateForTrust(e) {
787
- return y(new Uint8Array(e.der));
837
+ return W(new Uint8Array(e.der));
788
838
  }
789
839
  /** Returns `true` if the value is a non-negative integer (including zero). */
790
840
  function isNonNegativeInteger(e) {
791
841
  return e !== void 0 && Number.isInteger(e) && e >= 0;
792
842
  }
793
843
  /** Constructs a CSR verification failure result. */
794
- function verifyRequestFailureResult(e, n, r) {
795
- let a = {
844
+ function verifyRequestFailureResult(e, t, n) {
845
+ let r = {
796
846
  ok: !1,
797
- ...i(e, n, r)
847
+ ...z(e, t, n)
798
848
  };
799
- return t(a);
849
+ return I(r);
800
850
  }
801
851
  /** Constructs an EKU check failure result at the given chain index. */
802
- function ekuCheckFailureResult(e, t, i) {
803
- let a = {
852
+ function ekuCheckFailureResult(e, t, n) {
853
+ let r = {
804
854
  ok: !1,
805
- ...r(e, t, i),
806
- index: i
855
+ ...R(e, t, n),
856
+ index: n
807
857
  };
808
- return n(a);
858
+ return L(r);
809
859
  }
810
860
  /** Merges flat and nested policy fields, with nested taking precedence. */
811
861
  function resolvePolicyValidationInput(e) {
@@ -875,29 +925,29 @@ function detail(e) {
875
925
  }
876
926
  /** Initializes policy and name-constraint validation state for a chain walk. */
877
927
  function buildValidationState(e, t) {
878
- let n = T(resolvePolicyValidationInput(e), t), r = validateInitialNameConstraintsInput(resolveInitialNameConstraintsInput(e));
928
+ let n = m(resolvePolicyValidationInput(e), t), r = validateInitialNameConstraintsInput(resolveInitialNameConstraintsInput(e));
879
929
  return r.ok ? {
880
930
  ok: !0,
881
931
  value: {
882
932
  policy: n,
883
- nameConstraints: C(r.value)
933
+ nameConstraints: f(r.value)
884
934
  }
885
935
  } : r;
886
936
  }
887
- function normalizeInitialPolicySet(e) {
888
- if (e === void 0) return;
889
- if (e === "any") return e;
890
- if (!Array.isArray(e)) return [];
891
- let t = [];
892
- for (let n of e) {
893
- if (typeof n != "string") return [];
937
+ function normalizeInitialPolicySet(t) {
938
+ if (t === void 0) return;
939
+ if (t === "any") return t;
940
+ if (!Array.isArray(t)) return [];
941
+ let n = [];
942
+ for (let r of t) {
943
+ if (typeof r != "string") return [];
894
944
  try {
895
- t.push(s(n));
945
+ n.push(e(r));
896
946
  } catch {
897
947
  return [];
898
948
  }
899
949
  }
900
- return t.includes(c.anyPolicy) ? "any" : t;
950
+ return n.includes(r.anyPolicy) ? "any" : n;
901
951
  }
902
952
  function validateInitialNameConstraintsInput(e) {
903
953
  let t = validateInitialNameConstraintSubtrees(e.permittedSubtrees, "permittedSubtrees");
@@ -934,12 +984,12 @@ function validateInitialNameConstraintSubtrees(e, t) {
934
984
  function toAsciiInitialNameConstraint(e) {
935
985
  let { base: t } = e;
936
986
  if (t.type !== "dns" && t.type !== "email" && t.type !== "srv") return e;
937
- let n = t.type === "srv" ? m(t.value) : t.value, r = unconvertedConstraintPrefix(t.type, n), i = n.slice(r.length);
987
+ let n = t.type === "srv" ? j(t.value) : t.value, r = unconvertedConstraintPrefix(t.type, n), i = n.slice(r.length);
938
988
  if (t.type !== "srv" && i.endsWith(".")) return;
939
- let a = t.type === "srv" && i.length === 0 ? void 0 : d(i, "lookup");
989
+ let a = t.type === "srv" && i.length === 0 ? void 0 : l(i, "lookup");
940
990
  if (a !== void 0 && !a.ok) return;
941
991
  let o = `${r}${a?.value ?? ""}`;
942
- if (!(!/^[\x20-\x7e]*$/.test(o) || t.type === "srv" && g(o) === void 0)) return {
992
+ if (!(!/^[\x20-\x7e]*$/.test(o) || t.type === "srv" && N(o) === void 0)) return {
943
993
  ...e,
944
994
  base: {
945
995
  ...t,
@@ -960,7 +1010,7 @@ function describeInvalidInitialNameConstraintForm(e) {
960
1010
  if (!isRecord(t) || typeof t.type != "string") return "invalid subtree";
961
1011
  switch (t.type) {
962
1012
  case "dns": return typeof t.value == "string" ? void 0 : t.type;
963
- case "uri": return typeof t.value == "string" && _(t.value) !== void 0 ? void 0 : t.type;
1013
+ case "uri": return typeof t.value == "string" && P(t.value) !== void 0 ? void 0 : t.type;
964
1014
  case "email": return typeof t.value == "string" && !t.value.includes("@") ? void 0 : t.type;
965
1015
  case "srv": return typeof t.value == "string" && t.value.length > 0 ? void 0 : t.type;
966
1016
  case "directoryName": return typeof t.derHex == "string" ? void 0 : t.type;
@@ -978,6 +1028,6 @@ function invalidInitialNameConstraintsFailure(e) {
978
1028
  function isRecord(e) {
979
1029
  return typeof e == "object" && !!e;
980
1030
  }
981
- export { z as VERIFY_ERROR_CODES, buildCandidatePath, checkExtendedKeyUsage, M as isSelfIssuedCertificate, trustAnchorFromCertificate, validateCandidatePath, validateForCa, validateForCodeSigning, validateForTlsClient, validateForTlsServer, verifyCertificateChain, verifyCertificateSigningRequest };
1031
+ export { q as VERIFY_ERROR_CODES, buildCandidatePath, checkExtendedKeyUsage, w as isSelfIssuedCertificate, trustAnchorFromCertificate, validateCandidatePath, validateForCa, validateForCodeSigning, validateForTlsClient, validateForTlsServer, verifyCertificateChain, verifyCertificateSigningRequest };
982
1032
 
983
1033
  //# sourceMappingURL=verify.js.map