micro509 0.18.0 → 0.19.1
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 +109 -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 +7 -6
- 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 +64 -64
- package/dist/internal/crypto/hash.js.map +1 -1
- package/dist/internal/crypto/pbes2.js +3 -3
- 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 +1 -1
- package/dist/internal/shared/dn.js.map +1 -1
- package/dist/internal/shared/idna-tables.js +3 -3
- 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 +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 +1 -1
- package/dist/kdf/argon2-portable.js.map +1 -1
- package/dist/kdf/argon2.js +2 -2
- package/dist/kdf/argon2.js.map +1 -1
- package/dist/keys/keys.d.ts +7 -2
- package/dist/keys/keys.js +10 -6
- package/dist/keys/keys.js.map +1 -1
- package/dist/pem/pem.d.ts +20 -7
- package/dist/pem/pem.js +24 -20
- package/dist/pem/pem.js.map +1 -1
- package/dist/pem.d.ts +2 -2
- package/dist/pkcs/pfx.js.map +1 -1
- package/dist/pkcs/pkcs12-mac.js +3 -3
- 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 +472 -182
- 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 -175
- 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 +1 -1
- package/dist/x509/extensions.js.map +1 -1
- package/dist/x509/fingerprint.js.map +1 -1
- package/dist/x509/name-text.js +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 +16 -16
package/dist/revocation/chain.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { DECODE_REFUSAL_CODES as e } from "../result/result.js";
|
|
2
2
|
import { toHex as t } from "../internal/asn1/asn1.js";
|
|
3
3
|
import { decodeRefusalOf as n } from "../internal/asn1/decode-refusal.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
4
|
+
import { resolveSignatureVerifiers as r } from "../internal/crypto/sig-verify.js";
|
|
5
|
+
import { compareDistinguishedNames as i } from "../internal/shared/dn.js";
|
|
6
|
+
import { createSpkiDistrustCheck as a } from "../internal/verify/spki-distrust.js";
|
|
7
|
+
import { anchorWorkingKey as o, carriesTrustAnchorKey as s, certificateWorkingKey as c, pathWorkingKey as l, workingParametersAt as u } from "../internal/verify/verify-path.js";
|
|
8
|
+
import { assertClockSkew as d, assertCrlMaxAge as f, authenticateCrl as p, checkCertificateRevocationAgainstCrlsBy as m, coversAllDistributionPointReasons as h, distinctSignedCrls as g, isCrlApplicableTo as _, normalizeCrl as v, revocationReasonFromCode as y } from "./crl.js";
|
|
9
|
+
import { parseOcspResponseDerOrThrow as b, parseOcspResponsePemOrThrow as x, revocationSkipReasonOf as S, validateOcspResponseBy as C } from "./ocsp.js";
|
|
10
|
+
import { verifyCertificateChain as w } from "../verify/verify.js";
|
|
11
|
+
import { parseCertificateDer as T, parseCertificateFromSource as E } from "../x509/parse.js";
|
|
8
12
|
// src/revocation/chain.ts
|
|
9
13
|
/**
|
|
10
14
|
* Chain-level revocation orchestration.
|
|
@@ -15,6 +19,23 @@ import { parseCertificateDer as _, parseCertificateFromSource as v } from "../x5
|
|
|
15
19
|
* @see {@link https://datatracker.ietf.org/doc/html/rfc5280#section-6.3 | RFC 5280 §6.3 CRL Validation}
|
|
16
20
|
* @module
|
|
17
21
|
*/
|
|
22
|
+
function sameIssuer(e, t) {
|
|
23
|
+
return e.kind === "certificate" && t.kind === "certificate" ? sameCertificate(e.certificate, t.certificate) : e.kind === "trust_anchor" && t.kind === "trust_anchor" && e.trustAnchor === t.trustAnchor;
|
|
24
|
+
}
|
|
25
|
+
/** `certificate` as an issuer: the bare trust anchor when it carries the anchor's name and key. */
|
|
26
|
+
function issuerOf(e, t) {
|
|
27
|
+
return t !== void 0 && s(e, t) ? {
|
|
28
|
+
kind: "trust_anchor",
|
|
29
|
+
trustAnchor: t
|
|
30
|
+
} : {
|
|
31
|
+
kind: "certificate",
|
|
32
|
+
certificate: e
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/** The certificate that signed CRL or OCSP evidence, for its `source`. */
|
|
36
|
+
function signerCertificateOf(e) {
|
|
37
|
+
return e.kind === "certificate" ? { signerCertificate: e.certificate } : {};
|
|
38
|
+
}
|
|
18
39
|
/**
|
|
19
40
|
* Granular reasons why revocation status could not be determined.
|
|
20
41
|
*
|
|
@@ -29,15 +50,16 @@ import { parseCertificateDer as _, parseCertificateFromSource as v } from "../x5
|
|
|
29
50
|
* - **Freshness**: `crl_expired`, `ocsp_response_expired`,
|
|
30
51
|
* `ocsp_next_update_missing`
|
|
31
52
|
* - **Delta CRL**: `delta_crl_unusable` when an authenticated, current delta
|
|
32
|
-
* CRL cannot settle the status, `delta_crl_retry_limit_exceeded` when
|
|
33
|
-
*
|
|
53
|
+
* CRL cannot settle the status, `delta_crl_retry_limit_exceeded` when the
|
|
54
|
+
* attempt limits leave a delta CRL candidate unread that counts under
|
|
55
|
+
* `unreadSupersededDeltaCrls`. Either one outranks a
|
|
34
56
|
* `good` verdict from other evidence.
|
|
35
57
|
* - **Reason code**: `crl_reason_code_unrecognized` and
|
|
36
58
|
* `ocsp_reason_code_unrecognized` when evidence revokes the certificate with
|
|
37
59
|
* an unrecognized CRLReason under `unrecognizedReasonCode: 'reject'`. Either
|
|
38
60
|
* one outranks a `good` verdict from other evidence.
|
|
39
61
|
*/
|
|
40
|
-
const
|
|
62
|
+
const D = [
|
|
41
63
|
"no_applicable_crl",
|
|
42
64
|
"no_applicable_ocsp",
|
|
43
65
|
"distribution_point_mismatch",
|
|
@@ -67,7 +89,7 @@ const y = [
|
|
|
67
89
|
*/
|
|
68
90
|
function parseCertificateSafe(e) {
|
|
69
91
|
try {
|
|
70
|
-
return
|
|
92
|
+
return E(e);
|
|
71
93
|
} catch {
|
|
72
94
|
return;
|
|
73
95
|
}
|
|
@@ -110,12 +132,15 @@ function normalizeHex(e) {
|
|
|
110
132
|
* signer already inside the validated chain is authorized by construction. The
|
|
111
133
|
* path check runs without revocation to avoid unbounded recursion.
|
|
112
134
|
*/
|
|
113
|
-
async function crlSignerChainsToAnchor(e, t, n, r) {
|
|
114
|
-
if (
|
|
115
|
-
let
|
|
116
|
-
if (
|
|
117
|
-
|
|
118
|
-
|
|
135
|
+
async function crlSignerChainsToAnchor(e, t, n, r, i) {
|
|
136
|
+
if (e.kind === "trust_anchor") return !0;
|
|
137
|
+
let a = e.certificate;
|
|
138
|
+
if (t.some((e) => sameCertificate(e, a))) return !0;
|
|
139
|
+
if (i.trustAnchor !== void 0) return await chainsToBareAnchor(a, t, n, r, i.trustAnchor, i);
|
|
140
|
+
let o = t[t.length - 1];
|
|
141
|
+
if (o === void 0) return !1;
|
|
142
|
+
let s = [], addCandidate = (e) => {
|
|
143
|
+
sameCertificate(e, a) || sameCertificate(e, o) || s.some((t) => sameCertificate(t, e)) || s.push(e);
|
|
119
144
|
};
|
|
120
145
|
for (let e = 0; e < t.length - 1; e += 1) {
|
|
121
146
|
let n = t[e];
|
|
@@ -125,92 +150,177 @@ async function crlSignerChainsToAnchor(e, t, n, r) {
|
|
|
125
150
|
let t = parseCertificateSafe(e);
|
|
126
151
|
t !== void 0 && addCandidate(t);
|
|
127
152
|
}
|
|
128
|
-
|
|
153
|
+
let c = await w({
|
|
154
|
+
leaf: a.der,
|
|
155
|
+
intermediates: s.map((e) => e.der),
|
|
156
|
+
roots: [o.der],
|
|
157
|
+
at: r,
|
|
158
|
+
...signerPathOptions(i)
|
|
159
|
+
});
|
|
160
|
+
return c.ok && recordPathKeys(c.value, i), c.ok;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Remembers the working key (RFC 5280 §6.1.4 (e)) and the issuer that a
|
|
164
|
+
* signer's validated path gives each of its certificates outside the checked
|
|
165
|
+
* chain.
|
|
166
|
+
*/
|
|
167
|
+
function recordPathKeys(e, t) {
|
|
168
|
+
e.chain.forEach((n, r) => {
|
|
169
|
+
if (t.chain.some((e) => sameCertificate(e, n))) return;
|
|
170
|
+
let i = certCacheKey(n);
|
|
171
|
+
t.pathKeys.set(i, l(e, r));
|
|
172
|
+
let a = e.chain[r + 1];
|
|
173
|
+
a === void 0 ? e.anchorCertificateInChain || t.pathIssuers.set(i, {
|
|
174
|
+
kind: "trust_anchor",
|
|
175
|
+
trustAnchor: e.trustAnchor
|
|
176
|
+
}) : t.pathIssuers.set(i, issuerOf(a, t.trustAnchor));
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* {@linkcode crlSignerChainsToAnchor} below a bare trust anchor: every chain
|
|
181
|
+
* certificate is a candidate intermediate, and the anchor ends the path.
|
|
182
|
+
*/
|
|
183
|
+
async function chainsToBareAnchor(e, t, n, r, i, a) {
|
|
184
|
+
let o = [];
|
|
185
|
+
for (let r of [...t, ...n.flatMap(parsedOrEmpty)]) !sameCertificate(r, e) && !o.some((e) => sameCertificate(e, r)) && o.push(r);
|
|
186
|
+
let s = await w({
|
|
129
187
|
leaf: e.der,
|
|
130
|
-
intermediates:
|
|
131
|
-
roots: [
|
|
132
|
-
|
|
133
|
-
|
|
188
|
+
intermediates: o.map((e) => e.der),
|
|
189
|
+
roots: [],
|
|
190
|
+
trustAnchors: [i],
|
|
191
|
+
at: r,
|
|
192
|
+
...signerPathOptions(a)
|
|
193
|
+
});
|
|
194
|
+
return s.ok && recordPathKeys(s.value, a), s.ok;
|
|
195
|
+
}
|
|
196
|
+
/** The caller's verifiers and distrust for a signer's certification path. */
|
|
197
|
+
function signerPathOptions(e) {
|
|
198
|
+
return {
|
|
199
|
+
...e.signatureVerifiers !== void 0 && { signatureVerifiers: e.signatureVerifiers },
|
|
200
|
+
...e.distrustedSpkiSha256 !== void 0 && { distrustedSpkiSha256: e.distrustedSpkiSha256 }
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
function parsedOrEmpty(e) {
|
|
204
|
+
let t = parseCertificateSafe(e);
|
|
205
|
+
return t === void 0 ? [] : [t];
|
|
206
|
+
}
|
|
207
|
+
/** Caller verification for a signature by `signer`, with its working key parameters. */
|
|
208
|
+
function signerVerification(e, t) {
|
|
209
|
+
return {
|
|
210
|
+
verifiers: e.verifiers,
|
|
211
|
+
workingParameters: { parametersDer: t.kind === "trust_anchor" ? o(t.trustAnchor).parametersDer : e.workingKeyOf(t.certificate).parametersDer }
|
|
212
|
+
};
|
|
134
213
|
}
|
|
135
214
|
/**
|
|
136
|
-
*
|
|
137
|
-
*
|
|
215
|
+
* Working keys along `chain`: a member inherits key parameters from the members
|
|
216
|
+
* above it (RFC 5280 §6.1.4 (e)); any other certificate keeps its own.
|
|
138
217
|
*/
|
|
218
|
+
function chainWorkingKeys(e, t) {
|
|
219
|
+
let n = e[e.length - 1];
|
|
220
|
+
return (r) => {
|
|
221
|
+
let i = e.findIndex((e) => sameCertificate(e, r));
|
|
222
|
+
return n === void 0 || i < 0 ? c(r) : {
|
|
223
|
+
algorithmOid: r.publicKeyAlgorithmOid,
|
|
224
|
+
parametersDer: t === void 0 ? u(e, i, e.length - 2, c(n)) : u(e, i, e.length - 1, t)
|
|
225
|
+
};
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
/** A cache key for a certificate: its DER, so two certificates never share one. */
|
|
139
229
|
function certCacheKey(e) {
|
|
140
|
-
return
|
|
230
|
+
return t(e.der);
|
|
141
231
|
}
|
|
142
232
|
/**
|
|
143
233
|
* Validates that a CRL signer certificate is not revoked.
|
|
144
234
|
* Uses memoization to avoid redundant checks and detect cycles.
|
|
145
235
|
*/
|
|
146
236
|
async function validateCrlSigner(e, t) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
if (
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
return t.cache.set(n, o), o;
|
|
237
|
+
if (e.kind === "trust_anchor") return "resolved-valid";
|
|
238
|
+
let n = e.certificate, r = certCacheKey(n), i = t.cache.get(r);
|
|
239
|
+
if (i === "visiting") return "resolved-indeterminate";
|
|
240
|
+
if (i !== void 0) return i;
|
|
241
|
+
if (t.cache.set(r, "visiting"), t.chain.some((e) => sameCertificate(e, n))) return t.cache.set(r, "resolved-valid"), "resolved-valid";
|
|
242
|
+
let a = t.pathIssuers.get(r);
|
|
243
|
+
if (a === void 0) return t.cache.set(r, "resolved-indeterminate"), "resolved-indeterminate";
|
|
244
|
+
let o = revocationSkipReason(n) === void 0 ? await checkSignerRevocation(n, a, t) : "resolved-valid", s = o === "resolved-valid" ? statusBelow(await validateCrlSigner(a, t)) : o;
|
|
245
|
+
return t.cache.set(r, s), s;
|
|
157
246
|
}
|
|
158
247
|
/**
|
|
159
|
-
*
|
|
160
|
-
*
|
|
248
|
+
* A good or exempt signer's status once its issuer's is known: RFC 5280
|
|
249
|
+
* §6.3.3 (f) validates the whole path of a CRL issuer, so an issuer that is
|
|
250
|
+
* not known good leaves the signer indeterminate. RFC 9608 §4 exempts only the
|
|
251
|
+
* certificate carrying noRevAvail or id-pkix-ocsp-nocheck.
|
|
161
252
|
*/
|
|
162
|
-
function
|
|
163
|
-
|
|
164
|
-
for (let e of t.extraCertificates) {
|
|
165
|
-
let t = parseCertificateSafe(e);
|
|
166
|
-
t !== void 0 && n.push(t);
|
|
167
|
-
}
|
|
168
|
-
let r = [...t.chain, ...n];
|
|
169
|
-
for (let t of r) if (e.authorityKeyIdentifier !== void 0 && t.subjectKeyIdentifier !== void 0 && normalizeHex(e.authorityKeyIdentifier) === normalizeHex(t.subjectKeyIdentifier) || e.issuer.derHex === t.subject.derHex) return t;
|
|
253
|
+
function statusBelow(e) {
|
|
254
|
+
return e === "resolved-valid" ? "resolved-valid" : "resolved-indeterminate";
|
|
170
255
|
}
|
|
171
256
|
/**
|
|
172
257
|
* Checks if a CRL signer certificate is revoked by examining available CRLs.
|
|
173
258
|
* Recursively validates the CRL signer of any CRL used to check revocation.
|
|
174
259
|
*/
|
|
175
260
|
async function checkSignerRevocation(e, t, n) {
|
|
176
|
-
let r =
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
261
|
+
let r = /* @__PURE__ */ new Set(), i = !1, a = g(n.crls.flatMap((e) => {
|
|
262
|
+
try {
|
|
263
|
+
return [v(e)];
|
|
264
|
+
} catch {
|
|
265
|
+
return [];
|
|
266
|
+
}
|
|
267
|
+
})), o = a.filter((e) => e.baseCrlNumber !== void 0);
|
|
268
|
+
for (let s of a) {
|
|
269
|
+
if (s.baseCrlNumber !== void 0) continue;
|
|
270
|
+
let a = await checkSignerAgainstCrlAuthorities(e, t, s, o, n);
|
|
271
|
+
if (a.kind === "revoked") return "resolved-revoked";
|
|
272
|
+
if (a.kind === "unrecognized_reason" || a.kind === "unsettled_delta") i = !0;
|
|
273
|
+
else for (let e of a.reasons) r.add(e);
|
|
182
274
|
}
|
|
183
|
-
return
|
|
275
|
+
return i ? "resolved-indeterminate" : h(r) ? "resolved-valid" : "resolved-indeterminate";
|
|
184
276
|
}
|
|
185
|
-
const
|
|
277
|
+
const O = {
|
|
186
278
|
kind: "reasons",
|
|
187
279
|
reasons: []
|
|
188
280
|
};
|
|
189
281
|
/**
|
|
190
|
-
* Evaluates one CRL against a signer
|
|
191
|
-
*
|
|
192
|
-
*
|
|
282
|
+
* Evaluates one CRL against a signer with each key that may have signed it:
|
|
283
|
+
* the signer's issuer, then an indirect CRL issuer whose path validates, the
|
|
284
|
+
* signer itself included. The first key whose check yields evidence settles
|
|
285
|
+
* the CRL.
|
|
193
286
|
*/
|
|
194
|
-
async function
|
|
195
|
-
let i
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
return b;
|
|
287
|
+
async function checkSignerAgainstCrlAuthorities(e, t, n, r, i) {
|
|
288
|
+
for (let a of collectCrlSignerCandidates(n, t, i.extraCertificates, i.chain, i.trustAnchor)) {
|
|
289
|
+
if (!sameIssuer(a, t) && !await crlSignerChainsToAnchor(a, i.chain, i.extraCertificates, i.at, i)) continue;
|
|
290
|
+
let o = await checkSignerAgainstCrl(e, a, n, r, i, [i.deltaBudget]);
|
|
291
|
+
if (o.kind !== "reasons" || o.reasons.length > 0) return o;
|
|
200
292
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
293
|
+
return O;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Evaluates one CRL against a signer. A CRL that does not parse or does not
|
|
297
|
+
* apply yields no evidence. Its `good` needs a CRL signer known good, and its
|
|
298
|
+
* revocation one not known revoked. A CRL the signer itself signed vouches
|
|
299
|
+
* for it as `crlSignerSelfEvidence` allows.
|
|
300
|
+
*/
|
|
301
|
+
async function checkSignerAgainstCrl(e, t, n, r, i, a) {
|
|
302
|
+
let o = await m(e, n, r, t, {
|
|
303
|
+
at: i.at,
|
|
304
|
+
...i.crlMaxAgeMs === void 0 ? {} : { maxAgeMs: i.crlMaxAgeMs },
|
|
305
|
+
...i.clockSkewMs === void 0 ? {} : { clockSkewMs: i.clockSkewMs },
|
|
306
|
+
unrecognizedReasonCode: i.unrecognizedReasonCode,
|
|
307
|
+
unreadSupersededDeltaCrls: i.unreadSupersededDeltaCrls
|
|
308
|
+
}, signerVerification(i, t), a);
|
|
309
|
+
if (o.kind === "unsettled") return { kind: "unsettled_delta" };
|
|
310
|
+
let s = o.result;
|
|
311
|
+
if (!s.ok) return s.code === "reason_code_unrecognized" ? { kind: "unrecognized_reason" } : O;
|
|
312
|
+
let c = t.kind === "certificate" && sameCertificate(t.certificate, e);
|
|
313
|
+
if (c && i.crlSignerSelfEvidence === "delegated" && !delegatesOwnStatus(e)) return s.value.status === "revoked" ? { kind: "revoked" } : O;
|
|
314
|
+
let l = c ? "resolved-valid" : await validateCrlSigner(t, i);
|
|
315
|
+
return s.value.status === "revoked" ? l === "resolved-revoked" ? O : { kind: "revoked" } : l === "resolved-valid" ? {
|
|
211
316
|
kind: "reasons",
|
|
212
|
-
reasons:
|
|
213
|
-
} :
|
|
317
|
+
reasons: s.value.coveredReasons
|
|
318
|
+
} : O;
|
|
319
|
+
}
|
|
320
|
+
/** Whether `signer`'s cRLDistributionPoints names `signer` itself as cRLIssuer. */
|
|
321
|
+
function delegatesOwnStatus(e) {
|
|
322
|
+
let t = e.subject.derHex.toLowerCase();
|
|
323
|
+
return (e.crlDistributionPoints ?? []).some((e) => e.crlIssuer?.some((e) => e.type === "directoryName" && e.derHex.toLowerCase() === t) === !0);
|
|
214
324
|
}
|
|
215
325
|
/** Builds the `revoked` CertificateRevocationStatus for a CRL hit. */
|
|
216
326
|
function buildCrlRevokedStatus(e, t, n, r, i) {
|
|
@@ -219,7 +329,7 @@ function buildCrlRevokedStatus(e, t, n, r, i) {
|
|
|
219
329
|
status: "revoked",
|
|
220
330
|
source: {
|
|
221
331
|
kind: "crl",
|
|
222
|
-
|
|
332
|
+
...signerCertificateOf(t),
|
|
223
333
|
thisUpdate: n
|
|
224
334
|
},
|
|
225
335
|
revocationInfo: {
|
|
@@ -230,7 +340,7 @@ function buildCrlRevokedStatus(e, t, n, r, i) {
|
|
|
230
340
|
}
|
|
231
341
|
/** Parses an OCSP response from PEM string or DER bytes. */
|
|
232
342
|
function parseOcspResponseFromSource(e) {
|
|
233
|
-
return typeof e == "string" ?
|
|
343
|
+
return typeof e == "string" ? x(e) : b(e);
|
|
234
344
|
}
|
|
235
345
|
function evidenceParseError(t, r) {
|
|
236
346
|
return {
|
|
@@ -283,7 +393,7 @@ function classifyValidatedOcspEntry(e, t, n) {
|
|
|
283
393
|
thisUpdate: t.thisUpdate
|
|
284
394
|
};
|
|
285
395
|
if (t.certStatus === "unknown") return { kind: "unknown" };
|
|
286
|
-
let r =
|
|
396
|
+
let r = y(t.revocationReasonCode);
|
|
287
397
|
if (n === "reject" && typeof r == "object") return { kind: "unrecognized_reason" };
|
|
288
398
|
let i = buildOcspRevokedStatus(e, t.thisUpdate, t.revokedAt, r);
|
|
289
399
|
return r === "certificateHold" ? {
|
|
@@ -329,6 +439,7 @@ function ocspIndeterminateReasonFromFailure(e) {
|
|
|
329
439
|
case "responder_revoked": return "ocsp_responder_revoked";
|
|
330
440
|
case "signature_invalid":
|
|
331
441
|
case "responder_revocation_unknown":
|
|
442
|
+
case "malformed":
|
|
332
443
|
case "unsupported":
|
|
333
444
|
case "limit_exceeded": return "ocsp_responder_indeterminate";
|
|
334
445
|
case "response_status_invalid":
|
|
@@ -339,48 +450,64 @@ function ocspIndeterminateReasonFromFailure(e) {
|
|
|
339
450
|
}
|
|
340
451
|
}
|
|
341
452
|
/** Validation failures worth retrying with an explicit responder certificate. */
|
|
342
|
-
const
|
|
453
|
+
const k = /* @__PURE__ */ new Set([
|
|
343
454
|
"signature_invalid",
|
|
344
455
|
"responder_id_mismatch",
|
|
345
456
|
"responder_chain_invalid",
|
|
346
457
|
"ocsp_signing_missing",
|
|
458
|
+
"malformed",
|
|
347
459
|
"unsupported",
|
|
348
460
|
"limit_exceeded"
|
|
349
461
|
]);
|
|
462
|
+
/** The {@linkcode validateOcspResponse} options that a chain's `policy` sets. */
|
|
463
|
+
function ocspPolicyOptions(e) {
|
|
464
|
+
return {
|
|
465
|
+
...e?.ocspResponderRevocation === void 0 ? {} : { responderRevocationPolicy: e.ocspResponderRevocation },
|
|
466
|
+
...e?.crlMaxAgeMs === void 0 ? {} : { responderRevocationCrlMaxAgeMs: e.crlMaxAgeMs },
|
|
467
|
+
...e?.clockSkewMs === void 0 ? {} : { clockSkewMs: e.clockSkewMs },
|
|
468
|
+
...e?.ocspProfile === void 0 ? {} : { profile: e.ocspProfile },
|
|
469
|
+
...e?.unrecognizedReasonCode === void 0 ? {} : { responderRevocationUnrecognizedReasonCode: e.unrecognizedReasonCode },
|
|
470
|
+
...e?.unreadSupersededDeltaCrls === void 0 ? {} : { responderRevocationUnreadSupersededDeltaCrls: e.unreadSupersededDeltaCrls }
|
|
471
|
+
};
|
|
472
|
+
}
|
|
350
473
|
/**
|
|
351
474
|
* Validates an OCSP response, retrying with caller-provided extra certificates
|
|
352
475
|
* as explicit responder certificates when embedded discovery fails.
|
|
353
476
|
*/
|
|
354
|
-
async function validateOcspResponseWithResponderFallback(e, t, n, r) {
|
|
355
|
-
let
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
...n
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
477
|
+
async function validateOcspResponseWithResponderFallback(e, t, n, r, i, a) {
|
|
478
|
+
let c = {
|
|
479
|
+
verifiers: a.verifiers,
|
|
480
|
+
issuerWorkingKey: n.kind === "certificate" ? a.workingKeyOf(n.certificate) : o(n.trustAnchor),
|
|
481
|
+
deltaBudget: a.deltaBudget,
|
|
482
|
+
...a.distrustedSpkiSha256 !== void 0 && { distrustedSpkiSha256: a.distrustedSpkiSha256 }
|
|
483
|
+
}, l = r.trustedOcspResponders?.filter((e) => {
|
|
484
|
+
let t = parseCertificateSafe(e.issuerCertificate);
|
|
485
|
+
return t === void 0 ? !1 : n.kind === "certificate" ? sameCertificate(t, n.certificate) : s(t, n.trustAnchor);
|
|
486
|
+
}).map((e) => e.responderCertificate), u = n.kind === "certificate" ? n : {
|
|
487
|
+
...n,
|
|
488
|
+
certificateIssuer: t.issuer
|
|
489
|
+
}, d = {
|
|
490
|
+
at: i,
|
|
491
|
+
...l === void 0 ? {} : { trustedOcspResponders: l },
|
|
492
|
+
...ocspPolicyOptions(r.policy),
|
|
493
|
+
...r.crls === void 0 ? {} : { responderRevocationCrls: r.crls },
|
|
494
|
+
...r.signatureVerifiers === void 0 ? {} : { signatureVerifiers: r.signatureVerifiers }
|
|
495
|
+
}, f = await C({
|
|
369
496
|
response: e,
|
|
370
|
-
...
|
|
371
|
-
});
|
|
372
|
-
if (
|
|
373
|
-
for (let t of
|
|
497
|
+
...d
|
|
498
|
+
}, u, c);
|
|
499
|
+
if (f.ok || !k.has(f.code)) return f;
|
|
500
|
+
for (let t of r.extraCertificates ?? []) {
|
|
374
501
|
let n = parseCertificateSafe(t);
|
|
375
502
|
if (n === void 0) continue;
|
|
376
|
-
let r = await
|
|
503
|
+
let r = await C({
|
|
377
504
|
response: e,
|
|
378
|
-
...
|
|
505
|
+
...d,
|
|
379
506
|
responderCertificate: n
|
|
380
|
-
});
|
|
381
|
-
if (r.ok) return r;
|
|
507
|
+
}, u, c);
|
|
508
|
+
if (r.ok || !k.has(r.code)) return r;
|
|
382
509
|
}
|
|
383
|
-
return
|
|
510
|
+
return f;
|
|
384
511
|
}
|
|
385
512
|
/**
|
|
386
513
|
* Evaluates OCSP evidence for a single certificate (RFC 6960).
|
|
@@ -391,31 +518,31 @@ async function validateOcspResponseWithResponderFallback(e, t, n, r) {
|
|
|
391
518
|
* the validator, so a serial-number match on a validated response is
|
|
392
519
|
* sufficient to attribute the entry to `cert`.
|
|
393
520
|
*/
|
|
394
|
-
async function evaluateOcspEvidence(e, t, n) {
|
|
395
|
-
let { ocspResponses:
|
|
521
|
+
async function evaluateOcspEvidence(e, t, n, r) {
|
|
522
|
+
let { ocspResponses: i = [], at: a = /* @__PURE__ */ new Date() } = n, o = [], s = {
|
|
396
523
|
reasons: /* @__PURE__ */ new Set(),
|
|
397
524
|
sawUnrecognizedReason: !1
|
|
398
525
|
};
|
|
399
|
-
for (let
|
|
400
|
-
let
|
|
401
|
-
if (
|
|
402
|
-
|
|
526
|
+
for (let c of i) {
|
|
527
|
+
let i = findApplicableOcspResponse(c, e);
|
|
528
|
+
if (i.kind === "parse_error") {
|
|
529
|
+
o.push(i.error);
|
|
403
530
|
continue;
|
|
404
531
|
}
|
|
405
|
-
if (
|
|
406
|
-
let
|
|
407
|
-
if (!
|
|
408
|
-
|
|
532
|
+
if (i.kind === "not_applicable") continue;
|
|
533
|
+
let l = await validateOcspResponseWithResponderFallback(i.parsed, e, t, n, a, r);
|
|
534
|
+
if (!l.ok) {
|
|
535
|
+
s.reasons.add(ocspIndeterminateReasonFromFailure(l.code));
|
|
409
536
|
continue;
|
|
410
537
|
}
|
|
411
|
-
let
|
|
412
|
-
if (
|
|
413
|
-
status:
|
|
414
|
-
executionErrors:
|
|
538
|
+
let u = classifyValidatedOcspEntry(e, i.entry, n.policy?.unrecognizedReasonCode ?? "revoked");
|
|
539
|
+
if (u.kind === "revoked") return {
|
|
540
|
+
status: u.status,
|
|
541
|
+
executionErrors: o
|
|
415
542
|
};
|
|
416
|
-
recordOcspEvidence(
|
|
543
|
+
recordOcspEvidence(s, u);
|
|
417
544
|
}
|
|
418
|
-
return settleOcspEvidence(e,
|
|
545
|
+
return settleOcspEvidence(e, s, o);
|
|
419
546
|
}
|
|
420
547
|
function recordOcspEvidence(e, t) {
|
|
421
548
|
t.kind === "good" ? e.freshestGoodThisUpdate = laterEvidenceDate(e.freshestGoodThisUpdate, t.thisUpdate) : t.kind === "hold" ? (e.freshestHold === void 0 || t.evidence.thisUpdate.getTime() > e.freshestHold.thisUpdate.getTime()) && (e.freshestHold = t.evidence) : t.kind === "unrecognized_reason" ? e.sawUnrecognizedReason = !0 : e.reasons.add("ocsp_status_unknown");
|
|
@@ -433,59 +560,61 @@ function settleOcspEvidence(e, t, n) {
|
|
|
433
560
|
* Runs each candidate signer through the full pipeline for one base CRL:
|
|
434
561
|
* signature/applicability, RFC 5280 §6.3.3(f) path to the anchor, then signer
|
|
435
562
|
* revocation. A candidate that verifies the signature but fails a later step
|
|
436
|
-
* does not shadow a subsequent usable signer, so the search continues.
|
|
437
|
-
*
|
|
438
|
-
*
|
|
563
|
+
* does not shadow a subsequent usable signer, so the search continues. A
|
|
564
|
+
* revocation stands from a signer whose own status is indeterminate, while
|
|
565
|
+
* `good` needs a signer known good. Returns a revoked status when one is
|
|
566
|
+
* found; otherwise records good or diagnostic evidence into `state`.
|
|
439
567
|
*/
|
|
440
568
|
async function resolveBaseCrlAgainstSigners(e) {
|
|
441
|
-
let { cert: t, baseCrl: n,
|
|
442
|
-
for (let e of collectCrlSignerCandidates(n, i, a, o)) {
|
|
443
|
-
let i = await
|
|
569
|
+
let { cert: t, baseCrl: n, deltaCrls: r, issuer: i, extraCertificates: a, chain: o, at: s, crlMaxAgeMs: c, clockSkewMs: l, unrecognizedReasonCode: u, signerCtx: d, deltaBudget: f, state: m } = e;
|
|
570
|
+
for (let e of collectCrlSignerCandidates(n, i, a, o, d.trustAnchor)) {
|
|
571
|
+
let i = await crlSignerChainsToAnchor(e, o, a, s, d), h = signerVerification(d, e);
|
|
572
|
+
if (!i) {
|
|
573
|
+
m.sawCrlSignerNotAuthorized ||= (await p(n, e, h)).ok;
|
|
574
|
+
continue;
|
|
575
|
+
}
|
|
576
|
+
let g = await checkCrlAgainstDeltaCandidates({
|
|
444
577
|
cert: t,
|
|
445
578
|
baseCrl: n,
|
|
446
|
-
|
|
579
|
+
deltaCrls: r,
|
|
447
580
|
candidate: e,
|
|
448
581
|
at: s,
|
|
449
582
|
crlMaxAgeMs: c,
|
|
450
583
|
clockSkewMs: l,
|
|
451
584
|
unrecognizedReasonCode: u,
|
|
452
|
-
|
|
453
|
-
|
|
585
|
+
unreadSupersededDeltaCrls: d.unreadSupersededDeltaCrls,
|
|
586
|
+
budgets: [f],
|
|
587
|
+
state: m,
|
|
588
|
+
verification: h
|
|
454
589
|
});
|
|
455
|
-
if (
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
continue;
|
|
459
|
-
}
|
|
460
|
-
let h = await validateCrlSigner(e, d);
|
|
461
|
-
if (h === "resolved-revoked") {
|
|
462
|
-
p.sawCrlSignerRevoked = !0;
|
|
463
|
-
continue;
|
|
464
|
-
}
|
|
465
|
-
if (h === "resolved-indeterminate") {
|
|
466
|
-
p.sawCrlSignerIndeterminate = !0;
|
|
467
|
-
continue;
|
|
468
|
-
}
|
|
469
|
-
if (i.kind === "reason_code_unrecognized") {
|
|
470
|
-
p.sawUnrecognizedReasonCode = !0;
|
|
471
|
-
return;
|
|
472
|
-
}
|
|
473
|
-
if (i.kind === "delta_unusable") {
|
|
474
|
-
p.sawDeltaCrlUnusable = !0;
|
|
475
|
-
return;
|
|
476
|
-
}
|
|
477
|
-
if (i.kind === "retry_limit") {
|
|
478
|
-
p.sawDeltaCrlRetryLimit = !0;
|
|
479
|
-
return;
|
|
480
|
-
}
|
|
481
|
-
let { checked: g, crlThisUpdate: _ } = i;
|
|
482
|
-
if (g.value.status === "revoked") return buildCrlRevokedStatus(t, e, _, g.value.revocationDate, g.value.reasonCode);
|
|
483
|
-
recordGoodCrlEvidence(p, e, _, g.value.coveredReasons);
|
|
484
|
-
return;
|
|
590
|
+
if (g.kind === "unusable_base") continue;
|
|
591
|
+
let _ = settleCrlSignerCandidate(t, e, g, await validateCrlSigner(e, d), m);
|
|
592
|
+
if (_.kind === "done") return _.status;
|
|
485
593
|
}
|
|
486
594
|
}
|
|
595
|
+
const A = { kind: "next" };
|
|
596
|
+
/**
|
|
597
|
+
* Settles one authorized signer candidate's outcome for a base CRL by the
|
|
598
|
+
* signer's own status. A revocation stands from a signer whose status is
|
|
599
|
+
* indeterminate, while `good` needs a signer known good.
|
|
600
|
+
*/
|
|
601
|
+
function settleCrlSignerCandidate(e, t, n, r, i) {
|
|
602
|
+
if (r === "resolved-revoked") return i.sawCrlSignerRevoked = !0, A;
|
|
603
|
+
let a = revokedCrlStatus(e, t, n);
|
|
604
|
+
return r === "resolved-indeterminate" ? (i.sawCrlSignerIndeterminate = !0, a === void 0 ? A : {
|
|
605
|
+
kind: "done",
|
|
606
|
+
status: a
|
|
607
|
+
}) : (n.kind === "reason_code_unrecognized" ? i.sawUnrecognizedReasonCode = !0 : n.kind === "delta_unusable" ? i.sawDeltaCrlUnusable = !0 : n.kind === "retry_limit" ? i.sawDeltaCrlRetryLimit = !0 : n.checked.value.status === "good" && recordGoodCrlEvidence(i, t, n.crlThisUpdate, n.checked.value.coveredReasons), {
|
|
608
|
+
kind: "done",
|
|
609
|
+
status: a
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
/** The revoked status `resolved` reports for `cert`, signed by `signer`. */
|
|
613
|
+
function revokedCrlStatus(e, t, n) {
|
|
614
|
+
return n.kind === "checked" && n.checked.value.status === "revoked" ? buildCrlRevokedStatus(e, t, n.crlThisUpdate, n.checked.value.revocationDate, n.checked.value.reasonCode) : void 0;
|
|
615
|
+
}
|
|
487
616
|
async function evaluateCrlEvidence(e, t, n, r, i) {
|
|
488
|
-
let { crls: a = [], extraCertificates: o = [], chain:
|
|
617
|
+
let { crls: a = [], extraCertificates: o = [], chain: s = [], at: c = /* @__PURE__ */ new Date() } = n, l = {
|
|
489
618
|
executionErrors: [],
|
|
490
619
|
coveredReasons: /* @__PURE__ */ new Set(),
|
|
491
620
|
sawCrlSignerRevoked: !1,
|
|
@@ -496,61 +625,61 @@ async function evaluateCrlEvidence(e, t, n, r, i) {
|
|
|
496
625
|
sawDeltaCrlRetryLimit: !1,
|
|
497
626
|
sawUnrecognizedReasonCode: !1,
|
|
498
627
|
sawGood: !1
|
|
499
|
-
},
|
|
500
|
-
for (let a of
|
|
501
|
-
let
|
|
628
|
+
}, u = parseCrlEvidenceSources(a, l.executionErrors), d = g(u.filter((t) => t.baseCrlNumber === void 0 && _(e, t))), f = g(u.filter((e) => e.baseCrlNumber !== void 0)), p = n.policy?.crlMaxAgeMs, m = n.policy?.clockSkewMs;
|
|
629
|
+
for (let a of d) {
|
|
630
|
+
let u = await resolveBaseCrlAgainstSigners({
|
|
502
631
|
cert: e,
|
|
503
632
|
baseCrl: a,
|
|
504
|
-
|
|
633
|
+
deltaCrls: f,
|
|
505
634
|
issuer: t,
|
|
506
635
|
extraCertificates: o,
|
|
507
|
-
chain:
|
|
508
|
-
at:
|
|
509
|
-
crlMaxAgeMs:
|
|
510
|
-
clockSkewMs:
|
|
636
|
+
chain: s,
|
|
637
|
+
at: c,
|
|
638
|
+
crlMaxAgeMs: p,
|
|
639
|
+
clockSkewMs: m,
|
|
511
640
|
unrecognizedReasonCode: n.policy?.unrecognizedReasonCode ?? "revoked",
|
|
512
641
|
signerCtx: r,
|
|
513
642
|
deltaBudget: i,
|
|
514
|
-
state:
|
|
643
|
+
state: l
|
|
515
644
|
});
|
|
516
|
-
if (
|
|
517
|
-
status:
|
|
518
|
-
executionErrors:
|
|
645
|
+
if (u !== void 0) return {
|
|
646
|
+
status: u,
|
|
647
|
+
executionErrors: l.executionErrors
|
|
519
648
|
};
|
|
520
649
|
}
|
|
521
|
-
let
|
|
522
|
-
return
|
|
650
|
+
let v = blockingCrlIndeterminateReasons(l);
|
|
651
|
+
return v.length > 0 ? {
|
|
523
652
|
status: {
|
|
524
653
|
certificate: e,
|
|
525
654
|
status: "indeterminate",
|
|
526
|
-
indeterminateReasons:
|
|
655
|
+
indeterminateReasons: v
|
|
527
656
|
},
|
|
528
|
-
executionErrors:
|
|
529
|
-
} :
|
|
657
|
+
executionErrors: l.executionErrors
|
|
658
|
+
} : l.sawGood && l.freshestGood !== void 0 ? h(l.coveredReasons) ? {
|
|
530
659
|
status: {
|
|
531
660
|
certificate: e,
|
|
532
661
|
status: "good",
|
|
533
662
|
source: {
|
|
534
663
|
kind: "crl",
|
|
535
|
-
|
|
536
|
-
thisUpdate:
|
|
664
|
+
...signerCertificateOf(l.freshestGood.signer),
|
|
665
|
+
thisUpdate: l.freshestGood.thisUpdate
|
|
537
666
|
}
|
|
538
667
|
},
|
|
539
|
-
executionErrors:
|
|
668
|
+
executionErrors: l.executionErrors
|
|
540
669
|
} : {
|
|
541
670
|
status: {
|
|
542
671
|
certificate: e,
|
|
543
672
|
status: "indeterminate",
|
|
544
673
|
indeterminateReasons: ["reason_coverage_incomplete"]
|
|
545
674
|
},
|
|
546
|
-
executionErrors:
|
|
675
|
+
executionErrors: l.executionErrors
|
|
547
676
|
} : {
|
|
548
677
|
status: {
|
|
549
678
|
certificate: e,
|
|
550
679
|
status: "indeterminate",
|
|
551
|
-
indeterminateReasons: [crlUnavailableReason(
|
|
680
|
+
indeterminateReasons: [crlUnavailableReason(l)]
|
|
552
681
|
},
|
|
553
|
-
executionErrors:
|
|
682
|
+
executionErrors: l.executionErrors
|
|
554
683
|
};
|
|
555
684
|
}
|
|
556
685
|
/** CRL conditions that keep the status indeterminate despite `good` evidence. */
|
|
@@ -569,106 +698,43 @@ function crlUnavailableReason(e) {
|
|
|
569
698
|
function parseCrlEvidenceSources(e, t) {
|
|
570
699
|
let n = [];
|
|
571
700
|
for (let r of e) try {
|
|
572
|
-
n.push(
|
|
701
|
+
n.push(v(r));
|
|
573
702
|
} catch (e) {
|
|
574
703
|
t.push(evidenceParseError(e, "CRL parse failed"));
|
|
575
704
|
}
|
|
576
705
|
return n;
|
|
577
706
|
}
|
|
578
|
-
/** `crls` without repeats of the same signed content and signature. */
|
|
579
|
-
function distinctSignedCrls(e) {
|
|
580
|
-
let n = /* @__PURE__ */ new Set();
|
|
581
|
-
return e.filter((e) => {
|
|
582
|
-
let r = [
|
|
583
|
-
e.signatureAlgorithmOid,
|
|
584
|
-
t(e.signatureAlgorithmParametersDer ?? /* @__PURE__ */ new Uint8Array()),
|
|
585
|
-
t(e.signatureValue),
|
|
586
|
-
t(e.tbsCertListDer)
|
|
587
|
-
].join(":");
|
|
588
|
-
return !n.has(r) && (n.add(r), !0);
|
|
589
|
-
});
|
|
590
|
-
}
|
|
591
|
-
/** Every delta CRL that can update `baseCrl`, newest first, in the order to try authenticating them. */
|
|
592
|
-
function rankApplicableDeltaCrls(e, t, n, r, i) {
|
|
593
|
-
let a = e.crlNumber;
|
|
594
|
-
return a === void 0 ? [] : t.filter((t) => t.issuer.derHex === e.issuer.derHex && t.baseCrlNumber !== void 0 && t.baseCrlNumber <= a && t.crlNumber !== void 0 && t.crlNumber > a && t.thisUpdate.getTime() >= e.thisUpdate.getTime() && l(t, n, r, i)).sort((e, t) => isNewerDeltaCrl(e, t) ? -1 : +!!isNewerDeltaCrl(t, e));
|
|
595
|
-
}
|
|
596
|
-
const S = 4;
|
|
597
707
|
/**
|
|
598
|
-
*
|
|
599
|
-
*
|
|
600
|
-
*
|
|
601
|
-
* and applicability ends the search.
|
|
708
|
+
* Checks `baseCrl`, signed by `candidate`, and its delta CRLs through
|
|
709
|
+
* {@linkcode checkCertificateRevocationAgainstCrlsBy}, which every CRL
|
|
710
|
+
* consumer shares, and maps the outcome to the chain's evidence.
|
|
602
711
|
*/
|
|
603
712
|
async function checkCrlAgainstDeltaCandidates(e) {
|
|
604
|
-
let { cert: t, baseCrl: n,
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
};
|
|
615
|
-
for (let e of r) {
|
|
616
|
-
let r = takeDeltaCrlAttempt(d) ? settleAuthenticatedCrlOutcome(await o(t, p.value, {
|
|
617
|
-
...m,
|
|
618
|
-
deltaCrl: e
|
|
619
|
-
}), laterEvidenceDate(n.thisUpdate, e.thisUpdate), f) : { kind: "retry_limit" };
|
|
620
|
-
if (r !== void 0) {
|
|
621
|
-
if (r.kind === "delta_unusable") return irremovableRevocation(t, r.complete, s, n.thisUpdate) ?? r;
|
|
622
|
-
if (r.kind === "retry_limit") {
|
|
623
|
-
let e = await o(t, p.value, m);
|
|
624
|
-
return (e.kind === "checked" ? irremovableRevocation(t, e.result, s, n.thisUpdate) : void 0) ?? r;
|
|
625
|
-
}
|
|
626
|
-
return r;
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
return settleAuthenticatedCrlOutcome(await o(t, p.value, m), n.thisUpdate, f) ?? { kind: "unusable_base" };
|
|
630
|
-
}
|
|
631
|
-
/**
|
|
632
|
-
* The base CRL's revocation of `cert` in `complete` when no delta CRL could
|
|
633
|
-
* remove it at `at`. RFC 5280 §5.3.1 lets removeFromCRL clear only a
|
|
634
|
-
* certificateHold entry or a certificate that has expired.
|
|
635
|
-
*/
|
|
636
|
-
function irremovableRevocation(e, t, n, r) {
|
|
637
|
-
if (!(e.notAfter.getTime() < n.getTime() || !t.ok || t.value.status !== "revoked" || t.value.reasonCode === "certificateHold")) return {
|
|
638
|
-
kind: "checked",
|
|
639
|
-
checked: t,
|
|
640
|
-
crlThisUpdate: r
|
|
641
|
-
};
|
|
642
|
-
}
|
|
643
|
-
/** Spends one delta CRL check from every budget, or none when any is empty. */
|
|
644
|
-
function takeDeltaCrlAttempt(e) {
|
|
645
|
-
if (e.some((e) => e.remaining <= 0)) return !1;
|
|
646
|
-
for (let t of e) --t.remaining;
|
|
647
|
-
return !0;
|
|
648
|
-
}
|
|
649
|
-
/** Maps one staged CRL check to the search outcome, or `undefined` to try the next delta CRL. */
|
|
650
|
-
function settleAuthenticatedCrlOutcome(e, t, n) {
|
|
651
|
-
if (e.kind === "delta_unresolved") return {
|
|
652
|
-
kind: "delta_unusable",
|
|
653
|
-
complete: e.complete
|
|
654
|
-
};
|
|
655
|
-
let r = e.kind === "checked" ? e.result : e.failure;
|
|
656
|
-
if (!r.ok && r.code === "stale_crl" && (n.sawStaleCrl = !0), !r.ok && r.code === "reason_code_unrecognized") return { kind: "reason_code_unrecognized" };
|
|
657
|
-
if (e.kind !== "delta_rejected") return r.ok ? {
|
|
713
|
+
let { cert: t, baseCrl: n, deltaCrls: r, candidate: i, at: a, crlMaxAgeMs: o, clockSkewMs: s, unrecognizedReasonCode: c, unreadSupersededDeltaCrls: l, budgets: u, state: d, verification: f } = e, p = await m(t, n, r, i, {
|
|
714
|
+
at: a,
|
|
715
|
+
...o === void 0 ? {} : { maxAgeMs: o },
|
|
716
|
+
...s === void 0 ? {} : { clockSkewMs: s },
|
|
717
|
+
unrecognizedReasonCode: c,
|
|
718
|
+
unreadSupersededDeltaCrls: l
|
|
719
|
+
}, f, u);
|
|
720
|
+
if (p.kind === "unsettled") return p.reason === "retry_limit" ? { kind: "retry_limit" } : { kind: "delta_unusable" };
|
|
721
|
+
let h = p.result;
|
|
722
|
+
return h.ok ? {
|
|
658
723
|
kind: "checked",
|
|
659
|
-
checked:
|
|
660
|
-
crlThisUpdate:
|
|
661
|
-
} : { kind: "unusable_base" };
|
|
662
|
-
}
|
|
663
|
-
function isNewerDeltaCrl(e, t) {
|
|
664
|
-
let n = e.thisUpdate.getTime(), r = t.thisUpdate.getTime();
|
|
665
|
-
return n === r ? (e.crlNumber ?? 0n) > (t.crlNumber ?? 0n) : n > r;
|
|
724
|
+
checked: h,
|
|
725
|
+
crlThisUpdate: p.deltaCrl === void 0 ? n.thisUpdate : laterEvidenceDate(n.thisUpdate, p.deltaCrl.thisUpdate)
|
|
726
|
+
} : (h.code === "stale_crl" && (d.sawStaleCrl = !0), h.code === "reason_code_unrecognized" ? { kind: "reason_code_unrecognized" } : { kind: "unusable_base" });
|
|
666
727
|
}
|
|
667
728
|
/** The direct issuer first, then deduplicated indirect CRL-issuer candidates. */
|
|
668
|
-
function collectCrlSignerCandidates(e, t, n, r) {
|
|
669
|
-
let
|
|
670
|
-
|
|
671
|
-
|
|
729
|
+
function collectCrlSignerCandidates(e, t, n, r, a) {
|
|
730
|
+
let o = [t], push = (e) => {
|
|
731
|
+
o.some((t) => sameIssuer(t, e)) || o.push(e);
|
|
732
|
+
};
|
|
733
|
+
for (let t of findIndirectCrlIssuers(e, n, r)) push(issuerOf(t, a));
|
|
734
|
+
return a !== void 0 && i(e.issuer, a.subject) && push({
|
|
735
|
+
kind: "trust_anchor",
|
|
736
|
+
trustAnchor: a
|
|
737
|
+
}), o;
|
|
672
738
|
}
|
|
673
739
|
function recordGoodCrlEvidence(e, t, n, r) {
|
|
674
740
|
e.sawGood = !0, (e.freshestGood === void 0 || n.getTime() > e.freshestGood.thisUpdate.getTime()) && (e.freshestGood = {
|
|
@@ -678,7 +744,7 @@ function recordGoodCrlEvidence(e, t, n, r) {
|
|
|
678
744
|
for (let t of r) e.coveredReasons.add(t);
|
|
679
745
|
}
|
|
680
746
|
/** Indeterminate reasons that keep other evidence from settling the status as `good`. */
|
|
681
|
-
const
|
|
747
|
+
const j = /* @__PURE__ */ new Set([
|
|
682
748
|
"delta_crl_unusable",
|
|
683
749
|
"delta_crl_retry_limit_exceeded",
|
|
684
750
|
"crl_reason_code_unrecognized",
|
|
@@ -698,12 +764,12 @@ const C = /* @__PURE__ */ new Set([
|
|
|
698
764
|
* are merged.
|
|
699
765
|
*/
|
|
700
766
|
async function evaluateCertificateRevocation(e, t, n, r, i) {
|
|
701
|
-
let a = n.policy?.prefer ?? "best-available", o = await evaluateOcspEvidence(e, t, n), s = await evaluateCrlEvidence(e, t, n, r, i), c = [...o.executionErrors, ...s.executionErrors], l = a === "crl" ? [s, o] : a === "ocsp" ? [o, s] : [o, s].sort((e, t) => (t.status.source?.thisUpdate?.getTime() ?? 0) - (e.status.source?.thisUpdate?.getTime() ?? 0)), u = l.find((e) => e.status.status === "revoked");
|
|
767
|
+
let a = n.policy?.prefer ?? "best-available", o = await evaluateOcspEvidence(e, t, n, r), s = await evaluateCrlEvidence(e, t, n, r, i), c = [...o.executionErrors, ...s.executionErrors], l = a === "crl" ? [s, o] : a === "ocsp" ? [o, s] : [o, s].sort((e, t) => (t.status.source?.thisUpdate?.getTime() ?? 0) - (e.status.source?.thisUpdate?.getTime() ?? 0)), u = l.find((e) => e.status.status === "revoked");
|
|
702
768
|
if (u !== void 0) return {
|
|
703
769
|
status: u.status,
|
|
704
770
|
executionErrors: c
|
|
705
771
|
};
|
|
706
|
-
let d = l.find((e) => e.status.status === "good"), f = [s, o].some((e) => e.status.indeterminateReasons?.some((e) =>
|
|
772
|
+
let d = l.find((e) => e.status.status === "good"), f = [s, o].some((e) => e.status.indeterminateReasons?.some((e) => j.has(e)));
|
|
707
773
|
if (d !== void 0 && !f) return {
|
|
708
774
|
status: d.status,
|
|
709
775
|
executionErrors: c
|
|
@@ -720,19 +786,55 @@ async function evaluateCertificateRevocation(e, t, n, r, i) {
|
|
|
720
786
|
};
|
|
721
787
|
}
|
|
722
788
|
/**
|
|
789
|
+
* @throws RangeError when `trustAnchor` did not issue the last certificate of
|
|
790
|
+
* `chain`, or that certificate is the anchor's own.
|
|
791
|
+
*/
|
|
792
|
+
function assertIssuedByTrustAnchor(e, t) {
|
|
793
|
+
let n = e[e.length - 1];
|
|
794
|
+
if (t !== void 0 && n !== void 0) {
|
|
795
|
+
if (s(n, t)) throw RangeError("chain ends with the trust anchor certificate; omit it or trustAnchor");
|
|
796
|
+
if (!i(n.issuer, t.subject)) throw RangeError("trustAnchor does not name the issuer of the last chain certificate");
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
/** The issuer of `chain[index]`: the next chain certificate, or the bare anchor above the last. */
|
|
800
|
+
function issuerAt(e, t, n) {
|
|
801
|
+
let r = e[t + 1];
|
|
802
|
+
return r === void 0 ? n === void 0 ? void 0 : {
|
|
803
|
+
kind: "trust_anchor",
|
|
804
|
+
trustAnchor: n
|
|
805
|
+
} : {
|
|
806
|
+
kind: "certificate",
|
|
807
|
+
certificate: r
|
|
808
|
+
};
|
|
809
|
+
}
|
|
810
|
+
/**
|
|
811
|
+
* Each certificate of `chain` that has an issuer, with that issuer. Without
|
|
812
|
+
* `trustAnchor` the last certificate is the anchor and has none.
|
|
813
|
+
*/
|
|
814
|
+
function certificatesWithIssuers(e, t) {
|
|
815
|
+
return e.flatMap((n, r) => {
|
|
816
|
+
let i = issuerAt(e, r, t);
|
|
817
|
+
return i === void 0 ? [] : [{
|
|
818
|
+
cert: n,
|
|
819
|
+
issuer: i
|
|
820
|
+
}];
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
/**
|
|
723
824
|
* RFC 9608 §4: path validation skips RFC 5280 §6.1.3 step (a)(3) for a
|
|
724
825
|
* certificate carrying noRevAvail or id-pkix-ocsp-nocheck, read from its
|
|
725
826
|
* signed DER.
|
|
726
827
|
*/
|
|
727
828
|
function revocationSkipReason(e) {
|
|
728
|
-
let t =
|
|
729
|
-
|
|
829
|
+
let t = T(e.der);
|
|
830
|
+
return t.ok ? S(t.value) : void 0;
|
|
730
831
|
}
|
|
731
832
|
/**
|
|
732
833
|
* Checks revocation status for all certificates in a validated chain.
|
|
733
834
|
*
|
|
734
835
|
* Evaluates CRL and OCSP evidence against each certificate (except the trust
|
|
735
|
-
* anchor
|
|
836
|
+
* anchor at the end of `chain`; with `trustAnchor`, every certificate), applies
|
|
837
|
+
* the revocation policy, and returns a unified decision. A
|
|
736
838
|
* certificate carrying noRevAvail or id-pkix-ocsp-nocheck is reported as
|
|
737
839
|
* `skipped` without consulting evidence (RFC 9608 §4).
|
|
738
840
|
*
|
|
@@ -750,9 +852,46 @@ function revocationSkipReason(e) {
|
|
|
750
852
|
* ```
|
|
751
853
|
*/
|
|
752
854
|
async function checkChainRevocation(e) {
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
855
|
+
return await checkChainRevocationAt({
|
|
856
|
+
...e,
|
|
857
|
+
at: e.at ?? /* @__PURE__ */ new Date()
|
|
858
|
+
});
|
|
859
|
+
}
|
|
860
|
+
/**
|
|
861
|
+
* The signer validation state shared by every certificate check of one
|
|
862
|
+
* {@linkcode checkChainRevocation} call, with its delta CRL budget and the
|
|
863
|
+
* caller's distrust list as it stood when the call began.
|
|
864
|
+
*/
|
|
865
|
+
function signerValidationContext(e, t) {
|
|
866
|
+
let { chain: n, policy: r } = e, i = /* @__PURE__ */ new Map(), a = chainWorkingKeys(n, e.trustAnchor === void 0 ? void 0 : o(e.trustAnchor));
|
|
867
|
+
return {
|
|
868
|
+
cache: /* @__PURE__ */ new Map(),
|
|
869
|
+
chain: n,
|
|
870
|
+
crls: e.crls ?? [],
|
|
871
|
+
extraCertificates: e.extraCertificates ?? [],
|
|
872
|
+
at: e.at,
|
|
873
|
+
crlMaxAgeMs: r?.crlMaxAgeMs,
|
|
874
|
+
clockSkewMs: r?.clockSkewMs,
|
|
875
|
+
unrecognizedReasonCode: r?.unrecognizedReasonCode ?? "revoked",
|
|
876
|
+
crlSignerSelfEvidence: r?.crlSignerSelfEvidence ?? "delegated",
|
|
877
|
+
unreadSupersededDeltaCrls: r?.unreadSupersededDeltaCrls ?? "indeterminate",
|
|
878
|
+
signatureVerifiers: e.signatureVerifiers,
|
|
879
|
+
distrustedSpkiSha256: e.distrustedSpkiSha256 === void 0 ? void 0 : [...e.distrustedSpkiSha256],
|
|
880
|
+
verifiers: t,
|
|
881
|
+
deltaBudget: { remaining: 32 },
|
|
882
|
+
workingKeyOf: (e) => i.get(certCacheKey(e)) ?? a(e),
|
|
883
|
+
pathKeys: i,
|
|
884
|
+
pathIssuers: /* @__PURE__ */ new Map(),
|
|
885
|
+
trustAnchor: e.trustAnchor
|
|
886
|
+
};
|
|
887
|
+
}
|
|
888
|
+
/** {@linkcode checkChainRevocation} with its evaluation time resolved once for every check. */
|
|
889
|
+
async function checkChainRevocationAt(e) {
|
|
890
|
+
let { chain: t, policy: n } = e;
|
|
891
|
+
f(n?.crlMaxAgeMs), d(n?.clockSkewMs);
|
|
892
|
+
let i = r(e.signatureVerifiers);
|
|
893
|
+
a(e.distrustedSpkiSha256), assertIssuedByTrustAnchor(t, e.trustAnchor);
|
|
894
|
+
let o = n?.mode ?? "hard-fail";
|
|
756
895
|
if (t.length === 0) return {
|
|
757
896
|
ok: !0,
|
|
758
897
|
value: {
|
|
@@ -764,45 +903,34 @@ async function checkChainRevocation(e) {
|
|
|
764
903
|
certificates: []
|
|
765
904
|
}
|
|
766
905
|
};
|
|
767
|
-
let c =
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
crlMaxAgeMs: n?.crlMaxAgeMs,
|
|
774
|
-
clockSkewMs: n?.clockSkewMs,
|
|
775
|
-
unrecognizedReasonCode: n?.unrecognizedReasonCode ?? "revoked"
|
|
776
|
-
}, l = { remaining: 32 }, u = t.slice(0, -1), d = [], f = [], p = [], m = [];
|
|
777
|
-
for (let n = 0; n < u.length; n++) {
|
|
778
|
-
let r = u[n], i = t[n + 1];
|
|
779
|
-
if (r === void 0 || i === void 0) continue;
|
|
780
|
-
let a = revocationSkipReason(r);
|
|
781
|
-
if (a !== void 0) {
|
|
782
|
-
d.push({
|
|
783
|
-
certificate: r,
|
|
906
|
+
let s = signerValidationContext(e, i), c = s.deltaBudget, l = [], u = [], p = [], m = [];
|
|
907
|
+
for (let { cert: n, issuer: r } of certificatesWithIssuers(t, e.trustAnchor)) {
|
|
908
|
+
let t = revocationSkipReason(n);
|
|
909
|
+
if (t !== void 0) {
|
|
910
|
+
l.push({
|
|
911
|
+
certificate: n,
|
|
784
912
|
status: "skipped",
|
|
785
|
-
skipReason:
|
|
913
|
+
skipReason: t
|
|
786
914
|
});
|
|
787
915
|
continue;
|
|
788
916
|
}
|
|
789
|
-
let { status:
|
|
790
|
-
|
|
917
|
+
let { status: i, executionErrors: a } = await evaluateCertificateRevocation(n, r, e, s, c);
|
|
918
|
+
l.push(i), m.push(...a), i.status === "revoked" ? u.push(n) : i.status === "indeterminate" && p.push(n);
|
|
791
919
|
}
|
|
792
|
-
let h =
|
|
920
|
+
let h = u.length > 0, g = p.length > 0;
|
|
793
921
|
return {
|
|
794
922
|
ok: !0,
|
|
795
923
|
value: {
|
|
796
|
-
decision: h || g &&
|
|
924
|
+
decision: h || g && o === "hard-fail" ? "deny" : "allow",
|
|
797
925
|
summary: {
|
|
798
|
-
revokedCertificates:
|
|
926
|
+
revokedCertificates: u,
|
|
799
927
|
indeterminateCertificates: p
|
|
800
928
|
},
|
|
801
|
-
certificates:
|
|
929
|
+
certificates: l,
|
|
802
930
|
...m.length > 0 ? { executionErrors: m } : {}
|
|
803
931
|
}
|
|
804
932
|
};
|
|
805
933
|
}
|
|
806
|
-
export {
|
|
934
|
+
export { D as REVOCATION_INDETERMINATE_REASONS, checkChainRevocation };
|
|
807
935
|
|
|
808
936
|
//# sourceMappingURL=chain.js.map
|