Skip to content

Commit 98b0b73

Browse files
committed
Add reproducer for missing hostname verification for MySQL and update the PG test
1 parent cc56071 commit 98b0b73

File tree

3 files changed

+52
-8
lines changed

3 files changed

+52
-8
lines changed

vertx-mysql-client/src/test/java/io/vertx/mysqlclient/MySQLTLSTest.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
import io.vertx.core.Future;
1515
import io.vertx.core.Vertx;
16+
import io.vertx.core.VertxOptions;
17+
import io.vertx.core.buffer.Buffer;
18+
import io.vertx.core.dns.AddressResolverOptions;
1619
import io.vertx.core.net.PemKeyCertOptions;
1720
import io.vertx.core.net.PemTrustOptions;
1821
import io.vertx.ext.unit.TestContext;
@@ -260,6 +263,53 @@ public void testConnFailWithVerifyIdentitySslMode(TestContext ctx) {
260263
}));
261264
}
262265

266+
@Test
267+
public void testTLSInvalidHostname(TestContext ctx) {
268+
MySQLConnection.connect(
269+
vertx,
270+
options
271+
.setSslMode(SslMode.VERIFY_IDENTITY)
272+
// The hostname in the test certificate is MySQL_Server_8.0.17_Auto_Generated_Server_Certificate,
273+
// so 'localhost' should make for a failed connection
274+
.setHost("localhost")
275+
.setHostnameVerificationAlgorithm("HTTPS")
276+
.setPemTrustOptions(new PemTrustOptions().addCertPath("tls/files/ca.pem"))
277+
.setPemKeyCertOptions(new PemKeyCertOptions()
278+
.setCertPath("tls/files/client-cert.pem")
279+
.setKeyPath("tls/files/client-key.pem")),
280+
ctx.asyncAssertFailure(err -> {
281+
ctx.assertEquals(err.getMessage(), "No name matching localhost found");
282+
}));
283+
}
284+
285+
@Test
286+
public void testTLSCorrectHostname(TestContext ctx) {
287+
Vertx vertxWithHosts = Vertx.vertx(
288+
new VertxOptions()
289+
.setAddressResolverOptions(
290+
new AddressResolverOptions()
291+
.setHostsValue(Buffer.buffer("127.0.0.1 MySQL_Server_8.0.17_Auto_Generated_Server_Certificate\n"))
292+
)
293+
);
294+
295+
MySQLConnection.connect(
296+
vertxWithHosts,
297+
options
298+
.setSslMode(SslMode.VERIFY_IDENTITY)
299+
// The hostname in the test certificate is MySQL_Server_8.0.17_Auto_Generated_Server_Certificate,
300+
// so 'localhost' should make for a failed connection
301+
.setHost("MySQL_Server_8.0.17_Auto_Generated_Server_Certificate")
302+
.setHostnameVerificationAlgorithm("HTTPS")
303+
.setPemTrustOptions(new PemTrustOptions().addCertPath("tls/files/ca.pem"))
304+
.setPemKeyCertOptions(new PemKeyCertOptions()
305+
.setCertPath("tls/files/client-cert.pem")
306+
.setKeyPath("tls/files/client-key.pem")),
307+
ctx.asyncAssertSuccess(conn -> {
308+
ctx.assertTrue(conn.isSSL());
309+
vertxWithHosts.close();
310+
}));
311+
}
312+
263313
@Test
264314
public void testConnFail(TestContext ctx) {
265315
options.setSslMode(SslMode.REQUIRED);

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,7 @@ public void testTLSInvalidHostname(TestContext ctx) {
107107
// The hostname in the test certificate is thebrain.ca, so 'localhost' should make for a failed connection
108108
.setHost("localhost")
109109
.setHostnameVerificationAlgorithm("HTTPS")
110-
.setPemTrustOptions(
111-
new PemTrustOptions()
112-
.addCertValue(vertx.fileSystem().readFileBlocking("tls/server.crt"))
113-
),
110+
.setPemTrustOptions(new PemTrustOptions().addCertPath("tls/server.crt")),
114111
ctx.asyncAssertFailure(err -> {
115112
ctx.assertEquals(err.getMessage(), "SSL handshake failed");
116113
async.complete();
@@ -134,10 +131,7 @@ public void testTLSCorrectHostname(TestContext ctx) {
134131
.setSslMode(SslMode.VERIFY_FULL)
135132
.setHost("thebrain.ca")
136133
.setHostnameVerificationAlgorithm("HTTPS")
137-
.setPemTrustOptions(
138-
new PemTrustOptions()
139-
.addCertValue(vertxWithHosts.fileSystem().readFileBlocking("tls/server.crt"))
140-
),
134+
.setPemTrustOptions(new PemTrustOptions().addCertPath("tls/server.crt")),
141135
ctx.asyncAssertSuccess(conn -> {
142136
ctx.assertTrue(conn.isSSL());
143137
vertxWithHosts.close();

vertx-pg-client/src/test/resources/tls/ssl.sh

100644100755
File mode changed.

0 commit comments

Comments
 (0)