Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,13 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
}
case PgProtocolConstants.MESSAGE_TYPE_SSL_NO: {
upgradePromise.fail(new Exception("Postgres Server does not handle SSL connection"));
// The server waits for a startup message on this socket: close it, PREFER reconnects without SSL
ctx.close();
break;
}
default:
upgradePromise.fail(new Exception("Invalid SSL connection message"));
ctx.close();
break;
}
}
Expand Down
29 changes: 29 additions & 0 deletions vertx-pg-client/src/test/java/io/vertx/tests/pgclient/TLSTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@
import io.vertx.pgclient.*;
import io.vertx.sqlclient.Tuple;
import io.vertx.tests.pgclient.junit.ContainerPgRule;
import io.vertx.tests.sqlclient.ProxyServer;
import org.junit.*;
import org.junit.runner.RunWith;

import java.util.concurrent.atomic.AtomicInteger;

@RunWith(VertxUnitRunner.class)
public class TLSTest {

Expand Down Expand Up @@ -150,6 +153,32 @@ public void testSslModePreferFallback(TestContext ctx) {
}));
}

@Test
public void testSslModeRequireClosesRefusedSocket(TestContext ctx) {
PgConnectOptions options = ruleSllOff.options()
.setSslMode(SslMode.REQUIRE)
.setSslOptions(new ClientSSLOptions().setTrustAll(true));
AtomicInteger openSockets = new AtomicInteger();
ProxyServer proxy = ProxyServer.create(vertx, options.getPort(), options.getHost());
proxy.proxyHandler(conn -> {
openSockets.incrementAndGet();
conn.clientCloseHandler(v -> openSockets.decrementAndGet());
conn.connect();
});
Async listen = ctx.async();
proxy.listen(8080, "localhost", ctx.asyncAssertSuccess(v -> listen.complete()));
listen.awaitSuccess(10000);
options.setPort(8080).setHost("localhost");
Async async = ctx.async();
PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertFailure(err -> {
// The server refused SSL: the client must not keep the socket it opened to ask for it
vertx.setTimer(2000, id -> {
ctx.assertEquals(0, openSockets.get());
async.complete();
});
}));
}

@Test
public void testSslModeVerifyCaConf(TestContext ctx) {
PgConnectOptions options = ruleOptionalSll.options()
Expand Down