@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.
- package/README.md +4 -5
- package/dist/connection/handshake-driver.d.ts +29 -0
- package/dist/connection/handshake-driver.d.ts.map +1 -1
- package/dist/connection/handshake-driver.js +161 -23
- package/dist/connection/handshake-driver.js.map +1 -1
- package/dist/connection/handshake-messages.d.ts +70 -1
- package/dist/connection/handshake-messages.d.ts.map +1 -1
- package/dist/connection/handshake-messages.js +199 -9
- package/dist/connection/handshake-messages.js.map +1 -1
- package/dist/connection/index.d.ts +2 -1
- package/dist/connection/index.d.ts.map +1 -1
- package/dist/connection/index.js +2 -1
- package/dist/connection/index.js.map +1 -1
- package/dist/connection/lifecycle.d.ts +18 -5
- package/dist/connection/lifecycle.d.ts.map +1 -1
- package/dist/connection/lifecycle.js +20 -7
- package/dist/connection/lifecycle.js.map +1 -1
- package/dist/connection/record-layer.d.ts +5 -5
- package/dist/connection/record-layer.d.ts.map +1 -1
- package/dist/connection/record-layer.js +19 -12
- package/dist/connection/record-layer.js.map +1 -1
- package/dist/crypto/keySchedule.d.ts +18 -2
- package/dist/crypto/keySchedule.d.ts.map +1 -1
- package/dist/crypto/keySchedule.js +13 -1
- package/dist/crypto/keySchedule.js.map +1 -1
- package/dist/errors.d.ts +31 -2
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +20 -0
- package/dist/errors.js.map +1 -1
- package/dist/handshake/client-hello.d.ts +1 -1
- package/dist/handshake/client-hello.d.ts.map +1 -1
- package/dist/handshake/client-hello.js +23 -3
- package/dist/handshake/client-hello.js.map +1 -1
- package/dist/handshake/handshake.d.ts +1 -0
- package/dist/handshake/handshake.d.ts.map +1 -1
- package/dist/handshake/handshake.js +1 -0
- package/dist/handshake/handshake.js.map +1 -1
- package/dist/handshake/hello-retry-request.d.ts +89 -0
- package/dist/handshake/hello-retry-request.d.ts.map +1 -0
- package/dist/handshake/hello-retry-request.js +152 -0
- package/dist/handshake/hello-retry-request.js.map +1 -0
- package/dist/handshake/server-hello.d.ts.map +1 -1
- package/dist/handshake/server-hello.js +34 -0
- package/dist/handshake/server-hello.js.map +1 -1
- package/dist/tls.d.ts +56 -2
- package/dist/tls.d.ts.map +1 -1
- package/dist/tls.js +176 -14
- package/dist/tls.js.map +1 -1
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -106,9 +106,10 @@ connection.
|
|
|
106
106
|
| `src/extensions/` | Extension types, parsers, and wire encoders |
|
|
107
107
|
| `src/connection/handshake-driver.ts` | Handshake choreography (what to send, what to read, when to derive) |
|
|
108
108
|
| `src/connection/record-layer.ts` | TLS 1.3 inner-content-type wrapping, nonce XOR, record framing |
|
|
109
|
-
| `src/connection/key-exchange.ts` | (EC)DHE shared secret, transcript hash, server Finished verification |
|
|
109
|
+
| `src/connection/key-exchange.ts` | (EC)DHE shared secret, transcript hash, server Finished verification, CertificateVerify verification |
|
|
110
110
|
| `src/connection/handshake-messages.ts` | EncryptedExtensions/Certificate/Finished parsing, client Finished builder |
|
|
111
|
-
| `src/
|
|
111
|
+
| `src/handshake/hello-retry-request.ts` | HelloRetryRequest detection (RFC 8446 §4.1.3 sentinel) and cookie handling |
|
|
112
|
+
| `src/connection/lifecycle.ts` | Timeouts (with phase-attributed errors), alerts, state transitions, post-handshake record dispatch |
|
|
112
113
|
|
|
113
114
|
Errors all carry a `kind` discriminator so callers can narrow and inspect
|
|
114
115
|
without leaking backend specifics (`TlsHandshakeError(phase)`,
|
|
@@ -116,11 +117,9 @@ without leaking backend specifics (`TlsHandshakeError(phase)`,
|
|
|
116
117
|
|
|
117
118
|
## Not implemented
|
|
118
119
|
|
|
119
|
-
-
|
|
120
|
-
- Session resumption / PSK / 0-RTT
|
|
120
|
+
- NewSessionTicket / session resumption / PSK / 0-RTT
|
|
121
121
|
- Mutual TLS (client certificate)
|
|
122
122
|
- Certificate compression
|
|
123
|
-
- HelloRetryRequest
|
|
124
123
|
- Additional key-share groups beyond X25519
|
|
125
124
|
|
|
126
125
|
## Development
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import type { Transport } from "@browsercore/transport";
|
|
16
16
|
import type { CryptoProvider, HashId } from "@browsercore/crypto";
|
|
17
|
+
import { type AlertLevel, type HandshakePhase as TimeoutPhase } from "../errors.js";
|
|
17
18
|
import { type ServerHello } from "../handshake/handshake.js";
|
|
18
19
|
import type { AeadAlgorithm, ApplicationTrafficSecrets, CipherSuite, ClientHelloConfig, KeyPair, TrafficSecrets } from "../types.js";
|
|
19
20
|
type ValidatedCertificate = Awaited<ReturnType<typeof validateCertificateChain>>["leaf"];
|
|
@@ -41,13 +42,41 @@ export interface HandshakeContext {
|
|
|
41
42
|
clientHsTrafficSecret: Uint8Array;
|
|
42
43
|
serverHsTrafficSecret: Uint8Array;
|
|
43
44
|
masterSecret: Uint8Array;
|
|
45
|
+
/**
|
|
46
|
+
* Mutable: raw application traffic secrets, set when the driver derives
|
|
47
|
+
* application secrets (step 7). Retained so the connection can rotate keys
|
|
48
|
+
* via {@link updateTrafficSecrets} on KeyUpdate (RFC 8446 §4.6.3).
|
|
49
|
+
*/
|
|
50
|
+
clientAppSecret: Uint8Array;
|
|
51
|
+
serverAppSecret: Uint8Array;
|
|
44
52
|
/** Mutable: handshake-direction sequence counters. */
|
|
45
53
|
clientHsSeq: number;
|
|
46
54
|
serverHsSeq: number;
|
|
55
|
+
/** True once the handshake traffic secrets have been derived (sendAlert gate). */
|
|
56
|
+
hsTrafficReady: boolean;
|
|
47
57
|
/** Set when the server negotiates ALPN in EncryptedExtensions. */
|
|
48
58
|
alpnProtocol?: string | undefined;
|
|
49
59
|
/** Set to the validated leaf once the Certificate message is consumed. */
|
|
50
60
|
peerCertificate?: ValidatedCertificate | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Mutable: the handshake phase currently in progress. Updated by the driver
|
|
63
|
+
* before each step so {@link withTimeout} can report the true stall location
|
|
64
|
+
* in its error message instead of a hardcoded guess.
|
|
65
|
+
*/
|
|
66
|
+
currentPhase: TimeoutPhase;
|
|
67
|
+
/**
|
|
68
|
+
* Optional debug trace callback. When set, the driver and record layer emit
|
|
69
|
+
* a line before/after each I/O and crypto step. This is the primary
|
|
70
|
+
* diagnostic tool for pinpointing handshake stalls.
|
|
71
|
+
*/
|
|
72
|
+
onDebug: ((msg: string) => void) | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* Send a TLS alert (RFC 8446 §6) to the peer. Best-effort: if the traffic
|
|
75
|
+
* keys are not yet derived (early handshake failure) or the transport write
|
|
76
|
+
* fails, the alert is silently dropped. The connection's error-cleanup path
|
|
77
|
+
* (transport close) is the fallback.
|
|
78
|
+
*/
|
|
79
|
+
sendAlert(level: AlertLevel, description: number): Promise<void>;
|
|
51
80
|
}
|
|
52
81
|
/**
|
|
53
82
|
* Drive the TLS 1.3 handshake to completion against `ctx`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handshake-driver.d.ts","sourceRoot":"","sources":["../../src/connection/handshake-driver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"handshake-driver.d.ts","sourceRoot":"","sources":["../../src/connection/handshake-driver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAqB,KAAK,UAAU,EAAE,KAAK,cAAc,IAAI,YAAY,EAAE,MAAM,cAAc,CAAC;AAEvG,OAAO,EAUH,KAAK,WAAW,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;IACH,OAAO,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IAC7C;;;;;OAKG;IACH,SAAS,CAAC,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACpE;AAWD;;;;;;GAMG;AACH,wBAAsB,YAAY,CAC9B,GAAG,EAAE,gBAAgB,EACrB,OAAO,EAAE,iBAAiB,EAC1B,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,SAAS,UAAU,EAAE,EACnC,iBAAiB,EAAE,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,KAAK,OAAO,CAAC,OAAO,EAAE,CAAC,EACpE,GAAG,EAAE,MAAM,GACZ,OAAO,CAAC,yBAAyB,CAAC,CAuKpC"}
|
|
@@ -14,13 +14,13 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import { TlsHandshakeError } from "../errors.js";
|
|
16
16
|
import { ContentType, cipherSuiteToAead } from "../record/record.js";
|
|
17
|
-
import { advanceHandshake, buildClientHello, parseServerHello, recordServerHello, HandshakeType, } from "../handshake/handshake.js";
|
|
17
|
+
import { advanceHandshake, buildClientHello, parseServerHello, recordServerHello, HandshakeType, isHelloRetryRequest, parseHelloRetryRequestExtensions, buildMessageHashMessage, } from "../handshake/handshake.js";
|
|
18
18
|
import { deriveApplicationSecrets, deriveHandshakeTrafficSecrets, deriveTrafficSecrets, hashFor, } from "../crypto/keySchedule.js";
|
|
19
19
|
// Import from the individual submodules (not the ./index.js barrel) to avoid a
|
|
20
20
|
// dependency cycle: index.ts re-exports this module, so reaching back through
|
|
21
21
|
// it would close the loop. The submodules are the real owners of these helpers.
|
|
22
22
|
import { computeSharedSecret, transcriptHash, verifyServerFinished } from "./key-exchange.js";
|
|
23
|
-
import { buildClientFinishedMessage, parseAlpnFromEncryptedExtensions, readEncryptedHandshakeMessage, validateCertificateChain, } from "./handshake-messages.js";
|
|
23
|
+
import { buildClientFinishedMessage, parseAlpnFromEncryptedExtensions, readEncryptedHandshakeMessage, splitHandshakeMessages, validateCertificateChain, verifyCertificateVerify, } from "./handshake-messages.js";
|
|
24
24
|
import { readHeaderBytes, readRawRecord, writeEncryptedRecord, writeRecord, } from "./record-layer.js";
|
|
25
25
|
/** Constant: the only key-share group the crypto backend can generate. */
|
|
26
26
|
const SUPPORTED_GROUP = "x25519";
|
|
@@ -37,6 +37,7 @@ function applyNegotiation(ctx) {
|
|
|
37
37
|
* pure and testable.
|
|
38
38
|
*/
|
|
39
39
|
export async function runHandshake(ctx, profile, serverName, trustAnchors, generateKeyShares, now) {
|
|
40
|
+
ctx.currentPhase = "init";
|
|
40
41
|
// TLS 1.3 only: reject a profile that cannot negotiate TLS 1.3.
|
|
41
42
|
if (!profile.supportedVersions.some((v) => v.name === "TLS 1.3")) {
|
|
42
43
|
throw new TlsHandshakeError("client_hello", {
|
|
@@ -44,6 +45,8 @@ export async function runHandshake(ctx, profile, serverName, trustAnchors, gener
|
|
|
44
45
|
});
|
|
45
46
|
}
|
|
46
47
|
// 1. Generate key shares for the groups the crypto backend supports.
|
|
48
|
+
ctx.currentPhase = "client_hello";
|
|
49
|
+
ctx.onDebug?.("phase: client_hello — generating key shares");
|
|
47
50
|
const desired = profile.keyShareGroups.filter((g) => g === SUPPORTED_GROUP);
|
|
48
51
|
if (desired.length === 0) {
|
|
49
52
|
throw new TlsHandshakeError("client_hello", {
|
|
@@ -52,16 +55,21 @@ export async function runHandshake(ctx, profile, serverName, trustAnchors, gener
|
|
|
52
55
|
}
|
|
53
56
|
const keyPairs = await generateKeyShares(desired);
|
|
54
57
|
// 2. Build and send the ClientHello as a plaintext handshake record.
|
|
55
|
-
|
|
58
|
+
ctx.onDebug?.("phase: client_hello — building and sending ClientHello");
|
|
59
|
+
const greaseRandom = () => {
|
|
56
60
|
const byte = ctx.crypto.randomBytes(1)[0];
|
|
57
61
|
return byte === undefined ? 0 : byte / 256;
|
|
58
|
-
}
|
|
62
|
+
};
|
|
63
|
+
const clientHello = buildClientHello(profile, keyPairs, greaseRandom, ctx.crypto);
|
|
59
64
|
ctx.transcript.push(clientHello);
|
|
60
65
|
await writeRecord(ctx.transport, ContentType.HANDSHAKE, clientHello);
|
|
66
|
+
ctx.onDebug?.(`phase: client_hello — ClientHello sent (${clientHello.length} bytes)`);
|
|
61
67
|
// 3. Read the ServerHello (still plaintext) and validate the negotiation.
|
|
62
|
-
|
|
68
|
+
ctx.currentPhase = "server_hello";
|
|
69
|
+
ctx.onDebug?.("phase: server_hello — waiting for ServerHello record");
|
|
70
|
+
const shHeader = await readHeaderBytes(ctx.readBuffer, ctx.transport, ctx.onDebug);
|
|
63
71
|
ctx.readBuffer = shHeader.readBuffer;
|
|
64
|
-
const shRecord = await readRawRecord(ctx.readBuffer, ctx.transport, shHeader);
|
|
72
|
+
const shRecord = await readRawRecord(ctx.readBuffer, ctx.transport, shHeader, ctx.onDebug);
|
|
65
73
|
ctx.readBuffer = shRecord.readBuffer;
|
|
66
74
|
if (shRecord.type !== ContentType.HANDSHAKE) {
|
|
67
75
|
throw new TlsHandshakeError("server_hello", {
|
|
@@ -69,72 +77,202 @@ export async function runHandshake(ctx, profile, serverName, trustAnchors, gener
|
|
|
69
77
|
});
|
|
70
78
|
}
|
|
71
79
|
ctx.transcript.push(shRecord.fragment);
|
|
72
|
-
const
|
|
80
|
+
const firstHello = parseServerHello(shRecord.fragment.subarray(4), {
|
|
73
81
|
cipherSuites: profile.cipherSuites,
|
|
74
82
|
supportedVersions: profile.supportedVersions,
|
|
75
83
|
});
|
|
76
|
-
|
|
77
|
-
ctx.
|
|
84
|
+
// Set cipher suite + hash early — the HRR carries the same cipher suite as
|
|
85
|
+
// the real ServerHello will, and we need ctx.hash to compute the synthetic
|
|
86
|
+
// message_hash transcript prefix during HRR handling.
|
|
87
|
+
ctx.cipherSuite = firstHello.cipherSuite;
|
|
78
88
|
applyNegotiation(ctx);
|
|
89
|
+
// HelloRetryRequest detection (RFC 8446 §4.1.3). The server sends an HRR
|
|
90
|
+
// (a special ServerHello with the sentinel random) when the client's initial
|
|
91
|
+
// key-share group is unacceptable. The client must rewrite the transcript,
|
|
92
|
+
// generate a fresh key share, resend the ClientHello, and read the *real*
|
|
93
|
+
// ServerHello that follows.
|
|
94
|
+
let effectiveKeyPairs = keyPairs;
|
|
95
|
+
let serverHello = firstHello;
|
|
96
|
+
if (isHelloRetryRequest(firstHello.random)) {
|
|
97
|
+
ctx.onDebug?.("phase: server_hello — HelloRetryRequest detected");
|
|
98
|
+
// Transcript rewrite (RFC 8446 §4.4.1): replace ClientHello_1 + HRR
|
|
99
|
+
// with message_hash(Hash(ClientHello_1)) + HRR.
|
|
100
|
+
ctx.transcript.pop(); // remove HRR
|
|
101
|
+
ctx.transcript.pop(); // remove ClientHello_1
|
|
102
|
+
const ch1Hash = transcriptHash([clientHello], ctx.hash, ctx.crypto);
|
|
103
|
+
ctx.transcript.push(buildMessageHashMessage(ch1Hash), shRecord.fragment);
|
|
104
|
+
// Parse HRR extensions: selected_group + optional cookie.
|
|
105
|
+
const hrr = parseHelloRetryRequestExtensions(firstHello.extensions);
|
|
106
|
+
ctx.onDebug?.(`phase: server_hello — HRR requests group ${hrr.selectedGroup}${hrr.cookie === undefined ? "" : " with cookie"}`);
|
|
107
|
+
// Generate a fresh key share for the server's selected group.
|
|
108
|
+
effectiveKeyPairs = await generateKeyShares([hrr.selectedGroup]);
|
|
109
|
+
// Build and send ClientHello_2 with the new key share and the echoed cookie.
|
|
110
|
+
const clientHello2 = hrr.cookie === undefined
|
|
111
|
+
? buildClientHello(profile, effectiveKeyPairs, greaseRandom, ctx.crypto)
|
|
112
|
+
: buildClientHello(profile, effectiveKeyPairs, greaseRandom, ctx.crypto, hrr.cookie);
|
|
113
|
+
ctx.transcript.push(clientHello2);
|
|
114
|
+
await writeRecord(ctx.transport, ContentType.HANDSHAKE, clientHello2);
|
|
115
|
+
ctx.onDebug?.(`phase: server_hello — ClientHello_2 sent after HRR (${clientHello2.length} bytes)`);
|
|
116
|
+
// Read the *real* ServerHello.
|
|
117
|
+
ctx.onDebug?.("phase: server_hello — waiting for real ServerHello after HRR");
|
|
118
|
+
const realShHeader = await readHeaderBytes(ctx.readBuffer, ctx.transport, ctx.onDebug);
|
|
119
|
+
ctx.readBuffer = realShHeader.readBuffer;
|
|
120
|
+
const realShRecord = await readRawRecord(ctx.readBuffer, ctx.transport, realShHeader, ctx.onDebug);
|
|
121
|
+
ctx.readBuffer = realShRecord.readBuffer;
|
|
122
|
+
if (realShRecord.type !== ContentType.HANDSHAKE) {
|
|
123
|
+
throw new TlsHandshakeError("server_hello", {
|
|
124
|
+
cause: new Error(`expected handshake record after HRR, got content type ${realShRecord.type}`),
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
ctx.transcript.push(realShRecord.fragment);
|
|
128
|
+
serverHello = parseServerHello(realShRecord.fragment.subarray(4), {
|
|
129
|
+
cipherSuites: profile.cipherSuites,
|
|
130
|
+
supportedVersions: profile.supportedVersions,
|
|
131
|
+
});
|
|
132
|
+
// The real ServerHello is authoritative for the cipher suite (though it
|
|
133
|
+
// must match the HRR — the server cannot change suites mid-handshake).
|
|
134
|
+
ctx.cipherSuite = serverHello.cipherSuite;
|
|
135
|
+
applyNegotiation(ctx);
|
|
136
|
+
}
|
|
137
|
+
ctx.onDebug?.(`phase: server_hello — parsed ServerHello (cipher=${serverHello.cipherSuite}, version=${serverHello.selectedVersion.name})`);
|
|
138
|
+
ctx.serverHello = serverHello;
|
|
79
139
|
// 4. (EC)DHE key exchange.
|
|
80
|
-
|
|
140
|
+
ctx.currentPhase = "key_exchange";
|
|
141
|
+
ctx.onDebug?.("phase: key_exchange — computing shared secret");
|
|
142
|
+
const sharedSecret = computeSharedSecret(serverHello, effectiveKeyPairs, ctx.crypto);
|
|
143
|
+
ctx.onDebug?.("phase: key_exchange — shared secret computed");
|
|
81
144
|
// 5. Derive handshake traffic secrets from the ClientHello..ServerHello transcript.
|
|
145
|
+
ctx.onDebug?.("phase: key_exchange — deriving handshake traffic secrets");
|
|
82
146
|
const helloTranscript = transcriptHash(ctx.transcript, ctx.hash, ctx.crypto);
|
|
83
147
|
const { masterSecret, clientTrafficSecret, serverTrafficSecret } = deriveHandshakeTrafficSecrets(sharedSecret, helloTranscript, ctx.cipherSuite, ctx.crypto);
|
|
148
|
+
ctx.onDebug?.("phase: key_exchange — handshake traffic secrets derived");
|
|
84
149
|
ctx.masterSecret = masterSecret;
|
|
85
150
|
ctx.clientHsTrafficSecret = clientTrafficSecret;
|
|
86
151
|
ctx.serverHsTrafficSecret = serverTrafficSecret;
|
|
87
152
|
ctx.clientHsTraffic = deriveTrafficSecrets(clientTrafficSecret, ctx.cipherSuite, ctx.hash, ctx.crypto);
|
|
88
153
|
ctx.serverHsTraffic = deriveTrafficSecrets(serverTrafficSecret, ctx.cipherSuite, ctx.hash, ctx.crypto);
|
|
154
|
+
ctx.hsTrafficReady = true;
|
|
89
155
|
// 6. Consume the server's encrypted flight.
|
|
90
156
|
await consumeServerFlight(ctx, serverName, trustAnchors, now);
|
|
91
157
|
// 7. Derive application traffic secrets from the full transcript.
|
|
158
|
+
ctx.currentPhase = "client_finished";
|
|
159
|
+
ctx.onDebug?.("phase: client_finished — deriving application traffic secrets");
|
|
92
160
|
const handshakeTranscript = transcriptHash(ctx.transcript, ctx.hash, ctx.crypto);
|
|
93
161
|
const applicationSecrets = deriveApplicationSecrets(ctx.masterSecret, handshakeTranscript, ctx.cipherSuite, ctx.crypto);
|
|
162
|
+
ctx.clientAppSecret = applicationSecrets.clientSecret;
|
|
163
|
+
ctx.serverAppSecret = applicationSecrets.serverSecret;
|
|
164
|
+
ctx.onDebug?.("phase: client_finished — application traffic secrets derived");
|
|
94
165
|
// 8. Send the client Finished under the client handshake traffic key.
|
|
166
|
+
ctx.onDebug?.("phase: client_finished — building and sending client Finished");
|
|
95
167
|
const finishedMessage = buildClientFinishedMessage(ctx.hash, ctx.clientHsTrafficSecret, ctx.transcript, ctx.crypto);
|
|
96
|
-
await writeEncryptedRecord(ctx.transport, ctx.aead, ctx.clientHsTraffic, ContentType.HANDSHAKE, finishedMessage, ctx.clientHsSeq, ctx.crypto);
|
|
168
|
+
await writeEncryptedRecord(ctx.transport, ctx.aead, ctx.clientHsTraffic, ContentType.HANDSHAKE, finishedMessage, ctx.clientHsSeq, ctx.crypto, ctx.onDebug);
|
|
97
169
|
ctx.clientHsSeq++;
|
|
170
|
+
ctx.onDebug?.("phase: client_finished — client Finished sent");
|
|
171
|
+
ctx.currentPhase = "application";
|
|
98
172
|
return applicationSecrets;
|
|
99
173
|
}
|
|
100
174
|
/**
|
|
101
175
|
* Read the server's encrypted second flight message-by-message, advancing the
|
|
102
176
|
* handshake state machine and updating the transcript. Server Finished is
|
|
103
177
|
* verified against the transcript as it stood *before* the Finished message.
|
|
178
|
+
*
|
|
179
|
+
* RFC 8446 §5.1 permits a server to coalesce multiple handshake messages into a
|
|
180
|
+
* single encrypted record. This function buffers messages from a decrypted
|
|
181
|
+
* record and only reads + decrypts the next record when the buffer is drained,
|
|
182
|
+
* so it works correctly whether the server sends one message per record (the
|
|
183
|
+
* simple case) or packs the entire flight into a single record (the common case
|
|
184
|
+
* for real TLS 1.3 servers like Cloudflare, nginx, and OpenSSL).
|
|
104
185
|
*/
|
|
105
186
|
async function consumeServerFlight(ctx, serverName, trustAnchors, now) {
|
|
106
187
|
let phase = recordServerHello({ phase: "client_hello_sent" }, ctx.serverHello);
|
|
188
|
+
// Messages parsed from the current record but not yet consumed. The AEAD
|
|
189
|
+
// sequence number advances once per RECORD (not per message), because all
|
|
190
|
+
// messages in a coalesced record share the same nonce — so we only
|
|
191
|
+
// increment serverHsSeq when actually reading a new record.
|
|
192
|
+
let pendingMessages = [];
|
|
193
|
+
/**
|
|
194
|
+
* Return the next handshake message from the server, reading and decrypting
|
|
195
|
+
* a new record only when no buffered messages remain. This decouples
|
|
196
|
+
* "give me the next handshake message" (what the driver needs) from "read
|
|
197
|
+
* the next record" (the record-layer operation), bridging the gap that
|
|
198
|
+
* caused the coalesced-record stall.
|
|
199
|
+
*/
|
|
200
|
+
async function nextHandshakeMessage() {
|
|
201
|
+
if (pendingMessages.length > 0) {
|
|
202
|
+
const msg = pendingMessages.shift();
|
|
203
|
+
if (msg === undefined) {
|
|
204
|
+
// Length was just checked; this is unreachable but satisfies
|
|
205
|
+
// noUncheckedIndexedAccess without a non-null assertion.
|
|
206
|
+
throw new TlsHandshakeError("encrypted_extensions", {
|
|
207
|
+
cause: new Error("pending message queue emptied between check and shift"),
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
return { whole: msg, body: msg.subarray(4) };
|
|
211
|
+
}
|
|
212
|
+
ctx.onDebug?.(`consumeServerFlight: reading encrypted record, seq=${ctx.serverHsSeq}`);
|
|
213
|
+
const result = await readEncryptedHandshakeMessage(ctx.readBuffer, ctx.transport, ctx.aead, ctx.serverHsTraffic, ctx.serverHsSeq, ctx.crypto, ctx.onDebug);
|
|
214
|
+
ctx.readBuffer = result.readBuffer;
|
|
215
|
+
ctx.serverHsSeq++;
|
|
216
|
+
const messages = splitHandshakeMessages(result.whole);
|
|
217
|
+
ctx.onDebug?.(`consumeServerFlight: split into ${messages.length} handshake message(s)`);
|
|
218
|
+
const first = messages.shift();
|
|
219
|
+
if (first === undefined) {
|
|
220
|
+
throw new TlsHandshakeError("encrypted_extensions", {
|
|
221
|
+
cause: new Error("decrypted record contained no handshake messages"),
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
pendingMessages = messages;
|
|
225
|
+
return { whole: first, body: first.subarray(4) };
|
|
226
|
+
}
|
|
107
227
|
// EncryptedExtensions.
|
|
108
|
-
|
|
109
|
-
ctx.
|
|
110
|
-
|
|
228
|
+
ctx.currentPhase = "encrypted_extensions";
|
|
229
|
+
ctx.onDebug?.("consumeServerFlight: expecting EncryptedExtensions");
|
|
230
|
+
let message = await nextHandshakeMessage();
|
|
111
231
|
phase = advanceHandshake(phase, HandshakeType.ENCRYPTED_EXTENSIONS);
|
|
112
232
|
ctx.transcript.push(message.whole);
|
|
113
233
|
const alpn = parseAlpnFromEncryptedExtensions(message.body);
|
|
114
234
|
if (alpn !== undefined) {
|
|
115
235
|
ctx.alpnProtocol = alpn;
|
|
116
236
|
}
|
|
237
|
+
ctx.onDebug?.(`consumeServerFlight: EncryptedExtensions consumed (alpn=${alpn ?? "none"})`);
|
|
117
238
|
// Certificate.
|
|
118
|
-
|
|
119
|
-
ctx.
|
|
120
|
-
|
|
239
|
+
ctx.currentPhase = "certificate";
|
|
240
|
+
ctx.onDebug?.("consumeServerFlight: expecting Certificate");
|
|
241
|
+
message = await nextHandshakeMessage();
|
|
121
242
|
phase = advanceHandshake(phase, HandshakeType.CERTIFICATE);
|
|
122
243
|
ctx.transcript.push(message.whole);
|
|
123
244
|
const chain = await validateCertificateChain(message.body, serverName, trustAnchors, now, ctx.crypto);
|
|
124
245
|
ctx.peerCertificate = chain.leaf;
|
|
246
|
+
ctx.onDebug?.(`consumeServerFlight: Certificate validated (${chain.intermediates.length} intermediates)`);
|
|
125
247
|
// CertificateVerify.
|
|
126
|
-
|
|
127
|
-
ctx.
|
|
128
|
-
|
|
248
|
+
ctx.currentPhase = "certificate_verify";
|
|
249
|
+
ctx.onDebug?.("consumeServerFlight: expecting CertificateVerify");
|
|
250
|
+
message = await nextHandshakeMessage();
|
|
129
251
|
phase = advanceHandshake(phase, HandshakeType.CERTIFICATE_VERIFY);
|
|
252
|
+
// Verify the signature BEFORE pushing CertificateVerify to the transcript.
|
|
253
|
+
// The signed content covers Transcript-Hash(ClientHello..Certificate) — the
|
|
254
|
+
// transcript at this point still ends at Certificate, which is exactly the
|
|
255
|
+
// content the server signed (RFC 8446 §4.4.3). Pushing afterward would
|
|
256
|
+
// pollute the hash for the Finished verification, which covers
|
|
257
|
+
// ClientHello..CertificateVerify.
|
|
258
|
+
if (ctx.peerCertificate === undefined) {
|
|
259
|
+
throw new TlsHandshakeError("certificate_verify", {
|
|
260
|
+
cause: new Error("CertificateVerify received before a Certificate message was consumed"),
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
ctx.onDebug?.("consumeServerFlight: verifying CertificateVerify signature against leaf cert SPKI");
|
|
264
|
+
verifyCertificateVerify(message.body, ctx.peerCertificate.subjectPublicKeyInfo, ctx.transcript, ctx.hash, ctx.crypto);
|
|
130
265
|
ctx.transcript.push(message.whole);
|
|
266
|
+
ctx.onDebug?.("consumeServerFlight: CertificateVerify signature verified OK");
|
|
131
267
|
// Finished — verify against the transcript *before* appending the Finished.
|
|
268
|
+
ctx.currentPhase = "finished";
|
|
269
|
+
ctx.onDebug?.("consumeServerFlight: expecting Finished, computing transcript hash");
|
|
132
270
|
const finishedTranscript = transcriptHash(ctx.transcript, ctx.hash, ctx.crypto);
|
|
133
|
-
message = await
|
|
134
|
-
ctx.
|
|
135
|
-
ctx.serverHsSeq++;
|
|
271
|
+
message = await nextHandshakeMessage();
|
|
272
|
+
ctx.onDebug?.("consumeServerFlight: verifying server Finished verify_data");
|
|
136
273
|
verifyServerFinished(message.body, finishedTranscript, ctx.hash, ctx.serverHsTrafficSecret, ctx.crypto);
|
|
137
274
|
advanceHandshake(phase, HandshakeType.FINISHED);
|
|
138
275
|
ctx.transcript.push(message.whole);
|
|
276
|
+
ctx.onDebug?.("consumeServerFlight: server Finished verified OK");
|
|
139
277
|
}
|
|
140
278
|
//# sourceMappingURL=handshake-driver.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handshake-driver.js","sourceRoot":"","sources":["../../src/connection/handshake-driver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EACH,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,aAAa,GAGhB,MAAM,2BAA2B,CAAC;AACnC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,CAAC,CAAC;IACpF,MAAM,kBAAkB,GAAG,cAAc,CAAC,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAChF,OAAO,GAAG,MAAM,oBAAoB,EAAE,CAAC;IACvC,GAAG,CAAC,OAAO,EAAE,CAAC,4DAA4D,CAAC,CAAC;IAC5E,oBAAoB,CAAC,OAAO,CAAC,IAAI,EAAE,kBAAkB,EAAE,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,qBAAqB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACxG,gBAAgB,CAAC,KAAK,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;IAChD,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACnC,GAAG,CAAC,OAAO,EAAE,CAAC,kDAAkD,CAAC,CAAC;AACtE,CAAC"}
|
|
@@ -30,14 +30,83 @@ export declare function parseCertificateMessage(body: Uint8Array): CertificateCh
|
|
|
30
30
|
* the validation logic itself.
|
|
31
31
|
*/
|
|
32
32
|
export declare function validateCertificateChain(body: Uint8Array, serverName: string, trustAnchors: readonly Uint8Array[], now: number, provider: CryptoProvider): Promise<CertificateChain>;
|
|
33
|
+
/**
|
|
34
|
+
* Construct the to-be-signed content for a server CertificateVerify
|
|
35
|
+
* (RFC 8446 §4.4.3):
|
|
36
|
+
*
|
|
37
|
+
* ```
|
|
38
|
+
* 64 * 0x20 || "TLS 1.3, server CertificateVerify" || 0x00 || Transcript-Hash(ClientHello..Certificate)
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* The 64 space bytes and the context string form a domain-separation prefix
|
|
42
|
+
* that prevents the signature from being replayed in a different context. The
|
|
43
|
+
* 0x00 byte separates the context string from the transcript hash.
|
|
44
|
+
*
|
|
45
|
+
* Exposed as a pure function so it can be unit-tested in isolation against
|
|
46
|
+
* known-answer test vectors.
|
|
47
|
+
*
|
|
48
|
+
* @param transcriptHashValue Hash(ClientHello..Certificate) — the transcript
|
|
49
|
+
* hash up to and including the Certificate message (NOT including
|
|
50
|
+
* CertificateVerify itself).
|
|
51
|
+
*/
|
|
52
|
+
export declare function certificateVerifySignedContent(transcriptHashValue: Uint8Array): Uint8Array;
|
|
53
|
+
/**
|
|
54
|
+
* Verify a CertificateVerify message (RFC 8446 §4.4.3): confirm the server
|
|
55
|
+
* holds the private key corresponding to the leaf certificate's public key by
|
|
56
|
+
* checking the signature over the transcript hash.
|
|
57
|
+
*
|
|
58
|
+
* This closes the MITM vulnerability where a forged CertificateVerify with a
|
|
59
|
+
* dummy signature was silently accepted. After this check, the client is
|
|
60
|
+
* cryptographically assured that the server owns the leaf certificate's
|
|
61
|
+
* private key.
|
|
62
|
+
*
|
|
63
|
+
* The CertificateVerify body layout is:
|
|
64
|
+
* ```
|
|
65
|
+
* signature_scheme(2) || signature_length(2) || signature(N)
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* Throws {@link TlsHandshakeError} with phase "certificate_verify" on any
|
|
69
|
+
* parsing error or signature mismatch.
|
|
70
|
+
*
|
|
71
|
+
* @param body The CertificateVerify handshake message body (after the
|
|
72
|
+
* 4-byte handshake header).
|
|
73
|
+
* @param leafSpki The leaf certificate's SubjectPublicKeyInfo (DER), as
|
|
74
|
+
* extracted by {@link parseCertificate}.
|
|
75
|
+
* @param transcript The transcript up to and including Certificate — NOT
|
|
76
|
+
* including CertificateVerify. The signed content covers
|
|
77
|
+
* Transcript-Hash(ClientHello..Certificate) per §4.4.3.
|
|
78
|
+
* @param hash The negotiated cipher's hash (SHA-256 or SHA-384).
|
|
79
|
+
* @param provider The injected crypto provider (Platform injection — never
|
|
80
|
+
* node:crypto directly) for hashing + signature verification.
|
|
81
|
+
*/
|
|
82
|
+
export declare function verifyCertificateVerify(body: Uint8Array, leafSpki: Uint8Array, transcript: readonly Uint8Array[], hash: HashId, provider: CryptoProvider): void;
|
|
33
83
|
/** Build the client Finished message bytes under the client handshake traffic key. */
|
|
34
84
|
export declare function buildClientFinishedMessage(hash: HashId, clientHsTrafficSecret: Uint8Array, transcript: readonly Uint8Array[], provider: CryptoProvider): Uint8Array;
|
|
85
|
+
/**
|
|
86
|
+
* Split a decrypted record's content into individual handshake messages.
|
|
87
|
+
*
|
|
88
|
+
* RFC 8446 §5.1 permits a server to coalesce multiple handshake messages into a
|
|
89
|
+
* single TLSCiphertext record. Each message is framed as type(1) || length(3)
|
|
90
|
+
* || body (24-bit length in bytes 1..3), so the content can be split
|
|
91
|
+
* deterministically by walking the framing.
|
|
92
|
+
*
|
|
93
|
+
* When the content holds exactly one message (the non-coalesced case), this
|
|
94
|
+
* returns a single-element array containing the original content unchanged.
|
|
95
|
+
*
|
|
96
|
+
* @param content The full decrypted record content (inner content type byte
|
|
97
|
+
* and trailing zero-padding already stripped by the caller).
|
|
98
|
+
*/
|
|
99
|
+
export declare function splitHandshakeMessages(content: Uint8Array): Uint8Array[];
|
|
35
100
|
/**
|
|
36
101
|
* Read one encrypted handshake message, decrypting and stripping the inner type.
|
|
37
102
|
* Returns the whole handshake message (header + body), the body alone, and the
|
|
38
103
|
* buffer left after consuming the record.
|
|
104
|
+
*
|
|
105
|
+
* When the record contains multiple coalesced handshake messages (RFC 8446
|
|
106
|
+
* §5.1), `whole` holds the concatenation of all messages and the caller must
|
|
107
|
+
* use {@link splitHandshakeMessages} to separate them.
|
|
39
108
|
*/
|
|
40
|
-
export declare function readEncryptedHandshakeMessage(readBuffer: Uint8Array, transport: Transport, aead: Parameters<typeof encryptRecord>[4], traffic: TrafficSecrets, seq: number, provider: CryptoProvider): Promise<{
|
|
109
|
+
export declare function readEncryptedHandshakeMessage(readBuffer: Uint8Array, transport: Transport, aead: Parameters<typeof encryptRecord>[4], traffic: TrafficSecrets, seq: number, provider: CryptoProvider, onDebug?: (msg: string) => void): Promise<{
|
|
41
110
|
whole: Uint8Array;
|
|
42
111
|
body: Uint8Array;
|
|
43
112
|
readBuffer: Uint8Array;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handshake-messages.d.ts","sourceRoot":"","sources":["../../src/connection/handshake-messages.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAIlD,OAAO,EAA8B,KAAK,aAAa,EAAmB,MAAM,qBAAqB,CAAC;AACtG,OAAO,EAAqE,KAAK,gBAAgB,EAAoB,MAAM,iCAAiC,CAAC;AAI7J,6EAA6E;AAC7E,wBAAgB,gCAAgC,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CAerF;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,UAAU,GAAG,gBAAgB,CA6C1E;AAED;;;;;;;GAOG;AACH,wBAAsB,wBAAwB,CAC1C,IAAI,EAAE,UAAU,EAChB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,SAAS,UAAU,EAAE,EACnC,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,cAAc,GACzB,OAAO,CAAC,gBAAgB,CAAC,CAoB3B;AAED,sFAAsF;AACtF,wBAAgB,0BAA0B,CACtC,IAAI,EAAE,MAAM,EACZ,qBAAqB,EAAE,UAAU,EACjC,UAAU,EAAE,SAAS,UAAU,EAAE,EACjC,QAAQ,EAAE,cAAc,GACzB,UAAU,CAWZ;AAED
|
|
1
|
+
{"version":3,"file":"handshake-messages.d.ts","sourceRoot":"","sources":["../../src/connection/handshake-messages.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAA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