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
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
1
|
+
import { DECODE_REFUSAL_CODES as e } from "../../result/result.js";
|
|
2
|
+
import { decodeRefusalOf as t, rethrowDecodeRefusal as n } from "../asn1/decode-refusal.js";
|
|
3
|
+
import { readRootElement as r } from "../asn1/der.js";
|
|
4
|
+
import { childrenOf as i, decodeObjectIdentifier as a, decodeString as o, hexToBytes as s, requireElement as c, toHex as l } from "../asn1/asn1.js";
|
|
5
|
+
import { OIDS as u } from "../asn1/oids2.js";
|
|
6
|
+
import { domainToAscii as d } from "../shared/idna.js";
|
|
7
|
+
import { allOnesMaskForIpAddress as f, decodeIpAddress as p, parseIpAddressToBytes as m } from "../shared/ip.js";
|
|
8
|
+
import { isMailboxDomain as h, presentedSmtpUtf8MailboxDomain as g } from "../shared/mailbox.js";
|
|
9
|
+
import { uriAuthorityHost as _ } from "../shared/uri-host.js";
|
|
10
|
+
import { parsePresentedSrvName as v, parseSrvNameRestriction as y, parseUriNameConstraint as b } from "../x509/general-name-profile.js";
|
|
11
|
+
import { nameFieldKeyFromOid as x } from "../x509/name-fields.js";
|
|
12
|
+
import { compareDistinguishedNames as S, directoryNameSubtreeMatch as C } from "../shared/dn.js";
|
|
13
|
+
// src/internal/verify/name-constraints-engine.ts
|
|
8
14
|
/**
|
|
9
15
|
* Internal name-constraints evaluation engine.
|
|
10
16
|
*
|
|
@@ -34,7 +40,7 @@ function nameConstraintDetails(e) {
|
|
|
34
40
|
}
|
|
35
41
|
/** A certificate is self-issued when subject and issuer DNs are semantically equal (RFC 5280 §7.1). */
|
|
36
42
|
function isSelfIssued(e) {
|
|
37
|
-
return
|
|
43
|
+
return S(e.subject, e.issuer);
|
|
38
44
|
}
|
|
39
45
|
/**
|
|
40
46
|
* Initializes validation state from caller-supplied initial constraints.
|
|
@@ -70,14 +76,15 @@ function evaluateNameConstraints(e, t) {
|
|
|
70
76
|
}
|
|
71
77
|
/** True when the certificate carries a critical nameConstraints extension. */
|
|
72
78
|
function hasCriticalNameConstraintsExtension(e) {
|
|
73
|
-
return e.extensions.some((e) => e.oid ===
|
|
79
|
+
return e.extensions.some((e) => e.oid === u.nameConstraints && e.critical);
|
|
74
80
|
}
|
|
75
81
|
/** Converts initial state into the starting accumulated-constraints snapshot. */
|
|
76
82
|
function seedInitialNameConstraints(e) {
|
|
77
83
|
return {
|
|
78
84
|
permittedLevels: e.initialPermittedSubtrees.length > 0 ? [e.initialPermittedSubtrees] : [],
|
|
79
85
|
excluded: e.initialExcludedSubtrees,
|
|
80
|
-
unsupportedCriticalForms: /* @__PURE__ */ new Set()
|
|
86
|
+
unsupportedCriticalForms: /* @__PURE__ */ new Set(),
|
|
87
|
+
unsupportedCriticalOtherNames: /* @__PURE__ */ new Set()
|
|
81
88
|
};
|
|
82
89
|
}
|
|
83
90
|
/**
|
|
@@ -90,28 +97,27 @@ function seedInitialNameConstraints(e) {
|
|
|
90
97
|
* extensions (conforming CAs MUST mark nameConstraints critical anyway).
|
|
91
98
|
*/
|
|
92
99
|
function accumulateConstraints(e, t, n) {
|
|
93
|
-
let r = t.permittedSubtrees !== void 0 && t.permittedSubtrees.length > 0 ? [...e.permittedLevels, t.permittedSubtrees.flatMap((e) => isSupportedNameConstraintForm(e.base) ? [e.base] : [])] : e.permittedLevels, i = t.excludedSubtrees !== void 0 && t.excludedSubtrees.length > 0 ? [...e.excluded, ...t.excludedSubtrees.flatMap((e) => isSupportedNameConstraintForm(e.base) ? [e.base] : [])] : e.excluded, a = n ?
|
|
100
|
+
let r = t.permittedSubtrees !== void 0 && t.permittedSubtrees.length > 0 ? [...e.permittedLevels, t.permittedSubtrees.flatMap((e) => isSupportedNameConstraintForm(e.base) ? [e.base] : [])] : e.permittedLevels, i = t.excludedSubtrees !== void 0 && t.excludedSubtrees.length > 0 ? [...e.excluded, ...t.excludedSubtrees.flatMap((e) => isSupportedNameConstraintForm(e.base) ? [e.base] : [])] : e.excluded, a = n ? listUnsupportedNameConstraintForms(t) : [];
|
|
94
101
|
return {
|
|
95
102
|
permittedLevels: r,
|
|
96
103
|
excluded: i,
|
|
97
|
-
unsupportedCriticalForms:
|
|
104
|
+
unsupportedCriticalForms: /* @__PURE__ */ new Set([...e.unsupportedCriticalForms, ...a.flatMap((e) => e.type === "otherName" ? [] : [e.type])]),
|
|
105
|
+
unsupportedCriticalOtherNames: /* @__PURE__ */ new Set([...e.unsupportedCriticalOtherNames, ...a.flatMap((e) => e.type === "otherName" ? [e.typeId] : [])])
|
|
98
106
|
};
|
|
99
107
|
}
|
|
100
|
-
/** Collects the
|
|
101
|
-
function
|
|
102
|
-
|
|
103
|
-
for (let n of e.permittedSubtrees ?? []) isSupportedNameConstraintForm(n.base) || t.add(n.base.type);
|
|
104
|
-
for (let n of e.excludedSubtrees ?? []) isSupportedNameConstraintForm(n.base) || t.add(n.base.type);
|
|
105
|
-
return [...t];
|
|
108
|
+
/** Collects the unsupported GeneralName forms from a nameConstraints extension. */
|
|
109
|
+
function listUnsupportedNameConstraintForms(e) {
|
|
110
|
+
return [...e.permittedSubtrees ?? [], ...e.excludedSubtrees ?? []].flatMap((e) => isSupportedNameConstraintForm(e.base) ? [] : [e.base]);
|
|
106
111
|
}
|
|
107
|
-
/** True for name forms this engine can evaluate: dns, email, uri, ip, directoryName. */
|
|
112
|
+
/** True for name forms this engine can evaluate: dns, email, uri, ip, directoryName, srv. */
|
|
108
113
|
function isSupportedNameConstraintForm(e) {
|
|
109
114
|
switch (e.type) {
|
|
110
115
|
case "dns":
|
|
111
116
|
case "email":
|
|
112
117
|
case "uri":
|
|
113
118
|
case "ip":
|
|
114
|
-
case "directoryName":
|
|
119
|
+
case "directoryName":
|
|
120
|
+
case "srv": return !0;
|
|
115
121
|
case "otherName":
|
|
116
122
|
case "x400Address":
|
|
117
123
|
case "ediPartyName":
|
|
@@ -123,13 +129,20 @@ function isSupportedNameConstraintForm(e) {
|
|
|
123
129
|
* Checks a certificate's subject DN and SANs against accumulated
|
|
124
130
|
* name constraints. Returns a failure if any name violates constraints.
|
|
125
131
|
*/
|
|
126
|
-
function checkCertificateNames(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
132
|
+
function checkCertificateNames(n, r, i) {
|
|
133
|
+
try {
|
|
134
|
+
let e = checkCertificateSubjectName(n, r, i);
|
|
135
|
+
if (!e.ok) return e;
|
|
136
|
+
let t = checkCertificateSubjectAltNames(n, r, i);
|
|
137
|
+
return t.ok ? checkCertificateSubjectEmailFallback(n, r, i) : t;
|
|
138
|
+
} catch (r) {
|
|
139
|
+
let a = t(r, e);
|
|
140
|
+
if (a === void 0) throw r;
|
|
141
|
+
return nameConstraintFailure(a.code, a.message, i, nameConstraintDetails({
|
|
142
|
+
subjectCommonName: n.subject.values.commonName,
|
|
143
|
+
actual: a.message
|
|
144
|
+
}));
|
|
145
|
+
}
|
|
133
146
|
}
|
|
134
147
|
/** Checks a certificate subject DN against the accumulated directory-name constraints. */
|
|
135
148
|
function checkCertificateSubjectName(e, t, n) {
|
|
@@ -146,18 +159,22 @@ function checkCertificateSubjectAltNames(e, t, n) {
|
|
|
146
159
|
return { ok: !0 };
|
|
147
160
|
}
|
|
148
161
|
function checkCertificateSubjectAltName(e, t, n, r) {
|
|
149
|
-
let i =
|
|
150
|
-
if (i !== void 0
|
|
162
|
+
let i = unprocessableConstraintFormOf(n, t);
|
|
163
|
+
if (i !== void 0) return nameConstraintFailure("unsupported_name_constraints", `critical name constraints impose ${i} constraints that cannot be processed, and the certificate contains a ${i} subject alternative name`, r, nameConstraintDetails({
|
|
151
164
|
subjectCommonName: e.subject.values.commonName,
|
|
152
165
|
actual: i
|
|
153
166
|
}));
|
|
167
|
+
if (n.type === "smtpUtf8Mailbox") return checkSmtpUtf8Mailbox(e, t, n.value, r);
|
|
154
168
|
let a = sanToConstraintCheckable(n);
|
|
155
169
|
if (!a.ok) return nameConstraintFailure("name_constraints_violated", `SAN ${a.actual} is malformed and cannot be checked against name constraints`, r, nameConstraintDetails({
|
|
156
170
|
subjectCommonName: e.subject.values.commonName,
|
|
157
171
|
actual: a.actual
|
|
158
172
|
}));
|
|
159
173
|
let o = a.value;
|
|
160
|
-
return o?.type === "
|
|
174
|
+
return o?.type === "srv" && accumulatedHasConstraintsOfType("srv", t) && v(asciiLowercase(o.value)) === void 0 ? nameConstraintFailure("name_constraints_violated", `SAN srv:${o.value} is not _Service.Name and cannot be evaluated against SRVName constraints`, r, nameConstraintDetails({
|
|
175
|
+
subjectCommonName: e.subject.values.commonName,
|
|
176
|
+
actual: `srv:${o.value}`
|
|
177
|
+
})) : o?.type === "uri" && accumulatedHasConstraintsOfType("uri", t) && uriConstraintHost(o.value) === void 0 ? nameConstraintFailure("name_constraints_violated", `SAN uri:${o.value} has no FQDN authority host and cannot be evaluated against URI name constraints`, r, nameConstraintDetails({
|
|
161
178
|
subjectCommonName: e.subject.values.commonName,
|
|
162
179
|
actual: `uri:${o.value}`
|
|
163
180
|
})) : o === void 0 || isNamePermitted(o, t) ? { ok: !0 } : nameConstraintFailure("name_constraints_violated", `SAN ${formatConstraintForm(o)} violates name constraints`, r, nameConstraintDetails({
|
|
@@ -165,6 +182,67 @@ function checkCertificateSubjectAltName(e, t, n, r) {
|
|
|
165
182
|
actual: formatConstraintForm(o)
|
|
166
183
|
}));
|
|
167
184
|
}
|
|
185
|
+
/**
|
|
186
|
+
* RFC 9598 §6 applies rfc822Name constraints to a SmtpUTF8Mailbox by its domain
|
|
187
|
+
* alone: the Local-part and "@" are stripped from the name and the constraint,
|
|
188
|
+
* and the remaining domains compare octet for octet after lowercasing, as a
|
|
189
|
+
* suffix when the constraint starts with ".". A mailbox that breaks the §3
|
|
190
|
+
* syntax cannot be compared, so it fails whenever rfc822Name constraints are
|
|
191
|
+
* in force.
|
|
192
|
+
*/
|
|
193
|
+
function checkSmtpUtf8Mailbox(e, t, n, r) {
|
|
194
|
+
return !accumulatedHasEmailConstraints(t) || isSmtpUtf8MailboxDomainPermitted(n, t) ? { ok: !0 } : nameConstraintFailure("name_constraints_violated", `SAN smtpUtf8Mailbox:${n} violates name constraints`, r, nameConstraintDetails({
|
|
195
|
+
subjectCommonName: e.subject.values.commonName,
|
|
196
|
+
actual: `smtpUtf8Mailbox:${n}`
|
|
197
|
+
}));
|
|
198
|
+
}
|
|
199
|
+
/** RFC 9598 §5: a presented SmtpUTF8Mailbox whose domain the email constraints permit. */
|
|
200
|
+
function isSmtpUtf8MailboxDomainPermitted(e, t) {
|
|
201
|
+
let n = g(e);
|
|
202
|
+
return n !== void 0 && isMailboxDomainPermitted(n, t);
|
|
203
|
+
}
|
|
204
|
+
function isMailboxDomainPermitted(e, t) {
|
|
205
|
+
if (hasMalformedConstraint("email", t)) return !1;
|
|
206
|
+
let matches = (t) => t.type === "email" && matchesMailboxDomainConstraint(e, t.value);
|
|
207
|
+
return !t.excluded.some(matches) && t.permittedLevels.every((e) => !e.some((e) => e.type === "email") || e.some(matches));
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* A dNSName or rfc822Name constraint whose domain is not a well-formed name
|
|
211
|
+
* cannot be compared, so no name of its type is permitted while one is in force.
|
|
212
|
+
*/
|
|
213
|
+
function hasMalformedConstraint(e, t) {
|
|
214
|
+
return [...t.excluded, ...t.permittedLevels.flat()].some((t) => t.type === e && !isWellFormedConstraint(t));
|
|
215
|
+
}
|
|
216
|
+
function isWellFormedConstraint(e) {
|
|
217
|
+
switch (e.type) {
|
|
218
|
+
case "dns": {
|
|
219
|
+
let t = asciiLowercase(e.value);
|
|
220
|
+
return t.length === 0 || isComparableDomain(t.startsWith(".") ? t.slice(1) : t);
|
|
221
|
+
}
|
|
222
|
+
case "email": return constraintMailboxDomain(e.value) !== void 0;
|
|
223
|
+
case "srv": return y(asciiLowercase(e.value)) !== void 0;
|
|
224
|
+
case "directoryName": return parseDirectoryNameDerHex(e.derHex) !== void 0;
|
|
225
|
+
case "uri": return b(e.value) !== void 0;
|
|
226
|
+
case "ip": return !0;
|
|
227
|
+
default: throw Error(`Unhandled NameConstraintForm type: ${String(e)}`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
/** Labels of 1 to 63 letters, digits, hyphens or underscores, with each `xn--` label an A-label. */
|
|
231
|
+
function isComparableDomain(e) {
|
|
232
|
+
return e.length <= 253 && e.split(".").every((e) => /^[a-z0-9_-]{1,63}$/.test(e)) && d(e, "lookup").ok;
|
|
233
|
+
}
|
|
234
|
+
/** RFC 9598 §6: the lowercased domain of an rfc822Name constraint, keeping a leading ".". */
|
|
235
|
+
function constraintMailboxDomain(e) {
|
|
236
|
+
let t = asciiLowercase(e.slice(e.lastIndexOf("@") + 1)), n = t.startsWith(".") ? t.slice(1) : t;
|
|
237
|
+
return h(n, "lookup") ? t : void 0;
|
|
238
|
+
}
|
|
239
|
+
function matchesMailboxDomainConstraint(e, t) {
|
|
240
|
+
let n = constraintMailboxDomain(t);
|
|
241
|
+
return n?.startsWith(".") === !0 ? e.endsWith(n) : e === n;
|
|
242
|
+
}
|
|
243
|
+
function asciiLowercase(e) {
|
|
244
|
+
return e.replace(/[A-Z]/g, (e) => e.toLowerCase());
|
|
245
|
+
}
|
|
168
246
|
function checkCertificateSubjectEmailFallback(e, t, n) {
|
|
169
247
|
return accumulatedHasEmailConstraints(t) && !(e.subjectAltNames?.some((e) => e.type === "email") ?? !1) && e.subject.values.emailAddress !== void 0 && !isNamePermitted({
|
|
170
248
|
type: "email",
|
|
@@ -179,27 +257,45 @@ function accumulatedHasEmailConstraints(e) {
|
|
|
179
257
|
for (let t of e.permittedLevels) if (t.some((e) => e.type === "email")) return !0;
|
|
180
258
|
return e.excluded.some((e) => e.type === "email");
|
|
181
259
|
}
|
|
182
|
-
/** True when any level of accumulated constraints addresses the
|
|
183
|
-
function
|
|
184
|
-
|
|
185
|
-
return e.excluded.some((e) => e.type === "uri");
|
|
260
|
+
/** True when any level of accumulated constraints addresses the given name form. */
|
|
261
|
+
function accumulatedHasConstraintsOfType(e, t) {
|
|
262
|
+
return [...t.excluded, ...t.permittedLevels.flat()].some((t) => t.type === e);
|
|
186
263
|
}
|
|
187
264
|
/**
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
* tag byte: 0xa0 otherName [0], 0xa3 x400Address [3], 0xa5 ediPartyName [5],
|
|
192
|
-
* 0x88 registeredID [8].
|
|
265
|
+
* The unprocessable critical constraint form a SAN instantiates, if one is in
|
|
266
|
+
* force. An otherName is its own form per type-id. Raw `unknown` input carries
|
|
267
|
+
* the DER tag byte, and an unknown otherName meets every otherName type-id.
|
|
193
268
|
*/
|
|
194
|
-
function
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
case
|
|
198
|
-
case
|
|
199
|
-
case
|
|
200
|
-
case
|
|
269
|
+
function unprocessableConstraintFormOf(e, t) {
|
|
270
|
+
let otherName = (e) => t.unsupportedCriticalOtherNames.has(e) ? `otherName ${e}` : void 0, direct = (e) => t.unsupportedCriticalForms.has(e) ? e : void 0;
|
|
271
|
+
switch (e.type) {
|
|
272
|
+
case "otherName": return otherName(e.typeId);
|
|
273
|
+
case "smtpUtf8Mailbox": return otherName(u.idOnSmtpUtf8Mailbox);
|
|
274
|
+
case "upn": return otherName(u.ntPrincipalName);
|
|
275
|
+
case "krb5PrincipalName": return otherName(u.idPkinitSan);
|
|
276
|
+
case "x400Address":
|
|
277
|
+
case "ediPartyName":
|
|
278
|
+
case "registeredID": return direct(e.type);
|
|
279
|
+
case "unknown": return unknownTagForm(e.tag, t);
|
|
280
|
+
default: return;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
function unknownTagForm(e, t) {
|
|
284
|
+
let n;
|
|
285
|
+
switch (e) {
|
|
286
|
+
case 163:
|
|
287
|
+
n = "x400Address";
|
|
288
|
+
break;
|
|
289
|
+
case 165:
|
|
290
|
+
n = "ediPartyName";
|
|
291
|
+
break;
|
|
292
|
+
case 136:
|
|
293
|
+
n = "registeredID";
|
|
294
|
+
break;
|
|
295
|
+
case 160: return t.unsupportedCriticalOtherNames.size > 0 ? "otherName" : void 0;
|
|
201
296
|
default: return;
|
|
202
297
|
}
|
|
298
|
+
return t.unsupportedCriticalForms.has(n) ? n : void 0;
|
|
203
299
|
}
|
|
204
300
|
/**
|
|
205
301
|
* Converts a SubjectAltName to a NameConstraintForm for checking.
|
|
@@ -230,6 +326,19 @@ function sanToConstraintCheckable(e) {
|
|
|
230
326
|
}
|
|
231
327
|
};
|
|
232
328
|
case "srv": return {
|
|
329
|
+
ok: !0,
|
|
330
|
+
value: {
|
|
331
|
+
type: "srv",
|
|
332
|
+
value: e.value
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
case "smtpUtf8Mailbox":
|
|
336
|
+
case "upn":
|
|
337
|
+
case "krb5PrincipalName":
|
|
338
|
+
case "otherName":
|
|
339
|
+
case "x400Address":
|
|
340
|
+
case "ediPartyName":
|
|
341
|
+
case "registeredID": return {
|
|
233
342
|
ok: !0,
|
|
234
343
|
value: void 0
|
|
235
344
|
};
|
|
@@ -238,8 +347,8 @@ function sanToConstraintCheckable(e) {
|
|
|
238
347
|
ok: !0,
|
|
239
348
|
value: {
|
|
240
349
|
type: "ip",
|
|
241
|
-
addressBytes:
|
|
242
|
-
maskBytes:
|
|
350
|
+
addressBytes: m(e.value),
|
|
351
|
+
maskBytes: f(e.value)
|
|
243
352
|
}
|
|
244
353
|
};
|
|
245
354
|
} catch {
|
|
@@ -270,23 +379,42 @@ function sanToConstraintCheckable(e) {
|
|
|
270
379
|
* name form, it matches at least one.
|
|
271
380
|
*/
|
|
272
381
|
function isNamePermitted(e, t) {
|
|
273
|
-
|
|
382
|
+
if (hasMalformedConstraint(e.type, t) || endsInRootDot(e) && accumulatedHasConstraintsOfType(e.type, t)) return !1;
|
|
383
|
+
for (let n of t.excluded) if (nameConstraintMatch(e, n) !== "mismatch") return !1;
|
|
274
384
|
for (let n of t.permittedLevels) {
|
|
275
385
|
let t = n.filter((t) => t.type === e.type);
|
|
276
|
-
if (t.length !== 0 && !t.some((t) =>
|
|
386
|
+
if (t.length !== 0 && !t.some((t) => nameConstraintMatch(e, t) === "match")) return !1;
|
|
277
387
|
}
|
|
278
388
|
return !0;
|
|
279
389
|
}
|
|
390
|
+
/** RFC 5280 §4.2.1.6: a dNSName or rfc822Name host in RFC 1034 §3.5 preferred name syntax has no trailing root dot. */
|
|
391
|
+
function endsInRootDot(e) {
|
|
392
|
+
return (e.type === "dns" || e.type === "email") && e.value.endsWith(".");
|
|
393
|
+
}
|
|
394
|
+
/** RFC 4518 §2: a comparison that string preparation cannot perform is Undefined. */
|
|
395
|
+
function nameConstraintMatch(e, t) {
|
|
396
|
+
return e.type === "directoryName" && t.type === "directoryName" ? matchesDnConstraint(e.derHex, t.derHex) : nameMatchesConstraint(e, t) ? "match" : "mismatch";
|
|
397
|
+
}
|
|
280
398
|
/** Dispatches to the type-specific matching function for the name form. */
|
|
281
399
|
function nameMatchesConstraint(e, t) {
|
|
282
|
-
return e.type === "dns" && t.type === "dns" ? matchesDnsConstraint(e.value, t.value) : e.type === "email" && t.type === "email" ? matchesEmailConstraint(e.value, t.value) : e.type === "uri" && t.type === "uri" ? matchesUriConstraint(e.value, t.value) : e.type === "ip" && t.type === "ip" ? matchesIpConstraint(e.addressBytes, t.addressBytes, t.maskBytes) : e.type === "
|
|
400
|
+
return e.type === "dns" && t.type === "dns" ? matchesDnsConstraint(e.value, t.value) : e.type === "email" && t.type === "email" ? matchesEmailConstraint(e.value, t.value) : e.type === "uri" && t.type === "uri" ? matchesUriConstraint(e.value, t.value) : e.type === "ip" && t.type === "ip" ? matchesIpConstraint(e.addressBytes, t.addressBytes, t.maskBytes) : e.type === "srv" && t.type === "srv" && matchesSrvConstraint(e.value, t.value);
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* RFC 4985 §4: a restriction's service, when present, must equal the SRVName's
|
|
404
|
+
* service case-insensitively (§2), and its Name, when present, is satisfied by
|
|
405
|
+
* that domain or any subdomain added to the left.
|
|
406
|
+
*/
|
|
407
|
+
function matchesSrvConstraint(e, t) {
|
|
408
|
+
let n = v(asciiLowercase(e)), r = y(asciiLowercase(t));
|
|
409
|
+
return n !== void 0 && r !== void 0 && (r.service.length === 0 || n.service === r.service) && (r.name.length === 0 || n.name === r.name || n.name.endsWith(`.${r.name}`));
|
|
283
410
|
}
|
|
284
411
|
/**
|
|
285
412
|
* DNS name constraint matching. RFC 5280 §4.2.1.10 adds zero or more labels on
|
|
286
413
|
* the left; §7.2 compares label by label case-insensitively. Constraint
|
|
287
|
-
* "example.com" matches "example.com" and any subdomain.
|
|
288
|
-
* form ".example.com"
|
|
289
|
-
*
|
|
414
|
+
* "example.com" matches "example.com" and any subdomain. RFC 5280 defines no
|
|
415
|
+
* leading-period dNSName form; ".example.com" matches subdomains only, as in
|
|
416
|
+
* OpenSSL, BoringSSL, Go, NSS, mozilla::pkix and rustls-webpki (RFC 5280
|
|
417
|
+
* erratum 5997).
|
|
290
418
|
*/
|
|
291
419
|
function matchesDnsConstraint(e, t) {
|
|
292
420
|
let n = e.toLowerCase(), r = t.toLowerCase();
|
|
@@ -311,43 +439,28 @@ function matchesEmailConstraint(e, t) {
|
|
|
311
439
|
return i.startsWith(".") ? r.endsWith(i) : r === i;
|
|
312
440
|
}
|
|
313
441
|
/**
|
|
314
|
-
* RFC 5280 §4.2.1.10: URI constraint
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
* - Constraint "example.com" matches ONLY that exact host (no subdomain
|
|
318
|
-
* expansion, unlike DNS constraints).
|
|
442
|
+
* RFC 5280 §4.2.1.10: a URI constraint applies to the host part, a constraint
|
|
443
|
+
* without a leading period names one host, and ".example.com" is satisfied by
|
|
444
|
+
* its subdomains only.
|
|
319
445
|
*/
|
|
320
446
|
function matchesUriConstraint(e, t) {
|
|
321
|
-
let n =
|
|
322
|
-
if (n === void 0) return !1;
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
try {
|
|
329
|
-
return new URL(e).hostname;
|
|
330
|
-
} catch {
|
|
331
|
-
return;
|
|
447
|
+
let n = uriConstraintHost(e), r = b(t);
|
|
448
|
+
if (n === void 0 || r === void 0) return !1;
|
|
449
|
+
switch (r.type) {
|
|
450
|
+
case "any": return !0;
|
|
451
|
+
case "host": return n === r.name;
|
|
452
|
+
case "subdomains": return n.endsWith(`.${r.name}`);
|
|
453
|
+
default: throw Error(`Unhandled UriNameConstraint type: ${String(r)}`);
|
|
332
454
|
}
|
|
333
455
|
}
|
|
334
456
|
/**
|
|
335
|
-
* RFC 5280 §4.2.1.10: a URI
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
-
* single-label host such as `localhost` (an FQDN has at least two labels).
|
|
457
|
+
* RFC 5280 §4.2.1.10: the domain name of a URI's authority host, which a URI
|
|
458
|
+
* constraint in force requires. `undefined` for no authority, an IP address, a
|
|
459
|
+
* reg-name that is not a domain name, or a single-label host.
|
|
339
460
|
*/
|
|
340
|
-
function
|
|
341
|
-
let t =
|
|
342
|
-
return t
|
|
343
|
-
}
|
|
344
|
-
/** True when `host` parses as an IPv4 or IPv6 literal. */
|
|
345
|
-
function isIpLiteral(e) {
|
|
346
|
-
try {
|
|
347
|
-
return u(e), !0;
|
|
348
|
-
} catch {
|
|
349
|
-
return !1;
|
|
350
|
-
}
|
|
461
|
+
function uriConstraintHost(e) {
|
|
462
|
+
let t = _(e, "presented");
|
|
463
|
+
return t.type === "dns" && t.name.includes(".") ? t.name : void 0;
|
|
351
464
|
}
|
|
352
465
|
/**
|
|
353
466
|
* RFC 5280 §4.2.1.10: IP constraint matching.
|
|
@@ -368,27 +481,28 @@ function matchesIpConstraint(e, t, n) {
|
|
|
368
481
|
*/
|
|
369
482
|
function matchesDnConstraint(e, t) {
|
|
370
483
|
let n = parseDirectoryNameDerHex(e), r = parseDirectoryNameDerHex(t);
|
|
371
|
-
return n === void 0 || r === void 0 ?
|
|
484
|
+
return n === void 0 || r === void 0 ? "mismatch" : C(n, r);
|
|
372
485
|
}
|
|
373
486
|
/** Re-parses a hex-encoded DER Name for RDN-by-RDN comparison. Returns `undefined` on malformed input. */
|
|
374
|
-
function parseDirectoryNameDerHex(
|
|
375
|
-
if (/^(?:[0-9a-fA-F]{2})+$/.test(
|
|
376
|
-
let
|
|
377
|
-
if (
|
|
378
|
-
let
|
|
379
|
-
for (let
|
|
380
|
-
let
|
|
381
|
-
if (
|
|
382
|
-
|
|
383
|
-
for (let e of
|
|
487
|
+
function parseDirectoryNameDerHex(t) {
|
|
488
|
+
if (/^(?:[0-9a-fA-F]{2})+$/.test(t)) try {
|
|
489
|
+
let e = s(t), n = unwrapDirectoryNameElement(e, r(e, { maxDepth: 64 }));
|
|
490
|
+
if (n.tag !== 48) return;
|
|
491
|
+
let a = [], o = [], c = {};
|
|
492
|
+
for (let t of i(e, n)) {
|
|
493
|
+
let n = parseDirectoryNameRdn(e, t);
|
|
494
|
+
if (n === void 0) return;
|
|
495
|
+
a.push(n);
|
|
496
|
+
for (let e of n.attributes) o.push(e), e.key !== void 0 && c[e.key] === void 0 && (c[e.key] = e.value);
|
|
384
497
|
}
|
|
385
498
|
return {
|
|
386
|
-
derHex:
|
|
387
|
-
rdns:
|
|
388
|
-
attributes:
|
|
389
|
-
values:
|
|
499
|
+
derHex: l(e),
|
|
500
|
+
rdns: a,
|
|
501
|
+
attributes: o,
|
|
502
|
+
values: c
|
|
390
503
|
};
|
|
391
|
-
} catch {
|
|
504
|
+
} catch (t) {
|
|
505
|
+
n(t, e);
|
|
392
506
|
return;
|
|
393
507
|
}
|
|
394
508
|
}
|
|
@@ -398,43 +512,44 @@ function parseDirectoryNameDerHex(n) {
|
|
|
398
512
|
* Some encoders produce `[4] { SEQ { SEQ { SET... } } }` instead of `[4] { SEQ { SET... } }`.
|
|
399
513
|
* A single SEQUENCE child indicates the extra wrapper (valid Names have SET children).
|
|
400
514
|
*/
|
|
401
|
-
function unwrapDirectoryNameElement(e,
|
|
402
|
-
if (
|
|
403
|
-
let
|
|
404
|
-
return
|
|
515
|
+
function unwrapDirectoryNameElement(e, t) {
|
|
516
|
+
if (t.tag !== 48) return t;
|
|
517
|
+
let n = i(e, t), r = n[0];
|
|
518
|
+
return n.length === 1 && r?.tag === 48 ? r : t;
|
|
405
519
|
}
|
|
406
520
|
/** Parses one SET element (a single RDN) from the DER Name SEQUENCE. */
|
|
407
|
-
function parseDirectoryNameRdn(
|
|
408
|
-
if (
|
|
409
|
-
let s = t
|
|
521
|
+
function parseDirectoryNameRdn(t, r) {
|
|
522
|
+
if (r.tag !== 49) return;
|
|
523
|
+
let s = i(t, r);
|
|
410
524
|
if (s.length === 0) return;
|
|
411
|
-
let
|
|
412
|
-
for (let
|
|
413
|
-
if (
|
|
414
|
-
let
|
|
415
|
-
if (
|
|
416
|
-
let
|
|
525
|
+
let u = [], d = {};
|
|
526
|
+
for (let r of s) {
|
|
527
|
+
if (r.tag !== 48) return;
|
|
528
|
+
let s = i(t, r), l = s[0], f = s[1];
|
|
529
|
+
if (l === void 0 || f === void 0 || s.length !== 2 || l.tag !== 6) return;
|
|
530
|
+
let p = a(c(l, "directoryName OID").value), m;
|
|
417
531
|
try {
|
|
418
|
-
|
|
419
|
-
} catch {
|
|
532
|
+
m = o(f.tag, c(f, "directoryName value").value);
|
|
533
|
+
} catch (t) {
|
|
534
|
+
n(t, e);
|
|
420
535
|
return;
|
|
421
536
|
}
|
|
422
|
-
let
|
|
423
|
-
oid:
|
|
424
|
-
valueTag:
|
|
425
|
-
value:
|
|
537
|
+
let h = x(p), g = h === void 0 ? {
|
|
538
|
+
oid: p,
|
|
539
|
+
valueTag: f.tag,
|
|
540
|
+
value: m
|
|
426
541
|
} : {
|
|
427
|
-
oid:
|
|
428
|
-
key:
|
|
429
|
-
valueTag:
|
|
430
|
-
value:
|
|
542
|
+
oid: p,
|
|
543
|
+
key: h,
|
|
544
|
+
valueTag: f.tag,
|
|
545
|
+
value: m
|
|
431
546
|
};
|
|
432
|
-
|
|
547
|
+
u.push(g), h !== void 0 && d[h] === void 0 && (d[h] = m);
|
|
433
548
|
}
|
|
434
|
-
if (
|
|
435
|
-
derHex:
|
|
436
|
-
attributes:
|
|
437
|
-
values:
|
|
549
|
+
if (u.length !== 0) return {
|
|
550
|
+
derHex: l(t.slice(r.start - r.headerLength, r.end)),
|
|
551
|
+
attributes: u,
|
|
552
|
+
values: d
|
|
438
553
|
};
|
|
439
554
|
}
|
|
440
555
|
/** Human-readable label for a constraint form, used in error messages. */
|
|
@@ -443,12 +558,12 @@ function formatConstraintForm(e) {
|
|
|
443
558
|
case "dns": return `dns:${e.value}`;
|
|
444
559
|
case "email": return `email:${e.value}`;
|
|
445
560
|
case "uri": return `uri:${e.value}`;
|
|
446
|
-
case "ip": return `ip:${
|
|
561
|
+
case "ip": return `ip:${p(e.addressBytes)}`;
|
|
447
562
|
case "directoryName": return `dn:${e.derHex.slice(0, 20)}${e.derHex.length > 20 ? "..." : ""}`;
|
|
563
|
+
case "srv": return `srv:${e.value}`;
|
|
448
564
|
default: throw Error(`Unhandled NameConstraintForm type: ${String(e)}`);
|
|
449
565
|
}
|
|
450
566
|
}
|
|
451
|
-
//#endregion
|
|
452
567
|
export { createNameConstraintValidationState, evaluateNameConstraints };
|
|
453
568
|
|
|
454
569
|
//# sourceMappingURL=name-constraints-engine.js.map
|