micro509 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +3 -3
- package/dist/index.js +15 -15
- package/dist/internal/asn1/asn1.js +145 -186
- package/dist/internal/asn1/asn1.js.map +1 -0
- package/dist/internal/asn1/der.js +210 -227
- package/dist/internal/asn1/der.js.map +1 -0
- package/dist/internal/asn1/oids.js +297 -101
- package/dist/internal/asn1/oids.js.map +1 -0
- package/dist/internal/asn1/oids2.js +69 -0
- package/dist/internal/asn1/oids2.js.map +1 -0
- package/dist/internal/crypto/algorithm-names.js +37 -35
- package/dist/internal/crypto/algorithm-names.js.map +1 -0
- package/dist/internal/crypto/ecdsa.js +25 -28
- package/dist/internal/crypto/ecdsa.js.map +1 -0
- package/dist/internal/crypto/hash.js +56 -117
- package/dist/internal/crypto/hash.js.map +1 -0
- package/dist/internal/crypto/pbes2.js +122 -133
- package/dist/internal/crypto/pbes2.js.map +1 -0
- package/dist/internal/crypto/rsa-pss.js +118 -124
- package/dist/internal/crypto/rsa-pss.js.map +1 -0
- package/dist/internal/crypto/sig-verify.js +87 -99
- package/dist/internal/crypto/sig-verify.js.map +1 -0
- package/dist/internal/crypto/signing.d.ts +12 -8
- package/dist/internal/crypto/signing.js +53 -55
- package/dist/internal/crypto/signing.js.map +1 -0
- package/dist/internal/crypto/webcrypto.js +5 -3
- package/dist/internal/crypto/webcrypto.js.map +1 -0
- package/dist/internal/shared/base64.js +10 -9
- package/dist/internal/shared/base64.js.map +1 -0
- package/dist/internal/shared/dn.js +50 -57
- package/dist/internal/shared/dn.js.map +1 -0
- package/dist/internal/shared/ip.js +43 -53
- package/dist/internal/shared/ip.js.map +1 -0
- package/dist/internal/verify/name-constraints-engine.js +211 -239
- package/dist/internal/verify/name-constraints-engine.js.map +1 -0
- package/dist/internal/verify/policy-engine.js +228 -247
- package/dist/internal/verify/policy-engine.js.map +1 -0
- package/dist/internal/verify/verify-path.js +213 -228
- package/dist/internal/verify/verify-path.js.map +1 -0
- package/dist/internal/x509/extension-bits.js +62 -59
- package/dist/internal/x509/extension-bits.js.map +1 -0
- package/dist/internal/x509/extension-registry.js +133 -164
- package/dist/internal/x509/extension-registry.js.map +1 -0
- package/dist/internal/x509/name-fields.js +35 -41
- package/dist/internal/x509/name-fields.js.map +1 -0
- package/dist/keys/keys.d.ts +583 -547
- package/dist/keys/keys.js +519 -431
- package/dist/keys/keys.js.map +1 -0
- package/dist/keys.js +2 -2
- package/dist/pem/pem.d.ts +46 -46
- package/dist/pem/pem.js +62 -81
- package/dist/pem/pem.js.map +1 -0
- package/dist/pem.js +2 -2
- package/dist/pkcs/pfx.d.ts +96 -80
- package/dist/pkcs/pfx.js +191 -231
- package/dist/pkcs/pfx.js.map +1 -0
- package/dist/pkcs/pkcs12-mac.d.ts +20 -18
- package/dist/pkcs/pkcs12-mac.js +90 -111
- package/dist/pkcs/pkcs12-mac.js.map +1 -0
- package/dist/pkcs/pkcs7.d.ts +118 -69
- package/dist/pkcs/pkcs7.js +401 -443
- package/dist/pkcs/pkcs7.js.map +1 -0
- package/dist/pkcs.d.ts +2 -2
- package/dist/pkcs.js +4 -4
- package/dist/result/result.d.ts +37 -32
- package/dist/result/result.js +46 -44
- package/dist/result/result.js.map +1 -0
- package/dist/result.js +2 -2
- package/dist/revocation/chain.d.ts +138 -119
- package/dist/revocation/chain.js +248 -281
- package/dist/revocation/chain.js.map +1 -0
- package/dist/revocation/crl.d.ts +125 -123
- package/dist/revocation/crl.js +653 -745
- package/dist/revocation/crl.js.map +1 -0
- package/dist/revocation/ocsp.d.ts +183 -177
- package/dist/revocation/ocsp.js +579 -636
- package/dist/revocation/ocsp.js.map +1 -0
- package/dist/revocation/revocation.d.ts +26 -26
- package/dist/revocation/revocation.js +104 -125
- package/dist/revocation/revocation.js.map +1 -0
- package/dist/revocation.js +5 -5
- package/dist/verify/identity.d.ts +42 -42
- package/dist/verify/identity.js +158 -167
- package/dist/verify/identity.js.map +1 -0
- package/dist/verify/name-constraints.d.ts +7 -7
- package/dist/verify/policy.d.ts +10 -10
- package/dist/verify/verify.d.ts +163 -163
- package/dist/verify/verify.js +396 -392
- package/dist/verify/verify.js.map +1 -0
- package/dist/verify.js +3 -3
- package/dist/x509/certificate.d.ts +117 -117
- package/dist/x509/certificate.js +51 -60
- package/dist/x509/certificate.js.map +1 -0
- package/dist/x509/csr.d.ts +25 -25
- package/dist/x509/csr.js +26 -30
- package/dist/x509/csr.js.map +1 -0
- package/dist/x509/extensions.d.ts +228 -184
- package/dist/x509/extensions.js +175 -200
- package/dist/x509/extensions.js.map +1 -0
- package/dist/x509/name.d.ts +94 -93
- package/dist/x509/name.js +30 -29
- package/dist/x509/name.js.map +1 -0
- package/dist/x509/parse.d.ts +185 -185
- package/dist/x509/parse.js +638 -676
- package/dist/x509/parse.js.map +1 -0
- package/dist/x509.js +6 -6
- package/package.json +79 -41
package/dist/revocation/crl.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { bitString, concatBytes, explicitContext, generalizedTime, implicitConstructedContext, implicitPrimitiveContext, integer, integerFromNumber, readElement, readRootElement, readSequenceChildren, sequence, time, tlv } from "../internal/asn1/der.js";
|
|
2
|
-
import { childrenOf, decodeBoolean, decodeIntegerNumber, decodeObjectIdentifier, decodeString, extractBitStringValue, hexToBytes, parseTime, requireElement, toHex } from "../internal/asn1/asn1.js";
|
|
3
|
-
import { OIDS } from "../internal/asn1/
|
|
4
|
-
import { base64Encode } from "../internal/shared/base64.js";
|
|
5
|
-
import { failureResult, rethrowIfInvariant, successResult } from "../result/result.js";
|
|
6
|
-
import { pemDecodeOrThrow, pemEncode } from "../pem/pem.js";
|
|
7
|
-
import { exportSpkiDer } from "../keys/keys.js";
|
|
8
|
-
import { describeSignatureAlgorithm } from "../internal/crypto/algorithm-names.js";
|
|
9
|
-
import { decodeIpAddress } from "../internal/shared/ip.js";
|
|
10
|
-
import { encodeDistributionPointReasonFlagsContent, parseDistributionPointReasonFlagsContent } from "../internal/x509/extension-bits.js";
|
|
11
|
-
import { nameFieldKeyFromOid } from "../internal/x509/name-fields.js";
|
|
12
|
-
import { encodeName, encodeRelativeDistinguishedName } from "../x509/name.js";
|
|
13
|
-
import { buildSubjectKeyIdentifier, encodeCrlDistributionPoints, encodeExtension, encodeSubjectAltName } from "../x509/extensions.js";
|
|
14
|
-
import { parseCertificateDerOrThrow, parseCertificateFromSource } from "../x509/parse.js";
|
|
15
|
-
import { verifySignedDataDetailed } from "../internal/crypto/sig-verify.js";
|
|
16
|
-
import { encodeAlgorithmIdentifier, getSignatureAlgorithm, signBytes } from "../internal/crypto/signing.js";
|
|
17
|
-
import { compareDistinguishedNames, compareNameAttributeValue } from "../internal/shared/dn.js";
|
|
1
|
+
import { bitString as e, concatBytes as t, explicitContext as n, generalizedTime as r, implicitConstructedContext as i, implicitPrimitiveContext as a, integer as o, integerFromNumber as s, readElement as c, readRootElement as l, readSequenceChildren as u, sequence as d, time as f, tlv as p } from "../internal/asn1/der.js";
|
|
2
|
+
import { childrenOf as m, decodeBoolean as h, decodeIntegerNumber as g, decodeObjectIdentifier as _, decodeString as v, extractBitStringValue as y, hexToBytes as b, parseTime as x, requireElement as S, toHex as C } from "../internal/asn1/asn1.js";
|
|
3
|
+
import { OIDS as w } from "../internal/asn1/oids2.js";
|
|
4
|
+
import { base64Encode as T } from "../internal/shared/base64.js";
|
|
5
|
+
import { failureResult as E, rethrowIfInvariant as D, successResult as O } from "../result/result.js";
|
|
6
|
+
import { pemDecodeOrThrow as k, pemEncode as A } from "../pem/pem.js";
|
|
7
|
+
import { exportSpkiDer as j } from "../keys/keys.js";
|
|
8
|
+
import { describeSignatureAlgorithm as M } from "../internal/crypto/algorithm-names.js";
|
|
9
|
+
import { decodeIpAddress as N } from "../internal/shared/ip.js";
|
|
10
|
+
import { encodeDistributionPointReasonFlagsContent as P, parseDistributionPointReasonFlagsContent as F } from "../internal/x509/extension-bits.js";
|
|
11
|
+
import { nameFieldKeyFromOid as I } from "../internal/x509/name-fields.js";
|
|
12
|
+
import { encodeName as L, encodeRelativeDistinguishedName as R } from "../x509/name.js";
|
|
13
|
+
import { buildSubjectKeyIdentifier as z, encodeCrlDistributionPoints as B, encodeExtension as V, encodeSubjectAltName as H } from "../x509/extensions.js";
|
|
14
|
+
import { parseCertificateDerOrThrow as U, parseCertificateFromSource as W } from "../x509/parse.js";
|
|
15
|
+
import { verifySignedDataDetailed as G } from "../internal/crypto/sig-verify.js";
|
|
16
|
+
import { encodeAlgorithmIdentifier as K, getSignatureAlgorithm as q, signBytes as J } from "../internal/crypto/signing.js";
|
|
17
|
+
import { compareDistinguishedNames as Y, compareNameAttributeValue as X } from "../internal/shared/dn.js";
|
|
18
18
|
//#region src/revocation/crl.ts
|
|
19
19
|
/**
|
|
20
20
|
* Full CRL lifecycle: create, parse, verify, validate, and revocation check.
|
|
@@ -25,7 +25,7 @@ import { compareDistinguishedNames, compareNameAttributeValue } from "../interna
|
|
|
25
25
|
* @module
|
|
26
26
|
*/
|
|
27
27
|
/** RFC 5280 §5.3.1 CRLReason integer codes, keyed by reason name. */
|
|
28
|
-
const
|
|
28
|
+
const Z = {
|
|
29
29
|
unspecified: 0,
|
|
30
30
|
keyCompromise: 1,
|
|
31
31
|
cACompromise: 2,
|
|
@@ -61,32 +61,24 @@ const REVOCATION_REASON_CODES = {
|
|
|
61
61
|
* // crl.pem, crl.der, crl.base64
|
|
62
62
|
* ```
|
|
63
63
|
*/
|
|
64
|
-
async function createCertificateRevocationList(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
...revokedSequence,
|
|
78
|
-
...extensions.length === 0 ? [] : [explicitContext(0, sequence(extensions))]
|
|
79
|
-
]);
|
|
80
|
-
const signatureValue = await signBytes(input.signerPrivateKey, signatureAlgorithm, tbsCertList);
|
|
81
|
-
const der = sequence([
|
|
82
|
-
tbsCertList,
|
|
83
|
-
encodeAlgorithmIdentifier(signatureAlgorithm),
|
|
84
|
-
bitString(signatureValue)
|
|
64
|
+
async function createCertificateRevocationList(t) {
|
|
65
|
+
let r = q(t.signerPrivateKey), i = t.thisUpdate ?? /* @__PURE__ */ new Date(), a = t.nextUpdate, o = await buildCrlExtensions(t.issuerPublicKey, t.crlNumber, t.baseCrlNumber, t.issuingDistributionPoint, t.freshestCrlDistributionPoints), c = t.revokedCertificates ?? [], l = c.length === 0 ? [] : [d(c.map((e) => createRevokedCertificate(e, i)))], u = d([
|
|
66
|
+
s(1),
|
|
67
|
+
K(r),
|
|
68
|
+
L(t.issuer),
|
|
69
|
+
f(i),
|
|
70
|
+
...a === void 0 ? [] : [f(a)],
|
|
71
|
+
...l,
|
|
72
|
+
...o.length === 0 ? [] : [n(0, d(o))]
|
|
73
|
+
]), p = await J(t.signerPrivateKey, r, u), m = d([
|
|
74
|
+
u,
|
|
75
|
+
K(r),
|
|
76
|
+
e(p)
|
|
85
77
|
]);
|
|
86
78
|
return {
|
|
87
|
-
der,
|
|
88
|
-
pem:
|
|
89
|
-
base64:
|
|
79
|
+
der: m,
|
|
80
|
+
pem: A("X509 CRL", m),
|
|
81
|
+
base64: T(m)
|
|
90
82
|
};
|
|
91
83
|
}
|
|
92
84
|
/**
|
|
@@ -95,31 +87,27 @@ async function createCertificateRevocationList(input) {
|
|
|
95
87
|
* Does not verify the signature — call {@linkcode verifyCertificateRevocationListSignature} or
|
|
96
88
|
* {@linkcode validateCertificateRevocationList} for that.
|
|
97
89
|
*/
|
|
98
|
-
function parseCertificateRevocationListDerOrThrow(
|
|
99
|
-
|
|
100
|
-
if (
|
|
101
|
-
|
|
102
|
-
const signatureAlgorithm = requireElement(top[1], "signatureAlgorithm");
|
|
103
|
-
const signatureValue = requireElement(top[2], "signatureValue");
|
|
104
|
-
const signedFields = parseSignedCrlFields(der.slice(tbsCertList.start - tbsCertList.headerLength, tbsCertList.end));
|
|
105
|
-
const parsedSignatureAlgorithm = parseAlgorithmIdentifier(der, signatureAlgorithm);
|
|
90
|
+
function parseCertificateRevocationListDerOrThrow(e) {
|
|
91
|
+
let t = u(e, { maxDepth: 64 });
|
|
92
|
+
if (t.length !== 3) throw Error("Malformed CRL");
|
|
93
|
+
let n = S(t[0], "TBSCertList"), r = S(t[1], "signatureAlgorithm"), i = S(t[2], "signatureValue"), a = parseSignedCrlFields(e.slice(n.start - n.headerLength, n.end)), o = parseAlgorithmIdentifier(e, r);
|
|
106
94
|
return {
|
|
107
|
-
der: new Uint8Array(
|
|
108
|
-
version:
|
|
109
|
-
tbsCertListDer:
|
|
110
|
-
signatureValue:
|
|
111
|
-
issuer:
|
|
112
|
-
thisUpdate:
|
|
113
|
-
...
|
|
114
|
-
signatureAlgorithmOid:
|
|
115
|
-
signatureAlgorithmName:
|
|
116
|
-
...
|
|
117
|
-
...
|
|
118
|
-
...
|
|
119
|
-
...
|
|
120
|
-
...
|
|
121
|
-
...
|
|
122
|
-
revokedCertificates:
|
|
95
|
+
der: new Uint8Array(e),
|
|
96
|
+
version: a.version,
|
|
97
|
+
tbsCertListDer: e.slice(n.start - n.headerLength, n.end),
|
|
98
|
+
signatureValue: y(i),
|
|
99
|
+
issuer: a.issuer,
|
|
100
|
+
thisUpdate: a.thisUpdate,
|
|
101
|
+
...a.nextUpdate === void 0 ? {} : { nextUpdate: a.nextUpdate },
|
|
102
|
+
signatureAlgorithmOid: o.oid,
|
|
103
|
+
signatureAlgorithmName: M(o.oid, o.parametersDer),
|
|
104
|
+
...o.parametersDer === void 0 ? {} : { signatureAlgorithmParametersDer: o.parametersDer },
|
|
105
|
+
...a.authorityKeyIdentifier === void 0 ? {} : { authorityKeyIdentifier: a.authorityKeyIdentifier },
|
|
106
|
+
...a.crlNumber === void 0 ? {} : { crlNumber: a.crlNumber },
|
|
107
|
+
...a.baseCrlNumber === void 0 ? {} : { baseCrlNumber: a.baseCrlNumber },
|
|
108
|
+
...a.issuingDistributionPoint === void 0 ? {} : { issuingDistributionPoint: a.issuingDistributionPoint },
|
|
109
|
+
...a.freshestCrlDistributionPoints === void 0 ? {} : { freshestCrlDistributionPoints: a.freshestCrlDistributionPoints },
|
|
110
|
+
revokedCertificates: a.revokedCertificates
|
|
123
111
|
};
|
|
124
112
|
}
|
|
125
113
|
/**
|
|
@@ -133,8 +121,8 @@ function parseCertificateRevocationListDerOrThrow(der) {
|
|
|
133
121
|
* console.log(crl.issuer.values.commonName, crl.revokedCertificates.length);
|
|
134
122
|
* ```
|
|
135
123
|
*/
|
|
136
|
-
function parseCertificateRevocationListPemOrThrow(
|
|
137
|
-
return parseCertificateRevocationListDerOrThrow(
|
|
124
|
+
function parseCertificateRevocationListPemOrThrow(e) {
|
|
125
|
+
return parseCertificateRevocationListDerOrThrow(k("X509 CRL", e));
|
|
138
126
|
}
|
|
139
127
|
/**
|
|
140
128
|
* Decodes a DER-encoded X.509 CRL into a structured {@linkcode ParsedCertificateRevocationList}.
|
|
@@ -144,12 +132,11 @@ function parseCertificateRevocationListPemOrThrow(pem) {
|
|
|
144
132
|
* Does not verify the signature — call {@linkcode verifyCertificateRevocationListSignature} or
|
|
145
133
|
* {@linkcode validateCertificateRevocationList} for that.
|
|
146
134
|
*/
|
|
147
|
-
function parseCertificateRevocationListDer(
|
|
135
|
+
function parseCertificateRevocationListDer(e) {
|
|
148
136
|
try {
|
|
149
|
-
return
|
|
150
|
-
} catch (
|
|
151
|
-
|
|
152
|
-
return failureResult("malformed", error instanceof Error ? error.message : "Malformed CRL");
|
|
137
|
+
return O(parseCertificateRevocationListDerOrThrow(e));
|
|
138
|
+
} catch (e) {
|
|
139
|
+
return D(e), E("malformed", e instanceof Error ? e.message : "Malformed CRL");
|
|
153
140
|
}
|
|
154
141
|
}
|
|
155
142
|
/**
|
|
@@ -158,12 +145,11 @@ function parseCertificateRevocationListDer(der) {
|
|
|
158
145
|
* Returns a typed failure (`code: 'malformed'`) on malformed input. For the
|
|
159
146
|
* throwing form use {@linkcode parseCertificateRevocationListPemOrThrow}.
|
|
160
147
|
*/
|
|
161
|
-
function parseCertificateRevocationListPem(
|
|
148
|
+
function parseCertificateRevocationListPem(e) {
|
|
162
149
|
try {
|
|
163
|
-
return
|
|
164
|
-
} catch (
|
|
165
|
-
|
|
166
|
-
return failureResult("malformed", error instanceof Error ? error.message : "Malformed CRL");
|
|
150
|
+
return O(parseCertificateRevocationListPemOrThrow(e));
|
|
151
|
+
} catch (e) {
|
|
152
|
+
return D(e), E("malformed", e instanceof Error ? e.message : "Malformed CRL");
|
|
167
153
|
}
|
|
168
154
|
}
|
|
169
155
|
/**
|
|
@@ -172,68 +158,57 @@ function parseCertificateRevocationListPem(pem) {
|
|
|
172
158
|
* Does **not** check issuer name match, key-usage, or freshness — use
|
|
173
159
|
* {@linkcode validateCertificateRevocationList} for full validation.
|
|
174
160
|
*/
|
|
175
|
-
async function verifyCertificateRevocationListSignature(
|
|
176
|
-
let
|
|
177
|
-
let issuer;
|
|
161
|
+
async function verifyCertificateRevocationListSignature(e, t) {
|
|
162
|
+
let n, r;
|
|
178
163
|
try {
|
|
179
|
-
|
|
180
|
-
issuer = typeof issuerCertificate === "string" ? parseIssuerCertificatePem(issuerCertificate) : parseIssuerCertificateDer(new Uint8Array(issuerCertificate));
|
|
164
|
+
n = typeof e == "string" ? parseCertificateRevocationListPemOrThrow(e) : parseCertificateRevocationListDerOrThrow(new Uint8Array(e)), r = typeof t == "string" ? parseIssuerCertificatePem(t) : parseIssuerCertificateDer(new Uint8Array(t));
|
|
181
165
|
} catch {
|
|
182
166
|
return verifyCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list or issuer certificate input is malformed");
|
|
183
167
|
}
|
|
184
|
-
let
|
|
168
|
+
let i;
|
|
185
169
|
try {
|
|
186
|
-
|
|
170
|
+
i = await G(n.signatureAlgorithmOid, n.signatureAlgorithmParametersDer, r.publicKeyAlgorithmOid, r.publicKeyParametersOid, r.subjectPublicKeyInfoDer, n.signatureValue, n.tbsCertListDer);
|
|
187
171
|
} catch {
|
|
188
172
|
return verifyCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature verification failed");
|
|
189
173
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}
|
|
194
|
-
return verifiedResult.valid ? {
|
|
195
|
-
ok: true,
|
|
196
|
-
value: parsedCrl
|
|
197
|
-
} : verifyCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature does not verify");
|
|
174
|
+
return i.ok ? i.valid ? {
|
|
175
|
+
ok: !0,
|
|
176
|
+
value: n
|
|
177
|
+
} : 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");
|
|
198
178
|
}
|
|
199
179
|
/**
|
|
200
180
|
* Full CRL validation: issuer name match, authority key identifier match,
|
|
201
181
|
* cRLSign key-usage check, signature verification, and `thisUpdate`/`nextUpdate`
|
|
202
182
|
* freshness check (with optional clock-skew tolerance).
|
|
203
183
|
*/
|
|
204
|
-
async function validateCertificateRevocationList(
|
|
205
|
-
let
|
|
184
|
+
async function validateCertificateRevocationList(e) {
|
|
185
|
+
let t;
|
|
206
186
|
try {
|
|
207
|
-
|
|
187
|
+
t = normalizeCrl(e.crl);
|
|
208
188
|
} catch {
|
|
209
189
|
return validateCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signed content is malformed");
|
|
210
190
|
}
|
|
211
|
-
let
|
|
191
|
+
let n;
|
|
212
192
|
try {
|
|
213
|
-
|
|
193
|
+
n = normalizeCrlCertificate(e.issuerCertificate);
|
|
214
194
|
} catch {
|
|
215
195
|
return validateCertificateRevocationListFailureResult("signature_invalid", "issuer certificate input is malformed");
|
|
216
196
|
}
|
|
217
|
-
if (!
|
|
218
|
-
if (
|
|
219
|
-
if (
|
|
220
|
-
let
|
|
197
|
+
if (!Y(t.issuer, n.subject)) return validateCertificateRevocationListFailureResult("issuer_mismatch", "CRL issuer name does not match certificate subject");
|
|
198
|
+
if (t.authorityKeyIdentifier !== void 0 && n.subjectKeyIdentifier !== void 0 && t.authorityKeyIdentifier !== n.subjectKeyIdentifier) return validateCertificateRevocationListFailureResult("issuer_mismatch", "CRL authority key identifier does not match issuer subject key identifier");
|
|
199
|
+
if (n.keyUsage !== void 0 && !n.keyUsage.flags.includes("cRLSign")) return validateCertificateRevocationListFailureResult("crl_sign_not_permitted", "issuer certificate key usage does not permit CRL signing");
|
|
200
|
+
let r;
|
|
221
201
|
try {
|
|
222
|
-
|
|
202
|
+
r = await G(t.signatureAlgorithmOid, t.signatureAlgorithmParametersDer, n.publicKeyAlgorithmOid, n.publicKeyParametersOid, n.subjectPublicKeyInfoDer, t.signatureValue, t.tbsCertListDer);
|
|
223
203
|
} catch {
|
|
224
204
|
return validateCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature verification failed");
|
|
225
205
|
}
|
|
226
|
-
if (!
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
const skew = input.clockSkewMs ?? 0;
|
|
233
|
-
if (parsedCrl.thisUpdate.getTime() - skew > at.getTime() || parsedCrl.nextUpdate !== void 0 && parsedCrl.nextUpdate.getTime() + skew < at.getTime()) return validateCertificateRevocationListFailureResult("stale_crl", "CRL is not valid at requested time");
|
|
234
|
-
return {
|
|
235
|
-
ok: true,
|
|
236
|
-
value: parsedCrl
|
|
206
|
+
if (!r.ok) return r.code === "verification_error" ? validateCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature verification failed") : validateCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature uses unsupported algorithm parameters");
|
|
207
|
+
if (!r.valid) return validateCertificateRevocationListFailureResult("signature_invalid", "certificate revocation list signature does not verify");
|
|
208
|
+
let i = e.at ?? /* @__PURE__ */ new Date(), a = e.clockSkewMs ?? 0;
|
|
209
|
+
return t.thisUpdate.getTime() - a > i.getTime() || t.nextUpdate !== void 0 && t.nextUpdate.getTime() + a < i.getTime() ? validateCertificateRevocationListFailureResult("stale_crl", "CRL is not valid at requested time") : {
|
|
210
|
+
ok: !0,
|
|
211
|
+
value: t
|
|
237
212
|
};
|
|
238
213
|
}
|
|
239
214
|
/**
|
|
@@ -258,219 +233,194 @@ async function validateCertificateRevocationList(input) {
|
|
|
258
233
|
* }
|
|
259
234
|
* ```
|
|
260
235
|
*/
|
|
261
|
-
async function checkCertificateRevocationAgainstCrl(
|
|
262
|
-
let
|
|
236
|
+
async function checkCertificateRevocationAgainstCrl(e) {
|
|
237
|
+
let t;
|
|
263
238
|
try {
|
|
264
|
-
|
|
239
|
+
t = normalizeCrlCertificate(e.certificate);
|
|
265
240
|
} catch {
|
|
266
241
|
return checkCertificateRevocationAgainstCrlFailureResult("non_applicable", "certificate input is malformed");
|
|
267
242
|
}
|
|
268
|
-
|
|
269
|
-
crl:
|
|
270
|
-
issuerCertificate:
|
|
271
|
-
...
|
|
272
|
-
...
|
|
243
|
+
let n = await validateCertificateRevocationList({
|
|
244
|
+
crl: e.crl,
|
|
245
|
+
issuerCertificate: e.issuerCertificate,
|
|
246
|
+
...e.at === void 0 ? {} : { at: e.at },
|
|
247
|
+
...e.clockSkewMs === void 0 ? {} : { clockSkewMs: e.clockSkewMs }
|
|
273
248
|
});
|
|
274
|
-
if (!
|
|
275
|
-
let
|
|
276
|
-
if (
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
validatedDelta = deltaValidation.value;
|
|
249
|
+
if (!n.ok) return checkCertificateRevocationAgainstCrlFailureResult(n.code, n.message);
|
|
250
|
+
let r = await validateOptionalDeltaCrl(e, n.value);
|
|
251
|
+
if (!r.ok) return r;
|
|
252
|
+
let i = checkCrlAndDeltaApplicability(t, n.value, r.value);
|
|
253
|
+
if (i !== void 0) return i;
|
|
254
|
+
let a = findRevokedCertificateEntry(t, n.value);
|
|
255
|
+
if (!a.ok) return a;
|
|
256
|
+
let o;
|
|
257
|
+
if (r.value !== void 0) {
|
|
258
|
+
let e = findRevokedCertificateEntry(t, r.value);
|
|
259
|
+
if (!e.ok) return e;
|
|
260
|
+
o = e.entry;
|
|
287
261
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
262
|
+
return resolveCertificateRevocationStatus(t, e.at ?? /* @__PURE__ */ new Date(), n.value, a.entry, o);
|
|
263
|
+
}
|
|
264
|
+
/** Validates an optional delta CRL and checks compatibility with its complete CRL. */
|
|
265
|
+
async function validateOptionalDeltaCrl(e, t) {
|
|
266
|
+
if (e.deltaCrl === void 0) return { ok: !0 };
|
|
267
|
+
let n = await validateCertificateRevocationList({
|
|
268
|
+
crl: e.deltaCrl,
|
|
269
|
+
issuerCertificate: e.issuerCertificate,
|
|
270
|
+
...e.at === void 0 ? {} : { at: e.at },
|
|
271
|
+
...e.clockSkewMs === void 0 ? {} : { clockSkewMs: e.clockSkewMs }
|
|
272
|
+
});
|
|
273
|
+
return n.ok ? checkDeltaCrlCompatibility(t, n.value) ?? {
|
|
274
|
+
ok: !0,
|
|
275
|
+
value: n.value
|
|
276
|
+
} : checkCertificateRevocationAgainstCrlFailureResult(n.code, n.message);
|
|
277
|
+
}
|
|
278
|
+
function checkCrlAndDeltaApplicability(e, t, n) {
|
|
279
|
+
let r = checkCrlApplicability(e, t);
|
|
280
|
+
return r === void 0 ? n === void 0 ? void 0 : checkCrlApplicability(e, n, !0) : r;
|
|
303
281
|
}
|
|
304
282
|
/** Builds a `VerifyCertificateRevocationListSignatureFailureResult`. */
|
|
305
|
-
function verifyCertificateRevocationListFailureResult(
|
|
306
|
-
return
|
|
283
|
+
function verifyCertificateRevocationListFailureResult(e, t) {
|
|
284
|
+
return E(e, t);
|
|
307
285
|
}
|
|
308
286
|
/** Builds a `ValidateCertificateRevocationListFailureResult`. */
|
|
309
|
-
function validateCertificateRevocationListFailureResult(
|
|
310
|
-
return
|
|
287
|
+
function validateCertificateRevocationListFailureResult(e, t) {
|
|
288
|
+
return E(e, t);
|
|
311
289
|
}
|
|
312
290
|
/** Builds a `CheckCertificateRevocationAgainstCrlFailureResult`. */
|
|
313
|
-
function checkCertificateRevocationAgainstCrlFailureResult(
|
|
314
|
-
return
|
|
291
|
+
function checkCertificateRevocationAgainstCrlFailureResult(e, t, n) {
|
|
292
|
+
return E(e, t, n);
|
|
315
293
|
}
|
|
316
294
|
/** Wraps a success value into a `CheckCertificateRevocationAgainstCrlResult`. */
|
|
317
|
-
function checkCertificateRevocationAgainstCrlSuccess(
|
|
295
|
+
function checkCertificateRevocationAgainstCrlSuccess(e) {
|
|
318
296
|
return {
|
|
319
|
-
ok:
|
|
320
|
-
value
|
|
297
|
+
ok: !0,
|
|
298
|
+
value: e
|
|
321
299
|
};
|
|
322
300
|
}
|
|
323
301
|
/**
|
|
324
302
|
* Quick serial-number lookup — returns `true` if the serial appears in the
|
|
325
303
|
* CRL's revoked entries. Does **not** validate the CRL or check applicability.
|
|
326
304
|
*/
|
|
327
|
-
function isCertificateRevoked(
|
|
328
|
-
|
|
329
|
-
return
|
|
305
|
+
function isCertificateRevoked(e, t) {
|
|
306
|
+
let n = typeof e == "string" ? normalizeHex(e) : C(e);
|
|
307
|
+
return t.revokedCertificates.some((e) => normalizeHex(e.serialNumberHex) === n);
|
|
330
308
|
}
|
|
331
309
|
/** Searches CRL entries for the certificate's serial, respecting indirect-CRL issuer overrides. */
|
|
332
|
-
function findRevokedCertificateEntry(
|
|
333
|
-
|
|
334
|
-
let
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
const issuerMatch = matchesRevokedEntryIssuer(certificate, crl, effectiveIssuer);
|
|
341
|
-
if (issuerMatch === "match") {
|
|
342
|
-
if (matchedEntry !== void 0) return checkCertificateRevocationAgainstCrlFailureResult("signature_invalid", "CRL contains multiple revoked entries for certificate");
|
|
343
|
-
matchedEntry = entry;
|
|
310
|
+
function findRevokedCertificateEntry(e, t) {
|
|
311
|
+
let n = normalizeHex(e.serialNumberHex), r, i = !1, a;
|
|
312
|
+
for (let o of t.revokedCertificates) {
|
|
313
|
+
if (o.certificateIssuer !== void 0 && (r = o.certificateIssuer), normalizeHex(o.serialNumberHex) !== n) continue;
|
|
314
|
+
let s = matchesRevokedEntryIssuer(e, t, r);
|
|
315
|
+
if (s === "match") {
|
|
316
|
+
if (a !== void 0) return checkCertificateRevocationAgainstCrlFailureResult("signature_invalid", "CRL contains multiple revoked entries for certificate");
|
|
317
|
+
a = o;
|
|
344
318
|
continue;
|
|
345
319
|
}
|
|
346
|
-
|
|
320
|
+
s === "unsupported" && (i = !0);
|
|
347
321
|
}
|
|
348
|
-
|
|
349
|
-
ok:
|
|
350
|
-
entry:
|
|
322
|
+
return a === void 0 ? i ? nonApplicable("unsupported_indirect_crl", "indirect CRL entry certificateIssuer must include a directoryName") : { ok: !0 } : {
|
|
323
|
+
ok: !0,
|
|
324
|
+
entry: a
|
|
351
325
|
};
|
|
352
|
-
if (sawUnsupportedIssuer) return nonApplicable("unsupported_indirect_crl", "indirect CRL entry certificateIssuer must include a directoryName");
|
|
353
|
-
return { ok: true };
|
|
354
326
|
}
|
|
355
327
|
/** RFC 5280 §6.3 CRL applicability: scope, distribution-point, reason, and indirect-CRL checks. */
|
|
356
|
-
function checkCrlApplicability(
|
|
357
|
-
if (!
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
if (
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
if (
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
328
|
+
function checkCrlApplicability(e, t, n = !1) {
|
|
329
|
+
if (!n && t.baseCrlNumber !== void 0) return nonApplicable("unsupported_delta_crl", "a delta CRL cannot be used as the primary complete CRL input");
|
|
330
|
+
let r = t.issuingDistributionPoint, i = r?.indirectCrl === !0;
|
|
331
|
+
if (!i && !Y(e.issuer, t.issuer)) return nonApplicable("issuer_mismatch", "CRL issuer does not match certificate issuer for direct CRL processing");
|
|
332
|
+
if (r?.onlyContainsAttributeCerts === !0) return nonApplicable("certificate_scope_mismatch", "attribute-certificate-only CRLs are not applicable to public-key certificates");
|
|
333
|
+
let a = e.basicConstraints?.ca === !0;
|
|
334
|
+
if (r?.onlyContainsUserCerts === !0 && a) return nonApplicable("certificate_scope_mismatch", "CRL only applies to end-entity certificates");
|
|
335
|
+
if (r?.onlyContainsCACerts === !0 && !a) return nonApplicable("certificate_scope_mismatch", "CRL only applies to CA certificates");
|
|
336
|
+
let o = e.crlDistributionPoints ?? [];
|
|
337
|
+
return o.length === 0 ? r?.distributionPoint === void 0 ? i && !Y(e.issuer, t.issuer) ? nonApplicable("issuer_mismatch", "indirect CRLs for alternate certificate issuers require matching CRLIssuer distribution points") : void 0 : nonApplicable("distribution_point_mismatch", "certificates without CRL distribution points only accept full-scope CRLs") : crlDistributionPointScanFailure(scanCrlDistributionPoints(o, e, t, r, i));
|
|
338
|
+
}
|
|
339
|
+
/** Aggregates distribution-point matching outcomes across a certificate. */
|
|
340
|
+
function scanCrlDistributionPoints(e, t, n, r, i) {
|
|
341
|
+
let a = !1, o = !1, s = !1, c = !1, l = !1;
|
|
342
|
+
for (let u of e) {
|
|
343
|
+
let e = scanCrlDistributionPoint(u, t, n, r, i);
|
|
344
|
+
if (e === "matched") return e;
|
|
345
|
+
e === "indirect_distribution_point" && (a = !0), e === "distribution_point_mismatch" && (o = !0), e === "indirect_issuer_mismatch" && (s = !0), e === "unsupported_indirect_crl_issuer" && (c = !0), e === "reasons_mismatch" && (l = !0);
|
|
370
346
|
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
let
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
sawIndirectIssuerUnsupported = true;
|
|
386
|
-
continue;
|
|
387
|
-
}
|
|
388
|
-
if (!issuerMatch) {
|
|
389
|
-
sawIndirectIssuerMismatch = true;
|
|
390
|
-
continue;
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
if (!matchesDistributionPointName(distributionPoint.distributionPoint, issuingDistributionPoint?.distributionPoint, crl.issuer)) {
|
|
395
|
-
sawDistributionMismatch = true;
|
|
396
|
-
continue;
|
|
397
|
-
}
|
|
398
|
-
if (!hasOverlappingReasons(distributionPoint.reasons, issuingDistributionPoint?.onlySomeReasons)) {
|
|
399
|
-
sawReasonsMismatch = true;
|
|
400
|
-
continue;
|
|
401
|
-
}
|
|
402
|
-
return;
|
|
403
|
-
}
|
|
404
|
-
if (sawReasonsMismatch) return nonApplicable("reasons_mismatch", "certificate distribution point reasons do not overlap the CRL reason scope");
|
|
405
|
-
if (sawIndirectIssuerUnsupported) return nonApplicable("unsupported_indirect_crl", "indirect CRL distribution points must identify the CRL issuer with directoryName");
|
|
406
|
-
if (sawIndirectIssuerMismatch) return nonApplicable("issuer_mismatch", "certificate distribution points do not authorize this indirect CRL issuer");
|
|
407
|
-
if (sawDistributionMismatch) return nonApplicable("distribution_point_mismatch", "certificate distribution points do not match the CRL issuing distribution point");
|
|
408
|
-
if (sawIndirectDistributionPoint) return nonApplicable("unsupported_indirect_crl", "certificate distribution points that name alternate CRL issuers are not supported yet");
|
|
409
|
-
return nonApplicable("distribution_point_mismatch", "certificate distribution points do not match the CRL scope");
|
|
347
|
+
return l ? "reasons_mismatch" : c ? "unsupported_indirect_crl_issuer" : s ? "indirect_issuer_mismatch" : o ? "distribution_point_mismatch" : a ? "indirect_distribution_point" : "scope_mismatch";
|
|
348
|
+
}
|
|
349
|
+
function scanCrlDistributionPoint(e, t, n, r, i) {
|
|
350
|
+
let a = scanCrlDistributionPointIssuer(e, t, n, i);
|
|
351
|
+
return a === void 0 ? matchesDistributionPointName(e.distributionPoint, r?.distributionPoint, n.issuer) ? hasOverlappingReasons(e.reasons, r?.onlySomeReasons) ? "matched" : "reasons_mismatch" : "distribution_point_mismatch" : a;
|
|
352
|
+
}
|
|
353
|
+
function scanCrlDistributionPointIssuer(e, t, n, r) {
|
|
354
|
+
if (!r) return e.crlIssuer === void 0 ? void 0 : "indirect_distribution_point";
|
|
355
|
+
if (Y(t.issuer, n.issuer) && e.crlIssuer === void 0) return;
|
|
356
|
+
let i = matchesIndirectCrlIssuer(e.crlIssuer, n);
|
|
357
|
+
return i === "unsupported" ? "unsupported_indirect_crl_issuer" : i ? void 0 : "indirect_issuer_mismatch";
|
|
358
|
+
}
|
|
359
|
+
function crlDistributionPointScanFailure(e) {
|
|
360
|
+
if (e !== "matched") return e === "reasons_mismatch" ? nonApplicable("reasons_mismatch", "certificate distribution point reasons do not overlap the CRL reason scope") : e === "unsupported_indirect_crl_issuer" ? nonApplicable("unsupported_indirect_crl", "indirect CRL distribution points must identify the CRL issuer with directoryName") : e === "indirect_issuer_mismatch" ? nonApplicable("issuer_mismatch", "certificate distribution points do not authorize this indirect CRL issuer") : e === "distribution_point_mismatch" ? nonApplicable("distribution_point_mismatch", "certificate distribution points do not match the CRL issuing distribution point") : e === "indirect_distribution_point" ? nonApplicable("unsupported_indirect_crl", "certificate distribution points that name alternate CRL issuers are not supported yet") : nonApplicable("distribution_point_mismatch", "certificate distribution points do not match the CRL scope");
|
|
410
361
|
}
|
|
411
362
|
/** Verifies that a delta CRL is compatible with the given complete CRL (same issuer, AKI, IDP, and valid numbering). */
|
|
412
|
-
function checkDeltaCrlCompatibility(
|
|
413
|
-
if (
|
|
414
|
-
if (
|
|
415
|
-
if (!
|
|
416
|
-
if (
|
|
417
|
-
if (!sameIssuingDistributionPoint(
|
|
418
|
-
if (
|
|
419
|
-
if (
|
|
420
|
-
if (
|
|
363
|
+
function checkDeltaCrlCompatibility(e, t) {
|
|
364
|
+
if (e.baseCrlNumber !== void 0) return nonApplicable("delta_crl_incompatible", "complete CRL input must not itself be a delta CRL");
|
|
365
|
+
if (t.baseCrlNumber === void 0) return nonApplicable("delta_crl_incompatible", "delta CRL input must include a delta CRL indicator");
|
|
366
|
+
if (!Y(e.issuer, t.issuer)) return nonApplicable("delta_crl_incompatible", "complete and delta CRLs must share the same issuer");
|
|
367
|
+
if (e.authorityKeyIdentifier !== t.authorityKeyIdentifier) return nonApplicable("delta_crl_incompatible", "complete and delta CRLs must share the same authority key identifier");
|
|
368
|
+
if (!sameIssuingDistributionPoint(e.issuingDistributionPoint, t.issuingDistributionPoint)) return nonApplicable("delta_crl_incompatible", "complete and delta CRLs must share the same issuing distribution point scope");
|
|
369
|
+
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");
|
|
370
|
+
if (e.crlNumber < t.baseCrlNumber) return nonApplicable("delta_crl_incompatible", "delta CRL base number must not exceed the complete CRL number");
|
|
371
|
+
if (e.crlNumber >= t.crlNumber) return nonApplicable("delta_crl_incompatible", "delta CRL number must be newer than the complete CRL number");
|
|
421
372
|
}
|
|
422
373
|
/** Checks whether any `crlIssuer` GeneralName matches the CRL's issuer via directoryName DER comparison. */
|
|
423
|
-
function matchesIndirectCrlIssuer(
|
|
424
|
-
if (
|
|
425
|
-
let
|
|
426
|
-
for (
|
|
427
|
-
if (
|
|
428
|
-
if (directoryNameDerHexMatchesParsedName(
|
|
374
|
+
function matchesIndirectCrlIssuer(e, t) {
|
|
375
|
+
if (e === void 0) return !1;
|
|
376
|
+
let n = !1;
|
|
377
|
+
for (let r of e) {
|
|
378
|
+
if (r.type === "directoryName") {
|
|
379
|
+
if (directoryNameDerHexMatchesParsedName(r.derHex, t.issuer)) return !0;
|
|
429
380
|
continue;
|
|
430
381
|
}
|
|
431
|
-
|
|
382
|
+
n = !0;
|
|
432
383
|
}
|
|
433
|
-
return
|
|
384
|
+
return n ? "unsupported" : !1;
|
|
434
385
|
}
|
|
435
386
|
/** Determines whether a revoked entry's effective issuer matches the certificate's issuer. */
|
|
436
|
-
function matchesRevokedEntryIssuer(
|
|
437
|
-
if (
|
|
438
|
-
let
|
|
439
|
-
for (
|
|
440
|
-
if (
|
|
441
|
-
if (directoryNameDerHexMatchesParsedName(
|
|
387
|
+
function matchesRevokedEntryIssuer(e, t, n) {
|
|
388
|
+
if (n === void 0) return Y(e.issuer, t.issuer) ? "match" : "mismatch";
|
|
389
|
+
let r = !1;
|
|
390
|
+
for (let t of n) {
|
|
391
|
+
if (t.type === "directoryName") {
|
|
392
|
+
if (directoryNameDerHexMatchesParsedName(t.derHex, e.issuer)) return "match";
|
|
442
393
|
continue;
|
|
443
394
|
}
|
|
444
|
-
|
|
395
|
+
r = !0;
|
|
445
396
|
}
|
|
446
|
-
return
|
|
397
|
+
return r ? "unsupported" : "mismatch";
|
|
447
398
|
}
|
|
448
399
|
/** Shorthand for building a `non_applicable` failure result with the given reason. */
|
|
449
|
-
function nonApplicable(
|
|
450
|
-
return checkCertificateRevocationAgainstCrlFailureResult("non_applicable",
|
|
400
|
+
function nonApplicable(e, t) {
|
|
401
|
+
return checkCertificateRevocationAgainstCrlFailureResult("non_applicable", t, { reason: e });
|
|
451
402
|
}
|
|
452
403
|
/** Merges complete and delta CRL entries per RFC 5280 §5.2.4 to produce a final `good`/`revoked` status. */
|
|
453
|
-
function resolveCertificateRevocationStatus(
|
|
454
|
-
if (
|
|
455
|
-
if (
|
|
404
|
+
function resolveCertificateRevocationStatus(e, t, n, r, i) {
|
|
405
|
+
if (i !== void 0) if (i.reasonCode === "removeFromCRL") {
|
|
406
|
+
if (r?.reasonCode === "certificateHold" || e.notAfter.getTime() < t.getTime()) return checkCertificateRevocationAgainstCrlSuccess({
|
|
456
407
|
status: "good",
|
|
457
|
-
crl:
|
|
408
|
+
crl: n
|
|
458
409
|
});
|
|
459
410
|
} else return checkCertificateRevocationAgainstCrlSuccess({
|
|
460
411
|
status: "revoked",
|
|
461
|
-
crl:
|
|
462
|
-
revocationDate:
|
|
463
|
-
...
|
|
412
|
+
crl: n,
|
|
413
|
+
revocationDate: i.revocationDate,
|
|
414
|
+
...i.reasonCode === void 0 ? {} : { reasonCode: i.reasonCode }
|
|
464
415
|
});
|
|
465
|
-
|
|
416
|
+
return checkCertificateRevocationAgainstCrlSuccess(r === void 0 ? {
|
|
466
417
|
status: "good",
|
|
467
|
-
crl:
|
|
468
|
-
}
|
|
469
|
-
return checkCertificateRevocationAgainstCrlSuccess({
|
|
418
|
+
crl: n
|
|
419
|
+
} : {
|
|
470
420
|
status: "revoked",
|
|
471
|
-
crl:
|
|
472
|
-
revocationDate:
|
|
473
|
-
...
|
|
421
|
+
crl: n,
|
|
422
|
+
revocationDate: r.revocationDate,
|
|
423
|
+
...r.reasonCode === void 0 ? {} : { reasonCode: r.reasonCode }
|
|
474
424
|
});
|
|
475
425
|
}
|
|
476
426
|
/**
|
|
@@ -480,370 +430,345 @@ function resolveCertificateRevocationStatus(certificate, at, completeCrl, comple
|
|
|
480
430
|
* the full distribution point name is formed by appending that RDN to the CRL issuer's DN.
|
|
481
431
|
* This resolved name is then compared against the CRL's IDP fullName directoryName entries.
|
|
482
432
|
*/
|
|
483
|
-
function matchesDistributionPointName(
|
|
484
|
-
if (
|
|
485
|
-
if (
|
|
486
|
-
if (
|
|
487
|
-
if (
|
|
488
|
-
|
|
489
|
-
return
|
|
433
|
+
function matchesDistributionPointName(e, t, n) {
|
|
434
|
+
if (t === void 0) return !0;
|
|
435
|
+
if (e === void 0) return !1;
|
|
436
|
+
if (e.fullName !== void 0 && t.fullName !== void 0) return e.fullName.some((e) => t.fullName?.some((t) => compareGeneralNames(e, t)) === !0);
|
|
437
|
+
if (e.relativeName !== void 0 && t.fullName !== void 0) {
|
|
438
|
+
let r = resolveRelativeNameToDnHex(n, e.relativeName);
|
|
439
|
+
return t.fullName.some((e) => e.type === "directoryName" && e.derHex === r);
|
|
490
440
|
}
|
|
491
|
-
if (
|
|
492
|
-
if (
|
|
493
|
-
|
|
494
|
-
return
|
|
441
|
+
if (e.relativeName !== void 0 && t.relativeName !== void 0) return compareRelativeDistinguishedNames(e.relativeName, t.relativeName);
|
|
442
|
+
if (e.fullName !== void 0 && t.relativeName !== void 0) {
|
|
443
|
+
let r = resolveRelativeNameToDnHex(n, t.relativeName);
|
|
444
|
+
return e.fullName.some((e) => e.type === "directoryName" && e.derHex === r);
|
|
495
445
|
}
|
|
496
|
-
return
|
|
446
|
+
return !1;
|
|
497
447
|
}
|
|
498
448
|
/** Constructs a full DN by appending an RDN to an existing Name, returning hex-encoded DER. */
|
|
499
|
-
function resolveRelativeNameToDnHex(
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
rdnDerParts.push(relativeNameRdnDer);
|
|
503
|
-
return toHex(sequence(rdnDerParts));
|
|
449
|
+
function resolveRelativeNameToDnHex(e, t) {
|
|
450
|
+
let n = e.rdns.map((e) => b(e.derHex)), r = rebuildRelativeNameAsSet(b(t.derHex));
|
|
451
|
+
return n.push(r), C(d(n));
|
|
504
452
|
}
|
|
505
453
|
/** Converts an implicit-tagged [1] relativeName to a proper SET-tagged RDN. */
|
|
506
|
-
function rebuildRelativeNameAsSet(
|
|
507
|
-
return
|
|
454
|
+
function rebuildRelativeNameAsSet(e) {
|
|
455
|
+
return p(49, l(e, { maxDepth: 64 }).value);
|
|
508
456
|
}
|
|
509
457
|
/** Deep-compares two issuing distribution point extensions for delta-CRL compatibility. */
|
|
510
|
-
function sameIssuingDistributionPoint(
|
|
511
|
-
|
|
512
|
-
return sameDistributionPointName(left.distributionPoint, right.distributionPoint) && left.onlyContainsUserCerts === true === (right.onlyContainsUserCerts === true) && left.onlyContainsCACerts === true === (right.onlyContainsCACerts === true) && left.indirectCrl === true === (right.indirectCrl === true) && left.onlyContainsAttributeCerts === true === (right.onlyContainsAttributeCerts === true) && sameReasonSet(left.onlySomeReasons, right.onlySomeReasons);
|
|
458
|
+
function sameIssuingDistributionPoint(e, t) {
|
|
459
|
+
return e === void 0 || t === void 0 ? e === t : sameDistributionPointName(e.distributionPoint, t.distributionPoint) && e.onlyContainsUserCerts === !0 == (t.onlyContainsUserCerts === !0) && e.onlyContainsCACerts === !0 == (t.onlyContainsCACerts === !0) && e.indirectCrl === !0 == (t.indirectCrl === !0) && e.onlyContainsAttributeCerts === !0 == (t.onlyContainsAttributeCerts === !0) && sameReasonSet(e.onlySomeReasons, t.onlySomeReasons);
|
|
513
460
|
}
|
|
514
461
|
/** Compares two DistributionPointName values (fullName set or relativeName). */
|
|
515
|
-
function sameDistributionPointName(
|
|
516
|
-
|
|
517
|
-
if (left.fullName !== void 0 || right.fullName !== void 0) {
|
|
518
|
-
if (left.fullName === void 0 || right.fullName === void 0) return false;
|
|
519
|
-
return sameGeneralNameSet(left.fullName, right.fullName);
|
|
520
|
-
}
|
|
521
|
-
if (left.relativeName === void 0 || right.relativeName === void 0) return false;
|
|
522
|
-
return compareRelativeDistinguishedNames(left.relativeName, right.relativeName);
|
|
462
|
+
function sameDistributionPointName(e, t) {
|
|
463
|
+
return e === void 0 || t === void 0 ? e === t : e.fullName !== void 0 || t.fullName !== void 0 ? e.fullName === void 0 || t.fullName === void 0 ? !1 : sameGeneralNameSet(e.fullName, t.fullName) : e.relativeName === void 0 || t.relativeName === void 0 ? !1 : compareRelativeDistinguishedNames(e.relativeName, t.relativeName);
|
|
523
464
|
}
|
|
524
465
|
/** Set-equality comparison for GeneralName arrays (order-independent). */
|
|
525
|
-
function sameGeneralNameSet(
|
|
526
|
-
if (
|
|
527
|
-
|
|
528
|
-
for (
|
|
529
|
-
let
|
|
530
|
-
for (let
|
|
531
|
-
|
|
532
|
-
if (
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
break;
|
|
466
|
+
function sameGeneralNameSet(e, t) {
|
|
467
|
+
if (e.length !== t.length) return !1;
|
|
468
|
+
let n = Array(t.length).fill(!1);
|
|
469
|
+
for (let r of e) {
|
|
470
|
+
let e = !1;
|
|
471
|
+
for (let i = 0; i < t.length; i += 1) {
|
|
472
|
+
let a = t[i];
|
|
473
|
+
if (!(a === void 0 || n[i]) && compareGeneralNames(r, a)) {
|
|
474
|
+
n[i] = !0, e = !0;
|
|
475
|
+
break;
|
|
476
|
+
}
|
|
537
477
|
}
|
|
538
|
-
if (!
|
|
478
|
+
if (!e) return !1;
|
|
539
479
|
}
|
|
540
|
-
return
|
|
480
|
+
return !0;
|
|
541
481
|
}
|
|
542
482
|
/** Set-equality comparison for DistributionPointReason arrays. */
|
|
543
|
-
function sameReasonSet(
|
|
544
|
-
|
|
545
|
-
if (left.flags.length !== right.flags.length) return false;
|
|
546
|
-
return left.flags.every((reason) => right.flags.includes(reason));
|
|
483
|
+
function sameReasonSet(e, t) {
|
|
484
|
+
return e === void 0 || t === void 0 ? e === t : e.flags.length === t.flags.length && e.flags.every((e) => t.flags.includes(e));
|
|
547
485
|
}
|
|
548
486
|
/** Returns `true` if the certificate's DP reasons overlap the CRL's `onlySomeReasons`, or if either is absent (= all reasons). */
|
|
549
|
-
function hasOverlappingReasons(
|
|
550
|
-
|
|
551
|
-
return certificateReasons.flags.some((reason) => crlReasons.flags.includes(reason));
|
|
487
|
+
function hasOverlappingReasons(e, t) {
|
|
488
|
+
return e === void 0 || t === void 0 || e.flags.some((e) => t.flags.includes(e));
|
|
552
489
|
}
|
|
553
490
|
/** Value-equality for two GeneralName entries, using DER comparison for directoryName. */
|
|
554
|
-
function compareGeneralNames(
|
|
555
|
-
if (
|
|
556
|
-
if (
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
if (left.type === "directoryName" && right.type === "directoryName") {
|
|
560
|
-
const leftName = parseDerHexName(left.derHex);
|
|
561
|
-
const rightName = parseDerHexName(right.derHex);
|
|
562
|
-
if (leftName === void 0 || rightName === void 0) return false;
|
|
563
|
-
return compareDistinguishedNames(leftName, rightName);
|
|
491
|
+
function compareGeneralNames(e, t) {
|
|
492
|
+
if (e.type === "dns" && t.type === "dns" || e.type === "email" && t.type === "email" || e.type === "ip" && t.type === "ip" || e.type === "uri" && t.type === "uri") return e.value === t.value;
|
|
493
|
+
if (e.type === "directoryName" && t.type === "directoryName") {
|
|
494
|
+
let n = parseDerHexName(e.derHex), r = parseDerHexName(t.derHex);
|
|
495
|
+
return n === void 0 || r === void 0 ? !1 : Y(n, r);
|
|
564
496
|
}
|
|
565
|
-
|
|
566
|
-
return false;
|
|
497
|
+
return e.type === "unknown" && t.type === "unknown" && e.tag === t.tag && bytesEqual(e.value, t.value);
|
|
567
498
|
}
|
|
568
499
|
/** Constant-length byte-array equality check. */
|
|
569
|
-
function bytesEqual(
|
|
570
|
-
if (
|
|
571
|
-
for (let
|
|
572
|
-
return
|
|
500
|
+
function bytesEqual(e, t) {
|
|
501
|
+
if (e.length !== t.length) return !1;
|
|
502
|
+
for (let n = 0; n < e.length; n += 1) if (e[n] !== t[n]) return !1;
|
|
503
|
+
return !0;
|
|
573
504
|
}
|
|
574
505
|
/** Set-equality comparison for RDN attribute sets (order-independent, RFC 4518 string prep). */
|
|
575
|
-
function compareRelativeDistinguishedNames(
|
|
576
|
-
if (
|
|
577
|
-
|
|
578
|
-
for (
|
|
579
|
-
let
|
|
580
|
-
for (let
|
|
581
|
-
|
|
582
|
-
if (
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
break;
|
|
506
|
+
function compareRelativeDistinguishedNames(e, t) {
|
|
507
|
+
if (e.attributes.length !== t.attributes.length) return !1;
|
|
508
|
+
let n = Array(t.attributes.length).fill(!1);
|
|
509
|
+
for (let r of e.attributes) {
|
|
510
|
+
let e = !1;
|
|
511
|
+
for (let i = 0; i < t.attributes.length; i += 1) {
|
|
512
|
+
let a = t.attributes[i];
|
|
513
|
+
if (!(a === void 0 || n[i]) && X(r, a)) {
|
|
514
|
+
n[i] = !0, e = !0;
|
|
515
|
+
break;
|
|
516
|
+
}
|
|
587
517
|
}
|
|
588
|
-
if (!
|
|
518
|
+
if (!e) return !1;
|
|
589
519
|
}
|
|
590
|
-
return
|
|
520
|
+
return !0;
|
|
591
521
|
}
|
|
592
522
|
/** Assembles the CRL-level v2 extensions (AKI, CRLNumber, deltaCRLIndicator, IDP, freshestCRL). */
|
|
593
|
-
async function buildCrlExtensions(
|
|
594
|
-
|
|
595
|
-
if (
|
|
596
|
-
|
|
597
|
-
|
|
523
|
+
async function buildCrlExtensions(e, t, n, r, i) {
|
|
524
|
+
let o = [];
|
|
525
|
+
if (e !== void 0) {
|
|
526
|
+
let t = await j(e);
|
|
527
|
+
o.push(V(w.authorityKeyIdentifier, d([a(0, z(t))])));
|
|
598
528
|
}
|
|
599
|
-
|
|
600
|
-
if (baseCrlNumber !== void 0) extensions.push(encodeExtension(OIDS.deltaCRLIndicator, integerFromNumber(baseCrlNumber), true));
|
|
601
|
-
if (issuingDistributionPoint !== void 0) extensions.push(encodeExtension(OIDS.issuingDistributionPoint, encodeIssuingDistributionPoint(issuingDistributionPoint), true));
|
|
602
|
-
if (freshestCrlDistributionPoints !== void 0 && freshestCrlDistributionPoints.length > 0) extensions.push(encodeExtension(OIDS.freshestCRL, encodeCrlDistributionPoints(freshestCrlDistributionPoints)));
|
|
603
|
-
return extensions;
|
|
529
|
+
return t !== void 0 && o.push(V(w.cRLNumber, s(t))), n !== void 0 && o.push(V(w.deltaCRLIndicator, s(n), !0)), r !== void 0 && o.push(V(w.issuingDistributionPoint, encodeIssuingDistributionPoint(r), !0)), i !== void 0 && i.length > 0 && o.push(V(w.freshestCRL, B(i))), o;
|
|
604
530
|
}
|
|
605
531
|
/** DER-encodes a single revokedCertificate SEQUENCE (serial, date, optional extensions). */
|
|
606
|
-
function createRevokedCertificate(
|
|
607
|
-
|
|
608
|
-
return
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
...
|
|
532
|
+
function createRevokedCertificate(e, t) {
|
|
533
|
+
let n = buildRevokedCertificateExtensions(e);
|
|
534
|
+
return d([
|
|
535
|
+
o(e.serialNumber),
|
|
536
|
+
f(e.revocationDate ?? t),
|
|
537
|
+
...n.length === 0 ? [] : [d(n)]
|
|
612
538
|
]);
|
|
613
539
|
}
|
|
614
540
|
/** Encodes CRL entry extensions (reasonCode, invalidityDate). */
|
|
615
|
-
function buildRevokedCertificateExtensions(
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
if (entry.invalidityDate !== void 0) extensions.push(encodeExtension(OIDS.invalidityDate, generalizedTime(entry.invalidityDate)));
|
|
619
|
-
return extensions;
|
|
541
|
+
function buildRevokedCertificateExtensions(e) {
|
|
542
|
+
let t = [];
|
|
543
|
+
return e.reasonCode !== void 0 && t.push(V(w.cRLReason, p(10, Uint8Array.of(Z[e.reasonCode])))), e.invalidityDate !== void 0 && t.push(V(w.invalidityDate, r(e.invalidityDate))), t;
|
|
620
544
|
}
|
|
621
545
|
/** Decodes per-entry CRL extensions (reasonCode, invalidityDate, certificateIssuer). */
|
|
622
|
-
function parseRevokedCertificateExtensions(
|
|
623
|
-
if (
|
|
624
|
-
let
|
|
625
|
-
let
|
|
626
|
-
let certificateIssuer;
|
|
627
|
-
const seenOids = /* @__PURE__ */ new Set();
|
|
628
|
-
for (const extension of childrenOf(entryDer, element)) {
|
|
629
|
-
const parts = childrenOf(entryDer, extension);
|
|
630
|
-
if (parts.length < 2 || parts.length > 3) throw new Error("Malformed revoked certificate extension");
|
|
631
|
-
if (parts.length === 3 && parts[1]?.tag !== 1) throw new Error("Malformed revoked certificate extension");
|
|
632
|
-
const oid = decodeObjectIdentifier(requireElement(parts[0], "revoked certificate extension OID").value);
|
|
633
|
-
if (seenOids.has(oid)) throw new Error(`Duplicate revoked certificate extension OID: ${oid}`);
|
|
634
|
-
seenOids.add(oid);
|
|
635
|
-
const valueElement = requireElement(parts[parts.length - 1], "revoked certificate extension value");
|
|
636
|
-
if (valueElement.tag !== 4) throw new Error("Revoked certificate extension value must use OCTET STRING");
|
|
637
|
-
if (oid === OIDS.cRLReason) reasonCode = revocationReasonFromCode(readElement(valueElement.value).value[0]);
|
|
638
|
-
if (oid === OIDS.invalidityDate) invalidityDate = parseTime(readElement(valueElement.value));
|
|
639
|
-
if (oid === OIDS.certificateIssuer) {
|
|
640
|
-
const generalNames = readRootElement(valueElement.value, { maxDepth: 64 });
|
|
641
|
-
if (generalNames.tag !== 48) throw new Error("certificateIssuer must use SEQUENCE");
|
|
642
|
-
certificateIssuer = parseGeneralNames(valueElement.value, generalNames);
|
|
643
|
-
}
|
|
644
|
-
}
|
|
546
|
+
function parseRevokedCertificateExtensions(e, t) {
|
|
547
|
+
if (e === void 0 || t === void 0) return {};
|
|
548
|
+
let n = {}, r = /* @__PURE__ */ new Set();
|
|
549
|
+
for (let i of m(e, t)) parseRevokedCertificateExtension(e, i, r, n);
|
|
645
550
|
return {
|
|
646
|
-
...reasonCode === void 0 ? {} : { reasonCode },
|
|
647
|
-
...invalidityDate === void 0 ? {} : { invalidityDate },
|
|
648
|
-
...certificateIssuer === void 0 ? {} : { certificateIssuer }
|
|
551
|
+
...n.reasonCode === void 0 ? {} : { reasonCode: n.reasonCode },
|
|
552
|
+
...n.invalidityDate === void 0 ? {} : { invalidityDate: n.invalidityDate },
|
|
553
|
+
...n.certificateIssuer === void 0 ? {} : { certificateIssuer: n.certificateIssuer }
|
|
649
554
|
};
|
|
650
555
|
}
|
|
556
|
+
function parseRevokedCertificateExtension(e, t, n, r) {
|
|
557
|
+
let i = m(e, t);
|
|
558
|
+
if (i.length < 2 || i.length > 3 || i.length === 3 && i[1]?.tag !== 1) throw Error("Malformed revoked certificate extension");
|
|
559
|
+
let a = _(S(i[0], "revoked certificate extension OID").value);
|
|
560
|
+
if (n.has(a)) throw Error(`Duplicate revoked certificate extension OID: ${a}`);
|
|
561
|
+
n.add(a);
|
|
562
|
+
let o = S(i[i.length - 1], "revoked certificate extension value");
|
|
563
|
+
if (o.tag !== 4) throw Error("Revoked certificate extension value must use OCTET STRING");
|
|
564
|
+
applyRevokedCertificateExtensionValue(a, o.value, r);
|
|
565
|
+
}
|
|
566
|
+
function applyRevokedCertificateExtensionValue(e, t, n) {
|
|
567
|
+
if (e === w.cRLReason) {
|
|
568
|
+
let e = revocationReasonFromCode(c(t).value[0]);
|
|
569
|
+
e !== void 0 && (n.reasonCode = e);
|
|
570
|
+
}
|
|
571
|
+
if (e === w.invalidityDate && (n.invalidityDate = x(c(t))), e === w.certificateIssuer) {
|
|
572
|
+
let e = l(t, { maxDepth: 64 });
|
|
573
|
+
if (e.tag !== 48) throw Error("certificateIssuer must use SEQUENCE");
|
|
574
|
+
n.certificateIssuer = parseGeneralNames(t, e);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
651
577
|
/** Decodes the IssuingDistributionPoint extension from its OCTET STRING content. */
|
|
652
|
-
function parseIssuingDistributionPoint(
|
|
653
|
-
|
|
654
|
-
let
|
|
655
|
-
let onlyContainsUserCerts;
|
|
656
|
-
let onlyContainsCACerts;
|
|
657
|
-
let onlySomeReasons;
|
|
658
|
-
let indirectCrl;
|
|
659
|
-
let onlyContainsAttributeCerts;
|
|
660
|
-
for (const child of childrenOf(valueDer, sequenceElement)) if (child.tag === 160) {
|
|
661
|
-
if (distributionPoint !== void 0) throw new Error("IssuingDistributionPoint distributionPoint must not repeat");
|
|
662
|
-
const parsedDistributionPoint = parseDistributionPointName(valueDer, child);
|
|
663
|
-
if (parsedDistributionPoint !== void 0) distributionPoint = parsedDistributionPoint;
|
|
664
|
-
} else if (child.tag === 129) {
|
|
665
|
-
if (onlyContainsUserCerts !== void 0) throw new Error("IssuingDistributionPoint onlyContainsUserCerts must not repeat");
|
|
666
|
-
onlyContainsUserCerts = parseImplicitBoolean(child);
|
|
667
|
-
} else if (child.tag === 130) {
|
|
668
|
-
if (onlyContainsCACerts !== void 0) throw new Error("IssuingDistributionPoint onlyContainsCACerts must not repeat");
|
|
669
|
-
onlyContainsCACerts = parseImplicitBoolean(child);
|
|
670
|
-
} else if (child.tag === 131) {
|
|
671
|
-
if (onlySomeReasons !== void 0) throw new Error("IssuingDistributionPoint onlySomeReasons must not repeat");
|
|
672
|
-
onlySomeReasons = parseDistributionPointReasonFlagsContent(child.value);
|
|
673
|
-
} else if (child.tag === 132) {
|
|
674
|
-
if (indirectCrl !== void 0) throw new Error("IssuingDistributionPoint indirectCrl must not repeat");
|
|
675
|
-
indirectCrl = parseImplicitBoolean(child);
|
|
676
|
-
} else if (child.tag === 133) {
|
|
677
|
-
if (onlyContainsAttributeCerts !== void 0) throw new Error("IssuingDistributionPoint onlyContainsAttributeCerts must not repeat");
|
|
678
|
-
onlyContainsAttributeCerts = parseImplicitBoolean(child);
|
|
679
|
-
} else throw new Error(`Unsupported IssuingDistributionPoint field tag: ${String(child.tag)}`);
|
|
578
|
+
function parseIssuingDistributionPoint(e) {
|
|
579
|
+
let t = l(e, { maxDepth: 64 }), n = {};
|
|
580
|
+
for (let r of m(e, t)) parseIssuingDistributionPointField(e, r, n);
|
|
680
581
|
if ([
|
|
681
|
-
onlyContainsUserCerts,
|
|
682
|
-
onlyContainsCACerts,
|
|
683
|
-
onlyContainsAttributeCerts
|
|
684
|
-
].filter((
|
|
582
|
+
n.onlyContainsUserCerts,
|
|
583
|
+
n.onlyContainsCACerts,
|
|
584
|
+
n.onlyContainsAttributeCerts
|
|
585
|
+
].filter((e) => e === !0).length > 1) throw Error("IssuingDistributionPoint scope booleans are mutually exclusive");
|
|
685
586
|
return {
|
|
686
|
-
...distributionPoint === void 0 ? {} : { distributionPoint },
|
|
687
|
-
...onlyContainsUserCerts === void 0 ? {} : { onlyContainsUserCerts },
|
|
688
|
-
...onlyContainsCACerts === void 0 ? {} : { onlyContainsCACerts },
|
|
689
|
-
...onlySomeReasons === void 0 ? {} : { onlySomeReasons },
|
|
690
|
-
...indirectCrl === void 0 ? {} : { indirectCrl },
|
|
691
|
-
...onlyContainsAttributeCerts === void 0 ? {} : { onlyContainsAttributeCerts }
|
|
587
|
+
...n.distributionPoint === void 0 ? {} : { distributionPoint: n.distributionPoint },
|
|
588
|
+
...n.onlyContainsUserCerts === void 0 ? {} : { onlyContainsUserCerts: n.onlyContainsUserCerts },
|
|
589
|
+
...n.onlyContainsCACerts === void 0 ? {} : { onlyContainsCACerts: n.onlyContainsCACerts },
|
|
590
|
+
...n.onlySomeReasons === void 0 ? {} : { onlySomeReasons: n.onlySomeReasons },
|
|
591
|
+
...n.indirectCrl === void 0 ? {} : { indirectCrl: n.indirectCrl },
|
|
592
|
+
...n.onlyContainsAttributeCerts === void 0 ? {} : { onlyContainsAttributeCerts: n.onlyContainsAttributeCerts }
|
|
692
593
|
};
|
|
693
594
|
}
|
|
595
|
+
function parseIssuingDistributionPointField(e, t, n) {
|
|
596
|
+
switch (t.tag) {
|
|
597
|
+
case 160: {
|
|
598
|
+
if (n.distributionPoint !== void 0) throw Error("IssuingDistributionPoint distributionPoint must not repeat");
|
|
599
|
+
let r = parseDistributionPointName(e, t);
|
|
600
|
+
r !== void 0 && (n.distributionPoint = r);
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
case 129:
|
|
604
|
+
n.onlyContainsUserCerts = parseUniqueIssuingDistributionPointBoolean(n.onlyContainsUserCerts, t, "onlyContainsUserCerts");
|
|
605
|
+
return;
|
|
606
|
+
case 130:
|
|
607
|
+
n.onlyContainsCACerts = parseUniqueIssuingDistributionPointBoolean(n.onlyContainsCACerts, t, "onlyContainsCACerts");
|
|
608
|
+
return;
|
|
609
|
+
case 131:
|
|
610
|
+
if (n.onlySomeReasons !== void 0) throw Error("IssuingDistributionPoint onlySomeReasons must not repeat");
|
|
611
|
+
n.onlySomeReasons = F(t.value);
|
|
612
|
+
return;
|
|
613
|
+
case 132:
|
|
614
|
+
n.indirectCrl = parseUniqueIssuingDistributionPointBoolean(n.indirectCrl, t, "indirectCrl");
|
|
615
|
+
return;
|
|
616
|
+
case 133:
|
|
617
|
+
n.onlyContainsAttributeCerts = parseUniqueIssuingDistributionPointBoolean(n.onlyContainsAttributeCerts, t, "onlyContainsAttributeCerts");
|
|
618
|
+
return;
|
|
619
|
+
default: throw Error(`Unsupported IssuingDistributionPoint field tag: ${String(t.tag)}`);
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
function parseUniqueIssuingDistributionPointBoolean(e, t, n) {
|
|
623
|
+
if (e !== void 0) throw Error(`IssuingDistributionPoint ${n} must not repeat`);
|
|
624
|
+
return parseImplicitBoolean(t);
|
|
625
|
+
}
|
|
694
626
|
/** Decodes a SEQUENCE OF DistributionPoint from DER. */
|
|
695
|
-
function parseDistributionPoints(
|
|
696
|
-
|
|
697
|
-
if (
|
|
698
|
-
|
|
699
|
-
if (
|
|
700
|
-
return
|
|
627
|
+
function parseDistributionPoints(e) {
|
|
628
|
+
let t = l(e, { maxDepth: 64 });
|
|
629
|
+
if (t.tag !== 48) throw Error("DistributionPoints must use SEQUENCE");
|
|
630
|
+
let n = m(e, t);
|
|
631
|
+
if (n.length === 0) throw Error("DistributionPoints must not be empty");
|
|
632
|
+
return n.map((t) => parseDistributionPoint(e, t));
|
|
701
633
|
}
|
|
702
634
|
/** Decodes a DistributionPointName (fullName or relativeName). */
|
|
703
|
-
function parseDistributionPointName(
|
|
704
|
-
|
|
705
|
-
if (
|
|
706
|
-
|
|
707
|
-
if (
|
|
708
|
-
|
|
709
|
-
if (
|
|
710
|
-
for (
|
|
711
|
-
return { fullName:
|
|
635
|
+
function parseDistributionPointName(e, t) {
|
|
636
|
+
let n = m(e, t);
|
|
637
|
+
if (n.length !== 1) throw Error("distributionPointName must contain exactly one choice");
|
|
638
|
+
let r = S(n[0], "distributionPointName");
|
|
639
|
+
if (r.tag === 160) {
|
|
640
|
+
let t = m(e, r);
|
|
641
|
+
if (t.length === 0) throw Error("distributionPointName fullName must not be empty");
|
|
642
|
+
for (let e of t) if ((e.tag & 192) != 128) throw Error("distributionPointName fullName must contain GeneralName entries");
|
|
643
|
+
return { fullName: t.map((e) => parseGeneralName(e)) };
|
|
712
644
|
}
|
|
713
|
-
if (
|
|
714
|
-
throw
|
|
645
|
+
if (r.tag === 161) return { relativeName: parseRelativeName(e, r) };
|
|
646
|
+
throw Error(`Unsupported distributionPointName tag: ${String(r.tag)}`);
|
|
715
647
|
}
|
|
716
648
|
/** Decodes a single DistributionPoint SEQUENCE. */
|
|
717
|
-
function parseDistributionPoint(
|
|
718
|
-
if (
|
|
719
|
-
let
|
|
720
|
-
let
|
|
721
|
-
|
|
722
|
-
for (const child of childrenOf(valueDer, element)) if (child.tag === 160) {
|
|
723
|
-
if (distributionPoint !== void 0) throw new Error("DistributionPoint distributionPoint must not repeat");
|
|
724
|
-
const parsedDistributionPoint = parseDistributionPointName(valueDer, child);
|
|
725
|
-
if (parsedDistributionPoint !== void 0) distributionPoint = parsedDistributionPoint;
|
|
726
|
-
} else if (child.tag === 129) {
|
|
727
|
-
if (reasons !== void 0) throw new Error("DistributionPoint reasons must not repeat");
|
|
728
|
-
reasons = parseDistributionPointReasonFlagsContent(child.value);
|
|
729
|
-
} else if (child.tag === 162) {
|
|
730
|
-
if (crlIssuer !== void 0) throw new Error("DistributionPoint crlIssuer must not repeat");
|
|
731
|
-
crlIssuer = parseGeneralNames(valueDer, child);
|
|
732
|
-
} else throw new Error(`Unsupported DistributionPoint field tag: ${String(child.tag)}`);
|
|
733
|
-
if (distributionPoint === void 0 && crlIssuer === void 0) throw new Error("DistributionPoint must include distributionPoint or crlIssuer");
|
|
649
|
+
function parseDistributionPoint(e, t) {
|
|
650
|
+
if (t.tag !== 48) throw Error("DistributionPoint must use SEQUENCE");
|
|
651
|
+
let n = {};
|
|
652
|
+
for (let r of m(e, t)) parseDistributionPointField(e, r, n);
|
|
653
|
+
if (n.distributionPoint === void 0 && n.crlIssuer === void 0) throw Error("DistributionPoint must include distributionPoint or crlIssuer");
|
|
734
654
|
return {
|
|
735
|
-
...distributionPoint === void 0 ? {} : { distributionPoint },
|
|
736
|
-
...reasons === void 0 ? {} : { reasons },
|
|
737
|
-
...crlIssuer === void 0 ? {} : { crlIssuer }
|
|
655
|
+
...n.distributionPoint === void 0 ? {} : { distributionPoint: n.distributionPoint },
|
|
656
|
+
...n.reasons === void 0 ? {} : { reasons: n.reasons },
|
|
657
|
+
...n.crlIssuer === void 0 ? {} : { crlIssuer: n.crlIssuer }
|
|
738
658
|
};
|
|
739
659
|
}
|
|
660
|
+
function parseDistributionPointField(e, t, n) {
|
|
661
|
+
switch (t.tag) {
|
|
662
|
+
case 160: {
|
|
663
|
+
if (n.distributionPoint !== void 0) throw Error("DistributionPoint distributionPoint must not repeat");
|
|
664
|
+
let r = parseDistributionPointName(e, t);
|
|
665
|
+
r !== void 0 && (n.distributionPoint = r);
|
|
666
|
+
return;
|
|
667
|
+
}
|
|
668
|
+
case 129:
|
|
669
|
+
if (n.reasons !== void 0) throw Error("DistributionPoint reasons must not repeat");
|
|
670
|
+
n.reasons = F(t.value);
|
|
671
|
+
return;
|
|
672
|
+
case 162:
|
|
673
|
+
if (n.crlIssuer !== void 0) throw Error("DistributionPoint crlIssuer must not repeat");
|
|
674
|
+
n.crlIssuer = parseGeneralNames(e, t);
|
|
675
|
+
return;
|
|
676
|
+
default: throw Error(`Unsupported DistributionPoint field tag: ${String(t.tag)}`);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
740
679
|
/** Decodes a GeneralName from its context-tagged ASN.1 element. */
|
|
741
|
-
function parseGeneralName(
|
|
742
|
-
switch (
|
|
680
|
+
function parseGeneralName(e) {
|
|
681
|
+
switch (e.tag) {
|
|
743
682
|
case 129: return {
|
|
744
683
|
type: "email",
|
|
745
|
-
value:
|
|
684
|
+
value: Q.decode(e.value)
|
|
746
685
|
};
|
|
747
686
|
case 130: return {
|
|
748
687
|
type: "dns",
|
|
749
|
-
value:
|
|
688
|
+
value: Q.decode(e.value)
|
|
750
689
|
};
|
|
751
690
|
case 134: return {
|
|
752
691
|
type: "uri",
|
|
753
|
-
value:
|
|
692
|
+
value: Q.decode(e.value)
|
|
754
693
|
};
|
|
755
694
|
case 135: return {
|
|
756
695
|
type: "ip",
|
|
757
|
-
value:
|
|
696
|
+
value: N(e.value)
|
|
758
697
|
};
|
|
759
698
|
case 164: return {
|
|
760
699
|
type: "directoryName",
|
|
761
|
-
derHex:
|
|
700
|
+
derHex: C(rebuildDirectoryNameFromImplicit(e))
|
|
762
701
|
};
|
|
763
702
|
default: return {
|
|
764
703
|
type: "unknown",
|
|
765
|
-
tag:
|
|
766
|
-
value: new Uint8Array(
|
|
704
|
+
tag: e.tag,
|
|
705
|
+
value: new Uint8Array(e.value)
|
|
767
706
|
};
|
|
768
707
|
}
|
|
769
708
|
}
|
|
770
|
-
function parseGeneralNames(
|
|
771
|
-
|
|
772
|
-
if (
|
|
773
|
-
for (
|
|
774
|
-
return
|
|
709
|
+
function parseGeneralNames(e, t) {
|
|
710
|
+
let n = m(e, t);
|
|
711
|
+
if (n.length === 0) throw Error("GeneralNames must not be empty");
|
|
712
|
+
for (let e of n) if ((e.tag & 192) != 128) throw Error("GeneralNames must contain GeneralName entries");
|
|
713
|
+
return n.map((e) => parseGeneralName(e));
|
|
775
714
|
}
|
|
776
715
|
/** Decodes a RelativeDistinguishedName SET from an implicitly-tagged context element. */
|
|
777
|
-
function parseRelativeName(
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
const fieldKey = nameFieldKeyFromOid(oid);
|
|
785
|
-
const fieldValue = decodeNameValue(valueElement);
|
|
786
|
-
const attribute = fieldKey === void 0 ? {
|
|
787
|
-
oid,
|
|
788
|
-
valueTag: valueElement.tag,
|
|
789
|
-
value: fieldValue
|
|
716
|
+
function parseRelativeName(e, t) {
|
|
717
|
+
let n = [], r = {};
|
|
718
|
+
for (let i of m(e, t)) {
|
|
719
|
+
let t = m(e, i), a = _(S(t[0], "name OID").value), o = S(t[1], "name value"), s = I(a), c = decodeNameValue(o), l = s === void 0 ? {
|
|
720
|
+
oid: a,
|
|
721
|
+
valueTag: o.tag,
|
|
722
|
+
value: c
|
|
790
723
|
} : {
|
|
791
|
-
oid,
|
|
792
|
-
key:
|
|
793
|
-
valueTag:
|
|
794
|
-
value:
|
|
724
|
+
oid: a,
|
|
725
|
+
key: s,
|
|
726
|
+
valueTag: o.tag,
|
|
727
|
+
value: c
|
|
795
728
|
};
|
|
796
|
-
|
|
797
|
-
if (fieldKey !== void 0 && values[fieldKey] === void 0) values[fieldKey] = fieldValue;
|
|
729
|
+
n.push(l), s !== void 0 && r[s] === void 0 && (r[s] = c);
|
|
798
730
|
}
|
|
799
731
|
return {
|
|
800
|
-
derHex:
|
|
801
|
-
attributes,
|
|
802
|
-
values
|
|
732
|
+
derHex: C(e.slice(t.start - t.headerLength, t.end)),
|
|
733
|
+
attributes: n,
|
|
734
|
+
values: r
|
|
803
735
|
};
|
|
804
736
|
}
|
|
805
737
|
/** Decodes an ASN.1 string element (UTF8String, PrintableString, etc.) to a JS string. */
|
|
806
|
-
function decodeNameValue(
|
|
807
|
-
return
|
|
738
|
+
function decodeNameValue(e) {
|
|
739
|
+
return v(e.tag, e.value);
|
|
808
740
|
}
|
|
809
741
|
/** Reads an implicitly-tagged BOOLEAN from a context element. Absent content → `false`. */
|
|
810
|
-
function parseImplicitBoolean(
|
|
811
|
-
return (
|
|
742
|
+
function parseImplicitBoolean(e) {
|
|
743
|
+
return (e.value[0] ?? 0) !== 0;
|
|
812
744
|
}
|
|
813
745
|
/** DER-encodes an IssuingDistributionPoint extension value. Throws on mutually-exclusive scope flags. */
|
|
814
|
-
function encodeIssuingDistributionPoint(
|
|
746
|
+
function encodeIssuingDistributionPoint(e) {
|
|
815
747
|
if ([
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
].filter(Boolean).length > 1) throw
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
if (value.onlyContainsUserCerts) fields.push(implicitPrimitiveContext(1, Uint8Array.of(255)));
|
|
823
|
-
if (value.onlyContainsCACerts) fields.push(implicitPrimitiveContext(2, Uint8Array.of(255)));
|
|
824
|
-
if (value.onlySomeReasons !== void 0 && value.onlySomeReasons.length > 0) fields.push(implicitPrimitiveContext(3, encodeDistributionPointReasonFlagsContent(value.onlySomeReasons)));
|
|
825
|
-
if (value.indirectCrl) fields.push(implicitPrimitiveContext(4, Uint8Array.of(255)));
|
|
826
|
-
if (value.onlyContainsAttributeCerts) fields.push(implicitPrimitiveContext(5, Uint8Array.of(255)));
|
|
827
|
-
return sequence(fields);
|
|
748
|
+
e.onlyContainsUserCerts === !0,
|
|
749
|
+
e.onlyContainsCACerts === !0,
|
|
750
|
+
e.onlyContainsAttributeCerts === !0
|
|
751
|
+
].filter(Boolean).length > 1) throw Error("IssuingDistributionPoint can assert at most one of user, CA, or attribute cert scope");
|
|
752
|
+
let t = [];
|
|
753
|
+
return e.distributionPoint !== void 0 && t.push(i(0, encodeDistributionPointName(e.distributionPoint))), e.onlyContainsUserCerts && t.push(a(1, Uint8Array.of(255))), e.onlyContainsCACerts && t.push(a(2, Uint8Array.of(255))), e.onlySomeReasons !== void 0 && e.onlySomeReasons.length > 0 && t.push(a(3, P(e.onlySomeReasons))), e.indirectCrl && t.push(a(4, Uint8Array.of(255))), e.onlyContainsAttributeCerts && t.push(a(5, Uint8Array.of(255))), d(t);
|
|
828
754
|
}
|
|
829
755
|
/** DER-encodes a DistributionPointName (fullName or relativeName). */
|
|
830
|
-
function encodeDistributionPointName(
|
|
831
|
-
if (
|
|
832
|
-
if (
|
|
833
|
-
if (
|
|
834
|
-
if (
|
|
835
|
-
return
|
|
756
|
+
function encodeDistributionPointName(e) {
|
|
757
|
+
if (e === void 0) throw Error("IssuingDistributionPoint distributionPoint is required");
|
|
758
|
+
if (e.fullName !== void 0 && e.relativeName !== void 0) throw Error("DistributionPointName cannot contain both fullName and relativeName");
|
|
759
|
+
if (e.fullName !== void 0) {
|
|
760
|
+
if (e.fullName.length === 0) throw Error("DistributionPointName fullName must not be empty");
|
|
761
|
+
return i(0, concatGeneralNames(e.fullName));
|
|
836
762
|
}
|
|
837
|
-
if (
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
return implicitConstructedContext(1, relativeName.slice(relativeNameElement.start, relativeNameElement.end));
|
|
763
|
+
if (e.relativeName !== void 0) {
|
|
764
|
+
let t = R(e.relativeName), n = c(t);
|
|
765
|
+
return i(1, t.slice(n.start, n.end));
|
|
841
766
|
}
|
|
842
|
-
throw
|
|
767
|
+
throw Error("DistributionPointName must contain fullName or relativeName");
|
|
843
768
|
}
|
|
844
769
|
/** DER-encodes and concatenates a list of GeneralName values. */
|
|
845
|
-
function concatGeneralNames(
|
|
846
|
-
return
|
|
770
|
+
function concatGeneralNames(e) {
|
|
771
|
+
return t(e.map((e) => H(e)));
|
|
847
772
|
}
|
|
848
773
|
/** Re-wraps an implicitly-tagged directoryName as an explicit SEQUENCE (tag 0x30). */
|
|
849
774
|
/**
|
|
@@ -853,147 +778,130 @@ function concatGeneralNames(names) {
|
|
|
853
778
|
* - Proper implicit: [4] replaces SEQUENCE tag, content is RDN SETs directly → wrap with 0x30
|
|
854
779
|
* - Explicit-like: [4] wraps entire SEQUENCE, content starts with 0x30 → return content as-is
|
|
855
780
|
*/
|
|
856
|
-
function rebuildDirectoryNameFromImplicit(
|
|
857
|
-
|
|
858
|
-
return tlv(48, element.value);
|
|
781
|
+
function rebuildDirectoryNameFromImplicit(e) {
|
|
782
|
+
return e.value.length > 0 && e.value[0] === 48 ? new Uint8Array(e.value) : p(48, e.value);
|
|
859
783
|
}
|
|
860
784
|
/** Parses a Name SEQUENCE element into a full {@linkcode ParsedName}. */
|
|
861
|
-
function parseIssuer(
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
const rdnAttributes = [];
|
|
868
|
-
const rdnValues = {};
|
|
869
|
-
for (const attrSequence of childrenOf(source, setElement)) {
|
|
870
|
-
const parts = childrenOf(source, attrSequence);
|
|
871
|
-
const oidElement = requireElement(parts[0], "issuer attribute OID");
|
|
872
|
-
const valueElement = requireElement(parts[1], "issuer attribute value");
|
|
873
|
-
const oid = decodeObjectIdentifier(oidElement.value);
|
|
874
|
-
let fieldValue;
|
|
785
|
+
function parseIssuer(e, t) {
|
|
786
|
+
let n = C(e.slice(t.start - t.headerLength, t.end)), r = [], i = [], a = {};
|
|
787
|
+
for (let n of m(e, t)) {
|
|
788
|
+
let t = [], o = {};
|
|
789
|
+
for (let r of m(e, n)) {
|
|
790
|
+
let n = m(e, r), s = S(n[0], "issuer attribute OID"), c = S(n[1], "issuer attribute value"), l = _(s.value), u;
|
|
875
791
|
try {
|
|
876
|
-
|
|
792
|
+
u = v(c.tag, c.value);
|
|
877
793
|
} catch {
|
|
878
|
-
|
|
794
|
+
u = Q.decode(c.value);
|
|
879
795
|
}
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
valueTag: valueElement.tag,
|
|
885
|
-
value: fieldValue
|
|
796
|
+
let d = I(l), f = d === void 0 ? {
|
|
797
|
+
oid: l,
|
|
798
|
+
valueTag: c.tag,
|
|
799
|
+
value: u
|
|
886
800
|
} : {
|
|
887
|
-
oid,
|
|
888
|
-
|
|
889
|
-
|
|
801
|
+
oid: l,
|
|
802
|
+
key: d,
|
|
803
|
+
valueTag: c.tag,
|
|
804
|
+
value: u
|
|
890
805
|
};
|
|
891
|
-
|
|
892
|
-
allAttributes.push(attribute);
|
|
893
|
-
if (fieldKey !== void 0) {
|
|
894
|
-
if (rdnValues[fieldKey] === void 0) rdnValues[fieldKey] = fieldValue;
|
|
895
|
-
if (values[fieldKey] === void 0) values[fieldKey] = fieldValue;
|
|
896
|
-
}
|
|
806
|
+
t.push(f), i.push(f), d !== void 0 && (o[d] === void 0 && (o[d] = u), a[d] === void 0 && (a[d] = u));
|
|
897
807
|
}
|
|
898
|
-
|
|
899
|
-
derHex:
|
|
900
|
-
attributes:
|
|
901
|
-
values:
|
|
808
|
+
r.push({
|
|
809
|
+
derHex: C(e.slice(n.start - n.headerLength, n.end)),
|
|
810
|
+
attributes: t,
|
|
811
|
+
values: o
|
|
902
812
|
});
|
|
903
813
|
}
|
|
904
814
|
return {
|
|
905
|
-
derHex,
|
|
906
|
-
rdns,
|
|
907
|
-
attributes:
|
|
908
|
-
values
|
|
815
|
+
derHex: n,
|
|
816
|
+
rdns: r,
|
|
817
|
+
attributes: i,
|
|
818
|
+
values: a
|
|
909
819
|
};
|
|
910
820
|
}
|
|
911
821
|
/** Re-parses a hex-encoded DER Name into a {@linkcode ParsedName}. Returns `undefined` on malformed input. */
|
|
912
|
-
function parseDerHexName(
|
|
822
|
+
function parseDerHexName(e) {
|
|
913
823
|
try {
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
if (element.tag !== 48) return;
|
|
917
|
-
return parseIssuer(bytes, element);
|
|
824
|
+
let t = b(e), n = unwrapNameElement(t, l(t, { maxDepth: 64 }));
|
|
825
|
+
return n.tag === 48 ? parseIssuer(t, n) : void 0;
|
|
918
826
|
} catch {
|
|
919
827
|
return;
|
|
920
828
|
}
|
|
921
829
|
}
|
|
922
|
-
function unwrapNameElement(
|
|
923
|
-
if (
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
if (children.length === 1 && child?.tag === 48) return child;
|
|
927
|
-
return element;
|
|
830
|
+
function unwrapNameElement(e, t) {
|
|
831
|
+
if (t.tag !== 48) return t;
|
|
832
|
+
let n = m(e, t), r = n[0];
|
|
833
|
+
return n.length === 1 && r?.tag === 48 ? r : t;
|
|
928
834
|
}
|
|
929
835
|
/** Semantic comparison of a GeneralName directoryName `derHex` against a {@linkcode ParsedName}. */
|
|
930
|
-
function directoryNameDerHexMatchesParsedName(
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
return compareDistinguishedNames(parsed, name);
|
|
836
|
+
function directoryNameDerHexMatchesParsedName(e, t) {
|
|
837
|
+
let n = parseDerHexName(e);
|
|
838
|
+
return n !== void 0 && Y(n, t);
|
|
934
839
|
}
|
|
935
840
|
/** Extracts the keyIdentifier field from an AuthorityKeyIdentifier extension value. */
|
|
936
|
-
function parseAuthorityKeyIdentifier(
|
|
937
|
-
|
|
841
|
+
function parseAuthorityKeyIdentifier(e) {
|
|
842
|
+
let t = l(e, {
|
|
938
843
|
maxDepth: 64,
|
|
939
844
|
allowOpaqueConstructedTags: [161, 162]
|
|
940
845
|
});
|
|
941
|
-
if (
|
|
942
|
-
let
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
}
|
|
962
|
-
if (child.tag === 130) {
|
|
963
|
-
if (sawAuthorityCertSerialNumber) throw new Error("authorityKeyIdentifier authorityCertSerialNumber must not repeat");
|
|
964
|
-
if (lastFieldOrder >= 2 || !sawAuthorityCertIssuer) throw new Error("authorityKeyIdentifier fields must preserve DER order");
|
|
965
|
-
validateImplicitSerialNumberEncoding(child.value, "authorityKeyIdentifier authorityCertSerialNumber");
|
|
966
|
-
sawAuthorityCertSerialNumber = true;
|
|
967
|
-
lastFieldOrder = 2;
|
|
968
|
-
continue;
|
|
969
|
-
}
|
|
970
|
-
throw new Error(`Unsupported authorityKeyIdentifier field tag: ${String(child.tag)}`);
|
|
846
|
+
if (t.tag !== 48) throw Error("authorityKeyIdentifier must use SEQUENCE");
|
|
847
|
+
let n = {
|
|
848
|
+
sawAuthorityCertIssuer: !1,
|
|
849
|
+
sawAuthorityCertSerialNumber: !1,
|
|
850
|
+
lastFieldOrder: -1
|
|
851
|
+
};
|
|
852
|
+
for (let r of m(e, t)) parseAuthorityKeyIdentifierField(e, r, n);
|
|
853
|
+
return n.keyIdentifier;
|
|
854
|
+
}
|
|
855
|
+
function parseAuthorityKeyIdentifierField(e, t, n) {
|
|
856
|
+
switch (t.tag) {
|
|
857
|
+
case 128:
|
|
858
|
+
parseAuthorityKeyIdentifierKeyId(t, n);
|
|
859
|
+
return;
|
|
860
|
+
case 161:
|
|
861
|
+
parseAuthorityKeyIdentifierIssuer(e, t, n);
|
|
862
|
+
return;
|
|
863
|
+
case 130:
|
|
864
|
+
parseAuthorityKeyIdentifierSerial(t, n);
|
|
865
|
+
return;
|
|
866
|
+
default: throw Error(`Unsupported authorityKeyIdentifier field tag: ${String(t.tag)}`);
|
|
971
867
|
}
|
|
972
|
-
return keyIdentifier;
|
|
973
868
|
}
|
|
974
|
-
function
|
|
975
|
-
|
|
976
|
-
if (
|
|
977
|
-
|
|
978
|
-
|
|
869
|
+
function parseAuthorityKeyIdentifierKeyId(e, t) {
|
|
870
|
+
if (t.keyIdentifier !== void 0) throw Error("authorityKeyIdentifier keyIdentifier must not repeat");
|
|
871
|
+
if (t.lastFieldOrder >= 0) throw Error("authorityKeyIdentifier fields must preserve DER order");
|
|
872
|
+
t.keyIdentifier = C(e.value), t.lastFieldOrder = 0;
|
|
873
|
+
}
|
|
874
|
+
function parseAuthorityKeyIdentifierIssuer(e, t, n) {
|
|
875
|
+
if (n.sawAuthorityCertIssuer) throw Error("authorityKeyIdentifier authorityCertIssuer must not repeat");
|
|
876
|
+
if (n.lastFieldOrder >= 1) throw Error("authorityKeyIdentifier fields must preserve DER order");
|
|
877
|
+
parseGeneralNames(e, t), n.sawAuthorityCertIssuer = !0, n.lastFieldOrder = 1;
|
|
878
|
+
}
|
|
879
|
+
function parseAuthorityKeyIdentifierSerial(e, t) {
|
|
880
|
+
if (t.sawAuthorityCertSerialNumber) throw Error("authorityKeyIdentifier authorityCertSerialNumber must not repeat");
|
|
881
|
+
if (t.lastFieldOrder >= 2 || !t.sawAuthorityCertIssuer) throw Error("authorityKeyIdentifier fields must preserve DER order");
|
|
882
|
+
validateImplicitSerialNumberEncoding(e.value, "authorityKeyIdentifier authorityCertSerialNumber"), t.sawAuthorityCertSerialNumber = !0, t.lastFieldOrder = 2;
|
|
883
|
+
}
|
|
884
|
+
function validateImplicitSerialNumberEncoding(e, t) {
|
|
885
|
+
let n = e[0];
|
|
886
|
+
if (n === void 0) throw Error(`${t} must not be empty`);
|
|
887
|
+
if (n & 128) throw Error(`${t} must be non-negative`);
|
|
888
|
+
if (e.length > 1 && n === 0 && !((e[1] ?? 0) & 128)) throw Error(`${t} must use minimal encoding`);
|
|
979
889
|
}
|
|
980
890
|
/** Extracts the algorithm OID from an AlgorithmIdentifier SEQUENCE. */
|
|
981
|
-
function parseAlgorithmIdentifier(
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
oid: decodeObjectIdentifier(oid.value),
|
|
987
|
-
parametersDer: source.slice(parameters.start - parameters.headerLength, parameters.end)
|
|
891
|
+
function parseAlgorithmIdentifier(e, t) {
|
|
892
|
+
let n = m(e, t), r = S(n[0], "algorithm OID"), i = n[1];
|
|
893
|
+
return i === void 0 ? { oid: _(r.value) } : {
|
|
894
|
+
oid: _(r.value),
|
|
895
|
+
parametersDer: e.slice(i.start - i.headerLength, i.end)
|
|
988
896
|
};
|
|
989
897
|
}
|
|
990
898
|
/** Lowercases a hex string for bytewise serial-number comparison. */
|
|
991
|
-
function normalizeHex(
|
|
992
|
-
return
|
|
899
|
+
function normalizeHex(e) {
|
|
900
|
+
return e.toLowerCase();
|
|
993
901
|
}
|
|
994
902
|
/** Maps an integer CRLReason code back to its {@linkcode RevocationReason} string, or `undefined` for unknown codes. */
|
|
995
|
-
function revocationReasonFromCode(
|
|
996
|
-
switch (
|
|
903
|
+
function revocationReasonFromCode(e) {
|
|
904
|
+
switch (e) {
|
|
997
905
|
case 0: return "unspecified";
|
|
998
906
|
case 1: return "keyCompromise";
|
|
999
907
|
case 2: return "cACompromise";
|
|
@@ -1007,113 +915,113 @@ function revocationReasonFromCode(code) {
|
|
|
1007
915
|
}
|
|
1008
916
|
}
|
|
1009
917
|
/** Thin wrapper — parses a DER-encoded certificate for use as a CRL issuer. */
|
|
1010
|
-
function parseIssuerCertificateDer(
|
|
1011
|
-
return
|
|
918
|
+
function parseIssuerCertificateDer(e) {
|
|
919
|
+
return W(e);
|
|
1012
920
|
}
|
|
1013
921
|
/** Thin wrapper — parses a PEM-encoded certificate for use as a CRL issuer. */
|
|
1014
|
-
function parseIssuerCertificatePem(
|
|
1015
|
-
return
|
|
922
|
+
function parseIssuerCertificatePem(e) {
|
|
923
|
+
return W(e);
|
|
1016
924
|
}
|
|
1017
925
|
/** Accepts PEM, DER, or already-parsed CRL and returns a parsed CRL. */
|
|
1018
|
-
function normalizeCrl(
|
|
1019
|
-
if (typeof
|
|
1020
|
-
if (
|
|
1021
|
-
if (hasReparseableCrlShape(
|
|
1022
|
-
throw
|
|
1023
|
-
}
|
|
1024
|
-
function parseSignedCrlFields(
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
let
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
version
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
let
|
|
1066
|
-
|
|
1067
|
-
let
|
|
1068
|
-
let issuingDistributionPoint;
|
|
1069
|
-
let freshestCrlDistributionPoints;
|
|
1070
|
-
const maybeExtensions = tbsChildren[cursor];
|
|
1071
|
-
if (maybeExtensions?.tag === 160) {
|
|
1072
|
-
if (version !== 2) throw new Error("CRL extensions require version 2");
|
|
1073
|
-
const seenOids = /* @__PURE__ */ new Set();
|
|
1074
|
-
const extensionSequence = requireElement(childrenOf(tbsCertListDer, maybeExtensions)[0], "crl extensions");
|
|
1075
|
-
for (const extension of childrenOf(tbsCertListDer, extensionSequence)) {
|
|
1076
|
-
const parts = childrenOf(tbsCertListDer, extension);
|
|
1077
|
-
if (parts.length < 2 || parts.length > 3) throw new Error("Malformed CRL extension");
|
|
1078
|
-
if (parts.length === 3 && parts[1]?.tag !== 1) throw new Error("Malformed CRL extension");
|
|
1079
|
-
const oid = decodeObjectIdentifier(requireElement(parts[0], "extension OID").value);
|
|
1080
|
-
if (seenOids.has(oid)) throw new Error(`Duplicate CRL extension OID: ${oid}`);
|
|
1081
|
-
seenOids.add(oid);
|
|
1082
|
-
const critical = parts.length === 3 ? decodeBoolean(requireElement(parts[1], "extension critical").value) : false;
|
|
1083
|
-
const valueElement = requireElement(parts[parts.length - 1], "extension value");
|
|
1084
|
-
if (valueElement.tag !== 4) throw new Error("CRL extension value must use OCTET STRING");
|
|
1085
|
-
if (oid !== OIDS.authorityKeyIdentifier && oid !== OIDS.cRLNumber && oid !== OIDS.deltaCRLIndicator && oid !== OIDS.issuingDistributionPoint && oid !== OIDS.freshestCRL && critical) throw new Error(`Unsupported critical CRL extension OID: ${oid}`);
|
|
1086
|
-
if (oid === OIDS.authorityKeyIdentifier) authorityKeyIdentifier = parseAuthorityKeyIdentifier(valueElement.value);
|
|
1087
|
-
if (oid === OIDS.cRLNumber) crlNumber = decodeIntegerNumber(readElement(valueElement.value).value);
|
|
1088
|
-
if (oid === OIDS.deltaCRLIndicator) baseCrlNumber = decodeIntegerNumber(readElement(valueElement.value).value);
|
|
1089
|
-
if (oid === OIDS.issuingDistributionPoint) issuingDistributionPoint = parseIssuingDistributionPoint(valueElement.value);
|
|
1090
|
-
if (oid === OIDS.freshestCRL) freshestCrlDistributionPoints = parseDistributionPoints(valueElement.value);
|
|
1091
|
-
}
|
|
1092
|
-
}
|
|
926
|
+
function normalizeCrl(e) {
|
|
927
|
+
if (typeof e == "string") return parseCertificateRevocationListPemOrThrow(e);
|
|
928
|
+
if (e instanceof Uint8Array) return parseCertificateRevocationListDerOrThrow(new Uint8Array(e));
|
|
929
|
+
if (hasReparseableCrlShape(e)) return parseCertificateRevocationListDerOrThrow(new Uint8Array(e.der));
|
|
930
|
+
throw Error("certificate revocation list input is malformed");
|
|
931
|
+
}
|
|
932
|
+
function parseSignedCrlFields(e) {
|
|
933
|
+
let t = m(e, l(e, { maxDepth: 64 })), n = parseCrlVersionField(t), r = n.version, i = n.nextIndex;
|
|
934
|
+
i += 1;
|
|
935
|
+
let a = S(t[i], "issuer"), o = S(t[i + 1], "thisUpdate"), s = i + 2, c = t[s], u = c !== void 0 && (c.tag === 23 || c.tag === 24) ? x(c) : void 0;
|
|
936
|
+
u !== void 0 && (s += 1);
|
|
937
|
+
let d = t[s], f = d?.tag === 48 ? parseRevokedCertificates(e, d, r) : [];
|
|
938
|
+
d?.tag === 48 && (s += 1);
|
|
939
|
+
let p = t[s], h = parseCrlExtensionFields(e, p, r);
|
|
940
|
+
return {
|
|
941
|
+
version: r,
|
|
942
|
+
issuer: parseIssuer(e, a),
|
|
943
|
+
thisUpdate: x(o),
|
|
944
|
+
...u === void 0 ? {} : { nextUpdate: u },
|
|
945
|
+
...h.authorityKeyIdentifier === void 0 ? {} : { authorityKeyIdentifier: h.authorityKeyIdentifier },
|
|
946
|
+
...h.crlNumber === void 0 ? {} : { crlNumber: h.crlNumber },
|
|
947
|
+
...h.baseCrlNumber === void 0 ? {} : { baseCrlNumber: h.baseCrlNumber },
|
|
948
|
+
...h.issuingDistributionPoint === void 0 ? {} : { issuingDistributionPoint: h.issuingDistributionPoint },
|
|
949
|
+
...h.freshestCrlDistributionPoints === void 0 ? {} : { freshestCrlDistributionPoints: h.freshestCrlDistributionPoints },
|
|
950
|
+
revokedCertificates: f
|
|
951
|
+
};
|
|
952
|
+
}
|
|
953
|
+
function parseCrlVersionField(e) {
|
|
954
|
+
let t = e[0];
|
|
955
|
+
if (t !== void 0 && t.tag !== 2 && t.tag !== 48) throw Error("version must use INTEGER");
|
|
956
|
+
if (t?.tag !== 2) return {
|
|
957
|
+
version: 1,
|
|
958
|
+
nextIndex: 0
|
|
959
|
+
};
|
|
960
|
+
let n = g(t.value) + 1;
|
|
961
|
+
if (n !== 2) throw Error(`Unsupported CRL version: ${String(n)}`);
|
|
962
|
+
return {
|
|
963
|
+
version: n,
|
|
964
|
+
nextIndex: 1
|
|
965
|
+
};
|
|
966
|
+
}
|
|
967
|
+
function parseRevokedCertificates(e, t, n) {
|
|
968
|
+
return m(e, t).map((t) => parseRevokedCertificateEntry(e, t, n));
|
|
969
|
+
}
|
|
970
|
+
function parseRevokedCertificateEntry(e, t, n) {
|
|
971
|
+
let r = e.slice(t.start - t.headerLength, t.end), i = u(r), a = S(i[0], "revoked serialNumber");
|
|
972
|
+
if (a.tag !== 2) throw Error("revoked serialNumber must use INTEGER");
|
|
973
|
+
let o = i[2];
|
|
974
|
+
if (o !== void 0 && n !== 2) throw Error("revoked certificate extensions require CRL version 2");
|
|
975
|
+
let s = parseRevokedCertificateExtensions(r, o);
|
|
1093
976
|
return {
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
...
|
|
1098
|
-
...
|
|
1099
|
-
...crlNumber === void 0 ? {} : { crlNumber },
|
|
1100
|
-
...baseCrlNumber === void 0 ? {} : { baseCrlNumber },
|
|
1101
|
-
...issuingDistributionPoint === void 0 ? {} : { issuingDistributionPoint },
|
|
1102
|
-
...freshestCrlDistributionPoints === void 0 ? {} : { freshestCrlDistributionPoints },
|
|
1103
|
-
revokedCertificates
|
|
977
|
+
serialNumberHex: C(a.value),
|
|
978
|
+
revocationDate: x(S(i[1], "revocationDate")),
|
|
979
|
+
...s.reasonCode === void 0 ? {} : { reasonCode: s.reasonCode },
|
|
980
|
+
...s.invalidityDate === void 0 ? {} : { invalidityDate: s.invalidityDate },
|
|
981
|
+
...s.certificateIssuer === void 0 ? {} : { certificateIssuer: s.certificateIssuer }
|
|
1104
982
|
};
|
|
1105
983
|
}
|
|
984
|
+
function parseCrlExtensionFields(e, t, n) {
|
|
985
|
+
if (t?.tag !== 160) return {};
|
|
986
|
+
if (n !== 2) throw Error("CRL extensions require version 2");
|
|
987
|
+
let r = {}, i = /* @__PURE__ */ new Set(), a = S(m(e, t)[0], "crl extensions");
|
|
988
|
+
for (let t of m(e, a)) parseCrlExtensionField(e, t, i, r);
|
|
989
|
+
return r;
|
|
990
|
+
}
|
|
991
|
+
function parseCrlExtensionField(e, t, n, r) {
|
|
992
|
+
let i = m(e, t);
|
|
993
|
+
if (i.length < 2 || i.length > 3 || i.length === 3 && i[1]?.tag !== 1) throw Error("Malformed CRL extension");
|
|
994
|
+
let a = _(S(i[0], "extension OID").value);
|
|
995
|
+
if (n.has(a)) throw Error(`Duplicate CRL extension OID: ${a}`);
|
|
996
|
+
n.add(a);
|
|
997
|
+
let o = i.length === 3 && h(S(i[1], "extension critical").value), s = S(i[i.length - 1], "extension value");
|
|
998
|
+
if (s.tag !== 4) throw Error("CRL extension value must use OCTET STRING");
|
|
999
|
+
if (!isSupportedCrlExtensionOid(a) && o) throw Error(`Unsupported critical CRL extension OID: ${a}`);
|
|
1000
|
+
applyParsedCrlExtensionField(a, s.value, r);
|
|
1001
|
+
}
|
|
1002
|
+
function isSupportedCrlExtensionOid(e) {
|
|
1003
|
+
return e === w.authorityKeyIdentifier || e === w.cRLNumber || e === w.deltaCRLIndicator || e === w.issuingDistributionPoint || e === w.freshestCRL;
|
|
1004
|
+
}
|
|
1005
|
+
function applyParsedCrlExtensionField(e, t, n) {
|
|
1006
|
+
if (e === w.authorityKeyIdentifier) {
|
|
1007
|
+
let e = parseAuthorityKeyIdentifier(t);
|
|
1008
|
+
e !== void 0 && (n.authorityKeyIdentifier = e);
|
|
1009
|
+
}
|
|
1010
|
+
e === w.cRLNumber && (n.crlNumber = g(c(t).value)), e === w.deltaCRLIndicator && (n.baseCrlNumber = g(c(t).value)), e === w.issuingDistributionPoint && (n.issuingDistributionPoint = parseIssuingDistributionPoint(t)), e === w.freshestCRL && (n.freshestCrlDistributionPoints = parseDistributionPoints(t));
|
|
1011
|
+
}
|
|
1106
1012
|
/** Accepts PEM, DER, or already-parsed certificate and returns a parsed certificate. */
|
|
1107
|
-
function normalizeCrlCertificate(
|
|
1108
|
-
return hasParsedCertificateShape(
|
|
1013
|
+
function normalizeCrlCertificate(e) {
|
|
1014
|
+
return hasParsedCertificateShape(e) ? U(new Uint8Array(e.der)) : W(e);
|
|
1109
1015
|
}
|
|
1110
|
-
function hasParsedCertificateShape(
|
|
1111
|
-
return typeof
|
|
1016
|
+
function hasParsedCertificateShape(e) {
|
|
1017
|
+
return typeof e != "string" && "subjectPublicKeyInfoDer" in e;
|
|
1112
1018
|
}
|
|
1113
|
-
function hasReparseableCrlShape(
|
|
1114
|
-
return "der" in
|
|
1019
|
+
function hasReparseableCrlShape(e) {
|
|
1020
|
+
return "der" in e && e.der instanceof Uint8Array;
|
|
1115
1021
|
}
|
|
1116
1022
|
/** Shared UTF-8 decoder instance. */
|
|
1117
|
-
const
|
|
1023
|
+
const Q = new TextDecoder();
|
|
1118
1024
|
//#endregion
|
|
1119
1025
|
export { checkCertificateRevocationAgainstCrl, createCertificateRevocationList, isCertificateRevoked, parseCertificateRevocationListDer, parseCertificateRevocationListDerOrThrow, parseCertificateRevocationListPem, parseCertificateRevocationListPemOrThrow, revocationReasonFromCode, validateCertificateRevocationList, verifyCertificateRevocationListSignature };
|
|
1026
|
+
|
|
1027
|
+
//# sourceMappingURL=crl.js.map
|