mirror of
https://github.com/floci-io/floci.git
synced 2026-11-28 16:11:48 -05:00
fix(dsql): take TLS started with no SSLRequest, as DSQL does (#6296)
DSQL's own connectors, and libpq's and pgjdbc's sslnegotiation=direct, start TLS at once with no SSLRequest. The endpoint read their ClientHello as a plaintext startup packet and refused it as not TLS. The endpoint now reads a connection's first byte. A TLS handshake record goes straight to the handshake with that byte handed back, and anything else takes the SSLRequest path as before. The byte is TlsProxyServer's TLS_HANDSHAKE, now public, the one the TLS proxy already tells TLS apart by; its peek runs on a Vert.x socket, the endpoint's on a blocking one, so only the constant is shared. As DSQL does (measured, eu-west-1): the endpoint picks the ALPN protocol postgresql whenever a client offers it, after an SSLRequest too, and none otherwise; a direct handshake that does not end with postgresql picked completes and the connection closes without a message. DsqlWireClient opens TLS through one handshake helper, with an ALPN list, after an SSLRequest (tls) or at once (direct), and signs in separately.
This commit is contained in:
1 parent
d3359662e5
commit
1f25fd88cf
6 files changed
+155
-28
No files matched your search
@@ -179,11 +179,33 @@ class DsqlCompatTest {
|
||||
.hasMessageContaining("Wrong user to action mapping. user: admin, action: DbConnect");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void adminSignsInWithTlsStartedAtOnce() throws Exception {
|
||||
String token = dsql.utilities().generateDbConnectAdminAuthToken(b -> b.hostname(endpoint).region(REGION));
|
||||
|
||||
try (Connection connection = connect("admin", token, "direct");
|
||||
Statement statement = connection.createStatement();
|
||||
ResultSet row = statement.executeQuery("SELECT current_user")) {
|
||||
assertThat(row.next()).isTrue();
|
||||
assertThat(row.getString(1)).isEqualTo("admin");
|
||||
}
|
||||
}
|
||||
|
||||
private static Connection connect(String user, String token) throws SQLException {
|
||||
return connect(user, token, "postgres");
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code sslNegotiation} is pgjdbc's: {@code postgres} sends an SSLRequest first, {@code direct}
|
||||
* starts TLS at once, offering the ALPN protocol postgresql.
|
||||
*/
|
||||
private static Connection connect(String user, String token, String sslNegotiation) throws SQLException {
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty("user", user);
|
||||
properties.setProperty("password", token);
|
||||
properties.setProperty("sslmode", "require");
|
||||
properties.setProperty("sslNegotiation", sslNegotiation);
|
||||
properties.setProperty("sslfactory", ServerNameSocketFactory.class.getName());
|
||||
properties.setProperty(SERVER_NAME_PROPERTY, endpoint);
|
||||
String host = TestFixtures.endpoint().getHost();
|
||||
|
||||
Reference in new issue
Block a user