micro509 0.17.1 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +78 -6
- package/dist/crypto/crypto.d.ts +2 -3
- package/dist/crypto.d.ts +6 -0
- package/dist/der/der.d.ts +14 -4
- package/dist/der/der.js +19 -19
- package/dist/der.d.ts +26 -2
- package/dist/der.js +4 -4
- package/dist/index.d.ts +82 -15
- package/dist/index.js +19 -19
- package/dist/internal/asn1/asn1.d.ts +1 -2
- package/dist/internal/asn1/der.d.ts +1 -2
- package/dist/internal/asn1/oids.js +71 -353
- package/dist/internal/asn1/oids.js.map +1 -1
- package/dist/internal/asn1/oids.json.js +357 -0
- package/dist/internal/asn1/oids.json.js.map +1 -0
- package/dist/internal/crypto/algorithm-names.js +1 -1
- package/dist/internal/crypto/pbes2.d.ts +1 -2
- package/dist/internal/crypto/pbes2.js +70 -70
- package/dist/internal/crypto/prime-ec.js +37 -0
- package/dist/internal/crypto/prime-ec.js.map +1 -0
- package/dist/internal/crypto/rsa-pss.js +50 -50
- package/dist/internal/crypto/sig-verify.d.ts +1 -2
- package/dist/internal/crypto/sig-verify.js +60 -60
- package/dist/internal/crypto/signing.d.ts +1 -2
- package/dist/internal/crypto/signing.js +26 -26
- package/dist/internal/jose/json-data.js +108 -0
- package/dist/internal/jose/json-data.js.map +1 -0
- package/dist/internal/jose/strict-json.d.ts +1 -2
- package/dist/internal/shared/dn.d.ts +1 -2
- package/dist/internal/shared/dn.js +1 -1
- package/dist/internal/shared/ip.d.ts +1 -2
- package/dist/internal/verify/name-constraints-engine.js +64 -64
- package/dist/internal/verify/policy-engine.js +1 -1
- package/dist/internal/verify/verify-path.d.ts +1 -2
- package/dist/internal/verify/verify-path.js +19 -19
- package/dist/internal/x509/directory-name.js +10 -10
- package/dist/internal/x509/extension-errors.d.ts +1 -2
- package/dist/internal/x509/extension-registry.js +18 -18
- package/dist/internal/x509/general-name-profile.js +9 -9
- package/dist/internal/x509/general-name.js +32 -32
- package/dist/internal/x509/name-fields.js +1 -1
- package/dist/jose/base64url.d.ts +4 -0
- package/dist/jose/base64url.js +14 -0
- package/dist/jose/base64url.js.map +1 -0
- package/dist/jose/errors.d.ts +9 -3
- package/dist/jose/errors.js.map +1 -1
- package/dist/jose/jwe.d.ts +64 -0
- package/dist/jose/jwe.js +188 -0
- package/dist/jose/jwe.js.map +1 -0
- package/dist/jose/jwks.d.ts +38 -10
- package/dist/jose/jwks.js +156 -96
- package/dist/jose/jwks.js.map +1 -1
- package/dist/jose/jws.d.ts +8 -6
- package/dist/jose/jws.js +216 -170
- package/dist/jose/jws.js.map +1 -1
- package/dist/jose/jwt.d.ts +8 -2
- package/dist/jose/jwt.js +98 -98
- package/dist/jose/remote-jwks.d.ts +1 -2
- package/dist/jose/remote-jwks.js +106 -108
- package/dist/jose/remote-jwks.js.map +1 -1
- package/dist/jose.d.ts +15 -4
- package/dist/jose.js +7 -5
- package/dist/kdf/argon2.d.ts +7 -2
- package/dist/kdf.d.ts +6 -0
- package/dist/keys/keys.d.ts +31 -6
- package/dist/keys/keys.js +315 -233
- package/dist/keys/keys.js.map +1 -1
- package/dist/keys.d.ts +11 -2
- package/dist/keys.js +2 -2
- package/dist/pem/pem.d.ts +1 -2
- package/dist/pem/pem.js +40 -25
- package/dist/pem/pem.js.map +1 -1
- package/dist/pem.d.ts +6 -0
- package/dist/pkcs/pfx.d.ts +2 -3
- package/dist/pkcs/pfx.js +142 -142
- package/dist/pkcs/pkcs12-mac.d.ts +1 -2
- package/dist/pkcs/pkcs12-mac.js +122 -122
- package/dist/pkcs/pkcs7.d.ts +14 -3
- package/dist/pkcs/pkcs7.js +268 -248
- package/dist/pkcs/pkcs7.js.map +1 -1
- package/dist/pkcs.d.ts +10 -1
- package/dist/pkcs.js +4 -4
- package/dist/result/result.d.ts +1 -2
- package/dist/result.d.ts +6 -0
- package/dist/revocation/chain.d.ts +2 -3
- package/dist/revocation/chain.js +52 -52
- package/dist/revocation/crl.d.ts +2 -3
- package/dist/revocation/crl.js +319 -319
- package/dist/revocation/crl.js.map +1 -1
- package/dist/revocation/ocsp.d.ts +2 -3
- package/dist/revocation/ocsp.js +395 -395
- package/dist/revocation/revocation.d.ts +2 -3
- package/dist/revocation/revocation.js +22 -22
- package/dist/revocation.d.ts +12 -3
- package/dist/revocation.js +4 -4
- package/dist/ssh/ssh.d.ts +2 -3
- package/dist/ssh/ssh.js +165 -170
- package/dist/ssh/ssh.js.map +1 -1
- package/dist/ssh/wire.d.ts +1 -2
- package/dist/ssh/wire.js +10 -10
- package/dist/ssh.d.ts +8 -0
- package/dist/verify/identity.d.ts +1 -2
- package/dist/verify/identity.js +31 -31
- package/dist/verify/name-constraints.d.ts +9 -2
- package/dist/verify/policy.d.ts +9 -2
- package/dist/verify/verify.d.ts +3 -4
- package/dist/verify/verify.js +121 -121
- package/dist/verify.d.ts +9 -0
- package/dist/x509/certificate.d.ts +4 -5
- package/dist/x509/certificate.js +40 -40
- package/dist/x509/csr.d.ts +3 -4
- package/dist/x509/csr.js +15 -15
- package/dist/x509/extensions.d.ts +1 -2
- package/dist/x509/extensions.js +165 -165
- package/dist/x509/extensions.js.map +1 -1
- package/dist/x509/fingerprint.d.ts +1 -2
- package/dist/x509/name-text.d.ts +1 -2
- package/dist/x509/name.d.ts +1 -2
- package/dist/x509/name.js +15 -15
- package/dist/x509/parse.d.ts +3 -4
- package/dist/x509/parse.js +423 -423
- package/dist/x509.d.ts +17 -4
- package/dist/x509.js +8 -8
- package/package.json +22 -23
- package/dist/internal/asn1/oids2.js +0 -75
- package/dist/internal/asn1/oids2.js.map +0 -1
package/dist/revocation/crl.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { decodeFailureResult as
|
|
3
|
-
import { bitString as
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { childrenOf as e, decodeBoolean as t, decodeIntegerMagnitude as n, decodeIntegerNumber as r, decodeNonNegativeIntegerBigInt as i, decodeObjectIdentifier as a, decodeString as o, extractBitStringValue as s, hexToBytes as c, parseTime as l, requireElement as u, toHex as d } from "../internal/asn1/asn1.js";
|
|
2
|
+
import { decodeFailureResult as f, decodeRefusalOf as p, rethrowDecodeRefusal as m } from "../internal/asn1/decode-refusal.js";
|
|
3
|
+
import { bitString as h, concatBytes as g, explicitContext as _, generalizedTime as v, implicitConstructedContext as y, implicitPrimitiveContext as b, integer as x, integerFromNumber as S, optionalBytesEqual as ee, readElement as C, readRootElement as w, readSequenceChildren as T, sequence as E, time as D, tlv as O } from "../internal/asn1/der.js";
|
|
4
|
+
import { OIDS as k } from "../internal/asn1/oids.js";
|
|
5
|
+
import { describeSignatureAlgorithm as A } from "../internal/crypto/algorithm-names.js";
|
|
6
|
+
import { verifySignedDataDetailed as j } from "../internal/crypto/sig-verify.js";
|
|
7
|
+
import { encodeAlgorithmIdentifier as M, getSignatureAlgorithm as te, signBytes as N } from "../internal/crypto/signing.js";
|
|
6
8
|
import { base64Encode as P } from "../internal/shared/base64.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import { encodeCrlDistributionPoints as ae, encodeExtension as X, encodeSubjectAltName as oe, issuerKeyIdentifier as se } from "../x509/extensions.js";
|
|
18
|
-
import { parseCertificateDerOrThrow as ce, parseCertificateFromSource as Z } from "../x509/parse.js";
|
|
9
|
+
import { compareDistinguishedNames as F, compareRelativeDistinguishedNames as I } from "../internal/shared/dn.js";
|
|
10
|
+
import { encodeDistributionPointReasonFlagsContent as L, parseDistributionPointReasonFlagsContent as R } from "../internal/x509/extension-bits.js";
|
|
11
|
+
import { parseGeneralName as ne, parseGeneralNames as z } from "../internal/x509/general-name.js";
|
|
12
|
+
import { parsePresentedSrvName as B } from "../internal/x509/general-name-profile.js";
|
|
13
|
+
import { pemDecodeOrThrow as re, pemEncode as V } from "../pem/pem.js";
|
|
14
|
+
import { nameFieldKeyFromOid as H } from "../internal/x509/name-fields.js";
|
|
15
|
+
import { DECODE_REFUSAL_CODES as U, failureResult as W, rethrowIfInvariant as G, successResult as K, throwMicro509Error as q } from "../result/result.js";
|
|
16
|
+
import { encodeCrlDistributionPoints as J, encodeExtension as Y, encodeSubjectAltName as ie, issuerKeyIdentifier as ae } from "../x509/extensions.js";
|
|
17
|
+
import { encodeName as oe, encodeRelativeDistinguishedName as se, isNameInputEmpty as ce } from "../x509/name.js";
|
|
18
|
+
import { parseCertificateDerOrThrow as le, parseCertificateFromSource as X } from "../x509/parse.js";
|
|
19
19
|
// src/revocation/crl.ts
|
|
20
20
|
/**
|
|
21
21
|
* Full CRL lifecycle: create, parse, verify, validate, and revocation check.
|
|
@@ -26,7 +26,7 @@ import { parseCertificateDerOrThrow as ce, parseCertificateFromSource as Z } fro
|
|
|
26
26
|
* @module
|
|
27
27
|
*/
|
|
28
28
|
/** RFC 5280 §5.3.1 CRLReason integer codes, keyed by reason name. */
|
|
29
|
-
const
|
|
29
|
+
const ue = {
|
|
30
30
|
unspecified: 0,
|
|
31
31
|
keyCompromise: 1,
|
|
32
32
|
cACompromise: 2,
|
|
@@ -37,7 +37,7 @@ const le = {
|
|
|
37
37
|
removeFromCRL: 8,
|
|
38
38
|
privilegeWithdrawn: 9,
|
|
39
39
|
aACompromise: 10
|
|
40
|
-
},
|
|
40
|
+
}, Z = Object.freeze([
|
|
41
41
|
"keyCompromise",
|
|
42
42
|
"cACompromise",
|
|
43
43
|
"affiliationChanged",
|
|
@@ -50,7 +50,7 @@ const le = {
|
|
|
50
50
|
/** True when `reasons` covers every RFC 5280 §4.2.1.13 reason — a complete-scope CRL verdict. */
|
|
51
51
|
function coversAllDistributionPointReasons(e) {
|
|
52
52
|
let t = e instanceof Set ? e : new Set(e);
|
|
53
|
-
return
|
|
53
|
+
return Z.every((e) => t.has(e));
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
56
56
|
* Signs and encodes an X.509 v2 CRL.
|
|
@@ -78,28 +78,28 @@ function coversAllDistributionPointReasons(e) {
|
|
|
78
78
|
* ```
|
|
79
79
|
*/
|
|
80
80
|
async function createCertificateRevocationList(e) {
|
|
81
|
-
|
|
82
|
-
let t = issuerCertificateOf(e.issuerCertificate), n = encodeCrlNumber(e.crlNumber, "crlNumber"), r = e.baseCrlNumber === void 0 ? void 0 : encodeCrlNumber(e.baseCrlNumber, "baseCrlNumber"), i =
|
|
81
|
+
ce(e.issuer) && throwCrlEncoderError("issuer_distinguished_name_empty", "issuer must be a non-empty distinguished name");
|
|
82
|
+
let t = issuerCertificateOf(e.issuerCertificate), n = encodeCrlNumber(e.crlNumber, "crlNumber"), r = e.baseCrlNumber === void 0 ? void 0 : encodeCrlNumber(e.baseCrlNumber, "baseCrlNumber"), i = te(e.signerPrivateKey), a = e.thisUpdate ?? /* @__PURE__ */ new Date(), o = e.nextUpdate;
|
|
83
83
|
assertCrlDate(a, "thisUpdate"), assertCrlDate(o, "nextUpdate");
|
|
84
84
|
for (let t of e.revokedCertificates ?? []) assertCrlDate(t.revocationDate, "revocationDate"), assertCrlDate(t.invalidityDate, "invalidityDate");
|
|
85
85
|
Math.floor(o.getTime() / 1e3) <= Math.floor(a.getTime() / 1e3) && throwCrlEncoderError("next_update_not_after_this_update", "nextUpdate must be at least one second later than thisUpdate");
|
|
86
|
-
let s = buildCrlExtensions(t, n, r, e.issuingDistributionPoint, e.freshestCrlDistributionPoints),
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
...
|
|
93
|
-
|
|
94
|
-
]),
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
86
|
+
let s = buildCrlExtensions(t, n, r, e.issuingDistributionPoint, e.freshestCrlDistributionPoints), c = e.revokedCertificates ?? [], l = c.length === 0 ? [] : [E(c.map((e) => createRevokedCertificate(e, a)))], u = E([
|
|
87
|
+
S(1),
|
|
88
|
+
M(i),
|
|
89
|
+
oe(e.issuer),
|
|
90
|
+
D(a),
|
|
91
|
+
D(o),
|
|
92
|
+
...l,
|
|
93
|
+
_(0, E(s))
|
|
94
|
+
]), d = await N(e.signerPrivateKey, i, u), f = E([
|
|
95
|
+
u,
|
|
96
|
+
M(i),
|
|
97
|
+
h(d)
|
|
98
98
|
]);
|
|
99
99
|
return {
|
|
100
|
-
der:
|
|
101
|
-
pem:
|
|
102
|
-
base64: P(
|
|
100
|
+
der: f,
|
|
101
|
+
pem: V("X509 CRL", f),
|
|
102
|
+
base64: P(f)
|
|
103
103
|
};
|
|
104
104
|
}
|
|
105
105
|
/**
|
|
@@ -109,19 +109,19 @@ async function createCertificateRevocationList(e) {
|
|
|
109
109
|
* {@linkcode validateCertificateRevocationList} for that.
|
|
110
110
|
*/
|
|
111
111
|
function parseCertificateRevocationListDerOrThrow(e) {
|
|
112
|
-
let t =
|
|
112
|
+
let t = T(e, { maxDepth: 64 });
|
|
113
113
|
if (t.length !== 3) throw Error("Malformed CRL");
|
|
114
|
-
let n =
|
|
114
|
+
let n = u(t[0], "TBSCertList"), r = u(t[1], "signatureAlgorithm"), i = u(t[2], "signatureValue"), a = parseSignedCrlFields(e.slice(n.start - n.headerLength, n.end)), o = parseAlgorithmIdentifier(e, r);
|
|
115
115
|
return assertMatchingCrlSignatureAlgorithms(a.signature, o), {
|
|
116
116
|
der: new Uint8Array(e),
|
|
117
117
|
version: a.version,
|
|
118
118
|
tbsCertListDer: e.slice(n.start - n.headerLength, n.end),
|
|
119
|
-
signatureValue:
|
|
119
|
+
signatureValue: s(i),
|
|
120
120
|
issuer: a.issuer,
|
|
121
121
|
thisUpdate: a.thisUpdate,
|
|
122
122
|
...a.nextUpdate === void 0 ? {} : { nextUpdate: a.nextUpdate },
|
|
123
123
|
signatureAlgorithmOid: o.oid,
|
|
124
|
-
signatureAlgorithmName:
|
|
124
|
+
signatureAlgorithmName: A(o.oid, o.parametersDer),
|
|
125
125
|
...o.parametersDer === void 0 ? {} : { signatureAlgorithmParametersDer: o.parametersDer },
|
|
126
126
|
...a.authorityKeyIdentifier === void 0 ? {} : { authorityKeyIdentifier: a.authorityKeyIdentifier },
|
|
127
127
|
...a.crlNumber === void 0 ? {} : { crlNumber: a.crlNumber },
|
|
@@ -143,7 +143,7 @@ function parseCertificateRevocationListDerOrThrow(e) {
|
|
|
143
143
|
* ```
|
|
144
144
|
*/
|
|
145
145
|
function parseCertificateRevocationListPemOrThrow(e) {
|
|
146
|
-
return parseCertificateRevocationListDerOrThrow(
|
|
146
|
+
return parseCertificateRevocationListDerOrThrow(re("X509 CRL", e));
|
|
147
147
|
}
|
|
148
148
|
/**
|
|
149
149
|
* Decodes a DER-encoded X.509 CRL into a structured {@linkcode ParsedCertificateRevocationList}.
|
|
@@ -153,11 +153,11 @@ function parseCertificateRevocationListPemOrThrow(e) {
|
|
|
153
153
|
* Does not verify the signature — call {@linkcode verifyCertificateRevocationListSignature} or
|
|
154
154
|
* {@linkcode validateCertificateRevocationList} for that.
|
|
155
155
|
*/
|
|
156
|
-
function parseCertificateRevocationListDer(
|
|
156
|
+
function parseCertificateRevocationListDer(e) {
|
|
157
157
|
try {
|
|
158
|
-
return
|
|
159
|
-
} catch (
|
|
160
|
-
return
|
|
158
|
+
return K(parseCertificateRevocationListDerOrThrow(e));
|
|
159
|
+
} catch (e) {
|
|
160
|
+
return G(e), f(e, U, "Malformed CRL");
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
/**
|
|
@@ -166,11 +166,11 @@ function parseCertificateRevocationListDer(t) {
|
|
|
166
166
|
* Returns a typed failure (`code: 'malformed'`) on malformed input. For the
|
|
167
167
|
* throwing form use {@linkcode parseCertificateRevocationListPemOrThrow}.
|
|
168
168
|
*/
|
|
169
|
-
function parseCertificateRevocationListPem(
|
|
169
|
+
function parseCertificateRevocationListPem(e) {
|
|
170
170
|
try {
|
|
171
|
-
return
|
|
172
|
-
} catch (
|
|
173
|
-
return
|
|
171
|
+
return K(parseCertificateRevocationListPemOrThrow(e));
|
|
172
|
+
} catch (e) {
|
|
173
|
+
return G(e), f(e, U, "Malformed CRL");
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
176
|
/**
|
|
@@ -179,25 +179,25 @@ function parseCertificateRevocationListPem(t) {
|
|
|
179
179
|
* Does **not** check issuer name match, key-usage, or freshness — use
|
|
180
180
|
* {@linkcode validateCertificateRevocationList} for full validation.
|
|
181
181
|
*/
|
|
182
|
-
async function verifyCertificateRevocationListSignature(
|
|
183
|
-
let
|
|
182
|
+
async function verifyCertificateRevocationListSignature(e, t) {
|
|
183
|
+
let n, r;
|
|
184
184
|
try {
|
|
185
|
-
|
|
186
|
-
} catch (
|
|
187
|
-
let
|
|
188
|
-
return
|
|
185
|
+
n = typeof e == "string" ? parseCertificateRevocationListPemOrThrow(e) : parseCertificateRevocationListDerOrThrow(new Uint8Array(e)), r = typeof t == "string" ? parseIssuerCertificatePem(t) : parseIssuerCertificateDer(new Uint8Array(t));
|
|
186
|
+
} catch (e) {
|
|
187
|
+
let t = p(e, U);
|
|
188
|
+
return t === void 0 ? verifyCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list or issuer certificate input is malformed") : verifyCertificateRevocationListFailureResult(t.code, t.message);
|
|
189
189
|
}
|
|
190
|
-
let
|
|
190
|
+
let i;
|
|
191
191
|
try {
|
|
192
|
-
|
|
193
|
-
} catch (
|
|
194
|
-
let
|
|
195
|
-
return
|
|
192
|
+
i = await j(n.signatureAlgorithmOid, n.signatureAlgorithmParametersDer, r.publicKeyAlgorithmOid, r.publicKeyParametersOid, r.subjectPublicKeyInfoDer, n.signatureValue, n.tbsCertListDer);
|
|
193
|
+
} catch (e) {
|
|
194
|
+
let t = p(e, U);
|
|
195
|
+
return t === void 0 ? verifyCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature verification failed") : verifyCertificateRevocationListFailureResult(t.code, t.message);
|
|
196
196
|
}
|
|
197
|
-
return
|
|
197
|
+
return i.ok ? i.valid ? {
|
|
198
198
|
ok: !0,
|
|
199
|
-
value:
|
|
200
|
-
} : verifyCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature does not verify") :
|
|
199
|
+
value: n
|
|
200
|
+
} : verifyCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature does not verify") : i.code === "verification_error" ? verifyCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature verification failed") : verifyCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature uses unsupported algorithm parameters");
|
|
201
201
|
}
|
|
202
202
|
/**
|
|
203
203
|
* Full CRL validation: issuer name match, authority key identifier match,
|
|
@@ -220,36 +220,36 @@ async function validateCertificateRevocationList(e) {
|
|
|
220
220
|
*
|
|
221
221
|
* @internal
|
|
222
222
|
*/
|
|
223
|
-
async function authenticateCrl(
|
|
224
|
-
let
|
|
223
|
+
async function authenticateCrl(e, t) {
|
|
224
|
+
let n;
|
|
225
225
|
try {
|
|
226
|
-
|
|
227
|
-
} catch (
|
|
228
|
-
let
|
|
229
|
-
return
|
|
226
|
+
n = normalizeCrl(e);
|
|
227
|
+
} catch (e) {
|
|
228
|
+
let t = p(e, U);
|
|
229
|
+
return t === void 0 ? validateCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signed content is malformed") : validateCertificateRevocationListFailureResult(t.code, t.message);
|
|
230
230
|
}
|
|
231
|
-
let
|
|
231
|
+
let r;
|
|
232
232
|
try {
|
|
233
|
-
|
|
234
|
-
} catch (
|
|
235
|
-
let
|
|
236
|
-
return
|
|
233
|
+
r = normalizeCrlCertificate(t);
|
|
234
|
+
} catch (e) {
|
|
235
|
+
let t = p(e, U);
|
|
236
|
+
return t === void 0 ? validateCertificateRevocationListFailureResult("signature_invalid", "issuer certificate input is malformed") : validateCertificateRevocationListFailureResult(t.code, t.message);
|
|
237
237
|
}
|
|
238
|
-
if (!
|
|
239
|
-
if (
|
|
240
|
-
if (
|
|
241
|
-
if (
|
|
242
|
-
let
|
|
238
|
+
if (!F(n.issuer, r.subject)) return validateCertificateRevocationListFailureResult("issuer_mismatch", "CRL issuer name does not match certificate subject");
|
|
239
|
+
if (n.authorityKeyIdentifier !== void 0 && r.subjectKeyIdentifier !== void 0 && n.authorityKeyIdentifier !== r.subjectKeyIdentifier) return validateCertificateRevocationListFailureResult("issuer_mismatch", "CRL authority key identifier does not match issuer subject key identifier");
|
|
240
|
+
if (r.keyUsage === void 0 && r.version === 3) return validateCertificateRevocationListFailureResult("crl_sign_not_permitted", "v3 issuer certificate has no key usage extension");
|
|
241
|
+
if (r.keyUsage !== void 0 && !r.keyUsage.flags.includes("cRLSign")) return validateCertificateRevocationListFailureResult("crl_sign_not_permitted", "issuer certificate key usage does not permit CRL signing");
|
|
242
|
+
let i;
|
|
243
243
|
try {
|
|
244
|
-
|
|
245
|
-
} catch (
|
|
246
|
-
let
|
|
247
|
-
return
|
|
244
|
+
i = await j(n.signatureAlgorithmOid, n.signatureAlgorithmParametersDer, r.publicKeyAlgorithmOid, r.publicKeyParametersOid, r.subjectPublicKeyInfoDer, n.signatureValue, n.tbsCertListDer);
|
|
245
|
+
} catch (e) {
|
|
246
|
+
let t = p(e, U);
|
|
247
|
+
return t === void 0 ? validateCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature verification failed") : validateCertificateRevocationListFailureResult(t.code, t.message);
|
|
248
248
|
}
|
|
249
|
-
return
|
|
249
|
+
return i.ok ? i.valid ? {
|
|
250
250
|
ok: !0,
|
|
251
|
-
value:
|
|
252
|
-
} : validateCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature does not verify") :
|
|
251
|
+
value: n
|
|
252
|
+
} : validateCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature does not verify") : i.code === "verification_error" ? validateCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature verification failed") : validateCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature uses unsupported algorithm parameters");
|
|
253
253
|
}
|
|
254
254
|
function assertCrlMaxAge(e) {
|
|
255
255
|
if (e !== void 0 && (!Number.isFinite(e) || e < 0)) throw RangeError(`Invalid maxAgeMs: must be a non-negative number, got ${e}`);
|
|
@@ -284,19 +284,19 @@ function isCurrentDeltaCrl(e, t, n, r) {
|
|
|
284
284
|
* }
|
|
285
285
|
* ```
|
|
286
286
|
*/
|
|
287
|
-
async function checkCertificateRevocationAgainstCrl(
|
|
288
|
-
assertCrlMaxAge(
|
|
289
|
-
let
|
|
287
|
+
async function checkCertificateRevocationAgainstCrl(e) {
|
|
288
|
+
assertCrlMaxAge(e.maxAgeMs);
|
|
289
|
+
let t;
|
|
290
290
|
try {
|
|
291
|
-
|
|
292
|
-
} catch (
|
|
293
|
-
let
|
|
294
|
-
return
|
|
291
|
+
t = normalizeCrlCertificate(e.certificate);
|
|
292
|
+
} catch (e) {
|
|
293
|
+
let t = p(e, U);
|
|
294
|
+
return t === void 0 ? checkCertificateRevocationAgainstCrlFailureResult("non_applicable", "certificate input is malformed") : checkCertificateRevocationAgainstCrlFailureResult(t.code, t.message);
|
|
295
295
|
}
|
|
296
|
-
let
|
|
297
|
-
if (!
|
|
298
|
-
let
|
|
299
|
-
return
|
|
296
|
+
let n = await authenticateCrl(e.crl, e.issuerCertificate);
|
|
297
|
+
if (!n.ok) return checkCertificateRevocationAgainstCrlFailureResult(n.code, n.message);
|
|
298
|
+
let r = await checkRevocationAgainstAuthenticatedCrl(t, n.value, e);
|
|
299
|
+
return r.kind === "checked" ? r.result : r.failure;
|
|
300
300
|
}
|
|
301
301
|
/**
|
|
302
302
|
* Checks `certificate` against a complete CRL that {@linkcode authenticateCrl}
|
|
@@ -352,7 +352,7 @@ async function checkRevocationAgainstAuthenticatedCrl(e, t, n) {
|
|
|
352
352
|
/** RFC 5280 §6.3.3 (d): interim_reasons_mask from the matched DP and the CRL's IDP. */
|
|
353
353
|
function interimReasonsMask(e, t) {
|
|
354
354
|
let n = e?.reasons?.flags, r = t?.onlySomeReasons?.flags;
|
|
355
|
-
return n !== void 0 && r !== void 0 ? n.filter((e) => r.includes(e)) : n === void 0 ? r === void 0 ?
|
|
355
|
+
return n !== void 0 && r !== void 0 ? n.filter((e) => r.includes(e)) : n === void 0 ? r === void 0 ? Z : [...r] : [...n];
|
|
356
356
|
}
|
|
357
357
|
/** Validates an optional delta CRL and checks compatibility with its complete CRL. */
|
|
358
358
|
async function validateOptionalDeltaCrl(e, t) {
|
|
@@ -378,16 +378,16 @@ async function validateOptionalDeltaCrl(e, t) {
|
|
|
378
378
|
};
|
|
379
379
|
}
|
|
380
380
|
/** Builds a `VerifyCertificateRevocationListSignatureFailureResult`. */
|
|
381
|
-
function verifyCertificateRevocationListFailureResult(e,
|
|
382
|
-
return
|
|
381
|
+
function verifyCertificateRevocationListFailureResult(e, t) {
|
|
382
|
+
return W(e, t);
|
|
383
383
|
}
|
|
384
384
|
/** Builds a `ValidateCertificateRevocationListFailureResult`. */
|
|
385
|
-
function validateCertificateRevocationListFailureResult(e,
|
|
386
|
-
return
|
|
385
|
+
function validateCertificateRevocationListFailureResult(e, t) {
|
|
386
|
+
return W(e, t);
|
|
387
387
|
}
|
|
388
388
|
/** Builds a `CheckCertificateRevocationAgainstCrlFailureResult`. */
|
|
389
|
-
function checkCertificateRevocationAgainstCrlFailureResult(e,
|
|
390
|
-
return
|
|
389
|
+
function checkCertificateRevocationAgainstCrlFailureResult(e, t, n) {
|
|
390
|
+
return W(e, t, n);
|
|
391
391
|
}
|
|
392
392
|
/** Wraps a success value into a `CheckCertificateRevocationAgainstCrlResult`. */
|
|
393
393
|
function checkCertificateRevocationAgainstCrlSuccess(e) {
|
|
@@ -401,7 +401,7 @@ function checkCertificateRevocationAgainstCrlSuccess(e) {
|
|
|
401
401
|
* CRL's revoked entries. Does **not** validate the CRL or check applicability.
|
|
402
402
|
*/
|
|
403
403
|
function isCertificateRevoked(e, t) {
|
|
404
|
-
let n = typeof e == "string" ? normalizeHex(e) :
|
|
404
|
+
let n = typeof e == "string" ? normalizeHex(e) : d(e);
|
|
405
405
|
return t.revokedCertificates.some((e) => normalizeHex(e.serialNumberHex) === n);
|
|
406
406
|
}
|
|
407
407
|
/** Searches CRL entries for the certificate's serial, respecting indirect-CRL issuer overrides. */
|
|
@@ -449,13 +449,13 @@ function checkCrlApplicability(e, t, n = !1) {
|
|
|
449
449
|
function evaluateCrlApplicability(e, t, n) {
|
|
450
450
|
if (!n && t.baseCrlNumber !== void 0) return notApplicableOutcome("unsupported_delta_crl", "a delta CRL cannot be used as the primary complete CRL input");
|
|
451
451
|
let r = t.issuingDistributionPoint, i = r?.indirectCrl === !0;
|
|
452
|
-
if (!i && !
|
|
452
|
+
if (!i && !F(e.issuer, t.issuer)) return notApplicableOutcome("issuer_mismatch", "CRL issuer does not match certificate issuer for direct CRL processing");
|
|
453
453
|
if (r?.onlyContainsAttributeCerts === !0) return notApplicableOutcome("certificate_scope_mismatch", "attribute-certificate-only CRLs are not applicable to public-key certificates");
|
|
454
454
|
let a = e.basicConstraints?.ca === !0;
|
|
455
455
|
if (r?.onlyContainsUserCerts === !0 && a) return notApplicableOutcome("certificate_scope_mismatch", "CRL only applies to end-entity certificates");
|
|
456
456
|
if (r?.onlyContainsCACerts === !0 && !a) return notApplicableOutcome("certificate_scope_mismatch", "CRL only applies to CA certificates");
|
|
457
457
|
let o = e.crlDistributionPoints ?? [];
|
|
458
|
-
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 && !
|
|
458
|
+
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 && !F(e.issuer, t.issuer) ? notApplicableOutcome("issuer_mismatch", "indirect CRLs for alternate certificate issuers require matching CRLIssuer distribution points") : {
|
|
459
459
|
ok: !0,
|
|
460
460
|
coveredReasons: interimReasonsMask(void 0, r)
|
|
461
461
|
};
|
|
@@ -522,7 +522,7 @@ function scanCrlDistributionPoint(e, t, n, r, i) {
|
|
|
522
522
|
}
|
|
523
523
|
function scanCrlDistributionPointIssuer(e, t, n, r) {
|
|
524
524
|
if (!r) return e.crlIssuer === void 0 ? void 0 : "indirect_distribution_point";
|
|
525
|
-
if (
|
|
525
|
+
if (F(t.issuer, n.issuer) && e.crlIssuer === void 0) return;
|
|
526
526
|
let i = matchesIndirectCrlIssuer(e.crlIssuer, n);
|
|
527
527
|
return i === "unsupported" ? "unsupported_indirect_crl_issuer" : i ? void 0 : "indirect_issuer_mismatch";
|
|
528
528
|
}
|
|
@@ -533,7 +533,7 @@ function crlDistributionPointScanFailure(e) {
|
|
|
533
533
|
function checkDeltaCrlCompatibility(e, t) {
|
|
534
534
|
if (e.baseCrlNumber !== void 0) return nonApplicable("delta_crl_incompatible", "complete CRL input must not itself be a delta CRL");
|
|
535
535
|
if (t.baseCrlNumber === void 0) return nonApplicable("delta_crl_incompatible", "delta CRL input must include a delta CRL indicator");
|
|
536
|
-
if (!
|
|
536
|
+
if (!F(e.issuer, t.issuer)) return nonApplicable("delta_crl_incompatible", "complete and delta CRLs must share the same issuer");
|
|
537
537
|
if (e.authorityKeyIdentifier !== t.authorityKeyIdentifier) return nonApplicable("delta_crl_incompatible", "complete and delta CRLs must share the same authority key identifier");
|
|
538
538
|
if (!sameIssuingDistributionPoint(e.issuingDistributionPoint, t.issuingDistributionPoint)) return nonApplicable("delta_crl_incompatible", "complete and delta CRLs must share the same issuing distribution point scope");
|
|
539
539
|
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");
|
|
@@ -547,7 +547,7 @@ function matchesIndirectCrlIssuer(e, t) {
|
|
|
547
547
|
}
|
|
548
548
|
/** Determines whether a revoked entry's effective issuer matches the certificate's issuer. */
|
|
549
549
|
function matchesRevokedEntryIssuer(e, t, n) {
|
|
550
|
-
if (n === void 0) return
|
|
550
|
+
if (n === void 0) return F(e.issuer, t.issuer) ? "match" : "mismatch";
|
|
551
551
|
let r = !1;
|
|
552
552
|
for (let t of n) if (t.type === "directoryName") {
|
|
553
553
|
if (directoryNameDerHexMatchesParsedName(t.derHex, e.issuer)) return "match";
|
|
@@ -606,7 +606,7 @@ function matchesDistributionPointName(e, t, n, r) {
|
|
|
606
606
|
let r = resolveRelativeNameToDnHex(n, e.relativeName);
|
|
607
607
|
return t.fullName.some((e) => e.type === "directoryName" && e.derHex === r);
|
|
608
608
|
}
|
|
609
|
-
if (e.type === "relativeName" && t.type === "relativeName") return
|
|
609
|
+
if (e.type === "relativeName" && t.type === "relativeName") return I(e.relativeName, t.relativeName);
|
|
610
610
|
if (e.type === "fullName" && t.type === "relativeName") {
|
|
611
611
|
let r = resolveRelativeNameToDnHex(n, t.relativeName);
|
|
612
612
|
return e.fullName.some((e) => e.type === "directoryName" && e.derHex === r);
|
|
@@ -626,13 +626,13 @@ function matchesIdpNameAgainstCrlIssuer(e, t, n) {
|
|
|
626
626
|
}
|
|
627
627
|
/** Constructs a full DN by appending an RDN to an existing Name, returning hex-encoded DER. */
|
|
628
628
|
function resolveRelativeNameToDnHex(e, t) {
|
|
629
|
-
let n = e.rdns.map((e) =>
|
|
630
|
-
return n.push(r),
|
|
629
|
+
let n = e.rdns.map((e) => c(e.derHex)), r = rebuildRelativeNameAsSet(c(t.derHex));
|
|
630
|
+
return n.push(r), d(E(n));
|
|
631
631
|
}
|
|
632
632
|
/** Converts an implicit-tagged [1] relativeName to a proper SET-tagged RDN. */
|
|
633
633
|
function rebuildRelativeNameAsSet(e) {
|
|
634
|
-
let t =
|
|
635
|
-
return
|
|
634
|
+
let t = w(e, { maxDepth: 64 });
|
|
635
|
+
return O(49, t.value);
|
|
636
636
|
}
|
|
637
637
|
/** Deep-compares two issuing distribution point extensions for delta-CRL compatibility. */
|
|
638
638
|
function sameIssuingDistributionPoint(e, t) {
|
|
@@ -640,7 +640,7 @@ function sameIssuingDistributionPoint(e, t) {
|
|
|
640
640
|
}
|
|
641
641
|
/** Compares two DistributionPointName values (fullName set or relativeName). */
|
|
642
642
|
function sameDistributionPointName(e, t) {
|
|
643
|
-
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" &&
|
|
643
|
+
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" && I(e.relativeName, t.relativeName);
|
|
644
644
|
}
|
|
645
645
|
/** Set-equality comparison for GeneralName arrays (order-independent). */
|
|
646
646
|
function sameGeneralNameSet(e, t) {
|
|
@@ -676,12 +676,12 @@ function compareGeneralNames(e, t) {
|
|
|
676
676
|
if (e.type === "uri" && t.type === "uri") return compareUniformResourceIdentifiers(e.value, t.value);
|
|
677
677
|
if (e.type === "directoryName" && t.type === "directoryName") {
|
|
678
678
|
let n = parseDerHexName(e.derHex), r = parseDerHexName(t.derHex);
|
|
679
|
-
return n === void 0 || r === void 0 ? !1 :
|
|
679
|
+
return n === void 0 || r === void 0 ? !1 : F(n, r);
|
|
680
680
|
}
|
|
681
681
|
return compareOpaqueGeneralNames(e, t);
|
|
682
682
|
}
|
|
683
683
|
function compareSrvNames(e, t) {
|
|
684
|
-
let n =
|
|
684
|
+
let n = B(e), r = B(t);
|
|
685
685
|
return n === void 0 || r === void 0 ? e === t : n.service === r.service && n.name === r.name;
|
|
686
686
|
}
|
|
687
687
|
/** Encoding equality for the GeneralName alternatives carried as DER or an OID. */
|
|
@@ -704,7 +704,7 @@ function compareUniformResourceIdentifiers(e, t) {
|
|
|
704
704
|
* the default port that scheme-based normalization elides. `ldaps` is included
|
|
705
705
|
* as the TLS form of the mandatory `ldap` scheme.
|
|
706
706
|
*/
|
|
707
|
-
const
|
|
707
|
+
const Q = /* @__PURE__ */ new Map([
|
|
708
708
|
["ftp", "21"],
|
|
709
709
|
["http", "80"],
|
|
710
710
|
["https", "443"],
|
|
@@ -733,7 +733,7 @@ function normalizeUriForComparison(e) {
|
|
|
733
733
|
if (e === void 0) return;
|
|
734
734
|
t.hostname = e;
|
|
735
735
|
}
|
|
736
|
-
return t.port ===
|
|
736
|
+
return t.port === Q.get(t.protocol.slice(0, -1)) && (t.port = ""), normalizePercentEncoding(t.href);
|
|
737
737
|
}
|
|
738
738
|
/**
|
|
739
739
|
* Reparses a host under a special scheme so the URL parser applies IDNA and
|
|
@@ -777,71 +777,71 @@ function bytesEqual(e, t) {
|
|
|
777
777
|
}
|
|
778
778
|
/** Assembles the CRL-level v2 extensions (AKI, CRLNumber, deltaCRLIndicator, IDP, freshestCRL). */
|
|
779
779
|
function buildCrlExtensions(e, t, n, r, i) {
|
|
780
|
-
let a = [
|
|
781
|
-
return n !== void 0 && a.push(
|
|
780
|
+
let a = [Y(k.authorityKeyIdentifier, E([b(0, ae(e))])), Y(k.cRLNumber, t)];
|
|
781
|
+
return n !== void 0 && a.push(Y(k.deltaCRLIndicator, n, !0)), r !== void 0 && a.push(Y(k.issuingDistributionPoint, encodeIssuingDistributionPoint(r), !0)), i !== void 0 && i.length > 0 && a.push(Y(k.freshestCRL, J(i))), a;
|
|
782
782
|
}
|
|
783
783
|
/** DER-encodes a single revokedCertificate SEQUENCE (serial, date, optional extensions). */
|
|
784
784
|
function createRevokedCertificate(e, t) {
|
|
785
785
|
let n = buildRevokedCertificateExtensions(e);
|
|
786
|
-
return
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
...n.length === 0 ? [] : [
|
|
786
|
+
return E([
|
|
787
|
+
x(e.serialNumber),
|
|
788
|
+
D(e.revocationDate ?? t),
|
|
789
|
+
...n.length === 0 ? [] : [E(n)]
|
|
790
790
|
]);
|
|
791
791
|
}
|
|
792
792
|
/** Encodes CRL entry extensions (reasonCode, invalidityDate). */
|
|
793
793
|
function buildRevokedCertificateExtensions(e) {
|
|
794
794
|
let t = [];
|
|
795
|
-
return e.reasonCode !== void 0 && t.push(
|
|
795
|
+
return e.reasonCode !== void 0 && t.push(Y(k.cRLReason, O(10, Uint8Array.of(ue[e.reasonCode])))), e.invalidityDate !== void 0 && t.push(Y(k.invalidityDate, v(e.invalidityDate))), t;
|
|
796
796
|
}
|
|
797
797
|
/** Decodes per-entry CRL extensions (reasonCode, invalidityDate, certificateIssuer). */
|
|
798
|
-
function parseRevokedCertificateExtensions(
|
|
799
|
-
if (
|
|
800
|
-
let
|
|
801
|
-
for (let
|
|
798
|
+
function parseRevokedCertificateExtensions(t, n) {
|
|
799
|
+
if (t === void 0 || n === void 0) return {};
|
|
800
|
+
let r = {}, i = /* @__PURE__ */ new Set();
|
|
801
|
+
for (let a of e(t, n)) parseRevokedCertificateExtension(t, a, i, r);
|
|
802
802
|
return {
|
|
803
|
-
...
|
|
804
|
-
...
|
|
805
|
-
...
|
|
803
|
+
...r.reasonCode === void 0 ? {} : { reasonCode: r.reasonCode },
|
|
804
|
+
...r.invalidityDate === void 0 ? {} : { invalidityDate: r.invalidityDate },
|
|
805
|
+
...r.certificateIssuer === void 0 ? {} : { certificateIssuer: r.certificateIssuer }
|
|
806
806
|
};
|
|
807
807
|
}
|
|
808
|
-
function parseRevokedCertificateExtension(
|
|
809
|
-
let
|
|
810
|
-
if (
|
|
811
|
-
let
|
|
812
|
-
if (
|
|
813
|
-
|
|
814
|
-
let
|
|
815
|
-
if (
|
|
816
|
-
if (
|
|
817
|
-
applyRevokedCertificateExtensionValue(
|
|
808
|
+
function parseRevokedCertificateExtension(n, r, i, o) {
|
|
809
|
+
let s = e(n, r);
|
|
810
|
+
if (s.length < 2 || s.length > 3 || s.length === 3 && s[1]?.tag !== 1) throw Error("Malformed revoked certificate extension");
|
|
811
|
+
let c = a(u(s[0], "revoked certificate extension OID").value);
|
|
812
|
+
if (i.has(c)) throw Error(`Duplicate revoked certificate extension OID: ${c}`);
|
|
813
|
+
i.add(c);
|
|
814
|
+
let l = s.length === 3 && t(u(s[1], "revoked certificate extension critical").value), d = u(s[s.length - 1], "revoked certificate extension value");
|
|
815
|
+
if (d.tag !== 4) throw Error("Revoked certificate extension value must use OCTET STRING");
|
|
816
|
+
if (l && !isSupportedRevokedCertificateExtensionOid(c)) throw Error(`Unsupported critical revoked certificate extension OID: ${c}`);
|
|
817
|
+
applyRevokedCertificateExtensionValue(c, d.value, l, o);
|
|
818
818
|
}
|
|
819
819
|
function isSupportedRevokedCertificateExtensionOid(e) {
|
|
820
|
-
return e ===
|
|
820
|
+
return e === k.cRLReason || e === k.invalidityDate || e === k.certificateIssuer;
|
|
821
821
|
}
|
|
822
822
|
function applyRevokedCertificateExtensionValue(e, t, n, r) {
|
|
823
|
-
if (e ===
|
|
824
|
-
let e =
|
|
823
|
+
if (e === k.cRLReason) {
|
|
824
|
+
let e = w(t, { maxDepth: 64 });
|
|
825
825
|
if (e.tag !== 10) throw Error("cRLReason must use ENUMERATED");
|
|
826
|
-
let
|
|
827
|
-
if (n && typeof
|
|
828
|
-
r.reasonCode =
|
|
826
|
+
let a = parsedRevocationReason(i(e.value, "cRLReason"));
|
|
827
|
+
if (n && typeof a != "string") throw Error(`Critical cRLReason holds unrecognized reason code ${String(a.code)}`);
|
|
828
|
+
r.reasonCode = a;
|
|
829
829
|
}
|
|
830
|
-
if (e ===
|
|
831
|
-
let e =
|
|
830
|
+
if (e === k.invalidityDate && (r.invalidityDate = l(w(t, { maxDepth: 64 }))), e === k.certificateIssuer) {
|
|
831
|
+
let e = w(t, { maxDepth: 64 });
|
|
832
832
|
if (e.tag !== 48) throw Error("certificateIssuer must use SEQUENCE");
|
|
833
|
-
r.certificateIssuer =
|
|
833
|
+
r.certificateIssuer = z(t, e);
|
|
834
834
|
}
|
|
835
835
|
}
|
|
836
836
|
/** Decodes the IssuingDistributionPoint extension from its OCTET STRING content. */
|
|
837
|
-
function parseIssuingDistributionPoint(
|
|
838
|
-
let
|
|
839
|
-
for (let
|
|
837
|
+
function parseIssuingDistributionPoint(t) {
|
|
838
|
+
let n = w(t, { maxDepth: 64 }), r = {};
|
|
839
|
+
for (let i of e(t, n)) parseIssuingDistributionPointField(t, i, r);
|
|
840
840
|
return {
|
|
841
|
-
...
|
|
842
|
-
...
|
|
843
|
-
...
|
|
844
|
-
...parseIssuingDistributionPointScope(
|
|
841
|
+
...r.distributionPoint === void 0 ? {} : { distributionPoint: r.distributionPoint },
|
|
842
|
+
...r.onlySomeReasons === void 0 ? {} : { onlySomeReasons: r.onlySomeReasons },
|
|
843
|
+
...r.indirectCrl === void 0 ? {} : { indirectCrl: r.indirectCrl },
|
|
844
|
+
...parseIssuingDistributionPointScope(r)
|
|
845
845
|
};
|
|
846
846
|
}
|
|
847
847
|
/** RFC 5280 §5.2.5: at most one `onlyContains*` flag may be TRUE. */
|
|
@@ -904,7 +904,7 @@ function parseIssuingDistributionPointField(e, t, n) {
|
|
|
904
904
|
return;
|
|
905
905
|
case 131:
|
|
906
906
|
if (n.onlySomeReasons !== void 0) throw Error("IssuingDistributionPoint onlySomeReasons must not repeat");
|
|
907
|
-
n.onlySomeReasons =
|
|
907
|
+
n.onlySomeReasons = R(t.value);
|
|
908
908
|
return;
|
|
909
909
|
case 132:
|
|
910
910
|
n.indirectCrl = parseUniqueIssuingDistributionPointBoolean(n.indirectCrl, t, "indirectCrl");
|
|
@@ -915,48 +915,48 @@ function parseIssuingDistributionPointField(e, t, n) {
|
|
|
915
915
|
default: throw Error(`Unsupported IssuingDistributionPoint field tag: ${String(t.tag)}`);
|
|
916
916
|
}
|
|
917
917
|
}
|
|
918
|
-
function parseUniqueIssuingDistributionPointBoolean(e,
|
|
919
|
-
if (e !== void 0) throw Error(`IssuingDistributionPoint ${
|
|
920
|
-
return
|
|
918
|
+
function parseUniqueIssuingDistributionPointBoolean(e, n, r) {
|
|
919
|
+
if (e !== void 0) throw Error(`IssuingDistributionPoint ${r} must not repeat`);
|
|
920
|
+
return t(n.value);
|
|
921
921
|
}
|
|
922
922
|
/** Decodes a SEQUENCE OF DistributionPoint from DER. */
|
|
923
|
-
function parseDistributionPoints(
|
|
924
|
-
let
|
|
925
|
-
if (
|
|
926
|
-
let
|
|
927
|
-
if (
|
|
928
|
-
return
|
|
923
|
+
function parseDistributionPoints(t) {
|
|
924
|
+
let n = w(t, { maxDepth: 64 });
|
|
925
|
+
if (n.tag !== 48) throw Error("DistributionPoints must use SEQUENCE");
|
|
926
|
+
let r = e(t, n);
|
|
927
|
+
if (r.length === 0) throw Error("DistributionPoints must not be empty");
|
|
928
|
+
return r.map((e) => parseDistributionPoint(t, e));
|
|
929
929
|
}
|
|
930
930
|
/** Decodes a DistributionPointName (fullName or relativeName). */
|
|
931
|
-
function parseDistributionPointName(
|
|
932
|
-
let
|
|
933
|
-
if (
|
|
934
|
-
let
|
|
935
|
-
if (
|
|
936
|
-
let
|
|
937
|
-
if (
|
|
938
|
-
for (let e of
|
|
931
|
+
function parseDistributionPointName(t, n) {
|
|
932
|
+
let r = e(t, n);
|
|
933
|
+
if (r.length !== 1) throw Error("distributionPointName must contain exactly one choice");
|
|
934
|
+
let i = u(r[0], "distributionPointName");
|
|
935
|
+
if (i.tag === 160) {
|
|
936
|
+
let n = e(t, i);
|
|
937
|
+
if (n.length === 0) throw Error("distributionPointName fullName must not be empty");
|
|
938
|
+
for (let e of n) if ((e.tag & 192) != 128) throw Error("distributionPointName fullName must contain GeneralName entries");
|
|
939
939
|
return {
|
|
940
940
|
type: "fullName",
|
|
941
|
-
fullName:
|
|
941
|
+
fullName: n.map((e) => ne(t, e))
|
|
942
942
|
};
|
|
943
943
|
}
|
|
944
|
-
if (
|
|
944
|
+
if (i.tag === 161) return {
|
|
945
945
|
type: "relativeName",
|
|
946
|
-
relativeName: parseRelativeName(
|
|
946
|
+
relativeName: parseRelativeName(t, i)
|
|
947
947
|
};
|
|
948
|
-
throw Error(`Unsupported distributionPointName tag: ${String(
|
|
948
|
+
throw Error(`Unsupported distributionPointName tag: ${String(i.tag)}`);
|
|
949
949
|
}
|
|
950
950
|
/** Decodes a single DistributionPoint SEQUENCE. */
|
|
951
|
-
function parseDistributionPoint(
|
|
952
|
-
if (
|
|
953
|
-
let
|
|
954
|
-
for (let
|
|
955
|
-
if (
|
|
951
|
+
function parseDistributionPoint(t, n) {
|
|
952
|
+
if (n.tag !== 48) throw Error("DistributionPoint must use SEQUENCE");
|
|
953
|
+
let r = {};
|
|
954
|
+
for (let i of e(t, n)) parseDistributionPointField(t, i, r);
|
|
955
|
+
if (r.distributionPoint === void 0 && r.crlIssuer === void 0) throw Error("DistributionPoint must include distributionPoint or crlIssuer");
|
|
956
956
|
return {
|
|
957
|
-
...
|
|
958
|
-
...
|
|
959
|
-
...
|
|
957
|
+
...r.distributionPoint === void 0 ? {} : { distributionPoint: r.distributionPoint },
|
|
958
|
+
...r.reasons === void 0 ? {} : { reasons: r.reasons },
|
|
959
|
+
...r.crlIssuer === void 0 ? {} : { crlIssuer: r.crlIssuer }
|
|
960
960
|
};
|
|
961
961
|
}
|
|
962
962
|
function parseDistributionPointField(e, t, n) {
|
|
@@ -969,63 +969,63 @@ function parseDistributionPointField(e, t, n) {
|
|
|
969
969
|
}
|
|
970
970
|
case 129:
|
|
971
971
|
if (n.reasons !== void 0) throw Error("DistributionPoint reasons must not repeat");
|
|
972
|
-
n.reasons =
|
|
972
|
+
n.reasons = R(t.value);
|
|
973
973
|
return;
|
|
974
974
|
case 162:
|
|
975
975
|
if (n.crlIssuer !== void 0) throw Error("DistributionPoint crlIssuer must not repeat");
|
|
976
|
-
n.crlIssuer =
|
|
976
|
+
n.crlIssuer = z(e, t);
|
|
977
977
|
return;
|
|
978
978
|
default: throw Error(`Unsupported DistributionPoint field tag: ${String(t.tag)}`);
|
|
979
979
|
}
|
|
980
980
|
}
|
|
981
981
|
/** Decodes a RelativeDistinguishedName SET from an implicitly-tagged context element. */
|
|
982
|
-
function parseRelativeName(
|
|
983
|
-
let
|
|
984
|
-
for (let
|
|
985
|
-
let
|
|
986
|
-
oid:
|
|
987
|
-
valueTag:
|
|
988
|
-
value:
|
|
982
|
+
function parseRelativeName(t, n) {
|
|
983
|
+
let r = [], i = {};
|
|
984
|
+
for (let o of e(t, n)) {
|
|
985
|
+
let n = e(t, o), s = a(u(n[0], "name OID").value), c = u(n[1], "name value"), l = H(s), d = decodeNameValue(c), f = l === void 0 ? {
|
|
986
|
+
oid: s,
|
|
987
|
+
valueTag: c.tag,
|
|
988
|
+
value: d
|
|
989
989
|
} : {
|
|
990
|
-
oid:
|
|
991
|
-
key:
|
|
992
|
-
valueTag:
|
|
993
|
-
value:
|
|
990
|
+
oid: s,
|
|
991
|
+
key: l,
|
|
992
|
+
valueTag: c.tag,
|
|
993
|
+
value: d
|
|
994
994
|
};
|
|
995
|
-
|
|
995
|
+
r.push(f), l !== void 0 && i[l] === void 0 && (i[l] = d);
|
|
996
996
|
}
|
|
997
997
|
return {
|
|
998
|
-
derHex:
|
|
999
|
-
attributes:
|
|
1000
|
-
values:
|
|
998
|
+
derHex: d(t.slice(n.start - n.headerLength, n.end)),
|
|
999
|
+
attributes: r,
|
|
1000
|
+
values: i
|
|
1001
1001
|
};
|
|
1002
1002
|
}
|
|
1003
1003
|
/** Decodes an ASN.1 string element (UTF8String, PrintableString, etc.) to a JS string. */
|
|
1004
1004
|
function decodeNameValue(e) {
|
|
1005
|
-
return
|
|
1005
|
+
return o(e.tag, e.value);
|
|
1006
1006
|
}
|
|
1007
1007
|
/** Throws a {@link ResultError} for a CRL encoder input-validation failure. */
|
|
1008
1008
|
function throwCrlEncoderError(e, t) {
|
|
1009
|
-
|
|
1009
|
+
q(e, t);
|
|
1010
1010
|
}
|
|
1011
1011
|
/** The parsed issuer certificate of a CRL being built. */
|
|
1012
|
-
function issuerCertificateOf(
|
|
1012
|
+
function issuerCertificateOf(e) {
|
|
1013
1013
|
try {
|
|
1014
|
-
return normalizeCrlCertificate(
|
|
1015
|
-
} catch (
|
|
1016
|
-
return
|
|
1014
|
+
return normalizeCrlCertificate(e);
|
|
1015
|
+
} catch (e) {
|
|
1016
|
+
return m(e, U), throwCrlEncoderError("issuer_certificate_invalid", "issuerCertificate must be a PEM, DER or parsed certificate");
|
|
1017
1017
|
}
|
|
1018
1018
|
}
|
|
1019
1019
|
/** RFC 5280 §5.2.3 `CRLNumber ::= INTEGER (0..MAX)` as a DER INTEGER of at most 20 content octets. */
|
|
1020
1020
|
function encodeCrlNumber(e, t) {
|
|
1021
|
-
let n = typeof e == "bigint" ? e : Number.isSafeInteger(e) ? BigInt(e) : -1n, r = n.toString(16), i = n < 0n ? void 0 :
|
|
1022
|
-
return (i === void 0 || a === void 0 || i.length + +(a >= 128) > 20) && throwCrlEncoderError("crl_number_invalid", `${t} must be a non-negative integer of at most 20 octets (RFC 5280 §5.2.3)`),
|
|
1021
|
+
let n = typeof e == "bigint" ? e : Number.isSafeInteger(e) ? BigInt(e) : -1n, r = n.toString(16), i = n < 0n ? void 0 : c(r.length % 2 == 0 ? r : `0${r}`), a = i?.[0];
|
|
1022
|
+
return (i === void 0 || a === void 0 || i.length + +(a >= 128) > 20) && throwCrlEncoderError("crl_number_invalid", `${t} must be a non-negative integer of at most 20 octets (RFC 5280 §5.2.3)`), x(i);
|
|
1023
1023
|
}
|
|
1024
1024
|
/** RFC 5280 §5.2.3: a received CRLNumber of any length, since verifiers MUST handle up to 20 octets. */
|
|
1025
1025
|
function decodeCrlNumber(e) {
|
|
1026
|
-
let t =
|
|
1026
|
+
let t = w(e, { maxDepth: 64 });
|
|
1027
1027
|
if (t.tag !== 2) throw Error("CRLNumber must be an INTEGER");
|
|
1028
|
-
return
|
|
1028
|
+
return n(t.value, "CRLNumber"), BigInt(`0x${d(t.value)}`);
|
|
1029
1029
|
}
|
|
1030
1030
|
function assertCrlDate(e, t) {
|
|
1031
1031
|
e !== void 0 && Number.isNaN(e.getTime()) && throwCrlEncoderError("invalid_date", `${t} must be a valid date`);
|
|
@@ -1038,98 +1038,98 @@ function encodeIssuingDistributionPoint(e) {
|
|
|
1038
1038
|
e.onlyContainsAttributeCerts === !0
|
|
1039
1039
|
].filter(Boolean).length > 1) throw Error("IssuingDistributionPoint can assert at most one of user, CA, or attribute cert scope");
|
|
1040
1040
|
let t = [];
|
|
1041
|
-
return e.distributionPoint !== void 0 && t.push(
|
|
1041
|
+
return e.distributionPoint !== void 0 && t.push(y(0, encodeDistributionPointName(e.distributionPoint))), e.onlyContainsUserCerts && t.push(b(1, Uint8Array.of(255))), e.onlyContainsCACerts && t.push(b(2, Uint8Array.of(255))), e.onlySomeReasons !== void 0 && e.onlySomeReasons.length > 0 && t.push(b(3, L(e.onlySomeReasons))), e.indirectCrl && t.push(b(4, Uint8Array.of(255))), e.onlyContainsAttributeCerts && t.push(b(5, Uint8Array.of(255))), E(t);
|
|
1042
1042
|
}
|
|
1043
1043
|
/** DER-encodes a DistributionPointName (fullName or relativeName). */
|
|
1044
1044
|
function encodeDistributionPointName(e) {
|
|
1045
1045
|
if (e === void 0) throw Error("IssuingDistributionPoint distributionPoint is required");
|
|
1046
1046
|
switch (e.type) {
|
|
1047
|
-
case "fullName": return e.fullName.length === 0 && throwCrlEncoderError("distribution_point_full_name_empty", "DistributionPointName fullName must not be empty"),
|
|
1047
|
+
case "fullName": return e.fullName.length === 0 && throwCrlEncoderError("distribution_point_full_name_empty", "DistributionPointName fullName must not be empty"), y(0, concatGeneralNames(e.fullName));
|
|
1048
1048
|
case "relativeName": {
|
|
1049
|
-
let t =
|
|
1050
|
-
return
|
|
1049
|
+
let t = se(e.relativeName), n = C(t);
|
|
1050
|
+
return y(1, t.slice(n.start, n.end));
|
|
1051
1051
|
}
|
|
1052
1052
|
default: throw Error(`Unhandled DistributionPointName type: ${String(e)}`);
|
|
1053
1053
|
}
|
|
1054
1054
|
}
|
|
1055
1055
|
/** DER-encodes and concatenates a list of GeneralName values. */
|
|
1056
1056
|
function concatGeneralNames(e) {
|
|
1057
|
-
return
|
|
1057
|
+
return g(e.map((e) => ie(e)));
|
|
1058
1058
|
}
|
|
1059
1059
|
/** Parses a Name SEQUENCE element into a full {@linkcode ParsedName}. */
|
|
1060
|
-
function parseIssuer(
|
|
1061
|
-
let
|
|
1062
|
-
for (let
|
|
1063
|
-
let
|
|
1064
|
-
for (let
|
|
1065
|
-
let
|
|
1066
|
-
oid:
|
|
1067
|
-
valueTag:
|
|
1068
|
-
value:
|
|
1060
|
+
function parseIssuer(t, n) {
|
|
1061
|
+
let r = d(t.slice(n.start - n.headerLength, n.end)), i = [], o = [], s = {};
|
|
1062
|
+
for (let r of e(t, n)) {
|
|
1063
|
+
let n = [], c = {};
|
|
1064
|
+
for (let i of e(t, r)) {
|
|
1065
|
+
let r = e(t, i), l = u(r[0], "issuer attribute OID"), d = u(r[1], "issuer attribute value"), f = a(l.value), p = decodeNameValue(d), m = H(f), h = m === void 0 ? {
|
|
1066
|
+
oid: f,
|
|
1067
|
+
valueTag: d.tag,
|
|
1068
|
+
value: p
|
|
1069
1069
|
} : {
|
|
1070
|
-
oid:
|
|
1071
|
-
key:
|
|
1072
|
-
valueTag:
|
|
1073
|
-
value:
|
|
1070
|
+
oid: f,
|
|
1071
|
+
key: m,
|
|
1072
|
+
valueTag: d.tag,
|
|
1073
|
+
value: p
|
|
1074
1074
|
};
|
|
1075
|
-
|
|
1075
|
+
n.push(h), o.push(h), m !== void 0 && (c[m] === void 0 && (c[m] = p), s[m] === void 0 && (s[m] = p));
|
|
1076
1076
|
}
|
|
1077
|
-
|
|
1078
|
-
derHex:
|
|
1079
|
-
attributes:
|
|
1080
|
-
values:
|
|
1077
|
+
i.push({
|
|
1078
|
+
derHex: d(t.slice(r.start - r.headerLength, r.end)),
|
|
1079
|
+
attributes: n,
|
|
1080
|
+
values: c
|
|
1081
1081
|
});
|
|
1082
1082
|
}
|
|
1083
1083
|
return {
|
|
1084
|
-
derHex:
|
|
1085
|
-
rdns:
|
|
1086
|
-
attributes:
|
|
1087
|
-
values:
|
|
1084
|
+
derHex: r,
|
|
1085
|
+
rdns: i,
|
|
1086
|
+
attributes: o,
|
|
1087
|
+
values: s
|
|
1088
1088
|
};
|
|
1089
1089
|
}
|
|
1090
1090
|
/**
|
|
1091
1091
|
* Re-parses a hex-encoded DER Name into a {@linkcode ParsedName}. Returns
|
|
1092
1092
|
* `undefined` on malformed input and throws a decode refusal.
|
|
1093
1093
|
*/
|
|
1094
|
-
function parseDerHexName(
|
|
1094
|
+
function parseDerHexName(e) {
|
|
1095
1095
|
try {
|
|
1096
|
-
let
|
|
1097
|
-
return n.tag === 48 ? parseIssuer(
|
|
1098
|
-
} catch (
|
|
1099
|
-
|
|
1096
|
+
let t = c(e), n = unwrapNameElement(t, w(t, { maxDepth: 64 }));
|
|
1097
|
+
return n.tag === 48 ? parseIssuer(t, n) : void 0;
|
|
1098
|
+
} catch (e) {
|
|
1099
|
+
m(e, U);
|
|
1100
1100
|
return;
|
|
1101
1101
|
}
|
|
1102
1102
|
}
|
|
1103
1103
|
/** The failure for a decode refusal a directoryName comparison threw. */
|
|
1104
|
-
function crlNameRefusalFailure(
|
|
1105
|
-
let
|
|
1106
|
-
if (
|
|
1107
|
-
return checkCertificateRevocationAgainstCrlFailureResult(
|
|
1104
|
+
function crlNameRefusalFailure(e) {
|
|
1105
|
+
let t = p(e, U);
|
|
1106
|
+
if (t === void 0) throw e;
|
|
1107
|
+
return checkCertificateRevocationAgainstCrlFailureResult(t.code, t.message);
|
|
1108
1108
|
}
|
|
1109
|
-
function unwrapNameElement(
|
|
1110
|
-
if (
|
|
1111
|
-
let
|
|
1112
|
-
return
|
|
1109
|
+
function unwrapNameElement(t, n) {
|
|
1110
|
+
if (n.tag !== 48) return n;
|
|
1111
|
+
let r = e(t, n), i = r[0];
|
|
1112
|
+
return r.length === 1 && i?.tag === 48 ? i : n;
|
|
1113
1113
|
}
|
|
1114
1114
|
/** Semantic comparison of a GeneralName directoryName `derHex` against a {@linkcode ParsedName}. */
|
|
1115
1115
|
function directoryNameDerHexMatchesParsedName(e, t) {
|
|
1116
1116
|
let n = parseDerHexName(e);
|
|
1117
|
-
return n !== void 0 &&
|
|
1117
|
+
return n !== void 0 && F(n, t);
|
|
1118
1118
|
}
|
|
1119
1119
|
/** Extracts the keyIdentifier field from an AuthorityKeyIdentifier extension value. */
|
|
1120
|
-
function parseAuthorityKeyIdentifier(
|
|
1121
|
-
let
|
|
1120
|
+
function parseAuthorityKeyIdentifier(t) {
|
|
1121
|
+
let n = w(t, {
|
|
1122
1122
|
maxDepth: 64,
|
|
1123
1123
|
allowOpaqueConstructedTags: [161, 162]
|
|
1124
1124
|
});
|
|
1125
|
-
if (
|
|
1126
|
-
let
|
|
1125
|
+
if (n.tag !== 48) throw Error("authorityKeyIdentifier must use SEQUENCE");
|
|
1126
|
+
let r = {
|
|
1127
1127
|
sawAuthorityCertIssuer: !1,
|
|
1128
1128
|
sawAuthorityCertSerialNumber: !1,
|
|
1129
1129
|
lastFieldOrder: -1
|
|
1130
1130
|
};
|
|
1131
|
-
for (let
|
|
1132
|
-
return
|
|
1131
|
+
for (let i of e(t, n)) parseAuthorityKeyIdentifierField(t, i, r);
|
|
1132
|
+
return r.keyIdentifier;
|
|
1133
1133
|
}
|
|
1134
1134
|
function parseAuthorityKeyIdentifierField(e, t, n) {
|
|
1135
1135
|
switch (t.tag) {
|
|
@@ -1148,12 +1148,12 @@ function parseAuthorityKeyIdentifierField(e, t, n) {
|
|
|
1148
1148
|
function parseAuthorityKeyIdentifierKeyId(e, t) {
|
|
1149
1149
|
if (t.keyIdentifier !== void 0) throw Error("authorityKeyIdentifier keyIdentifier must not repeat");
|
|
1150
1150
|
if (t.lastFieldOrder >= 0) throw Error("authorityKeyIdentifier fields must preserve DER order");
|
|
1151
|
-
t.keyIdentifier =
|
|
1151
|
+
t.keyIdentifier = d(e.value), t.lastFieldOrder = 0;
|
|
1152
1152
|
}
|
|
1153
1153
|
function parseAuthorityKeyIdentifierIssuer(e, t, n) {
|
|
1154
1154
|
if (n.sawAuthorityCertIssuer) throw Error("authorityKeyIdentifier authorityCertIssuer must not repeat");
|
|
1155
1155
|
if (n.lastFieldOrder >= 1) throw Error("authorityKeyIdentifier fields must preserve DER order");
|
|
1156
|
-
|
|
1156
|
+
z(e, t), n.sawAuthorityCertIssuer = !0, n.lastFieldOrder = 1;
|
|
1157
1157
|
}
|
|
1158
1158
|
function parseAuthorityKeyIdentifierSerial(e, t) {
|
|
1159
1159
|
if (t.sawAuthorityCertSerialNumber) throw Error("authorityKeyIdentifier authorityCertSerialNumber must not repeat");
|
|
@@ -1171,11 +1171,11 @@ function assertMatchingCrlSignatureAlgorithms(e, t) {
|
|
|
1171
1171
|
if (e.oid !== t.oid || !ee(e.parametersDer, t.parametersDer)) throw Error("CRL signatureAlgorithm must match TBSCertList signature");
|
|
1172
1172
|
}
|
|
1173
1173
|
/** Extracts the algorithm OID from an AlgorithmIdentifier SEQUENCE. */
|
|
1174
|
-
function parseAlgorithmIdentifier(
|
|
1175
|
-
let
|
|
1176
|
-
return
|
|
1177
|
-
oid:
|
|
1178
|
-
parametersDer:
|
|
1174
|
+
function parseAlgorithmIdentifier(t, n) {
|
|
1175
|
+
let r = e(t, n), i = u(r[0], "algorithm OID"), o = r[1];
|
|
1176
|
+
return o === void 0 ? { oid: a(i.value) } : {
|
|
1177
|
+
oid: a(i.value),
|
|
1178
|
+
parametersDer: t.slice(o.start - o.headerLength, o.end)
|
|
1179
1179
|
};
|
|
1180
1180
|
}
|
|
1181
1181
|
/** Lowercases a hex string for bytewise serial-number comparison. */
|
|
@@ -1210,11 +1210,11 @@ function parsedRevocationReason(e) {
|
|
|
1210
1210
|
}
|
|
1211
1211
|
/** Thin wrapper — parses a DER-encoded certificate for use as a CRL issuer. */
|
|
1212
1212
|
function parseIssuerCertificateDer(e) {
|
|
1213
|
-
return
|
|
1213
|
+
return X(e);
|
|
1214
1214
|
}
|
|
1215
1215
|
/** Thin wrapper — parses a PEM-encoded certificate for use as a CRL issuer. */
|
|
1216
1216
|
function parseIssuerCertificatePem(e) {
|
|
1217
|
-
return
|
|
1217
|
+
return X(e);
|
|
1218
1218
|
}
|
|
1219
1219
|
/**
|
|
1220
1220
|
* Parses PEM, DER, or an already-parsed CRL's `der`, so every decoded field
|
|
@@ -1228,24 +1228,24 @@ function normalizeCrl(e) {
|
|
|
1228
1228
|
if (hasReparseableCrlShape(e)) return parseCertificateRevocationListDerOrThrow(new Uint8Array(e.der));
|
|
1229
1229
|
throw Error("certificate revocation list input is malformed");
|
|
1230
1230
|
}
|
|
1231
|
-
function parseSignedCrlFields(
|
|
1232
|
-
let
|
|
1233
|
-
|
|
1234
|
-
let
|
|
1235
|
-
|
|
1236
|
-
let
|
|
1231
|
+
function parseSignedCrlFields(t) {
|
|
1232
|
+
let n = w(t, { maxDepth: 64 }), r = e(t, n), i = parseCrlVersionField(r), a = i.version, o = u(r[i.nextIndex], "signature"), s = i.nextIndex + 1, c = u(r[s], "issuer"), d = u(r[s + 1], "thisUpdate"), f = s + 2, p = r[f], m = p !== void 0 && (p.tag === 23 || p.tag === 24) ? l(p) : void 0;
|
|
1233
|
+
m !== void 0 && (f += 1);
|
|
1234
|
+
let h = r[f], g = h?.tag === 48 ? parseRevokedCertificates(t, h, a) : [];
|
|
1235
|
+
h?.tag === 48 && (f += 1);
|
|
1236
|
+
let _ = r[f], v = parseCrlExtensionFields(t, _, a);
|
|
1237
1237
|
return {
|
|
1238
|
-
version:
|
|
1239
|
-
signature: parseAlgorithmIdentifier(
|
|
1240
|
-
issuer: parseIssuer(
|
|
1241
|
-
thisUpdate:
|
|
1242
|
-
...
|
|
1243
|
-
...
|
|
1244
|
-
...
|
|
1245
|
-
...
|
|
1246
|
-
...
|
|
1247
|
-
...
|
|
1248
|
-
revokedCertificates:
|
|
1238
|
+
version: a,
|
|
1239
|
+
signature: parseAlgorithmIdentifier(t, o),
|
|
1240
|
+
issuer: parseIssuer(t, c),
|
|
1241
|
+
thisUpdate: l(d),
|
|
1242
|
+
...m === void 0 ? {} : { nextUpdate: m },
|
|
1243
|
+
...v.authorityKeyIdentifier === void 0 ? {} : { authorityKeyIdentifier: v.authorityKeyIdentifier },
|
|
1244
|
+
...v.crlNumber === void 0 ? {} : { crlNumber: v.crlNumber },
|
|
1245
|
+
...v.baseCrlNumber === void 0 ? {} : { baseCrlNumber: v.baseCrlNumber },
|
|
1246
|
+
...v.issuingDistributionPoint === void 0 ? {} : { issuingDistributionPoint: v.issuingDistributionPoint },
|
|
1247
|
+
...v.freshestCrlDistributionPoints === void 0 ? {} : { freshestCrlDistributionPoints: v.freshestCrlDistributionPoints },
|
|
1248
|
+
revokedCertificates: g
|
|
1249
1249
|
};
|
|
1250
1250
|
}
|
|
1251
1251
|
function parseCrlVersionField(e) {
|
|
@@ -1255,61 +1255,61 @@ function parseCrlVersionField(e) {
|
|
|
1255
1255
|
version: 1,
|
|
1256
1256
|
nextIndex: 0
|
|
1257
1257
|
};
|
|
1258
|
-
let n =
|
|
1258
|
+
let n = r(t.value) + 1;
|
|
1259
1259
|
if (n !== 2) throw Error(`Unsupported CRL version: ${String(n)}`);
|
|
1260
1260
|
return {
|
|
1261
1261
|
version: n,
|
|
1262
1262
|
nextIndex: 1
|
|
1263
1263
|
};
|
|
1264
1264
|
}
|
|
1265
|
-
function parseRevokedCertificates(
|
|
1266
|
-
return
|
|
1265
|
+
function parseRevokedCertificates(t, n, r) {
|
|
1266
|
+
return e(t, n).map((e) => parseRevokedCertificateEntry(t, e, r));
|
|
1267
1267
|
}
|
|
1268
1268
|
function parseRevokedCertificateEntry(e, t, n) {
|
|
1269
|
-
let r = e.slice(t.start - t.headerLength, t.end), i =
|
|
1269
|
+
let r = e.slice(t.start - t.headerLength, t.end), i = T(r), a = u(i[0], "revoked serialNumber");
|
|
1270
1270
|
if (a.tag !== 2) throw Error("revoked serialNumber must use INTEGER");
|
|
1271
1271
|
let o = i[2];
|
|
1272
1272
|
if (o !== void 0 && n !== 2) throw Error("revoked certificate extensions require CRL version 2");
|
|
1273
1273
|
let s = parseRevokedCertificateExtensions(r, o);
|
|
1274
1274
|
return {
|
|
1275
|
-
serialNumberHex:
|
|
1276
|
-
revocationDate:
|
|
1275
|
+
serialNumberHex: d(a.value),
|
|
1276
|
+
revocationDate: l(u(i[1], "revocationDate")),
|
|
1277
1277
|
...s.reasonCode === void 0 ? {} : { reasonCode: s.reasonCode },
|
|
1278
1278
|
...s.invalidityDate === void 0 ? {} : { invalidityDate: s.invalidityDate },
|
|
1279
1279
|
...s.certificateIssuer === void 0 ? {} : { certificateIssuer: s.certificateIssuer }
|
|
1280
1280
|
};
|
|
1281
1281
|
}
|
|
1282
|
-
function parseCrlExtensionFields(
|
|
1283
|
-
if (
|
|
1284
|
-
if (
|
|
1285
|
-
let
|
|
1286
|
-
for (let
|
|
1287
|
-
return
|
|
1288
|
-
}
|
|
1289
|
-
function parseCrlExtensionField(
|
|
1290
|
-
let
|
|
1291
|
-
if (
|
|
1292
|
-
let
|
|
1293
|
-
if (
|
|
1294
|
-
|
|
1295
|
-
let
|
|
1296
|
-
if (
|
|
1297
|
-
if (!isSupportedCrlExtensionOid(
|
|
1298
|
-
applyParsedCrlExtensionField(
|
|
1282
|
+
function parseCrlExtensionFields(t, n, r) {
|
|
1283
|
+
if (n?.tag !== 160) return {};
|
|
1284
|
+
if (r !== 2) throw Error("CRL extensions require version 2");
|
|
1285
|
+
let i = {}, a = /* @__PURE__ */ new Set(), o = u(e(t, n)[0], "crl extensions");
|
|
1286
|
+
for (let n of e(t, o)) parseCrlExtensionField(t, n, a, i);
|
|
1287
|
+
return i;
|
|
1288
|
+
}
|
|
1289
|
+
function parseCrlExtensionField(n, r, i, o) {
|
|
1290
|
+
let s = e(n, r);
|
|
1291
|
+
if (s.length < 2 || s.length > 3 || s.length === 3 && s[1]?.tag !== 1) throw Error("Malformed CRL extension");
|
|
1292
|
+
let c = a(u(s[0], "extension OID").value);
|
|
1293
|
+
if (i.has(c)) throw Error(`Duplicate CRL extension OID: ${c}`);
|
|
1294
|
+
i.add(c);
|
|
1295
|
+
let l = s.length === 3 && t(u(s[1], "extension critical").value), d = u(s[s.length - 1], "extension value");
|
|
1296
|
+
if (d.tag !== 4) throw Error("CRL extension value must use OCTET STRING");
|
|
1297
|
+
if (!isSupportedCrlExtensionOid(c) && l) throw Error(`Unsupported critical CRL extension OID: ${c}`);
|
|
1298
|
+
applyParsedCrlExtensionField(c, d.value, o);
|
|
1299
1299
|
}
|
|
1300
1300
|
function isSupportedCrlExtensionOid(e) {
|
|
1301
|
-
return e ===
|
|
1301
|
+
return e === k.authorityKeyIdentifier || e === k.cRLNumber || e === k.deltaCRLIndicator || e === k.issuingDistributionPoint || e === k.freshestCRL;
|
|
1302
1302
|
}
|
|
1303
1303
|
function applyParsedCrlExtensionField(e, t, n) {
|
|
1304
|
-
if (e ===
|
|
1304
|
+
if (e === k.authorityKeyIdentifier) {
|
|
1305
1305
|
let e = parseAuthorityKeyIdentifier(t);
|
|
1306
1306
|
e !== void 0 && (n.authorityKeyIdentifier = e);
|
|
1307
1307
|
}
|
|
1308
|
-
e ===
|
|
1308
|
+
e === k.cRLNumber && (n.crlNumber = decodeCrlNumber(t)), e === k.deltaCRLIndicator && (n.baseCrlNumber = decodeCrlNumber(t)), e === k.issuingDistributionPoint && (n.issuingDistributionPoint = parseIssuingDistributionPoint(t)), e === k.freshestCRL && (n.freshestCrlDistributionPoints = parseDistributionPoints(t));
|
|
1309
1309
|
}
|
|
1310
1310
|
/** Accepts PEM, DER, or already-parsed certificate and returns a parsed certificate. */
|
|
1311
1311
|
function normalizeCrlCertificate(e) {
|
|
1312
|
-
return hasParsedCertificateShape(e) ?
|
|
1312
|
+
return hasParsedCertificateShape(e) ? le(new Uint8Array(e.der)) : X(e);
|
|
1313
1313
|
}
|
|
1314
1314
|
function hasParsedCertificateShape(e) {
|
|
1315
1315
|
return typeof e != "string" && "subjectPublicKeyInfoDer" in e;
|
|
@@ -1317,6 +1317,6 @@ function hasParsedCertificateShape(e) {
|
|
|
1317
1317
|
function hasReparseableCrlShape(e) {
|
|
1318
1318
|
return "der" in e && e.der instanceof Uint8Array;
|
|
1319
1319
|
}
|
|
1320
|
-
export {
|
|
1320
|
+
export { Z as ALL_DISTRIBUTION_POINT_REASONS, assertCrlMaxAge, authenticateCrl, checkCertificateRevocationAgainstCrl, checkRevocationAgainstAuthenticatedCrl, coversAllDistributionPointReasons, createCertificateRevocationList, isCertificateRevoked, isCrlApplicableTo, isCurrentDeltaCrl, normalizeCrl, parseCertificateRevocationListDer, parseCertificateRevocationListDerOrThrow, parseCertificateRevocationListPem, parseCertificateRevocationListPemOrThrow, revocationReasonFromCode, validateCertificateRevocationList, verifyCertificateRevocationListSignature };
|
|
1321
1321
|
|
|
1322
1322
|
//# sourceMappingURL=crl.js.map
|