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
|
@@ -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,167 @@ 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) {
|
|
131
|
+
let f = [...t, ...r], p = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), h = new Set(r.map((e) => fingerprint(e))), g = /* @__PURE__ */ new Map();
|
|
132
|
+
for (let e of a) {
|
|
133
|
+
let t = i(e.subject), n = g.get(t);
|
|
134
|
+
n === void 0 ? g.set(t, [e]) : n.push(e);
|
|
65
135
|
}
|
|
66
|
-
let
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
136
|
+
let _ = { current: {
|
|
137
|
+
kind: "none",
|
|
138
|
+
path: [e]
|
|
139
|
+
} }, v = /* @__PURE__ */ new Map(), y = [], b = /* @__PURE__ */ new Map(), x = {
|
|
140
|
+
remaining: d,
|
|
141
|
+
exhausted: !1
|
|
142
|
+
}, S = /* @__PURE__ */ new Map();
|
|
143
|
+
f.forEach((e, t) => {
|
|
144
|
+
let n = i(e.subject), r = p.get(n);
|
|
145
|
+
r === void 0 ? p.set(n, [e]) : r.push(e), m.set(fingerprint(e), t);
|
|
70
146
|
});
|
|
71
|
-
let
|
|
72
|
-
if (
|
|
73
|
-
let e =
|
|
147
|
+
let C = f.length + 1, w = fingerprint(e), T = await search(e, [e], /* @__PURE__ */ new Set([w]), 0);
|
|
148
|
+
if (T !== void 0) {
|
|
149
|
+
let e = T[T.length - 1];
|
|
74
150
|
return {
|
|
75
|
-
chain:
|
|
151
|
+
chain: T,
|
|
76
152
|
foundTrustedRoot: !0,
|
|
77
|
-
anchorCertificateInChain: e !== void 0 &&
|
|
153
|
+
anchorCertificateInChain: e !== void 0 && h.has(fingerprint(e))
|
|
78
154
|
};
|
|
79
155
|
}
|
|
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,
|
|
156
|
+
let E = _.current;
|
|
157
|
+
if (x.exhausted) return {
|
|
158
|
+
chain: E.path,
|
|
94
159
|
foundTrustedRoot: !1,
|
|
95
|
-
|
|
160
|
+
failure: l.failure("path_building_limit_exceeded", "path building stopped at its work limit", void 0, l.detail({
|
|
161
|
+
expected: `at most ${d} issuer and trust-anchor checks`,
|
|
162
|
+
actual: "limit reached before a trusted path was found"
|
|
163
|
+
}))
|
|
96
164
|
};
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
165
|
+
switch (E.kind) {
|
|
166
|
+
case "specific-failure": return {
|
|
167
|
+
chain: E.path,
|
|
168
|
+
foundTrustedRoot: !1,
|
|
169
|
+
failure: E.failure
|
|
170
|
+
};
|
|
171
|
+
case "missing-issuer": return {
|
|
172
|
+
chain: E.path,
|
|
173
|
+
foundTrustedRoot: !1,
|
|
174
|
+
missingIssuerAt: E.missingIssuerAt
|
|
175
|
+
};
|
|
176
|
+
case "untrusted-anchor":
|
|
177
|
+
case "none": return {
|
|
178
|
+
chain: E.path,
|
|
179
|
+
foundTrustedRoot: !1
|
|
180
|
+
};
|
|
181
|
+
default: throw Error(`unreachable diagnostic ${String(E)}`);
|
|
182
|
+
}
|
|
183
|
+
async function search(e, t, n, r) {
|
|
184
|
+
if (x.exhausted) return;
|
|
185
|
+
if (h.has(fingerprint(e))) return t;
|
|
186
|
+
let i = await matchTrustAnchor(e, g, l, t.length - 1, verifyAnchorOnce, chargeBudget);
|
|
187
|
+
if (x.exhausted) return;
|
|
188
|
+
if (i.failure !== void 0 && recordFailure(i.failure, t), i.matched) return t;
|
|
189
|
+
if (t.length > C) return;
|
|
190
|
+
let a = `${fingerprint(e)}:${r}`, o = v.get(a);
|
|
191
|
+
if (o !== void 0) {
|
|
192
|
+
consider(rebaseDiagnostic(o.diagnostic, o.nodeIndex, t));
|
|
107
193
|
return;
|
|
108
194
|
}
|
|
109
|
-
let
|
|
110
|
-
|
|
111
|
-
|
|
195
|
+
let s = { best: {
|
|
196
|
+
kind: "none",
|
|
197
|
+
path: t
|
|
198
|
+
} };
|
|
199
|
+
y.push(s);
|
|
200
|
+
try {
|
|
201
|
+
let i = await searchBelow(e, t, n, r);
|
|
202
|
+
if (i !== void 0) return i;
|
|
203
|
+
} finally {
|
|
204
|
+
y.pop();
|
|
205
|
+
}
|
|
206
|
+
v.set(a, {
|
|
207
|
+
diagnostic: s.best,
|
|
208
|
+
nodeIndex: t.length - 1
|
|
209
|
+
});
|
|
112
210
|
}
|
|
113
|
-
function
|
|
114
|
-
|
|
211
|
+
async function searchBelow(e, t, n, r) {
|
|
212
|
+
let i = !1;
|
|
213
|
+
for (let a of issuerCandidates(e)) {
|
|
214
|
+
if (!chargeBudget()) return;
|
|
215
|
+
if (!isIssuerOf(a, e)) continue;
|
|
216
|
+
i = !0;
|
|
217
|
+
let o = fingerprint(a);
|
|
218
|
+
if (n.has(o)) continue;
|
|
219
|
+
let s = await searchIssuerCandidate(e, a, o, t, n, r);
|
|
220
|
+
if (s !== void 0) return s;
|
|
221
|
+
if (x.exhausted) return;
|
|
222
|
+
}
|
|
223
|
+
i ? consider({
|
|
224
|
+
kind: "none",
|
|
225
|
+
path: t
|
|
226
|
+
}) : recordMissingIssuers(e, t);
|
|
115
227
|
}
|
|
116
|
-
/**
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
228
|
+
/** Yields the issuer bucket for `current`: AKI matches first, then roots, then input order. */
|
|
229
|
+
function* issuerCandidates(e) {
|
|
230
|
+
let t = i(e.issuer), n = S.get(t);
|
|
231
|
+
n === void 0 && (n = rankBucket(p.get(t) ?? [], m, h), S.set(t, n));
|
|
232
|
+
let r = e.authorityKeyIdentifier;
|
|
233
|
+
if (r === void 0) yield* n.ordered;
|
|
234
|
+
else {
|
|
235
|
+
yield* n.bySubjectKeyIdentifier.get(r) ?? [];
|
|
236
|
+
for (let e of n.ordered) e.subjectKeyIdentifier !== r && (yield e);
|
|
121
237
|
}
|
|
122
238
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
239
|
+
function recordMissingIssuers(e, t) {
|
|
240
|
+
isSelfIssued(e) ? consider({
|
|
241
|
+
kind: "untrusted-anchor",
|
|
242
|
+
path: t
|
|
243
|
+
}) : t.length > 1 && consider({
|
|
244
|
+
kind: "missing-issuer",
|
|
245
|
+
path: t,
|
|
246
|
+
missingIssuerAt: t.length - 1
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
async function searchIssuerCandidate(e, t, n, r, i, a) {
|
|
250
|
+
let s = await evaluateIssuerCandidate(e, t, r, a, o, l, verifySignatureOnce);
|
|
251
|
+
if (!s.ok) {
|
|
252
|
+
recordFailure(s.failure, r);
|
|
129
253
|
return;
|
|
130
254
|
}
|
|
131
|
-
let
|
|
132
|
-
return
|
|
255
|
+
let c = new Set(i);
|
|
256
|
+
return c.add(n), await search(t, [...r, t], c, s.nextCaBelowCount);
|
|
257
|
+
}
|
|
258
|
+
function chargeBudget() {
|
|
259
|
+
return x.remaining === 0 ? (x.exhausted = !0, !1) : (--x.remaining, !0);
|
|
260
|
+
}
|
|
261
|
+
function verifySignatureOnce(e, t) {
|
|
262
|
+
return verifyOnce(`c:${fingerprint(e)}:${n(t.subjectPublicKeyInfoDer)}`, () => u.certificate(e, t));
|
|
263
|
+
}
|
|
264
|
+
function verifyAnchorOnce(e, t) {
|
|
265
|
+
let r = `${t.publicKeyAlgorithmOid}:${t.publicKeyParametersOid ?? ""}:${n(t.subjectPublicKeyInfoDer)}`;
|
|
266
|
+
return verifyOnce(`a:${fingerprint(e)}:${r}`, () => u.trustAnchor(e, t));
|
|
267
|
+
}
|
|
268
|
+
/** One signature check per distinct certificate-and-key pair for the whole search. */
|
|
269
|
+
function verifyOnce(e, t) {
|
|
270
|
+
let n = b.get(e);
|
|
271
|
+
return n === void 0 && (n = t(), b.set(e, n)), n;
|
|
133
272
|
}
|
|
134
|
-
function
|
|
135
|
-
|
|
273
|
+
function consider(e) {
|
|
274
|
+
isMoreSignificant(e, _.current) && (_.current = e);
|
|
275
|
+
for (let t of y) isMoreSignificant(e, t.best) && (t.best = e);
|
|
136
276
|
}
|
|
137
277
|
function recordFailure(e, t) {
|
|
138
|
-
(
|
|
278
|
+
consider({
|
|
279
|
+
kind: "specific-failure",
|
|
280
|
+
path: t,
|
|
281
|
+
failure: e
|
|
282
|
+
});
|
|
139
283
|
}
|
|
140
284
|
}
|
|
141
285
|
/** 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
|
|
286
|
+
async function evaluateIssuerCandidate(e, t, n, r, i, a, o) {
|
|
287
|
+
let s = evaluateIssuerConstraints(e, t, n, r, i, a);
|
|
288
|
+
if (!s.ok) return s;
|
|
289
|
+
let c = await o(e, t);
|
|
290
|
+
return c.ok ? c.valid ? s : {
|
|
147
291
|
ok: !1,
|
|
148
292
|
failure: a.failure("signature_invalid", "certificate signature does not verify", n.length - 1, a.detail({
|
|
149
293
|
subjectCommonName: e.subject.values.commonName,
|
|
@@ -151,10 +295,10 @@ async function evaluateIssuerCandidate(e, t, n, r, i, a) {
|
|
|
151
295
|
}))
|
|
152
296
|
} : {
|
|
153
297
|
ok: !1,
|
|
154
|
-
failure: a.failure(
|
|
298
|
+
failure: a.failure(c.code, c.reason, n.length - 1, a.detail({
|
|
155
299
|
subjectCommonName: e.subject.values.commonName,
|
|
156
300
|
issuerCommonName: t.subject.values.commonName,
|
|
157
|
-
actual:
|
|
301
|
+
actual: c.reason
|
|
158
302
|
}))
|
|
159
303
|
};
|
|
160
304
|
}
|
|
@@ -203,22 +347,24 @@ function authorityKeyIdentifierMismatch(e, t) {
|
|
|
203
347
|
}
|
|
204
348
|
/** Expands a PEM (possibly multi-block) or DER source into parsed certificates. */
|
|
205
349
|
function expandSource(e) {
|
|
206
|
-
return
|
|
350
|
+
return o(e);
|
|
207
351
|
}
|
|
208
|
-
/**
|
|
209
|
-
function
|
|
210
|
-
let
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
let
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
352
|
+
/** Orders one subject bucket once, roots first and then input order, and indexes it by SKI. */
|
|
353
|
+
function rankBucket(e, t, n) {
|
|
354
|
+
let r = [...e].sort((e, r) => {
|
|
355
|
+
let i = fingerprint(e), a = fingerprint(r), o = compareBooleans(n.has(i), n.has(a));
|
|
356
|
+
return o === 0 ? (t.get(i) ?? 2 ** 53 - 1) - (t.get(a) ?? 2 ** 53 - 1) : o;
|
|
357
|
+
}), i = /* @__PURE__ */ new Map();
|
|
358
|
+
for (let e of r) {
|
|
359
|
+
let t = e.subjectKeyIdentifier;
|
|
360
|
+
if (t === void 0) continue;
|
|
361
|
+
let n = i.get(t);
|
|
362
|
+
n === void 0 ? i.set(t, [e]) : n.push(e);
|
|
363
|
+
}
|
|
364
|
+
return {
|
|
365
|
+
ordered: r,
|
|
366
|
+
bySubjectKeyIdentifier: i
|
|
367
|
+
};
|
|
222
368
|
}
|
|
223
369
|
/** Sort comparator: `true` sorts before `false`. Returns -1, 0, or 1. */
|
|
224
370
|
function compareBooleans(e, t) {
|
|
@@ -226,47 +372,38 @@ function compareBooleans(e, t) {
|
|
|
226
372
|
}
|
|
227
373
|
/** Returns `true` if `issuer`'s subject DN semantically matches `child`'s issuer DN (RFC 5280 §7.1). */
|
|
228
374
|
function isIssuerOf(e, t) {
|
|
229
|
-
return
|
|
375
|
+
return a(t.issuer, e.subject);
|
|
230
376
|
}
|
|
231
377
|
/** 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
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
actual: "certificate signature does not verify"
|
|
250
|
-
})));
|
|
251
|
-
continue;
|
|
252
|
-
}
|
|
253
|
-
return { matched: !0 };
|
|
378
|
+
async function matchTrustAnchor(e, t, n, r, o, s) {
|
|
379
|
+
let c = t.get(i(e.issuer));
|
|
380
|
+
if (c === void 0) return { matched: !1 };
|
|
381
|
+
let l;
|
|
382
|
+
for (let t of c) {
|
|
383
|
+
if (!s()) return { matched: !1 };
|
|
384
|
+
if (trustAnchorAkiMismatch(e, t) || !a(e.issuer, t.subject)) continue;
|
|
385
|
+
let i = await o(e, t);
|
|
386
|
+
if (!i.ok) l === void 0 && (l = n.failure(i.code, i.reason, r, n.detail({
|
|
387
|
+
subjectCommonName: e.subject.values.commonName,
|
|
388
|
+
actual: i.reason
|
|
389
|
+
})));
|
|
390
|
+
else if (!i.valid) l === void 0 && (l = n.failure("signature_invalid", "certificate signature does not verify", r, n.detail({
|
|
391
|
+
subjectCommonName: e.subject.values.commonName,
|
|
392
|
+
actual: "certificate signature does not verify"
|
|
393
|
+
})));
|
|
394
|
+
else return { matched: !0 };
|
|
254
395
|
}
|
|
255
|
-
return
|
|
396
|
+
return l === void 0 ? { matched: !1 } : {
|
|
256
397
|
matched: !1,
|
|
257
|
-
failure:
|
|
398
|
+
failure: l
|
|
258
399
|
};
|
|
259
400
|
}
|
|
260
401
|
function trustAnchorAkiMismatch(e, t) {
|
|
261
402
|
return t.subjectKeyIdentifier !== void 0 && e.authorityKeyIdentifier !== void 0 && t.subjectKeyIdentifier !== e.authorityKeyIdentifier;
|
|
262
403
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
return
|
|
266
|
-
ok: !1,
|
|
267
|
-
code: "signature_invalid",
|
|
268
|
-
reason: n.reason
|
|
269
|
-
} : n;
|
|
404
|
+
/** Verifies that `certificate` was signed by a bare trust anchor's key. */
|
|
405
|
+
function verifyTrustAnchorSignature(e, t) {
|
|
406
|
+
return signatureCheck(() => r(e.signatureAlgorithmOid, e.signatureAlgorithmParametersDer, t.publicKeyAlgorithmOid, t.publicKeyParametersOid, t.subjectPublicKeyInfoDer, e.signatureValue, e.tbsCertificateDer));
|
|
270
407
|
}
|
|
271
408
|
function describeDateTime(e) {
|
|
272
409
|
return Number.isNaN(e.getTime()) ? "<invalid date>" : e.toISOString();
|
|
@@ -275,13 +412,12 @@ function isNonNegativeInteger(e) {
|
|
|
275
412
|
return e !== void 0 && Number.isInteger(e) && e >= 0;
|
|
276
413
|
}
|
|
277
414
|
/** Cache for computed fingerprints to avoid repeated toHex() calls. */
|
|
278
|
-
const
|
|
415
|
+
const u = /* @__PURE__ */ new WeakMap();
|
|
279
416
|
/** Returns a hex fingerprint of the certificate's raw DER, used for cycle detection and dedup. */
|
|
280
|
-
function fingerprint(
|
|
281
|
-
let
|
|
282
|
-
return
|
|
417
|
+
function fingerprint(e) {
|
|
418
|
+
let t = u.get(e);
|
|
419
|
+
return t === void 0 && (t = n(e.der), u.set(e, t)), t;
|
|
283
420
|
}
|
|
284
|
-
|
|
285
|
-
export { authorityKeyIdentifierMismatch, buildChainInternal, countCaCertificatesBelowParsed, isSelfIssued, isWithinValidity, loadCertificates, loadSingleCertificate, verifyCertificateSignature };
|
|
421
|
+
export { s as DEFAULT_MAX_PATH_BUILDING_CHECKS, assertPathBuildingChecks, authorityKeyIdentifierMismatch, buildChainInternal, countCaCertificatesBelowParsed, isSelfIssued, isWithinValidity, loadCertificates, loadSingleCertificate, rebaseDiagnostic, verifyCertificateSignature, verifyTrustAnchorSignature };
|
|
286
422
|
|
|
287
423
|
//# sourceMappingURL=verify-path.js.map
|