micro509 0.13.0 → 0.14.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/README.md +78 -30
- package/dist/crypto/crypto.d.ts +73 -0
- package/dist/crypto/crypto.js +74 -0
- package/dist/crypto/crypto.js.map +1 -0
- package/dist/crypto.d.ts +4 -0
- package/dist/crypto.js +2 -0
- package/dist/der/der.d.ts +1 -1
- package/dist/index.d.ts +13 -9
- package/dist/index.js +17 -15
- package/dist/internal/asn1/asn1.js +21 -10
- package/dist/internal/asn1/asn1.js.map +1 -1
- package/dist/internal/asn1/der.d.ts +4 -2
- package/dist/internal/asn1/der.js +18 -5
- package/dist/internal/asn1/der.js.map +1 -1
- package/dist/internal/asn1/oids.js +7 -1
- package/dist/internal/crypto/algorithm-names.js +4 -0
- package/dist/internal/crypto/algorithm-names.js.map +1 -1
- package/dist/internal/crypto/pbes2.d.ts +38 -0
- package/dist/internal/crypto/pbes2.js +9 -10
- package/dist/internal/crypto/pbes2.js.map +1 -1
- package/dist/internal/crypto/rsa-pss.js +2 -0
- package/dist/internal/crypto/rsa-pss.js.map +1 -1
- package/dist/internal/crypto/sig-verify.d.ts +31 -0
- package/dist/internal/crypto/sig-verify.js +10 -8
- package/dist/internal/crypto/sig-verify.js.map +1 -1
- package/dist/internal/shared/base64.js +7 -1
- package/dist/internal/shared/base64.js.map +1 -1
- package/dist/internal/shared/dn.d.ts +16 -0
- package/dist/internal/shared/dn.js +13 -6
- package/dist/internal/shared/dn.js.map +1 -1
- package/dist/internal/shared/ip.d.ts +69 -0
- package/dist/internal/shared/ip.js +18 -1
- package/dist/internal/shared/ip.js.map +1 -1
- package/dist/internal/verify/verify-path.d.ts +7 -0
- package/dist/internal/verify/verify-path.js +36 -36
- package/dist/internal/x509/directory-name.js +24 -0
- package/dist/internal/x509/directory-name.js.map +1 -0
- package/dist/internal/x509/extension-bits.js +13 -10
- package/dist/internal/x509/extension-bits.js.map +1 -1
- package/dist/internal/x509/extension-errors.d.ts +6 -0
- package/dist/internal/x509/extension-errors.js +20 -0
- package/dist/internal/x509/extension-errors.js.map +1 -0
- package/dist/internal/x509/extension-registry.js +113 -55
- package/dist/internal/x509/extension-registry.js.map +1 -1
- package/dist/internal/x509/general-name-tags.js +28 -0
- package/dist/internal/x509/general-name-tags.js.map +1 -0
- package/dist/internal/x509/general-name.js +97 -0
- package/dist/internal/x509/general-name.js.map +1 -0
- package/dist/internal/x509/name-fields.js +20 -10
- package/dist/internal/x509/name-fields.js.map +1 -1
- package/dist/keys/keys.d.ts +16 -2
- package/dist/keys/keys.js +311 -170
- package/dist/keys/keys.js.map +1 -1
- package/dist/keys.d.ts +3 -2
- package/dist/keys.js +3 -2
- package/dist/pem/pem.d.ts +3 -2
- package/dist/pem/pem.js +112 -30
- package/dist/pem/pem.js.map +1 -1
- package/dist/pkcs/pkcs12-mac.js +3 -3
- package/dist/pkcs/pkcs12-mac.js.map +1 -1
- package/dist/pkcs/pkcs7.d.ts +85 -21
- package/dist/pkcs/pkcs7.js +261 -186
- package/dist/pkcs/pkcs7.js.map +1 -1
- package/dist/pkcs.d.ts +2 -2
- package/dist/result/result.d.ts +18 -10
- package/dist/result/result.js +20 -12
- package/dist/result/result.js.map +1 -1
- package/dist/result.d.ts +2 -2
- package/dist/result.js +2 -2
- package/dist/revocation/chain.js +77 -81
- package/dist/revocation/chain.js.map +1 -1
- package/dist/revocation/crl.d.ts +13 -2
- package/dist/revocation/crl.js +415 -236
- package/dist/revocation/crl.js.map +1 -1
- package/dist/revocation/ocsp.d.ts +58 -17
- package/dist/revocation/ocsp.js +185 -173
- package/dist/revocation/ocsp.js.map +1 -1
- package/dist/revocation/revocation.d.ts +4 -4
- package/dist/revocation/revocation.js +48 -30
- package/dist/revocation/revocation.js.map +1 -1
- package/dist/revocation.d.ts +4 -4
- package/dist/revocation.js +5 -5
- package/dist/verify/identity.d.ts +2 -1
- package/dist/verify/identity.js +2 -1
- package/dist/verify/identity.js.map +1 -1
- package/dist/verify/policy.d.ts +6 -1
- package/dist/verify/verify.d.ts +4 -2
- package/dist/verify/verify.js +32 -14
- package/dist/verify/verify.js.map +1 -1
- package/dist/verify.d.ts +2 -1
- package/dist/verify.js +4 -3
- package/dist/x509/certificate.d.ts +36 -13
- package/dist/x509/certificate.js +36 -19
- package/dist/x509/certificate.js.map +1 -1
- package/dist/x509/csr.d.ts +6 -3
- package/dist/x509/extensions.d.ts +58 -21
- package/dist/x509/extensions.js +384 -117
- package/dist/x509/extensions.js.map +1 -1
- package/dist/x509/name-text.js +2 -0
- package/dist/x509/name-text.js.map +1 -1
- package/dist/x509/name.d.ts +8 -5
- package/dist/x509/name.js +17 -12
- package/dist/x509/name.js.map +1 -1
- package/dist/x509/parse.d.ts +104 -18
- package/dist/x509/parse.js +127 -163
- package/dist/x509/parse.js.map +1 -1
- package/dist/x509.d.ts +8 -5
- package/dist/x509.js +10 -8
- package/package.json +28 -20
package/dist/x509/parse.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { optionalBytesEqual as e, readElement as t, readRootElement as n, readSequenceChildren as r } from "../internal/asn1/der.js";
|
|
2
2
|
import { childrenOf as i, decodeBoolean as a, decodeIntegerNumber as o, decodeNonNegativeIntegerNumber as s, decodeObjectIdentifier as c, decodeString as l, extractBitStringValue as u, parseTime as d, requireElement as f, toHex as p } from "../internal/asn1/asn1.js";
|
|
3
3
|
import { OIDS as m } from "../internal/asn1/oids2.js";
|
|
4
4
|
import { failureResult as h, rethrowIfInvariant as g, successResult as _ } from "../result/result.js";
|
|
5
5
|
import { pemDecodeOrThrow as v, splitPemBlocksOrThrow as y } from "../pem/pem.js";
|
|
6
6
|
import { derivePublicKey as b, exportSpkiDer as x, importSpkiDer as S, importSpkiDerOrThrow as C } from "../keys/keys.js";
|
|
7
7
|
import { describePublicKeyAlgorithm as w, describeSignatureAlgorithm as T } from "../internal/crypto/algorithm-names.js";
|
|
8
|
-
import {
|
|
8
|
+
import { readDirectoryNameTlv as E } from "../internal/x509/directory-name.js";
|
|
9
9
|
import { parseDistributionPointReasonFlagsContent as D, parseKeyUsageExtension as O } from "../internal/x509/extension-bits.js";
|
|
10
10
|
import { nameFieldKeyFromOid as k } from "../internal/x509/name-fields.js";
|
|
11
11
|
import { parseAuthorityInfoAccessMethodOid as A, parseExtendedKeyUsageOid as j } from "./extensions.js";
|
|
12
12
|
import { decodeAndApplyKnownExtension as M } from "../internal/x509/extension-registry.js";
|
|
13
|
+
import { parseGeneralName as N, parseGeneralNames as P } from "../internal/x509/general-name.js";
|
|
13
14
|
//#region src/x509/parse.ts
|
|
14
15
|
/**
|
|
15
16
|
* Certificate and CSR parse boundary.
|
|
@@ -22,7 +23,7 @@ import { decodeAndApplyKnownExtension as M } from "../internal/x509/extension-re
|
|
|
22
23
|
* @module
|
|
23
24
|
*/
|
|
24
25
|
/** Shared UTF-8 decoder for IA5String / UTF8String values. */
|
|
25
|
-
const
|
|
26
|
+
const F = new TextDecoder();
|
|
26
27
|
/**
|
|
27
28
|
* Identity helper that narrows the type of a custom {@linkcode ExtensionDecoder} literal.
|
|
28
29
|
*
|
|
@@ -81,6 +82,7 @@ function parseCertificateDerOrThrow(e, t) {
|
|
|
81
82
|
...c.keyUsage === void 0 ? {} : { keyUsage: c.keyUsage },
|
|
82
83
|
...c.extendedKeyUsage === void 0 ? {} : { extendedKeyUsage: c.extendedKeyUsage },
|
|
83
84
|
...c.subjectAltNames === void 0 ? {} : { subjectAltNames: c.subjectAltNames },
|
|
85
|
+
...c.issuerAltNames === void 0 ? {} : { issuerAltNames: c.issuerAltNames },
|
|
84
86
|
...c.nameConstraints === void 0 ? {} : { nameConstraints: c.nameConstraints },
|
|
85
87
|
...c.certificatePolicies === void 0 ? {} : { certificatePolicies: c.certificatePolicies },
|
|
86
88
|
...c.policyMappings === void 0 ? {} : { policyMappings: c.policyMappings },
|
|
@@ -217,17 +219,33 @@ function parseCertificateFromSource(e, t) {
|
|
|
217
219
|
return typeof e == "string" ? parseCertificatePemOrThrow(e, t) : hasParsedCertificateShape(e) ? e : parseCertificateDerOrThrow(new Uint8Array(e), t);
|
|
218
220
|
}
|
|
219
221
|
/**
|
|
220
|
-
* Decode a PEM bundle containing one or more certificates.
|
|
222
|
+
* Decode a PEM bundle containing one or more certificates, throwing on malformed input.
|
|
221
223
|
*
|
|
222
224
|
* Non-CERTIFICATE blocks (e.g. private keys) are silently skipped.
|
|
223
225
|
*
|
|
224
226
|
* @param pemBundle PEM text that may contain multiple CERTIFICATE blocks.
|
|
225
227
|
* @param options Custom extension decoders to apply during parsing.
|
|
226
228
|
*/
|
|
227
|
-
function
|
|
229
|
+
function parseCertificateChainPemOrThrow(e, t) {
|
|
228
230
|
return parseCertificatesFromPemBlocks(e, t);
|
|
229
231
|
}
|
|
230
232
|
/**
|
|
233
|
+
* Decode a PEM bundle containing one or more certificates.
|
|
234
|
+
*
|
|
235
|
+
* Non-CERTIFICATE blocks (e.g. private keys) are silently skipped. Returns a
|
|
236
|
+
* typed `malformed` failure for invalid PEM or certificate DER.
|
|
237
|
+
*
|
|
238
|
+
* @param pemBundle PEM text that may contain multiple CERTIFICATE blocks.
|
|
239
|
+
* @param options Custom extension decoders to apply during parsing.
|
|
240
|
+
*/
|
|
241
|
+
function parseCertificateChainPem(e, t) {
|
|
242
|
+
try {
|
|
243
|
+
return _(parseCertificateChainPemOrThrow(e, t));
|
|
244
|
+
} catch (e) {
|
|
245
|
+
return g(e), h("malformed", e instanceof Error ? e.message : "Malformed certificate chain");
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
231
249
|
* Decode a DER-encoded PKCS#10 CSR into a {@linkcode ParsedCertificateSigningRequest}.
|
|
232
250
|
*
|
|
233
251
|
* @param der Raw DER bytes of a PKCS#10 certificate signing request.
|
|
@@ -268,18 +286,18 @@ function parseCertificateSigningRequestDerOrThrow(e, t) {
|
|
|
268
286
|
}
|
|
269
287
|
function parseCertificationRequestInfoFields(e, t) {
|
|
270
288
|
let n = i(e, t);
|
|
271
|
-
if (n.length
|
|
289
|
+
if (n.length !== 4) throw Error("Malformed CertificationRequestInfo");
|
|
272
290
|
let r = f(n[0], "version");
|
|
273
291
|
if (r.tag !== 2) throw Error("version must use INTEGER");
|
|
274
292
|
let a = o(r.value) + 1;
|
|
275
293
|
if (a !== 1) throw Error(`Unsupported CertificationRequestInfo version: ${String(a)}`);
|
|
276
|
-
let s = n[3];
|
|
277
|
-
if (s
|
|
294
|
+
let s = f(n[3], "attributes");
|
|
295
|
+
if (s.tag !== 160) throw Error("CertificationRequestInfo attributes must use [0]");
|
|
278
296
|
return {
|
|
279
297
|
version: a,
|
|
280
298
|
subject: f(n[1], "subject"),
|
|
281
299
|
subjectPublicKeyInfo: f(n[2], "subjectPublicKeyInfo"),
|
|
282
|
-
|
|
300
|
+
attributes: s
|
|
283
301
|
};
|
|
284
302
|
}
|
|
285
303
|
/**
|
|
@@ -376,9 +394,9 @@ function subjectPublicKeyInfoAlgorithmDer(e) {
|
|
|
376
394
|
* AlgorithmIdentifier portions decide whether it is a same-algorithm key
|
|
377
395
|
* mismatch or a cross-algorithm (`key_type_mismatch`) one.
|
|
378
396
|
*/
|
|
379
|
-
async function compareCertificateToPrivateKey(
|
|
380
|
-
let
|
|
381
|
-
return
|
|
397
|
+
async function compareCertificateToPrivateKey(t, n) {
|
|
398
|
+
let r = await x(await b(n));
|
|
399
|
+
return e(r, t) ? "match" : e(subjectPublicKeyInfoAlgorithmDer(r), subjectPublicKeyInfoAlgorithmDer(t)) ? "key_mismatch" : "key_type_mismatch";
|
|
382
400
|
}
|
|
383
401
|
/**
|
|
384
402
|
* Check whether a certificate's subject public key belongs to a private key.
|
|
@@ -483,6 +501,7 @@ async function matchCertificatePrivateKey(e, t) {
|
|
|
483
501
|
case "match": return _(void 0);
|
|
484
502
|
case "key_mismatch": return h("key_mismatch", "Private key does not match the certificate's subject public key");
|
|
485
503
|
case "key_type_mismatch": return h("key_type_mismatch", "Private key algorithm does not match the certificate's subject public key algorithm");
|
|
504
|
+
default: throw Error(`Unhandled key comparison result: ${String(r)}`);
|
|
486
505
|
}
|
|
487
506
|
}
|
|
488
507
|
/**
|
|
@@ -553,19 +572,22 @@ function parseExtensionContainer(e, t) {
|
|
|
553
572
|
}
|
|
554
573
|
/** Extract extensions from the CSR extensionRequest attribute. */
|
|
555
574
|
function parseRequestedExtensions(e, t) {
|
|
556
|
-
if (t === void 0) return { all: [] };
|
|
557
|
-
if (t.tag !== 160) throw Error("CertificationRequestInfo attributes must use [0]");
|
|
558
575
|
let n;
|
|
559
576
|
for (let r of i(e, t)) {
|
|
577
|
+
if (r.tag !== 48) throw Error("CSR attribute must use SEQUENCE");
|
|
560
578
|
let t = i(e, r);
|
|
561
579
|
if (t.length !== 2) throw Error("Malformed CSR attribute");
|
|
562
|
-
|
|
563
|
-
if (
|
|
564
|
-
let
|
|
565
|
-
if (
|
|
566
|
-
let
|
|
567
|
-
if (
|
|
568
|
-
|
|
580
|
+
let a = f(t[0], "attribute OID");
|
|
581
|
+
if (a.tag !== 6) throw Error("CSR attribute type must use OBJECT IDENTIFIER");
|
|
582
|
+
let o = f(t[1], "attribute values");
|
|
583
|
+
if (o.tag !== 49) throw Error("CSR attribute values must use SET");
|
|
584
|
+
let s = i(e, o);
|
|
585
|
+
if (s.length === 0) throw Error("CSR attribute values must not be empty");
|
|
586
|
+
if (c(a.value) === m.extensionRequest) {
|
|
587
|
+
if (n !== void 0) throw Error("extensionRequest attribute must not repeat");
|
|
588
|
+
if (s.length !== 1) throw Error("extensionRequest attribute must contain exactly one value");
|
|
589
|
+
n = parseExtensionSequence(e, f(s[0], "requested extensions"), "csr");
|
|
590
|
+
}
|
|
569
591
|
}
|
|
570
592
|
return n ?? { all: [] };
|
|
571
593
|
}
|
|
@@ -596,8 +618,10 @@ function parseExtensionSequence(e, t, n) {
|
|
|
596
618
|
}
|
|
597
619
|
/** Decode an X.501 Name (issuer / subject) into a {@linkcode ParsedName}. */
|
|
598
620
|
function parseName(e, t) {
|
|
621
|
+
if (t.tag !== 48) throw Error("Name must use SEQUENCE");
|
|
599
622
|
let n = [], r = [], a = {};
|
|
600
623
|
for (let o of i(e, t)) {
|
|
624
|
+
if (o.tag !== 49) throw Error("RelativeDistinguishedName must use SET");
|
|
601
625
|
let t = parseNameAttributeSet(e, o);
|
|
602
626
|
n.push(t);
|
|
603
627
|
for (let e of t.attributes) r.push(e), e.key !== void 0 && a[e.key] === void 0 && (a[e.key] = e.value);
|
|
@@ -617,17 +641,22 @@ function parseRelativeDistinguishedName(e, t) {
|
|
|
617
641
|
function parseNameAttributeSet(e, t) {
|
|
618
642
|
let n = [], r = {};
|
|
619
643
|
for (let a of i(e, t)) {
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
644
|
+
if (a.tag !== 48) throw Error("AttributeTypeAndValue must use SEQUENCE");
|
|
645
|
+
let t = i(e, a);
|
|
646
|
+
if (t.length !== 2) throw Error("AttributeTypeAndValue must contain type and value");
|
|
647
|
+
let o = f(t[0], "name OID");
|
|
648
|
+
if (o.tag !== 6) throw Error("AttributeTypeAndValue type must use OBJECT IDENTIFIER");
|
|
649
|
+
let s = c(o.value), u = f(t[1], "name value"), d = k(s), p = l(u.tag, u.value), m = d === void 0 ? {
|
|
650
|
+
oid: s,
|
|
651
|
+
valueTag: u.tag,
|
|
652
|
+
value: p
|
|
624
653
|
} : {
|
|
625
|
-
oid:
|
|
626
|
-
key:
|
|
627
|
-
valueTag:
|
|
628
|
-
value:
|
|
654
|
+
oid: s,
|
|
655
|
+
key: d,
|
|
656
|
+
valueTag: u.tag,
|
|
657
|
+
value: p
|
|
629
658
|
};
|
|
630
|
-
n.push(
|
|
659
|
+
n.push(m), d !== void 0 && r[d] === void 0 && (r[d] = p);
|
|
631
660
|
}
|
|
632
661
|
return {
|
|
633
662
|
derHex: p(e.slice(t.start - t.headerLength, t.end)),
|
|
@@ -655,30 +684,27 @@ function parseSubjectPublicKeyInfo(e, t) {
|
|
|
655
684
|
}
|
|
656
685
|
/** Decode an AlgorithmIdentifier SEQUENCE (OID + optional parameters). */
|
|
657
686
|
function parseAlgorithmIdentifier(e, t) {
|
|
687
|
+
if (t.tag !== 48) throw Error("AlgorithmIdentifier must use SEQUENCE");
|
|
658
688
|
let n = i(e, t);
|
|
659
689
|
if (n.length === 0 || n.length > 2) throw Error("Malformed AlgorithmIdentifier");
|
|
660
|
-
let r =
|
|
661
|
-
if (
|
|
662
|
-
let
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
690
|
+
let r = f(n[0], "algorithm OID");
|
|
691
|
+
if (r.tag !== 6) throw Error("AlgorithmIdentifier algorithm must use OBJECT IDENTIFIER");
|
|
692
|
+
let a = c(r.value), o = n[1];
|
|
693
|
+
if (o === void 0) return { oid: a };
|
|
694
|
+
let s = e.slice(o.start - o.headerLength, o.end);
|
|
695
|
+
return o?.tag === 6 ? {
|
|
696
|
+
oid: a,
|
|
697
|
+
parametersDer: s,
|
|
698
|
+
parametersOid: c(o.value)
|
|
667
699
|
} : {
|
|
668
|
-
oid:
|
|
669
|
-
parametersDer:
|
|
700
|
+
oid: a,
|
|
701
|
+
parametersDer: s
|
|
670
702
|
};
|
|
671
703
|
}
|
|
672
|
-
function assertMatchingCertificateSignatureAlgorithms(
|
|
673
|
-
if (
|
|
674
|
-
}
|
|
675
|
-
function optionalBytesEqual(e, t) {
|
|
676
|
-
if (e === void 0 || t === void 0) return e === t;
|
|
677
|
-
if (e.length !== t.length) return !1;
|
|
678
|
-
for (let n = 0; n < e.length; n += 1) if (e[n] !== t[n]) return !1;
|
|
679
|
-
return !0;
|
|
704
|
+
function assertMatchingCertificateSignatureAlgorithms(t, n) {
|
|
705
|
+
if (t.oid !== n.oid || !e(t.parametersDer, n.parametersDer)) throw Error("Certificate signatureAlgorithm must match TBSCertificate signature");
|
|
680
706
|
}
|
|
681
|
-
/**
|
|
707
|
+
/** Decodes the Basic Constraints extension value DER. */
|
|
682
708
|
function parseBasicConstraints(e) {
|
|
683
709
|
let t = n(e, { maxDepth: 64 });
|
|
684
710
|
if (t.tag !== 48) throw Error("basicConstraints must use SEQUENCE");
|
|
@@ -703,15 +729,20 @@ function parseBasicConstraints(e) {
|
|
|
703
729
|
pathLength: c
|
|
704
730
|
} : { ca: !1 };
|
|
705
731
|
}
|
|
706
|
-
/**
|
|
732
|
+
/** Decodes the Key Usage BIT STRING extension value. */
|
|
707
733
|
function parseKeyUsage(e) {
|
|
708
734
|
return O(e);
|
|
709
735
|
}
|
|
710
|
-
/**
|
|
736
|
+
/** Decodes the Extended Key Usage SEQUENCE OF OIDs. */
|
|
711
737
|
function parseExtendedKeyUsage(e) {
|
|
712
|
-
|
|
738
|
+
let t = r(e, { maxDepth: 64 });
|
|
739
|
+
if (t.length === 0) throw Error("extendedKeyUsage must not be empty");
|
|
740
|
+
return t.map((e) => {
|
|
741
|
+
if (e.tag !== 6) throw Error("extendedKeyUsage entry must use OBJECT IDENTIFIER");
|
|
742
|
+
return j(c(e.value));
|
|
743
|
+
});
|
|
713
744
|
}
|
|
714
|
-
/**
|
|
745
|
+
/** Decodes the Certificate Policies extension value. */
|
|
715
746
|
function parseCertificatePolicies(e) {
|
|
716
747
|
let t = i(e, f(n(e, { maxDepth: 64 }), "certificatePolicies sequence"));
|
|
717
748
|
if (t.length === 0) throw Error("certificatePolicies must not be empty");
|
|
@@ -786,7 +817,7 @@ function parsePolicyNoticeNumbers(e, t) {
|
|
|
786
817
|
return s(e.value, "noticeRef noticeNumber");
|
|
787
818
|
});
|
|
788
819
|
}
|
|
789
|
-
/**
|
|
820
|
+
/** Decodes the Policy Mappings extension value. */
|
|
790
821
|
function parsePolicyMappings(e) {
|
|
791
822
|
let t = i(e, f(n(e, { maxDepth: 64 }), "policyMappings sequence"));
|
|
792
823
|
if (t.length === 0) throw Error("policyMappings must not be empty");
|
|
@@ -800,7 +831,7 @@ function parsePolicyMappings(e) {
|
|
|
800
831
|
};
|
|
801
832
|
});
|
|
802
833
|
}
|
|
803
|
-
/**
|
|
834
|
+
/** Decodes the Policy Constraints extension value. */
|
|
804
835
|
function parsePolicyConstraints(e) {
|
|
805
836
|
let t = f(n(e, { maxDepth: 64 }), "policyConstraints sequence"), r, a;
|
|
806
837
|
for (let n of i(e, t)) {
|
|
@@ -822,23 +853,25 @@ function parsePolicyConstraints(e) {
|
|
|
822
853
|
...a === void 0 ? {} : { inhibitPolicyMapping: a }
|
|
823
854
|
};
|
|
824
855
|
}
|
|
825
|
-
/**
|
|
856
|
+
/** Decodes the Inhibit anyPolicy extension (single INTEGER). */
|
|
826
857
|
function parseInhibitAnyPolicy(e) {
|
|
827
858
|
let t = f(n(e, { maxDepth: 64 }), "inhibitAnyPolicy integer");
|
|
828
859
|
if (t.tag !== 2) throw Error("inhibitAnyPolicy must be an INTEGER");
|
|
829
860
|
return { skipCerts: s(t.value, "inhibitAnyPolicy skipCerts") };
|
|
830
861
|
}
|
|
831
|
-
/**
|
|
832
|
-
function parseSubjectAltNames(e) {
|
|
833
|
-
|
|
862
|
+
/** Decodes a subjectAltName or issuerAltName SEQUENCE OF GeneralName. */
|
|
863
|
+
function parseSubjectAltNames(e, t = "subjectAltName") {
|
|
864
|
+
let r = f(n(e, { maxDepth: 64 }), `${t} sequence`);
|
|
865
|
+
if (r.tag !== 48) throw Error(`${t} must use SEQUENCE`);
|
|
866
|
+
return P(e, r);
|
|
834
867
|
}
|
|
835
|
-
/**
|
|
868
|
+
/** Decodes a bare DER-encoded X.501 Name, as carried in a `directoryName` GeneralName. */
|
|
836
869
|
function parseDistinguishedNameDer(e) {
|
|
837
870
|
let t = f(n(e, { maxDepth: 64 }), "distinguished name sequence");
|
|
838
871
|
if (t.tag !== 48) throw Error("distinguished name must use SEQUENCE");
|
|
839
872
|
return parseName(e, t);
|
|
840
873
|
}
|
|
841
|
-
/**
|
|
874
|
+
/** Decodes the Authority Information Access extension value. */
|
|
842
875
|
function parseAuthorityInfoAccess(e) {
|
|
843
876
|
let t = f(n(e, { maxDepth: 64 }), "authorityInfoAccess sequence");
|
|
844
877
|
if (t.tag !== 48) throw Error("authorityInfoAccess must use SEQUENCE");
|
|
@@ -850,14 +883,13 @@ function parseAuthorityInfoAccess(e) {
|
|
|
850
883
|
if (n.length !== 2) throw Error("authorityInfoAccess entry must contain method and location only");
|
|
851
884
|
let r = f(n[0], "authorityInfoAccess method"), a = f(n[1], "authorityInfoAccess location");
|
|
852
885
|
if (r.tag !== 6) throw Error("authorityInfoAccess method must use OBJECT IDENTIFIER");
|
|
853
|
-
if (a.tag !== 134) throw Error(`Unsupported authorityInfoAccess location tag: ${a.tag}`);
|
|
854
886
|
return {
|
|
855
887
|
method: A(c(r.value)),
|
|
856
|
-
|
|
888
|
+
location: N(e, a)
|
|
857
889
|
};
|
|
858
890
|
});
|
|
859
891
|
}
|
|
860
|
-
/**
|
|
892
|
+
/** Decodes the CRL Distribution Points extension value. */
|
|
861
893
|
function parseCrlDistributionPoints(e) {
|
|
862
894
|
let t = f(n(e, { maxDepth: 64 }), "CRLDistributionPoints sequence");
|
|
863
895
|
if (t.tag !== 48) throw Error("CRLDistributionPoints must use SEQUENCE");
|
|
@@ -891,7 +923,7 @@ function parseDistributionPointField(e, t, n) {
|
|
|
891
923
|
return;
|
|
892
924
|
case 162:
|
|
893
925
|
if (n.crlIssuer !== void 0) throw Error("DistributionPoint crlIssuer must not repeat");
|
|
894
|
-
n.crlIssuer =
|
|
926
|
+
n.crlIssuer = P(e, t);
|
|
895
927
|
return;
|
|
896
928
|
default: throw Error(`Unsupported DistributionPoint field tag: ${String(t.tag)}`);
|
|
897
929
|
}
|
|
@@ -905,75 +937,18 @@ function parseDistributionPointName(e, t) {
|
|
|
905
937
|
let t = i(e, r);
|
|
906
938
|
if (t.length === 0) throw Error("distributionPointName fullName must not be empty");
|
|
907
939
|
for (let e of t) if ((e.tag & 192) != 128) throw Error("distributionPointName fullName must contain GeneralName entries");
|
|
908
|
-
return {
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
throw Error(`Unsupported distributionPointName tag: ${r.tag}`);
|
|
912
|
-
}
|
|
913
|
-
/** Decode a SEQUENCE OF GeneralName. */
|
|
914
|
-
function parseGeneralNames(e, t) {
|
|
915
|
-
let n = i(e, t);
|
|
916
|
-
if (n.length === 0) throw Error("GeneralNames must not be empty");
|
|
917
|
-
for (let e of n) if ((e.tag & 192) != 128) throw Error("GeneralNames must contain GeneralName entries");
|
|
918
|
-
return n.map((t) => parseGeneralName(e, t));
|
|
919
|
-
}
|
|
920
|
-
/** Decode a single GeneralName from its implicit context tag. */
|
|
921
|
-
function parseGeneralName(e, t) {
|
|
922
|
-
switch (t.tag) {
|
|
923
|
-
case 160: {
|
|
924
|
-
let n = parseOtherName(e, t);
|
|
925
|
-
return n === void 0 ? {
|
|
926
|
-
type: "unknown",
|
|
927
|
-
tag: t.tag,
|
|
928
|
-
value: e.slice(t.start, t.end)
|
|
929
|
-
} : n;
|
|
930
|
-
}
|
|
931
|
-
case 129: return {
|
|
932
|
-
type: "email",
|
|
933
|
-
value: N.decode(t.value)
|
|
934
|
-
};
|
|
935
|
-
case 130: return {
|
|
936
|
-
type: "dns",
|
|
937
|
-
value: N.decode(t.value)
|
|
938
|
-
};
|
|
939
|
-
case 134: return {
|
|
940
|
-
type: "uri",
|
|
941
|
-
value: N.decode(t.value)
|
|
942
|
-
};
|
|
943
|
-
case 135: return {
|
|
944
|
-
type: "ip",
|
|
945
|
-
value: E(t.value)
|
|
946
|
-
};
|
|
947
|
-
case 164: return {
|
|
948
|
-
type: "directoryName",
|
|
949
|
-
derHex: p(rebuildDirectoryNameFromImplicit(t, e))
|
|
950
|
-
};
|
|
951
|
-
default: return {
|
|
952
|
-
type: "unknown",
|
|
953
|
-
tag: t.tag,
|
|
954
|
-
value: e.slice(t.start, t.end)
|
|
940
|
+
return {
|
|
941
|
+
type: "fullName",
|
|
942
|
+
fullName: t.map((t) => N(e, t))
|
|
955
943
|
};
|
|
956
944
|
}
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
let n = i(e, t);
|
|
961
|
-
if (n.length !== 1) throw Error("otherName must contain exactly one SEQUENCE");
|
|
962
|
-
let r = i(e, f(n[0], "otherName sequence"));
|
|
963
|
-
if (r.length !== 2) throw Error("otherName must contain exactly type-id and value");
|
|
964
|
-
let a = f(r[0], "otherName type-id"), o = f(r[1], "otherName value");
|
|
965
|
-
if (c(a.value) !== m.idOnDnsSrv) return;
|
|
966
|
-
if (o.tag !== 160) throw Error("SRV-ID otherName value must use explicit [0]");
|
|
967
|
-
let s = i(e, o);
|
|
968
|
-
if (s.length !== 1) throw Error("SRV-ID otherName value must contain exactly one IA5String");
|
|
969
|
-
let u = f(s[0], "SRV-ID IA5String");
|
|
970
|
-
if (u.tag !== 22) throw Error("SRV-ID otherName value must be an IA5String");
|
|
971
|
-
return {
|
|
972
|
-
type: "srv",
|
|
973
|
-
value: l(u.tag, u.value)
|
|
945
|
+
if (r.tag === 161) return {
|
|
946
|
+
type: "relativeName",
|
|
947
|
+
relativeName: parseRelativeDistinguishedName(e, r)
|
|
974
948
|
};
|
|
949
|
+
throw Error(`Unsupported distributionPointName tag: ${r.tag}`);
|
|
975
950
|
}
|
|
976
|
-
/**
|
|
951
|
+
/** Decodes the Name Constraints extension value. */
|
|
977
952
|
function parseNameConstraints(e) {
|
|
978
953
|
let t = f(n(e, {
|
|
979
954
|
maxDepth: 64,
|
|
@@ -1011,7 +986,7 @@ function parseGeneralSubtree(e, t) {
|
|
|
1011
986
|
if (t.tag !== 48) throw Error("name constraints GeneralSubtree must use SEQUENCE");
|
|
1012
987
|
let n = i(e, t), r = n[0];
|
|
1013
988
|
if (r === void 0) throw Error("GeneralSubtree base is required");
|
|
1014
|
-
return validateGeneralSubtreeBounds(n.slice(1)), parseNameConstraintGeneralName(
|
|
989
|
+
return validateGeneralSubtreeBounds(n.slice(1)), parseNameConstraintGeneralName(r);
|
|
1015
990
|
}
|
|
1016
991
|
function validateGeneralSubtreeBounds(e) {
|
|
1017
992
|
let t = !1;
|
|
@@ -1025,73 +1000,61 @@ function validateGeneralSubtreeBounds(e) {
|
|
|
1025
1000
|
}
|
|
1026
1001
|
}
|
|
1027
1002
|
/** Decode a GeneralName for use in name constraints (IP carries address+mask). */
|
|
1028
|
-
function parseNameConstraintGeneralName(e
|
|
1029
|
-
switch (
|
|
1003
|
+
function parseNameConstraintGeneralName(e) {
|
|
1004
|
+
switch (e.tag) {
|
|
1030
1005
|
case 160: return {
|
|
1031
1006
|
type: "otherName",
|
|
1032
|
-
value: new Uint8Array(
|
|
1007
|
+
value: new Uint8Array(e.value)
|
|
1033
1008
|
};
|
|
1034
1009
|
case 129: return {
|
|
1035
1010
|
type: "email",
|
|
1036
|
-
value:
|
|
1011
|
+
value: l(22, e.value)
|
|
1037
1012
|
};
|
|
1038
1013
|
case 130: return {
|
|
1039
1014
|
type: "dns",
|
|
1040
|
-
value:
|
|
1015
|
+
value: l(22, e.value)
|
|
1041
1016
|
};
|
|
1042
1017
|
case 163: return {
|
|
1043
1018
|
type: "x400Address",
|
|
1044
|
-
value: new Uint8Array(
|
|
1019
|
+
value: new Uint8Array(e.value)
|
|
1045
1020
|
};
|
|
1046
1021
|
case 134: return {
|
|
1047
1022
|
type: "uri",
|
|
1048
|
-
value:
|
|
1023
|
+
value: l(22, e.value)
|
|
1049
1024
|
};
|
|
1050
1025
|
case 135:
|
|
1051
|
-
if (
|
|
1026
|
+
if (e.value.length === 8) return {
|
|
1052
1027
|
type: "ip",
|
|
1053
|
-
addressBytes:
|
|
1054
|
-
maskBytes:
|
|
1028
|
+
addressBytes: e.value.slice(0, 4),
|
|
1029
|
+
maskBytes: e.value.slice(4, 8)
|
|
1055
1030
|
};
|
|
1056
|
-
if (
|
|
1031
|
+
if (e.value.length === 32) return {
|
|
1057
1032
|
type: "ip",
|
|
1058
|
-
addressBytes:
|
|
1059
|
-
maskBytes:
|
|
1033
|
+
addressBytes: e.value.slice(0, 16),
|
|
1034
|
+
maskBytes: e.value.slice(16, 32)
|
|
1060
1035
|
};
|
|
1061
|
-
throw Error(`Invalid IP name constraint: expected 8 (IPv4) or 32 (IPv6) bytes, got ${String(
|
|
1036
|
+
throw Error(`Invalid IP name constraint: expected 8 (IPv4) or 32 (IPv6) bytes, got ${String(e.value.length)}`);
|
|
1062
1037
|
case 164: return {
|
|
1063
1038
|
type: "directoryName",
|
|
1064
|
-
derHex: p(
|
|
1039
|
+
derHex: p(E(e))
|
|
1065
1040
|
};
|
|
1066
1041
|
case 165: return {
|
|
1067
1042
|
type: "ediPartyName",
|
|
1068
|
-
value: new Uint8Array(
|
|
1043
|
+
value: new Uint8Array(e.value)
|
|
1069
1044
|
};
|
|
1070
1045
|
case 136: return {
|
|
1071
1046
|
type: "registeredID",
|
|
1072
|
-
value: c(
|
|
1047
|
+
value: c(e.value)
|
|
1073
1048
|
};
|
|
1074
1049
|
}
|
|
1075
|
-
throw Error(`Unsupported name constraint GeneralName tag: ${String(
|
|
1076
|
-
}
|
|
1077
|
-
/**
|
|
1078
|
-
* Extracts the Name SEQUENCE from an implicitly-tagged directoryName [4].
|
|
1079
|
-
*
|
|
1080
|
-
* Handles two encoding styles found in the wild:
|
|
1081
|
-
* - Proper implicit: [4] replaces SEQUENCE tag, content is RDN SETs directly → wrap with 0x30
|
|
1082
|
-
* - Explicit-like: [4] wraps entire SEQUENCE, content starts with 0x30 → return content as-is
|
|
1083
|
-
*/
|
|
1084
|
-
function rebuildDirectoryNameFromImplicit(t, n) {
|
|
1085
|
-
if (t.value.length > 0 && t.value[0] === 48) return new Uint8Array(t.value);
|
|
1086
|
-
let r = e(t.value.length), i = new Uint8Array(1 + r.length + t.value.length);
|
|
1087
|
-
return i[0] = 48, i.set(r, 1), i.set(t.value, 1 + r.length), i;
|
|
1050
|
+
throw Error(`Unsupported name constraint GeneralName tag: ${String(e.tag)}`);
|
|
1088
1051
|
}
|
|
1089
1052
|
/** Decode a DisplayText (UTF8String, IA5String, VisibleString, or BMPString). */
|
|
1090
1053
|
function parseDisplayText(e) {
|
|
1091
1054
|
switch (e.tag) {
|
|
1092
1055
|
case 12:
|
|
1093
1056
|
case 22:
|
|
1094
|
-
case 26: return
|
|
1057
|
+
case 26: return F.decode(e.value);
|
|
1095
1058
|
case 30: return decodeBmpString(e.value);
|
|
1096
1059
|
default: throw Error(`Unsupported DisplayText tag: ${e.tag}`);
|
|
1097
1060
|
}
|
|
@@ -1107,6 +1070,7 @@ function decodeBmpString(e) {
|
|
|
1107
1070
|
}
|
|
1108
1071
|
return t;
|
|
1109
1072
|
}
|
|
1073
|
+
/** Decodes the Authority Key Identifier extension, returning the keyIdentifier hex or undefined. */
|
|
1110
1074
|
function parseAuthorityKeyIdentifier(e) {
|
|
1111
1075
|
let n = f(t(e, 0), "authorityKeyIdentifier sequence");
|
|
1112
1076
|
if (n.end !== e.length) throw Error("Trailing data after DER element");
|
|
@@ -1150,7 +1114,7 @@ function parseAuthorityKeyIdentifierIssuer(e, t, n) {
|
|
|
1150
1114
|
if (r.length === 0) throw Error("authorityKeyIdentifier authorityCertIssuer must contain GeneralName entries");
|
|
1151
1115
|
for (let t of r) {
|
|
1152
1116
|
if ((t.tag & 192) != 128) throw Error("authorityKeyIdentifier authorityCertIssuer must contain GeneralName entries");
|
|
1153
|
-
|
|
1117
|
+
N(e, t);
|
|
1154
1118
|
}
|
|
1155
1119
|
n.sawAuthorityCertIssuer = !0, n.lastFieldOrder = 1;
|
|
1156
1120
|
}
|
|
@@ -1179,6 +1143,6 @@ function validateImplicitBitStringContent(e, t) {
|
|
|
1179
1143
|
if (i & (1 << n) - 1) throw Error(`${t} BIT STRING must not set padding bits`);
|
|
1180
1144
|
}
|
|
1181
1145
|
//#endregion
|
|
1182
|
-
export { certificateMatchesPrivateKey, decodeExtension, decodeExtensionMap, decodeExtensions, defineExtensionDecoder, defineExtensionDecoderMap, findExtension, getSubjectPublicKey, getSubjectPublicKeyOrThrow, matchCertificatePrivateKey, parseAuthorityInfoAccess, parseAuthorityKeyIdentifier, parseBasicConstraints, parseCertificateChainPem, parseCertificateDer, parseCertificateDerOrThrow, parseCertificateFromSource, parseCertificatePem, parseCertificatePemOrThrow, parseCertificatePolicies, parseCertificateSigningRequestDer, parseCertificateSigningRequestDerOrThrow, parseCertificateSigningRequestPem, parseCertificateSigningRequestPemOrThrow, parseCertificatesFromSource, parseCrlDistributionPoints, parseDistinguishedNameDer, parseExtendedKeyUsage, parseInhibitAnyPolicy, parseKeyUsage, parseNameConstraints, parsePolicyConstraints, parsePolicyMappings, parseSubjectAltNames };
|
|
1146
|
+
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 };
|
|
1183
1147
|
|
|
1184
1148
|
//# sourceMappingURL=parse.js.map
|