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