micro509 0.8.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 +4 -4
- 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 +626 -447
- package/dist/keys/keys.js +652 -404
- package/dist/keys/keys.js.map +1 -0
- package/dist/keys.d.ts +2 -2
- 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 +581 -638
- 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/x509/parse.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { encodeLength, readElement, readRootElement, readSequenceChildren } from "../internal/asn1/der.js";
|
|
2
|
-
import { childrenOf, decodeBoolean, decodeIntegerNumber, decodeNonNegativeIntegerNumber, decodeObjectIdentifier, decodeString, extractBitStringValue, parseTime, requireElement, toHex } from "../internal/asn1/asn1.js";
|
|
3
|
-
import { OIDS } from "../internal/asn1/
|
|
4
|
-
import { failureResult, rethrowIfInvariant, successResult } from "../result/result.js";
|
|
5
|
-
import { pemDecodeOrThrow, splitPemBlocksOrThrow } from "../pem/pem.js";
|
|
6
|
-
import { importSpkiDer, importSpkiDerOrThrow } from "../keys/keys.js";
|
|
7
|
-
import { describePublicKeyAlgorithm, describeSignatureAlgorithm } from "../internal/crypto/algorithm-names.js";
|
|
8
|
-
import { decodeIpAddress } from "../internal/shared/ip.js";
|
|
9
|
-
import { parseDistributionPointReasonFlagsContent, parseKeyUsageExtension } from "../internal/x509/extension-bits.js";
|
|
10
|
-
import { nameFieldKeyFromOid } from "../internal/x509/name-fields.js";
|
|
11
|
-
import { parseAuthorityInfoAccessMethodOid, parseExtendedKeyUsageOid } from "./extensions.js";
|
|
12
|
-
import { decodeAndApplyKnownExtension } from "../internal/x509/extension-registry.js";
|
|
1
|
+
import { encodeLength as e, readElement as t, readRootElement as n, readSequenceChildren as r } from "../internal/asn1/der.js";
|
|
2
|
+
import { childrenOf as i, decodeBoolean as a, decodeIntegerNumber as o, decodeNonNegativeIntegerNumber as s, decodeObjectIdentifier as c, decodeString as l, extractBitStringValue as u, parseTime as d, requireElement as f, toHex as p } from "../internal/asn1/asn1.js";
|
|
3
|
+
import { OIDS as m } from "../internal/asn1/oids2.js";
|
|
4
|
+
import { failureResult as h, rethrowIfInvariant as g, successResult as _ } from "../result/result.js";
|
|
5
|
+
import { pemDecodeOrThrow as v, splitPemBlocksOrThrow as y } from "../pem/pem.js";
|
|
6
|
+
import { importSpkiDer as b, importSpkiDerOrThrow as x } from "../keys/keys.js";
|
|
7
|
+
import { describePublicKeyAlgorithm as S, describeSignatureAlgorithm as C } from "../internal/crypto/algorithm-names.js";
|
|
8
|
+
import { decodeIpAddress as w } from "../internal/shared/ip.js";
|
|
9
|
+
import { parseDistributionPointReasonFlagsContent as T, parseKeyUsageExtension as E } from "../internal/x509/extension-bits.js";
|
|
10
|
+
import { nameFieldKeyFromOid as D } from "../internal/x509/name-fields.js";
|
|
11
|
+
import { parseAuthorityInfoAccessMethodOid as O, parseExtendedKeyUsageOid as k } from "./extensions.js";
|
|
12
|
+
import { decodeAndApplyKnownExtension as A } from "../internal/x509/extension-registry.js";
|
|
13
13
|
//#region src/x509/parse.ts
|
|
14
14
|
/**
|
|
15
15
|
* Certificate and CSR parse boundary.
|
|
@@ -22,15 +22,15 @@ import { decodeAndApplyKnownExtension } from "../internal/x509/extension-registr
|
|
|
22
22
|
* @module
|
|
23
23
|
*/
|
|
24
24
|
/** Shared UTF-8 decoder for IA5String / UTF8String values. */
|
|
25
|
-
const
|
|
25
|
+
const j = new TextDecoder();
|
|
26
26
|
/**
|
|
27
27
|
* Identity helper that narrows the type of a custom {@linkcode ExtensionDecoder} literal.
|
|
28
28
|
*
|
|
29
29
|
* @param decoder Decoder definition to return unchanged.
|
|
30
30
|
* @returns The same decoder, properly typed.
|
|
31
31
|
*/
|
|
32
|
-
function defineExtensionDecoder(
|
|
33
|
-
return
|
|
32
|
+
function defineExtensionDecoder(e) {
|
|
33
|
+
return e;
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
36
|
* Identity helper that narrows the type of a custom {@linkcode ExtensionDecoderMap} literal.
|
|
@@ -38,8 +38,8 @@ function defineExtensionDecoder(decoder) {
|
|
|
38
38
|
* @param decoderMap Map of named decoders to return unchanged.
|
|
39
39
|
* @returns The same map, properly typed.
|
|
40
40
|
*/
|
|
41
|
-
function defineExtensionDecoderMap(
|
|
42
|
-
return
|
|
41
|
+
function defineExtensionDecoderMap(e) {
|
|
42
|
+
return e;
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
45
45
|
* Throwing core for {@linkcode parseCertificateDer}.
|
|
@@ -52,94 +52,99 @@ function defineExtensionDecoderMap(decoderMap) {
|
|
|
52
52
|
* @param der Raw DER bytes of an X.509 certificate.
|
|
53
53
|
* @param options Custom extension decoders to apply during parsing.
|
|
54
54
|
*/
|
|
55
|
-
function parseCertificateDerOrThrow(
|
|
56
|
-
|
|
57
|
-
if (
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
55
|
+
function parseCertificateDerOrThrow(e, t) {
|
|
56
|
+
let n = r(e, { maxDepth: 64 });
|
|
57
|
+
if (n.length !== 3) throw Error("Malformed Certificate");
|
|
58
|
+
let i = f(n[0], "TBSCertificate"), a = f(n[1], "signatureAlgorithm"), o = f(n[2], "signatureValue"), s = parseTbsCertificateFields(e, i), c = parseExtensionContainer(e, s.extensions), l = parseValidity(e, s.validity), d = parseSubjectPublicKeyInfo(e, s.subjectPublicKeyInfo), m = parseAlgorithmIdentifier(e, s.tbsSignatureAlgorithm), h = parseAlgorithmIdentifier(e, a);
|
|
59
|
+
assertMatchingCertificateSignatureAlgorithms(m, h);
|
|
60
|
+
let g = parseCustomExtensions(c.all, t);
|
|
61
|
+
return {
|
|
62
|
+
der: new Uint8Array(e),
|
|
63
|
+
version: s.version,
|
|
64
|
+
serialNumberHex: p(s.serialNumber.value),
|
|
65
|
+
tbsCertificateDer: e.slice(i.start - i.headerLength, i.end),
|
|
66
|
+
subjectPublicKeyInfoDer: e.slice(s.subjectPublicKeyInfo.start - s.subjectPublicKeyInfo.headerLength, s.subjectPublicKeyInfo.end),
|
|
67
|
+
signatureValue: u(o),
|
|
68
|
+
issuer: parseName(e, s.issuer),
|
|
69
|
+
subject: parseName(e, s.subject),
|
|
70
|
+
notBefore: l.notBefore,
|
|
71
|
+
notAfter: l.notAfter,
|
|
72
|
+
signatureAlgorithmOid: h.oid,
|
|
73
|
+
signatureAlgorithmName: C(h.oid, h.parametersDer),
|
|
74
|
+
...h.parametersDer === void 0 ? {} : { signatureAlgorithmParametersDer: h.parametersDer },
|
|
75
|
+
publicKeyAlgorithmOid: d.oid,
|
|
76
|
+
publicKeyAlgorithmName: S(d.oid, d.parametersOid),
|
|
77
|
+
...d.parametersDer === void 0 ? {} : { publicKeyAlgorithmParametersDer: d.parametersDer },
|
|
78
|
+
...d.parametersOid === void 0 ? {} : { publicKeyParametersOid: d.parametersOid },
|
|
79
|
+
extensions: c.all,
|
|
80
|
+
...c.basicConstraints === void 0 ? {} : { basicConstraints: c.basicConstraints },
|
|
81
|
+
...c.keyUsage === void 0 ? {} : { keyUsage: c.keyUsage },
|
|
82
|
+
...c.extendedKeyUsage === void 0 ? {} : { extendedKeyUsage: c.extendedKeyUsage },
|
|
83
|
+
...c.subjectAltNames === void 0 ? {} : { subjectAltNames: c.subjectAltNames },
|
|
84
|
+
...c.nameConstraints === void 0 ? {} : { nameConstraints: c.nameConstraints },
|
|
85
|
+
...c.certificatePolicies === void 0 ? {} : { certificatePolicies: c.certificatePolicies },
|
|
86
|
+
...c.policyMappings === void 0 ? {} : { policyMappings: c.policyMappings },
|
|
87
|
+
...c.policyConstraints === void 0 ? {} : { policyConstraints: c.policyConstraints },
|
|
88
|
+
...c.inhibitAnyPolicy === void 0 ? {} : { inhibitAnyPolicy: c.inhibitAnyPolicy },
|
|
89
|
+
...c.authorityInfoAccess === void 0 ? {} : { authorityInfoAccess: c.authorityInfoAccess },
|
|
90
|
+
...c.crlDistributionPoints === void 0 ? {} : { crlDistributionPoints: c.crlDistributionPoints },
|
|
91
|
+
...g.decodedExtensions === void 0 ? {} : { decodedExtensions: g.decodedExtensions },
|
|
92
|
+
...g.decodedExtensionMap === void 0 ? {} : { decodedExtensionMap: g.decodedExtensionMap },
|
|
93
|
+
...c.subjectKeyIdentifier === void 0 ? {} : { subjectKeyIdentifier: c.subjectKeyIdentifier },
|
|
94
|
+
...c.authorityKeyIdentifier === void 0 ? {} : { authorityKeyIdentifier: c.authorityKeyIdentifier }
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function parseCustomExtensions(e, t) {
|
|
98
|
+
return {
|
|
99
|
+
...t?.decoders === void 0 ? {} : { decodedExtensions: decodeExtensions(e, t.decoders) },
|
|
100
|
+
...t?.decoderMap === void 0 ? {} : { decodedExtensionMap: decodeExtensionMap(e, t.decoderMap) }
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/** Extracts and validates the structural fields of a TBSCertificate sequence. */
|
|
104
|
+
function parseTbsCertificateFields(e, t) {
|
|
105
|
+
let n = i(e, t), r = parseCertificateVersionField(e, n), a = r.version, o = r.nextIndex, s = f(n[o], "serialNumber");
|
|
106
|
+
if (s.tag !== 2) throw Error("serialNumber must use INTEGER");
|
|
107
|
+
let c = validateOptionalTbsCertificateFields(n, o + 6, a);
|
|
107
108
|
return {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
notBefore: parsedValidity.notBefore,
|
|
117
|
-
notAfter: parsedValidity.notAfter,
|
|
118
|
-
signatureAlgorithmOid: parsedSignatureAlgorithm.oid,
|
|
119
|
-
signatureAlgorithmName: describeSignatureAlgorithm(parsedSignatureAlgorithm.oid, parsedSignatureAlgorithm.parametersDer),
|
|
120
|
-
...parsedSignatureAlgorithm.parametersDer !== void 0 ? { signatureAlgorithmParametersDer: parsedSignatureAlgorithm.parametersDer } : {},
|
|
121
|
-
publicKeyAlgorithmOid: parsedSpki.oid,
|
|
122
|
-
publicKeyAlgorithmName: describePublicKeyAlgorithm(parsedSpki.oid, parsedSpki.parametersOid),
|
|
123
|
-
...parsedSpki.parametersDer !== void 0 ? { publicKeyAlgorithmParametersDer: parsedSpki.parametersDer } : {},
|
|
124
|
-
...parsedSpki.parametersOid !== void 0 ? { publicKeyParametersOid: parsedSpki.parametersOid } : {},
|
|
125
|
-
extensions: parsedExtensions.all,
|
|
126
|
-
...parsedExtensions.basicConstraints !== void 0 ? { basicConstraints: parsedExtensions.basicConstraints } : {},
|
|
127
|
-
...parsedExtensions.keyUsage !== void 0 ? { keyUsage: parsedExtensions.keyUsage } : {},
|
|
128
|
-
...parsedExtensions.extendedKeyUsage !== void 0 ? { extendedKeyUsage: parsedExtensions.extendedKeyUsage } : {},
|
|
129
|
-
...parsedExtensions.subjectAltNames !== void 0 ? { subjectAltNames: parsedExtensions.subjectAltNames } : {},
|
|
130
|
-
...parsedExtensions.nameConstraints !== void 0 ? { nameConstraints: parsedExtensions.nameConstraints } : {},
|
|
131
|
-
...parsedExtensions.certificatePolicies !== void 0 ? { certificatePolicies: parsedExtensions.certificatePolicies } : {},
|
|
132
|
-
...parsedExtensions.policyMappings !== void 0 ? { policyMappings: parsedExtensions.policyMappings } : {},
|
|
133
|
-
...parsedExtensions.policyConstraints !== void 0 ? { policyConstraints: parsedExtensions.policyConstraints } : {},
|
|
134
|
-
...parsedExtensions.inhibitAnyPolicy !== void 0 ? { inhibitAnyPolicy: parsedExtensions.inhibitAnyPolicy } : {},
|
|
135
|
-
...parsedExtensions.authorityInfoAccess !== void 0 ? { authorityInfoAccess: parsedExtensions.authorityInfoAccess } : {},
|
|
136
|
-
...parsedExtensions.crlDistributionPoints !== void 0 ? { crlDistributionPoints: parsedExtensions.crlDistributionPoints } : {},
|
|
137
|
-
...decodedExtensions !== void 0 ? { decodedExtensions } : {},
|
|
138
|
-
...decodedExtensionMap !== void 0 ? { decodedExtensionMap } : {},
|
|
139
|
-
...parsedExtensions.subjectKeyIdentifier !== void 0 ? { subjectKeyIdentifier: parsedExtensions.subjectKeyIdentifier } : {},
|
|
140
|
-
...parsedExtensions.authorityKeyIdentifier !== void 0 ? { authorityKeyIdentifier: parsedExtensions.authorityKeyIdentifier } : {}
|
|
109
|
+
version: a,
|
|
110
|
+
serialNumber: s,
|
|
111
|
+
tbsSignatureAlgorithm: f(n[o + 1], "TBSCertificate signature"),
|
|
112
|
+
issuer: f(n[o + 2], "issuer"),
|
|
113
|
+
validity: f(n[o + 3], "validity"),
|
|
114
|
+
subject: f(n[o + 4], "subject"),
|
|
115
|
+
subjectPublicKeyInfo: f(n[o + 5], "subjectPublicKeyInfo"),
|
|
116
|
+
...n[c - 1]?.tag === 163 ? { extensions: n[c - 1] } : {}
|
|
141
117
|
};
|
|
142
118
|
}
|
|
119
|
+
function parseCertificateVersionField(e, t) {
|
|
120
|
+
let n = t[0];
|
|
121
|
+
if (n?.tag !== 160) return {
|
|
122
|
+
version: 1,
|
|
123
|
+
nextIndex: 0
|
|
124
|
+
};
|
|
125
|
+
let r = i(e, n), a = f(r[0], "version INTEGER");
|
|
126
|
+
if (r.length !== 1 || a.tag !== 2) throw Error("version must use INTEGER");
|
|
127
|
+
let s = o(a.value) + 1;
|
|
128
|
+
if (s < 1 || s > 3) throw Error(`Unsupported certificate version: ${String(s)}`);
|
|
129
|
+
return {
|
|
130
|
+
version: s,
|
|
131
|
+
nextIndex: 1
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function validateOptionalTbsCertificateFields(e, t, n) {
|
|
135
|
+
let r = t;
|
|
136
|
+
if (e[r]?.tag === 129 && (validateCertificateUniqueId(e[r], n, "issuerUniqueID"), r += 1), e[r]?.tag === 130 && (validateCertificateUniqueId(e[r], n, "subjectUniqueID"), r += 1), e[r]?.tag === 163) {
|
|
137
|
+
if (n !== 3) throw Error("extensions require certificate version 3");
|
|
138
|
+
r += 1;
|
|
139
|
+
}
|
|
140
|
+
if (r !== e.length) throw Error(`Unsupported TBSCertificate field tag: ${String(f(e[r], "TBSCertificate field").tag)}`);
|
|
141
|
+
return r;
|
|
142
|
+
}
|
|
143
|
+
function validateCertificateUniqueId(e, t, n) {
|
|
144
|
+
let r = f(e, n);
|
|
145
|
+
if (t < 2) throw Error(`${n} requires certificate version 2 or 3`);
|
|
146
|
+
validateImplicitBitStringContent(r.value, n);
|
|
147
|
+
}
|
|
143
148
|
/**
|
|
144
149
|
* Decode a DER-encoded X.509 certificate into a {@linkcode ParsedCertificate}.
|
|
145
150
|
*
|
|
@@ -156,12 +161,11 @@ function parseCertificateDerOrThrow(der, options) {
|
|
|
156
161
|
* @param der Raw DER bytes of an X.509 certificate.
|
|
157
162
|
* @param options Custom extension decoders to apply during parsing.
|
|
158
163
|
*/
|
|
159
|
-
function parseCertificateDer(
|
|
164
|
+
function parseCertificateDer(e, t) {
|
|
160
165
|
try {
|
|
161
|
-
return
|
|
162
|
-
} catch (
|
|
163
|
-
|
|
164
|
-
return failureResult("malformed", error instanceof Error ? error.message : "Malformed certificate");
|
|
166
|
+
return _(parseCertificateDerOrThrow(e, t));
|
|
167
|
+
} catch (e) {
|
|
168
|
+
return g(e), h("malformed", e instanceof Error ? e.message : "Malformed certificate");
|
|
165
169
|
}
|
|
166
170
|
}
|
|
167
171
|
/**
|
|
@@ -182,8 +186,8 @@ function parseCertificateDer(der, options) {
|
|
|
182
186
|
* @param pem PEM string with a CERTIFICATE block.
|
|
183
187
|
* @param options Custom extension decoders to apply during parsing.
|
|
184
188
|
*/
|
|
185
|
-
function parseCertificatePemOrThrow(
|
|
186
|
-
return parseCertificateDerOrThrow(
|
|
189
|
+
function parseCertificatePemOrThrow(e, t) {
|
|
190
|
+
return parseCertificateDerOrThrow(v("CERTIFICATE", e), t);
|
|
187
191
|
}
|
|
188
192
|
/**
|
|
189
193
|
* Decode a PEM-encoded X.509 certificate into a {@linkcode ParsedCertificate}.
|
|
@@ -194,23 +198,20 @@ function parseCertificatePemOrThrow(pem, options) {
|
|
|
194
198
|
* @param pem PEM string with a CERTIFICATE block.
|
|
195
199
|
* @param options Custom extension decoders to apply during parsing.
|
|
196
200
|
*/
|
|
197
|
-
function parseCertificatePem(
|
|
201
|
+
function parseCertificatePem(e, t) {
|
|
198
202
|
try {
|
|
199
|
-
return
|
|
200
|
-
} catch (
|
|
201
|
-
|
|
202
|
-
return failureResult("malformed", error instanceof Error ? error.message : "Malformed certificate");
|
|
203
|
+
return _(parseCertificatePemOrThrow(e, t));
|
|
204
|
+
} catch (e) {
|
|
205
|
+
return g(e), h("malformed", e instanceof Error ? e.message : "Malformed certificate");
|
|
203
206
|
}
|
|
204
207
|
}
|
|
205
208
|
/** Normalizes a PEM bundle or single DER certificate source into parsed certificates. */
|
|
206
|
-
function parseCertificatesFromSource(
|
|
207
|
-
return typeof
|
|
209
|
+
function parseCertificatesFromSource(e, t) {
|
|
210
|
+
return typeof e == "string" ? parseCertificatesFromPemBlocks(e, t) : [parseCertificateDerOrThrow(new Uint8Array(e), t)];
|
|
208
211
|
}
|
|
209
212
|
/** Normalizes a PEM, DER, or already-parsed certificate source into one parsed certificate. */
|
|
210
|
-
function parseCertificateFromSource(
|
|
211
|
-
|
|
212
|
-
if (hasParsedCertificateShape(source)) return source;
|
|
213
|
-
return parseCertificateDerOrThrow(new Uint8Array(source), options);
|
|
213
|
+
function parseCertificateFromSource(e, t) {
|
|
214
|
+
return typeof e == "string" ? parseCertificatePemOrThrow(e, t) : hasParsedCertificateShape(e) ? e : parseCertificateDerOrThrow(new Uint8Array(e), t);
|
|
214
215
|
}
|
|
215
216
|
/**
|
|
216
217
|
* Decode a PEM bundle containing one or more certificates.
|
|
@@ -220,8 +221,8 @@ function parseCertificateFromSource(source, options) {
|
|
|
220
221
|
* @param pemBundle PEM text that may contain multiple CERTIFICATE blocks.
|
|
221
222
|
* @param options Custom extension decoders to apply during parsing.
|
|
222
223
|
*/
|
|
223
|
-
function parseCertificateChainPem(
|
|
224
|
-
return parseCertificatesFromPemBlocks(
|
|
224
|
+
function parseCertificateChainPem(e, t) {
|
|
225
|
+
return parseCertificatesFromPemBlocks(e, t);
|
|
225
226
|
}
|
|
226
227
|
/**
|
|
227
228
|
* Decode a DER-encoded PKCS#10 CSR into a {@linkcode ParsedCertificateSigningRequest}.
|
|
@@ -229,54 +230,53 @@ function parseCertificateChainPem(pemBundle, options) {
|
|
|
229
230
|
* @param der Raw DER bytes of a PKCS#10 certificate signing request.
|
|
230
231
|
* @param options Custom extension decoders to apply during parsing.
|
|
231
232
|
*/
|
|
232
|
-
function parseCertificateSigningRequestDerOrThrow(
|
|
233
|
-
|
|
234
|
-
if (
|
|
235
|
-
|
|
236
|
-
const signatureAlgorithm = requireElement(topLevel[1], "signatureAlgorithm");
|
|
237
|
-
const signatureValue = requireElement(topLevel[2], "signatureValue");
|
|
238
|
-
const criChildren = childrenOf(der, certificationRequestInfo);
|
|
239
|
-
if (criChildren.length < 3 || criChildren.length > 4) throw new Error("Malformed CertificationRequestInfo");
|
|
240
|
-
const versionElement = requireElement(criChildren[0], "version");
|
|
241
|
-
if (versionElement.tag !== 2) throw new Error("version must use INTEGER");
|
|
242
|
-
const version = decodeIntegerNumber(versionElement.value) + 1;
|
|
243
|
-
if (version !== 1) throw new Error(`Unsupported CertificationRequestInfo version: ${String(version)}`);
|
|
244
|
-
const subject = requireElement(criChildren[1], "subject");
|
|
245
|
-
const subjectPublicKeyInfo = requireElement(criChildren[2], "subjectPublicKeyInfo");
|
|
246
|
-
const attributes = criChildren[3];
|
|
247
|
-
if (attributes !== void 0 && attributes.tag !== 160) throw new Error("CertificationRequestInfo attributes must use [0]");
|
|
248
|
-
const parsedExtensions = parseRequestedExtensions(der, attributes);
|
|
249
|
-
const parsedSpki = parseSubjectPublicKeyInfo(der, subjectPublicKeyInfo);
|
|
250
|
-
const parsedSignatureAlgorithm = parseAlgorithmIdentifier(der, signatureAlgorithm);
|
|
251
|
-
const decodedExtensions = options?.decoders === void 0 ? void 0 : decodeExtensions(parsedExtensions.all, options.decoders);
|
|
252
|
-
const decodedExtensionMap = options?.decoderMap === void 0 ? void 0 : decodeExtensionMap(parsedExtensions.all, options.decoderMap);
|
|
233
|
+
function parseCertificateSigningRequestDerOrThrow(e, t) {
|
|
234
|
+
let n = r(e, { maxDepth: 64 });
|
|
235
|
+
if (n.length !== 3) throw Error("Malformed CertificationRequest");
|
|
236
|
+
let i = f(n[0], "CertificationRequestInfo"), a = f(n[1], "signatureAlgorithm"), o = f(n[2], "signatureValue"), s = parseCertificationRequestInfoFields(e, i), c = parseRequestedExtensions(e, s.attributes), l = parseSubjectPublicKeyInfo(e, s.subjectPublicKeyInfo), d = parseAlgorithmIdentifier(e, a), p = parseCustomExtensions(c.all, t);
|
|
253
237
|
return {
|
|
254
|
-
version,
|
|
255
|
-
certificationRequestInfoDer:
|
|
256
|
-
subjectPublicKeyInfoDer:
|
|
257
|
-
signatureValue:
|
|
258
|
-
subject: parseName(
|
|
259
|
-
signatureAlgorithmOid:
|
|
260
|
-
signatureAlgorithmName:
|
|
261
|
-
...
|
|
262
|
-
publicKeyAlgorithmOid:
|
|
263
|
-
publicKeyAlgorithmName:
|
|
264
|
-
...
|
|
265
|
-
...
|
|
266
|
-
requestedExtensions:
|
|
267
|
-
...
|
|
268
|
-
...
|
|
269
|
-
...
|
|
270
|
-
...
|
|
271
|
-
...
|
|
272
|
-
...
|
|
273
|
-
...
|
|
274
|
-
...
|
|
275
|
-
...
|
|
276
|
-
...
|
|
277
|
-
...
|
|
278
|
-
...decodedExtensions
|
|
279
|
-
...decodedExtensionMap
|
|
238
|
+
version: s.version,
|
|
239
|
+
certificationRequestInfoDer: e.slice(i.start - i.headerLength, i.end),
|
|
240
|
+
subjectPublicKeyInfoDer: e.slice(s.subjectPublicKeyInfo.start - s.subjectPublicKeyInfo.headerLength, s.subjectPublicKeyInfo.end),
|
|
241
|
+
signatureValue: u(o),
|
|
242
|
+
subject: parseName(e, s.subject),
|
|
243
|
+
signatureAlgorithmOid: d.oid,
|
|
244
|
+
signatureAlgorithmName: C(d.oid, d.parametersDer),
|
|
245
|
+
...d.parametersDer === void 0 ? {} : { signatureAlgorithmParametersDer: d.parametersDer },
|
|
246
|
+
publicKeyAlgorithmOid: l.oid,
|
|
247
|
+
publicKeyAlgorithmName: S(l.oid, l.parametersOid),
|
|
248
|
+
...l.parametersDer === void 0 ? {} : { publicKeyAlgorithmParametersDer: l.parametersDer },
|
|
249
|
+
...l.parametersOid === void 0 ? {} : { publicKeyParametersOid: l.parametersOid },
|
|
250
|
+
requestedExtensions: c.all,
|
|
251
|
+
...c.basicConstraints === void 0 ? {} : { basicConstraints: c.basicConstraints },
|
|
252
|
+
...c.keyUsage === void 0 ? {} : { keyUsage: c.keyUsage },
|
|
253
|
+
...c.extendedKeyUsage === void 0 ? {} : { extendedKeyUsage: c.extendedKeyUsage },
|
|
254
|
+
...c.subjectAltNames === void 0 ? {} : { subjectAltNames: c.subjectAltNames },
|
|
255
|
+
...c.nameConstraints === void 0 ? {} : { nameConstraints: c.nameConstraints },
|
|
256
|
+
...c.certificatePolicies === void 0 ? {} : { certificatePolicies: c.certificatePolicies },
|
|
257
|
+
...c.policyMappings === void 0 ? {} : { policyMappings: c.policyMappings },
|
|
258
|
+
...c.policyConstraints === void 0 ? {} : { policyConstraints: c.policyConstraints },
|
|
259
|
+
...c.inhibitAnyPolicy === void 0 ? {} : { inhibitAnyPolicy: c.inhibitAnyPolicy },
|
|
260
|
+
...c.authorityInfoAccess === void 0 ? {} : { authorityInfoAccess: c.authorityInfoAccess },
|
|
261
|
+
...c.crlDistributionPoints === void 0 ? {} : { crlDistributionPoints: c.crlDistributionPoints },
|
|
262
|
+
...p.decodedExtensions === void 0 ? {} : { decodedExtensions: p.decodedExtensions },
|
|
263
|
+
...p.decodedExtensionMap === void 0 ? {} : { decodedExtensionMap: p.decodedExtensionMap }
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
function parseCertificationRequestInfoFields(e, t) {
|
|
267
|
+
let n = i(e, t);
|
|
268
|
+
if (n.length < 3 || n.length > 4) throw Error("Malformed CertificationRequestInfo");
|
|
269
|
+
let r = f(n[0], "version");
|
|
270
|
+
if (r.tag !== 2) throw Error("version must use INTEGER");
|
|
271
|
+
let a = o(r.value) + 1;
|
|
272
|
+
if (a !== 1) throw Error(`Unsupported CertificationRequestInfo version: ${String(a)}`);
|
|
273
|
+
let s = n[3];
|
|
274
|
+
if (s !== void 0 && s.tag !== 160) throw Error("CertificationRequestInfo attributes must use [0]");
|
|
275
|
+
return {
|
|
276
|
+
version: a,
|
|
277
|
+
subject: f(n[1], "subject"),
|
|
278
|
+
subjectPublicKeyInfo: f(n[2], "subjectPublicKeyInfo"),
|
|
279
|
+
...s === void 0 ? {} : { attributes: s }
|
|
280
280
|
};
|
|
281
281
|
}
|
|
282
282
|
/**
|
|
@@ -285,19 +285,18 @@ function parseCertificateSigningRequestDerOrThrow(der, options) {
|
|
|
285
285
|
* @param der Raw DER bytes of a PKCS#10 certificate signing request.
|
|
286
286
|
* @param options Custom extension decoders to apply during parsing.
|
|
287
287
|
*/
|
|
288
|
-
function parseCertificateSigningRequestDer(
|
|
288
|
+
function parseCertificateSigningRequestDer(e, t) {
|
|
289
289
|
try {
|
|
290
|
-
return
|
|
291
|
-
} catch (
|
|
292
|
-
|
|
293
|
-
return failureResult("malformed", error instanceof Error ? error.message : "Malformed certificate signing request");
|
|
290
|
+
return _(parseCertificateSigningRequestDerOrThrow(e, t));
|
|
291
|
+
} catch (e) {
|
|
292
|
+
return g(e), h("malformed", e instanceof Error ? e.message : "Malformed certificate signing request");
|
|
294
293
|
}
|
|
295
294
|
}
|
|
296
|
-
function parseCertificatesFromPemBlocks(
|
|
297
|
-
return
|
|
295
|
+
function parseCertificatesFromPemBlocks(e, t) {
|
|
296
|
+
return y(e).filter((e) => e.label === "CERTIFICATE").map((e) => parseCertificateDerOrThrow(e.bytes, t));
|
|
298
297
|
}
|
|
299
|
-
function hasParsedCertificateShape(
|
|
300
|
-
return "subjectPublicKeyInfoDer" in
|
|
298
|
+
function hasParsedCertificateShape(e) {
|
|
299
|
+
return "subjectPublicKeyInfoDer" in e;
|
|
301
300
|
}
|
|
302
301
|
/**
|
|
303
302
|
* Decode a PEM-encoded PKCS#10 CSR into a {@linkcode ParsedCertificateSigningRequest}.
|
|
@@ -305,8 +304,8 @@ function hasParsedCertificateShape(value) {
|
|
|
305
304
|
* @param pem PEM string with a CERTIFICATE REQUEST block.
|
|
306
305
|
* @param options Custom extension decoders to apply during parsing.
|
|
307
306
|
*/
|
|
308
|
-
function parseCertificateSigningRequestPemOrThrow(
|
|
309
|
-
return parseCertificateSigningRequestDerOrThrow(
|
|
307
|
+
function parseCertificateSigningRequestPemOrThrow(e, t) {
|
|
308
|
+
return parseCertificateSigningRequestDerOrThrow(v("CERTIFICATE REQUEST", e), t);
|
|
310
309
|
}
|
|
311
310
|
/**
|
|
312
311
|
* Decode a PEM-encoded PKCS#10 CSR into a {@linkcode ParsedCertificateSigningRequest}.
|
|
@@ -314,12 +313,11 @@ function parseCertificateSigningRequestPemOrThrow(pem, options) {
|
|
|
314
313
|
* @param pem PEM string with a CERTIFICATE REQUEST block.
|
|
315
314
|
* @param options Custom extension decoders to apply during parsing.
|
|
316
315
|
*/
|
|
317
|
-
function parseCertificateSigningRequestPem(
|
|
316
|
+
function parseCertificateSigningRequestPem(e, t) {
|
|
318
317
|
try {
|
|
319
|
-
return
|
|
320
|
-
} catch (
|
|
321
|
-
|
|
322
|
-
return failureResult("malformed", error instanceof Error ? error.message : "Malformed certificate signing request");
|
|
318
|
+
return _(parseCertificateSigningRequestPemOrThrow(e, t));
|
|
319
|
+
} catch (e) {
|
|
320
|
+
return g(e), h("malformed", e instanceof Error ? e.message : "Malformed certificate signing request");
|
|
323
321
|
}
|
|
324
322
|
}
|
|
325
323
|
/**
|
|
@@ -350,16 +348,16 @@ function parseCertificateSigningRequestPem(pem, options) {
|
|
|
350
348
|
*
|
|
351
349
|
* @see {@linkcode getSubjectPublicKey} for the non-throwing variant
|
|
352
350
|
*/
|
|
353
|
-
function getSubjectPublicKeyOrThrow(
|
|
354
|
-
return
|
|
351
|
+
function getSubjectPublicKeyOrThrow(e, t) {
|
|
352
|
+
return x(e.subjectPublicKeyInfoDer, t);
|
|
355
353
|
}
|
|
356
354
|
/**
|
|
357
355
|
* Import the subject public key of a parsed certificate or CSR as a WebCrypto `CryptoKey`.
|
|
358
356
|
*
|
|
359
357
|
* @see `getSubjectPublicKeyOrThrow` for the throwing variant
|
|
360
358
|
*/
|
|
361
|
-
function getSubjectPublicKey(
|
|
362
|
-
return
|
|
359
|
+
function getSubjectPublicKey(e, t) {
|
|
360
|
+
return b(e.subjectPublicKeyInfoDer, t);
|
|
363
361
|
}
|
|
364
362
|
/**
|
|
365
363
|
* Find a raw extension by OID within a parsed extension list.
|
|
@@ -368,8 +366,8 @@ function getSubjectPublicKey(parsed, algorithm) {
|
|
|
368
366
|
* @param oid Dotted-decimal OID to look up.
|
|
369
367
|
* @returns The matching extension, or `undefined` if not present.
|
|
370
368
|
*/
|
|
371
|
-
function findExtension(
|
|
372
|
-
return
|
|
369
|
+
function findExtension(e, t) {
|
|
370
|
+
return e.find((e) => e.oid === t);
|
|
373
371
|
}
|
|
374
372
|
/**
|
|
375
373
|
* Decode a single extension using a custom {@linkcode ExtensionDecoder}.
|
|
@@ -378,10 +376,9 @@ function findExtension(extensions, oid) {
|
|
|
378
376
|
* @param decoder Decoder whose OID will be matched.
|
|
379
377
|
* @returns The decoded value, or `undefined` if the extension is absent.
|
|
380
378
|
*/
|
|
381
|
-
function decodeExtension(
|
|
382
|
-
|
|
383
|
-
if (
|
|
384
|
-
return decoder.decode(extension);
|
|
379
|
+
function decodeExtension(e, t) {
|
|
380
|
+
let n = findExtension(e, t.oid);
|
|
381
|
+
if (n !== void 0) return t.decode(n);
|
|
385
382
|
}
|
|
386
383
|
/**
|
|
387
384
|
* Decode all matching extensions using an array of {@linkcode ExtensionDecoder}s.
|
|
@@ -389,18 +386,17 @@ function decodeExtension(extensions, decoder) {
|
|
|
389
386
|
* @param extensions Extension list to search.
|
|
390
387
|
* @param decoders Decoders to apply. Only matching OIDs produce output.
|
|
391
388
|
*/
|
|
392
|
-
function decodeExtensions(
|
|
393
|
-
|
|
394
|
-
for (
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
value: decoder.decode(extension)
|
|
389
|
+
function decodeExtensions(e, t) {
|
|
390
|
+
let n = [];
|
|
391
|
+
for (let r of t) {
|
|
392
|
+
let t = findExtension(e, r.oid);
|
|
393
|
+
t !== void 0 && n.push({
|
|
394
|
+
oid: t.oid,
|
|
395
|
+
critical: t.critical,
|
|
396
|
+
value: r.decode(t)
|
|
401
397
|
});
|
|
402
398
|
}
|
|
403
|
-
return
|
|
399
|
+
return n;
|
|
404
400
|
}
|
|
405
401
|
/**
|
|
406
402
|
* Decode all matching extensions using a named {@linkcode ExtensionDecoderMap}.
|
|
@@ -408,488 +404,446 @@ function decodeExtensions(extensions, decoders) {
|
|
|
408
404
|
* @param extensions Extension list to search.
|
|
409
405
|
* @param decoderMap Named decoders. Results are keyed by the same map keys.
|
|
410
406
|
*/
|
|
411
|
-
function decodeExtensionMap(
|
|
412
|
-
let
|
|
413
|
-
for (
|
|
414
|
-
|
|
415
|
-
if (
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
value: decoder.decode(extension)
|
|
407
|
+
function decodeExtensionMap(e, t) {
|
|
408
|
+
let n = {};
|
|
409
|
+
for (let r in t) {
|
|
410
|
+
let i = t[r];
|
|
411
|
+
if (i === void 0) continue;
|
|
412
|
+
let a = findExtension(e, i.oid);
|
|
413
|
+
a !== void 0 && (n = {
|
|
414
|
+
...n,
|
|
415
|
+
[r]: {
|
|
416
|
+
oid: a.oid,
|
|
417
|
+
critical: a.critical,
|
|
418
|
+
value: i.decode(a)
|
|
424
419
|
}
|
|
425
|
-
};
|
|
420
|
+
});
|
|
426
421
|
}
|
|
427
|
-
return
|
|
422
|
+
return n;
|
|
428
423
|
}
|
|
429
424
|
/** Decode the explicit [3] extensions wrapper from a TBSCertificate. */
|
|
430
|
-
function parseExtensionContainer(
|
|
431
|
-
|
|
432
|
-
return parseExtensionSequence(source, requireElement(childrenOf(source, container)[0], "extensions sequence"), "certificate");
|
|
425
|
+
function parseExtensionContainer(e, t) {
|
|
426
|
+
return t === void 0 ? { all: [] } : parseExtensionSequence(e, f(i(e, t)[0], "extensions sequence"), "certificate");
|
|
433
427
|
}
|
|
434
428
|
/** Extract extensions from the CSR extensionRequest attribute. */
|
|
435
|
-
function parseRequestedExtensions(
|
|
436
|
-
if (
|
|
437
|
-
if (
|
|
438
|
-
let
|
|
439
|
-
for (
|
|
440
|
-
|
|
441
|
-
if (
|
|
442
|
-
if (
|
|
443
|
-
if (
|
|
444
|
-
|
|
445
|
-
if (
|
|
446
|
-
|
|
447
|
-
if (
|
|
448
|
-
|
|
429
|
+
function parseRequestedExtensions(e, t) {
|
|
430
|
+
if (t === void 0) return { all: [] };
|
|
431
|
+
if (t.tag !== 160) throw Error("CertificationRequestInfo attributes must use [0]");
|
|
432
|
+
let n;
|
|
433
|
+
for (let r of i(e, t)) {
|
|
434
|
+
let t = i(e, r);
|
|
435
|
+
if (t.length !== 2) throw Error("Malformed CSR attribute");
|
|
436
|
+
if (c(f(t[0], "attribute OID").value) !== m.extensionRequest) continue;
|
|
437
|
+
if (n !== void 0) throw Error("extensionRequest attribute must not repeat");
|
|
438
|
+
let a = f(t[1], "attribute values");
|
|
439
|
+
if (a.tag !== 49) throw Error("extensionRequest attribute values must use SET");
|
|
440
|
+
let o = i(e, a);
|
|
441
|
+
if (o.length !== 1) throw Error("extensionRequest attribute must contain exactly one value");
|
|
442
|
+
n = parseExtensionSequence(e, f(o[0], "requested extensions"), "csr");
|
|
449
443
|
}
|
|
450
|
-
return
|
|
444
|
+
return n ?? { all: [] };
|
|
451
445
|
}
|
|
452
446
|
/** Walk a SEQUENCE OF Extension and decode each one, populating known-extension slots. */
|
|
453
|
-
function parseExtensionSequence(
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
if (
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
let
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
critical
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
if (extnValue.tag !== 4 || offset !== children.length - 1) throw new Error("Extension value must use OCTET STRING");
|
|
472
|
-
parsed.push({
|
|
473
|
-
oid,
|
|
474
|
-
critical,
|
|
475
|
-
valueDer: new Uint8Array(extnValue.value),
|
|
476
|
-
valueHex: toHex(extnValue.value)
|
|
477
|
-
});
|
|
478
|
-
decodeAndApplyKnownExtension(context, oid, knownParsed, extnValue.value);
|
|
447
|
+
function parseExtensionSequence(e, t, n) {
|
|
448
|
+
let r = [], o = {}, s = /* @__PURE__ */ new Set();
|
|
449
|
+
for (let l of i(e, t)) {
|
|
450
|
+
let t = i(e, l);
|
|
451
|
+
if (t.length < 2 || t.length > 3) throw Error("Malformed Extension");
|
|
452
|
+
let u = c(f(t[0], "extension OID").value);
|
|
453
|
+
if (s.has(u)) throw Error(`Duplicate extension OID: ${u}`);
|
|
454
|
+
s.add(u);
|
|
455
|
+
let d = 1, m = !1, h = t[d];
|
|
456
|
+
h?.tag === 1 && (m = a(h.value), d += 1);
|
|
457
|
+
let g = f(t[d], "extension value");
|
|
458
|
+
if (g.tag !== 4 || d !== t.length - 1) throw Error("Extension value must use OCTET STRING");
|
|
459
|
+
r.push({
|
|
460
|
+
oid: u,
|
|
461
|
+
critical: m,
|
|
462
|
+
valueDer: new Uint8Array(g.value),
|
|
463
|
+
valueHex: p(g.value)
|
|
464
|
+
}), A(n, u, o, g.value);
|
|
479
465
|
}
|
|
480
466
|
return {
|
|
481
|
-
all:
|
|
482
|
-
...
|
|
467
|
+
all: r,
|
|
468
|
+
...o
|
|
483
469
|
};
|
|
484
470
|
}
|
|
485
471
|
/** Decode an X.501 Name (issuer / subject) into a {@linkcode ParsedName}. */
|
|
486
|
-
function parseName(
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
rdns.push(rdn);
|
|
493
|
-
for (const attribute of rdn.attributes) {
|
|
494
|
-
attributes.push(attribute);
|
|
495
|
-
if (attribute.key !== void 0 && values[attribute.key] === void 0) values[attribute.key] = attribute.value;
|
|
496
|
-
}
|
|
472
|
+
function parseName(e, t) {
|
|
473
|
+
let n = [], r = [], a = {};
|
|
474
|
+
for (let o of i(e, t)) {
|
|
475
|
+
let t = parseNameAttributeSet(e, o);
|
|
476
|
+
n.push(t);
|
|
477
|
+
for (let e of t.attributes) r.push(e), e.key !== void 0 && a[e.key] === void 0 && (a[e.key] = e.value);
|
|
497
478
|
}
|
|
498
479
|
return {
|
|
499
|
-
derHex:
|
|
500
|
-
rdns,
|
|
501
|
-
attributes,
|
|
502
|
-
values
|
|
480
|
+
derHex: p(e.slice(t.start - t.headerLength, t.end)),
|
|
481
|
+
rdns: n,
|
|
482
|
+
attributes: r,
|
|
483
|
+
values: a
|
|
503
484
|
};
|
|
504
485
|
}
|
|
505
486
|
/** Decode a single RDN SET element. */
|
|
506
|
-
function parseRelativeDistinguishedName(
|
|
507
|
-
return parseNameAttributeSet(
|
|
487
|
+
function parseRelativeDistinguishedName(e, t) {
|
|
488
|
+
return parseNameAttributeSet(e, t);
|
|
508
489
|
}
|
|
509
490
|
/** Decode the AttributeTypeAndValue pairs within a SET element. */
|
|
510
|
-
function parseNameAttributeSet(
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
const fieldKey = nameFieldKeyFromOid(oid);
|
|
518
|
-
const fieldValue = decodeString(valueElement.tag, valueElement.value);
|
|
519
|
-
const attribute = fieldKey !== void 0 ? {
|
|
520
|
-
oid,
|
|
521
|
-
key: fieldKey,
|
|
522
|
-
valueTag: valueElement.tag,
|
|
523
|
-
value: fieldValue
|
|
491
|
+
function parseNameAttributeSet(e, t) {
|
|
492
|
+
let n = [], r = {};
|
|
493
|
+
for (let a of i(e, t)) {
|
|
494
|
+
let t = i(e, a), o = c(f(t[0], "name OID").value), s = f(t[1], "name value"), u = D(o), d = l(s.tag, s.value), p = u === void 0 ? {
|
|
495
|
+
oid: o,
|
|
496
|
+
valueTag: s.tag,
|
|
497
|
+
value: d
|
|
524
498
|
} : {
|
|
525
|
-
oid,
|
|
526
|
-
|
|
527
|
-
|
|
499
|
+
oid: o,
|
|
500
|
+
key: u,
|
|
501
|
+
valueTag: s.tag,
|
|
502
|
+
value: d
|
|
528
503
|
};
|
|
529
|
-
|
|
530
|
-
if (fieldKey !== void 0 && values[fieldKey] === void 0) values[fieldKey] = fieldValue;
|
|
504
|
+
n.push(p), u !== void 0 && r[u] === void 0 && (r[u] = d);
|
|
531
505
|
}
|
|
532
506
|
return {
|
|
533
|
-
derHex:
|
|
534
|
-
attributes,
|
|
535
|
-
values
|
|
507
|
+
derHex: p(e.slice(t.start - t.headerLength, t.end)),
|
|
508
|
+
attributes: n,
|
|
509
|
+
values: r
|
|
536
510
|
};
|
|
537
511
|
}
|
|
538
512
|
/** Decode the Validity SEQUENCE into notBefore / notAfter Dates. */
|
|
539
|
-
function parseValidity(
|
|
540
|
-
|
|
513
|
+
function parseValidity(e, t) {
|
|
514
|
+
let n = i(e, t);
|
|
541
515
|
return {
|
|
542
|
-
notBefore:
|
|
543
|
-
notAfter:
|
|
516
|
+
notBefore: d(f(n[0], "notBefore")),
|
|
517
|
+
notAfter: d(f(n[1], "notAfter"))
|
|
544
518
|
};
|
|
545
519
|
}
|
|
546
520
|
/** Extract the algorithm identifier from a SubjectPublicKeyInfo SEQUENCE. */
|
|
547
|
-
function parseSubjectPublicKeyInfo(
|
|
548
|
-
if (
|
|
549
|
-
|
|
550
|
-
if (
|
|
551
|
-
|
|
552
|
-
if (
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
return algorithm;
|
|
521
|
+
function parseSubjectPublicKeyInfo(e, t) {
|
|
522
|
+
if (t.tag !== 48) throw Error("SubjectPublicKeyInfo must use SEQUENCE");
|
|
523
|
+
let n = i(e, t);
|
|
524
|
+
if (n.length !== 2) throw Error("SubjectPublicKeyInfo must contain algorithm and subjectPublicKey");
|
|
525
|
+
let r = f(n[0], "SPKI algorithm");
|
|
526
|
+
if (r.tag !== 48) throw Error("SubjectPublicKeyInfo algorithm must use SEQUENCE");
|
|
527
|
+
let a = parseAlgorithmIdentifier(e, r);
|
|
528
|
+
return u(f(n[1], "subjectPublicKey BIT STRING")), a;
|
|
556
529
|
}
|
|
557
530
|
/** Decode an AlgorithmIdentifier SEQUENCE (OID + optional parameters). */
|
|
558
|
-
function parseAlgorithmIdentifier(
|
|
559
|
-
|
|
560
|
-
if (
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
oid,
|
|
572
|
-
parametersDer
|
|
531
|
+
function parseAlgorithmIdentifier(e, t) {
|
|
532
|
+
let n = i(e, t);
|
|
533
|
+
if (n.length === 0 || n.length > 2) throw Error("Malformed AlgorithmIdentifier");
|
|
534
|
+
let r = c(f(n[0], "algorithm OID").value), a = n[1];
|
|
535
|
+
if (a === void 0) return { oid: r };
|
|
536
|
+
let o = e.slice(a.start - a.headerLength, a.end);
|
|
537
|
+
return a?.tag === 6 ? {
|
|
538
|
+
oid: r,
|
|
539
|
+
parametersDer: o,
|
|
540
|
+
parametersOid: c(a.value)
|
|
541
|
+
} : {
|
|
542
|
+
oid: r,
|
|
543
|
+
parametersDer: o
|
|
573
544
|
};
|
|
574
545
|
}
|
|
575
|
-
function assertMatchingCertificateSignatureAlgorithms(
|
|
576
|
-
if (
|
|
546
|
+
function assertMatchingCertificateSignatureAlgorithms(e, t) {
|
|
547
|
+
if (e.oid !== t.oid || !optionalBytesEqual(e.parametersDer, t.parametersDer)) throw Error("Certificate signatureAlgorithm must match TBSCertificate signature");
|
|
577
548
|
}
|
|
578
|
-
function optionalBytesEqual(
|
|
579
|
-
if (
|
|
580
|
-
if (
|
|
581
|
-
for (let
|
|
582
|
-
return
|
|
549
|
+
function optionalBytesEqual(e, t) {
|
|
550
|
+
if (e === void 0 || t === void 0) return e === t;
|
|
551
|
+
if (e.length !== t.length) return !1;
|
|
552
|
+
for (let n = 0; n < e.length; n += 1) if (e[n] !== t[n]) return !1;
|
|
553
|
+
return !0;
|
|
583
554
|
}
|
|
584
555
|
/** @internal Decode the Basic Constraints extension value DER. */
|
|
585
|
-
function parseBasicConstraints(
|
|
586
|
-
|
|
587
|
-
if (
|
|
588
|
-
|
|
589
|
-
let
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
if (child.tag === 1) {
|
|
595
|
-
if (sawCa) throw new Error("basicConstraints cA must not repeat");
|
|
596
|
-
if (sawPathLength) throw new Error("basicConstraints cA must precede pathLength");
|
|
597
|
-
sawCa = true;
|
|
598
|
-
ca = decodeBoolean(child.value);
|
|
556
|
+
function parseBasicConstraints(e) {
|
|
557
|
+
let t = n(e, { maxDepth: 64 });
|
|
558
|
+
if (t.tag !== 48) throw Error("basicConstraints must use SEQUENCE");
|
|
559
|
+
let r = i(e, t), o = !1, c, l = !1, u = !1;
|
|
560
|
+
for (let e of r) {
|
|
561
|
+
if (e.tag === 1) {
|
|
562
|
+
if (l) throw Error("basicConstraints cA must not repeat");
|
|
563
|
+
if (u) throw Error("basicConstraints cA must precede pathLength");
|
|
564
|
+
l = !0, o = a(e.value);
|
|
599
565
|
continue;
|
|
600
566
|
}
|
|
601
|
-
if (
|
|
602
|
-
if (
|
|
603
|
-
|
|
604
|
-
pathLength = decodeNonNegativeIntegerNumber(child.value, "basicConstraints pathLength");
|
|
567
|
+
if (e.tag === 2) {
|
|
568
|
+
if (u) throw Error("basicConstraints pathLength must not repeat");
|
|
569
|
+
u = !0, c = s(e.value, "basicConstraints pathLength");
|
|
605
570
|
continue;
|
|
606
571
|
}
|
|
607
|
-
throw
|
|
572
|
+
throw Error(`Unsupported basicConstraints field tag: ${String(e.tag)}`);
|
|
608
573
|
}
|
|
609
|
-
if (
|
|
610
|
-
|
|
611
|
-
ca:
|
|
612
|
-
pathLength
|
|
613
|
-
} : { ca:
|
|
614
|
-
return { ca: false };
|
|
574
|
+
if (c !== void 0 && o !== !0) throw Error("basicConstraints pathLength requires cA = true");
|
|
575
|
+
return o ? c === void 0 ? { ca: !0 } : {
|
|
576
|
+
ca: !0,
|
|
577
|
+
pathLength: c
|
|
578
|
+
} : { ca: !1 };
|
|
615
579
|
}
|
|
616
580
|
/** @internal Decode the Key Usage BIT STRING extension value. */
|
|
617
|
-
function parseKeyUsage(
|
|
618
|
-
return
|
|
581
|
+
function parseKeyUsage(e) {
|
|
582
|
+
return E(e);
|
|
619
583
|
}
|
|
620
584
|
/** @internal Decode the Extended Key Usage SEQUENCE OF OIDs. */
|
|
621
|
-
function parseExtendedKeyUsage(
|
|
622
|
-
return
|
|
585
|
+
function parseExtendedKeyUsage(e) {
|
|
586
|
+
return i(e, f(n(e, { maxDepth: 64 }), "extendedKeyUsage sequence")).map((e) => k(c(e.value)));
|
|
623
587
|
}
|
|
624
588
|
/** @internal Decode the Certificate Policies extension value. */
|
|
625
|
-
function parseCertificatePolicies(
|
|
626
|
-
|
|
627
|
-
if (
|
|
628
|
-
return
|
|
589
|
+
function parseCertificatePolicies(e) {
|
|
590
|
+
let t = i(e, f(n(e, { maxDepth: 64 }), "certificatePolicies sequence"));
|
|
591
|
+
if (t.length === 0) throw Error("certificatePolicies must not be empty");
|
|
592
|
+
return t.map((t) => parsePolicyInformation(e, t));
|
|
629
593
|
}
|
|
630
594
|
/** Decode a single PolicyInformation SEQUENCE (OID + optional qualifiers). */
|
|
631
|
-
function parsePolicyInformation(
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
if (
|
|
637
|
-
const qualifiers = childrenOf(source, qualifiersElement);
|
|
638
|
-
if (qualifiers.length === 0) throw new Error("policyQualifiers must not be empty");
|
|
595
|
+
function parsePolicyInformation(e, t) {
|
|
596
|
+
let n = i(e, t), r = c(f(n[0], "policyIdentifier").value), a = n[1];
|
|
597
|
+
if (n.length > 2) throw Error("policyInformation has unexpected trailing fields");
|
|
598
|
+
if (a === void 0) return { policyIdentifier: r };
|
|
599
|
+
let o = i(e, a);
|
|
600
|
+
if (o.length === 0) throw Error("policyQualifiers must not be empty");
|
|
639
601
|
return {
|
|
640
|
-
policyIdentifier,
|
|
641
|
-
policyQualifiers:
|
|
602
|
+
policyIdentifier: r,
|
|
603
|
+
policyQualifiers: o.map((t) => parsePolicyQualifierInfo(e, t))
|
|
642
604
|
};
|
|
643
605
|
}
|
|
644
606
|
/** Decode a PolicyQualifierInfo (CPS URI, UserNotice, or opaque OID). */
|
|
645
|
-
function parsePolicyQualifierInfo(
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
if (qualifierId === OIDS.cpsPolicyQualifier) {
|
|
651
|
-
if (qualifierValue.tag !== 22) throw new Error("cps policy qualifier must use IA5String");
|
|
607
|
+
function parsePolicyQualifierInfo(e, t) {
|
|
608
|
+
let n = i(e, t), r = c(f(n[0], "policyQualifierId").value), a = f(n[1], "policyQualifier");
|
|
609
|
+
if (n.length > 2) throw Error("policyQualifierInfo has unexpected trailing fields");
|
|
610
|
+
if (r === m.cpsPolicyQualifier) {
|
|
611
|
+
if (a.tag !== 22) throw Error("cps policy qualifier must use IA5String");
|
|
652
612
|
return {
|
|
653
613
|
type: "cps",
|
|
654
|
-
uri:
|
|
614
|
+
uri: l(a.tag, a.value)
|
|
655
615
|
};
|
|
656
616
|
}
|
|
657
|
-
|
|
617
|
+
return r === m.userNoticePolicyQualifier ? {
|
|
658
618
|
type: "userNotice",
|
|
659
|
-
...parseUserNoticePolicyQualifierInfo(
|
|
660
|
-
}
|
|
661
|
-
return {
|
|
619
|
+
...parseUserNoticePolicyQualifierInfo(e, a)
|
|
620
|
+
} : {
|
|
662
621
|
type: "oid",
|
|
663
|
-
oid:
|
|
664
|
-
qualifierDer:
|
|
622
|
+
oid: r,
|
|
623
|
+
qualifierDer: e.slice(a.start - a.headerLength, a.end)
|
|
665
624
|
};
|
|
666
625
|
}
|
|
667
626
|
/** Decode a UserNotice qualifier (optional noticeRef + optional explicitText). */
|
|
668
|
-
function parseUserNoticePolicyQualifierInfo(
|
|
669
|
-
|
|
670
|
-
let
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
if (noticeRef !== void 0) throw new Error("userNotice must not contain multiple noticeRef values");
|
|
675
|
-
noticeRef = parsePolicyNoticeReference(source, child);
|
|
627
|
+
function parseUserNoticePolicyQualifierInfo(e, t) {
|
|
628
|
+
let n = i(e, t), r, a;
|
|
629
|
+
for (let t of n) {
|
|
630
|
+
if (t.tag === 48) {
|
|
631
|
+
if (r !== void 0) throw Error("userNotice must not contain multiple noticeRef values");
|
|
632
|
+
r = parsePolicyNoticeReference(e, t);
|
|
676
633
|
continue;
|
|
677
634
|
}
|
|
678
|
-
if (
|
|
679
|
-
|
|
635
|
+
if (a !== void 0) throw Error("userNotice must not contain multiple explicitText values");
|
|
636
|
+
a = parseDisplayText(t);
|
|
680
637
|
}
|
|
681
638
|
return {
|
|
682
|
-
...
|
|
683
|
-
...
|
|
639
|
+
...r === void 0 ? {} : { noticeRef: r },
|
|
640
|
+
...a === void 0 ? {} : { explicitText: a }
|
|
684
641
|
};
|
|
685
642
|
}
|
|
686
643
|
/** Decode a NoticeReference (organization name + notice number list). */
|
|
687
|
-
function parsePolicyNoticeReference(
|
|
688
|
-
if (
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
const noticeNumbersElement = requireElement(children[1], "noticeRef noticeNumbers");
|
|
692
|
-
if (children.length > 2) throw new Error("noticeRef has unexpected trailing fields");
|
|
644
|
+
function parsePolicyNoticeReference(e, t) {
|
|
645
|
+
if (t.tag !== 48) throw Error("noticeRef must use SEQUENCE");
|
|
646
|
+
let n = i(e, t), r = parseDisplayText(f(n[0], "noticeRef organization")), a = f(n[1], "noticeRef noticeNumbers");
|
|
647
|
+
if (n.length > 2) throw Error("noticeRef has unexpected trailing fields");
|
|
693
648
|
return {
|
|
694
|
-
organization,
|
|
695
|
-
noticeNumbers: parsePolicyNoticeNumbers(
|
|
649
|
+
organization: r,
|
|
650
|
+
noticeNumbers: parsePolicyNoticeNumbers(e, a)
|
|
696
651
|
};
|
|
697
652
|
}
|
|
698
653
|
/** Decode a SEQUENCE OF INTEGER notice numbers. */
|
|
699
|
-
function parsePolicyNoticeNumbers(
|
|
700
|
-
if (
|
|
701
|
-
|
|
702
|
-
if (
|
|
703
|
-
return
|
|
704
|
-
if (
|
|
705
|
-
return
|
|
654
|
+
function parsePolicyNoticeNumbers(e, t) {
|
|
655
|
+
if (t.tag !== 48) throw Error("noticeRef noticeNumbers must use SEQUENCE");
|
|
656
|
+
let n = i(e, t);
|
|
657
|
+
if (n.length === 0) throw Error("noticeRef noticeNumbers must not be empty");
|
|
658
|
+
return n.map((e) => {
|
|
659
|
+
if (e.tag !== 2) throw Error("noticeRef noticeNumber must use INTEGER");
|
|
660
|
+
return s(e.value, "noticeRef noticeNumber");
|
|
706
661
|
});
|
|
707
662
|
}
|
|
708
663
|
/** @internal Decode the Policy Mappings extension value. */
|
|
709
|
-
function parsePolicyMappings(
|
|
710
|
-
|
|
711
|
-
if (
|
|
712
|
-
return
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
if (children.length > 2) throw new Error("policyMappings entry has unexpected trailing fields");
|
|
717
|
-
if (issuerDomainPolicy === OIDS.anyPolicy || subjectDomainPolicy === OIDS.anyPolicy) throw new Error("policyMappings must not use anyPolicy");
|
|
664
|
+
function parsePolicyMappings(e) {
|
|
665
|
+
let t = i(e, f(n(e, { maxDepth: 64 }), "policyMappings sequence"));
|
|
666
|
+
if (t.length === 0) throw Error("policyMappings must not be empty");
|
|
667
|
+
return t.map((t) => {
|
|
668
|
+
let n = i(e, t), r = c(f(n[0], "policyMappings issuerDomainPolicy").value), a = c(f(n[1], "policyMappings subjectDomainPolicy").value);
|
|
669
|
+
if (n.length > 2) throw Error("policyMappings entry has unexpected trailing fields");
|
|
670
|
+
if (r === m.anyPolicy || a === m.anyPolicy) throw Error("policyMappings must not use anyPolicy");
|
|
718
671
|
return {
|
|
719
|
-
issuerDomainPolicy,
|
|
720
|
-
subjectDomainPolicy
|
|
672
|
+
issuerDomainPolicy: r,
|
|
673
|
+
subjectDomainPolicy: a
|
|
721
674
|
};
|
|
722
675
|
});
|
|
723
676
|
}
|
|
724
677
|
/** @internal Decode the Policy Constraints extension value. */
|
|
725
|
-
function parsePolicyConstraints(
|
|
726
|
-
|
|
727
|
-
let
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
if (requireExplicitPolicy !== void 0) throw new Error("policyConstraints must not repeat requireExplicitPolicy");
|
|
732
|
-
requireExplicitPolicy = decodeNonNegativeIntegerNumber(child.value, "policyConstraints requireExplicitPolicy");
|
|
678
|
+
function parsePolicyConstraints(e) {
|
|
679
|
+
let t = f(n(e, { maxDepth: 64 }), "policyConstraints sequence"), r, a;
|
|
680
|
+
for (let n of i(e, t)) {
|
|
681
|
+
if (n.tag === 128) {
|
|
682
|
+
if (r !== void 0) throw Error("policyConstraints must not repeat requireExplicitPolicy");
|
|
683
|
+
r = s(n.value, "policyConstraints requireExplicitPolicy");
|
|
733
684
|
continue;
|
|
734
685
|
}
|
|
735
|
-
if (
|
|
736
|
-
if (
|
|
737
|
-
|
|
686
|
+
if (n.tag === 129) {
|
|
687
|
+
if (a !== void 0) throw Error("policyConstraints must not repeat inhibitPolicyMapping");
|
|
688
|
+
a = s(n.value, "policyConstraints inhibitPolicyMapping");
|
|
738
689
|
continue;
|
|
739
690
|
}
|
|
740
|
-
throw
|
|
691
|
+
throw Error(`Unsupported policyConstraints field tag: ${n.tag}`);
|
|
741
692
|
}
|
|
742
|
-
if (
|
|
693
|
+
if (r === void 0 && a === void 0) throw Error("policyConstraints must set requireExplicitPolicy or inhibitPolicyMapping");
|
|
743
694
|
return {
|
|
744
|
-
...
|
|
745
|
-
...
|
|
695
|
+
...r === void 0 ? {} : { requireExplicitPolicy: r },
|
|
696
|
+
...a === void 0 ? {} : { inhibitPolicyMapping: a }
|
|
746
697
|
};
|
|
747
698
|
}
|
|
748
699
|
/** @internal Decode the Inhibit anyPolicy extension (single INTEGER). */
|
|
749
|
-
function parseInhibitAnyPolicy(
|
|
750
|
-
|
|
751
|
-
if (
|
|
752
|
-
return { skipCerts:
|
|
700
|
+
function parseInhibitAnyPolicy(e) {
|
|
701
|
+
let t = f(n(e, { maxDepth: 64 }), "inhibitAnyPolicy integer");
|
|
702
|
+
if (t.tag !== 2) throw Error("inhibitAnyPolicy must be an INTEGER");
|
|
703
|
+
return { skipCerts: s(t.value, "inhibitAnyPolicy skipCerts") };
|
|
753
704
|
}
|
|
754
705
|
/** @internal Decode the Subject Alternative Names SEQUENCE OF GeneralName. */
|
|
755
|
-
function parseSubjectAltNames(
|
|
756
|
-
return
|
|
706
|
+
function parseSubjectAltNames(e) {
|
|
707
|
+
return i(e, f(n(e, { maxDepth: 64 }), "subjectAltName sequence")).map((t) => parseGeneralName(e, t));
|
|
757
708
|
}
|
|
758
709
|
/** @internal Decode the Authority Information Access extension value. */
|
|
759
|
-
function parseAuthorityInfoAccess(
|
|
760
|
-
|
|
761
|
-
if (
|
|
762
|
-
|
|
763
|
-
if (
|
|
764
|
-
return
|
|
765
|
-
if (
|
|
766
|
-
|
|
767
|
-
if (
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
if (
|
|
771
|
-
if (location.tag !== 134) throw new Error(`Unsupported authorityInfoAccess location tag: ${location.tag}`);
|
|
710
|
+
function parseAuthorityInfoAccess(e) {
|
|
711
|
+
let t = f(n(e, { maxDepth: 64 }), "authorityInfoAccess sequence");
|
|
712
|
+
if (t.tag !== 48) throw Error("authorityInfoAccess must use SEQUENCE");
|
|
713
|
+
let r = i(e, t);
|
|
714
|
+
if (r.length === 0) throw Error("authorityInfoAccess must not be empty");
|
|
715
|
+
return r.map((t) => {
|
|
716
|
+
if (t.tag !== 48) throw Error("authorityInfoAccess entry must use SEQUENCE");
|
|
717
|
+
let n = i(e, t);
|
|
718
|
+
if (n.length !== 2) throw Error("authorityInfoAccess entry must contain method and location only");
|
|
719
|
+
let r = f(n[0], "authorityInfoAccess method"), a = f(n[1], "authorityInfoAccess location");
|
|
720
|
+
if (r.tag !== 6) throw Error("authorityInfoAccess method must use OBJECT IDENTIFIER");
|
|
721
|
+
if (a.tag !== 134) throw Error(`Unsupported authorityInfoAccess location tag: ${a.tag}`);
|
|
772
722
|
return {
|
|
773
|
-
method:
|
|
774
|
-
uri:
|
|
723
|
+
method: O(c(r.value)),
|
|
724
|
+
uri: j.decode(a.value)
|
|
775
725
|
};
|
|
776
726
|
});
|
|
777
727
|
}
|
|
778
728
|
/** @internal Decode the CRL Distribution Points extension value. */
|
|
779
|
-
function parseCrlDistributionPoints(
|
|
780
|
-
|
|
781
|
-
if (
|
|
782
|
-
|
|
783
|
-
if (
|
|
784
|
-
|
|
785
|
-
for (
|
|
786
|
-
return
|
|
729
|
+
function parseCrlDistributionPoints(e) {
|
|
730
|
+
let t = f(n(e, { maxDepth: 64 }), "CRLDistributionPoints sequence");
|
|
731
|
+
if (t.tag !== 48) throw Error("CRLDistributionPoints must use SEQUENCE");
|
|
732
|
+
let r = i(e, t);
|
|
733
|
+
if (r.length === 0) throw Error("CRLDistributionPoints must not be empty");
|
|
734
|
+
let a = [];
|
|
735
|
+
for (let t of r) a.push(parseDistributionPoint(e, t));
|
|
736
|
+
return a;
|
|
787
737
|
}
|
|
788
738
|
/** Decode a single DistributionPoint SEQUENCE. */
|
|
789
|
-
function parseDistributionPoint(
|
|
790
|
-
if (
|
|
791
|
-
let
|
|
792
|
-
let
|
|
793
|
-
|
|
794
|
-
for (const child of childrenOf(source, element)) if (child.tag === 160) {
|
|
795
|
-
if (distributionPoint !== void 0) throw new Error("DistributionPoint distributionPoint must not repeat");
|
|
796
|
-
distributionPoint = parseDistributionPointName(source, child);
|
|
797
|
-
} else if (child.tag === 129) {
|
|
798
|
-
if (reasons !== void 0) throw new Error("DistributionPoint reasons must not repeat");
|
|
799
|
-
reasons = parseDistributionPointReasonFlagsContent(child.value);
|
|
800
|
-
} else if (child.tag === 162) {
|
|
801
|
-
if (crlIssuer !== void 0) throw new Error("DistributionPoint crlIssuer must not repeat");
|
|
802
|
-
crlIssuer = parseGeneralNames(source, child);
|
|
803
|
-
} else throw new Error(`Unsupported DistributionPoint field tag: ${String(child.tag)}`);
|
|
804
|
-
if (distributionPoint === void 0 && crlIssuer === void 0) throw new Error("DistributionPoint must include distributionPoint or crlIssuer");
|
|
739
|
+
function parseDistributionPoint(e, t) {
|
|
740
|
+
if (t.tag !== 48) throw Error("DistributionPoint must use SEQUENCE");
|
|
741
|
+
let n = {};
|
|
742
|
+
for (let r of i(e, t)) parseDistributionPointField(e, r, n);
|
|
743
|
+
if (n.distributionPoint === void 0 && n.crlIssuer === void 0) throw Error("DistributionPoint must include distributionPoint or crlIssuer");
|
|
805
744
|
return {
|
|
806
|
-
...distributionPoint === void 0 ? {} : { distributionPoint },
|
|
807
|
-
...reasons === void 0 ? {} : { reasons },
|
|
808
|
-
...crlIssuer === void 0 ? {} : { crlIssuer }
|
|
745
|
+
...n.distributionPoint === void 0 ? {} : { distributionPoint: n.distributionPoint },
|
|
746
|
+
...n.reasons === void 0 ? {} : { reasons: n.reasons },
|
|
747
|
+
...n.crlIssuer === void 0 ? {} : { crlIssuer: n.crlIssuer }
|
|
809
748
|
};
|
|
810
749
|
}
|
|
750
|
+
function parseDistributionPointField(e, t, n) {
|
|
751
|
+
switch (t.tag) {
|
|
752
|
+
case 160:
|
|
753
|
+
if (n.distributionPoint !== void 0) throw Error("DistributionPoint distributionPoint must not repeat");
|
|
754
|
+
n.distributionPoint = parseDistributionPointName(e, t);
|
|
755
|
+
return;
|
|
756
|
+
case 129:
|
|
757
|
+
if (n.reasons !== void 0) throw Error("DistributionPoint reasons must not repeat");
|
|
758
|
+
n.reasons = T(t.value);
|
|
759
|
+
return;
|
|
760
|
+
case 162:
|
|
761
|
+
if (n.crlIssuer !== void 0) throw Error("DistributionPoint crlIssuer must not repeat");
|
|
762
|
+
n.crlIssuer = parseGeneralNames(e, t);
|
|
763
|
+
return;
|
|
764
|
+
default: throw Error(`Unsupported DistributionPoint field tag: ${String(t.tag)}`);
|
|
765
|
+
}
|
|
766
|
+
}
|
|
811
767
|
/** Decode a DistributionPointName (fullName or relativeName). */
|
|
812
|
-
function parseDistributionPointName(
|
|
813
|
-
|
|
814
|
-
if (
|
|
815
|
-
|
|
816
|
-
if (
|
|
817
|
-
|
|
818
|
-
if (
|
|
819
|
-
for (
|
|
820
|
-
return { fullName:
|
|
768
|
+
function parseDistributionPointName(e, t) {
|
|
769
|
+
let n = i(e, t);
|
|
770
|
+
if (n.length !== 1) throw Error("distributionPointName must contain exactly one choice");
|
|
771
|
+
let r = f(n[0], "distributionPointName");
|
|
772
|
+
if (r.tag === 160) {
|
|
773
|
+
let t = i(e, r);
|
|
774
|
+
if (t.length === 0) throw Error("distributionPointName fullName must not be empty");
|
|
775
|
+
for (let e of t) if ((e.tag & 192) != 128) throw Error("distributionPointName fullName must contain GeneralName entries");
|
|
776
|
+
return { fullName: t.map((t) => parseGeneralName(e, t)) };
|
|
821
777
|
}
|
|
822
|
-
if (
|
|
823
|
-
throw
|
|
778
|
+
if (r.tag === 161) return { relativeName: parseRelativeDistinguishedName(e, r) };
|
|
779
|
+
throw Error(`Unsupported distributionPointName tag: ${r.tag}`);
|
|
824
780
|
}
|
|
825
781
|
/** Decode a SEQUENCE OF GeneralName. */
|
|
826
|
-
function parseGeneralNames(
|
|
827
|
-
|
|
828
|
-
if (
|
|
829
|
-
for (
|
|
830
|
-
return
|
|
782
|
+
function parseGeneralNames(e, t) {
|
|
783
|
+
let n = i(e, t);
|
|
784
|
+
if (n.length === 0) throw Error("GeneralNames must not be empty");
|
|
785
|
+
for (let e of n) if ((e.tag & 192) != 128) throw Error("GeneralNames must contain GeneralName entries");
|
|
786
|
+
return n.map((t) => parseGeneralName(e, t));
|
|
831
787
|
}
|
|
832
788
|
/** Decode a single GeneralName from its implicit context tag. */
|
|
833
|
-
function parseGeneralName(
|
|
834
|
-
switch (
|
|
789
|
+
function parseGeneralName(e, t) {
|
|
790
|
+
switch (t.tag) {
|
|
835
791
|
case 160: {
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
return {
|
|
792
|
+
let n = parseOtherName(e, t);
|
|
793
|
+
return n === void 0 ? {
|
|
839
794
|
type: "unknown",
|
|
840
|
-
tag:
|
|
841
|
-
value:
|
|
842
|
-
};
|
|
795
|
+
tag: t.tag,
|
|
796
|
+
value: e.slice(t.start, t.end)
|
|
797
|
+
} : n;
|
|
843
798
|
}
|
|
844
799
|
case 129: return {
|
|
845
800
|
type: "email",
|
|
846
|
-
value:
|
|
801
|
+
value: j.decode(t.value)
|
|
847
802
|
};
|
|
848
803
|
case 130: return {
|
|
849
804
|
type: "dns",
|
|
850
|
-
value:
|
|
805
|
+
value: j.decode(t.value)
|
|
851
806
|
};
|
|
852
807
|
case 134: return {
|
|
853
808
|
type: "uri",
|
|
854
|
-
value:
|
|
809
|
+
value: j.decode(t.value)
|
|
855
810
|
};
|
|
856
811
|
case 135: return {
|
|
857
812
|
type: "ip",
|
|
858
|
-
value:
|
|
813
|
+
value: w(t.value)
|
|
859
814
|
};
|
|
860
815
|
case 164: return {
|
|
861
816
|
type: "directoryName",
|
|
862
|
-
derHex:
|
|
817
|
+
derHex: p(rebuildDirectoryNameFromImplicit(t, e))
|
|
863
818
|
};
|
|
864
819
|
default: return {
|
|
865
820
|
type: "unknown",
|
|
866
|
-
tag:
|
|
867
|
-
value:
|
|
821
|
+
tag: t.tag,
|
|
822
|
+
value: e.slice(t.start, t.end)
|
|
868
823
|
};
|
|
869
824
|
}
|
|
870
825
|
}
|
|
871
826
|
/** Attempt to decode an otherName [0] as a known type (currently only SRV-ID). */
|
|
872
|
-
function parseOtherName(
|
|
873
|
-
|
|
874
|
-
if (
|
|
875
|
-
|
|
876
|
-
if (
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
if (
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
if (srvNameElement.tag !== 22) throw new Error("SRV-ID otherName value must be an IA5String");
|
|
827
|
+
function parseOtherName(e, t) {
|
|
828
|
+
let n = i(e, t);
|
|
829
|
+
if (n.length !== 1) throw Error("otherName must contain exactly one SEQUENCE");
|
|
830
|
+
let r = i(e, f(n[0], "otherName sequence"));
|
|
831
|
+
if (r.length !== 2) throw Error("otherName must contain exactly type-id and value");
|
|
832
|
+
let a = f(r[0], "otherName type-id"), o = f(r[1], "otherName value");
|
|
833
|
+
if (c(a.value) !== m.idOnDnsSrv) return;
|
|
834
|
+
if (o.tag !== 160) throw Error("SRV-ID otherName value must use explicit [0]");
|
|
835
|
+
let s = i(e, o);
|
|
836
|
+
if (s.length !== 1) throw Error("SRV-ID otherName value must contain exactly one IA5String");
|
|
837
|
+
let u = f(s[0], "SRV-ID IA5String");
|
|
838
|
+
if (u.tag !== 22) throw Error("SRV-ID otherName value must be an IA5String");
|
|
885
839
|
return {
|
|
886
840
|
type: "srv",
|
|
887
|
-
value:
|
|
841
|
+
value: l(u.tag, u.value)
|
|
888
842
|
};
|
|
889
843
|
}
|
|
890
844
|
/** @internal Decode the Name Constraints extension value. */
|
|
891
|
-
function parseNameConstraints(
|
|
892
|
-
|
|
845
|
+
function parseNameConstraints(e) {
|
|
846
|
+
let t = f(n(e, {
|
|
893
847
|
maxDepth: 64,
|
|
894
848
|
allowOpaqueConstructedTags: [
|
|
895
849
|
160,
|
|
@@ -897,96 +851,96 @@ function parseNameConstraints(bytes) {
|
|
|
897
851
|
165
|
|
898
852
|
]
|
|
899
853
|
}), "nameConstraints sequence");
|
|
900
|
-
if (
|
|
901
|
-
let
|
|
902
|
-
let
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
} else throw new Error(`Unsupported nameConstraints field tag: ${String(child.tag)}`);
|
|
854
|
+
if (t.tag !== 48) throw Error("nameConstraints must use SEQUENCE");
|
|
855
|
+
let r, a;
|
|
856
|
+
for (let n of i(e, t)) if (n.tag === 160) {
|
|
857
|
+
if (r !== void 0) throw Error("nameConstraints permittedSubtrees must not repeat");
|
|
858
|
+
r = parseGeneralSubtrees(e, n);
|
|
859
|
+
} else if (n.tag === 161) {
|
|
860
|
+
if (a !== void 0) throw Error("nameConstraints excludedSubtrees must not repeat");
|
|
861
|
+
a = parseGeneralSubtrees(e, n);
|
|
862
|
+
} else throw Error(`Unsupported nameConstraints field tag: ${String(n.tag)}`);
|
|
910
863
|
return {
|
|
911
|
-
...
|
|
912
|
-
...
|
|
864
|
+
...r === void 0 ? {} : { permittedSubtrees: r },
|
|
865
|
+
...a === void 0 ? {} : { excludedSubtrees: a }
|
|
913
866
|
};
|
|
914
867
|
}
|
|
915
868
|
/** Decode a SEQUENCE OF GeneralSubtree from a permittedSubtrees or excludedSubtrees wrapper. */
|
|
916
|
-
function parseGeneralSubtrees(
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
869
|
+
function parseGeneralSubtrees(e, t) {
|
|
870
|
+
let n = [], r = i(e, t);
|
|
871
|
+
if (r.length === 0) throw Error("name constraints GeneralSubtrees must not be empty");
|
|
872
|
+
for (let t of r) {
|
|
873
|
+
let r = parseGeneralSubtree(e, t);
|
|
874
|
+
r !== void 0 && n.push({ base: r });
|
|
875
|
+
}
|
|
876
|
+
return n;
|
|
877
|
+
}
|
|
878
|
+
function parseGeneralSubtree(e, t) {
|
|
879
|
+
if (t.tag !== 48) throw Error("name constraints GeneralSubtree must use SEQUENCE");
|
|
880
|
+
let n = i(e, t), r = n[0];
|
|
881
|
+
if (r === void 0) throw Error("GeneralSubtree base is required");
|
|
882
|
+
return validateGeneralSubtreeBounds(n.slice(1)), parseNameConstraintGeneralName(e, r);
|
|
883
|
+
}
|
|
884
|
+
function validateGeneralSubtreeBounds(e) {
|
|
885
|
+
let t = !1;
|
|
886
|
+
for (let n of e) {
|
|
887
|
+
if (n.tag === 128) {
|
|
888
|
+
if (t) throw Error("name constraints GeneralSubtree minimum must not repeat");
|
|
889
|
+
if (t = !0, s(n.value, "name constraints GeneralSubtree minimum") !== 0) throw Error("name constraints GeneralSubtree minimum must be 0");
|
|
890
|
+
continue;
|
|
935
891
|
}
|
|
936
|
-
|
|
937
|
-
if (form !== void 0) subtrees.push({ base: form });
|
|
892
|
+
throw n.tag === 129 ? Error("name constraints GeneralSubtree maximum is not supported") : Error(`Unsupported name constraints GeneralSubtree field tag: ${String(n.tag)}`);
|
|
938
893
|
}
|
|
939
|
-
return subtrees;
|
|
940
894
|
}
|
|
941
895
|
/** Decode a GeneralName for use in name constraints (IP carries address+mask). */
|
|
942
|
-
function parseNameConstraintGeneralName(
|
|
943
|
-
switch (
|
|
896
|
+
function parseNameConstraintGeneralName(e, t) {
|
|
897
|
+
switch (t.tag) {
|
|
944
898
|
case 160: return {
|
|
945
899
|
type: "otherName",
|
|
946
|
-
value: new Uint8Array(
|
|
900
|
+
value: new Uint8Array(t.value)
|
|
947
901
|
};
|
|
948
902
|
case 129: return {
|
|
949
903
|
type: "email",
|
|
950
|
-
value:
|
|
904
|
+
value: j.decode(t.value)
|
|
951
905
|
};
|
|
952
906
|
case 130: return {
|
|
953
907
|
type: "dns",
|
|
954
|
-
value:
|
|
908
|
+
value: j.decode(t.value)
|
|
955
909
|
};
|
|
956
910
|
case 163: return {
|
|
957
911
|
type: "x400Address",
|
|
958
|
-
value: new Uint8Array(
|
|
912
|
+
value: new Uint8Array(t.value)
|
|
959
913
|
};
|
|
960
914
|
case 134: return {
|
|
961
915
|
type: "uri",
|
|
962
|
-
value:
|
|
916
|
+
value: j.decode(t.value)
|
|
963
917
|
};
|
|
964
918
|
case 135:
|
|
965
|
-
if (
|
|
919
|
+
if (t.value.length === 8) return {
|
|
966
920
|
type: "ip",
|
|
967
|
-
addressBytes:
|
|
968
|
-
maskBytes:
|
|
921
|
+
addressBytes: t.value.slice(0, 4),
|
|
922
|
+
maskBytes: t.value.slice(4, 8)
|
|
969
923
|
};
|
|
970
|
-
if (
|
|
924
|
+
if (t.value.length === 32) return {
|
|
971
925
|
type: "ip",
|
|
972
|
-
addressBytes:
|
|
973
|
-
maskBytes:
|
|
926
|
+
addressBytes: t.value.slice(0, 16),
|
|
927
|
+
maskBytes: t.value.slice(16, 32)
|
|
974
928
|
};
|
|
975
|
-
throw
|
|
929
|
+
throw Error(`Invalid IP name constraint: expected 8 (IPv4) or 32 (IPv6) bytes, got ${String(t.value.length)}`);
|
|
976
930
|
case 164: return {
|
|
977
931
|
type: "directoryName",
|
|
978
|
-
derHex:
|
|
932
|
+
derHex: p(rebuildDirectoryNameFromImplicit(t, e))
|
|
979
933
|
};
|
|
980
934
|
case 165: return {
|
|
981
935
|
type: "ediPartyName",
|
|
982
|
-
value: new Uint8Array(
|
|
936
|
+
value: new Uint8Array(t.value)
|
|
983
937
|
};
|
|
984
938
|
case 136: return {
|
|
985
939
|
type: "registeredID",
|
|
986
|
-
value:
|
|
940
|
+
value: c(t.value)
|
|
987
941
|
};
|
|
988
942
|
}
|
|
989
|
-
throw
|
|
943
|
+
throw Error(`Unsupported name constraint GeneralName tag: ${String(t.tag)}`);
|
|
990
944
|
}
|
|
991
945
|
/**
|
|
992
946
|
* Extracts the Name SEQUENCE from an implicitly-tagged directoryName [4].
|
|
@@ -995,96 +949,104 @@ function parseNameConstraintGeneralName(source, element) {
|
|
|
995
949
|
* - Proper implicit: [4] replaces SEQUENCE tag, content is RDN SETs directly → wrap with 0x30
|
|
996
950
|
* - Explicit-like: [4] wraps entire SEQUENCE, content starts with 0x30 → return content as-is
|
|
997
951
|
*/
|
|
998
|
-
function rebuildDirectoryNameFromImplicit(
|
|
999
|
-
if (
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
result[0] = 48;
|
|
1003
|
-
result.set(lengthEncoded, 1);
|
|
1004
|
-
result.set(element.value, 1 + lengthEncoded.length);
|
|
1005
|
-
return result;
|
|
952
|
+
function rebuildDirectoryNameFromImplicit(t, n) {
|
|
953
|
+
if (t.value.length > 0 && t.value[0] === 48) return new Uint8Array(t.value);
|
|
954
|
+
let r = e(t.value.length), i = new Uint8Array(1 + r.length + t.value.length);
|
|
955
|
+
return i[0] = 48, i.set(r, 1), i.set(t.value, 1 + r.length), i;
|
|
1006
956
|
}
|
|
1007
957
|
/** Decode a DisplayText (UTF8String, IA5String, VisibleString, or BMPString). */
|
|
1008
|
-
function parseDisplayText(
|
|
1009
|
-
switch (
|
|
958
|
+
function parseDisplayText(e) {
|
|
959
|
+
switch (e.tag) {
|
|
1010
960
|
case 12:
|
|
1011
961
|
case 22:
|
|
1012
|
-
case 26: return
|
|
1013
|
-
case 30: return decodeBmpString(
|
|
1014
|
-
default: throw
|
|
962
|
+
case 26: return j.decode(e.value);
|
|
963
|
+
case 30: return decodeBmpString(e.value);
|
|
964
|
+
default: throw Error(`Unsupported DisplayText tag: ${e.tag}`);
|
|
1015
965
|
}
|
|
1016
966
|
}
|
|
1017
967
|
/** Decode a BMPString (UCS-2 big-endian) to a JS string. */
|
|
1018
|
-
function decodeBmpString(
|
|
1019
|
-
if (
|
|
1020
|
-
let
|
|
1021
|
-
for (let
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
value += String.fromCharCode(left << 8 | right);
|
|
968
|
+
function decodeBmpString(e) {
|
|
969
|
+
if (e.length % 2 != 0) throw Error("Invalid BMPString length");
|
|
970
|
+
let t = "";
|
|
971
|
+
for (let n = 0; n < e.length; n += 2) {
|
|
972
|
+
let r = e[n], i = e[n + 1];
|
|
973
|
+
if (r === void 0 || i === void 0) throw Error("Invalid BMPString content");
|
|
974
|
+
t += String.fromCharCode(r << 8 | i);
|
|
1026
975
|
}
|
|
1027
|
-
return
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
if (child.tag === 128) {
|
|
1042
|
-
if (keyIdentifier !== void 0) throw new Error("authorityKeyIdentifier keyIdentifier must not repeat");
|
|
1043
|
-
if (lastFieldOrder >= 0) throw new Error("authorityKeyIdentifier fields must preserve DER order");
|
|
1044
|
-
keyIdentifier = toHex(child.value);
|
|
1045
|
-
lastFieldOrder = 0;
|
|
1046
|
-
} else if (child.tag === 161) {
|
|
1047
|
-
if (sawAuthorityCertIssuer) throw new Error("authorityKeyIdentifier authorityCertIssuer must not repeat");
|
|
1048
|
-
if (lastFieldOrder >= 1) throw new Error("authorityKeyIdentifier fields must preserve DER order");
|
|
1049
|
-
const issuerNames = childrenOf(bytes, child);
|
|
1050
|
-
if (issuerNames.length === 0) throw new Error("authorityKeyIdentifier authorityCertIssuer must contain GeneralName entries");
|
|
1051
|
-
for (const issuerName of issuerNames) {
|
|
1052
|
-
if ((issuerName.tag & 192) !== 128) throw new Error("authorityKeyIdentifier authorityCertIssuer must contain GeneralName entries");
|
|
1053
|
-
parseGeneralName(bytes, issuerName);
|
|
1054
|
-
}
|
|
1055
|
-
sawAuthorityCertIssuer = true;
|
|
1056
|
-
lastFieldOrder = 1;
|
|
1057
|
-
} else if (child.tag === 130) {
|
|
1058
|
-
if (sawAuthorityCertSerialNumber) throw new Error("authorityKeyIdentifier authorityCertSerialNumber must not repeat");
|
|
1059
|
-
if (lastFieldOrder >= 2 || !sawAuthorityCertIssuer) throw new Error("authorityKeyIdentifier fields must preserve DER order");
|
|
1060
|
-
validateImplicitSerialNumberEncoding(child.value, "authorityKeyIdentifier authorityCertSerialNumber");
|
|
1061
|
-
sawAuthorityCertSerialNumber = true;
|
|
1062
|
-
lastFieldOrder = 2;
|
|
1063
|
-
} else throw new Error(`Unsupported authorityKeyIdentifier field tag: ${String(child.tag)}`);
|
|
1064
|
-
offset = child.end;
|
|
976
|
+
return t;
|
|
977
|
+
}
|
|
978
|
+
function parseAuthorityKeyIdentifier(e) {
|
|
979
|
+
let n = f(t(e, 0), "authorityKeyIdentifier sequence");
|
|
980
|
+
if (n.end !== e.length) throw Error("Trailing data after DER element");
|
|
981
|
+
let r = {
|
|
982
|
+
sawAuthorityCertIssuer: !1,
|
|
983
|
+
sawAuthorityCertSerialNumber: !1,
|
|
984
|
+
lastFieldOrder: -1
|
|
985
|
+
}, i = n.start;
|
|
986
|
+
for (; i < n.end;) {
|
|
987
|
+
let a = t(e, i);
|
|
988
|
+
if (a.end > n.end) throw Error("DER child exceeds parent length");
|
|
989
|
+
parseAuthorityKeyIdentifierField(e, a, r), i = a.end;
|
|
1065
990
|
}
|
|
1066
|
-
if (
|
|
1067
|
-
if (sawAuthorityCertIssuer !== sawAuthorityCertSerialNumber) throw
|
|
1068
|
-
return keyIdentifier;
|
|
1069
|
-
}
|
|
1070
|
-
function
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
991
|
+
if (i !== n.end) throw Error("Malformed DER sequence");
|
|
992
|
+
if (r.sawAuthorityCertIssuer !== r.sawAuthorityCertSerialNumber) throw Error("authorityKeyIdentifier authorityCertIssuer and authorityCertSerialNumber must appear together");
|
|
993
|
+
return r.keyIdentifier;
|
|
994
|
+
}
|
|
995
|
+
function parseAuthorityKeyIdentifierField(e, t, n) {
|
|
996
|
+
switch (t.tag) {
|
|
997
|
+
case 128:
|
|
998
|
+
parseAuthorityKeyIdentifierKeyId(t, n);
|
|
999
|
+
return;
|
|
1000
|
+
case 161:
|
|
1001
|
+
parseAuthorityKeyIdentifierIssuer(e, t, n);
|
|
1002
|
+
return;
|
|
1003
|
+
case 130:
|
|
1004
|
+
parseAuthorityKeyIdentifierSerial(t, n);
|
|
1005
|
+
return;
|
|
1006
|
+
default: throw Error(`Unsupported authorityKeyIdentifier field tag: ${String(t.tag)}`);
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
function parseAuthorityKeyIdentifierKeyId(e, t) {
|
|
1010
|
+
if (t.keyIdentifier !== void 0) throw Error("authorityKeyIdentifier keyIdentifier must not repeat");
|
|
1011
|
+
if (t.lastFieldOrder >= 0) throw Error("authorityKeyIdentifier fields must preserve DER order");
|
|
1012
|
+
t.keyIdentifier = p(e.value), t.lastFieldOrder = 0;
|
|
1013
|
+
}
|
|
1014
|
+
function parseAuthorityKeyIdentifierIssuer(e, t, n) {
|
|
1015
|
+
if (n.sawAuthorityCertIssuer) throw Error("authorityKeyIdentifier authorityCertIssuer must not repeat");
|
|
1016
|
+
if (n.lastFieldOrder >= 1) throw Error("authorityKeyIdentifier fields must preserve DER order");
|
|
1017
|
+
let r = i(e, t);
|
|
1018
|
+
if (r.length === 0) throw Error("authorityKeyIdentifier authorityCertIssuer must contain GeneralName entries");
|
|
1019
|
+
for (let t of r) {
|
|
1020
|
+
if ((t.tag & 192) != 128) throw Error("authorityKeyIdentifier authorityCertIssuer must contain GeneralName entries");
|
|
1021
|
+
parseGeneralName(e, t);
|
|
1022
|
+
}
|
|
1023
|
+
n.sawAuthorityCertIssuer = !0, n.lastFieldOrder = 1;
|
|
1024
|
+
}
|
|
1025
|
+
function parseAuthorityKeyIdentifierSerial(e, t) {
|
|
1026
|
+
if (t.sawAuthorityCertSerialNumber) throw Error("authorityKeyIdentifier authorityCertSerialNumber must not repeat");
|
|
1027
|
+
if (t.lastFieldOrder >= 2 || !t.sawAuthorityCertIssuer) throw Error("authorityKeyIdentifier fields must preserve DER order");
|
|
1028
|
+
validateImplicitSerialNumberEncoding(e.value, "authorityKeyIdentifier authorityCertSerialNumber"), t.sawAuthorityCertSerialNumber = !0, t.lastFieldOrder = 2;
|
|
1029
|
+
}
|
|
1030
|
+
function validateImplicitSerialNumberEncoding(e, t) {
|
|
1031
|
+
let n = e[0];
|
|
1032
|
+
if (n === void 0) throw Error(`${t} must not be empty`);
|
|
1033
|
+
if (n & 128) throw Error(`${t} must be non-negative`);
|
|
1034
|
+
if (e.length > 1 && n === 0 && !((e[1] ?? 0) & 128)) throw Error(`${t} must use minimal encoding`);
|
|
1035
|
+
}
|
|
1036
|
+
function validateImplicitBitStringContent(e, t) {
|
|
1037
|
+
let n = e[0];
|
|
1038
|
+
if (n === void 0 || n > 7) throw Error(`${t} must use BIT STRING encoding`);
|
|
1039
|
+
let r = e.slice(1);
|
|
1040
|
+
if (r.length === 0) {
|
|
1041
|
+
if (n !== 0) throw Error(`${t} must use BIT STRING encoding`);
|
|
1082
1042
|
return;
|
|
1083
1043
|
}
|
|
1084
|
-
if (
|
|
1085
|
-
|
|
1086
|
-
if (
|
|
1087
|
-
if (
|
|
1044
|
+
if (n === 0) return;
|
|
1045
|
+
let i = r[r.length - 1];
|
|
1046
|
+
if (i === void 0) throw Error(`${t} must use BIT STRING encoding`);
|
|
1047
|
+
if (i & (1 << n) - 1) throw Error(`${t} BIT STRING must not set padding bits`);
|
|
1088
1048
|
}
|
|
1089
1049
|
//#endregion
|
|
1090
1050
|
export { decodeExtension, decodeExtensionMap, decodeExtensions, defineExtensionDecoder, defineExtensionDecoderMap, findExtension, getSubjectPublicKey, getSubjectPublicKeyOrThrow, parseAuthorityInfoAccess, parseAuthorityKeyIdentifier, parseBasicConstraints, parseCertificateChainPem, parseCertificateDer, parseCertificateDerOrThrow, parseCertificateFromSource, parseCertificatePem, parseCertificatePemOrThrow, parseCertificatePolicies, parseCertificateSigningRequestDer, parseCertificateSigningRequestDerOrThrow, parseCertificateSigningRequestPem, parseCertificateSigningRequestPemOrThrow, parseCertificatesFromSource, parseCrlDistributionPoints, parseExtendedKeyUsage, parseInhibitAnyPolicy, parseKeyUsage, parseNameConstraints, parsePolicyConstraints, parsePolicyMappings, parseSubjectAltNames };
|
|
1051
|
+
|
|
1052
|
+
//# sourceMappingURL=parse.js.map
|