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

@@ -125,6 +125,12 @@ public class MySqlProtocolHandler {
// permanently one behind the client's for the rest of the connection phase.
sequenceOffset = 1;
clientResponseRaw[3] = (byte) (clientResponseRaw[3] - sequenceOffset);
// Real clients keep CLIENT_SSL set in the HandshakeResponse they send over the
// now-encrypted stream. The backend connection stays plaintext, and a MySQL server
// treats any first packet with CLIENT_SSL as an SSLRequest — it would sit waiting for
// a TLS ClientHello that never comes while the proxy waits for its auth verdict,
// deadlocking the connection. Clear the bit (the mirror of forceClientSslCapability).
clearClientSslCapability(clientResponseRaw);
} else {
clientResponseRaw = clientFirstRaw;
if (clientResponseRaw.length < 40) {
@@ -259,6 +265,15 @@ public class MySqlProtocolHandler {
}
}
/**
* Clears the {@code CLIENT_SSL} bit in a raw HandshakeResponse41 packet's capability flags.
* The client capabilities are the first 4 payload bytes, little-endian; {@code CLIENT_SSL}
* (0x0800) lives in the second byte.
*/
private static void clearClientSslCapability(byte[] raw) {
raw[5] &= (byte) ~(CLIENT_SSL >> 8);
}
/**
* Sets the {@code CLIENT_SSL} bit in a raw Handshake V10 packet's capability flags, so the
* client is offered TLS even when the (plaintext) backend didn't advertise it. Walks the same