micro509 0.14.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 +105 -225
- package/dist/crypto/crypto.d.ts +42 -11
- package/dist/crypto/crypto.js +53 -22
- package/dist/crypto/crypto.js.map +1 -1
- package/dist/crypto.d.ts +2 -2
- package/dist/crypto.js +1 -2
- 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 +10 -10
- package/dist/index.js +19 -19
- package/dist/internal/asn1/asn1.d.ts +3 -6
- package/dist/internal/asn1/asn1.js +343 -43
- 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 +38 -41
- package/dist/internal/asn1/der.js +131 -52
- package/dist/internal/asn1/der.js.map +1 -1
- package/dist/internal/asn1/oids.js +83 -53
- 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 +1 -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 +24 -11
- package/dist/internal/crypto/pbes2.js +79 -26
- package/dist/internal/crypto/pbes2.js.map +1 -1
- package/dist/internal/crypto/rsa-pss.js +46 -44
- package/dist/internal/crypto/rsa-pss.js.map +1 -1
- package/dist/internal/crypto/sig-verify.d.ts +4 -7
- package/dist/internal/crypto/sig-verify.js +107 -60
- 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 +1 -2
- package/dist/internal/shared/base64.js.map +1 -1
- package/dist/internal/shared/dn.d.ts +3 -6
- package/dist/internal/shared/dn.js +99 -53
- 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 +4 -7
- package/dist/internal/shared/ip.js +1 -2
- 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 +1 -4
- package/dist/internal/verify/verify-path.js +267 -131
- package/dist/internal/verify/verify-path.js.map +1 -1
- package/dist/internal/x509/directory-name.js +1 -2
- package/dist/internal/x509/directory-name.js.map +1 -1
- package/dist/internal/x509/extension-bits.js +2 -3
- package/dist/internal/x509/extension-bits.js.map +1 -1
- package/dist/internal/x509/extension-errors.d.ts +1 -4
- package/dist/internal/x509/extension-errors.js +1 -2
- package/dist/internal/x509/extension-errors.js.map +1 -1
- package/dist/internal/x509/extension-registry.js +107 -89
- 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 +1 -2
- package/dist/internal/x509/general-name-tags.js.map +1 -1
- package/dist/internal/x509/general-name.js +128 -42
- package/dist/internal/x509/general-name.js.map +1 -1
- package/dist/internal/x509/name-fields.js +1 -2
- 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 +112 -97
- package/dist/keys/keys.js +211 -204
- package/dist/keys/keys.js.map +1 -1
- package/dist/keys.d.ts +3 -3
- package/dist/pem/pem.d.ts +14 -17
- package/dist/pem/pem.js +16 -17
- 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 +43 -37
- package/dist/pkcs/pkcs7.js +218 -217
- package/dist/pkcs/pkcs7.js.map +1 -1
- package/dist/pkcs.d.ts +4 -3
- package/dist/result/result.d.ts +27 -20
- package/dist/result/result.js +8 -3
- 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 +436 -182
- package/dist/revocation/chain.js.map +1 -1
- package/dist/revocation/crl.d.ts +131 -67
- package/dist/revocation/crl.js +444 -323
- package/dist/revocation/crl.js.map +1 -1
- package/dist/revocation/ocsp.d.ts +94 -59
- package/dist/revocation/ocsp.js +331 -293
- package/dist/revocation/ocsp.js.map +1 -1
- package/dist/revocation/revocation.d.ts +47 -35
- package/dist/revocation/revocation.js +88 -57
- package/dist/revocation/revocation.js.map +1 -1
- package/dist/revocation.d.ts +3 -3
- package/dist/verify/identity.d.ts +16 -19
- package/dist/verify/identity.js +118 -89
- package/dist/verify/identity.js.map +1 -1
- package/dist/verify/name-constraints.d.ts +1 -4
- package/dist/verify/policy.d.ts +9 -7
- package/dist/verify/verify.d.ts +84 -46
- package/dist/verify/verify.js +300 -152
- package/dist/verify/verify.js.map +1 -1
- package/dist/verify.d.ts +2 -2
- package/dist/x509/certificate.d.ts +20 -21
- package/dist/x509/certificate.js +62 -46
- package/dist/x509/certificate.js.map +1 -1
- package/dist/x509/csr.d.ts +5 -7
- package/dist/x509/csr.js +10 -11
- package/dist/x509/csr.js.map +1 -1
- package/dist/x509/extensions.d.ts +154 -66
- package/dist/x509/extensions.js +317 -151
- 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 +18 -4
- package/dist/x509/name-text.js.map +1 -1
- package/dist/x509/name.d.ts +9 -11
- package/dist/x509/name.js +18 -19
- package/dist/x509/name.js.map +1 -1
- package/dist/x509/parse.d.ts +84 -69
- package/dist/x509/parse.js +421 -400
- package/dist/x509/parse.js.map +1 -1
- package/dist/x509.d.ts +2 -2
- package/package.json +76 -59
package/dist/verify/verify.js
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
|
|
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 { 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`.
|
|
@@ -53,47 +62,51 @@ import { checkChainRevocation as w } from "../revocation/chain.js";
|
|
|
53
62
|
* - `ec_domain_parameters_missing` — an elliptic curve public key carries no namedCurve domain parameters.
|
|
54
63
|
* - `certificate_revoked` — revocation evidence confirms a chain certificate is revoked.
|
|
55
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`).
|
|
56
67
|
*/
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
"initial_policy_set_not_satisfied",
|
|
74
|
-
"unsupported_initial_name_constraints",
|
|
75
|
-
"unsupported_name_constraints",
|
|
76
|
-
"name_constraints_violated",
|
|
77
|
-
"unsupported_signature_algorithm_parameters",
|
|
78
|
-
"ec_domain_parameters_missing",
|
|
79
|
-
"certificate_revoked",
|
|
80
|
-
"revocation_indeterminate"
|
|
81
|
-
], E = /* @__PURE__ */ new Set([
|
|
82
|
-
e.basicConstraints,
|
|
83
|
-
e.keyUsage,
|
|
84
|
-
e.extendedKeyUsage,
|
|
85
|
-
e.subjectAltName,
|
|
86
|
-
e.issuerAltName,
|
|
87
|
-
e.nameConstraints,
|
|
88
|
-
e.authorityKeyIdentifier,
|
|
89
|
-
e.subjectKeyIdentifier,
|
|
90
|
-
e.authorityInfoAccess,
|
|
91
|
-
e.cRLDistributionPoints,
|
|
92
|
-
e.certificatePolicies,
|
|
93
|
-
e.policyMappings,
|
|
94
|
-
e.policyConstraints,
|
|
95
|
-
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
|
|
96
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
|
+
}
|
|
97
110
|
/**
|
|
98
111
|
* Discovers and signature-verifies a candidate certification path from a
|
|
99
112
|
* leaf certificate to a trusted root or trust anchor. Does NOT validate
|
|
@@ -101,16 +114,21 @@ const T = [
|
|
|
101
114
|
* for that, or {@linkcode verifyCertificateChain} for the all-in-one API.
|
|
102
115
|
*/
|
|
103
116
|
async function buildCandidatePathRaw(e) {
|
|
104
|
-
|
|
117
|
+
D(e.maxPathBuildingChecks);
|
|
118
|
+
let t;
|
|
105
119
|
try {
|
|
106
|
-
t =
|
|
120
|
+
t = P(e.leaf);
|
|
107
121
|
} catch (e) {
|
|
108
|
-
return
|
|
122
|
+
return certificateSourceFailure(e, void 0);
|
|
109
123
|
}
|
|
110
|
-
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, {
|
|
111
129
|
failure,
|
|
112
130
|
detail
|
|
113
|
-
}), s = o.chain;
|
|
131
|
+
}, void 0, e.maxPathBuildingChecks), s = o.chain;
|
|
114
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;
|
|
115
133
|
let c = s[s.length - 1];
|
|
116
134
|
return c === void 0 ? failure("no_trusted_root", "no trusted root found") : {
|
|
@@ -164,7 +182,7 @@ async function validateCandidatePathRaw(e) {
|
|
|
164
182
|
if (i === void 0) return failure("issuer_not_found", "chain is empty", 0);
|
|
165
183
|
let a = await validateSelfSignedLeafAllowed(i, t.length, e);
|
|
166
184
|
if (a !== void 0) return a;
|
|
167
|
-
let o = await validatePathCertificates(t, n);
|
|
185
|
+
let o = await validatePathCertificates(t, n, e.rejectOversizedDisplayText === !0);
|
|
168
186
|
if (o !== void 0) return o;
|
|
169
187
|
let s = validatePathLengthConstraints(t);
|
|
170
188
|
if (s !== void 0) return s;
|
|
@@ -173,19 +191,44 @@ async function validateCandidatePathRaw(e) {
|
|
|
173
191
|
}
|
|
174
192
|
/** RFC 5280 §3.2 makes a self-issued certificate self-signed only when the public key it binds verifies its signature. */
|
|
175
193
|
async function validateSelfSignedLeafAllowed(e, t, n) {
|
|
176
|
-
if (t !== 1 || !
|
|
177
|
-
let r = await
|
|
178
|
-
if (
|
|
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 }));
|
|
179
197
|
}
|
|
180
198
|
/** Validates every certificate and issuer relationship in a candidate path. */
|
|
181
|
-
async function validatePathCertificates(e, t) {
|
|
182
|
-
for (let
|
|
183
|
-
let
|
|
184
|
-
if (
|
|
185
|
-
let
|
|
186
|
-
if (i !== void 0) return i;
|
|
187
|
-
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);
|
|
188
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
|
+
}));
|
|
189
232
|
}
|
|
190
233
|
}
|
|
191
234
|
async function validatePathIssuerAtIndex(e, t, n) {
|
|
@@ -197,7 +240,7 @@ function validatePathLengthConstraints(e) {
|
|
|
197
240
|
for (let t = 1; t < e.length; t += 1) {
|
|
198
241
|
let n = e[t];
|
|
199
242
|
if (n === void 0) return failure("issuer_not_found", "chain element missing", t);
|
|
200
|
-
let r =
|
|
243
|
+
let r = A(e, t), i = n.basicConstraints?.pathLength;
|
|
201
244
|
if (isNonNegativeInteger(i) && r > i) return pathLengthExceededFailure(n, t, i, r);
|
|
202
245
|
}
|
|
203
246
|
}
|
|
@@ -209,47 +252,64 @@ function pathLengthExceededFailure(e, t, n, r) {
|
|
|
209
252
|
}));
|
|
210
253
|
}
|
|
211
254
|
function validatePolicyAndNameConstraints(e, t, n) {
|
|
212
|
-
let r =
|
|
255
|
+
let r = E(e, t.policy, n);
|
|
213
256
|
if (!r.ok) return failure(r.error.code, r.error.message, 0, detail({
|
|
214
257
|
expected: r.error.details?.expected,
|
|
215
258
|
actual: r.error.details?.actual
|
|
216
259
|
}));
|
|
217
|
-
let i =
|
|
260
|
+
let i = w(e, t.nameConstraints);
|
|
218
261
|
return i.ok ? {
|
|
219
262
|
ok: !0,
|
|
220
263
|
policyValidation: r.value
|
|
221
264
|
} : i;
|
|
222
265
|
}
|
|
223
266
|
function validateCertificateAtPathIndex(e, t, n) {
|
|
224
|
-
if (!
|
|
267
|
+
if (!M(e, n)) return failure("certificate_expired", "certificate not valid at requested time", t, detail({
|
|
225
268
|
subjectCommonName: e.subject.values.commonName,
|
|
226
269
|
expected: describeDateTime(n),
|
|
227
270
|
actual: `${describeDateTime(e.notBefore)}..${describeDateTime(e.notAfter)}`
|
|
228
271
|
}));
|
|
229
272
|
let r = findUnprocessedCriticalExtension(e);
|
|
230
|
-
|
|
273
|
+
if (r !== void 0) return failure("unrecognized_critical_extension", `certificate contains unrecognized critical extension ${r}`, t, detail({
|
|
231
274
|
subjectCommonName: e.subject.values.commonName,
|
|
232
275
|
actual: r
|
|
233
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
|
+
}
|
|
234
294
|
}
|
|
235
295
|
/**
|
|
236
296
|
* RFC 5480 §2.1.1 admits only the namedCurve alternative of ECParameters, and
|
|
237
297
|
* requires clients to reject a certificate whose elliptic curve domain
|
|
238
298
|
* parameters are not present.
|
|
239
299
|
*/
|
|
240
|
-
function validateEcDomainParametersAtPathIndex(
|
|
241
|
-
if (
|
|
242
|
-
subjectCommonName:
|
|
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,
|
|
243
303
|
expected: "namedCurve OBJECT IDENTIFIER",
|
|
244
|
-
actual:
|
|
304
|
+
actual: e.publicKeyAlgorithmParametersDer === void 0 ? "absent" : `tag 0x${(e.publicKeyAlgorithmParametersDer[0] ?? 0).toString(16).padStart(2, "0")}`
|
|
245
305
|
}));
|
|
246
306
|
}
|
|
247
307
|
async function validateIssuerAtPathIndex(e, t, n) {
|
|
248
|
-
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({
|
|
249
309
|
subjectCommonName: e.subject.values.commonName,
|
|
250
310
|
issuerCommonName: t.subject.values.commonName
|
|
251
311
|
}));
|
|
252
|
-
let r = await
|
|
312
|
+
let r = await F(e, t);
|
|
253
313
|
return r.ok ? r.valid ? validateIssuerConstraintsAtPathIndex(e, t, n) : failure("signature_invalid", "certificate signature does not verify", n, detail({
|
|
254
314
|
subjectCommonName: e.subject.values.commonName,
|
|
255
315
|
issuerCommonName: t.subject.values.commonName
|
|
@@ -262,7 +322,7 @@ async function validateIssuerAtPathIndex(e, t, n) {
|
|
|
262
322
|
function validateIssuerConstraintsAtPathIndex(e, t, n) {
|
|
263
323
|
if (t.basicConstraints?.ca !== !0) return failure("ca_required", "issuer must be a CA certificate", n + 1, detail({ subjectCommonName: t.subject.values.commonName }));
|
|
264
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 }));
|
|
265
|
-
if (
|
|
325
|
+
if (O(e, t)) return failure("authority_key_identifier_mismatch", "authorityKeyIdentifier does not match issuer subjectKeyIdentifier", n, detail({
|
|
266
326
|
subjectCommonName: e.subject.values.commonName,
|
|
267
327
|
issuerCommonName: t.subject.values.commonName,
|
|
268
328
|
expected: t.subjectKeyIdentifier,
|
|
@@ -273,18 +333,17 @@ function validateIssuerConstraintsAtPathIndex(e, t, n) {
|
|
|
273
333
|
* Validates a pre-built certificate chain for time, constraints, policy, and
|
|
274
334
|
* optionally leaf purpose. Wrap the result of {@linkcode buildCandidatePath}.
|
|
275
335
|
*/
|
|
276
|
-
async function validateCandidatePath(
|
|
277
|
-
let t;
|
|
278
|
-
|
|
279
|
-
t =
|
|
280
|
-
|
|
281
|
-
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 })));
|
|
282
341
|
}
|
|
283
|
-
let
|
|
284
|
-
...
|
|
285
|
-
chain:
|
|
342
|
+
let r = await validateCandidatePathRaw({
|
|
343
|
+
...t,
|
|
344
|
+
chain: n.chain
|
|
286
345
|
});
|
|
287
|
-
return
|
|
346
|
+
return r.ok ? validateCandidatePathSuccessResult(r.policyValidation) : verifyFailureResult(r);
|
|
288
347
|
}
|
|
289
348
|
/**
|
|
290
349
|
* All-in-one certificate chain verification: builds a candidate path then
|
|
@@ -310,12 +369,14 @@ async function validateCandidatePath(e) {
|
|
|
310
369
|
* ```
|
|
311
370
|
*/
|
|
312
371
|
async function verifyCertificateChain(e) {
|
|
372
|
+
S(e.revocation?.policy?.crlMaxAgeMs);
|
|
313
373
|
let t = await buildCandidatePath({
|
|
314
374
|
leaf: e.leaf,
|
|
315
375
|
roots: e.roots,
|
|
316
376
|
...e.intermediates !== void 0 && { intermediates: e.intermediates },
|
|
317
377
|
...e.trustAnchors !== void 0 && { trustAnchors: e.trustAnchors },
|
|
318
|
-
...e.at !== void 0 && { at: e.at }
|
|
378
|
+
...e.at !== void 0 && { at: e.at },
|
|
379
|
+
...e.maxPathBuildingChecks !== void 0 && { maxPathBuildingChecks: e.maxPathBuildingChecks }
|
|
319
380
|
});
|
|
320
381
|
if (!t.ok) return t;
|
|
321
382
|
let n = await validateCandidatePath({
|
|
@@ -324,7 +385,8 @@ async function verifyCertificateChain(e) {
|
|
|
324
385
|
...e.at !== void 0 && { at: e.at },
|
|
325
386
|
...e.purpose !== void 0 && { purpose: e.purpose },
|
|
326
387
|
...copyValidationInputs(e),
|
|
327
|
-
...e.allowSelfSignedLeaf !== void 0 && { allowSelfSignedLeaf: e.allowSelfSignedLeaf }
|
|
388
|
+
...e.allowSelfSignedLeaf !== void 0 && { allowSelfSignedLeaf: e.allowSelfSignedLeaf },
|
|
389
|
+
...e.rejectOversizedDisplayText !== void 0 && { rejectOversizedDisplayText: e.rejectOversizedDisplayText }
|
|
328
390
|
});
|
|
329
391
|
if (!n.ok) return n;
|
|
330
392
|
if (e.serviceIdentity !== void 0) {
|
|
@@ -346,7 +408,7 @@ async function verifyCertificateChain(e) {
|
|
|
346
408
|
/** Applies optional revocation evidence to an otherwise verified certificate chain. */
|
|
347
409
|
async function validateVerifiedChainRevocation(e, t) {
|
|
348
410
|
if (e.revocation === void 0) return;
|
|
349
|
-
let n = await
|
|
411
|
+
let n = await L({
|
|
350
412
|
chain: t,
|
|
351
413
|
...e.revocation.crls === void 0 ? {} : { crls: e.revocation.crls },
|
|
352
414
|
...e.revocation.ocspResponses === void 0 ? {} : { ocspResponses: e.revocation.ocspResponses },
|
|
@@ -382,28 +444,33 @@ function revocationFailureResult(e) {
|
|
|
382
444
|
* }
|
|
383
445
|
* ```
|
|
384
446
|
*/
|
|
385
|
-
async function verifyCertificateSigningRequest(
|
|
386
|
-
let
|
|
447
|
+
async function verifyCertificateSigningRequest(t) {
|
|
448
|
+
let n;
|
|
387
449
|
try {
|
|
388
|
-
|
|
389
|
-
} catch (
|
|
390
|
-
|
|
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 }));
|
|
391
454
|
}
|
|
392
|
-
let
|
|
455
|
+
let r;
|
|
393
456
|
try {
|
|
394
|
-
|
|
395
|
-
} catch (
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
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
|
|
399
466
|
}));
|
|
400
467
|
}
|
|
401
|
-
return
|
|
468
|
+
return r.ok ? r.valid ? {
|
|
402
469
|
ok: !0,
|
|
403
|
-
value:
|
|
404
|
-
} : verifyRequestFailureResult("signature_invalid", "certificate request signature does not verify", detail({ subjectCommonName:
|
|
405
|
-
subjectCommonName:
|
|
406
|
-
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
|
|
407
474
|
}));
|
|
408
475
|
}
|
|
409
476
|
/**
|
|
@@ -421,19 +488,18 @@ async function verifyCertificateSigningRequest(e) {
|
|
|
421
488
|
* }
|
|
422
489
|
* ```
|
|
423
490
|
*/
|
|
424
|
-
function checkExtendedKeyUsage(
|
|
425
|
-
let
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
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);
|
|
430
496
|
}
|
|
431
|
-
let r =
|
|
432
|
-
if (
|
|
433
|
-
if (
|
|
434
|
-
for (let e = 1; e <
|
|
435
|
-
let
|
|
436
|
-
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);
|
|
437
503
|
}
|
|
438
504
|
return {
|
|
439
505
|
ok: !0,
|
|
@@ -441,19 +507,19 @@ function checkExtendedKeyUsage(e, t) {
|
|
|
441
507
|
};
|
|
442
508
|
}
|
|
443
509
|
/** Extracts a {@linkcode TrustAnchor} from a parsed certificate, copying the subject, SPKI, and key identifiers. */
|
|
444
|
-
function trustAnchorFromCertificate(
|
|
445
|
-
let
|
|
510
|
+
function trustAnchorFromCertificate(t) {
|
|
511
|
+
let n;
|
|
446
512
|
try {
|
|
447
|
-
|
|
448
|
-
} catch {
|
|
449
|
-
throw Error("certificate input is malformed");
|
|
513
|
+
n = reparseCertificateForTrust(t);
|
|
514
|
+
} catch (t) {
|
|
515
|
+
throw o(t, e), Error("certificate input is malformed");
|
|
450
516
|
}
|
|
451
517
|
return {
|
|
452
|
-
subject:
|
|
453
|
-
subjectPublicKeyInfoDer:
|
|
454
|
-
publicKeyAlgorithmOid:
|
|
455
|
-
...
|
|
456
|
-
...
|
|
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 }
|
|
457
523
|
};
|
|
458
524
|
}
|
|
459
525
|
/** Extracts defined optional fields from a base input for safe forwarding. */
|
|
@@ -464,6 +530,7 @@ function baseChainInput(e) {
|
|
|
464
530
|
...e.intermediates !== void 0 && { intermediates: e.intermediates },
|
|
465
531
|
...e.trustAnchors !== void 0 && { trustAnchors: e.trustAnchors },
|
|
466
532
|
...e.at !== void 0 && { at: e.at },
|
|
533
|
+
...e.maxPathBuildingChecks !== void 0 && { maxPathBuildingChecks: e.maxPathBuildingChecks },
|
|
467
534
|
...copyValidationInputs(e)
|
|
468
535
|
};
|
|
469
536
|
}
|
|
@@ -570,7 +637,7 @@ function validateLeaf(e, t, n) {
|
|
|
570
637
|
function validateServiceIdentity(e, t) {
|
|
571
638
|
let n = validateServiceIdentityInput(t);
|
|
572
639
|
if (!n.ok) return n;
|
|
573
|
-
let r =
|
|
640
|
+
let r = I({
|
|
574
641
|
certificate: reparseCertificateForTrust(e),
|
|
575
642
|
serviceIdentity: t
|
|
576
643
|
});
|
|
@@ -582,7 +649,7 @@ function validateServiceIdentity(e, t) {
|
|
|
582
649
|
message: i.message,
|
|
583
650
|
index: 0,
|
|
584
651
|
...i.details === void 0 ? {} : { details: i.details }
|
|
585
|
-
} : 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({
|
|
586
653
|
expected: t.value,
|
|
587
654
|
actual: i.code
|
|
588
655
|
})) : {
|
|
@@ -598,7 +665,7 @@ function validateServiceIdentityInput(e) {
|
|
|
598
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) }));
|
|
599
666
|
if (typeof e.value != "string") return failure("subject_alt_name_mismatch", "service identity input is malformed", 0, detail({ actual: e.type }));
|
|
600
667
|
if (e.type === "ip") try {
|
|
601
|
-
|
|
668
|
+
f(e.value);
|
|
602
669
|
} catch {
|
|
603
670
|
return failure("subject_alt_name_mismatch", "service identity input is malformed", 0, detail({
|
|
604
671
|
expected: e.value,
|
|
@@ -618,8 +685,23 @@ async function verifyChainForExtendedKeyUsageProfile(e, t) {
|
|
|
618
685
|
return n.ok ? applyEkuCheck(n, t) : n;
|
|
619
686
|
}
|
|
620
687
|
/** Returns the OID of the first critical extension not in {@linkcode PROCESSED_EXTENSION_OIDS}, or `undefined`. */
|
|
621
|
-
function findUnprocessedCriticalExtension(
|
|
622
|
-
for (let
|
|
688
|
+
function findUnprocessedCriticalExtension(e) {
|
|
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
|
+
}
|
|
623
705
|
}
|
|
624
706
|
/** Constructs a {@linkcode VerifyChainFailure} with the given code, message, optional chain index, and details. */
|
|
625
707
|
function failure(e, t, n, i) {
|
|
@@ -644,10 +726,23 @@ function describeDateTime(e) {
|
|
|
644
726
|
return Number.isNaN(e.getTime()) ? "<invalid date>" : e.toISOString();
|
|
645
727
|
}
|
|
646
728
|
function normalizeValidationChain(e) {
|
|
647
|
-
|
|
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
|
+
};
|
|
648
743
|
}
|
|
649
744
|
function reparseCertificateForTrust(e) {
|
|
650
|
-
return
|
|
745
|
+
return y(new Uint8Array(e.der));
|
|
651
746
|
}
|
|
652
747
|
/** Returns `true` if the value is a non-negative integer (including zero). */
|
|
653
748
|
function isNonNegativeInteger(e) {
|
|
@@ -655,18 +750,20 @@ function isNonNegativeInteger(e) {
|
|
|
655
750
|
}
|
|
656
751
|
/** Constructs a CSR verification failure result. */
|
|
657
752
|
function verifyRequestFailureResult(e, n, r) {
|
|
658
|
-
|
|
753
|
+
let a = {
|
|
659
754
|
ok: !1,
|
|
660
755
|
...i(e, n, r)
|
|
661
|
-
}
|
|
756
|
+
};
|
|
757
|
+
return t(a);
|
|
662
758
|
}
|
|
663
759
|
/** Constructs an EKU check failure result at the given chain index. */
|
|
664
760
|
function ekuCheckFailureResult(e, t, i) {
|
|
665
|
-
|
|
761
|
+
let a = {
|
|
666
762
|
ok: !1,
|
|
667
763
|
...r(e, t, i),
|
|
668
764
|
index: i
|
|
669
|
-
}
|
|
765
|
+
};
|
|
766
|
+
return n(a);
|
|
670
767
|
}
|
|
671
768
|
/** Merges flat and nested policy fields, with nested taking precedence. */
|
|
672
769
|
function resolvePolicyValidationInput(e) {
|
|
@@ -729,22 +826,36 @@ function detail(e) {
|
|
|
729
826
|
...e.actual === void 0 ? {} : { actual: e.actual },
|
|
730
827
|
...e.chainCommonNames === void 0 ? {} : { chainCommonNames: e.chainCommonNames },
|
|
731
828
|
...e.presentedIdentifierTypes === void 0 ? {} : { presentedIdentifierTypes: e.presentedIdentifierTypes },
|
|
732
|
-
...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 }
|
|
733
832
|
};
|
|
734
833
|
}
|
|
735
834
|
/** Initializes policy and name-constraint validation state for a chain walk. */
|
|
736
835
|
function buildValidationState(e, t) {
|
|
737
|
-
let n =
|
|
836
|
+
let n = T(resolvePolicyValidationInput(e), t), r = validateInitialNameConstraintsInput(resolveInitialNameConstraintsInput(e));
|
|
738
837
|
return r.ok ? {
|
|
739
838
|
ok: !0,
|
|
740
839
|
value: {
|
|
741
840
|
policy: n,
|
|
742
|
-
nameConstraints:
|
|
841
|
+
nameConstraints: C(r.value)
|
|
743
842
|
}
|
|
744
843
|
} : r;
|
|
745
844
|
}
|
|
746
845
|
function normalizeInitialPolicySet(e) {
|
|
747
|
-
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;
|
|
748
859
|
}
|
|
749
860
|
function validateInitialNameConstraintsInput(e) {
|
|
750
861
|
let t = validateInitialNameConstraintSubtrees(e.permittedSubtrees, "permittedSubtrees");
|
|
@@ -752,26 +863,64 @@ function validateInitialNameConstraintsInput(e) {
|
|
|
752
863
|
let n = validateInitialNameConstraintSubtrees(e.excludedSubtrees, "excludedSubtrees");
|
|
753
864
|
return n.ok ? {
|
|
754
865
|
ok: !0,
|
|
755
|
-
value:
|
|
866
|
+
value: {
|
|
867
|
+
...t.value === void 0 ? {} : { permittedSubtrees: t.value },
|
|
868
|
+
...n.value === void 0 ? {} : { excludedSubtrees: n.value }
|
|
869
|
+
}
|
|
756
870
|
} : n;
|
|
757
871
|
}
|
|
758
872
|
function validateInitialNameConstraintSubtrees(e, t) {
|
|
759
873
|
if (e === void 0) return { ok: !0 };
|
|
760
874
|
if (!Array.isArray(e)) return invalidInitialNameConstraintsFailure(t);
|
|
875
|
+
let n = [];
|
|
761
876
|
for (let t of e) {
|
|
762
877
|
let e = describeInvalidInitialNameConstraintForm(t);
|
|
763
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);
|
|
764
882
|
}
|
|
765
|
-
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);
|
|
766
914
|
}
|
|
767
915
|
function describeInvalidInitialNameConstraintForm(e) {
|
|
768
916
|
if (!isRecord(e)) return "invalid subtree";
|
|
769
917
|
let t = e.base;
|
|
770
918
|
if (!isRecord(t) || typeof t.type != "string") return "invalid subtree";
|
|
771
919
|
switch (t.type) {
|
|
772
|
-
case "dns":
|
|
773
|
-
case "
|
|
774
|
-
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;
|
|
775
924
|
case "directoryName": return typeof t.derHex == "string" ? void 0 : t.type;
|
|
776
925
|
case "ip": return t.addressBytes instanceof Uint8Array && t.maskBytes instanceof Uint8Array ? void 0 : t.type;
|
|
777
926
|
case "otherName":
|
|
@@ -787,7 +936,6 @@ function invalidInitialNameConstraintsFailure(e) {
|
|
|
787
936
|
function isRecord(e) {
|
|
788
937
|
return typeof e == "object" && !!e;
|
|
789
938
|
}
|
|
790
|
-
|
|
791
|
-
export { T as VERIFY_ERROR_CODES, buildCandidatePath, checkExtendedKeyUsage, v as isSelfIssuedCertificate, 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 };
|
|
792
940
|
|
|
793
941
|
//# sourceMappingURL=verify.js.map
|