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/extensions.js
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
|
|
1
|
+
import { DECODE_REFUSAL_CODES as e, isResultError as t } from "../result/result.js";
|
|
2
|
+
import { rethrowDecodeRefusal as n } from "../internal/asn1/decode-refusal.js";
|
|
3
|
+
import { bmpString as r, bool as i, concatBytes as a, explicitContext as o, hasLoneSurrogate as s, ia5Bytes as ee, ia5String as te, implicitConstructedContext as c, implicitPrimitiveContext as l, integerFromNumber as u, objectIdentifier as d, octetString as ne, readElement as f, readRootElement as p, readSequenceChildren as m, sequence as h, tlv as g, utf8String as _, visibleString as v } from "../internal/asn1/der.js";
|
|
4
|
+
import { canonicalizeOid as y, checkStrictDer as re, childrenOf as b, decodeObjectIdentifier as ie, hexToBytes as x, toHex as S } from "../internal/asn1/asn1.js";
|
|
5
|
+
import { OIDS as C } from "../internal/asn1/oids2.js";
|
|
6
|
+
import { sha1 as w } from "../internal/crypto/hash.js";
|
|
7
|
+
import { throwExtensionEncoderError as T } from "../internal/x509/extension-errors.js";
|
|
8
|
+
import { encodeDistributionPointReasonFlagsContent as E, encodeKeyUsageExtension as D } from "../internal/x509/extension-bits.js";
|
|
9
|
+
import { domainToAscii as O } from "../internal/shared/idna.js";
|
|
10
|
+
import { allOnesMaskForIpAddress as k, decodeIpAddress as A, normalizeIpAddress as j, parseIpAddressToBytes as M } from "../internal/shared/ip.js";
|
|
11
|
+
import { isMailboxDomain as N, isSmtpUtf8LocalPart as P } from "../internal/shared/mailbox.js";
|
|
12
|
+
import { typedOtherName as F } from "../internal/x509/general-name.js";
|
|
13
|
+
import { checkEdiPartyName as I, checkOrAddress as L, normalizeLabelSeparators as R, parsePresentedSrvName as z, parseSrvNameRestriction as B, parseUriNameConstraint as V } from "../internal/x509/general-name-profile.js";
|
|
14
|
+
import { GENERAL_NAME_WIRE_TAGS as H } from "../internal/x509/general-name-tags.js";
|
|
15
|
+
import { encodeRelativeDistinguishedName as U } from "./name.js";
|
|
16
|
+
import { AUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION as W, AUTHORITY_KEY_IDENTIFIER_EXTENSION_DEFINITION as G, BASIC_CONSTRAINTS_EXTENSION_DEFINITION as K, CERTIFICATE_POLICIES_EXTENSION_DEFINITION as q, CRL_DISTRIBUTION_POINTS_EXTENSION_DEFINITION as J, EXTENDED_KEY_USAGE_EXTENSION_DEFINITION as Y, INHIBIT_ANY_POLICY_EXTENSION_DEFINITION as ae, KEY_USAGE_EXTENSION_DEFINITION as X, NAME_CONSTRAINTS_EXTENSION_DEFINITION as oe, NO_REV_AVAIL_EXTENSION_DEFINITION as se, POLICY_CONSTRAINTS_EXTENSION_DEFINITION as ce, POLICY_MAPPINGS_EXTENSION_DEFINITION as le, SUBJECT_ALT_NAME_EXTENSION_DEFINITION as Z, SUBJECT_KEY_IDENTIFIER_EXTENSION_DEFINITION as ue, getExtensionDefinition as Q } from "../internal/x509/extension-registry.js";
|
|
17
|
+
// src/x509/extensions.ts
|
|
13
18
|
/**
|
|
14
19
|
* Typed certificate and CSR extension model plus ASN.1 encoder helpers.
|
|
15
20
|
*
|
|
@@ -19,35 +24,35 @@ import { AUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION as N, AUTHORITY_KEY_IDENTIFI
|
|
|
19
24
|
* @module
|
|
20
25
|
*/
|
|
21
26
|
/** Map from well-known EKU names to their dotted-decimal OIDs. */
|
|
22
|
-
const
|
|
23
|
-
serverAuth:
|
|
24
|
-
clientAuth:
|
|
25
|
-
codeSigning:
|
|
26
|
-
emailProtection:
|
|
27
|
-
timeStamping:
|
|
28
|
-
ocspSigning:
|
|
29
|
-
},
|
|
30
|
-
ocsp:
|
|
31
|
-
caIssuers:
|
|
27
|
+
const de = {
|
|
28
|
+
serverAuth: C.serverAuth,
|
|
29
|
+
clientAuth: C.clientAuth,
|
|
30
|
+
codeSigning: C.codeSigning,
|
|
31
|
+
emailProtection: C.emailProtection,
|
|
32
|
+
timeStamping: C.timeStamping,
|
|
33
|
+
ocspSigning: C.ocspSigning
|
|
34
|
+
}, fe = {
|
|
35
|
+
ocsp: C.ocspAccessMethod,
|
|
36
|
+
caIssuers: C.caIssuersAccessMethod
|
|
32
37
|
};
|
|
33
38
|
/**
|
|
34
39
|
* Build the v3 extensions block for a certificate.
|
|
35
40
|
*
|
|
36
|
-
* Automatically adds SKI, AKI (when
|
|
41
|
+
* Automatically adds SKI, AKI (when a key identifier is given), and
|
|
37
42
|
* basicConstraints (defaults to `{ ca: false }`). Additional extensions
|
|
38
43
|
* come from the caller's {@linkcode CertificateExtensionsInput}.
|
|
39
44
|
*
|
|
40
45
|
* @param subjectPublicKeyInfo DER-encoded SPKI of the subject.
|
|
41
|
-
* @param
|
|
46
|
+
* @param authorityKeyIdentifier Key identifier for the AKI, or `undefined` to omit it.
|
|
42
47
|
* @param input Optional extension configuration.
|
|
43
48
|
* @param subjectIsEmpty Whether the certificate subject DN is empty. When `true`, a
|
|
44
49
|
* subjectAltName extension is required and marked critical per RFC 5280 §4.2.1.6.
|
|
45
50
|
* @returns Array of DER-encoded Extension SEQUENCEs.
|
|
46
51
|
*/
|
|
47
52
|
function buildCertificateExtensions(e, t, n, r = !1) {
|
|
48
|
-
assertCustomExtensionsValid(n, "certificate"), r && assertEmptySubjectHasCriticalSubjectAltName(n), assertPathLengthKeyUsage(n), assertSafeCurveKeyUsage(e, n);
|
|
49
|
-
let i = [], a = /* @__PURE__ */ new Set();
|
|
50
|
-
return pushKnownExtension(i, a,
|
|
53
|
+
assertCustomExtensionsValid(n, "certificate"), r && assertEmptySubjectHasCriticalSubjectAltName(n), assertPathLengthKeyUsage(n), assertSafeCurveKeyUsage(e, n), assertNoRevAvailProfile(n);
|
|
54
|
+
let i = [], a = /* @__PURE__ */ new Set(), o = n?.basicConstraints ?? { ca: !1 };
|
|
55
|
+
return pushKnownExtension(i, a, K, o), pushKnownExtension(i, a, ue, buildSubjectKeyIdentifier(e)), t !== void 0 && pushKnownExtension(i, a, G, t), appendConfiguredExtensions(i, a, n, {
|
|
51
56
|
includeBasicConstraints: !1,
|
|
52
57
|
subjectIsEmpty: r
|
|
53
58
|
}), i;
|
|
@@ -77,20 +82,20 @@ function appendConfiguredExtensions(e, t, n, r) {
|
|
|
77
82
|
function assertPathLengthKeyUsage(e) {
|
|
78
83
|
if (resolveEffectiveBasicConstraints(e)?.pathLength === void 0) return;
|
|
79
84
|
let t = resolveEffectiveKeyUsage(e);
|
|
80
|
-
|
|
85
|
+
t !== void 0 && t.length !== 0 && t.includes("keyCertSign") || T("path_length_requires_key_cert_sign", "basicConstraints pathLength requires the keyUsage keyCertSign bit");
|
|
81
86
|
}
|
|
82
87
|
/** RFC 9295 §3: an end-entity id-Ed25519 or id-Ed448 certificate needs one of these. */
|
|
83
|
-
const
|
|
88
|
+
const $ = [
|
|
84
89
|
"nonRepudiation",
|
|
85
90
|
"digitalSignature",
|
|
86
91
|
"cRLSign"
|
|
87
|
-
],
|
|
92
|
+
], pe = [
|
|
88
93
|
"keyEncipherment",
|
|
89
94
|
"dataEncipherment",
|
|
90
95
|
"keyAgreement",
|
|
91
96
|
"encipherOnly",
|
|
92
97
|
"decipherOnly"
|
|
93
|
-
],
|
|
98
|
+
], me = [
|
|
94
99
|
"digitalSignature",
|
|
95
100
|
"nonRepudiation",
|
|
96
101
|
"keyEncipherment",
|
|
@@ -120,32 +125,26 @@ function assertSafeCurveKeyUsage(e, t) {
|
|
|
120
125
|
let n = resolveEffectiveKeyUsage(t);
|
|
121
126
|
if (n === void 0 || n.length === 0) return;
|
|
122
127
|
let r = readSubjectKeyAlgorithmOid(e);
|
|
123
|
-
|
|
124
|
-
if (oidEquals(r, x.x25519) || oidEquals(r, x.x448)) {
|
|
125
|
-
assertMontgomeryKeyUsage(n);
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
(oidEquals(r, x.ed25519) || oidEquals(r, x.ed448)) && assertEdwardsKeyUsage(n, resolveEffectiveBasicConstraints(t)?.ca === !0);
|
|
129
|
-
}
|
|
128
|
+
r !== void 0 && (oidEquals(r, C.x25519) || oidEquals(r, C.x448) ? assertMontgomeryKeyUsage(n) : (oidEquals(r, C.ed25519) || oidEquals(r, C.ed448)) && assertEdwardsKeyUsage(n, resolveEffectiveBasicConstraints(t)?.ca === !0));
|
|
130
129
|
}
|
|
131
130
|
/** The X25519 and X448 half of RFC 9295 §3. */
|
|
132
131
|
function assertMontgomeryKeyUsage(e) {
|
|
133
|
-
e.includes("keyAgreement") ||
|
|
134
|
-
let t =
|
|
135
|
-
t.length > 0 &&
|
|
132
|
+
e.includes("keyAgreement") || T("montgomery_key_usage_requires_key_agreement", "keyUsage on an X25519 or X448 certificate must set keyAgreement");
|
|
133
|
+
let t = me.filter((t) => e.includes(t));
|
|
134
|
+
t.length > 0 && T("montgomery_key_usage_forbids_signature_bit", `keyUsage on an X25519 or X448 certificate must not set ${t.join(", ")}`), e.includes("encipherOnly") && e.includes("decipherOnly") && T("montgomery_key_usage_forbids_both_cipher_bits", "keyUsage on an X25519 or X448 certificate must not set both encipherOnly and decipherOnly");
|
|
136
135
|
}
|
|
137
136
|
/** The Ed25519 and Ed448 half of RFC 9295 §3. */
|
|
138
137
|
function assertEdwardsKeyUsage(e, t) {
|
|
139
|
-
t ? e.includes("keyCertSign") ||
|
|
140
|
-
let n =
|
|
141
|
-
n.length > 0 &&
|
|
138
|
+
t ? e.includes("keyCertSign") || T("edwards_key_usage_requires_key_cert_sign", "keyUsage on an Ed25519 or Ed448 certification authority certificate must set keyCertSign") : $.some((t) => e.includes(t)) || T("edwards_key_usage_requires_signing_bit", `keyUsage on an Ed25519 or Ed448 certificate must set one of ${$.join(", ")}`);
|
|
139
|
+
let n = pe.filter((t) => e.includes(t));
|
|
140
|
+
n.length > 0 && T("edwards_key_usage_forbids_agreement_bit", `keyUsage on an Ed25519 or Ed448 certificate must not set ${n.join(", ")}`), !t && e.includes("keyCertSign") && T("edwards_key_usage_forbids_key_cert_sign", "keyUsage on an Ed25519 or Ed448 end-entity certificate must not set keyCertSign");
|
|
142
141
|
}
|
|
143
142
|
/** The algorithm OID of a SubjectPublicKeyInfo, or `undefined` when the field is not an OID. */
|
|
144
143
|
function readSubjectKeyAlgorithmOid(e) {
|
|
145
|
-
let t =
|
|
144
|
+
let t = m(e)[0];
|
|
146
145
|
if (t === void 0 || t.tag !== 48) return;
|
|
147
|
-
let n =
|
|
148
|
-
return n?.tag === 6 ?
|
|
146
|
+
let n = b(e, t)[0];
|
|
147
|
+
return n?.tag === 6 ? ie(n.value) : void 0;
|
|
149
148
|
}
|
|
150
149
|
/**
|
|
151
150
|
* RFC 5280 §4.2.1.9: basicConstraints is critical in a CA certificate whose key
|
|
@@ -161,17 +160,35 @@ function readSubjectKeyAlgorithmOid(e) {
|
|
|
161
160
|
* always emitted with the registry default.
|
|
162
161
|
*/
|
|
163
162
|
function assertCaBasicConstraintsCritical(e) {
|
|
164
|
-
let t = e?.customExtensions?.find((e) => oidEquals(e.oid,
|
|
165
|
-
if (t === void 0 || t.critical === !0 || !
|
|
163
|
+
let t = e?.customExtensions?.find((e) => oidEquals(e.oid, C.basicConstraints));
|
|
164
|
+
if (t === void 0 || t.critical === !0 || !K.decode(new Uint8Array(t.value)).ca) return;
|
|
166
165
|
let n = resolveEffectiveKeyUsage(e);
|
|
167
166
|
(n === void 0 || n.length === 0 || n.includes("keyCertSign")) && assertExtensionCriticality("basicConstraints", !0, !1);
|
|
168
167
|
}
|
|
169
168
|
/**
|
|
169
|
+
* RFC 9608 §2 and §3: a certificate carrying noRevAvail is not a CA certificate
|
|
170
|
+
* and carries no cRLDistributionPoints, no freshestCRL, and no id-ad-ocsp
|
|
171
|
+
* authorityInfoAccess entry. Known extensions supplied through customExtensions
|
|
172
|
+
* participate in the effective view.
|
|
173
|
+
*/
|
|
174
|
+
function assertNoRevAvailProfile(e) {
|
|
175
|
+
(e?.noRevAvail === !0 || findCustomExtensionValue(e, C.noRevAvail) !== void 0) && (resolveEffectiveBasicConstraints(e)?.ca === !0 && throwNoRevAvailConflict("basicConstraints with cA TRUE"), ((e?.crlDistributionPoints?.length ?? 0) > 0 || findCustomExtensionValue(e, C.cRLDistributionPoints) !== void 0) && throwNoRevAvailConflict("cRLDistributionPoints"), findCustomExtensionValue(e, C.freshestCRL) !== void 0 && throwNoRevAvailConflict("freshestCRL"), resolveEffectiveAuthorityInfoAccess(e).some((e) => getAuthorityInfoAccessMethodOid(e.method) === C.ocspAccessMethod) && throwNoRevAvailConflict("an id-ad-ocsp authorityInfoAccess entry"));
|
|
176
|
+
}
|
|
177
|
+
/** The authorityInfoAccess entries the builder will emit: the typed list when non-empty, otherwise a custom-known extension. */
|
|
178
|
+
function resolveEffectiveAuthorityInfoAccess(e) {
|
|
179
|
+
if (e?.authorityInfoAccess !== void 0 && e.authorityInfoAccess.length > 0) return e.authorityInfoAccess;
|
|
180
|
+
let t = findCustomExtensionValue(e, C.authorityInfoAccess);
|
|
181
|
+
return t === void 0 ? [] : W.decode(t);
|
|
182
|
+
}
|
|
183
|
+
function throwNoRevAvailConflict(e) {
|
|
184
|
+
T("no_rev_avail_conflict", `A certificate carrying noRevAvail must not also carry ${e}`);
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
170
187
|
* RFC 5280 §4.2.1.6: an empty subject DN requires a subjectAltName extension
|
|
171
188
|
* present, marked critical, and carrying at least one non-empty GeneralName.
|
|
172
189
|
*/
|
|
173
190
|
function assertEmptySubjectHasCriticalSubjectAltName(e) {
|
|
174
|
-
e?.subjectAltNames?.some(subjectAltNameHasIdentity) !== !0 && e?.customExtensions?.some((e) => oidEquals(e.oid,
|
|
191
|
+
e?.subjectAltNames?.some(subjectAltNameHasIdentity) !== !0 && e?.customExtensions?.some((e) => oidEquals(e.oid, C.subjectAltName) && e.critical === !0 && customSubjectAltNameHasIdentity(e.value)) !== !0 && T("empty_subject_requires_subject_alt_name", "An empty subject requires a critical subjectAltName extension");
|
|
175
192
|
}
|
|
176
193
|
/**
|
|
177
194
|
* Canonical OID equality: matches even when arcs carry redundant leading zeros.
|
|
@@ -180,7 +197,7 @@ function assertEmptySubjectHasCriticalSubjectAltName(e) {
|
|
|
180
197
|
* which rejects an OID that cannot be canonicalized.
|
|
181
198
|
*/
|
|
182
199
|
function oidEquals(e, t) {
|
|
183
|
-
return e === t ||
|
|
200
|
+
return e === t || y(e) === y(t);
|
|
184
201
|
}
|
|
185
202
|
/** First customExtensions value whose OID canonically matches `oid`. */
|
|
186
203
|
function findCustomExtensionValue(e, t) {
|
|
@@ -195,8 +212,8 @@ function findCustomExtensionValue(e, t) {
|
|
|
195
212
|
*/
|
|
196
213
|
function assertCustomExtensionsValid(e, t) {
|
|
197
214
|
for (let n of e?.customExtensions ?? []) {
|
|
198
|
-
let e =
|
|
199
|
-
|
|
215
|
+
let e = validateOid(n.oid), r = Q(e);
|
|
216
|
+
r !== void 0 && (r.contexts.includes(t) || T("extension_not_supported_in_context", `Extension ${n.oid} is not supported in ${t} context`), assertKnownExtensionPayload(r, new Uint8Array(n.value), n.critical ?? !1, n.oid));
|
|
200
217
|
}
|
|
201
218
|
}
|
|
202
219
|
/**
|
|
@@ -206,50 +223,54 @@ function assertCustomExtensionsValid(e, t) {
|
|
|
206
223
|
* A profile violation already carries its own code and propagates unchanged; a
|
|
207
224
|
* decode failure means the payload is not the DER the OID's schema defines.
|
|
208
225
|
*/
|
|
209
|
-
function assertKnownExtensionPayload(e,
|
|
226
|
+
function assertKnownExtensionPayload(e, n, r, i) {
|
|
210
227
|
try {
|
|
211
|
-
e.assertDerProfile(
|
|
212
|
-
} catch (
|
|
213
|
-
if (
|
|
214
|
-
|
|
228
|
+
e.assertDerProfile(n, r);
|
|
229
|
+
} catch (n) {
|
|
230
|
+
if (t(n)) throw n;
|
|
231
|
+
T("malformed_known_extension_value", `Custom extension ${i} does not decode as ${e.oid}`);
|
|
215
232
|
}
|
|
216
233
|
}
|
|
217
234
|
/** Effective basicConstraints across the typed field and any custom-known extension. */
|
|
218
235
|
function resolveEffectiveBasicConstraints(e) {
|
|
219
236
|
if (e?.basicConstraints !== void 0) return e.basicConstraints;
|
|
220
|
-
let t = findCustomExtensionValue(e,
|
|
221
|
-
return t === void 0 ? void 0 :
|
|
237
|
+
let t = findCustomExtensionValue(e, C.basicConstraints);
|
|
238
|
+
return t === void 0 ? void 0 : K.decode(t);
|
|
222
239
|
}
|
|
223
240
|
/** Effective keyUsage flags across the typed field and any custom-known extension. */
|
|
224
241
|
function resolveEffectiveKeyUsage(e) {
|
|
225
242
|
if (e?.keyUsage !== void 0) return e.keyUsage;
|
|
226
|
-
let t = findCustomExtensionValue(e,
|
|
227
|
-
return t === void 0 ? void 0 :
|
|
243
|
+
let t = findCustomExtensionValue(e, C.keyUsage);
|
|
244
|
+
return t === void 0 ? void 0 : X.decode(t).flags;
|
|
228
245
|
}
|
|
229
246
|
/** Whether a typed GeneralName carries a non-empty identity value. */
|
|
230
247
|
function subjectAltNameHasIdentity(e) {
|
|
231
|
-
|
|
248
|
+
switch (e.type) {
|
|
249
|
+
case "directoryName": return e.derHex.length > 0;
|
|
250
|
+
case "krb5PrincipalName": return e.realm.length > 0 || e.nameString.length > 0;
|
|
251
|
+
default: return e.value.length > 0;
|
|
252
|
+
}
|
|
232
253
|
}
|
|
233
254
|
/** Whether a custom subjectAltName value decodes to at least one non-empty GeneralName. */
|
|
234
255
|
function customSubjectAltNameHasIdentity(e) {
|
|
235
|
-
return
|
|
256
|
+
return Z.decode(e).some(subjectAltNameHasIdentity);
|
|
236
257
|
}
|
|
237
258
|
function appendConstraintExtensions(e, t, n, r) {
|
|
238
|
-
assertPathLengthKeyUsage(n), assertCaBasicConstraintsCritical(n), r && n.basicConstraints !== void 0 && pushKnownExtension(e, t,
|
|
259
|
+
assertPathLengthKeyUsage(n), assertCaBasicConstraintsCritical(n), r && n.basicConstraints !== void 0 && pushKnownExtension(e, t, K, n.basicConstraints), n.keyUsage !== void 0 && n.keyUsage.length > 0 && pushKnownExtension(e, t, X, n.keyUsage), n.nameConstraints !== void 0 && pushKnownExtension(e, t, oe, n.nameConstraints);
|
|
239
260
|
}
|
|
240
261
|
function appendIdentityExtensions(e, t, n, r) {
|
|
241
262
|
if (n.subjectAltNames !== void 0 && n.subjectAltNames.length > 0) {
|
|
242
263
|
let i = r ? !0 : void 0;
|
|
243
|
-
pushKnownExtension(e, t,
|
|
264
|
+
pushKnownExtension(e, t, Z, n.subjectAltNames, i);
|
|
244
265
|
}
|
|
245
|
-
n.extendedKeyUsage !== void 0 && n.extendedKeyUsage.length > 0 && pushKnownExtension(e, t,
|
|
266
|
+
n.extendedKeyUsage !== void 0 && n.extendedKeyUsage.length > 0 && pushKnownExtension(e, t, Y, n.extendedKeyUsage);
|
|
246
267
|
}
|
|
247
268
|
/** Appends configured certificate-policy extensions while enforcing unique OIDs. */
|
|
248
269
|
function appendPolicyExtensions(e, t, n) {
|
|
249
|
-
n.certificatePolicies !== void 0 && n.certificatePolicies.length > 0 && pushKnownExtension(e, t,
|
|
270
|
+
n.certificatePolicies !== void 0 && n.certificatePolicies.length > 0 && pushKnownExtension(e, t, q, n.certificatePolicies), n.policyMappings !== void 0 && n.policyMappings.length > 0 && pushKnownExtension(e, t, le, n.policyMappings), n.policyConstraints !== void 0 && pushKnownExtension(e, t, ce, n.policyConstraints), n.inhibitAnyPolicy !== void 0 && pushKnownExtension(e, t, ae, n.inhibitAnyPolicy);
|
|
250
271
|
}
|
|
251
272
|
function appendAccessExtensions(e, t, n) {
|
|
252
|
-
n.authorityInfoAccess !== void 0 && n.authorityInfoAccess.length > 0 && pushKnownExtension(e, t,
|
|
273
|
+
n.authorityInfoAccess !== void 0 && n.authorityInfoAccess.length > 0 && pushKnownExtension(e, t, W, n.authorityInfoAccess), n.crlDistributionPoints !== void 0 && n.crlDistributionPoints.length > 0 && pushKnownExtension(e, t, J, n.crlDistributionPoints), n.noRevAvail === !0 && pushKnownExtension(e, t, se, !0);
|
|
253
274
|
}
|
|
254
275
|
/** Push each custom extension. Context and payload were checked by `assertCustomExtensionsValid`. */
|
|
255
276
|
function appendCustomExtensions(e, t, n) {
|
|
@@ -266,10 +287,10 @@ function pushKnownExtension(e, t, n, r, i = n.defaultCritical) {
|
|
|
266
287
|
* @param extnValue DER-encoded extension payload.
|
|
267
288
|
* @param critical Whether to mark the extension as critical. Default `false`.
|
|
268
289
|
*/
|
|
269
|
-
function encodeExtension(t, n
|
|
270
|
-
validateOid(
|
|
271
|
-
let
|
|
272
|
-
return
|
|
290
|
+
function encodeExtension(e, t, n = !1) {
|
|
291
|
+
validateOid(e);
|
|
292
|
+
let r = [d(e)];
|
|
293
|
+
return n && r.push(i(!0)), r.push(ne(t)), h(r);
|
|
273
294
|
}
|
|
274
295
|
/**
|
|
275
296
|
* DER-encode a {@linkcode BasicConstraints} value.
|
|
@@ -277,9 +298,9 @@ function encodeExtension(t, n, r = !1) {
|
|
|
277
298
|
* @param input CA flag and optional pathLength.
|
|
278
299
|
* @returns DER SEQUENCE suitable for wrapping in an Extension OCTET STRING.
|
|
279
300
|
*/
|
|
280
|
-
function encodeBasicConstraints(
|
|
281
|
-
let
|
|
282
|
-
return
|
|
301
|
+
function encodeBasicConstraints(e) {
|
|
302
|
+
let t = [];
|
|
303
|
+
return e.ca && t.push(i(!0)), e.pathLength !== void 0 && (e.ca || T("path_length_requires_ca", "basicConstraints pathLength requires ca = true"), t.push(u(e.pathLength))), h(t);
|
|
283
304
|
}
|
|
284
305
|
/**
|
|
285
306
|
* DER-encode a Key Usage BIT STRING from an array of {@linkcode KeyUsage} flags.
|
|
@@ -287,18 +308,106 @@ function encodeBasicConstraints(t) {
|
|
|
287
308
|
* @param usages Flags to set in the bit string.
|
|
288
309
|
*/
|
|
289
310
|
function encodeKeyUsage(e) {
|
|
290
|
-
return
|
|
311
|
+
return D(e);
|
|
291
312
|
}
|
|
292
313
|
function encodeIa5Content(e) {
|
|
293
314
|
try {
|
|
294
|
-
return
|
|
315
|
+
return ee(e);
|
|
295
316
|
} catch {
|
|
296
|
-
|
|
317
|
+
T("invalid_ia5_string", "Invalid IA5String: contains non-ASCII characters");
|
|
297
318
|
}
|
|
298
319
|
}
|
|
299
320
|
/** RFC 5280 §4.2.1.6: reject an empty GeneralName string value (empty dNSName, rfc822Name, URI, or SRV name). */
|
|
300
321
|
function requireNonEmptyName(e) {
|
|
301
|
-
return e.length === 0 &&
|
|
322
|
+
return e.length === 0 && T("empty_general_name_value", "GeneralName value must not be empty"), e;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* RFC 9598 §3: a SmtpUTF8Mailbox carries no Byte Order Mark, is used only when
|
|
326
|
+
* the Local-part holds a non-ASCII character, and stores its domain as
|
|
327
|
+
* lowercase A-labels and NR-LDH labels.
|
|
328
|
+
*/
|
|
329
|
+
function assertSmtpUtf8Mailbox(e) {
|
|
330
|
+
let t = requireNonEmptyName(e).lastIndexOf("@"), n = t > 0 ? e.slice(0, t) : "", r = toAsciiDomain(e.slice(t + 1));
|
|
331
|
+
return (n.length === 0 || e.includes("") || !N(r, "registration")) && T("invalid_smtp_utf8_mailbox", "SmtpUTF8Mailbox must be Local-part@Domain with no Byte Order Mark and a domain of lowercase A-labels and NR-LDH labels"), [...n].some((e) => (e.codePointAt(0) ?? 0) > 127) || T("smtp_utf8_mailbox_ascii_local_part", "A mailbox with an ASCII Local-part must use rfc822Name (type email)"), P(n) || T("invalid_smtp_utf8_mailbox", "SmtpUTF8Mailbox Local-part must be an RFC 6531 Dot-string or Quoted-string"), `${n}@${r}`;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* @internal A decoded SAN or IAN entry of a custom extension, which is emitted
|
|
335
|
+
* as given: the typed builder's rules, with a SmtpUTF8Mailbox domain already
|
|
336
|
+
* stored in A-labels.
|
|
337
|
+
*/
|
|
338
|
+
function assertStoredSubjectAltName(e) {
|
|
339
|
+
encodeSubjectAltName(e), e.type === "smtpUtf8Mailbox" && assertSmtpUtf8Mailbox(e.value) !== e.value && T("invalid_smtp_utf8_mailbox", "SmtpUTF8Mailbox domain must be stored as lowercase A-labels and NR-LDH labels");
|
|
340
|
+
}
|
|
341
|
+
/** RFC 5891 §4: the domain with each U-label converted to its A-label and each A-label checked. */
|
|
342
|
+
function toAsciiDomain(e) {
|
|
343
|
+
let t = O(e, "registration");
|
|
344
|
+
return t.ok ? t.value : T("invalid_idn", `Domain name is not valid IDNA2008 (${t.reason})`);
|
|
345
|
+
}
|
|
346
|
+
/** RFC 5280 §4.2.1.6 dNSName and rfc822Name domains take the RFC 1034 §3.5 preferred name syntax, which has no trailing root dot. */
|
|
347
|
+
function requireRelativeDomain(e) {
|
|
348
|
+
return e.endsWith(".") && T("domain_trailing_dot", "A dNSName or rfc822Name domain must not end in \".\" (RFC 5280 §4.2.1.6)"), e;
|
|
349
|
+
}
|
|
350
|
+
/** A dNSName or dNSName constraint with its leading `*.` or `.` kept and its domain in A-labels. */
|
|
351
|
+
function toAsciiDnsName(e) {
|
|
352
|
+
let t = e.startsWith("*.") ? "*." : e.startsWith(".") ? "." : "";
|
|
353
|
+
return `${t}${toAsciiDomain(requireRelativeDomain(e.slice(t.length)))}`;
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* RFC 4985 §3: a SRVName or SRVName restriction with its label separators
|
|
357
|
+
* normalized, its `_Service` label kept, and its Name in A-labels.
|
|
358
|
+
*/
|
|
359
|
+
function toAsciiSrvComponents(e) {
|
|
360
|
+
let t = R(e), n = t.indexOf(".");
|
|
361
|
+
if (!t.startsWith("_")) return toAsciiDomain(t);
|
|
362
|
+
if (n < 0) return t;
|
|
363
|
+
let r = t.slice(n + 1);
|
|
364
|
+
return `${t.slice(0, n + 1)}${r.length === 0 ? "" : toAsciiDomain(r)}`;
|
|
365
|
+
}
|
|
366
|
+
/** RFC 4985 §2 and RFC 6335 §5.1: a presented SRVName is `_Service.Name`. */
|
|
367
|
+
function toAsciiSrvName(e) {
|
|
368
|
+
let t = toAsciiSrvComponents(e);
|
|
369
|
+
return z(t) === void 0 && T("invalid_srv_name", "A SRVName is _Service.Name with an RFC 6335 service and an LDH Name (RFC 4985 §2)"), t;
|
|
370
|
+
}
|
|
371
|
+
/** RFC 4985 §4: a SRVName constraint is `_Service.Name`, `_Service`, or `Name`. */
|
|
372
|
+
function toAsciiSrvNameConstraint(e) {
|
|
373
|
+
let t = toAsciiSrvComponents(e);
|
|
374
|
+
return B(t) === void 0 && T("invalid_srv_name_constraint", "A SRVName constraint is _Service.Name, _Service, or Name (RFC 4985 §4)"), t;
|
|
375
|
+
}
|
|
376
|
+
/** RFC 4120 §5.2.1 KerberosString content: IA5String characters in a GeneralString, without code-extension controls. */
|
|
377
|
+
function kerberosString(e, t) {
|
|
378
|
+
let outside = (e) => e > 127 || e === 14 || e === 15 || e === 27;
|
|
379
|
+
return [...e].some((e) => outside(e.codePointAt(0) ?? 0)) && T("invalid_krb5_principal_name", `KRB5PrincipalName ${t} must hold IA5String characters other than SO, SI and ESC (RFC 4120 §5.2.1)`), g(27, new TextEncoder().encode(e));
|
|
380
|
+
}
|
|
381
|
+
/** RFC 4120 §5.2.4 Int32 as a DER-minimal two's-complement INTEGER. */
|
|
382
|
+
function int32(e) {
|
|
383
|
+
(!Number.isInteger(e) || e < -2147483648 || e > 2147483647) && T("invalid_krb5_principal_name", "KRB5PrincipalName nameType must be an Int32 (RFC 4120 §5.2.4)");
|
|
384
|
+
let t = [], n = e;
|
|
385
|
+
do
|
|
386
|
+
t.unshift(n & 255), n >>= 8;
|
|
387
|
+
while (!(n === 0 && (t[0] ?? 0) < 128) && !(n === -1 && (t[0] ?? 0) >= 128));
|
|
388
|
+
return g(2, Uint8Array.from(t));
|
|
389
|
+
}
|
|
390
|
+
/** RFC 4556 §3.2.2 KRB5PrincipalName in the EXPLICIT tagging of RFC 4120's module. */
|
|
391
|
+
function encodeKrb5PrincipalName(e) {
|
|
392
|
+
return e.realm.includes("\0") && T("invalid_krb5_principal_name", "KRB5PrincipalName realm must not contain NUL (RFC 4120 §5.2.2)"), h([o(0, kerberosString(e.realm, "realm")), o(1, h([o(0, int32(e.nameType)), o(1, h(e.nameString.map((e) => kerberosString(e, "nameString"))))]))]);
|
|
393
|
+
}
|
|
394
|
+
/** An otherName type-id that has no dedicated {@linkcode SubjectAltName} variant. */
|
|
395
|
+
function validateOtherNameTypeId(e) {
|
|
396
|
+
let t = validateOid(e);
|
|
397
|
+
return (t === C.idOnDnsSrv || t === C.idOnSmtpUtf8Mailbox) && T("other_name_type_id_has_variant", `otherName type-id ${t} is encoded through its dedicated SubjectAltName variant`), t;
|
|
398
|
+
}
|
|
399
|
+
function requireGeneralNameContent(e, t, n) {
|
|
400
|
+
let r = n(e);
|
|
401
|
+
return r.ok || T("invalid_general_name_content", r.reason === "unsupported" ? `${t} contents use an encoding micro509 cannot validate` : `${t} contents do not match the ${t === "x400Address" ? "ORAddress" : "EDIPartyName"} ASN.1 (RFC 5280)`), e;
|
|
402
|
+
}
|
|
403
|
+
function requireSingleDerElement(e) {
|
|
404
|
+
let t = re(e);
|
|
405
|
+
return t !== "valid" && T("invalid_other_name_value", t === "unsupported" ? "otherName value uses an encoding micro509 cannot validate" : "otherName value must be exactly one DER element"), e;
|
|
406
|
+
}
|
|
407
|
+
/** RFC 9549 §2.5: an rfc822Name or rfc822Name constraint with its host in A-labels. */
|
|
408
|
+
function toAsciiMailbox(e) {
|
|
409
|
+
let t = e.lastIndexOf("@");
|
|
410
|
+
return t < 0 ? toAsciiDnsName(e) : `${e.slice(0, t + 1)}${toAsciiDomain(requireRelativeDomain(e.slice(t + 1)))}`;
|
|
302
411
|
}
|
|
303
412
|
/**
|
|
304
413
|
* DER-encode a single {@linkcode SubjectAltName} GeneralName element.
|
|
@@ -307,13 +416,23 @@ function requireNonEmptyName(e) {
|
|
|
307
416
|
*/
|
|
308
417
|
function encodeSubjectAltName(e) {
|
|
309
418
|
switch (e.type) {
|
|
310
|
-
case "dns": return
|
|
311
|
-
case "email": return
|
|
312
|
-
case "uri": return
|
|
313
|
-
case "srv": return
|
|
314
|
-
case "
|
|
315
|
-
case "
|
|
316
|
-
case "
|
|
419
|
+
case "dns": return l(2, encodeIa5Content(toAsciiDnsName(requireNonEmptyName(e.value))));
|
|
420
|
+
case "email": return l(1, encodeIa5Content(toAsciiMailbox(requireNonEmptyName(e.value))));
|
|
421
|
+
case "uri": return l(6, encodeIa5Content(requireNonEmptyName(e.value)));
|
|
422
|
+
case "srv": return c(0, a([d(C.idOnDnsSrv), o(0, g(22, encodeIa5Content(toAsciiSrvName(requireNonEmptyName(e.value)))))]));
|
|
423
|
+
case "smtpUtf8Mailbox": return c(0, a([d(C.idOnSmtpUtf8Mailbox), o(0, _(assertSmtpUtf8Mailbox(e.value)))]));
|
|
424
|
+
case "upn": return c(0, a([d(C.ntPrincipalName), o(0, _(requireNonEmptyName(e.value)))]));
|
|
425
|
+
case "krb5PrincipalName": return c(0, a([d(C.idPkinitSan), o(0, encodeKrb5PrincipalName(e))]));
|
|
426
|
+
case "ip": return l(7, encodeIpAddress(e.value));
|
|
427
|
+
case "directoryName": return c(4, readDirectoryNameTlv(e.derHex));
|
|
428
|
+
case "otherName": {
|
|
429
|
+
let t = validateOtherNameTypeId(e.typeId), n = requireSingleDerElement(e.value);
|
|
430
|
+
return F(t, n, p(n)) !== void 0 && T("other_name_type_id_has_variant", `otherName type-id ${t} with this value is encoded through its dedicated SubjectAltName variant`), c(0, a([d(t), o(0, n)]));
|
|
431
|
+
}
|
|
432
|
+
case "x400Address": return requireGeneralNameContent(c(3, e.value), "x400Address", L);
|
|
433
|
+
case "ediPartyName": return requireGeneralNameContent(c(5, e.value), "ediPartyName", I);
|
|
434
|
+
case "registeredID": return l(8, p(d(validateOid(e.value))).value);
|
|
435
|
+
case "unknown": return H.has(e.tag) || T("invalid_general_name_tag", `Invalid GeneralName tag: ${e.tag}`), g(e.tag, e.value);
|
|
317
436
|
default: throw Error(`Unhandled SubjectAltName type: ${String(e)}`);
|
|
318
437
|
}
|
|
319
438
|
}
|
|
@@ -323,7 +442,7 @@ function encodeSubjectAltName(e) {
|
|
|
323
442
|
* @param usages EKU purposes to encode.
|
|
324
443
|
*/
|
|
325
444
|
function encodeExtendedKeyUsage(e) {
|
|
326
|
-
return e.length === 0 &&
|
|
445
|
+
return e.length === 0 && T("extended_key_usage_empty", "extendedKeyUsage must not be empty"), h(e.map((e) => d(getExtendedKeyUsageOid(e))));
|
|
327
446
|
}
|
|
328
447
|
/**
|
|
329
448
|
* DER-encode an Authority Information Access SEQUENCE.
|
|
@@ -331,7 +450,7 @@ function encodeExtendedKeyUsage(e) {
|
|
|
331
450
|
* @param entries AIA entries (OCSP, caIssuers, or custom) to encode.
|
|
332
451
|
*/
|
|
333
452
|
function encodeAuthorityInfoAccess(e) {
|
|
334
|
-
return assertAuthorityInfoAccessProfile(e),
|
|
453
|
+
return assertAuthorityInfoAccessProfile(e), h(e.map((e) => h([d(getAuthorityInfoAccessMethodOid(e.method)), encodeSubjectAltName(e.location)])));
|
|
335
454
|
}
|
|
336
455
|
/**
|
|
337
456
|
* @internal RFC 5280 §4.2.2.1 and RFC 6960 §3.1 rules for Authority Information
|
|
@@ -341,8 +460,8 @@ function encodeAuthorityInfoAccess(e) {
|
|
|
341
460
|
* smuggle a non-URI OCSP location past the input union.
|
|
342
461
|
*/
|
|
343
462
|
function assertAuthorityInfoAccessProfile(e) {
|
|
344
|
-
e.length === 0 &&
|
|
345
|
-
for (let t of e) getAuthorityInfoAccessMethodOid(t.method) ===
|
|
463
|
+
e.length === 0 && T("authority_info_access_empty", "authorityInfoAccess must not be empty");
|
|
464
|
+
for (let t of e) getAuthorityInfoAccessMethodOid(t.method) === C.ocspAccessMethod && t.location.type !== "uri" && T("authority_info_access_ocsp_not_uri", "authorityInfoAccess OCSP location must be a URI");
|
|
346
465
|
}
|
|
347
466
|
/**
|
|
348
467
|
* DER-encode a CRL Distribution Points SEQUENCE.
|
|
@@ -350,7 +469,7 @@ function assertAuthorityInfoAccessProfile(e) {
|
|
|
350
469
|
* @param points Distribution points to encode.
|
|
351
470
|
*/
|
|
352
471
|
function encodeCrlDistributionPoints(e) {
|
|
353
|
-
return assertCrlDistributionPointsProfile(e),
|
|
472
|
+
return assertCrlDistributionPointsProfile(e), h(e.map((e) => h(encodeDistributionPoint(e))));
|
|
354
473
|
}
|
|
355
474
|
/**
|
|
356
475
|
* @internal RFC 5280 §4.2.1.13 profile rules for a CRLDistributionPoints value,
|
|
@@ -361,12 +480,12 @@ function encodeCrlDistributionPoints(e) {
|
|
|
361
480
|
* a decoded point carries the parsed one. The rules only read its presence.
|
|
362
481
|
*/
|
|
363
482
|
function assertCrlDistributionPointsProfile(e) {
|
|
364
|
-
e.length === 0 &&
|
|
483
|
+
e.length === 0 && T("crl_distribution_points_empty", "cRLDistributionPoints must not be empty");
|
|
365
484
|
for (let t of e) assertDistributionPointProfile(t);
|
|
366
485
|
}
|
|
367
486
|
/** RFC 5280 §4.2.1.13 rules for one distribution point. */
|
|
368
487
|
function assertDistributionPointProfile(e) {
|
|
369
|
-
e.crlIssuer !== void 0 && e.crlIssuer.length === 0 &&
|
|
488
|
+
e.crlIssuer !== void 0 && e.crlIssuer.length === 0 && T("distribution_point_crl_issuer_empty", "DistributionPoint crlIssuer must not be empty"), e.distributionPoint === void 0 && e.crlIssuer === void 0 && T("distribution_point_empty", "DistributionPoint must contain distributionPoint or crlIssuer"), assertCrlIssuerDistinguishedNames(e), e.distributionPoint?.type === "fullName" && e.distributionPoint.fullName.length === 0 && T("distribution_point_full_name_empty", "DistributionPointName fullName must not be empty");
|
|
370
489
|
}
|
|
371
490
|
/**
|
|
372
491
|
* DER-encode a Name Constraints extension value.
|
|
@@ -375,8 +494,8 @@ function assertDistributionPointProfile(e) {
|
|
|
375
494
|
*/
|
|
376
495
|
function encodeNameConstraints(e) {
|
|
377
496
|
assertNameConstraintsProfile(e);
|
|
378
|
-
let
|
|
379
|
-
return e.permittedSubtrees !== void 0 && e.permittedSubtrees.length > 0 &&
|
|
497
|
+
let t = [];
|
|
498
|
+
return e.permittedSubtrees !== void 0 && e.permittedSubtrees.length > 0 && t.push(c(0, a(e.permittedSubtrees.map(encodeGeneralSubtree)))), e.excludedSubtrees !== void 0 && e.excludedSubtrees.length > 0 && t.push(c(1, a(e.excludedSubtrees.map(encodeGeneralSubtree)))), h(t);
|
|
380
499
|
}
|
|
381
500
|
/**
|
|
382
501
|
* @internal RFC 5280 fixes the criticality of several extensions: nameConstraints
|
|
@@ -389,7 +508,7 @@ function encodeNameConstraints(e) {
|
|
|
389
508
|
* @param critical The criticality the caller asked for.
|
|
390
509
|
*/
|
|
391
510
|
function assertExtensionCriticality(e, t, n) {
|
|
392
|
-
n !== t &&
|
|
511
|
+
n !== t && T(t ? "extension_must_be_critical" : "extension_must_be_non_critical", `The ${e} extension must be marked ${t ? "critical" : "non-critical"}`);
|
|
393
512
|
}
|
|
394
513
|
/**
|
|
395
514
|
* @internal RFC 5280 §4.2.1.10: a nameConstraints extension states at least one
|
|
@@ -397,7 +516,7 @@ function assertExtensionCriticality(e, t, n) {
|
|
|
397
516
|
*/
|
|
398
517
|
function assertNameConstraintsProfile(e) {
|
|
399
518
|
let t = e.permittedSubtrees?.length ?? 0, n = e.excludedSubtrees?.length ?? 0;
|
|
400
|
-
t === 0 && n === 0 &&
|
|
519
|
+
t === 0 && n === 0 && T("name_constraints_empty", "nameConstraints must set permittedSubtrees or excludedSubtrees");
|
|
401
520
|
}
|
|
402
521
|
/**
|
|
403
522
|
* DER-encode a Certificate Policies extension value.
|
|
@@ -405,13 +524,13 @@ function assertNameConstraintsProfile(e) {
|
|
|
405
524
|
* @param policies Non-empty array of policy information entries.
|
|
406
525
|
*/
|
|
407
526
|
function encodeCertificatePolicies(e) {
|
|
408
|
-
e.length === 0 &&
|
|
527
|
+
e.length === 0 && T("certificate_policies_empty", "certificatePolicies must not be empty");
|
|
409
528
|
let t = /* @__PURE__ */ new Set();
|
|
410
529
|
for (let n of e) {
|
|
411
530
|
let e = validatePolicyOid(n.policyIdentifier);
|
|
412
|
-
t.has(e) &&
|
|
531
|
+
t.has(e) && T("duplicate_policy_oid", `Duplicate certificate policy OID: ${n.policyIdentifier}`), t.add(e);
|
|
413
532
|
}
|
|
414
|
-
return
|
|
533
|
+
return h(e.map(encodePolicyInformation));
|
|
415
534
|
}
|
|
416
535
|
/**
|
|
417
536
|
* DER-encode a Policy Mappings extension value.
|
|
@@ -419,9 +538,9 @@ function encodeCertificatePolicies(e) {
|
|
|
419
538
|
* @param mappings Non-empty array of issuer-to-subject policy pairs. Neither OID may be anyPolicy.
|
|
420
539
|
*/
|
|
421
540
|
function encodePolicyMappings(e) {
|
|
422
|
-
return e.length === 0 &&
|
|
541
|
+
return e.length === 0 && T("policy_mappings_empty", "policyMappings must not be empty"), h(e.map((e) => {
|
|
423
542
|
let t = validatePolicyOid(e.issuerDomainPolicy), n = validatePolicyOid(e.subjectDomainPolicy);
|
|
424
|
-
return (t ===
|
|
543
|
+
return (t === C.anyPolicy || n === C.anyPolicy) && T("policy_mappings_any_policy", "policyMappings must not use anyPolicy"), h([d(e.issuerDomainPolicy), d(e.subjectDomainPolicy)]);
|
|
425
544
|
}));
|
|
426
545
|
}
|
|
427
546
|
/**
|
|
@@ -431,7 +550,7 @@ function encodePolicyMappings(e) {
|
|
|
431
550
|
*/
|
|
432
551
|
function encodePolicyConstraints(e) {
|
|
433
552
|
let t = [];
|
|
434
|
-
return e.requireExplicitPolicy !== void 0 && t.push(
|
|
553
|
+
return e.requireExplicitPolicy !== void 0 && t.push(l(0, encodeIntegerContent(e.requireExplicitPolicy))), e.inhibitPolicyMapping !== void 0 && t.push(l(1, encodeIntegerContent(e.inhibitPolicyMapping))), t.length === 0 && T("policy_constraints_empty", "policyConstraints must set requireExplicitPolicy or inhibitPolicyMapping"), h(t);
|
|
435
554
|
}
|
|
436
555
|
/**
|
|
437
556
|
* DER-encode an Inhibit anyPolicy extension value (single INTEGER).
|
|
@@ -439,47 +558,84 @@ function encodePolicyConstraints(e) {
|
|
|
439
558
|
* @param input The skipCerts threshold.
|
|
440
559
|
*/
|
|
441
560
|
function encodeInhibitAnyPolicy(e) {
|
|
442
|
-
return
|
|
561
|
+
return u(e.skipCerts);
|
|
443
562
|
}
|
|
444
563
|
/** DER-encode a single PolicyInformation SEQUENCE. */
|
|
445
564
|
function encodePolicyInformation(e) {
|
|
446
565
|
validatePolicyOid(e.policyIdentifier);
|
|
447
|
-
let t = [
|
|
448
|
-
return e.policyQualifiers !== void 0 && e.policyQualifiers.length > 0 && t.push(
|
|
566
|
+
let t = [d(e.policyIdentifier)];
|
|
567
|
+
return e.policyQualifiers !== void 0 && e.policyQualifiers.length > 0 && t.push(h(e.policyQualifiers.map(encodePolicyQualifierInfo))), h(t);
|
|
449
568
|
}
|
|
450
569
|
/** DER-encode a single PolicyQualifierInfo SEQUENCE. */
|
|
451
570
|
function encodePolicyQualifierInfo(e) {
|
|
452
571
|
switch (e.type) {
|
|
453
|
-
case "cps": return
|
|
454
|
-
case "userNotice": return
|
|
572
|
+
case "cps": return h([d(C.cpsPolicyQualifier), te(e.uri)]);
|
|
573
|
+
case "userNotice": return h([d(C.userNoticePolicyQualifier), encodeUserNoticePolicyQualifierInfo(e)]);
|
|
455
574
|
case "oid": {
|
|
456
575
|
validateOid(e.oid);
|
|
457
|
-
let t =
|
|
458
|
-
return (n ===
|
|
576
|
+
let t = d(e.oid), n = S(t);
|
|
577
|
+
return (n === S(d(C.cpsPolicyQualifier)) || n === S(d(C.userNoticePolicyQualifier))) && T("reserved_policy_qualifier_oid", "Policy qualifier must use the typed cps or userNotice variant, not a built-in OID"), h([t, new Uint8Array(e.qualifierDer)]);
|
|
459
578
|
}
|
|
460
579
|
default: throw Error(`Unhandled PolicyQualifierInfo type: ${String(e)}`);
|
|
461
580
|
}
|
|
462
581
|
}
|
|
463
582
|
/** DER-encode a UserNotice qualifier SEQUENCE. */
|
|
464
583
|
function assertDisplayText(e) {
|
|
584
|
+
s(e) && T("display_text_lone_surrogate", "DisplayText must not hold a lone UTF-16 surrogate");
|
|
465
585
|
let t = [...e].length;
|
|
466
|
-
(t === 0 || t > 200) &&
|
|
586
|
+
(t === 0 || t > 200) && T("display_text_out_of_range", "DisplayText must be 1 to 200 characters");
|
|
467
587
|
}
|
|
468
588
|
function encodeUserNoticePolicyQualifierInfo(e) {
|
|
469
589
|
let t = [];
|
|
470
|
-
return e.noticeRef !== void 0 && t.push(encodePolicyNoticeReference(e.noticeRef)), e.explicitText !== void 0 && (assertDisplayText(e.explicitText), t.push(
|
|
590
|
+
return e.noticeRef !== void 0 && t.push(encodePolicyNoticeReference(e.noticeRef)), e.explicitText !== void 0 && (assertDisplayText(e.explicitText), t.push(encodeExplicitText(e.explicitText, e.explicitTextType))), h(t);
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* RFC 6818 §3, replacing the explicitText paragraph of RFC 5280 §4.2.1.4:
|
|
594
|
+
* UTF8String is preferred, VisibleString and BMPString are acceptable,
|
|
595
|
+
* IA5String is forbidden, control characters should not appear, and UTF8String
|
|
596
|
+
* and BMPString text should be in Unicode normalization form C.
|
|
597
|
+
*/
|
|
598
|
+
function encodeExplicitText(e, t = "utf8String") {
|
|
599
|
+
switch ([...e].some(isControlCharacter) && T("display_text_control_character", "explicitText must not contain control characters"), t) {
|
|
600
|
+
case "utf8String": return assertNormalizationFormC(e), _(e);
|
|
601
|
+
case "bmpString": return assertNormalizationFormC(e), encodeBmpDisplayText(e);
|
|
602
|
+
case "visibleString": return encodeVisibleDisplayText(e);
|
|
603
|
+
case "ia5String": return T("display_text_ia5_string", "explicitText must not be encoded as IA5String");
|
|
604
|
+
default: throw Error(`Unhandled DisplayText type: ${String(t)}`);
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
function isControlCharacter(e) {
|
|
608
|
+
let t = e.codePointAt(0) ?? 0;
|
|
609
|
+
return t <= 31 || t >= 127 && t <= 159;
|
|
610
|
+
}
|
|
611
|
+
function assertNormalizationFormC(e) {
|
|
612
|
+
e.normalize("NFC") !== e && T("display_text_not_nfc", "explicitText must be in Unicode normalization form C");
|
|
613
|
+
}
|
|
614
|
+
function encodeVisibleDisplayText(e) {
|
|
615
|
+
try {
|
|
616
|
+
return v(e);
|
|
617
|
+
} catch {
|
|
618
|
+
return T("invalid_visible_string", "VisibleString explicitText must be printable ASCII");
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
function encodeBmpDisplayText(e) {
|
|
622
|
+
try {
|
|
623
|
+
return r(e);
|
|
624
|
+
} catch {
|
|
625
|
+
return T("invalid_bmp_string", "BMPString explicitText must hold Basic Multilingual Plane characters other than surrogates, U+FFFE and U+FFFF");
|
|
626
|
+
}
|
|
471
627
|
}
|
|
472
628
|
/** DER-encode a NoticeReference SEQUENCE. */
|
|
473
629
|
function encodePolicyNoticeReference(e) {
|
|
474
|
-
return assertDisplayText(e.organization),
|
|
630
|
+
return assertDisplayText(e.organization), h([_(e.organization), h(e.noticeNumbers.map((e) => u(e)))]);
|
|
475
631
|
}
|
|
476
632
|
/** Encode an INTEGER and return only the content bytes (no TLV wrapper). */
|
|
477
633
|
function encodeIntegerContent(e) {
|
|
478
|
-
return u(
|
|
634
|
+
return f(u(e)).value;
|
|
479
635
|
}
|
|
480
636
|
/** DER-encode a GeneralSubtree SEQUENCE (base name only; min/max omitted per RFC 5280). */
|
|
481
637
|
function encodeGeneralSubtree(e) {
|
|
482
|
-
return
|
|
638
|
+
return h([encodeNameConstraintForm(e.base)]);
|
|
483
639
|
}
|
|
484
640
|
/**
|
|
485
641
|
* RFC 5280 §4.2.1.13: cRLIssuer, when present, only contains the CRL issuer's
|
|
@@ -490,20 +646,20 @@ function encodeGeneralSubtree(e) {
|
|
|
490
646
|
* arrives through `crlDistributionPoints` or through `customExtensions`.
|
|
491
647
|
*/
|
|
492
648
|
function assertCrlIssuerDistinguishedNames(e) {
|
|
493
|
-
e.crlIssuer !== void 0 && (e.crlIssuer.some((e) => e.type !== "directoryName") &&
|
|
649
|
+
e.crlIssuer !== void 0 && (e.crlIssuer.some((e) => e.type !== "directoryName") && T("distribution_point_crl_issuer_not_directory_name", "DistributionPoint cRLIssuer must only contain directoryName entries"), e.distributionPoint?.type === "relativeName" && e.crlIssuer.length > 1 && T("distribution_point_relative_name_multiple_crl_issuers", "DistributionPointName relativeName requires at most one cRLIssuer distinguished name"));
|
|
494
650
|
}
|
|
495
651
|
/** DER-encode the fields of a single DistributionPoint, already profile-checked. */
|
|
496
652
|
function encodeDistributionPoint(e) {
|
|
497
|
-
let
|
|
498
|
-
return e.distributionPoint !== void 0 &&
|
|
653
|
+
let t = [];
|
|
654
|
+
return e.distributionPoint !== void 0 && t.push(c(0, encodeDistributionPointName(e.distributionPoint))), e.reasons !== void 0 && e.reasons.length > 0 && t.push(l(1, E(e.reasons))), e.crlIssuer !== void 0 && t.push(c(2, a(e.crlIssuer.map(encodeSubjectAltName)))), t;
|
|
499
655
|
}
|
|
500
656
|
/** DER-encode a DistributionPointName (fullName or relativeName). */
|
|
501
657
|
function encodeDistributionPointName(e) {
|
|
502
658
|
switch (e.type) {
|
|
503
|
-
case "fullName": return e.fullName.length === 0 &&
|
|
659
|
+
case "fullName": return e.fullName.length === 0 && T("distribution_point_full_name_empty", "DistributionPointName fullName must not be empty"), c(0, a(e.fullName.map(encodeSubjectAltName)));
|
|
504
660
|
case "relativeName": {
|
|
505
|
-
let t =
|
|
506
|
-
return
|
|
661
|
+
let t = U(e.relativeName), n = f(t);
|
|
662
|
+
return c(1, t.slice(n.start, n.end));
|
|
507
663
|
}
|
|
508
664
|
default: throw Error(`Unhandled DistributionPointName type: ${String(e)}`);
|
|
509
665
|
}
|
|
@@ -511,21 +667,22 @@ function encodeDistributionPointName(e) {
|
|
|
511
667
|
/** DER-encode a NameConstraintForm as an implicit-tagged {@linkcode GeneralName}. */
|
|
512
668
|
function encodeNameConstraintForm(e) {
|
|
513
669
|
switch (e.type) {
|
|
514
|
-
case "dns": return
|
|
515
|
-
case "email": return
|
|
516
|
-
case "uri": return
|
|
670
|
+
case "dns": return l(2, encodeIa5Content(toAsciiDnsName(e.value)));
|
|
671
|
+
case "email": return e.value.includes("@") && T("email_name_constraint_names_mailbox", "An rfc822Name constraint names a host or a domain, not a particular mailbox (RFC 9549 §2.2)"), l(1, encodeIa5Content(toAsciiMailbox(e.value)));
|
|
672
|
+
case "uri": return V(e.value) === void 0 && T("invalid_uri_name_constraint", "A uniformResourceIdentifier constraint is a fully qualified domain name, with a leading period for its subdomains (RFC 5280 §4.2.1.10)"), l(6, encodeIa5Content(e.value));
|
|
517
673
|
case "ip": {
|
|
518
|
-
let
|
|
519
|
-
return (e.addressBytes.length !== e.maskBytes.length ||
|
|
674
|
+
let t = e.addressBytes.length + e.maskBytes.length;
|
|
675
|
+
return (e.addressBytes.length !== e.maskBytes.length || t !== 8 && t !== 32) && T("invalid_ip_name_constraint", "IP name constraint must be 8 octets (IPv4) or 32 octets (IPv6)"), l(7, a([e.addressBytes, e.maskBytes]));
|
|
520
676
|
}
|
|
521
|
-
case "directoryName": return
|
|
677
|
+
case "directoryName": return c(4, readDirectoryNameTlv(e.derHex));
|
|
678
|
+
case "srv": return c(0, a([d(C.idOnDnsSrv), o(0, g(22, encodeIa5Content(toAsciiSrvNameConstraint(e.value))))]));
|
|
522
679
|
default: throw Error(`Unhandled NameConstraintForm type: ${String(e)}`);
|
|
523
680
|
}
|
|
524
681
|
}
|
|
525
682
|
/** Returns the complete Name TLV from a hex-encoded DER SEQUENCE, validating the root tag. */
|
|
526
683
|
function readDirectoryNameTlv(e) {
|
|
527
|
-
let t =
|
|
528
|
-
return n.tag !== 48 &&
|
|
684
|
+
let t = x(e), n = p(t, { maxDepth: 64 });
|
|
685
|
+
return n.tag !== 48 && T("directory_name_not_sequence", "directoryName derHex must encode a DER SEQUENCE"), t.slice(n.start - n.headerLength, n.end);
|
|
529
686
|
}
|
|
530
687
|
/**
|
|
531
688
|
* Resolve an {@linkcode ExtendedKeyUsage} to its dotted-decimal OID.
|
|
@@ -533,7 +690,7 @@ function readDirectoryNameTlv(e) {
|
|
|
533
690
|
* @param usage Well-known string or custom OID object.
|
|
534
691
|
*/
|
|
535
692
|
function getExtendedKeyUsageOid(e) {
|
|
536
|
-
return typeof e == "string" ?
|
|
693
|
+
return typeof e == "string" ? de[e] : validateOid(e.value);
|
|
537
694
|
}
|
|
538
695
|
/**
|
|
539
696
|
* Map a dotted-decimal OID to an {@linkcode ExtendedKeyUsage} value.
|
|
@@ -542,12 +699,12 @@ function getExtendedKeyUsageOid(e) {
|
|
|
542
699
|
*/
|
|
543
700
|
function parseExtendedKeyUsageOid(e) {
|
|
544
701
|
switch (e) {
|
|
545
|
-
case
|
|
546
|
-
case
|
|
547
|
-
case
|
|
548
|
-
case
|
|
549
|
-
case
|
|
550
|
-
case
|
|
702
|
+
case C.serverAuth: return "serverAuth";
|
|
703
|
+
case C.clientAuth: return "clientAuth";
|
|
704
|
+
case C.codeSigning: return "codeSigning";
|
|
705
|
+
case C.emailProtection: return "emailProtection";
|
|
706
|
+
case C.timeStamping: return "timeStamping";
|
|
707
|
+
case C.ocspSigning: return "ocspSigning";
|
|
551
708
|
}
|
|
552
709
|
return {
|
|
553
710
|
type: "oid",
|
|
@@ -560,7 +717,7 @@ function parseExtendedKeyUsageOid(e) {
|
|
|
560
717
|
* @param method Well-known string or custom OID object.
|
|
561
718
|
*/
|
|
562
719
|
function getAuthorityInfoAccessMethodOid(e) {
|
|
563
|
-
return typeof e == "string" ?
|
|
720
|
+
return typeof e == "string" ? fe[e] : validateOid(e.value);
|
|
564
721
|
}
|
|
565
722
|
/**
|
|
566
723
|
* Map a dotted-decimal OID to an {@linkcode AuthorityInfoAccessMethod} value.
|
|
@@ -569,8 +726,8 @@ function getAuthorityInfoAccessMethodOid(e) {
|
|
|
569
726
|
*/
|
|
570
727
|
function parseAuthorityInfoAccessMethodOid(e) {
|
|
571
728
|
switch (e) {
|
|
572
|
-
case
|
|
573
|
-
case
|
|
729
|
+
case C.ocspAccessMethod: return "ocsp";
|
|
730
|
+
case C.caIssuersAccessMethod: return "caIssuers";
|
|
574
731
|
}
|
|
575
732
|
return {
|
|
576
733
|
type: "oid",
|
|
@@ -579,7 +736,7 @@ function parseAuthorityInfoAccessMethodOid(e) {
|
|
|
579
736
|
}
|
|
580
737
|
/** Parse a dotted-decimal/colon-hex IP string to raw address bytes. */
|
|
581
738
|
function encodeIpAddress(e) {
|
|
582
|
-
return
|
|
739
|
+
return M(e);
|
|
583
740
|
}
|
|
584
741
|
/**
|
|
585
742
|
* Computes a key identifier from a DER `SubjectPublicKeyInfo` using method (1)
|
|
@@ -588,9 +745,19 @@ function encodeIpAddress(e) {
|
|
|
588
745
|
* A parsed certificate carries the input as `subjectPublicKeyInfoDer`.
|
|
589
746
|
*/
|
|
590
747
|
function buildSubjectKeyIdentifier(e) {
|
|
591
|
-
let t =
|
|
748
|
+
let t = m(e)[1];
|
|
592
749
|
if (t === void 0 || t.tag !== 3) throw Error("SPKI missing subject public key bit string");
|
|
593
|
-
|
|
750
|
+
let n = t.value.slice(1);
|
|
751
|
+
return w(n);
|
|
752
|
+
}
|
|
753
|
+
/**
|
|
754
|
+
* The key identifier a certificate or CRL issued by `issuer` carries in its
|
|
755
|
+
* authority key identifier: the issuer's subject key identifier (RFC 5280
|
|
756
|
+
* §4.2.1.2, §5.2.1), or a method (1) identifier over its public key when it
|
|
757
|
+
* has none (§4.2.1.1).
|
|
758
|
+
*/
|
|
759
|
+
function issuerKeyIdentifier(e) {
|
|
760
|
+
return e.subjectKeyIdentifier === void 0 ? buildSubjectKeyIdentifier(e.subjectPublicKeyInfoDer) : x(e.subjectKeyIdentifier);
|
|
594
761
|
}
|
|
595
762
|
/**
|
|
596
763
|
* Throw if the string is not an encodable dotted-decimal OID, and return its
|
|
@@ -600,12 +767,12 @@ function buildSubjectKeyIdentifier(e) {
|
|
|
600
767
|
* second to under 40 beneath arcs 0 and 1, so `3.1` and `1.40` parse as decimals
|
|
601
768
|
* yet cannot be encoded.
|
|
602
769
|
*/
|
|
603
|
-
function validateOid(
|
|
604
|
-
/^\d+(?:\.\d+)+$/.test(
|
|
770
|
+
function validateOid(t) {
|
|
771
|
+
/^\d+(?:\.\d+)+$/.test(t) || T("invalid_oid", `Invalid OID: ${t}`);
|
|
605
772
|
try {
|
|
606
|
-
return
|
|
607
|
-
} catch {
|
|
608
|
-
|
|
773
|
+
return y(t);
|
|
774
|
+
} catch (r) {
|
|
775
|
+
n(r, e), T("invalid_oid", `Invalid OID: ${t}`);
|
|
609
776
|
}
|
|
610
777
|
}
|
|
611
778
|
/** Validate a policy OID and return its canonical spelling. */
|
|
@@ -621,9 +788,8 @@ function validatePolicyOid(e) {
|
|
|
621
788
|
*/
|
|
622
789
|
function pushExtension(e, t, n, r, i = !1) {
|
|
623
790
|
let a = validateOid(n);
|
|
624
|
-
t.has(a) &&
|
|
791
|
+
t.has(a) && T("duplicate_extension_oid", `Duplicate extension OID: ${n}`), t.add(a), e.push(encodeExtension(n, r, i));
|
|
625
792
|
}
|
|
626
|
-
|
|
627
|
-
export { D as allOnesMaskForIpAddress, assertAuthorityInfoAccessProfile, assertCrlDistributionPointsProfile, assertExtensionCriticality, assertNameConstraintsProfile, buildCertificateExtensions, buildRequestedExtensions, buildSubjectKeyIdentifier, O as decodeIpAddress, encodeAuthorityInfoAccess, encodeBasicConstraints, encodeCertificatePolicies, encodeCrlDistributionPoints, encodeExtendedKeyUsage, encodeExtension, encodeInhibitAnyPolicy, encodeKeyUsage, encodeNameConstraints, encodePolicyConstraints, encodePolicyMappings, encodeSubjectAltName, getAuthorityInfoAccessMethodOid, getExtendedKeyUsageOid, k as normalizeIpAddress, parseAuthorityInfoAccessMethodOid, parseExtendedKeyUsageOid, A as parseIpAddressToBytes };
|
|
793
|
+
export { k as allOnesMaskForIpAddress, assertAuthorityInfoAccessProfile, assertCrlDistributionPointsProfile, assertExtensionCriticality, assertNameConstraintsProfile, assertStoredSubjectAltName, buildCertificateExtensions, buildRequestedExtensions, buildSubjectKeyIdentifier, A as decodeIpAddress, encodeAuthorityInfoAccess, encodeBasicConstraints, encodeCertificatePolicies, encodeCrlDistributionPoints, encodeExtendedKeyUsage, encodeExtension, encodeInhibitAnyPolicy, encodeKeyUsage, encodeNameConstraints, encodePolicyConstraints, encodePolicyMappings, encodeSubjectAltName, getAuthorityInfoAccessMethodOid, getExtendedKeyUsageOid, issuerKeyIdentifier, j as normalizeIpAddress, parseAuthorityInfoAccessMethodOid, parseExtendedKeyUsageOid, M as parseIpAddressToBytes };
|
|
628
794
|
|
|
629
795
|
//# sourceMappingURL=extensions.js.map
|