micro509 0.17.1 → 0.19.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 +165 -6
- package/dist/crypto/crypto.d.ts +12 -4
- package/dist/crypto/crypto.js +30 -17
- package/dist/crypto/crypto.js.map +1 -1
- package/dist/crypto.d.ts +8 -2
- package/dist/der/der.d.ts +14 -4
- package/dist/der/der.js +19 -19
- package/dist/der/der.js.map +1 -1
- package/dist/der.d.ts +26 -2
- package/dist/der.js +4 -4
- package/dist/index.d.ts +84 -16
- package/dist/index.js +19 -19
- package/dist/internal/asn1/asn1.d.ts +1 -2
- package/dist/internal/asn1/asn1.js +10 -2
- package/dist/internal/asn1/asn1.js.map +1 -1
- package/dist/internal/asn1/ber.js.map +1 -1
- package/dist/internal/asn1/decode-refusal.js.map +1 -1
- package/dist/internal/asn1/der.d.ts +1 -2
- package/dist/internal/asn1/der.js.map +1 -1
- 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/algorithm-names.js.map +1 -1
- package/dist/internal/crypto/ecdsa.js.map +1 -1
- package/dist/internal/crypto/hash.js.map +1 -1
- package/dist/internal/crypto/pbes2.d.ts +1 -2
- package/dist/internal/crypto/pbes2.js +70 -70
- package/dist/internal/crypto/pbes2.js.map +1 -1
- 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/rsa-pss.js.map +1 -1
- package/dist/internal/crypto/sig-verify.d.ts +41 -2
- package/dist/internal/crypto/sig-verify.js +125 -38
- package/dist/internal/crypto/sig-verify.js.map +1 -1
- package/dist/internal/crypto/signing.d.ts +1 -2
- package/dist/internal/crypto/signing.js +26 -26
- package/dist/internal/crypto/signing.js.map +1 -1
- package/dist/internal/jose/base64url.js.map +1 -1
- package/dist/internal/jose/json-data.js +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/jose/strict-json.js.map +1 -1
- package/dist/internal/shared/base64.js.map +1 -1
- package/dist/internal/shared/dn.d.ts +1 -2
- package/dist/internal/shared/dn.js +1 -1
- package/dist/internal/shared/dn.js.map +1 -1
- package/dist/internal/shared/idna.js.map +1 -1
- package/dist/internal/shared/ip.d.ts +1 -2
- package/dist/internal/shared/ip.js.map +1 -1
- package/dist/internal/shared/mailbox.js.map +1 -1
- package/dist/internal/shared/punycode.js.map +1 -1
- package/dist/internal/shared/uri-host.js.map +1 -1
- package/dist/internal/verify/name-constraints-engine.js +64 -64
- package/dist/internal/verify/name-constraints-engine.js.map +1 -1
- package/dist/internal/verify/policy-engine.js +1 -1
- package/dist/internal/verify/policy-engine.js.map +1 -1
- package/dist/internal/verify/spki-distrust.js.map +1 -1
- package/dist/internal/verify/verify-path.d.ts +1 -2
- package/dist/internal/verify/verify-path.js +234 -128
- package/dist/internal/verify/verify-path.js.map +1 -1
- package/dist/internal/x509/directory-name.js +10 -10
- package/dist/internal/x509/directory-name.js.map +1 -1
- package/dist/internal/x509/extension-bits.js.map +1 -1
- package/dist/internal/x509/extension-errors.d.ts +1 -2
- package/dist/internal/x509/extension-errors.js.map +1 -1
- package/dist/internal/x509/extension-registry.js +18 -18
- package/dist/internal/x509/extension-registry.js.map +1 -1
- package/dist/internal/x509/general-name-profile.js +9 -9
- package/dist/internal/x509/general-name-profile.js.map +1 -1
- package/dist/internal/x509/general-name.js +32 -32
- package/dist/internal/x509/general-name.js.map +1 -1
- package/dist/internal/x509/name-fields.js +1 -1
- package/dist/internal/x509/name-fields.js.map +1 -1
- package/dist/internal/x509/or-address.js.map +1 -1
- package/dist/jose/base64url.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/jwt.js.map +1 -1
- 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-arithmetic.js.map +1 -1
- package/dist/kdf/argon2-core.js.map +1 -1
- package/dist/kdf/argon2-memory.js.map +1 -1
- package/dist/kdf/argon2-portable.js.map +1 -1
- package/dist/kdf/argon2.d.ts +7 -2
- package/dist/kdf/argon2.js.map +1 -1
- 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/pfx.js.map +1 -1
- package/dist/pkcs/pkcs12-mac.d.ts +1 -2
- package/dist/pkcs/pkcs12-mac.js +122 -122
- package/dist/pkcs/pkcs12-mac.js.map +1 -1
- package/dist/pkcs/pkcs7.d.ts +24 -3
- package/dist/pkcs/pkcs7.js +294 -256
- 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/result.js.map +1 -1
- package/dist/result.d.ts +6 -0
- package/dist/revocation/chain.d.ts +69 -16
- package/dist/revocation/chain.js +431 -303
- package/dist/revocation/chain.js.map +1 -1
- package/dist/revocation/crl.d.ts +67 -14
- package/dist/revocation/crl.js +656 -366
- package/dist/revocation/crl.js.map +1 -1
- package/dist/revocation/ocsp.d.ts +78 -24
- package/dist/revocation/ocsp.js +622 -436
- package/dist/revocation/ocsp.js.map +1 -1
- package/dist/revocation/revocation.d.ts +68 -14
- package/dist/revocation/revocation.js +195 -74
- package/dist/revocation/revocation.js.map +1 -1
- package/dist/revocation.d.ts +14 -5
- 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/wire.js.map +1 -1
- package/dist/ssh.d.ts +8 -0
- package/dist/verify/identity.d.ts +3 -4
- package/dist/verify/identity.js +33 -33
- package/dist/verify/identity.js.map +1 -1
- package/dist/verify/name-constraints.d.ts +9 -2
- package/dist/verify/policy.d.ts +9 -2
- package/dist/verify/verify.d.ts +85 -34
- package/dist/verify/verify.js +276 -226
- package/dist/verify/verify.js.map +1 -1
- package/dist/verify.d.ts +12 -2
- package/dist/x509/certificate.d.ts +4 -5
- package/dist/x509/certificate.js +40 -40
- package/dist/x509/certificate.js.map +1 -1
- package/dist/x509/csr.d.ts +3 -4
- package/dist/x509/csr.js +15 -15
- package/dist/x509/csr.js.map +1 -1
- 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/fingerprint.js.map +1 -1
- package/dist/x509/name-text.d.ts +1 -2
- package/dist/x509/name-text.js.map +1 -1
- package/dist/x509/name.d.ts +1 -2
- package/dist/x509/name.js +15 -15
- package/dist/x509/name.js.map +1 -1
- package/dist/x509/parse.d.ts +9 -6
- package/dist/x509/parse.js +394 -394
- package/dist/x509/parse.js.map +1 -1
- package/dist/x509.d.ts +17 -4
- package/dist/x509.js +8 -8
- package/package.json +32 -33
- 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 {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import { nameFieldKeyFromOid as
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import { parseCertificateDerOrThrow as
|
|
1
|
+
import { childrenOf as e, decodeBoolean as t, decodeIntegerMagnitude as n, decodeIntegerNumber as r, decodeNonNegativeIntegerBigInt as i, decodeObjectIdentifier as a, decodeString as o, hexToBytes as s, parseTime as c, requireElement as l, signatureBits 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 ee, optionalBytesEqual as te, readElement as ne, readRootElement as S, readSequenceChildren as C, sequence as w, time as T, tlv as E } from "../internal/asn1/der.js";
|
|
4
|
+
import { OIDS as D } from "../internal/asn1/oids.js";
|
|
5
|
+
import { describeSignatureAlgorithm as O } from "../internal/crypto/algorithm-names.js";
|
|
6
|
+
import { NO_CALLER_VERIFICATION as k, callerVerification as A, verifySignedDataDetailed as j } from "../internal/crypto/sig-verify.js";
|
|
7
|
+
import { encodeAlgorithmIdentifier as M, getSignatureAlgorithm as N, signBytes as P } from "../internal/crypto/signing.js";
|
|
8
|
+
import { base64Encode as F } from "../internal/shared/base64.js";
|
|
9
|
+
import { compareDistinguishedNames as I, compareRelativeDistinguishedNames as L } from "../internal/shared/dn.js";
|
|
10
|
+
import { encodeDistributionPointReasonFlagsContent as re, parseDistributionPointReasonFlagsContent as R } from "../internal/x509/extension-bits.js";
|
|
11
|
+
import { parseGeneralName as ie, 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 V, pemEncode as H } from "../pem/pem.js";
|
|
14
|
+
import { nameFieldKeyFromOid as U } from "../internal/x509/name-fields.js";
|
|
15
|
+
import { DECODE_REFUSAL_CODES as W, failureResult as G, rethrowIfInvariant as K, successResult as q, throwMicro509Error as J } from "../result/result.js";
|
|
16
|
+
import { encodeCrlDistributionPoints as ae, encodeExtension as Y, encodeSubjectAltName as oe, issuerKeyIdentifier as se } from "../x509/extensions.js";
|
|
17
|
+
import { encodeName as ce, encodeRelativeDistinguishedName as le, isNameInputEmpty as X } from "../x509/name.js";
|
|
18
|
+
import { parseCertificateDerOrThrow as ue, parseCertificateFromSource as Z } 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 de = {
|
|
30
30
|
unspecified: 0,
|
|
31
31
|
keyCompromise: 1,
|
|
32
32
|
cACompromise: 2,
|
|
@@ -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
|
+
X(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 = N(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 ? [] : [w(c.map((e) => createRevokedCertificate(e, a)))], u = w([
|
|
87
|
+
ee(1),
|
|
88
|
+
M(i),
|
|
89
|
+
ce(e.issuer),
|
|
90
|
+
T(a),
|
|
91
|
+
T(o),
|
|
92
|
+
...l,
|
|
93
|
+
_(0, w(s))
|
|
94
|
+
]), d = await P(e.signerPrivateKey, i, u), f = w([
|
|
95
|
+
u,
|
|
96
|
+
M(i),
|
|
97
|
+
h(d)
|
|
98
98
|
]);
|
|
99
99
|
return {
|
|
100
|
-
der:
|
|
101
|
-
pem:
|
|
102
|
-
base64:
|
|
100
|
+
der: f,
|
|
101
|
+
pem: H("X509 CRL", f),
|
|
102
|
+
base64: F(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 = C(e, { maxDepth: 64 });
|
|
113
113
|
if (t.length !== 3) throw Error("Malformed CRL");
|
|
114
|
-
let n =
|
|
114
|
+
let n = l(t[0], "TBSCertList"), r = l(t[1], "signatureAlgorithm"), i = l(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
|
-
|
|
119
|
+
...u(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: O(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(V("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 q(parseCertificateRevocationListDerOrThrow(e));
|
|
159
|
+
} catch (e) {
|
|
160
|
+
return K(e), f(e, W, "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 q(parseCertificateRevocationListPemOrThrow(e));
|
|
172
|
+
} catch (e) {
|
|
173
|
+
return K(e), f(e, W, "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(t, n) {
|
|
183
|
-
let r, i;
|
|
182
|
+
async function verifyCertificateRevocationListSignature(e, t, n = {}) {
|
|
183
|
+
let r = A(n.signatureVerifiers), i, a;
|
|
184
184
|
try {
|
|
185
|
-
|
|
186
|
-
} catch (
|
|
187
|
-
let
|
|
188
|
-
return
|
|
185
|
+
i = typeof e == "string" ? parseCertificateRevocationListPemOrThrow(e) : parseCertificateRevocationListDerOrThrow(new Uint8Array(e)), a = typeof t == "string" ? parseIssuerCertificatePem(t) : parseIssuerCertificateDer(new Uint8Array(t));
|
|
186
|
+
} catch (e) {
|
|
187
|
+
let t = p(e, W);
|
|
188
|
+
return t === void 0 ? verifyCertificateRevocationListFailureResult("malformed", "certificate revocation list or issuer certificate input is malformed") : verifyCertificateRevocationListFailureResult(t.code, t.message);
|
|
189
189
|
}
|
|
190
|
-
let
|
|
190
|
+
let o;
|
|
191
191
|
try {
|
|
192
|
-
|
|
193
|
-
} catch (
|
|
194
|
-
let
|
|
195
|
-
return
|
|
192
|
+
o = await j(i.signatureAlgorithmOid, i.signatureAlgorithmParametersDer, a.publicKeyAlgorithmOid, a.publicKeyParametersOid, a.subjectPublicKeyInfoDer, i.signatureValue, i.signatureValueUnusedBits, i.tbsCertListDer, r);
|
|
193
|
+
} catch (e) {
|
|
194
|
+
let t = p(e, W);
|
|
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 o.ok ? o.valid ? {
|
|
198
198
|
ok: !0,
|
|
199
|
-
value:
|
|
200
|
-
} : verifyCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature does not verify") :
|
|
199
|
+
value: i
|
|
200
|
+
} : verifyCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature does not verify") : o.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,
|
|
@@ -208,59 +208,98 @@ async function verifyCertificateRevocationListSignature(t, n) {
|
|
|
208
208
|
* `stale_crl` unless `maxAgeMs` is set.
|
|
209
209
|
*/
|
|
210
210
|
async function validateCertificateRevocationList(e) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
return
|
|
211
|
+
return await validateCrlWith(e, A(e.signatureVerifiers));
|
|
212
|
+
}
|
|
213
|
+
/** {@linkcode validateCertificateRevocationList} with resolved caller verification. */
|
|
214
|
+
async function validateCrlWith(e, t) {
|
|
215
|
+
return await validateCrlBy(e, {
|
|
216
|
+
kind: "certificate",
|
|
217
|
+
certificate: e.issuerCertificate
|
|
218
|
+
}, t);
|
|
219
|
+
}
|
|
220
|
+
/** {@linkcode validateCertificateRevocationList} for a CRL that `authority` signs. */
|
|
221
|
+
async function validateCrlBy(e, t, n) {
|
|
222
|
+
assertCrlMaxAge(e.maxAgeMs), assertClockSkew(e.clockSkewMs);
|
|
223
|
+
let r = await authenticateCrl(e.crl, t, n);
|
|
224
|
+
if (!r.ok) return r;
|
|
225
|
+
let i = crlFreshnessFailure(r.value, e.at ?? /* @__PURE__ */ new Date(), e.clockSkewMs ?? 0, e.maxAgeMs);
|
|
226
|
+
return i === void 0 ? r : validateCertificateRevocationListFailureResult("stale_crl", i);
|
|
216
227
|
}
|
|
217
228
|
/**
|
|
218
229
|
* Verifies the issuer binding, cRLSign permission and signature of `crl`
|
|
219
|
-
* against `
|
|
230
|
+
* against `authority`, without freshness checks. A trust anchor carries no
|
|
231
|
+
* certificate, so the RFC 10007 §4 key usage check applies to certificates only.
|
|
220
232
|
*
|
|
221
233
|
* @internal
|
|
222
234
|
*/
|
|
223
|
-
async function authenticateCrl(t, n) {
|
|
235
|
+
async function authenticateCrl(e, t, n = k) {
|
|
224
236
|
let r;
|
|
225
237
|
try {
|
|
226
|
-
r = normalizeCrl(
|
|
227
|
-
} catch (
|
|
228
|
-
let
|
|
229
|
-
return
|
|
230
|
-
}
|
|
231
|
-
let i;
|
|
232
|
-
try {
|
|
233
|
-
i = normalizeCrlCertificate(n);
|
|
234
|
-
} catch (t) {
|
|
235
|
-
let n = o(t, e);
|
|
236
|
-
return n === void 0 ? validateCertificateRevocationListFailureResult("signature_invalid", "issuer certificate input is malformed") : validateCertificateRevocationListFailureResult(n.code, n.message);
|
|
238
|
+
r = normalizeCrl(e);
|
|
239
|
+
} catch (e) {
|
|
240
|
+
let t = p(e, W);
|
|
241
|
+
return t === void 0 ? validateCertificateRevocationListFailureResult("malformed", "certificate revocation list signed content is malformed") : validateCertificateRevocationListFailureResult(t.code, t.message);
|
|
237
242
|
}
|
|
238
|
-
|
|
239
|
-
if (
|
|
240
|
-
|
|
241
|
-
if (
|
|
242
|
-
|
|
243
|
+
let i = resolveCrlSigningKey(t);
|
|
244
|
+
if (!i.ok) return i;
|
|
245
|
+
let { issuer: a, issuerCertificate: o } = i;
|
|
246
|
+
if (!I(r.issuer, a.subject)) return validateCertificateRevocationListFailureResult("issuer_mismatch", "CRL issuer name does not match certificate subject");
|
|
247
|
+
if (r.authorityKeyIdentifier !== void 0 && a.subjectKeyIdentifier !== void 0 && r.authorityKeyIdentifier !== a.subjectKeyIdentifier) return validateCertificateRevocationListFailureResult("issuer_mismatch", "CRL authority key identifier does not match issuer subject key identifier");
|
|
248
|
+
let s = o === void 0 ? void 0 : crlSignFailure(o);
|
|
249
|
+
if (s !== void 0) return s;
|
|
250
|
+
let c;
|
|
243
251
|
try {
|
|
244
|
-
|
|
245
|
-
} catch (
|
|
246
|
-
let
|
|
247
|
-
return
|
|
252
|
+
c = await j(r.signatureAlgorithmOid, r.signatureAlgorithmParametersDer, a.publicKeyAlgorithmOid, a.publicKeyParametersOid, a.subjectPublicKeyInfoDer, r.signatureValue, r.signatureValueUnusedBits, r.tbsCertListDer, n);
|
|
253
|
+
} catch (e) {
|
|
254
|
+
let t = p(e, W);
|
|
255
|
+
return t === void 0 ? validateCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature verification failed") : validateCertificateRevocationListFailureResult(t.code, t.message);
|
|
248
256
|
}
|
|
249
|
-
return
|
|
257
|
+
return c.ok ? c.valid ? {
|
|
250
258
|
ok: !0,
|
|
251
259
|
value: r
|
|
252
|
-
} : validateCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature does not verify") :
|
|
260
|
+
} : validateCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature does not verify") : c.code === "verification_error" ? validateCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature verification failed") : validateCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature uses unsupported algorithm parameters");
|
|
261
|
+
}
|
|
262
|
+
/** The signing key `authority` names, with its certificate when it has one. */
|
|
263
|
+
function resolveCrlSigningKey(e) {
|
|
264
|
+
if (e.kind === "trust_anchor") return {
|
|
265
|
+
ok: !0,
|
|
266
|
+
issuer: e.trustAnchor,
|
|
267
|
+
issuerCertificate: void 0
|
|
268
|
+
};
|
|
269
|
+
try {
|
|
270
|
+
let t = normalizeCrlCertificate(e.certificate);
|
|
271
|
+
return {
|
|
272
|
+
ok: !0,
|
|
273
|
+
issuer: t,
|
|
274
|
+
issuerCertificate: t
|
|
275
|
+
};
|
|
276
|
+
} catch (e) {
|
|
277
|
+
let t = p(e, W);
|
|
278
|
+
return t === void 0 ? validateCertificateRevocationListFailureResult("malformed", "issuer certificate input is malformed") : validateCertificateRevocationListFailureResult(t.code, t.message);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
/** RFC 10007 §4: a v3 CRL issuer certificate must carry key usage asserting cRLSign. */
|
|
282
|
+
function crlSignFailure(e) {
|
|
283
|
+
if (e.keyUsage === void 0 && e.version === 3) return validateCertificateRevocationListFailureResult("crl_sign_not_permitted", "v3 issuer certificate has no key usage extension");
|
|
284
|
+
if (e.keyUsage !== void 0 && !e.keyUsage.flags.includes("cRLSign")) return validateCertificateRevocationListFailureResult("crl_sign_not_permitted", "issuer certificate key usage does not permit CRL signing");
|
|
253
285
|
}
|
|
254
286
|
function assertCrlMaxAge(e) {
|
|
255
287
|
if (e !== void 0 && (!Number.isFinite(e) || e < 0)) throw RangeError(`Invalid maxAgeMs: must be a non-negative number, got ${e}`);
|
|
256
288
|
}
|
|
289
|
+
function assertClockSkew(e) {
|
|
290
|
+
if (e !== void 0 && (!Number.isFinite(e) || e < 0)) throw RangeError(`Invalid clockSkewMs: must be a non-negative number, got ${e}`);
|
|
291
|
+
}
|
|
257
292
|
function crlFreshnessFailure(e, t, n, r) {
|
|
258
293
|
if (e.thisUpdate.getTime() - n > t.getTime() || e.nextUpdate !== void 0 && e.nextUpdate.getTime() + n < t.getTime()) return "CRL is not valid at requested time";
|
|
259
294
|
if (e.nextUpdate === void 0 && r === void 0) return "CRL has no nextUpdate and no maximum age is set";
|
|
260
295
|
if (r !== void 0 && t.getTime() - e.thisUpdate.getTime() > r + n) return "CRL thisUpdate is older than the maximum age";
|
|
261
296
|
}
|
|
262
|
-
function
|
|
263
|
-
return e.nextUpdate
|
|
297
|
+
function deltaCrlFreshnessFailure(e, t, n, r) {
|
|
298
|
+
return e.nextUpdate === void 0 ? "delta CRL has no nextUpdate" : crlFreshnessFailure(e, t, n, r);
|
|
299
|
+
}
|
|
300
|
+
/** Whether `crl` was issued by `at`, so its entries record revocations known then. */
|
|
301
|
+
function isIssuedCrl(e, t, n) {
|
|
302
|
+
return e.thisUpdate.getTime() - n <= t.getTime();
|
|
264
303
|
}
|
|
265
304
|
/**
|
|
266
305
|
* End-to-end revocation check: validates the CRL (and optional delta CRL),
|
|
@@ -284,110 +323,361 @@ function isCurrentDeltaCrl(e, t, n, r) {
|
|
|
284
323
|
* }
|
|
285
324
|
* ```
|
|
286
325
|
*/
|
|
287
|
-
async function checkCertificateRevocationAgainstCrl(
|
|
288
|
-
|
|
326
|
+
async function checkCertificateRevocationAgainstCrl(e) {
|
|
327
|
+
return await checkCertificateRevocationAgainstCrlWith(e, A(e.signatureVerifiers));
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* {@linkcode checkCertificateRevocationAgainstCrl} with resolved caller
|
|
331
|
+
* verification, which can carry the issuer's inherited key parameters.
|
|
332
|
+
*
|
|
333
|
+
* @internal
|
|
334
|
+
*/
|
|
335
|
+
async function checkCertificateRevocationAgainstCrlWith(e, t) {
|
|
336
|
+
assertCrlMaxAge(e.maxAgeMs), assertClockSkew(e.clockSkewMs);
|
|
289
337
|
let n;
|
|
290
338
|
try {
|
|
291
|
-
n = normalizeCrlCertificate(
|
|
292
|
-
} catch (
|
|
293
|
-
let
|
|
294
|
-
return
|
|
339
|
+
n = normalizeCrlCertificate(e.certificate);
|
|
340
|
+
} catch (e) {
|
|
341
|
+
let t = p(e, W);
|
|
342
|
+
return t === void 0 ? checkCertificateRevocationAgainstCrlFailureResult("malformed", "certificate input is malformed") : checkCertificateRevocationAgainstCrlFailureResult(t.code, t.message);
|
|
295
343
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
344
|
+
return await checkCertificateRevocationAgainstCrlBy(n, e.crl, {
|
|
345
|
+
kind: "certificate",
|
|
346
|
+
certificate: e.issuerCertificate
|
|
347
|
+
}, e, t);
|
|
300
348
|
}
|
|
301
349
|
/**
|
|
302
|
-
*
|
|
303
|
-
*
|
|
350
|
+
* {@linkcode checkCertificateRevocationAgainstCrl} for a CRL that `authority`
|
|
351
|
+
* signs, which may be a bare trust anchor.
|
|
304
352
|
*
|
|
305
353
|
* @internal
|
|
306
354
|
*/
|
|
307
|
-
async function
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
355
|
+
async function checkCertificateRevocationAgainstCrlBy(e, t, n, r, i) {
|
|
356
|
+
let a = await authenticateCrl(t, n, i);
|
|
357
|
+
if (!a.ok) return checkCertificateRevocationAgainstCrlFailureResult(a.code, a.message);
|
|
358
|
+
let o = await checkRevocationAgainstAuthenticatedCrl(e, a.value, n, r, i);
|
|
359
|
+
if (o.kind === "checked") return o.result;
|
|
360
|
+
let s = o.kind === "delta_unresolved" ? o.complete : await checkCompleteCrlAlone(e, a.value, n, r, i);
|
|
361
|
+
return o.kind === "delta_stale" ? s : irremovableCrlRevocation(e, s, r.at ?? /* @__PURE__ */ new Date()) ?? o.failure;
|
|
362
|
+
}
|
|
363
|
+
/** {@linkcode checkRevocationAgainstAuthenticatedCrl} on `completeCrl` without its delta CRL. */
|
|
364
|
+
async function checkCompleteCrlAlone(e, t, n, r, i) {
|
|
365
|
+
let { deltaCrl: a, ...o } = r, s = await checkRevocationAgainstAuthenticatedCrl(e, t, n, o, i);
|
|
366
|
+
return s.kind === "checked" ? s.result : s.failure;
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Checks `certificate` against a complete CRL that {@linkcode authenticateCrl}
|
|
370
|
+
* accepted for `authority`, updated by `input.deltaCrl` when given.
|
|
371
|
+
*/
|
|
372
|
+
async function checkRevocationAgainstAuthenticatedCrl(e, t, n, r, i = A(r.signatureVerifiers)) {
|
|
373
|
+
if (r.deltaCrl === void 0) {
|
|
374
|
+
let n = crlFreshnessFailure(t, r.at ?? /* @__PURE__ */ new Date(), r.clockSkewMs ?? 0, r.maxAgeMs);
|
|
375
|
+
if (n !== void 0) return {
|
|
311
376
|
kind: "checked",
|
|
312
|
-
result: checkCertificateRevocationAgainstCrlFailureResult("stale_crl",
|
|
377
|
+
result: staleCompleteCrlResult(e, t, checkCertificateRevocationAgainstCrlFailureResult("stale_crl", n), r)
|
|
313
378
|
};
|
|
314
379
|
}
|
|
315
|
-
let
|
|
316
|
-
if (!
|
|
380
|
+
let a = await validateOptionalDeltaCrl(r, t, n, i);
|
|
381
|
+
if (!a.ok) return {
|
|
317
382
|
kind: "delta_rejected",
|
|
318
|
-
failure:
|
|
383
|
+
failure: a
|
|
319
384
|
};
|
|
320
|
-
|
|
321
|
-
|
|
385
|
+
if (a.value !== void 0 && a.stale !== void 0) return staleDeltaCrlOutcome(e, t, a.value, a.stale, r);
|
|
386
|
+
let o = a.value, s = checkCrlApplicability(e, t);
|
|
387
|
+
if (!s.ok) return {
|
|
322
388
|
kind: "checked",
|
|
323
|
-
result:
|
|
389
|
+
result: s.failure
|
|
324
390
|
};
|
|
325
|
-
if (
|
|
326
|
-
let t = checkCrlApplicability(e,
|
|
391
|
+
if (o !== void 0) {
|
|
392
|
+
let t = checkCrlApplicability(e, o, !0);
|
|
327
393
|
if (!t.ok) return {
|
|
328
394
|
kind: "delta_rejected",
|
|
329
395
|
failure: t.failure
|
|
330
396
|
};
|
|
331
397
|
}
|
|
332
|
-
let
|
|
333
|
-
if (!
|
|
398
|
+
let c = findRevokedCertificateEntry(e, t);
|
|
399
|
+
if (!c.ok) return {
|
|
334
400
|
kind: "checked",
|
|
335
|
-
result:
|
|
401
|
+
result: c
|
|
336
402
|
};
|
|
337
|
-
let
|
|
338
|
-
if (
|
|
339
|
-
let
|
|
340
|
-
if (!
|
|
403
|
+
let l;
|
|
404
|
+
if (o !== void 0) {
|
|
405
|
+
let n = findRevokedCertificateEntry(e, o);
|
|
406
|
+
if (!n.ok) return {
|
|
341
407
|
kind: "delta_unresolved",
|
|
342
|
-
failure:
|
|
343
|
-
complete: resolveCertificateRevocationStatus(e, void 0, t,
|
|
408
|
+
failure: n,
|
|
409
|
+
complete: resolveCertificateRevocationStatus(e, void 0, t, c.entry, void 0, s.coveredReasons, r.unrecognizedReasonCode ?? "revoked")
|
|
344
410
|
};
|
|
345
|
-
|
|
411
|
+
l = n.entry;
|
|
346
412
|
}
|
|
347
413
|
return {
|
|
348
414
|
kind: "checked",
|
|
349
|
-
result: resolveCertificateRevocationStatus(e,
|
|
415
|
+
result: resolveCertificateRevocationStatus(e, o?.thisUpdate, t, c.entry, l, s.coveredReasons, r.unrecognizedReasonCode ?? "revoked")
|
|
350
416
|
};
|
|
351
417
|
}
|
|
418
|
+
/**
|
|
419
|
+
* A key equal for two CRLs exactly when their signed content and signature
|
|
420
|
+
* are equal.
|
|
421
|
+
*
|
|
422
|
+
* @internal
|
|
423
|
+
*/
|
|
424
|
+
function signedCrlKey(e) {
|
|
425
|
+
return [
|
|
426
|
+
e.signatureAlgorithmOid,
|
|
427
|
+
d(e.signatureAlgorithmParametersDer ?? /* @__PURE__ */ new Uint8Array()),
|
|
428
|
+
d(e.signatureValue),
|
|
429
|
+
e.signatureValueUnusedBits,
|
|
430
|
+
d(e.tbsCertListDer)
|
|
431
|
+
].join(":");
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* `crls` with each signed content and signature kept once.
|
|
435
|
+
*
|
|
436
|
+
* @internal
|
|
437
|
+
*/
|
|
438
|
+
function distinctSignedCrls(e) {
|
|
439
|
+
let t = /* @__PURE__ */ new Set();
|
|
440
|
+
return e.filter((e) => {
|
|
441
|
+
let n = signedCrlKey(e);
|
|
442
|
+
return !t.has(n) && (t.add(n), !0);
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Every delta CRL that can update `baseCrl` and was issued by `at`, newest
|
|
447
|
+
* first. A delta CRL that is no longer current still settles a revocation no
|
|
448
|
+
* later CRL could remove (RFC 5280 §5.3.1), so currency does not move it
|
|
449
|
+
* behind older ones.
|
|
450
|
+
*/
|
|
451
|
+
function rankApplicableDeltaCrls(e, t, n, r) {
|
|
452
|
+
return t.filter((t) => isCompatibleDeltaCrl(e, t) && isIssuedCrl(t, n, r)).sort(compareDeltaCrlRecency);
|
|
453
|
+
}
|
|
454
|
+
/** Whether {@linkcode checkDeltaCrlCompatibility} accepts `deltaCrl` for `completeCrl`. */
|
|
455
|
+
function isCompatibleDeltaCrl(e, t) {
|
|
456
|
+
try {
|
|
457
|
+
return checkDeltaCrlCompatibility(e, t) === void 0;
|
|
458
|
+
} catch (e) {
|
|
459
|
+
return K(e), !1;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Orders delta CRLs newest first by `thisUpdate`, the key RFC 5280 §5.2.4
|
|
464
|
+
* names for the most current one, then by CRL number.
|
|
465
|
+
*/
|
|
466
|
+
function compareDeltaCrlRecency(e, t) {
|
|
467
|
+
let n = t.thisUpdate.getTime() - e.thisUpdate.getTime();
|
|
468
|
+
if (n !== 0) return n;
|
|
469
|
+
let r = e.crlNumber ?? 0n, i = t.crlNumber ?? 0n;
|
|
470
|
+
return r === i ? 0 : r < i ? 1 : -1;
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Whether `newer` supersedes `older` by both its `thisUpdate` and its CRL
|
|
474
|
+
* number (RFC 5280 §5.2.3, §5.1.2.4). RFC 5280 leaves a pair whose keys
|
|
475
|
+
* disagree unspecified, and micro509 ranks such a pair alike.
|
|
476
|
+
*/
|
|
477
|
+
function supersedesDeltaCrl(e, t) {
|
|
478
|
+
return e.thisUpdate.getTime() > t.thisUpdate.getTime() && e.crlNumber !== void 0 && t.crlNumber !== void 0 && e.crlNumber > t.crlNumber;
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Checks `certificate` against `completeCrl`, which `authority` signs, and
|
|
482
|
+
* the delta CRLs in `deltaCrls` that update it, newest first. A rejected
|
|
483
|
+
* delta CRL, or one past its `nextUpdate` that records no lasting revocation,
|
|
484
|
+
* passes the search to the next. The first current delta CRL settles the
|
|
485
|
+
* status, and one past its `nextUpdate` settles a revocation no later CRL
|
|
486
|
+
* could remove (RFC 5280 §5.3.1, §3.3). After a good status, older delta CRLs
|
|
487
|
+
* are still read for such a revocation the newer one omits. Each delta CRL
|
|
488
|
+
* check spends one from {@linkcode DELTA_CRL_ATTEMPTS_PER_BASE} and from every
|
|
489
|
+
* budget in `budgets`. When they leave a delta CRL unread, the outcome is
|
|
490
|
+
* `retry_limit` unless the complete CRL holds such a revocation. Under
|
|
491
|
+
* `unreadSupersededDeltaCrls: 'ignore'`, only an unread delta CRL that
|
|
492
|
+
* {@linkcode mayChangeSettledStatus} finds could change the status counts. A
|
|
493
|
+
* complete CRL that does not cover `certificate` spends none.
|
|
494
|
+
*
|
|
495
|
+
* @internal
|
|
496
|
+
*/
|
|
497
|
+
async function checkCertificateRevocationAgainstCrlsBy(e, t, n, r, i, a, o = []) {
|
|
498
|
+
let s = await authenticateCrl(t, r, a);
|
|
499
|
+
if (!s.ok) return {
|
|
500
|
+
kind: "checked",
|
|
501
|
+
result: checkCertificateRevocationAgainstCrlFailureResult(s.code, s.message)
|
|
502
|
+
};
|
|
503
|
+
let c = i.at ?? /* @__PURE__ */ new Date(), l = checkCrlApplicability(e, s.value).ok ? rankApplicableDeltaCrls(s.value, n, c, i.clockSkewMs ?? 0) : [], u = {
|
|
504
|
+
attempts: 0,
|
|
505
|
+
unread: []
|
|
506
|
+
};
|
|
507
|
+
for (let [t, n] of l.entries()) {
|
|
508
|
+
if (!spendDeltaCrlAttempt(u, o)) {
|
|
509
|
+
u.unread = l.slice(t);
|
|
510
|
+
break;
|
|
511
|
+
}
|
|
512
|
+
if (recordDeltaCrlOutcome(u, e, n, await checkRevocationAgainstAuthenticatedCrl(e, s.value, r, {
|
|
513
|
+
...i,
|
|
514
|
+
deltaCrl: n
|
|
515
|
+
}, a), c), u.result !== void 0) return u.result;
|
|
516
|
+
}
|
|
517
|
+
let d = i.unreadSupersededDeltaCrls === "ignore" ? u.unread.some((e) => mayChangeSettledStatus(u, e, c, i)) : u.unread.length > 0;
|
|
518
|
+
if (!d && u.good !== void 0) return u.good;
|
|
519
|
+
let f = await checkRevocationAgainstAuthenticatedCrl(e, s.value, r, i, a), p = f.kind === "checked" ? f.result : f.failure;
|
|
520
|
+
return d ? settledOrUnsettled(irremovableCrlRevocation(e, p, c), "retry_limit") : {
|
|
521
|
+
kind: "checked",
|
|
522
|
+
result: p
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Whether reading the unread `deltaCrl` could change the status `search`
|
|
527
|
+
* reached by more than an older entry its newer delta CRLs omit. After a good
|
|
528
|
+
* status, only a delta CRL that the one settling it supersedes cannot.
|
|
529
|
+
* Otherwise only one that is not current and that a delta CRL examined
|
|
530
|
+
* supersedes cannot, since a current one settles the status.
|
|
531
|
+
*/
|
|
532
|
+
function mayChangeSettledStatus(e, t, n, r) {
|
|
533
|
+
return e.good === void 0 ? deltaCrlFreshnessFailure(t, n, r.clockSkewMs ?? 0, r.maxAgeMs) === void 0 || e.newest === void 0 || !supersedesDeltaCrl(e.newest, t) : !supersedesDeltaCrl(e.good.deltaCrl, t);
|
|
534
|
+
}
|
|
535
|
+
/** Spends one delta CRL check from the per-base limit and every budget, or none when any is spent. */
|
|
536
|
+
function spendDeltaCrlAttempt(e, t) {
|
|
537
|
+
if (e.attempts >= 4 || t.some((e) => e.remaining <= 0)) return !1;
|
|
538
|
+
e.attempts += 1;
|
|
539
|
+
for (let e of t) --e.remaining;
|
|
540
|
+
return !0;
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Folds the outcome of `deltaCrl` into `search`. A delta CRL that the one
|
|
544
|
+
* settling the status as good supersedes only adds what
|
|
545
|
+
* {@linkcode olderDeltaRevocation} finds. Any other settles like the first,
|
|
546
|
+
* so two delta CRLs ranked alike that disagree yield the stricter result.
|
|
547
|
+
*/
|
|
548
|
+
function recordDeltaCrlOutcome(e, t, n, r, i) {
|
|
549
|
+
r.kind !== "delta_rejected" && (e.newest ??= n, e.good !== void 0 && supersedesDeltaCrl(e.good.deltaCrl, n) ? e.result = olderDeltaRevocation(t, n, r, i) : r.kind === "checked" ? isGoodResult(r.result) ? e.good ??= {
|
|
550
|
+
kind: "checked",
|
|
551
|
+
result: r.result,
|
|
552
|
+
deltaCrl: n
|
|
553
|
+
} : e.result = {
|
|
554
|
+
kind: "checked",
|
|
555
|
+
result: r.result,
|
|
556
|
+
deltaCrl: n
|
|
557
|
+
} : r.kind === "delta_unresolved" && (e.result = settledOrUnsettled(irremovableCrlRevocation(t, r.complete, i), "delta_unusable")));
|
|
558
|
+
}
|
|
559
|
+
function isGoodResult(e) {
|
|
560
|
+
return e.ok && e.value.status === "good";
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* What an older delta CRL changes after a newer one settled the status as
|
|
564
|
+
* good: a revocation no later CRL may drop (RFC 5280 §5.3.1, §3.3), a
|
|
565
|
+
* failure such as an entry `unrecognizedReasonCode: 'reject'` refuses, or
|
|
566
|
+
* entries that cannot settle the status. A newer delta CRL that omits such an
|
|
567
|
+
* entry contradicts its issuer.
|
|
568
|
+
*/
|
|
569
|
+
function olderDeltaRevocation(e, t, n, r) {
|
|
570
|
+
if (n.kind === "delta_unresolved") return settledOrUnsettled(irremovableCrlRevocation(e, n.complete, r), "delta_unusable");
|
|
571
|
+
if (n.kind !== "checked") return;
|
|
572
|
+
if (!n.result.ok) return {
|
|
573
|
+
kind: "checked",
|
|
574
|
+
result: n.result,
|
|
575
|
+
deltaCrl: t
|
|
576
|
+
};
|
|
577
|
+
let i = irremovableCrlRevocation(e, n.result, r);
|
|
578
|
+
return i === void 0 ? void 0 : {
|
|
579
|
+
kind: "checked",
|
|
580
|
+
result: i,
|
|
581
|
+
deltaCrl: t
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
function settledOrUnsettled(e, t) {
|
|
585
|
+
return e === void 0 ? {
|
|
586
|
+
kind: "unsettled",
|
|
587
|
+
reason: t
|
|
588
|
+
} : {
|
|
589
|
+
kind: "checked",
|
|
590
|
+
result: e
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* `result` when it revokes `certificate` in a way no delta CRL could undo at
|
|
595
|
+
* `at`. RFC 5280 §5.3.1 lets removeFromCRL clear only a certificateHold entry
|
|
596
|
+
* or a certificate that has expired.
|
|
597
|
+
*/
|
|
598
|
+
function irremovableCrlRevocation(e, t, n) {
|
|
599
|
+
return e.notAfter.getTime() >= n.getTime() && t.ok && t.value.status === "revoked" && t.value.reasonCode !== "certificateHold" ? t : void 0;
|
|
600
|
+
}
|
|
352
601
|
/** RFC 5280 §6.3.3 (d): interim_reasons_mask from the matched DP and the CRL's IDP. */
|
|
353
602
|
function interimReasonsMask(e, t) {
|
|
354
603
|
let n = e?.reasons?.flags, r = t?.onlySomeReasons?.flags;
|
|
355
604
|
return n !== void 0 && r !== void 0 ? n.filter((e) => r.includes(e)) : n === void 0 ? r === void 0 ? Q : [...r] : [...n];
|
|
356
605
|
}
|
|
357
|
-
/**
|
|
358
|
-
|
|
606
|
+
/**
|
|
607
|
+
* Authenticates an optional delta CRL and checks compatibility with its
|
|
608
|
+
* complete CRL. A delta CRL issued by `input.at` but not current there comes
|
|
609
|
+
* back with the freshness failure as `stale`.
|
|
610
|
+
*/
|
|
611
|
+
async function validateOptionalDeltaCrl(e, t, n, r) {
|
|
359
612
|
if (e.deltaCrl === void 0) return { ok: !0 };
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
});
|
|
367
|
-
if (!n.ok) return checkCertificateRevocationAgainstCrlFailureResult(n.code, n.message);
|
|
368
|
-
if (n.value.nextUpdate === void 0) return checkCertificateRevocationAgainstCrlFailureResult("stale_crl", "delta CRL has no nextUpdate");
|
|
369
|
-
let r;
|
|
613
|
+
assertCrlMaxAge(e.maxAgeMs), assertClockSkew(e.clockSkewMs);
|
|
614
|
+
let i = await authenticateCrl(e.deltaCrl, n, r);
|
|
615
|
+
if (!i.ok) return checkCertificateRevocationAgainstCrlFailureResult(i.code, i.message);
|
|
616
|
+
let a = e.at ?? /* @__PURE__ */ new Date(), o = e.clockSkewMs ?? 0, s = deltaCrlFreshnessFailure(i.value, a, o, e.maxAgeMs);
|
|
617
|
+
if (s !== void 0 && !isIssuedCrl(i.value, a, o)) return checkCertificateRevocationAgainstCrlFailureResult("stale_crl", s);
|
|
618
|
+
let c;
|
|
370
619
|
try {
|
|
371
|
-
|
|
620
|
+
c = checkDeltaCrlCompatibility(t, i.value);
|
|
372
621
|
} catch (e) {
|
|
373
622
|
return crlNameRefusalFailure(e);
|
|
374
623
|
}
|
|
375
|
-
return
|
|
624
|
+
return c === void 0 ? {
|
|
376
625
|
ok: !0,
|
|
377
|
-
value:
|
|
626
|
+
value: i.value,
|
|
627
|
+
...s === void 0 ? {} : { stale: checkCertificateRevocationAgainstCrlFailureResult("stale_crl", s) }
|
|
628
|
+
} : s === void 0 ? c : checkCertificateRevocationAgainstCrlFailureResult("stale_crl", s);
|
|
629
|
+
}
|
|
630
|
+
/**
|
|
631
|
+
* The result of `completeCrl`, which is not current at `input.at`: its
|
|
632
|
+
* revocation of `certificate` when no later CRL could remove it (RFC 5280
|
|
633
|
+
* §5.3.1, §3.3), otherwise `stale`. A CRL issued after `input.at` yields
|
|
634
|
+
* `stale`.
|
|
635
|
+
*/
|
|
636
|
+
function staleCompleteCrlResult(e, t, n, r) {
|
|
637
|
+
let i = r.at ?? /* @__PURE__ */ new Date();
|
|
638
|
+
if (!isIssuedCrl(t, i, r.clockSkewMs ?? 0) || !checkCrlApplicability(e, t).ok) return n;
|
|
639
|
+
let a = findRevokedCertificateEntry(e, t);
|
|
640
|
+
if (!a.ok || a.entry === void 0) return n;
|
|
641
|
+
let o = revokedEntryResult(t, a.entry, r.unrecognizedReasonCode ?? "revoked");
|
|
642
|
+
return o.ok ? irremovableCrlRevocation(e, o, i) ?? n : o;
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* The outcome of `deltaCrl`, which updates `completeCrl` but is not current at
|
|
646
|
+
* `input.at`. Its revocation of `certificate` settles the status when no later
|
|
647
|
+
* CRL could remove it (RFC 5280 §5.3.1). Otherwise it is `delta_stale` when it
|
|
648
|
+
* applies to `certificate`, and settles nothing. A delta CRL that does not
|
|
649
|
+
* apply is rejected with `stale`.
|
|
650
|
+
*/
|
|
651
|
+
function staleDeltaCrlOutcome(e, t, n, r, i) {
|
|
652
|
+
let a = {
|
|
653
|
+
kind: "delta_rejected",
|
|
654
|
+
failure: r
|
|
655
|
+
};
|
|
656
|
+
if (!checkCrlApplicability(e, t).ok || !checkCrlApplicability(e, n, !0).ok) return a;
|
|
657
|
+
let o = findRevokedCertificateEntry(e, n);
|
|
658
|
+
if (!o.ok) return a;
|
|
659
|
+
let s = {
|
|
660
|
+
kind: "delta_stale",
|
|
661
|
+
failure: r
|
|
662
|
+
};
|
|
663
|
+
if (o.entry === void 0 || o.entry.reasonCode === "removeFromCRL") return s;
|
|
664
|
+
let c = revokedEntryResult(t, o.entry, i.unrecognizedReasonCode ?? "revoked");
|
|
665
|
+
return c.ok && irremovableCrlRevocation(e, c, i.at ?? /* @__PURE__ */ new Date()) === void 0 ? s : {
|
|
666
|
+
kind: "checked",
|
|
667
|
+
result: c
|
|
378
668
|
};
|
|
379
669
|
}
|
|
380
670
|
/** Builds a `VerifyCertificateRevocationListSignatureFailureResult`. */
|
|
381
|
-
function verifyCertificateRevocationListFailureResult(e,
|
|
382
|
-
return
|
|
671
|
+
function verifyCertificateRevocationListFailureResult(e, t) {
|
|
672
|
+
return G(e, t);
|
|
383
673
|
}
|
|
384
674
|
/** Builds a `ValidateCertificateRevocationListFailureResult`. */
|
|
385
|
-
function validateCertificateRevocationListFailureResult(e,
|
|
386
|
-
return
|
|
675
|
+
function validateCertificateRevocationListFailureResult(e, t) {
|
|
676
|
+
return G(e, t);
|
|
387
677
|
}
|
|
388
678
|
/** Builds a `CheckCertificateRevocationAgainstCrlFailureResult`. */
|
|
389
|
-
function checkCertificateRevocationAgainstCrlFailureResult(e,
|
|
390
|
-
return
|
|
679
|
+
function checkCertificateRevocationAgainstCrlFailureResult(e, t, n) {
|
|
680
|
+
return G(e, t, n);
|
|
391
681
|
}
|
|
392
682
|
/** Wraps a success value into a `CheckCertificateRevocationAgainstCrlResult`. */
|
|
393
683
|
function checkCertificateRevocationAgainstCrlSuccess(e) {
|
|
@@ -401,7 +691,7 @@ function checkCertificateRevocationAgainstCrlSuccess(e) {
|
|
|
401
691
|
* CRL's revoked entries. Does **not** validate the CRL or check applicability.
|
|
402
692
|
*/
|
|
403
693
|
function isCertificateRevoked(e, t) {
|
|
404
|
-
let n = typeof e == "string" ? normalizeHex(e) :
|
|
694
|
+
let n = typeof e == "string" ? normalizeHex(e) : d(e);
|
|
405
695
|
return t.revokedCertificates.some((e) => normalizeHex(e.serialNumberHex) === n);
|
|
406
696
|
}
|
|
407
697
|
/** Searches CRL entries for the certificate's serial, respecting indirect-CRL issuer overrides. */
|
|
@@ -449,13 +739,13 @@ function checkCrlApplicability(e, t, n = !1) {
|
|
|
449
739
|
function evaluateCrlApplicability(e, t, n) {
|
|
450
740
|
if (!n && t.baseCrlNumber !== void 0) return notApplicableOutcome("unsupported_delta_crl", "a delta CRL cannot be used as the primary complete CRL input");
|
|
451
741
|
let r = t.issuingDistributionPoint, i = r?.indirectCrl === !0;
|
|
452
|
-
if (!i && !
|
|
742
|
+
if (!i && !I(e.issuer, t.issuer)) return notApplicableOutcome("issuer_mismatch", "CRL issuer does not match certificate issuer for direct CRL processing");
|
|
453
743
|
if (r?.onlyContainsAttributeCerts === !0) return notApplicableOutcome("certificate_scope_mismatch", "attribute-certificate-only CRLs are not applicable to public-key certificates");
|
|
454
744
|
let a = e.basicConstraints?.ca === !0;
|
|
455
745
|
if (r?.onlyContainsUserCerts === !0 && a) return notApplicableOutcome("certificate_scope_mismatch", "CRL only applies to end-entity certificates");
|
|
456
746
|
if (r?.onlyContainsCACerts === !0 && !a) return notApplicableOutcome("certificate_scope_mismatch", "CRL only applies to CA certificates");
|
|
457
747
|
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 && !
|
|
748
|
+
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 && !I(e.issuer, t.issuer) ? notApplicableOutcome("issuer_mismatch", "indirect CRLs for alternate certificate issuers require matching CRLIssuer distribution points") : {
|
|
459
749
|
ok: !0,
|
|
460
750
|
coveredReasons: interimReasonsMask(void 0, r)
|
|
461
751
|
};
|
|
@@ -522,7 +812,7 @@ function scanCrlDistributionPoint(e, t, n, r, i) {
|
|
|
522
812
|
}
|
|
523
813
|
function scanCrlDistributionPointIssuer(e, t, n, r) {
|
|
524
814
|
if (!r) return e.crlIssuer === void 0 ? void 0 : "indirect_distribution_point";
|
|
525
|
-
if (
|
|
815
|
+
if (I(t.issuer, n.issuer) && e.crlIssuer === void 0) return;
|
|
526
816
|
let i = matchesIndirectCrlIssuer(e.crlIssuer, n);
|
|
527
817
|
return i === "unsupported" ? "unsupported_indirect_crl_issuer" : i ? void 0 : "indirect_issuer_mismatch";
|
|
528
818
|
}
|
|
@@ -533,7 +823,7 @@ function crlDistributionPointScanFailure(e) {
|
|
|
533
823
|
function checkDeltaCrlCompatibility(e, t) {
|
|
534
824
|
if (e.baseCrlNumber !== void 0) return nonApplicable("delta_crl_incompatible", "complete CRL input must not itself be a delta CRL");
|
|
535
825
|
if (t.baseCrlNumber === void 0) return nonApplicable("delta_crl_incompatible", "delta CRL input must include a delta CRL indicator");
|
|
536
|
-
if (!
|
|
826
|
+
if (!I(e.issuer, t.issuer)) return nonApplicable("delta_crl_incompatible", "complete and delta CRLs must share the same issuer");
|
|
537
827
|
if (e.authorityKeyIdentifier !== t.authorityKeyIdentifier) return nonApplicable("delta_crl_incompatible", "complete and delta CRLs must share the same authority key identifier");
|
|
538
828
|
if (!sameIssuingDistributionPoint(e.issuingDistributionPoint, t.issuingDistributionPoint)) return nonApplicable("delta_crl_incompatible", "complete and delta CRLs must share the same issuing distribution point scope");
|
|
539
829
|
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 +837,7 @@ function matchesIndirectCrlIssuer(e, t) {
|
|
|
547
837
|
}
|
|
548
838
|
/** Determines whether a revoked entry's effective issuer matches the certificate's issuer. */
|
|
549
839
|
function matchesRevokedEntryIssuer(e, t, n) {
|
|
550
|
-
if (n === void 0) return
|
|
840
|
+
if (n === void 0) return I(e.issuer, t.issuer) ? "match" : "mismatch";
|
|
551
841
|
let r = !1;
|
|
552
842
|
for (let t of n) if (t.type === "directoryName") {
|
|
553
843
|
if (directoryNameDerHexMatchesParsedName(t.derHex, e.issuer)) return "match";
|
|
@@ -606,7 +896,7 @@ function matchesDistributionPointName(e, t, n, r) {
|
|
|
606
896
|
let r = resolveRelativeNameToDnHex(n, e.relativeName);
|
|
607
897
|
return t.fullName.some((e) => e.type === "directoryName" && e.derHex === r);
|
|
608
898
|
}
|
|
609
|
-
if (e.type === "relativeName" && t.type === "relativeName") return
|
|
899
|
+
if (e.type === "relativeName" && t.type === "relativeName") return L(e.relativeName, t.relativeName);
|
|
610
900
|
if (e.type === "fullName" && t.type === "relativeName") {
|
|
611
901
|
let r = resolveRelativeNameToDnHex(n, t.relativeName);
|
|
612
902
|
return e.fullName.some((e) => e.type === "directoryName" && e.derHex === r);
|
|
@@ -626,13 +916,13 @@ function matchesIdpNameAgainstCrlIssuer(e, t, n) {
|
|
|
626
916
|
}
|
|
627
917
|
/** Constructs a full DN by appending an RDN to an existing Name, returning hex-encoded DER. */
|
|
628
918
|
function resolveRelativeNameToDnHex(e, t) {
|
|
629
|
-
let n = e.rdns.map((e) =>
|
|
630
|
-
return n.push(r),
|
|
919
|
+
let n = e.rdns.map((e) => s(e.derHex)), r = rebuildRelativeNameAsSet(s(t.derHex));
|
|
920
|
+
return n.push(r), d(w(n));
|
|
631
921
|
}
|
|
632
922
|
/** Converts an implicit-tagged [1] relativeName to a proper SET-tagged RDN. */
|
|
633
923
|
function rebuildRelativeNameAsSet(e) {
|
|
634
|
-
let t =
|
|
635
|
-
return
|
|
924
|
+
let t = S(e, { maxDepth: 64 });
|
|
925
|
+
return E(49, t.value);
|
|
636
926
|
}
|
|
637
927
|
/** Deep-compares two issuing distribution point extensions for delta-CRL compatibility. */
|
|
638
928
|
function sameIssuingDistributionPoint(e, t) {
|
|
@@ -640,7 +930,7 @@ function sameIssuingDistributionPoint(e, t) {
|
|
|
640
930
|
}
|
|
641
931
|
/** Compares two DistributionPointName values (fullName set or relativeName). */
|
|
642
932
|
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" &&
|
|
933
|
+
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" && L(e.relativeName, t.relativeName);
|
|
644
934
|
}
|
|
645
935
|
/** Set-equality comparison for GeneralName arrays (order-independent). */
|
|
646
936
|
function sameGeneralNameSet(e, t) {
|
|
@@ -676,12 +966,12 @@ function compareGeneralNames(e, t) {
|
|
|
676
966
|
if (e.type === "uri" && t.type === "uri") return compareUniformResourceIdentifiers(e.value, t.value);
|
|
677
967
|
if (e.type === "directoryName" && t.type === "directoryName") {
|
|
678
968
|
let n = parseDerHexName(e.derHex), r = parseDerHexName(t.derHex);
|
|
679
|
-
return n === void 0 || r === void 0 ? !1 :
|
|
969
|
+
return n === void 0 || r === void 0 ? !1 : I(n, r);
|
|
680
970
|
}
|
|
681
971
|
return compareOpaqueGeneralNames(e, t);
|
|
682
972
|
}
|
|
683
973
|
function compareSrvNames(e, t) {
|
|
684
|
-
let n =
|
|
974
|
+
let n = B(e), r = B(t);
|
|
685
975
|
return n === void 0 || r === void 0 ? e === t : n.service === r.service && n.name === r.name;
|
|
686
976
|
}
|
|
687
977
|
/** Encoding equality for the GeneralName alternatives carried as DER or an OID. */
|
|
@@ -704,7 +994,7 @@ function compareUniformResourceIdentifiers(e, t) {
|
|
|
704
994
|
* the default port that scheme-based normalization elides. `ldaps` is included
|
|
705
995
|
* as the TLS form of the mandatory `ldap` scheme.
|
|
706
996
|
*/
|
|
707
|
-
const
|
|
997
|
+
const fe = /* @__PURE__ */ new Map([
|
|
708
998
|
["ftp", "21"],
|
|
709
999
|
["http", "80"],
|
|
710
1000
|
["https", "443"],
|
|
@@ -733,7 +1023,7 @@ function normalizeUriForComparison(e) {
|
|
|
733
1023
|
if (e === void 0) return;
|
|
734
1024
|
t.hostname = e;
|
|
735
1025
|
}
|
|
736
|
-
return t.port ===
|
|
1026
|
+
return t.port === fe.get(t.protocol.slice(0, -1)) && (t.port = ""), normalizePercentEncoding(t.href);
|
|
737
1027
|
}
|
|
738
1028
|
/**
|
|
739
1029
|
* Reparses a host under a special scheme so the URL parser applies IDNA and
|
|
@@ -757,10 +1047,10 @@ function decodeHostPercentEncoding(e) {
|
|
|
757
1047
|
return e;
|
|
758
1048
|
}
|
|
759
1049
|
}
|
|
760
|
-
const
|
|
1050
|
+
const pe = /%[0-9A-Fa-f]{2}/g;
|
|
761
1051
|
/** RFC 3986 §6.2.2.2: unreserved triplets decode, every other triplet uppercases. */
|
|
762
1052
|
function normalizePercentEncoding(e) {
|
|
763
|
-
return e.replace(
|
|
1053
|
+
return e.replace(pe, (e) => {
|
|
764
1054
|
let t = Number.parseInt(e.slice(1), 16);
|
|
765
1055
|
return isUnreservedUriCharacter(t) ? String.fromCharCode(t) : e.toUpperCase();
|
|
766
1056
|
});
|
|
@@ -777,71 +1067,71 @@ function bytesEqual(e, t) {
|
|
|
777
1067
|
}
|
|
778
1068
|
/** Assembles the CRL-level v2 extensions (AKI, CRLNumber, deltaCRLIndicator, IDP, freshestCRL). */
|
|
779
1069
|
function buildCrlExtensions(e, t, n, r, i) {
|
|
780
|
-
let a = [
|
|
781
|
-
return n !== void 0 && a.push(
|
|
1070
|
+
let a = [Y(D.authorityKeyIdentifier, w([b(0, se(e))])), Y(D.cRLNumber, t)];
|
|
1071
|
+
return n !== void 0 && a.push(Y(D.deltaCRLIndicator, n, !0)), r !== void 0 && a.push(Y(D.issuingDistributionPoint, encodeIssuingDistributionPoint(r), !0)), i !== void 0 && i.length > 0 && a.push(Y(D.freshestCRL, ae(i))), a;
|
|
782
1072
|
}
|
|
783
1073
|
/** DER-encodes a single revokedCertificate SEQUENCE (serial, date, optional extensions). */
|
|
784
1074
|
function createRevokedCertificate(e, t) {
|
|
785
1075
|
let n = buildRevokedCertificateExtensions(e);
|
|
786
|
-
return
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
...n.length === 0 ? [] : [
|
|
1076
|
+
return w([
|
|
1077
|
+
x(e.serialNumber),
|
|
1078
|
+
T(e.revocationDate ?? t),
|
|
1079
|
+
...n.length === 0 ? [] : [w(n)]
|
|
790
1080
|
]);
|
|
791
1081
|
}
|
|
792
1082
|
/** Encodes CRL entry extensions (reasonCode, invalidityDate). */
|
|
793
1083
|
function buildRevokedCertificateExtensions(e) {
|
|
794
1084
|
let t = [];
|
|
795
|
-
return e.reasonCode !== void 0 && t.push(
|
|
1085
|
+
return e.reasonCode !== void 0 && t.push(Y(D.cRLReason, E(10, Uint8Array.of(de[e.reasonCode])))), e.invalidityDate !== void 0 && t.push(Y(D.invalidityDate, v(e.invalidityDate))), t;
|
|
796
1086
|
}
|
|
797
1087
|
/** Decodes per-entry CRL extensions (reasonCode, invalidityDate, certificateIssuer). */
|
|
798
|
-
function parseRevokedCertificateExtensions(
|
|
799
|
-
if (
|
|
800
|
-
let
|
|
801
|
-
for (let
|
|
1088
|
+
function parseRevokedCertificateExtensions(t, n) {
|
|
1089
|
+
if (t === void 0 || n === void 0) return {};
|
|
1090
|
+
let r = {}, i = /* @__PURE__ */ new Set();
|
|
1091
|
+
for (let a of e(t, n)) parseRevokedCertificateExtension(t, a, i, r);
|
|
802
1092
|
return {
|
|
803
|
-
...
|
|
804
|
-
...
|
|
805
|
-
...
|
|
1093
|
+
...r.reasonCode === void 0 ? {} : { reasonCode: r.reasonCode },
|
|
1094
|
+
...r.invalidityDate === void 0 ? {} : { invalidityDate: r.invalidityDate },
|
|
1095
|
+
...r.certificateIssuer === void 0 ? {} : { certificateIssuer: r.certificateIssuer }
|
|
806
1096
|
};
|
|
807
1097
|
}
|
|
808
|
-
function parseRevokedCertificateExtension(
|
|
809
|
-
let
|
|
810
|
-
if (
|
|
811
|
-
let
|
|
812
|
-
if (
|
|
813
|
-
|
|
814
|
-
let
|
|
815
|
-
if (
|
|
816
|
-
if (
|
|
817
|
-
applyRevokedCertificateExtensionValue(
|
|
1098
|
+
function parseRevokedCertificateExtension(n, r, i, o) {
|
|
1099
|
+
let s = e(n, r);
|
|
1100
|
+
if (s.length < 2 || s.length > 3 || s.length === 3 && s[1]?.tag !== 1) throw Error("Malformed revoked certificate extension");
|
|
1101
|
+
let c = a(l(s[0], "revoked certificate extension OID").value);
|
|
1102
|
+
if (i.has(c)) throw Error(`Duplicate revoked certificate extension OID: ${c}`);
|
|
1103
|
+
i.add(c);
|
|
1104
|
+
let u = s.length === 3 && t(l(s[1], "revoked certificate extension critical").value), d = l(s[s.length - 1], "revoked certificate extension value");
|
|
1105
|
+
if (d.tag !== 4) throw Error("Revoked certificate extension value must use OCTET STRING");
|
|
1106
|
+
if (u && !isSupportedRevokedCertificateExtensionOid(c)) throw Error(`Unsupported critical revoked certificate extension OID: ${c}`);
|
|
1107
|
+
applyRevokedCertificateExtensionValue(c, d.value, u, o);
|
|
818
1108
|
}
|
|
819
1109
|
function isSupportedRevokedCertificateExtensionOid(e) {
|
|
820
|
-
return e ===
|
|
1110
|
+
return e === D.cRLReason || e === D.invalidityDate || e === D.certificateIssuer;
|
|
821
1111
|
}
|
|
822
1112
|
function applyRevokedCertificateExtensionValue(e, t, n, r) {
|
|
823
|
-
if (e ===
|
|
824
|
-
let e =
|
|
1113
|
+
if (e === D.cRLReason) {
|
|
1114
|
+
let e = S(t, { maxDepth: 64 });
|
|
825
1115
|
if (e.tag !== 10) throw Error("cRLReason must use ENUMERATED");
|
|
826
|
-
let
|
|
827
|
-
if (n && typeof
|
|
828
|
-
r.reasonCode =
|
|
1116
|
+
let a = parsedRevocationReason(i(e.value, "cRLReason"));
|
|
1117
|
+
if (n && typeof a != "string") throw Error(`Critical cRLReason holds unrecognized reason code ${String(a.code)}`);
|
|
1118
|
+
r.reasonCode = a;
|
|
829
1119
|
}
|
|
830
|
-
if (e ===
|
|
831
|
-
let e =
|
|
1120
|
+
if (e === D.invalidityDate && (r.invalidityDate = c(S(t, { maxDepth: 64 }))), e === D.certificateIssuer) {
|
|
1121
|
+
let e = S(t, { maxDepth: 64 });
|
|
832
1122
|
if (e.tag !== 48) throw Error("certificateIssuer must use SEQUENCE");
|
|
833
|
-
r.certificateIssuer =
|
|
1123
|
+
r.certificateIssuer = z(t, e);
|
|
834
1124
|
}
|
|
835
1125
|
}
|
|
836
1126
|
/** Decodes the IssuingDistributionPoint extension from its OCTET STRING content. */
|
|
837
|
-
function parseIssuingDistributionPoint(
|
|
838
|
-
let
|
|
839
|
-
for (let
|
|
1127
|
+
function parseIssuingDistributionPoint(t) {
|
|
1128
|
+
let n = S(t, { maxDepth: 64 }), r = {};
|
|
1129
|
+
for (let i of e(t, n)) parseIssuingDistributionPointField(t, i, r);
|
|
840
1130
|
return {
|
|
841
|
-
...
|
|
842
|
-
...
|
|
843
|
-
...
|
|
844
|
-
...parseIssuingDistributionPointScope(
|
|
1131
|
+
...r.distributionPoint === void 0 ? {} : { distributionPoint: r.distributionPoint },
|
|
1132
|
+
...r.onlySomeReasons === void 0 ? {} : { onlySomeReasons: r.onlySomeReasons },
|
|
1133
|
+
...r.indirectCrl === void 0 ? {} : { indirectCrl: r.indirectCrl },
|
|
1134
|
+
...parseIssuingDistributionPointScope(r)
|
|
845
1135
|
};
|
|
846
1136
|
}
|
|
847
1137
|
/** RFC 5280 §5.2.5: at most one `onlyContains*` flag may be TRUE. */
|
|
@@ -904,7 +1194,7 @@ function parseIssuingDistributionPointField(e, t, n) {
|
|
|
904
1194
|
return;
|
|
905
1195
|
case 131:
|
|
906
1196
|
if (n.onlySomeReasons !== void 0) throw Error("IssuingDistributionPoint onlySomeReasons must not repeat");
|
|
907
|
-
n.onlySomeReasons =
|
|
1197
|
+
n.onlySomeReasons = R(t.value);
|
|
908
1198
|
return;
|
|
909
1199
|
case 132:
|
|
910
1200
|
n.indirectCrl = parseUniqueIssuingDistributionPointBoolean(n.indirectCrl, t, "indirectCrl");
|
|
@@ -915,48 +1205,48 @@ function parseIssuingDistributionPointField(e, t, n) {
|
|
|
915
1205
|
default: throw Error(`Unsupported IssuingDistributionPoint field tag: ${String(t.tag)}`);
|
|
916
1206
|
}
|
|
917
1207
|
}
|
|
918
|
-
function parseUniqueIssuingDistributionPointBoolean(e,
|
|
919
|
-
if (e !== void 0) throw Error(`IssuingDistributionPoint ${
|
|
920
|
-
return
|
|
1208
|
+
function parseUniqueIssuingDistributionPointBoolean(e, n, r) {
|
|
1209
|
+
if (e !== void 0) throw Error(`IssuingDistributionPoint ${r} must not repeat`);
|
|
1210
|
+
return t(n.value);
|
|
921
1211
|
}
|
|
922
1212
|
/** Decodes a SEQUENCE OF DistributionPoint from DER. */
|
|
923
|
-
function parseDistributionPoints(
|
|
924
|
-
let
|
|
925
|
-
if (
|
|
926
|
-
let
|
|
927
|
-
if (
|
|
928
|
-
return
|
|
1213
|
+
function parseDistributionPoints(t) {
|
|
1214
|
+
let n = S(t, { maxDepth: 64 });
|
|
1215
|
+
if (n.tag !== 48) throw Error("DistributionPoints must use SEQUENCE");
|
|
1216
|
+
let r = e(t, n);
|
|
1217
|
+
if (r.length === 0) throw Error("DistributionPoints must not be empty");
|
|
1218
|
+
return r.map((e) => parseDistributionPoint(t, e));
|
|
929
1219
|
}
|
|
930
1220
|
/** 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
|
|
1221
|
+
function parseDistributionPointName(t, n) {
|
|
1222
|
+
let r = e(t, n);
|
|
1223
|
+
if (r.length !== 1) throw Error("distributionPointName must contain exactly one choice");
|
|
1224
|
+
let i = l(r[0], "distributionPointName");
|
|
1225
|
+
if (i.tag === 160) {
|
|
1226
|
+
let n = e(t, i);
|
|
1227
|
+
if (n.length === 0) throw Error("distributionPointName fullName must not be empty");
|
|
1228
|
+
for (let e of n) if ((e.tag & 192) != 128) throw Error("distributionPointName fullName must contain GeneralName entries");
|
|
939
1229
|
return {
|
|
940
1230
|
type: "fullName",
|
|
941
|
-
fullName:
|
|
1231
|
+
fullName: n.map((e) => ie(t, e))
|
|
942
1232
|
};
|
|
943
1233
|
}
|
|
944
|
-
if (
|
|
1234
|
+
if (i.tag === 161) return {
|
|
945
1235
|
type: "relativeName",
|
|
946
|
-
relativeName: parseRelativeName(
|
|
1236
|
+
relativeName: parseRelativeName(t, i)
|
|
947
1237
|
};
|
|
948
|
-
throw Error(`Unsupported distributionPointName tag: ${String(
|
|
1238
|
+
throw Error(`Unsupported distributionPointName tag: ${String(i.tag)}`);
|
|
949
1239
|
}
|
|
950
1240
|
/** Decodes a single DistributionPoint SEQUENCE. */
|
|
951
|
-
function parseDistributionPoint(
|
|
952
|
-
if (
|
|
953
|
-
let
|
|
954
|
-
for (let
|
|
955
|
-
if (
|
|
1241
|
+
function parseDistributionPoint(t, n) {
|
|
1242
|
+
if (n.tag !== 48) throw Error("DistributionPoint must use SEQUENCE");
|
|
1243
|
+
let r = {};
|
|
1244
|
+
for (let i of e(t, n)) parseDistributionPointField(t, i, r);
|
|
1245
|
+
if (r.distributionPoint === void 0 && r.crlIssuer === void 0) throw Error("DistributionPoint must include distributionPoint or crlIssuer");
|
|
956
1246
|
return {
|
|
957
|
-
...
|
|
958
|
-
...
|
|
959
|
-
...
|
|
1247
|
+
...r.distributionPoint === void 0 ? {} : { distributionPoint: r.distributionPoint },
|
|
1248
|
+
...r.reasons === void 0 ? {} : { reasons: r.reasons },
|
|
1249
|
+
...r.crlIssuer === void 0 ? {} : { crlIssuer: r.crlIssuer }
|
|
960
1250
|
};
|
|
961
1251
|
}
|
|
962
1252
|
function parseDistributionPointField(e, t, n) {
|
|
@@ -969,63 +1259,63 @@ function parseDistributionPointField(e, t, n) {
|
|
|
969
1259
|
}
|
|
970
1260
|
case 129:
|
|
971
1261
|
if (n.reasons !== void 0) throw Error("DistributionPoint reasons must not repeat");
|
|
972
|
-
n.reasons =
|
|
1262
|
+
n.reasons = R(t.value);
|
|
973
1263
|
return;
|
|
974
1264
|
case 162:
|
|
975
1265
|
if (n.crlIssuer !== void 0) throw Error("DistributionPoint crlIssuer must not repeat");
|
|
976
|
-
n.crlIssuer =
|
|
1266
|
+
n.crlIssuer = z(e, t);
|
|
977
1267
|
return;
|
|
978
1268
|
default: throw Error(`Unsupported DistributionPoint field tag: ${String(t.tag)}`);
|
|
979
1269
|
}
|
|
980
1270
|
}
|
|
981
1271
|
/** 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:
|
|
1272
|
+
function parseRelativeName(t, n) {
|
|
1273
|
+
let r = [], i = {};
|
|
1274
|
+
for (let o of e(t, n)) {
|
|
1275
|
+
let n = e(t, o), s = a(l(n[0], "name OID").value), c = l(n[1], "name value"), u = U(s), d = decodeNameValue(c), f = u === void 0 ? {
|
|
1276
|
+
oid: s,
|
|
1277
|
+
valueTag: c.tag,
|
|
1278
|
+
value: d
|
|
989
1279
|
} : {
|
|
990
|
-
oid:
|
|
991
|
-
key:
|
|
992
|
-
valueTag:
|
|
993
|
-
value:
|
|
1280
|
+
oid: s,
|
|
1281
|
+
key: u,
|
|
1282
|
+
valueTag: c.tag,
|
|
1283
|
+
value: d
|
|
994
1284
|
};
|
|
995
|
-
|
|
1285
|
+
r.push(f), u !== void 0 && i[u] === void 0 && (i[u] = d);
|
|
996
1286
|
}
|
|
997
1287
|
return {
|
|
998
|
-
derHex:
|
|
999
|
-
attributes:
|
|
1000
|
-
values:
|
|
1288
|
+
derHex: d(t.slice(n.start - n.headerLength, n.end)),
|
|
1289
|
+
attributes: r,
|
|
1290
|
+
values: i
|
|
1001
1291
|
};
|
|
1002
1292
|
}
|
|
1003
1293
|
/** Decodes an ASN.1 string element (UTF8String, PrintableString, etc.) to a JS string. */
|
|
1004
1294
|
function decodeNameValue(e) {
|
|
1005
|
-
return
|
|
1295
|
+
return o(e.tag, e.value);
|
|
1006
1296
|
}
|
|
1007
1297
|
/** Throws a {@link ResultError} for a CRL encoder input-validation failure. */
|
|
1008
1298
|
function throwCrlEncoderError(e, t) {
|
|
1009
|
-
|
|
1299
|
+
J(e, t);
|
|
1010
1300
|
}
|
|
1011
1301
|
/** The parsed issuer certificate of a CRL being built. */
|
|
1012
|
-
function issuerCertificateOf(
|
|
1302
|
+
function issuerCertificateOf(e) {
|
|
1013
1303
|
try {
|
|
1014
|
-
return normalizeCrlCertificate(
|
|
1015
|
-
} catch (
|
|
1016
|
-
return
|
|
1304
|
+
return normalizeCrlCertificate(e);
|
|
1305
|
+
} catch (e) {
|
|
1306
|
+
return m(e, W), throwCrlEncoderError("issuer_certificate_invalid", "issuerCertificate must be a PEM, DER or parsed certificate");
|
|
1017
1307
|
}
|
|
1018
1308
|
}
|
|
1019
1309
|
/** RFC 5280 §5.2.3 `CRLNumber ::= INTEGER (0..MAX)` as a DER INTEGER of at most 20 content octets. */
|
|
1020
1310
|
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)`),
|
|
1311
|
+
let n = typeof e == "bigint" ? e : Number.isSafeInteger(e) ? BigInt(e) : -1n, r = n.toString(16), i = n < 0n ? void 0 : s(r.length % 2 == 0 ? r : `0${r}`), a = i?.[0];
|
|
1312
|
+
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
1313
|
}
|
|
1024
1314
|
/** RFC 5280 §5.2.3: a received CRLNumber of any length, since verifiers MUST handle up to 20 octets. */
|
|
1025
1315
|
function decodeCrlNumber(e) {
|
|
1026
|
-
let t =
|
|
1316
|
+
let t = S(e, { maxDepth: 64 });
|
|
1027
1317
|
if (t.tag !== 2) throw Error("CRLNumber must be an INTEGER");
|
|
1028
|
-
return
|
|
1318
|
+
return n(t.value, "CRLNumber"), BigInt(`0x${d(t.value)}`);
|
|
1029
1319
|
}
|
|
1030
1320
|
function assertCrlDate(e, t) {
|
|
1031
1321
|
e !== void 0 && Number.isNaN(e.getTime()) && throwCrlEncoderError("invalid_date", `${t} must be a valid date`);
|
|
@@ -1038,98 +1328,98 @@ function encodeIssuingDistributionPoint(e) {
|
|
|
1038
1328
|
e.onlyContainsAttributeCerts === !0
|
|
1039
1329
|
].filter(Boolean).length > 1) throw Error("IssuingDistributionPoint can assert at most one of user, CA, or attribute cert scope");
|
|
1040
1330
|
let t = [];
|
|
1041
|
-
return e.distributionPoint !== void 0 && t.push(
|
|
1331
|
+
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, re(e.onlySomeReasons))), e.indirectCrl && t.push(b(4, Uint8Array.of(255))), e.onlyContainsAttributeCerts && t.push(b(5, Uint8Array.of(255))), w(t);
|
|
1042
1332
|
}
|
|
1043
1333
|
/** DER-encodes a DistributionPointName (fullName or relativeName). */
|
|
1044
1334
|
function encodeDistributionPointName(e) {
|
|
1045
1335
|
if (e === void 0) throw Error("IssuingDistributionPoint distributionPoint is required");
|
|
1046
1336
|
switch (e.type) {
|
|
1047
|
-
case "fullName": return e.fullName.length === 0 && throwCrlEncoderError("distribution_point_full_name_empty", "DistributionPointName fullName must not be empty"),
|
|
1337
|
+
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
1338
|
case "relativeName": {
|
|
1049
|
-
let t =
|
|
1050
|
-
return
|
|
1339
|
+
let t = le(e.relativeName), n = ne(t);
|
|
1340
|
+
return y(1, t.slice(n.start, n.end));
|
|
1051
1341
|
}
|
|
1052
1342
|
default: throw Error(`Unhandled DistributionPointName type: ${String(e)}`);
|
|
1053
1343
|
}
|
|
1054
1344
|
}
|
|
1055
1345
|
/** DER-encodes and concatenates a list of GeneralName values. */
|
|
1056
1346
|
function concatGeneralNames(e) {
|
|
1057
|
-
return
|
|
1347
|
+
return g(e.map((e) => oe(e)));
|
|
1058
1348
|
}
|
|
1059
1349
|
/** 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:
|
|
1350
|
+
function parseIssuer(t, n) {
|
|
1351
|
+
let r = d(t.slice(n.start - n.headerLength, n.end)), i = [], o = [], s = {};
|
|
1352
|
+
for (let r of e(t, n)) {
|
|
1353
|
+
let n = [], c = {};
|
|
1354
|
+
for (let i of e(t, r)) {
|
|
1355
|
+
let r = e(t, i), u = l(r[0], "issuer attribute OID"), d = l(r[1], "issuer attribute value"), f = a(u.value), p = decodeNameValue(d), m = U(f), h = m === void 0 ? {
|
|
1356
|
+
oid: f,
|
|
1357
|
+
valueTag: d.tag,
|
|
1358
|
+
value: p
|
|
1069
1359
|
} : {
|
|
1070
|
-
oid:
|
|
1071
|
-
key:
|
|
1072
|
-
valueTag:
|
|
1073
|
-
value:
|
|
1360
|
+
oid: f,
|
|
1361
|
+
key: m,
|
|
1362
|
+
valueTag: d.tag,
|
|
1363
|
+
value: p
|
|
1074
1364
|
};
|
|
1075
|
-
|
|
1365
|
+
n.push(h), o.push(h), m !== void 0 && (c[m] === void 0 && (c[m] = p), s[m] === void 0 && (s[m] = p));
|
|
1076
1366
|
}
|
|
1077
|
-
|
|
1078
|
-
derHex:
|
|
1079
|
-
attributes:
|
|
1080
|
-
values:
|
|
1367
|
+
i.push({
|
|
1368
|
+
derHex: d(t.slice(r.start - r.headerLength, r.end)),
|
|
1369
|
+
attributes: n,
|
|
1370
|
+
values: c
|
|
1081
1371
|
});
|
|
1082
1372
|
}
|
|
1083
1373
|
return {
|
|
1084
|
-
derHex:
|
|
1085
|
-
rdns:
|
|
1086
|
-
attributes:
|
|
1087
|
-
values:
|
|
1374
|
+
derHex: r,
|
|
1375
|
+
rdns: i,
|
|
1376
|
+
attributes: o,
|
|
1377
|
+
values: s
|
|
1088
1378
|
};
|
|
1089
1379
|
}
|
|
1090
1380
|
/**
|
|
1091
1381
|
* Re-parses a hex-encoded DER Name into a {@linkcode ParsedName}. Returns
|
|
1092
1382
|
* `undefined` on malformed input and throws a decode refusal.
|
|
1093
1383
|
*/
|
|
1094
|
-
function parseDerHexName(
|
|
1384
|
+
function parseDerHexName(e) {
|
|
1095
1385
|
try {
|
|
1096
|
-
let
|
|
1097
|
-
return n.tag === 48 ? parseIssuer(
|
|
1098
|
-
} catch (
|
|
1099
|
-
|
|
1386
|
+
let t = s(e), n = unwrapNameElement(t, S(t, { maxDepth: 64 }));
|
|
1387
|
+
return n.tag === 48 ? parseIssuer(t, n) : void 0;
|
|
1388
|
+
} catch (e) {
|
|
1389
|
+
m(e, W);
|
|
1100
1390
|
return;
|
|
1101
1391
|
}
|
|
1102
1392
|
}
|
|
1103
1393
|
/** The failure for a decode refusal a directoryName comparison threw. */
|
|
1104
|
-
function crlNameRefusalFailure(
|
|
1105
|
-
let
|
|
1106
|
-
if (
|
|
1107
|
-
return checkCertificateRevocationAgainstCrlFailureResult(
|
|
1394
|
+
function crlNameRefusalFailure(e) {
|
|
1395
|
+
let t = p(e, W);
|
|
1396
|
+
if (t === void 0) throw e;
|
|
1397
|
+
return checkCertificateRevocationAgainstCrlFailureResult(t.code, t.message);
|
|
1108
1398
|
}
|
|
1109
|
-
function unwrapNameElement(
|
|
1110
|
-
if (
|
|
1111
|
-
let
|
|
1112
|
-
return
|
|
1399
|
+
function unwrapNameElement(t, n) {
|
|
1400
|
+
if (n.tag !== 48) return n;
|
|
1401
|
+
let r = e(t, n), i = r[0];
|
|
1402
|
+
return r.length === 1 && i?.tag === 48 ? i : n;
|
|
1113
1403
|
}
|
|
1114
1404
|
/** Semantic comparison of a GeneralName directoryName `derHex` against a {@linkcode ParsedName}. */
|
|
1115
1405
|
function directoryNameDerHexMatchesParsedName(e, t) {
|
|
1116
1406
|
let n = parseDerHexName(e);
|
|
1117
|
-
return n !== void 0 &&
|
|
1407
|
+
return n !== void 0 && I(n, t);
|
|
1118
1408
|
}
|
|
1119
1409
|
/** Extracts the keyIdentifier field from an AuthorityKeyIdentifier extension value. */
|
|
1120
|
-
function parseAuthorityKeyIdentifier(
|
|
1121
|
-
let
|
|
1410
|
+
function parseAuthorityKeyIdentifier(t) {
|
|
1411
|
+
let n = S(t, {
|
|
1122
1412
|
maxDepth: 64,
|
|
1123
1413
|
allowOpaqueConstructedTags: [161, 162]
|
|
1124
1414
|
});
|
|
1125
|
-
if (
|
|
1126
|
-
let
|
|
1415
|
+
if (n.tag !== 48) throw Error("authorityKeyIdentifier must use SEQUENCE");
|
|
1416
|
+
let r = {
|
|
1127
1417
|
sawAuthorityCertIssuer: !1,
|
|
1128
1418
|
sawAuthorityCertSerialNumber: !1,
|
|
1129
1419
|
lastFieldOrder: -1
|
|
1130
1420
|
};
|
|
1131
|
-
for (let
|
|
1132
|
-
return
|
|
1421
|
+
for (let i of e(t, n)) parseAuthorityKeyIdentifierField(t, i, r);
|
|
1422
|
+
return r.keyIdentifier;
|
|
1133
1423
|
}
|
|
1134
1424
|
function parseAuthorityKeyIdentifierField(e, t, n) {
|
|
1135
1425
|
switch (t.tag) {
|
|
@@ -1148,12 +1438,12 @@ function parseAuthorityKeyIdentifierField(e, t, n) {
|
|
|
1148
1438
|
function parseAuthorityKeyIdentifierKeyId(e, t) {
|
|
1149
1439
|
if (t.keyIdentifier !== void 0) throw Error("authorityKeyIdentifier keyIdentifier must not repeat");
|
|
1150
1440
|
if (t.lastFieldOrder >= 0) throw Error("authorityKeyIdentifier fields must preserve DER order");
|
|
1151
|
-
t.keyIdentifier =
|
|
1441
|
+
t.keyIdentifier = d(e.value), t.lastFieldOrder = 0;
|
|
1152
1442
|
}
|
|
1153
1443
|
function parseAuthorityKeyIdentifierIssuer(e, t, n) {
|
|
1154
1444
|
if (n.sawAuthorityCertIssuer) throw Error("authorityKeyIdentifier authorityCertIssuer must not repeat");
|
|
1155
1445
|
if (n.lastFieldOrder >= 1) throw Error("authorityKeyIdentifier fields must preserve DER order");
|
|
1156
|
-
|
|
1446
|
+
z(e, t), n.sawAuthorityCertIssuer = !0, n.lastFieldOrder = 1;
|
|
1157
1447
|
}
|
|
1158
1448
|
function parseAuthorityKeyIdentifierSerial(e, t) {
|
|
1159
1449
|
if (t.sawAuthorityCertSerialNumber) throw Error("authorityKeyIdentifier authorityCertSerialNumber must not repeat");
|
|
@@ -1168,14 +1458,14 @@ function validateImplicitSerialNumberEncoding(e, t) {
|
|
|
1168
1458
|
}
|
|
1169
1459
|
/** RFC 5280 §5.1.1.2: signatureAlgorithm MUST equal the tbsCertList signature field. */
|
|
1170
1460
|
function assertMatchingCrlSignatureAlgorithms(e, t) {
|
|
1171
|
-
if (e.oid !== t.oid || !
|
|
1461
|
+
if (e.oid !== t.oid || !te(e.parametersDer, t.parametersDer)) throw Error("CRL signatureAlgorithm must match TBSCertList signature");
|
|
1172
1462
|
}
|
|
1173
1463
|
/** Extracts the algorithm OID from an AlgorithmIdentifier SEQUENCE. */
|
|
1174
|
-
function parseAlgorithmIdentifier(
|
|
1175
|
-
let
|
|
1176
|
-
return
|
|
1177
|
-
oid:
|
|
1178
|
-
parametersDer:
|
|
1464
|
+
function parseAlgorithmIdentifier(t, n) {
|
|
1465
|
+
let r = e(t, n), i = l(r[0], "algorithm OID"), o = r[1];
|
|
1466
|
+
return o === void 0 ? { oid: a(i.value) } : {
|
|
1467
|
+
oid: a(i.value),
|
|
1468
|
+
parametersDer: t.slice(o.start - o.headerLength, o.end)
|
|
1179
1469
|
};
|
|
1180
1470
|
}
|
|
1181
1471
|
/** Lowercases a hex string for bytewise serial-number comparison. */
|
|
@@ -1228,24 +1518,24 @@ function normalizeCrl(e) {
|
|
|
1228
1518
|
if (hasReparseableCrlShape(e)) return parseCertificateRevocationListDerOrThrow(new Uint8Array(e.der));
|
|
1229
1519
|
throw Error("certificate revocation list input is malformed");
|
|
1230
1520
|
}
|
|
1231
|
-
function parseSignedCrlFields(
|
|
1232
|
-
let
|
|
1233
|
-
|
|
1234
|
-
let
|
|
1235
|
-
|
|
1236
|
-
let
|
|
1521
|
+
function parseSignedCrlFields(t) {
|
|
1522
|
+
let n = S(t, { maxDepth: 64 }), r = e(t, n), i = parseCrlVersionField(r), a = i.version, o = l(r[i.nextIndex], "signature"), s = i.nextIndex + 1, u = l(r[s], "issuer"), d = l(r[s + 1], "thisUpdate"), f = s + 2, p = r[f], m = p !== void 0 && (p.tag === 23 || p.tag === 24) ? c(p) : void 0;
|
|
1523
|
+
m !== void 0 && (f += 1);
|
|
1524
|
+
let h = r[f], g = h?.tag === 48 ? parseRevokedCertificates(t, h, a) : [];
|
|
1525
|
+
h?.tag === 48 && (f += 1);
|
|
1526
|
+
let _ = r[f], v = parseCrlExtensionFields(t, _, a);
|
|
1237
1527
|
return {
|
|
1238
|
-
version:
|
|
1239
|
-
signature: parseAlgorithmIdentifier(
|
|
1240
|
-
issuer: parseIssuer(
|
|
1241
|
-
thisUpdate:
|
|
1242
|
-
...
|
|
1243
|
-
...
|
|
1244
|
-
...
|
|
1245
|
-
...
|
|
1246
|
-
...
|
|
1247
|
-
...
|
|
1248
|
-
revokedCertificates:
|
|
1528
|
+
version: a,
|
|
1529
|
+
signature: parseAlgorithmIdentifier(t, o),
|
|
1530
|
+
issuer: parseIssuer(t, u),
|
|
1531
|
+
thisUpdate: c(d),
|
|
1532
|
+
...m === void 0 ? {} : { nextUpdate: m },
|
|
1533
|
+
...v.authorityKeyIdentifier === void 0 ? {} : { authorityKeyIdentifier: v.authorityKeyIdentifier },
|
|
1534
|
+
...v.crlNumber === void 0 ? {} : { crlNumber: v.crlNumber },
|
|
1535
|
+
...v.baseCrlNumber === void 0 ? {} : { baseCrlNumber: v.baseCrlNumber },
|
|
1536
|
+
...v.issuingDistributionPoint === void 0 ? {} : { issuingDistributionPoint: v.issuingDistributionPoint },
|
|
1537
|
+
...v.freshestCrlDistributionPoints === void 0 ? {} : { freshestCrlDistributionPoints: v.freshestCrlDistributionPoints },
|
|
1538
|
+
revokedCertificates: g
|
|
1249
1539
|
};
|
|
1250
1540
|
}
|
|
1251
1541
|
function parseCrlVersionField(e) {
|
|
@@ -1255,61 +1545,61 @@ function parseCrlVersionField(e) {
|
|
|
1255
1545
|
version: 1,
|
|
1256
1546
|
nextIndex: 0
|
|
1257
1547
|
};
|
|
1258
|
-
let n =
|
|
1548
|
+
let n = r(t.value) + 1;
|
|
1259
1549
|
if (n !== 2) throw Error(`Unsupported CRL version: ${String(n)}`);
|
|
1260
1550
|
return {
|
|
1261
1551
|
version: n,
|
|
1262
1552
|
nextIndex: 1
|
|
1263
1553
|
};
|
|
1264
1554
|
}
|
|
1265
|
-
function parseRevokedCertificates(
|
|
1266
|
-
return
|
|
1555
|
+
function parseRevokedCertificates(t, n, r) {
|
|
1556
|
+
return e(t, n).map((e) => parseRevokedCertificateEntry(t, e, r));
|
|
1267
1557
|
}
|
|
1268
1558
|
function parseRevokedCertificateEntry(e, t, n) {
|
|
1269
|
-
let r = e.slice(t.start - t.headerLength, t.end), i =
|
|
1559
|
+
let r = e.slice(t.start - t.headerLength, t.end), i = C(r), a = l(i[0], "revoked serialNumber");
|
|
1270
1560
|
if (a.tag !== 2) throw Error("revoked serialNumber must use INTEGER");
|
|
1271
1561
|
let o = i[2];
|
|
1272
1562
|
if (o !== void 0 && n !== 2) throw Error("revoked certificate extensions require CRL version 2");
|
|
1273
1563
|
let s = parseRevokedCertificateExtensions(r, o);
|
|
1274
1564
|
return {
|
|
1275
|
-
serialNumberHex:
|
|
1276
|
-
revocationDate:
|
|
1565
|
+
serialNumberHex: d(a.value),
|
|
1566
|
+
revocationDate: c(l(i[1], "revocationDate")),
|
|
1277
1567
|
...s.reasonCode === void 0 ? {} : { reasonCode: s.reasonCode },
|
|
1278
1568
|
...s.invalidityDate === void 0 ? {} : { invalidityDate: s.invalidityDate },
|
|
1279
1569
|
...s.certificateIssuer === void 0 ? {} : { certificateIssuer: s.certificateIssuer }
|
|
1280
1570
|
};
|
|
1281
1571
|
}
|
|
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(
|
|
1572
|
+
function parseCrlExtensionFields(t, n, r) {
|
|
1573
|
+
if (n?.tag !== 160) return {};
|
|
1574
|
+
if (r !== 2) throw Error("CRL extensions require version 2");
|
|
1575
|
+
let i = {}, a = /* @__PURE__ */ new Set(), o = l(e(t, n)[0], "crl extensions");
|
|
1576
|
+
for (let n of e(t, o)) parseCrlExtensionField(t, n, a, i);
|
|
1577
|
+
return i;
|
|
1578
|
+
}
|
|
1579
|
+
function parseCrlExtensionField(n, r, i, o) {
|
|
1580
|
+
let s = e(n, r);
|
|
1581
|
+
if (s.length < 2 || s.length > 3 || s.length === 3 && s[1]?.tag !== 1) throw Error("Malformed CRL extension");
|
|
1582
|
+
let c = a(l(s[0], "extension OID").value);
|
|
1583
|
+
if (i.has(c)) throw Error(`Duplicate CRL extension OID: ${c}`);
|
|
1584
|
+
i.add(c);
|
|
1585
|
+
let u = s.length === 3 && t(l(s[1], "extension critical").value), d = l(s[s.length - 1], "extension value");
|
|
1586
|
+
if (d.tag !== 4) throw Error("CRL extension value must use OCTET STRING");
|
|
1587
|
+
if (!isSupportedCrlExtensionOid(c) && u) throw Error(`Unsupported critical CRL extension OID: ${c}`);
|
|
1588
|
+
applyParsedCrlExtensionField(c, d.value, o);
|
|
1299
1589
|
}
|
|
1300
1590
|
function isSupportedCrlExtensionOid(e) {
|
|
1301
|
-
return e ===
|
|
1591
|
+
return e === D.authorityKeyIdentifier || e === D.cRLNumber || e === D.deltaCRLIndicator || e === D.issuingDistributionPoint || e === D.freshestCRL;
|
|
1302
1592
|
}
|
|
1303
1593
|
function applyParsedCrlExtensionField(e, t, n) {
|
|
1304
|
-
if (e ===
|
|
1594
|
+
if (e === D.authorityKeyIdentifier) {
|
|
1305
1595
|
let e = parseAuthorityKeyIdentifier(t);
|
|
1306
1596
|
e !== void 0 && (n.authorityKeyIdentifier = e);
|
|
1307
1597
|
}
|
|
1308
|
-
e ===
|
|
1598
|
+
e === D.cRLNumber && (n.crlNumber = decodeCrlNumber(t)), e === D.deltaCRLIndicator && (n.baseCrlNumber = decodeCrlNumber(t)), e === D.issuingDistributionPoint && (n.issuingDistributionPoint = parseIssuingDistributionPoint(t)), e === D.freshestCRL && (n.freshestCrlDistributionPoints = parseDistributionPoints(t));
|
|
1309
1599
|
}
|
|
1310
1600
|
/** Accepts PEM, DER, or already-parsed certificate and returns a parsed certificate. */
|
|
1311
1601
|
function normalizeCrlCertificate(e) {
|
|
1312
|
-
return hasParsedCertificateShape(e) ?
|
|
1602
|
+
return hasParsedCertificateShape(e) ? ue(new Uint8Array(e.der)) : Z(e);
|
|
1313
1603
|
}
|
|
1314
1604
|
function hasParsedCertificateShape(e) {
|
|
1315
1605
|
return typeof e != "string" && "subjectPublicKeyInfoDer" in e;
|
|
@@ -1317,6 +1607,6 @@ function hasParsedCertificateShape(e) {
|
|
|
1317
1607
|
function hasReparseableCrlShape(e) {
|
|
1318
1608
|
return "der" in e && e.der instanceof Uint8Array;
|
|
1319
1609
|
}
|
|
1320
|
-
export { Q as ALL_DISTRIBUTION_POINT_REASONS, assertCrlMaxAge, authenticateCrl, checkCertificateRevocationAgainstCrl,
|
|
1610
|
+
export { Q as ALL_DISTRIBUTION_POINT_REASONS, assertClockSkew, assertCrlMaxAge, authenticateCrl, checkCertificateRevocationAgainstCrl, checkCertificateRevocationAgainstCrlBy, checkCertificateRevocationAgainstCrlWith, checkCertificateRevocationAgainstCrlsBy, coversAllDistributionPointReasons, createCertificateRevocationList, distinctSignedCrls, isCertificateRevoked, isCrlApplicableTo, normalizeCrl, parseCertificateRevocationListDer, parseCertificateRevocationListDerOrThrow, parseCertificateRevocationListPem, parseCertificateRevocationListPemOrThrow, revocationReasonFromCode, signedCrlKey, validateCertificateRevocationList, verifyCertificateRevocationListSignature };
|
|
1321
1611
|
|
|
1322
1612
|
//# sourceMappingURL=crl.js.map
|