micro509 0.14.0 → 0.16.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 +2119 -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 +11 -11
- 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/spki-distrust.js +23 -0
- package/dist/internal/verify/spki-distrust.js.map +1 -0
- package/dist/internal/verify/verify-path.d.ts +1 -4
- package/dist/internal/verify/verify-path.js +282 -129
- 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 +122 -104
- 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 +443 -327
- 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 +115 -46
- package/dist/verify/verify.js +373 -183
- 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 +15 -7
- package/dist/x509/fingerprint.js +20 -3
- 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 +3 -3
- package/dist/x509.js +3 -3
- package/package.json +76 -59
package/dist/verify/verify.js
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
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 { createSpkiDistrustCheck as D } from "../internal/verify/spki-distrust.js";
|
|
16
|
+
import { assertPathBuildingChecks as O, authorityKeyIdentifierMismatch as k, buildChainInternal as A, countCaCertificatesBelowParsed as j, isSelfIssued as M, isWithinValidity as N, loadCertificates as P, loadSingleCertificate as F, verifyCertificateSignature as I } from "../internal/verify/verify-path.js";
|
|
17
|
+
import { matchServiceIdentity as L } from "./identity.js";
|
|
18
|
+
import { checkChainRevocation as R } from "../revocation/chain.js";
|
|
19
|
+
// src/verify/verify.ts
|
|
13
20
|
/**
|
|
14
21
|
* Public certificate and CSR verification APIs.
|
|
15
22
|
*
|
|
@@ -37,12 +44,15 @@ import { checkChainRevocation as w } from "../revocation/chain.js";
|
|
|
37
44
|
* - `ca_required` — an issuer lacks `basicConstraints.ca = true`.
|
|
38
45
|
* - `key_cert_sign_required` — an issuer has keyUsage but omits `keyCertSign`.
|
|
39
46
|
* - `path_length_exceeded` — the number of CA certificates below an issuer exceeds its pathLength.
|
|
47
|
+
* - `path_building_limit_exceeded` — candidate-path construction exceeded its bounded work limits.
|
|
40
48
|
* - `authority_key_identifier_mismatch` — a certificate's AKI does not match the issuer's SKI.
|
|
41
49
|
* - `extended_key_usage_invalid` — the leaf certificate lacks the required EKU for the requested purpose.
|
|
42
50
|
* - `subject_alt_name_mismatch` — no SAN entry matches the requested service identity.
|
|
43
51
|
* - `common_name_fallback_suppressed` — CN fallback was attempted but suppressed (SAN present or disabled).
|
|
44
52
|
* - `self_signed_leaf_not_allowed` — the leaf is self-signed and `allowSelfSignedLeaf` was not set.
|
|
45
53
|
* - `unrecognized_critical_extension` — a certificate contains a critical extension the verifier cannot process.
|
|
54
|
+
* - `no_rev_avail_conflict` — a certificate carries noRevAvail alongside a CA basicConstraints, cRLDistributionPoints, freshestCRL, or an id-ad-ocsp authorityInfoAccess entry (RFC 9608 §3).
|
|
55
|
+
* - `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
56
|
* - `intermediate_eku_constraint` — an intermediate CA's EKU set does not include the required purpose.
|
|
47
57
|
* - `explicit_policy_required` — `requireExplicitPolicy` was set but no acceptable policy was found.
|
|
48
58
|
* - `initial_policy_set_not_satisfied` — the chain's policies do not intersect `initialPolicySet`.
|
|
@@ -51,49 +61,54 @@ import { checkChainRevocation as w } from "../revocation/chain.js";
|
|
|
51
61
|
* - `name_constraints_violated` — a subject name violates a permitted/excluded subtree.
|
|
52
62
|
* - `unsupported_signature_algorithm_parameters` — the signature algorithm uses unrecognized parameters.
|
|
53
63
|
* - `ec_domain_parameters_missing` — an elliptic curve public key carries no namedCurve domain parameters.
|
|
64
|
+
* - `public_key_distrusted` — a certificate or bare trust anchor uses an explicitly distrusted SHA-256 SPKI.
|
|
54
65
|
* - `certificate_revoked` — revocation evidence confirms a chain certificate is revoked.
|
|
55
66
|
* - `revocation_indeterminate` — revocation status could not be determined under a hard-fail policy.
|
|
67
|
+
* - `unsupported` — a certificate source holds a construct micro509 does not decode (see `ParseCertificateErrorCode`).
|
|
68
|
+
* - `limit_exceeded` — a certificate source exceeds a micro509 decoding limit (see `ParseCertificateErrorCode`).
|
|
56
69
|
*/
|
|
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
|
|
70
|
+
const z = /* @__PURE__ */ "no_trusted_root.issuer_not_found.signature_invalid.certificate_expired.ca_required.key_cert_sign_required.path_length_exceeded.path_building_limit_exceeded.authority_key_identifier_mismatch.extended_key_usage_invalid.subject_alt_name_mismatch.common_name_fallback_suppressed.self_signed_leaf_not_allowed.unrecognized_critical_extension.no_rev_avail_conflict.display_text_oversized.intermediate_eku_constraint.explicit_policy_required.initial_policy_set_not_satisfied.unsupported_initial_name_constraints.unsupported_name_constraints.name_constraints_violated.unsupported_signature_algorithm_parameters.ec_domain_parameters_missing.public_key_distrusted.certificate_revoked.revocation_indeterminate.unsupported.limit_exceeded".split("."), B = /* @__PURE__ */ new Set([
|
|
71
|
+
c.basicConstraints,
|
|
72
|
+
c.keyUsage,
|
|
73
|
+
c.extendedKeyUsage,
|
|
74
|
+
c.subjectAltName,
|
|
75
|
+
c.issuerAltName,
|
|
76
|
+
c.nameConstraints,
|
|
77
|
+
c.authorityKeyIdentifier,
|
|
78
|
+
c.subjectKeyIdentifier,
|
|
79
|
+
c.authorityInfoAccess,
|
|
80
|
+
c.cRLDistributionPoints,
|
|
81
|
+
c.certificatePolicies,
|
|
82
|
+
c.policyMappings,
|
|
83
|
+
c.policyConstraints,
|
|
84
|
+
c.inhibitAnyPolicy,
|
|
85
|
+
c.noRevAvail
|
|
96
86
|
]);
|
|
87
|
+
function loadCertificatePool(e, t) {
|
|
88
|
+
let n = [];
|
|
89
|
+
for (let [r, i] of e.entries()) try {
|
|
90
|
+
n.push(...P([i]));
|
|
91
|
+
} catch (e) {
|
|
92
|
+
return certificateSourceFailure(e, {
|
|
93
|
+
kind: t,
|
|
94
|
+
position: r
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
ok: !0,
|
|
99
|
+
certificates: n
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function certificateSourceFailure(t, n) {
|
|
103
|
+
let r = a(t, e);
|
|
104
|
+
return r === void 0 ? failure("issuer_not_found", "certificate source is malformed or leaf source does not contain exactly one certificate", 0, detail({
|
|
105
|
+
actual: t instanceof Error ? t.message : "certificate source is malformed",
|
|
106
|
+
source: n
|
|
107
|
+
})) : failure(r.code, r.message, 0, detail({
|
|
108
|
+
actual: r.message,
|
|
109
|
+
source: n
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
97
112
|
/**
|
|
98
113
|
* Discovers and signature-verifies a candidate certification path from a
|
|
99
114
|
* leaf certificate to a trusted root or trust anchor. Does NOT validate
|
|
@@ -101,25 +116,31 @@ const T = [
|
|
|
101
116
|
* for that, or {@linkcode verifyCertificateChain} for the all-in-one API.
|
|
102
117
|
*/
|
|
103
118
|
async function buildCandidatePathRaw(e) {
|
|
104
|
-
|
|
119
|
+
O(e.maxPathBuildingChecks);
|
|
120
|
+
let t = D(e.distrustedSpkiSha256), n;
|
|
105
121
|
try {
|
|
106
|
-
|
|
122
|
+
n = F(e.leaf);
|
|
107
123
|
} catch (e) {
|
|
108
|
-
return
|
|
124
|
+
return certificateSourceFailure(e, void 0);
|
|
109
125
|
}
|
|
110
|
-
let
|
|
126
|
+
let r = loadCertificatePool(e.intermediates ?? [], "intermediates");
|
|
127
|
+
if (!r.ok) return r;
|
|
128
|
+
let i = loadCertificatePool(e.roots, "roots");
|
|
129
|
+
if (!i.ok) return i;
|
|
130
|
+
let a = e.trustAnchors ?? [], o = e.at ?? /* @__PURE__ */ new Date(), s = await A(n, r.certificates, i.certificates, a, o, {
|
|
111
131
|
failure,
|
|
112
132
|
detail
|
|
113
|
-
}),
|
|
114
|
-
if (!
|
|
115
|
-
let
|
|
116
|
-
return
|
|
133
|
+
}, void 0, e.maxPathBuildingChecks, t), c = s.chain;
|
|
134
|
+
if (!s.foundTrustedRoot) return s.failure === void 0 ? s.missingIssuerAt === void 0 ? failure("no_trusted_root", "no trusted root found", void 0, detail({ chainCommonNames: c.map((e) => e.subject.values.commonName ?? "<unnamed>") })) : failure("issuer_not_found", "issuer certificate not found", s.missingIssuerAt, buildFailureDetails(c, s.missingIssuerAt)) : s.failure;
|
|
135
|
+
let l = c[c.length - 1];
|
|
136
|
+
return l === void 0 ? failure("no_trusted_root", "no trusted root found") : {
|
|
117
137
|
ok: !0,
|
|
118
138
|
value: {
|
|
119
|
-
leaf:
|
|
120
|
-
chain:
|
|
121
|
-
root:
|
|
122
|
-
anchorCertificateInChain:
|
|
139
|
+
leaf: n,
|
|
140
|
+
chain: c,
|
|
141
|
+
root: l,
|
|
142
|
+
anchorCertificateInChain: s.anchorCertificateInChain ?? !0,
|
|
143
|
+
...s.trustAnchor !== void 0 && { trustAnchor: s.trustAnchor }
|
|
123
144
|
}
|
|
124
145
|
};
|
|
125
146
|
}
|
|
@@ -158,34 +179,88 @@ async function buildCandidatePath(e) {
|
|
|
158
179
|
* assumed trusted and not re-verified.
|
|
159
180
|
*/
|
|
160
181
|
async function validateCandidatePathRaw(e) {
|
|
161
|
-
let t =
|
|
162
|
-
if (!
|
|
163
|
-
let
|
|
164
|
-
if (
|
|
165
|
-
let
|
|
166
|
-
if (a
|
|
167
|
-
let o =
|
|
168
|
-
if (o
|
|
169
|
-
let s =
|
|
182
|
+
let t = D(e.distrustedSpkiSha256);
|
|
183
|
+
if (e.distrustedSpkiSha256?.length && e.anchorCertificateInChain === !1 && e.trustAnchor === void 0) throw RangeError("trustAnchor is required to check distrust on a path with a bare anchor");
|
|
184
|
+
let n = e.chain, r = await validatePathDistrust(e, t);
|
|
185
|
+
if (r !== void 0) return r;
|
|
186
|
+
let i = e.at ?? /* @__PURE__ */ new Date(), a = buildValidationState(e, n.length);
|
|
187
|
+
if (!a.ok) return a;
|
|
188
|
+
let o = n[0];
|
|
189
|
+
if (o === void 0) return failure("issuer_not_found", "chain is empty", 0);
|
|
190
|
+
let s = await validateSelfSignedLeafAllowed(o, n.length, e);
|
|
170
191
|
if (s !== void 0) return s;
|
|
171
|
-
let c =
|
|
172
|
-
|
|
192
|
+
let c = await validatePathCertificates(n, i, e.rejectOversizedDisplayText === !0);
|
|
193
|
+
if (c !== void 0) return c;
|
|
194
|
+
let l = validatePathLengthConstraints(n);
|
|
195
|
+
if (l !== void 0) return l;
|
|
196
|
+
let u = validatePolicyAndNameConstraints(n, a.value, e.anchorCertificateInChain ?? !0);
|
|
197
|
+
return u.ok ? validateLeaf(o, e, u.policyValidation) : u;
|
|
198
|
+
}
|
|
199
|
+
/** Checks signed certificate SPKIs and the separately supplied bare anchor. */
|
|
200
|
+
async function validatePathDistrust(e, t) {
|
|
201
|
+
if (e.distrustedSpkiSha256?.length) {
|
|
202
|
+
for (let [n, r] of e.chain.entries()) {
|
|
203
|
+
let e;
|
|
204
|
+
try {
|
|
205
|
+
e = y(r.der);
|
|
206
|
+
} catch (e) {
|
|
207
|
+
return {
|
|
208
|
+
...certificateSourceFailure(e, void 0),
|
|
209
|
+
index: n
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
let i = await t(e.subjectPublicKeyInfoDer);
|
|
213
|
+
if (i !== void 0) return failure("public_key_distrusted", "certificate public key is explicitly distrusted", n, detail({
|
|
214
|
+
subjectCommonName: e.subject.values.commonName,
|
|
215
|
+
actual: i
|
|
216
|
+
}));
|
|
217
|
+
}
|
|
218
|
+
if (e.trustAnchor !== void 0) {
|
|
219
|
+
let n = await t(e.trustAnchor.subjectPublicKeyInfoDer);
|
|
220
|
+
if (n !== void 0) return failure("public_key_distrusted", "bare trust anchor public key is explicitly distrusted", void 0, detail({ actual: n }));
|
|
221
|
+
}
|
|
222
|
+
}
|
|
173
223
|
}
|
|
174
224
|
/** RFC 5280 §3.2 makes a self-issued certificate self-signed only when the public key it binds verifies its signature. */
|
|
175
225
|
async function validateSelfSignedLeafAllowed(e, t, n) {
|
|
176
|
-
if (t !== 1 || !
|
|
177
|
-
let r = await
|
|
178
|
-
if (
|
|
226
|
+
if (t !== 1 || !M(e) || n.allowSelfSignedLeaf === !0) return;
|
|
227
|
+
let r = await I(e, e);
|
|
228
|
+
if (r.ok && r.valid) return failure("self_signed_leaf_not_allowed", "self-signed leaf not allowed", 0, detail({ subjectCommonName: e.subject.values.commonName }));
|
|
179
229
|
}
|
|
180
230
|
/** 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);
|
|
231
|
+
async function validatePathCertificates(e, t, n) {
|
|
232
|
+
for (let r = 0; r < e.length; r += 1) {
|
|
233
|
+
let i = e[r];
|
|
234
|
+
if (i === void 0) return failure("issuer_not_found", "chain element missing", r);
|
|
235
|
+
let a = validateCertificateAtPathIndex(i, r, t);
|
|
188
236
|
if (a !== void 0) return a;
|
|
237
|
+
if (n) {
|
|
238
|
+
let e = validateDisplayTextAtPathIndex(i, r);
|
|
239
|
+
if (e !== void 0) return e;
|
|
240
|
+
}
|
|
241
|
+
let o = await validatePathIssuerAtIndex(e, i, r);
|
|
242
|
+
if (o !== void 0) return o;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
/** RFC 5280 §4.2.1.4 bounds a DisplayText at 200 characters; PKITS 4.8.19 lets the application reject a longer explicitText. */
|
|
246
|
+
function validateDisplayTextAtPathIndex(e, t) {
|
|
247
|
+
for (let n of e.certificatePolicies ?? []) for (let r of n.policyQualifiers ?? []) {
|
|
248
|
+
if (r.type !== "userNotice") continue;
|
|
249
|
+
let i = [[
|
|
250
|
+
"explicitText",
|
|
251
|
+
"explicitText",
|
|
252
|
+
r.oversizedExplicitText
|
|
253
|
+
], [
|
|
254
|
+
"noticeRefOrganization",
|
|
255
|
+
"noticeRef organization",
|
|
256
|
+
r.noticeRef?.oversizedOrganization
|
|
257
|
+
]];
|
|
258
|
+
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({
|
|
259
|
+
subjectCommonName: e.subject.values.commonName,
|
|
260
|
+
expected: String(o.limit),
|
|
261
|
+
actual: String(o.characters),
|
|
262
|
+
userNoticeField: r
|
|
263
|
+
}));
|
|
189
264
|
}
|
|
190
265
|
}
|
|
191
266
|
async function validatePathIssuerAtIndex(e, t, n) {
|
|
@@ -197,7 +272,7 @@ function validatePathLengthConstraints(e) {
|
|
|
197
272
|
for (let t = 1; t < e.length; t += 1) {
|
|
198
273
|
let n = e[t];
|
|
199
274
|
if (n === void 0) return failure("issuer_not_found", "chain element missing", t);
|
|
200
|
-
let r =
|
|
275
|
+
let r = j(e, t), i = n.basicConstraints?.pathLength;
|
|
201
276
|
if (isNonNegativeInteger(i) && r > i) return pathLengthExceededFailure(n, t, i, r);
|
|
202
277
|
}
|
|
203
278
|
}
|
|
@@ -209,47 +284,64 @@ function pathLengthExceededFailure(e, t, n, r) {
|
|
|
209
284
|
}));
|
|
210
285
|
}
|
|
211
286
|
function validatePolicyAndNameConstraints(e, t, n) {
|
|
212
|
-
let r =
|
|
287
|
+
let r = E(e, t.policy, n);
|
|
213
288
|
if (!r.ok) return failure(r.error.code, r.error.message, 0, detail({
|
|
214
289
|
expected: r.error.details?.expected,
|
|
215
290
|
actual: r.error.details?.actual
|
|
216
291
|
}));
|
|
217
|
-
let i =
|
|
292
|
+
let i = w(e, t.nameConstraints);
|
|
218
293
|
return i.ok ? {
|
|
219
294
|
ok: !0,
|
|
220
295
|
policyValidation: r.value
|
|
221
296
|
} : i;
|
|
222
297
|
}
|
|
223
298
|
function validateCertificateAtPathIndex(e, t, n) {
|
|
224
|
-
if (!
|
|
299
|
+
if (!N(e, n)) return failure("certificate_expired", "certificate not valid at requested time", t, detail({
|
|
225
300
|
subjectCommonName: e.subject.values.commonName,
|
|
226
301
|
expected: describeDateTime(n),
|
|
227
302
|
actual: `${describeDateTime(e.notBefore)}..${describeDateTime(e.notAfter)}`
|
|
228
303
|
}));
|
|
229
304
|
let r = findUnprocessedCriticalExtension(e);
|
|
230
|
-
|
|
305
|
+
if (r !== void 0) return failure("unrecognized_critical_extension", `certificate contains unrecognized critical extension ${r}`, t, detail({
|
|
231
306
|
subjectCommonName: e.subject.values.commonName,
|
|
232
307
|
actual: r
|
|
233
308
|
}));
|
|
309
|
+
let i = findNoRevAvailConflict(e);
|
|
310
|
+
return i === void 0 ? validateEcDomainParametersAtPathIndex(e, t) : failure("no_rev_avail_conflict", `certificate carries noRevAvail with ${i}`, t, detail({
|
|
311
|
+
subjectCommonName: e.subject.values.commonName,
|
|
312
|
+
actual: i
|
|
313
|
+
}));
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* RFC 9608 §3: a relying party MUST consider a certificate carrying noRevAvail
|
|
317
|
+
* invalid when it also asserts cA, points at a CRL, or names an OCSP responder.
|
|
318
|
+
*/
|
|
319
|
+
function findNoRevAvailConflict(e) {
|
|
320
|
+
if (e.noRevAvail === !0) {
|
|
321
|
+
if (e.basicConstraints?.ca === !0) return "basicConstraints cA TRUE";
|
|
322
|
+
if (e.crlDistributionPoints !== void 0) return "cRLDistributionPoints";
|
|
323
|
+
if (e.extensions.some((e) => e.oid === c.freshestCRL)) return "freshestCRL";
|
|
324
|
+
if (e.authorityInfoAccess?.some((e) => e.method === "ocsp") === !0) return "an id-ad-ocsp authorityInfoAccess entry";
|
|
325
|
+
}
|
|
234
326
|
}
|
|
235
327
|
/**
|
|
236
328
|
* RFC 5480 §2.1.1 admits only the namedCurve alternative of ECParameters, and
|
|
237
329
|
* requires clients to reject a certificate whose elliptic curve domain
|
|
238
330
|
* parameters are not present.
|
|
239
331
|
*/
|
|
240
|
-
function validateEcDomainParametersAtPathIndex(
|
|
241
|
-
if (
|
|
242
|
-
subjectCommonName:
|
|
332
|
+
function validateEcDomainParametersAtPathIndex(e, t) {
|
|
333
|
+
if (e.publicKeyAlgorithmOid === c.ecPublicKey && e.publicKeyParametersOid === void 0) return failure("ec_domain_parameters_missing", "elliptic curve public key carries no namedCurve domain parameters", t, detail({
|
|
334
|
+
subjectCommonName: e.subject.values.commonName,
|
|
243
335
|
expected: "namedCurve OBJECT IDENTIFIER",
|
|
244
|
-
actual:
|
|
336
|
+
actual: e.publicKeyAlgorithmParametersDer === void 0 ? "absent" : `tag 0x${(e.publicKeyAlgorithmParametersDer[0] ?? 0).toString(16).padStart(2, "0")}`
|
|
245
337
|
}));
|
|
246
338
|
}
|
|
247
339
|
async function validateIssuerAtPathIndex(e, t, n) {
|
|
248
|
-
if (!
|
|
340
|
+
if (!v(e.issuer, t.subject)) return failure("issuer_not_found", "issuer distinguished name does not match the candidate issuer subject", n, detail({
|
|
249
341
|
subjectCommonName: e.subject.values.commonName,
|
|
250
342
|
issuerCommonName: t.subject.values.commonName
|
|
251
343
|
}));
|
|
252
|
-
let r = await
|
|
344
|
+
let r = await I(e, t);
|
|
253
345
|
return r.ok ? r.valid ? validateIssuerConstraintsAtPathIndex(e, t, n) : failure("signature_invalid", "certificate signature does not verify", n, detail({
|
|
254
346
|
subjectCommonName: e.subject.values.commonName,
|
|
255
347
|
issuerCommonName: t.subject.values.commonName
|
|
@@ -262,7 +354,7 @@ async function validateIssuerAtPathIndex(e, t, n) {
|
|
|
262
354
|
function validateIssuerConstraintsAtPathIndex(e, t, n) {
|
|
263
355
|
if (t.basicConstraints?.ca !== !0) return failure("ca_required", "issuer must be a CA certificate", n + 1, detail({ subjectCommonName: t.subject.values.commonName }));
|
|
264
356
|
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 (
|
|
357
|
+
if (k(e, t)) return failure("authority_key_identifier_mismatch", "authorityKeyIdentifier does not match issuer subjectKeyIdentifier", n, detail({
|
|
266
358
|
subjectCommonName: e.subject.values.commonName,
|
|
267
359
|
issuerCommonName: t.subject.values.commonName,
|
|
268
360
|
expected: t.subjectKeyIdentifier,
|
|
@@ -273,18 +365,17 @@ function validateIssuerConstraintsAtPathIndex(e, t, n) {
|
|
|
273
365
|
* Validates a pre-built certificate chain for time, constraints, policy, and
|
|
274
366
|
* optionally leaf purpose. Wrap the result of {@linkcode buildCandidatePath}.
|
|
275
367
|
*/
|
|
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" })));
|
|
368
|
+
async function validateCandidatePath(t) {
|
|
369
|
+
let n = normalizeValidationChain(t.chain);
|
|
370
|
+
if (!n.ok) {
|
|
371
|
+
let { error: t, index: r } = n, i = a(t, e);
|
|
372
|
+
return verifyFailureResult(i === void 0 ? failure("signature_invalid", "certificate input is malformed", r, detail({ actual: t instanceof Error ? t.message : "certificate input is malformed" })) : failure(i.code, i.message, r, detail({ actual: i.message })));
|
|
282
373
|
}
|
|
283
|
-
let
|
|
284
|
-
...
|
|
285
|
-
chain:
|
|
374
|
+
let r = await validateCandidatePathRaw({
|
|
375
|
+
...t,
|
|
376
|
+
chain: n.chain
|
|
286
377
|
});
|
|
287
|
-
return
|
|
378
|
+
return r.ok ? validateCandidatePathSuccessResult(r.policyValidation) : verifyFailureResult(r);
|
|
288
379
|
}
|
|
289
380
|
/**
|
|
290
381
|
* All-in-one certificate chain verification: builds a candidate path then
|
|
@@ -310,43 +401,50 @@ async function validateCandidatePath(e) {
|
|
|
310
401
|
* ```
|
|
311
402
|
*/
|
|
312
403
|
async function verifyCertificateChain(e) {
|
|
313
|
-
let t =
|
|
404
|
+
let t = e.distrustedSpkiSha256 === void 0 ? void 0 : [...e.distrustedSpkiSha256];
|
|
405
|
+
S(e.revocation?.policy?.crlMaxAgeMs);
|
|
406
|
+
let n = await buildCandidatePath({
|
|
314
407
|
leaf: e.leaf,
|
|
315
408
|
roots: e.roots,
|
|
316
409
|
...e.intermediates !== void 0 && { intermediates: e.intermediates },
|
|
317
410
|
...e.trustAnchors !== void 0 && { trustAnchors: e.trustAnchors },
|
|
318
|
-
...e.at !== void 0 && { at: e.at }
|
|
411
|
+
...e.at !== void 0 && { at: e.at },
|
|
412
|
+
...e.maxPathBuildingChecks !== void 0 && { maxPathBuildingChecks: e.maxPathBuildingChecks },
|
|
413
|
+
...t !== void 0 && { distrustedSpkiSha256: t }
|
|
319
414
|
});
|
|
320
|
-
if (!
|
|
321
|
-
let
|
|
322
|
-
chain:
|
|
323
|
-
anchorCertificateInChain:
|
|
415
|
+
if (!n.ok) return n;
|
|
416
|
+
let r = await validateCandidatePath({
|
|
417
|
+
chain: n.value.chain,
|
|
418
|
+
anchorCertificateInChain: n.value.anchorCertificateInChain,
|
|
419
|
+
...n.value.trustAnchor !== void 0 && { trustAnchor: n.value.trustAnchor },
|
|
420
|
+
...t !== void 0 && { distrustedSpkiSha256: t },
|
|
324
421
|
...e.at !== void 0 && { at: e.at },
|
|
325
422
|
...e.purpose !== void 0 && { purpose: e.purpose },
|
|
326
423
|
...copyValidationInputs(e),
|
|
327
|
-
...e.allowSelfSignedLeaf !== void 0 && { allowSelfSignedLeaf: e.allowSelfSignedLeaf }
|
|
424
|
+
...e.allowSelfSignedLeaf !== void 0 && { allowSelfSignedLeaf: e.allowSelfSignedLeaf },
|
|
425
|
+
...e.rejectOversizedDisplayText !== void 0 && { rejectOversizedDisplayText: e.rejectOversizedDisplayText }
|
|
328
426
|
});
|
|
329
|
-
if (!
|
|
427
|
+
if (!r.ok) return r;
|
|
330
428
|
if (e.serviceIdentity !== void 0) {
|
|
331
|
-
let
|
|
332
|
-
if (!
|
|
429
|
+
let t = validateServiceIdentity(n.value.leaf, e.serviceIdentity);
|
|
430
|
+
if (!t.ok) return verifyFailureResult(t);
|
|
333
431
|
}
|
|
334
432
|
if (e.revocation !== void 0) {
|
|
335
|
-
let
|
|
336
|
-
if (
|
|
433
|
+
let t = await validateVerifiedChainRevocation(e, n.value.chain);
|
|
434
|
+
if (t !== void 0) return t;
|
|
337
435
|
}
|
|
338
436
|
return {
|
|
339
437
|
ok: !0,
|
|
340
438
|
value: {
|
|
341
|
-
...
|
|
342
|
-
policyValidation:
|
|
439
|
+
...n.value,
|
|
440
|
+
policyValidation: r.value.policyValidation
|
|
343
441
|
}
|
|
344
442
|
};
|
|
345
443
|
}
|
|
346
444
|
/** Applies optional revocation evidence to an otherwise verified certificate chain. */
|
|
347
445
|
async function validateVerifiedChainRevocation(e, t) {
|
|
348
446
|
if (e.revocation === void 0) return;
|
|
349
|
-
let n = await
|
|
447
|
+
let n = await R({
|
|
350
448
|
chain: t,
|
|
351
449
|
...e.revocation.crls === void 0 ? {} : { crls: e.revocation.crls },
|
|
352
450
|
...e.revocation.ocspResponses === void 0 ? {} : { ocspResponses: e.revocation.ocspResponses },
|
|
@@ -359,13 +457,18 @@ async function validateVerifiedChainRevocation(e, t) {
|
|
|
359
457
|
}
|
|
360
458
|
function revocationFailureResult(e) {
|
|
361
459
|
let t = e.summary.revokedCertificates[0];
|
|
362
|
-
if (t !== void 0) return verifyFailureResult(failure("certificate_revoked", `certificate revoked: ${t.subject.values.commonName ?? "unknown"}`,
|
|
460
|
+
if (t !== void 0) return verifyFailureResult(failure("certificate_revoked", `certificate revoked: ${t.subject.values.commonName ?? "unknown"}`, revocationFailureIndex(e, "revoked"), detail({ subjectCommonName: t.subject.values.commonName })));
|
|
363
461
|
let n = e.summary.indeterminateCertificates[0], r = e.certificates.find((e) => e.status === "indeterminate")?.indeterminateReasons;
|
|
364
|
-
return verifyFailureResult(failure("revocation_indeterminate", `revocation status indeterminate: ${n?.subject.values.commonName ?? "unknown"}`,
|
|
462
|
+
return verifyFailureResult(failure("revocation_indeterminate", `revocation status indeterminate: ${n?.subject.values.commonName ?? "unknown"}`, revocationFailureIndex(e, "indeterminate"), detail({
|
|
365
463
|
subjectCommonName: n?.subject.values.commonName,
|
|
366
464
|
actual: r?.join(", ")
|
|
367
465
|
})));
|
|
368
466
|
}
|
|
467
|
+
/** Revocation evaluates each non-anchor chain certificate in path order. */
|
|
468
|
+
function revocationFailureIndex(e, t) {
|
|
469
|
+
let n = e.certificates.findIndex((e) => e.status === t);
|
|
470
|
+
return n < 0 ? void 0 : n;
|
|
471
|
+
}
|
|
369
472
|
/**
|
|
370
473
|
* Verifies the self-signature of a PKCS#10 certificate signing request.
|
|
371
474
|
*
|
|
@@ -382,28 +485,33 @@ function revocationFailureResult(e) {
|
|
|
382
485
|
* }
|
|
383
486
|
* ```
|
|
384
487
|
*/
|
|
385
|
-
async function verifyCertificateSigningRequest(
|
|
386
|
-
let
|
|
488
|
+
async function verifyCertificateSigningRequest(t) {
|
|
489
|
+
let n;
|
|
387
490
|
try {
|
|
388
|
-
|
|
389
|
-
} catch (
|
|
390
|
-
|
|
491
|
+
n = typeof t == "string" ? x(t) : b(new Uint8Array(t));
|
|
492
|
+
} catch (t) {
|
|
493
|
+
let n = a(t, e);
|
|
494
|
+
return n === void 0 ? verifyRequestFailureResult("signature_invalid", "certificate request input is malformed", detail({ actual: t instanceof Error ? t.message : "certificate request input is malformed" })) : verifyRequestFailureResult(n.code, n.message, detail({ actual: n.message }));
|
|
391
495
|
}
|
|
392
|
-
let
|
|
496
|
+
let r;
|
|
393
497
|
try {
|
|
394
|
-
|
|
395
|
-
} catch (
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
498
|
+
r = await l(n.signatureAlgorithmOid, n.signatureAlgorithmParametersDer, n.publicKeyAlgorithmOid, n.publicKeyParametersOid, n.subjectPublicKeyInfoDer, n.signatureValue, n.certificationRequestInfoDer);
|
|
499
|
+
} catch (t) {
|
|
500
|
+
let r = a(t, e);
|
|
501
|
+
return r === void 0 ? verifyRequestFailureResult("signature_invalid", "certificate request input is malformed", detail({
|
|
502
|
+
subjectCommonName: n.subject.values.commonName,
|
|
503
|
+
actual: t instanceof Error ? t.message : "certificate request input is malformed"
|
|
504
|
+
})) : verifyRequestFailureResult(r.code, r.message, detail({
|
|
505
|
+
subjectCommonName: n.subject.values.commonName,
|
|
506
|
+
actual: r.message
|
|
399
507
|
}));
|
|
400
508
|
}
|
|
401
|
-
return
|
|
509
|
+
return r.ok ? r.valid ? {
|
|
402
510
|
ok: !0,
|
|
403
|
-
value:
|
|
404
|
-
} : verifyRequestFailureResult("signature_invalid", "certificate request signature does not verify", detail({ subjectCommonName:
|
|
405
|
-
subjectCommonName:
|
|
406
|
-
actual:
|
|
511
|
+
value: n
|
|
512
|
+
} : verifyRequestFailureResult("signature_invalid", "certificate request signature does not verify", detail({ subjectCommonName: n.subject.values.commonName })) : verifyRequestFailureResult(r.code === "verification_error" ? "signature_invalid" : r.code, r.reason, detail({
|
|
513
|
+
subjectCommonName: n.subject.values.commonName,
|
|
514
|
+
actual: r.reason
|
|
407
515
|
}));
|
|
408
516
|
}
|
|
409
517
|
/**
|
|
@@ -421,19 +529,18 @@ async function verifyCertificateSigningRequest(e) {
|
|
|
421
529
|
* }
|
|
422
530
|
* ```
|
|
423
531
|
*/
|
|
424
|
-
function checkExtendedKeyUsage(
|
|
425
|
-
let
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
return ekuCheckFailureResult("leaf_eku_missing", "certificate input is malformed", 0);
|
|
532
|
+
function checkExtendedKeyUsage(t, n) {
|
|
533
|
+
let r = normalizeValidationChain(t);
|
|
534
|
+
if (!r.ok) {
|
|
535
|
+
let t = a(r.error, e);
|
|
536
|
+
return t === void 0 ? ekuCheckFailureResult("leaf_eku_missing", "certificate input is malformed", r.index) : ekuCheckFailureResult(t.code, t.message, r.index);
|
|
430
537
|
}
|
|
431
|
-
let r =
|
|
432
|
-
if (
|
|
433
|
-
if (
|
|
434
|
-
for (let e = 1; e <
|
|
435
|
-
let
|
|
436
|
-
if (
|
|
538
|
+
let i = r.chain, o = i[0];
|
|
539
|
+
if (o === void 0) return ekuCheckFailureResult("leaf_eku_missing", "chain is empty", 0);
|
|
540
|
+
if (o.extendedKeyUsage !== void 0 && !o.extendedKeyUsage.includes(n)) return ekuCheckFailureResult("leaf_eku_missing", `leaf certificate does not include EKU ${n}`, 0);
|
|
541
|
+
for (let e = 1; e < i.length; e += 1) {
|
|
542
|
+
let t = i[e];
|
|
543
|
+
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
544
|
}
|
|
438
545
|
return {
|
|
439
546
|
ok: !0,
|
|
@@ -441,19 +548,19 @@ function checkExtendedKeyUsage(e, t) {
|
|
|
441
548
|
};
|
|
442
549
|
}
|
|
443
550
|
/** Extracts a {@linkcode TrustAnchor} from a parsed certificate, copying the subject, SPKI, and key identifiers. */
|
|
444
|
-
function trustAnchorFromCertificate(
|
|
445
|
-
let
|
|
551
|
+
function trustAnchorFromCertificate(t) {
|
|
552
|
+
let n;
|
|
446
553
|
try {
|
|
447
|
-
|
|
448
|
-
} catch {
|
|
449
|
-
throw Error("certificate input is malformed");
|
|
554
|
+
n = reparseCertificateForTrust(t);
|
|
555
|
+
} catch (t) {
|
|
556
|
+
throw o(t, e), Error("certificate input is malformed");
|
|
450
557
|
}
|
|
451
558
|
return {
|
|
452
|
-
subject:
|
|
453
|
-
subjectPublicKeyInfoDer:
|
|
454
|
-
publicKeyAlgorithmOid:
|
|
455
|
-
...
|
|
456
|
-
...
|
|
559
|
+
subject: n.subject,
|
|
560
|
+
subjectPublicKeyInfoDer: n.subjectPublicKeyInfoDer,
|
|
561
|
+
publicKeyAlgorithmOid: n.publicKeyAlgorithmOid,
|
|
562
|
+
...n.publicKeyParametersOid === void 0 ? {} : { publicKeyParametersOid: n.publicKeyParametersOid },
|
|
563
|
+
...n.subjectKeyIdentifier === void 0 ? {} : { subjectKeyIdentifier: n.subjectKeyIdentifier }
|
|
457
564
|
};
|
|
458
565
|
}
|
|
459
566
|
/** Extracts defined optional fields from a base input for safe forwarding. */
|
|
@@ -464,6 +571,8 @@ function baseChainInput(e) {
|
|
|
464
571
|
...e.intermediates !== void 0 && { intermediates: e.intermediates },
|
|
465
572
|
...e.trustAnchors !== void 0 && { trustAnchors: e.trustAnchors },
|
|
466
573
|
...e.at !== void 0 && { at: e.at },
|
|
574
|
+
...e.maxPathBuildingChecks !== void 0 && { maxPathBuildingChecks: e.maxPathBuildingChecks },
|
|
575
|
+
...e.distrustedSpkiSha256 !== void 0 && { distrustedSpkiSha256: e.distrustedSpkiSha256 },
|
|
467
576
|
...copyValidationInputs(e)
|
|
468
577
|
};
|
|
469
578
|
}
|
|
@@ -570,7 +679,7 @@ function validateLeaf(e, t, n) {
|
|
|
570
679
|
function validateServiceIdentity(e, t) {
|
|
571
680
|
let n = validateServiceIdentityInput(t);
|
|
572
681
|
if (!n.ok) return n;
|
|
573
|
-
let r =
|
|
682
|
+
let r = L({
|
|
574
683
|
certificate: reparseCertificateForTrust(e),
|
|
575
684
|
serviceIdentity: t
|
|
576
685
|
});
|
|
@@ -582,7 +691,7 @@ function validateServiceIdentity(e, t) {
|
|
|
582
691
|
message: i.message,
|
|
583
692
|
index: 0,
|
|
584
693
|
...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({
|
|
694
|
+
} : i.code !== "subject_alt_name_mismatch" && i.code !== "common_name_fallback_suppressed" && i.code !== "unsupported" && i.code !== "limit_exceeded" ? failure("subject_alt_name_mismatch", "service identity input is malformed", 0, detail({
|
|
586
695
|
expected: t.value,
|
|
587
696
|
actual: i.code
|
|
588
697
|
})) : {
|
|
@@ -598,7 +707,7 @@ function validateServiceIdentityInput(e) {
|
|
|
598
707
|
if (e.type !== "dns" && e.type !== "ip" && e.type !== "uri" && e.type !== "srv") return failure("subject_alt_name_mismatch", "service identity input is malformed", 0, detail({ actual: String(e.type) }));
|
|
599
708
|
if (typeof e.value != "string") return failure("subject_alt_name_mismatch", "service identity input is malformed", 0, detail({ actual: e.type }));
|
|
600
709
|
if (e.type === "ip") try {
|
|
601
|
-
|
|
710
|
+
f(e.value);
|
|
602
711
|
} catch {
|
|
603
712
|
return failure("subject_alt_name_mismatch", "service identity input is malformed", 0, detail({
|
|
604
713
|
expected: e.value,
|
|
@@ -618,8 +727,23 @@ async function verifyChainForExtendedKeyUsageProfile(e, t) {
|
|
|
618
727
|
return n.ok ? applyEkuCheck(n, t) : n;
|
|
619
728
|
}
|
|
620
729
|
/** Returns the OID of the first critical extension not in {@linkcode PROCESSED_EXTENSION_OIDS}, or `undefined`. */
|
|
621
|
-
function findUnprocessedCriticalExtension(
|
|
622
|
-
for (let
|
|
730
|
+
function findUnprocessedCriticalExtension(e) {
|
|
731
|
+
for (let t of e.extensions) if (t.critical && (!B.has(t.oid) || t.oid === c.subjectAltName && e.subjectAltNames?.some(isUninterpretedGeneralName) === !0)) return t.oid;
|
|
732
|
+
}
|
|
733
|
+
const V = /* @__PURE__ */ new Set([
|
|
734
|
+
"otherName",
|
|
735
|
+
"upn",
|
|
736
|
+
"krb5PrincipalName",
|
|
737
|
+
"x400Address",
|
|
738
|
+
"ediPartyName",
|
|
739
|
+
"unknown"
|
|
740
|
+
]);
|
|
741
|
+
function isUninterpretedGeneralName(e) {
|
|
742
|
+
switch (e.type) {
|
|
743
|
+
case "srv": return h(u(e.value)) === void 0;
|
|
744
|
+
case "smtpUtf8Mailbox": return p(e.value) === void 0;
|
|
745
|
+
default: return V.has(e.type);
|
|
746
|
+
}
|
|
623
747
|
}
|
|
624
748
|
/** Constructs a {@linkcode VerifyChainFailure} with the given code, message, optional chain index, and details. */
|
|
625
749
|
function failure(e, t, n, i) {
|
|
@@ -644,10 +768,23 @@ function describeDateTime(e) {
|
|
|
644
768
|
return Number.isNaN(e.getTime()) ? "<invalid date>" : e.toISOString();
|
|
645
769
|
}
|
|
646
770
|
function normalizeValidationChain(e) {
|
|
647
|
-
|
|
771
|
+
let t = [];
|
|
772
|
+
for (let [n, r] of e.entries()) try {
|
|
773
|
+
t.push(reparseCertificateForTrust(r));
|
|
774
|
+
} catch (e) {
|
|
775
|
+
return {
|
|
776
|
+
ok: !1,
|
|
777
|
+
index: n,
|
|
778
|
+
error: e
|
|
779
|
+
};
|
|
780
|
+
}
|
|
781
|
+
return {
|
|
782
|
+
ok: !0,
|
|
783
|
+
chain: t
|
|
784
|
+
};
|
|
648
785
|
}
|
|
649
786
|
function reparseCertificateForTrust(e) {
|
|
650
|
-
return
|
|
787
|
+
return y(new Uint8Array(e.der));
|
|
651
788
|
}
|
|
652
789
|
/** Returns `true` if the value is a non-negative integer (including zero). */
|
|
653
790
|
function isNonNegativeInteger(e) {
|
|
@@ -655,18 +792,20 @@ function isNonNegativeInteger(e) {
|
|
|
655
792
|
}
|
|
656
793
|
/** Constructs a CSR verification failure result. */
|
|
657
794
|
function verifyRequestFailureResult(e, n, r) {
|
|
658
|
-
|
|
795
|
+
let a = {
|
|
659
796
|
ok: !1,
|
|
660
797
|
...i(e, n, r)
|
|
661
|
-
}
|
|
798
|
+
};
|
|
799
|
+
return t(a);
|
|
662
800
|
}
|
|
663
801
|
/** Constructs an EKU check failure result at the given chain index. */
|
|
664
802
|
function ekuCheckFailureResult(e, t, i) {
|
|
665
|
-
|
|
803
|
+
let a = {
|
|
666
804
|
ok: !1,
|
|
667
805
|
...r(e, t, i),
|
|
668
806
|
index: i
|
|
669
|
-
}
|
|
807
|
+
};
|
|
808
|
+
return n(a);
|
|
670
809
|
}
|
|
671
810
|
/** Merges flat and nested policy fields, with nested taking precedence. */
|
|
672
811
|
function resolvePolicyValidationInput(e) {
|
|
@@ -729,22 +868,36 @@ function detail(e) {
|
|
|
729
868
|
...e.actual === void 0 ? {} : { actual: e.actual },
|
|
730
869
|
...e.chainCommonNames === void 0 ? {} : { chainCommonNames: e.chainCommonNames },
|
|
731
870
|
...e.presentedIdentifierTypes === void 0 ? {} : { presentedIdentifierTypes: e.presentedIdentifierTypes },
|
|
732
|
-
...e.commonNameFallbackReason === void 0 ? {} : { commonNameFallbackReason: e.commonNameFallbackReason }
|
|
871
|
+
...e.commonNameFallbackReason === void 0 ? {} : { commonNameFallbackReason: e.commonNameFallbackReason },
|
|
872
|
+
...e.userNoticeField === void 0 ? {} : { userNoticeField: e.userNoticeField },
|
|
873
|
+
...e.source === void 0 ? {} : { source: e.source }
|
|
733
874
|
};
|
|
734
875
|
}
|
|
735
876
|
/** Initializes policy and name-constraint validation state for a chain walk. */
|
|
736
877
|
function buildValidationState(e, t) {
|
|
737
|
-
let n =
|
|
878
|
+
let n = T(resolvePolicyValidationInput(e), t), r = validateInitialNameConstraintsInput(resolveInitialNameConstraintsInput(e));
|
|
738
879
|
return r.ok ? {
|
|
739
880
|
ok: !0,
|
|
740
881
|
value: {
|
|
741
882
|
policy: n,
|
|
742
|
-
nameConstraints:
|
|
883
|
+
nameConstraints: C(r.value)
|
|
743
884
|
}
|
|
744
885
|
} : r;
|
|
745
886
|
}
|
|
746
887
|
function normalizeInitialPolicySet(e) {
|
|
747
|
-
if (e
|
|
888
|
+
if (e === void 0) return;
|
|
889
|
+
if (e === "any") return e;
|
|
890
|
+
if (!Array.isArray(e)) return [];
|
|
891
|
+
let t = [];
|
|
892
|
+
for (let n of e) {
|
|
893
|
+
if (typeof n != "string") return [];
|
|
894
|
+
try {
|
|
895
|
+
t.push(s(n));
|
|
896
|
+
} catch {
|
|
897
|
+
return [];
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
return t.includes(c.anyPolicy) ? "any" : t;
|
|
748
901
|
}
|
|
749
902
|
function validateInitialNameConstraintsInput(e) {
|
|
750
903
|
let t = validateInitialNameConstraintSubtrees(e.permittedSubtrees, "permittedSubtrees");
|
|
@@ -752,26 +905,64 @@ function validateInitialNameConstraintsInput(e) {
|
|
|
752
905
|
let n = validateInitialNameConstraintSubtrees(e.excludedSubtrees, "excludedSubtrees");
|
|
753
906
|
return n.ok ? {
|
|
754
907
|
ok: !0,
|
|
755
|
-
value:
|
|
908
|
+
value: {
|
|
909
|
+
...t.value === void 0 ? {} : { permittedSubtrees: t.value },
|
|
910
|
+
...n.value === void 0 ? {} : { excludedSubtrees: n.value }
|
|
911
|
+
}
|
|
756
912
|
} : n;
|
|
757
913
|
}
|
|
758
914
|
function validateInitialNameConstraintSubtrees(e, t) {
|
|
759
915
|
if (e === void 0) return { ok: !0 };
|
|
760
916
|
if (!Array.isArray(e)) return invalidInitialNameConstraintsFailure(t);
|
|
917
|
+
let n = [];
|
|
761
918
|
for (let t of e) {
|
|
762
919
|
let e = describeInvalidInitialNameConstraintForm(t);
|
|
763
920
|
if (e !== void 0) return invalidInitialNameConstraintsFailure(e);
|
|
921
|
+
let r = toAsciiInitialNameConstraint(t);
|
|
922
|
+
if (r === void 0) return invalidInitialNameConstraintsFailure(t.base.type);
|
|
923
|
+
n.push(r);
|
|
764
924
|
}
|
|
765
|
-
return {
|
|
925
|
+
return {
|
|
926
|
+
ok: !0,
|
|
927
|
+
value: n
|
|
928
|
+
};
|
|
929
|
+
}
|
|
930
|
+
/**
|
|
931
|
+
* RFC 9549 §1, RFC 9598 §6 and RFC 4985 §3: a DNS or mail domain constraint, or
|
|
932
|
+
* the Name of a SRVName constraint, in A-labels.
|
|
933
|
+
*/
|
|
934
|
+
function toAsciiInitialNameConstraint(e) {
|
|
935
|
+
let { base: t } = e;
|
|
936
|
+
if (t.type !== "dns" && t.type !== "email" && t.type !== "srv") return e;
|
|
937
|
+
let n = t.type === "srv" ? m(t.value) : t.value, r = unconvertedConstraintPrefix(t.type, n), i = n.slice(r.length);
|
|
938
|
+
if (t.type !== "srv" && i.endsWith(".")) return;
|
|
939
|
+
let a = t.type === "srv" && i.length === 0 ? void 0 : d(i, "lookup");
|
|
940
|
+
if (a !== void 0 && !a.ok) return;
|
|
941
|
+
let o = `${r}${a?.value ?? ""}`;
|
|
942
|
+
if (!(!/^[\x20-\x7e]*$/.test(o) || t.type === "srv" && g(o) === void 0)) return {
|
|
943
|
+
...e,
|
|
944
|
+
base: {
|
|
945
|
+
...t,
|
|
946
|
+
value: o
|
|
947
|
+
}
|
|
948
|
+
};
|
|
949
|
+
}
|
|
950
|
+
/** The leading `.` of a domain constraint, or the `_Service` label of a SRVName constraint with its dot. */
|
|
951
|
+
function unconvertedConstraintPrefix(e, t) {
|
|
952
|
+
if (e !== "srv") return t.startsWith(".") ? "." : "";
|
|
953
|
+
if (!t.startsWith("_")) return "";
|
|
954
|
+
let n = t.indexOf(".");
|
|
955
|
+
return n < 0 ? t : t.slice(0, n + 1);
|
|
766
956
|
}
|
|
767
957
|
function describeInvalidInitialNameConstraintForm(e) {
|
|
768
958
|
if (!isRecord(e)) return "invalid subtree";
|
|
769
959
|
let t = e.base;
|
|
770
960
|
if (!isRecord(t) || typeof t.type != "string") return "invalid subtree";
|
|
771
961
|
switch (t.type) {
|
|
772
|
-
case "dns":
|
|
773
|
-
case "
|
|
774
|
-
case "
|
|
962
|
+
case "dns": return typeof t.value == "string" ? void 0 : t.type;
|
|
963
|
+
case "uri": return typeof t.value == "string" && _(t.value) !== void 0 ? void 0 : t.type;
|
|
964
|
+
case "email": return typeof t.value == "string" && !t.value.includes("@") ? void 0 : t.type;
|
|
965
|
+
case "srv": return typeof t.value == "string" && t.value.length > 0 ? void 0 : t.type;
|
|
775
966
|
case "directoryName": return typeof t.derHex == "string" ? void 0 : t.type;
|
|
776
967
|
case "ip": return t.addressBytes instanceof Uint8Array && t.maskBytes instanceof Uint8Array ? void 0 : t.type;
|
|
777
968
|
case "otherName":
|
|
@@ -787,7 +978,6 @@ function invalidInitialNameConstraintsFailure(e) {
|
|
|
787
978
|
function isRecord(e) {
|
|
788
979
|
return typeof e == "object" && !!e;
|
|
789
980
|
}
|
|
790
|
-
|
|
791
|
-
export { T as VERIFY_ERROR_CODES, buildCandidatePath, checkExtendedKeyUsage, v as isSelfIssuedCertificate, trustAnchorFromCertificate, validateCandidatePath, validateForCa, validateForCodeSigning, validateForTlsClient, validateForTlsServer, verifyCertificateChain, verifyCertificateSigningRequest };
|
|
981
|
+
export { z as VERIFY_ERROR_CODES, buildCandidatePath, checkExtendedKeyUsage, M as isSelfIssuedCertificate, trustAnchorFromCertificate, validateCandidatePath, validateForCa, validateForCodeSigning, validateForTlsClient, validateForTlsServer, verifyCertificateChain, verifyCertificateSigningRequest };
|
|
792
982
|
|
|
793
983
|
//# sourceMappingURL=verify.js.map
|