@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.
- package/README.md +140 -23
- package/dist/certificates/ca-constraints.d.ts +15 -13
- package/dist/certificates/ca-constraints.d.ts.map +1 -1
- package/dist/certificates/ca-constraints.js +41 -59
- package/dist/certificates/ca-constraints.js.map +1 -1
- package/dist/certificates/cert-extensions.d.ts +59 -9
- package/dist/certificates/cert-extensions.d.ts.map +1 -1
- package/dist/certificates/cert-extensions.js +104 -50
- package/dist/certificates/cert-extensions.js.map +1 -1
- package/dist/certificates/certificate-path.d.ts +66 -7
- package/dist/certificates/certificate-path.d.ts.map +1 -1
- package/dist/certificates/certificate-path.js +125 -11
- package/dist/certificates/certificate-path.js.map +1 -1
- package/dist/certificates/certificates.d.ts.map +1 -1
- package/dist/certificates/certificates.js +107 -29
- package/dist/certificates/certificates.js.map +1 -1
- package/dist/certificates/extension-policy.d.ts +16 -6
- package/dist/certificates/extension-policy.d.ts.map +1 -1
- package/dist/certificates/extension-policy.js +17 -6
- package/dist/certificates/extension-policy.js.map +1 -1
- package/dist/certificates/extension-values.d.ts +131 -0
- package/dist/certificates/extension-values.d.ts.map +1 -0
- package/dist/certificates/extension-values.js +443 -0
- package/dist/certificates/extension-values.js.map +1 -0
- package/dist/certificates/general-names.d.ts +142 -0
- package/dist/certificates/general-names.d.ts.map +1 -0
- package/dist/certificates/general-names.js +354 -0
- package/dist/certificates/general-names.js.map +1 -0
- package/dist/certificates/name-constraints.d.ts +245 -0
- package/dist/certificates/name-constraints.d.ts.map +1 -0
- package/dist/certificates/name-constraints.js +692 -0
- package/dist/certificates/name-constraints.js.map +1 -0
- package/dist/certificates/name-match.d.ts +59 -0
- package/dist/certificates/name-match.d.ts.map +1 -0
- package/dist/certificates/name-match.js +271 -0
- package/dist/certificates/name-match.js.map +1 -0
- package/dist/errors.d.ts +61 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +48 -0
- package/dist/errors.js.map +1 -1
- package/dist/handshake/client-hello.d.ts +16 -2
- package/dist/handshake/client-hello.d.ts.map +1 -1
- package/dist/handshake/client-hello.js +38 -5
- package/dist/handshake/client-hello.js.map +1 -1
- package/dist/handshake/handshake.d.ts +1 -1
- package/dist/handshake/handshake.d.ts.map +1 -1
- package/dist/handshake/handshake.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/session/binder.d.ts +76 -0
- package/dist/session/binder.d.ts.map +1 -0
- package/dist/session/binder.js +107 -0
- package/dist/session/binder.js.map +1 -0
- package/dist/session/psk-extension.d.ts +49 -0
- package/dist/session/psk-extension.d.ts.map +1 -0
- package/dist/session/psk-extension.js +96 -0
- package/dist/session/psk-extension.js.map +1 -0
- package/dist/session/psk-offer.d.ts +52 -0
- package/dist/session/psk-offer.d.ts.map +1 -0
- package/dist/session/psk-offer.js +62 -0
- package/dist/session/psk-offer.js.map +1 -0
- package/dist/types.d.ts +28 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -64,6 +64,7 @@ await tls.close();
|
|
|
64
64
|
| `ProtocolVersion` | discriminated union | `TLS 1.2` / `TLS 1.3` with wire codes |
|
|
65
65
|
| `CipherSuite` | string-literal union | Negotiated AEAD + hash |
|
|
66
66
|
| `ClientHelloConfig` | interface | ClientHello configuration (placeholder for @browsercore/profiles) |
|
|
67
|
+
| `PskIdentity` | interface | Wire-ready PSK identity consumed by `buildClientHello`'s optional `psk` parameter: verbatim ticket bytes, `obfuscatedTicketAge` (u32), the resumption PSK (binder input, never on the wire), and the TICKET suite's hash (sizes the binder). Emitted as the `pre_shared_key` extension — always the LAST ClientHello extension, after the trailing GREASE (RFC 8446 §4.2.11) |
|
|
67
68
|
| `TlsProfile` | interface | Named, reusable ClientHello config |
|
|
68
69
|
| `resolveProfile()` | function | Look up a profile by name and fill in serverName |
|
|
69
70
|
| `TlsError` | class | Base typed error |
|
|
@@ -230,7 +231,9 @@ Exactly what is checked, and when:
|
|
|
230
231
|
Usage is NOT processed for end-entity certificates … however it is
|
|
231
232
|
considered 'handled' here in order to allow being marked as critical"),
|
|
232
233
|
extendedKeyUsage (2.5.29.37, processed — rule 7), subjectAltName
|
|
233
|
-
(2.5.29.17, processed — the hostname check),
|
|
234
|
+
(2.5.29.17, processed — the hostname check), nameConstraints (2.5.29.30,
|
|
235
|
+
processed — rule 9; BoringSSL's branch is unconditional `return true`
|
|
236
|
+
BECAUSE it processes the constraints), policyMappings (2.5.29.33),
|
|
234
237
|
policyConstraints (2.5.29.36) and inhibitAnyPolicy (2.5.29.54) (accepted
|
|
235
238
|
like BoringSSL's unconditional `return true`; policy ENFORCEMENT is a
|
|
236
239
|
documented limitation below), certificatePolicies (2.5.29.32) when the
|
|
@@ -255,33 +258,104 @@ Exactly what is checked, and when:
|
|
|
255
258
|
rejected, and a present-but-malformed EKU value rejected
|
|
256
259
|
(`kFailedParsingEku`).
|
|
257
260
|
|
|
261
|
+
9. **nameConstraints (RFC 5280 §4.2.1.10)** — on the built path, processed
|
|
262
|
+
EXACTLY as BoringSSL pki/name_constraints.cc processes it for TLS server
|
|
263
|
+
authentication at the pinned revision. The extension VALUE is parsed for
|
|
264
|
+
EVERY certificate carrying it, critical or not (`kFailedParsingName
|
|
265
|
+
Constraints` rejects the certificate): the extnValue is one SEQUENCE {
|
|
266
|
+
permittedSubtrees [0] OPTIONAL, excludedSubtrees [1] OPTIONAL }, at least
|
|
267
|
+
one side present ("Conforming CAs MUST NOT issue certificates where name
|
|
268
|
+
constraints is an empty sequence"), each side SEQUENCE SIZE (1..MAX) OF
|
|
269
|
+
GeneralSubtree { base } with NO minimum/maximum (name_constraints.cc
|
|
270
|
+
179-181 rejects any element after the base — including an explicitly
|
|
271
|
+
encoded DEFAULT minimum), an iPAddress base of exactly 8 or 32 octets with
|
|
272
|
+
a contiguous-ones CIDR netmask, ASCII dNSName/rfc822Name bases, and no
|
|
273
|
+
unknown GeneralName tag. CONSTRAINTS apply to every certificate BELOW the
|
|
274
|
+
carrier — the trust anchor's included (Chrome arms caller-supplied
|
|
275
|
+
constrained anchors with `.WithEnforceAnchorConstraints()`) and never the
|
|
276
|
+
carrier itself ("Don't do any other checks for root certificates";
|
|
277
|
+
name_constraints_list_ is consumed by the NEXT certificates). A
|
|
278
|
+
SELF-ISSUED non-target certificate is skipped ("If certificate i is
|
|
279
|
+
self-issued and it is not the final certificate in the path, skip this
|
|
280
|
+
step for certificate i"). The per-name rules: dNSName suffix matching,
|
|
281
|
+
case-insensitive, label-boundary enforced ("foobar.com is not a match for
|
|
282
|
+
bar.com"), a leading-dot constraint permits SUBDOMAINS ONLY ("foo.bar.com
|
|
283
|
+
matches constraint .bar.com, but bar.com doesn't"), one trailing dot
|
|
284
|
+
stripped from BOTH sides, the EMPTY constraint matches everything,
|
|
285
|
+
wildcards are literal strings with BoringSSL's two special cases
|
|
286
|
+
(exclusions: "*.bar.com" matches constraint "foo.bar.com" — any expansion;
|
|
287
|
+
permissions: it matches only a constraint matching EVERY expansion);
|
|
288
|
+
iPAddress by netmask with no cross-family matching (an IPv6 SAN under
|
|
289
|
+
IPv4-only permitted subtrees is not permitted); directoryName by
|
|
290
|
+
RFC 5280 §7.1 subtree match (prefix-of-RDNs-in-order, per-attribute
|
|
291
|
+
normalization — verify_name_match.cc) applied to SAN directoryNames AND
|
|
292
|
+
the subject DN (unless the subject is empty with a SAN — RFC 5280 §4.1.2.6);
|
|
293
|
+
rfc822Name mailbox/domain forms plus the subject's emailAddress attributes
|
|
294
|
+
when NO SAN exists (RFC 5280 §4.2.1.10 legacy rule). commonName is NEVER
|
|
295
|
+
consulted: "this method does not check hostname or IP address in
|
|
296
|
+
commonName, which is deprecated (crbug.com/308330)"
|
|
297
|
+
(name_constraints.h:59-60) — and there is NO empty-SAN rejection rule at
|
|
298
|
+
the pinned revision (every check iterates the names actually present).
|
|
299
|
+
Constraints on forms BoringSSL does not process (URI, otherName,
|
|
300
|
+
x400Address, ediPartyName, registeredID) are ignored when the extension is
|
|
301
|
+
NON-critical (`constrained_name_types_ & kSupportedNameTypes` mask) and —
|
|
302
|
+
when critical — reject any certificate whose SAN carries that form
|
|
303
|
+
(name_constraints.cc:450-454, RFC 5280's MUST-process-or-reject). A DoS
|
|
304
|
+
ceiling caps name × constraint combinations at 2^20
|
|
305
|
+
(`kMaxChecks = 1048576`). Violations fail with
|
|
306
|
+
`name-constraint-violation`, naming the constrained certificate (wire
|
|
307
|
+
index + issuer DN), the constraint holder, the offending name and whether
|
|
308
|
+
it matched an excludedSubtrees entry or no permittedSubtrees entry.
|
|
309
|
+
|
|
310
|
+
10. **Malformed NON-critical extension values are rejected (Part B parity)** —
|
|
311
|
+
BoringSSL's ParsedCertificate::Create parses the VALUE of basic
|
|
312
|
+
Constraints, keyUsage, extendedKeyUsage, subjectAltName, nameConstraints,
|
|
313
|
+
authorityInfoAccess, certificatePolicies, policyConstraints,
|
|
314
|
+
policyMappings, inhibitAnyPolicy, subjectKeyIdentifier and
|
|
315
|
+
authorityKeyIdentifier at certificate-parse time — critical or NOT — and
|
|
316
|
+
rejects the whole certificate on a malformed value (`kFailedParsing…`).
|
|
317
|
+
This verifier does the same with a typed `TlsMalformedExtensionError`
|
|
318
|
+
naming the extension OID. Faults per extension follow BoringSSL exactly
|
|
319
|
+
(e.g. an empty AIA list, an empty certificatePolicies sequence, duplicate
|
|
320
|
+
policy OIDs, qualifiers under anyPolicy restricted to CPS/userNotice —
|
|
321
|
+
unknown qualifier OIDs under OTHER policies are TOLERATED at parse time —
|
|
322
|
+
an empty policyConstraints sequence, an inhibitAnyPolicy that is not one
|
|
323
|
+
uint8 INTEGER, an authorityKeyIdentifier with only one of [1]/[2]);
|
|
324
|
+
explicitly-encoded cA=FALSE in basicConstraints is tolerated (BoringSSL's
|
|
325
|
+
own TODO — real certificates use the broken encoding), and an EMPTY
|
|
326
|
+
AuthorityKeyIdentifier SEQUENCE is legal. cRLDistributionPoints is
|
|
327
|
+
deliberately NOT value-parsed: `ParseCrlDistributionPoints` has no caller
|
|
328
|
+
in the parse path at the pinned revision, so a malformed value does not
|
|
329
|
+
reject the certificate in Chrome — and does not here.
|
|
330
|
+
|
|
258
331
|
Every certificate-phase failure is a `TlsCertificateError` (a
|
|
259
332
|
`TlsHandshakeError` with phase `"certificate"`) carrying a discriminated
|
|
260
333
|
`reason`: `no-anchors` (verifyChain called with an empty anchor list — never a
|
|
261
334
|
vacuous success), `no-issuer`, `bad-signature`, `expired`, `not-yet-valid`,
|
|
262
335
|
`not-a-ca`, `missing-key-cert-sign`, `path-too-long`,
|
|
263
|
-
`unsupported-critical-extension`, `missing-server-auth-eku
|
|
264
|
-
the offending certificate (wire
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
336
|
+
`unsupported-critical-extension`, `missing-server-auth-eku`,
|
|
337
|
+
`name-constraint-violation`. The message names the offending certificate (wire
|
|
338
|
+
index + issuer DN — and, for the extension, EKU and name-constraint failures,
|
|
339
|
+
the offending OID / offending name) so an operator can identify it without
|
|
340
|
+
re-running the handshake. A malformed extension VALUE at PARSE time throws a
|
|
341
|
+
`TlsMalformedExtensionError` (a `TlsHandshakeError` subclass with phase
|
|
342
|
+
"certificate" carrying the `extensionOid`).
|
|
343
|
+
|
|
344
|
+
Explicit limitations — current scope, tracked as separate follow-up subsets
|
|
269
345
|
(not permanent design decisions): no revocation checking of any kind (no
|
|
270
|
-
CRL, no OCSP — neither stapled nor fetched);
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
issuer/subject encodings differ for the same DN (rare; real CAs copy the DER
|
|
284
|
-
bytes) fails with `no-issuer` rather than being leniently matched, and the
|
|
346
|
+
CRL, no OCSP — neither stapled nor fetched); no AIA fetching; no policy
|
|
347
|
+
constraints / policy mappings / certificate-policies ENFORCEMENT (the
|
|
348
|
+
critical-acceptance of those OIDs mirrors BoringSSL's parseability bar and the
|
|
349
|
+
values are parsed per rule 10 — but the policy GRAPH is not evaluated, exactly
|
|
350
|
+
like BoringSSL's own policy processing which this verifier does not implement;
|
|
351
|
+
under Chrome's SERVER_AUTH verification the initial policy set is {anyPolicy},
|
|
352
|
+
so these cannot make Chrome reject a path this verifier would accept); no
|
|
353
|
+
IP-address SAN matching for the HOSTNAME check (name-constraint iPAddress
|
|
354
|
+
checking IS implemented — rule 9). Additionally, DN comparison for path
|
|
355
|
+
BUILDING is byte-exact: a path whose issuer/subject encodings differ for the
|
|
356
|
+
same DN (rare; real CAs copy the DER bytes) fails with `no-issuer` rather than
|
|
357
|
+
being leniently matched (the name-constraint DN matcher, by contrast, is
|
|
358
|
+
BoringSSL's normalized per-attribute comparison — rule 9), and the
|
|
285
359
|
inner/outer AlgorithmIdentifier equality of RFC 5280 §4.1.2.2 is not enforced
|
|
286
360
|
(the TBSCertificate identifier is authoritative).
|
|
287
361
|
|
|
@@ -372,10 +446,53 @@ the next batch: `@browsercore/quic` stops importing `@browsercore/tls`
|
|
|
372
446
|
directly and receives the engine via injection, exactly like crypto/transport
|
|
373
447
|
(no-hard-wires invariant).
|
|
374
448
|
|
|
449
|
+
## Session resumption offer (wire level)
|
|
450
|
+
|
|
451
|
+
`buildClientHello` takes an optional `psk` argument (`PskIdentity`) that turns
|
|
452
|
+
the ClientHello into a TLS 1.3 resumption offer (RFC 8446 §4.2.11). The caller
|
|
453
|
+
supplies the identity: the ticket bytes verbatim, the ticket's resumption PSK
|
|
454
|
+
(the binder input — it never crosses the wire), the hash of the TICKET's
|
|
455
|
+
cipher suite (it sizes the binder), and the `obfuscatedTicketAge` u32. The
|
|
456
|
+
`src/session/` helpers (package-internal) cover the rest of the caller's job:
|
|
457
|
+
`mayOfferTicket` gates the offer on the ticket's suite being among the offered
|
|
458
|
+
suites, `obfuscatedTicketAge` computes the u32 age
|
|
459
|
+
(`(nowMs − receivedAt + ticketAgeAdd) mod 2^32`), and `buildPskIdentity`
|
|
460
|
+
converts a stored ticket into the wire-ready identity.
|
|
461
|
+
|
|
462
|
+
On the wire, a PSK-offering ClientHello carries:
|
|
463
|
+
|
|
464
|
+
- `psk_key_exchange_modes` with the single `psk_dhe_ke` value;
|
|
465
|
+
- `pre_shared_key` as the last extension — after the trailing GREASE and the
|
|
466
|
+
padding extension — with ONE identity (`ticket<16>` +
|
|
467
|
+
`obfuscated_ticket_age` u32) and ONE zero-placeholder binder sized by the
|
|
468
|
+
ticket hash. The padding probe counts the PSK bytes, and servers reject a
|
|
469
|
+
`pre_shared_key` that is not last with `illegal_parameter`.
|
|
470
|
+
- the placeholder binder is then computed (`computePskBinder`,
|
|
471
|
+
RFC 8446 §4.2.11.2) as `HMAC(finished_key, Hash(transcript ‖ truncated
|
|
472
|
+
ClientHello))`, keyed through `HKDF-Extract(0, psk)` → `"res binder"` →
|
|
473
|
+
`"finished"`, and patched over the last `Hash.length` bytes of the message
|
|
474
|
+
(`truncateClientHelloForBinder` + `patchPskBinder`).
|
|
475
|
+
|
|
476
|
+
Invalid inputs fail with the typed `TlsPskError`: a ticket outside the u16
|
|
477
|
+
identity range, a binder longer than the ClientHello, or a ClientHello
|
|
478
|
+
shorter than the binder tail. Without the `psk` argument no `pre_shared_key`
|
|
479
|
+
extension is emitted and the ClientHello is byte-identical to the
|
|
480
|
+
non-resuming build.
|
|
481
|
+
|
|
375
482
|
## Not implemented
|
|
376
483
|
|
|
377
|
-
-
|
|
484
|
+
- Session resumption from `connectTls` — no connection offers a PSK. The
|
|
485
|
+
connection does receive and store tickets: NewSessionTicket post-handshake
|
|
486
|
+
messages are parsed, the resumption PSK is derived and kept in a
|
|
487
|
+
per-connection `SessionCache`, and `getResumptionTicket(serverName)` hands
|
|
488
|
+
the stored ticket to the caller. What the client does not do is offer one:
|
|
489
|
+
the handshake driver never consults the store, so every ClientHello it
|
|
490
|
+
emits is a fresh full handshake — no `pre_shared_key`, no PSK-aware key
|
|
491
|
+
schedule, no resumed state machine. Tickets received today reach the wire
|
|
492
|
+
only when a caller feeds one back into `buildClientHello`'s `psk` argument
|
|
493
|
+
(tracked in #91).
|
|
378
494
|
- Mutual TLS (client certificate)
|
|
495
|
+
- 0-RTT early data (never offered; `max_early_data_size` from a ticket is stored informationally only)
|
|
379
496
|
- Certificate compression
|
|
380
497
|
- Key-share groups beyond X25519, secp256r1, secp384r1, and the X25519MLKEM768 hybrid (secp521r1 / x448 / FFDHE fail with a typed error — the crypto backend does not expose them)
|
|
381
498
|
|
|
@@ -23,19 +23,21 @@ export declare const KEY_USAGE_KEY_CERT_SIGN_BIT = 5;
|
|
|
23
23
|
*/
|
|
24
24
|
export declare function hasKeyUsageBit(value: Uint8Array, bitIndex: number): boolean;
|
|
25
25
|
/**
|
|
26
|
-
* Parse
|
|
27
|
-
*
|
|
28
|
-
*
|
|
26
|
+
* Parse the pathLenConstraint INTEGER element (RFC 5280 §4.2.1.9,
|
|
27
|
+
* `intTlv` already read inside the BasicConstraints SEQUENCE) under
|
|
28
|
+
* BoringSSL der::ParseUint8's rule — the same test ParseBasicConstraints
|
|
29
|
+
* applies at certificate-parse time, whose failure rejects the whole
|
|
30
|
+
* certificate (kFailedParsingBasicConstraints): the INTEGER must be
|
|
31
|
+
* non-negative (no high-bit-set leading byte), minimally encoded (a leading
|
|
32
|
+
* 0x00 is allowed only before a byte with the high bit set), and its value
|
|
33
|
+
* must fit one unsigned byte (≤ 255).
|
|
29
34
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* constraint"). A sign-violating or NON-MINIMAL INTEGER, however, is a
|
|
33
|
-
* malformed certificate and THROWS a typed error: RFC 5280 §4.2.1.9 defines
|
|
34
|
-
* pathLenConstraint as a non-negative INTEGER, so a negative value (DER
|
|
35
|
-
* two's-complement, high bit of the first content byte set) or a redundant
|
|
36
|
-
* padding octet (the non-minimal encodings BoringSSL also rejects) cannot be
|
|
37
|
-
* interpreted as "no constraint" — silently ignoring them would turn a
|
|
38
|
-
* malformed constraint into an unlimited one.
|
|
35
|
+
* Returns the constraint value, or null when the element is absent. Throws
|
|
36
|
+
* the typed malformed-extension error otherwise.
|
|
39
37
|
*/
|
|
40
|
-
export declare function parsePathLenConstraint(value: Uint8Array
|
|
38
|
+
export declare function parsePathLenConstraint(value: Uint8Array, intTlv: {
|
|
39
|
+
tag: number;
|
|
40
|
+
valueStart: number;
|
|
41
|
+
end: number;
|
|
42
|
+
}, extensionOid: string): number | null;
|
|
41
43
|
//# sourceMappingURL=ca-constraints.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ca-constraints.d.ts","sourceRoot":"","sources":["../../src/certificates/ca-constraints.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH;;;;GAIG;AACH,eAAO,MAAM,2BAA2B,IAAI,CAAC;AAE7C;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAe3E;AAED
|
|
1
|
+
{"version":3,"file":"ca-constraints.d.ts","sourceRoot":"","sources":["../../src/certificates/ca-constraints.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH;;;;GAIG;AACH,eAAO,MAAM,2BAA2B,IAAI,CAAC;AAE7C;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAe3E;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,sBAAsB,CAClC,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,EACxD,YAAY,EAAE,MAAM,GACrB,MAAM,GAAG,IAAI,CAgDf"}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* unwrapped extension values to both parsers.
|
|
11
11
|
*/
|
|
12
12
|
import { readTlv } from "./der.js";
|
|
13
|
-
import {
|
|
13
|
+
import { TlsMalformedExtensionError } from "../errors.js";
|
|
14
14
|
/**
|
|
15
15
|
* keyUsage BIT STRING bit position of keyCertSign (RFC 5280 §4.2.1.3):
|
|
16
16
|
* digitalSignature(0), nonRepudiation(1), keyEncipherment(2),
|
|
@@ -40,68 +40,50 @@ export function hasKeyUsageBit(value, bitIndex) {
|
|
|
40
40
|
return (byte & (1 << (7 - bitInByte))) !== 0;
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
|
-
* Parse
|
|
44
|
-
*
|
|
45
|
-
*
|
|
43
|
+
* Parse the pathLenConstraint INTEGER element (RFC 5280 §4.2.1.9,
|
|
44
|
+
* `intTlv` already read inside the BasicConstraints SEQUENCE) under
|
|
45
|
+
* BoringSSL der::ParseUint8's rule — the same test ParseBasicConstraints
|
|
46
|
+
* applies at certificate-parse time, whose failure rejects the whole
|
|
47
|
+
* certificate (kFailedParsingBasicConstraints): the INTEGER must be
|
|
48
|
+
* non-negative (no high-bit-set leading byte), minimally encoded (a leading
|
|
49
|
+
* 0x00 is allowed only before a byte with the high bit set), and its value
|
|
50
|
+
* must fit one unsigned byte (≤ 255).
|
|
46
51
|
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* constraint"). A sign-violating or NON-MINIMAL INTEGER, however, is a
|
|
50
|
-
* malformed certificate and THROWS a typed error: RFC 5280 §4.2.1.9 defines
|
|
51
|
-
* pathLenConstraint as a non-negative INTEGER, so a negative value (DER
|
|
52
|
-
* two's-complement, high bit of the first content byte set) or a redundant
|
|
53
|
-
* padding octet (the non-minimal encodings BoringSSL also rejects) cannot be
|
|
54
|
-
* interpreted as "no constraint" — silently ignoring them would turn a
|
|
55
|
-
* malformed constraint into an unlimited one.
|
|
52
|
+
* Returns the constraint value, or null when the element is absent. Throws
|
|
53
|
+
* the typed malformed-extension error otherwise.
|
|
56
54
|
*/
|
|
57
|
-
export function parsePathLenConstraint(value) {
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
55
|
+
export function parsePathLenConstraint(value, intTlv, extensionOid) {
|
|
56
|
+
const content = value.subarray(intTlv.valueStart, intTlv.end);
|
|
57
|
+
const first = content[0];
|
|
58
|
+
if (first === undefined) {
|
|
59
|
+
throw new TlsMalformedExtensionError(extensionOid, "pathLenConstraint INTEGER has no content bytes (der::ParseUint8)");
|
|
61
60
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
if (content.length > 1) {
|
|
84
|
-
const second = content[1] ?? 0;
|
|
85
|
-
if (first === 0x00 && (second & 0x80) === 0) {
|
|
86
|
-
// Redundant positive padding: DER requires the minimal
|
|
87
|
-
// encoding (02 02 00 05 is not a valid encoding of 5).
|
|
88
|
-
throw new TlsHandshakeError("certificate", {
|
|
89
|
-
cause: new Error("malformed BasicConstraints pathLenConstraint: non-minimal INTEGER encoding"),
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
let decoded = 0;
|
|
94
|
-
// Iteration over the slice yields plain numbers — no
|
|
95
|
-
// noUncheckedIndexedAccess branch, and the bounds are validated by
|
|
96
|
-
// readTlv above.
|
|
97
|
-
for (const byte of content) {
|
|
98
|
-
decoded = (decoded << 8) | byte;
|
|
99
|
-
}
|
|
100
|
-
return decoded;
|
|
61
|
+
if ((first & 0x80) !== 0) {
|
|
62
|
+
// High bit of the first byte set: a negative two's-complement
|
|
63
|
+
// INTEGER — never a valid pathLenConstraint.
|
|
64
|
+
throw new TlsMalformedExtensionError(extensionOid, "pathLenConstraint must be a non-negative INTEGER; the leading byte makes it negative (der::ParseUint8)");
|
|
65
|
+
}
|
|
66
|
+
if (content.length === 1) {
|
|
67
|
+
return first;
|
|
68
|
+
}
|
|
69
|
+
const second = content[1] ?? 0;
|
|
70
|
+
if (first === 0x00) {
|
|
71
|
+
// Padded form: DER minimality permits the 0x00 only when the next
|
|
72
|
+
// byte's high bit is set (otherwise the padding octet is redundant —
|
|
73
|
+
// CBS_is_valid_asn1_integer rejects it, so der::ParseUint8 does too).
|
|
74
|
+
if ((second & 0x80) === 0) {
|
|
75
|
+
throw new TlsMalformedExtensionError(extensionOid, "pathLenConstraint INTEGER is not minimally encoded (a leading 0x00 is only valid before a byte with the high bit set)");
|
|
76
|
+
}
|
|
77
|
+
if (content.length > 2) {
|
|
78
|
+
// [0x00, 0x80, ...] — the value is ≥ 2^15, far above one byte.
|
|
79
|
+
throw new TlsMalformedExtensionError(extensionOid, "pathLenConstraint must fit one unsigned byte — der::ParseUint8 (ParseUint64) rejects values above 255");
|
|
101
80
|
}
|
|
102
|
-
//
|
|
103
|
-
|
|
81
|
+
// [0x00, 0x80..0xFF] — the two's-complement leading zero makes the
|
|
82
|
+
// value the unsigned second byte (128..255).
|
|
83
|
+
return second;
|
|
104
84
|
}
|
|
105
|
-
|
|
85
|
+
// first in 0x01..0x7F with ≥ 2 content bytes: a minimal encoding whose
|
|
86
|
+
// value is ≥ 256 — above the uint8 range ParseUint8 accepts.
|
|
87
|
+
throw new TlsMalformedExtensionError(extensionOid, "pathLenConstraint must fit one unsigned byte — der::ParseUint8 (ParseUint64) rejects values above 255");
|
|
106
88
|
}
|
|
107
89
|
//# sourceMappingURL=ca-constraints.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ca-constraints.js","sourceRoot":"","sources":["../../src/certificates/ca-constraints.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,OAAO,EAAE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M,CAAC,GAAG,CAAC,CAAC;IAC9D,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACzB,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACtB,MAAM,IAAI,0BAA0B,CAChC,YAAY,EACZ,kEAAkE,CACrE,CAAC;IACN,CAAC;IACD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACvB,8DAA8D;QAC9D,6CAA6C;QAC7C,MAAM,IAAI,0BAA0B,CAChC,YAAY,EACZ,wGAAwG,CAC3G,CAAC;IACN,CAAC;IACD,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,MAAM,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAC/B,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACjB,kEAAkE;QAClE,qEAAqE;QACrE,sEAAsE;QACtE,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACxB,MAAM,IAAI,0BAA0B,CAChC,YAAY,EACZ,uHAAuH,CAC1H,CAAC;QACN,CAAC;QACD,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACrB,+DAA+D;YAC/D,MAAM,IAAI,0BAA0B,CAChC,YAAY,EACZ,uGAAuG,CAC1G,CAAC;QACN,CAAC;QACD,mEAAmE;QACnE,6CAA6C;QAC7C,OAAO,MAAM,CAAC;IAClB,CAAC;IACD,uEAAuE;IACvE,6DAA6D;IAC7D,MAAM,IAAI,0BAA0B,CAChC,YAAY,EACZ,uGAAuG,CAC1G,CAAC;AACN,CAAC"}
|
|
@@ -11,6 +11,12 @@
|
|
|
11
11
|
* extension-policy.ts — this layer only turns bytes into structured fields.
|
|
12
12
|
*/
|
|
13
13
|
import type { CertificateExtension } from "./certificate-path.js";
|
|
14
|
+
import { parseGeneralNames, type GeneralNames } from "./general-names.js";
|
|
15
|
+
import { parseNameConstraints, type NameConstraints } from "./name-constraints.js";
|
|
16
|
+
import { BASIC_CONSTRAINTS_OID, EXTENDED_KEY_USAGE_OID, KEY_USAGE_OID, SUBJECT_ALT_NAME_OID } from "./extension-policy.js";
|
|
17
|
+
export { parseGeneralNames, parseNameConstraints };
|
|
18
|
+
export type { GeneralNames, NameConstraints };
|
|
19
|
+
export { BASIC_CONSTRAINTS_OID, EXTENDED_KEY_USAGE_OID, KEY_USAGE_OID, SUBJECT_ALT_NAME_OID };
|
|
14
20
|
/**
|
|
15
21
|
* Parse the subject Name and return a readable DN string (RFC 2253-ish).
|
|
16
22
|
* Used only for the `issuer` field and debug-friendliness.
|
|
@@ -61,23 +67,67 @@ export declare function parseExtensionsBlock(buf: Uint8Array, start: number, _en
|
|
|
61
67
|
*/
|
|
62
68
|
export declare function parseExtendedKeyUsage(value: Uint8Array): readonly string[];
|
|
63
69
|
/**
|
|
64
|
-
* Parse the SAN extension value (already unwrapped from its OCTET STRING)
|
|
65
|
-
*
|
|
66
|
-
*
|
|
70
|
+
* Parse the SAN extension value (already unwrapped from its OCTET STRING) —
|
|
71
|
+
* the STRICT GeneralNames::Create twin (see general-names.ts for the exact
|
|
72
|
+
* fault list): BoringSSL parses the SAN value for EVERY certificate carrying
|
|
73
|
+
* the extension, critical or not, and a fault rejects the whole certificate
|
|
74
|
+
* (kFailedParsingSubjectAltName). Returns the full parsed name set (the DNS
|
|
75
|
+
* names the hostname check uses, plus the rfc822 / iPAddress / directoryName
|
|
76
|
+
* forms the name-constraint engine consumes).
|
|
67
77
|
*/
|
|
68
|
-
export declare function parseSubjectAltNames(value: Uint8Array):
|
|
78
|
+
export declare function parseSubjectAltNames(value: Uint8Array): GeneralNames;
|
|
69
79
|
/**
|
|
70
80
|
* Parse the KeyUsage extension value (unwrapped OCTET STRING holding a BIT
|
|
71
|
-
* STRING)
|
|
72
|
-
*
|
|
81
|
+
* STRING) — the STRICT ParseKeyUsage twin (pki/parse_certificate.cc:794):
|
|
82
|
+
* BoringSSL runs this for every keyUsage extension, critical or not, and a
|
|
83
|
+
* fault rejects the certificate (kFailedParsingKeyUsage):
|
|
84
|
+
*
|
|
85
|
+
* - the value must be exactly one BIT STRING (nothing before or after —
|
|
86
|
+
* "By definition the input was a single BIT STRING");
|
|
87
|
+
* - the unused-bits byte must be < 8 and a BIT STRING with no data bytes
|
|
88
|
+
* must declare 0 unused bits (CBS_asn1_bitstring rules);
|
|
89
|
+
* - "When the keyUsage extension appears in a certificate, at least one of
|
|
90
|
+
* the bits MUST be set to 1" (RFC 5280 §4.2.1.3) — an all-zero BIT STRING
|
|
91
|
+
* is the parse failure (`if (BitStringIsAllZeros(...)) { return false; }`).
|
|
92
|
+
*
|
|
93
|
+
* Returns the digitalSignature (bit 0) and keyEncipherment (bit 2) flags.
|
|
73
94
|
*/
|
|
74
95
|
export declare function parseKeyUsage(value: Uint8Array): {
|
|
75
96
|
readonly digitalSignature: boolean;
|
|
76
97
|
readonly keyEncipherment: boolean;
|
|
77
98
|
};
|
|
78
99
|
/**
|
|
79
|
-
*
|
|
80
|
-
|
|
100
|
+
* The strict BasicConstraints parse result (see {@link parseBasicConstraints}).
|
|
101
|
+
*/
|
|
102
|
+
export interface BasicConstraints {
|
|
103
|
+
readonly isCa: boolean;
|
|
104
|
+
/**
|
|
105
|
+
* pathLenConstraint (RFC 5280 §4.2.1.9), or null when absent. A value
|
|
106
|
+
* outside 0..255 or with a non-minimal / negative DER encoding is a
|
|
107
|
+
* malformed certificate (BoringSSL der::ParseUint8 fails →
|
|
108
|
+
* kFailedParsingBasicConstraints) and THROWS.
|
|
109
|
+
*/
|
|
110
|
+
readonly pathLenConstraint: number | null;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Parse the BasicConstraints extension value (unwrapped OCTET STRING holding
|
|
114
|
+
* SEQUENCE { cA BOOLEAN DEFAULT FALSE, pathLenConstraint INTEGER? }) — the
|
|
115
|
+
* STRICT ParseBasicConstraints twin (pki/parse_certificate.cc:735): BoringSSL
|
|
116
|
+
* runs this for every basicConstraints extension, critical or not, and a
|
|
117
|
+
* fault rejects the certificate (kFailedParsingBasicConstraints):
|
|
118
|
+
*
|
|
119
|
+
* - the value must be exactly one SEQUENCE (nothing trailing);
|
|
120
|
+
* - the cA BOOLEAN, when present, is der::ParseBool — one byte, 0x00 or
|
|
121
|
+
* 0xFF (X.690 §11.1); an explicitly-encoded FALSE is TOLERATED
|
|
122
|
+
* (BoringSSL's own TODO: "Should reject if CA was set to false… In
|
|
123
|
+
* practice however there are a lot of certificates that use the broken
|
|
124
|
+
* encoding");
|
|
125
|
+
* - the pathLenConstraint INTEGER, when present, must decode as uint8 —
|
|
126
|
+
* non-negative, minimally encoded, value ≤ 255 (der::ParseUint8; a larger
|
|
127
|
+
* constraint cannot appear in a certificate Chrome accepts);
|
|
128
|
+
* - nothing may follow inside the SEQUENCE.
|
|
129
|
+
*
|
|
130
|
+
* An empty SEQUENCE parses fine with cA = FALSE (the DEFAULT applies).
|
|
81
131
|
*/
|
|
82
|
-
export declare function parseBasicConstraints(value: Uint8Array):
|
|
132
|
+
export declare function parseBasicConstraints(value: Uint8Array): BasicConstraints;
|
|
83
133
|
//# sourceMappingURL=cert-extensions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cert-extensions.d.ts","sourceRoot":"","sources":["../../src/certificates/cert-extensions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"cert-extensions.d.ts","sourceRoot":"","sources":["../../src/certificates/cert-extensions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AA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