micro509 0.17.1 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +165 -6
- package/dist/crypto/crypto.d.ts +12 -4
- package/dist/crypto/crypto.js +30 -17
- package/dist/crypto/crypto.js.map +1 -1
- package/dist/crypto.d.ts +8 -2
- package/dist/der/der.d.ts +14 -4
- package/dist/der/der.js +19 -19
- package/dist/der/der.js.map +1 -1
- package/dist/der.d.ts +26 -2
- package/dist/der.js +4 -4
- package/dist/index.d.ts +84 -16
- package/dist/index.js +19 -19
- package/dist/internal/asn1/asn1.d.ts +1 -2
- package/dist/internal/asn1/asn1.js +10 -2
- package/dist/internal/asn1/asn1.js.map +1 -1
- package/dist/internal/asn1/ber.js.map +1 -1
- package/dist/internal/asn1/decode-refusal.js.map +1 -1
- package/dist/internal/asn1/der.d.ts +1 -2
- package/dist/internal/asn1/der.js.map +1 -1
- package/dist/internal/asn1/oids.js +71 -353
- package/dist/internal/asn1/oids.js.map +1 -1
- package/dist/internal/asn1/oids.json.js +357 -0
- package/dist/internal/asn1/oids.json.js.map +1 -0
- package/dist/internal/crypto/algorithm-names.js +1 -1
- package/dist/internal/crypto/algorithm-names.js.map +1 -1
- package/dist/internal/crypto/ecdsa.js.map +1 -1
- package/dist/internal/crypto/hash.js.map +1 -1
- package/dist/internal/crypto/pbes2.d.ts +1 -2
- package/dist/internal/crypto/pbes2.js +70 -70
- package/dist/internal/crypto/pbes2.js.map +1 -1
- package/dist/internal/crypto/prime-ec.js +37 -0
- package/dist/internal/crypto/prime-ec.js.map +1 -0
- package/dist/internal/crypto/rsa-pss.js +50 -50
- package/dist/internal/crypto/rsa-pss.js.map +1 -1
- package/dist/internal/crypto/sig-verify.d.ts +41 -2
- package/dist/internal/crypto/sig-verify.js +125 -38
- package/dist/internal/crypto/sig-verify.js.map +1 -1
- package/dist/internal/crypto/signing.d.ts +1 -2
- package/dist/internal/crypto/signing.js +26 -26
- package/dist/internal/crypto/signing.js.map +1 -1
- package/dist/internal/jose/base64url.js.map +1 -1
- package/dist/internal/jose/json-data.js +108 -0
- package/dist/internal/jose/json-data.js.map +1 -0
- package/dist/internal/jose/strict-json.d.ts +1 -2
- package/dist/internal/jose/strict-json.js.map +1 -1
- package/dist/internal/shared/base64.js.map +1 -1
- package/dist/internal/shared/dn.d.ts +1 -2
- package/dist/internal/shared/dn.js +1 -1
- package/dist/internal/shared/dn.js.map +1 -1
- package/dist/internal/shared/idna.js.map +1 -1
- package/dist/internal/shared/ip.d.ts +1 -2
- package/dist/internal/shared/ip.js.map +1 -1
- package/dist/internal/shared/mailbox.js.map +1 -1
- package/dist/internal/shared/punycode.js.map +1 -1
- package/dist/internal/shared/uri-host.js.map +1 -1
- package/dist/internal/verify/name-constraints-engine.js +64 -64
- package/dist/internal/verify/name-constraints-engine.js.map +1 -1
- package/dist/internal/verify/policy-engine.js +1 -1
- package/dist/internal/verify/policy-engine.js.map +1 -1
- package/dist/internal/verify/spki-distrust.js.map +1 -1
- package/dist/internal/verify/verify-path.d.ts +1 -2
- package/dist/internal/verify/verify-path.js +234 -128
- package/dist/internal/verify/verify-path.js.map +1 -1
- package/dist/internal/x509/directory-name.js +10 -10
- package/dist/internal/x509/directory-name.js.map +1 -1
- package/dist/internal/x509/extension-bits.js.map +1 -1
- package/dist/internal/x509/extension-errors.d.ts +1 -2
- package/dist/internal/x509/extension-errors.js.map +1 -1
- package/dist/internal/x509/extension-registry.js +18 -18
- package/dist/internal/x509/extension-registry.js.map +1 -1
- package/dist/internal/x509/general-name-profile.js +9 -9
- package/dist/internal/x509/general-name-profile.js.map +1 -1
- package/dist/internal/x509/general-name.js +32 -32
- package/dist/internal/x509/general-name.js.map +1 -1
- package/dist/internal/x509/name-fields.js +1 -1
- package/dist/internal/x509/name-fields.js.map +1 -1
- package/dist/internal/x509/or-address.js.map +1 -1
- package/dist/jose/base64url.d.ts +4 -0
- package/dist/jose/base64url.js +14 -0
- package/dist/jose/base64url.js.map +1 -0
- package/dist/jose/errors.d.ts +9 -3
- package/dist/jose/errors.js.map +1 -1
- package/dist/jose/jwe.d.ts +64 -0
- package/dist/jose/jwe.js +188 -0
- package/dist/jose/jwe.js.map +1 -0
- package/dist/jose/jwks.d.ts +38 -10
- package/dist/jose/jwks.js +156 -96
- package/dist/jose/jwks.js.map +1 -1
- package/dist/jose/jws.d.ts +8 -6
- package/dist/jose/jws.js +216 -170
- package/dist/jose/jws.js.map +1 -1
- package/dist/jose/jwt.d.ts +8 -2
- package/dist/jose/jwt.js +98 -98
- package/dist/jose/jwt.js.map +1 -1
- package/dist/jose/remote-jwks.d.ts +1 -2
- package/dist/jose/remote-jwks.js +106 -108
- package/dist/jose/remote-jwks.js.map +1 -1
- package/dist/jose.d.ts +15 -4
- package/dist/jose.js +7 -5
- package/dist/kdf/argon2-arithmetic.js.map +1 -1
- package/dist/kdf/argon2-core.js.map +1 -1
- package/dist/kdf/argon2-memory.js.map +1 -1
- package/dist/kdf/argon2-portable.js.map +1 -1
- package/dist/kdf/argon2.d.ts +7 -2
- package/dist/kdf/argon2.js.map +1 -1
- package/dist/kdf.d.ts +6 -0
- package/dist/keys/keys.d.ts +31 -6
- package/dist/keys/keys.js +315 -233
- package/dist/keys/keys.js.map +1 -1
- package/dist/keys.d.ts +11 -2
- package/dist/keys.js +2 -2
- package/dist/pem/pem.d.ts +1 -2
- package/dist/pem/pem.js +40 -25
- package/dist/pem/pem.js.map +1 -1
- package/dist/pem.d.ts +6 -0
- package/dist/pkcs/pfx.d.ts +2 -3
- package/dist/pkcs/pfx.js +142 -142
- package/dist/pkcs/pfx.js.map +1 -1
- package/dist/pkcs/pkcs12-mac.d.ts +1 -2
- package/dist/pkcs/pkcs12-mac.js +122 -122
- package/dist/pkcs/pkcs12-mac.js.map +1 -1
- package/dist/pkcs/pkcs7.d.ts +24 -3
- package/dist/pkcs/pkcs7.js +294 -256
- package/dist/pkcs/pkcs7.js.map +1 -1
- package/dist/pkcs.d.ts +10 -1
- package/dist/pkcs.js +4 -4
- package/dist/result/result.d.ts +1 -2
- package/dist/result/result.js.map +1 -1
- package/dist/result.d.ts +6 -0
- package/dist/revocation/chain.d.ts +69 -16
- package/dist/revocation/chain.js +431 -303
- package/dist/revocation/chain.js.map +1 -1
- package/dist/revocation/crl.d.ts +67 -14
- package/dist/revocation/crl.js +656 -366
- package/dist/revocation/crl.js.map +1 -1
- package/dist/revocation/ocsp.d.ts +78 -24
- package/dist/revocation/ocsp.js +622 -436
- package/dist/revocation/ocsp.js.map +1 -1
- package/dist/revocation/revocation.d.ts +68 -14
- package/dist/revocation/revocation.js +195 -74
- package/dist/revocation/revocation.js.map +1 -1
- package/dist/revocation.d.ts +14 -5
- package/dist/revocation.js +4 -4
- package/dist/ssh/ssh.d.ts +2 -3
- package/dist/ssh/ssh.js +165 -170
- package/dist/ssh/ssh.js.map +1 -1
- package/dist/ssh/wire.d.ts +1 -2
- package/dist/ssh/wire.js +10 -10
- package/dist/ssh/wire.js.map +1 -1
- package/dist/ssh.d.ts +8 -0
- package/dist/verify/identity.d.ts +3 -4
- package/dist/verify/identity.js +33 -33
- package/dist/verify/identity.js.map +1 -1
- package/dist/verify/name-constraints.d.ts +9 -2
- package/dist/verify/policy.d.ts +9 -2
- package/dist/verify/verify.d.ts +85 -34
- package/dist/verify/verify.js +276 -226
- package/dist/verify/verify.js.map +1 -1
- package/dist/verify.d.ts +12 -2
- package/dist/x509/certificate.d.ts +4 -5
- package/dist/x509/certificate.js +40 -40
- package/dist/x509/certificate.js.map +1 -1
- package/dist/x509/csr.d.ts +3 -4
- package/dist/x509/csr.js +15 -15
- package/dist/x509/csr.js.map +1 -1
- package/dist/x509/extensions.d.ts +1 -2
- package/dist/x509/extensions.js +165 -165
- package/dist/x509/extensions.js.map +1 -1
- package/dist/x509/fingerprint.d.ts +1 -2
- package/dist/x509/fingerprint.js.map +1 -1
- package/dist/x509/name-text.d.ts +1 -2
- package/dist/x509/name-text.js.map +1 -1
- package/dist/x509/name.d.ts +1 -2
- package/dist/x509/name.js +15 -15
- package/dist/x509/name.js.map +1 -1
- package/dist/x509/parse.d.ts +9 -6
- package/dist/x509/parse.js +394 -394
- package/dist/x509/parse.js.map +1 -1
- package/dist/x509.d.ts +17 -4
- package/dist/x509.js +8 -8
- package/package.json +32 -33
- package/dist/internal/asn1/oids2.js +0 -75
- package/dist/internal/asn1/oids2.js.map +0 -1
package/dist/x509/parse.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { decodeFailureResult as
|
|
3
|
-
import { optionalBytesEqual as
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import { parseAuthorityInfoAccessMethodOid as
|
|
14
|
-
import {
|
|
1
|
+
import { childrenOf as e, decodeBoolean as t, decodeIntegerNumber as n, decodeNonNegativeIntegerNumber as r, decodeObjectIdentifier as i, decodeString as a, decodeVisibleString as o, extractBitStringValue as s, parseTime as c, requireElement as l, signatureBits as u, toHex as d } from "../internal/asn1/asn1.js";
|
|
2
|
+
import { decodeFailureResult as f, decodeRefusalOf as p } from "../internal/asn1/decode-refusal.js";
|
|
3
|
+
import { optionalBytesEqual as m, readElement as h, readRootElement as g, readSequenceChildren as _ } from "../internal/asn1/der.js";
|
|
4
|
+
import { OIDS as v } from "../internal/asn1/oids.js";
|
|
5
|
+
import { describePublicKeyAlgorithm as y, describeSignatureAlgorithm as b } from "../internal/crypto/algorithm-names.js";
|
|
6
|
+
import { readDirectoryNameTlv as x } from "../internal/x509/directory-name.js";
|
|
7
|
+
import { parseDistributionPointReasonFlagsContent as S, parseKeyUsageExtension as C } from "../internal/x509/extension-bits.js";
|
|
8
|
+
import { decodeAndApplyKnownExtension as w } from "../internal/x509/extension-registry.js";
|
|
9
|
+
import { decodeSrvName as T, otherNameValueDer as E, parseGeneralName as D, parseGeneralNames as O, readOtherName as k } from "../internal/x509/general-name.js";
|
|
10
|
+
import { derivePublicKey as A, exportSpkiDer as j, importSpkiDer as M, importSpkiDerOrThrow as N } from "../keys/keys.js";
|
|
11
|
+
import { pemDecodeOrThrow as P, splitPemBlocksOrThrow as F } from "../pem/pem.js";
|
|
12
|
+
import { DECODE_REFUSAL_CODES as I, failureResult as L, rethrowIfInvariant as R, successResult as z } from "../result/result.js";
|
|
13
|
+
import { parseAuthorityInfoAccessMethodOid as B, parseExtendedKeyUsageOid as V } from "./extensions.js";
|
|
14
|
+
import { nameFieldKeyFromOid as H } from "../internal/x509/name-fields.js";
|
|
15
15
|
// src/x509/parse.ts
|
|
16
16
|
/**
|
|
17
17
|
* Certificate and CSR parse boundary.
|
|
@@ -53,29 +53,29 @@ function defineExtensionDecoderMap(e) {
|
|
|
53
53
|
* @param options Custom extension decoders to apply during parsing.
|
|
54
54
|
*/
|
|
55
55
|
function parseCertificateDerOrThrow(e, t) {
|
|
56
|
-
let n =
|
|
56
|
+
let n = _(e, { maxDepth: 64 });
|
|
57
57
|
if (n.length !== 3) throw Error("Malformed Certificate");
|
|
58
|
-
let r =
|
|
59
|
-
assertMatchingCertificateSignatureAlgorithms(
|
|
60
|
-
let
|
|
58
|
+
let r = l(n[0], "TBSCertificate"), i = l(n[1], "signatureAlgorithm"), a = l(n[2], "signatureValue"), o = parseTbsCertificateFields(e, r), s = parseExtensionContainer(e, o.extensions), c = parseValidity(e, o.validity), f = parseSubjectPublicKeyInfo(e, o.subjectPublicKeyInfo), p = parseAlgorithmIdentifier(e, o.tbsSignatureAlgorithm), m = parseAlgorithmIdentifier(e, i);
|
|
59
|
+
assertMatchingCertificateSignatureAlgorithms(p, m);
|
|
60
|
+
let h = parseCustomExtensions(s.all, t);
|
|
61
61
|
return {
|
|
62
62
|
der: new Uint8Array(e),
|
|
63
63
|
version: o.version,
|
|
64
|
-
serialNumberHex:
|
|
64
|
+
serialNumberHex: d(o.serialNumber.value),
|
|
65
65
|
tbsCertificateDer: e.slice(r.start - r.headerLength, r.end),
|
|
66
66
|
subjectPublicKeyInfoDer: e.slice(o.subjectPublicKeyInfo.start - o.subjectPublicKeyInfo.headerLength, o.subjectPublicKeyInfo.end),
|
|
67
|
-
|
|
67
|
+
...u(a),
|
|
68
68
|
issuer: parseName(e, o.issuer),
|
|
69
69
|
subject: parseName(e, o.subject),
|
|
70
70
|
notBefore: c.notBefore,
|
|
71
71
|
notAfter: c.notAfter,
|
|
72
|
-
signatureAlgorithmOid:
|
|
73
|
-
signatureAlgorithmName:
|
|
74
|
-
...
|
|
75
|
-
publicKeyAlgorithmOid:
|
|
76
|
-
publicKeyAlgorithmName:
|
|
77
|
-
...
|
|
78
|
-
...
|
|
72
|
+
signatureAlgorithmOid: m.oid,
|
|
73
|
+
signatureAlgorithmName: b(m.oid, m.parametersDer),
|
|
74
|
+
...m.parametersDer === void 0 ? {} : { signatureAlgorithmParametersDer: m.parametersDer },
|
|
75
|
+
publicKeyAlgorithmOid: f.oid,
|
|
76
|
+
publicKeyAlgorithmName: y(f.oid, f.parametersOid),
|
|
77
|
+
...f.parametersDer === void 0 ? {} : { publicKeyAlgorithmParametersDer: f.parametersDer },
|
|
78
|
+
...f.parametersOid === void 0 ? {} : { publicKeyParametersOid: f.parametersOid },
|
|
79
79
|
extensions: s.all,
|
|
80
80
|
...s.basicConstraints === void 0 ? {} : { basicConstraints: s.basicConstraints },
|
|
81
81
|
...s.keyUsage === void 0 ? {} : { keyUsage: s.keyUsage },
|
|
@@ -88,8 +88,8 @@ function parseCertificateDerOrThrow(e, t) {
|
|
|
88
88
|
...s.policyConstraints === void 0 ? {} : { policyConstraints: s.policyConstraints },
|
|
89
89
|
...s.inhibitAnyPolicy === void 0 ? {} : { inhibitAnyPolicy: s.inhibitAnyPolicy },
|
|
90
90
|
...accessExtensionFields(s),
|
|
91
|
-
...
|
|
92
|
-
...
|
|
91
|
+
...h.decodedExtensions === void 0 ? {} : { decodedExtensions: h.decodedExtensions },
|
|
92
|
+
...h.decodedExtensionMap === void 0 ? {} : { decodedExtensionMap: h.decodedExtensionMap },
|
|
93
93
|
...s.subjectKeyIdentifier === void 0 ? {} : { subjectKeyIdentifier: s.subjectKeyIdentifier },
|
|
94
94
|
...s.authorityKeyIdentifier === void 0 ? {} : { authorityKeyIdentifier: s.authorityKeyIdentifier }
|
|
95
95
|
};
|
|
@@ -105,33 +105,33 @@ function parseCustomExtensions(e, t) {
|
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
/** Extracts and validates the structural fields of a TBSCertificate sequence. */
|
|
108
|
-
function parseTbsCertificateFields(
|
|
109
|
-
let
|
|
110
|
-
if (
|
|
111
|
-
let
|
|
108
|
+
function parseTbsCertificateFields(t, n) {
|
|
109
|
+
let r = e(t, n), i = parseCertificateVersionField(t, r), a = i.version, o = i.nextIndex, s = l(r[o], "serialNumber");
|
|
110
|
+
if (s.tag !== 2) throw Error("serialNumber must use INTEGER");
|
|
111
|
+
let c = validateOptionalTbsCertificateFields(r, o + 6, a);
|
|
112
112
|
return {
|
|
113
|
-
version:
|
|
114
|
-
serialNumber:
|
|
115
|
-
tbsSignatureAlgorithm:
|
|
116
|
-
issuer:
|
|
117
|
-
validity:
|
|
118
|
-
subject:
|
|
119
|
-
subjectPublicKeyInfo:
|
|
120
|
-
...
|
|
113
|
+
version: a,
|
|
114
|
+
serialNumber: s,
|
|
115
|
+
tbsSignatureAlgorithm: l(r[o + 1], "TBSCertificate signature"),
|
|
116
|
+
issuer: l(r[o + 2], "issuer"),
|
|
117
|
+
validity: l(r[o + 3], "validity"),
|
|
118
|
+
subject: l(r[o + 4], "subject"),
|
|
119
|
+
subjectPublicKeyInfo: l(r[o + 5], "subjectPublicKeyInfo"),
|
|
120
|
+
...r[c - 1]?.tag === 163 ? { extensions: r[c - 1] } : {}
|
|
121
121
|
};
|
|
122
122
|
}
|
|
123
|
-
function parseCertificateVersionField(
|
|
124
|
-
let
|
|
125
|
-
if (
|
|
123
|
+
function parseCertificateVersionField(t, r) {
|
|
124
|
+
let i = r[0];
|
|
125
|
+
if (i?.tag !== 160) return {
|
|
126
126
|
version: 1,
|
|
127
127
|
nextIndex: 0
|
|
128
128
|
};
|
|
129
|
-
let
|
|
130
|
-
if (
|
|
131
|
-
let
|
|
132
|
-
if (
|
|
129
|
+
let a = e(t, i), o = l(a[0], "version INTEGER");
|
|
130
|
+
if (a.length !== 1 || o.tag !== 2) throw Error("version must use INTEGER");
|
|
131
|
+
let s = n(o.value) + 1;
|
|
132
|
+
if (s < 1 || s > 3) throw Error(`Unsupported certificate version: ${String(s)}`);
|
|
133
133
|
return {
|
|
134
|
-
version:
|
|
134
|
+
version: s,
|
|
135
135
|
nextIndex: 1
|
|
136
136
|
};
|
|
137
137
|
}
|
|
@@ -141,11 +141,11 @@ function validateOptionalTbsCertificateFields(e, t, n) {
|
|
|
141
141
|
if (n !== 3) throw Error("extensions require certificate version 3");
|
|
142
142
|
r += 1;
|
|
143
143
|
}
|
|
144
|
-
if (r !== e.length) throw Error(`Unsupported TBSCertificate field tag: ${String(
|
|
144
|
+
if (r !== e.length) throw Error(`Unsupported TBSCertificate field tag: ${String(l(e[r], "TBSCertificate field").tag)}`);
|
|
145
145
|
return r;
|
|
146
146
|
}
|
|
147
147
|
function validateCertificateUniqueId(e, t, n) {
|
|
148
|
-
let r =
|
|
148
|
+
let r = l(e, n);
|
|
149
149
|
if (t < 2) throw Error(`${n} requires certificate version 2 or 3`);
|
|
150
150
|
validateImplicitBitStringContent(r.value, n);
|
|
151
151
|
}
|
|
@@ -165,11 +165,11 @@ function validateCertificateUniqueId(e, t, n) {
|
|
|
165
165
|
* @param der Raw DER bytes of an X.509 certificate.
|
|
166
166
|
* @param options Custom extension decoders to apply during parsing.
|
|
167
167
|
*/
|
|
168
|
-
function parseCertificateDer(
|
|
168
|
+
function parseCertificateDer(e, t) {
|
|
169
169
|
try {
|
|
170
|
-
return
|
|
171
|
-
} catch (
|
|
172
|
-
return
|
|
170
|
+
return z(parseCertificateDerOrThrow(e, t));
|
|
171
|
+
} catch (e) {
|
|
172
|
+
return R(e), f(e, I, "Malformed certificate");
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
175
|
/**
|
|
@@ -191,7 +191,7 @@ function parseCertificateDer(t, a) {
|
|
|
191
191
|
* @param options Custom extension decoders to apply during parsing.
|
|
192
192
|
*/
|
|
193
193
|
function parseCertificatePemOrThrow(e, t) {
|
|
194
|
-
return parseCertificateDerOrThrow(
|
|
194
|
+
return parseCertificateDerOrThrow(P("CERTIFICATE", e), t);
|
|
195
195
|
}
|
|
196
196
|
/**
|
|
197
197
|
* Decode a PEM-encoded X.509 certificate into a {@linkcode ParsedCertificate}.
|
|
@@ -205,11 +205,11 @@ function parseCertificatePemOrThrow(e, t) {
|
|
|
205
205
|
* @param pem PEM string with a CERTIFICATE block.
|
|
206
206
|
* @param options Custom extension decoders to apply during parsing.
|
|
207
207
|
*/
|
|
208
|
-
function parseCertificatePem(
|
|
208
|
+
function parseCertificatePem(e, t) {
|
|
209
209
|
try {
|
|
210
|
-
return
|
|
211
|
-
} catch (
|
|
212
|
-
return
|
|
210
|
+
return z(parseCertificatePemOrThrow(e, t));
|
|
211
|
+
} catch (e) {
|
|
212
|
+
return R(e), f(e, I, "Malformed certificate");
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
215
|
/** Normalizes a PEM bundle or single DER certificate source into parsed certificates. */
|
|
@@ -240,11 +240,11 @@ function parseCertificateChainPemOrThrow(e, t) {
|
|
|
240
240
|
* @param pemBundle PEM text that may contain multiple CERTIFICATE blocks.
|
|
241
241
|
* @param options Custom extension decoders to apply during parsing.
|
|
242
242
|
*/
|
|
243
|
-
function parseCertificateChainPem(
|
|
243
|
+
function parseCertificateChainPem(e, t) {
|
|
244
244
|
try {
|
|
245
|
-
return
|
|
246
|
-
} catch (
|
|
247
|
-
return
|
|
245
|
+
return z(parseCertificateChainPemOrThrow(e, t));
|
|
246
|
+
} catch (e) {
|
|
247
|
+
return R(e), f(e, I, "Malformed certificate chain");
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
250
|
/**
|
|
@@ -254,20 +254,20 @@ function parseCertificateChainPem(t, a) {
|
|
|
254
254
|
* @param options Custom extension decoders to apply during parsing.
|
|
255
255
|
*/
|
|
256
256
|
function parseCertificateSigningRequestDerOrThrow(e, t) {
|
|
257
|
-
let n =
|
|
257
|
+
let n = _(e, { maxDepth: 64 });
|
|
258
258
|
if (n.length !== 3) throw Error("Malformed CertificationRequest");
|
|
259
|
-
let r =
|
|
259
|
+
let r = l(n[0], "CertificationRequestInfo"), i = l(n[1], "signatureAlgorithm"), a = l(n[2], "signatureValue"), o = parseCertificationRequestInfoFields(e, r), s = parseRequestedExtensions(e, o.attributes), c = parseSubjectPublicKeyInfo(e, o.subjectPublicKeyInfo), d = parseAlgorithmIdentifier(e, i), f = parseCustomExtensions(s.all, t);
|
|
260
260
|
return {
|
|
261
261
|
version: o.version,
|
|
262
262
|
certificationRequestInfoDer: e.slice(r.start - r.headerLength, r.end),
|
|
263
263
|
subjectPublicKeyInfoDer: e.slice(o.subjectPublicKeyInfo.start - o.subjectPublicKeyInfo.headerLength, o.subjectPublicKeyInfo.end),
|
|
264
|
-
|
|
264
|
+
...u(a),
|
|
265
265
|
subject: parseName(e, o.subject),
|
|
266
|
-
signatureAlgorithmOid:
|
|
267
|
-
signatureAlgorithmName:
|
|
268
|
-
...
|
|
266
|
+
signatureAlgorithmOid: d.oid,
|
|
267
|
+
signatureAlgorithmName: b(d.oid, d.parametersDer),
|
|
268
|
+
...d.parametersDer === void 0 ? {} : { signatureAlgorithmParametersDer: d.parametersDer },
|
|
269
269
|
publicKeyAlgorithmOid: c.oid,
|
|
270
|
-
publicKeyAlgorithmName:
|
|
270
|
+
publicKeyAlgorithmName: y(c.oid, c.parametersOid),
|
|
271
271
|
...c.parametersDer === void 0 ? {} : { publicKeyAlgorithmParametersDer: c.parametersDer },
|
|
272
272
|
...c.parametersOid === void 0 ? {} : { publicKeyParametersOid: c.parametersOid },
|
|
273
273
|
requestedExtensions: s.all,
|
|
@@ -281,24 +281,24 @@ function parseCertificateSigningRequestDerOrThrow(e, t) {
|
|
|
281
281
|
...s.policyConstraints === void 0 ? {} : { policyConstraints: s.policyConstraints },
|
|
282
282
|
...s.inhibitAnyPolicy === void 0 ? {} : { inhibitAnyPolicy: s.inhibitAnyPolicy },
|
|
283
283
|
...accessExtensionFields(s),
|
|
284
|
-
...
|
|
285
|
-
...
|
|
284
|
+
...f.decodedExtensions === void 0 ? {} : { decodedExtensions: f.decodedExtensions },
|
|
285
|
+
...f.decodedExtensionMap === void 0 ? {} : { decodedExtensionMap: f.decodedExtensionMap }
|
|
286
286
|
};
|
|
287
287
|
}
|
|
288
|
-
function parseCertificationRequestInfoFields(
|
|
289
|
-
let
|
|
290
|
-
if (
|
|
291
|
-
let
|
|
292
|
-
if (
|
|
293
|
-
let
|
|
294
|
-
if (
|
|
295
|
-
let
|
|
296
|
-
if (
|
|
288
|
+
function parseCertificationRequestInfoFields(t, r) {
|
|
289
|
+
let i = e(t, r);
|
|
290
|
+
if (i.length !== 4) throw Error("Malformed CertificationRequestInfo");
|
|
291
|
+
let a = l(i[0], "version");
|
|
292
|
+
if (a.tag !== 2) throw Error("version must use INTEGER");
|
|
293
|
+
let o = n(a.value) + 1;
|
|
294
|
+
if (o !== 1) throw Error(`Unsupported CertificationRequestInfo version: ${String(o)}`);
|
|
295
|
+
let s = l(i[3], "attributes");
|
|
296
|
+
if (s.tag !== 160) throw Error("CertificationRequestInfo attributes must use [0]");
|
|
297
297
|
return {
|
|
298
|
-
version:
|
|
299
|
-
subject:
|
|
300
|
-
subjectPublicKeyInfo:
|
|
301
|
-
attributes:
|
|
298
|
+
version: o,
|
|
299
|
+
subject: l(i[1], "subject"),
|
|
300
|
+
subjectPublicKeyInfo: l(i[2], "subjectPublicKeyInfo"),
|
|
301
|
+
attributes: s
|
|
302
302
|
};
|
|
303
303
|
}
|
|
304
304
|
/**
|
|
@@ -307,15 +307,15 @@ function parseCertificationRequestInfoFields(e, t) {
|
|
|
307
307
|
* @param der Raw DER bytes of a PKCS#10 certificate signing request.
|
|
308
308
|
* @param options Custom extension decoders to apply during parsing.
|
|
309
309
|
*/
|
|
310
|
-
function parseCertificateSigningRequestDer(
|
|
310
|
+
function parseCertificateSigningRequestDer(e, t) {
|
|
311
311
|
try {
|
|
312
|
-
return
|
|
313
|
-
} catch (
|
|
314
|
-
return
|
|
312
|
+
return z(parseCertificateSigningRequestDerOrThrow(e, t));
|
|
313
|
+
} catch (e) {
|
|
314
|
+
return R(e), f(e, I, "Malformed certificate signing request");
|
|
315
315
|
}
|
|
316
316
|
}
|
|
317
317
|
function parseCertificatesFromPemBlocks(e, t) {
|
|
318
|
-
return
|
|
318
|
+
return F(e).filter((e) => e.label === "CERTIFICATE").map((e) => parseCertificateDerOrThrow(e.bytes, t));
|
|
319
319
|
}
|
|
320
320
|
function hasParsedCertificateShape(e) {
|
|
321
321
|
return "subjectPublicKeyInfoDer" in e;
|
|
@@ -327,7 +327,7 @@ function hasParsedCertificateShape(e) {
|
|
|
327
327
|
* @param options Custom extension decoders to apply during parsing.
|
|
328
328
|
*/
|
|
329
329
|
function parseCertificateSigningRequestPemOrThrow(e, t) {
|
|
330
|
-
return parseCertificateSigningRequestDerOrThrow(
|
|
330
|
+
return parseCertificateSigningRequestDerOrThrow(P("CERTIFICATE REQUEST", e), t);
|
|
331
331
|
}
|
|
332
332
|
/**
|
|
333
333
|
* Decode a PEM-encoded PKCS#10 CSR into a {@linkcode ParsedCertificateSigningRequest}.
|
|
@@ -335,11 +335,11 @@ function parseCertificateSigningRequestPemOrThrow(e, t) {
|
|
|
335
335
|
* @param pem PEM string with a CERTIFICATE REQUEST block.
|
|
336
336
|
* @param options Custom extension decoders to apply during parsing.
|
|
337
337
|
*/
|
|
338
|
-
function parseCertificateSigningRequestPem(
|
|
338
|
+
function parseCertificateSigningRequestPem(e, t) {
|
|
339
339
|
try {
|
|
340
|
-
return
|
|
341
|
-
} catch (
|
|
342
|
-
return
|
|
340
|
+
return z(parseCertificateSigningRequestPemOrThrow(e, t));
|
|
341
|
+
} catch (e) {
|
|
342
|
+
return R(e), f(e, I, "Malformed certificate signing request");
|
|
343
343
|
}
|
|
344
344
|
}
|
|
345
345
|
/**
|
|
@@ -371,7 +371,7 @@ function parseCertificateSigningRequestPem(t, a) {
|
|
|
371
371
|
* @see {@linkcode getSubjectPublicKey} for the non-throwing variant
|
|
372
372
|
*/
|
|
373
373
|
function getSubjectPublicKeyOrThrow(e, t) {
|
|
374
|
-
return
|
|
374
|
+
return N(e.subjectPublicKeyInfoDer, t);
|
|
375
375
|
}
|
|
376
376
|
/**
|
|
377
377
|
* Import the subject public key of a parsed certificate or CSR as a WebCrypto `CryptoKey`.
|
|
@@ -379,11 +379,11 @@ function getSubjectPublicKeyOrThrow(e, t) {
|
|
|
379
379
|
* @see `getSubjectPublicKeyOrThrow` for the throwing variant
|
|
380
380
|
*/
|
|
381
381
|
function getSubjectPublicKey(e, t) {
|
|
382
|
-
return
|
|
382
|
+
return M(e.subjectPublicKeyInfoDer, t);
|
|
383
383
|
}
|
|
384
384
|
/** Extract the AlgorithmIdentifier TLV from a SubjectPublicKeyInfo DER buffer. */
|
|
385
385
|
function subjectPublicKeyInfoAlgorithmDer(e) {
|
|
386
|
-
let t =
|
|
386
|
+
let t = _(e, { maxDepth: 64 }), n = l(t[0], "SubjectPublicKeyInfo algorithm");
|
|
387
387
|
return e.slice(n.start - n.headerLength, n.end);
|
|
388
388
|
}
|
|
389
389
|
/**
|
|
@@ -396,8 +396,8 @@ function subjectPublicKeyInfoAlgorithmDer(e) {
|
|
|
396
396
|
* mismatch or a cross-algorithm (`key_type_mismatch`) one.
|
|
397
397
|
*/
|
|
398
398
|
async function compareCertificateToPrivateKey(e, t) {
|
|
399
|
-
let n = await
|
|
400
|
-
return
|
|
399
|
+
let n = await j(await A(t));
|
|
400
|
+
return m(n, e) ? "match" : m(subjectPublicKeyInfoAlgorithmDer(n), subjectPublicKeyInfoAlgorithmDer(e)) ? "key_mismatch" : "key_type_mismatch";
|
|
401
401
|
}
|
|
402
402
|
/**
|
|
403
403
|
* Check whether a certificate's subject public key belongs to a private key.
|
|
@@ -489,26 +489,26 @@ async function certificateMatchesPrivateKey(e, t) {
|
|
|
489
489
|
*
|
|
490
490
|
* @see {@linkcode certificateMatchesPrivateKey} for the plain-boolean variant
|
|
491
491
|
*/
|
|
492
|
-
async function matchCertificatePrivateKey(
|
|
493
|
-
let
|
|
492
|
+
async function matchCertificatePrivateKey(e, t) {
|
|
493
|
+
let n;
|
|
494
494
|
try {
|
|
495
|
-
|
|
496
|
-
} catch (
|
|
497
|
-
|
|
498
|
-
let
|
|
499
|
-
return
|
|
495
|
+
n = parseCertificateFromSource(e);
|
|
496
|
+
} catch (e) {
|
|
497
|
+
R(e);
|
|
498
|
+
let t = p(e, I);
|
|
499
|
+
return t === void 0 ? L("malformed_certificate", e instanceof Error ? e.message : "Malformed certificate") : L(t.code, t.message);
|
|
500
500
|
}
|
|
501
|
-
let
|
|
501
|
+
let r;
|
|
502
502
|
try {
|
|
503
|
-
|
|
503
|
+
r = await compareCertificateToPrivateKey(n.subjectPublicKeyInfoDer, t);
|
|
504
504
|
} catch (e) {
|
|
505
|
-
return
|
|
505
|
+
return R(e), L("unsupported_private_key", e instanceof Error ? e.message : "Unsupported private key");
|
|
506
506
|
}
|
|
507
|
-
switch (
|
|
508
|
-
case "match": return
|
|
509
|
-
case "key_mismatch": return
|
|
510
|
-
case "key_type_mismatch": return
|
|
511
|
-
default: throw Error(`Unhandled key comparison result: ${String(
|
|
507
|
+
switch (r) {
|
|
508
|
+
case "match": return z(void 0);
|
|
509
|
+
case "key_mismatch": return L("key_mismatch", "Private key does not match the certificate's subject public key");
|
|
510
|
+
case "key_type_mismatch": return L("key_type_mismatch", "Private key algorithm does not match the certificate's subject public key algorithm");
|
|
511
|
+
default: throw Error(`Unhandled key comparison result: ${String(r)}`);
|
|
512
512
|
}
|
|
513
513
|
}
|
|
514
514
|
/**
|
|
@@ -582,70 +582,70 @@ function accessExtensionFields(e) {
|
|
|
582
582
|
};
|
|
583
583
|
}
|
|
584
584
|
/** Decode the explicit [3] extensions wrapper from a TBSCertificate. */
|
|
585
|
-
function parseExtensionContainer(
|
|
586
|
-
return
|
|
585
|
+
function parseExtensionContainer(t, n) {
|
|
586
|
+
return n === void 0 ? { all: [] } : parseExtensionSequence(t, l(e(t, n)[0], "extensions sequence"), "certificate");
|
|
587
587
|
}
|
|
588
588
|
/** Extract extensions from the CSR extensionRequest attribute. */
|
|
589
|
-
function parseRequestedExtensions(
|
|
590
|
-
let
|
|
591
|
-
for (let
|
|
592
|
-
if (
|
|
593
|
-
let
|
|
594
|
-
if (
|
|
595
|
-
let
|
|
596
|
-
if (
|
|
597
|
-
let
|
|
598
|
-
if (
|
|
599
|
-
let
|
|
600
|
-
if (
|
|
601
|
-
if (
|
|
602
|
-
if (
|
|
603
|
-
if (
|
|
604
|
-
|
|
589
|
+
function parseRequestedExtensions(t, n) {
|
|
590
|
+
let r;
|
|
591
|
+
for (let a of e(t, n)) {
|
|
592
|
+
if (a.tag !== 48) throw Error("CSR attribute must use SEQUENCE");
|
|
593
|
+
let n = e(t, a);
|
|
594
|
+
if (n.length !== 2) throw Error("Malformed CSR attribute");
|
|
595
|
+
let o = l(n[0], "attribute OID");
|
|
596
|
+
if (o.tag !== 6) throw Error("CSR attribute type must use OBJECT IDENTIFIER");
|
|
597
|
+
let s = l(n[1], "attribute values");
|
|
598
|
+
if (s.tag !== 49) throw Error("CSR attribute values must use SET");
|
|
599
|
+
let c = e(t, s);
|
|
600
|
+
if (c.length === 0) throw Error("CSR attribute values must not be empty");
|
|
601
|
+
if (i(o.value) === v.extensionRequest) {
|
|
602
|
+
if (r !== void 0) throw Error("extensionRequest attribute must not repeat");
|
|
603
|
+
if (c.length !== 1) throw Error("extensionRequest attribute must contain exactly one value");
|
|
604
|
+
r = parseExtensionSequence(t, l(c[0], "requested extensions"), "csr");
|
|
605
605
|
}
|
|
606
606
|
}
|
|
607
|
-
return
|
|
607
|
+
return r ?? { all: [] };
|
|
608
608
|
}
|
|
609
609
|
/** Walk a SEQUENCE OF Extension and decode each one, populating known-extension slots. */
|
|
610
|
-
function parseExtensionSequence(
|
|
611
|
-
let
|
|
612
|
-
for (let
|
|
613
|
-
let
|
|
614
|
-
if (
|
|
615
|
-
let
|
|
616
|
-
if (
|
|
617
|
-
|
|
618
|
-
let
|
|
619
|
-
|
|
620
|
-
let
|
|
621
|
-
if (
|
|
622
|
-
|
|
623
|
-
oid:
|
|
624
|
-
critical:
|
|
625
|
-
valueDer: new Uint8Array(
|
|
626
|
-
valueHex:
|
|
627
|
-
}),
|
|
610
|
+
function parseExtensionSequence(n, r, a) {
|
|
611
|
+
let o = [], s = {}, c = /* @__PURE__ */ new Set();
|
|
612
|
+
for (let u of e(n, r)) {
|
|
613
|
+
let r = e(n, u);
|
|
614
|
+
if (r.length < 2 || r.length > 3) throw Error("Malformed Extension");
|
|
615
|
+
let f = l(r[0], "extension OID"), p = i(f.value);
|
|
616
|
+
if (c.has(p)) throw Error(`Duplicate extension OID: ${p}`);
|
|
617
|
+
c.add(p);
|
|
618
|
+
let m = 1, h = !1, g = r[m];
|
|
619
|
+
g?.tag === 1 && (h = t(g.value), m += 1);
|
|
620
|
+
let _ = l(r[m], "extension value");
|
|
621
|
+
if (_.tag !== 4 || m !== r.length - 1) throw Error("Extension value must use OCTET STRING");
|
|
622
|
+
o.push({
|
|
623
|
+
oid: p,
|
|
624
|
+
critical: h,
|
|
625
|
+
valueDer: new Uint8Array(_.value),
|
|
626
|
+
valueHex: d(_.value)
|
|
627
|
+
}), w(a, p, s, _.value);
|
|
628
628
|
}
|
|
629
629
|
return {
|
|
630
|
-
all:
|
|
631
|
-
...
|
|
630
|
+
all: o,
|
|
631
|
+
...s
|
|
632
632
|
};
|
|
633
633
|
}
|
|
634
634
|
/** Decode an X.501 Name (issuer / subject) into a {@linkcode ParsedName}. */
|
|
635
|
-
function parseName(
|
|
636
|
-
if (
|
|
637
|
-
let
|
|
638
|
-
for (let
|
|
639
|
-
if (
|
|
640
|
-
let
|
|
641
|
-
|
|
642
|
-
for (let
|
|
635
|
+
function parseName(t, n) {
|
|
636
|
+
if (n.tag !== 48) throw Error("Name must use SEQUENCE");
|
|
637
|
+
let r = [], i = [], a = {};
|
|
638
|
+
for (let o of e(t, n)) {
|
|
639
|
+
if (o.tag !== 49) throw Error("RelativeDistinguishedName must use SET");
|
|
640
|
+
let e = parseNameAttributeSet(t, o);
|
|
641
|
+
r.push(e);
|
|
642
|
+
for (let t of e.attributes) i.push(t), t.key !== void 0 && a[t.key] === void 0 && (a[t.key] = t.value);
|
|
643
643
|
}
|
|
644
644
|
return {
|
|
645
|
-
derHex:
|
|
646
|
-
rdns:
|
|
647
|
-
attributes:
|
|
648
|
-
values:
|
|
645
|
+
derHex: d(t.slice(n.start - n.headerLength, n.end)),
|
|
646
|
+
rdns: r,
|
|
647
|
+
attributes: i,
|
|
648
|
+
values: a
|
|
649
649
|
};
|
|
650
650
|
}
|
|
651
651
|
/** Decode a single RDN SET element. */
|
|
@@ -653,155 +653,155 @@ function parseRelativeDistinguishedName(e, t) {
|
|
|
653
653
|
return parseNameAttributeSet(e, t);
|
|
654
654
|
}
|
|
655
655
|
/** Decode the AttributeTypeAndValue pairs within a SET element. */
|
|
656
|
-
function parseNameAttributeSet(
|
|
657
|
-
let
|
|
658
|
-
for (let
|
|
659
|
-
if (
|
|
660
|
-
let
|
|
661
|
-
if (
|
|
662
|
-
let
|
|
663
|
-
if (
|
|
664
|
-
let
|
|
665
|
-
oid:
|
|
666
|
-
valueTag:
|
|
667
|
-
value:
|
|
656
|
+
function parseNameAttributeSet(t, n) {
|
|
657
|
+
let r = [], o = {};
|
|
658
|
+
for (let s of e(t, n)) {
|
|
659
|
+
if (s.tag !== 48) throw Error("AttributeTypeAndValue must use SEQUENCE");
|
|
660
|
+
let n = e(t, s);
|
|
661
|
+
if (n.length !== 2) throw Error("AttributeTypeAndValue must contain type and value");
|
|
662
|
+
let c = l(n[0], "name OID");
|
|
663
|
+
if (c.tag !== 6) throw Error("AttributeTypeAndValue type must use OBJECT IDENTIFIER");
|
|
664
|
+
let u = i(c.value), d = l(n[1], "name value"), f = H(u), p = a(d.tag, d.value), m = f === void 0 ? {
|
|
665
|
+
oid: u,
|
|
666
|
+
valueTag: d.tag,
|
|
667
|
+
value: p
|
|
668
668
|
} : {
|
|
669
|
-
oid:
|
|
670
|
-
key:
|
|
671
|
-
valueTag:
|
|
672
|
-
value:
|
|
669
|
+
oid: u,
|
|
670
|
+
key: f,
|
|
671
|
+
valueTag: d.tag,
|
|
672
|
+
value: p
|
|
673
673
|
};
|
|
674
|
-
|
|
674
|
+
r.push(m), f !== void 0 && o[f] === void 0 && (o[f] = p);
|
|
675
675
|
}
|
|
676
676
|
return {
|
|
677
|
-
derHex:
|
|
678
|
-
attributes:
|
|
679
|
-
values:
|
|
677
|
+
derHex: d(t.slice(n.start - n.headerLength, n.end)),
|
|
678
|
+
attributes: r,
|
|
679
|
+
values: o
|
|
680
680
|
};
|
|
681
681
|
}
|
|
682
682
|
/** Decode the Validity SEQUENCE into notBefore / notAfter Dates. */
|
|
683
|
-
function parseValidity(
|
|
684
|
-
let
|
|
683
|
+
function parseValidity(t, n) {
|
|
684
|
+
let r = e(t, n);
|
|
685
685
|
return {
|
|
686
|
-
notBefore:
|
|
687
|
-
notAfter:
|
|
686
|
+
notBefore: c(l(r[0], "notBefore")),
|
|
687
|
+
notAfter: c(l(r[1], "notAfter"))
|
|
688
688
|
};
|
|
689
689
|
}
|
|
690
690
|
/** Extract the algorithm identifier from a SubjectPublicKeyInfo SEQUENCE. */
|
|
691
|
-
function parseSubjectPublicKeyInfo(
|
|
692
|
-
if (
|
|
693
|
-
let
|
|
694
|
-
if (
|
|
695
|
-
let
|
|
696
|
-
if (
|
|
697
|
-
let
|
|
698
|
-
return
|
|
691
|
+
function parseSubjectPublicKeyInfo(t, n) {
|
|
692
|
+
if (n.tag !== 48) throw Error("SubjectPublicKeyInfo must use SEQUENCE");
|
|
693
|
+
let r = e(t, n);
|
|
694
|
+
if (r.length !== 2) throw Error("SubjectPublicKeyInfo must contain algorithm and subjectPublicKey");
|
|
695
|
+
let i = l(r[0], "SPKI algorithm");
|
|
696
|
+
if (i.tag !== 48) throw Error("SubjectPublicKeyInfo algorithm must use SEQUENCE");
|
|
697
|
+
let a = parseAlgorithmIdentifier(t, i);
|
|
698
|
+
return s(l(r[1], "subjectPublicKey BIT STRING")), a;
|
|
699
699
|
}
|
|
700
700
|
/** Decode an AlgorithmIdentifier SEQUENCE (OID + optional parameters). */
|
|
701
|
-
function parseAlgorithmIdentifier(
|
|
702
|
-
if (
|
|
703
|
-
let
|
|
704
|
-
if (
|
|
705
|
-
let
|
|
706
|
-
if (
|
|
707
|
-
let
|
|
708
|
-
if (
|
|
709
|
-
let
|
|
710
|
-
return
|
|
711
|
-
oid:
|
|
712
|
-
parametersDer:
|
|
713
|
-
parametersOid:
|
|
701
|
+
function parseAlgorithmIdentifier(t, n) {
|
|
702
|
+
if (n.tag !== 48) throw Error("AlgorithmIdentifier must use SEQUENCE");
|
|
703
|
+
let r = e(t, n);
|
|
704
|
+
if (r.length === 0 || r.length > 2) throw Error("Malformed AlgorithmIdentifier");
|
|
705
|
+
let a = l(r[0], "algorithm OID");
|
|
706
|
+
if (a.tag !== 6) throw Error("AlgorithmIdentifier algorithm must use OBJECT IDENTIFIER");
|
|
707
|
+
let o = i(a.value), s = r[1];
|
|
708
|
+
if (s === void 0) return { oid: o };
|
|
709
|
+
let c = t.slice(s.start - s.headerLength, s.end);
|
|
710
|
+
return s?.tag === 6 ? {
|
|
711
|
+
oid: o,
|
|
712
|
+
parametersDer: c,
|
|
713
|
+
parametersOid: i(s.value)
|
|
714
714
|
} : {
|
|
715
|
-
oid:
|
|
716
|
-
parametersDer:
|
|
715
|
+
oid: o,
|
|
716
|
+
parametersDer: c
|
|
717
717
|
};
|
|
718
718
|
}
|
|
719
719
|
function assertMatchingCertificateSignatureAlgorithms(e, t) {
|
|
720
|
-
if (e.oid !== t.oid || !
|
|
720
|
+
if (e.oid !== t.oid || !m(e.parametersDer, t.parametersDer)) throw Error("Certificate signatureAlgorithm must match TBSCertificate signature");
|
|
721
721
|
}
|
|
722
722
|
/** Decodes the Basic Constraints extension value DER. */
|
|
723
|
-
function parseBasicConstraints(
|
|
724
|
-
let
|
|
725
|
-
if (
|
|
726
|
-
let
|
|
727
|
-
for (let e of
|
|
728
|
-
if (
|
|
729
|
-
if (
|
|
730
|
-
|
|
723
|
+
function parseBasicConstraints(n) {
|
|
724
|
+
let i = g(n, { maxDepth: 64 });
|
|
725
|
+
if (i.tag !== 48) throw Error("basicConstraints must use SEQUENCE");
|
|
726
|
+
let a = e(n, i), o = !1, s, c = !1, l = !1;
|
|
727
|
+
for (let e of a) if (e.tag === 1) {
|
|
728
|
+
if (c) throw Error("basicConstraints cA must not repeat");
|
|
729
|
+
if (l) throw Error("basicConstraints cA must precede pathLength");
|
|
730
|
+
c = !0, o = t(e.value);
|
|
731
731
|
} else if (e.tag === 2) {
|
|
732
|
-
if (
|
|
733
|
-
|
|
732
|
+
if (l) throw Error("basicConstraints pathLength must not repeat");
|
|
733
|
+
l = !0, s = r(e.value, "basicConstraints pathLength");
|
|
734
734
|
} else throw Error(`Unsupported basicConstraints field tag: ${String(e.tag)}`);
|
|
735
|
-
if (
|
|
736
|
-
return
|
|
735
|
+
if (s !== void 0 && o !== !0) throw Error("basicConstraints pathLength requires cA = true");
|
|
736
|
+
return o ? s === void 0 ? { ca: !0 } : {
|
|
737
737
|
ca: !0,
|
|
738
|
-
pathLength:
|
|
738
|
+
pathLength: s
|
|
739
739
|
} : { ca: !1 };
|
|
740
740
|
}
|
|
741
741
|
/** Decodes the Key Usage BIT STRING extension value. */
|
|
742
742
|
function parseKeyUsage(e) {
|
|
743
|
-
return
|
|
743
|
+
return C(e);
|
|
744
744
|
}
|
|
745
745
|
/** Decodes the Extended Key Usage SEQUENCE OF OIDs. */
|
|
746
746
|
function parseExtendedKeyUsage(e) {
|
|
747
|
-
let t =
|
|
747
|
+
let t = _(e, { maxDepth: 64 });
|
|
748
748
|
if (t.length === 0) throw Error("extendedKeyUsage must not be empty");
|
|
749
749
|
return t.map((e) => {
|
|
750
750
|
if (e.tag !== 6) throw Error("extendedKeyUsage entry must use OBJECT IDENTIFIER");
|
|
751
|
-
return
|
|
751
|
+
return V(i(e.value));
|
|
752
752
|
});
|
|
753
753
|
}
|
|
754
754
|
/** Decodes the Certificate Policies extension value. */
|
|
755
|
-
function parseCertificatePolicies(
|
|
756
|
-
let
|
|
757
|
-
if (
|
|
758
|
-
return
|
|
755
|
+
function parseCertificatePolicies(t) {
|
|
756
|
+
let n = l(g(t, { maxDepth: 64 }), "certificatePolicies sequence"), r = e(t, n);
|
|
757
|
+
if (r.length === 0) throw Error("certificatePolicies must not be empty");
|
|
758
|
+
return r.map((e) => parsePolicyInformation(t, e));
|
|
759
759
|
}
|
|
760
760
|
/** Decode a single PolicyInformation SEQUENCE (OID + optional qualifiers). */
|
|
761
|
-
function parsePolicyInformation(
|
|
762
|
-
let
|
|
763
|
-
if (
|
|
764
|
-
if (
|
|
765
|
-
let
|
|
766
|
-
if (
|
|
761
|
+
function parsePolicyInformation(t, n) {
|
|
762
|
+
let r = e(t, n), a = i(l(r[0], "policyIdentifier").value), o = r[1];
|
|
763
|
+
if (r.length > 2) throw Error("policyInformation has unexpected trailing fields");
|
|
764
|
+
if (o === void 0) return { policyIdentifier: a };
|
|
765
|
+
let s = e(t, o);
|
|
766
|
+
if (s.length === 0) throw Error("policyQualifiers must not be empty");
|
|
767
767
|
return {
|
|
768
|
-
policyIdentifier:
|
|
769
|
-
policyQualifiers:
|
|
768
|
+
policyIdentifier: a,
|
|
769
|
+
policyQualifiers: s.map((e) => parsePolicyQualifierInfo(t, e))
|
|
770
770
|
};
|
|
771
771
|
}
|
|
772
772
|
/** Decode a PolicyQualifierInfo (CPS URI, UserNotice, or opaque OID). */
|
|
773
|
-
function parsePolicyQualifierInfo(
|
|
774
|
-
let
|
|
775
|
-
if (
|
|
776
|
-
if (
|
|
777
|
-
if (
|
|
773
|
+
function parsePolicyQualifierInfo(t, n) {
|
|
774
|
+
let r = e(t, n), o = i(l(r[0], "policyQualifierId").value), s = l(r[1], "policyQualifier");
|
|
775
|
+
if (r.length > 2) throw Error("policyQualifierInfo has unexpected trailing fields");
|
|
776
|
+
if (o === v.cpsPolicyQualifier) {
|
|
777
|
+
if (s.tag !== 22) throw Error("cps policy qualifier must use IA5String");
|
|
778
778
|
return {
|
|
779
779
|
type: "cps",
|
|
780
|
-
uri:
|
|
780
|
+
uri: a(s.tag, s.value)
|
|
781
781
|
};
|
|
782
782
|
}
|
|
783
|
-
return
|
|
783
|
+
return o === v.userNoticePolicyQualifier ? {
|
|
784
784
|
type: "userNotice",
|
|
785
|
-
...parseUserNoticePolicyQualifierInfo(
|
|
785
|
+
...parseUserNoticePolicyQualifierInfo(t, s)
|
|
786
786
|
} : {
|
|
787
787
|
type: "oid",
|
|
788
|
-
oid:
|
|
789
|
-
qualifierDer:
|
|
788
|
+
oid: o,
|
|
789
|
+
qualifierDer: t.slice(s.start - s.headerLength, s.end)
|
|
790
790
|
};
|
|
791
791
|
}
|
|
792
792
|
/** Decode a UserNotice qualifier (optional noticeRef + optional explicitText). */
|
|
793
|
-
function parseUserNoticePolicyQualifierInfo(
|
|
794
|
-
let
|
|
795
|
-
for (let
|
|
796
|
-
if (
|
|
797
|
-
|
|
793
|
+
function parseUserNoticePolicyQualifierInfo(t, n) {
|
|
794
|
+
let r = e(t, n), i, a;
|
|
795
|
+
for (let e of r) if (e.tag === 48) {
|
|
796
|
+
if (i !== void 0) throw Error("userNotice must not contain multiple noticeRef values");
|
|
797
|
+
i = parsePolicyNoticeReference(t, e);
|
|
798
798
|
} else {
|
|
799
|
-
if (
|
|
800
|
-
|
|
799
|
+
if (a !== void 0) throw Error("userNotice must not contain multiple explicitText values");
|
|
800
|
+
a = parseExplicitText(e);
|
|
801
801
|
}
|
|
802
802
|
return {
|
|
803
|
-
...
|
|
804
|
-
...
|
|
803
|
+
...i === void 0 ? {} : { noticeRef: i },
|
|
804
|
+
...a
|
|
805
805
|
};
|
|
806
806
|
}
|
|
807
807
|
function parseExplicitText(e) {
|
|
@@ -813,112 +813,112 @@ function parseExplicitText(e) {
|
|
|
813
813
|
};
|
|
814
814
|
}
|
|
815
815
|
/** Decode a NoticeReference (organization name + notice number list). */
|
|
816
|
-
function parsePolicyNoticeReference(
|
|
817
|
-
if (
|
|
818
|
-
let
|
|
819
|
-
if (
|
|
816
|
+
function parsePolicyNoticeReference(t, n) {
|
|
817
|
+
if (n.tag !== 48) throw Error("noticeRef must use SEQUENCE");
|
|
818
|
+
let r = e(t, n), i = parseDisplayText(l(r[0], "noticeRef organization")), a = l(r[1], "noticeRef noticeNumbers");
|
|
819
|
+
if (r.length > 2) throw Error("noticeRef has unexpected trailing fields");
|
|
820
820
|
return {
|
|
821
|
-
organization:
|
|
822
|
-
noticeNumbers: parsePolicyNoticeNumbers(
|
|
823
|
-
...
|
|
821
|
+
organization: i.text,
|
|
822
|
+
noticeNumbers: parsePolicyNoticeNumbers(t, a),
|
|
823
|
+
...i.oversized === void 0 ? {} : { oversizedOrganization: i.oversized }
|
|
824
824
|
};
|
|
825
825
|
}
|
|
826
826
|
/** Decode a SEQUENCE OF INTEGER notice numbers. */
|
|
827
|
-
function parsePolicyNoticeNumbers(
|
|
828
|
-
if (
|
|
829
|
-
let
|
|
830
|
-
if (
|
|
831
|
-
return
|
|
827
|
+
function parsePolicyNoticeNumbers(t, n) {
|
|
828
|
+
if (n.tag !== 48) throw Error("noticeRef noticeNumbers must use SEQUENCE");
|
|
829
|
+
let i = e(t, n);
|
|
830
|
+
if (i.length === 0) throw Error("noticeRef noticeNumbers must not be empty");
|
|
831
|
+
return i.map((e) => {
|
|
832
832
|
if (e.tag !== 2) throw Error("noticeRef noticeNumber must use INTEGER");
|
|
833
|
-
return
|
|
833
|
+
return r(e.value, "noticeRef noticeNumber");
|
|
834
834
|
});
|
|
835
835
|
}
|
|
836
836
|
/** Decodes the Policy Mappings extension value. */
|
|
837
|
-
function parsePolicyMappings(
|
|
838
|
-
let
|
|
839
|
-
if (
|
|
840
|
-
return
|
|
841
|
-
let
|
|
842
|
-
if (
|
|
843
|
-
if (
|
|
837
|
+
function parsePolicyMappings(t) {
|
|
838
|
+
let n = l(g(t, { maxDepth: 64 }), "policyMappings sequence"), r = e(t, n);
|
|
839
|
+
if (r.length === 0) throw Error("policyMappings must not be empty");
|
|
840
|
+
return r.map((n) => {
|
|
841
|
+
let r = e(t, n), a = i(l(r[0], "policyMappings issuerDomainPolicy").value), o = i(l(r[1], "policyMappings subjectDomainPolicy").value);
|
|
842
|
+
if (r.length > 2) throw Error("policyMappings entry has unexpected trailing fields");
|
|
843
|
+
if (a === v.anyPolicy || o === v.anyPolicy) throw Error("policyMappings must not use anyPolicy");
|
|
844
844
|
return {
|
|
845
|
-
issuerDomainPolicy:
|
|
846
|
-
subjectDomainPolicy:
|
|
845
|
+
issuerDomainPolicy: a,
|
|
846
|
+
subjectDomainPolicy: o
|
|
847
847
|
};
|
|
848
848
|
});
|
|
849
849
|
}
|
|
850
850
|
/** Decodes the Policy Constraints extension value. */
|
|
851
|
-
function parsePolicyConstraints(
|
|
852
|
-
let
|
|
853
|
-
for (let
|
|
854
|
-
if (
|
|
855
|
-
|
|
856
|
-
} else if (
|
|
857
|
-
if (
|
|
858
|
-
|
|
859
|
-
} else throw Error(`Unsupported policyConstraints field tag: ${
|
|
860
|
-
if (
|
|
851
|
+
function parsePolicyConstraints(t) {
|
|
852
|
+
let n = l(g(t, { maxDepth: 64 }), "policyConstraints sequence"), i, a;
|
|
853
|
+
for (let o of e(t, n)) if (o.tag === 128) {
|
|
854
|
+
if (i !== void 0) throw Error("policyConstraints must not repeat requireExplicitPolicy");
|
|
855
|
+
i = r(o.value, "policyConstraints requireExplicitPolicy");
|
|
856
|
+
} else if (o.tag === 129) {
|
|
857
|
+
if (a !== void 0) throw Error("policyConstraints must not repeat inhibitPolicyMapping");
|
|
858
|
+
a = r(o.value, "policyConstraints inhibitPolicyMapping");
|
|
859
|
+
} else throw Error(`Unsupported policyConstraints field tag: ${o.tag}`);
|
|
860
|
+
if (i === void 0 && a === void 0) throw Error("policyConstraints must set requireExplicitPolicy or inhibitPolicyMapping");
|
|
861
861
|
return {
|
|
862
|
-
...
|
|
863
|
-
...
|
|
862
|
+
...i === void 0 ? {} : { requireExplicitPolicy: i },
|
|
863
|
+
...a === void 0 ? {} : { inhibitPolicyMapping: a }
|
|
864
864
|
};
|
|
865
865
|
}
|
|
866
866
|
/** Decodes the Inhibit anyPolicy extension (single INTEGER). */
|
|
867
867
|
function parseInhibitAnyPolicy(e) {
|
|
868
|
-
let t =
|
|
868
|
+
let t = l(g(e, { maxDepth: 64 }), "inhibitAnyPolicy integer");
|
|
869
869
|
if (t.tag !== 2) throw Error("inhibitAnyPolicy must be an INTEGER");
|
|
870
|
-
return { skipCerts:
|
|
870
|
+
return { skipCerts: r(t.value, "inhibitAnyPolicy skipCerts") };
|
|
871
871
|
}
|
|
872
872
|
/** Decodes a subjectAltName or issuerAltName SEQUENCE OF GeneralName. */
|
|
873
873
|
function parseSubjectAltNames(e, t = "subjectAltName") {
|
|
874
|
-
let n =
|
|
874
|
+
let n = l(g(e, { maxDepth: 64 }), `${t} sequence`);
|
|
875
875
|
if (n.tag !== 48) throw Error(`${t} must use SEQUENCE`);
|
|
876
|
-
return
|
|
876
|
+
return O(e, n);
|
|
877
877
|
}
|
|
878
878
|
/** Decodes a bare DER-encoded X.501 Name, as carried in a `directoryName` GeneralName. */
|
|
879
879
|
function parseDistinguishedNameDer(e) {
|
|
880
|
-
let t =
|
|
880
|
+
let t = l(g(e, { maxDepth: 64 }), "distinguished name sequence");
|
|
881
881
|
if (t.tag !== 48) throw Error("distinguished name must use SEQUENCE");
|
|
882
882
|
return parseName(e, t);
|
|
883
883
|
}
|
|
884
884
|
/** Decodes the Authority Information Access extension value. */
|
|
885
|
-
function parseAuthorityInfoAccess(
|
|
886
|
-
let
|
|
887
|
-
if (
|
|
888
|
-
let
|
|
889
|
-
if (
|
|
890
|
-
return
|
|
891
|
-
if (
|
|
892
|
-
let
|
|
893
|
-
if (
|
|
894
|
-
let
|
|
895
|
-
if (
|
|
885
|
+
function parseAuthorityInfoAccess(t) {
|
|
886
|
+
let n = l(g(t, { maxDepth: 64 }), "authorityInfoAccess sequence");
|
|
887
|
+
if (n.tag !== 48) throw Error("authorityInfoAccess must use SEQUENCE");
|
|
888
|
+
let r = e(t, n);
|
|
889
|
+
if (r.length === 0) throw Error("authorityInfoAccess must not be empty");
|
|
890
|
+
return r.map((n) => {
|
|
891
|
+
if (n.tag !== 48) throw Error("authorityInfoAccess entry must use SEQUENCE");
|
|
892
|
+
let r = e(t, n);
|
|
893
|
+
if (r.length !== 2) throw Error("authorityInfoAccess entry must contain method and location only");
|
|
894
|
+
let a = l(r[0], "authorityInfoAccess method"), o = l(r[1], "authorityInfoAccess location");
|
|
895
|
+
if (a.tag !== 6) throw Error("authorityInfoAccess method must use OBJECT IDENTIFIER");
|
|
896
896
|
return {
|
|
897
|
-
method:
|
|
898
|
-
location:
|
|
897
|
+
method: B(i(a.value)),
|
|
898
|
+
location: D(t, o)
|
|
899
899
|
};
|
|
900
900
|
});
|
|
901
901
|
}
|
|
902
902
|
/** Decodes the CRL Distribution Points extension value. */
|
|
903
|
-
function parseCrlDistributionPoints(
|
|
904
|
-
let
|
|
905
|
-
if (
|
|
906
|
-
let
|
|
907
|
-
if (
|
|
908
|
-
let
|
|
909
|
-
for (let
|
|
910
|
-
return
|
|
903
|
+
function parseCrlDistributionPoints(t) {
|
|
904
|
+
let n = l(g(t, { maxDepth: 64 }), "CRLDistributionPoints sequence");
|
|
905
|
+
if (n.tag !== 48) throw Error("CRLDistributionPoints must use SEQUENCE");
|
|
906
|
+
let r = e(t, n);
|
|
907
|
+
if (r.length === 0) throw Error("CRLDistributionPoints must not be empty");
|
|
908
|
+
let i = [];
|
|
909
|
+
for (let e of r) i.push(parseDistributionPoint(t, e));
|
|
910
|
+
return i;
|
|
911
911
|
}
|
|
912
912
|
/** Decode a single DistributionPoint SEQUENCE. */
|
|
913
|
-
function parseDistributionPoint(
|
|
914
|
-
if (
|
|
915
|
-
let
|
|
916
|
-
for (let
|
|
917
|
-
if (
|
|
913
|
+
function parseDistributionPoint(t, n) {
|
|
914
|
+
if (n.tag !== 48) throw Error("DistributionPoint must use SEQUENCE");
|
|
915
|
+
let r = {};
|
|
916
|
+
for (let i of e(t, n)) parseDistributionPointField(t, i, r);
|
|
917
|
+
if (r.distributionPoint === void 0 && r.crlIssuer === void 0) throw Error("DistributionPoint must include distributionPoint or crlIssuer");
|
|
918
918
|
return {
|
|
919
|
-
...
|
|
920
|
-
...
|
|
921
|
-
...
|
|
919
|
+
...r.distributionPoint === void 0 ? {} : { distributionPoint: r.distributionPoint },
|
|
920
|
+
...r.reasons === void 0 ? {} : { reasons: r.reasons },
|
|
921
|
+
...r.crlIssuer === void 0 ? {} : { crlIssuer: r.crlIssuer }
|
|
922
922
|
};
|
|
923
923
|
}
|
|
924
924
|
function parseDistributionPointField(e, t, n) {
|
|
@@ -929,38 +929,38 @@ function parseDistributionPointField(e, t, n) {
|
|
|
929
929
|
return;
|
|
930
930
|
case 129:
|
|
931
931
|
if (n.reasons !== void 0) throw Error("DistributionPoint reasons must not repeat");
|
|
932
|
-
n.reasons =
|
|
932
|
+
n.reasons = S(t.value);
|
|
933
933
|
return;
|
|
934
934
|
case 162:
|
|
935
935
|
if (n.crlIssuer !== void 0) throw Error("DistributionPoint crlIssuer must not repeat");
|
|
936
|
-
n.crlIssuer =
|
|
936
|
+
n.crlIssuer = O(e, t);
|
|
937
937
|
return;
|
|
938
938
|
default: throw Error(`Unsupported DistributionPoint field tag: ${String(t.tag)}`);
|
|
939
939
|
}
|
|
940
940
|
}
|
|
941
941
|
/** Decode a DistributionPointName (fullName or relativeName). */
|
|
942
|
-
function parseDistributionPointName(
|
|
943
|
-
let
|
|
944
|
-
if (
|
|
945
|
-
let
|
|
946
|
-
if (
|
|
947
|
-
let
|
|
948
|
-
if (
|
|
949
|
-
for (let e of
|
|
942
|
+
function parseDistributionPointName(t, n) {
|
|
943
|
+
let r = e(t, n);
|
|
944
|
+
if (r.length !== 1) throw Error("distributionPointName must contain exactly one choice");
|
|
945
|
+
let i = l(r[0], "distributionPointName");
|
|
946
|
+
if (i.tag === 160) {
|
|
947
|
+
let n = e(t, i);
|
|
948
|
+
if (n.length === 0) throw Error("distributionPointName fullName must not be empty");
|
|
949
|
+
for (let e of n) if ((e.tag & 192) != 128) throw Error("distributionPointName fullName must contain GeneralName entries");
|
|
950
950
|
return {
|
|
951
951
|
type: "fullName",
|
|
952
|
-
fullName:
|
|
952
|
+
fullName: n.map((e) => D(t, e))
|
|
953
953
|
};
|
|
954
954
|
}
|
|
955
|
-
if (
|
|
955
|
+
if (i.tag === 161) return {
|
|
956
956
|
type: "relativeName",
|
|
957
|
-
relativeName: parseRelativeDistinguishedName(
|
|
957
|
+
relativeName: parseRelativeDistinguishedName(t, i)
|
|
958
958
|
};
|
|
959
|
-
throw Error(`Unsupported distributionPointName tag: ${
|
|
959
|
+
throw Error(`Unsupported distributionPointName tag: ${i.tag}`);
|
|
960
960
|
}
|
|
961
961
|
/** Decodes the Name Constraints extension value. */
|
|
962
|
-
function parseNameConstraints(
|
|
963
|
-
let
|
|
962
|
+
function parseNameConstraints(t) {
|
|
963
|
+
let n = l(g(t, {
|
|
964
964
|
maxDepth: 64,
|
|
965
965
|
allowOpaqueConstructedTags: [
|
|
966
966
|
160,
|
|
@@ -968,64 +968,64 @@ function parseNameConstraints(e) {
|
|
|
968
968
|
165
|
|
969
969
|
]
|
|
970
970
|
}), "nameConstraints sequence");
|
|
971
|
-
if (
|
|
972
|
-
let
|
|
973
|
-
for (let
|
|
974
|
-
if (
|
|
975
|
-
|
|
976
|
-
} else if (
|
|
977
|
-
if (
|
|
978
|
-
|
|
979
|
-
} else throw Error(`Unsupported nameConstraints field tag: ${String(
|
|
971
|
+
if (n.tag !== 48) throw Error("nameConstraints must use SEQUENCE");
|
|
972
|
+
let r, i;
|
|
973
|
+
for (let a of e(t, n)) if (a.tag === 160) {
|
|
974
|
+
if (r !== void 0) throw Error("nameConstraints permittedSubtrees must not repeat");
|
|
975
|
+
r = parseGeneralSubtrees(t, a);
|
|
976
|
+
} else if (a.tag === 161) {
|
|
977
|
+
if (i !== void 0) throw Error("nameConstraints excludedSubtrees must not repeat");
|
|
978
|
+
i = parseGeneralSubtrees(t, a);
|
|
979
|
+
} else throw Error(`Unsupported nameConstraints field tag: ${String(a.tag)}`);
|
|
980
980
|
return {
|
|
981
|
-
...
|
|
982
|
-
...
|
|
981
|
+
...r === void 0 ? {} : { permittedSubtrees: r },
|
|
982
|
+
...i === void 0 ? {} : { excludedSubtrees: i }
|
|
983
983
|
};
|
|
984
984
|
}
|
|
985
985
|
/** Decode a SEQUENCE OF GeneralSubtree from a permittedSubtrees or excludedSubtrees wrapper. */
|
|
986
|
-
function parseGeneralSubtrees(
|
|
987
|
-
let
|
|
988
|
-
if (
|
|
989
|
-
for (let
|
|
990
|
-
let
|
|
991
|
-
|
|
986
|
+
function parseGeneralSubtrees(t, n) {
|
|
987
|
+
let r = [], i = e(t, n);
|
|
988
|
+
if (i.length === 0) throw Error("name constraints GeneralSubtrees must not be empty");
|
|
989
|
+
for (let e of i) {
|
|
990
|
+
let n = parseGeneralSubtree(t, e);
|
|
991
|
+
n !== void 0 && r.push({ base: n });
|
|
992
992
|
}
|
|
993
|
-
return
|
|
993
|
+
return r;
|
|
994
994
|
}
|
|
995
|
-
function parseGeneralSubtree(
|
|
996
|
-
if (
|
|
997
|
-
let
|
|
998
|
-
if (
|
|
999
|
-
return validateGeneralSubtreeBounds(
|
|
995
|
+
function parseGeneralSubtree(t, n) {
|
|
996
|
+
if (n.tag !== 48) throw Error("name constraints GeneralSubtree must use SEQUENCE");
|
|
997
|
+
let r = e(t, n), i = r[0];
|
|
998
|
+
if (i === void 0) throw Error("GeneralSubtree base is required");
|
|
999
|
+
return validateGeneralSubtreeBounds(r.slice(1)), parseNameConstraintGeneralName(t, i);
|
|
1000
1000
|
}
|
|
1001
1001
|
function validateGeneralSubtreeBounds(e) {
|
|
1002
1002
|
let t = !1;
|
|
1003
1003
|
for (let n of e) if (n.tag === 128) {
|
|
1004
1004
|
if (t) throw Error("name constraints GeneralSubtree minimum must not repeat");
|
|
1005
|
-
if (t = !0,
|
|
1005
|
+
if (t = !0, r(n.value, "name constraints GeneralSubtree minimum") !== 0) throw Error("name constraints GeneralSubtree minimum must be 0");
|
|
1006
1006
|
} else throw n.tag === 129 ? Error("name constraints GeneralSubtree maximum is not supported") : Error(`Unsupported name constraints GeneralSubtree field tag: ${String(n.tag)}`);
|
|
1007
1007
|
}
|
|
1008
1008
|
/** Decode a GeneralName for use in name constraints (IP carries address+mask). */
|
|
1009
1009
|
function parseNameConstraintGeneralName(e, t) {
|
|
1010
1010
|
switch (t.tag) {
|
|
1011
1011
|
case 160: {
|
|
1012
|
-
let { typeId: n, value: r } =
|
|
1013
|
-
return n ===
|
|
1012
|
+
let { typeId: n, value: r } = k(e, t);
|
|
1013
|
+
return n === v.idOnDnsSrv ? {
|
|
1014
1014
|
type: "srv",
|
|
1015
|
-
value:
|
|
1015
|
+
value: T(r)
|
|
1016
1016
|
} : {
|
|
1017
1017
|
type: "otherName",
|
|
1018
1018
|
typeId: n,
|
|
1019
|
-
value:
|
|
1019
|
+
value: E(e, r)
|
|
1020
1020
|
};
|
|
1021
1021
|
}
|
|
1022
1022
|
case 129: return {
|
|
1023
1023
|
type: "email",
|
|
1024
|
-
value:
|
|
1024
|
+
value: a(22, t.value)
|
|
1025
1025
|
};
|
|
1026
1026
|
case 130: return {
|
|
1027
1027
|
type: "dns",
|
|
1028
|
-
value:
|
|
1028
|
+
value: a(22, t.value)
|
|
1029
1029
|
};
|
|
1030
1030
|
case 163: return {
|
|
1031
1031
|
type: "x400Address",
|
|
@@ -1033,7 +1033,7 @@ function parseNameConstraintGeneralName(e, t) {
|
|
|
1033
1033
|
};
|
|
1034
1034
|
case 134: return {
|
|
1035
1035
|
type: "uri",
|
|
1036
|
-
value:
|
|
1036
|
+
value: a(22, t.value)
|
|
1037
1037
|
};
|
|
1038
1038
|
case 135:
|
|
1039
1039
|
if (t.value.length === 8) return {
|
|
@@ -1049,7 +1049,7 @@ function parseNameConstraintGeneralName(e, t) {
|
|
|
1049
1049
|
throw Error(`Invalid IP name constraint: expected 8 (IPv4) or 32 (IPv6) bytes, got ${String(t.value.length)}`);
|
|
1050
1050
|
case 164: return {
|
|
1051
1051
|
type: "directoryName",
|
|
1052
|
-
derHex:
|
|
1052
|
+
derHex: d(x(t))
|
|
1053
1053
|
};
|
|
1054
1054
|
case 165: return {
|
|
1055
1055
|
type: "ediPartyName",
|
|
@@ -1057,7 +1057,7 @@ function parseNameConstraintGeneralName(e, t) {
|
|
|
1057
1057
|
};
|
|
1058
1058
|
case 136: return {
|
|
1059
1059
|
type: "registeredID",
|
|
1060
|
-
value:
|
|
1060
|
+
value: i(t.value)
|
|
1061
1061
|
};
|
|
1062
1062
|
}
|
|
1063
1063
|
throw Error(`Unsupported name constraint GeneralName tag: ${String(t.tag)}`);
|
|
@@ -1087,14 +1087,14 @@ function decodeDisplayText(e) {
|
|
|
1087
1087
|
switch (e.tag) {
|
|
1088
1088
|
case 12:
|
|
1089
1089
|
case 22:
|
|
1090
|
-
case 30: return
|
|
1091
|
-
case 26: return
|
|
1090
|
+
case 30: return a(e.tag, e.value);
|
|
1091
|
+
case 26: return o(e.value);
|
|
1092
1092
|
default: throw Error(`Unsupported DisplayText tag: ${e.tag}`);
|
|
1093
1093
|
}
|
|
1094
1094
|
}
|
|
1095
1095
|
/** Decodes the Authority Key Identifier extension, returning the keyIdentifier hex or undefined. */
|
|
1096
1096
|
function parseAuthorityKeyIdentifier(e) {
|
|
1097
|
-
let t =
|
|
1097
|
+
let t = l(h(e, 0), "authorityKeyIdentifier sequence");
|
|
1098
1098
|
if (t.end !== e.length) throw Error("Trailing data after DER element");
|
|
1099
1099
|
let n = {
|
|
1100
1100
|
sawAuthorityCertIssuer: !1,
|
|
@@ -1102,7 +1102,7 @@ function parseAuthorityKeyIdentifier(e) {
|
|
|
1102
1102
|
lastFieldOrder: -1
|
|
1103
1103
|
}, r = t.start;
|
|
1104
1104
|
for (; r < t.end;) {
|
|
1105
|
-
let i =
|
|
1105
|
+
let i = h(e, r);
|
|
1106
1106
|
if (i.end > t.end) throw Error("DER child exceeds parent length");
|
|
1107
1107
|
parseAuthorityKeyIdentifierField(e, i, n), r = i.end;
|
|
1108
1108
|
}
|
|
@@ -1127,18 +1127,18 @@ function parseAuthorityKeyIdentifierField(e, t, n) {
|
|
|
1127
1127
|
function parseAuthorityKeyIdentifierKeyId(e, t) {
|
|
1128
1128
|
if (t.keyIdentifier !== void 0) throw Error("authorityKeyIdentifier keyIdentifier must not repeat");
|
|
1129
1129
|
if (t.lastFieldOrder >= 0) throw Error("authorityKeyIdentifier fields must preserve DER order");
|
|
1130
|
-
t.keyIdentifier =
|
|
1131
|
-
}
|
|
1132
|
-
function parseAuthorityKeyIdentifierIssuer(
|
|
1133
|
-
if (
|
|
1134
|
-
if (
|
|
1135
|
-
let
|
|
1136
|
-
if (
|
|
1137
|
-
for (let
|
|
1138
|
-
if ((
|
|
1139
|
-
|
|
1130
|
+
t.keyIdentifier = d(e.value), t.lastFieldOrder = 0;
|
|
1131
|
+
}
|
|
1132
|
+
function parseAuthorityKeyIdentifierIssuer(t, n, r) {
|
|
1133
|
+
if (r.sawAuthorityCertIssuer) throw Error("authorityKeyIdentifier authorityCertIssuer must not repeat");
|
|
1134
|
+
if (r.lastFieldOrder >= 1) throw Error("authorityKeyIdentifier fields must preserve DER order");
|
|
1135
|
+
let i = e(t, n);
|
|
1136
|
+
if (i.length === 0) throw Error("authorityKeyIdentifier authorityCertIssuer must contain GeneralName entries");
|
|
1137
|
+
for (let e of i) {
|
|
1138
|
+
if ((e.tag & 192) != 128) throw Error("authorityKeyIdentifier authorityCertIssuer must contain GeneralName entries");
|
|
1139
|
+
D(t, e);
|
|
1140
1140
|
}
|
|
1141
|
-
|
|
1141
|
+
r.sawAuthorityCertIssuer = !0, r.lastFieldOrder = 1;
|
|
1142
1142
|
}
|
|
1143
1143
|
function parseAuthorityKeyIdentifierSerial(e, t) {
|
|
1144
1144
|
if (t.sawAuthorityCertSerialNumber) throw Error("authorityKeyIdentifier authorityCertSerialNumber must not repeat");
|