micro509 0.13.0 → 0.14.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/README.md +78 -30
- package/dist/crypto/crypto.d.ts +73 -0
- package/dist/crypto/crypto.js +74 -0
- package/dist/crypto/crypto.js.map +1 -0
- package/dist/crypto.d.ts +4 -0
- package/dist/crypto.js +2 -0
- package/dist/der/der.d.ts +1 -1
- package/dist/index.d.ts +13 -9
- package/dist/index.js +17 -15
- package/dist/internal/asn1/asn1.js +21 -10
- package/dist/internal/asn1/asn1.js.map +1 -1
- package/dist/internal/asn1/der.d.ts +4 -2
- package/dist/internal/asn1/der.js +18 -5
- package/dist/internal/asn1/der.js.map +1 -1
- package/dist/internal/asn1/oids.js +7 -1
- package/dist/internal/crypto/algorithm-names.js +4 -0
- package/dist/internal/crypto/algorithm-names.js.map +1 -1
- package/dist/internal/crypto/pbes2.d.ts +38 -0
- package/dist/internal/crypto/pbes2.js +9 -10
- package/dist/internal/crypto/pbes2.js.map +1 -1
- package/dist/internal/crypto/rsa-pss.js +2 -0
- package/dist/internal/crypto/rsa-pss.js.map +1 -1
- package/dist/internal/crypto/sig-verify.d.ts +31 -0
- package/dist/internal/crypto/sig-verify.js +10 -8
- package/dist/internal/crypto/sig-verify.js.map +1 -1
- package/dist/internal/shared/base64.js +7 -1
- package/dist/internal/shared/base64.js.map +1 -1
- package/dist/internal/shared/dn.d.ts +16 -0
- package/dist/internal/shared/dn.js +13 -6
- package/dist/internal/shared/dn.js.map +1 -1
- package/dist/internal/shared/ip.d.ts +69 -0
- package/dist/internal/shared/ip.js +18 -1
- package/dist/internal/shared/ip.js.map +1 -1
- package/dist/internal/verify/verify-path.d.ts +7 -0
- package/dist/internal/verify/verify-path.js +36 -36
- package/dist/internal/x509/directory-name.js +24 -0
- package/dist/internal/x509/directory-name.js.map +1 -0
- package/dist/internal/x509/extension-bits.js +13 -10
- package/dist/internal/x509/extension-bits.js.map +1 -1
- package/dist/internal/x509/extension-errors.d.ts +6 -0
- package/dist/internal/x509/extension-errors.js +20 -0
- package/dist/internal/x509/extension-errors.js.map +1 -0
- package/dist/internal/x509/extension-registry.js +113 -55
- package/dist/internal/x509/extension-registry.js.map +1 -1
- package/dist/internal/x509/general-name-tags.js +28 -0
- package/dist/internal/x509/general-name-tags.js.map +1 -0
- package/dist/internal/x509/general-name.js +97 -0
- package/dist/internal/x509/general-name.js.map +1 -0
- package/dist/internal/x509/name-fields.js +20 -10
- package/dist/internal/x509/name-fields.js.map +1 -1
- package/dist/keys/keys.d.ts +16 -2
- package/dist/keys/keys.js +311 -170
- package/dist/keys/keys.js.map +1 -1
- package/dist/keys.d.ts +3 -2
- package/dist/keys.js +3 -2
- package/dist/pem/pem.d.ts +3 -2
- package/dist/pem/pem.js +112 -30
- package/dist/pem/pem.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 +85 -21
- package/dist/pkcs/pkcs7.js +261 -186
- package/dist/pkcs/pkcs7.js.map +1 -1
- package/dist/pkcs.d.ts +2 -2
- package/dist/result/result.d.ts +18 -10
- package/dist/result/result.js +20 -12
- package/dist/result/result.js.map +1 -1
- package/dist/result.d.ts +2 -2
- package/dist/result.js +2 -2
- package/dist/revocation/chain.js +77 -81
- package/dist/revocation/chain.js.map +1 -1
- package/dist/revocation/crl.d.ts +13 -2
- package/dist/revocation/crl.js +415 -236
- package/dist/revocation/crl.js.map +1 -1
- package/dist/revocation/ocsp.d.ts +58 -17
- package/dist/revocation/ocsp.js +185 -173
- package/dist/revocation/ocsp.js.map +1 -1
- package/dist/revocation/revocation.d.ts +4 -4
- package/dist/revocation/revocation.js +48 -30
- package/dist/revocation/revocation.js.map +1 -1
- package/dist/revocation.d.ts +4 -4
- package/dist/revocation.js +5 -5
- package/dist/verify/identity.d.ts +2 -1
- package/dist/verify/identity.js +2 -1
- package/dist/verify/identity.js.map +1 -1
- package/dist/verify/policy.d.ts +6 -1
- package/dist/verify/verify.d.ts +4 -2
- package/dist/verify/verify.js +32 -14
- package/dist/verify/verify.js.map +1 -1
- package/dist/verify.d.ts +2 -1
- package/dist/verify.js +4 -3
- package/dist/x509/certificate.d.ts +36 -13
- package/dist/x509/certificate.js +36 -19
- package/dist/x509/certificate.js.map +1 -1
- package/dist/x509/csr.d.ts +6 -3
- package/dist/x509/extensions.d.ts +58 -21
- package/dist/x509/extensions.js +384 -117
- package/dist/x509/extensions.js.map +1 -1
- package/dist/x509/name-text.js +2 -0
- package/dist/x509/name-text.js.map +1 -1
- package/dist/x509/name.d.ts +8 -5
- package/dist/x509/name.js +17 -12
- package/dist/x509/name.js.map +1 -1
- package/dist/x509/parse.d.ts +104 -18
- package/dist/x509/parse.js +127 -163
- package/dist/x509/parse.js.map +1 -1
- package/dist/x509.d.ts +8 -5
- package/dist/x509.js +10 -8
- package/package.json +28 -20
package/dist/revocation/crl.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { bitString as e, concatBytes as t, explicitContext as n, generalizedTime as r, implicitConstructedContext as i, implicitPrimitiveContext as a, integer as o, integerFromNumber as s,
|
|
2
|
-
import { childrenOf as
|
|
3
|
-
import { OIDS as
|
|
4
|
-
import { base64Encode as
|
|
5
|
-
import { failureResult as
|
|
6
|
-
import { pemDecodeOrThrow as
|
|
7
|
-
import { exportSpkiDer as
|
|
8
|
-
import { describeSignatureAlgorithm as
|
|
9
|
-
import { decodeIpAddress as N } from "../internal/shared/ip.js";
|
|
1
|
+
import { bitString as e, concatBytes as t, explicitContext as n, generalizedTime as r, implicitConstructedContext as i, implicitPrimitiveContext as a, integer as o, integerFromNumber as s, optionalBytesEqual as c, readElement as l, readRootElement as u, readSequenceChildren as d, sequence as f, time as p, tlv as m } from "../internal/asn1/der.js";
|
|
2
|
+
import { childrenOf as h, decodeBoolean as g, decodeIntegerNumber as _, decodeObjectIdentifier as v, decodeString as y, extractBitStringValue as b, hexToBytes as x, parseTime as S, requireElement as C, toHex as w } from "../internal/asn1/asn1.js";
|
|
3
|
+
import { OIDS as T } from "../internal/asn1/oids2.js";
|
|
4
|
+
import { base64Encode as E } from "../internal/shared/base64.js";
|
|
5
|
+
import { failureResult as D, rethrowIfInvariant as O, successResult as k, throwMicro509Error as ee } from "../result/result.js";
|
|
6
|
+
import { pemDecodeOrThrow as A, pemEncode as j } from "../pem/pem.js";
|
|
7
|
+
import { exportSpkiDer as M } from "../keys/keys.js";
|
|
8
|
+
import { describeSignatureAlgorithm as N } from "../internal/crypto/algorithm-names.js";
|
|
10
9
|
import { encodeDistributionPointReasonFlagsContent as P, parseDistributionPointReasonFlagsContent as F } from "../internal/x509/extension-bits.js";
|
|
11
10
|
import { nameFieldKeyFromOid as I } from "../internal/x509/name-fields.js";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
11
|
+
import { compareDistinguishedNames as L, compareNameAttributeValue as R } from "../internal/shared/dn.js";
|
|
12
|
+
import { encodeName as z, encodeRelativeDistinguishedName as B, isNameInputEmpty as V } from "../x509/name.js";
|
|
13
|
+
import { buildSubjectKeyIdentifier as H, encodeCrlDistributionPoints as U, encodeExtension as W, encodeSubjectAltName as G } from "../x509/extensions.js";
|
|
14
|
+
import { parseGeneralName as K, parseGeneralNames as q } from "../internal/x509/general-name.js";
|
|
15
|
+
import { parseCertificateDerOrThrow as J, parseCertificateFromSource as Y } from "../x509/parse.js";
|
|
16
|
+
import { verifySignedDataDetailed as X } from "../internal/crypto/sig-verify.js";
|
|
17
|
+
import { encodeAlgorithmIdentifier as Z, getSignatureAlgorithm as te, signBytes as ne } from "../internal/crypto/signing.js";
|
|
18
18
|
//#region src/revocation/crl.ts
|
|
19
19
|
/**
|
|
20
20
|
* Full CRL lifecycle: create, parse, verify, validate, and revocation check.
|
|
@@ -25,7 +25,7 @@ import { compareDistinguishedNames as Y, compareNameAttributeValue as X } from "
|
|
|
25
25
|
* @module
|
|
26
26
|
*/
|
|
27
27
|
/** RFC 5280 §5.3.1 CRLReason integer codes, keyed by reason name. */
|
|
28
|
-
const
|
|
28
|
+
const re = {
|
|
29
29
|
unspecified: 0,
|
|
30
30
|
keyCompromise: 1,
|
|
31
31
|
cACompromise: 2,
|
|
@@ -36,7 +36,21 @@ const Z = {
|
|
|
36
36
|
removeFromCRL: 8,
|
|
37
37
|
privilegeWithdrawn: 9,
|
|
38
38
|
aACompromise: 10
|
|
39
|
-
}
|
|
39
|
+
}, Q = Object.freeze([
|
|
40
|
+
"keyCompromise",
|
|
41
|
+
"cACompromise",
|
|
42
|
+
"affiliationChanged",
|
|
43
|
+
"superseded",
|
|
44
|
+
"cessationOfOperation",
|
|
45
|
+
"certificateHold",
|
|
46
|
+
"privilegeWithdrawn",
|
|
47
|
+
"aACompromise"
|
|
48
|
+
]);
|
|
49
|
+
/** True when `reasons` covers every RFC 5280 §4.2.1.13 reason — a complete-scope CRL verdict. */
|
|
50
|
+
function coversAllDistributionPointReasons(e) {
|
|
51
|
+
let t = e instanceof Set ? e : new Set(e);
|
|
52
|
+
return Q.every((e) => t.has(e));
|
|
53
|
+
}
|
|
40
54
|
/**
|
|
41
55
|
* Signs and encodes an X.509 v2 CRL.
|
|
42
56
|
*
|
|
@@ -62,23 +76,24 @@ const Z = {
|
|
|
62
76
|
* ```
|
|
63
77
|
*/
|
|
64
78
|
async function createCertificateRevocationList(t) {
|
|
65
|
-
|
|
79
|
+
V(t.issuer) && throwCrlEncoderError("issuer_distinguished_name_empty", "issuer must be a non-empty distinguished name");
|
|
80
|
+
let r = te(t.signerPrivateKey), i = t.thisUpdate ?? /* @__PURE__ */ new Date(), a = t.nextUpdate, o = await buildCrlExtensions(t.issuerPublicKey, t.crlNumber, t.baseCrlNumber, t.issuingDistributionPoint, t.freshestCrlDistributionPoints), c = t.revokedCertificates ?? [], l = c.length === 0 ? [] : [f(c.map((e) => createRevokedCertificate(e, i)))], u = f([
|
|
66
81
|
s(1),
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
...a === void 0 ? [] : [
|
|
82
|
+
Z(r),
|
|
83
|
+
z(t.issuer),
|
|
84
|
+
p(i),
|
|
85
|
+
...a === void 0 ? [] : [p(a)],
|
|
71
86
|
...l,
|
|
72
|
-
...o.length === 0 ? [] : [n(0,
|
|
73
|
-
]),
|
|
87
|
+
...o.length === 0 ? [] : [n(0, f(o))]
|
|
88
|
+
]), d = await ne(t.signerPrivateKey, r, u), m = f([
|
|
74
89
|
u,
|
|
75
|
-
|
|
76
|
-
e(
|
|
90
|
+
Z(r),
|
|
91
|
+
e(d)
|
|
77
92
|
]);
|
|
78
93
|
return {
|
|
79
94
|
der: m,
|
|
80
|
-
pem:
|
|
81
|
-
base64:
|
|
95
|
+
pem: j("X509 CRL", m),
|
|
96
|
+
base64: E(m)
|
|
82
97
|
};
|
|
83
98
|
}
|
|
84
99
|
/**
|
|
@@ -88,19 +103,19 @@ async function createCertificateRevocationList(t) {
|
|
|
88
103
|
* {@linkcode validateCertificateRevocationList} for that.
|
|
89
104
|
*/
|
|
90
105
|
function parseCertificateRevocationListDerOrThrow(e) {
|
|
91
|
-
let t =
|
|
106
|
+
let t = d(e, { maxDepth: 64 });
|
|
92
107
|
if (t.length !== 3) throw Error("Malformed CRL");
|
|
93
|
-
let n =
|
|
94
|
-
return {
|
|
108
|
+
let n = C(t[0], "TBSCertList"), r = C(t[1], "signatureAlgorithm"), i = C(t[2], "signatureValue"), a = parseSignedCrlFields(e.slice(n.start - n.headerLength, n.end)), o = parseAlgorithmIdentifier(e, r);
|
|
109
|
+
return assertMatchingCrlSignatureAlgorithms(a.signature, o), {
|
|
95
110
|
der: new Uint8Array(e),
|
|
96
111
|
version: a.version,
|
|
97
112
|
tbsCertListDer: e.slice(n.start - n.headerLength, n.end),
|
|
98
|
-
signatureValue:
|
|
113
|
+
signatureValue: b(i),
|
|
99
114
|
issuer: a.issuer,
|
|
100
115
|
thisUpdate: a.thisUpdate,
|
|
101
116
|
...a.nextUpdate === void 0 ? {} : { nextUpdate: a.nextUpdate },
|
|
102
117
|
signatureAlgorithmOid: o.oid,
|
|
103
|
-
signatureAlgorithmName:
|
|
118
|
+
signatureAlgorithmName: N(o.oid, o.parametersDer),
|
|
104
119
|
...o.parametersDer === void 0 ? {} : { signatureAlgorithmParametersDer: o.parametersDer },
|
|
105
120
|
...a.authorityKeyIdentifier === void 0 ? {} : { authorityKeyIdentifier: a.authorityKeyIdentifier },
|
|
106
121
|
...a.crlNumber === void 0 ? {} : { crlNumber: a.crlNumber },
|
|
@@ -122,7 +137,7 @@ function parseCertificateRevocationListDerOrThrow(e) {
|
|
|
122
137
|
* ```
|
|
123
138
|
*/
|
|
124
139
|
function parseCertificateRevocationListPemOrThrow(e) {
|
|
125
|
-
return parseCertificateRevocationListDerOrThrow(
|
|
140
|
+
return parseCertificateRevocationListDerOrThrow(A("X509 CRL", e));
|
|
126
141
|
}
|
|
127
142
|
/**
|
|
128
143
|
* Decodes a DER-encoded X.509 CRL into a structured {@linkcode ParsedCertificateRevocationList}.
|
|
@@ -134,9 +149,9 @@ function parseCertificateRevocationListPemOrThrow(e) {
|
|
|
134
149
|
*/
|
|
135
150
|
function parseCertificateRevocationListDer(e) {
|
|
136
151
|
try {
|
|
137
|
-
return
|
|
152
|
+
return k(parseCertificateRevocationListDerOrThrow(e));
|
|
138
153
|
} catch (e) {
|
|
139
|
-
return
|
|
154
|
+
return O(e), D("malformed", e instanceof Error ? e.message : "Malformed CRL");
|
|
140
155
|
}
|
|
141
156
|
}
|
|
142
157
|
/**
|
|
@@ -147,9 +162,9 @@ function parseCertificateRevocationListDer(e) {
|
|
|
147
162
|
*/
|
|
148
163
|
function parseCertificateRevocationListPem(e) {
|
|
149
164
|
try {
|
|
150
|
-
return
|
|
165
|
+
return k(parseCertificateRevocationListPemOrThrow(e));
|
|
151
166
|
} catch (e) {
|
|
152
|
-
return
|
|
167
|
+
return O(e), D("malformed", e instanceof Error ? e.message : "Malformed CRL");
|
|
153
168
|
}
|
|
154
169
|
}
|
|
155
170
|
/**
|
|
@@ -167,7 +182,7 @@ async function verifyCertificateRevocationListSignature(e, t) {
|
|
|
167
182
|
}
|
|
168
183
|
let i;
|
|
169
184
|
try {
|
|
170
|
-
i = await
|
|
185
|
+
i = await X(n.signatureAlgorithmOid, n.signatureAlgorithmParametersDer, r.publicKeyAlgorithmOid, r.publicKeyParametersOid, r.subjectPublicKeyInfoDer, n.signatureValue, n.tbsCertListDer);
|
|
171
186
|
} catch {
|
|
172
187
|
return verifyCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature verification failed");
|
|
173
188
|
}
|
|
@@ -194,12 +209,12 @@ async function validateCertificateRevocationList(e) {
|
|
|
194
209
|
} catch {
|
|
195
210
|
return validateCertificateRevocationListFailureResult("signature_invalid", "issuer certificate input is malformed");
|
|
196
211
|
}
|
|
197
|
-
if (!
|
|
212
|
+
if (!L(t.issuer, n.subject)) return validateCertificateRevocationListFailureResult("issuer_mismatch", "CRL issuer name does not match certificate subject");
|
|
198
213
|
if (t.authorityKeyIdentifier !== void 0 && n.subjectKeyIdentifier !== void 0 && t.authorityKeyIdentifier !== n.subjectKeyIdentifier) return validateCertificateRevocationListFailureResult("issuer_mismatch", "CRL authority key identifier does not match issuer subject key identifier");
|
|
199
214
|
if (n.keyUsage !== void 0 && !n.keyUsage.flags.includes("cRLSign")) return validateCertificateRevocationListFailureResult("crl_sign_not_permitted", "issuer certificate key usage does not permit CRL signing");
|
|
200
215
|
let r;
|
|
201
216
|
try {
|
|
202
|
-
r = await
|
|
217
|
+
r = await X(t.signatureAlgorithmOid, t.signatureAlgorithmParametersDer, n.publicKeyAlgorithmOid, n.publicKeyParametersOid, n.subjectPublicKeyInfoDer, t.signatureValue, t.tbsCertListDer);
|
|
203
218
|
} catch {
|
|
204
219
|
return validateCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature verification failed");
|
|
205
220
|
}
|
|
@@ -250,16 +265,21 @@ async function checkCertificateRevocationAgainstCrl(e) {
|
|
|
250
265
|
let r = await validateOptionalDeltaCrl(e, n.value);
|
|
251
266
|
if (!r.ok) return r;
|
|
252
267
|
let i = checkCrlAndDeltaApplicability(t, n.value, r.value);
|
|
253
|
-
if (i
|
|
254
|
-
let a = findRevokedCertificateEntry(t, n.value);
|
|
255
|
-
if (!
|
|
256
|
-
let
|
|
268
|
+
if (!i.ok) return i.failure;
|
|
269
|
+
let a = i.coveredReasons, o = findRevokedCertificateEntry(t, n.value);
|
|
270
|
+
if (!o.ok) return o;
|
|
271
|
+
let s;
|
|
257
272
|
if (r.value !== void 0) {
|
|
258
273
|
let e = findRevokedCertificateEntry(t, r.value);
|
|
259
274
|
if (!e.ok) return e;
|
|
260
|
-
|
|
275
|
+
s = e.entry;
|
|
261
276
|
}
|
|
262
|
-
return resolveCertificateRevocationStatus(t,
|
|
277
|
+
return resolveCertificateRevocationStatus(t, r.value?.thisUpdate, n.value, o.entry, s, a);
|
|
278
|
+
}
|
|
279
|
+
/** RFC 5280 §6.3.3 (d): interim_reasons_mask from the matched DP and the CRL's IDP. */
|
|
280
|
+
function interimReasonsMask(e, t) {
|
|
281
|
+
let n = e?.reasons?.flags, r = t?.onlySomeReasons?.flags;
|
|
282
|
+
return n !== void 0 && r !== void 0 ? n.filter((e) => r.includes(e)) : n === void 0 ? r === void 0 ? Q : [...r] : [...n];
|
|
263
283
|
}
|
|
264
284
|
/** Validates an optional delta CRL and checks compatibility with its complete CRL. */
|
|
265
285
|
async function validateOptionalDeltaCrl(e, t) {
|
|
@@ -277,19 +297,21 @@ async function validateOptionalDeltaCrl(e, t) {
|
|
|
277
297
|
}
|
|
278
298
|
function checkCrlAndDeltaApplicability(e, t, n) {
|
|
279
299
|
let r = checkCrlApplicability(e, t);
|
|
280
|
-
|
|
300
|
+
if (!r.ok || n === void 0) return r;
|
|
301
|
+
let i = checkCrlApplicability(e, n, !0);
|
|
302
|
+
return i.ok ? r : i;
|
|
281
303
|
}
|
|
282
304
|
/** Builds a `VerifyCertificateRevocationListSignatureFailureResult`. */
|
|
283
305
|
function verifyCertificateRevocationListFailureResult(e, t) {
|
|
284
|
-
return
|
|
306
|
+
return D(e, t);
|
|
285
307
|
}
|
|
286
308
|
/** Builds a `ValidateCertificateRevocationListFailureResult`. */
|
|
287
309
|
function validateCertificateRevocationListFailureResult(e, t) {
|
|
288
|
-
return
|
|
310
|
+
return D(e, t);
|
|
289
311
|
}
|
|
290
312
|
/** Builds a `CheckCertificateRevocationAgainstCrlFailureResult`. */
|
|
291
313
|
function checkCertificateRevocationAgainstCrlFailureResult(e, t, n) {
|
|
292
|
-
return
|
|
314
|
+
return D(e, t, n);
|
|
293
315
|
}
|
|
294
316
|
/** Wraps a success value into a `CheckCertificateRevocationAgainstCrlResult`. */
|
|
295
317
|
function checkCertificateRevocationAgainstCrlSuccess(e) {
|
|
@@ -303,7 +325,7 @@ function checkCertificateRevocationAgainstCrlSuccess(e) {
|
|
|
303
325
|
* CRL's revoked entries. Does **not** validate the CRL or check applicability.
|
|
304
326
|
*/
|
|
305
327
|
function isCertificateRevoked(e, t) {
|
|
306
|
-
let n = typeof e == "string" ? normalizeHex(e) :
|
|
328
|
+
let n = typeof e == "string" ? normalizeHex(e) : w(e);
|
|
307
329
|
return t.revokedCertificates.some((e) => normalizeHex(e.serialNumberHex) === n);
|
|
308
330
|
}
|
|
309
331
|
/** Searches CRL entries for the certificate's serial, respecting indirect-CRL issuer overrides. */
|
|
@@ -326,44 +348,95 @@ function findRevokedCertificateEntry(e, t) {
|
|
|
326
348
|
}
|
|
327
349
|
/** RFC 5280 §6.3 CRL applicability: scope, distribution-point, reason, and indirect-CRL checks. */
|
|
328
350
|
function checkCrlApplicability(e, t, n = !1) {
|
|
329
|
-
if (!n && t.baseCrlNumber !== void 0) return
|
|
351
|
+
if (!n && t.baseCrlNumber !== void 0) return notApplicableOutcome("unsupported_delta_crl", "a delta CRL cannot be used as the primary complete CRL input");
|
|
330
352
|
let r = t.issuingDistributionPoint, i = r?.indirectCrl === !0;
|
|
331
|
-
if (!i && !
|
|
332
|
-
if (r?.onlyContainsAttributeCerts === !0) return
|
|
353
|
+
if (!i && !L(e.issuer, t.issuer)) return notApplicableOutcome("issuer_mismatch", "CRL issuer does not match certificate issuer for direct CRL processing");
|
|
354
|
+
if (r?.onlyContainsAttributeCerts === !0) return notApplicableOutcome("certificate_scope_mismatch", "attribute-certificate-only CRLs are not applicable to public-key certificates");
|
|
333
355
|
let a = e.basicConstraints?.ca === !0;
|
|
334
|
-
if (r?.onlyContainsUserCerts === !0 && a) return
|
|
335
|
-
if (r?.onlyContainsCACerts === !0 && !a) return
|
|
356
|
+
if (r?.onlyContainsUserCerts === !0 && a) return notApplicableOutcome("certificate_scope_mismatch", "CRL only applies to end-entity certificates");
|
|
357
|
+
if (r?.onlyContainsCACerts === !0 && !a) return notApplicableOutcome("certificate_scope_mismatch", "CRL only applies to CA certificates");
|
|
336
358
|
let o = e.crlDistributionPoints ?? [];
|
|
337
|
-
|
|
359
|
+
if (o.length === 0) return r?.distributionPoint !== void 0 && !matchesDistributionPointName(issuerFallbackDistributionPointName(e), r.distributionPoint, t.issuer, void 0) ? notApplicableOutcome("distribution_point_mismatch", "CRL issuing distribution point does not name the certificate issuer") : i && !L(e.issuer, t.issuer) ? notApplicableOutcome("issuer_mismatch", "indirect CRLs for alternate certificate issuers require matching CRLIssuer distribution points") : {
|
|
360
|
+
ok: !0,
|
|
361
|
+
coveredReasons: interimReasonsMask(void 0, r)
|
|
362
|
+
};
|
|
363
|
+
let s = scanCrlDistributionPoints(o, e, t, r, i);
|
|
364
|
+
return typeof s == "string" ? {
|
|
365
|
+
ok: !1,
|
|
366
|
+
failure: crlDistributionPointScanFailure(s)
|
|
367
|
+
} : {
|
|
368
|
+
ok: !0,
|
|
369
|
+
coveredReasons: s.coveredReasons
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
/** Wraps a non-applicability failure into a {@linkcode CrlApplicabilityOutcome}. */
|
|
373
|
+
function notApplicableOutcome(e, t) {
|
|
374
|
+
return {
|
|
375
|
+
ok: !1,
|
|
376
|
+
failure: nonApplicable(e, t)
|
|
377
|
+
};
|
|
338
378
|
}
|
|
339
|
-
/**
|
|
379
|
+
/**
|
|
380
|
+
* RFC 5280 §6.3.3 final paragraph: for a certificate without a CRLDP extension,
|
|
381
|
+
* assume a distribution point named by the certificate issuer and its
|
|
382
|
+
* issuerAltName entries, with reasons and cRLIssuer omitted.
|
|
383
|
+
*/
|
|
384
|
+
function issuerFallbackDistributionPointName(e) {
|
|
385
|
+
return {
|
|
386
|
+
type: "fullName",
|
|
387
|
+
fullName: [{
|
|
388
|
+
type: "directoryName",
|
|
389
|
+
derHex: e.issuer.derHex
|
|
390
|
+
}, ...e.issuerAltNames ?? []]
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Aggregates distribution-point matching across a certificate.
|
|
395
|
+
*
|
|
396
|
+
* RFC 5280 §6.3.3 processes every corresponding DP, so when several match the same CRL their
|
|
397
|
+
* interim reason masks (d) are unioned rather than stopping at the first.
|
|
398
|
+
*/
|
|
340
399
|
function scanCrlDistributionPoints(e, t, n, r, i) {
|
|
341
|
-
let a =
|
|
342
|
-
for (let
|
|
343
|
-
let e = scanCrlDistributionPoint(
|
|
344
|
-
if (e === "matched")
|
|
345
|
-
|
|
400
|
+
let a = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Set(), s = !1;
|
|
401
|
+
for (let c of e) {
|
|
402
|
+
let e = scanCrlDistributionPoint(c, t, n, r, i);
|
|
403
|
+
if (e === "matched") {
|
|
404
|
+
s = !0;
|
|
405
|
+
for (let e of interimReasonsMask(c, r)) a.add(e);
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
o.add(e);
|
|
346
409
|
}
|
|
347
|
-
return
|
|
410
|
+
return s ? { coveredReasons: [...a] } : resolveScanFailure(o);
|
|
411
|
+
}
|
|
412
|
+
/** Reports the highest-precedence distribution-point scan failure. */
|
|
413
|
+
function resolveScanFailure(e) {
|
|
414
|
+
return [
|
|
415
|
+
"reasons_mismatch",
|
|
416
|
+
"unsupported_indirect_crl_issuer",
|
|
417
|
+
"indirect_issuer_mismatch",
|
|
418
|
+
"distribution_point_mismatch",
|
|
419
|
+
"indirect_distribution_point"
|
|
420
|
+
].find((t) => e.has(t)) ?? "scope_mismatch";
|
|
348
421
|
}
|
|
349
422
|
function scanCrlDistributionPoint(e, t, n, r, i) {
|
|
350
423
|
let a = scanCrlDistributionPointIssuer(e, t, n, i);
|
|
351
|
-
return a === void 0 ? matchesDistributionPointName(e.distributionPoint, r?.distributionPoint, n.issuer) ? hasOverlappingReasons(e.reasons, r?.onlySomeReasons) ? "matched" : "reasons_mismatch" : "distribution_point_mismatch" : a;
|
|
424
|
+
return a === void 0 ? matchesDistributionPointName(e.distributionPoint, r?.distributionPoint, n.issuer, e.crlIssuer) ? hasOverlappingReasons(e.reasons, r?.onlySomeReasons) ? "matched" : "reasons_mismatch" : "distribution_point_mismatch" : a;
|
|
352
425
|
}
|
|
353
426
|
function scanCrlDistributionPointIssuer(e, t, n, r) {
|
|
354
427
|
if (!r) return e.crlIssuer === void 0 ? void 0 : "indirect_distribution_point";
|
|
355
|
-
if (
|
|
428
|
+
if (L(t.issuer, n.issuer) && e.crlIssuer === void 0) return;
|
|
356
429
|
let i = matchesIndirectCrlIssuer(e.crlIssuer, n);
|
|
357
430
|
return i === "unsupported" ? "unsupported_indirect_crl_issuer" : i ? void 0 : "indirect_issuer_mismatch";
|
|
358
431
|
}
|
|
359
432
|
function crlDistributionPointScanFailure(e) {
|
|
360
|
-
|
|
433
|
+
return e === "reasons_mismatch" ? nonApplicable("reasons_mismatch", "certificate distribution point reasons do not overlap the CRL reason scope") : e === "unsupported_indirect_crl_issuer" ? nonApplicable("unsupported_indirect_crl", "indirect CRL distribution points must identify the CRL issuer with directoryName") : e === "indirect_issuer_mismatch" ? nonApplicable("issuer_mismatch", "certificate distribution points do not authorize this indirect CRL issuer") : e === "distribution_point_mismatch" ? nonApplicable("distribution_point_mismatch", "certificate distribution points do not match the CRL issuing distribution point") : e === "indirect_distribution_point" ? nonApplicable("unsupported_indirect_crl", "certificate distribution points that name alternate CRL issuers are not supported yet") : nonApplicable("distribution_point_mismatch", "certificate distribution points do not match the CRL scope");
|
|
361
434
|
}
|
|
362
435
|
/** Verifies that a delta CRL is compatible with the given complete CRL (same issuer, AKI, IDP, and valid numbering). */
|
|
363
436
|
function checkDeltaCrlCompatibility(e, t) {
|
|
364
437
|
if (e.baseCrlNumber !== void 0) return nonApplicable("delta_crl_incompatible", "complete CRL input must not itself be a delta CRL");
|
|
365
438
|
if (t.baseCrlNumber === void 0) return nonApplicable("delta_crl_incompatible", "delta CRL input must include a delta CRL indicator");
|
|
366
|
-
if (!
|
|
439
|
+
if (!L(e.issuer, t.issuer)) return nonApplicable("delta_crl_incompatible", "complete and delta CRLs must share the same issuer");
|
|
367
440
|
if (e.authorityKeyIdentifier !== t.authorityKeyIdentifier) return nonApplicable("delta_crl_incompatible", "complete and delta CRLs must share the same authority key identifier");
|
|
368
441
|
if (!sameIssuingDistributionPoint(e.issuingDistributionPoint, t.issuingDistributionPoint)) return nonApplicable("delta_crl_incompatible", "complete and delta CRLs must share the same issuing distribution point scope");
|
|
369
442
|
if (e.crlNumber === void 0 || t.crlNumber === void 0) return nonApplicable("delta_crl_incompatible", "complete and delta CRLs must both carry CRL numbers for delta processing");
|
|
@@ -385,7 +458,7 @@ function matchesIndirectCrlIssuer(e, t) {
|
|
|
385
458
|
}
|
|
386
459
|
/** Determines whether a revoked entry's effective issuer matches the certificate's issuer. */
|
|
387
460
|
function matchesRevokedEntryIssuer(e, t, n) {
|
|
388
|
-
if (n === void 0) return
|
|
461
|
+
if (n === void 0) return L(e.issuer, t.issuer) ? "match" : "mismatch";
|
|
389
462
|
let r = !1;
|
|
390
463
|
for (let t of n) {
|
|
391
464
|
if (t.type === "directoryName") {
|
|
@@ -400,12 +473,21 @@ function matchesRevokedEntryIssuer(e, t, n) {
|
|
|
400
473
|
function nonApplicable(e, t) {
|
|
401
474
|
return checkCertificateRevocationAgainstCrlFailureResult("non_applicable", t, { reason: e });
|
|
402
475
|
}
|
|
403
|
-
/**
|
|
404
|
-
|
|
476
|
+
/**
|
|
477
|
+
* Merges complete and delta CRL entries into a final `good`/`revoked` status
|
|
478
|
+
* per the RFC 5280 §6.3.3 (i)-(k) relying-party algorithm.
|
|
479
|
+
*
|
|
480
|
+
* Deliberately harder than (i)-(k) on `removeFromCRL`: the entry clears a
|
|
481
|
+
* revocation only in the two situations §5.2.4(b)/§5.3.1 permit an issuer to
|
|
482
|
+
* emit it, a complete-CRL `certificateHold` entry or a certificate that
|
|
483
|
+
* expired before the delta CRL's thisUpdate.
|
|
484
|
+
*/
|
|
485
|
+
function resolveCertificateRevocationStatus(e, t, n, r, i, a) {
|
|
405
486
|
if (i !== void 0) if (i.reasonCode === "removeFromCRL") {
|
|
406
|
-
if (r?.reasonCode === "certificateHold" || e.notAfter.getTime() < t.getTime()) return checkCertificateRevocationAgainstCrlSuccess({
|
|
487
|
+
if (r?.reasonCode === "certificateHold" || t !== void 0 && e.notAfter.getTime() < t.getTime()) return checkCertificateRevocationAgainstCrlSuccess({
|
|
407
488
|
status: "good",
|
|
408
|
-
crl: n
|
|
489
|
+
crl: n,
|
|
490
|
+
coveredReasons: a
|
|
409
491
|
});
|
|
410
492
|
} else return checkCertificateRevocationAgainstCrlSuccess({
|
|
411
493
|
status: "revoked",
|
|
@@ -415,7 +497,8 @@ function resolveCertificateRevocationStatus(e, t, n, r, i) {
|
|
|
415
497
|
});
|
|
416
498
|
return checkCertificateRevocationAgainstCrlSuccess(r === void 0 ? {
|
|
417
499
|
status: "good",
|
|
418
|
-
crl: n
|
|
500
|
+
crl: n,
|
|
501
|
+
coveredReasons: a
|
|
419
502
|
} : {
|
|
420
503
|
status: "revoked",
|
|
421
504
|
crl: n,
|
|
@@ -430,29 +513,40 @@ function resolveCertificateRevocationStatus(e, t, n, r, i) {
|
|
|
430
513
|
* the full distribution point name is formed by appending that RDN to the CRL issuer's DN.
|
|
431
514
|
* This resolved name is then compared against the CRL's IDP fullName directoryName entries.
|
|
432
515
|
*/
|
|
433
|
-
function matchesDistributionPointName(e, t, n) {
|
|
516
|
+
function matchesDistributionPointName(e, t, n, r) {
|
|
434
517
|
if (t === void 0) return !0;
|
|
435
|
-
if (e === void 0) return
|
|
436
|
-
if (e.
|
|
437
|
-
if (e.
|
|
518
|
+
if (e === void 0) return matchesIdpNameAgainstCrlIssuer(t, r, n);
|
|
519
|
+
if (e.type === "fullName" && t.type === "fullName") return e.fullName.some((e) => t.fullName.some((t) => compareGeneralNames(e, t)));
|
|
520
|
+
if (e.type === "relativeName" && t.type === "fullName") {
|
|
438
521
|
let r = resolveRelativeNameToDnHex(n, e.relativeName);
|
|
439
522
|
return t.fullName.some((e) => e.type === "directoryName" && e.derHex === r);
|
|
440
523
|
}
|
|
441
|
-
if (e.
|
|
442
|
-
if (e.
|
|
524
|
+
if (e.type === "relativeName" && t.type === "relativeName") return compareRelativeDistinguishedNames(e.relativeName, t.relativeName);
|
|
525
|
+
if (e.type === "fullName" && t.type === "relativeName") {
|
|
443
526
|
let r = resolveRelativeNameToDnHex(n, t.relativeName);
|
|
444
527
|
return e.fullName.some((e) => e.type === "directoryName" && e.derHex === r);
|
|
445
528
|
}
|
|
446
529
|
return !1;
|
|
447
530
|
}
|
|
531
|
+
/**
|
|
532
|
+
* RFC 5280 §6.3.3 (b)(2)(i): when the certificate's distribution point omits the
|
|
533
|
+
* distributionPoint field, match the CRL IDP's distributionPoint names against
|
|
534
|
+
* the distribution point's `cRLIssuer` names.
|
|
535
|
+
*/
|
|
536
|
+
function matchesIdpNameAgainstCrlIssuer(e, t, n) {
|
|
537
|
+
if (t === void 0) return !1;
|
|
538
|
+
if (e.type === "fullName") return t.some((t) => e.fullName.some((e) => compareGeneralNames(t, e)));
|
|
539
|
+
let r = resolveRelativeNameToDnHex(n, e.relativeName);
|
|
540
|
+
return t.some((e) => e.type === "directoryName" && e.derHex === r);
|
|
541
|
+
}
|
|
448
542
|
/** Constructs a full DN by appending an RDN to an existing Name, returning hex-encoded DER. */
|
|
449
543
|
function resolveRelativeNameToDnHex(e, t) {
|
|
450
|
-
let n = e.rdns.map((e) =>
|
|
451
|
-
return n.push(r),
|
|
544
|
+
let n = e.rdns.map((e) => x(e.derHex)), r = rebuildRelativeNameAsSet(x(t.derHex));
|
|
545
|
+
return n.push(r), w(f(n));
|
|
452
546
|
}
|
|
453
547
|
/** Converts an implicit-tagged [1] relativeName to a proper SET-tagged RDN. */
|
|
454
548
|
function rebuildRelativeNameAsSet(e) {
|
|
455
|
-
return
|
|
549
|
+
return m(49, u(e, { maxDepth: 64 }).value);
|
|
456
550
|
}
|
|
457
551
|
/** Deep-compares two issuing distribution point extensions for delta-CRL compatibility. */
|
|
458
552
|
function sameIssuingDistributionPoint(e, t) {
|
|
@@ -460,7 +554,7 @@ function sameIssuingDistributionPoint(e, t) {
|
|
|
460
554
|
}
|
|
461
555
|
/** Compares two DistributionPointName values (fullName set or relativeName). */
|
|
462
556
|
function sameDistributionPointName(e, t) {
|
|
463
|
-
return e === void 0 || t === void 0 ? e === t : e.
|
|
557
|
+
return e === void 0 || t === void 0 ? e === t : e.type === "fullName" && t.type === "fullName" ? sameGeneralNameSet(e.fullName, t.fullName) : e.type === "relativeName" && t.type === "relativeName" && compareRelativeDistinguishedNames(e.relativeName, t.relativeName);
|
|
464
558
|
}
|
|
465
559
|
/** Set-equality comparison for GeneralName arrays (order-independent). */
|
|
466
560
|
function sameGeneralNameSet(e, t) {
|
|
@@ -489,13 +583,97 @@ function hasOverlappingReasons(e, t) {
|
|
|
489
583
|
}
|
|
490
584
|
/** Value-equality for two GeneralName entries, using DER comparison for directoryName. */
|
|
491
585
|
function compareGeneralNames(e, t) {
|
|
492
|
-
if (e.type === "dns" && t.type === "dns" || e.type === "
|
|
586
|
+
if (e.type === "dns" && t.type === "dns" || e.type === "srv" && t.type === "srv") return e.value.toLowerCase() === t.value.toLowerCase();
|
|
587
|
+
if (e.type === "email" && t.type === "email") return compareRfc822Names(e.value, t.value);
|
|
588
|
+
if (e.type === "ip" && t.type === "ip") return e.value === t.value;
|
|
589
|
+
if (e.type === "uri" && t.type === "uri") return compareUniformResourceIdentifiers(e.value, t.value);
|
|
493
590
|
if (e.type === "directoryName" && t.type === "directoryName") {
|
|
494
591
|
let n = parseDerHexName(e.derHex), r = parseDerHexName(t.derHex);
|
|
495
|
-
return n === void 0 || r === void 0 ? !1 :
|
|
592
|
+
return n === void 0 || r === void 0 ? !1 : L(n, r);
|
|
496
593
|
}
|
|
497
594
|
return e.type === "unknown" && t.type === "unknown" && e.tag === t.tag && bytesEqual(e.value, t.value);
|
|
498
595
|
}
|
|
596
|
+
/** RFC 5280 §7.5: rfc822Name local-part is case-sensitive, the host-part case-insensitive. */
|
|
597
|
+
function compareRfc822Names(e, t) {
|
|
598
|
+
let n = e.lastIndexOf("@"), r = t.lastIndexOf("@");
|
|
599
|
+
return n < 0 || r < 0 ? e.toLowerCase() === t.toLowerCase() : e.slice(0, n) === t.slice(0, r) && e.slice(n + 1).toLowerCase() === t.slice(r + 1).toLowerCase();
|
|
600
|
+
}
|
|
601
|
+
/** RFC 5280 §7.4: URIs compare only after syntax-based and scheme-based normalization. */
|
|
602
|
+
function compareUniformResourceIdentifiers(e, t) {
|
|
603
|
+
if (e === t) return !0;
|
|
604
|
+
let n = normalizeUriForComparison(e);
|
|
605
|
+
return n !== void 0 && n === normalizeUriForComparison(t);
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* The schemes RFC 5280 §7.4 step 5 requires implementations to recognise, with
|
|
609
|
+
* the default port that scheme-based normalization elides. `ldaps` is included
|
|
610
|
+
* as the TLS form of the mandatory `ldap` scheme.
|
|
611
|
+
*/
|
|
612
|
+
const ie = /* @__PURE__ */ new Map([
|
|
613
|
+
["ftp", "21"],
|
|
614
|
+
["http", "80"],
|
|
615
|
+
["https", "443"],
|
|
616
|
+
["ldap", "389"],
|
|
617
|
+
["ldaps", "636"]
|
|
618
|
+
]);
|
|
619
|
+
/**
|
|
620
|
+
* Applies the RFC 5280 §7.4 comparison preparation: IDN labels to ASCII
|
|
621
|
+
* Compatible Encoding, lowercased scheme and host, percent-encoding and path
|
|
622
|
+
* segment normalization, and scheme-based normalization. The URL parser covers
|
|
623
|
+
* path segments for every scheme and the scheme case; the remaining steps are
|
|
624
|
+
* applied here because it leaves the host of a non-special scheme such as
|
|
625
|
+
* `ldap` untouched and never normalizes percent-encoding.
|
|
626
|
+
*
|
|
627
|
+
* @returns `undefined` when the value does not parse as an absolute URI.
|
|
628
|
+
*/
|
|
629
|
+
function normalizeUriForComparison(e) {
|
|
630
|
+
let t;
|
|
631
|
+
try {
|
|
632
|
+
t = new URL(e);
|
|
633
|
+
} catch {
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
if (t.hostname !== "") {
|
|
637
|
+
let e = normalizeUriHost(t.hostname);
|
|
638
|
+
if (e === void 0) return;
|
|
639
|
+
t.hostname = e;
|
|
640
|
+
}
|
|
641
|
+
return t.port === ie.get(t.protocol.slice(0, -1)) && (t.port = ""), normalizePercentEncoding(t.href);
|
|
642
|
+
}
|
|
643
|
+
/**
|
|
644
|
+
* Reparses a host under a special scheme so the URL parser applies IDNA and
|
|
645
|
+
* lowercasing to it, which it skips for opaque hosts.
|
|
646
|
+
*
|
|
647
|
+
* @returns `undefined` when the host does not survive the round trip intact.
|
|
648
|
+
*/
|
|
649
|
+
function normalizeUriHost(e) {
|
|
650
|
+
try {
|
|
651
|
+
let t = new URL(`https://${decodeHostPercentEncoding(e)}`);
|
|
652
|
+
return t.href === `https://${t.hostname}/` ? t.hostname : void 0;
|
|
653
|
+
} catch {
|
|
654
|
+
return;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
/** Recovers the Unicode host an opaque-host URI carries as percent-encoded UTF-8. */
|
|
658
|
+
function decodeHostPercentEncoding(e) {
|
|
659
|
+
try {
|
|
660
|
+
return decodeURIComponent(e);
|
|
661
|
+
} catch {
|
|
662
|
+
return e;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
const ae = /%[0-9A-Fa-f]{2}/g;
|
|
666
|
+
/** RFC 3986 §6.2.2.2: unreserved triplets decode, every other triplet uppercases. */
|
|
667
|
+
function normalizePercentEncoding(e) {
|
|
668
|
+
return e.replace(ae, (e) => {
|
|
669
|
+
let t = Number.parseInt(e.slice(1), 16);
|
|
670
|
+
return isUnreservedUriCharacter(t) ? String.fromCharCode(t) : e.toUpperCase();
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
/** RFC 3986 §2.3 unreserved set: `ALPHA / DIGIT / "-" / "." / "_" / "~"`. */
|
|
674
|
+
function isUnreservedUriCharacter(e) {
|
|
675
|
+
return e >= 65 && e <= 90 || e >= 97 && e <= 122 || e >= 48 && e <= 57 || e === 45 || e === 46 || e === 95 || e === 126;
|
|
676
|
+
}
|
|
499
677
|
/** Constant-length byte-array equality check. */
|
|
500
678
|
function bytesEqual(e, t) {
|
|
501
679
|
if (e.length !== t.length) return !1;
|
|
@@ -510,7 +688,7 @@ function compareRelativeDistinguishedNames(e, t) {
|
|
|
510
688
|
let e = !1;
|
|
511
689
|
for (let i = 0; i < t.attributes.length; i += 1) {
|
|
512
690
|
let a = t.attributes[i];
|
|
513
|
-
if (!(a === void 0 || n[i]) &&
|
|
691
|
+
if (!(a === void 0 || n[i]) && R(r, a)) {
|
|
514
692
|
n[i] = !0, e = !0;
|
|
515
693
|
break;
|
|
516
694
|
}
|
|
@@ -523,30 +701,30 @@ function compareRelativeDistinguishedNames(e, t) {
|
|
|
523
701
|
async function buildCrlExtensions(e, t, n, r, i) {
|
|
524
702
|
let o = [];
|
|
525
703
|
if (e !== void 0) {
|
|
526
|
-
let t = await
|
|
527
|
-
o.push(
|
|
704
|
+
let t = await M(e);
|
|
705
|
+
o.push(W(T.authorityKeyIdentifier, f([a(0, H(t))])));
|
|
528
706
|
}
|
|
529
|
-
return t !== void 0 && o.push(
|
|
707
|
+
return t !== void 0 && o.push(W(T.cRLNumber, s(t))), n !== void 0 && o.push(W(T.deltaCRLIndicator, s(n), !0)), r !== void 0 && o.push(W(T.issuingDistributionPoint, encodeIssuingDistributionPoint(r), !0)), i !== void 0 && i.length > 0 && o.push(W(T.freshestCRL, U(i))), o;
|
|
530
708
|
}
|
|
531
709
|
/** DER-encodes a single revokedCertificate SEQUENCE (serial, date, optional extensions). */
|
|
532
710
|
function createRevokedCertificate(e, t) {
|
|
533
711
|
let n = buildRevokedCertificateExtensions(e);
|
|
534
|
-
return
|
|
712
|
+
return f([
|
|
535
713
|
o(e.serialNumber),
|
|
536
|
-
|
|
537
|
-
...n.length === 0 ? [] : [
|
|
714
|
+
p(e.revocationDate ?? t),
|
|
715
|
+
...n.length === 0 ? [] : [f(n)]
|
|
538
716
|
]);
|
|
539
717
|
}
|
|
540
718
|
/** Encodes CRL entry extensions (reasonCode, invalidityDate). */
|
|
541
719
|
function buildRevokedCertificateExtensions(e) {
|
|
542
720
|
let t = [];
|
|
543
|
-
return e.reasonCode !== void 0 && t.push(
|
|
721
|
+
return e.reasonCode !== void 0 && t.push(W(T.cRLReason, m(10, Uint8Array.of(re[e.reasonCode])))), e.invalidityDate !== void 0 && t.push(W(T.invalidityDate, r(e.invalidityDate))), t;
|
|
544
722
|
}
|
|
545
723
|
/** Decodes per-entry CRL extensions (reasonCode, invalidityDate, certificateIssuer). */
|
|
546
724
|
function parseRevokedCertificateExtensions(e, t) {
|
|
547
725
|
if (e === void 0 || t === void 0) return {};
|
|
548
726
|
let n = {}, r = /* @__PURE__ */ new Set();
|
|
549
|
-
for (let i of
|
|
727
|
+
for (let i of h(e, t)) parseRevokedCertificateExtension(e, i, r, n);
|
|
550
728
|
return {
|
|
551
729
|
...n.reasonCode === void 0 ? {} : { reasonCode: n.reasonCode },
|
|
552
730
|
...n.invalidityDate === void 0 ? {} : { invalidityDate: n.invalidityDate },
|
|
@@ -554,44 +732,81 @@ function parseRevokedCertificateExtensions(e, t) {
|
|
|
554
732
|
};
|
|
555
733
|
}
|
|
556
734
|
function parseRevokedCertificateExtension(e, t, n, r) {
|
|
557
|
-
let i =
|
|
735
|
+
let i = h(e, t);
|
|
558
736
|
if (i.length < 2 || i.length > 3 || i.length === 3 && i[1]?.tag !== 1) throw Error("Malformed revoked certificate extension");
|
|
559
|
-
let a =
|
|
737
|
+
let a = v(C(i[0], "revoked certificate extension OID").value);
|
|
560
738
|
if (n.has(a)) throw Error(`Duplicate revoked certificate extension OID: ${a}`);
|
|
561
739
|
n.add(a);
|
|
562
|
-
let o =
|
|
740
|
+
let o = C(i[i.length - 1], "revoked certificate extension value");
|
|
563
741
|
if (o.tag !== 4) throw Error("Revoked certificate extension value must use OCTET STRING");
|
|
564
742
|
applyRevokedCertificateExtensionValue(a, o.value, r);
|
|
565
743
|
}
|
|
566
744
|
function applyRevokedCertificateExtensionValue(e, t, n) {
|
|
567
|
-
if (e ===
|
|
568
|
-
let e = revocationReasonFromCode(
|
|
745
|
+
if (e === T.cRLReason) {
|
|
746
|
+
let e = revocationReasonFromCode(l(t).value[0]);
|
|
569
747
|
e !== void 0 && (n.reasonCode = e);
|
|
570
748
|
}
|
|
571
|
-
if (e ===
|
|
572
|
-
let e =
|
|
749
|
+
if (e === T.invalidityDate && (n.invalidityDate = S(l(t))), e === T.certificateIssuer) {
|
|
750
|
+
let e = u(t, { maxDepth: 64 });
|
|
573
751
|
if (e.tag !== 48) throw Error("certificateIssuer must use SEQUENCE");
|
|
574
|
-
n.certificateIssuer =
|
|
752
|
+
n.certificateIssuer = q(t, e);
|
|
575
753
|
}
|
|
576
754
|
}
|
|
577
755
|
/** Decodes the IssuingDistributionPoint extension from its OCTET STRING content. */
|
|
578
756
|
function parseIssuingDistributionPoint(e) {
|
|
579
|
-
let t =
|
|
580
|
-
for (let r of
|
|
581
|
-
if ([
|
|
582
|
-
n.onlyContainsUserCerts,
|
|
583
|
-
n.onlyContainsCACerts,
|
|
584
|
-
n.onlyContainsAttributeCerts
|
|
585
|
-
].filter((e) => e === !0).length > 1) throw Error("IssuingDistributionPoint scope booleans are mutually exclusive");
|
|
757
|
+
let t = u(e, { maxDepth: 64 }), n = {};
|
|
758
|
+
for (let r of h(e, t)) parseIssuingDistributionPointField(e, r, n);
|
|
586
759
|
return {
|
|
587
760
|
...n.distributionPoint === void 0 ? {} : { distributionPoint: n.distributionPoint },
|
|
588
|
-
...n.onlyContainsUserCerts === void 0 ? {} : { onlyContainsUserCerts: n.onlyContainsUserCerts },
|
|
589
|
-
...n.onlyContainsCACerts === void 0 ? {} : { onlyContainsCACerts: n.onlyContainsCACerts },
|
|
590
761
|
...n.onlySomeReasons === void 0 ? {} : { onlySomeReasons: n.onlySomeReasons },
|
|
591
762
|
...n.indirectCrl === void 0 ? {} : { indirectCrl: n.indirectCrl },
|
|
592
|
-
...n
|
|
763
|
+
...parseIssuingDistributionPointScope(n)
|
|
593
764
|
};
|
|
594
765
|
}
|
|
766
|
+
/** RFC 5280 §5.2.5: at most one `onlyContains*` flag may be TRUE. */
|
|
767
|
+
function parseIssuingDistributionPointScope(e) {
|
|
768
|
+
let t = e.onlyContainsUserCerts, n = e.onlyContainsCACerts, r = e.onlyContainsAttributeCerts;
|
|
769
|
+
if (t === !0) {
|
|
770
|
+
if (n === !0 || r === !0) throw Error($);
|
|
771
|
+
return {
|
|
772
|
+
onlyContainsUserCerts: !0,
|
|
773
|
+
...unselectedScopeFlags({
|
|
774
|
+
caCerts: n,
|
|
775
|
+
attributeCerts: r
|
|
776
|
+
})
|
|
777
|
+
};
|
|
778
|
+
}
|
|
779
|
+
if (n === !0) {
|
|
780
|
+
if (r === !0) throw Error($);
|
|
781
|
+
return {
|
|
782
|
+
onlyContainsCACerts: !0,
|
|
783
|
+
...unselectedScopeFlags({
|
|
784
|
+
userCerts: t,
|
|
785
|
+
attributeCerts: r
|
|
786
|
+
})
|
|
787
|
+
};
|
|
788
|
+
}
|
|
789
|
+
return r === !0 ? {
|
|
790
|
+
onlyContainsAttributeCerts: !0,
|
|
791
|
+
...unselectedScopeFlags({
|
|
792
|
+
userCerts: t,
|
|
793
|
+
caCerts: n
|
|
794
|
+
})
|
|
795
|
+
} : unselectedScopeFlags({
|
|
796
|
+
userCerts: t,
|
|
797
|
+
caCerts: n,
|
|
798
|
+
attributeCerts: r
|
|
799
|
+
});
|
|
800
|
+
}
|
|
801
|
+
/** Keeps the explicit-FALSE flags the encoding carried, omitting the ones it left out. */
|
|
802
|
+
function unselectedScopeFlags(e) {
|
|
803
|
+
return {
|
|
804
|
+
...e.userCerts === void 0 ? {} : { onlyContainsUserCerts: e.userCerts },
|
|
805
|
+
...e.caCerts === void 0 ? {} : { onlyContainsCACerts: e.caCerts },
|
|
806
|
+
...e.attributeCerts === void 0 ? {} : { onlyContainsAttributeCerts: e.attributeCerts }
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
const $ = "IssuingDistributionPoint scope booleans are mutually exclusive";
|
|
595
810
|
function parseIssuingDistributionPointField(e, t, n) {
|
|
596
811
|
switch (t.tag) {
|
|
597
812
|
case 160: {
|
|
@@ -625,31 +840,37 @@ function parseUniqueIssuingDistributionPointBoolean(e, t, n) {
|
|
|
625
840
|
}
|
|
626
841
|
/** Decodes a SEQUENCE OF DistributionPoint from DER. */
|
|
627
842
|
function parseDistributionPoints(e) {
|
|
628
|
-
let t =
|
|
843
|
+
let t = u(e, { maxDepth: 64 });
|
|
629
844
|
if (t.tag !== 48) throw Error("DistributionPoints must use SEQUENCE");
|
|
630
|
-
let n =
|
|
845
|
+
let n = h(e, t);
|
|
631
846
|
if (n.length === 0) throw Error("DistributionPoints must not be empty");
|
|
632
847
|
return n.map((t) => parseDistributionPoint(e, t));
|
|
633
848
|
}
|
|
634
849
|
/** Decodes a DistributionPointName (fullName or relativeName). */
|
|
635
850
|
function parseDistributionPointName(e, t) {
|
|
636
|
-
let n =
|
|
851
|
+
let n = h(e, t);
|
|
637
852
|
if (n.length !== 1) throw Error("distributionPointName must contain exactly one choice");
|
|
638
|
-
let r =
|
|
853
|
+
let r = C(n[0], "distributionPointName");
|
|
639
854
|
if (r.tag === 160) {
|
|
640
|
-
let t =
|
|
855
|
+
let t = h(e, r);
|
|
641
856
|
if (t.length === 0) throw Error("distributionPointName fullName must not be empty");
|
|
642
857
|
for (let e of t) if ((e.tag & 192) != 128) throw Error("distributionPointName fullName must contain GeneralName entries");
|
|
643
|
-
return {
|
|
858
|
+
return {
|
|
859
|
+
type: "fullName",
|
|
860
|
+
fullName: t.map((t) => K(e, t))
|
|
861
|
+
};
|
|
644
862
|
}
|
|
645
|
-
if (r.tag === 161) return {
|
|
863
|
+
if (r.tag === 161) return {
|
|
864
|
+
type: "relativeName",
|
|
865
|
+
relativeName: parseRelativeName(e, r)
|
|
866
|
+
};
|
|
646
867
|
throw Error(`Unsupported distributionPointName tag: ${String(r.tag)}`);
|
|
647
868
|
}
|
|
648
869
|
/** Decodes a single DistributionPoint SEQUENCE. */
|
|
649
870
|
function parseDistributionPoint(e, t) {
|
|
650
871
|
if (t.tag !== 48) throw Error("DistributionPoint must use SEQUENCE");
|
|
651
872
|
let n = {};
|
|
652
|
-
for (let r of
|
|
873
|
+
for (let r of h(e, t)) parseDistributionPointField(e, r, n);
|
|
653
874
|
if (n.distributionPoint === void 0 && n.crlIssuer === void 0) throw Error("DistributionPoint must include distributionPoint or crlIssuer");
|
|
654
875
|
return {
|
|
655
876
|
...n.distributionPoint === void 0 ? {} : { distributionPoint: n.distributionPoint },
|
|
@@ -671,52 +892,16 @@ function parseDistributionPointField(e, t, n) {
|
|
|
671
892
|
return;
|
|
672
893
|
case 162:
|
|
673
894
|
if (n.crlIssuer !== void 0) throw Error("DistributionPoint crlIssuer must not repeat");
|
|
674
|
-
n.crlIssuer =
|
|
895
|
+
n.crlIssuer = q(e, t);
|
|
675
896
|
return;
|
|
676
897
|
default: throw Error(`Unsupported DistributionPoint field tag: ${String(t.tag)}`);
|
|
677
898
|
}
|
|
678
899
|
}
|
|
679
|
-
/** Decodes a GeneralName from its context-tagged ASN.1 element. */
|
|
680
|
-
function parseGeneralName(e) {
|
|
681
|
-
switch (e.tag) {
|
|
682
|
-
case 129: return {
|
|
683
|
-
type: "email",
|
|
684
|
-
value: Q.decode(e.value)
|
|
685
|
-
};
|
|
686
|
-
case 130: return {
|
|
687
|
-
type: "dns",
|
|
688
|
-
value: Q.decode(e.value)
|
|
689
|
-
};
|
|
690
|
-
case 134: return {
|
|
691
|
-
type: "uri",
|
|
692
|
-
value: Q.decode(e.value)
|
|
693
|
-
};
|
|
694
|
-
case 135: return {
|
|
695
|
-
type: "ip",
|
|
696
|
-
value: N(e.value)
|
|
697
|
-
};
|
|
698
|
-
case 164: return {
|
|
699
|
-
type: "directoryName",
|
|
700
|
-
derHex: C(rebuildDirectoryNameFromImplicit(e))
|
|
701
|
-
};
|
|
702
|
-
default: return {
|
|
703
|
-
type: "unknown",
|
|
704
|
-
tag: e.tag,
|
|
705
|
-
value: new Uint8Array(e.value)
|
|
706
|
-
};
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
function parseGeneralNames(e, t) {
|
|
710
|
-
let n = m(e, t);
|
|
711
|
-
if (n.length === 0) throw Error("GeneralNames must not be empty");
|
|
712
|
-
for (let e of n) if ((e.tag & 192) != 128) throw Error("GeneralNames must contain GeneralName entries");
|
|
713
|
-
return n.map((e) => parseGeneralName(e));
|
|
714
|
-
}
|
|
715
900
|
/** Decodes a RelativeDistinguishedName SET from an implicitly-tagged context element. */
|
|
716
901
|
function parseRelativeName(e, t) {
|
|
717
902
|
let n = [], r = {};
|
|
718
|
-
for (let i of
|
|
719
|
-
let t =
|
|
903
|
+
for (let i of h(e, t)) {
|
|
904
|
+
let t = h(e, i), a = v(C(t[0], "name OID").value), o = C(t[1], "name value"), s = I(a), c = decodeNameValue(o), l = s === void 0 ? {
|
|
720
905
|
oid: a,
|
|
721
906
|
valueTag: o.tag,
|
|
722
907
|
value: c
|
|
@@ -729,19 +914,23 @@ function parseRelativeName(e, t) {
|
|
|
729
914
|
n.push(l), s !== void 0 && r[s] === void 0 && (r[s] = c);
|
|
730
915
|
}
|
|
731
916
|
return {
|
|
732
|
-
derHex:
|
|
917
|
+
derHex: w(e.slice(t.start - t.headerLength, t.end)),
|
|
733
918
|
attributes: n,
|
|
734
919
|
values: r
|
|
735
920
|
};
|
|
736
921
|
}
|
|
737
922
|
/** Decodes an ASN.1 string element (UTF8String, PrintableString, etc.) to a JS string. */
|
|
738
923
|
function decodeNameValue(e) {
|
|
739
|
-
return
|
|
924
|
+
return y(e.tag, e.value);
|
|
740
925
|
}
|
|
741
926
|
/** Reads an implicitly-tagged BOOLEAN from a context element. Absent content → `false`. */
|
|
742
927
|
function parseImplicitBoolean(e) {
|
|
743
928
|
return (e.value[0] ?? 0) !== 0;
|
|
744
929
|
}
|
|
930
|
+
/** Throws a {@link ResultError} for a CRL encoder input-validation failure. */
|
|
931
|
+
function throwCrlEncoderError(e, t) {
|
|
932
|
+
ee(e, t);
|
|
933
|
+
}
|
|
745
934
|
/** DER-encodes an IssuingDistributionPoint extension value. Throws on mutually-exclusive scope flags. */
|
|
746
935
|
function encodeIssuingDistributionPoint(e) {
|
|
747
936
|
if ([
|
|
@@ -750,48 +939,35 @@ function encodeIssuingDistributionPoint(e) {
|
|
|
750
939
|
e.onlyContainsAttributeCerts === !0
|
|
751
940
|
].filter(Boolean).length > 1) throw Error("IssuingDistributionPoint can assert at most one of user, CA, or attribute cert scope");
|
|
752
941
|
let t = [];
|
|
753
|
-
return e.distributionPoint !== void 0 && t.push(i(0, encodeDistributionPointName(e.distributionPoint))), e.onlyContainsUserCerts && t.push(a(1, Uint8Array.of(255))), e.onlyContainsCACerts && t.push(a(2, Uint8Array.of(255))), e.onlySomeReasons !== void 0 && e.onlySomeReasons.length > 0 && t.push(a(3, P(e.onlySomeReasons))), e.indirectCrl && t.push(a(4, Uint8Array.of(255))), e.onlyContainsAttributeCerts && t.push(a(5, Uint8Array.of(255))),
|
|
942
|
+
return e.distributionPoint !== void 0 && t.push(i(0, encodeDistributionPointName(e.distributionPoint))), e.onlyContainsUserCerts && t.push(a(1, Uint8Array.of(255))), e.onlyContainsCACerts && t.push(a(2, Uint8Array.of(255))), e.onlySomeReasons !== void 0 && e.onlySomeReasons.length > 0 && t.push(a(3, P(e.onlySomeReasons))), e.indirectCrl && t.push(a(4, Uint8Array.of(255))), e.onlyContainsAttributeCerts && t.push(a(5, Uint8Array.of(255))), f(t);
|
|
754
943
|
}
|
|
755
944
|
/** DER-encodes a DistributionPointName (fullName or relativeName). */
|
|
756
945
|
function encodeDistributionPointName(e) {
|
|
757
946
|
if (e === void 0) throw Error("IssuingDistributionPoint distributionPoint is required");
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
return i(1, t.slice(n.start, n.end));
|
|
947
|
+
switch (e.type) {
|
|
948
|
+
case "fullName": return e.fullName.length === 0 && throwCrlEncoderError("distribution_point_full_name_empty", "DistributionPointName fullName must not be empty"), i(0, concatGeneralNames(e.fullName));
|
|
949
|
+
case "relativeName": {
|
|
950
|
+
let t = B(e.relativeName), n = l(t);
|
|
951
|
+
return i(1, t.slice(n.start, n.end));
|
|
952
|
+
}
|
|
953
|
+
default: throw Error(`Unhandled DistributionPointName type: ${String(e)}`);
|
|
766
954
|
}
|
|
767
|
-
throw Error("DistributionPointName must contain fullName or relativeName");
|
|
768
955
|
}
|
|
769
956
|
/** DER-encodes and concatenates a list of GeneralName values. */
|
|
770
957
|
function concatGeneralNames(e) {
|
|
771
|
-
return t(e.map((e) =>
|
|
772
|
-
}
|
|
773
|
-
/** Re-wraps an implicitly-tagged directoryName as an explicit SEQUENCE (tag 0x30). */
|
|
774
|
-
/**
|
|
775
|
-
* Extracts the Name SEQUENCE from an implicitly-tagged directoryName [4].
|
|
776
|
-
*
|
|
777
|
-
* Handles two encoding styles found in the wild:
|
|
778
|
-
* - Proper implicit: [4] replaces SEQUENCE tag, content is RDN SETs directly → wrap with 0x30
|
|
779
|
-
* - Explicit-like: [4] wraps entire SEQUENCE, content starts with 0x30 → return content as-is
|
|
780
|
-
*/
|
|
781
|
-
function rebuildDirectoryNameFromImplicit(e) {
|
|
782
|
-
return e.value.length > 0 && e.value[0] === 48 ? new Uint8Array(e.value) : p(48, e.value);
|
|
958
|
+
return t(e.map((e) => G(e)));
|
|
783
959
|
}
|
|
784
960
|
/** Parses a Name SEQUENCE element into a full {@linkcode ParsedName}. */
|
|
785
961
|
function parseIssuer(e, t) {
|
|
786
|
-
let n =
|
|
787
|
-
for (let n of
|
|
962
|
+
let n = w(e.slice(t.start - t.headerLength, t.end)), r = [], i = [], a = {};
|
|
963
|
+
for (let n of h(e, t)) {
|
|
788
964
|
let t = [], o = {};
|
|
789
|
-
for (let r of
|
|
790
|
-
let n =
|
|
965
|
+
for (let r of h(e, n)) {
|
|
966
|
+
let n = h(e, r), s = C(n[0], "issuer attribute OID"), c = C(n[1], "issuer attribute value"), l = v(s.value), u;
|
|
791
967
|
try {
|
|
792
|
-
u =
|
|
968
|
+
u = y(c.tag, c.value);
|
|
793
969
|
} catch {
|
|
794
|
-
u =
|
|
970
|
+
u = oe.decode(c.value);
|
|
795
971
|
}
|
|
796
972
|
let d = I(l), f = d === void 0 ? {
|
|
797
973
|
oid: l,
|
|
@@ -806,7 +982,7 @@ function parseIssuer(e, t) {
|
|
|
806
982
|
t.push(f), i.push(f), d !== void 0 && (o[d] === void 0 && (o[d] = u), a[d] === void 0 && (a[d] = u));
|
|
807
983
|
}
|
|
808
984
|
r.push({
|
|
809
|
-
derHex:
|
|
985
|
+
derHex: w(e.slice(n.start - n.headerLength, n.end)),
|
|
810
986
|
attributes: t,
|
|
811
987
|
values: o
|
|
812
988
|
});
|
|
@@ -821,7 +997,7 @@ function parseIssuer(e, t) {
|
|
|
821
997
|
/** Re-parses a hex-encoded DER Name into a {@linkcode ParsedName}. Returns `undefined` on malformed input. */
|
|
822
998
|
function parseDerHexName(e) {
|
|
823
999
|
try {
|
|
824
|
-
let t =
|
|
1000
|
+
let t = x(e), n = unwrapNameElement(t, u(t, { maxDepth: 64 }));
|
|
825
1001
|
return n.tag === 48 ? parseIssuer(t, n) : void 0;
|
|
826
1002
|
} catch {
|
|
827
1003
|
return;
|
|
@@ -829,17 +1005,17 @@ function parseDerHexName(e) {
|
|
|
829
1005
|
}
|
|
830
1006
|
function unwrapNameElement(e, t) {
|
|
831
1007
|
if (t.tag !== 48) return t;
|
|
832
|
-
let n =
|
|
1008
|
+
let n = h(e, t), r = n[0];
|
|
833
1009
|
return n.length === 1 && r?.tag === 48 ? r : t;
|
|
834
1010
|
}
|
|
835
1011
|
/** Semantic comparison of a GeneralName directoryName `derHex` against a {@linkcode ParsedName}. */
|
|
836
1012
|
function directoryNameDerHexMatchesParsedName(e, t) {
|
|
837
1013
|
let n = parseDerHexName(e);
|
|
838
|
-
return n !== void 0 &&
|
|
1014
|
+
return n !== void 0 && L(n, t);
|
|
839
1015
|
}
|
|
840
1016
|
/** Extracts the keyIdentifier field from an AuthorityKeyIdentifier extension value. */
|
|
841
1017
|
function parseAuthorityKeyIdentifier(e) {
|
|
842
|
-
let t =
|
|
1018
|
+
let t = u(e, {
|
|
843
1019
|
maxDepth: 64,
|
|
844
1020
|
allowOpaqueConstructedTags: [161, 162]
|
|
845
1021
|
});
|
|
@@ -849,7 +1025,7 @@ function parseAuthorityKeyIdentifier(e) {
|
|
|
849
1025
|
sawAuthorityCertSerialNumber: !1,
|
|
850
1026
|
lastFieldOrder: -1
|
|
851
1027
|
};
|
|
852
|
-
for (let r of
|
|
1028
|
+
for (let r of h(e, t)) parseAuthorityKeyIdentifierField(e, r, n);
|
|
853
1029
|
return n.keyIdentifier;
|
|
854
1030
|
}
|
|
855
1031
|
function parseAuthorityKeyIdentifierField(e, t, n) {
|
|
@@ -869,12 +1045,12 @@ function parseAuthorityKeyIdentifierField(e, t, n) {
|
|
|
869
1045
|
function parseAuthorityKeyIdentifierKeyId(e, t) {
|
|
870
1046
|
if (t.keyIdentifier !== void 0) throw Error("authorityKeyIdentifier keyIdentifier must not repeat");
|
|
871
1047
|
if (t.lastFieldOrder >= 0) throw Error("authorityKeyIdentifier fields must preserve DER order");
|
|
872
|
-
t.keyIdentifier =
|
|
1048
|
+
t.keyIdentifier = w(e.value), t.lastFieldOrder = 0;
|
|
873
1049
|
}
|
|
874
1050
|
function parseAuthorityKeyIdentifierIssuer(e, t, n) {
|
|
875
1051
|
if (n.sawAuthorityCertIssuer) throw Error("authorityKeyIdentifier authorityCertIssuer must not repeat");
|
|
876
1052
|
if (n.lastFieldOrder >= 1) throw Error("authorityKeyIdentifier fields must preserve DER order");
|
|
877
|
-
|
|
1053
|
+
q(e, t), n.sawAuthorityCertIssuer = !0, n.lastFieldOrder = 1;
|
|
878
1054
|
}
|
|
879
1055
|
function parseAuthorityKeyIdentifierSerial(e, t) {
|
|
880
1056
|
if (t.sawAuthorityCertSerialNumber) throw Error("authorityKeyIdentifier authorityCertSerialNumber must not repeat");
|
|
@@ -887,11 +1063,15 @@ function validateImplicitSerialNumberEncoding(e, t) {
|
|
|
887
1063
|
if (n & 128) throw Error(`${t} must be non-negative`);
|
|
888
1064
|
if (e.length > 1 && n === 0 && !((e[1] ?? 0) & 128)) throw Error(`${t} must use minimal encoding`);
|
|
889
1065
|
}
|
|
1066
|
+
/** RFC 5280 §5.1.1.2: signatureAlgorithm MUST equal the tbsCertList signature field. */
|
|
1067
|
+
function assertMatchingCrlSignatureAlgorithms(e, t) {
|
|
1068
|
+
if (e.oid !== t.oid || !c(e.parametersDer, t.parametersDer)) throw Error("CRL signatureAlgorithm must match TBSCertList signature");
|
|
1069
|
+
}
|
|
890
1070
|
/** Extracts the algorithm OID from an AlgorithmIdentifier SEQUENCE. */
|
|
891
1071
|
function parseAlgorithmIdentifier(e, t) {
|
|
892
|
-
let n =
|
|
893
|
-
return i === void 0 ? { oid:
|
|
894
|
-
oid:
|
|
1072
|
+
let n = h(e, t), r = C(n[0], "algorithm OID"), i = n[1];
|
|
1073
|
+
return i === void 0 ? { oid: v(r.value) } : {
|
|
1074
|
+
oid: v(r.value),
|
|
895
1075
|
parametersDer: e.slice(i.start - i.headerLength, i.end)
|
|
896
1076
|
};
|
|
897
1077
|
}
|
|
@@ -916,11 +1096,11 @@ function revocationReasonFromCode(e) {
|
|
|
916
1096
|
}
|
|
917
1097
|
/** Thin wrapper — parses a DER-encoded certificate for use as a CRL issuer. */
|
|
918
1098
|
function parseIssuerCertificateDer(e) {
|
|
919
|
-
return
|
|
1099
|
+
return Y(e);
|
|
920
1100
|
}
|
|
921
1101
|
/** Thin wrapper — parses a PEM-encoded certificate for use as a CRL issuer. */
|
|
922
1102
|
function parseIssuerCertificatePem(e) {
|
|
923
|
-
return
|
|
1103
|
+
return Y(e);
|
|
924
1104
|
}
|
|
925
1105
|
/** Accepts PEM, DER, or already-parsed CRL and returns a parsed CRL. */
|
|
926
1106
|
function normalizeCrl(e) {
|
|
@@ -930,24 +1110,23 @@ function normalizeCrl(e) {
|
|
|
930
1110
|
throw Error("certificate revocation list input is malformed");
|
|
931
1111
|
}
|
|
932
1112
|
function parseSignedCrlFields(e) {
|
|
933
|
-
let t =
|
|
934
|
-
|
|
935
|
-
let
|
|
936
|
-
|
|
937
|
-
let
|
|
938
|
-
d?.tag === 48 && (s += 1);
|
|
939
|
-
let p = t[s], h = parseCrlExtensionFields(e, p, r);
|
|
1113
|
+
let t = h(e, u(e, { maxDepth: 64 })), n = parseCrlVersionField(t), r = n.version, i = C(t[n.nextIndex], "signature"), a = n.nextIndex + 1, o = C(t[a], "issuer"), s = C(t[a + 1], "thisUpdate"), c = a + 2, l = t[c], d = l !== void 0 && (l.tag === 23 || l.tag === 24) ? S(l) : void 0;
|
|
1114
|
+
d !== void 0 && (c += 1);
|
|
1115
|
+
let f = t[c], p = f?.tag === 48 ? parseRevokedCertificates(e, f, r) : [];
|
|
1116
|
+
f?.tag === 48 && (c += 1);
|
|
1117
|
+
let m = t[c], g = parseCrlExtensionFields(e, m, r);
|
|
940
1118
|
return {
|
|
941
1119
|
version: r,
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
...
|
|
946
|
-
...
|
|
947
|
-
...
|
|
948
|
-
...
|
|
949
|
-
...
|
|
950
|
-
|
|
1120
|
+
signature: parseAlgorithmIdentifier(e, i),
|
|
1121
|
+
issuer: parseIssuer(e, o),
|
|
1122
|
+
thisUpdate: S(s),
|
|
1123
|
+
...d === void 0 ? {} : { nextUpdate: d },
|
|
1124
|
+
...g.authorityKeyIdentifier === void 0 ? {} : { authorityKeyIdentifier: g.authorityKeyIdentifier },
|
|
1125
|
+
...g.crlNumber === void 0 ? {} : { crlNumber: g.crlNumber },
|
|
1126
|
+
...g.baseCrlNumber === void 0 ? {} : { baseCrlNumber: g.baseCrlNumber },
|
|
1127
|
+
...g.issuingDistributionPoint === void 0 ? {} : { issuingDistributionPoint: g.issuingDistributionPoint },
|
|
1128
|
+
...g.freshestCrlDistributionPoints === void 0 ? {} : { freshestCrlDistributionPoints: g.freshestCrlDistributionPoints },
|
|
1129
|
+
revokedCertificates: p
|
|
951
1130
|
};
|
|
952
1131
|
}
|
|
953
1132
|
function parseCrlVersionField(e) {
|
|
@@ -957,7 +1136,7 @@ function parseCrlVersionField(e) {
|
|
|
957
1136
|
version: 1,
|
|
958
1137
|
nextIndex: 0
|
|
959
1138
|
};
|
|
960
|
-
let n =
|
|
1139
|
+
let n = _(t.value) + 1;
|
|
961
1140
|
if (n !== 2) throw Error(`Unsupported CRL version: ${String(n)}`);
|
|
962
1141
|
return {
|
|
963
1142
|
version: n,
|
|
@@ -965,17 +1144,17 @@ function parseCrlVersionField(e) {
|
|
|
965
1144
|
};
|
|
966
1145
|
}
|
|
967
1146
|
function parseRevokedCertificates(e, t, n) {
|
|
968
|
-
return
|
|
1147
|
+
return h(e, t).map((t) => parseRevokedCertificateEntry(e, t, n));
|
|
969
1148
|
}
|
|
970
1149
|
function parseRevokedCertificateEntry(e, t, n) {
|
|
971
|
-
let r = e.slice(t.start - t.headerLength, t.end), i =
|
|
1150
|
+
let r = e.slice(t.start - t.headerLength, t.end), i = d(r), a = C(i[0], "revoked serialNumber");
|
|
972
1151
|
if (a.tag !== 2) throw Error("revoked serialNumber must use INTEGER");
|
|
973
1152
|
let o = i[2];
|
|
974
1153
|
if (o !== void 0 && n !== 2) throw Error("revoked certificate extensions require CRL version 2");
|
|
975
1154
|
let s = parseRevokedCertificateExtensions(r, o);
|
|
976
1155
|
return {
|
|
977
|
-
serialNumberHex:
|
|
978
|
-
revocationDate:
|
|
1156
|
+
serialNumberHex: w(a.value),
|
|
1157
|
+
revocationDate: S(C(i[1], "revocationDate")),
|
|
979
1158
|
...s.reasonCode === void 0 ? {} : { reasonCode: s.reasonCode },
|
|
980
1159
|
...s.invalidityDate === void 0 ? {} : { invalidityDate: s.invalidityDate },
|
|
981
1160
|
...s.certificateIssuer === void 0 ? {} : { certificateIssuer: s.certificateIssuer }
|
|
@@ -984,34 +1163,34 @@ function parseRevokedCertificateEntry(e, t, n) {
|
|
|
984
1163
|
function parseCrlExtensionFields(e, t, n) {
|
|
985
1164
|
if (t?.tag !== 160) return {};
|
|
986
1165
|
if (n !== 2) throw Error("CRL extensions require version 2");
|
|
987
|
-
let r = {}, i = /* @__PURE__ */ new Set(), a =
|
|
988
|
-
for (let t of
|
|
1166
|
+
let r = {}, i = /* @__PURE__ */ new Set(), a = C(h(e, t)[0], "crl extensions");
|
|
1167
|
+
for (let t of h(e, a)) parseCrlExtensionField(e, t, i, r);
|
|
989
1168
|
return r;
|
|
990
1169
|
}
|
|
991
1170
|
function parseCrlExtensionField(e, t, n, r) {
|
|
992
|
-
let i =
|
|
1171
|
+
let i = h(e, t);
|
|
993
1172
|
if (i.length < 2 || i.length > 3 || i.length === 3 && i[1]?.tag !== 1) throw Error("Malformed CRL extension");
|
|
994
|
-
let a =
|
|
1173
|
+
let a = v(C(i[0], "extension OID").value);
|
|
995
1174
|
if (n.has(a)) throw Error(`Duplicate CRL extension OID: ${a}`);
|
|
996
1175
|
n.add(a);
|
|
997
|
-
let o = i.length === 3 &&
|
|
1176
|
+
let o = i.length === 3 && g(C(i[1], "extension critical").value), s = C(i[i.length - 1], "extension value");
|
|
998
1177
|
if (s.tag !== 4) throw Error("CRL extension value must use OCTET STRING");
|
|
999
1178
|
if (!isSupportedCrlExtensionOid(a) && o) throw Error(`Unsupported critical CRL extension OID: ${a}`);
|
|
1000
1179
|
applyParsedCrlExtensionField(a, s.value, r);
|
|
1001
1180
|
}
|
|
1002
1181
|
function isSupportedCrlExtensionOid(e) {
|
|
1003
|
-
return e ===
|
|
1182
|
+
return e === T.authorityKeyIdentifier || e === T.cRLNumber || e === T.deltaCRLIndicator || e === T.issuingDistributionPoint || e === T.freshestCRL;
|
|
1004
1183
|
}
|
|
1005
1184
|
function applyParsedCrlExtensionField(e, t, n) {
|
|
1006
|
-
if (e ===
|
|
1185
|
+
if (e === T.authorityKeyIdentifier) {
|
|
1007
1186
|
let e = parseAuthorityKeyIdentifier(t);
|
|
1008
1187
|
e !== void 0 && (n.authorityKeyIdentifier = e);
|
|
1009
1188
|
}
|
|
1010
|
-
e ===
|
|
1189
|
+
e === T.cRLNumber && (n.crlNumber = _(l(t).value)), e === T.deltaCRLIndicator && (n.baseCrlNumber = _(l(t).value)), e === T.issuingDistributionPoint && (n.issuingDistributionPoint = parseIssuingDistributionPoint(t)), e === T.freshestCRL && (n.freshestCrlDistributionPoints = parseDistributionPoints(t));
|
|
1011
1190
|
}
|
|
1012
1191
|
/** Accepts PEM, DER, or already-parsed certificate and returns a parsed certificate. */
|
|
1013
1192
|
function normalizeCrlCertificate(e) {
|
|
1014
|
-
return hasParsedCertificateShape(e) ?
|
|
1193
|
+
return hasParsedCertificateShape(e) ? J(new Uint8Array(e.der)) : Y(e);
|
|
1015
1194
|
}
|
|
1016
1195
|
function hasParsedCertificateShape(e) {
|
|
1017
1196
|
return typeof e != "string" && "subjectPublicKeyInfoDer" in e;
|
|
@@ -1020,8 +1199,8 @@ function hasReparseableCrlShape(e) {
|
|
|
1020
1199
|
return "der" in e && e.der instanceof Uint8Array;
|
|
1021
1200
|
}
|
|
1022
1201
|
/** Shared UTF-8 decoder instance. */
|
|
1023
|
-
const
|
|
1202
|
+
const oe = new TextDecoder();
|
|
1024
1203
|
//#endregion
|
|
1025
|
-
export { checkCertificateRevocationAgainstCrl, createCertificateRevocationList, isCertificateRevoked, parseCertificateRevocationListDer, parseCertificateRevocationListDerOrThrow, parseCertificateRevocationListPem, parseCertificateRevocationListPemOrThrow, revocationReasonFromCode, validateCertificateRevocationList, verifyCertificateRevocationListSignature };
|
|
1204
|
+
export { Q as ALL_DISTRIBUTION_POINT_REASONS, checkCertificateRevocationAgainstCrl, coversAllDistributionPointReasons, createCertificateRevocationList, isCertificateRevoked, parseCertificateRevocationListDer, parseCertificateRevocationListDerOrThrow, parseCertificateRevocationListPem, parseCertificateRevocationListPemOrThrow, revocationReasonFromCode, validateCertificateRevocationList, verifyCertificateRevocationListSignature };
|
|
1026
1205
|
|
|
1027
1206
|
//# sourceMappingURL=crl.js.map
|