mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
test(dsql): pin TLS told apart by its first byte, and fix the timeout a comment names (#6332)
Asked in review on #6296 after it merged: a plaintext startup packet whose length starts with 0x16 is taken for TLS rather than refused as not TLS. DSQL does the same (measured, eu-west-1): such a packet, claiming 0x16000000 or 0x16030100, gets a TLS alert record and a close, never the SSL-mandatory refusal. The direct TLS test now pins that case, which fails against the endpoint as it was before #6296. The same test's comment named the endpoint's handshake timeout as 10 s, the RDS proxy's; DsqlEndpoint's is 30 s.
This commit is contained in:
1 parent
204231d4b3
commit
151cf30476
1 file changed
+13
-3
+13
-3
@@ -198,7 +198,8 @@ class DsqlDataPlaneIntegrationTest {
|
||||
/**
|
||||
* Before TLS, DSQL reads no more of a packet than its length and code (measured): a startup
|
||||
* packet is refused as not TLS whatever length it claims, after a GSSENCRequest too, and one
|
||||
* under 8 bytes ends the connection without a word.
|
||||
* under 8 bytes ends the connection without a word. A length whose first byte is TLS's is read
|
||||
* as TLS (see {@link #tlsWithNoSslRequestFirstIsTakenForTheAlpnProtocolPostgresql}).
|
||||
*/
|
||||
@Test
|
||||
void aPacketBeforeTlsIsRefusedAsNotTlsWhateverItsLength() throws Exception {
|
||||
@@ -231,7 +232,8 @@ class DsqlDataPlaneIntegrationTest {
|
||||
* DSQL takes TLS started at once, with no SSLRequest, from a client offering the ALPN protocol
|
||||
* postgresql, as libpq's and pgjdbc's direct negotiation do, and picks postgresql whenever a
|
||||
* client offers it; a direct handshake without it completes and the connection closes without a
|
||||
* word (measured).
|
||||
* word. A connection is told apart by its first byte alone: a startup packet claiming a length
|
||||
* that starts with 0x16 is read as TLS, and answered with a TLS alert (measured).
|
||||
*/
|
||||
@Test
|
||||
void tlsWithNoSslRequestFirstIsTakenForTheAlpnProtocolPostgresql() throws Exception {
|
||||
@@ -252,7 +254,7 @@ class DsqlDataPlaneIntegrationTest {
|
||||
for (String[] alpn : new String[][] {{}, {"http/1.1"}}) {
|
||||
try (DsqlWireClient client = DsqlWireClient.direct(endpoint.port(), cluster.host(), alpn)) {
|
||||
assertEquals("", client.applicationProtocol(), List.of(alpn).toString());
|
||||
// The endpoint's 10 s handshake timeout would close it too, later: only a close at once is this quick.
|
||||
// The endpoint's 30 s handshake timeout would close it too, later: only a close at once is this quick.
|
||||
assertThrows(EOFException.class, () -> assertTimeoutPreemptively(Duration.ofSeconds(5), client::next),
|
||||
List.of(alpn).toString());
|
||||
}
|
||||
@@ -265,6 +267,14 @@ class DsqlDataPlaneIntegrationTest {
|
||||
assertEquals("", client.applicationProtocol());
|
||||
client.signIn("admin", cluster.adminToken());
|
||||
}
|
||||
try (Socket socket = new Socket("127.0.0.1", endpoint.port())) {
|
||||
byte[] startup = startupOfLength(100);
|
||||
System.arraycopy(PostgresWire.int32(0x16000000), 0, startup, 0, 4);
|
||||
socket.getOutputStream().write(startup);
|
||||
socket.setSoTimeout(5_000);
|
||||
byte[] answer = socket.getInputStream().readAllBytes();
|
||||
assertEquals(0x15, answer[0], "a TLS alert record, not a PostgreSQL message");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user