@browsercore/tls 0.4.17 → 0.4.19

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 (56) hide show
  1. package/README.md +238 -27
  2. package/dist/certificates/ca-constraints.d.ts +41 -0
  3. package/dist/certificates/ca-constraints.d.ts.map +1 -0
  4. package/dist/certificates/ca-constraints.js +107 -0
  5. package/dist/certificates/ca-constraints.js.map +1 -0
  6. package/dist/certificates/cert-extensions.d.ts +47 -10
  7. package/dist/certificates/cert-extensions.d.ts.map +1 -1
  8. package/dist/certificates/cert-extensions.js +111 -10
  9. package/dist/certificates/cert-extensions.js.map +1 -1
  10. package/dist/certificates/certificate-path.d.ts +282 -0
  11. package/dist/certificates/certificate-path.d.ts.map +1 -0
  12. package/dist/certificates/certificate-path.js +499 -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 +163 -82
  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 +195 -0
  23. package/dist/certificates/extension-policy.d.ts.map +1 -0
  24. package/dist/certificates/extension-policy.js +346 -0
  25. package/dist/certificates/extension-policy.js.map +1 -0
  26. package/dist/certificates/signature-algorithm.d.ts +54 -0
  27. package/dist/certificates/signature-algorithm.d.ts.map +1 -0
  28. package/dist/certificates/signature-algorithm.js +359 -0
  29. package/dist/certificates/signature-algorithm.js.map +1 -0
  30. package/dist/connection/handshake-driver.d.ts +9 -6
  31. package/dist/connection/handshake-driver.d.ts.map +1 -1
  32. package/dist/connection/handshake-driver.js.map +1 -1
  33. package/dist/connection/handshake-messages.d.ts +9 -2
  34. package/dist/connection/handshake-messages.d.ts.map +1 -1
  35. package/dist/connection/handshake-messages.js +57 -23
  36. package/dist/connection/handshake-messages.js.map +1 -1
  37. package/dist/errors.d.ts +54 -0
  38. package/dist/errors.d.ts.map +1 -1
  39. package/dist/errors.js +22 -0
  40. package/dist/errors.js.map +1 -1
  41. package/dist/index.d.ts +8 -5
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +5 -3
  44. package/dist/index.js.map +1 -1
  45. package/dist/session/session-cache.d.ts +2 -16
  46. package/dist/session/session-cache.d.ts.map +1 -1
  47. package/dist/session/session-cache.js.map +1 -1
  48. package/dist/tls.d.ts +4 -3
  49. package/dist/tls.d.ts.map +1 -1
  50. package/dist/tls.js +4 -3
  51. package/dist/tls.js.map +1 -1
  52. package/dist/types.d.ts +43 -2
  53. package/dist/types.d.ts.map +1 -1
  54. package/dist/types.js +2 -1
  55. package/dist/types.js.map +1 -1
  56. package/package.json +4 -4
package/README.md CHANGED
@@ -1,14 +1,13 @@
1
1
  # @browsercore/tls
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/@browsercore/tls)](https://www.npmjs.com/package/@browsercore/tls)
4
- [![coverage](https://img.shields.io/endpoint?url=https://jverneuer.github.io/browsercore-tls/badge.json)](https://github.com/jverneuer/browsercore-tls/blob/main/COVERAGE.md)
5
- [![lint](https://img.shields.io/github/actions/workflow/status/jverneuer/browsercore-tls/ci.yml?label=lint)](https://github.com/jverneuer/browsercore-tls/actions/workflows/ci.yml)
4
+ [![CI](https://img.shields.io/github/actions/workflow/status/jverneuer/browsercore-tls/ci.yml?label=ci)](https://github.com/jverneuer/browsercore-tls/actions/workflows/ci.yml)
6
5
 
7
- A TLS 1.3 client implemented entirely in TypeScript, with optional TLS 1.2
8
- fallback (RFC 5246). TLS 1.2 support is gated behind server negotiation: if the
9
- server selects a TLS 1.2 cipher suite, the handshake driver branches to
10
- runTls12Handshake(). Requesting a TLS 1.2-only handshake (one that cannot
11
- negotiate TLS 1.3) is rejected up front with a typed error.
6
+ A TLS 1.3-only client implemented entirely in TypeScript (RFC 8446). There is
7
+ no TLS 1.2 fallback: a profile that cannot negotiate TLS 1.3 is rejected up
8
+ front with a typed `TlsHandshakeError`, and a server that answers with a
9
+ TLS 1.2 cipher suite or a downgrade sentinel aborts the handshake with the
10
+ same typed error.
12
11
 
13
12
  ## Responsibility
14
13
 
@@ -23,7 +22,7 @@ validation. Provides an encrypted byte stream over an existing
23
22
  - Cookies
24
23
 
25
24
  It knows about byte streams (`@browsercore/transport`) and cryptographic primitives
26
- (`@browsercore/crypto`). It **never** imports `node:crypto` directly — that boundary
25
+ (`@browsercore/crypto`). It **never** imports `node:crypto` directly, and that boundary
27
26
  is `@browsercore/crypto`'s job, which keeps the crypto backend replaceable.
28
27
 
29
28
  ## Public API
@@ -35,7 +34,7 @@ import { connectTls, resolveProfile, TlsHandshakeError } from "@browsercore/tls"
35
34
 
36
35
  const transport = await connect({ host: "example.com", port: 443 });
37
36
 
38
- // `events` is required — an injected EventProvider backend that decouples the
37
+ // `events` is required: an injected EventProvider backend that decouples the
39
38
  // connection from node:events. Any runtime adapter satisfying the EventProvider
40
39
  // interface works (here a thin wrapper over Node's EventEmitter).
41
40
  const events = new EventEmitter();
@@ -69,11 +68,223 @@ await tls.close();
69
68
  | `resolveProfile()` | function | Look up a profile by name and fill in serverName |
70
69
  | `TlsError` | class | Base typed error |
71
70
  | `TlsHandshakeError` | class | Handshake failure at a specific phase |
71
+ | `TlsCertificateError` | class | Certificate validation failure with a typed `reason` (extends `TlsHandshakeError`, phase `"certificate"`) |
72
+ | `CertificateFailureReason` | string-literal union | Why certificate validation failed: `no-anchors`, `no-issuer`, `bad-signature`, `expired`, `not-yet-valid`, `not-a-ca`, `missing-key-cert-sign`, `path-too-long`, `unsupported-critical-extension`, `missing-server-auth-eku` |
72
73
  | `TlsDecryptError` | class | Record decryption / auth failure |
73
74
  | `TlsAlertError` | class | TLS alert with level + description |
74
- | `Clock` | interface (re-export) | Canonical time source from `@browsercore/contracts` — injected via `TlsOptions.clock` |
75
+ | `Certificate` | interface | Parsed X.509 certificate (validation-relevant fields; the canonical contract type) |
76
+ | `ParsedCertificate` | interface | tls-internal superset of `Certificate` carrying the subject/issuer DN byte spans, keyUsage presence + keyCertSign bit, `pathLenConstraint`, the ordered extension inventory (`extensions`: `{ oid, critical, value }` per RFC 5280 §4.1.2.9), and the parsed extendedKeyUsage OID list (`extendedKeyUsagePresent` + `extendedKeyUsage`) |
77
+ | `CertificateChain` | interface | The server-sent list: `leaf` first, `intermediates` = every following entry in wire order (breaking change in 0.4.19: the forced `root` field is gone) |
78
+ | `TrustAnchor` | type alias | A parsed certificate trusted a priori (= `ParsedCertificate`; breaking change in 0.4.19: was `{ subjectPublicKeyInfo, subject }`) |
79
+ | `CertificatePath` | discriminated union | `buildCertificatePath` result: `anchored` (path + anchor) or `unanchored` — `reason` is one of `no-issuer`, `bad-signature`, `expired`, `not-yet-valid`, `not-a-ca`, `missing-key-cert-sign`, `path-too-long`, `unsupported-critical-extension`, `missing-server-auth-eku` (every certificate failure reason except `no-anchors`, which `verifyChain` raises before building), plus the fully rendered `message` and the certificate the failure names |
80
+ | `buildCertificatePath()` / `parseCertificateDetails()` | functions | The pure RFC 5280 §6.1 path builder; the full internal parse behind `parseCertificate` |
81
+ | `CertificateSignatureAlgorithm` | discriminated union | The certificate's signature algorithm: `supported` (with TLS scheme) or `rejected` (with reason + OID) |
82
+ | `Clock` | interface (re-export) | Canonical time source from `@browsercore/contracts`, injected via `TlsOptions.clock` |
75
83
  | `systemClock` | const | Default `Clock` over the plain JS globals (`Date.now`, `performance.now`, `setTimeout`) |
76
84
 
85
+ ## Certificate signature algorithms
86
+
87
+ `parseCertificate` never rejects a structurally valid certificate because of
88
+ its signature algorithm. Instead it reports the parsed SignatureAlgorithm
89
+ Identifier (OID **and** parameters, RFC 5280 §4.1.1.2 / RFC 4055 §3.1) as a
90
+ `Certificate.signatureAlgorithm` discriminated union:
91
+
92
+ - `{ kind: "supported", scheme }` — maps to a TLS `SignatureScheme` usable for
93
+ chain-signature verification.
94
+ - `{ kind: "rejected", reason, oid }` — `reason` is one of `"sha1"`, `"md5"`,
95
+ `"pss-parameters"` (missing/non-conforming RSA-PSS parameters) or `"unknown"`.
96
+
97
+ Supported mappings: RSA PKCS#1 v1.5 SHA-256/384/512 (`rsa_pkcs1_*`), RSA-PSS
98
+ SHA-256/384/512 with MGF1 using the same hash and salt = digest length
99
+ (`rsa_pss_rsae_*` — the rsae/pss split only exists for TLS CertificateVerify;
100
+ certificate signatures are verified with the issuer's key, so only the hash
101
+ matters), ECDSA with SHA-256/384/512 (`ecdsa_secp256r1_sha256`,
102
+ `ecdsa_secp384r1_sha384`, `ecdsa_secp521r1_sha512` — the curve in the name is
103
+ the conventional pairing; verification uses the issuer's actual key), and
104
+ Ed25519 (parameters absent).
105
+
106
+ This is a breaking rename in 0.4.19: `Certificate.signatureScheme: SignatureScheme`
107
+ (a scalar that threw at parse time for every OID outside four hardcoded
108
+ entries) is replaced by `Certificate.signatureAlgorithm` above.
109
+
110
+ ### Rejection policy
111
+
112
+ `validateCertificateChain` enforces signature-algorithm policy in EVERY mode —
113
+ with or without trust anchors — the way Chrome does: a chain certificate whose
114
+ signature algorithm is `rejected` fails the handshake with a typed
115
+ `TlsHandshakeError` (phase `"certificate"`) naming the certificate (index +
116
+ issuer), the reason, and the OID. Self-signed certificates are EXEMPT: their
117
+ signature covers nothing the client relies on, and old trust anchors are
118
+ commonly self-signed with SHA-1 — so a SHA-1-self-signed root parses, can sit
119
+ in `trustAnchors`, and is never refused. When trust anchors are supplied,
120
+ `verifyChain` verifies each signature with the certificate's real scheme and
121
+ fails with a typed error for a rejected scheme before touching the crypto
122
+ provider.
123
+
124
+ Related diagnostics: the "certificate data may be compressed (RFC 8879)" hint
125
+ in a `Certificate`-message parse failure appears only when the offending entry
126
+ does not start with a DER SEQUENCE tag (0x30); a 0x30-prefixed entry surfaces
127
+ the parser's own error unchanged.
128
+
129
+ ## Certificate chain validation
130
+
131
+ `parseCertificateMessage` keeps the server-sent list VERBATIM (`leaf` +
132
+ `intermediates` in wire order); there is no forced `root` field, because
133
+ servers almost always omit the root and whether the last entry is a root, an
134
+ intermediate, or an unrelated certificate is decided by path building, never by
135
+ wire position. When trust anchors are supplied (`TlsOptions.trustAnchors`, raw
136
+ DER), `verifyChain` builds the certification path per RFC 5280 §6.1 with a
137
+ DEPTH-FIRST SEARCH WITH BACKTRACKING: at each step the candidates for the
138
+ current certificate's issuer are tried anchors-first, then the remaining
139
+ server-sent certificates in wire order. A candidate matches when its subject
140
+ DN equals the current certificate's issuer DN **byte-for-byte** (the same
141
+ comparison the parser uses for `selfSigned`; the DN is only the candidate
142
+ filter — the signature check with the candidate's public key is what actually
143
+ binds issuer to subject) and its key verifies the current certificate's
144
+ signature over its TBSCertificate using the certificate's own
145
+ `signatureAlgorithm` scheme. Every completed candidate path is then checked
146
+ (validity window, basicConstraints/keyCertSign, pathLenConstraint); the
147
+ result is the FIRST FULLY VALID path, and a candidate whose completed path
148
+ fails a check is abandoned for the next candidate — so the outcome never
149
+ depends on the order the server happened to choose (e.g. a cross-signed
150
+ intermediate sent in a pathlen-constrained and an unconstrained variant).
151
+ Only when every candidate is exhausted is the path reported unanchored, with
152
+ the failure observed at the DEEPEST search depth (the attempt that got
153
+ closest to acceptance; a completed-but-invalid path outranks a dead end at
154
+ the same prefix; ties resolve to the first attempt in search order). Every
155
+ signature verification performed while building IS the chain verification —
156
+ no pair is verified twice (the number of verifications is bounded by
157
+ candidates × path length). A certificate is never used twice on one path
158
+ (cycles terminate) and at most 8 intermediates are accepted
159
+ (`MAX_PATH_INTERMEDIATES`).
160
+
161
+ PINNED ANCHORS — matched by identity, never signature-verified: a certificate
162
+ that is itself an anchor (self-signed, subject DN bytes AND
163
+ subjectPublicKeyInfo bytes equal to the anchor's) ends the path immediately
164
+ WITHOUT any signature verification, because there is no issuer edge left to
165
+ verify — so a pinned leaf verifies regardless of its own signature algorithm
166
+ (a SHA-1 or unknown-OID self-signature is accepted). A pinned leaf is still a
167
+ WIRE certificate, and wire certificates are always validity-checked: an
168
+ EXPIRED pinned leaf fails with reason `expired` (the outcome is identical
169
+ whether the pinned match reuses the same parsed object or a second parse of
170
+ the same DER — there is no object-identity exemption). Only the trust anchor
171
+ ITSELF, in its position as the ISSUER of the top certificate (the parsed
172
+ anchor object, which is never part of the built path), is exempt from the
173
+ validity and CA checks — this matches BoringSSL, which checks the target's
174
+ validity unconditionally even for a directly trusted leaf. A NON-self-signed
175
+ certificate whose issuer is an anchor is a real edge and stays
176
+ signature-verified. A self-signed certificate that merely SHARES the anchor's
177
+ subject DN but not its SPKI is a name collision: it is not the anchor and has
178
+ no (real) issuer, so it fails with `no-issuer`.
179
+
180
+ Exactly what is checked, and when:
181
+
182
+ 1. **Hostname** — always, first: SAN DNS names, then the legacy CommonName
183
+ (RFC 6125). A mismatch fails before anything else, in every mode (before
184
+ even the no-anchors guard in `verifyChain`).
185
+ 2. **Signature-algorithm policy** — always: a `rejected` algorithm on a
186
+ non-self-signed chain certificate fails the handshake (see the previous
187
+ section). Self-signed certificates are exempt.
188
+ 3. **Chain building + signatures** — only when trust anchors are supplied:
189
+ the path must reach an anchor — by issuer-edge verification or by pinned
190
+ identity — and be fully valid.
191
+ 4. **Validity window** — on EVERY wire certificate of the built path (leaf +
192
+ intermediates, a pinned leaf included) at the injected `now`; only the
193
+ trust anchor itself is exempt (RFC 5280 §6.1: an anchor is trusted a
194
+ priori and, as the issuer of the top certificate, is not part of the
195
+ built path), so a chain under an EXPIRED anchor still verifies while an
196
+ expired intermediate — or an expired pinned leaf — fails.
197
+ 5. **Issuer authorization** — on the built path: every intermediate must
198
+ carry basicConstraints cA=TRUE (RFC 5280 §6.1.3 (k)) and, when it carries
199
+ a keyUsage extension, the keyCertSign bit (§4.2.1.3). Absence of keyUsage
200
+ is tolerated; absence of the cA flag is not.
201
+ 6. **pathLenConstraint** — on the built path: every issuer (each
202
+ intermediate, and the anchor as issuer of the top intermediate — RFC 5280
203
+ §6.1.1 (h) seeds the limit from the anchor) may have at most its
204
+ `pathLenConstraint` non-self-issued intermediates below it.
205
+ 7. **extendedKeyUsage (SERVER_AUTH)** — on the built path, exactly as Chrome
206
+ 140 enforces it (BoringSSL `VerifyExtendedKeyUsage` with
207
+ `KeyPurpose::SERVER_AUTH` — the value cert_verify_proc_builtin.cc passes for
208
+ every TLS-server verification — "Legacy compatible" branch): every path
209
+ certificate that CARRIES an EKU extension must include id-kp-serverAuth
210
+ (1.3.6.1.5.5.7.3.1) or anyExtendedKeyUsage (2.5.29.37.0), or the path fails
211
+ with `missing-server-auth-eku` (BoringSSL: `if (cert.has_extended_key_usage()
212
+ && !has_server_auth_eku && !has_any_eku) errors->AddError(kEkuLacksServerAuth)`
213
+ — raised for the target AND every issuer alike). An ABSENT extension is
214
+ accepted (on a leaf it is only Chrome's `kEkuNotPresent` warning; on
215
+ intermediates "we allow the noEKU case to permit everything"); an EMPTY EKU
216
+ sequence is present-but-permitting-nothing and fails; codeSigning /
217
+ timeStamping / OCSP-signing EKUs alongside serverAuth are warnings-only in
218
+ this mode (`add_error_if_strict`). The trust anchor is exempt (BoringSSL's
219
+ verification loop: "Don't do any other checks for root certificates").
220
+ 8. **Unrecognized critical extensions** — on the built path (RFC 5280 §4.2: "A
221
+ certificate-using system MUST reject the certificate if it encounters a
222
+ critical extension it does not recognize or a critical extension that
223
+ contains information that it cannot process"), mirroring BoringSSL's
224
+ `VerifyNoUnconsumedCriticalExtensions` + `IsHandledCriticalExtension` at the
225
+ BoringSSL revision Chromium 140 pins (0a0009998fa180695f3e2071805dc03c9a5f3124):
226
+ a CRITICAL extension fails the path with `unsupported-critical-extension`
227
+ (naming the OID and the certificate) unless it is in the recognized set —
228
+ exactly BoringSSL's: basicConstraints (2.5.29.19, processed),
229
+ keyUsage (2.5.29.15, keyCertSign processed; BoringSSL's own comment: "Key
230
+ Usage is NOT processed for end-entity certificates … however it is
231
+ considered 'handled' here in order to allow being marked as critical"),
232
+ extendedKeyUsage (2.5.29.37, processed — rule 7), subjectAltName
233
+ (2.5.29.17, processed — the hostname check), policyMappings (2.5.29.33),
234
+ policyConstraints (2.5.29.36) and inhibitAnyPolicy (2.5.29.54) (accepted
235
+ like BoringSSL's unconditional `return true`; policy ENFORCEMENT is a
236
+ documented limitation below), certificatePolicies (2.5.29.32) when the
237
+ value parses with only CPS (1.3.6.1.5.5.7.2.1) or userNotice
238
+ (1.3.6.1.5.5.7.2.2) qualifiers — BoringSSL: "if the extension is marked
239
+ critical need to ensure there weren't any qualifiers other than User Notice
240
+ / CPS" — and MSApplicationPolicies (1.3.6.1.4.1.311.21.10) when an EKU
241
+ extension is also present (crbug.com/1439638). Everything else critical —
242
+ including cRLDistributionPoints (2.5.29.31), authorityInfoAccess
243
+ (1.3.6.1.5.5.7.1.1), the embedded SCT list (1.3.6.1.4.1.11129.2.4.2), the
244
+ CT poison extension (1.3.6.1.4.1.11129.2.4.3 — Chrome never accepts
245
+ pre-certificates here: `SimplePathBuilderDelegate::AcceptPreCertificates()`
246
+ returns false), and the Netscape certificate-type extension
247
+ (2.16.840.1.113730.1.1) — is rejected. The trust anchor is exempt in every
248
+ position (issuer or pinned identity — Chrome's loop skips the root), and
249
+ the checks run ONLY when trust anchors are supplied: hostname-only mode
250
+ performs no chain validation at all. The extension STRUCTURE is validated
251
+ at parse time like BoringSSL's `ParseExtensions`: at least one extension
252
+ when the block is present, every entry a SEQUENCE { OID, critical?,
253
+ OCTET STRING } with no trailing data, an explicit critical=FALSE rejected
254
+ (DER requires DEFAULT values be omitted, X.690 §11.5), duplicate OIDs
255
+ rejected, and a present-but-malformed EKU value rejected
256
+ (`kFailedParsingEku`).
257
+
258
+ Every certificate-phase failure is a `TlsCertificateError` (a
259
+ `TlsHandshakeError` with phase `"certificate"`) carrying a discriminated
260
+ `reason`: `no-anchors` (verifyChain called with an empty anchor list — never a
261
+ vacuous success), `no-issuer`, `bad-signature`, `expired`, `not-yet-valid`,
262
+ `not-a-ca`, `missing-key-cert-sign`, `path-too-long`,
263
+ `unsupported-critical-extension`, `missing-server-auth-eku`. The message names
264
+ the offending certificate (wire index + issuer DN — and, for the extension and
265
+ EKU failures, the offending OID) so an operator can identify it without
266
+ re-running the handshake.
267
+
268
+ Explicit limitations — current scope, tracked as a separate follow-up subset
269
+ (not permanent design decisions): no revocation checking of any kind (no
270
+ CRL, no OCSP — neither stapled nor fetched); NO NAME CONSTRAINTS (RFC 5280
271
+ §4.2.1.10) — a certificate carrying a CRITICAL nameConstraints extension is
272
+ REJECTED (`unsupported-critical-extension`) until the name-constraints subset
273
+ lands, because this verifier cannot process it and RFC 5280 §4.2 requires
274
+ rejecting unprocessed critical extensions (the same certificate WITHOUT the
275
+ critical flag is accepted; openssl, which processes name constraints, accepts
276
+ both); no AIA fetching; no policy constraints / policy mappings /
277
+ certificate-policies ENFORCEMENT (the critical-acceptance of those OIDs above
278
+ only mirrors BoringSSL's parseability bar — the constraint VALUES are not
279
+ applied, and non-critical policy extensions are not parsed at all: a
280
+ malformed VALUE of an extension this verifier does not process is ignored
281
+ where Chrome rejects the certificate at parse time); no IP-address SAN
282
+ matching. Additionally, DN comparison is byte-exact: a path whose
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
285
+ inner/outer AlgorithmIdentifier equality of RFC 5280 §4.1.2.2 is not enforced
286
+ (the TBSCertificate identifier is authoritative).
287
+
77
288
  ## Dependency graph
78
289
 
79
290
  ```
@@ -84,7 +295,7 @@ await tls.close();
84
295
  ```
85
296
 
86
297
  `@browsercore/contracts` provides the `EventProvider` interface the connection
87
- composes (dependency injection — no `node:events` import), the canonical
298
+ composes (dependency injection, no `node:events` import), the canonical
88
299
  `Clock` (see [Time](#time--the-canonical-clock)), and the `TlsHandshakeEngine`
89
300
  contract tls satisfies (see
90
301
  [TlsHandshakeEngine conformance](#tlshandshakeengine-conformance-contracts-026)).
@@ -105,7 +316,7 @@ connection.
105
316
  | --- | --- |
106
317
  | `src/record/record.ts` | Record header parse/serialize, AEAD encrypt/decrypt (delegates to `@browsercore/crypto`) |
107
318
  | `src/handshake/client-hello.ts` | ClientHello builder (SNI, supported_versions, key_share, signature_algorithms, ALPN) |
108
- | `src/handshake/server-hello.ts` | ServerHello parser — validates cipher suite + version |
319
+ | `src/handshake/server-hello.ts` | ServerHello parser, validates cipher suite + version |
109
320
  | `src/handshake/state-machine.ts` | Handshake phase state machine with phase-tagged errors |
110
321
  | `src/crypto/keySchedule.ts` | TLS 1.3 key schedule (RFC 8446 §7.1): HKDF-Expand-Label, traffic secrets |
111
322
  | `src/certificates/` | X.509 DER parse, hostname validation (RFC 6125), chain verification |
@@ -121,11 +332,11 @@ Errors all carry a `kind` discriminator so callers can narrow and inspect
121
332
  without leaking backend specifics (`TlsHandshakeError(phase)`,
122
333
  `TlsDecryptError`, `TlsAlertError(level, description)`).
123
334
 
124
- ## Time — the canonical Clock
335
+ ## Time: the canonical Clock
125
336
 
126
337
  Since 0.4.17 this package has **no local Clock type**. `TlsOptions.clock`
127
338
  accepts the canonical `Clock` from `@browsercore/contracts` (`src/time.ts`,
128
- 0.2.6) — the single time contract the entire stack migrates onto (five
339
+ 0.2.6), the single time contract the entire stack migrates onto (five
129
340
  package-local sibling clocks existed before; tls's `{ now; sleep }` shape was
130
341
  one of them and is deleted). The default `systemClock` implements the FULL
131
342
  contract (`now` / `monotonic` / `sleep` / `setTimeout` / `clearTimeout`) over
@@ -134,23 +345,23 @@ the plain JS globals, so the same object can serve as the whole stack's
134
345
 
135
346
  tls itself only calls `now` and `sleep` today:
136
347
 
137
- - handshake timeout — `withTimeout` races the handshake against `clock.sleep`
138
- - certificate `notBefore`/`notAfter` validation — `now()` (epoch seconds)
139
- - NewSessionTicket timestamps and connection-id generation — `now()`
348
+ - handshake timeout: `withTimeout` races the handshake against `clock.sleep`
349
+ - certificate `notBefore`/`notAfter` validation via `now()` (epoch seconds)
350
+ - NewSessionTicket timestamps and connection-id generation via `now()`
140
351
 
141
352
  `monotonic()` is available on the same seam for future deadline hardening:
142
353
  timeout code can migrate from a single `sleep(ms)` race to monotonic deadline
143
354
  math (immune to wall-clock jumps) with no signature change at call sites (noted
144
355
  where the timeout is computed, `src/connection/lifecycle.ts`). Unit contract:
145
356
  `now()` is wall time (epoch ms, can jump); `monotonic()` is elapsed-time ms
146
- and never goes backwards — never compare the two.
357
+ and never goes backwards, so never compare the two.
147
358
 
148
359
  ## TlsHandshakeEngine conformance (contracts 0.2.6)
149
360
 
150
361
  `@browsercore/tls` is formally **an implementation of the contracts handshake
151
362
  engine**: `runHandshake`, `generateKeyShares`, and `cipherSuiteToAead`, wired
152
363
  from the public barrel, satisfy `TlsHandshakeEngine`
153
- (`@browsercore/contracts` `src/tls-engine.ts`, 0.2.6) with zero adaptation —
364
+ (`@browsercore/contracts` `src/tls-engine.ts`, 0.2.6) with zero adaptation;
154
365
  the contract's signatures were lifted verbatim from this package.
155
366
 
156
367
  The proof is type-level and checked in
@@ -166,7 +377,7 @@ directly and receives the engine via injection, exactly like crypto/transport
166
377
  - NewSessionTicket / session resumption / PSK / 0-RTT
167
378
  - Mutual TLS (client certificate)
168
379
  - Certificate compression
169
- - Additional key-share groups beyond X25519
380
+ - 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)
170
381
 
171
382
  ## Development
172
383
 
@@ -174,10 +385,10 @@ This repo shares tooling with the `@browsercore/*` family via
174
385
  [`@browsercore/dev`](https://www.npmjs.com/package/@browsercore/dev). That package
175
386
  is the single source of truth for:
176
387
 
177
- - `tsconfig` strict flags — `tsconfig.json` extends `@browsercore/dev/tsconfig.base.json`
178
- - `vitest` config — `vitest.config.ts` imports `definePackageConfig` from `@browsercore/dev/vitest`
179
- - `oxlint` config — `oxlint.config.ts` imports the base ruleset from `@browsercore/dev/oxlint`
180
- - `coverage-md` bin — shipped via `@browsercore/dev`'s `bin/`, used as `npx coverage-md`
388
+ - `tsconfig` strict flags: `tsconfig.json` extends `@browsercore/dev/tsconfig.base.json`
389
+ - `vitest` config: `vitest.config.ts` imports `definePackageConfig` from `@browsercore/dev/vitest`
390
+ - `oxlint` config: `oxlint.config.ts` imports the base ruleset from `@browsercore/dev/oxlint`
391
+ - `coverage-md` bin: shipped via `@browsercore/dev`'s `bin/`, used as `npx coverage-md`
181
392
 
182
393
  `@browsercore/dev` is declared in `devDependencies` as `"file:../dev"` for local
183
394
  development (the monorepo layout). When installing from npm, consumers resolve the
@@ -186,7 +397,7 @@ published version.
186
397
  ### Scripts
187
398
 
188
399
  ```sh
189
- npm run typecheck # tsc --noEmit (strict mode — noUncheckedIndexedAccess, exactOptionalPropertyTypes)
400
+ npm run typecheck # tsc --noEmit (strict mode, noUncheckedIndexedAccess + exactOptionalPropertyTypes)
190
401
  npm run lint # oxlint --type-aware src/ (tests excluded)
191
402
  npm test # vitest run (in-process fixture server, no real network)
192
403
  npm run build # tsc -p tsconfig.build.json → dist/
@@ -212,7 +423,7 @@ Linting is type-aware oxlint via `oxlint.config.ts`. The file extends the shared
212
423
  `promise`, and `node` plugins with `correctness`/`suspicious`/`pedantic` as errors).
213
424
  The old `.oxlintrc.json` has been removed.
214
425
 
215
- Private fields use the native TypeScript `private` keyword — the legacy
426
+ Private fields use the native TypeScript `private` keyword. The legacy
216
427
  `_`-prefixed naming convention has been fully migrated away, so no
217
428
  `no-underscore-dangle` allowlist is required.
218
429
 
@@ -220,4 +431,4 @@ Requires **Node >= 26**. ESM only (`"type": "module"`).
220
431
 
221
432
  ## Contributing
222
433
 
223
- Contributions are welcome — bug reports, reproductions, docs and code alike. Start with [CONTRIBUTING.md](CONTRIBUTING.md); the full guide lives in the [browsersmith repo](https://github.com/jverneuer/browsersmith/blob/main/CONTRIBUTING.md). First timer? Check the [`good first issue`](https://github.com/jverneuer/browsercore-tls/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) label. Security issues: [SECURITY.md](SECURITY.md), never a public issue.
434
+ Contributions are welcome: bug reports, reproductions, docs and code alike. Start with [CONTRIBUTING.md](CONTRIBUTING.md); the full guide lives in the [browsersmith repo](https://github.com/jverneuer/browsersmith/blob/main/CONTRIBUTING.md). First timer? Check the [`good first issue`](https://github.com/jverneuer/browsercore-tls/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) label. Security issues: [SECURITY.md](SECURITY.md), never a public issue.
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Certificate-authority constraint bits for path validation (RFC 5280
3
+ * §4.2.1.3 KeyUsage, §4.2.1.9 BasicConstraints pathLenConstraint).
4
+ *
5
+ * This module holds ONLY the delta the path builder needs beyond what
6
+ * `cert-extensions.ts` already parses (digitalSignature/keyEncipherment bits
7
+ * and the cA flag): the keyCertSign bit and the pathLenConstraint integer.
8
+ * Keeping the additions beside the path checks means the RFC 5280 §6.1
9
+ * issuer-authorization inputs have one owner; `certificates.ts` feeds the same
10
+ * unwrapped extension values to both parsers.
11
+ */
12
+ /**
13
+ * keyUsage BIT STRING bit position of keyCertSign (RFC 5280 §4.2.1.3):
14
+ * digitalSignature(0), nonRepudiation(1), keyEncipherment(2),
15
+ * dataEncipherment(3), keyAgreement(4), keyCertSign(5), cRLSign(6).
16
+ */
17
+ export declare const KEY_USAGE_KEY_CERT_SIGN_BIT = 5;
18
+ /**
19
+ * True when the keyUsage BIT STRING (unwrapped from its extnValue OCTET
20
+ * STRING) asserts the bit at `bitIndex`. Bits are numbered from the most
21
+ * significant bit of the first content byte (after the unused-bits count),
22
+ * exactly the layout parseKeyUsage decodes.
23
+ */
24
+ export declare function hasKeyUsageBit(value: Uint8Array, bitIndex: number): boolean;
25
+ /**
26
+ * Parse BasicConstraints (unwrapped extnValue: SEQUENCE { cA BOOLEAN DEFAULT
27
+ * FALSE, pathLenConstraint INTEGER? }) and return the pathLenConstraint, or
28
+ * null when it is absent.
29
+ *
30
+ * Lenient about structurally odd extension VALUES (non-SEQUENCE content,
31
+ * no INTEGER element, an over-long INTEGER all yield null — "no usable
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.
39
+ */
40
+ export declare function parsePathLenConstraint(value: Uint8Array): number | null;
41
+ //# sourceMappingURL=ca-constraints.d.ts.map
@@ -0,0 +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;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI,CAiDvE"}
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Certificate-authority constraint bits for path validation (RFC 5280
3
+ * §4.2.1.3 KeyUsage, §4.2.1.9 BasicConstraints pathLenConstraint).
4
+ *
5
+ * This module holds ONLY the delta the path builder needs beyond what
6
+ * `cert-extensions.ts` already parses (digitalSignature/keyEncipherment bits
7
+ * and the cA flag): the keyCertSign bit and the pathLenConstraint integer.
8
+ * Keeping the additions beside the path checks means the RFC 5280 §6.1
9
+ * issuer-authorization inputs have one owner; `certificates.ts` feeds the same
10
+ * unwrapped extension values to both parsers.
11
+ */
12
+ import { readTlv } from "./der.js";
13
+ import { TlsHandshakeError } from "../errors.js";
14
+ /**
15
+ * keyUsage BIT STRING bit position of keyCertSign (RFC 5280 §4.2.1.3):
16
+ * digitalSignature(0), nonRepudiation(1), keyEncipherment(2),
17
+ * dataEncipherment(3), keyAgreement(4), keyCertSign(5), cRLSign(6).
18
+ */
19
+ export const KEY_USAGE_KEY_CERT_SIGN_BIT = 5;
20
+ /**
21
+ * True when the keyUsage BIT STRING (unwrapped from its extnValue OCTET
22
+ * STRING) asserts the bit at `bitIndex`. Bits are numbered from the most
23
+ * significant bit of the first content byte (after the unused-bits count),
24
+ * exactly the layout parseKeyUsage decodes.
25
+ */
26
+ export function hasKeyUsageBit(value, bitIndex) {
27
+ const bitString = readTlv(value, 0);
28
+ if (bitString.tag !== 0x03) {
29
+ return false;
30
+ }
31
+ // BIT STRING content: first byte = number of unused bits, then the bits.
32
+ const usedBytes = value.subarray(bitString.valueStart + 1, bitString.end);
33
+ const byteIndex = Math.floor(bitIndex / 8);
34
+ const byte = usedBytes[byteIndex];
35
+ if (byte === undefined) {
36
+ // The extension simply does not extend to this bit — not asserted.
37
+ return false;
38
+ }
39
+ const bitInByte = bitIndex % 8;
40
+ return (byte & (1 << (7 - bitInByte))) !== 0;
41
+ }
42
+ /**
43
+ * Parse BasicConstraints (unwrapped extnValue: SEQUENCE { cA BOOLEAN DEFAULT
44
+ * FALSE, pathLenConstraint INTEGER? }) and return the pathLenConstraint, or
45
+ * null when it is absent.
46
+ *
47
+ * Lenient about structurally odd extension VALUES (non-SEQUENCE content,
48
+ * no INTEGER element, an over-long INTEGER all yield null — "no usable
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.
56
+ */
57
+ export function parsePathLenConstraint(value) {
58
+ const seq = readTlv(value, 0);
59
+ if (seq.tag !== 0x30) {
60
+ return null;
61
+ }
62
+ let o = seq.valueStart;
63
+ while (o < seq.end) {
64
+ const element = readTlv(value, o);
65
+ if (element.tag === 0x02) {
66
+ // INTEGER: big-endian two's complement; a pathLenConstraint is
67
+ // always non-negative (0..MAX) and fits in a few bytes.
68
+ const content = value.subarray(element.valueStart, element.end);
69
+ if (content.length === 0 || content.length > 4) {
70
+ return null;
71
+ }
72
+ const first = content[0];
73
+ if (first === undefined) {
74
+ return null;
75
+ }
76
+ if ((first & 0x80) !== 0) {
77
+ // High bit of the first byte set: a negative two's-complement
78
+ // INTEGER — never a valid pathLenConstraint.
79
+ throw new TlsHandshakeError("certificate", {
80
+ cause: new Error("malformed BasicConstraints pathLenConstraint: negative INTEGER"),
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;
101
+ }
102
+ // The cA BOOLEAN (or anything unexpected) precedes the INTEGER — walk on.
103
+ o = element.end;
104
+ }
105
+ return null;
106
+ }
107
+ //# sourceMappingURL=ca-constraints.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ca-constraints.js","sourceRoot":"","sources":["../../src/certificates/ca-constraints.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD;;;;GAIG;AACH,MAAM,CAAC,MAAM,2BAA2B,GA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EAA0E;QAC1E,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC;IACpB,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC"}
@@ -3,11 +3,14 @@
3
3
  *
4
4
  * These decode the higher-level X.509 structures a TLS server cert actually
5
5
  * carries: the subject/issuer DistinguishedNames (RFC 2253), the SAN
6
- * extension (the source of truth for hostname validation), KeyUsage, and
7
- * BasicConstraints (the cA flag that separates leaf from CA certs). They sit on
8
- * top of the raw DER primitives in `der.ts` but are agnostic to validation
9
- * policy — they only turn bytes into structured fields.
6
+ * extension (the source of truth for hostname validation), KeyUsage,
7
+ * BasicConstraints (the cA flag that separates leaf from CA certs), and the
8
+ * extendedKeyUsage OID list (RFC 5280 §4.2.1.12). They sit on top of the raw
9
+ * DER primitives in `der.ts`; structural decisions (which critical extension
10
+ * may be consumed, whether an EKU list authorizes server auth) live in
11
+ * extension-policy.ts — this layer only turns bytes into structured fields.
10
12
  */
13
+ import type { CertificateExtension } from "./certificate-path.js";
11
14
  /**
12
15
  * Parse the subject Name and return a readable DN string (RFC 2253-ish).
13
16
  * Used only for the `issuer` field and debug-friendliness.
@@ -16,13 +19,47 @@ export declare function parseName(buf: Uint8Array, start: number, _end: number):
16
19
  /** Extract the CN (OID 2.5.4.3) from a subject Name, if present. */
17
20
  export declare function parseCommonName(buf: Uint8Array, start: number, _end: number): string | undefined;
18
21
  /**
19
- * Parse the extensions block (SEQUENCE OF Extension) between `start` and `end`.
20
- * Each extension is SEQUENCE { extnID OID, critical BOOLEAN?, extnValue OCTET STRING }.
22
+ * Parse the extensions block (SEQUENCE OF Extension, RFC 5280 §4.1.2.9) between
23
+ * `start` and `end` into the ordered extension inventory:
24
+ * `{ oid, critical, value }` per extension, where `critical` defaults to FALSE
25
+ * (RFC 5280 §4.2: "critical BOOLEAN DEFAULT FALSE") and `value` is the CONTENTS
26
+ * of the extnValue OCTET STRING.
27
+ *
28
+ * Structural faults throw the typed certificate-phase error, mirroring
29
+ * BoringSSL's ParseExtensions/ParseExtension (pki/parse_certificate.cc), whose
30
+ * failure rejects the whole certificate:
31
+ *
32
+ * - the block must be a SEQUENCE containing at least one extension ("The
33
+ * Extensions SEQUENCE must contains at least 1 element (otherwise it
34
+ * should have been omitted)" — RFC 5280 §4.1.2.9 makes the whole block
35
+ * OPTIONAL, so an empty one is an encoding fault);
36
+ * - each entry must be a SEQUENCE whose extnID is an OBJECT IDENTIFIER;
37
+ * - the critical BOOLEAN, when present, must be a single 0xFF byte:
38
+ * BoringSSL `der::ParseBool` (X.690 §11.1) accepts only 0x00/0xFF, and
39
+ * `ParseExtension` then rejects FALSE — "DER-encoding requires DEFAULT
40
+ * values be omitted" (X.690 §11.5 via RFC 5280's DER mandate);
41
+ * - extnValue must be an OCTET STRING with no trailing data inside the
42
+ * Extension element ("The Extension type does not have an extension
43
+ * point (everything goes in extnValue)" — HasMore check);
44
+ * - an OID must not appear twice ("RFC 5280 says that an extension should
45
+ * not appear more than once" — the duplicate insert fails in
46
+ * ParseExtensions).
47
+ */
48
+ export declare function parseExtensionsBlock(buf: Uint8Array, start: number, _end: number): readonly CertificateExtension[];
49
+ /**
50
+ * Parse the extendedKeyUsage extension value (already unwrapped from its OCTET
51
+ * STRING): SEQUENCE OF KeyPurposeId, i.e. a SEQUENCE whose every element is an
52
+ * OBJECT IDENTIFIER (RFC 5280 §4.2.1.12). Returns the OIDs in dotted form,
53
+ * in order; an empty SEQUENCE is valid DER and yields an empty list (the
54
+ * SERVER_AUTH policy then rejects the certificate — "present but permitting
55
+ * nothing").
56
+ *
57
+ * A malformed value throws the typed certificate-phase error: BoringSSL parses
58
+ * the EKU at certificate-parse time and a failed `ParseEKUExtension` rejects
59
+ * the whole certificate (parsed_certificate.cc: `if (!ParseEKUExtension(...))
60
+ * { errors->AddError(kFailedParsingEku); return nullptr; }`).
21
61
  */
22
- export declare function parseExtensionsBlock(buf: Uint8Array, start: number, _end: number): readonly {
23
- readonly oid: string;
24
- readonly value: Uint8Array;
25
- }[];
62
+ export declare function parseExtendedKeyUsage(value: Uint8Array): readonly string[];
26
63
  /**
27
64
  * Parse the SAN extension value (already unwrapped from its OCTET STRING).
28
65
  * The value is a SEQUENCE OF GeneralName; we only extract dNSName entries
@@ -1 +1 @@
1
- {"version":3,"file":"cert-extensions.d.ts","sourceRoot":"","sources":["../../src/certificates/cert-extensions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH;;;GAGG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAiC9E;AAED,oEAAoE;AACpE,wBAAgB,eAAe,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CA8BhG;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS;IACzF,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;CAC9B,EAAE,CAkCF;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,MAAM,EAAE,CAoBzE;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG;IAC9C,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC;IACnC,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC;CACrC,CAiCA;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAWhE"}
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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