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
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
import { DECODE_LIMIT_CODES as e, decodeRefusalOf as t } from "../asn1/decode-refusal.js";
|
|
2
|
+
import { toHex as n } from "../asn1/asn1.js";
|
|
3
|
+
import { verifySignedDataDetailed as r } from "../crypto/sig-verify.js";
|
|
4
|
+
import { canonicalDnKey as i, compareDistinguishedNames as a } from "../shared/dn.js";
|
|
5
|
+
import { parseCertificatesFromSource as o } from "../../x509/parse.js";
|
|
6
|
+
// src/internal/verify/verify-path.ts
|
|
6
7
|
/**
|
|
7
8
|
* Internal certificate path-building and signature-check helpers.
|
|
8
9
|
*
|
|
@@ -12,13 +13,19 @@ import { verifySignedDataDetailed as i } from "../crypto/sig-verify.js";
|
|
|
12
13
|
*
|
|
13
14
|
* @module
|
|
14
15
|
*/
|
|
16
|
+
/** Default upper bound on issuer candidates and trust anchors one path search may try. */
|
|
17
|
+
const s = 1e5;
|
|
18
|
+
/** Throws when a caller-supplied path-building limit is not a positive safe integer. */
|
|
19
|
+
function assertPathBuildingChecks(e) {
|
|
20
|
+
if (e !== void 0 && (!Number.isSafeInteger(e) || e < 1)) throw RangeError(`Invalid maxPathBuildingChecks: must be an integer >= 1, got ${e}`);
|
|
21
|
+
}
|
|
15
22
|
/** Returns `true` if `at` falls within the certificate's notBefore/notAfter window (inclusive). */
|
|
16
23
|
function isWithinValidity(e, t) {
|
|
17
24
|
return e.notBefore.getTime() <= t.getTime() && t.getTime() <= e.notAfter.getTime();
|
|
18
25
|
}
|
|
19
26
|
/** Returns `true` if the certificate's subject and issuer DNs are semantically equal (RFC 5280 §7.1). */
|
|
20
27
|
function isSelfIssued(e) {
|
|
21
|
-
return
|
|
28
|
+
return a(e.subject, e.issuer);
|
|
22
29
|
}
|
|
23
30
|
/** Counts non-self-issued CA certificates in positions 0..(index-1) for pathLength checking. */
|
|
24
31
|
function countCaCertificatesBelowParsed(e, t) {
|
|
@@ -43,13 +50,76 @@ function loadSingleCertificate(e) {
|
|
|
43
50
|
return n;
|
|
44
51
|
}
|
|
45
52
|
/** Verifies that `certificate` was signed by `issuer`'s public key. */
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
53
|
+
function verifyCertificateSignature(e, t) {
|
|
54
|
+
return signatureCheck(() => r(e.signatureAlgorithmOid, e.signatureAlgorithmParametersDer, t.publicKeyAlgorithmOid, t.publicKeyParametersOid, t.subjectPublicKeyInfoDer, e.signatureValue, e.tbsCertificateDer));
|
|
55
|
+
}
|
|
56
|
+
/** Runs `verify` as a path check, reporting a runtime failure as `signature_invalid` and a decoding limit as `limit_exceeded`. */
|
|
57
|
+
async function signatureCheck(n) {
|
|
58
|
+
let r;
|
|
59
|
+
try {
|
|
60
|
+
r = await n();
|
|
61
|
+
} catch (n) {
|
|
62
|
+
let r = t(n, e);
|
|
63
|
+
if (r === void 0) throw n;
|
|
64
|
+
return {
|
|
65
|
+
ok: !1,
|
|
66
|
+
code: r.code,
|
|
67
|
+
reason: r.message
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
return !r.ok && r.code === "verification_error" ? {
|
|
49
71
|
ok: !1,
|
|
50
72
|
code: "signature_invalid",
|
|
51
|
-
reason:
|
|
52
|
-
} :
|
|
73
|
+
reason: r.reason
|
|
74
|
+
} : r;
|
|
75
|
+
}
|
|
76
|
+
/** The real signature checks, used unless a caller injects its own. */
|
|
77
|
+
const c = {
|
|
78
|
+
certificate: verifyCertificateSignature,
|
|
79
|
+
trustAnchor: verifyTrustAnchorSignature
|
|
80
|
+
}, l = {
|
|
81
|
+
"specific-failure": 3,
|
|
82
|
+
"untrusted-anchor": 2,
|
|
83
|
+
"missing-issuer": 1,
|
|
84
|
+
none: 0
|
|
85
|
+
};
|
|
86
|
+
function isMoreSignificant(e, t) {
|
|
87
|
+
let n = l[e.kind], r = l[t.kind];
|
|
88
|
+
return n === r ? e.path.length > t.path.length : n > r;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Moves a diagnostic recorded below the certificate at `nodeIndex` onto a new
|
|
92
|
+
* prefix ending at that same certificate. A suffix that repeats a certificate
|
|
93
|
+
* of the new prefix cannot form a path, so only the prefix is reported.
|
|
94
|
+
*/
|
|
95
|
+
function rebaseDiagnostic(e, t, n) {
|
|
96
|
+
let r = e.path.slice(t + 1), i = new Set(n.map((e) => fingerprint(e)));
|
|
97
|
+
if (r.some((e) => i.has(fingerprint(e)))) return {
|
|
98
|
+
kind: "none",
|
|
99
|
+
path: n
|
|
100
|
+
};
|
|
101
|
+
let a = [...n, ...r], o = n.length - 1 - t;
|
|
102
|
+
switch (e.kind) {
|
|
103
|
+
case "none":
|
|
104
|
+
case "untrusted-anchor": return {
|
|
105
|
+
kind: e.kind,
|
|
106
|
+
path: a
|
|
107
|
+
};
|
|
108
|
+
case "missing-issuer": return {
|
|
109
|
+
kind: "missing-issuer",
|
|
110
|
+
path: a,
|
|
111
|
+
missingIssuerAt: e.missingIssuerAt + o
|
|
112
|
+
};
|
|
113
|
+
case "specific-failure": return {
|
|
114
|
+
kind: "specific-failure",
|
|
115
|
+
path: a,
|
|
116
|
+
failure: e.failure.index === void 0 ? e.failure : {
|
|
117
|
+
...e.failure,
|
|
118
|
+
index: e.failure.index + o
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
default: throw Error(`unreachable diagnostic ${String(e)}`);
|
|
122
|
+
}
|
|
53
123
|
}
|
|
54
124
|
/**
|
|
55
125
|
* Depth-first chain search from leaf to root. Tries all issuer candidates,
|
|
@@ -57,93 +127,176 @@ async function verifyCertificateSignature(e, t) {
|
|
|
57
127
|
* step. Returns the first fully anchored path or the deepest partial path
|
|
58
128
|
* with the best failure encountered.
|
|
59
129
|
*/
|
|
60
|
-
async function buildChainInternal(e,
|
|
61
|
-
let
|
|
62
|
-
for (let e of
|
|
63
|
-
let
|
|
64
|
-
|
|
130
|
+
async function buildChainInternal(e, t, r, a, o, l, u = c, d = s, f = () => Promise.resolve(void 0)) {
|
|
131
|
+
let p, m = [...t, ...r], h = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Map(), _ = new Set(r.map((e) => fingerprint(e))), v = /* @__PURE__ */ new Map();
|
|
132
|
+
for (let e of a) {
|
|
133
|
+
let t = i(e.subject), n = v.get(t);
|
|
134
|
+
n === void 0 ? v.set(t, [e]) : n.push(e);
|
|
65
135
|
}
|
|
66
|
-
let
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
136
|
+
let y = { current: {
|
|
137
|
+
kind: "none",
|
|
138
|
+
path: [e]
|
|
139
|
+
} }, b = /* @__PURE__ */ new Map(), x = [], S = /* @__PURE__ */ new Map(), C = {
|
|
140
|
+
remaining: d,
|
|
141
|
+
exhausted: !1
|
|
142
|
+
}, w = /* @__PURE__ */ new Map();
|
|
143
|
+
m.forEach((e, t) => {
|
|
144
|
+
let n = i(e.subject), r = h.get(n);
|
|
145
|
+
r === void 0 ? h.set(n, [e]) : r.push(e), g.set(fingerprint(e), t);
|
|
70
146
|
});
|
|
71
|
-
let
|
|
72
|
-
if (
|
|
73
|
-
let e =
|
|
147
|
+
let T = m.length + 1, E = fingerprint(e), D = await search(e, [e], /* @__PURE__ */ new Set([E]), 0);
|
|
148
|
+
if (D !== void 0) {
|
|
149
|
+
let e = D[D.length - 1];
|
|
74
150
|
return {
|
|
75
|
-
chain:
|
|
151
|
+
chain: D,
|
|
76
152
|
foundTrustedRoot: !0,
|
|
77
|
-
|
|
153
|
+
...p !== void 0 && { trustAnchor: p },
|
|
154
|
+
anchorCertificateInChain: e !== void 0 && _.has(fingerprint(e))
|
|
78
155
|
};
|
|
79
156
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
failure: h
|
|
84
|
-
};
|
|
85
|
-
if (f) return {
|
|
86
|
-
chain: p,
|
|
87
|
-
foundTrustedRoot: !1
|
|
88
|
-
};
|
|
89
|
-
return m === void 0 ? {
|
|
90
|
-
chain: p,
|
|
91
|
-
foundTrustedRoot: !1
|
|
92
|
-
} : {
|
|
93
|
-
chain: p,
|
|
157
|
+
let O = y.current;
|
|
158
|
+
if (C.exhausted) return {
|
|
159
|
+
chain: O.path,
|
|
94
160
|
foundTrustedRoot: !1,
|
|
95
|
-
|
|
161
|
+
failure: l.failure("path_building_limit_exceeded", "path building stopped at its work limit", void 0, l.detail({
|
|
162
|
+
expected: `at most ${d} issuer and trust-anchor checks`,
|
|
163
|
+
actual: "limit reached before a trusted path was found"
|
|
164
|
+
}))
|
|
96
165
|
};
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
166
|
+
switch (O.kind) {
|
|
167
|
+
case "specific-failure": return {
|
|
168
|
+
chain: O.path,
|
|
169
|
+
foundTrustedRoot: !1,
|
|
170
|
+
failure: O.failure
|
|
171
|
+
};
|
|
172
|
+
case "missing-issuer": return {
|
|
173
|
+
chain: O.path,
|
|
174
|
+
foundTrustedRoot: !1,
|
|
175
|
+
missingIssuerAt: O.missingIssuerAt
|
|
176
|
+
};
|
|
177
|
+
case "untrusted-anchor":
|
|
178
|
+
case "none": return {
|
|
179
|
+
chain: O.path,
|
|
180
|
+
foundTrustedRoot: !1
|
|
181
|
+
};
|
|
182
|
+
default: throw Error(`unreachable diagnostic ${String(O)}`);
|
|
183
|
+
}
|
|
184
|
+
async function search(e, t, n, r) {
|
|
185
|
+
if (C.exhausted) return;
|
|
186
|
+
let i = await f(e.subjectPublicKeyInfoDer);
|
|
187
|
+
if (i !== void 0) {
|
|
188
|
+
recordFailure(l.failure("public_key_distrusted", "certificate public key is explicitly distrusted", t.length - 1, l.detail({
|
|
189
|
+
subjectCommonName: e.subject.values.commonName,
|
|
190
|
+
actual: i
|
|
191
|
+
})), t);
|
|
107
192
|
return;
|
|
108
193
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
194
|
+
if (_.has(fingerprint(e))) return t;
|
|
195
|
+
let a = await matchTrustAnchor(e, v, l, t.length - 1, verifyAnchorOnce, chargeBudget, f);
|
|
196
|
+
if (C.exhausted) return;
|
|
197
|
+
if (a.failure !== void 0 && recordFailure(a.failure, t), a.matched) return p = a.anchor, t;
|
|
198
|
+
if (t.length > T) return;
|
|
199
|
+
let o = `${fingerprint(e)}:${r}`, s = b.get(o);
|
|
200
|
+
if (s !== void 0) {
|
|
201
|
+
consider(rebaseDiagnostic(s.diagnostic, s.nodeIndex, t));
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
let c = { best: {
|
|
205
|
+
kind: "none",
|
|
206
|
+
path: t
|
|
207
|
+
} };
|
|
208
|
+
x.push(c);
|
|
209
|
+
try {
|
|
210
|
+
let i = await searchBelow(e, t, n, r);
|
|
211
|
+
if (i !== void 0) return i;
|
|
212
|
+
} finally {
|
|
213
|
+
x.pop();
|
|
214
|
+
}
|
|
215
|
+
b.set(o, {
|
|
216
|
+
diagnostic: c.best,
|
|
217
|
+
nodeIndex: t.length - 1
|
|
218
|
+
});
|
|
112
219
|
}
|
|
113
|
-
function
|
|
114
|
-
|
|
220
|
+
async function searchBelow(e, t, n, r) {
|
|
221
|
+
let i = !1;
|
|
222
|
+
for (let a of issuerCandidates(e)) {
|
|
223
|
+
if (!chargeBudget()) return;
|
|
224
|
+
if (!isIssuerOf(a, e)) continue;
|
|
225
|
+
i = !0;
|
|
226
|
+
let o = fingerprint(a);
|
|
227
|
+
if (n.has(o)) continue;
|
|
228
|
+
let s = await searchIssuerCandidate(e, a, o, t, n, r);
|
|
229
|
+
if (s !== void 0) return s;
|
|
230
|
+
if (C.exhausted) return;
|
|
231
|
+
}
|
|
232
|
+
i ? consider({
|
|
233
|
+
kind: "none",
|
|
234
|
+
path: t
|
|
235
|
+
}) : recordMissingIssuers(e, t);
|
|
115
236
|
}
|
|
116
|
-
/**
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
237
|
+
/** Yields the issuer bucket for `current`: AKI matches first, then roots, then input order. */
|
|
238
|
+
function* issuerCandidates(e) {
|
|
239
|
+
let t = i(e.issuer), n = w.get(t);
|
|
240
|
+
n === void 0 && (n = rankBucket(h.get(t) ?? [], g, _), w.set(t, n));
|
|
241
|
+
let r = e.authorityKeyIdentifier;
|
|
242
|
+
if (r === void 0) yield* n.ordered;
|
|
243
|
+
else {
|
|
244
|
+
yield* n.bySubjectKeyIdentifier.get(r) ?? [];
|
|
245
|
+
for (let e of n.ordered) e.subjectKeyIdentifier !== r && (yield e);
|
|
121
246
|
}
|
|
122
247
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
248
|
+
function recordMissingIssuers(e, t) {
|
|
249
|
+
isSelfIssued(e) ? consider({
|
|
250
|
+
kind: "untrusted-anchor",
|
|
251
|
+
path: t
|
|
252
|
+
}) : t.length > 1 && consider({
|
|
253
|
+
kind: "missing-issuer",
|
|
254
|
+
path: t,
|
|
255
|
+
missingIssuerAt: t.length - 1
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
async function searchIssuerCandidate(e, t, n, r, i, a) {
|
|
259
|
+
let s = await evaluateIssuerCandidate(e, t, r, a, o, l, verifySignatureOnce);
|
|
260
|
+
if (!s.ok) {
|
|
261
|
+
recordFailure(s.failure, r);
|
|
129
262
|
return;
|
|
130
263
|
}
|
|
131
|
-
let
|
|
132
|
-
return
|
|
264
|
+
let c = new Set(i);
|
|
265
|
+
return c.add(n), await search(t, [...r, t], c, s.nextCaBelowCount);
|
|
266
|
+
}
|
|
267
|
+
function chargeBudget() {
|
|
268
|
+
return C.remaining === 0 ? (C.exhausted = !0, !1) : (--C.remaining, !0);
|
|
269
|
+
}
|
|
270
|
+
function verifySignatureOnce(e, t) {
|
|
271
|
+
return verifyOnce(`c:${fingerprint(e)}:${n(t.subjectPublicKeyInfoDer)}`, () => u.certificate(e, t));
|
|
133
272
|
}
|
|
134
|
-
function
|
|
135
|
-
|
|
273
|
+
function verifyAnchorOnce(e, t) {
|
|
274
|
+
let r = `${t.publicKeyAlgorithmOid}:${t.publicKeyParametersOid ?? ""}:${n(t.subjectPublicKeyInfoDer)}`;
|
|
275
|
+
return verifyOnce(`a:${fingerprint(e)}:${r}`, () => u.trustAnchor(e, t));
|
|
276
|
+
}
|
|
277
|
+
/** One signature check per distinct certificate-and-key pair for the whole search. */
|
|
278
|
+
function verifyOnce(e, t) {
|
|
279
|
+
let n = S.get(e);
|
|
280
|
+
return n === void 0 && (n = t(), S.set(e, n)), n;
|
|
281
|
+
}
|
|
282
|
+
function consider(e) {
|
|
283
|
+
isMoreSignificant(e, y.current) && (y.current = e);
|
|
284
|
+
for (let t of x) isMoreSignificant(e, t.best) && (t.best = e);
|
|
136
285
|
}
|
|
137
286
|
function recordFailure(e, t) {
|
|
138
|
-
(
|
|
287
|
+
consider({
|
|
288
|
+
kind: "specific-failure",
|
|
289
|
+
path: t,
|
|
290
|
+
failure: e
|
|
291
|
+
});
|
|
139
292
|
}
|
|
140
293
|
}
|
|
141
294
|
/** Applies issuer constraints and signature verification to one path candidate. */
|
|
142
|
-
async function evaluateIssuerCandidate(e, t, n, r, i, a) {
|
|
143
|
-
let
|
|
144
|
-
if (!
|
|
145
|
-
let
|
|
146
|
-
return
|
|
295
|
+
async function evaluateIssuerCandidate(e, t, n, r, i, a, o) {
|
|
296
|
+
let s = evaluateIssuerConstraints(e, t, n, r, i, a);
|
|
297
|
+
if (!s.ok) return s;
|
|
298
|
+
let c = await o(e, t);
|
|
299
|
+
return c.ok ? c.valid ? s : {
|
|
147
300
|
ok: !1,
|
|
148
301
|
failure: a.failure("signature_invalid", "certificate signature does not verify", n.length - 1, a.detail({
|
|
149
302
|
subjectCommonName: e.subject.values.commonName,
|
|
@@ -151,10 +304,10 @@ async function evaluateIssuerCandidate(e, t, n, r, i, a) {
|
|
|
151
304
|
}))
|
|
152
305
|
} : {
|
|
153
306
|
ok: !1,
|
|
154
|
-
failure: a.failure(
|
|
307
|
+
failure: a.failure(c.code, c.reason, n.length - 1, a.detail({
|
|
155
308
|
subjectCommonName: e.subject.values.commonName,
|
|
156
309
|
issuerCommonName: t.subject.values.commonName,
|
|
157
|
-
actual:
|
|
310
|
+
actual: c.reason
|
|
158
311
|
}))
|
|
159
312
|
};
|
|
160
313
|
}
|
|
@@ -203,22 +356,24 @@ function authorityKeyIdentifierMismatch(e, t) {
|
|
|
203
356
|
}
|
|
204
357
|
/** Expands a PEM (possibly multi-block) or DER source into parsed certificates. */
|
|
205
358
|
function expandSource(e) {
|
|
206
|
-
return
|
|
207
|
-
}
|
|
208
|
-
/** Filters and sorts issuer candidates: AKI match first, then roots, then input order. */
|
|
209
|
-
function rankIssuerCandidates(e, t, n, r) {
|
|
210
|
-
let i = e.authorityKeyIdentifier, a = [...t].filter((t) => isIssuerOf(t, e)), o = /* @__PURE__ */ new Map();
|
|
211
|
-
for (let e of a) o.set(e, fingerprint(e));
|
|
212
|
-
return a.sort((e, t) => {
|
|
213
|
-
let a = compareBooleans(matchesAki(e, i), matchesAki(t, i));
|
|
214
|
-
if (a !== 0) return a;
|
|
215
|
-
let s = o.get(e) ?? "", c = o.get(t) ?? "", l = compareBooleans(r.has(s), r.has(c));
|
|
216
|
-
return l === 0 ? (n.get(s) ?? 2 ** 53 - 1) - (n.get(c) ?? 2 ** 53 - 1) : l;
|
|
217
|
-
});
|
|
359
|
+
return o(e);
|
|
218
360
|
}
|
|
219
|
-
/**
|
|
220
|
-
function
|
|
221
|
-
|
|
361
|
+
/** Orders one subject bucket once, roots first and then input order, and indexes it by SKI. */
|
|
362
|
+
function rankBucket(e, t, n) {
|
|
363
|
+
let r = [...e].sort((e, r) => {
|
|
364
|
+
let i = fingerprint(e), a = fingerprint(r), o = compareBooleans(n.has(i), n.has(a));
|
|
365
|
+
return o === 0 ? (t.get(i) ?? 2 ** 53 - 1) - (t.get(a) ?? 2 ** 53 - 1) : o;
|
|
366
|
+
}), i = /* @__PURE__ */ new Map();
|
|
367
|
+
for (let e of r) {
|
|
368
|
+
let t = e.subjectKeyIdentifier;
|
|
369
|
+
if (t === void 0) continue;
|
|
370
|
+
let n = i.get(t);
|
|
371
|
+
n === void 0 ? i.set(t, [e]) : n.push(e);
|
|
372
|
+
}
|
|
373
|
+
return {
|
|
374
|
+
ordered: r,
|
|
375
|
+
bySubjectKeyIdentifier: i
|
|
376
|
+
};
|
|
222
377
|
}
|
|
223
378
|
/** Sort comparator: `true` sorts before `false`. Returns -1, 0, or 1. */
|
|
224
379
|
function compareBooleans(e, t) {
|
|
@@ -226,47 +381,46 @@ function compareBooleans(e, t) {
|
|
|
226
381
|
}
|
|
227
382
|
/** Returns `true` if `issuer`'s subject DN semantically matches `child`'s issuer DN (RFC 5280 §7.1). */
|
|
228
383
|
function isIssuerOf(e, t) {
|
|
229
|
-
return
|
|
384
|
+
return a(t.issuer, e.subject);
|
|
230
385
|
}
|
|
231
386
|
/** Attempts to verify `certificate` against each bare trust anchor whose subject DN matches. */
|
|
232
|
-
async function matchTrustAnchor(e, r,
|
|
233
|
-
let
|
|
234
|
-
if (
|
|
235
|
-
let
|
|
236
|
-
for (let t of
|
|
237
|
-
if (
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
actual: r.reason
|
|
243
|
-
})));
|
|
244
|
-
continue;
|
|
245
|
-
}
|
|
246
|
-
if (!r.valid) {
|
|
247
|
-
s === void 0 && (s = i.failure("signature_invalid", "certificate signature does not verify", a, i.detail({
|
|
248
|
-
subjectCommonName: e.subject.values.commonName,
|
|
249
|
-
actual: "certificate signature does not verify"
|
|
250
|
-
})));
|
|
387
|
+
async function matchTrustAnchor(e, t, n, r, o, s, c) {
|
|
388
|
+
let l = t.get(i(e.issuer));
|
|
389
|
+
if (l === void 0) return { matched: !1 };
|
|
390
|
+
let u;
|
|
391
|
+
for (let t of l) {
|
|
392
|
+
if (!s()) return { matched: !1 };
|
|
393
|
+
if (trustAnchorAkiMismatch(e, t) || !a(e.issuer, t.subject)) continue;
|
|
394
|
+
let i = await c(t.subjectPublicKeyInfoDer);
|
|
395
|
+
if (i !== void 0) {
|
|
396
|
+
u = n.failure("public_key_distrusted", "bare trust anchor public key is explicitly distrusted", void 0, n.detail({ actual: i }));
|
|
251
397
|
continue;
|
|
252
398
|
}
|
|
253
|
-
|
|
399
|
+
let l = await o(e, t);
|
|
400
|
+
if (!l.ok) u ??= n.failure(l.code, l.reason, r, n.detail({
|
|
401
|
+
subjectCommonName: e.subject.values.commonName,
|
|
402
|
+
actual: l.reason
|
|
403
|
+
}));
|
|
404
|
+
else if (!l.valid) u === void 0 && (u = n.failure("signature_invalid", "certificate signature does not verify", r, n.detail({
|
|
405
|
+
subjectCommonName: e.subject.values.commonName,
|
|
406
|
+
actual: "certificate signature does not verify"
|
|
407
|
+
})));
|
|
408
|
+
else return {
|
|
409
|
+
matched: !0,
|
|
410
|
+
anchor: t
|
|
411
|
+
};
|
|
254
412
|
}
|
|
255
|
-
return
|
|
413
|
+
return u === void 0 ? { matched: !1 } : {
|
|
256
414
|
matched: !1,
|
|
257
|
-
failure:
|
|
415
|
+
failure: u
|
|
258
416
|
};
|
|
259
417
|
}
|
|
260
418
|
function trustAnchorAkiMismatch(e, t) {
|
|
261
419
|
return t.subjectKeyIdentifier !== void 0 && e.authorityKeyIdentifier !== void 0 && t.subjectKeyIdentifier !== e.authorityKeyIdentifier;
|
|
262
420
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
return
|
|
266
|
-
ok: !1,
|
|
267
|
-
code: "signature_invalid",
|
|
268
|
-
reason: n.reason
|
|
269
|
-
} : n;
|
|
421
|
+
/** Verifies that `certificate` was signed by a bare trust anchor's key. */
|
|
422
|
+
function verifyTrustAnchorSignature(e, t) {
|
|
423
|
+
return signatureCheck(() => r(e.signatureAlgorithmOid, e.signatureAlgorithmParametersDer, t.publicKeyAlgorithmOid, t.publicKeyParametersOid, t.subjectPublicKeyInfoDer, e.signatureValue, e.tbsCertificateDer));
|
|
270
424
|
}
|
|
271
425
|
function describeDateTime(e) {
|
|
272
426
|
return Number.isNaN(e.getTime()) ? "<invalid date>" : e.toISOString();
|
|
@@ -275,13 +429,12 @@ function isNonNegativeInteger(e) {
|
|
|
275
429
|
return e !== void 0 && Number.isInteger(e) && e >= 0;
|
|
276
430
|
}
|
|
277
431
|
/** Cache for computed fingerprints to avoid repeated toHex() calls. */
|
|
278
|
-
const
|
|
432
|
+
const u = /* @__PURE__ */ new WeakMap();
|
|
279
433
|
/** Returns a hex fingerprint of the certificate's raw DER, used for cycle detection and dedup. */
|
|
280
|
-
function fingerprint(
|
|
281
|
-
let
|
|
282
|
-
return
|
|
434
|
+
function fingerprint(e) {
|
|
435
|
+
let t = u.get(e);
|
|
436
|
+
return t === void 0 && (t = n(e.der), u.set(e, t)), t;
|
|
283
437
|
}
|
|
284
|
-
|
|
285
|
-
export { authorityKeyIdentifierMismatch, buildChainInternal, countCaCertificatesBelowParsed, isSelfIssued, isWithinValidity, loadCertificates, loadSingleCertificate, verifyCertificateSignature };
|
|
438
|
+
export { s as DEFAULT_MAX_PATH_BUILDING_CHECKS, assertPathBuildingChecks, authorityKeyIdentifierMismatch, buildChainInternal, countCaCertificatesBelowParsed, isSelfIssued, isWithinValidity, loadCertificates, loadSingleCertificate, rebaseDiagnostic, verifyCertificateSignature, verifyTrustAnchorSignature };
|
|
286
439
|
|
|
287
440
|
//# sourceMappingURL=verify-path.js.map
|