Skip to content

Commit cc56071

Browse files
committed
Add reproducer for missing hostname verification
1 parent 4cdf60f commit cc56071

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

vertx-pg-client/src/test/java/io/vertx/pgclient/TLSTest.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
package io.vertx.pgclient;
1919

2020
import io.vertx.core.Vertx;
21+
import io.vertx.core.VertxOptions;
22+
import io.vertx.core.buffer.Buffer;
23+
import io.vertx.core.dns.AddressResolverOptions;
2124
import io.vertx.core.net.PemTrustOptions;
2225
import io.vertx.ext.unit.Async;
2326
import io.vertx.ext.unit.TestContext;
@@ -94,6 +97,54 @@ public void testTLSInvalidCertificate(TestContext ctx) {
9497
}));
9598
}
9699

100+
@Test
101+
public void testTLSInvalidHostname(TestContext ctx) {
102+
Async async = ctx.async();
103+
PgConnection.connect(
104+
vertx,
105+
rule.options()
106+
.setSslMode(SslMode.VERIFY_FULL)
107+
// The hostname in the test certificate is thebrain.ca, so 'localhost' should make for a failed connection
108+
.setHost("localhost")
109+
.setHostnameVerificationAlgorithm("HTTPS")
110+
.setPemTrustOptions(
111+
new PemTrustOptions()
112+
.addCertValue(vertx.fileSystem().readFileBlocking("tls/server.crt"))
113+
),
114+
ctx.asyncAssertFailure(err -> {
115+
ctx.assertEquals(err.getMessage(), "SSL handshake failed");
116+
async.complete();
117+
}));
118+
}
119+
120+
@Test
121+
public void testTLSCorrectHostname(TestContext ctx) {
122+
Vertx vertxWithHosts = Vertx.vertx(
123+
new VertxOptions()
124+
.setAddressResolverOptions(
125+
new AddressResolverOptions()
126+
.setHostsValue(Buffer.buffer("127.0.0.1 thebrain.ca\n"))
127+
)
128+
);
129+
130+
Async async = ctx.async();
131+
PgConnection.connect(
132+
vertxWithHosts,
133+
rule.options()
134+
.setSslMode(SslMode.VERIFY_FULL)
135+
.setHost("thebrain.ca")
136+
.setHostnameVerificationAlgorithm("HTTPS")
137+
.setPemTrustOptions(
138+
new PemTrustOptions()
139+
.addCertValue(vertxWithHosts.fileSystem().readFileBlocking("tls/server.crt"))
140+
),
141+
ctx.asyncAssertSuccess(conn -> {
142+
ctx.assertTrue(conn.isSSL());
143+
vertxWithHosts.close();
144+
async.complete();
145+
}));
146+
}
147+
97148
@Test
98149
public void testSslModeDisable(TestContext ctx) {
99150
Async async = ctx.async();

0 commit comments

Comments
 (0)