micro509 0.18.0 → 0.19.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 +88 -1
- package/dist/crypto/crypto.d.ts +11 -2
- package/dist/crypto/crypto.js +30 -17
- package/dist/crypto/crypto.js.map +1 -1
- package/dist/crypto.d.ts +2 -2
- package/dist/der/der.js.map +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/internal/asn1/asn1.js +10 -2
- package/dist/internal/asn1/asn1.js.map +1 -1
- package/dist/internal/asn1/ber.js.map +1 -1
- package/dist/internal/asn1/decode-refusal.js.map +1 -1
- package/dist/internal/asn1/der.js.map +1 -1
- package/dist/internal/asn1/oids.js.map +1 -1
- package/dist/internal/crypto/algorithm-names.js.map +1 -1
- package/dist/internal/crypto/ecdsa.js.map +1 -1
- package/dist/internal/crypto/hash.js.map +1 -1
- package/dist/internal/crypto/pbes2.js.map +1 -1
- package/dist/internal/crypto/prime-ec.js.map +1 -1
- package/dist/internal/crypto/rsa-pss.js.map +1 -1
- package/dist/internal/crypto/sig-verify.d.ts +40 -0
- package/dist/internal/crypto/sig-verify.js +152 -65
- package/dist/internal/crypto/sig-verify.js.map +1 -1
- package/dist/internal/crypto/signing.js.map +1 -1
- package/dist/internal/jose/base64url.js.map +1 -1
- package/dist/internal/jose/json-data.js.map +1 -1
- package/dist/internal/jose/strict-json.js.map +1 -1
- package/dist/internal/shared/base64.js.map +1 -1
- package/dist/internal/shared/dn.js.map +1 -1
- package/dist/internal/shared/idna.js.map +1 -1
- package/dist/internal/shared/ip.js.map +1 -1
- package/dist/internal/shared/mailbox.js.map +1 -1
- package/dist/internal/shared/punycode.js.map +1 -1
- package/dist/internal/shared/uri-host.js.map +1 -1
- package/dist/internal/verify/name-constraints-engine.js.map +1 -1
- package/dist/internal/verify/policy-engine.js.map +1 -1
- package/dist/internal/verify/spki-distrust.js.map +1 -1
- package/dist/internal/verify/verify-path.js +222 -116
- package/dist/internal/verify/verify-path.js.map +1 -1
- package/dist/internal/x509/directory-name.js.map +1 -1
- package/dist/internal/x509/extension-bits.js.map +1 -1
- package/dist/internal/x509/extension-errors.js.map +1 -1
- package/dist/internal/x509/extension-registry.js.map +1 -1
- package/dist/internal/x509/general-name-profile.js.map +1 -1
- package/dist/internal/x509/general-name.js.map +1 -1
- package/dist/internal/x509/name-fields.js.map +1 -1
- package/dist/internal/x509/or-address.js.map +1 -1
- package/dist/jose/base64url.js.map +1 -1
- package/dist/jose/errors.js.map +1 -1
- package/dist/jose/jwe.js.map +1 -1
- package/dist/jose/jwks.js.map +1 -1
- package/dist/jose/jws.js.map +1 -1
- package/dist/jose/jwt.js.map +1 -1
- package/dist/jose/remote-jwks.js.map +1 -1
- package/dist/kdf/argon2-arithmetic.js.map +1 -1
- package/dist/kdf/argon2-core.js.map +1 -1
- package/dist/kdf/argon2-memory.js.map +1 -1
- package/dist/kdf/argon2-portable.js.map +1 -1
- package/dist/kdf/argon2.js.map +1 -1
- package/dist/keys/keys.js.map +1 -1
- package/dist/pem/pem.js.map +1 -1
- package/dist/pkcs/pfx.js.map +1 -1
- package/dist/pkcs/pkcs12-mac.js +1 -1
- package/dist/pkcs/pkcs12-mac.js.map +1 -1
- package/dist/pkcs/pkcs7.d.ts +10 -0
- package/dist/pkcs/pkcs7.js +106 -88
- package/dist/pkcs/pkcs7.js.map +1 -1
- package/dist/result/result.js.map +1 -1
- package/dist/revocation/chain.d.ts +67 -13
- package/dist/revocation/chain.js +429 -301
- package/dist/revocation/chain.js.map +1 -1
- package/dist/revocation/crl.d.ts +65 -11
- package/dist/revocation/crl.js +492 -202
- package/dist/revocation/crl.js.map +1 -1
- package/dist/revocation/ocsp.d.ts +79 -24
- package/dist/revocation/ocsp.js +417 -231
- package/dist/revocation/ocsp.js.map +1 -1
- package/dist/revocation/revocation.d.ts +68 -13
- package/dist/revocation/revocation.js +194 -73
- package/dist/revocation/revocation.js.map +1 -1
- package/dist/revocation.d.ts +4 -4
- package/dist/ssh/ssh.js.map +1 -1
- package/dist/ssh/wire.js.map +1 -1
- package/dist/verify/identity.d.ts +2 -2
- package/dist/verify/identity.js +2 -2
- package/dist/verify/identity.js.map +1 -1
- package/dist/verify/verify.d.ts +84 -32
- package/dist/verify/verify.js +221 -171
- package/dist/verify/verify.js.map +1 -1
- package/dist/verify.d.ts +3 -2
- package/dist/x509/certificate.js.map +1 -1
- package/dist/x509/csr.js.map +1 -1
- package/dist/x509/extensions.js.map +1 -1
- package/dist/x509/fingerprint.js.map +1 -1
- package/dist/x509/name-text.js.map +1 -1
- package/dist/x509/name.js.map +1 -1
- package/dist/x509/parse.d.ts +6 -2
- package/dist/x509/parse.js +121 -121
- package/dist/x509/parse.js.map +1 -1
- package/package.json +11 -11
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { toHex as e } from "../asn1/asn1.js";
|
|
2
2
|
import { DECODE_LIMIT_CODES as t, decodeRefusalOf as n } from "../asn1/decode-refusal.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { readSequenceChildren as r, sequence as i } from "../asn1/der.js";
|
|
4
|
+
import { NO_CALLER_VERIFICATION as a, explicitParameters as o, spkiAlgorithmParametersDer as s, verifySignedDataDetailed as c } from "../crypto/sig-verify.js";
|
|
5
|
+
import { canonicalDnKey as l, compareDistinguishedNames as u } from "../shared/dn.js";
|
|
6
|
+
import { parseCertificatesFromSource as d } from "../../x509/parse.js";
|
|
6
7
|
// src/internal/verify/verify-path.ts
|
|
7
8
|
/**
|
|
8
9
|
* Internal certificate path-building and signature-check helpers.
|
|
@@ -14,7 +15,7 @@ import { parseCertificatesFromSource as o } from "../../x509/parse.js";
|
|
|
14
15
|
* @module
|
|
15
16
|
*/
|
|
16
17
|
/** Default upper bound on issuer candidates and trust anchors one path search may try. */
|
|
17
|
-
const
|
|
18
|
+
const f = 1e5;
|
|
18
19
|
/** Throws when a caller-supplied path-building limit is not a positive safe integer. */
|
|
19
20
|
function assertPathBuildingChecks(e) {
|
|
20
21
|
if (e !== void 0 && (!Number.isSafeInteger(e) || e < 1)) throw RangeError(`Invalid maxPathBuildingChecks: must be an integer >= 1, got ${e}`);
|
|
@@ -25,7 +26,7 @@ function isWithinValidity(e, t) {
|
|
|
25
26
|
}
|
|
26
27
|
/** Returns `true` if the certificate's subject and issuer DNs are semantically equal (RFC 5280 §7.1). */
|
|
27
28
|
function isSelfIssued(e) {
|
|
28
|
-
return
|
|
29
|
+
return u(e.subject, e.issuer);
|
|
29
30
|
}
|
|
30
31
|
/** Counts non-self-issued CA certificates in positions 0..(index-1) for pathLength checking. */
|
|
31
32
|
function countCaCertificatesBelowParsed(e, t) {
|
|
@@ -50,8 +51,8 @@ function loadSingleCertificate(e) {
|
|
|
50
51
|
return n;
|
|
51
52
|
}
|
|
52
53
|
/** Verifies that `certificate` was signed by `issuer`'s public key. */
|
|
53
|
-
function verifyCertificateSignature(e, t) {
|
|
54
|
-
return signatureCheck(() =>
|
|
54
|
+
function verifyCertificateSignature(e, t, n = a) {
|
|
55
|
+
return signatureCheck(() => c(e.signatureAlgorithmOid, e.signatureAlgorithmParametersDer, t.publicKeyAlgorithmOid, t.publicKeyParametersOid, t.subjectPublicKeyInfoDer, e.signatureValue, e.signatureValueUnusedBits, e.tbsCertificateDer, n));
|
|
55
56
|
}
|
|
56
57
|
/** Runs `verify` as a path check, reporting a runtime failure as `signature_invalid` and a decoding limit as `limit_exceeded`. */
|
|
57
58
|
async function signatureCheck(e) {
|
|
@@ -74,17 +75,88 @@ async function signatureCheck(e) {
|
|
|
74
75
|
} : r;
|
|
75
76
|
}
|
|
76
77
|
/** The real signature checks, used unless a caller injects its own. */
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
const p = signatureChecksWith(/* @__PURE__ */ new Map());
|
|
79
|
+
/** The real signature checks, falling back to caller verifiers for algorithms WebCrypto cannot run. */
|
|
80
|
+
function signatureChecksWith(e) {
|
|
81
|
+
return {
|
|
82
|
+
certificate: (t, n, r) => verifyCertificateSignature(t, n, {
|
|
83
|
+
verifiers: e,
|
|
84
|
+
...r !== void 0 && { workingParameters: r }
|
|
85
|
+
}),
|
|
86
|
+
trustAnchor: (t, n) => verifyTrustAnchorSignature(t, n, { verifiers: e }),
|
|
87
|
+
inheritsParameters: (t, n) => e.has(t.signatureAlgorithmOid) && o(n.publicKeyAlgorithmParametersDer) === void 0
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/** The working key a trust anchor initializes (RFC 5280 §6.1.2 (g)-(i)). */
|
|
91
|
+
function anchorWorkingKey(e) {
|
|
92
|
+
return {
|
|
93
|
+
algorithmOid: e.publicKeyAlgorithmOid,
|
|
94
|
+
parametersDer: o(s(e.subjectPublicKeyInfoDer))
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/** Whether `certificate` carries `anchor`'s name and public key: the anchor's own certificate. */
|
|
98
|
+
function carriesTrustAnchorKey(e, t) {
|
|
99
|
+
let n = t.subjectPublicKeyInfoDer;
|
|
100
|
+
return u(e.subject, t.subject) && e.subjectPublicKeyInfoDer.length === n.length && e.subjectPublicKeyInfoDer.every((e, t) => e === n[t]);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* `anchor` with `parametersDer` in its SubjectPublicKeyInfo: the trust anchor
|
|
104
|
+
* information of RFC 5280 §6.1.1 (d) for a key whose path supplies its
|
|
105
|
+
* parameters (§6.1.4 (e)).
|
|
106
|
+
*/
|
|
107
|
+
function withWorkingParameters(e, t) {
|
|
108
|
+
let n = e.subjectPublicKeyInfoDer, [a, o] = r(n);
|
|
109
|
+
if (a === void 0 || o === void 0) throw Error("SubjectPublicKeyInfo lacks its algorithm or key");
|
|
110
|
+
let s = n.subarray(a.start - a.headerLength, a.end), [c] = r(s);
|
|
111
|
+
if (c === void 0) throw Error("AlgorithmIdentifier lacks its OID");
|
|
112
|
+
return {
|
|
113
|
+
...e,
|
|
114
|
+
subjectPublicKeyInfoDer: i([i([s.subarray(c.start - c.headerLength, c.end), t]), n.subarray(o.start - o.headerLength, o.end)])
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* The working key of `path.chain[index]` along a validated path: its own key
|
|
119
|
+
* parameters, or those it inherits from the root or bare anchor above it.
|
|
120
|
+
*/
|
|
121
|
+
function pathWorkingKey(e, t) {
|
|
122
|
+
let n = e.chain[t], r = e.chain[e.chain.length - 1];
|
|
123
|
+
if (n === void 0 || r === void 0) throw Error(`no certificate at path index ${t}`);
|
|
124
|
+
return {
|
|
125
|
+
algorithmOid: n.publicKeyAlgorithmOid,
|
|
126
|
+
parametersDer: e.anchorCertificateInChain ? workingParametersAt(e.chain, t, e.chain.length - 2, certificateWorkingKey(r)) : workingParametersAt(e.chain, t, e.chain.length - 1, anchorWorkingKey(e.trustAnchor))
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/** The working key a certificate used as trust anchor initializes. */
|
|
130
|
+
function certificateWorkingKey(e) {
|
|
131
|
+
return {
|
|
132
|
+
algorithmOid: e.publicKeyAlgorithmOid,
|
|
133
|
+
parametersDer: o(e.publicKeyAlgorithmParametersDer)
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* RFC 5280 §6.1.4 (e)-(f): the working parameters after processing `path` from
|
|
138
|
+
* index `firstProcessed` down to `issuerIndex`, starting from `start`. A
|
|
139
|
+
* certificate with its own parameters sets them. One without keeps the working
|
|
140
|
+
* parameters when its algorithm matches and clears them when it differs.
|
|
141
|
+
*/
|
|
142
|
+
function workingParametersAt(e, t, n, r) {
|
|
143
|
+
let { algorithmOid: i, parametersDer: a } = r;
|
|
144
|
+
for (let r = n; r >= t; --r) {
|
|
145
|
+
let t = e[r];
|
|
146
|
+
if (t === void 0) return;
|
|
147
|
+
let n = o(t.publicKeyAlgorithmParametersDer);
|
|
148
|
+
n === void 0 ? t.publicKeyAlgorithmOid !== i && (a = void 0) : a = n, i = t.publicKeyAlgorithmOid;
|
|
149
|
+
}
|
|
150
|
+
return a;
|
|
151
|
+
}
|
|
152
|
+
const m = {
|
|
81
153
|
"specific-failure": 3,
|
|
82
154
|
"untrusted-anchor": 2,
|
|
83
155
|
"missing-issuer": 1,
|
|
84
156
|
none: 0
|
|
85
157
|
};
|
|
86
158
|
function isMoreSignificant(e, t) {
|
|
87
|
-
let n =
|
|
159
|
+
let n = m[e.kind], r = m[t.kind];
|
|
88
160
|
return n === r ? e.path.length > t.path.length : n > r;
|
|
89
161
|
}
|
|
90
162
|
/**
|
|
@@ -127,116 +199,143 @@ function rebaseDiagnostic(e, t, n) {
|
|
|
127
199
|
* step. Returns the first fully anchored path or the deepest partial path
|
|
128
200
|
* with the best failure encountered.
|
|
129
201
|
*/
|
|
130
|
-
async function buildChainInternal(t, n, r, a, o,
|
|
131
|
-
let
|
|
132
|
-
for (let e of
|
|
133
|
-
let t =
|
|
202
|
+
async function buildChainInternal(t, n, r, i, a, o, s = p, c = f, u = () => Promise.resolve(void 0)) {
|
|
203
|
+
let d, m = [...n, ...r], h = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Map(), _ = new Set(r.map((e) => fingerprint(e))), v = /* @__PURE__ */ new Map();
|
|
204
|
+
for (let e of i) {
|
|
205
|
+
let t = l(e.subject), n = v.get(t);
|
|
134
206
|
n === void 0 ? v.set(t, [e]) : n.push(e);
|
|
135
207
|
}
|
|
136
208
|
let y = { current: {
|
|
137
209
|
kind: "none",
|
|
138
210
|
path: [t]
|
|
139
211
|
} }, b = /* @__PURE__ */ new Map(), x = [], S = /* @__PURE__ */ new Map(), C = {
|
|
140
|
-
remaining:
|
|
212
|
+
remaining: c,
|
|
141
213
|
exhausted: !1
|
|
142
214
|
}, w = /* @__PURE__ */ new Map();
|
|
143
215
|
m.forEach((e, t) => {
|
|
144
|
-
let n =
|
|
216
|
+
let n = l(e.subject), r = h.get(n);
|
|
145
217
|
r === void 0 ? h.set(n, [e]) : r.push(e), g.set(fingerprint(e), t);
|
|
146
218
|
});
|
|
147
|
-
let T =
|
|
148
|
-
if (
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
let O = y.current;
|
|
219
|
+
let T = fingerprint(t), E = await search(t, [t], /* @__PURE__ */ new Set([T]), 0, []);
|
|
220
|
+
if (E !== void 0) return {
|
|
221
|
+
chain: E,
|
|
222
|
+
foundTrustedRoot: !0,
|
|
223
|
+
...d === void 0 ? { anchorCertificateInChain: !0 } : {
|
|
224
|
+
anchorCertificateInChain: !1,
|
|
225
|
+
trustAnchor: d
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
let D = y.current;
|
|
158
229
|
if (C.exhausted) return {
|
|
159
|
-
chain:
|
|
230
|
+
chain: D.path,
|
|
160
231
|
foundTrustedRoot: !1,
|
|
161
|
-
failure:
|
|
162
|
-
expected: `at most ${
|
|
232
|
+
failure: o.failure("path_building_limit_exceeded", "path building stopped at its work limit", void 0, o.detail({
|
|
233
|
+
expected: `at most ${c} issuer and trust-anchor checks`,
|
|
163
234
|
actual: "limit reached before a trusted path was found"
|
|
164
235
|
}))
|
|
165
236
|
};
|
|
166
|
-
switch (
|
|
237
|
+
switch (D.kind) {
|
|
167
238
|
case "specific-failure": return {
|
|
168
|
-
chain:
|
|
239
|
+
chain: D.path,
|
|
169
240
|
foundTrustedRoot: !1,
|
|
170
|
-
failure:
|
|
241
|
+
failure: D.failure
|
|
171
242
|
};
|
|
172
243
|
case "missing-issuer": return {
|
|
173
|
-
chain:
|
|
244
|
+
chain: D.path,
|
|
174
245
|
foundTrustedRoot: !1,
|
|
175
|
-
missingIssuerAt:
|
|
246
|
+
missingIssuerAt: D.missingIssuerAt
|
|
176
247
|
};
|
|
177
248
|
case "untrusted-anchor":
|
|
178
249
|
case "none": return {
|
|
179
|
-
chain:
|
|
250
|
+
chain: D.path,
|
|
180
251
|
foundTrustedRoot: !1
|
|
181
252
|
};
|
|
182
|
-
default: throw Error(`unreachable diagnostic ${String(
|
|
253
|
+
default: throw Error(`unreachable diagnostic ${String(D)}`);
|
|
183
254
|
}
|
|
184
|
-
async function search(e, t, n, r) {
|
|
255
|
+
async function search(e, t, n, r, i) {
|
|
185
256
|
if (C.exhausted) return;
|
|
186
|
-
let
|
|
187
|
-
if (
|
|
188
|
-
recordFailure(
|
|
257
|
+
let a = await u(e.subjectPublicKeyInfoDer);
|
|
258
|
+
if (a !== void 0) {
|
|
259
|
+
recordFailure(o.failure("public_key_distrusted", "certificate public key is explicitly distrusted", t.length - 1, o.detail({
|
|
189
260
|
subjectCommonName: e.subject.values.commonName,
|
|
190
|
-
actual:
|
|
261
|
+
actual: a
|
|
191
262
|
})), t);
|
|
192
263
|
return;
|
|
193
264
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
265
|
+
let s = await terminateAtAnchor(e, t, i);
|
|
266
|
+
return s === "open" ? await searchIssuers(e, t, n, r, i) : s;
|
|
267
|
+
}
|
|
268
|
+
/** Ends the path at a root or a bare trust anchor, or reports `'open'` to keep searching. */
|
|
269
|
+
async function terminateAtAnchor(e, t, n) {
|
|
270
|
+
if (_.has(fingerprint(e)) && await verifyInheritedLinks(t, n, certificateWorkingKey(e), t.length - 2)) return t;
|
|
271
|
+
let r = await matchTrustAnchor(e, v, o, t.length - 1, {
|
|
272
|
+
verifyAnchor: verifyAnchorOnce,
|
|
273
|
+
charge: chargeBudget,
|
|
274
|
+
distrust: u,
|
|
275
|
+
completesPath: (e) => verifyInheritedLinks(t, n, anchorWorkingKey(e), t.length - 1)
|
|
276
|
+
});
|
|
277
|
+
if (!C.exhausted) return r.matched ? (d = r.anchor, t) : (r.failure !== void 0 && recordFailure(r.failure, t), "open");
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Searches the issuers of `current`. A subtree that carries deferred links
|
|
281
|
+
* depends on the path below it, so it skips the dead-end memo.
|
|
282
|
+
*/
|
|
283
|
+
async function searchIssuers(e, t, n, r, i) {
|
|
284
|
+
let a = i.length === 0 ? `${fingerprint(e)}:${r}` : void 0, o = a === void 0 ? void 0 : b.get(a);
|
|
285
|
+
if (o !== void 0) {
|
|
286
|
+
consider(rebaseDiagnostic(o.diagnostic, o.nodeIndex, t));
|
|
202
287
|
return;
|
|
203
288
|
}
|
|
204
|
-
let
|
|
289
|
+
let s = { best: {
|
|
205
290
|
kind: "none",
|
|
206
291
|
path: t
|
|
207
292
|
} };
|
|
208
|
-
x.push(
|
|
293
|
+
x.push(s);
|
|
209
294
|
try {
|
|
210
|
-
let
|
|
211
|
-
if (
|
|
295
|
+
let a = await searchBelow(e, t, n, r, i);
|
|
296
|
+
if (a !== void 0) return a;
|
|
212
297
|
} finally {
|
|
213
298
|
x.pop();
|
|
214
299
|
}
|
|
215
|
-
b.set(
|
|
216
|
-
diagnostic:
|
|
300
|
+
a !== void 0 && b.set(a, {
|
|
301
|
+
diagnostic: s.best,
|
|
217
302
|
nodeIndex: t.length - 1
|
|
218
303
|
});
|
|
219
304
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
305
|
+
/**
|
|
306
|
+
* Verifies the deferred links of a completed path once its trust anchor fixes
|
|
307
|
+
* the working key. `pending` holds the index of each certificate whose issuer
|
|
308
|
+
* key inherits its parameters.
|
|
309
|
+
*/
|
|
310
|
+
async function verifyInheritedLinks(t, n, r, i) {
|
|
311
|
+
for (let a of n) {
|
|
312
|
+
let n = t[a], c = t[a + 1];
|
|
313
|
+
if (n === void 0 || c === void 0) return !1;
|
|
314
|
+
let l = workingParametersAt(t, a + 1, i, r), u = signatureResultFailure(await verifyOnce(`c:${fingerprint(n)}:${e(c.subjectPublicKeyInfoDer)}:${l === void 0 ? "-" : e(l)}`, () => s.certificate(n, c, { parametersDer: l })), n, c, a, o);
|
|
315
|
+
if (u !== void 0) return recordFailure(u, t), !1;
|
|
316
|
+
}
|
|
317
|
+
return !0;
|
|
318
|
+
}
|
|
319
|
+
async function searchBelow(e, t, n, r, i) {
|
|
320
|
+
let a = !1;
|
|
321
|
+
for (let o of issuerCandidates(e)) {
|
|
223
322
|
if (!chargeBudget()) return;
|
|
224
|
-
if (!isIssuerOf(
|
|
225
|
-
|
|
226
|
-
let
|
|
227
|
-
if (n.has(
|
|
228
|
-
let
|
|
229
|
-
if (
|
|
323
|
+
if (!isIssuerOf(o, e)) continue;
|
|
324
|
+
a = !0;
|
|
325
|
+
let s = fingerprint(o);
|
|
326
|
+
if (n.has(s)) continue;
|
|
327
|
+
let c = await searchIssuerCandidate(e, o, s, t, n, r, i);
|
|
328
|
+
if (c !== void 0) return c;
|
|
230
329
|
if (C.exhausted) return;
|
|
231
330
|
}
|
|
232
|
-
|
|
331
|
+
a ? consider({
|
|
233
332
|
kind: "none",
|
|
234
333
|
path: t
|
|
235
334
|
}) : recordMissingIssuers(e, t);
|
|
236
335
|
}
|
|
237
336
|
/** Yields the issuer bucket for `current`: AKI matches first, then roots, then input order. */
|
|
238
337
|
function* issuerCandidates(e) {
|
|
239
|
-
let t =
|
|
338
|
+
let t = l(e.issuer), n = w.get(t);
|
|
240
339
|
n === void 0 && (n = rankBucket(h.get(t) ?? [], g, _), w.set(t, n));
|
|
241
340
|
let r = e.authorityKeyIdentifier;
|
|
242
341
|
if (r === void 0) yield* n.ordered;
|
|
@@ -255,24 +354,30 @@ async function buildChainInternal(t, n, r, a, o, l, u = c, d = s, f = () => Prom
|
|
|
255
354
|
missingIssuerAt: t.length - 1
|
|
256
355
|
});
|
|
257
356
|
}
|
|
258
|
-
async function searchIssuerCandidate(e, t, n, r, i,
|
|
259
|
-
let s = await evaluateIssuerCandidate(e, t, r, a, o,
|
|
260
|
-
if (!
|
|
261
|
-
recordFailure(
|
|
357
|
+
async function searchIssuerCandidate(e, t, n, r, i, c, l) {
|
|
358
|
+
let u = s.inheritsParameters(e, t), d = await evaluateIssuerCandidate(e, t, r, c, a, o, u ? deferSignature : verifySignatureOnce);
|
|
359
|
+
if (!d.ok) {
|
|
360
|
+
recordFailure(d.failure, r);
|
|
262
361
|
return;
|
|
263
362
|
}
|
|
264
|
-
let
|
|
265
|
-
return
|
|
363
|
+
let f = new Set(i);
|
|
364
|
+
return f.add(n), await search(t, [...r, t], f, d.nextCaBelowCount, u ? [...l, r.length - 1] : l);
|
|
365
|
+
}
|
|
366
|
+
function deferSignature() {
|
|
367
|
+
return Promise.resolve({
|
|
368
|
+
ok: !0,
|
|
369
|
+
valid: !0
|
|
370
|
+
});
|
|
266
371
|
}
|
|
267
372
|
function chargeBudget() {
|
|
268
373
|
return C.remaining === 0 ? (C.exhausted = !0, !1) : (--C.remaining, !0);
|
|
269
374
|
}
|
|
270
375
|
function verifySignatureOnce(t, n) {
|
|
271
|
-
return verifyOnce(`c:${fingerprint(t)}:${e(n.subjectPublicKeyInfoDer)}`, () =>
|
|
376
|
+
return verifyOnce(`c:${fingerprint(t)}:${e(n.subjectPublicKeyInfoDer)}`, () => s.certificate(t, n));
|
|
272
377
|
}
|
|
273
378
|
function verifyAnchorOnce(t, n) {
|
|
274
379
|
let r = `${n.publicKeyAlgorithmOid}:${n.publicKeyParametersOid ?? ""}:${e(n.subjectPublicKeyInfoDer)}`;
|
|
275
|
-
return verifyOnce(`a:${fingerprint(t)}:${r}`, () =>
|
|
380
|
+
return verifyOnce(`a:${fingerprint(t)}:${r}`, () => s.trustAnchor(t, n));
|
|
276
381
|
}
|
|
277
382
|
/** One signature check per distinct certificate-and-key pair for the whole search. */
|
|
278
383
|
function verifyOnce(e, t) {
|
|
@@ -295,22 +400,24 @@ async function buildChainInternal(t, n, r, a, o, l, u = c, d = s, f = () => Prom
|
|
|
295
400
|
async function evaluateIssuerCandidate(e, t, n, r, i, a, o) {
|
|
296
401
|
let s = evaluateIssuerConstraints(e, t, n, r, i, a);
|
|
297
402
|
if (!s.ok) return s;
|
|
298
|
-
let c = await o(e, t);
|
|
299
|
-
return c
|
|
300
|
-
ok: !1,
|
|
301
|
-
failure: a.failure("signature_invalid", "certificate signature does not verify", n.length - 1, a.detail({
|
|
302
|
-
subjectCommonName: e.subject.values.commonName,
|
|
303
|
-
issuerCommonName: t.subject.values.commonName
|
|
304
|
-
}))
|
|
305
|
-
} : {
|
|
403
|
+
let c = signatureResultFailure(await o(e, t), e, t, n.length - 1, a);
|
|
404
|
+
return c === void 0 ? s : {
|
|
306
405
|
ok: !1,
|
|
307
|
-
failure:
|
|
308
|
-
subjectCommonName: e.subject.values.commonName,
|
|
309
|
-
issuerCommonName: t.subject.values.commonName,
|
|
310
|
-
actual: c.reason
|
|
311
|
-
}))
|
|
406
|
+
failure: c
|
|
312
407
|
};
|
|
313
408
|
}
|
|
409
|
+
/** The path failure for a signature check of `current` under `issuer`, if it did not pass. */
|
|
410
|
+
function signatureResultFailure(e, t, n, r, i) {
|
|
411
|
+
if (!e.ok) return i.failure(e.code, e.reason, r, i.detail({
|
|
412
|
+
subjectCommonName: t.subject.values.commonName,
|
|
413
|
+
issuerCommonName: n.subject.values.commonName,
|
|
414
|
+
actual: e.reason
|
|
415
|
+
}));
|
|
416
|
+
if (!e.valid) return i.failure("signature_invalid", "certificate signature does not verify", r, i.detail({
|
|
417
|
+
subjectCommonName: t.subject.values.commonName,
|
|
418
|
+
issuerCommonName: n.subject.values.commonName
|
|
419
|
+
}));
|
|
420
|
+
}
|
|
314
421
|
function evaluateIssuerConstraints(e, t, n, r, i, a) {
|
|
315
422
|
return isWithinValidity(t, i) ? t.basicConstraints?.ca === !0 ? evaluateIssuerKeyConstraints(e, t, n, r, a) : {
|
|
316
423
|
ok: !1,
|
|
@@ -356,7 +463,7 @@ function authorityKeyIdentifierMismatch(e, t) {
|
|
|
356
463
|
}
|
|
357
464
|
/** Expands a PEM (possibly multi-block) or DER source into parsed certificates. */
|
|
358
465
|
function expandSource(e) {
|
|
359
|
-
return
|
|
466
|
+
return d(e);
|
|
360
467
|
}
|
|
361
468
|
/** Orders one subject bucket once, roots first and then input order, and indexes it by SKI. */
|
|
362
469
|
function rankBucket(e, t, n) {
|
|
@@ -381,46 +488,45 @@ function compareBooleans(e, t) {
|
|
|
381
488
|
}
|
|
382
489
|
/** Returns `true` if `issuer`'s subject DN semantically matches `child`'s issuer DN (RFC 5280 §7.1). */
|
|
383
490
|
function isIssuerOf(e, t) {
|
|
384
|
-
return
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
let
|
|
391
|
-
|
|
392
|
-
if (
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
u = n.failure("public_key_distrusted", "bare trust anchor public key is explicitly distrusted", void 0, n.detail({ actual: i }));
|
|
491
|
+
return u(t.issuer, e.subject);
|
|
492
|
+
}
|
|
493
|
+
async function matchTrustAnchor(e, t, n, r, { verifyAnchor: i, charge: a, distrust: o, completesPath: s }) {
|
|
494
|
+
let c = t.get(l(e.issuer));
|
|
495
|
+
if (c === void 0) return { matched: !1 };
|
|
496
|
+
let d;
|
|
497
|
+
for (let t of c) {
|
|
498
|
+
if (!a()) return { matched: !1 };
|
|
499
|
+
if (trustAnchorAkiMismatch(e, t) || !u(e.issuer, t.subject)) continue;
|
|
500
|
+
let c = await o(t.subjectPublicKeyInfoDer);
|
|
501
|
+
if (c !== void 0) {
|
|
502
|
+
d = n.failure("public_key_distrusted", "bare trust anchor public key is explicitly distrusted", void 0, n.detail({ actual: c }));
|
|
397
503
|
continue;
|
|
398
504
|
}
|
|
399
|
-
let l = await
|
|
400
|
-
if (!l.ok)
|
|
505
|
+
let l = await i(e, t);
|
|
506
|
+
if (!l.ok) d ??= n.failure(l.code, l.reason, r, n.detail({
|
|
401
507
|
subjectCommonName: e.subject.values.commonName,
|
|
402
508
|
actual: l.reason
|
|
403
509
|
}));
|
|
404
|
-
else if (!l.valid)
|
|
510
|
+
else if (!l.valid) d === void 0 && (d = n.failure("signature_invalid", "certificate signature does not verify", r, n.detail({
|
|
405
511
|
subjectCommonName: e.subject.values.commonName,
|
|
406
512
|
actual: "certificate signature does not verify"
|
|
407
513
|
})));
|
|
408
|
-
else return {
|
|
514
|
+
else if (await s(t)) return {
|
|
409
515
|
matched: !0,
|
|
410
516
|
anchor: t
|
|
411
517
|
};
|
|
412
518
|
}
|
|
413
|
-
return
|
|
519
|
+
return d === void 0 ? { matched: !1 } : {
|
|
414
520
|
matched: !1,
|
|
415
|
-
failure:
|
|
521
|
+
failure: d
|
|
416
522
|
};
|
|
417
523
|
}
|
|
418
524
|
function trustAnchorAkiMismatch(e, t) {
|
|
419
525
|
return t.subjectKeyIdentifier !== void 0 && e.authorityKeyIdentifier !== void 0 && t.subjectKeyIdentifier !== e.authorityKeyIdentifier;
|
|
420
526
|
}
|
|
421
527
|
/** Verifies that `certificate` was signed by a bare trust anchor's key. */
|
|
422
|
-
function verifyTrustAnchorSignature(e, t) {
|
|
423
|
-
return signatureCheck(() =>
|
|
528
|
+
function verifyTrustAnchorSignature(e, t, n = a) {
|
|
529
|
+
return signatureCheck(() => c(e.signatureAlgorithmOid, e.signatureAlgorithmParametersDer, t.publicKeyAlgorithmOid, t.publicKeyParametersOid, t.subjectPublicKeyInfoDer, e.signatureValue, e.signatureValueUnusedBits, e.tbsCertificateDer, n));
|
|
424
530
|
}
|
|
425
531
|
function describeDateTime(e) {
|
|
426
532
|
return Number.isNaN(e.getTime()) ? "<invalid date>" : e.toISOString();
|
|
@@ -429,12 +535,12 @@ function isNonNegativeInteger(e) {
|
|
|
429
535
|
return e !== void 0 && Number.isInteger(e) && e >= 0;
|
|
430
536
|
}
|
|
431
537
|
/** Cache for computed fingerprints to avoid repeated toHex() calls. */
|
|
432
|
-
const
|
|
538
|
+
const h = /* @__PURE__ */ new WeakMap();
|
|
433
539
|
/** Returns a hex fingerprint of the certificate's raw DER, used for cycle detection and dedup. */
|
|
434
540
|
function fingerprint(t) {
|
|
435
|
-
let n =
|
|
436
|
-
return n === void 0 && (n = e(t.der),
|
|
541
|
+
let n = h.get(t);
|
|
542
|
+
return n === void 0 && (n = e(t.der), h.set(t, n)), n;
|
|
437
543
|
}
|
|
438
|
-
export {
|
|
544
|
+
export { f as DEFAULT_MAX_PATH_BUILDING_CHECKS, anchorWorkingKey, assertPathBuildingChecks, authorityKeyIdentifierMismatch, buildChainInternal, carriesTrustAnchorKey, certificateWorkingKey, countCaCertificatesBelowParsed, isSelfIssued, isWithinValidity, loadCertificates, loadSingleCertificate, pathWorkingKey, rebaseDiagnostic, signatureChecksWith, verifyCertificateSignature, verifyTrustAnchorSignature, withWorkingParameters, workingParametersAt };
|
|
439
545
|
|
|
440
546
|
//# sourceMappingURL=verify-path.js.map
|