@browsercore/tls 0.4.2 → 0.4.4

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 (51) hide show
  1. package/README.md +4 -5
  2. package/dist/connection/handshake-driver.d.ts +29 -0
  3. package/dist/connection/handshake-driver.d.ts.map +1 -1
  4. package/dist/connection/handshake-driver.js +161 -23
  5. package/dist/connection/handshake-driver.js.map +1 -1
  6. package/dist/connection/handshake-messages.d.ts +70 -1
  7. package/dist/connection/handshake-messages.d.ts.map +1 -1
  8. package/dist/connection/handshake-messages.js +199 -9
  9. package/dist/connection/handshake-messages.js.map +1 -1
  10. package/dist/connection/index.d.ts +2 -1
  11. package/dist/connection/index.d.ts.map +1 -1
  12. package/dist/connection/index.js +2 -1
  13. package/dist/connection/index.js.map +1 -1
  14. package/dist/connection/lifecycle.d.ts +18 -5
  15. package/dist/connection/lifecycle.d.ts.map +1 -1
  16. package/dist/connection/lifecycle.js +20 -7
  17. package/dist/connection/lifecycle.js.map +1 -1
  18. package/dist/connection/record-layer.d.ts +5 -5
  19. package/dist/connection/record-layer.d.ts.map +1 -1
  20. package/dist/connection/record-layer.js +19 -12
  21. package/dist/connection/record-layer.js.map +1 -1
  22. package/dist/crypto/keySchedule.d.ts +18 -2
  23. package/dist/crypto/keySchedule.d.ts.map +1 -1
  24. package/dist/crypto/keySchedule.js +13 -1
  25. package/dist/crypto/keySchedule.js.map +1 -1
  26. package/dist/errors.d.ts +31 -2
  27. package/dist/errors.d.ts.map +1 -1
  28. package/dist/errors.js +20 -0
  29. package/dist/errors.js.map +1 -1
  30. package/dist/handshake/client-hello.d.ts +1 -1
  31. package/dist/handshake/client-hello.d.ts.map +1 -1
  32. package/dist/handshake/client-hello.js +23 -3
  33. package/dist/handshake/client-hello.js.map +1 -1
  34. package/dist/handshake/handshake.d.ts +1 -0
  35. package/dist/handshake/handshake.d.ts.map +1 -1
  36. package/dist/handshake/handshake.js +1 -0
  37. package/dist/handshake/handshake.js.map +1 -1
  38. package/dist/handshake/hello-retry-request.d.ts +89 -0
  39. package/dist/handshake/hello-retry-request.d.ts.map +1 -0
  40. package/dist/handshake/hello-retry-request.js +152 -0
  41. package/dist/handshake/hello-retry-request.js.map +1 -0
  42. package/dist/handshake/server-hello.d.ts.map +1 -1
  43. package/dist/handshake/server-hello.js +34 -0
  44. package/dist/handshake/server-hello.js.map +1 -1
  45. package/dist/tls.d.ts +56 -2
  46. package/dist/tls.d.ts.map +1 -1
  47. package/dist/tls.js +176 -14
  48. package/dist/tls.js.map +1 -1
  49. package/dist/types.d.ts +8 -0
  50. package/dist/types.d.ts.map +1 -1
  51. package/package.json +1 -1
@@ -112,6 +112,145 @@ export async function validateCertificateChain(body, serverName, trustAnchors, n
112
112
  }
113
113
  return chain;
114
114
  }
115
+ /**
116
+ * Map a 2-byte IANA signature-scheme wire code to its canonical name.
117
+ *
118
+ * Mirrors the entries in `SIGNATURE_SCHEME_CODES` (src/iana/signature-schemes.ts)
119
+ * but as a focused switch so this module stays under its dependency-count budget.
120
+ * The values are IANA registry constants, not magic strings — adding a new
121
+ * scheme to the registry requires updating BOTH this switch and the IANA table.
122
+ */
123
+ function wireToSignatureSchemeName(wire) {
124
+ switch (wire) {
125
+ case 0x0403: return "ecdsa_secp256r1_sha256";
126
+ case 0x0503: return "ecdsa_secp384r1_sha384";
127
+ case 0x0603: return "ecdsa_secp521r1_sha512";
128
+ case 0x0203: return "ecdsa_sha1";
129
+ case 0x0804: return "rsa_pss_rsae_sha256";
130
+ case 0x0805: return "rsa_pss_rsae_sha384";
131
+ case 0x0806: return "rsa_pss_rsae_sha512";
132
+ case 0x0401: return "rsa_pkcs1_sha256";
133
+ case 0x0501: return "rsa_pkcs1_sha384";
134
+ case 0x0601: return "rsa_pkcs1_sha512";
135
+ case 0x0201: return "rsa_pkcs1_sha1";
136
+ case 0x0807: return "ed25519";
137
+ default: return undefined;
138
+ }
139
+ }
140
+ /**
141
+ * The context string for a server CertificateVerify (RFC 8446 §4.4.3).
142
+ *
143
+ * Fixed by the protocol — a different context string ("TLS 1.3, client
144
+ * CertificateVerify") is used for the client's CertificateVerify. The 64-byte
145
+ * 0x20 prefix and the context string together prevent cross-protocol signature
146
+ * confusion attacks (the signing context is unique to this role + message).
147
+ */
148
+ const SERVER_CERT_VERIFY_CONTEXT = "TLS 1.3, server CertificateVerify";
149
+ /**
150
+ * Construct the to-be-signed content for a server CertificateVerify
151
+ * (RFC 8446 §4.4.3):
152
+ *
153
+ * ```
154
+ * 64 * 0x20 || "TLS 1.3, server CertificateVerify" || 0x00 || Transcript-Hash(ClientHello..Certificate)
155
+ * ```
156
+ *
157
+ * The 64 space bytes and the context string form a domain-separation prefix
158
+ * that prevents the signature from being replayed in a different context. The
159
+ * 0x00 byte separates the context string from the transcript hash.
160
+ *
161
+ * Exposed as a pure function so it can be unit-tested in isolation against
162
+ * known-answer test vectors.
163
+ *
164
+ * @param transcriptHashValue Hash(ClientHello..Certificate) — the transcript
165
+ * hash up to and including the Certificate message (NOT including
166
+ * CertificateVerify itself).
167
+ */
168
+ export function certificateVerifySignedContent(transcriptHashValue) {
169
+ const context = new TextEncoder().encode(SERVER_CERT_VERIFY_CONTEXT);
170
+ const padding = new Uint8Array(64).fill(0x20);
171
+ const separator = new Uint8Array([0x00]);
172
+ const out = new Uint8Array(padding.length + context.length + separator.length + transcriptHashValue.length);
173
+ let o = 0;
174
+ out.set(padding, o);
175
+ o += padding.length;
176
+ out.set(context, o);
177
+ o += context.length;
178
+ out.set(separator, o);
179
+ o += separator.length;
180
+ out.set(transcriptHashValue, o);
181
+ return out;
182
+ }
183
+ /**
184
+ * Verify a CertificateVerify message (RFC 8446 §4.4.3): confirm the server
185
+ * holds the private key corresponding to the leaf certificate's public key by
186
+ * checking the signature over the transcript hash.
187
+ *
188
+ * This closes the MITM vulnerability where a forged CertificateVerify with a
189
+ * dummy signature was silently accepted. After this check, the client is
190
+ * cryptographically assured that the server owns the leaf certificate's
191
+ * private key.
192
+ *
193
+ * The CertificateVerify body layout is:
194
+ * ```
195
+ * signature_scheme(2) || signature_length(2) || signature(N)
196
+ * ```
197
+ *
198
+ * Throws {@link TlsHandshakeError} with phase "certificate_verify" on any
199
+ * parsing error or signature mismatch.
200
+ *
201
+ * @param body The CertificateVerify handshake message body (after the
202
+ * 4-byte handshake header).
203
+ * @param leafSpki The leaf certificate's SubjectPublicKeyInfo (DER), as
204
+ * extracted by {@link parseCertificate}.
205
+ * @param transcript The transcript up to and including Certificate — NOT
206
+ * including CertificateVerify. The signed content covers
207
+ * Transcript-Hash(ClientHello..Certificate) per §4.4.3.
208
+ * @param hash The negotiated cipher's hash (SHA-256 or SHA-384).
209
+ * @param provider The injected crypto provider (Platform injection — never
210
+ * node:crypto directly) for hashing + signature verification.
211
+ */
212
+ export function verifyCertificateVerify(body, leafSpki, transcript, hash, provider) {
213
+ // Parse: signature_scheme(2) || signature_length(2) || signature(N).
214
+ if (body.length < 4) {
215
+ throw new TlsHandshakeError("certificate_verify", {
216
+ cause: new Error("CertificateVerify body too short for scheme + length fields"),
217
+ });
218
+ }
219
+ const b0 = body[0];
220
+ const b1 = body[1];
221
+ const b2 = body[2];
222
+ const b3 = body[3];
223
+ if (b0 === undefined || b1 === undefined || b2 === undefined || b3 === undefined) {
224
+ throw new TlsHandshakeError("certificate_verify", {
225
+ cause: new Error("CertificateVerify body truncated"),
226
+ });
227
+ }
228
+ const schemeWire = (b0 << 8) | b1;
229
+ const sigLen = (b2 << 8) | b3;
230
+ const sigEnd = 4 + sigLen;
231
+ if (sigEnd > body.length) {
232
+ throw new TlsHandshakeError("certificate_verify", {
233
+ cause: new Error("CertificateVerify signature length exceeds remaining body"),
234
+ });
235
+ }
236
+ const signature = body.subarray(4, sigEnd);
237
+ // Map the 2-byte wire scheme to the string name the crypto provider expects.
238
+ const scheme = wireToSignatureSchemeName(schemeWire);
239
+ if (scheme === undefined) {
240
+ throw new TlsHandshakeError("certificate_verify", {
241
+ cause: new Error(`unsupported signature scheme: 0x${schemeWire.toString(16)}`),
242
+ });
243
+ }
244
+ // Construct the signed content and verify against the leaf cert's public key.
245
+ const transcriptHashValue = transcriptHash(transcript, hash, provider);
246
+ const signedContent = certificateVerifySignedContent(transcriptHashValue);
247
+ const valid = provider.verifySignature(scheme, leafSpki, signature, signedContent);
248
+ if (!valid) {
249
+ throw new TlsHandshakeError("certificate_verify", {
250
+ cause: new Error("CertificateVerify signature does not match the leaf certificate public key"),
251
+ });
252
+ }
253
+ }
115
254
  /** Build the client Finished message bytes under the client handshake traffic key. */
116
255
  export function buildClientFinishedMessage(hash, clientHsTrafficSecret, transcript, provider) {
117
256
  const hashLen = hashLengthFor(hash);
@@ -125,55 +264,106 @@ export function buildClientFinishedMessage(hash, clientHsTrafficSecret, transcri
125
264
  message.set(verifyData, 4);
126
265
  return message;
127
266
  }
267
+ /**
268
+ * Split a decrypted record's content into individual handshake messages.
269
+ *
270
+ * RFC 8446 §5.1 permits a server to coalesce multiple handshake messages into a
271
+ * single TLSCiphertext record. Each message is framed as type(1) || length(3)
272
+ * || body (24-bit length in bytes 1..3), so the content can be split
273
+ * deterministically by walking the framing.
274
+ *
275
+ * When the content holds exactly one message (the non-coalesced case), this
276
+ * returns a single-element array containing the original content unchanged.
277
+ *
278
+ * @param content The full decrypted record content (inner content type byte
279
+ * and trailing zero-padding already stripped by the caller).
280
+ */
281
+ export function splitHandshakeMessages(content) {
282
+ const messages = [];
283
+ let offset = 0;
284
+ while (offset < content.length) {
285
+ if (offset + 4 > content.length) {
286
+ throw new TlsHandshakeError("encrypted_extensions", {
287
+ cause: new Error("truncated handshake message header in coalesced record"),
288
+ });
289
+ }
290
+ // 24-bit body length in bytes 1..3 (byte 0 is the handshake type).
291
+ const b1 = content[offset + 1];
292
+ const b2 = content[offset + 2];
293
+ const b3 = content[offset + 3];
294
+ if (b1 === undefined || b2 === undefined || b3 === undefined) {
295
+ throw new TlsHandshakeError("encrypted_extensions", {
296
+ cause: new Error("truncated handshake message header in coalesced record"),
297
+ });
298
+ }
299
+ const bodyLen = (b1 << 16) | (b2 << 8) | b3;
300
+ const totalLen = 4 + bodyLen;
301
+ if (offset + totalLen > content.length) {
302
+ throw new TlsHandshakeError("encrypted_extensions", {
303
+ cause: new Error("handshake message body exceeds record content boundary"),
304
+ });
305
+ }
306
+ messages.push(content.subarray(offset, offset + totalLen));
307
+ offset += totalLen;
308
+ }
309
+ return messages;
310
+ }
128
311
  /**
129
312
  * Read one encrypted handshake message, decrypting and stripping the inner type.
130
313
  * Returns the whole handshake message (header + body), the body alone, and the
131
314
  * buffer left after consuming the record.
315
+ *
316
+ * When the record contains multiple coalesced handshake messages (RFC 8446
317
+ * §5.1), `whole` holds the concatenation of all messages and the caller must
318
+ * use {@link splitHandshakeMessages} to separate them.
132
319
  */
133
- export async function readEncryptedHandshakeMessage(readBuffer, transport, aead, traffic, seq, provider) {
320
+ export async function readEncryptedHandshakeMessage(readBuffer, transport, aead, traffic, seq, provider, onDebug) {
134
321
  // RFC 8446 §5: a TLS 1.3 server may send a single change_cipher_spec record
135
322
  // (content type 20) between ServerHello and the encrypted flight for
136
323
  // middlebox compatibility. Clients MUST silently ignore it. CCS records are
137
324
  // unencrypted and pre-handshake, so they do NOT advance the AEAD sequence
138
325
  // number — only the real encrypted record that follows consumes `seq`.
139
- let header = await readHeaderBytesFromRecord(readBuffer, transport);
140
- let record = await readRawRecordFromRecord(header.readBuffer, transport, header);
326
+ let header = await readHeaderBytesFromRecord(readBuffer, transport, onDebug);
327
+ let record = await readRawRecordFromRecord(header.readBuffer, transport, header, onDebug);
141
328
  while (record.type === ContentType.CHANGE_CIPHER_SPEC) {
329
+ onDebug?.(`CCS record detected (middlebox compatibility) — skipping, seq not advanced`);
142
330
  // Sequential by necessity: each read consumes a prefix of readBuffer and
143
331
  // returns the remainder, so the next read must wait for it. The loop
144
332
  // continuation (record.type) is also re-evaluated after every read.
145
333
  // eslint-disable-next-line no-await-in-loop
146
- header = await readHeaderBytesFromRecord(record.readBuffer, transport);
334
+ header = await readHeaderBytesFromRecord(record.readBuffer, transport, onDebug);
147
335
  // eslint-disable-next-line no-await-in-loop
148
- record = await readRawRecordFromRecord(header.readBuffer, transport, header);
336
+ record = await readRawRecordFromRecord(header.readBuffer, transport, header, onDebug);
149
337
  }
150
338
  if (record.type !== ContentType.APPLICATION_DATA) {
151
- throw new TlsHandshakeError("finished", {
339
+ throw new TlsHandshakeError("encrypted_extensions", {
152
340
  cause: new Error(`expected encrypted APPLICATION_DATA record, got ${record.type}`),
153
341
  });
154
342
  }
155
343
  const nonce = xorNonce(traffic.iv, seq);
344
+ onDebug?.(`AEAD decrypt: algorithm=${aead}, seq=${seq}, ciphertext_len=${record.fragment.length}`);
156
345
  const plaintext = decryptRecord(record.fragment, traffic.key, nonce, header.raw, aead, provider);
346
+ onDebug?.(`AEAD decrypt: success, plaintext_len=${plaintext.length}`);
157
347
  // plaintext = content || innerType || optional zero padding. Find the type.
158
348
  let end = plaintext.length;
159
349
  while (end > 0 && plaintext[end - 1] === 0) {
160
350
  end--;
161
351
  }
162
352
  if (end === 0) {
163
- throw new TlsHandshakeError("finished", {
353
+ throw new TlsHandshakeError("encrypted_extensions", {
164
354
  cause: new Error("encrypted record plaintext is all zero padding"),
165
355
  });
166
356
  }
167
357
  const innerTypeByte = plaintext[end - 1];
168
358
  if (innerTypeByte === undefined) {
169
- throw new TlsHandshakeError("finished", {
359
+ throw new TlsHandshakeError("encrypted_extensions", {
170
360
  cause: new Error("encrypted handshake plaintext ended before the inner content type byte"),
171
361
  });
172
362
  }
173
363
  const innerType = readContentType(innerTypeByte);
174
364
  const content = plaintext.subarray(0, end - 1);
175
365
  if (innerType !== ContentType.HANDSHAKE) {
176
- throw new TlsHandshakeError("finished", {
366
+ throw new TlsHandshakeError("encrypted_extensions", {
177
367
  cause: new Error(`expected inner handshake type, got ${innerType}`),
178
368
  });
179
369
  }
@@ -1 +1 @@
1
- {"version":3,"file":"handshake-messages.js","sourceRoot":"","sources":["../../src/connection/handshake-messages.ts"],"names":[],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ACP,CAAC;IACD,MAAM,SAAS,GAAG,eAAe,CAAC,aAAa,CAAC,CAAC;IACjD,MAAM,OAAO,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC;IAC/C,IAAI,SAAS,KAAK,WAAW,CAAC,SAAS,EAAE,CAAC;QACtC,MAAM,IAAI,iBAAiB,CAAC,sBAAsB,EAAE;YAChD,KAAK,EAAE,IAAI,KAAK,CAAC,sCAAsC,SAAS,EAAE,CAAC;SACtE,CAAC,CAAC;IACP,CAAC;IACD,kEAAkE;IAClE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC;AACxF,CAAC"}
@@ -13,7 +13,8 @@
13
13
  */
14
14
  export { ensureOpen, handleAlert, handlePostHandshakeRecord, withTimeout } from "./lifecycle.js";
15
15
  export { computeSharedSecret, transcriptHash, verifyServerFinished } from "./key-exchange.js";
16
- export { buildClientFinishedMessage, parseAlpnFromEncryptedExtensions, readEncryptedHandshakeMessage, validateCertificateChain, } from "./handshake-messages.js";
16
+ export { buildClientFinishedMessage, parseAlpnFromEncryptedExtensions, readEncryptedHandshakeMessage, splitHandshakeMessages, validateCertificateChain, } from "./handshake-messages.js";
17
17
  export { readEncryptedRecord, readHeaderBytes, readRawRecord, writeEncryptedRecord, writeRecord, } from "./record-layer.js";
18
18
  export { runHandshake, type HandshakeContext } from "./handshake-driver.js";
19
+ export { updateTrafficSecrets } from "../crypto/keySchedule.js";
19
20
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connection/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,yBAAyB,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACjG,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC9F,OAAO,EACH,0BAA0B,EAC1B,gCAAgC,EAChC,6BAA6B,EAC7B,wBAAwB,GAC3B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACH,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,oBAAoB,EACpB,WAAW,GACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,KAAK,gBAAgB,EAAE,MAAM,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connection/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,yBAAyB,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACjG,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC9F,OAAO,EACH,0BAA0B,EAC1B,gCAAgC,EAChC,6BAA6B,EAC7B,sBAAsB,EACtB,wBAAwB,GAC3B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACH,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,oBAAoB,EACpB,WAAW,GACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,KAAK,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC"}
@@ -13,7 +13,8 @@
13
13
  */
14
14
  export { ensureOpen, handleAlert, handlePostHandshakeRecord, withTimeout } from "./lifecycle.js";
15
15
  export { computeSharedSecret, transcriptHash, verifyServerFinished } from "./key-exchange.js";
16
- export { buildClientFinishedMessage, parseAlpnFromEncryptedExtensions, readEncryptedHandshakeMessage, validateCertificateChain, } from "./handshake-messages.js";
16
+ export { buildClientFinishedMessage, parseAlpnFromEncryptedExtensions, readEncryptedHandshakeMessage, splitHandshakeMessages, validateCertificateChain, } from "./handshake-messages.js";
17
17
  export { readEncryptedRecord, readHeaderBytes, readRawRecord, writeEncryptedRecord, writeRecord, } from "./record-layer.js";
18
18
  export { runHandshake } from "./handshake-driver.js";
19
+ export { updateTrafficSecrets } from "../crypto/keySchedule.js";
19
20
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/connection/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,yBAAyB,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACjG,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC9F,OAAO,EACH,0BAA0B,EAC1B,gCAAgC,EAChC,6BAA6B,EAC7B,wBAAwB,GAC3B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACH,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,oBAAoB,EACpB,WAAW,GACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAyB,MAAM,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/connection/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,yBAAyB,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACjG,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC9F,OAAO,EACH,0BAA0B,EAC1B,gCAAgC,EAChC,6BAA6B,EAC7B,sBAAsB,EACtB,wBAAwB,GAC3B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACH,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,oBAAoB,EACpB,WAAW,GACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAyB,MAAM,uBAAuB,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC"}
@@ -8,20 +8,33 @@
8
8
  * this plumbing.
9
9
  */
10
10
  import { type Clock, type TlsState } from "../types.js";
11
- import { TlsAlertError } from "../errors.js";
11
+ import { TlsAlertError, type HandshakePhase } from "../errors.js";
12
12
  import { ContentType } from "../record/record.js";
13
- /** Race `run` against a timeout, rejecting with a handshake error if it fires. */
14
- export declare function withTimeout(ms: number, run: () => Promise<void>, clock?: Clock): Promise<void>;
13
+ /**
14
+ * Race `run` against a timeout, rejecting with a handshake error if it fires.
15
+ *
16
+ * `getPhase` is queried at timeout-fire time so the error reports the phase the
17
+ * handshake was actually in when it stalled — not a hardcoded guess. The caller
18
+ * (the connection) exposes a mutable `currentPhase` field that the driver
19
+ * updates before each step, and passes `() => this.currentPhase` here.
20
+ */
21
+ export declare function withTimeout(ms: number, run: () => Promise<void>, clock?: Clock, getPhase?: () => HandshakePhase): Promise<void>;
15
22
  /**
16
23
  * Handle a non-application record encountered while reading application data.
17
24
  *
18
25
  * Routes alerts to {@link handleAlert}, ignores post-handshake handshake
19
- * messages (NewSessionTicket, KeyUpdate — out of scope for the happy path),
20
- * and rejects any {@link ContentType.CHANGE_CIPHER_SPEC} or
26
+ * messages (NewSessionTicket — out of scope for the happy path), and rejects
27
+ * any {@link ContentType.CHANGE_CIPHER_SPEC} or
21
28
  * {@link ContentType.APPLICATION_DATA} that appears *inside* an encrypted
22
29
  * record (application data is only valid as the outer record type; TLS 1.3 has
23
30
  * no change_cipher_spec). Returns `true` if the alert was a close_notify and
24
31
  * the connection should close gracefully.
32
+ *
33
+ * Note: the connection class (`TlsConnectionImpl.handlePostHandshakeRecord`)
34
+ * now handles post-handshake records inline — including KeyUpdate key rotation
35
+ * (RFC 8446 §4.6.3) — rather than delegating to this function. This standalone
36
+ * utility remains for testing and for code that operates outside the
37
+ * connection lifecycle.
25
38
  */
26
39
  export declare function handlePostHandshakeRecord(innerType: ContentType, content: Uint8Array): boolean;
27
40
  /** Translate a received alert into a typed error and close the connection. */
@@ -1 +1 @@
1
- {"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../../src/connection/lifecycle.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAe,KAAK,KAAK,EAAE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,aAAa,EAAqB,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGlD,kFAAkF;AAClF,wBAAsB,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,EAAE,KAAK,GAAE,KAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAOjH;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAkB9F;AAED,8EAA8E;AAC9E,wBAAgB,WAAW,CAAC,OAAO,EAAE,UAAU,GAAG;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,aAAa,CAAA;CAAE,CAiB1F;AAED,2CAA2C;AAC3C,wBAAgB,UAAU,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,CAMhD"}
1
+ {"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../../src/connection/lifecycle.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAe,KAAK,KAAK,EAAE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,aAAa,EAAqB,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AACrF,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGlD;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAC7B,EAAE,EAAE,MAAM,EACV,GAAG,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,EACxB,KAAK,GAAE,KAAmB,EAC1B,QAAQ,GAAE,MAAM,cAA6B,GAC9C,OAAO,CAAC,IAAI,CAAC,CAOf;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAkB9F;AAED,8EAA8E;AAC9E,wBAAgB,WAAW,CAAC,OAAO,EAAE,UAAU,GAAG;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,aAAa,CAAA;CAAE,CAiB1F;AAED,2CAA2C;AAC3C,wBAAgB,UAAU,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,CAMhD"}
@@ -11,10 +11,17 @@ import { systemClock } from "../types.js";
11
11
  import { TlsAlertError, TlsHandshakeError } from "../errors.js";
12
12
  import { ContentType } from "../record/record.js";
13
13
  import { assertNever } from "../utils.js";
14
- /** Race `run` against a timeout, rejecting with a handshake error if it fires. */
15
- export async function withTimeout(ms, run, clock = systemClock) {
14
+ /**
15
+ * Race `run` against a timeout, rejecting with a handshake error if it fires.
16
+ *
17
+ * `getPhase` is queried at timeout-fire time so the error reports the phase the
18
+ * handshake was actually in when it stalled — not a hardcoded guess. The caller
19
+ * (the connection) exposes a mutable `currentPhase` field that the driver
20
+ * updates before each step, and passes `() => this.currentPhase` here.
21
+ */
22
+ export async function withTimeout(ms, run, clock = systemClock, getPhase = () => "init") {
16
23
  const timeout = clock.sleep(ms).then(() => {
17
- throw new TlsHandshakeError("finished", {
24
+ throw new TlsHandshakeError(getPhase(), {
18
25
  cause: new Error(`handshake timed out after ${ms}ms`),
19
26
  });
20
27
  });
@@ -24,12 +31,18 @@ export async function withTimeout(ms, run, clock = systemClock) {
24
31
  * Handle a non-application record encountered while reading application data.
25
32
  *
26
33
  * Routes alerts to {@link handleAlert}, ignores post-handshake handshake
27
- * messages (NewSessionTicket, KeyUpdate — out of scope for the happy path),
28
- * and rejects any {@link ContentType.CHANGE_CIPHER_SPEC} or
34
+ * messages (NewSessionTicket — out of scope for the happy path), and rejects
35
+ * any {@link ContentType.CHANGE_CIPHER_SPEC} or
29
36
  * {@link ContentType.APPLICATION_DATA} that appears *inside* an encrypted
30
37
  * record (application data is only valid as the outer record type; TLS 1.3 has
31
38
  * no change_cipher_spec). Returns `true` if the alert was a close_notify and
32
39
  * the connection should close gracefully.
40
+ *
41
+ * Note: the connection class (`TlsConnectionImpl.handlePostHandshakeRecord`)
42
+ * now handles post-handshake records inline — including KeyUpdate key rotation
43
+ * (RFC 8446 §4.6.3) — rather than delegating to this function. This standalone
44
+ * utility remains for testing and for code that operates outside the
45
+ * connection lifecycle.
33
46
  */
34
47
  export function handlePostHandshakeRecord(innerType, content) {
35
48
  switch (innerType) {
@@ -43,7 +56,7 @@ export function handlePostHandshakeRecord(innerType, content) {
43
56
  case ContentType.APPLICATION_DATA:
44
57
  // Neither should appear here: application data is the only expected
45
58
  // outer type, and TLS 1.3 has no change_cipher_spec. Reject typed.
46
- throw new TlsHandshakeError("finished", {
59
+ throw new TlsHandshakeError("application", {
47
60
  cause: new Error(`unexpected post-handshake record type ${innerType}`),
48
61
  });
49
62
  default:
@@ -72,7 +85,7 @@ export function handleAlert(content) {
72
85
  /** Throw unless the connection is open. */
73
86
  export function ensureOpen(state) {
74
87
  if (state.state !== "open") {
75
- throw new TlsHandshakeError("finished", {
88
+ throw new TlsHandshakeError("application", {
76
89
  cause: new Error(`connection not open (state: ${state.state})`),
77
90
  });
78
91
  }
@@ -1 +1 @@
1
- {"version":3,"file":"lifecycle.js","sourceRoot":"","sources":["../../src/connection/lifecycle.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,WAAW,EAA6B,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,WA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,CAAC,+BAA+B,KAAK,CAAC,KAAK,GAAG,CAAC;SAClE,CAAC,CAAC;IACP,CAAC;AACL,CAAC"}
@@ -26,12 +26,12 @@ export declare function concat(...chunks: readonly Uint8Array[]): Uint8Array;
26
26
  */
27
27
  export declare function xorNonce(iv: Uint8Array, seq: number): Uint8Array;
28
28
  /** Pull bytes from the transport until at least `n` are buffered. Returns the new buffer. */
29
- export declare function ensureBytes(readBuffer: Uint8Array, transport: Transport, n: number): Promise<Uint8Array>;
29
+ export declare function ensureBytes(readBuffer: Uint8Array, transport: Transport, n: number, onDebug?: (msg: string) => void): Promise<Uint8Array>;
30
30
  /**
31
31
  * Read the 5-byte record header and return it raw (needed as AEAD AAD) plus the
32
32
  * parsed length and the buffer left after consuming the header.
33
33
  */
34
- export declare function readHeaderBytes(readBuffer: Uint8Array, transport: Transport): Promise<{
34
+ export declare function readHeaderBytes(readBuffer: Uint8Array, transport: Transport, onDebug?: (msg: string) => void): Promise<{
35
35
  raw: Uint8Array;
36
36
  length: number;
37
37
  readBuffer: Uint8Array;
@@ -40,7 +40,7 @@ export declare function readHeaderBytes(readBuffer: Uint8Array, transport: Trans
40
40
  export declare function readRawRecord(readBuffer: Uint8Array, transport: Transport, header: {
41
41
  raw: Uint8Array;
42
42
  length: number;
43
- }): Promise<{
43
+ }, onDebug?: (msg: string) => void): Promise<{
44
44
  type: ContentType;
45
45
  fragment: Uint8Array;
46
46
  readBuffer: Uint8Array;
@@ -50,7 +50,7 @@ export declare function readRawRecord(readBuffer: Uint8Array, transport: Transpo
50
50
  * TLS 1.3 wraps encrypted handshake messages in records whose outer type is
51
51
  * application_data; the real type is the last non-zero byte of the plaintext.
52
52
  */
53
- export declare function readEncryptedRecord(readBuffer: Uint8Array, transport: Transport, aead: Parameters<typeof encryptRecord>[4], traffic: TrafficSecrets, seq: number, provider: CryptoProvider): Promise<{
53
+ export declare function readEncryptedRecord(readBuffer: Uint8Array, transport: Transport, aead: Parameters<typeof encryptRecord>[4], traffic: TrafficSecrets, seq: number, provider: CryptoProvider, onDebug?: (msg: string) => void): Promise<{
54
54
  innerType: ContentType;
55
55
  content: Uint8Array;
56
56
  readBuffer: Uint8Array;
@@ -62,5 +62,5 @@ export declare function writeRecord(transport: Transport, type: ContentType, fra
62
62
  * outer type is application_data. The inner content type byte is appended to
63
63
  * the plaintext before encryption.
64
64
  */
65
- export declare function writeEncryptedRecord(transport: Transport, aead: Parameters<typeof encryptRecord>[4], traffic: TrafficSecrets, innerType: ContentType, content: Uint8Array, seq: number, provider: CryptoProvider): Promise<void>;
65
+ export declare function writeEncryptedRecord(transport: Transport, aead: Parameters<typeof encryptRecord>[4], traffic: TrafficSecrets, innerType: ContentType, content: Uint8Array, seq: number, provider: CryptoProvider, onDebug?: (msg: string) => void): Promise<void>;
66
66
  //# sourceMappingURL=record-layer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"record-layer.d.ts","sourceRoot":"","sources":["../../src/connection/record-layer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,OAAO,EAAE,WAAW,EAAiB,aAAa,EAA6D,MAAM,qBAAqB,CAAC;AAC3I,0EAA0E;AAC1E,eAAO,MAAM,eAAe,KAAK,CAAC;AAElC,oDAAoD;AACpD,wBAAgB,MAAM,CAAC,GAAG,MAAM,EAAE,SAAS,UAAU,EAAE,GAAG,UAAU,CAYnE;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,UAAU,CAgBhE;AAED,6FAA6F;AAC7F,wBAAsB,WAAW,CAAC,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,EAAE,MAAM,GAA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}
54
54
  /** Pull bytes from the transport until at least `n` are buffered. Returns the new buffer. */
55
- export async function ensureBytes(readBuffer, transport, n) {
55
+ export async function ensureBytes(readBuffer, transport, n, onDebug) {
56
56
  let buffer = readBuffer;
57
57
  while (buffer.length < n) {
58
58
  // Sequential by necessity: each transport.read() delivers a variable
59
59
  // number of bytes and the loop continuation (buffer.length < n) must be
60
60
  // re-evaluated after every read, so the reads cannot be parallelized.
61
+ onDebug?.(`ensureBytes: need ${n} bytes, have ${buffer.length}, calling transport.read()`);
61
62
  // eslint-disable-next-line no-await-in-loop
62
63
  const chunk = await transport.read();
64
+ onDebug?.(`ensureBytes: transport.read() returned ${chunk.length} bytes (now ${buffer.length + chunk.length}/${n})`);
63
65
  buffer = concat(buffer, chunk);
64
66
  }
65
67
  return buffer;
@@ -68,15 +70,15 @@ export async function ensureBytes(readBuffer, transport, n) {
68
70
  * Read the 5-byte record header and return it raw (needed as AEAD AAD) plus the
69
71
  * parsed length and the buffer left after consuming the header.
70
72
  */
71
- export async function readHeaderBytes(readBuffer, transport) {
72
- const buffer = await ensureBytes(readBuffer, transport, 5);
73
+ export async function readHeaderBytes(readBuffer, transport, onDebug) {
74
+ const buffer = await ensureBytes(readBuffer, transport, 5, onDebug);
73
75
  const raw = buffer.subarray(0, 5);
74
76
  const parsed = parseRecordHeader(raw);
75
77
  return { raw, length: parsed.length, readBuffer: buffer };
76
78
  }
77
79
  /** Read a complete record given its already-consumed header. Returns the new buffer. */
78
- export async function readRawRecord(readBuffer, transport, header) {
79
- const buffer = await ensureBytes(readBuffer, transport, 5 + header.length);
80
+ export async function readRawRecord(readBuffer, transport, header, onDebug) {
81
+ const buffer = await ensureBytes(readBuffer, transport, 5 + header.length, onDebug);
80
82
  // type is byte 0 of the header; validate it back to the union (the cast that
81
83
  // used to live here is replaced by a properly-typed parse step).
82
84
  const typeByte = header.raw[0];
@@ -84,6 +86,7 @@ export async function readRawRecord(readBuffer, transport, header) {
84
86
  throw new TlsDecryptError("record", { cause: new Error("record header missing content type byte") });
85
87
  }
86
88
  const type = readContentType(typeByte);
89
+ onDebug?.(`record read: content_type=${typeByte} (0x${typeByte.toString(16).padStart(2, "0")}), fragment_length=${header.length}`);
87
90
  const fragment = buffer.subarray(5, 5 + header.length);
88
91
  return { type, fragment, readBuffer: buffer.subarray(5 + header.length) };
89
92
  }
@@ -92,29 +95,31 @@ export async function readRawRecord(readBuffer, transport, header) {
92
95
  * TLS 1.3 wraps encrypted handshake messages in records whose outer type is
93
96
  * application_data; the real type is the last non-zero byte of the plaintext.
94
97
  */
95
- export async function readEncryptedRecord(readBuffer, transport, aead, traffic, seq, provider) {
96
- const header = await readHeaderBytes(readBuffer, transport);
97
- const record = await readRawRecord(header.readBuffer, transport, header);
98
+ export async function readEncryptedRecord(readBuffer, transport, aead, traffic, seq, provider, onDebug) {
99
+ const header = await readHeaderBytes(readBuffer, transport, onDebug);
100
+ const record = await readRawRecord(header.readBuffer, transport, header, onDebug);
98
101
  if (record.type !== ContentType.APPLICATION_DATA) {
99
- throw new TlsHandshakeError("finished", {
102
+ throw new TlsHandshakeError("application", {
100
103
  cause: new Error(`expected encrypted APPLICATION_DATA record, got ${record.type}`),
101
104
  });
102
105
  }
103
106
  const nonce = xorNonce(traffic.iv, seq);
107
+ onDebug?.(`AEAD decrypt: algorithm=${aead}, seq=${seq}, ciphertext_len=${record.fragment.length}`);
104
108
  const plaintext = decryptRecord(record.fragment, traffic.key, nonce, header.raw, aead, provider);
109
+ onDebug?.(`AEAD decrypt: success, plaintext_len=${plaintext.length}`);
105
110
  // plaintext = content || innerType || optional zero padding. Find the type.
106
111
  let end = plaintext.length;
107
112
  while (end > 0 && plaintext[end - 1] === 0) {
108
113
  end--;
109
114
  }
110
115
  if (end === 0) {
111
- throw new TlsHandshakeError("finished", {
116
+ throw new TlsHandshakeError("application", {
112
117
  cause: new Error("encrypted record plaintext is all zero padding"),
113
118
  });
114
119
  }
115
120
  const innerTypeByte = plaintext[end - 1];
116
121
  if (innerTypeByte === undefined) {
117
- throw new TlsHandshakeError("finished", {
122
+ throw new TlsHandshakeError("application", {
118
123
  cause: new Error("encrypted record plaintext ended before the inner content type byte"),
119
124
  });
120
125
  }
@@ -130,11 +135,13 @@ export async function writeRecord(transport, type, fragment) {
130
135
  * outer type is application_data. The inner content type byte is appended to
131
136
  * the plaintext before encryption.
132
137
  */
133
- export async function writeEncryptedRecord(transport, aead, traffic, innerType, content, seq, provider) {
138
+ export async function writeEncryptedRecord(transport, aead, traffic, innerType, content, seq, provider, onDebug) {
134
139
  const plaintext = concat(content, new Uint8Array([innerType]));
135
140
  const header = serializeRecordHeader(ContentType.APPLICATION_DATA, plaintext.length + AEAD_TAG_LENGTH);
136
141
  const nonce = xorNonce(traffic.iv, seq);
142
+ onDebug?.(`AEAD encrypt: algorithm=${aead}, seq=${seq}, inner_type=${innerType}, plaintext_len=${plaintext.length}`);
137
143
  const ciphertext = encryptRecord(plaintext, traffic.key, nonce, header, aead, provider);
144
+ onDebug?.(`AEAD encrypt: success, ciphertext_len=${ciphertext.length}`);
138
145
  await transport.write(concat(header, ciphertext));
139
146
  }
140
147
  //# sourceMappingURL=record-layer.js.map