micro509 0.13.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2064 -0
- package/README.md +111 -183
- package/dist/crypto/crypto.d.ts +104 -0
- package/dist/crypto/crypto.js +105 -0
- package/dist/crypto/crypto.js.map +1 -0
- package/dist/crypto.d.ts +4 -0
- package/dist/crypto.js +1 -0
- package/dist/der/der.d.ts +41 -33
- package/dist/der/der.js +26 -24
- package/dist/der/der.js.map +1 -1
- package/dist/index.d.ts +18 -14
- package/dist/index.js +19 -17
- package/dist/internal/asn1/asn1.d.ts +3 -6
- package/dist/internal/asn1/asn1.js +355 -44
- package/dist/internal/asn1/asn1.js.map +1 -1
- package/dist/internal/asn1/ber.js +146 -0
- package/dist/internal/asn1/ber.js.map +1 -0
- package/dist/internal/asn1/decode-refusal.js +29 -0
- package/dist/internal/asn1/decode-refusal.js.map +1 -0
- package/dist/internal/asn1/der.d.ts +42 -43
- package/dist/internal/asn1/der.js +148 -56
- package/dist/internal/asn1/der.js.map +1 -1
- package/dist/internal/asn1/oids.js +90 -54
- package/dist/internal/asn1/oids.js.map +1 -1
- package/dist/internal/asn1/oids2.js +1 -2
- package/dist/internal/asn1/oids2.js.map +1 -1
- package/dist/internal/crypto/algorithm-names.js +5 -2
- package/dist/internal/crypto/algorithm-names.js.map +1 -1
- package/dist/internal/crypto/ecdsa.js +13 -8
- package/dist/internal/crypto/ecdsa.js.map +1 -1
- package/dist/internal/crypto/hash.js +1 -2
- package/dist/internal/crypto/hash.js.map +1 -1
- package/dist/internal/crypto/pbes2.d.ts +51 -0
- package/dist/internal/crypto/pbes2.js +86 -34
- package/dist/internal/crypto/pbes2.js.map +1 -1
- package/dist/internal/crypto/rsa-pss.js +48 -44
- package/dist/internal/crypto/rsa-pss.js.map +1 -1
- package/dist/internal/crypto/sig-verify.d.ts +28 -0
- package/dist/internal/crypto/sig-verify.js +111 -62
- package/dist/internal/crypto/sig-verify.js.map +1 -1
- package/dist/internal/crypto/signing.d.ts +1 -4
- package/dist/internal/crypto/signing.js +28 -29
- package/dist/internal/crypto/signing.js.map +1 -1
- package/dist/internal/crypto/webcrypto.js +1 -2
- package/dist/internal/crypto/webcrypto.js.map +1 -1
- package/dist/internal/shared/base64.js +8 -3
- package/dist/internal/shared/base64.js.map +1 -1
- package/dist/internal/shared/dn.d.ts +13 -0
- package/dist/internal/shared/dn.js +101 -48
- package/dist/internal/shared/dn.js.map +1 -1
- package/dist/internal/shared/idna-tables.js +7217 -0
- package/dist/internal/shared/idna-tables.js.map +1 -0
- package/dist/internal/shared/idna.js +296 -0
- package/dist/internal/shared/idna.js.map +1 -0
- package/dist/internal/shared/ip.d.ts +66 -0
- package/dist/internal/shared/ip.js +19 -3
- package/dist/internal/shared/ip.js.map +1 -1
- package/dist/internal/shared/mailbox.js +26 -0
- package/dist/internal/shared/mailbox.js.map +1 -0
- package/dist/internal/shared/punycode.js +101 -0
- package/dist/internal/shared/punycode.js.map +1 -0
- package/dist/internal/shared/rfc3454-tables.js +1 -2
- package/dist/internal/shared/rfc3454-tables.js.map +1 -1
- package/dist/internal/shared/rfc4518-tables.js +119 -0
- package/dist/internal/shared/rfc4518-tables.js.map +1 -0
- package/dist/internal/shared/uri-host.js +102 -0
- package/dist/internal/shared/uri-host.js.map +1 -0
- package/dist/internal/verify/name-constraints-engine.js +246 -131
- package/dist/internal/verify/name-constraints-engine.js.map +1 -1
- package/dist/internal/verify/policy-engine.js +6 -21
- package/dist/internal/verify/policy-engine.js.map +1 -1
- package/dist/internal/verify/verify-path.d.ts +4 -0
- package/dist/internal/verify/verify-path.js +264 -128
- package/dist/internal/verify/verify-path.js.map +1 -1
- package/dist/internal/x509/directory-name.js +23 -0
- package/dist/internal/x509/directory-name.js.map +1 -0
- package/dist/internal/x509/extension-bits.js +15 -13
- package/dist/internal/x509/extension-bits.js.map +1 -1
- package/dist/internal/x509/extension-errors.d.ts +3 -0
- package/dist/internal/x509/extension-errors.js +19 -0
- package/dist/internal/x509/extension-errors.js.map +1 -0
- package/dist/internal/x509/extension-registry.js +157 -81
- package/dist/internal/x509/extension-registry.js.map +1 -1
- package/dist/internal/x509/general-name-profile.js +129 -0
- package/dist/internal/x509/general-name-profile.js.map +1 -0
- package/dist/internal/x509/general-name-tags.js +27 -0
- package/dist/internal/x509/general-name-tags.js.map +1 -0
- package/dist/internal/x509/general-name.js +183 -0
- package/dist/internal/x509/general-name.js.map +1 -0
- package/dist/internal/x509/name-fields.js +21 -12
- package/dist/internal/x509/name-fields.js.map +1 -1
- package/dist/internal/x509/or-address.js +217 -0
- package/dist/internal/x509/or-address.js.map +1 -0
- package/dist/keys/keys.d.ts +124 -95
- package/dist/keys/keys.js +362 -214
- package/dist/keys/keys.js.map +1 -1
- package/dist/keys.d.ts +3 -2
- package/dist/keys.js +3 -2
- package/dist/pem/pem.d.ts +17 -19
- package/dist/pem/pem.js +122 -41
- package/dist/pem/pem.js.map +1 -1
- package/dist/pem.js +1 -2
- package/dist/pkcs/pfx.d.ts +57 -32
- package/dist/pkcs/pfx.js +209 -173
- package/dist/pkcs/pfx.js.map +1 -1
- package/dist/pkcs/pkcs12-mac.d.ts +104 -27
- package/dist/pkcs/pkcs12-mac.js +266 -79
- package/dist/pkcs/pkcs12-mac.js.map +1 -1
- package/dist/pkcs/pkcs7.d.ts +123 -53
- package/dist/pkcs/pkcs7.js +314 -238
- package/dist/pkcs/pkcs7.js.map +1 -1
- package/dist/pkcs.d.ts +5 -4
- package/dist/result/result.d.ts +43 -28
- package/dist/result/result.js +27 -14
- package/dist/result/result.js.map +1 -1
- package/dist/result.d.ts +2 -2
- package/dist/result.js +1 -2
- package/dist/revocation/chain.d.ts +101 -23
- package/dist/revocation/chain.js +456 -206
- package/dist/revocation/chain.js.map +1 -1
- package/dist/revocation/crl.d.ts +140 -65
- package/dist/revocation/crl.js +691 -391
- package/dist/revocation/crl.js.map +1 -1
- package/dist/revocation/ocsp.d.ts +145 -69
- package/dist/revocation/ocsp.js +347 -297
- package/dist/revocation/ocsp.js.map +1 -1
- package/dist/revocation/revocation.d.ts +48 -36
- package/dist/revocation/revocation.js +112 -63
- package/dist/revocation/revocation.js.map +1 -1
- package/dist/revocation.d.ts +5 -5
- package/dist/revocation.js +5 -5
- package/dist/verify/identity.d.ts +18 -20
- package/dist/verify/identity.js +120 -90
- package/dist/verify/identity.js.map +1 -1
- package/dist/verify/name-constraints.d.ts +1 -4
- package/dist/verify/policy.d.ts +15 -8
- package/dist/verify/verify.d.ts +86 -46
- package/dist/verify/verify.js +309 -143
- package/dist/verify/verify.js.map +1 -1
- package/dist/verify.d.ts +3 -2
- package/dist/verify.js +4 -3
- package/dist/x509/certificate.d.ts +50 -28
- package/dist/x509/certificate.js +69 -36
- package/dist/x509/certificate.js.map +1 -1
- package/dist/x509/csr.d.ts +9 -8
- package/dist/x509/csr.js +10 -11
- package/dist/x509/csr.js.map +1 -1
- package/dist/x509/extensions.d.ts +207 -82
- package/dist/x509/extensions.js +561 -128
- package/dist/x509/extensions.js.map +1 -1
- package/dist/x509/fingerprint.d.ts +4 -7
- package/dist/x509/fingerprint.js +1 -2
- package/dist/x509/fingerprint.js.map +1 -1
- package/dist/x509/name-text.d.ts +7 -9
- package/dist/x509/name-text.js +20 -4
- package/dist/x509/name-text.js.map +1 -1
- package/dist/x509/name.d.ts +15 -14
- package/dist/x509/name.js +23 -19
- package/dist/x509/name.js.map +1 -1
- package/dist/x509/parse.d.ts +165 -64
- package/dist/x509/parse.js +444 -459
- package/dist/x509/parse.js.map +1 -1
- package/dist/x509.d.ts +8 -5
- package/dist/x509.js +10 -8
- package/package.json +90 -65
package/dist/verify/verify.js
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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
5
|
import { verifySignedDataDetailed as l } from "../internal/crypto/sig-verify.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
|
|
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 { assertPathBuildingChecks as D, authorityKeyIdentifierMismatch as O, buildChainInternal as k, countCaCertificatesBelowParsed as A, isSelfIssued as j, isWithinValidity as M, loadCertificates as N, loadSingleCertificate as P, verifyCertificateSignature as F } from "../internal/verify/verify-path.js";
|
|
16
|
+
import { matchServiceIdentity as I } from "./identity.js";
|
|
17
|
+
import { checkChainRevocation as L } from "../revocation/chain.js";
|
|
18
|
+
// src/verify/verify.ts
|
|
13
19
|
/**
|
|
14
20
|
* Public certificate and CSR verification APIs.
|
|
15
21
|
*
|
|
@@ -37,12 +43,15 @@ import { checkChainRevocation as w } from "../revocation/chain.js";
|
|
|
37
43
|
* - `ca_required` — an issuer lacks `basicConstraints.ca = true`.
|
|
38
44
|
* - `key_cert_sign_required` — an issuer has keyUsage but omits `keyCertSign`.
|
|
39
45
|
* - `path_length_exceeded` — the number of CA certificates below an issuer exceeds its pathLength.
|
|
46
|
+
* - `path_building_limit_exceeded` — candidate-path construction exceeded its bounded work limits.
|
|
40
47
|
* - `authority_key_identifier_mismatch` — a certificate's AKI does not match the issuer's SKI.
|
|
41
48
|
* - `extended_key_usage_invalid` — the leaf certificate lacks the required EKU for the requested purpose.
|
|
42
49
|
* - `subject_alt_name_mismatch` — no SAN entry matches the requested service identity.
|
|
43
50
|
* - `common_name_fallback_suppressed` — CN fallback was attempted but suppressed (SAN present or disabled).
|
|
44
51
|
* - `self_signed_leaf_not_allowed` — the leaf is self-signed and `allowSelfSignedLeaf` was not set.
|
|
45
52
|
* - `unrecognized_critical_extension` — a certificate contains a critical extension the verifier cannot process.
|
|
53
|
+
* - `no_rev_avail_conflict` — a certificate carries noRevAvail alongside a CA basicConstraints, cRLDistributionPoints, freshestCRL, or an id-ad-ocsp authorityInfoAccess entry (RFC 9608 §3).
|
|
54
|
+
* - `display_text_oversized` — under `rejectOversizedDisplayText`, a certificate's user notice `explicitText` or `noticeRef` organization exceeds the 200 characters of RFC 5280 §4.2.1.4.
|
|
46
55
|
* - `intermediate_eku_constraint` — an intermediate CA's EKU set does not include the required purpose.
|
|
47
56
|
* - `explicit_policy_required` — `requireExplicitPolicy` was set but no acceptable policy was found.
|
|
48
57
|
* - `initial_policy_set_not_satisfied` — the chain's policies do not intersect `initialPolicySet`.
|
|
@@ -50,47 +59,54 @@ import { checkChainRevocation as w } from "../revocation/chain.js";
|
|
|
50
59
|
* - `unsupported_name_constraints` — a certificate's nameConstraints use an unsupported form.
|
|
51
60
|
* - `name_constraints_violated` — a subject name violates a permitted/excluded subtree.
|
|
52
61
|
* - `unsupported_signature_algorithm_parameters` — the signature algorithm uses unrecognized parameters.
|
|
62
|
+
* - `ec_domain_parameters_missing` — an elliptic curve public key carries no namedCurve domain parameters.
|
|
53
63
|
* - `certificate_revoked` — revocation evidence confirms a chain certificate is revoked.
|
|
54
64
|
* - `revocation_indeterminate` — revocation status could not be determined under a hard-fail policy.
|
|
65
|
+
* - `unsupported` — a certificate source holds a construct micro509 does not decode (see `ParseCertificateErrorCode`).
|
|
66
|
+
* - `limit_exceeded` — a certificate source exceeds a micro509 decoding limit (see `ParseCertificateErrorCode`).
|
|
55
67
|
*/
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
"initial_policy_set_not_satisfied",
|
|
73
|
-
"unsupported_initial_name_constraints",
|
|
74
|
-
"unsupported_name_constraints",
|
|
75
|
-
"name_constraints_violated",
|
|
76
|
-
"unsupported_signature_algorithm_parameters",
|
|
77
|
-
"certificate_revoked",
|
|
78
|
-
"revocation_indeterminate"
|
|
79
|
-
], E = /* @__PURE__ */ new Set([
|
|
80
|
-
e.basicConstraints,
|
|
81
|
-
e.keyUsage,
|
|
82
|
-
e.extendedKeyUsage,
|
|
83
|
-
e.subjectAltName,
|
|
84
|
-
e.nameConstraints,
|
|
85
|
-
e.authorityKeyIdentifier,
|
|
86
|
-
e.subjectKeyIdentifier,
|
|
87
|
-
e.authorityInfoAccess,
|
|
88
|
-
e.cRLDistributionPoints,
|
|
89
|
-
e.certificatePolicies,
|
|
90
|
-
e.policyMappings,
|
|
91
|
-
e.policyConstraints,
|
|
92
|
-
e.inhibitAnyPolicy
|
|
68
|
+
const R = /* @__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.certificate_revoked.revocation_indeterminate.unsupported.limit_exceeded".split("."), z = /* @__PURE__ */ new Set([
|
|
69
|
+
c.basicConstraints,
|
|
70
|
+
c.keyUsage,
|
|
71
|
+
c.extendedKeyUsage,
|
|
72
|
+
c.subjectAltName,
|
|
73
|
+
c.issuerAltName,
|
|
74
|
+
c.nameConstraints,
|
|
75
|
+
c.authorityKeyIdentifier,
|
|
76
|
+
c.subjectKeyIdentifier,
|
|
77
|
+
c.authorityInfoAccess,
|
|
78
|
+
c.cRLDistributionPoints,
|
|
79
|
+
c.certificatePolicies,
|
|
80
|
+
c.policyMappings,
|
|
81
|
+
c.policyConstraints,
|
|
82
|
+
c.inhibitAnyPolicy,
|
|
83
|
+
c.noRevAvail
|
|
93
84
|
]);
|
|
85
|
+
function loadCertificatePool(e, t) {
|
|
86
|
+
let n = [];
|
|
87
|
+
for (let [r, i] of e.entries()) try {
|
|
88
|
+
n.push(...N([i]));
|
|
89
|
+
} catch (e) {
|
|
90
|
+
return certificateSourceFailure(e, {
|
|
91
|
+
kind: t,
|
|
92
|
+
position: r
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
ok: !0,
|
|
97
|
+
certificates: n
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function certificateSourceFailure(t, n) {
|
|
101
|
+
let r = a(t, e);
|
|
102
|
+
return r === void 0 ? failure("issuer_not_found", "certificate source is malformed or leaf source does not contain exactly one certificate", 0, detail({
|
|
103
|
+
actual: t instanceof Error ? t.message : "certificate source is malformed",
|
|
104
|
+
source: n
|
|
105
|
+
})) : failure(r.code, r.message, 0, detail({
|
|
106
|
+
actual: r.message,
|
|
107
|
+
source: n
|
|
108
|
+
}));
|
|
109
|
+
}
|
|
94
110
|
/**
|
|
95
111
|
* Discovers and signature-verifies a candidate certification path from a
|
|
96
112
|
* leaf certificate to a trusted root or trust anchor. Does NOT validate
|
|
@@ -98,16 +114,21 @@ const T = [
|
|
|
98
114
|
* for that, or {@linkcode verifyCertificateChain} for the all-in-one API.
|
|
99
115
|
*/
|
|
100
116
|
async function buildCandidatePathRaw(e) {
|
|
101
|
-
|
|
117
|
+
D(e.maxPathBuildingChecks);
|
|
118
|
+
let t;
|
|
102
119
|
try {
|
|
103
|
-
t =
|
|
120
|
+
t = P(e.leaf);
|
|
104
121
|
} catch (e) {
|
|
105
|
-
return
|
|
122
|
+
return certificateSourceFailure(e, void 0);
|
|
106
123
|
}
|
|
107
|
-
let
|
|
124
|
+
let n = loadCertificatePool(e.intermediates ?? [], "intermediates");
|
|
125
|
+
if (!n.ok) return n;
|
|
126
|
+
let r = loadCertificatePool(e.roots, "roots");
|
|
127
|
+
if (!r.ok) return r;
|
|
128
|
+
let i = e.trustAnchors ?? [], a = e.at ?? /* @__PURE__ */ new Date(), o = await k(t, n.certificates, r.certificates, i, a, {
|
|
108
129
|
failure,
|
|
109
130
|
detail
|
|
110
|
-
}), s = o.chain;
|
|
131
|
+
}, void 0, e.maxPathBuildingChecks), s = o.chain;
|
|
111
132
|
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;
|
|
112
133
|
let c = s[s.length - 1];
|
|
113
134
|
return c === void 0 ? failure("no_trusted_root", "no trusted root found") : {
|
|
@@ -159,27 +180,55 @@ async function validateCandidatePathRaw(e) {
|
|
|
159
180
|
if (!r.ok) return r;
|
|
160
181
|
let i = t[0];
|
|
161
182
|
if (i === void 0) return failure("issuer_not_found", "chain is empty", 0);
|
|
162
|
-
let a = validateSelfSignedLeafAllowed(i, t.length, e);
|
|
183
|
+
let a = await validateSelfSignedLeafAllowed(i, t.length, e);
|
|
163
184
|
if (a !== void 0) return a;
|
|
164
|
-
let o = await validatePathCertificates(t, n);
|
|
185
|
+
let o = await validatePathCertificates(t, n, e.rejectOversizedDisplayText === !0);
|
|
165
186
|
if (o !== void 0) return o;
|
|
166
187
|
let s = validatePathLengthConstraints(t);
|
|
167
188
|
if (s !== void 0) return s;
|
|
168
189
|
let c = validatePolicyAndNameConstraints(t, r.value, e.anchorCertificateInChain ?? !0);
|
|
169
190
|
return c.ok ? validateLeaf(i, e, c.policyValidation) : c;
|
|
170
191
|
}
|
|
171
|
-
|
|
172
|
-
|
|
192
|
+
/** RFC 5280 §3.2 makes a self-issued certificate self-signed only when the public key it binds verifies its signature. */
|
|
193
|
+
async function validateSelfSignedLeafAllowed(e, t, n) {
|
|
194
|
+
if (t !== 1 || !j(e) || n.allowSelfSignedLeaf === !0) return;
|
|
195
|
+
let r = await F(e, e);
|
|
196
|
+
if (r.ok && r.valid) return failure("self_signed_leaf_not_allowed", "self-signed leaf not allowed", 0, detail({ subjectCommonName: e.subject.values.commonName }));
|
|
173
197
|
}
|
|
174
198
|
/** Validates every certificate and issuer relationship in a candidate path. */
|
|
175
|
-
async function validatePathCertificates(e, t) {
|
|
176
|
-
for (let
|
|
177
|
-
let
|
|
178
|
-
if (
|
|
179
|
-
let
|
|
180
|
-
if (i !== void 0) return i;
|
|
181
|
-
let a = await validatePathIssuerAtIndex(e, r, n);
|
|
199
|
+
async function validatePathCertificates(e, t, n) {
|
|
200
|
+
for (let r = 0; r < e.length; r += 1) {
|
|
201
|
+
let i = e[r];
|
|
202
|
+
if (i === void 0) return failure("issuer_not_found", "chain element missing", r);
|
|
203
|
+
let a = validateCertificateAtPathIndex(i, r, t);
|
|
182
204
|
if (a !== void 0) return a;
|
|
205
|
+
if (n) {
|
|
206
|
+
let e = validateDisplayTextAtPathIndex(i, r);
|
|
207
|
+
if (e !== void 0) return e;
|
|
208
|
+
}
|
|
209
|
+
let o = await validatePathIssuerAtIndex(e, i, r);
|
|
210
|
+
if (o !== void 0) return o;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/** RFC 5280 §4.2.1.4 bounds a DisplayText at 200 characters; PKITS 4.8.19 lets the application reject a longer explicitText. */
|
|
214
|
+
function validateDisplayTextAtPathIndex(e, t) {
|
|
215
|
+
for (let n of e.certificatePolicies ?? []) for (let r of n.policyQualifiers ?? []) {
|
|
216
|
+
if (r.type !== "userNotice") continue;
|
|
217
|
+
let i = [[
|
|
218
|
+
"explicitText",
|
|
219
|
+
"explicitText",
|
|
220
|
+
r.oversizedExplicitText
|
|
221
|
+
], [
|
|
222
|
+
"noticeRefOrganization",
|
|
223
|
+
"noticeRef organization",
|
|
224
|
+
r.noticeRef?.oversizedOrganization
|
|
225
|
+
]];
|
|
226
|
+
for (let [r, a, o] of i) if (o !== void 0) return failure("display_text_oversized", `certificate policy ${n.policyIdentifier} carries a user notice ${a} of ${String(o.characters)} characters`, t, detail({
|
|
227
|
+
subjectCommonName: e.subject.values.commonName,
|
|
228
|
+
expected: String(o.limit),
|
|
229
|
+
actual: String(o.characters),
|
|
230
|
+
userNoticeField: r
|
|
231
|
+
}));
|
|
183
232
|
}
|
|
184
233
|
}
|
|
185
234
|
async function validatePathIssuerAtIndex(e, t, n) {
|
|
@@ -191,7 +240,7 @@ function validatePathLengthConstraints(e) {
|
|
|
191
240
|
for (let t = 1; t < e.length; t += 1) {
|
|
192
241
|
let n = e[t];
|
|
193
242
|
if (n === void 0) return failure("issuer_not_found", "chain element missing", t);
|
|
194
|
-
let r =
|
|
243
|
+
let r = A(e, t), i = n.basicConstraints?.pathLength;
|
|
195
244
|
if (isNonNegativeInteger(i) && r > i) return pathLengthExceededFailure(n, t, i, r);
|
|
196
245
|
}
|
|
197
246
|
}
|
|
@@ -203,19 +252,19 @@ function pathLengthExceededFailure(e, t, n, r) {
|
|
|
203
252
|
}));
|
|
204
253
|
}
|
|
205
254
|
function validatePolicyAndNameConstraints(e, t, n) {
|
|
206
|
-
let r =
|
|
255
|
+
let r = E(e, t.policy, n);
|
|
207
256
|
if (!r.ok) return failure(r.error.code, r.error.message, 0, detail({
|
|
208
257
|
expected: r.error.details?.expected,
|
|
209
258
|
actual: r.error.details?.actual
|
|
210
259
|
}));
|
|
211
|
-
let i =
|
|
260
|
+
let i = w(e, t.nameConstraints);
|
|
212
261
|
return i.ok ? {
|
|
213
262
|
ok: !0,
|
|
214
263
|
policyValidation: r.value
|
|
215
264
|
} : i;
|
|
216
265
|
}
|
|
217
266
|
function validateCertificateAtPathIndex(e, t, n) {
|
|
218
|
-
if (!
|
|
267
|
+
if (!M(e, n)) return failure("certificate_expired", "certificate not valid at requested time", t, detail({
|
|
219
268
|
subjectCommonName: e.subject.values.commonName,
|
|
220
269
|
expected: describeDateTime(n),
|
|
221
270
|
actual: `${describeDateTime(e.notBefore)}..${describeDateTime(e.notAfter)}`
|
|
@@ -225,13 +274,42 @@ function validateCertificateAtPathIndex(e, t, n) {
|
|
|
225
274
|
subjectCommonName: e.subject.values.commonName,
|
|
226
275
|
actual: r
|
|
227
276
|
}));
|
|
277
|
+
let i = findNoRevAvailConflict(e);
|
|
278
|
+
return i === void 0 ? validateEcDomainParametersAtPathIndex(e, t) : failure("no_rev_avail_conflict", `certificate carries noRevAvail with ${i}`, t, detail({
|
|
279
|
+
subjectCommonName: e.subject.values.commonName,
|
|
280
|
+
actual: i
|
|
281
|
+
}));
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* RFC 9608 §3: a relying party MUST consider a certificate carrying noRevAvail
|
|
285
|
+
* invalid when it also asserts cA, points at a CRL, or names an OCSP responder.
|
|
286
|
+
*/
|
|
287
|
+
function findNoRevAvailConflict(e) {
|
|
288
|
+
if (e.noRevAvail === !0) {
|
|
289
|
+
if (e.basicConstraints?.ca === !0) return "basicConstraints cA TRUE";
|
|
290
|
+
if (e.crlDistributionPoints !== void 0) return "cRLDistributionPoints";
|
|
291
|
+
if (e.extensions.some((e) => e.oid === c.freshestCRL)) return "freshestCRL";
|
|
292
|
+
if (e.authorityInfoAccess?.some((e) => e.method === "ocsp") === !0) return "an id-ad-ocsp authorityInfoAccess entry";
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* RFC 5480 §2.1.1 admits only the namedCurve alternative of ECParameters, and
|
|
297
|
+
* requires clients to reject a certificate whose elliptic curve domain
|
|
298
|
+
* parameters are not present.
|
|
299
|
+
*/
|
|
300
|
+
function validateEcDomainParametersAtPathIndex(e, t) {
|
|
301
|
+
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({
|
|
302
|
+
subjectCommonName: e.subject.values.commonName,
|
|
303
|
+
expected: "namedCurve OBJECT IDENTIFIER",
|
|
304
|
+
actual: e.publicKeyAlgorithmParametersDer === void 0 ? "absent" : `tag 0x${(e.publicKeyAlgorithmParametersDer[0] ?? 0).toString(16).padStart(2, "0")}`
|
|
305
|
+
}));
|
|
228
306
|
}
|
|
229
307
|
async function validateIssuerAtPathIndex(e, t, n) {
|
|
230
|
-
if (!
|
|
308
|
+
if (!v(e.issuer, t.subject)) return failure("issuer_not_found", "issuer distinguished name does not match the candidate issuer subject", n, detail({
|
|
231
309
|
subjectCommonName: e.subject.values.commonName,
|
|
232
310
|
issuerCommonName: t.subject.values.commonName
|
|
233
311
|
}));
|
|
234
|
-
let r = await
|
|
312
|
+
let r = await F(e, t);
|
|
235
313
|
return r.ok ? r.valid ? validateIssuerConstraintsAtPathIndex(e, t, n) : failure("signature_invalid", "certificate signature does not verify", n, detail({
|
|
236
314
|
subjectCommonName: e.subject.values.commonName,
|
|
237
315
|
issuerCommonName: t.subject.values.commonName
|
|
@@ -244,7 +322,7 @@ async function validateIssuerAtPathIndex(e, t, n) {
|
|
|
244
322
|
function validateIssuerConstraintsAtPathIndex(e, t, n) {
|
|
245
323
|
if (t.basicConstraints?.ca !== !0) return failure("ca_required", "issuer must be a CA certificate", n + 1, detail({ subjectCommonName: t.subject.values.commonName }));
|
|
246
324
|
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 }));
|
|
247
|
-
if (
|
|
325
|
+
if (O(e, t)) return failure("authority_key_identifier_mismatch", "authorityKeyIdentifier does not match issuer subjectKeyIdentifier", n, detail({
|
|
248
326
|
subjectCommonName: e.subject.values.commonName,
|
|
249
327
|
issuerCommonName: t.subject.values.commonName,
|
|
250
328
|
expected: t.subjectKeyIdentifier,
|
|
@@ -255,18 +333,17 @@ function validateIssuerConstraintsAtPathIndex(e, t, n) {
|
|
|
255
333
|
* Validates a pre-built certificate chain for time, constraints, policy, and
|
|
256
334
|
* optionally leaf purpose. Wrap the result of {@linkcode buildCandidatePath}.
|
|
257
335
|
*/
|
|
258
|
-
async function validateCandidatePath(
|
|
259
|
-
let t;
|
|
260
|
-
|
|
261
|
-
t =
|
|
262
|
-
|
|
263
|
-
return verifyFailureResult(failure("signature_invalid", "certificate input is malformed", 0, detail({ actual: e instanceof Error ? e.message : "certificate input is malformed" })));
|
|
336
|
+
async function validateCandidatePath(t) {
|
|
337
|
+
let n = normalizeValidationChain(t.chain);
|
|
338
|
+
if (!n.ok) {
|
|
339
|
+
let { error: t, index: r } = n, i = a(t, e);
|
|
340
|
+
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 })));
|
|
264
341
|
}
|
|
265
|
-
let
|
|
266
|
-
...
|
|
267
|
-
chain:
|
|
342
|
+
let r = await validateCandidatePathRaw({
|
|
343
|
+
...t,
|
|
344
|
+
chain: n.chain
|
|
268
345
|
});
|
|
269
|
-
return
|
|
346
|
+
return r.ok ? validateCandidatePathSuccessResult(r.policyValidation) : verifyFailureResult(r);
|
|
270
347
|
}
|
|
271
348
|
/**
|
|
272
349
|
* All-in-one certificate chain verification: builds a candidate path then
|
|
@@ -292,12 +369,14 @@ async function validateCandidatePath(e) {
|
|
|
292
369
|
* ```
|
|
293
370
|
*/
|
|
294
371
|
async function verifyCertificateChain(e) {
|
|
372
|
+
S(e.revocation?.policy?.crlMaxAgeMs);
|
|
295
373
|
let t = await buildCandidatePath({
|
|
296
374
|
leaf: e.leaf,
|
|
297
375
|
roots: e.roots,
|
|
298
376
|
...e.intermediates !== void 0 && { intermediates: e.intermediates },
|
|
299
377
|
...e.trustAnchors !== void 0 && { trustAnchors: e.trustAnchors },
|
|
300
|
-
...e.at !== void 0 && { at: e.at }
|
|
378
|
+
...e.at !== void 0 && { at: e.at },
|
|
379
|
+
...e.maxPathBuildingChecks !== void 0 && { maxPathBuildingChecks: e.maxPathBuildingChecks }
|
|
301
380
|
});
|
|
302
381
|
if (!t.ok) return t;
|
|
303
382
|
let n = await validateCandidatePath({
|
|
@@ -306,7 +385,8 @@ async function verifyCertificateChain(e) {
|
|
|
306
385
|
...e.at !== void 0 && { at: e.at },
|
|
307
386
|
...e.purpose !== void 0 && { purpose: e.purpose },
|
|
308
387
|
...copyValidationInputs(e),
|
|
309
|
-
...e.allowSelfSignedLeaf !== void 0 && { allowSelfSignedLeaf: e.allowSelfSignedLeaf }
|
|
388
|
+
...e.allowSelfSignedLeaf !== void 0 && { allowSelfSignedLeaf: e.allowSelfSignedLeaf },
|
|
389
|
+
...e.rejectOversizedDisplayText !== void 0 && { rejectOversizedDisplayText: e.rejectOversizedDisplayText }
|
|
310
390
|
});
|
|
311
391
|
if (!n.ok) return n;
|
|
312
392
|
if (e.serviceIdentity !== void 0) {
|
|
@@ -328,7 +408,7 @@ async function verifyCertificateChain(e) {
|
|
|
328
408
|
/** Applies optional revocation evidence to an otherwise verified certificate chain. */
|
|
329
409
|
async function validateVerifiedChainRevocation(e, t) {
|
|
330
410
|
if (e.revocation === void 0) return;
|
|
331
|
-
let n = await
|
|
411
|
+
let n = await L({
|
|
332
412
|
chain: t,
|
|
333
413
|
...e.revocation.crls === void 0 ? {} : { crls: e.revocation.crls },
|
|
334
414
|
...e.revocation.ocspResponses === void 0 ? {} : { ocspResponses: e.revocation.ocspResponses },
|
|
@@ -364,28 +444,33 @@ function revocationFailureResult(e) {
|
|
|
364
444
|
* }
|
|
365
445
|
* ```
|
|
366
446
|
*/
|
|
367
|
-
async function verifyCertificateSigningRequest(
|
|
368
|
-
let
|
|
447
|
+
async function verifyCertificateSigningRequest(t) {
|
|
448
|
+
let n;
|
|
369
449
|
try {
|
|
370
|
-
|
|
371
|
-
} catch (
|
|
372
|
-
|
|
450
|
+
n = typeof t == "string" ? x(t) : b(new Uint8Array(t));
|
|
451
|
+
} catch (t) {
|
|
452
|
+
let n = a(t, e);
|
|
453
|
+
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 }));
|
|
373
454
|
}
|
|
374
|
-
let
|
|
455
|
+
let r;
|
|
375
456
|
try {
|
|
376
|
-
|
|
377
|
-
} catch (
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
457
|
+
r = await l(n.signatureAlgorithmOid, n.signatureAlgorithmParametersDer, n.publicKeyAlgorithmOid, n.publicKeyParametersOid, n.subjectPublicKeyInfoDer, n.signatureValue, n.certificationRequestInfoDer);
|
|
458
|
+
} catch (t) {
|
|
459
|
+
let r = a(t, e);
|
|
460
|
+
return r === void 0 ? verifyRequestFailureResult("signature_invalid", "certificate request input is malformed", detail({
|
|
461
|
+
subjectCommonName: n.subject.values.commonName,
|
|
462
|
+
actual: t instanceof Error ? t.message : "certificate request input is malformed"
|
|
463
|
+
})) : verifyRequestFailureResult(r.code, r.message, detail({
|
|
464
|
+
subjectCommonName: n.subject.values.commonName,
|
|
465
|
+
actual: r.message
|
|
381
466
|
}));
|
|
382
467
|
}
|
|
383
|
-
return
|
|
468
|
+
return r.ok ? r.valid ? {
|
|
384
469
|
ok: !0,
|
|
385
|
-
value:
|
|
386
|
-
} : verifyRequestFailureResult("signature_invalid", "certificate request signature does not verify", detail({ subjectCommonName:
|
|
387
|
-
subjectCommonName:
|
|
388
|
-
actual:
|
|
470
|
+
value: n
|
|
471
|
+
} : 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({
|
|
472
|
+
subjectCommonName: n.subject.values.commonName,
|
|
473
|
+
actual: r.reason
|
|
389
474
|
}));
|
|
390
475
|
}
|
|
391
476
|
/**
|
|
@@ -403,19 +488,18 @@ async function verifyCertificateSigningRequest(e) {
|
|
|
403
488
|
* }
|
|
404
489
|
* ```
|
|
405
490
|
*/
|
|
406
|
-
function checkExtendedKeyUsage(
|
|
407
|
-
let
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
return ekuCheckFailureResult("leaf_eku_missing", "certificate input is malformed", 0);
|
|
491
|
+
function checkExtendedKeyUsage(t, n) {
|
|
492
|
+
let r = normalizeValidationChain(t);
|
|
493
|
+
if (!r.ok) {
|
|
494
|
+
let t = a(r.error, e);
|
|
495
|
+
return t === void 0 ? ekuCheckFailureResult("leaf_eku_missing", "certificate input is malformed", r.index) : ekuCheckFailureResult(t.code, t.message, r.index);
|
|
412
496
|
}
|
|
413
|
-
let r =
|
|
414
|
-
if (
|
|
415
|
-
if (
|
|
416
|
-
for (let e = 1; e <
|
|
417
|
-
let
|
|
418
|
-
if (
|
|
497
|
+
let i = r.chain, o = i[0];
|
|
498
|
+
if (o === void 0) return ekuCheckFailureResult("leaf_eku_missing", "chain is empty", 0);
|
|
499
|
+
if (o.extendedKeyUsage !== void 0 && !o.extendedKeyUsage.includes(n)) return ekuCheckFailureResult("leaf_eku_missing", `leaf certificate does not include EKU ${n}`, 0);
|
|
500
|
+
for (let e = 1; e < i.length; e += 1) {
|
|
501
|
+
let t = i[e];
|
|
502
|
+
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);
|
|
419
503
|
}
|
|
420
504
|
return {
|
|
421
505
|
ok: !0,
|
|
@@ -423,19 +507,19 @@ function checkExtendedKeyUsage(e, t) {
|
|
|
423
507
|
};
|
|
424
508
|
}
|
|
425
509
|
/** Extracts a {@linkcode TrustAnchor} from a parsed certificate, copying the subject, SPKI, and key identifiers. */
|
|
426
|
-
function trustAnchorFromCertificate(
|
|
427
|
-
let
|
|
510
|
+
function trustAnchorFromCertificate(t) {
|
|
511
|
+
let n;
|
|
428
512
|
try {
|
|
429
|
-
|
|
430
|
-
} catch {
|
|
431
|
-
throw Error("certificate input is malformed");
|
|
513
|
+
n = reparseCertificateForTrust(t);
|
|
514
|
+
} catch (t) {
|
|
515
|
+
throw o(t, e), Error("certificate input is malformed");
|
|
432
516
|
}
|
|
433
517
|
return {
|
|
434
|
-
subject:
|
|
435
|
-
subjectPublicKeyInfoDer:
|
|
436
|
-
publicKeyAlgorithmOid:
|
|
437
|
-
...
|
|
438
|
-
...
|
|
518
|
+
subject: n.subject,
|
|
519
|
+
subjectPublicKeyInfoDer: n.subjectPublicKeyInfoDer,
|
|
520
|
+
publicKeyAlgorithmOid: n.publicKeyAlgorithmOid,
|
|
521
|
+
...n.publicKeyParametersOid === void 0 ? {} : { publicKeyParametersOid: n.publicKeyParametersOid },
|
|
522
|
+
...n.subjectKeyIdentifier === void 0 ? {} : { subjectKeyIdentifier: n.subjectKeyIdentifier }
|
|
439
523
|
};
|
|
440
524
|
}
|
|
441
525
|
/** Extracts defined optional fields from a base input for safe forwarding. */
|
|
@@ -446,6 +530,7 @@ function baseChainInput(e) {
|
|
|
446
530
|
...e.intermediates !== void 0 && { intermediates: e.intermediates },
|
|
447
531
|
...e.trustAnchors !== void 0 && { trustAnchors: e.trustAnchors },
|
|
448
532
|
...e.at !== void 0 && { at: e.at },
|
|
533
|
+
...e.maxPathBuildingChecks !== void 0 && { maxPathBuildingChecks: e.maxPathBuildingChecks },
|
|
449
534
|
...copyValidationInputs(e)
|
|
450
535
|
};
|
|
451
536
|
}
|
|
@@ -552,7 +637,7 @@ function validateLeaf(e, t, n) {
|
|
|
552
637
|
function validateServiceIdentity(e, t) {
|
|
553
638
|
let n = validateServiceIdentityInput(t);
|
|
554
639
|
if (!n.ok) return n;
|
|
555
|
-
let r =
|
|
640
|
+
let r = I({
|
|
556
641
|
certificate: reparseCertificateForTrust(e),
|
|
557
642
|
serviceIdentity: t
|
|
558
643
|
});
|
|
@@ -564,7 +649,7 @@ function validateServiceIdentity(e, t) {
|
|
|
564
649
|
message: i.message,
|
|
565
650
|
index: 0,
|
|
566
651
|
...i.details === void 0 ? {} : { details: i.details }
|
|
567
|
-
} : i.code !== "subject_alt_name_mismatch" && i.code !== "common_name_fallback_suppressed" ? failure("subject_alt_name_mismatch", "service identity input is malformed", 0, detail({
|
|
652
|
+
} : 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({
|
|
568
653
|
expected: t.value,
|
|
569
654
|
actual: i.code
|
|
570
655
|
})) : {
|
|
@@ -580,7 +665,7 @@ function validateServiceIdentityInput(e) {
|
|
|
580
665
|
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) }));
|
|
581
666
|
if (typeof e.value != "string") return failure("subject_alt_name_mismatch", "service identity input is malformed", 0, detail({ actual: e.type }));
|
|
582
667
|
if (e.type === "ip") try {
|
|
583
|
-
|
|
668
|
+
f(e.value);
|
|
584
669
|
} catch {
|
|
585
670
|
return failure("subject_alt_name_mismatch", "service identity input is malformed", 0, detail({
|
|
586
671
|
expected: e.value,
|
|
@@ -601,7 +686,22 @@ async function verifyChainForExtendedKeyUsageProfile(e, t) {
|
|
|
601
686
|
}
|
|
602
687
|
/** Returns the OID of the first critical extension not in {@linkcode PROCESSED_EXTENSION_OIDS}, or `undefined`. */
|
|
603
688
|
function findUnprocessedCriticalExtension(e) {
|
|
604
|
-
for (let t of e.extensions) if (t.critical && !
|
|
689
|
+
for (let t of e.extensions) if (t.critical && (!z.has(t.oid) || t.oid === c.subjectAltName && e.subjectAltNames?.some(isUninterpretedGeneralName) === !0)) return t.oid;
|
|
690
|
+
}
|
|
691
|
+
const B = /* @__PURE__ */ new Set([
|
|
692
|
+
"otherName",
|
|
693
|
+
"upn",
|
|
694
|
+
"krb5PrincipalName",
|
|
695
|
+
"x400Address",
|
|
696
|
+
"ediPartyName",
|
|
697
|
+
"unknown"
|
|
698
|
+
]);
|
|
699
|
+
function isUninterpretedGeneralName(e) {
|
|
700
|
+
switch (e.type) {
|
|
701
|
+
case "srv": return h(u(e.value)) === void 0;
|
|
702
|
+
case "smtpUtf8Mailbox": return p(e.value) === void 0;
|
|
703
|
+
default: return B.has(e.type);
|
|
704
|
+
}
|
|
605
705
|
}
|
|
606
706
|
/** Constructs a {@linkcode VerifyChainFailure} with the given code, message, optional chain index, and details. */
|
|
607
707
|
function failure(e, t, n, i) {
|
|
@@ -626,10 +726,23 @@ function describeDateTime(e) {
|
|
|
626
726
|
return Number.isNaN(e.getTime()) ? "<invalid date>" : e.toISOString();
|
|
627
727
|
}
|
|
628
728
|
function normalizeValidationChain(e) {
|
|
629
|
-
|
|
729
|
+
let t = [];
|
|
730
|
+
for (let [n, r] of e.entries()) try {
|
|
731
|
+
t.push(reparseCertificateForTrust(r));
|
|
732
|
+
} catch (e) {
|
|
733
|
+
return {
|
|
734
|
+
ok: !1,
|
|
735
|
+
index: n,
|
|
736
|
+
error: e
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
return {
|
|
740
|
+
ok: !0,
|
|
741
|
+
chain: t
|
|
742
|
+
};
|
|
630
743
|
}
|
|
631
744
|
function reparseCertificateForTrust(e) {
|
|
632
|
-
return
|
|
745
|
+
return y(new Uint8Array(e.der));
|
|
633
746
|
}
|
|
634
747
|
/** Returns `true` if the value is a non-negative integer (including zero). */
|
|
635
748
|
function isNonNegativeInteger(e) {
|
|
@@ -637,18 +750,20 @@ function isNonNegativeInteger(e) {
|
|
|
637
750
|
}
|
|
638
751
|
/** Constructs a CSR verification failure result. */
|
|
639
752
|
function verifyRequestFailureResult(e, n, r) {
|
|
640
|
-
|
|
753
|
+
let a = {
|
|
641
754
|
ok: !1,
|
|
642
755
|
...i(e, n, r)
|
|
643
|
-
}
|
|
756
|
+
};
|
|
757
|
+
return t(a);
|
|
644
758
|
}
|
|
645
759
|
/** Constructs an EKU check failure result at the given chain index. */
|
|
646
760
|
function ekuCheckFailureResult(e, t, i) {
|
|
647
|
-
|
|
761
|
+
let a = {
|
|
648
762
|
ok: !1,
|
|
649
763
|
...r(e, t, i),
|
|
650
764
|
index: i
|
|
651
|
-
}
|
|
765
|
+
};
|
|
766
|
+
return n(a);
|
|
652
767
|
}
|
|
653
768
|
/** Merges flat and nested policy fields, with nested taking precedence. */
|
|
654
769
|
function resolvePolicyValidationInput(e) {
|
|
@@ -711,22 +826,36 @@ function detail(e) {
|
|
|
711
826
|
...e.actual === void 0 ? {} : { actual: e.actual },
|
|
712
827
|
...e.chainCommonNames === void 0 ? {} : { chainCommonNames: e.chainCommonNames },
|
|
713
828
|
...e.presentedIdentifierTypes === void 0 ? {} : { presentedIdentifierTypes: e.presentedIdentifierTypes },
|
|
714
|
-
...e.commonNameFallbackReason === void 0 ? {} : { commonNameFallbackReason: e.commonNameFallbackReason }
|
|
829
|
+
...e.commonNameFallbackReason === void 0 ? {} : { commonNameFallbackReason: e.commonNameFallbackReason },
|
|
830
|
+
...e.userNoticeField === void 0 ? {} : { userNoticeField: e.userNoticeField },
|
|
831
|
+
...e.source === void 0 ? {} : { source: e.source }
|
|
715
832
|
};
|
|
716
833
|
}
|
|
717
834
|
/** Initializes policy and name-constraint validation state for a chain walk. */
|
|
718
835
|
function buildValidationState(e, t) {
|
|
719
|
-
let n =
|
|
836
|
+
let n = T(resolvePolicyValidationInput(e), t), r = validateInitialNameConstraintsInput(resolveInitialNameConstraintsInput(e));
|
|
720
837
|
return r.ok ? {
|
|
721
838
|
ok: !0,
|
|
722
839
|
value: {
|
|
723
840
|
policy: n,
|
|
724
|
-
nameConstraints:
|
|
841
|
+
nameConstraints: C(r.value)
|
|
725
842
|
}
|
|
726
843
|
} : r;
|
|
727
844
|
}
|
|
728
845
|
function normalizeInitialPolicySet(e) {
|
|
729
|
-
if (e
|
|
846
|
+
if (e === void 0) return;
|
|
847
|
+
if (e === "any") return e;
|
|
848
|
+
if (!Array.isArray(e)) return [];
|
|
849
|
+
let t = [];
|
|
850
|
+
for (let n of e) {
|
|
851
|
+
if (typeof n != "string") return [];
|
|
852
|
+
try {
|
|
853
|
+
t.push(s(n));
|
|
854
|
+
} catch {
|
|
855
|
+
return [];
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
return t.includes(c.anyPolicy) ? "any" : t;
|
|
730
859
|
}
|
|
731
860
|
function validateInitialNameConstraintsInput(e) {
|
|
732
861
|
let t = validateInitialNameConstraintSubtrees(e.permittedSubtrees, "permittedSubtrees");
|
|
@@ -734,26 +863,64 @@ function validateInitialNameConstraintsInput(e) {
|
|
|
734
863
|
let n = validateInitialNameConstraintSubtrees(e.excludedSubtrees, "excludedSubtrees");
|
|
735
864
|
return n.ok ? {
|
|
736
865
|
ok: !0,
|
|
737
|
-
value:
|
|
866
|
+
value: {
|
|
867
|
+
...t.value === void 0 ? {} : { permittedSubtrees: t.value },
|
|
868
|
+
...n.value === void 0 ? {} : { excludedSubtrees: n.value }
|
|
869
|
+
}
|
|
738
870
|
} : n;
|
|
739
871
|
}
|
|
740
872
|
function validateInitialNameConstraintSubtrees(e, t) {
|
|
741
873
|
if (e === void 0) return { ok: !0 };
|
|
742
874
|
if (!Array.isArray(e)) return invalidInitialNameConstraintsFailure(t);
|
|
875
|
+
let n = [];
|
|
743
876
|
for (let t of e) {
|
|
744
877
|
let e = describeInvalidInitialNameConstraintForm(t);
|
|
745
878
|
if (e !== void 0) return invalidInitialNameConstraintsFailure(e);
|
|
879
|
+
let r = toAsciiInitialNameConstraint(t);
|
|
880
|
+
if (r === void 0) return invalidInitialNameConstraintsFailure(t.base.type);
|
|
881
|
+
n.push(r);
|
|
746
882
|
}
|
|
747
|
-
return {
|
|
883
|
+
return {
|
|
884
|
+
ok: !0,
|
|
885
|
+
value: n
|
|
886
|
+
};
|
|
887
|
+
}
|
|
888
|
+
/**
|
|
889
|
+
* RFC 9549 §1, RFC 9598 §6 and RFC 4985 §3: a DNS or mail domain constraint, or
|
|
890
|
+
* the Name of a SRVName constraint, in A-labels.
|
|
891
|
+
*/
|
|
892
|
+
function toAsciiInitialNameConstraint(e) {
|
|
893
|
+
let { base: t } = e;
|
|
894
|
+
if (t.type !== "dns" && t.type !== "email" && t.type !== "srv") return e;
|
|
895
|
+
let n = t.type === "srv" ? m(t.value) : t.value, r = unconvertedConstraintPrefix(t.type, n), i = n.slice(r.length);
|
|
896
|
+
if (t.type !== "srv" && i.endsWith(".")) return;
|
|
897
|
+
let a = t.type === "srv" && i.length === 0 ? void 0 : d(i, "lookup");
|
|
898
|
+
if (a !== void 0 && !a.ok) return;
|
|
899
|
+
let o = `${r}${a?.value ?? ""}`;
|
|
900
|
+
if (!(!/^[\x20-\x7e]*$/.test(o) || t.type === "srv" && g(o) === void 0)) return {
|
|
901
|
+
...e,
|
|
902
|
+
base: {
|
|
903
|
+
...t,
|
|
904
|
+
value: o
|
|
905
|
+
}
|
|
906
|
+
};
|
|
907
|
+
}
|
|
908
|
+
/** The leading `.` of a domain constraint, or the `_Service` label of a SRVName constraint with its dot. */
|
|
909
|
+
function unconvertedConstraintPrefix(e, t) {
|
|
910
|
+
if (e !== "srv") return t.startsWith(".") ? "." : "";
|
|
911
|
+
if (!t.startsWith("_")) return "";
|
|
912
|
+
let n = t.indexOf(".");
|
|
913
|
+
return n < 0 ? t : t.slice(0, n + 1);
|
|
748
914
|
}
|
|
749
915
|
function describeInvalidInitialNameConstraintForm(e) {
|
|
750
916
|
if (!isRecord(e)) return "invalid subtree";
|
|
751
917
|
let t = e.base;
|
|
752
918
|
if (!isRecord(t) || typeof t.type != "string") return "invalid subtree";
|
|
753
919
|
switch (t.type) {
|
|
754
|
-
case "dns":
|
|
755
|
-
case "
|
|
756
|
-
case "
|
|
920
|
+
case "dns": return typeof t.value == "string" ? void 0 : t.type;
|
|
921
|
+
case "uri": return typeof t.value == "string" && _(t.value) !== void 0 ? void 0 : t.type;
|
|
922
|
+
case "email": return typeof t.value == "string" && !t.value.includes("@") ? void 0 : t.type;
|
|
923
|
+
case "srv": return typeof t.value == "string" && t.value.length > 0 ? void 0 : t.type;
|
|
757
924
|
case "directoryName": return typeof t.derHex == "string" ? void 0 : t.type;
|
|
758
925
|
case "ip": return t.addressBytes instanceof Uint8Array && t.maskBytes instanceof Uint8Array ? void 0 : t.type;
|
|
759
926
|
case "otherName":
|
|
@@ -769,7 +936,6 @@ function invalidInitialNameConstraintsFailure(e) {
|
|
|
769
936
|
function isRecord(e) {
|
|
770
937
|
return typeof e == "object" && !!e;
|
|
771
938
|
}
|
|
772
|
-
|
|
773
|
-
export { T as VERIFY_ERROR_CODES, buildCandidatePath, checkExtendedKeyUsage, trustAnchorFromCertificate, validateCandidatePath, validateForCa, validateForCodeSigning, validateForTlsClient, validateForTlsServer, verifyCertificateChain, verifyCertificateSigningRequest };
|
|
939
|
+
export { R as VERIFY_ERROR_CODES, buildCandidatePath, checkExtendedKeyUsage, j as isSelfIssuedCertificate, trustAnchorFromCertificate, validateCandidatePath, validateForCa, validateForCodeSigning, validateForTlsClient, validateForTlsServer, verifyCertificateChain, verifyCertificateSigningRequest };
|
|
774
940
|
|
|
775
941
|
//# sourceMappingURL=verify.js.map
|