fix(rds): clear CLIENT_SSL before forwarding the TLS-terminated handshake response to the backend (#2698)

Real MySQL clients keep CLIENT_SSL set in the HandshakeResponse41 they send
over the encrypted stream after the SSLRequest. The proxy terminates TLS
itself and forwards that response to the plaintext backend verbatim, and a
MySQL server treats any first packet carrying CLIENT_SSL as an SSLRequest:
it waits for a TLS ClientHello that never comes while the proxy waits in
relayConnectionPhase for an auth verdict that never comes. Every TLS
connection through the proxy (mysql's default ssl-mode PREFERRED included)
hung until the client timed out; only --ssl-mode=DISABLED worked.

Clear the bit before the response reaches the backend, mirroring
forceClientSslCapability on the server handshake. The TLS tests now send
real-client-shaped responses (CLIENT_SSL set) and assert the backend never
sees the bit; the assertion fails without this fix.
This commit is contained in:
Matan Baruch authored and GitHub committed 2026-08-28 22:23:41 -04:00
1 parent 14112b8ace
commit 0090739617
2 files changed
+34 -4

No files matched your search

@@ -153,8 +153,11 @@ class MySqlProtocolHandlerTest {
byte[] scramble = scrambleNativePassword("secret", nonce);
// Real clients send this at sequence 2 after the TLS upgrade — the proxy must
// rewrite it to 1 before forwarding to the (plaintext-only) backend.
byte[] response = buildHandshakeResponse41("admin", scramble, (byte) 2);
// rewrite it to 1 before forwarding to the (plaintext-only) backend. They also
// keep CLIENT_SSL set in it; a real backend would treat a first packet carrying
// that bit as an SSLRequest and hang waiting for a TLS handshake.
byte[] response = buildHandshakeResponse41("admin", scramble, (byte) 2,
CLIENT_PROTOCOL_41 | CLIENT_SECURE_CONNECTION | CLIENT_SSL);
tlsOut.write(response);
tlsOut.flush();
@@ -178,6 +181,11 @@ class MySqlProtocolHandlerTest {
assertEquals((byte) 1, backendResponseSeq.get(),
"backend never saw the SSLRequest, so it must receive the real response at sequence 1");
assertEquals("admin", extractUsername(backendResponsePayload.get()));
int backendCaps = (backendResponsePayload.get()[0] & 0xFF)
| ((backendResponsePayload.get()[1] & 0xFF) << 8);
assertEquals(0, backendCaps & CLIENT_SSL,
"the plaintext backend must not see CLIENT_SSL, or it treats the response as an "
+ "SSLRequest and waits forever for a TLS handshake");
}
@Test
@@ -238,7 +246,8 @@ class MySqlProtocolHandlerTest {
OutputStream tlsOut = sslClient.getOutputStream();
byte[] scramble = scrambleNativePassword("secret", nonce);
byte[] response = buildHandshakeResponse41("admin", scramble, (byte) 2);
byte[] response = buildHandshakeResponse41("admin", scramble, (byte) 2,
CLIENT_PROTOCOL_41 | CLIENT_SECURE_CONNECTION | CLIENT_SSL);
tlsOut.write(response);
tlsOut.flush();
@@ -352,8 +361,14 @@ class MySqlProtocolHandlerTest {
private static byte[] buildHandshakeResponse41(String username, byte[] scramble, byte sequence)
throws IOException {
return buildHandshakeResponse41(username, scramble, sequence,
CLIENT_PROTOCOL_41 | CLIENT_SECURE_CONNECTION);
}
private static byte[] buildHandshakeResponse41(String username, byte[] scramble, byte sequence,
int capabilities) throws IOException {
ByteArrayOutputStream payload = new ByteArrayOutputStream();
writeInt32LE(payload, CLIENT_PROTOCOL_41 | CLIENT_SECURE_CONNECTION);
writeInt32LE(payload, capabilities);
writeInt32LE(payload, 0); // max packet size
payload.write(0x21); // charset
payload.write(new byte[23]); // reserved