micro509 0.14.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2119 -0
- package/README.md +105 -225
- package/dist/crypto/crypto.d.ts +42 -11
- package/dist/crypto/crypto.js +53 -22
- package/dist/crypto/crypto.js.map +1 -1
- package/dist/crypto.d.ts +2 -2
- package/dist/crypto.js +1 -2
- package/dist/der/der.d.ts +41 -33
- package/dist/der/der.js +26 -24
- package/dist/der/der.js.map +1 -1
- package/dist/index.d.ts +11 -11
- package/dist/index.js +19 -19
- package/dist/internal/asn1/asn1.d.ts +3 -6
- package/dist/internal/asn1/asn1.js +343 -43
- package/dist/internal/asn1/asn1.js.map +1 -1
- package/dist/internal/asn1/ber.js +146 -0
- package/dist/internal/asn1/ber.js.map +1 -0
- package/dist/internal/asn1/decode-refusal.js +29 -0
- package/dist/internal/asn1/decode-refusal.js.map +1 -0
- package/dist/internal/asn1/der.d.ts +38 -41
- package/dist/internal/asn1/der.js +131 -52
- package/dist/internal/asn1/der.js.map +1 -1
- package/dist/internal/asn1/oids.js +83 -53
- package/dist/internal/asn1/oids.js.map +1 -1
- package/dist/internal/asn1/oids2.js +1 -2
- package/dist/internal/asn1/oids2.js.map +1 -1
- package/dist/internal/crypto/algorithm-names.js +1 -2
- package/dist/internal/crypto/algorithm-names.js.map +1 -1
- package/dist/internal/crypto/ecdsa.js +13 -8
- package/dist/internal/crypto/ecdsa.js.map +1 -1
- package/dist/internal/crypto/hash.js +1 -2
- package/dist/internal/crypto/hash.js.map +1 -1
- package/dist/internal/crypto/pbes2.d.ts +24 -11
- package/dist/internal/crypto/pbes2.js +79 -26
- package/dist/internal/crypto/pbes2.js.map +1 -1
- package/dist/internal/crypto/rsa-pss.js +46 -44
- package/dist/internal/crypto/rsa-pss.js.map +1 -1
- package/dist/internal/crypto/sig-verify.d.ts +4 -7
- package/dist/internal/crypto/sig-verify.js +107 -60
- package/dist/internal/crypto/sig-verify.js.map +1 -1
- package/dist/internal/crypto/signing.d.ts +1 -4
- package/dist/internal/crypto/signing.js +28 -29
- package/dist/internal/crypto/signing.js.map +1 -1
- package/dist/internal/crypto/webcrypto.js +1 -2
- package/dist/internal/crypto/webcrypto.js.map +1 -1
- package/dist/internal/shared/base64.js +1 -2
- package/dist/internal/shared/base64.js.map +1 -1
- package/dist/internal/shared/dn.d.ts +3 -6
- package/dist/internal/shared/dn.js +99 -53
- package/dist/internal/shared/dn.js.map +1 -1
- package/dist/internal/shared/idna-tables.js +7217 -0
- package/dist/internal/shared/idna-tables.js.map +1 -0
- package/dist/internal/shared/idna.js +296 -0
- package/dist/internal/shared/idna.js.map +1 -0
- package/dist/internal/shared/ip.d.ts +4 -7
- package/dist/internal/shared/ip.js +1 -2
- package/dist/internal/shared/ip.js.map +1 -1
- package/dist/internal/shared/mailbox.js +26 -0
- package/dist/internal/shared/mailbox.js.map +1 -0
- package/dist/internal/shared/punycode.js +101 -0
- package/dist/internal/shared/punycode.js.map +1 -0
- package/dist/internal/shared/rfc3454-tables.js +1 -2
- package/dist/internal/shared/rfc3454-tables.js.map +1 -1
- package/dist/internal/shared/rfc4518-tables.js +119 -0
- package/dist/internal/shared/rfc4518-tables.js.map +1 -0
- package/dist/internal/shared/uri-host.js +102 -0
- package/dist/internal/shared/uri-host.js.map +1 -0
- package/dist/internal/verify/name-constraints-engine.js +246 -131
- package/dist/internal/verify/name-constraints-engine.js.map +1 -1
- package/dist/internal/verify/policy-engine.js +6 -21
- package/dist/internal/verify/policy-engine.js.map +1 -1
- package/dist/internal/verify/spki-distrust.js +23 -0
- package/dist/internal/verify/spki-distrust.js.map +1 -0
- package/dist/internal/verify/verify-path.d.ts +1 -4
- package/dist/internal/verify/verify-path.js +282 -129
- package/dist/internal/verify/verify-path.js.map +1 -1
- package/dist/internal/x509/directory-name.js +1 -2
- package/dist/internal/x509/directory-name.js.map +1 -1
- package/dist/internal/x509/extension-bits.js +2 -3
- package/dist/internal/x509/extension-bits.js.map +1 -1
- package/dist/internal/x509/extension-errors.d.ts +1 -4
- package/dist/internal/x509/extension-errors.js +1 -2
- package/dist/internal/x509/extension-errors.js.map +1 -1
- package/dist/internal/x509/extension-registry.js +107 -89
- package/dist/internal/x509/extension-registry.js.map +1 -1
- package/dist/internal/x509/general-name-profile.js +129 -0
- package/dist/internal/x509/general-name-profile.js.map +1 -0
- package/dist/internal/x509/general-name-tags.js +1 -2
- package/dist/internal/x509/general-name-tags.js.map +1 -1
- package/dist/internal/x509/general-name.js +128 -42
- package/dist/internal/x509/general-name.js.map +1 -1
- package/dist/internal/x509/name-fields.js +1 -2
- package/dist/internal/x509/name-fields.js.map +1 -1
- package/dist/internal/x509/or-address.js +217 -0
- package/dist/internal/x509/or-address.js.map +1 -0
- package/dist/keys/keys.d.ts +122 -104
- package/dist/keys/keys.js +211 -204
- package/dist/keys/keys.js.map +1 -1
- package/dist/keys.d.ts +3 -3
- package/dist/pem/pem.d.ts +14 -17
- package/dist/pem/pem.js +16 -17
- package/dist/pem/pem.js.map +1 -1
- package/dist/pem.js +1 -2
- package/dist/pkcs/pfx.d.ts +57 -32
- package/dist/pkcs/pfx.js +209 -173
- package/dist/pkcs/pfx.js.map +1 -1
- package/dist/pkcs/pkcs12-mac.d.ts +104 -27
- package/dist/pkcs/pkcs12-mac.js +266 -79
- package/dist/pkcs/pkcs12-mac.js.map +1 -1
- package/dist/pkcs/pkcs7.d.ts +43 -37
- package/dist/pkcs/pkcs7.js +218 -217
- package/dist/pkcs/pkcs7.js.map +1 -1
- package/dist/pkcs.d.ts +4 -3
- package/dist/result/result.d.ts +27 -20
- package/dist/result/result.js +8 -3
- package/dist/result/result.js.map +1 -1
- package/dist/result.d.ts +2 -2
- package/dist/result.js +1 -2
- package/dist/revocation/chain.d.ts +101 -23
- package/dist/revocation/chain.js +436 -182
- package/dist/revocation/chain.js.map +1 -1
- package/dist/revocation/crl.d.ts +131 -67
- package/dist/revocation/crl.js +443 -327
- package/dist/revocation/crl.js.map +1 -1
- package/dist/revocation/ocsp.d.ts +94 -59
- package/dist/revocation/ocsp.js +331 -293
- package/dist/revocation/ocsp.js.map +1 -1
- package/dist/revocation/revocation.d.ts +47 -35
- package/dist/revocation/revocation.js +88 -57
- package/dist/revocation/revocation.js.map +1 -1
- package/dist/revocation.d.ts +3 -3
- package/dist/verify/identity.d.ts +16 -19
- package/dist/verify/identity.js +118 -89
- package/dist/verify/identity.js.map +1 -1
- package/dist/verify/name-constraints.d.ts +1 -4
- package/dist/verify/policy.d.ts +9 -7
- package/dist/verify/verify.d.ts +115 -46
- package/dist/verify/verify.js +373 -183
- package/dist/verify/verify.js.map +1 -1
- package/dist/verify.d.ts +2 -2
- package/dist/x509/certificate.d.ts +20 -21
- package/dist/x509/certificate.js +62 -46
- package/dist/x509/certificate.js.map +1 -1
- package/dist/x509/csr.d.ts +5 -7
- package/dist/x509/csr.js +10 -11
- package/dist/x509/csr.js.map +1 -1
- package/dist/x509/extensions.d.ts +154 -66
- package/dist/x509/extensions.js +317 -151
- package/dist/x509/extensions.js.map +1 -1
- package/dist/x509/fingerprint.d.ts +15 -7
- package/dist/x509/fingerprint.js +20 -3
- package/dist/x509/fingerprint.js.map +1 -1
- package/dist/x509/name-text.d.ts +7 -9
- package/dist/x509/name-text.js +18 -4
- package/dist/x509/name-text.js.map +1 -1
- package/dist/x509/name.d.ts +9 -11
- package/dist/x509/name.js +18 -19
- package/dist/x509/name.js.map +1 -1
- package/dist/x509/parse.d.ts +84 -69
- package/dist/x509/parse.js +421 -400
- package/dist/x509/parse.js.map +1 -1
- package/dist/x509.d.ts +3 -3
- package/dist/x509.js +3 -3
- package/package.json +76 -59
package/dist/revocation/chain.js
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
import { DECODE_REFUSAL_CODES as e } from "../result/result.js";
|
|
2
|
+
import { decodeRefusalOf as t } from "../internal/asn1/decode-refusal.js";
|
|
3
|
+
import { toHex as n } from "../internal/asn1/asn1.js";
|
|
4
|
+
import { parseCertificateDer as r, parseCertificateFromSource as i } from "../x509/parse.js";
|
|
5
|
+
import { assertCrlMaxAge as a, authenticateCrl as o, checkCertificateRevocationAgainstCrl as s, checkRevocationAgainstAuthenticatedCrl as c, coversAllDistributionPointReasons as l, isCrlApplicableTo as u, isCurrentDeltaCrl as d, normalizeCrl as f, revocationReasonFromCode as p } from "./crl.js";
|
|
6
|
+
import { verifyCertificateChain as m } from "../verify/verify.js";
|
|
7
|
+
import { carriesOcspNoCheck as h, parseOcspResponseDerOrThrow as g, parseOcspResponsePemOrThrow as _, validateOcspResponse as v } from "./ocsp.js";
|
|
8
|
+
// src/revocation/chain.ts
|
|
9
|
+
/**
|
|
10
|
+
* Chain-level revocation orchestration.
|
|
11
|
+
*
|
|
12
|
+
* Evaluates CRL and OCSP evidence for an entire validated certificate chain,
|
|
13
|
+
* implementing the revocation checking portion of RFC 5280 §6.3.
|
|
14
|
+
*
|
|
15
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc5280#section-6.3 | RFC 5280 §6.3 CRL Validation}
|
|
16
|
+
* @module
|
|
17
|
+
*/
|
|
6
18
|
/**
|
|
7
19
|
* Granular reasons why revocation status could not be determined.
|
|
8
20
|
*
|
|
@@ -14,9 +26,18 @@ import { parseOcspResponseDerOrThrow as s, parseOcspResponsePemOrThrow as c, val
|
|
|
14
26
|
* `reason_scope_mismatch`, `indirect_crl_scope_mismatch`, `reason_coverage_incomplete`
|
|
15
27
|
* - **Signer trust**: `crl_signer_not_found`, `crl_signer_not_authorized`,
|
|
16
28
|
* `crl_signer_revoked`, `crl_signer_indeterminate`, and OCSP equivalents
|
|
17
|
-
* - **Freshness**: `crl_expired`, `ocsp_response_expired
|
|
29
|
+
* - **Freshness**: `crl_expired`, `ocsp_response_expired`,
|
|
30
|
+
* `ocsp_next_update_missing`
|
|
31
|
+
* - **Delta CRL**: `delta_crl_unusable` when an authenticated, current delta
|
|
32
|
+
* CRL cannot settle the status, `delta_crl_retry_limit_exceeded` when delta
|
|
33
|
+
* CRL candidates remain after the attempt limit. Either one outranks a
|
|
34
|
+
* `good` verdict from other evidence.
|
|
35
|
+
* - **Reason code**: `crl_reason_code_unrecognized` and
|
|
36
|
+
* `ocsp_reason_code_unrecognized` when evidence revokes the certificate with
|
|
37
|
+
* an unrecognized CRLReason under `unrecognizedReasonCode: 'reject'`. Either
|
|
38
|
+
* one outranks a `good` verdict from other evidence.
|
|
18
39
|
*/
|
|
19
|
-
const
|
|
40
|
+
const y = [
|
|
20
41
|
"no_applicable_crl",
|
|
21
42
|
"no_applicable_ocsp",
|
|
22
43
|
"distribution_point_mismatch",
|
|
@@ -34,20 +55,19 @@ const u = [
|
|
|
34
55
|
"ocsp_responder_indeterminate",
|
|
35
56
|
"crl_expired",
|
|
36
57
|
"ocsp_response_expired",
|
|
37
|
-
"
|
|
58
|
+
"ocsp_next_update_missing",
|
|
59
|
+
"ocsp_status_unknown",
|
|
60
|
+
"delta_crl_unusable",
|
|
61
|
+
"delta_crl_retry_limit_exceeded",
|
|
62
|
+
"crl_reason_code_unrecognized",
|
|
63
|
+
"ocsp_reason_code_unrecognized"
|
|
38
64
|
];
|
|
39
65
|
/**
|
|
40
|
-
* Parses a CRL from various source formats.
|
|
41
|
-
*/
|
|
42
|
-
function parseCrlFromSource(e) {
|
|
43
|
-
return typeof e == "object" && "issuer" in e ? e : typeof e == "string" ? i(e) : r(e);
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
66
|
* Parses a certificate from various source formats, returning undefined on failure.
|
|
47
67
|
*/
|
|
48
|
-
function parseCertificateSafe(
|
|
68
|
+
function parseCertificateSafe(e) {
|
|
49
69
|
try {
|
|
50
|
-
return e
|
|
70
|
+
return i(e);
|
|
51
71
|
} catch {
|
|
52
72
|
return;
|
|
53
73
|
}
|
|
@@ -105,7 +125,7 @@ async function crlSignerChainsToAnchor(e, t, n, r) {
|
|
|
105
125
|
let t = parseCertificateSafe(e);
|
|
106
126
|
t !== void 0 && addCandidate(t);
|
|
107
127
|
}
|
|
108
|
-
return (await
|
|
128
|
+
return (await m({
|
|
109
129
|
leaf: e.der,
|
|
110
130
|
intermediates: a.map((e) => e.der),
|
|
111
131
|
roots: [i.der],
|
|
@@ -152,16 +172,17 @@ function findSignerIssuer(e, t) {
|
|
|
152
172
|
* Checks if a CRL signer certificate is revoked by examining available CRLs.
|
|
153
173
|
* Recursively validates the CRL signer of any CRL used to check revocation.
|
|
154
174
|
*/
|
|
155
|
-
async function checkSignerRevocation(e, t,
|
|
156
|
-
let
|
|
157
|
-
for (let
|
|
158
|
-
let
|
|
159
|
-
if (
|
|
160
|
-
|
|
175
|
+
async function checkSignerRevocation(e, t, n) {
|
|
176
|
+
let r = n.chain.some((e) => sameCertificate(e, t)), i = /* @__PURE__ */ new Set(), a = !1;
|
|
177
|
+
for (let r of n.crls) {
|
|
178
|
+
let o = await checkSignerAgainstCrl(e, t, r, n);
|
|
179
|
+
if (o.kind === "revoked") return "resolved-revoked";
|
|
180
|
+
if (o.kind === "unrecognized_reason") a = !0;
|
|
181
|
+
else for (let e of o.reasons) i.add(e);
|
|
161
182
|
}
|
|
162
|
-
return
|
|
183
|
+
return a ? "resolved-indeterminate" : l(i) || r ? "resolved-valid" : "resolved-indeterminate";
|
|
163
184
|
}
|
|
164
|
-
const
|
|
185
|
+
const b = {
|
|
165
186
|
kind: "reasons",
|
|
166
187
|
reasons: []
|
|
167
188
|
};
|
|
@@ -170,23 +191,26 @@ const d = {
|
|
|
170
191
|
* apply, or is itself signed by a signer that is not known good yields no
|
|
171
192
|
* evidence rather than a verdict.
|
|
172
193
|
*/
|
|
173
|
-
async function checkSignerAgainstCrl(e, n, r
|
|
174
|
-
let
|
|
194
|
+
async function checkSignerAgainstCrl(e, t, n, r) {
|
|
195
|
+
let i;
|
|
175
196
|
try {
|
|
176
|
-
|
|
197
|
+
i = f(n);
|
|
177
198
|
} catch {
|
|
178
|
-
return
|
|
199
|
+
return b;
|
|
179
200
|
}
|
|
180
|
-
let
|
|
201
|
+
let a = await s({
|
|
181
202
|
certificate: e,
|
|
182
|
-
issuerCertificate:
|
|
183
|
-
crl:
|
|
184
|
-
at:
|
|
203
|
+
issuerCertificate: t,
|
|
204
|
+
crl: i,
|
|
205
|
+
at: r.at,
|
|
206
|
+
...r.crlMaxAgeMs === void 0 ? {} : { maxAgeMs: r.crlMaxAgeMs },
|
|
207
|
+
...r.clockSkewMs === void 0 ? {} : { clockSkewMs: r.clockSkewMs },
|
|
208
|
+
unrecognizedReasonCode: r.unrecognizedReasonCode
|
|
185
209
|
});
|
|
186
|
-
return
|
|
210
|
+
return a.ok ? a.value.status === "revoked" ? { kind: "revoked" } : await validateCrlSigner(t, r) === "resolved-valid" ? {
|
|
187
211
|
kind: "reasons",
|
|
188
|
-
reasons:
|
|
189
|
-
} :
|
|
212
|
+
reasons: a.value.coveredReasons
|
|
213
|
+
} : b : a.code === "reason_code_unrecognized" ? { kind: "unrecognized_reason" } : b;
|
|
190
214
|
}
|
|
191
215
|
/** Builds the `revoked` CertificateRevocationStatus for a CRL hit. */
|
|
192
216
|
function buildCrlRevokedStatus(e, t, n, r, i) {
|
|
@@ -206,18 +230,107 @@ function buildCrlRevokedStatus(e, t, n, r, i) {
|
|
|
206
230
|
}
|
|
207
231
|
/** Parses an OCSP response from PEM string or DER bytes. */
|
|
208
232
|
function parseOcspResponseFromSource(e) {
|
|
209
|
-
return typeof e == "string" ?
|
|
233
|
+
return typeof e == "string" ? _(e) : g(e);
|
|
234
|
+
}
|
|
235
|
+
function evidenceParseError(n, r) {
|
|
236
|
+
return {
|
|
237
|
+
kind: "parse_error",
|
|
238
|
+
code: t(n, e)?.code ?? "malformed",
|
|
239
|
+
message: n instanceof Error ? n.message : r
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
/** Parses one OCSP source and locates the entry for the certificate under evaluation. */
|
|
243
|
+
function findApplicableOcspResponse(e, t) {
|
|
244
|
+
let n;
|
|
245
|
+
try {
|
|
246
|
+
n = parseOcspResponseFromSource(e);
|
|
247
|
+
} catch (e) {
|
|
248
|
+
return {
|
|
249
|
+
kind: "parse_error",
|
|
250
|
+
error: evidenceParseError(e, "OCSP response parse failed")
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
let r = (n.responses ?? []).find((e) => normalizeHex(e.certId.serialNumberHex) === normalizeHex(t.serialNumberHex));
|
|
254
|
+
return r === void 0 ? { kind: "not_applicable" } : {
|
|
255
|
+
kind: "applicable",
|
|
256
|
+
parsed: n,
|
|
257
|
+
entry: r
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
/** Returns the later of two evidence timestamps, tolerating an empty accumulator. */
|
|
261
|
+
function laterEvidenceDate(e, t) {
|
|
262
|
+
return e === void 0 || t.getTime() > e.getTime() ? t : e;
|
|
263
|
+
}
|
|
264
|
+
/** Builds a definitive OCSP-revoked status from a validated response entry. */
|
|
265
|
+
function buildOcspRevokedStatus(e, t, n, r) {
|
|
266
|
+
return {
|
|
267
|
+
certificate: e,
|
|
268
|
+
status: "revoked",
|
|
269
|
+
source: {
|
|
270
|
+
kind: "ocsp",
|
|
271
|
+
thisUpdate: t
|
|
272
|
+
},
|
|
273
|
+
revocationInfo: {
|
|
274
|
+
revocationDate: n,
|
|
275
|
+
...r === void 0 ? {} : { reason: r }
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
/** Classifies one fully validated OCSP entry for aggregation. */
|
|
280
|
+
function classifyValidatedOcspEntry(e, t, n) {
|
|
281
|
+
if (t.certStatus === "good") return {
|
|
282
|
+
kind: "good",
|
|
283
|
+
thisUpdate: t.thisUpdate
|
|
284
|
+
};
|
|
285
|
+
if (t.certStatus === "unknown") return { kind: "unknown" };
|
|
286
|
+
let r = p(t.revocationReasonCode);
|
|
287
|
+
if (n === "reject" && typeof r == "object") return { kind: "unrecognized_reason" };
|
|
288
|
+
let i = buildOcspRevokedStatus(e, t.thisUpdate, t.revokedAt, r);
|
|
289
|
+
return r === "certificateHold" ? {
|
|
290
|
+
kind: "hold",
|
|
291
|
+
evidence: {
|
|
292
|
+
status: i,
|
|
293
|
+
thisUpdate: t.thisUpdate
|
|
294
|
+
}
|
|
295
|
+
} : {
|
|
296
|
+
kind: "revoked",
|
|
297
|
+
status: i
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
/** Builds the definitive OCSP-good result or the accumulated indeterminate result. */
|
|
301
|
+
function finalizeOcspEvidence(e, t, n, r) {
|
|
302
|
+
return t === void 0 ? (n.size === 0 && n.add("no_applicable_ocsp"), {
|
|
303
|
+
status: {
|
|
304
|
+
certificate: e,
|
|
305
|
+
status: "indeterminate",
|
|
306
|
+
indeterminateReasons: [...n]
|
|
307
|
+
},
|
|
308
|
+
executionErrors: r
|
|
309
|
+
}) : {
|
|
310
|
+
status: {
|
|
311
|
+
certificate: e,
|
|
312
|
+
status: "good",
|
|
313
|
+
source: {
|
|
314
|
+
kind: "ocsp",
|
|
315
|
+
thisUpdate: t
|
|
316
|
+
}
|
|
317
|
+
},
|
|
318
|
+
executionErrors: r
|
|
319
|
+
};
|
|
210
320
|
}
|
|
211
321
|
/** Maps a {@linkcode validateOcspResponse} failure code to an indeterminate reason. */
|
|
212
322
|
function ocspIndeterminateReasonFromFailure(e) {
|
|
213
323
|
switch (e) {
|
|
214
324
|
case "stale_response": return "ocsp_response_expired";
|
|
325
|
+
case "next_update_missing": return "ocsp_next_update_missing";
|
|
215
326
|
case "responder_id_mismatch":
|
|
216
327
|
case "responder_chain_invalid":
|
|
217
328
|
case "ocsp_signing_missing": return "ocsp_responder_not_authorized";
|
|
218
329
|
case "responder_revoked": return "ocsp_responder_revoked";
|
|
219
330
|
case "signature_invalid":
|
|
220
|
-
case "responder_revocation_unknown":
|
|
331
|
+
case "responder_revocation_unknown":
|
|
332
|
+
case "unsupported":
|
|
333
|
+
case "limit_exceeded": return "ocsp_responder_indeterminate";
|
|
221
334
|
case "response_status_invalid":
|
|
222
335
|
case "issuer_mismatch":
|
|
223
336
|
case "nonce_mismatch":
|
|
@@ -226,39 +339,48 @@ function ocspIndeterminateReasonFromFailure(e) {
|
|
|
226
339
|
}
|
|
227
340
|
}
|
|
228
341
|
/** Validation failures worth retrying with an explicit responder certificate. */
|
|
229
|
-
const
|
|
342
|
+
const x = /* @__PURE__ */ new Set([
|
|
230
343
|
"signature_invalid",
|
|
231
344
|
"responder_id_mismatch",
|
|
232
345
|
"responder_chain_invalid",
|
|
233
|
-
"ocsp_signing_missing"
|
|
346
|
+
"ocsp_signing_missing",
|
|
347
|
+
"unsupported",
|
|
348
|
+
"limit_exceeded"
|
|
234
349
|
]);
|
|
235
350
|
/**
|
|
236
351
|
* Validates an OCSP response, retrying with caller-provided extra certificates
|
|
237
352
|
* as explicit responder certificates when embedded discovery fails.
|
|
238
353
|
*/
|
|
239
354
|
async function validateOcspResponseWithResponderFallback(e, t, n, r) {
|
|
240
|
-
let i = {
|
|
355
|
+
let i = n.trustedOcspResponders?.filter((e) => {
|
|
356
|
+
let n = parseCertificateSafe(e.issuerCertificate);
|
|
357
|
+
return n !== void 0 && sameCertificate(n, t);
|
|
358
|
+
}).map((e) => e.responderCertificate), a = {
|
|
241
359
|
issuerCertificate: t,
|
|
242
360
|
at: r,
|
|
243
|
-
...
|
|
361
|
+
...i === void 0 ? {} : { trustedOcspResponders: i },
|
|
244
362
|
...n.policy?.ocspResponderRevocation === void 0 ? {} : { responderRevocationPolicy: n.policy.ocspResponderRevocation },
|
|
245
|
-
...n.crls === void 0 ? {} : { responderRevocationCrls: n.crls }
|
|
246
|
-
|
|
363
|
+
...n.crls === void 0 ? {} : { responderRevocationCrls: n.crls },
|
|
364
|
+
...n.policy?.crlMaxAgeMs === void 0 ? {} : { responderRevocationCrlMaxAgeMs: n.policy.crlMaxAgeMs },
|
|
365
|
+
...n.policy?.clockSkewMs === void 0 ? {} : { clockSkewMs: n.policy.clockSkewMs },
|
|
366
|
+
...n.policy?.ocspProfile === void 0 ? {} : { profile: n.policy.ocspProfile },
|
|
367
|
+
...n.policy?.unrecognizedReasonCode === void 0 ? {} : { responderRevocationUnrecognizedReasonCode: n.policy.unrecognizedReasonCode }
|
|
368
|
+
}, o = await v({
|
|
247
369
|
response: e,
|
|
248
|
-
...
|
|
370
|
+
...a
|
|
249
371
|
});
|
|
250
|
-
if (
|
|
372
|
+
if (o.ok || !x.has(o.code)) return o;
|
|
251
373
|
for (let t of n.extraCertificates ?? []) {
|
|
252
374
|
let n = parseCertificateSafe(t);
|
|
253
375
|
if (n === void 0) continue;
|
|
254
|
-
let r = await
|
|
376
|
+
let r = await v({
|
|
255
377
|
response: e,
|
|
256
|
-
...
|
|
378
|
+
...a,
|
|
257
379
|
responderCertificate: n
|
|
258
380
|
});
|
|
259
381
|
if (r.ok) return r;
|
|
260
382
|
}
|
|
261
|
-
return
|
|
383
|
+
return o;
|
|
262
384
|
}
|
|
263
385
|
/**
|
|
264
386
|
* Evaluates OCSP evidence for a single certificate (RFC 6960).
|
|
@@ -270,64 +392,42 @@ async function validateOcspResponseWithResponderFallback(e, t, n, r) {
|
|
|
270
392
|
* sufficient to attribute the entry to `cert`.
|
|
271
393
|
*/
|
|
272
394
|
async function evaluateOcspEvidence(e, t, n) {
|
|
273
|
-
let { ocspResponses: r = [], at: i = /* @__PURE__ */ new Date() } = n,
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
message: e instanceof Error ? e.message : "OCSP response parse failed"
|
|
282
|
-
});
|
|
395
|
+
let { ocspResponses: r = [], at: i = /* @__PURE__ */ new Date() } = n, a = [], o = {
|
|
396
|
+
reasons: /* @__PURE__ */ new Set(),
|
|
397
|
+
sawUnrecognizedReason: !1
|
|
398
|
+
};
|
|
399
|
+
for (let s of r) {
|
|
400
|
+
let r = findApplicableOcspResponse(s, e);
|
|
401
|
+
if (r.kind === "parse_error") {
|
|
402
|
+
a.push(r.error);
|
|
283
403
|
continue;
|
|
284
404
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
s.add(ocspIndeterminateReasonFromFailure(u.code));
|
|
405
|
+
if (r.kind === "not_applicable") continue;
|
|
406
|
+
let c = await validateOcspResponseWithResponderFallback(r.parsed, t, n, i);
|
|
407
|
+
if (!c.ok) {
|
|
408
|
+
o.reasons.add(ocspIndeterminateReasonFromFailure(c.code));
|
|
290
409
|
continue;
|
|
291
410
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
certificate: e,
|
|
297
|
-
status: "revoked",
|
|
298
|
-
source: {
|
|
299
|
-
kind: "ocsp",
|
|
300
|
-
thisUpdate: l.thisUpdate
|
|
301
|
-
},
|
|
302
|
-
revocationInfo: {
|
|
303
|
-
revocationDate: l.revokedAt ?? l.thisUpdate,
|
|
304
|
-
...t === void 0 ? {} : { reason: t }
|
|
305
|
-
}
|
|
306
|
-
},
|
|
307
|
-
executionErrors: o
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
|
-
if (l.certStatus === "good") return {
|
|
311
|
-
status: {
|
|
312
|
-
certificate: e,
|
|
313
|
-
status: "good",
|
|
314
|
-
source: {
|
|
315
|
-
kind: "ocsp",
|
|
316
|
-
thisUpdate: l.thisUpdate
|
|
317
|
-
}
|
|
318
|
-
},
|
|
319
|
-
executionErrors: o
|
|
411
|
+
let l = classifyValidatedOcspEntry(e, r.entry, n.policy?.unrecognizedReasonCode ?? "revoked");
|
|
412
|
+
if (l.kind === "revoked") return {
|
|
413
|
+
status: l.status,
|
|
414
|
+
executionErrors: a
|
|
320
415
|
};
|
|
321
|
-
|
|
416
|
+
recordOcspEvidence(o, l);
|
|
322
417
|
}
|
|
323
|
-
return
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
418
|
+
return settleOcspEvidence(e, o, a);
|
|
419
|
+
}
|
|
420
|
+
function recordOcspEvidence(e, t) {
|
|
421
|
+
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");
|
|
422
|
+
}
|
|
423
|
+
/** The OCSP verdict once no response revoked the certificate outright. */
|
|
424
|
+
function settleOcspEvidence(e, t, n) {
|
|
425
|
+
if (t.sawUnrecognizedReason) return t.reasons.add("ocsp_reason_code_unrecognized"), finalizeOcspEvidence(e, void 0, t.reasons, n);
|
|
426
|
+
let { freshestGoodThisUpdate: r, freshestHold: i } = t;
|
|
427
|
+
return i !== void 0 && (r === void 0 || r.getTime() <= i.thisUpdate.getTime()) ? {
|
|
428
|
+
status: i.status,
|
|
429
|
+
executionErrors: n
|
|
430
|
+
} : finalizeOcspEvidence(e, r, t.reasons, n);
|
|
331
431
|
}
|
|
332
432
|
/**
|
|
333
433
|
* Runs each candidate signer through the full pipeline for one base CRL:
|
|
@@ -338,101 +438,231 @@ async function evaluateOcspEvidence(e, t, n) {
|
|
|
338
438
|
* evidence into `state`.
|
|
339
439
|
*/
|
|
340
440
|
async function resolveBaseCrlAgainstSigners(e) {
|
|
341
|
-
let { cert: t, baseCrl: n,
|
|
342
|
-
for (let e of collectCrlSignerCandidates(n, a, o
|
|
343
|
-
let
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
441
|
+
let { cert: t, baseCrl: n, deltaCandidates: r, issuer: i, extraCertificates: a, chain: o, at: s, crlMaxAgeMs: c, clockSkewMs: l, unrecognizedReasonCode: u, signerCtx: d, deltaBudget: f, state: p } = e, m = { remaining: S };
|
|
442
|
+
for (let e of collectCrlSignerCandidates(n, i, a, o)) {
|
|
443
|
+
let i = await checkCrlAgainstDeltaCandidates({
|
|
444
|
+
cert: t,
|
|
445
|
+
baseCrl: n,
|
|
446
|
+
deltaCandidates: r,
|
|
447
|
+
candidate: e,
|
|
448
|
+
at: s,
|
|
449
|
+
crlMaxAgeMs: c,
|
|
450
|
+
clockSkewMs: l,
|
|
451
|
+
unrecognizedReasonCode: u,
|
|
452
|
+
budgets: [m, f],
|
|
453
|
+
state: p
|
|
454
|
+
});
|
|
455
|
+
if (i.kind === "unusable_base") continue;
|
|
456
|
+
if (!await crlSignerChainsToAnchor(e, o, a, s)) {
|
|
457
|
+
p.sawCrlSignerNotAuthorized = !0;
|
|
347
458
|
continue;
|
|
348
459
|
}
|
|
349
|
-
let
|
|
350
|
-
if (
|
|
351
|
-
|
|
460
|
+
let h = await validateCrlSigner(e, d);
|
|
461
|
+
if (h === "resolved-revoked") {
|
|
462
|
+
p.sawCrlSignerRevoked = !0;
|
|
352
463
|
continue;
|
|
353
464
|
}
|
|
354
|
-
if (
|
|
355
|
-
|
|
465
|
+
if (h === "resolved-indeterminate") {
|
|
466
|
+
p.sawCrlSignerIndeterminate = !0;
|
|
356
467
|
continue;
|
|
357
468
|
}
|
|
358
|
-
if (
|
|
359
|
-
|
|
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);
|
|
360
484
|
return;
|
|
361
485
|
}
|
|
362
486
|
}
|
|
363
|
-
async function evaluateCrlEvidence(e, t, r, i) {
|
|
364
|
-
let { crls: a = [], extraCertificates: o = [], chain: s = [], at: c = /* @__PURE__ */ new Date() } =
|
|
487
|
+
async function evaluateCrlEvidence(e, t, n, r, i) {
|
|
488
|
+
let { crls: a = [], extraCertificates: o = [], chain: s = [], at: c = /* @__PURE__ */ new Date() } = n, d = {
|
|
365
489
|
executionErrors: [],
|
|
366
490
|
coveredReasons: /* @__PURE__ */ new Set(),
|
|
367
491
|
sawCrlSignerRevoked: !1,
|
|
368
492
|
sawCrlSignerIndeterminate: !1,
|
|
369
493
|
sawCrlSignerNotAuthorized: !1,
|
|
494
|
+
sawStaleCrl: !1,
|
|
495
|
+
sawDeltaCrlUnusable: !1,
|
|
496
|
+
sawDeltaCrlRetryLimit: !1,
|
|
497
|
+
sawUnrecognizedReasonCode: !1,
|
|
370
498
|
sawGood: !1
|
|
371
|
-
},
|
|
372
|
-
for (let
|
|
373
|
-
let
|
|
499
|
+
}, f = parseCrlEvidenceSources(a, d.executionErrors), p = distinctSignedCrls(f.filter((t) => t.baseCrlNumber === void 0 && u(e, t))), m = distinctSignedCrls(f.filter((e) => e.baseCrlNumber !== void 0)), h = n.policy?.crlMaxAgeMs, g = n.policy?.clockSkewMs;
|
|
500
|
+
for (let a of p) {
|
|
501
|
+
let l = await resolveBaseCrlAgainstSigners({
|
|
374
502
|
cert: e,
|
|
375
|
-
baseCrl:
|
|
376
|
-
|
|
377
|
-
crlThisUpdate: r !== void 0 && r.thisUpdate.getTime() > n.thisUpdate.getTime() ? r.thisUpdate : n.thisUpdate,
|
|
503
|
+
baseCrl: a,
|
|
504
|
+
deltaCandidates: rankApplicableDeltaCrls(a, m, c, g ?? 0, h),
|
|
378
505
|
issuer: t,
|
|
379
506
|
extraCertificates: o,
|
|
380
507
|
chain: s,
|
|
381
508
|
at: c,
|
|
382
|
-
|
|
383
|
-
|
|
509
|
+
crlMaxAgeMs: h,
|
|
510
|
+
clockSkewMs: g,
|
|
511
|
+
unrecognizedReasonCode: n.policy?.unrecognizedReasonCode ?? "revoked",
|
|
512
|
+
signerCtx: r,
|
|
513
|
+
deltaBudget: i,
|
|
514
|
+
state: d
|
|
384
515
|
});
|
|
385
|
-
if (
|
|
386
|
-
status:
|
|
387
|
-
executionErrors:
|
|
516
|
+
if (l !== void 0) return {
|
|
517
|
+
status: l,
|
|
518
|
+
executionErrors: d.executionErrors
|
|
388
519
|
};
|
|
389
520
|
}
|
|
390
|
-
|
|
521
|
+
let _ = blockingCrlIndeterminateReasons(d);
|
|
522
|
+
return _.length > 0 ? {
|
|
523
|
+
status: {
|
|
524
|
+
certificate: e,
|
|
525
|
+
status: "indeterminate",
|
|
526
|
+
indeterminateReasons: _
|
|
527
|
+
},
|
|
528
|
+
executionErrors: d.executionErrors
|
|
529
|
+
} : d.sawGood && d.freshestGood !== void 0 ? l(d.coveredReasons) ? {
|
|
391
530
|
status: {
|
|
392
531
|
certificate: e,
|
|
393
532
|
status: "good",
|
|
394
533
|
source: {
|
|
395
534
|
kind: "crl",
|
|
396
|
-
signerCertificate:
|
|
397
|
-
thisUpdate:
|
|
535
|
+
signerCertificate: d.freshestGood.signer,
|
|
536
|
+
thisUpdate: d.freshestGood.thisUpdate
|
|
398
537
|
}
|
|
399
538
|
},
|
|
400
|
-
executionErrors:
|
|
539
|
+
executionErrors: d.executionErrors
|
|
401
540
|
} : {
|
|
402
541
|
status: {
|
|
403
542
|
certificate: e,
|
|
404
543
|
status: "indeterminate",
|
|
405
544
|
indeterminateReasons: ["reason_coverage_incomplete"]
|
|
406
545
|
},
|
|
407
|
-
executionErrors:
|
|
546
|
+
executionErrors: d.executionErrors
|
|
408
547
|
} : {
|
|
409
548
|
status: {
|
|
410
549
|
certificate: e,
|
|
411
550
|
status: "indeterminate",
|
|
412
|
-
indeterminateReasons: [crlUnavailableReason(
|
|
551
|
+
indeterminateReasons: [crlUnavailableReason(d)]
|
|
413
552
|
},
|
|
414
|
-
executionErrors:
|
|
553
|
+
executionErrors: d.executionErrors
|
|
415
554
|
};
|
|
416
555
|
}
|
|
556
|
+
/** CRL conditions that keep the status indeterminate despite `good` evidence. */
|
|
557
|
+
function blockingCrlIndeterminateReasons(e) {
|
|
558
|
+
return [
|
|
559
|
+
...e.sawDeltaCrlUnusable ? ["delta_crl_unusable"] : [],
|
|
560
|
+
...e.sawDeltaCrlRetryLimit ? ["delta_crl_retry_limit_exceeded"] : [],
|
|
561
|
+
...e.sawUnrecognizedReasonCode ? ["crl_reason_code_unrecognized"] : []
|
|
562
|
+
];
|
|
563
|
+
}
|
|
417
564
|
/** Most specific indeterminate reason when no CRL yielded a usable verdict. */
|
|
418
565
|
function crlUnavailableReason(e) {
|
|
419
|
-
return e.sawCrlSignerRevoked ? "crl_signer_revoked" : e.sawCrlSignerNotAuthorized ? "crl_signer_not_authorized" : e.sawCrlSignerIndeterminate ? "crl_signer_indeterminate" : "no_applicable_crl";
|
|
566
|
+
return e.sawCrlSignerRevoked ? "crl_signer_revoked" : e.sawCrlSignerNotAuthorized ? "crl_signer_not_authorized" : e.sawCrlSignerIndeterminate ? "crl_signer_indeterminate" : e.sawStaleCrl ? "crl_expired" : "no_applicable_crl";
|
|
420
567
|
}
|
|
421
568
|
/** Parses complete and delta CRL evidence while retaining source provenance. */
|
|
422
569
|
function parseCrlEvidenceSources(e, t) {
|
|
423
570
|
let n = [];
|
|
424
571
|
for (let r of e) try {
|
|
425
|
-
n.push(
|
|
572
|
+
n.push(f(r));
|
|
426
573
|
} catch (e) {
|
|
427
|
-
t.push(
|
|
428
|
-
kind: "parse_error",
|
|
429
|
-
message: e instanceof Error ? e.message : "CRL parse failed"
|
|
430
|
-
});
|
|
574
|
+
t.push(evidenceParseError(e, "CRL parse failed"));
|
|
431
575
|
}
|
|
432
576
|
return n;
|
|
433
577
|
}
|
|
434
|
-
|
|
435
|
-
|
|
578
|
+
/** `crls` without repeats of the same signed content and signature. */
|
|
579
|
+
function distinctSignedCrls(e) {
|
|
580
|
+
let t = /* @__PURE__ */ new Set();
|
|
581
|
+
return e.filter((e) => {
|
|
582
|
+
let r = [
|
|
583
|
+
e.signatureAlgorithmOid,
|
|
584
|
+
n(e.signatureAlgorithmParametersDer ?? /* @__PURE__ */ new Uint8Array()),
|
|
585
|
+
n(e.signatureValue),
|
|
586
|
+
n(e.tbsCertListDer)
|
|
587
|
+
].join(":");
|
|
588
|
+
return !t.has(r) && (t.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() && d(t, n, r, i)).sort((e, t) => isNewerDeltaCrl(e, t) ? -1 : +!!isNewerDeltaCrl(t, e));
|
|
595
|
+
}
|
|
596
|
+
const S = 4;
|
|
597
|
+
/**
|
|
598
|
+
* Authenticates `baseCrl` with `candidate` once, then checks it with each
|
|
599
|
+
* ranked delta CRL while the budgets last, and alone once every delta CRL is
|
|
600
|
+
* rejected. A delta CRL that passes authentication, freshness, compatibility
|
|
601
|
+
* and applicability ends the search.
|
|
602
|
+
*/
|
|
603
|
+
async function checkCrlAgainstDeltaCandidates(e) {
|
|
604
|
+
let { cert: t, baseCrl: n, deltaCandidates: r, candidate: i, at: a, crlMaxAgeMs: s, clockSkewMs: l, unrecognizedReasonCode: u, budgets: d, state: f } = e, p = await o(n, i);
|
|
605
|
+
if (!p.ok) return { kind: "unusable_base" };
|
|
606
|
+
let m = {
|
|
607
|
+
certificate: t,
|
|
608
|
+
issuerCertificate: i,
|
|
609
|
+
crl: p.value,
|
|
610
|
+
at: a,
|
|
611
|
+
...s === void 0 ? {} : { maxAgeMs: s },
|
|
612
|
+
...l === void 0 ? {} : { clockSkewMs: l },
|
|
613
|
+
unrecognizedReasonCode: u
|
|
614
|
+
};
|
|
615
|
+
for (let e of r) {
|
|
616
|
+
let r = takeDeltaCrlAttempt(d) ? settleAuthenticatedCrlOutcome(await c(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, a, n.thisUpdate) ?? r;
|
|
622
|
+
if (r.kind === "retry_limit") {
|
|
623
|
+
let e = await c(t, p.value, m);
|
|
624
|
+
return (e.kind === "checked" ? irremovableRevocation(t, e.result, a, n.thisUpdate) : void 0) ?? r;
|
|
625
|
+
}
|
|
626
|
+
return r;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
return settleAuthenticatedCrlOutcome(await c(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 ? {
|
|
658
|
+
kind: "checked",
|
|
659
|
+
checked: r,
|
|
660
|
+
crlThisUpdate: t
|
|
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;
|
|
436
666
|
}
|
|
437
667
|
/** The direct issuer first, then deduplicated indirect CRL-issuer candidates. */
|
|
438
668
|
function collectCrlSignerCandidates(e, t, n, r) {
|
|
@@ -440,15 +670,6 @@ function collectCrlSignerCandidates(e, t, n, r) {
|
|
|
440
670
|
for (let t of findIndirectCrlIssuers(e, n, r)) i.some((e) => sameCertificate(e, t)) || i.push(t);
|
|
441
671
|
return i;
|
|
442
672
|
}
|
|
443
|
-
function checkCrlWithIssuer(e, n, r, i, a) {
|
|
444
|
-
return t({
|
|
445
|
-
certificate: e,
|
|
446
|
-
issuerCertificate: i,
|
|
447
|
-
crl: n,
|
|
448
|
-
...r === void 0 ? {} : { deltaCrl: r },
|
|
449
|
-
at: a
|
|
450
|
-
});
|
|
451
|
-
}
|
|
452
673
|
function recordGoodCrlEvidence(e, t, n, r) {
|
|
453
674
|
e.sawGood = !0, (e.freshestGood === void 0 || n.getTime() > e.freshestGood.thisUpdate.getTime()) && (e.freshestGood = {
|
|
454
675
|
signer: t,
|
|
@@ -456,6 +677,13 @@ function recordGoodCrlEvidence(e, t, n, r) {
|
|
|
456
677
|
});
|
|
457
678
|
for (let t of r) e.coveredReasons.add(t);
|
|
458
679
|
}
|
|
680
|
+
/** Indeterminate reasons that keep other evidence from settling the status as `good`. */
|
|
681
|
+
const C = /* @__PURE__ */ new Set([
|
|
682
|
+
"delta_crl_unusable",
|
|
683
|
+
"delta_crl_retry_limit_exceeded",
|
|
684
|
+
"crl_reason_code_unrecognized",
|
|
685
|
+
"ocsp_reason_code_unrecognized"
|
|
686
|
+
]);
|
|
459
687
|
/**
|
|
460
688
|
* Evaluates revocation status for a single certificate by combining OCSP and
|
|
461
689
|
* CRL evidence.
|
|
@@ -464,36 +692,49 @@ function recordGoodCrlEvidence(e, t, n, r) {
|
|
|
464
692
|
* either source wins regardless of {@linkcode RevocationPolicy.prefer}
|
|
465
693
|
* (fail-closed). Otherwise the preferred source's `good` verdict is reported —
|
|
466
694
|
* for `'best-available'` the source with the later evidence `thisUpdate` wins,
|
|
467
|
-
* ties favoring OCSP.
|
|
468
|
-
* from
|
|
695
|
+
* ties favoring OCSP. An indeterminate reason in
|
|
696
|
+
* {@linkcode GOOD_BLOCKING_REASONS} from either source outranks a `good`
|
|
697
|
+
* verdict. If neither source is definitive, indeterminate reasons from both
|
|
698
|
+
* are merged.
|
|
469
699
|
*/
|
|
470
|
-
async function evaluateCertificateRevocation(e, t, n, r) {
|
|
471
|
-
let
|
|
472
|
-
if (l !== void 0) return {
|
|
473
|
-
status: l.status,
|
|
474
|
-
executionErrors: s
|
|
475
|
-
};
|
|
476
|
-
let u = c.find((e) => e.status.status === "good");
|
|
700
|
+
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");
|
|
477
702
|
if (u !== void 0) return {
|
|
478
703
|
status: u.status,
|
|
479
|
-
executionErrors:
|
|
704
|
+
executionErrors: c
|
|
705
|
+
};
|
|
706
|
+
let d = l.find((e) => e.status.status === "good"), f = [s, o].some((e) => e.status.indeterminateReasons?.some((e) => C.has(e)));
|
|
707
|
+
if (d !== void 0 && !f) return {
|
|
708
|
+
status: d.status,
|
|
709
|
+
executionErrors: c
|
|
480
710
|
};
|
|
481
|
-
let
|
|
482
|
-
for (let e of
|
|
711
|
+
let p = /* @__PURE__ */ new Set();
|
|
712
|
+
for (let e of l) for (let t of e.status.indeterminateReasons ?? []) p.add(t);
|
|
483
713
|
return {
|
|
484
714
|
status: {
|
|
485
715
|
certificate: e,
|
|
486
716
|
status: "indeterminate",
|
|
487
|
-
indeterminateReasons: [...
|
|
717
|
+
indeterminateReasons: [...p]
|
|
488
718
|
},
|
|
489
|
-
executionErrors:
|
|
719
|
+
executionErrors: c
|
|
490
720
|
};
|
|
491
721
|
}
|
|
492
722
|
/**
|
|
723
|
+
* RFC 9608 §4: path validation skips RFC 5280 §6.1.3 step (a)(3) for a
|
|
724
|
+
* certificate carrying noRevAvail or id-pkix-ocsp-nocheck, read from its
|
|
725
|
+
* signed DER.
|
|
726
|
+
*/
|
|
727
|
+
function revocationSkipReason(e) {
|
|
728
|
+
let t = r(e.der);
|
|
729
|
+
if (t.ok) return t.value.noRevAvail === !0 ? "no_rev_avail" : h(t.value) ? "ocsp_nocheck" : void 0;
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
493
732
|
* Checks revocation status for all certificates in a validated chain.
|
|
494
733
|
*
|
|
495
734
|
* Evaluates CRL and OCSP evidence against each certificate (except the trust
|
|
496
|
-
* anchor), applies the revocation policy, and returns a unified decision.
|
|
735
|
+
* anchor), applies the revocation policy, and returns a unified decision. A
|
|
736
|
+
* certificate carrying noRevAvail or id-pkix-ocsp-nocheck is reported as
|
|
737
|
+
* `skipped` without consulting evidence (RFC 9608 §4).
|
|
497
738
|
*
|
|
498
739
|
* @example
|
|
499
740
|
* ```ts
|
|
@@ -509,7 +750,9 @@ async function evaluateCertificateRevocation(e, t, n, r) {
|
|
|
509
750
|
* ```
|
|
510
751
|
*/
|
|
511
752
|
async function checkChainRevocation(e) {
|
|
512
|
-
let { chain: t, policy: n, crls: r = [], extraCertificates: i = [], at:
|
|
753
|
+
let { chain: t, policy: n, crls: r = [], extraCertificates: i = [], at: o = /* @__PURE__ */ new Date() } = e;
|
|
754
|
+
a(n?.crlMaxAgeMs);
|
|
755
|
+
let s = n?.mode ?? "hard-fail";
|
|
513
756
|
if (t.length === 0) return {
|
|
514
757
|
ok: !0,
|
|
515
758
|
value: {
|
|
@@ -521,34 +764,45 @@ async function checkChainRevocation(e) {
|
|
|
521
764
|
certificates: []
|
|
522
765
|
}
|
|
523
766
|
};
|
|
524
|
-
let
|
|
767
|
+
let c = {
|
|
525
768
|
cache: /* @__PURE__ */ new Map(),
|
|
526
769
|
chain: t,
|
|
527
770
|
crls: r,
|
|
528
771
|
extraCertificates: i,
|
|
529
|
-
at:
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
772
|
+
at: o,
|
|
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];
|
|
533
779
|
if (r === void 0 || i === void 0) continue;
|
|
534
|
-
let
|
|
535
|
-
|
|
780
|
+
let a = revocationSkipReason(r);
|
|
781
|
+
if (a !== void 0) {
|
|
782
|
+
d.push({
|
|
783
|
+
certificate: r,
|
|
784
|
+
status: "skipped",
|
|
785
|
+
skipReason: a
|
|
786
|
+
});
|
|
787
|
+
continue;
|
|
788
|
+
}
|
|
789
|
+
let { status: o, executionErrors: s } = await evaluateCertificateRevocation(r, i, e, c, l);
|
|
790
|
+
d.push(o), m.push(...s), o.status === "revoked" ? f.push(r) : o.status === "indeterminate" && p.push(r);
|
|
536
791
|
}
|
|
537
|
-
let
|
|
792
|
+
let h = f.length > 0, g = p.length > 0;
|
|
538
793
|
return {
|
|
539
794
|
ok: !0,
|
|
540
795
|
value: {
|
|
541
|
-
decision:
|
|
796
|
+
decision: h || g && s === "hard-fail" ? "deny" : "allow",
|
|
542
797
|
summary: {
|
|
543
|
-
revokedCertificates:
|
|
544
|
-
indeterminateCertificates:
|
|
798
|
+
revokedCertificates: f,
|
|
799
|
+
indeterminateCertificates: p
|
|
545
800
|
},
|
|
546
|
-
certificates:
|
|
547
|
-
...
|
|
801
|
+
certificates: d,
|
|
802
|
+
...m.length > 0 ? { executionErrors: m } : {}
|
|
548
803
|
}
|
|
549
804
|
};
|
|
550
805
|
}
|
|
551
|
-
|
|
552
|
-
export { u as REVOCATION_INDETERMINATE_REASONS, checkChainRevocation };
|
|
806
|
+
export { y as REVOCATION_INDETERMINATE_REASONS, checkChainRevocation };
|
|
553
807
|
|
|
554
808
|
//# sourceMappingURL=chain.js.map
|