micro509 0.18.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +88 -1
- package/dist/crypto/crypto.d.ts +11 -2
- package/dist/crypto/crypto.js +30 -17
- package/dist/crypto/crypto.js.map +1 -1
- package/dist/crypto.d.ts +2 -2
- package/dist/der/der.js.map +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/internal/asn1/asn1.js +10 -2
- package/dist/internal/asn1/asn1.js.map +1 -1
- package/dist/internal/asn1/ber.js.map +1 -1
- package/dist/internal/asn1/decode-refusal.js.map +1 -1
- package/dist/internal/asn1/der.js.map +1 -1
- package/dist/internal/asn1/oids.js.map +1 -1
- package/dist/internal/crypto/algorithm-names.js.map +1 -1
- package/dist/internal/crypto/ecdsa.js.map +1 -1
- package/dist/internal/crypto/hash.js.map +1 -1
- package/dist/internal/crypto/pbes2.js.map +1 -1
- package/dist/internal/crypto/prime-ec.js.map +1 -1
- package/dist/internal/crypto/rsa-pss.js.map +1 -1
- package/dist/internal/crypto/sig-verify.d.ts +40 -0
- package/dist/internal/crypto/sig-verify.js +152 -65
- package/dist/internal/crypto/sig-verify.js.map +1 -1
- package/dist/internal/crypto/signing.js.map +1 -1
- package/dist/internal/jose/base64url.js.map +1 -1
- package/dist/internal/jose/json-data.js.map +1 -1
- package/dist/internal/jose/strict-json.js.map +1 -1
- package/dist/internal/shared/base64.js.map +1 -1
- package/dist/internal/shared/dn.js.map +1 -1
- package/dist/internal/shared/idna.js.map +1 -1
- package/dist/internal/shared/ip.js.map +1 -1
- package/dist/internal/shared/mailbox.js.map +1 -1
- package/dist/internal/shared/punycode.js.map +1 -1
- package/dist/internal/shared/uri-host.js.map +1 -1
- package/dist/internal/verify/name-constraints-engine.js.map +1 -1
- package/dist/internal/verify/policy-engine.js.map +1 -1
- package/dist/internal/verify/spki-distrust.js.map +1 -1
- package/dist/internal/verify/verify-path.js +222 -116
- package/dist/internal/verify/verify-path.js.map +1 -1
- package/dist/internal/x509/directory-name.js.map +1 -1
- package/dist/internal/x509/extension-bits.js.map +1 -1
- package/dist/internal/x509/extension-errors.js.map +1 -1
- package/dist/internal/x509/extension-registry.js.map +1 -1
- package/dist/internal/x509/general-name-profile.js.map +1 -1
- package/dist/internal/x509/general-name.js.map +1 -1
- package/dist/internal/x509/name-fields.js.map +1 -1
- package/dist/internal/x509/or-address.js.map +1 -1
- package/dist/jose/base64url.js.map +1 -1
- package/dist/jose/errors.js.map +1 -1
- package/dist/jose/jwe.js.map +1 -1
- package/dist/jose/jwks.js.map +1 -1
- package/dist/jose/jws.js.map +1 -1
- package/dist/jose/jwt.js.map +1 -1
- package/dist/jose/remote-jwks.js.map +1 -1
- package/dist/kdf/argon2-arithmetic.js.map +1 -1
- package/dist/kdf/argon2-core.js.map +1 -1
- package/dist/kdf/argon2-memory.js.map +1 -1
- package/dist/kdf/argon2-portable.js.map +1 -1
- package/dist/kdf/argon2.js.map +1 -1
- package/dist/keys/keys.js.map +1 -1
- package/dist/pem/pem.js.map +1 -1
- package/dist/pkcs/pfx.js.map +1 -1
- package/dist/pkcs/pkcs12-mac.js +1 -1
- package/dist/pkcs/pkcs12-mac.js.map +1 -1
- package/dist/pkcs/pkcs7.d.ts +10 -0
- package/dist/pkcs/pkcs7.js +106 -88
- package/dist/pkcs/pkcs7.js.map +1 -1
- package/dist/result/result.js.map +1 -1
- package/dist/revocation/chain.d.ts +67 -13
- package/dist/revocation/chain.js +429 -301
- package/dist/revocation/chain.js.map +1 -1
- package/dist/revocation/crl.d.ts +65 -11
- package/dist/revocation/crl.js +492 -202
- package/dist/revocation/crl.js.map +1 -1
- package/dist/revocation/ocsp.d.ts +79 -24
- package/dist/revocation/ocsp.js +417 -231
- package/dist/revocation/ocsp.js.map +1 -1
- package/dist/revocation/revocation.d.ts +68 -13
- package/dist/revocation/revocation.js +194 -73
- package/dist/revocation/revocation.js.map +1 -1
- package/dist/revocation.d.ts +4 -4
- package/dist/ssh/ssh.js.map +1 -1
- package/dist/ssh/wire.js.map +1 -1
- package/dist/verify/identity.d.ts +2 -2
- package/dist/verify/identity.js +2 -2
- package/dist/verify/identity.js.map +1 -1
- package/dist/verify/verify.d.ts +84 -32
- package/dist/verify/verify.js +221 -171
- package/dist/verify/verify.js.map +1 -1
- package/dist/verify.d.ts +3 -2
- package/dist/x509/certificate.js.map +1 -1
- package/dist/x509/csr.js.map +1 -1
- package/dist/x509/extensions.js.map +1 -1
- package/dist/x509/fingerprint.js.map +1 -1
- package/dist/x509/name-text.js.map +1 -1
- package/dist/x509/name.js.map +1 -1
- package/dist/x509/parse.d.ts +6 -2
- package/dist/x509/parse.js +121 -121
- package/dist/x509/parse.js.map +1 -1
- package/package.json +11 -11
package/dist/x509/parse.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { childrenOf as e, decodeBoolean as t, decodeIntegerNumber as n, decodeNonNegativeIntegerNumber as r, decodeObjectIdentifier as i, decodeString as a, decodeVisibleString as o, extractBitStringValue as s, parseTime as c, requireElement as l,
|
|
2
|
-
import { decodeFailureResult as
|
|
3
|
-
import { optionalBytesEqual as
|
|
4
|
-
import { OIDS as
|
|
5
|
-
import { describePublicKeyAlgorithm as
|
|
6
|
-
import { readDirectoryNameTlv as
|
|
7
|
-
import { parseDistributionPointReasonFlagsContent as
|
|
8
|
-
import { decodeAndApplyKnownExtension as
|
|
9
|
-
import { decodeSrvName as
|
|
10
|
-
import { derivePublicKey as
|
|
11
|
-
import { pemDecodeOrThrow as
|
|
12
|
-
import { DECODE_REFUSAL_CODES as
|
|
13
|
-
import { parseAuthorityInfoAccessMethodOid as
|
|
14
|
-
import { nameFieldKeyFromOid as
|
|
1
|
+
import { childrenOf as e, decodeBoolean as t, decodeIntegerNumber as n, decodeNonNegativeIntegerNumber as r, decodeObjectIdentifier as i, decodeString as a, decodeVisibleString as o, extractBitStringValue as s, parseTime as c, requireElement as l, signatureBits as u, toHex as d } from "../internal/asn1/asn1.js";
|
|
2
|
+
import { decodeFailureResult as f, decodeRefusalOf as p } from "../internal/asn1/decode-refusal.js";
|
|
3
|
+
import { optionalBytesEqual as m, readElement as h, readRootElement as g, readSequenceChildren as _ } from "../internal/asn1/der.js";
|
|
4
|
+
import { OIDS as v } from "../internal/asn1/oids.js";
|
|
5
|
+
import { describePublicKeyAlgorithm as y, describeSignatureAlgorithm as b } from "../internal/crypto/algorithm-names.js";
|
|
6
|
+
import { readDirectoryNameTlv as x } from "../internal/x509/directory-name.js";
|
|
7
|
+
import { parseDistributionPointReasonFlagsContent as S, parseKeyUsageExtension as C } from "../internal/x509/extension-bits.js";
|
|
8
|
+
import { decodeAndApplyKnownExtension as w } from "../internal/x509/extension-registry.js";
|
|
9
|
+
import { decodeSrvName as T, otherNameValueDer as E, parseGeneralName as D, parseGeneralNames as O, readOtherName as k } from "../internal/x509/general-name.js";
|
|
10
|
+
import { derivePublicKey as A, exportSpkiDer as j, importSpkiDer as M, importSpkiDerOrThrow as N } from "../keys/keys.js";
|
|
11
|
+
import { pemDecodeOrThrow as P, splitPemBlocksOrThrow as F } from "../pem/pem.js";
|
|
12
|
+
import { DECODE_REFUSAL_CODES as I, failureResult as L, rethrowIfInvariant as R, successResult as z } from "../result/result.js";
|
|
13
|
+
import { parseAuthorityInfoAccessMethodOid as B, parseExtendedKeyUsageOid as V } from "./extensions.js";
|
|
14
|
+
import { nameFieldKeyFromOid as H } from "../internal/x509/name-fields.js";
|
|
15
15
|
// src/x509/parse.ts
|
|
16
16
|
/**
|
|
17
17
|
* Certificate and CSR parse boundary.
|
|
@@ -53,45 +53,45 @@ function defineExtensionDecoderMap(e) {
|
|
|
53
53
|
* @param options Custom extension decoders to apply during parsing.
|
|
54
54
|
*/
|
|
55
55
|
function parseCertificateDerOrThrow(e, t) {
|
|
56
|
-
let n =
|
|
56
|
+
let n = _(e, { maxDepth: 64 });
|
|
57
57
|
if (n.length !== 3) throw Error("Malformed Certificate");
|
|
58
|
-
let r = l(n[0], "TBSCertificate"), i = l(n[1], "signatureAlgorithm"), a = l(n[2], "signatureValue"), o = parseTbsCertificateFields(e, r),
|
|
58
|
+
let r = l(n[0], "TBSCertificate"), i = l(n[1], "signatureAlgorithm"), a = l(n[2], "signatureValue"), o = parseTbsCertificateFields(e, r), s = parseExtensionContainer(e, o.extensions), c = parseValidity(e, o.validity), f = parseSubjectPublicKeyInfo(e, o.subjectPublicKeyInfo), p = parseAlgorithmIdentifier(e, o.tbsSignatureAlgorithm), m = parseAlgorithmIdentifier(e, i);
|
|
59
59
|
assertMatchingCertificateSignatureAlgorithms(p, m);
|
|
60
|
-
let h = parseCustomExtensions(
|
|
60
|
+
let h = parseCustomExtensions(s.all, t);
|
|
61
61
|
return {
|
|
62
62
|
der: new Uint8Array(e),
|
|
63
63
|
version: o.version,
|
|
64
|
-
serialNumberHex:
|
|
64
|
+
serialNumberHex: d(o.serialNumber.value),
|
|
65
65
|
tbsCertificateDer: e.slice(r.start - r.headerLength, r.end),
|
|
66
66
|
subjectPublicKeyInfoDer: e.slice(o.subjectPublicKeyInfo.start - o.subjectPublicKeyInfo.headerLength, o.subjectPublicKeyInfo.end),
|
|
67
|
-
|
|
67
|
+
...u(a),
|
|
68
68
|
issuer: parseName(e, o.issuer),
|
|
69
69
|
subject: parseName(e, o.subject),
|
|
70
|
-
notBefore:
|
|
71
|
-
notAfter:
|
|
70
|
+
notBefore: c.notBefore,
|
|
71
|
+
notAfter: c.notAfter,
|
|
72
72
|
signatureAlgorithmOid: m.oid,
|
|
73
|
-
signatureAlgorithmName:
|
|
73
|
+
signatureAlgorithmName: b(m.oid, m.parametersDer),
|
|
74
74
|
...m.parametersDer === void 0 ? {} : { signatureAlgorithmParametersDer: m.parametersDer },
|
|
75
75
|
publicKeyAlgorithmOid: f.oid,
|
|
76
|
-
publicKeyAlgorithmName:
|
|
76
|
+
publicKeyAlgorithmName: y(f.oid, f.parametersOid),
|
|
77
77
|
...f.parametersDer === void 0 ? {} : { publicKeyAlgorithmParametersDer: f.parametersDer },
|
|
78
78
|
...f.parametersOid === void 0 ? {} : { publicKeyParametersOid: f.parametersOid },
|
|
79
|
-
extensions:
|
|
80
|
-
...
|
|
81
|
-
...
|
|
82
|
-
...
|
|
83
|
-
...
|
|
84
|
-
...
|
|
85
|
-
...
|
|
86
|
-
...
|
|
87
|
-
...
|
|
88
|
-
...
|
|
89
|
-
...
|
|
90
|
-
...accessExtensionFields(
|
|
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
91
|
...h.decodedExtensions === void 0 ? {} : { decodedExtensions: h.decodedExtensions },
|
|
92
92
|
...h.decodedExtensionMap === void 0 ? {} : { decodedExtensionMap: h.decodedExtensionMap },
|
|
93
|
-
...
|
|
94
|
-
...
|
|
93
|
+
...s.subjectKeyIdentifier === void 0 ? {} : { subjectKeyIdentifier: s.subjectKeyIdentifier },
|
|
94
|
+
...s.authorityKeyIdentifier === void 0 ? {} : { authorityKeyIdentifier: s.authorityKeyIdentifier }
|
|
95
95
|
};
|
|
96
96
|
}
|
|
97
97
|
function parseCustomExtensions(e, t) {
|
|
@@ -167,9 +167,9 @@ function validateCertificateUniqueId(e, t, n) {
|
|
|
167
167
|
*/
|
|
168
168
|
function parseCertificateDer(e, t) {
|
|
169
169
|
try {
|
|
170
|
-
return
|
|
170
|
+
return z(parseCertificateDerOrThrow(e, t));
|
|
171
171
|
} catch (e) {
|
|
172
|
-
return
|
|
172
|
+
return R(e), f(e, I, "Malformed certificate");
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
175
|
/**
|
|
@@ -191,7 +191,7 @@ function parseCertificateDer(e, t) {
|
|
|
191
191
|
* @param options Custom extension decoders to apply during parsing.
|
|
192
192
|
*/
|
|
193
193
|
function parseCertificatePemOrThrow(e, t) {
|
|
194
|
-
return parseCertificateDerOrThrow(
|
|
194
|
+
return parseCertificateDerOrThrow(P("CERTIFICATE", e), t);
|
|
195
195
|
}
|
|
196
196
|
/**
|
|
197
197
|
* Decode a PEM-encoded X.509 certificate into a {@linkcode ParsedCertificate}.
|
|
@@ -207,9 +207,9 @@ function parseCertificatePemOrThrow(e, t) {
|
|
|
207
207
|
*/
|
|
208
208
|
function parseCertificatePem(e, t) {
|
|
209
209
|
try {
|
|
210
|
-
return
|
|
210
|
+
return z(parseCertificatePemOrThrow(e, t));
|
|
211
211
|
} catch (e) {
|
|
212
|
-
return
|
|
212
|
+
return R(e), f(e, I, "Malformed certificate");
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
215
|
/** Normalizes a PEM bundle or single DER certificate source into parsed certificates. */
|
|
@@ -242,9 +242,9 @@ function parseCertificateChainPemOrThrow(e, t) {
|
|
|
242
242
|
*/
|
|
243
243
|
function parseCertificateChainPem(e, t) {
|
|
244
244
|
try {
|
|
245
|
-
return
|
|
245
|
+
return z(parseCertificateChainPemOrThrow(e, t));
|
|
246
246
|
} catch (e) {
|
|
247
|
-
return
|
|
247
|
+
return R(e), f(e, I, "Malformed certificate chain");
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
250
|
/**
|
|
@@ -254,33 +254,33 @@ function parseCertificateChainPem(e, t) {
|
|
|
254
254
|
* @param options Custom extension decoders to apply during parsing.
|
|
255
255
|
*/
|
|
256
256
|
function parseCertificateSigningRequestDerOrThrow(e, t) {
|
|
257
|
-
let n =
|
|
257
|
+
let n = _(e, { maxDepth: 64 });
|
|
258
258
|
if (n.length !== 3) throw Error("Malformed CertificationRequest");
|
|
259
|
-
let r = l(n[0], "CertificationRequestInfo"), i = l(n[1], "signatureAlgorithm"), a = l(n[2], "signatureValue"), o = parseCertificationRequestInfoFields(e, r),
|
|
259
|
+
let r = l(n[0], "CertificationRequestInfo"), i = l(n[1], "signatureAlgorithm"), a = l(n[2], "signatureValue"), o = parseCertificationRequestInfoFields(e, r), s = parseRequestedExtensions(e, o.attributes), c = parseSubjectPublicKeyInfo(e, o.subjectPublicKeyInfo), d = parseAlgorithmIdentifier(e, i), f = parseCustomExtensions(s.all, t);
|
|
260
260
|
return {
|
|
261
261
|
version: o.version,
|
|
262
262
|
certificationRequestInfoDer: e.slice(r.start - r.headerLength, r.end),
|
|
263
263
|
subjectPublicKeyInfoDer: e.slice(o.subjectPublicKeyInfo.start - o.subjectPublicKeyInfo.headerLength, o.subjectPublicKeyInfo.end),
|
|
264
|
-
|
|
264
|
+
...u(a),
|
|
265
265
|
subject: parseName(e, o.subject),
|
|
266
266
|
signatureAlgorithmOid: d.oid,
|
|
267
|
-
signatureAlgorithmName:
|
|
267
|
+
signatureAlgorithmName: b(d.oid, d.parametersDer),
|
|
268
268
|
...d.parametersDer === void 0 ? {} : { signatureAlgorithmParametersDer: d.parametersDer },
|
|
269
|
-
publicKeyAlgorithmOid:
|
|
270
|
-
publicKeyAlgorithmName:
|
|
271
|
-
...
|
|
272
|
-
...
|
|
273
|
-
requestedExtensions:
|
|
274
|
-
...
|
|
275
|
-
...
|
|
276
|
-
...
|
|
277
|
-
...
|
|
278
|
-
...
|
|
279
|
-
...
|
|
280
|
-
...
|
|
281
|
-
...
|
|
282
|
-
...
|
|
283
|
-
...accessExtensionFields(
|
|
269
|
+
publicKeyAlgorithmOid: c.oid,
|
|
270
|
+
publicKeyAlgorithmName: y(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
284
|
...f.decodedExtensions === void 0 ? {} : { decodedExtensions: f.decodedExtensions },
|
|
285
285
|
...f.decodedExtensionMap === void 0 ? {} : { decodedExtensionMap: f.decodedExtensionMap }
|
|
286
286
|
};
|
|
@@ -309,13 +309,13 @@ function parseCertificationRequestInfoFields(t, r) {
|
|
|
309
309
|
*/
|
|
310
310
|
function parseCertificateSigningRequestDer(e, t) {
|
|
311
311
|
try {
|
|
312
|
-
return
|
|
312
|
+
return z(parseCertificateSigningRequestDerOrThrow(e, t));
|
|
313
313
|
} catch (e) {
|
|
314
|
-
return
|
|
314
|
+
return R(e), f(e, I, "Malformed certificate signing request");
|
|
315
315
|
}
|
|
316
316
|
}
|
|
317
317
|
function parseCertificatesFromPemBlocks(e, t) {
|
|
318
|
-
return
|
|
318
|
+
return F(e).filter((e) => e.label === "CERTIFICATE").map((e) => parseCertificateDerOrThrow(e.bytes, t));
|
|
319
319
|
}
|
|
320
320
|
function hasParsedCertificateShape(e) {
|
|
321
321
|
return "subjectPublicKeyInfoDer" in e;
|
|
@@ -327,7 +327,7 @@ function hasParsedCertificateShape(e) {
|
|
|
327
327
|
* @param options Custom extension decoders to apply during parsing.
|
|
328
328
|
*/
|
|
329
329
|
function parseCertificateSigningRequestPemOrThrow(e, t) {
|
|
330
|
-
return parseCertificateSigningRequestDerOrThrow(
|
|
330
|
+
return parseCertificateSigningRequestDerOrThrow(P("CERTIFICATE REQUEST", e), t);
|
|
331
331
|
}
|
|
332
332
|
/**
|
|
333
333
|
* Decode a PEM-encoded PKCS#10 CSR into a {@linkcode ParsedCertificateSigningRequest}.
|
|
@@ -337,9 +337,9 @@ function parseCertificateSigningRequestPemOrThrow(e, t) {
|
|
|
337
337
|
*/
|
|
338
338
|
function parseCertificateSigningRequestPem(e, t) {
|
|
339
339
|
try {
|
|
340
|
-
return
|
|
340
|
+
return z(parseCertificateSigningRequestPemOrThrow(e, t));
|
|
341
341
|
} catch (e) {
|
|
342
|
-
return
|
|
342
|
+
return R(e), f(e, I, "Malformed certificate signing request");
|
|
343
343
|
}
|
|
344
344
|
}
|
|
345
345
|
/**
|
|
@@ -371,7 +371,7 @@ function parseCertificateSigningRequestPem(e, t) {
|
|
|
371
371
|
* @see {@linkcode getSubjectPublicKey} for the non-throwing variant
|
|
372
372
|
*/
|
|
373
373
|
function getSubjectPublicKeyOrThrow(e, t) {
|
|
374
|
-
return
|
|
374
|
+
return N(e.subjectPublicKeyInfoDer, t);
|
|
375
375
|
}
|
|
376
376
|
/**
|
|
377
377
|
* Import the subject public key of a parsed certificate or CSR as a WebCrypto `CryptoKey`.
|
|
@@ -379,11 +379,11 @@ function getSubjectPublicKeyOrThrow(e, t) {
|
|
|
379
379
|
* @see `getSubjectPublicKeyOrThrow` for the throwing variant
|
|
380
380
|
*/
|
|
381
381
|
function getSubjectPublicKey(e, t) {
|
|
382
|
-
return
|
|
382
|
+
return M(e.subjectPublicKeyInfoDer, t);
|
|
383
383
|
}
|
|
384
384
|
/** Extract the AlgorithmIdentifier TLV from a SubjectPublicKeyInfo DER buffer. */
|
|
385
385
|
function subjectPublicKeyInfoAlgorithmDer(e) {
|
|
386
|
-
let t =
|
|
386
|
+
let t = _(e, { maxDepth: 64 }), n = l(t[0], "SubjectPublicKeyInfo algorithm");
|
|
387
387
|
return e.slice(n.start - n.headerLength, n.end);
|
|
388
388
|
}
|
|
389
389
|
/**
|
|
@@ -396,8 +396,8 @@ function subjectPublicKeyInfoAlgorithmDer(e) {
|
|
|
396
396
|
* mismatch or a cross-algorithm (`key_type_mismatch`) one.
|
|
397
397
|
*/
|
|
398
398
|
async function compareCertificateToPrivateKey(e, t) {
|
|
399
|
-
let n = await
|
|
400
|
-
return
|
|
399
|
+
let n = await j(await A(t));
|
|
400
|
+
return m(n, e) ? "match" : m(subjectPublicKeyInfoAlgorithmDer(n), subjectPublicKeyInfoAlgorithmDer(e)) ? "key_mismatch" : "key_type_mismatch";
|
|
401
401
|
}
|
|
402
402
|
/**
|
|
403
403
|
* Check whether a certificate's subject public key belongs to a private key.
|
|
@@ -494,20 +494,20 @@ async function matchCertificatePrivateKey(e, t) {
|
|
|
494
494
|
try {
|
|
495
495
|
n = parseCertificateFromSource(e);
|
|
496
496
|
} catch (e) {
|
|
497
|
-
|
|
498
|
-
let t =
|
|
499
|
-
return t === void 0 ?
|
|
497
|
+
R(e);
|
|
498
|
+
let t = p(e, I);
|
|
499
|
+
return t === void 0 ? L("malformed_certificate", e instanceof Error ? e.message : "Malformed certificate") : L(t.code, t.message);
|
|
500
500
|
}
|
|
501
501
|
let r;
|
|
502
502
|
try {
|
|
503
503
|
r = await compareCertificateToPrivateKey(n.subjectPublicKeyInfoDer, t);
|
|
504
504
|
} catch (e) {
|
|
505
|
-
return
|
|
505
|
+
return R(e), L("unsupported_private_key", e instanceof Error ? e.message : "Unsupported private key");
|
|
506
506
|
}
|
|
507
507
|
switch (r) {
|
|
508
|
-
case "match": return
|
|
509
|
-
case "key_mismatch": return
|
|
510
|
-
case "key_type_mismatch": return
|
|
508
|
+
case "match": return z(void 0);
|
|
509
|
+
case "key_mismatch": return L("key_mismatch", "Private key does not match the certificate's subject public key");
|
|
510
|
+
case "key_type_mismatch": return L("key_type_mismatch", "Private key algorithm does not match the certificate's subject public key algorithm");
|
|
511
511
|
default: throw Error(`Unhandled key comparison result: ${String(r)}`);
|
|
512
512
|
}
|
|
513
513
|
}
|
|
@@ -598,7 +598,7 @@ function parseRequestedExtensions(t, n) {
|
|
|
598
598
|
if (s.tag !== 49) throw Error("CSR attribute values must use SET");
|
|
599
599
|
let c = e(t, s);
|
|
600
600
|
if (c.length === 0) throw Error("CSR attribute values must not be empty");
|
|
601
|
-
if (i(o.value) ===
|
|
601
|
+
if (i(o.value) === v.extensionRequest) {
|
|
602
602
|
if (r !== void 0) throw Error("extensionRequest attribute must not repeat");
|
|
603
603
|
if (c.length !== 1) throw Error("extensionRequest attribute must contain exactly one value");
|
|
604
604
|
r = parseExtensionSequence(t, l(c[0], "requested extensions"), "csr");
|
|
@@ -609,8 +609,8 @@ function parseRequestedExtensions(t, n) {
|
|
|
609
609
|
/** Walk a SEQUENCE OF Extension and decode each one, populating known-extension slots. */
|
|
610
610
|
function parseExtensionSequence(n, r, a) {
|
|
611
611
|
let o = [], s = {}, c = /* @__PURE__ */ new Set();
|
|
612
|
-
for (let
|
|
613
|
-
let r = e(n,
|
|
612
|
+
for (let u of e(n, r)) {
|
|
613
|
+
let r = e(n, u);
|
|
614
614
|
if (r.length < 2 || r.length > 3) throw Error("Malformed Extension");
|
|
615
615
|
let f = l(r[0], "extension OID"), p = i(f.value);
|
|
616
616
|
if (c.has(p)) throw Error(`Duplicate extension OID: ${p}`);
|
|
@@ -623,8 +623,8 @@ function parseExtensionSequence(n, r, a) {
|
|
|
623
623
|
oid: p,
|
|
624
624
|
critical: h,
|
|
625
625
|
valueDer: new Uint8Array(_.value),
|
|
626
|
-
valueHex:
|
|
627
|
-
}),
|
|
626
|
+
valueHex: d(_.value)
|
|
627
|
+
}), w(a, p, s, _.value);
|
|
628
628
|
}
|
|
629
629
|
return {
|
|
630
630
|
all: o,
|
|
@@ -642,7 +642,7 @@ function parseName(t, n) {
|
|
|
642
642
|
for (let t of e.attributes) i.push(t), t.key !== void 0 && a[t.key] === void 0 && (a[t.key] = t.value);
|
|
643
643
|
}
|
|
644
644
|
return {
|
|
645
|
-
derHex:
|
|
645
|
+
derHex: d(t.slice(n.start - n.headerLength, n.end)),
|
|
646
646
|
rdns: r,
|
|
647
647
|
attributes: i,
|
|
648
648
|
values: a
|
|
@@ -661,7 +661,7 @@ function parseNameAttributeSet(t, n) {
|
|
|
661
661
|
if (n.length !== 2) throw Error("AttributeTypeAndValue must contain type and value");
|
|
662
662
|
let c = l(n[0], "name OID");
|
|
663
663
|
if (c.tag !== 6) throw Error("AttributeTypeAndValue type must use OBJECT IDENTIFIER");
|
|
664
|
-
let u = i(c.value), d = l(n[1], "name value"), f =
|
|
664
|
+
let u = i(c.value), d = l(n[1], "name value"), f = H(u), p = a(d.tag, d.value), m = f === void 0 ? {
|
|
665
665
|
oid: u,
|
|
666
666
|
valueTag: d.tag,
|
|
667
667
|
value: p
|
|
@@ -674,7 +674,7 @@ function parseNameAttributeSet(t, n) {
|
|
|
674
674
|
r.push(m), f !== void 0 && o[f] === void 0 && (o[f] = p);
|
|
675
675
|
}
|
|
676
676
|
return {
|
|
677
|
-
derHex:
|
|
677
|
+
derHex: d(t.slice(n.start - n.headerLength, n.end)),
|
|
678
678
|
attributes: r,
|
|
679
679
|
values: o
|
|
680
680
|
};
|
|
@@ -717,11 +717,11 @@ function parseAlgorithmIdentifier(t, n) {
|
|
|
717
717
|
};
|
|
718
718
|
}
|
|
719
719
|
function assertMatchingCertificateSignatureAlgorithms(e, t) {
|
|
720
|
-
if (e.oid !== t.oid || !
|
|
720
|
+
if (e.oid !== t.oid || !m(e.parametersDer, t.parametersDer)) throw Error("Certificate signatureAlgorithm must match TBSCertificate signature");
|
|
721
721
|
}
|
|
722
722
|
/** Decodes the Basic Constraints extension value DER. */
|
|
723
723
|
function parseBasicConstraints(n) {
|
|
724
|
-
let i =
|
|
724
|
+
let i = g(n, { maxDepth: 64 });
|
|
725
725
|
if (i.tag !== 48) throw Error("basicConstraints must use SEQUENCE");
|
|
726
726
|
let a = e(n, i), o = !1, s, c = !1, l = !1;
|
|
727
727
|
for (let e of a) if (e.tag === 1) {
|
|
@@ -740,20 +740,20 @@ function parseBasicConstraints(n) {
|
|
|
740
740
|
}
|
|
741
741
|
/** Decodes the Key Usage BIT STRING extension value. */
|
|
742
742
|
function parseKeyUsage(e) {
|
|
743
|
-
return
|
|
743
|
+
return C(e);
|
|
744
744
|
}
|
|
745
745
|
/** Decodes the Extended Key Usage SEQUENCE OF OIDs. */
|
|
746
746
|
function parseExtendedKeyUsage(e) {
|
|
747
|
-
let t =
|
|
747
|
+
let t = _(e, { maxDepth: 64 });
|
|
748
748
|
if (t.length === 0) throw Error("extendedKeyUsage must not be empty");
|
|
749
749
|
return t.map((e) => {
|
|
750
750
|
if (e.tag !== 6) throw Error("extendedKeyUsage entry must use OBJECT IDENTIFIER");
|
|
751
|
-
return
|
|
751
|
+
return V(i(e.value));
|
|
752
752
|
});
|
|
753
753
|
}
|
|
754
754
|
/** Decodes the Certificate Policies extension value. */
|
|
755
755
|
function parseCertificatePolicies(t) {
|
|
756
|
-
let n = l(
|
|
756
|
+
let n = l(g(t, { maxDepth: 64 }), "certificatePolicies sequence"), r = e(t, n);
|
|
757
757
|
if (r.length === 0) throw Error("certificatePolicies must not be empty");
|
|
758
758
|
return r.map((e) => parsePolicyInformation(t, e));
|
|
759
759
|
}
|
|
@@ -773,14 +773,14 @@ function parsePolicyInformation(t, n) {
|
|
|
773
773
|
function parsePolicyQualifierInfo(t, n) {
|
|
774
774
|
let r = e(t, n), o = i(l(r[0], "policyQualifierId").value), s = l(r[1], "policyQualifier");
|
|
775
775
|
if (r.length > 2) throw Error("policyQualifierInfo has unexpected trailing fields");
|
|
776
|
-
if (o ===
|
|
776
|
+
if (o === v.cpsPolicyQualifier) {
|
|
777
777
|
if (s.tag !== 22) throw Error("cps policy qualifier must use IA5String");
|
|
778
778
|
return {
|
|
779
779
|
type: "cps",
|
|
780
780
|
uri: a(s.tag, s.value)
|
|
781
781
|
};
|
|
782
782
|
}
|
|
783
|
-
return o ===
|
|
783
|
+
return o === v.userNoticePolicyQualifier ? {
|
|
784
784
|
type: "userNotice",
|
|
785
785
|
...parseUserNoticePolicyQualifierInfo(t, s)
|
|
786
786
|
} : {
|
|
@@ -835,12 +835,12 @@ function parsePolicyNoticeNumbers(t, n) {
|
|
|
835
835
|
}
|
|
836
836
|
/** Decodes the Policy Mappings extension value. */
|
|
837
837
|
function parsePolicyMappings(t) {
|
|
838
|
-
let n = l(
|
|
838
|
+
let n = l(g(t, { maxDepth: 64 }), "policyMappings sequence"), r = e(t, n);
|
|
839
839
|
if (r.length === 0) throw Error("policyMappings must not be empty");
|
|
840
840
|
return r.map((n) => {
|
|
841
841
|
let r = e(t, n), a = i(l(r[0], "policyMappings issuerDomainPolicy").value), o = i(l(r[1], "policyMappings subjectDomainPolicy").value);
|
|
842
842
|
if (r.length > 2) throw Error("policyMappings entry has unexpected trailing fields");
|
|
843
|
-
if (a ===
|
|
843
|
+
if (a === v.anyPolicy || o === v.anyPolicy) throw Error("policyMappings must not use anyPolicy");
|
|
844
844
|
return {
|
|
845
845
|
issuerDomainPolicy: a,
|
|
846
846
|
subjectDomainPolicy: o
|
|
@@ -849,7 +849,7 @@ function parsePolicyMappings(t) {
|
|
|
849
849
|
}
|
|
850
850
|
/** Decodes the Policy Constraints extension value. */
|
|
851
851
|
function parsePolicyConstraints(t) {
|
|
852
|
-
let n = l(
|
|
852
|
+
let n = l(g(t, { maxDepth: 64 }), "policyConstraints sequence"), i, a;
|
|
853
853
|
for (let o of e(t, n)) if (o.tag === 128) {
|
|
854
854
|
if (i !== void 0) throw Error("policyConstraints must not repeat requireExplicitPolicy");
|
|
855
855
|
i = r(o.value, "policyConstraints requireExplicitPolicy");
|
|
@@ -865,25 +865,25 @@ function parsePolicyConstraints(t) {
|
|
|
865
865
|
}
|
|
866
866
|
/** Decodes the Inhibit anyPolicy extension (single INTEGER). */
|
|
867
867
|
function parseInhibitAnyPolicy(e) {
|
|
868
|
-
let t = l(
|
|
868
|
+
let t = l(g(e, { maxDepth: 64 }), "inhibitAnyPolicy integer");
|
|
869
869
|
if (t.tag !== 2) throw Error("inhibitAnyPolicy must be an INTEGER");
|
|
870
870
|
return { skipCerts: r(t.value, "inhibitAnyPolicy skipCerts") };
|
|
871
871
|
}
|
|
872
872
|
/** Decodes a subjectAltName or issuerAltName SEQUENCE OF GeneralName. */
|
|
873
873
|
function parseSubjectAltNames(e, t = "subjectAltName") {
|
|
874
|
-
let n = l(
|
|
874
|
+
let n = l(g(e, { maxDepth: 64 }), `${t} sequence`);
|
|
875
875
|
if (n.tag !== 48) throw Error(`${t} must use SEQUENCE`);
|
|
876
|
-
return
|
|
876
|
+
return O(e, n);
|
|
877
877
|
}
|
|
878
878
|
/** Decodes a bare DER-encoded X.501 Name, as carried in a `directoryName` GeneralName. */
|
|
879
879
|
function parseDistinguishedNameDer(e) {
|
|
880
|
-
let t = l(
|
|
880
|
+
let t = l(g(e, { maxDepth: 64 }), "distinguished name sequence");
|
|
881
881
|
if (t.tag !== 48) throw Error("distinguished name must use SEQUENCE");
|
|
882
882
|
return parseName(e, t);
|
|
883
883
|
}
|
|
884
884
|
/** Decodes the Authority Information Access extension value. */
|
|
885
885
|
function parseAuthorityInfoAccess(t) {
|
|
886
|
-
let n = l(
|
|
886
|
+
let n = l(g(t, { maxDepth: 64 }), "authorityInfoAccess sequence");
|
|
887
887
|
if (n.tag !== 48) throw Error("authorityInfoAccess must use SEQUENCE");
|
|
888
888
|
let r = e(t, n);
|
|
889
889
|
if (r.length === 0) throw Error("authorityInfoAccess must not be empty");
|
|
@@ -894,14 +894,14 @@ function parseAuthorityInfoAccess(t) {
|
|
|
894
894
|
let a = l(r[0], "authorityInfoAccess method"), o = l(r[1], "authorityInfoAccess location");
|
|
895
895
|
if (a.tag !== 6) throw Error("authorityInfoAccess method must use OBJECT IDENTIFIER");
|
|
896
896
|
return {
|
|
897
|
-
method:
|
|
898
|
-
location:
|
|
897
|
+
method: B(i(a.value)),
|
|
898
|
+
location: D(t, o)
|
|
899
899
|
};
|
|
900
900
|
});
|
|
901
901
|
}
|
|
902
902
|
/** Decodes the CRL Distribution Points extension value. */
|
|
903
903
|
function parseCrlDistributionPoints(t) {
|
|
904
|
-
let n = l(
|
|
904
|
+
let n = l(g(t, { maxDepth: 64 }), "CRLDistributionPoints sequence");
|
|
905
905
|
if (n.tag !== 48) throw Error("CRLDistributionPoints must use SEQUENCE");
|
|
906
906
|
let r = e(t, n);
|
|
907
907
|
if (r.length === 0) throw Error("CRLDistributionPoints must not be empty");
|
|
@@ -929,11 +929,11 @@ function parseDistributionPointField(e, t, n) {
|
|
|
929
929
|
return;
|
|
930
930
|
case 129:
|
|
931
931
|
if (n.reasons !== void 0) throw Error("DistributionPoint reasons must not repeat");
|
|
932
|
-
n.reasons =
|
|
932
|
+
n.reasons = S(t.value);
|
|
933
933
|
return;
|
|
934
934
|
case 162:
|
|
935
935
|
if (n.crlIssuer !== void 0) throw Error("DistributionPoint crlIssuer must not repeat");
|
|
936
|
-
n.crlIssuer =
|
|
936
|
+
n.crlIssuer = O(e, t);
|
|
937
937
|
return;
|
|
938
938
|
default: throw Error(`Unsupported DistributionPoint field tag: ${String(t.tag)}`);
|
|
939
939
|
}
|
|
@@ -949,7 +949,7 @@ function parseDistributionPointName(t, n) {
|
|
|
949
949
|
for (let e of n) if ((e.tag & 192) != 128) throw Error("distributionPointName fullName must contain GeneralName entries");
|
|
950
950
|
return {
|
|
951
951
|
type: "fullName",
|
|
952
|
-
fullName: n.map((e) =>
|
|
952
|
+
fullName: n.map((e) => D(t, e))
|
|
953
953
|
};
|
|
954
954
|
}
|
|
955
955
|
if (i.tag === 161) return {
|
|
@@ -960,7 +960,7 @@ function parseDistributionPointName(t, n) {
|
|
|
960
960
|
}
|
|
961
961
|
/** Decodes the Name Constraints extension value. */
|
|
962
962
|
function parseNameConstraints(t) {
|
|
963
|
-
let n = l(
|
|
963
|
+
let n = l(g(t, {
|
|
964
964
|
maxDepth: 64,
|
|
965
965
|
allowOpaqueConstructedTags: [
|
|
966
966
|
160,
|
|
@@ -1009,14 +1009,14 @@ function validateGeneralSubtreeBounds(e) {
|
|
|
1009
1009
|
function parseNameConstraintGeneralName(e, t) {
|
|
1010
1010
|
switch (t.tag) {
|
|
1011
1011
|
case 160: {
|
|
1012
|
-
let { typeId: n, value: r } =
|
|
1013
|
-
return n ===
|
|
1012
|
+
let { typeId: n, value: r } = k(e, t);
|
|
1013
|
+
return n === v.idOnDnsSrv ? {
|
|
1014
1014
|
type: "srv",
|
|
1015
|
-
value:
|
|
1015
|
+
value: T(r)
|
|
1016
1016
|
} : {
|
|
1017
1017
|
type: "otherName",
|
|
1018
1018
|
typeId: n,
|
|
1019
|
-
value:
|
|
1019
|
+
value: E(e, r)
|
|
1020
1020
|
};
|
|
1021
1021
|
}
|
|
1022
1022
|
case 129: return {
|
|
@@ -1049,7 +1049,7 @@ function parseNameConstraintGeneralName(e, t) {
|
|
|
1049
1049
|
throw Error(`Invalid IP name constraint: expected 8 (IPv4) or 32 (IPv6) bytes, got ${String(t.value.length)}`);
|
|
1050
1050
|
case 164: return {
|
|
1051
1051
|
type: "directoryName",
|
|
1052
|
-
derHex:
|
|
1052
|
+
derHex: d(x(t))
|
|
1053
1053
|
};
|
|
1054
1054
|
case 165: return {
|
|
1055
1055
|
type: "ediPartyName",
|
|
@@ -1094,7 +1094,7 @@ function decodeDisplayText(e) {
|
|
|
1094
1094
|
}
|
|
1095
1095
|
/** Decodes the Authority Key Identifier extension, returning the keyIdentifier hex or undefined. */
|
|
1096
1096
|
function parseAuthorityKeyIdentifier(e) {
|
|
1097
|
-
let t = l(
|
|
1097
|
+
let t = l(h(e, 0), "authorityKeyIdentifier sequence");
|
|
1098
1098
|
if (t.end !== e.length) throw Error("Trailing data after DER element");
|
|
1099
1099
|
let n = {
|
|
1100
1100
|
sawAuthorityCertIssuer: !1,
|
|
@@ -1102,7 +1102,7 @@ function parseAuthorityKeyIdentifier(e) {
|
|
|
1102
1102
|
lastFieldOrder: -1
|
|
1103
1103
|
}, r = t.start;
|
|
1104
1104
|
for (; r < t.end;) {
|
|
1105
|
-
let i =
|
|
1105
|
+
let i = h(e, r);
|
|
1106
1106
|
if (i.end > t.end) throw Error("DER child exceeds parent length");
|
|
1107
1107
|
parseAuthorityKeyIdentifierField(e, i, n), r = i.end;
|
|
1108
1108
|
}
|
|
@@ -1127,7 +1127,7 @@ function parseAuthorityKeyIdentifierField(e, t, n) {
|
|
|
1127
1127
|
function parseAuthorityKeyIdentifierKeyId(e, t) {
|
|
1128
1128
|
if (t.keyIdentifier !== void 0) throw Error("authorityKeyIdentifier keyIdentifier must not repeat");
|
|
1129
1129
|
if (t.lastFieldOrder >= 0) throw Error("authorityKeyIdentifier fields must preserve DER order");
|
|
1130
|
-
t.keyIdentifier =
|
|
1130
|
+
t.keyIdentifier = d(e.value), t.lastFieldOrder = 0;
|
|
1131
1131
|
}
|
|
1132
1132
|
function parseAuthorityKeyIdentifierIssuer(t, n, r) {
|
|
1133
1133
|
if (r.sawAuthorityCertIssuer) throw Error("authorityKeyIdentifier authorityCertIssuer must not repeat");
|
|
@@ -1136,7 +1136,7 @@ function parseAuthorityKeyIdentifierIssuer(t, n, r) {
|
|
|
1136
1136
|
if (i.length === 0) throw Error("authorityKeyIdentifier authorityCertIssuer must contain GeneralName entries");
|
|
1137
1137
|
for (let e of i) {
|
|
1138
1138
|
if ((e.tag & 192) != 128) throw Error("authorityKeyIdentifier authorityCertIssuer must contain GeneralName entries");
|
|
1139
|
-
|
|
1139
|
+
D(t, e);
|
|
1140
1140
|
}
|
|
1141
1141
|
r.sawAuthorityCertIssuer = !0, r.lastFieldOrder = 1;
|
|
1142
1142
|
}
|