@browsercore/tls 0.4.18 → 0.4.20

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 (69) hide show
  1. package/README.md +291 -6
  2. package/dist/certificates/ca-constraints.d.ts +43 -0
  3. package/dist/certificates/ca-constraints.d.ts.map +1 -0
  4. package/dist/certificates/ca-constraints.js +89 -0
  5. package/dist/certificates/ca-constraints.js.map +1 -0
  6. package/dist/certificates/cert-extensions.d.ts +106 -19
  7. package/dist/certificates/cert-extensions.d.ts.map +1 -1
  8. package/dist/certificates/cert-extensions.js +203 -48
  9. package/dist/certificates/cert-extensions.js.map +1 -1
  10. package/dist/certificates/certificate-path.d.ts +341 -0
  11. package/dist/certificates/certificate-path.d.ts.map +1 -0
  12. package/dist/certificates/certificate-path.js +613 -0
  13. package/dist/certificates/certificate-path.js.map +1 -0
  14. package/dist/certificates/certificates.d.ts +66 -47
  15. package/dist/certificates/certificates.d.ts.map +1 -1
  16. package/dist/certificates/certificates.js +251 -92
  17. package/dist/certificates/certificates.js.map +1 -1
  18. package/dist/certificates/der.d.ts +0 -8
  19. package/dist/certificates/der.d.ts.map +1 -1
  20. package/dist/certificates/der.js +0 -42
  21. package/dist/certificates/der.js.map +1 -1
  22. package/dist/certificates/extension-policy.d.ts +205 -0
  23. package/dist/certificates/extension-policy.d.ts.map +1 -0
  24. package/dist/certificates/extension-policy.js +357 -0
  25. package/dist/certificates/extension-policy.js.map +1 -0
  26. package/dist/certificates/extension-values.d.ts +131 -0
  27. package/dist/certificates/extension-values.d.ts.map +1 -0
  28. package/dist/certificates/extension-values.js +443 -0
  29. package/dist/certificates/extension-values.js.map +1 -0
  30. package/dist/certificates/general-names.d.ts +142 -0
  31. package/dist/certificates/general-names.d.ts.map +1 -0
  32. package/dist/certificates/general-names.js +354 -0
  33. package/dist/certificates/general-names.js.map +1 -0
  34. package/dist/certificates/name-constraints.d.ts +245 -0
  35. package/dist/certificates/name-constraints.d.ts.map +1 -0
  36. package/dist/certificates/name-constraints.js +692 -0
  37. package/dist/certificates/name-constraints.js.map +1 -0
  38. package/dist/certificates/name-match.d.ts +59 -0
  39. package/dist/certificates/name-match.d.ts.map +1 -0
  40. package/dist/certificates/name-match.js +271 -0
  41. package/dist/certificates/name-match.js.map +1 -0
  42. package/dist/certificates/signature-algorithm.d.ts +54 -0
  43. package/dist/certificates/signature-algorithm.d.ts.map +1 -0
  44. package/dist/certificates/signature-algorithm.js +359 -0
  45. package/dist/certificates/signature-algorithm.js.map +1 -0
  46. package/dist/connection/handshake-driver.d.ts +9 -6
  47. package/dist/connection/handshake-driver.d.ts.map +1 -1
  48. package/dist/connection/handshake-driver.js.map +1 -1
  49. package/dist/connection/handshake-messages.d.ts +9 -2
  50. package/dist/connection/handshake-messages.d.ts.map +1 -1
  51. package/dist/connection/handshake-messages.js +57 -23
  52. package/dist/connection/handshake-messages.js.map +1 -1
  53. package/dist/errors.d.ts +100 -0
  54. package/dist/errors.d.ts.map +1 -1
  55. package/dist/errors.js +54 -0
  56. package/dist/errors.js.map +1 -1
  57. package/dist/index.d.ts +8 -5
  58. package/dist/index.d.ts.map +1 -1
  59. package/dist/index.js +5 -3
  60. package/dist/index.js.map +1 -1
  61. package/dist/tls.d.ts +4 -3
  62. package/dist/tls.d.ts.map +1 -1
  63. package/dist/tls.js +4 -3
  64. package/dist/tls.js.map +1 -1
  65. package/dist/types.d.ts +2 -1
  66. package/dist/types.d.ts.map +1 -1
  67. package/dist/types.js +2 -1
  68. package/dist/types.js.map +1 -1
  69. package/package.json +3 -3
@@ -0,0 +1,613 @@
1
+ /**
2
+ * Pure RFC 5280 §6.1 certification-path building and path checks (no I/O).
3
+ *
4
+ * `buildCertificatePath` runs a depth-first search with backtracking from the
5
+ * leaf. At every step the candidates for the current certificate's issuer are
6
+ * tried in order: first the certificate ITSELF as a pinned anchor (identity
7
+ * match, see below), then the trust anchors as issuers, then the remaining
8
+ * server-sent certificates in wire order. A candidate matches when its
9
+ * subject DN equals the current certificate's issuer DN byte-for-byte AND its
10
+ * public key verifies the current certificate's signature; each such
11
+ * verification performed during building IS the chain verification (RFC 5280
12
+ * §6.1.3 (a)), so no pair is ever verified twice.
13
+ *
14
+ * PINNED ANCHORS — matched by identity, never verified: a certificate that is
15
+ * itself an anchor (self-signed, subject DN bytes AND subjectPublicKeyInfo
16
+ * bytes equal to the anchor's) ends the path immediately WITHOUT any
17
+ * signature verification, because there is no issuer edge left to verify —
18
+ * trust rests on the anchor identity, not on the certificate's own signature
19
+ * (old pinned leaves/roots are commonly self-signed with SHA-1 or another
20
+ * rejected algorithm). A NON-self-signed certificate whose ISSUER is an
21
+ * anchor is a real edge and stays signature-verified. A self-signed
22
+ * certificate that merely SHARES the anchor's subject DN but not its SPKI is
23
+ * a name collision: it is not the anchor and has no (real) issuer, so it
24
+ * fails with no-issuer.
25
+ *
26
+ * BACKTRACKING: reaching an anchor completes a candidate path; the path
27
+ * checks below then decide whether it is valid. The FIRST FULLY VALID path
28
+ * (anchored and passing every check) is the result; a candidate whose
29
+ * completed path fails a check is abandoned and the NEXT candidate is tried,
30
+ * so the outcome never depends on the order the server happened to choose
31
+ * (e.g. a cross-signed intermediate sent in a constrained and an unconstrained
32
+ * variant). Termination is unconditional: a certificate is never used twice
33
+ * on one path, and at most {@link MAX_PATH_INTERMEDIATES} intermediates are
34
+ * accepted, so the search visits at most (candidates × path length) states.
35
+ *
36
+ * FAILURE REPORTING: only when every candidate is exhausted is the path
37
+ * reported unanchored, with the failure observed at the DEEPEST search depth —
38
+ * the attempt that got closest to acceptance, where a completed-but-invalid
39
+ * path (anchor edge already added) outranks a dead end at the same prefix —
40
+ * ties resolved by the FIRST attempt recorded at that depth. The message
41
+ * always names the offending certificate.
42
+ *
43
+ * The signature-algorithm policy is deliberately NOT re-checked here — it
44
+ * lives in `validateCertificateChain`'s sweep, which runs in every mode.
45
+ *
46
+ * DN comparison detail: candidate filtering compares the DER byte spans of the
47
+ * candidate's subject and the current certificate's issuer. The signature check
48
+ * is what actually binds issuer to subject — DN equality only selects the
49
+ * candidate set (BoringSSL matches names byte-exactly for the same reason). A
50
+ * false-negative filter (differing encodings of the same DN) yields no-issuer,
51
+ * never a false-accept: nothing is trusted without a verifying signature (or
52
+ * an identity match with a pinned anchor).
53
+ */
54
+ import { TlsCertificateError } from "../errors.js";
55
+ import { assertNever, constantTimeEqual } from "../utils.js";
56
+ import { nameMatchesExact } from "./name-match.js";
57
+ import { nameConstraintViolation, } from "./name-constraints.js";
58
+ import { isCriticalExtensionHandled, serverAuthEkuAcceptable, CERTIFICATE_POLICIES_OID, } from "./extension-policy.js";
59
+ /**
60
+ * Maximum intermediates between the leaf and the anchor. Chrome caps path
61
+ * length the same way; without a limit a degenerate chain (or a hostile
62
+ * server) could make the search walk hundreds of useless entries.
63
+ */
64
+ export const MAX_PATH_INTERMEDIATES = 8;
65
+ /**
66
+ * Verify `subject`'s signature with the candidate issuer's SPKI. Returns false
67
+ * for a `rejected` signature algorithm — there is no TLS scheme to verify
68
+ * with; that policy failure belongs to validateCertificateChain's sweep, and
69
+ * treating it as "cannot verify" keeps this builder total (never throwing).
70
+ */
71
+ function signatureVerifies(subject, issuerSpki, provider) {
72
+ const algorithm = subject.signatureAlgorithm;
73
+ if (algorithm.kind !== "supported") {
74
+ return false;
75
+ }
76
+ return provider.verifySignature(algorithm.scheme, issuerSpki, subject.signatureValue, subject.tbsBytes);
77
+ }
78
+ /**
79
+ * The pinned-anchor identity match: `cert` is itself a trust anchor when it is
80
+ * self-signed AND some anchor has byte-equal subject DN AND byte-equal SPKI.
81
+ * Only identity pins — a same-DN different-key anchor is a collision, not a
82
+ * match.
83
+ */
84
+ function findPinnedAnchor(cert, trustAnchors) {
85
+ if (!cert.selfSigned) {
86
+ return undefined;
87
+ }
88
+ return trustAnchors.find((anchor) => constantTimeEqual(anchor.subjectDn, cert.subjectDn) &&
89
+ constantTimeEqual(anchor.subjectPublicKeyInfo, cert.subjectPublicKeyInfo));
90
+ }
91
+ /**
92
+ * Run the path checks on a completed candidate path (RFC 5280 §6.1.2–§6.1.4,
93
+ * in verifyChain's documented order) WITHOUT throwing; the first failure is
94
+ * returned so the search can record it and backtrack. `anchor` is the trust
95
+ * anchor that completed this path — exempt from all the checks (trusted a
96
+ * priori), including when a pinned anchor sits at the top of the path. The
97
+ * extension-policy checks run AFTER the EKU check to mirror Chrome's
98
+ * per-certificate processing order (EKU in BasicCertificateProcessing, the
99
+ * critical-extension sweep in PrepareForNextCertificate / WrapUp — both after
100
+ * VerifyExtendedKeyUsage).
101
+ */
102
+ function validateBuiltPath(path, anchor, now) {
103
+ return (pathValidityWindowError(path, now) ??
104
+ pathCaConstraintsError(path) ??
105
+ pathLengthConstraintsError(path, anchor) ??
106
+ pathNameConstraintsError(path, anchor) ??
107
+ pathServerAuthEkuError(path, anchor) ??
108
+ pathCriticalExtensionsError(path, anchor));
109
+ }
110
+ /**
111
+ * Build the certification path from the leaf to a trust anchor.
112
+ *
113
+ * Depth-first search with backtracking: candidates are tried anchors-first,
114
+ * then server certificates in wire order; the first FULLY VALID path (reaching
115
+ * an anchor and passing every check) wins; exhausted candidates yield an
116
+ * unanchored result carrying the deepest failure (see the module comment).
117
+ * Unanchored results never throw — the caller decides how to surface them.
118
+ */
119
+ export function buildCertificatePath(chain, trustAnchors, provider, now) {
120
+ /**
121
+ * Extend `path` (whose LAST element is `current` — the invariant the
122
+ * failure records rely on) toward an anchor using `candidates`, never
123
+ * reusing a certificate on one path. Returns the first fully valid
124
+ * completion, or the deepest failure observed in this subtree.
125
+ */
126
+ const extend = (current, path, candidates) => {
127
+ // Each extend() invocation tracks its OWN deepest failure; the parent
128
+ // merges the child's result, so a strictly deeper failure wins and —
129
+ // on equal depth — the attempt that came first in search order.
130
+ let deepestHere;
131
+ const note = (failure) => {
132
+ deepestHere = deepestHere === undefined || failure.depth > deepestHere.depth ? failure : deepestHere;
133
+ return deepestHere;
134
+ };
135
+ // 0. Pinned identity: current IS an anchor — no edge to verify, its
136
+ // own signature algorithm is irrelevant. The completed path must
137
+ // still pass the checks; on failure this route is abandoned like
138
+ // any other (backtracking) and the search continues.
139
+ const pinned = findPinnedAnchor(current, trustAnchors);
140
+ if (pinned !== undefined) {
141
+ const invalid = validateBuiltPath(path, pinned, now);
142
+ if (invalid === undefined) {
143
+ return { outcome: "anchored", anchored: { kind: "anchored", path, anchor: pinned } };
144
+ }
145
+ note({
146
+ reason: invalid.reason,
147
+ message: invalid.message,
148
+ details: invalid.details,
149
+ depth: path.length + 1,
150
+ certificate: current,
151
+ certificateIndex: path.length - 1,
152
+ candidateCount: 0,
153
+ });
154
+ }
155
+ // 1. The trust anchors as ISSUER of current: a real edge, signature
156
+ // verified. Every DN-matching anchor is tried until one yields a
157
+ // fully valid path.
158
+ let anchorDnMatches = 0;
159
+ let anchorSigFailed = 0;
160
+ for (const anchor of trustAnchors) {
161
+ if (!constantTimeEqual(anchor.subjectDn, current.issuerDn)) {
162
+ continue;
163
+ }
164
+ anchorDnMatches++;
165
+ if (!signatureVerifies(current, anchor.subjectPublicKeyInfo, provider)) {
166
+ anchorSigFailed++;
167
+ continue;
168
+ }
169
+ const invalid = validateBuiltPath(path, anchor, now);
170
+ if (invalid === undefined) {
171
+ return { outcome: "anchored", anchored: { kind: "anchored", path, anchor } };
172
+ }
173
+ note({
174
+ reason: invalid.reason,
175
+ message: invalid.message,
176
+ details: invalid.details,
177
+ depth: path.length + 1,
178
+ certificate: current,
179
+ certificateIndex: path.length - 1,
180
+ candidateCount: 0,
181
+ });
182
+ }
183
+ // 2. Server-sent certificates as issuer, in wire order, each used at
184
+ // most once on a path (a cycle cannot re-consume its own entries).
185
+ let intermediateDnMatches = 0;
186
+ let intermediateSigFailed = 0;
187
+ let candidateIndex = 0;
188
+ for (const candidate of candidates) {
189
+ if (constantTimeEqual(candidate.subjectDn, current.issuerDn)) {
190
+ if (!signatureVerifies(current, candidate.subjectPublicKeyInfo, provider)) {
191
+ intermediateDnMatches++;
192
+ intermediateSigFailed++;
193
+ }
194
+ else if (path.length > MAX_PATH_INTERMEDIATES) {
195
+ // The verified issuer would become intermediate number
196
+ // path.length — exceeding the cap abandons this route
197
+ // (recorded, then the next candidate is tried).
198
+ note({
199
+ reason: "path-too-long",
200
+ message: `certificate path exceeds the maximum of ${MAX_PATH_INTERMEDIATES} intermediates: ` +
201
+ `certificate at index ${path.length} (issuer DN "${candidate.issuer}") would add one more`,
202
+ depth: path.length + 1,
203
+ certificate: candidate,
204
+ certificateIndex: path.length,
205
+ candidateCount: 0,
206
+ });
207
+ }
208
+ else {
209
+ const remaining = [...candidates.slice(0, candidateIndex), ...candidates.slice(candidateIndex + 1)];
210
+ const child = extend(candidate, [...path, candidate], remaining);
211
+ if (child.outcome === "anchored") {
212
+ return child;
213
+ }
214
+ // The route through this candidate dead-ended — its
215
+ // deepest failure is merged below; try the next candidate.
216
+ note(child.deepest);
217
+ }
218
+ }
219
+ candidateIndex++;
220
+ }
221
+ // 3. Dead end at this level: record the step failure so it can be
222
+ // reported if no deeper attempt exists. For a SELF-SIGNED current,
223
+ // a DN match on a different key is a name collision, not a failed
224
+ // verification of a real edge — the only legitimate issuer of a
225
+ // self-signed certificate is itself, and it is not the anchor —
226
+ // so that shape reports no-issuer, not bad-signature.
227
+ const dnMatched = anchorDnMatches + intermediateDnMatches > 0;
228
+ const reason = dnMatched && !current.selfSigned ? "bad-signature" : "no-issuer";
229
+ const candidateCount = anchorSigFailed + intermediateSigFailed;
230
+ const message = reason === "bad-signature"
231
+ ? `signature verification failed: certificate at index ${path.length - 1} (issuer DN "${current.issuer}") ` +
232
+ `matched ${candidateCount} candidate issuer(s) by name but none of their public keys verified the signature`
233
+ : `no issuer found for certificate at index ${path.length - 1} (issuer DN "${current.issuer}"): ` +
234
+ `no trust anchor and no remaining server-sent certificate has this subject and verified the signature`;
235
+ // The returned value is this subtree's deepest failure — the note
236
+ // above guarantees it is at least the step failure just recorded.
237
+ const deepest = note({
238
+ reason,
239
+ message,
240
+ depth: path.length,
241
+ certificate: current,
242
+ certificateIndex: path.length - 1,
243
+ candidateCount,
244
+ });
245
+ return { outcome: "exhausted", deepest };
246
+ };
247
+ const result = extend(chain.leaf, [chain.leaf], chain.intermediates);
248
+ if (result.outcome === "anchored") {
249
+ return result.anchored;
250
+ }
251
+ // Every candidate exhausted: report the deepest failure of the search
252
+ // (see the module comment).
253
+ const failure = result.deepest;
254
+ return {
255
+ kind: "unanchored",
256
+ reason: failure.reason,
257
+ message: failure.message,
258
+ details: failure.details,
259
+ certificate: failure.certificate,
260
+ certificateIndex: failure.certificateIndex,
261
+ candidateCount: failure.candidateCount,
262
+ };
263
+ }
264
+ /**
265
+ * Validity window for EVERY certificate on the built path (RFC 5280 §6.1.2
266
+ * (a)/(b) + §6.1.3) — including a pinned leaf: the path's certificates come
267
+ * from the wire, and the wire target's validity is checked unconditionally
268
+ * (BoringSSL's verify_certificate_chain does the same for a directly trusted
269
+ * leaf). The trust anchor itself is never part of the built path when it acts
270
+ * as the ISSUER of the top certificate, so its own expiry is never checked
271
+ * (old roots outlive their notAfter all the time); there is deliberately no
272
+ * object-identity shortcut here — whether the pinned match reuses the same
273
+ * parsed object or a second parse of the same DER, the outcome is identical.
274
+ */
275
+ export function pathValidityWindowError(path, now) {
276
+ for (const [index, cert] of path.entries()) {
277
+ const window = `(valid ${new Date(cert.notBefore * 1000).toISOString()}..${new Date(cert.notAfter * 1000).toISOString()}, now ${new Date(now * 1000).toISOString()})`;
278
+ if (now < cert.notBefore) {
279
+ return {
280
+ reason: "not-yet-valid",
281
+ message: `certificate at index ${index} (issuer DN "${cert.issuer}") is not yet valid ${window}`,
282
+ };
283
+ }
284
+ if (now > cert.notAfter) {
285
+ return {
286
+ reason: "expired",
287
+ message: `certificate at index ${index} (issuer DN "${cert.issuer}") expired ${window}`,
288
+ };
289
+ }
290
+ }
291
+ return undefined;
292
+ }
293
+ /** Throwing wrapper around {@link pathValidityWindowError} (see it for the WHY). */
294
+ export function checkPathValidityWindow(path, now) {
295
+ const failure = pathValidityWindowError(path, now);
296
+ if (failure !== undefined) {
297
+ throw new TlsCertificateError(failure.reason, failure.message);
298
+ }
299
+ }
300
+ /**
301
+ * Issuer-authorization constraints for every intermediate on the built path
302
+ * (RFC 5280 §6.1.3 (k)/(l) + §4.2.1.3): an intermediate must carry
303
+ * basicConstraints cA=TRUE, and when it carries a keyUsage extension, that
304
+ * extension must assert keyCertSign. Absence of the keyUsage EXTENSION is
305
+ * tolerated (RFC 5280 makes it optional); absence of the cA flag is not. The
306
+ * anchor is exempt because it is trusted a priori AND never part of the built
307
+ * path when it acts as the issuer of the top certificate (a legacy root
308
+ * without basicConstraints or keyCertSign must still verify paths under it);
309
+ * a WIRE certificate that merely matches an anchor by DN+SPKI is checked like
310
+ * any other intermediate.
311
+ */
312
+ export function pathCaConstraintsError(path) {
313
+ for (const [index, cert] of path.entries()) {
314
+ if (index === 0) {
315
+ // The leaf is the end-entity — it need not be a CA.
316
+ continue;
317
+ }
318
+ if (!cert.isCa) {
319
+ return {
320
+ reason: "not-a-ca",
321
+ message: `intermediate certificate at index ${index} (issuer DN "${cert.issuer}") is missing basicConstraints cA`,
322
+ };
323
+ }
324
+ if (cert.keyUsagePresent && !cert.keyUsageKeyCertSign) {
325
+ return {
326
+ reason: "missing-key-cert-sign",
327
+ message: `intermediate certificate at index ${index} (issuer DN "${cert.issuer}") carries a keyUsage extension without the keyCertSign bit`,
328
+ };
329
+ }
330
+ }
331
+ return undefined;
332
+ }
333
+ /** Throwing wrapper around {@link pathCaConstraintsError} (see it for the WHY). */
334
+ export function checkPathCaConstraints(path) {
335
+ const failure = pathCaConstraintsError(path);
336
+ if (failure !== undefined) {
337
+ throw new TlsCertificateError(failure.reason, failure.message);
338
+ }
339
+ }
340
+ /**
341
+ * pathLenConstraint along the built path (RFC 5280 §4.2.1.9): a certificate's
342
+ * constraint bounds the number of NON-self-issued intermediates that may
343
+ * FOLLOW it ("below" it, towards the leaf). Every issuer on the path is
344
+ * checked — each intermediate, and the anchor as issuer of the top
345
+ * intermediate (RFC 5280 §6.1.1 (h) seeds max_path_length from the anchor's
346
+ * constraint; the anchor's own status is a priori trusted, but its constraint
347
+ * is a delegation LIMIT on the certificates below it). RFC 5280 counts
348
+ * non-self-issued certificates only; our `selfSigned` flag (subject DN bytes
349
+ * equal issuer DN bytes) is exactly the subject==issuer test. The counting
350
+ * loop skips `anchor` by POSITION (the certificate in anchor position is the
351
+ * issuer, never one of the intermediates it constrains) — a WIRE certificate
352
+ * that merely matches the anchor by DN+SPKI is counted like any other
353
+ * intermediate, so the outcome does not depend on whether the pinned match
354
+ * reused the same parsed object.
355
+ */
356
+ export function pathLengthConstraintsError(path, anchor) {
357
+ // Non-self-issued intermediates BELOW the issuer currently being checked.
358
+ let nonSelfIssuedBelow = 0;
359
+ let index = 0;
360
+ for (const issuer of path) {
361
+ if (index >= 1 && issuer !== anchor) {
362
+ if (issuer.pathLenConstraint !== null && nonSelfIssuedBelow > issuer.pathLenConstraint) {
363
+ return {
364
+ reason: "path-too-long",
365
+ message: `pathLenConstraint violated at certificate index ${index} (issuer DN "${issuer.issuer}"): ` +
366
+ `${nonSelfIssuedBelow} non-self-issued intermediate(s) below it exceed the limit of ${issuer.pathLenConstraint}`,
367
+ };
368
+ }
369
+ // This certificate sits BELOW the next issuer up the path — count it.
370
+ if (!issuer.selfSigned) {
371
+ nonSelfIssuedBelow++;
372
+ }
373
+ }
374
+ index++;
375
+ }
376
+ if (anchor.pathLenConstraint !== null && nonSelfIssuedBelow > anchor.pathLenConstraint) {
377
+ return {
378
+ reason: "path-too-long",
379
+ message: `pathLenConstraint violated at the trust anchor (issuer DN "${anchor.issuer}"): ` +
380
+ `${nonSelfIssuedBelow} non-self-issued intermediate(s) below it exceed the limit of ${anchor.pathLenConstraint}`,
381
+ };
382
+ }
383
+ return undefined;
384
+ }
385
+ /** Throwing wrapper around {@link pathLengthConstraintsError} (see it for the WHY). */
386
+ export function checkPathLengthConstraints(path, anchor) {
387
+ const failure = pathLengthConstraintsError(path, anchor);
388
+ if (failure !== undefined) {
389
+ throw new TlsCertificateError(failure.reason, failure.message);
390
+ }
391
+ }
392
+ /**
393
+ * Render a BoringSSL name-constraint outcome into the diagnostic that names
394
+ * the constrained certificate, the constraint holder and the offending name,
395
+ * with the excluded / not-permitted distinction carried verbatim (BoringSSL
396
+ * reports both through kNotPermittedByNameConstraints / kTooManyName
397
+ * ConstraintChecks; the sub-kind is this verifier's added detail).
398
+ */
399
+ function nameConstraintViolationMessage(subjectIndex, subject, holderDescription, violation) {
400
+ const subjectName = `certificate at index ${subjectIndex} (issuer DN "${subject.issuer}")`;
401
+ switch (violation.kind) {
402
+ case "excluded":
403
+ return (`${subjectName} violates the name constraints of ${holderDescription}: ` +
404
+ `${violation.form} "${violation.name}" matches an excludedSubtrees entry`);
405
+ case "not-permitted":
406
+ return (`${subjectName} violates the name constraints of ${holderDescription}: ` +
407
+ `${violation.form} "${violation.name}" matches no permittedSubtrees entry`);
408
+ case "unsupported-name-form":
409
+ return (`${subjectName} violates the name constraints of ${holderDescription}: ` +
410
+ `its subjectAltName carries a ${violation.form} constrained by a CRITICAL nameConstraints extension — ` +
411
+ "RFC 5280 §4.2.1.10 requires processing the constraint or rejecting the certificate");
412
+ case "subject-email-unreadable":
413
+ return (`${subjectName} violates the name constraints of ${holderDescription}: ` +
414
+ "its subject (no subjectAltName present) carries an emailAddress attribute that cannot be parsed under an rfc822Name constraint");
415
+ case "too-many-checks":
416
+ return (`${subjectName} violates the name constraints of ${holderDescription}: ` +
417
+ "the name × constraint combinations exceed the 2^20 DoS limit (kTooManyNameConstraintChecks)");
418
+ default:
419
+ // The union is exhausted; assertNever keeps it that way at
420
+ // compile time (code-standards §15).
421
+ return assertNever(violation);
422
+ }
423
+ }
424
+ /**
425
+ * nameConstraints enforcement along the built path (RFC 5280 §4.2.1.10,
426
+ * BoringSSL `NameConstraints::IsPermittedCert` driven from
427
+ * verify_certificate_chain.cc): the constraints of every certificate ABOVE a
428
+ * path certificate apply to it — the trust anchor's included, because this
429
+ * verifier's anchors are caller-supplied, exactly Chrome's
430
+ * `additional_trust_anchors_with_constraints` which Chromium's
431
+ * net/cert/cert_verify_proc_builtin.cc arms with
432
+ * `WithEnforceAnchorConstraints` —
433
+ * and NEVER the constraints of the certificate itself (BoringSSL accumulates
434
+ * `name_constraints_list_` in PrepareForNextCertificate and checks the NEXT
435
+ * certificates against it; the root's own name is never checked — "Don't do
436
+ * any other checks for root certificates"). A SELF-ISSUED non-target
437
+ * certificate skips the check ("If certificate i is self-issued and it is
438
+ * not the final certificate in the path, skip this step for certificate i" —
439
+ * verify_certificate_chain.cc:1176-1178; self-issued = normalized subject
440
+ * equals normalized issuer, IsSelfIssued at :132-134).
441
+ *
442
+ * Checking order mirrors BoringSSL's list: the anchor's constraints first
443
+ * (ApplyTrustAnchorConstraints pushes them at the root step), then the
444
+ * intermediates top-down. Runs ONLY from the anchor-supplied path builder —
445
+ * hostname-only mode never sees it.
446
+ */
447
+ export function pathNameConstraintsError(path, anchor) {
448
+ for (const [subjectIndex, subject] of path.entries()) {
449
+ // The anchor certificate is exempt from being CHECKED (trusted a
450
+ // priori; BoringSSL's verification loop `continue`s past the root) —
451
+ // including when it sits ON the path as a pinned identity match.
452
+ if (isAnchorOnPath(subject, anchor)) {
453
+ continue;
454
+ }
455
+ const subjectIsTarget = subjectIndex === 0;
456
+ // IsSelfIssued (verify_certificate_chain.cc:132-134): normalized
457
+ // subject == normalized issuer. The exact-match name comparator is
458
+ // that test (see name-match.ts for the equivalence argument).
459
+ const selfIssued = nameMatchesExact(subject.subjectNameValue, subject.issuerNameValue);
460
+ // Constraint holders ABOVE the subject, in BoringSSL's list order:
461
+ // the anchor (when it is not itself the pinned top-of-path entry —
462
+ // that entry is covered by the path sweep below), then the path
463
+ // certificates from the top down to the one just above the subject.
464
+ const anchorIsOnPath = path.some((cert) => isAnchorOnPath(cert, anchor));
465
+ const holders = [
466
+ ...(anchorIsOnPath || anchor.nameConstraints === null
467
+ ? []
468
+ : [{ description: `the trust anchor (issuer DN "${anchor.issuer}")`, constraints: anchor.nameConstraints }]),
469
+ ...path
470
+ .slice(subjectIndex + 1)
471
+ .toReversed()
472
+ .filter((holder) => holder.nameConstraints !== null)
473
+ .map((holder) => ({
474
+ description: `certificate at index ${path.indexOf(holder)} (issuer DN "${holder.issuer}")`,
475
+ constraints: holder.nameConstraints,
476
+ })),
477
+ ];
478
+ for (const holder of holders) {
479
+ const violation = nameConstraintViolation(holder.constraints, subject.sanNames, subject.subjectNameValue, subjectIsTarget, selfIssued);
480
+ if (violation !== undefined) {
481
+ return {
482
+ reason: "name-constraint-violation",
483
+ message: nameConstraintViolationMessage(subjectIndex, subject, holder.description, violation),
484
+ // The discriminated BoringSSL outcome rides in the thrown
485
+ // error's `details.nameConstraint` (see
486
+ // TlsCertificateError) — the caller-matchable form of the
487
+ // message text.
488
+ details: { nameConstraint: violation },
489
+ };
490
+ }
491
+ }
492
+ }
493
+ return undefined;
494
+ }
495
+ /** Throwing wrapper around {@link pathNameConstraintsError} (see it for the WHY). */
496
+ export function checkPathNameConstraints(path, anchor) {
497
+ const failure = pathNameConstraintsError(path, anchor);
498
+ if (failure !== undefined) {
499
+ throw new TlsCertificateError(failure.reason, failure.message, failure.details === undefined ? undefined : { details: failure.details });
500
+ }
501
+ }
502
+ /**
503
+ * Whether `cert` IS the trust anchor on a completed path — the pinned identity
504
+ * match (self-signed, subject DN bytes AND SPKI bytes equal to the anchor's),
505
+ * exactly {@link findPinnedAnchor}'s rule. Only the anchor can sit ON a built
506
+ * path this way: when an anchor acts as the ISSUER of the top certificate it
507
+ * is never part of `path`, and any intermediate that matched an anchor by
508
+ * identity would have ended the path at that point. BoringSSL exempts the
509
+ * root the same way: ProcessRootCertificate runs and then `continue`s —
510
+ * "Don't do any other checks for root certificates" — so the trust anchor is
511
+ * never EKU- or critical-extension-checked (unless anchor-constraint
512
+ * enforcement is switched on, which Chrome does not do for root-store
513
+ * anchors).
514
+ */
515
+ function isAnchorOnPath(cert, anchor) {
516
+ return (cert.selfSigned &&
517
+ constantTimeEqual(anchor.subjectDn, cert.subjectDn) &&
518
+ constantTimeEqual(anchor.subjectPublicKeyInfo, cert.subjectPublicKeyInfo));
519
+ }
520
+ /**
521
+ * extendedKeyUsage as Chrome 140 enforces it (RFC 5280 §4.2.1.12, BoringSSL
522
+ * `VerifyExtendedKeyUsage` with KeyPurpose::SERVER_AUTH — the value
523
+ * cert_verify_proc_builtin.cc passes for every TLS-server verification): every
524
+ * certificate on the built path that carries an EKU extension must include
525
+ * id-kp-serverAuth (1.3.6.1.5.5.7.3.1) or anyExtendedKeyUsage (2.5.29.37.0);
526
+ * the deciding SERVER_AUTH error is `kEkuLacksServerAuth`, raised by "if
527
+ * (cert.has_extended_key_usage() && !has_server_auth_eku && !has_any_eku)" for
528
+ * the target and for EVERY issuer alike ("Legacy compatible" branch). A
529
+ * MISSING extension is accepted (leaf: only the kEkuNotPresent warning;
530
+ * intermediates: "At this time … some intermediates are lacking EKU in the
531
+ * world at large from common CA's, so we allow the noEKU case to permit
532
+ * everything."), and an EMPTY EKU sequence is present-but-permitting-nothing,
533
+ * so it fails. Code-signing/time-stamping/OCSP-signing EKUs alongside
534
+ * serverAuth are only warnings in this mode (`add_error_if_strict` → warning).
535
+ * The anchor is exempt (see {@link isAnchorOnPath}).
536
+ */
537
+ export function pathServerAuthEkuError(path, anchor) {
538
+ for (const [index, cert] of path.entries()) {
539
+ if (isAnchorOnPath(cert, anchor)) {
540
+ continue;
541
+ }
542
+ if (!cert.extendedKeyUsagePresent) {
543
+ continue;
544
+ }
545
+ if (serverAuthEkuAcceptable(cert.extendedKeyUsage)) {
546
+ continue;
547
+ }
548
+ return {
549
+ reason: "missing-server-auth-eku",
550
+ message: `certificate at index ${index} (issuer DN "${cert.issuer}") carries an extendedKeyUsage ` +
551
+ `extension without id-kp-serverAuth (1.3.6.1.5.5.7.3.1) or anyExtendedKeyUsage (2.5.29.37.0): ` +
552
+ `not usable for TLS server authentication`,
553
+ };
554
+ }
555
+ return undefined;
556
+ }
557
+ /** Throwing wrapper around {@link pathServerAuthEkuError} (see it for the WHY). */
558
+ export function checkPathServerAuthEku(path, anchor) {
559
+ const failure = pathServerAuthEkuError(path, anchor);
560
+ if (failure !== undefined) {
561
+ throw new TlsCertificateError(failure.reason, failure.message);
562
+ }
563
+ }
564
+ /**
565
+ * Unrecognized critical extensions on the built path (RFC 5280 §4.2: "A
566
+ * certificate-using system MUST reject the certificate if it encounters a
567
+ * critical extension it does not recognize or a critical extension that
568
+ * contains information that it cannot process."), applied exactly like
569
+ * Chrome's built-in verifier: BoringSSL's `VerifyNoUnconsumedCriticalExtensions`
570
+ * runs for the target certificate (WrapUp) and for every intermediate
571
+ * (PrepareForNextCertificate), but NOT for the trust anchor ("Don't do any
572
+ * other checks for root certificates" in the verification loop; the anchor is
573
+ * only checked when trust-anchor CONSTRAINT enforcement is enabled, which
574
+ * Chrome does not do by default) — hence the {@link isAnchorOnPath} exemption.
575
+ * The recognized set is decided by extension-policy.ts
576
+ * ({@link isCriticalExtensionHandled}); nameConstraints (2.5.29.30) is in the
577
+ * recognized set because its constraints are now PROCESSED (see
578
+ * {@link pathNameConstraintsError}) — BoringSSL's IsHandledCriticalExtension
579
+ * accepts it for the same reason.
580
+ */
581
+ export function pathCriticalExtensionsError(path, anchor) {
582
+ for (const [index, cert] of path.entries()) {
583
+ if (isAnchorOnPath(cert, anchor)) {
584
+ continue;
585
+ }
586
+ for (const ext of cert.extensions) {
587
+ if (!ext.critical) {
588
+ continue;
589
+ }
590
+ if (isCriticalExtensionHandled(ext.oid, ext.value, cert.extendedKeyUsagePresent)) {
591
+ continue;
592
+ }
593
+ const note = ext.oid === CERTIFICATE_POLICIES_OID
594
+ ? " (critical certificatePolicies must parse with only CPS or userNotice qualifiers — BoringSSL IsHandledCriticalExtension)"
595
+ : "";
596
+ return {
597
+ reason: "unsupported-critical-extension",
598
+ message: `certificate at index ${index} (issuer DN "${cert.issuer}") carries an unrecognized ` +
599
+ `critical extension (OID ${ext.oid}): RFC 5280 §4.2 requires rejecting critical ` +
600
+ `extensions that cannot be processed${note}`,
601
+ };
602
+ }
603
+ }
604
+ return undefined;
605
+ }
606
+ /** Throwing wrapper around {@link pathCriticalExtensionsError} (see it for the WHY). */
607
+ export function checkPathCriticalExtensions(path, anchor) {
608
+ const failure = pathCriticalExtensionsError(path, anchor);
609
+ if (failure !== undefined) {
610
+ throw new TlsCertificateError(failure.reason, failure.message);
611
+ }
612
+ }
613
+ //# sourceMappingURL=certificate-path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"certificate-path.js","sourceRoot":"","sources":["../../src/certificates/certificate-path.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AAGH,OAAO,EAAE,mBAAmB,EAAiC,MAAM,cAAc,CAAC;AAClF,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAE7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EACH,uBAAuB,GAG1B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACH,0BAA0B,EAC1B,uBAAuB,EACvB,wBAAwB,GAC3B,MAAM,uBAAuB,CAAC;AAkH/B;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAmFxC;;;;;GAKG;AACH,SAAS,iBAAiB,CACtB,OAA0B,EAC1B,UAAsB,EACtB,QAAwB;IAExB,MAAM,SAAS,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAC7C,IAAI,SAAS,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;QACjC,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,OAAO,QAAQ,CAAC,eAAe,CAAC,SAAS,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,cAAc,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;AAC5G,CAAC;AAED;;;;;GAKG;AACH,SAAS,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