micro509 0.9.0 → 0.10.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/dist/index.d.ts +3 -3
- package/dist/index.js +15 -15
- package/dist/internal/asn1/asn1.js +145 -186
- package/dist/internal/asn1/asn1.js.map +1 -0
- package/dist/internal/asn1/der.js +210 -227
- package/dist/internal/asn1/der.js.map +1 -0
- package/dist/internal/asn1/oids.js +297 -101
- package/dist/internal/asn1/oids.js.map +1 -0
- package/dist/internal/asn1/oids2.js +69 -0
- package/dist/internal/asn1/oids2.js.map +1 -0
- package/dist/internal/crypto/algorithm-names.js +37 -35
- package/dist/internal/crypto/algorithm-names.js.map +1 -0
- package/dist/internal/crypto/ecdsa.js +25 -28
- package/dist/internal/crypto/ecdsa.js.map +1 -0
- package/dist/internal/crypto/hash.js +56 -117
- package/dist/internal/crypto/hash.js.map +1 -0
- package/dist/internal/crypto/pbes2.js +122 -133
- package/dist/internal/crypto/pbes2.js.map +1 -0
- package/dist/internal/crypto/rsa-pss.js +118 -124
- package/dist/internal/crypto/rsa-pss.js.map +1 -0
- package/dist/internal/crypto/sig-verify.js +87 -99
- package/dist/internal/crypto/sig-verify.js.map +1 -0
- package/dist/internal/crypto/signing.d.ts +12 -8
- package/dist/internal/crypto/signing.js +53 -55
- package/dist/internal/crypto/signing.js.map +1 -0
- package/dist/internal/crypto/webcrypto.js +5 -3
- package/dist/internal/crypto/webcrypto.js.map +1 -0
- package/dist/internal/shared/base64.js +10 -9
- package/dist/internal/shared/base64.js.map +1 -0
- package/dist/internal/shared/dn.js +50 -57
- package/dist/internal/shared/dn.js.map +1 -0
- package/dist/internal/shared/ip.js +43 -53
- package/dist/internal/shared/ip.js.map +1 -0
- package/dist/internal/verify/name-constraints-engine.js +211 -239
- package/dist/internal/verify/name-constraints-engine.js.map +1 -0
- package/dist/internal/verify/policy-engine.js +228 -247
- package/dist/internal/verify/policy-engine.js.map +1 -0
- package/dist/internal/verify/verify-path.js +213 -228
- package/dist/internal/verify/verify-path.js.map +1 -0
- package/dist/internal/x509/extension-bits.js +62 -59
- package/dist/internal/x509/extension-bits.js.map +1 -0
- package/dist/internal/x509/extension-registry.js +133 -164
- package/dist/internal/x509/extension-registry.js.map +1 -0
- package/dist/internal/x509/name-fields.js +35 -41
- package/dist/internal/x509/name-fields.js.map +1 -0
- package/dist/keys/keys.d.ts +583 -547
- package/dist/keys/keys.js +519 -431
- package/dist/keys/keys.js.map +1 -0
- package/dist/keys.js +2 -2
- package/dist/pem/pem.d.ts +46 -46
- package/dist/pem/pem.js +62 -81
- package/dist/pem/pem.js.map +1 -0
- package/dist/pem.js +2 -2
- package/dist/pkcs/pfx.d.ts +96 -80
- package/dist/pkcs/pfx.js +191 -231
- package/dist/pkcs/pfx.js.map +1 -0
- package/dist/pkcs/pkcs12-mac.d.ts +20 -18
- package/dist/pkcs/pkcs12-mac.js +90 -111
- package/dist/pkcs/pkcs12-mac.js.map +1 -0
- package/dist/pkcs/pkcs7.d.ts +118 -69
- package/dist/pkcs/pkcs7.js +401 -443
- package/dist/pkcs/pkcs7.js.map +1 -0
- package/dist/pkcs.d.ts +2 -2
- package/dist/pkcs.js +4 -4
- package/dist/result/result.d.ts +37 -32
- package/dist/result/result.js +46 -44
- package/dist/result/result.js.map +1 -0
- package/dist/result.js +2 -2
- package/dist/revocation/chain.d.ts +138 -119
- package/dist/revocation/chain.js +248 -281
- package/dist/revocation/chain.js.map +1 -0
- package/dist/revocation/crl.d.ts +125 -123
- package/dist/revocation/crl.js +653 -745
- package/dist/revocation/crl.js.map +1 -0
- package/dist/revocation/ocsp.d.ts +183 -177
- package/dist/revocation/ocsp.js +579 -636
- package/dist/revocation/ocsp.js.map +1 -0
- package/dist/revocation/revocation.d.ts +26 -26
- package/dist/revocation/revocation.js +104 -125
- package/dist/revocation/revocation.js.map +1 -0
- package/dist/revocation.js +5 -5
- package/dist/verify/identity.d.ts +42 -42
- package/dist/verify/identity.js +158 -167
- package/dist/verify/identity.js.map +1 -0
- package/dist/verify/name-constraints.d.ts +7 -7
- package/dist/verify/policy.d.ts +10 -10
- package/dist/verify/verify.d.ts +163 -163
- package/dist/verify/verify.js +396 -392
- package/dist/verify/verify.js.map +1 -0
- package/dist/verify.js +3 -3
- package/dist/x509/certificate.d.ts +117 -117
- package/dist/x509/certificate.js +51 -60
- package/dist/x509/certificate.js.map +1 -0
- package/dist/x509/csr.d.ts +25 -25
- package/dist/x509/csr.js +26 -30
- package/dist/x509/csr.js.map +1 -0
- package/dist/x509/extensions.d.ts +228 -184
- package/dist/x509/extensions.js +175 -200
- package/dist/x509/extensions.js.map +1 -0
- package/dist/x509/name.d.ts +94 -93
- package/dist/x509/name.js +30 -29
- package/dist/x509/name.js.map +1 -0
- package/dist/x509/parse.d.ts +185 -185
- package/dist/x509/parse.js +638 -676
- package/dist/x509/parse.js.map +1 -0
- package/dist/x509.js +6 -6
- package/package.json +79 -41
package/dist/revocation/chain.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { parseCertificateFromSource } from "../x509/parse.js";
|
|
2
|
-
import { checkCertificateRevocationAgainstCrl, parseCertificateRevocationListDerOrThrow, parseCertificateRevocationListPemOrThrow, revocationReasonFromCode } from "./crl.js";
|
|
3
|
-
import { parseOcspResponseDerOrThrow, parseOcspResponsePemOrThrow, validateOcspResponse } from "./ocsp.js";
|
|
1
|
+
import { parseCertificateFromSource as e } from "../x509/parse.js";
|
|
2
|
+
import { checkCertificateRevocationAgainstCrl as t, parseCertificateRevocationListDerOrThrow as n, parseCertificateRevocationListPemOrThrow as r, revocationReasonFromCode as i } from "./crl.js";
|
|
3
|
+
import { parseOcspResponseDerOrThrow as a, parseOcspResponsePemOrThrow as o, validateOcspResponse as s } from "./ocsp.js";
|
|
4
4
|
//#region src/revocation/chain.ts
|
|
5
5
|
/**
|
|
6
6
|
* Granular reasons why revocation status could not be determined.
|
|
@@ -15,7 +15,7 @@ import { parseOcspResponseDerOrThrow, parseOcspResponsePemOrThrow, validateOcspR
|
|
|
15
15
|
* `crl_signer_revoked`, `crl_signer_indeterminate`, and OCSP equivalents
|
|
16
16
|
* - **Freshness**: `crl_expired`, `ocsp_response_expired`
|
|
17
17
|
*/
|
|
18
|
-
const
|
|
18
|
+
const c = [
|
|
19
19
|
"no_applicable_crl",
|
|
20
20
|
"no_applicable_ocsp",
|
|
21
21
|
"distribution_point_mismatch",
|
|
@@ -38,17 +38,15 @@ const REVOCATION_INDETERMINATE_REASONS = [
|
|
|
38
38
|
/**
|
|
39
39
|
* Parses a CRL from various source formats.
|
|
40
40
|
*/
|
|
41
|
-
function parseCrlFromSource(
|
|
42
|
-
|
|
43
|
-
if (typeof source === "string") return parseCertificateRevocationListPemOrThrow(source);
|
|
44
|
-
return parseCertificateRevocationListDerOrThrow(source);
|
|
41
|
+
function parseCrlFromSource(e) {
|
|
42
|
+
return typeof e == "object" && "issuer" in e ? e : typeof e == "string" ? r(e) : n(e);
|
|
45
43
|
}
|
|
46
44
|
/**
|
|
47
45
|
* Parses a certificate from various source formats, returning undefined on failure.
|
|
48
46
|
*/
|
|
49
|
-
function parseCertificateSafe(
|
|
47
|
+
function parseCertificateSafe(t) {
|
|
50
48
|
try {
|
|
51
|
-
return
|
|
49
|
+
return e(t);
|
|
52
50
|
} catch {
|
|
53
51
|
return;
|
|
54
52
|
}
|
|
@@ -57,135 +55,116 @@ function parseCertificateSafe(source) {
|
|
|
57
55
|
* Compares two certificates by DER bytes for identity.
|
|
58
56
|
* Reference equality fails when same cert is parsed from different sources.
|
|
59
57
|
*/
|
|
60
|
-
function sameCertificate(
|
|
61
|
-
if (
|
|
62
|
-
for (let
|
|
63
|
-
return
|
|
58
|
+
function sameCertificate(e, t) {
|
|
59
|
+
if (e.der.length !== t.der.length) return !1;
|
|
60
|
+
for (let n = 0; n < e.der.length; n++) if (e.der[n] !== t.der[n]) return !1;
|
|
61
|
+
return !0;
|
|
64
62
|
}
|
|
65
63
|
/**
|
|
66
64
|
* Searches for a certificate that could have signed the given CRL.
|
|
67
65
|
* Matches by AKI/SKI or issuer/subject DN.
|
|
68
66
|
*/
|
|
69
|
-
function findIndirectCrlIssuer(
|
|
70
|
-
|
|
71
|
-
for (
|
|
72
|
-
|
|
73
|
-
|
|
67
|
+
function findIndirectCrlIssuer(e, t, n) {
|
|
68
|
+
let r = [];
|
|
69
|
+
for (let e of t) {
|
|
70
|
+
let t = parseCertificateSafe(e);
|
|
71
|
+
t !== void 0 && r.push(t);
|
|
74
72
|
}
|
|
75
|
-
|
|
76
|
-
if (
|
|
77
|
-
for (
|
|
73
|
+
let i = [...r, ...n];
|
|
74
|
+
if (e.authorityKeyIdentifier !== void 0) {
|
|
75
|
+
for (let t of i) if (t.subjectKeyIdentifier !== void 0 && normalizeHex(e.authorityKeyIdentifier) === normalizeHex(t.subjectKeyIdentifier)) return t;
|
|
78
76
|
}
|
|
79
|
-
for (
|
|
77
|
+
for (let t of i) if (e.issuer.derHex === t.subject.derHex) return t;
|
|
80
78
|
}
|
|
81
79
|
/** Lowercases a hex string for bytewise comparison. */
|
|
82
|
-
function normalizeHex(
|
|
83
|
-
return
|
|
80
|
+
function normalizeHex(e) {
|
|
81
|
+
return e.toLowerCase();
|
|
84
82
|
}
|
|
85
83
|
/**
|
|
86
84
|
* Builds a unique cache key for a certificate.
|
|
87
85
|
* Uses issuer DN + serial number which uniquely identifies a cert.
|
|
88
86
|
*/
|
|
89
|
-
function certCacheKey(
|
|
90
|
-
return `${
|
|
87
|
+
function certCacheKey(e) {
|
|
88
|
+
return `${e.issuer.derHex}:${e.serialNumberHex}`;
|
|
91
89
|
}
|
|
92
90
|
/**
|
|
93
91
|
* Validates that a CRL signer certificate is not revoked.
|
|
94
92
|
* Uses memoization to avoid redundant checks and detect cycles.
|
|
95
93
|
*/
|
|
96
|
-
async function validateCrlSigner(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (ctx.chain.some((c) => sameCertificate(c, signer))) {
|
|
108
|
-
ctx.cache.set(key, "resolved-valid");
|
|
109
|
-
return "resolved-valid";
|
|
110
|
-
}
|
|
111
|
-
const signerIssuer = findSignerIssuer(signer, ctx);
|
|
112
|
-
if (signerIssuer === void 0) {
|
|
113
|
-
ctx.cache.set(key, "resolved-indeterminate");
|
|
114
|
-
return "resolved-indeterminate";
|
|
115
|
-
}
|
|
116
|
-
const signerRevocation = await checkSignerRevocation(signer, signerIssuer, ctx);
|
|
117
|
-
ctx.cache.set(key, signerRevocation);
|
|
118
|
-
return signerRevocation;
|
|
94
|
+
async function validateCrlSigner(e, t) {
|
|
95
|
+
let n = certCacheKey(e), r = t.cache.get(n);
|
|
96
|
+
if (r === "visiting") return "resolved-indeterminate";
|
|
97
|
+
if (r !== void 0) return r;
|
|
98
|
+
t.cache.set(n, "visiting");
|
|
99
|
+
let i = t.chain[t.chain.length - 1];
|
|
100
|
+
if (i !== void 0 && sameCertificate(e, i) || t.chain.some((t) => sameCertificate(t, e))) return t.cache.set(n, "resolved-valid"), "resolved-valid";
|
|
101
|
+
let a = findSignerIssuer(e, t);
|
|
102
|
+
if (a === void 0) return t.cache.set(n, "resolved-indeterminate"), "resolved-indeterminate";
|
|
103
|
+
let o = await checkSignerRevocation(e, a, t);
|
|
104
|
+
return t.cache.set(n, o), o;
|
|
119
105
|
}
|
|
120
106
|
/**
|
|
121
107
|
* Finds the issuer certificate for a CRL signer.
|
|
122
108
|
* Searches the chain and extraCertificates by AKI/SKI or DN matching.
|
|
123
109
|
*/
|
|
124
|
-
function findSignerIssuer(
|
|
125
|
-
|
|
126
|
-
for (
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
const candidates = [...ctx.chain, ...parsedExtras];
|
|
131
|
-
for (const candidate of candidates) {
|
|
132
|
-
if (signer.authorityKeyIdentifier !== void 0 && candidate.subjectKeyIdentifier !== void 0 && normalizeHex(signer.authorityKeyIdentifier) === normalizeHex(candidate.subjectKeyIdentifier)) return candidate;
|
|
133
|
-
if (signer.issuer.derHex === candidate.subject.derHex) return candidate;
|
|
110
|
+
function findSignerIssuer(e, t) {
|
|
111
|
+
let n = [];
|
|
112
|
+
for (let e of t.extraCertificates) {
|
|
113
|
+
let t = parseCertificateSafe(e);
|
|
114
|
+
t !== void 0 && n.push(t);
|
|
134
115
|
}
|
|
116
|
+
let r = [...t.chain, ...n];
|
|
117
|
+
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;
|
|
135
118
|
}
|
|
136
119
|
/**
|
|
137
120
|
* Checks if a CRL signer certificate is revoked by examining available CRLs.
|
|
138
121
|
* Recursively validates the CRL signer of any CRL used to check revocation.
|
|
139
122
|
*/
|
|
140
|
-
async function checkSignerRevocation(
|
|
141
|
-
|
|
142
|
-
for (
|
|
143
|
-
let
|
|
123
|
+
async function checkSignerRevocation(e, n, r) {
|
|
124
|
+
let i = r.chain.some((e) => sameCertificate(e, n));
|
|
125
|
+
for (let i of r.crls) {
|
|
126
|
+
let a;
|
|
144
127
|
try {
|
|
145
|
-
|
|
128
|
+
a = parseCrlFromSource(i);
|
|
146
129
|
} catch {
|
|
147
130
|
continue;
|
|
148
131
|
}
|
|
149
|
-
|
|
150
|
-
certificate:
|
|
151
|
-
issuerCertificate:
|
|
152
|
-
crl,
|
|
153
|
-
at:
|
|
132
|
+
let o = await t({
|
|
133
|
+
certificate: e,
|
|
134
|
+
issuerCertificate: n,
|
|
135
|
+
crl: a,
|
|
136
|
+
at: r.at
|
|
154
137
|
});
|
|
155
|
-
if (
|
|
156
|
-
if (
|
|
157
|
-
if (
|
|
158
|
-
if (await validateCrlSigner(issuer, ctx) === "resolved-valid") return "resolved-valid";
|
|
159
|
-
}
|
|
138
|
+
if (o.ok) {
|
|
139
|
+
if (o.value.status === "revoked") return "resolved-revoked";
|
|
140
|
+
if (o.value.status === "good" && await validateCrlSigner(n, r) === "resolved-valid") return "resolved-valid";
|
|
160
141
|
}
|
|
161
142
|
}
|
|
162
|
-
|
|
163
|
-
return "resolved-indeterminate";
|
|
143
|
+
return i ? "resolved-valid" : "resolved-indeterminate";
|
|
164
144
|
}
|
|
165
145
|
/** Builds the `revoked` CertificateRevocationStatus for a CRL hit. */
|
|
166
|
-
function buildCrlRevokedStatus(
|
|
146
|
+
function buildCrlRevokedStatus(e, t, n, r, i) {
|
|
167
147
|
return {
|
|
168
|
-
certificate:
|
|
148
|
+
certificate: e,
|
|
169
149
|
status: "revoked",
|
|
170
150
|
source: {
|
|
171
151
|
kind: "crl",
|
|
172
|
-
signerCertificate:
|
|
173
|
-
thisUpdate
|
|
152
|
+
signerCertificate: t,
|
|
153
|
+
thisUpdate: n
|
|
174
154
|
},
|
|
175
155
|
revocationInfo: {
|
|
176
|
-
revocationDate,
|
|
177
|
-
...
|
|
156
|
+
revocationDate: r,
|
|
157
|
+
...i === void 0 ? {} : { reason: i }
|
|
178
158
|
}
|
|
179
159
|
};
|
|
180
160
|
}
|
|
181
161
|
/** Parses an OCSP response from PEM string or DER bytes. */
|
|
182
|
-
function parseOcspResponseFromSource(
|
|
183
|
-
|
|
184
|
-
return parseOcspResponseDerOrThrow(source);
|
|
162
|
+
function parseOcspResponseFromSource(e) {
|
|
163
|
+
return typeof e == "string" ? o(e) : a(e);
|
|
185
164
|
}
|
|
186
165
|
/** Maps a {@linkcode validateOcspResponse} failure code to an indeterminate reason. */
|
|
187
|
-
function ocspIndeterminateReasonFromFailure(
|
|
188
|
-
switch (
|
|
166
|
+
function ocspIndeterminateReasonFromFailure(e) {
|
|
167
|
+
switch (e) {
|
|
189
168
|
case "stale_response": return "ocsp_response_expired";
|
|
190
169
|
case "responder_id_mismatch":
|
|
191
170
|
case "responder_chain_invalid":
|
|
@@ -200,7 +179,7 @@ function ocspIndeterminateReasonFromFailure(code) {
|
|
|
200
179
|
}
|
|
201
180
|
}
|
|
202
181
|
/** Validation failures worth retrying with an explicit responder certificate. */
|
|
203
|
-
const
|
|
182
|
+
const l = /* @__PURE__ */ new Set([
|
|
204
183
|
"signature_invalid",
|
|
205
184
|
"responder_id_mismatch",
|
|
206
185
|
"responder_chain_invalid",
|
|
@@ -210,30 +189,29 @@ const OCSP_RESPONDER_FAILURE_CODES = /* @__PURE__ */ new Set([
|
|
|
210
189
|
* Validates an OCSP response, retrying with caller-provided extra certificates
|
|
211
190
|
* as explicit responder certificates when embedded discovery fails.
|
|
212
191
|
*/
|
|
213
|
-
async function validateOcspResponseWithResponderFallback(
|
|
214
|
-
|
|
215
|
-
issuerCertificate:
|
|
216
|
-
at,
|
|
217
|
-
...
|
|
218
|
-
...
|
|
219
|
-
...
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
...shared
|
|
192
|
+
async function validateOcspResponseWithResponderFallback(e, t, n, r) {
|
|
193
|
+
let i = {
|
|
194
|
+
issuerCertificate: t,
|
|
195
|
+
at: r,
|
|
196
|
+
...n.trustedOcspResponders === void 0 ? {} : { trustedOcspResponders: n.trustedOcspResponders },
|
|
197
|
+
...n.policy?.ocspResponderRevocation === void 0 ? {} : { responderRevocationPolicy: n.policy.ocspResponderRevocation },
|
|
198
|
+
...n.crls === void 0 ? {} : { responderRevocationCrls: n.crls }
|
|
199
|
+
}, a = await s({
|
|
200
|
+
response: e,
|
|
201
|
+
...i
|
|
224
202
|
});
|
|
225
|
-
if (
|
|
226
|
-
for (
|
|
227
|
-
|
|
228
|
-
if (
|
|
229
|
-
|
|
230
|
-
response,
|
|
231
|
-
...
|
|
232
|
-
responderCertificate:
|
|
203
|
+
if (a.ok || !l.has(a.code)) return a;
|
|
204
|
+
for (let t of n.extraCertificates ?? []) {
|
|
205
|
+
let n = parseCertificateSafe(t);
|
|
206
|
+
if (n === void 0) continue;
|
|
207
|
+
let r = await s({
|
|
208
|
+
response: e,
|
|
209
|
+
...i,
|
|
210
|
+
responderCertificate: n
|
|
233
211
|
});
|
|
234
|
-
if (
|
|
212
|
+
if (r.ok) return r;
|
|
235
213
|
}
|
|
236
|
-
return
|
|
214
|
+
return a;
|
|
237
215
|
}
|
|
238
216
|
/**
|
|
239
217
|
* Evaluates OCSP evidence for a single certificate (RFC 6960).
|
|
@@ -244,67 +222,64 @@ async function validateOcspResponseWithResponderFallback(response, issuer, input
|
|
|
244
222
|
* the validator, so a serial-number match on a validated response is
|
|
245
223
|
* sufficient to attribute the entry to `cert`.
|
|
246
224
|
*/
|
|
247
|
-
async function evaluateOcspEvidence(
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
for (const source of ocspResponses) {
|
|
252
|
-
let parsed;
|
|
225
|
+
async function evaluateOcspEvidence(e, t, n) {
|
|
226
|
+
let { ocspResponses: r = [], at: a = /* @__PURE__ */ new Date() } = n, o = [], s = /* @__PURE__ */ new Set();
|
|
227
|
+
for (let c of r) {
|
|
228
|
+
let r;
|
|
253
229
|
try {
|
|
254
|
-
|
|
230
|
+
r = parseOcspResponseFromSource(c);
|
|
255
231
|
} catch (e) {
|
|
256
|
-
|
|
232
|
+
o.push({
|
|
257
233
|
kind: "parse_error",
|
|
258
234
|
message: e instanceof Error ? e.message : "OCSP response parse failed"
|
|
259
235
|
});
|
|
260
236
|
continue;
|
|
261
237
|
}
|
|
262
|
-
|
|
263
|
-
if (
|
|
264
|
-
|
|
265
|
-
if (!
|
|
266
|
-
|
|
238
|
+
let l = (r.responses ?? []).find((t) => normalizeHex(t.certId.serialNumberHex) === normalizeHex(e.serialNumberHex));
|
|
239
|
+
if (l === void 0) continue;
|
|
240
|
+
let u = await validateOcspResponseWithResponderFallback(r, t, n, a);
|
|
241
|
+
if (!u.ok) {
|
|
242
|
+
s.add(ocspIndeterminateReasonFromFailure(u.code));
|
|
267
243
|
continue;
|
|
268
244
|
}
|
|
269
|
-
if (
|
|
270
|
-
|
|
245
|
+
if (l.certStatus === "revoked") {
|
|
246
|
+
let t = i(l.revocationReasonCode);
|
|
271
247
|
return {
|
|
272
248
|
status: {
|
|
273
|
-
certificate:
|
|
249
|
+
certificate: e,
|
|
274
250
|
status: "revoked",
|
|
275
251
|
source: {
|
|
276
252
|
kind: "ocsp",
|
|
277
|
-
thisUpdate:
|
|
253
|
+
thisUpdate: l.thisUpdate
|
|
278
254
|
},
|
|
279
255
|
revocationInfo: {
|
|
280
|
-
revocationDate:
|
|
281
|
-
...
|
|
256
|
+
revocationDate: l.revokedAt ?? l.thisUpdate,
|
|
257
|
+
...t === void 0 ? {} : { reason: t }
|
|
282
258
|
}
|
|
283
259
|
},
|
|
284
|
-
executionErrors
|
|
260
|
+
executionErrors: o
|
|
285
261
|
};
|
|
286
262
|
}
|
|
287
|
-
if (
|
|
263
|
+
if (l.certStatus === "good") return {
|
|
288
264
|
status: {
|
|
289
|
-
certificate:
|
|
265
|
+
certificate: e,
|
|
290
266
|
status: "good",
|
|
291
267
|
source: {
|
|
292
268
|
kind: "ocsp",
|
|
293
|
-
thisUpdate:
|
|
269
|
+
thisUpdate: l.thisUpdate
|
|
294
270
|
}
|
|
295
271
|
},
|
|
296
|
-
executionErrors
|
|
272
|
+
executionErrors: o
|
|
297
273
|
};
|
|
298
|
-
|
|
274
|
+
s.add("ocsp_status_unknown");
|
|
299
275
|
}
|
|
300
|
-
|
|
301
|
-
return {
|
|
276
|
+
return s.size === 0 && s.add("no_applicable_ocsp"), {
|
|
302
277
|
status: {
|
|
303
|
-
certificate:
|
|
278
|
+
certificate: e,
|
|
304
279
|
status: "indeterminate",
|
|
305
|
-
indeterminateReasons: [...
|
|
280
|
+
indeterminateReasons: [...s]
|
|
306
281
|
},
|
|
307
|
-
executionErrors
|
|
282
|
+
executionErrors: o
|
|
308
283
|
};
|
|
309
284
|
}
|
|
310
285
|
/**
|
|
@@ -316,7 +291,7 @@ async function evaluateOcspEvidence(cert, issuer, input) {
|
|
|
316
291
|
*
|
|
317
292
|
* Also validates that CRL signers are not revoked (RFC 5280 §6.3.3).
|
|
318
293
|
*/
|
|
319
|
-
const
|
|
294
|
+
const u = [
|
|
320
295
|
"keyCompromise",
|
|
321
296
|
"cACompromise",
|
|
322
297
|
"affiliationChanged",
|
|
@@ -326,104 +301,110 @@ const ALL_REASON_FLAGS = [
|
|
|
326
301
|
"privilegeWithdrawn",
|
|
327
302
|
"aACompromise"
|
|
328
303
|
];
|
|
329
|
-
async function evaluateCrlEvidence(
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
message: e instanceof Error ? e.message : "CRL parse failed"
|
|
344
|
-
});
|
|
345
|
-
}
|
|
346
|
-
const baseCrls = parsedCrls.filter((crl) => crl.baseCrlNumber === void 0);
|
|
347
|
-
const deltaCrls = parsedCrls.filter((crl) => crl.baseCrlNumber !== void 0);
|
|
348
|
-
const checkWithIssuer = (crl, deltaCrl, crlIssuer) => {
|
|
349
|
-
return checkCertificateRevocationAgainstCrl({
|
|
350
|
-
certificate: cert,
|
|
351
|
-
issuerCertificate: crlIssuer,
|
|
352
|
-
crl,
|
|
353
|
-
...deltaCrl !== void 0 ? { deltaCrl } : {},
|
|
354
|
-
at
|
|
355
|
-
});
|
|
356
|
-
};
|
|
357
|
-
for (const baseCrl of baseCrls) {
|
|
358
|
-
const applicableDelta = deltaCrls.find((d) => d.issuer.derHex === baseCrl.issuer.derHex && d.baseCrlNumber !== void 0 && baseCrl.crlNumber !== void 0 && BigInt(d.baseCrlNumber) <= BigInt(baseCrl.crlNumber));
|
|
359
|
-
let result = await checkWithIssuer(baseCrl, applicableDelta, issuer);
|
|
360
|
-
let effectiveSigner = issuer;
|
|
361
|
-
if (!result.ok) {
|
|
362
|
-
const indirectIssuer = findIndirectCrlIssuer(baseCrl, extraCertificates, chain);
|
|
363
|
-
if (indirectIssuer !== void 0 && !sameCertificate(indirectIssuer, issuer)) {
|
|
364
|
-
result = await checkWithIssuer(baseCrl, applicableDelta, indirectIssuer);
|
|
365
|
-
effectiveSigner = indirectIssuer;
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
if (!result.ok) continue;
|
|
369
|
-
const signerStatus = await validateCrlSigner(effectiveSigner, signerCtx);
|
|
370
|
-
if (signerStatus === "resolved-revoked") {
|
|
371
|
-
sawCrlSignerRevoked = true;
|
|
304
|
+
async function evaluateCrlEvidence(e, t, n, r) {
|
|
305
|
+
let { crls: i = [], extraCertificates: a = [], chain: o = [], at: s = /* @__PURE__ */ new Date() } = n, c = {
|
|
306
|
+
executionErrors: [],
|
|
307
|
+
coveredReasons: /* @__PURE__ */ new Set(),
|
|
308
|
+
sawCrlSignerRevoked: !1,
|
|
309
|
+
sawCrlSignerIndeterminate: !1,
|
|
310
|
+
sawGood: !1
|
|
311
|
+
}, l = parseCrlEvidenceSources(i, c.executionErrors), d = l.filter((e) => e.baseCrlNumber === void 0), f = l.filter((e) => e.baseCrlNumber !== void 0);
|
|
312
|
+
for (let n of d) {
|
|
313
|
+
let i = findApplicableDeltaCrl(n, f), l = await checkCrlWithAvailableIssuers(e, n, i, t, a, o, s);
|
|
314
|
+
if (!l.result.ok) continue;
|
|
315
|
+
let u = await validateCrlSigner(l.signer, r);
|
|
316
|
+
if (u === "resolved-revoked") {
|
|
317
|
+
c.sawCrlSignerRevoked = !0;
|
|
372
318
|
continue;
|
|
373
319
|
}
|
|
374
|
-
if (
|
|
375
|
-
sawCrlSignerIndeterminate =
|
|
320
|
+
if (u === "resolved-indeterminate") {
|
|
321
|
+
c.sawCrlSignerIndeterminate = !0;
|
|
376
322
|
continue;
|
|
377
323
|
}
|
|
378
|
-
|
|
379
|
-
if (result.value.status === "revoked") return {
|
|
380
|
-
status: buildCrlRevokedStatus(
|
|
381
|
-
executionErrors
|
|
382
|
-
};
|
|
383
|
-
sawGood = true;
|
|
384
|
-
if (freshestGood === void 0 || crlThisUpdate.getTime() > freshestGood.thisUpdate.getTime()) freshestGood = {
|
|
385
|
-
signer: effectiveSigner,
|
|
386
|
-
thisUpdate: crlThisUpdate
|
|
387
|
-
};
|
|
388
|
-
const crlReasons = baseCrl.issuingDistributionPoint?.onlySomeReasons?.flags;
|
|
389
|
-
if (crlReasons === void 0) for (const reason of ALL_REASON_FLAGS) coveredReasons.add(reason);
|
|
390
|
-
else for (const reason of crlReasons) coveredReasons.add(reason);
|
|
391
|
-
}
|
|
392
|
-
if (sawGood && freshestGood !== void 0) {
|
|
393
|
-
if (ALL_REASON_FLAGS.every((r) => coveredReasons.has(r))) return {
|
|
394
|
-
status: {
|
|
395
|
-
certificate: cert,
|
|
396
|
-
status: "good",
|
|
397
|
-
source: {
|
|
398
|
-
kind: "crl",
|
|
399
|
-
signerCertificate: freshestGood.signer,
|
|
400
|
-
thisUpdate: freshestGood.thisUpdate
|
|
401
|
-
}
|
|
402
|
-
},
|
|
403
|
-
executionErrors
|
|
404
|
-
};
|
|
405
|
-
return {
|
|
406
|
-
status: {
|
|
407
|
-
certificate: cert,
|
|
408
|
-
status: "indeterminate",
|
|
409
|
-
indeterminateReasons: ["reason_coverage_incomplete"]
|
|
410
|
-
},
|
|
411
|
-
executionErrors
|
|
324
|
+
let d = i !== void 0 && i.thisUpdate.getTime() > n.thisUpdate.getTime() ? i.thisUpdate : n.thisUpdate;
|
|
325
|
+
if (l.result.value.status === "revoked") return {
|
|
326
|
+
status: buildCrlRevokedStatus(e, l.signer, d, l.result.value.revocationDate, l.result.value.reasonCode),
|
|
327
|
+
executionErrors: c.executionErrors
|
|
412
328
|
};
|
|
329
|
+
recordGoodCrlEvidence(c, l.signer, d, n);
|
|
413
330
|
}
|
|
414
|
-
|
|
415
|
-
if (sawCrlSignerRevoked) reasons.push("crl_signer_revoked");
|
|
416
|
-
else if (sawCrlSignerIndeterminate) reasons.push("crl_signer_indeterminate");
|
|
417
|
-
else reasons.push("no_applicable_crl");
|
|
418
|
-
return {
|
|
331
|
+
if (c.sawGood && c.freshestGood !== void 0) return u.every((e) => c.coveredReasons.has(e)) ? {
|
|
419
332
|
status: {
|
|
420
|
-
certificate:
|
|
333
|
+
certificate: e,
|
|
334
|
+
status: "good",
|
|
335
|
+
source: {
|
|
336
|
+
kind: "crl",
|
|
337
|
+
signerCertificate: c.freshestGood.signer,
|
|
338
|
+
thisUpdate: c.freshestGood.thisUpdate
|
|
339
|
+
}
|
|
340
|
+
},
|
|
341
|
+
executionErrors: c.executionErrors
|
|
342
|
+
} : {
|
|
343
|
+
status: {
|
|
344
|
+
certificate: e,
|
|
421
345
|
status: "indeterminate",
|
|
422
|
-
indeterminateReasons:
|
|
346
|
+
indeterminateReasons: ["reason_coverage_incomplete"]
|
|
423
347
|
},
|
|
424
|
-
executionErrors
|
|
348
|
+
executionErrors: c.executionErrors
|
|
349
|
+
};
|
|
350
|
+
let p = [];
|
|
351
|
+
return c.sawCrlSignerRevoked ? p.push("crl_signer_revoked") : c.sawCrlSignerIndeterminate ? p.push("crl_signer_indeterminate") : p.push("no_applicable_crl"), {
|
|
352
|
+
status: {
|
|
353
|
+
certificate: e,
|
|
354
|
+
status: "indeterminate",
|
|
355
|
+
indeterminateReasons: p
|
|
356
|
+
},
|
|
357
|
+
executionErrors: c.executionErrors
|
|
425
358
|
};
|
|
426
359
|
}
|
|
360
|
+
/** Parses complete and delta CRL evidence while retaining source provenance. */
|
|
361
|
+
function parseCrlEvidenceSources(e, t) {
|
|
362
|
+
let n = [];
|
|
363
|
+
for (let r of e) try {
|
|
364
|
+
n.push(parseCrlFromSource(r));
|
|
365
|
+
} catch (e) {
|
|
366
|
+
t.push({
|
|
367
|
+
kind: "parse_error",
|
|
368
|
+
message: e instanceof Error ? e.message : "CRL parse failed"
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
return n;
|
|
372
|
+
}
|
|
373
|
+
function findApplicableDeltaCrl(e, t) {
|
|
374
|
+
return t.find((t) => t.issuer.derHex === e.issuer.derHex && t.baseCrlNumber !== void 0 && e.crlNumber !== void 0 && BigInt(t.baseCrlNumber) <= BigInt(e.crlNumber));
|
|
375
|
+
}
|
|
376
|
+
/** Evaluates a CRL against each available issuer until applicable evidence is found. */
|
|
377
|
+
async function checkCrlWithAvailableIssuers(e, t, n, r, i, a, o) {
|
|
378
|
+
let s = await checkCrlWithIssuer(e, t, n, r, o);
|
|
379
|
+
if (s.ok) return {
|
|
380
|
+
result: s,
|
|
381
|
+
signer: r
|
|
382
|
+
};
|
|
383
|
+
let c = findIndirectCrlIssuer(t, i, a);
|
|
384
|
+
return c === void 0 || sameCertificate(c, r) ? {
|
|
385
|
+
result: s,
|
|
386
|
+
signer: r
|
|
387
|
+
} : {
|
|
388
|
+
result: await checkCrlWithIssuer(e, t, n, c, o),
|
|
389
|
+
signer: c
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
function checkCrlWithIssuer(e, n, r, i, a) {
|
|
393
|
+
return t({
|
|
394
|
+
certificate: e,
|
|
395
|
+
issuerCertificate: i,
|
|
396
|
+
crl: n,
|
|
397
|
+
...r === void 0 ? {} : { deltaCrl: r },
|
|
398
|
+
at: a
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
function recordGoodCrlEvidence(e, t, n, r) {
|
|
402
|
+
e.sawGood = !0, (e.freshestGood === void 0 || n.getTime() > e.freshestGood.thisUpdate.getTime()) && (e.freshestGood = {
|
|
403
|
+
signer: t,
|
|
404
|
+
thisUpdate: n
|
|
405
|
+
});
|
|
406
|
+
for (let t of r.issuingDistributionPoint?.onlySomeReasons?.flags ?? u) e.coveredReasons.add(t);
|
|
407
|
+
}
|
|
427
408
|
/**
|
|
428
409
|
* Evaluates revocation status for a single certificate by combining OCSP and
|
|
429
410
|
* CRL evidence.
|
|
@@ -435,31 +416,26 @@ async function evaluateCrlEvidence(cert, issuer, input, signerCtx) {
|
|
|
435
416
|
* ties favoring OCSP. If neither source is definitive, indeterminate reasons
|
|
436
417
|
* from both are merged.
|
|
437
418
|
*/
|
|
438
|
-
async function evaluateCertificateRevocation(
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
const ordered = prefer === "crl" ? [crl, ocsp] : prefer === "ocsp" ? [ocsp, crl] : [ocsp, crl].sort((a, b) => (b.status.source?.thisUpdate?.getTime() ?? 0) - (a.status.source?.thisUpdate?.getTime() ?? 0));
|
|
444
|
-
const revoked = ordered.find((evaluation) => evaluation.status.status === "revoked");
|
|
445
|
-
if (revoked !== void 0) return {
|
|
446
|
-
status: revoked.status,
|
|
447
|
-
executionErrors
|
|
419
|
+
async function evaluateCertificateRevocation(e, t, n, r) {
|
|
420
|
+
let i = n.policy?.prefer ?? "best-available", a = await evaluateOcspEvidence(e, t, n), o = await evaluateCrlEvidence(e, t, n, r), s = [...a.executionErrors, ...o.executionErrors], c = i === "crl" ? [o, a] : i === "ocsp" ? [a, o] : [a, o].sort((e, t) => (t.status.source?.thisUpdate?.getTime() ?? 0) - (e.status.source?.thisUpdate?.getTime() ?? 0)), l = c.find((e) => e.status.status === "revoked");
|
|
421
|
+
if (l !== void 0) return {
|
|
422
|
+
status: l.status,
|
|
423
|
+
executionErrors: s
|
|
448
424
|
};
|
|
449
|
-
|
|
450
|
-
if (
|
|
451
|
-
status:
|
|
452
|
-
executionErrors
|
|
425
|
+
let u = c.find((e) => e.status.status === "good");
|
|
426
|
+
if (u !== void 0) return {
|
|
427
|
+
status: u.status,
|
|
428
|
+
executionErrors: s
|
|
453
429
|
};
|
|
454
|
-
|
|
455
|
-
for (
|
|
430
|
+
let d = /* @__PURE__ */ new Set();
|
|
431
|
+
for (let e of c) for (let t of e.status.indeterminateReasons ?? []) d.add(t);
|
|
456
432
|
return {
|
|
457
433
|
status: {
|
|
458
|
-
certificate:
|
|
434
|
+
certificate: e,
|
|
459
435
|
status: "indeterminate",
|
|
460
|
-
indeterminateReasons: [...
|
|
436
|
+
indeterminateReasons: [...d]
|
|
461
437
|
},
|
|
462
|
-
executionErrors
|
|
438
|
+
executionErrors: s
|
|
463
439
|
};
|
|
464
440
|
}
|
|
465
441
|
/**
|
|
@@ -481,11 +457,10 @@ async function evaluateCertificateRevocation(cert, issuer, input, signerCtx) {
|
|
|
481
457
|
* }
|
|
482
458
|
* ```
|
|
483
459
|
*/
|
|
484
|
-
async function checkChainRevocation(
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
ok: true,
|
|
460
|
+
async function checkChainRevocation(e) {
|
|
461
|
+
let { chain: t, policy: n, crls: r = [], extraCertificates: i = [], at: a = /* @__PURE__ */ new Date() } = e, o = n?.mode ?? "hard-fail";
|
|
462
|
+
if (t.length === 0) return {
|
|
463
|
+
ok: !0,
|
|
489
464
|
value: {
|
|
490
465
|
decision: "allow",
|
|
491
466
|
summary: {
|
|
@@ -495,42 +470,34 @@ async function checkChainRevocation(input) {
|
|
|
495
470
|
certificates: []
|
|
496
471
|
}
|
|
497
472
|
};
|
|
498
|
-
|
|
473
|
+
let s = {
|
|
499
474
|
cache: /* @__PURE__ */ new Map(),
|
|
500
|
-
chain,
|
|
501
|
-
crls,
|
|
502
|
-
extraCertificates,
|
|
503
|
-
at
|
|
504
|
-
};
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
for (let i = 0; i < certsToCheck.length; i++) {
|
|
511
|
-
const cert = certsToCheck[i];
|
|
512
|
-
const issuer = chain[i + 1];
|
|
513
|
-
if (cert === void 0 || issuer === void 0) continue;
|
|
514
|
-
const { status, executionErrors } = await evaluateCertificateRevocation(cert, issuer, input, signerCtx);
|
|
515
|
-
certificates.push(status);
|
|
516
|
-
allExecutionErrors.push(...executionErrors);
|
|
517
|
-
if (status.status === "revoked") revokedCertificates.push(cert);
|
|
518
|
-
else if (status.status === "indeterminate") indeterminateCertificates.push(cert);
|
|
475
|
+
chain: t,
|
|
476
|
+
crls: r,
|
|
477
|
+
extraCertificates: i,
|
|
478
|
+
at: a
|
|
479
|
+
}, c = t.slice(0, -1), l = [], u = [], d = [], f = [];
|
|
480
|
+
for (let n = 0; n < c.length; n++) {
|
|
481
|
+
let r = c[n], i = t[n + 1];
|
|
482
|
+
if (r === void 0 || i === void 0) continue;
|
|
483
|
+
let { status: a, executionErrors: o } = await evaluateCertificateRevocation(r, i, e, s);
|
|
484
|
+
l.push(a), f.push(...o), a.status === "revoked" ? u.push(r) : a.status === "indeterminate" && d.push(r);
|
|
519
485
|
}
|
|
520
|
-
|
|
521
|
-
const hasIndeterminate = indeterminateCertificates.length > 0;
|
|
486
|
+
let p = u.length > 0, m = d.length > 0;
|
|
522
487
|
return {
|
|
523
|
-
ok:
|
|
488
|
+
ok: !0,
|
|
524
489
|
value: {
|
|
525
|
-
decision:
|
|
490
|
+
decision: p || m && o === "hard-fail" ? "deny" : "allow",
|
|
526
491
|
summary: {
|
|
527
|
-
revokedCertificates,
|
|
528
|
-
indeterminateCertificates
|
|
492
|
+
revokedCertificates: u,
|
|
493
|
+
indeterminateCertificates: d
|
|
529
494
|
},
|
|
530
|
-
certificates,
|
|
531
|
-
...
|
|
495
|
+
certificates: l,
|
|
496
|
+
...f.length > 0 ? { executionErrors: f } : {}
|
|
532
497
|
}
|
|
533
498
|
};
|
|
534
499
|
}
|
|
535
500
|
//#endregion
|
|
536
|
-
export { REVOCATION_INDETERMINATE_REASONS, checkChainRevocation };
|
|
501
|
+
export { c as REVOCATION_INDETERMINATE_REASONS, checkChainRevocation };
|
|
502
|
+
|
|
503
|
+
//# sourceMappingURL=chain.js.map
|