@browsercore/tls 0.4.19 → 0.4.21

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.
Files changed (66) hide show
  1. package/README.md +140 -23
  2. package/dist/certificates/ca-constraints.d.ts +15 -13
  3. package/dist/certificates/ca-constraints.d.ts.map +1 -1
  4. package/dist/certificates/ca-constraints.js +41 -59
  5. package/dist/certificates/ca-constraints.js.map +1 -1
  6. package/dist/certificates/cert-extensions.d.ts +59 -9
  7. package/dist/certificates/cert-extensions.d.ts.map +1 -1
  8. package/dist/certificates/cert-extensions.js +104 -50
  9. package/dist/certificates/cert-extensions.js.map +1 -1
  10. package/dist/certificates/certificate-path.d.ts +66 -7
  11. package/dist/certificates/certificate-path.d.ts.map +1 -1
  12. package/dist/certificates/certificate-path.js +125 -11
  13. package/dist/certificates/certificate-path.js.map +1 -1
  14. package/dist/certificates/certificates.d.ts.map +1 -1
  15. package/dist/certificates/certificates.js +107 -29
  16. package/dist/certificates/certificates.js.map +1 -1
  17. package/dist/certificates/extension-policy.d.ts +16 -6
  18. package/dist/certificates/extension-policy.d.ts.map +1 -1
  19. package/dist/certificates/extension-policy.js +17 -6
  20. package/dist/certificates/extension-policy.js.map +1 -1
  21. package/dist/certificates/extension-values.d.ts +131 -0
  22. package/dist/certificates/extension-values.d.ts.map +1 -0
  23. package/dist/certificates/extension-values.js +443 -0
  24. package/dist/certificates/extension-values.js.map +1 -0
  25. package/dist/certificates/general-names.d.ts +142 -0
  26. package/dist/certificates/general-names.d.ts.map +1 -0
  27. package/dist/certificates/general-names.js +354 -0
  28. package/dist/certificates/general-names.js.map +1 -0
  29. package/dist/certificates/name-constraints.d.ts +245 -0
  30. package/dist/certificates/name-constraints.d.ts.map +1 -0
  31. package/dist/certificates/name-constraints.js +692 -0
  32. package/dist/certificates/name-constraints.js.map +1 -0
  33. package/dist/certificates/name-match.d.ts +59 -0
  34. package/dist/certificates/name-match.d.ts.map +1 -0
  35. package/dist/certificates/name-match.js +271 -0
  36. package/dist/certificates/name-match.js.map +1 -0
  37. package/dist/errors.d.ts +61 -1
  38. package/dist/errors.d.ts.map +1 -1
  39. package/dist/errors.js +48 -0
  40. package/dist/errors.js.map +1 -1
  41. package/dist/handshake/client-hello.d.ts +16 -2
  42. package/dist/handshake/client-hello.d.ts.map +1 -1
  43. package/dist/handshake/client-hello.js +38 -5
  44. package/dist/handshake/client-hello.js.map +1 -1
  45. package/dist/handshake/handshake.d.ts +1 -1
  46. package/dist/handshake/handshake.d.ts.map +1 -1
  47. package/dist/handshake/handshake.js.map +1 -1
  48. package/dist/index.d.ts +2 -2
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +1 -1
  51. package/dist/index.js.map +1 -1
  52. package/dist/session/binder.d.ts +76 -0
  53. package/dist/session/binder.d.ts.map +1 -0
  54. package/dist/session/binder.js +107 -0
  55. package/dist/session/binder.js.map +1 -0
  56. package/dist/session/psk-extension.d.ts +49 -0
  57. package/dist/session/psk-extension.d.ts.map +1 -0
  58. package/dist/session/psk-extension.js +96 -0
  59. package/dist/session/psk-extension.js.map +1 -0
  60. package/dist/session/psk-offer.d.ts +52 -0
  61. package/dist/session/psk-offer.d.ts.map +1 -0
  62. package/dist/session/psk-offer.js +62 -0
  63. package/dist/session/psk-offer.js.map +1 -0
  64. package/dist/types.d.ts +28 -1
  65. package/dist/types.d.ts.map +1 -1
  66. package/package.json +2 -2
@@ -0,0 +1,354 @@
1
+ /**
2
+ * GeneralName / GeneralNames DER parsing (RFC 5280 §4.2.1.6, §4.2.1.10).
3
+ *
4
+ * One strict parser serves both consumers that BoringSSL parses at
5
+ * certificate-parse time (parsed_certificate.cc): the subjectAltName
6
+ * extension (`GeneralNames::Create`) and the nameConstraints subtrees
7
+ * (`ParseGeneralSubtrees` → `ParseGeneralName` with
8
+ * `IP_ADDRESS_AND_NETMASK`). Every structural fault this module THROWS on is
9
+ * one BoringSSL rejects the certificate for at parse time, regardless of the
10
+ * extension's critical flag:
11
+ *
12
+ * - the value is not a SEQUENCE covering all its bytes, or is an empty
13
+ * sequence ("GeneralNames is a sequence of 0 elements" /
14
+ * `kGeneralNamesEmpty`; "The GeneralNames sequence should have at least
15
+ * 1 element");
16
+ * - a GeneralName tag outside the nine CHOICE arms ("Unknown GeneralName
17
+ * type" — kUnknownGeneralNameType);
18
+ * - an rfc822Name / dNSName / uniformResourceIdentifier that is not ASCII
19
+ * ("rfc822Name is not ASCII" etc.);
20
+ * - an iPAddress whose octet length is not 4/16 (SAN) or 8/32 with a valid
21
+ * CIDR netmask (constraints) — "Failed parsing iPAddress";
22
+ * - a directoryName whose content does not BEGIN with a readable Name
23
+ * SEQUENCE. Trailing bytes after that SEQUENCE are IGNORED, exactly like
24
+ * BoringSSL: ParseGeneralName checks `parser.HasMore()` on the outer
25
+ * parser, which ReadTagAndValue already consumed (general_names.cc
26
+ * 152-157), so junk inside the [4] TLV after the Name never rejects.
27
+ *
28
+ * Only the name forms BoringSSL's name-constraint engine actually uses are
29
+ * retained (rfc822/dNS/directoryName/iPAddress — name_constraints.cc
30
+ * `kSupportedNameTypes`); the remaining CHOICE arms are validated for
31
+ * structure (so a malformed one still rejects the certificate) but not kept.
32
+ */
33
+ import { parseOid, readTlv } from "./der.js";
34
+ import { TlsMalformedExtensionError } from "../errors.js";
35
+ /** DER content-encoding of one GeneralName CHOICE arm (RFC 5280 §4.2.1.6). */
36
+ export const GENERAL_NAME_TAGS = {
37
+ otherName: 0xa0,
38
+ rfc822Name: 0x81,
39
+ dNSName: 0x82,
40
+ x400Address: 0xa3,
41
+ directoryName: 0xa4,
42
+ ediPartyName: 0xa5,
43
+ uniformResourceIdentifier: 0x86,
44
+ iPAddress: 0x87,
45
+ registeredID: 0x88,
46
+ };
47
+ /** Byte sizes of a SAN iPAddress entry (RFC 5280 §4.2.1.6: exactly 4 or 16). */
48
+ const IPV4_ADDRESS_SIZE = 4;
49
+ const IPV6_ADDRESS_SIZE = 16;
50
+ /**
51
+ * Throw the typed malformed-extension error. One helper so every rejection in
52
+ * this module names the extension OID uniformly (TlsMalformedExtensionError) —
53
+ * the parse-time value faults are kFailedParsingGeneralName /
54
+ * kFailedParsingSubjectAltName in BoringSSL, which reject the certificate the
55
+ * same way for every extension.
56
+ */
57
+ function malformed(oid, detail) {
58
+ throw new TlsMalformedExtensionError(oid, detail);
59
+ }
60
+ /** True when every byte of `bytes` is ASCII (BoringSSL string_util::IsAscii). */
61
+ function isAscii(bytes) {
62
+ for (const byte of bytes) {
63
+ if (byte > 0x7f) {
64
+ return false;
65
+ }
66
+ }
67
+ return true;
68
+ }
69
+ function asAsciiText(bytes, what, oid) {
70
+ const textDecoder = new TextDecoder("latin1");
71
+ if (!isAscii(bytes)) {
72
+ malformed(oid, `${what} is not ASCII (BoringSSL kDnsNameNotAscii / kRFC822NameNotAscii / kURINotAscii reject the certificate at parse time)`);
73
+ }
74
+ return textDecoder.decode(bytes);
75
+ }
76
+ /**
77
+ * Parse ONE GeneralName TLV (`tlv` already read at `tag`) inside a GeneralNames
78
+ * or GeneralSubtrees SEQUENCE. Returns the retained form, or undefined for the
79
+ * arms this package keeps only structurally-validated (otherName, x400Address,
80
+ * ediPartyName, registeredID). `ipMode` selects the SAN rule (4/16 bytes) or
81
+ * the name-constraint rule (8/32 bytes = address + CIDR netmask).
82
+ *
83
+ * Throws the typed certificate-phase error on any fault BoringSSL's
84
+ * ParseGeneralName (pki/general_names.cc) rejects the certificate for.
85
+ */
86
+ export function parseGeneralName(buf, tlv, ipMode, oid) {
87
+ const tag = tlv.tag;
88
+ const content = buf.subarray(tlv.valueStart, tlv.end);
89
+ switch (tag) {
90
+ case GENERAL_NAME_TAGS.rfc822Name:
91
+ return { kind: "rfc822", value: asAsciiText(content, "rfc822Name", oid) };
92
+ case GENERAL_NAME_TAGS.dNSName:
93
+ return { kind: "dns", value: asAsciiText(content, "dNSName", oid) };
94
+ case GENERAL_NAME_TAGS.uniformResourceIdentifier:
95
+ return { kind: "uri", value: asAsciiText(content, "uniformResourceIdentifier", oid) };
96
+ case GENERAL_NAME_TAGS.directoryName: {
97
+ // Name is a CHOICE { rdnSequence RDNSequence }, "therefore the
98
+ // SEQUENCE tag is explicit. Remove it, since the name matching
99
+ // functions expect only the value portion" (general_names.cc).
100
+ // BoringSSL then checks `parser.HasMore()` on the OUTER parser —
101
+ // the one ReadTagAndValue already consumed — so it is always
102
+ // false: bytes after the Name SEQUENCE inside the [4] TLV are
103
+ // silently ignored (general_names.cc:152-157; parser.cc
104
+ // ReadTagAndValue = PeekTagAndValue + Advance). Only a missing or
105
+ // non-SEQUENCE Name is the fault.
106
+ const name = readTlv(buf, tlv.valueStart);
107
+ if (name.tag !== 0x30) {
108
+ malformed(oid, "directoryName must carry a Name SEQUENCE element");
109
+ }
110
+ // Keep the RDNSequence VALUE (without the outer SEQUENCE tag) —
111
+ // the same form BoringSSL stores in `directory_names`.
112
+ return { kind: "directory", value: buf.subarray(name.valueStart, name.end) };
113
+ }
114
+ case GENERAL_NAME_TAGS.iPAddress: {
115
+ // RFC 5280 §4.2.1.6: "For IP version 4 … the octet string MUST
116
+ // contain exactly four octets. For IP version 6 … exactly sixteen
117
+ // octets." In name constraints (§4.2.1.10) the value is "eight
118
+ // (8) octets, encoded in the style of RFC 4632 (CIDR) … For IPv6
119
+ // … 32 octets" — the first half the address, the second the
120
+ // netmask, which must be contiguous 1s (IsValidNetmask).
121
+ const expected = ipMode === "address-only"
122
+ ? [IPV4_ADDRESS_SIZE, IPV6_ADDRESS_SIZE]
123
+ : [IPV4_ADDRESS_SIZE * 2, IPV6_ADDRESS_SIZE * 2];
124
+ if (content.length !== expected[0] && content.length !== expected[1]) {
125
+ malformed(oid, `iPAddress GeneralName must be ${expected[0]} or ${expected[1]} octets ` +
126
+ `(got ${content.length}) — BoringSSL kFailedParsingIp rejects the certificate`);
127
+ }
128
+ if (ipMode === "address-and-netmask" && !isValidNetmask(content.subarray(content.length / 2))) {
129
+ malformed(oid, "iPAddress netmask must be contiguous 1-bits followed by 0-bits " +
130
+ "(RFC 4632 CIDR; BoringSSL IsValidNetmask)");
131
+ }
132
+ return { kind: "ip", value: content };
133
+ }
134
+ case GENERAL_NAME_TAGS.otherName:
135
+ case GENERAL_NAME_TAGS.x400Address:
136
+ case GENERAL_NAME_TAGS.ediPartyName:
137
+ case GENERAL_NAME_TAGS.registeredID:
138
+ // Structurally validated (an unreadable TLV throws in readTlv
139
+ // before we get here), retained nowhere — these forms are not in
140
+ // BoringSSL's kSupportedNameTypes either.
141
+ return undefined;
142
+ default:
143
+ return malformed(oid, `unknown GeneralName tag 0x${tag.toString(16)} — BoringSSL kUnknownGeneralNameType ` +
144
+ "rejects the certificate at parse time");
145
+ }
146
+ }
147
+ /**
148
+ * Parse the subjectAltName / GeneralNames value (already unwrapped from its
149
+ * extnValue OCTET STRING): SEQUENCE SIZE (1..MAX) OF GeneralName.
150
+ *
151
+ * Mirrors BoringSSL `GeneralNames::Create` (pki/general_names.cc) which
152
+ * ParsedCertificate::Create runs for EVERY subjectAltName, critical or not;
153
+ * a fault throws the typed error and the certificate is rejected.
154
+ */
155
+ export function parseGeneralNames(value, oid) {
156
+ const seq = readTlv(value, 0);
157
+ if (seq.tag !== 0x30) {
158
+ malformed(oid, `expected GeneralNames SEQUENCE, got tag 0x${seq.tag.toString(16)}`);
159
+ }
160
+ // "The GeneralNames sequence should have at least 1 element" — an empty
161
+ // SAN is kGeneralNamesEmpty and rejects the certificate (BoringSSL).
162
+ if (seq.valueStart >= seq.end) {
163
+ malformed(oid, "GeneralNames is a sequence of 0 elements (kGeneralNamesEmpty)");
164
+ }
165
+ const dnsNames = [];
166
+ const rfc822Names = [];
167
+ const ipAddresses = [];
168
+ const directoryNames = [];
169
+ const uris = [];
170
+ const presentTags = new Set();
171
+ let o = seq.valueStart;
172
+ while (o < seq.end) {
173
+ const tlv = readTlv(value, o);
174
+ presentTags.add(tlv.tag);
175
+ const parsed = parseGeneralName(value, tlv, "address-only", oid);
176
+ if (parsed !== undefined) {
177
+ switch (parsed.kind) {
178
+ case "dns":
179
+ dnsNames.push(parsed.value);
180
+ break;
181
+ case "rfc822":
182
+ rfc822Names.push(parsed.value);
183
+ break;
184
+ case "ip":
185
+ ipAddresses.push(parsed.value);
186
+ break;
187
+ case "directory":
188
+ directoryNames.push(parsed.value);
189
+ break;
190
+ case "uri":
191
+ uris.push(parsed.value);
192
+ break;
193
+ }
194
+ }
195
+ o = tlv.end;
196
+ }
197
+ return {
198
+ dnsNames: Object.freeze(dnsNames),
199
+ rfc822Names: Object.freeze(rfc822Names),
200
+ ipAddresses: Object.freeze(ipAddresses),
201
+ directoryNames: Object.freeze(directoryNames),
202
+ uris: Object.freeze(uris),
203
+ presentTags: new Set(presentTags),
204
+ };
205
+ }
206
+ /**
207
+ * True when `mask` is a valid CIDR netmask (BoringSSL ip_util.h IsValidNetmask):
208
+ * "some number of ones, followed by some number of zeros".
209
+ */
210
+ export function isValidNetmask(mask) {
211
+ let onesDone = false;
212
+ for (const byte of mask) {
213
+ if (onesDone) {
214
+ if (byte !== 0) {
215
+ return false;
216
+ }
217
+ continue;
218
+ }
219
+ // Walk the bits of this byte from the MSB; the first 0 finishes the
220
+ // run of 1s and every following bit (here and in later bytes) must be 0.
221
+ for (let bit = 7; bit >= 0; bit--) {
222
+ const isOne = (byte & (1 << bit)) !== 0;
223
+ if (!isOne) {
224
+ onesDone = true;
225
+ }
226
+ else if (onesDone) {
227
+ return false;
228
+ }
229
+ }
230
+ }
231
+ return true;
232
+ }
233
+ /** True when `addr1`/`addr2` are equal under netmask `mask` (IPAddressMatchesWithNetmask). */
234
+ export function ipAddressMatchesWithNetmask(addr1, addr2, mask) {
235
+ if (addr1.length !== addr2.length || addr1.length !== mask.length) {
236
+ // "If they're different lengths, they're not in the same family" —
237
+ // an IPv4 range can never contain an IPv6 address and vice versa.
238
+ return false;
239
+ }
240
+ for (let i = 0; i < addr1.length; i++) {
241
+ const a = addr1[i] ?? 0;
242
+ const b = addr2[i] ?? 0;
243
+ const m = mask[i] ?? 0;
244
+ if ((a & m) !== (b & m)) {
245
+ return false;
246
+ }
247
+ }
248
+ return true;
249
+ }
250
+ /** Dotted-decimal / colon-hex rendering of an iPAddress octet string for diagnostics. */
251
+ export function formatIpAddress(bytes) {
252
+ if (bytes.length === 4) {
253
+ return Array.from(bytes, (b) => b.toString(10)).join(".");
254
+ }
255
+ return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join(":");
256
+ }
257
+ /**
258
+ * OID of the pkcs-9 emailAddress attribute (RFC 2985 §5.3.1) — the subject
259
+ * attribute the rfc822Name constraint applies to when the certificate has no
260
+ * subjectAltName (BoringSSL verify_name_match.cc FindEmailAddressesInName,
261
+ * `kTypeEmailAddressOid`).
262
+ */
263
+ export const EMAIL_ADDRESS_ATTRIBUTE_OID = "1.2.840.113549.1.9.1";
264
+ /**
265
+ * True when `oid` (dotted) equals `bytes` (a DER-encoded OBJECT IDENTIFIER
266
+ * value, without tag/length). Used to match name attribute types (OIDs) that
267
+ * were parsed with parseOid against raw OIDs read from constraint DNs.
268
+ */
269
+ export function dottedOidEqualsDer(oid, bytes) {
270
+ // Re-encode the dotted OID the DER way and compare bytes — the arcs are
271
+ // canonical so two encodings of the same OID are byte-equal.
272
+ const arcs = oid.split(".").map(Number);
273
+ const out = [];
274
+ for (const [index, arc] of arcs.entries()) {
275
+ if (index === 0) {
276
+ out.push(arc * 40 + (arcs[1] ?? 0));
277
+ continue;
278
+ }
279
+ if (index === 1) {
280
+ continue;
281
+ }
282
+ const enc = [];
283
+ let v = arc;
284
+ do {
285
+ enc.unshift((v & 0x7f) | (enc.length > 0 ? 0x80 : 0));
286
+ v = Math.floor(v / 128);
287
+ } while (v > 0);
288
+ out.push(...enc);
289
+ }
290
+ if (out.length !== bytes.length) {
291
+ return false;
292
+ }
293
+ return out.every((byte, i) => byte === (bytes[i] ?? -1));
294
+ }
295
+ /** Read one attribute value as text (AttributeValue ANY → string, like ValueAsString). */
296
+ export function attributeValueAsText(buf, tlv) {
297
+ const content = buf.subarray(tlv.valueStart, tlv.end);
298
+ const textDecoder = new TextDecoder("latin1");
299
+ switch (tlv.tag) {
300
+ case 0x0c: // UTF8String
301
+ case 0x13: // PrintableString
302
+ case 0x16: // IA5String
303
+ case 0x1b: // GeneralString (treated as bytes → latin1, like ValueAsString's best effort)
304
+ case 0x1e: { // BMPString (UCS-2 big-endian)
305
+ if (tlv.tag === 0x1e) {
306
+ // BMPString: UTF-16BE → UTF-8.
307
+ return new TextDecoder("utf-16be").decode(content);
308
+ }
309
+ return textDecoder.decode(content);
310
+ }
311
+ default:
312
+ return undefined;
313
+ }
314
+ }
315
+ /**
316
+ * Render an RDNSequence VALUE (bytes WITHOUT the outer SEQUENCE tag) as a
317
+ * readable "OID=value, OID=value" string for diagnostics — the display form
318
+ * parseName produces for full Name TLVs, kept byte-shape-independent.
319
+ */
320
+ export function formatRdnSequence(value) {
321
+ const parts = [];
322
+ let o = 0;
323
+ while (o < value.length) {
324
+ try {
325
+ const set = readTlv(value, o);
326
+ if (set.tag !== 0x31) {
327
+ break;
328
+ }
329
+ let p = set.valueStart;
330
+ const rdnParts = [];
331
+ while (p < set.end) {
332
+ const atv = readTlv(value, p);
333
+ if (atv.tag !== 0x30) {
334
+ break;
335
+ }
336
+ const oidTlv = readTlv(value, atv.valueStart);
337
+ const oid = parseOid(value, oidTlv.valueStart, oidTlv.end);
338
+ const valueTlv = readTlv(value, oidTlv.end);
339
+ const text = attributeValueAsText(value, valueTlv);
340
+ rdnParts.push(`${oid}=${text ?? `<tag 0x${valueTlv.tag.toString(16)}>`}`);
341
+ p = atv.end;
342
+ }
343
+ parts.push(rdnParts.join("+"));
344
+ o = set.end;
345
+ }
346
+ catch {
347
+ // Diagnostics only: an undecodable tail renders as opaque bytes.
348
+ parts.push(`<${value.length - o} unreadable byte(s)>`);
349
+ break;
350
+ }
351
+ }
352
+ return parts.join(", ");
353
+ }
354
+ //# sourceMappingURL=general-names.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"general-names.js","sourceRoot":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QAChB,CAAC;QAAC,MAAM,CAAC;YACL,iEAAiE;YACjE,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,sBAAsB,CAAC,CAAC;YACvD,MAAM;QACV,CAAC;IACL,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC5B,CAAC"}
@@ -0,0 +1,245 @@
1
+ /**
2
+ * nameConstraints processing (RFC 5280 §4.2.1.10), byte-for-byte the behavior
3
+ * of BoringSSL pki/name_constraints.cc at the revision Chromium 140 pins
4
+ * (0a0009998fa180695f3e2071805dc03c9a5f3124 — the file this module is a line-
5
+ * by-line twin of). Chrome never runs a different name-constraint engine for
6
+ * TLS server authentication: cert_verify_proc_builtin.cc just passes
7
+ * KeyPurpose::SERVER_AUTH to the CertPathBuilder and the pki verifier does
8
+ * the rest.
9
+ *
10
+ * Parse (NameConstraints::Parse):
11
+ * - the extnValue content is ONE SEQUENCE { permittedSubtrees [0] EXPLICIT
12
+ * GeneralSubtrees OPTIONAL, excludedSubtrees [1] EXPLICIT GeneralSubtrees
13
+ * OPTIONAL } with no trailing data;
14
+ * - both subtrees absent is a parse failure — RFC 5280: "Conforming CAs
15
+ * MUST NOT issue certificates where name constraints is an empty
16
+ * sequence" (name_constraints.cc:360-366);
17
+ * - each GeneralSubtrees SEQUENCE must hold ≥ 1 GeneralSubtree, and each
18
+ * GeneralSubtree is { base GeneralName } with NOTHING after the base:
19
+ * `if (subtree_sequence.HasMore()) { return false; }` (name_constraints.cc
20
+ * 179-181) rejects an explicit minimum [0] (even minimum=0 — the RFC's
21
+ * "the minimum MUST be zero" is implemented as "the field must be
22
+ * omitted, as DEFAULT requires in DER") and a maximum [1] alike;
23
+ * - an iPAddress base must be 8 or 32 octets with a contiguous-ones netmask
24
+ * (general_names.cc: RFC 5280 §4.2.1.10 "MUST contain eight (8) octets,
25
+ * encoded in the style of RFC 4632 (CIDR) … 32 octets"); a dNSName /
26
+ * rfc822Name base must be ASCII; an unknown tag or a non-ASCII string is
27
+ * a parse failure (kUnknownGeneralNameType / kFailedParsingGeneralName →
28
+ * kFailedParsingNameConstraints → ParsedCertificate::Create returns
29
+ * nullptr) REGARDLESS of the critical flag;
30
+ * - a constraint in a form the engine does not process (otherName,
31
+ * x400Address, ediPartyName, uniformResourceIdentifier, registeredID)
32
+ * PARSES fine and only matters when the extension is critical: Parse
33
+ * computes `constrained_name_types_ |= present_name_types & (is_critical
34
+ * ? GENERAL_NAME_ALL_TYPES : kSupportedNameTypes)` (name_constraints.cc
35
+ * 341-343, 356-358), and IsPermittedCert rejects a certificate whose SAN
36
+ * carries a name of such an unsupported-but-critically-constrained type
37
+ * (name_constraints.cc:450-454) — the RFC 5280 "MUST either process the
38
+ * constraint or reject the certificate" branch. The mask is a per-FORM
39
+ * bitfield (general_names.h gives every GeneralName CHOICE arm its own
40
+ * bit), so the check intersects forms independently: a critical URI
41
+ * constraint binds URI SANs and leaves otherName SANs untouched. NON-
42
+ * critical constraints on unsupported forms are dropped entirely.
43
+ *
44
+ * Enforcement (IsPermittedCert), on every certificate BELOW the constraint
45
+ * holder (never the holder itself — verify_certificate_chain.cc accumulates
46
+ * `name_constraints_list_` in PrepareForNextCertificate and applies it to the
47
+ * NEXT certificates: "Name constraints (RFC 5280 section 6.1.3 step b & c)…
48
+ * If certificate i is self-issued and it is not the final certificate in the
49
+ * path, skip this step for certificate i"; the root is exempt because the
50
+ * loop `continue`s after ProcessRootCertificate — "Don't do any other checks
51
+ * for root certificates" — but its constraints DO apply below it when anchor
52
+ * constraint enforcement is on, which Chromium's net/cert/
53
+ * cert_verify_proc_builtin.cc switches on for explicitly-supplied constrained
54
+ * anchors (`WithEnforceAnchorConstraints` over
55
+ * `additional_trust_anchors_with_constraints`)):
56
+ * - a DoS guard caps name × constraint combinations at 2^20
57
+ * (kMaxChecks = 1048576) — exceeding it is a HIGH-severity error, i.e. a
58
+ * failed verification, exactly like kNotPermittedByNameConstraints;
59
+ * - the subject's emailAddress attributes are constrained like
60
+ * rfc822Name SANs ONLY when the certificate has NO subjectAltName (RFC
61
+ * 5280 §4.2.1.10 legacy rule, name_constraints.cc:419-427, 493-519);
62
+ * - every SAN name is checked against its form's constraints: excluded
63
+ * subtrees first (a match = excluded), then — only when at least one
64
+ * permitted subtree of THAT form exists (`present_name_types` gate, e.g.
65
+ * name_constraints.cc:657 "If permitted subtrees are not constrained, any
66
+ * name that is not excluded is allowed") — the permitted match;
67
+ * - an rfc822Name CONSTRAINT that is itself structurally invalid (more
68
+ * than one "@", a local-part or domain with forbidden characters, an
69
+ * empty domain) resolves by Rfc822NameMatches' match-type polarity:
70
+ * "In case of parsing errors, return a value that will cause the name to
71
+ * not be permitted" — error_value is FALSE for a permitted-subtree
72
+ * constraint (the fault does not match) and TRUE for an excluded one
73
+ * (the fault MATCHES, so the certificate is REJECTED — fail closed,
74
+ * name_constraints.cc:234-236);
75
+ * - a dNSName SAN is matched case-insensitively with suffix semantics
76
+ * (DNSNameMatches): the empty constraint matches everything, a trailing
77
+ * dot is stripped from BOTH sides (once), a leading-dot constraint
78
+ * matches subdomains ONLY ("foo.bar.com matches constraint .bar.com, but
79
+ * bar.com doesn't" — name_constraints.cc:109-114), the label boundary is
80
+ * enforced ("foobar.com is not a match for bar.com" — 120-122), and
81
+ * wildcards are literal strings with one special case: "*.bar.com" is
82
+ * EXCLUDED by constraint "foo.bar.com" (any expansion could hit it —
83
+ * WILDCARD_PARTIAL_MATCH, 646-652) and PERMITTED only by a constraint
84
+ * that would match every expansion ("*.bar.com should match a constraint
85
+ * of bar.com, but not foo.bar.com" — WILDCARD_FULL_MATCH, 661-668);
86
+ * - the subject DN (and SAN directoryNames) are matched as DNs: subtree =
87
+ * prefix-of-RDNs-in-order with per-attribute normalization
88
+ * (VerifyNameInSubtree / verify_name_match.cc) — via name-match.ts;
89
+ * - iPAddress SANs match constraint ranges by netmask; a family with no
90
+ * range of its own is simply never matched, so an IPv6 SAN under
91
+ * IPv4-only permitted subtrees is NOT permitted (IPAddressMatchesWith
92
+ * Netmask returns false for differing lengths — "If they're different
93
+ * lengths, they're not in the same family");
94
+ * - the subject DN is checked against directoryName constraints even when a
95
+ * SAN is present, UNLESS the subject is empty (RFC 5280 §4.1.2.6
96
+ * empty-subject-with-SAN shape: name_constraints.cc:529-531 "only needs
97
+ * to avoid the IsPermittedDirectoryName check against an empty subject in
98
+ * such a case");
99
+ * - commonName is NEVER checked: "Note that this method does not check
100
+ * hostname or IP address in commonName, which is deprecated
101
+ * (crbug.com/308330)" (name_constraints.h:59-60) — and a certificate with
102
+ * an empty or SAN-less name set is NOT rejected for that reason alone
103
+ * (every check in IsPermittedCert iterates the names actually present).
104
+ */
105
+ import { type GeneralNames } from "./general-names.js";
106
+ /**
107
+ * The parsed subtrees of one nameConstraints side: the four processed forms
108
+ * plus `presentTypes` — which SUPPORTED forms OCCURRED (BoringSSL
109
+ * `present_name_types`), the gate that decides whether the permitted list
110
+ * constrains a form at all — and `unsupportedTags`, the unsupported-form
111
+ * bases that occurred (the per-form intersection side of the
112
+ * critical-unsupported-form rule).
113
+ */
114
+ export interface GeneralSubtrees {
115
+ readonly dnsNames: readonly string[];
116
+ readonly rfc822Names: readonly string[];
117
+ /** RDNSequence VALUE bytes (outer SEQUENCE tag stripped), like BoringSSL stores. */
118
+ readonly directoryNames: readonly Uint8Array[];
119
+ /** {address, netmask} pairs, each half 4 or 16 bytes. */
120
+ readonly ipRanges: readonly {
121
+ readonly address: Uint8Array;
122
+ readonly netmask: Uint8Array;
123
+ }[];
124
+ /** GeneralName tag bytes of unsupported-form bases (otherName/x400/ediParty/registeredID/URI). */
125
+ readonly unsupportedTags: ReadonlySet<number>;
126
+ /** Bitmask of the CONSTRAINABLE (supported) forms that occurred. */
127
+ readonly presentTypes: number;
128
+ }
129
+ /**
130
+ * The parsed nameConstraints of one certificate: both subtree sets, the
131
+ * constrained-type mask for the four SUPPORTED forms (BoringSSL
132
+ * `constrained_name_types_`), and — only when the extension is critical —
133
+ * the unsupported-form tags it constrains. The unsupported set is per-FORM
134
+ * tag, never a collapsed marker: the SAN-side check intersects tags
135
+ * independently, exactly the general_names.h bitfield semantics behind
136
+ * name_constraints.cc:450-454 (a critical URI constraint must not reject an
137
+ * otherName SAN).
138
+ */
139
+ export interface NameConstraints {
140
+ readonly permittedSubtrees: GeneralSubtrees;
141
+ readonly excludedSubtrees: GeneralSubtrees;
142
+ readonly constrainedTypes: number;
143
+ /** Unsupported-form tags constrained critically (empty when non-critical). */
144
+ readonly constrainedUnsupportedTags: ReadonlySet<number>;
145
+ readonly isCritical: boolean;
146
+ }
147
+ /**
148
+ * Parse the nameConstraints extnValue content (unwrapped OCTET STRING) — the
149
+ * NameConstraints::Parse twin. Throws the typed certificate-phase error on
150
+ * any fault: BoringSSL runs this for EVERY nameConstraints extension in
151
+ * ParsedCertificate::Create and `kFailedParsingNameConstraints` rejects the
152
+ * certificate ("Failed parsing name constraints"), critical or not.
153
+ */
154
+ export declare function parseNameConstraints(value: Uint8Array, isCritical: boolean): NameConstraints;
155
+ /**
156
+ * WildcardMatchType (name_constraints.cc:54): excluded subtrees use
157
+ * PARTIAL ("*.bar.com" matches constraint "foo.bar.com" — any expansion of
158
+ * the wildcard could land in the excluded subtree); permitted subtrees use
159
+ * FULL ("*.bar.com" matches "bar.com" but not "foo.bar.com" — the constraint
160
+ * must hold for EVERY expansion).
161
+ */
162
+ type WildcardMatchType = "partial" | "full";
163
+ /**
164
+ * DNSNameMatches: does `name` fall in the subtree of `dnsConstraint`?
165
+ *
166
+ * RFC 5280 §4.2.1.10 (quoted in the BoringSSL source): "DNS name restrictions
167
+ * are expressed as host.example.com. Any DNS name that can be constructed by
168
+ * simply adding zero or more labels to the left-hand side of the name
169
+ * satisfies the name constraint. For example, www.host.example.com would
170
+ * satisfy the constraint but host1.example.com would not."
171
+ *
172
+ * Rule by rule (name_constraints.cc:69-122):
173
+ * - the EMPTY constraint matches everything ("Everything matches the empty
174
+ * DNS name constraint");
175
+ * - ONE trailing dot is stripped from name and constraint alike
176
+ * ("Normalize absolute DNS names by removing the trailing dot, if any");
177
+ * - wildcard partial-match: a name "*.<domain>" matches a constraint whose
178
+ * own part after the first dot equals <domain> (exclusions only);
179
+ * - the suffix test is case-insensitive; equal length = exact match;
180
+ * - a constraint with a LEADING dot strips it and then only subdomains
181
+ * match ("foo.bar.com matches constraint .bar.com, but bar.com doesn't");
182
+ * - otherwise the character before the matched suffix must be a label
183
+ * boundary dot ("Trailing text matches, but not in a subtree (e.g.,
184
+ * foobar.com is not a match for bar.com)").
185
+ */
186
+ export declare function dnsNameMatches(name: string, dnsConstraint: string, wildcardMatching: WildcardMatchType): boolean;
187
+ /**
188
+ * Which subtree side a constraint sits on — BoringSSL's Rfc822NameMatchType
189
+ * (name_constraints.cc:227). The polarity decides STRUCTURAL FAULTS of the
190
+ * CONSTRAINT: "In case of parsing errors, return a value that will cause the
191
+ * name to not be permitted" — the fault value is FALSE for a permitted
192
+ * constraint (the fault does not match) and TRUE for an excluded one (the
193
+ * fault MATCHES, so the certificate is rejected — fail closed,
194
+ * name_constraints.cc:232-235).
195
+ */
196
+ export type Rfc822NameMatchType = "permitted" | "excluded";
197
+ /**
198
+ * RFC 5280 §4.2.1.10 mailbox matching: constraint "root@example.com" pins one
199
+ * mailbox; ".example.com" matches every address whose domain ends with
200
+ * ".example.com"; "example.com" matches every address at that host
201
+ * (domain equality). Names with a local-part that uses characters outside the
202
+ * unquoted atext set or more than one "@" never match (IsPermittedRfc822Name's
203
+ * own structure check); CONSTRAINTS with such faults, more than one "@", or a
204
+ * domain with characters outside alnum/-/. resolve to the match-type's fault
205
+ * value (IsAllowedRfc822LocalPart / IsAllowedRfc822Domain: "we don't
206
+ * implement [RFC 2821 mailbox parsing] either, but do something a bit more
207
+ * fail-safe by rejecting any addresses that contain characters that are not
208
+ * allowed in the non-quoted formats").
209
+ */
210
+ export declare function rfc822NameMatches(name: string, rfc822Constraint: string, matchType: Rfc822NameMatchType, caseInsensitiveLocalPart: boolean): boolean;
211
+ /**
212
+ * The discriminated outcome of checking one certificate against one
213
+ * constraint holder (BoringSSL adds kNotPermittedByNameConstraints or
214
+ * kTooManyNameConstraintChecks, both SEVERITY_HIGH): everything else
215
+ * resolves to permitted.
216
+ */
217
+ export type NameConstraintViolation = {
218
+ readonly kind: "excluded";
219
+ readonly form: string;
220
+ readonly name: string;
221
+ } | {
222
+ readonly kind: "not-permitted";
223
+ readonly form: string;
224
+ readonly name: string;
225
+ } | {
226
+ readonly kind: "unsupported-name-form";
227
+ readonly form: string;
228
+ } | {
229
+ readonly kind: "subject-email-unreadable";
230
+ } | {
231
+ readonly kind: "too-many-checks";
232
+ };
233
+ /**
234
+ * IsPermittedCert (name_constraints.cc:375-537): is `subject` — its SANs
235
+ * (`san`, null when the extension is absent) and its subject DN (RDNSequence
236
+ * VALUE bytes) — permitted by `constraints`? `subjectIsTarget` mirrors
237
+ * BoringSSL's `is_target_cert` in the caller's self-issued exemption
238
+ * ("(!IsSelfIssued(cert) || is_target_cert)"): a self-issued NON-target
239
+ * certificate skips the check entirely.
240
+ *
241
+ * Returns undefined (permitted) or the discriminated violation.
242
+ */
243
+ export declare function nameConstraintViolation(constraints: NameConstraints, san: GeneralNames | null, subjectValue: Uint8Array, subjectIsTarget: boolean, isSelfIssued: boolean): NameConstraintViolation | undefined;
244
+ export {};
245
+ //# sourceMappingURL=name-constraints.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"name-constraints.d.ts","sourceRoot":"","sources":["../../src/certificates/name-constraints.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuGG;AAKH,OAAO,EAMH,KAAK,YAAY,EACpB,MAAM,oBAAoB,CAAC;AAiB5B;;;;;;;GAOG;AACH,MAAM,WAAW,eAAe;IAC5B,QAAQ,CAAC,QAAQ,EAAE,SAAS,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