micro509 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +4 -4
- package/dist/index.js +15 -15
- package/dist/internal/asn1/asn1.js +145 -186
- package/dist/internal/asn1/asn1.js.map +1 -0
- package/dist/internal/asn1/der.js +210 -227
- package/dist/internal/asn1/der.js.map +1 -0
- package/dist/internal/asn1/oids.js +297 -101
- package/dist/internal/asn1/oids.js.map +1 -0
- package/dist/internal/asn1/oids2.js +69 -0
- package/dist/internal/asn1/oids2.js.map +1 -0
- package/dist/internal/crypto/algorithm-names.js +37 -35
- package/dist/internal/crypto/algorithm-names.js.map +1 -0
- package/dist/internal/crypto/ecdsa.js +25 -28
- package/dist/internal/crypto/ecdsa.js.map +1 -0
- package/dist/internal/crypto/hash.js +56 -117
- package/dist/internal/crypto/hash.js.map +1 -0
- package/dist/internal/crypto/pbes2.js +122 -133
- package/dist/internal/crypto/pbes2.js.map +1 -0
- package/dist/internal/crypto/rsa-pss.js +118 -124
- package/dist/internal/crypto/rsa-pss.js.map +1 -0
- package/dist/internal/crypto/sig-verify.js +87 -99
- package/dist/internal/crypto/sig-verify.js.map +1 -0
- package/dist/internal/crypto/signing.d.ts +12 -8
- package/dist/internal/crypto/signing.js +53 -55
- package/dist/internal/crypto/signing.js.map +1 -0
- package/dist/internal/crypto/webcrypto.js +5 -3
- package/dist/internal/crypto/webcrypto.js.map +1 -0
- package/dist/internal/shared/base64.js +10 -9
- package/dist/internal/shared/base64.js.map +1 -0
- package/dist/internal/shared/dn.js +50 -57
- package/dist/internal/shared/dn.js.map +1 -0
- package/dist/internal/shared/ip.js +43 -53
- package/dist/internal/shared/ip.js.map +1 -0
- package/dist/internal/verify/name-constraints-engine.js +211 -239
- package/dist/internal/verify/name-constraints-engine.js.map +1 -0
- package/dist/internal/verify/policy-engine.js +228 -247
- package/dist/internal/verify/policy-engine.js.map +1 -0
- package/dist/internal/verify/verify-path.js +213 -228
- package/dist/internal/verify/verify-path.js.map +1 -0
- package/dist/internal/x509/extension-bits.js +62 -59
- package/dist/internal/x509/extension-bits.js.map +1 -0
- package/dist/internal/x509/extension-registry.js +133 -164
- package/dist/internal/x509/extension-registry.js.map +1 -0
- package/dist/internal/x509/name-fields.js +35 -41
- package/dist/internal/x509/name-fields.js.map +1 -0
- package/dist/keys/keys.d.ts +626 -447
- package/dist/keys/keys.js +652 -404
- package/dist/keys/keys.js.map +1 -0
- package/dist/keys.d.ts +2 -2
- package/dist/keys.js +2 -2
- package/dist/pem/pem.d.ts +46 -46
- package/dist/pem/pem.js +62 -81
- package/dist/pem/pem.js.map +1 -0
- package/dist/pem.js +2 -2
- package/dist/pkcs/pfx.d.ts +96 -80
- package/dist/pkcs/pfx.js +191 -231
- package/dist/pkcs/pfx.js.map +1 -0
- package/dist/pkcs/pkcs12-mac.d.ts +20 -18
- package/dist/pkcs/pkcs12-mac.js +90 -111
- package/dist/pkcs/pkcs12-mac.js.map +1 -0
- package/dist/pkcs/pkcs7.d.ts +118 -69
- package/dist/pkcs/pkcs7.js +401 -443
- package/dist/pkcs/pkcs7.js.map +1 -0
- package/dist/pkcs.d.ts +2 -2
- package/dist/pkcs.js +4 -4
- package/dist/result/result.d.ts +37 -32
- package/dist/result/result.js +46 -44
- package/dist/result/result.js.map +1 -0
- package/dist/result.js +2 -2
- package/dist/revocation/chain.d.ts +138 -119
- package/dist/revocation/chain.js +248 -281
- package/dist/revocation/chain.js.map +1 -0
- package/dist/revocation/crl.d.ts +125 -123
- package/dist/revocation/crl.js +653 -745
- package/dist/revocation/crl.js.map +1 -0
- package/dist/revocation/ocsp.d.ts +183 -177
- package/dist/revocation/ocsp.js +581 -638
- package/dist/revocation/ocsp.js.map +1 -0
- package/dist/revocation/revocation.d.ts +26 -26
- package/dist/revocation/revocation.js +104 -125
- package/dist/revocation/revocation.js.map +1 -0
- package/dist/revocation.js +5 -5
- package/dist/verify/identity.d.ts +42 -42
- package/dist/verify/identity.js +158 -167
- package/dist/verify/identity.js.map +1 -0
- package/dist/verify/name-constraints.d.ts +7 -7
- package/dist/verify/policy.d.ts +10 -10
- package/dist/verify/verify.d.ts +163 -163
- package/dist/verify/verify.js +396 -392
- package/dist/verify/verify.js.map +1 -0
- package/dist/verify.js +3 -3
- package/dist/x509/certificate.d.ts +117 -117
- package/dist/x509/certificate.js +51 -60
- package/dist/x509/certificate.js.map +1 -0
- package/dist/x509/csr.d.ts +25 -25
- package/dist/x509/csr.js +26 -30
- package/dist/x509/csr.js.map +1 -0
- package/dist/x509/extensions.d.ts +228 -184
- package/dist/x509/extensions.js +175 -200
- package/dist/x509/extensions.js.map +1 -0
- package/dist/x509/name.d.ts +94 -93
- package/dist/x509/name.js +30 -29
- package/dist/x509/name.js.map +1 -0
- package/dist/x509/parse.d.ts +185 -185
- package/dist/x509/parse.js +638 -676
- package/dist/x509/parse.js.map +1 -0
- package/dist/x509.js +6 -6
- package/package.json +79 -41
package/dist/x509/extensions.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { bool, concatBytes, explicitContext, ia5String, implicitConstructedContext, implicitPrimitiveContext, integerFromNumber, objectIdentifier, octetString, readElement, readRootElement, readSequenceChildren, sequence, tlv, utf8String } from "../internal/asn1/der.js";
|
|
2
|
-
import { hexToBytes } from "../internal/asn1/asn1.js";
|
|
3
|
-
import { OIDS } from "../internal/asn1/
|
|
4
|
-
import { sha1 } from "../internal/crypto/hash.js";
|
|
5
|
-
import { parseIpAddressToBytes } from "../internal/shared/ip.js";
|
|
6
|
-
import { encodeDistributionPointReasonFlagsContent, encodeKeyUsageExtension } from "../internal/x509/extension-bits.js";
|
|
7
|
-
import { encodeRelativeDistinguishedName } from "./name.js";
|
|
8
|
-
import { AUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION, AUTHORITY_KEY_IDENTIFIER_EXTENSION_DEFINITION, BASIC_CONSTRAINTS_EXTENSION_DEFINITION, CERTIFICATE_POLICIES_EXTENSION_DEFINITION, CRL_DISTRIBUTION_POINTS_EXTENSION_DEFINITION, EXTENDED_KEY_USAGE_EXTENSION_DEFINITION, INHIBIT_ANY_POLICY_EXTENSION_DEFINITION, KEY_USAGE_EXTENSION_DEFINITION, NAME_CONSTRAINTS_EXTENSION_DEFINITION, POLICY_CONSTRAINTS_EXTENSION_DEFINITION, POLICY_MAPPINGS_EXTENSION_DEFINITION, SUBJECT_ALT_NAME_EXTENSION_DEFINITION, SUBJECT_KEY_IDENTIFIER_EXTENSION_DEFINITION, getExtensionDefinition } from "../internal/x509/extension-registry.js";
|
|
1
|
+
import { bool as e, concatBytes as t, explicitContext as n, ia5String as r, implicitConstructedContext as i, implicitPrimitiveContext as a, integerFromNumber as o, objectIdentifier as s, octetString as c, readElement as l, readRootElement as u, readSequenceChildren as d, sequence as f, tlv as p, utf8String as m } from "../internal/asn1/der.js";
|
|
2
|
+
import { hexToBytes as h } from "../internal/asn1/asn1.js";
|
|
3
|
+
import { OIDS as g } from "../internal/asn1/oids2.js";
|
|
4
|
+
import { sha1 as _ } from "../internal/crypto/hash.js";
|
|
5
|
+
import { parseIpAddressToBytes as v } from "../internal/shared/ip.js";
|
|
6
|
+
import { encodeDistributionPointReasonFlagsContent as y, encodeKeyUsageExtension as b } from "../internal/x509/extension-bits.js";
|
|
7
|
+
import { encodeRelativeDistinguishedName as x } from "./name.js";
|
|
8
|
+
import { AUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION as S, AUTHORITY_KEY_IDENTIFIER_EXTENSION_DEFINITION as C, BASIC_CONSTRAINTS_EXTENSION_DEFINITION as w, CERTIFICATE_POLICIES_EXTENSION_DEFINITION as T, CRL_DISTRIBUTION_POINTS_EXTENSION_DEFINITION as E, EXTENDED_KEY_USAGE_EXTENSION_DEFINITION as D, INHIBIT_ANY_POLICY_EXTENSION_DEFINITION as O, KEY_USAGE_EXTENSION_DEFINITION as k, NAME_CONSTRAINTS_EXTENSION_DEFINITION as A, POLICY_CONSTRAINTS_EXTENSION_DEFINITION as j, POLICY_MAPPINGS_EXTENSION_DEFINITION as M, SUBJECT_ALT_NAME_EXTENSION_DEFINITION as N, SUBJECT_KEY_IDENTIFIER_EXTENSION_DEFINITION as P, getExtensionDefinition as F } from "../internal/x509/extension-registry.js";
|
|
9
9
|
//#region src/x509/extensions.ts
|
|
10
10
|
/**
|
|
11
11
|
* Typed certificate and CSR extension model plus ASN.1 encoder helpers.
|
|
@@ -16,18 +16,16 @@ import { AUTHORITY_INFO_ACCESS_EXTENSION_DEFINITION, AUTHORITY_KEY_IDENTIFIER_EX
|
|
|
16
16
|
* @module
|
|
17
17
|
*/
|
|
18
18
|
/** Map from well-known EKU names to their dotted-decimal OIDs. */
|
|
19
|
-
const
|
|
20
|
-
serverAuth:
|
|
21
|
-
clientAuth:
|
|
22
|
-
codeSigning:
|
|
23
|
-
emailProtection:
|
|
24
|
-
timeStamping:
|
|
25
|
-
ocspSigning:
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
ocsp: OIDS.ocspAccessMethod,
|
|
30
|
-
caIssuers: OIDS.caIssuersAccessMethod
|
|
19
|
+
const I = {
|
|
20
|
+
serverAuth: g.serverAuth,
|
|
21
|
+
clientAuth: g.clientAuth,
|
|
22
|
+
codeSigning: g.codeSigning,
|
|
23
|
+
emailProtection: g.emailProtection,
|
|
24
|
+
timeStamping: g.timeStamping,
|
|
25
|
+
ocspSigning: g.ocspSigning
|
|
26
|
+
}, L = {
|
|
27
|
+
ocsp: g.ocspAccessMethod,
|
|
28
|
+
caIssuers: g.caIssuersAccessMethod
|
|
31
29
|
};
|
|
32
30
|
/**
|
|
33
31
|
* Build the v3 extensions block for a certificate.
|
|
@@ -43,17 +41,12 @@ const AUTHORITY_INFO_ACCESS_METHOD_OIDS = {
|
|
|
43
41
|
* subjectAltName extension is marked critical per RFC 5280 §4.2.1.6.
|
|
44
42
|
* @returns Array of DER-encoded Extension SEQUENCEs.
|
|
45
43
|
*/
|
|
46
|
-
function buildCertificateExtensions(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
appendConfiguredExtensions(extensions, seen, input, "certificate", {
|
|
53
|
-
includeBasicConstraints: false,
|
|
54
|
-
subjectIsEmpty
|
|
55
|
-
});
|
|
56
|
-
return extensions;
|
|
44
|
+
function buildCertificateExtensions(e, t, n, r = !1) {
|
|
45
|
+
let i = [], a = /* @__PURE__ */ new Set();
|
|
46
|
+
return pushKnownExtension(i, a, w, n?.basicConstraints ?? { ca: !1 }), pushKnownExtension(i, a, P, buildSubjectKeyIdentifier(e)), t !== void 0 && pushKnownExtension(i, a, C, buildSubjectKeyIdentifier(t)), appendConfiguredExtensions(i, a, n, "certificate", {
|
|
47
|
+
includeBasicConstraints: !1,
|
|
48
|
+
subjectIsEmpty: r
|
|
49
|
+
}), i;
|
|
57
50
|
}
|
|
58
51
|
/**
|
|
59
52
|
* Build the extensions for a CSR's extensionRequest attribute.
|
|
@@ -63,37 +56,41 @@ function buildCertificateExtensions(subjectPublicKeyInfo, issuerPublicKeyInfo, i
|
|
|
63
56
|
* @param input Optional extension configuration.
|
|
64
57
|
* @returns Array of DER-encoded Extension SEQUENCEs.
|
|
65
58
|
*/
|
|
66
|
-
function buildRequestedExtensions(
|
|
67
|
-
|
|
68
|
-
appendConfiguredExtensions(
|
|
69
|
-
return extensions;
|
|
59
|
+
function buildRequestedExtensions(e) {
|
|
60
|
+
let t = [];
|
|
61
|
+
return appendConfiguredExtensions(t, /* @__PURE__ */ new Set(), e, "csr", { includeBasicConstraints: !0 }), t;
|
|
70
62
|
}
|
|
71
63
|
/** Encode and push each configured extension from the input, enforcing no duplicates. */
|
|
72
|
-
function appendConfiguredExtensions(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
64
|
+
function appendConfiguredExtensions(e, t, n, r, i) {
|
|
65
|
+
n !== void 0 && (appendConstraintExtensions(e, t, n, i.includeBasicConstraints), appendIdentityExtensions(e, t, n, i.subjectIsEmpty === !0), appendPolicyExtensions(e, t, n), appendAccessExtensions(e, t, n), appendCustomExtensions(e, t, n, r));
|
|
66
|
+
}
|
|
67
|
+
function appendConstraintExtensions(e, t, n, r) {
|
|
68
|
+
r && n.basicConstraints !== void 0 && pushKnownExtension(e, t, w, n.basicConstraints), n.keyUsage !== void 0 && n.keyUsage.length > 0 && pushKnownExtension(e, t, k, n.keyUsage), n.nameConstraints !== void 0 && pushKnownExtension(e, t, A, n.nameConstraints);
|
|
69
|
+
}
|
|
70
|
+
function appendIdentityExtensions(e, t, n, r) {
|
|
71
|
+
if (n.subjectAltNames !== void 0 && n.subjectAltNames.length > 0) {
|
|
72
|
+
let i = r ? !0 : void 0;
|
|
73
|
+
pushKnownExtension(e, t, N, n.subjectAltNames, i);
|
|
79
74
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
75
|
+
n.extendedKeyUsage !== void 0 && n.extendedKeyUsage.length > 0 && pushKnownExtension(e, t, D, n.extendedKeyUsage);
|
|
76
|
+
}
|
|
77
|
+
/** Appends configured certificate-policy extensions while enforcing unique OIDs. */
|
|
78
|
+
function appendPolicyExtensions(e, t, n) {
|
|
79
|
+
n.certificatePolicies !== void 0 && n.certificatePolicies.length > 0 && pushKnownExtension(e, t, T, n.certificatePolicies), n.policyMappings !== void 0 && n.policyMappings.length > 0 && pushKnownExtension(e, t, M, n.policyMappings), n.policyConstraints !== void 0 && pushKnownExtension(e, t, j, n.policyConstraints), n.inhibitAnyPolicy !== void 0 && pushKnownExtension(e, t, O, n.inhibitAnyPolicy);
|
|
80
|
+
}
|
|
81
|
+
function appendAccessExtensions(e, t, n) {
|
|
82
|
+
n.authorityInfoAccess !== void 0 && n.authorityInfoAccess.length > 0 && pushKnownExtension(e, t, S, n.authorityInfoAccess), n.crlDistributionPoints !== void 0 && n.crlDistributionPoints.length > 0 && pushKnownExtension(e, t, E, n.crlDistributionPoints);
|
|
83
|
+
}
|
|
84
|
+
function appendCustomExtensions(e, t, n, r) {
|
|
85
|
+
if (n.customExtensions !== void 0) for (let i of n.customExtensions) {
|
|
86
|
+
let n = F(i.oid);
|
|
87
|
+
if (n !== void 0 && !n.contexts.includes(r)) throw Error(`Extension ${i.oid} is not supported in ${r} context`);
|
|
88
|
+
pushExtension(e, t, i.oid, new Uint8Array(i.value), i.critical ?? !1);
|
|
92
89
|
}
|
|
93
90
|
}
|
|
94
91
|
/** Encode a known extension via its registry definition and push it. */
|
|
95
|
-
function pushKnownExtension(
|
|
96
|
-
pushExtension(
|
|
92
|
+
function pushKnownExtension(e, t, n, r, i = n.defaultCritical) {
|
|
93
|
+
pushExtension(e, t, n.oid, n.encode(r), i);
|
|
97
94
|
}
|
|
98
95
|
/**
|
|
99
96
|
* Encode a single X.509 Extension SEQUENCE (OID + optional critical BOOLEAN + OCTET STRING).
|
|
@@ -102,11 +99,9 @@ function pushKnownExtension(encoded, seen, definition, value, critical = definit
|
|
|
102
99
|
* @param extnValue DER-encoded extension payload.
|
|
103
100
|
* @param critical Whether to mark the extension as critical. Default `false`.
|
|
104
101
|
*/
|
|
105
|
-
function encodeExtension(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
fields.push(octetString(extnValue));
|
|
109
|
-
return sequence(fields);
|
|
102
|
+
function encodeExtension(t, n, r = !1) {
|
|
103
|
+
let i = [s(t)];
|
|
104
|
+
return r && i.push(e(!0)), i.push(c(n)), f(i);
|
|
110
105
|
}
|
|
111
106
|
/**
|
|
112
107
|
* DER-encode a {@linkcode BasicConstraints} value.
|
|
@@ -114,38 +109,37 @@ function encodeExtension(oid, extnValue, critical = false) {
|
|
|
114
109
|
* @param input CA flag and optional pathLength.
|
|
115
110
|
* @returns DER SEQUENCE suitable for wrapping in an Extension OCTET STRING.
|
|
116
111
|
*/
|
|
117
|
-
function encodeBasicConstraints(
|
|
118
|
-
|
|
119
|
-
if (
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
fields.push(integerFromNumber(input.pathLength));
|
|
112
|
+
function encodeBasicConstraints(t) {
|
|
113
|
+
let n = [];
|
|
114
|
+
if (t.ca && n.push(e(!0)), t.pathLength !== void 0) {
|
|
115
|
+
if (!t.ca) throw Error("pathLength requires ca=true");
|
|
116
|
+
n.push(o(t.pathLength));
|
|
123
117
|
}
|
|
124
|
-
return
|
|
118
|
+
return f(n);
|
|
125
119
|
}
|
|
126
120
|
/**
|
|
127
121
|
* DER-encode a Key Usage BIT STRING from an array of {@linkcode KeyUsage} flags.
|
|
128
122
|
*
|
|
129
123
|
* @param usages Flags to set in the bit string.
|
|
130
124
|
*/
|
|
131
|
-
function encodeKeyUsage(
|
|
132
|
-
return
|
|
125
|
+
function encodeKeyUsage(e) {
|
|
126
|
+
return b(e);
|
|
133
127
|
}
|
|
134
128
|
/**
|
|
135
129
|
* DER-encode a single {@linkcode SubjectAltName} GeneralName element.
|
|
136
130
|
*
|
|
137
131
|
* @param value The SAN entry to encode.
|
|
138
132
|
*/
|
|
139
|
-
function encodeSubjectAltName(
|
|
140
|
-
switch (
|
|
141
|
-
case "dns": return
|
|
142
|
-
case "email": return
|
|
143
|
-
case "uri": return
|
|
144
|
-
case "srv": return
|
|
145
|
-
case "ip": return
|
|
146
|
-
case "directoryName": return
|
|
147
|
-
case "unknown": return
|
|
148
|
-
default: throw
|
|
133
|
+
function encodeSubjectAltName(e) {
|
|
134
|
+
switch (e.type) {
|
|
135
|
+
case "dns": return a(2, new TextEncoder().encode(e.value));
|
|
136
|
+
case "email": return a(1, new TextEncoder().encode(e.value));
|
|
137
|
+
case "uri": return a(6, new TextEncoder().encode(e.value));
|
|
138
|
+
case "srv": return i(0, f([s(g.idOnDnsSrv), n(0, r(e.value))]));
|
|
139
|
+
case "ip": return a(7, encodeIpAddress(e.value));
|
|
140
|
+
case "directoryName": return i(4, extractDirectoryNameContent(e.derHex));
|
|
141
|
+
case "unknown": return p(e.tag, e.value);
|
|
142
|
+
default: throw Error(`Unhandled SubjectAltName type: ${String(e)}`);
|
|
149
143
|
}
|
|
150
144
|
}
|
|
151
145
|
/**
|
|
@@ -153,57 +147,53 @@ function encodeSubjectAltName(value) {
|
|
|
153
147
|
*
|
|
154
148
|
* @param usages EKU purposes to encode.
|
|
155
149
|
*/
|
|
156
|
-
function encodeExtendedKeyUsage(
|
|
157
|
-
return
|
|
150
|
+
function encodeExtendedKeyUsage(e) {
|
|
151
|
+
return f(e.map((e) => s(getExtendedKeyUsageOid(e))));
|
|
158
152
|
}
|
|
159
153
|
/**
|
|
160
154
|
* DER-encode an Authority Information Access SEQUENCE.
|
|
161
155
|
*
|
|
162
156
|
* @param entries AIA entries (OCSP, caIssuers, or custom) to encode.
|
|
163
157
|
*/
|
|
164
|
-
function encodeAuthorityInfoAccess(
|
|
165
|
-
return
|
|
158
|
+
function encodeAuthorityInfoAccess(e) {
|
|
159
|
+
return f(e.map((e) => f([s(getAuthorityInfoAccessMethodOid(e.method)), a(6, new TextEncoder().encode(e.uri))])));
|
|
166
160
|
}
|
|
167
161
|
/**
|
|
168
162
|
* DER-encode a CRL Distribution Points SEQUENCE.
|
|
169
163
|
*
|
|
170
164
|
* @param points Distribution points to encode.
|
|
171
165
|
*/
|
|
172
|
-
function encodeCrlDistributionPoints(
|
|
173
|
-
return
|
|
166
|
+
function encodeCrlDistributionPoints(e) {
|
|
167
|
+
return f(e.map((e) => f(encodeDistributionPoint(e))));
|
|
174
168
|
}
|
|
175
169
|
/**
|
|
176
170
|
* DER-encode a Name Constraints extension value.
|
|
177
171
|
*
|
|
178
172
|
* @param constraints Permitted and/or excluded subtrees.
|
|
179
173
|
*/
|
|
180
|
-
function encodeNameConstraints(
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
if (constraints.excludedSubtrees !== void 0 && constraints.excludedSubtrees.length > 0) parts.push(implicitConstructedContext(1, concatBytes(constraints.excludedSubtrees.map(encodeGeneralSubtree))));
|
|
184
|
-
return sequence(parts);
|
|
174
|
+
function encodeNameConstraints(e) {
|
|
175
|
+
let n = [];
|
|
176
|
+
return e.permittedSubtrees !== void 0 && e.permittedSubtrees.length > 0 && n.push(i(0, t(e.permittedSubtrees.map(encodeGeneralSubtree)))), e.excludedSubtrees !== void 0 && e.excludedSubtrees.length > 0 && n.push(i(1, t(e.excludedSubtrees.map(encodeGeneralSubtree)))), f(n);
|
|
185
177
|
}
|
|
186
178
|
/**
|
|
187
179
|
* DER-encode a Certificate Policies extension value.
|
|
188
180
|
*
|
|
189
181
|
* @param policies Non-empty array of policy information entries.
|
|
190
182
|
*/
|
|
191
|
-
function encodeCertificatePolicies(
|
|
192
|
-
if (
|
|
193
|
-
return
|
|
183
|
+
function encodeCertificatePolicies(e) {
|
|
184
|
+
if (e.length === 0) throw Error("certificatePolicies must not be empty");
|
|
185
|
+
return f(e.map(encodePolicyInformation));
|
|
194
186
|
}
|
|
195
187
|
/**
|
|
196
188
|
* DER-encode a Policy Mappings extension value.
|
|
197
189
|
*
|
|
198
190
|
* @param mappings Non-empty array of issuer-to-subject policy pairs. Neither OID may be anyPolicy.
|
|
199
191
|
*/
|
|
200
|
-
function encodePolicyMappings(
|
|
201
|
-
if (
|
|
202
|
-
return
|
|
203
|
-
validatePolicyOid(
|
|
204
|
-
|
|
205
|
-
if (mapping.issuerDomainPolicy === OIDS.anyPolicy || mapping.subjectDomainPolicy === OIDS.anyPolicy) throw new Error("policyMappings must not use anyPolicy");
|
|
206
|
-
return sequence([objectIdentifier(mapping.issuerDomainPolicy), objectIdentifier(mapping.subjectDomainPolicy)]);
|
|
192
|
+
function encodePolicyMappings(e) {
|
|
193
|
+
if (e.length === 0) throw Error("policyMappings must not be empty");
|
|
194
|
+
return f(e.map((e) => {
|
|
195
|
+
if (validatePolicyOid(e.issuerDomainPolicy), validatePolicyOid(e.subjectDomainPolicy), e.issuerDomainPolicy === g.anyPolicy || e.subjectDomainPolicy === g.anyPolicy) throw Error("policyMappings must not use anyPolicy");
|
|
196
|
+
return f([s(e.issuerDomainPolicy), s(e.subjectDomainPolicy)]);
|
|
207
197
|
}));
|
|
208
198
|
}
|
|
209
199
|
/**
|
|
@@ -211,126 +201,113 @@ function encodePolicyMappings(mappings) {
|
|
|
211
201
|
*
|
|
212
202
|
* @param constraints At least one of `requireExplicitPolicy` or `inhibitPolicyMapping` must be set.
|
|
213
203
|
*/
|
|
214
|
-
function encodePolicyConstraints(
|
|
215
|
-
|
|
216
|
-
if (
|
|
217
|
-
|
|
218
|
-
if (fields.length === 0) throw new Error("policyConstraints must set requireExplicitPolicy or inhibitPolicyMapping");
|
|
219
|
-
return sequence(fields);
|
|
204
|
+
function encodePolicyConstraints(e) {
|
|
205
|
+
let t = [];
|
|
206
|
+
if (e.requireExplicitPolicy !== void 0 && t.push(a(0, encodeIntegerContent(e.requireExplicitPolicy))), e.inhibitPolicyMapping !== void 0 && t.push(a(1, encodeIntegerContent(e.inhibitPolicyMapping))), t.length === 0) throw Error("policyConstraints must set requireExplicitPolicy or inhibitPolicyMapping");
|
|
207
|
+
return f(t);
|
|
220
208
|
}
|
|
221
209
|
/**
|
|
222
210
|
* DER-encode an Inhibit anyPolicy extension value (single INTEGER).
|
|
223
211
|
*
|
|
224
212
|
* @param input The skipCerts threshold.
|
|
225
213
|
*/
|
|
226
|
-
function encodeInhibitAnyPolicy(
|
|
227
|
-
return
|
|
214
|
+
function encodeInhibitAnyPolicy(e) {
|
|
215
|
+
return o(e.skipCerts);
|
|
228
216
|
}
|
|
229
217
|
/** DER-encode a single PolicyInformation SEQUENCE. */
|
|
230
|
-
function encodePolicyInformation(
|
|
231
|
-
validatePolicyOid(
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
return sequence(fields);
|
|
218
|
+
function encodePolicyInformation(e) {
|
|
219
|
+
validatePolicyOid(e.policyIdentifier);
|
|
220
|
+
let t = [s(e.policyIdentifier)];
|
|
221
|
+
return e.policyQualifiers !== void 0 && e.policyQualifiers.length > 0 && t.push(f(e.policyQualifiers.map(encodePolicyQualifierInfo))), f(t);
|
|
235
222
|
}
|
|
236
223
|
/** DER-encode a single PolicyQualifierInfo SEQUENCE. */
|
|
237
|
-
function encodePolicyQualifierInfo(
|
|
238
|
-
switch (
|
|
239
|
-
case "cps": return
|
|
240
|
-
case "userNotice": return
|
|
241
|
-
case "oid":
|
|
242
|
-
|
|
243
|
-
return sequence([objectIdentifier(qualifier.oid), new Uint8Array(qualifier.qualifierDer)]);
|
|
244
|
-
default: throw new Error(`Unhandled PolicyQualifierInfo type: ${String(qualifier)}`);
|
|
224
|
+
function encodePolicyQualifierInfo(e) {
|
|
225
|
+
switch (e.type) {
|
|
226
|
+
case "cps": return f([s(g.cpsPolicyQualifier), r(e.uri)]);
|
|
227
|
+
case "userNotice": return f([s(g.userNoticePolicyQualifier), encodeUserNoticePolicyQualifierInfo(e)]);
|
|
228
|
+
case "oid": return validateOid(e.oid), f([s(e.oid), new Uint8Array(e.qualifierDer)]);
|
|
229
|
+
default: throw Error(`Unhandled PolicyQualifierInfo type: ${String(e)}`);
|
|
245
230
|
}
|
|
246
231
|
}
|
|
247
232
|
/** DER-encode a UserNotice qualifier SEQUENCE. */
|
|
248
|
-
function encodeUserNoticePolicyQualifierInfo(
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
if (qualifier.explicitText !== void 0) fields.push(utf8String(qualifier.explicitText));
|
|
252
|
-
return sequence(fields);
|
|
233
|
+
function encodeUserNoticePolicyQualifierInfo(e) {
|
|
234
|
+
let t = [];
|
|
235
|
+
return e.noticeRef !== void 0 && t.push(encodePolicyNoticeReference(e.noticeRef)), e.explicitText !== void 0 && t.push(m(e.explicitText)), f(t);
|
|
253
236
|
}
|
|
254
237
|
/** DER-encode a NoticeReference SEQUENCE. */
|
|
255
|
-
function encodePolicyNoticeReference(
|
|
256
|
-
return
|
|
238
|
+
function encodePolicyNoticeReference(e) {
|
|
239
|
+
return f([m(e.organization), f(e.noticeNumbers.map((e) => o(e)))]);
|
|
257
240
|
}
|
|
258
241
|
/** Encode an INTEGER and return only the content bytes (no TLV wrapper). */
|
|
259
|
-
function encodeIntegerContent(
|
|
260
|
-
return
|
|
242
|
+
function encodeIntegerContent(e) {
|
|
243
|
+
return l(o(e)).value;
|
|
261
244
|
}
|
|
262
245
|
/** DER-encode a GeneralSubtree SEQUENCE (base name only; min/max omitted per RFC 5280). */
|
|
263
|
-
function encodeGeneralSubtree(
|
|
264
|
-
return
|
|
246
|
+
function encodeGeneralSubtree(e) {
|
|
247
|
+
return f([encodeNameConstraintForm(e.base)]);
|
|
265
248
|
}
|
|
266
249
|
/** DER-encode the fields of a single DistributionPoint. */
|
|
267
|
-
function encodeDistributionPoint(
|
|
268
|
-
if (
|
|
269
|
-
if (
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
if (point.reasons !== void 0 && point.reasons.length > 0) fields.push(implicitPrimitiveContext(1, encodeDistributionPointReasonFlagsContent(point.reasons)));
|
|
273
|
-
if (point.crlIssuer !== void 0 && point.crlIssuer.length > 0) fields.push(implicitConstructedContext(2, concatBytes(point.crlIssuer.map(encodeSubjectAltName))));
|
|
274
|
-
return fields;
|
|
250
|
+
function encodeDistributionPoint(e) {
|
|
251
|
+
if (e.crlIssuer !== void 0 && e.crlIssuer.length === 0) throw Error("DistributionPoint crlIssuer must not be empty");
|
|
252
|
+
if (e.distributionPoint === void 0 && e.crlIssuer === void 0) throw Error("DistributionPoint must contain distributionPoint or crlIssuer");
|
|
253
|
+
let n = [];
|
|
254
|
+
return e.distributionPoint !== void 0 && n.push(i(0, encodeDistributionPointName(e.distributionPoint))), e.reasons !== void 0 && e.reasons.length > 0 && n.push(a(1, y(e.reasons))), e.crlIssuer !== void 0 && e.crlIssuer.length > 0 && n.push(i(2, t(e.crlIssuer.map(encodeSubjectAltName)))), n;
|
|
275
255
|
}
|
|
276
256
|
/** DER-encode a DistributionPointName (fullName or relativeName). */
|
|
277
|
-
function encodeDistributionPointName(
|
|
278
|
-
if (
|
|
279
|
-
if (
|
|
280
|
-
if (
|
|
281
|
-
return
|
|
257
|
+
function encodeDistributionPointName(e) {
|
|
258
|
+
if (e.fullName !== void 0 && e.relativeName !== void 0) throw Error("DistributionPointName cannot contain both fullName and relativeName");
|
|
259
|
+
if (e.fullName !== void 0) {
|
|
260
|
+
if (e.fullName.length === 0) throw Error("DistributionPointName fullName must not be empty");
|
|
261
|
+
return i(0, t(e.fullName.map(encodeSubjectAltName)));
|
|
282
262
|
}
|
|
283
|
-
if (
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
return implicitConstructedContext(1, relativeName.slice(relativeNameElement.start, relativeNameElement.end));
|
|
263
|
+
if (e.relativeName !== void 0) {
|
|
264
|
+
let t = x(e.relativeName), n = l(t);
|
|
265
|
+
return i(1, t.slice(n.start, n.end));
|
|
287
266
|
}
|
|
288
|
-
throw
|
|
267
|
+
throw Error("DistributionPointName must contain fullName or relativeName");
|
|
289
268
|
}
|
|
290
269
|
/** DER-encode a NameConstraintForm as an implicit-tagged {@linkcode GeneralName}. */
|
|
291
|
-
function encodeNameConstraintForm(
|
|
292
|
-
switch (
|
|
293
|
-
case "dns": return
|
|
294
|
-
case "email": return
|
|
295
|
-
case "uri": return
|
|
296
|
-
case "ip": return
|
|
297
|
-
case "directoryName": return
|
|
298
|
-
default: throw
|
|
270
|
+
function encodeNameConstraintForm(e) {
|
|
271
|
+
switch (e.type) {
|
|
272
|
+
case "dns": return a(2, new TextEncoder().encode(e.value));
|
|
273
|
+
case "email": return a(1, new TextEncoder().encode(e.value));
|
|
274
|
+
case "uri": return a(6, new TextEncoder().encode(e.value));
|
|
275
|
+
case "ip": return a(7, t([e.addressBytes, e.maskBytes]));
|
|
276
|
+
case "directoryName": return i(4, extractDirectoryNameContent(e.derHex));
|
|
277
|
+
default: throw Error(`Unhandled NameConstraintForm type: ${String(e)}`);
|
|
299
278
|
}
|
|
300
279
|
}
|
|
301
280
|
/** Extract the content bytes from a hex-encoded DER SEQUENCE (strips the outer TLV). */
|
|
302
|
-
function extractDirectoryNameContent(
|
|
303
|
-
|
|
304
|
-
if (
|
|
305
|
-
return new Uint8Array(
|
|
281
|
+
function extractDirectoryNameContent(e) {
|
|
282
|
+
let t = u(h(e), { maxDepth: 64 });
|
|
283
|
+
if (t.tag !== 48) throw Error("directoryName derHex must encode a DER SEQUENCE");
|
|
284
|
+
return new Uint8Array(t.value);
|
|
306
285
|
}
|
|
307
286
|
/**
|
|
308
287
|
* Resolve an {@linkcode ExtendedKeyUsage} to its dotted-decimal OID.
|
|
309
288
|
*
|
|
310
289
|
* @param usage Well-known string or custom OID object.
|
|
311
290
|
*/
|
|
312
|
-
function getExtendedKeyUsageOid(
|
|
313
|
-
|
|
314
|
-
validateOid(usage.value);
|
|
315
|
-
return usage.value;
|
|
291
|
+
function getExtendedKeyUsageOid(e) {
|
|
292
|
+
return typeof e == "string" ? I[e] : (validateOid(e.value), e.value);
|
|
316
293
|
}
|
|
317
294
|
/**
|
|
318
295
|
* Map a dotted-decimal OID to an {@linkcode ExtendedKeyUsage} value.
|
|
319
296
|
*
|
|
320
297
|
* Returns a well-known string for recognized OIDs, or `{ type: 'oid', value }` otherwise.
|
|
321
298
|
*/
|
|
322
|
-
function parseExtendedKeyUsageOid(
|
|
323
|
-
switch (
|
|
324
|
-
case
|
|
325
|
-
case
|
|
326
|
-
case
|
|
327
|
-
case
|
|
328
|
-
case
|
|
329
|
-
case
|
|
299
|
+
function parseExtendedKeyUsageOid(e) {
|
|
300
|
+
switch (e) {
|
|
301
|
+
case g.serverAuth: return "serverAuth";
|
|
302
|
+
case g.clientAuth: return "clientAuth";
|
|
303
|
+
case g.codeSigning: return "codeSigning";
|
|
304
|
+
case g.emailProtection: return "emailProtection";
|
|
305
|
+
case g.timeStamping: return "timeStamping";
|
|
306
|
+
case g.ocspSigning: return "ocspSigning";
|
|
330
307
|
}
|
|
331
308
|
return {
|
|
332
309
|
type: "oid",
|
|
333
|
-
value:
|
|
310
|
+
value: e
|
|
334
311
|
};
|
|
335
312
|
}
|
|
336
313
|
/**
|
|
@@ -338,50 +315,48 @@ function parseExtendedKeyUsageOid(oid) {
|
|
|
338
315
|
*
|
|
339
316
|
* @param method Well-known string or custom OID object.
|
|
340
317
|
*/
|
|
341
|
-
function getAuthorityInfoAccessMethodOid(
|
|
342
|
-
|
|
343
|
-
validateOid(method.value);
|
|
344
|
-
return method.value;
|
|
318
|
+
function getAuthorityInfoAccessMethodOid(e) {
|
|
319
|
+
return typeof e == "string" ? L[e] : (validateOid(e.value), e.value);
|
|
345
320
|
}
|
|
346
321
|
/**
|
|
347
322
|
* Map a dotted-decimal OID to an {@linkcode AuthorityInfoAccessMethod} value.
|
|
348
323
|
*
|
|
349
324
|
* Returns `'ocsp'` or `'caIssuers'` for recognized OIDs, or `{ type: 'oid', value }` otherwise.
|
|
350
325
|
*/
|
|
351
|
-
function parseAuthorityInfoAccessMethodOid(
|
|
352
|
-
switch (
|
|
353
|
-
case
|
|
354
|
-
case
|
|
326
|
+
function parseAuthorityInfoAccessMethodOid(e) {
|
|
327
|
+
switch (e) {
|
|
328
|
+
case g.ocspAccessMethod: return "ocsp";
|
|
329
|
+
case g.caIssuersAccessMethod: return "caIssuers";
|
|
355
330
|
}
|
|
356
331
|
return {
|
|
357
332
|
type: "oid",
|
|
358
|
-
value:
|
|
333
|
+
value: e
|
|
359
334
|
};
|
|
360
335
|
}
|
|
361
336
|
/** Parse a dotted-decimal/colon-hex IP string to raw address bytes. */
|
|
362
|
-
function encodeIpAddress(
|
|
363
|
-
return
|
|
337
|
+
function encodeIpAddress(e) {
|
|
338
|
+
return v(e);
|
|
364
339
|
}
|
|
365
340
|
/** @internal Compute the SKI as SHA-1 of the subjectPublicKey BIT STRING content. */
|
|
366
|
-
function buildSubjectKeyIdentifier(
|
|
367
|
-
|
|
368
|
-
if (
|
|
369
|
-
return
|
|
341
|
+
function buildSubjectKeyIdentifier(e) {
|
|
342
|
+
let t = d(e)[1];
|
|
343
|
+
if (t === void 0 || t.tag !== 3) throw Error("SPKI missing subject public key bit string");
|
|
344
|
+
return _(t.value.slice(1));
|
|
370
345
|
}
|
|
371
346
|
/** Throw if the string is not a valid dotted-decimal OID. */
|
|
372
|
-
function validateOid(
|
|
373
|
-
if (!/^\d+(?:\.\d+)+$/.test(
|
|
347
|
+
function validateOid(e) {
|
|
348
|
+
if (!/^\d+(?:\.\d+)+$/.test(e)) throw Error(`Invalid OID: ${e}`);
|
|
374
349
|
}
|
|
375
350
|
/** Validate that a policy OID is syntactically valid. */
|
|
376
|
-
function validatePolicyOid(
|
|
377
|
-
validateOid(
|
|
351
|
+
function validatePolicyOid(e) {
|
|
352
|
+
validateOid(e);
|
|
378
353
|
}
|
|
379
354
|
/** Encode and push an extension, rejecting duplicate OIDs. */
|
|
380
|
-
function pushExtension(
|
|
381
|
-
validateOid(
|
|
382
|
-
|
|
383
|
-
seen.add(oid);
|
|
384
|
-
encoded.push(encodeExtension(oid, value, critical));
|
|
355
|
+
function pushExtension(e, t, n, r, i = !1) {
|
|
356
|
+
if (validateOid(n), t.has(n)) throw Error(`Duplicate extension OID: ${n}`);
|
|
357
|
+
t.add(n), e.push(encodeExtension(n, r, i));
|
|
385
358
|
}
|
|
386
359
|
//#endregion
|
|
387
360
|
export { buildCertificateExtensions, buildRequestedExtensions, buildSubjectKeyIdentifier, encodeAuthorityInfoAccess, encodeBasicConstraints, encodeCertificatePolicies, encodeCrlDistributionPoints, encodeExtendedKeyUsage, encodeExtension, encodeInhibitAnyPolicy, encodeKeyUsage, encodeNameConstraints, encodePolicyConstraints, encodePolicyMappings, encodeSubjectAltName, getAuthorityInfoAccessMethodOid, getExtendedKeyUsageOid, parseAuthorityInfoAccessMethodOid, parseExtendedKeyUsageOid };
|
|
361
|
+
|
|
362
|
+
//# sourceMappingURL=extensions.js.map
|