Skip to content

Commit 8a7fad3

Browse files
committed
Deprecate SelfSignedCertificate and update accordingly.
Motivation: SelfSignedCertificate does not work consistently on stock Java distribution and requires Bouncy Castle. As consequence it cannot really be used for testing and is complicated to test as well. Changes: - Deprecate SelfSignedCertificate - Replace usage of SelfSignedCertificate in testing - Remove SelfSignedCertificate from documentation
1 parent cc8b149 commit 8a7fad3

File tree

6 files changed

+12
-143
lines changed

6 files changed

+12
-143
lines changed

vertx-core/pom.xml

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@
158158
<version>${apacheds-protocol-dns.version}</version>
159159
<exclusions>
160160
<exclusion>
161-
<groupId>bouncycastle</groupId>
162-
<artifactId>bcprov-jdk15</artifactId>
161+
<groupId>org.bouncycastle</groupId>
162+
<artifactId>*</artifactId>
163163
</exclusion>
164164
</exclusions>
165165
<scope>test</scope>
@@ -180,20 +180,6 @@
180180
<artifactId>log4j-core</artifactId>
181181
<scope>test</scope>
182182
</dependency>
183-
184-
<dependency>
185-
<groupId>org.bouncycastle</groupId>
186-
<artifactId>bcpkix-jdk15on</artifactId>
187-
<version>${org.bouncycastle.version}</version>
188-
<scope>test</scope>
189-
</dependency>
190-
<dependency>
191-
<groupId>org.bouncycastle</groupId>
192-
<artifactId>bcprov-jdk15on</artifactId>
193-
<version>${org.bouncycastle.version}</version>
194-
<scope>test</scope>
195-
</dependency>
196-
197183
<dependency>
198184
<groupId>io.netty</groupId>
199185
<artifactId>netty-tcnative-boringssl-static</artifactId>

vertx-core/src/main/asciidoc/net.adoc

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -710,35 +710,6 @@ NOTE: The options object is compared (using `equals`) against the existing optio
710710
are equals since loading options can be costly. When object are equals, you can use the `force` parameter to force
711711
the update.
712712

713-
==== Self-signed certificates for testing and development purposes
714-
715-
CAUTION: Do not use this in production settings, and note that the generated keys are very insecure.
716-
717-
It is very often the case that self-signed certificates are required, be it for unit / integration tests or for
718-
running a development version of an application.
719-
720-
{@link io.vertx.core.net.SelfSignedCertificate} can be used to provide self-signed PEM certificate helpers and
721-
give {@link io.vertx.core.net.KeyCertOptions} and {@link io.vertx.core.net.TrustOptions} configurations:
722-
723-
[source,$lang]
724-
----
725-
{@link examples.NetExamples#example48}
726-
----
727-
728-
The client can also be configured to trust all certificates:
729-
730-
[source,$lang]
731-
----
732-
{@link examples.NetExamples#example49}
733-
----
734-
735-
Note that self-signed certificates also work for other TCP protocols like HTTPS:
736-
737-
[source,$lang]
738-
----
739-
{@link examples.NetExamples#example50}
740-
----
741-
742713
==== Revoking certificate authorities
743714

744715
Trust can be configured to use a certificate revocation list (CRL) for revoked certificates that should no

vertx-core/src/main/java/examples/NetExamples.java

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -642,52 +642,12 @@ public void nonProxyHosts(Vertx vertx) {
642642
NetClient client = vertx.createNetClient(options);
643643
}
644644

645-
public void example48(Vertx vertx) throws CertificateException {
646-
SelfSignedCertificate certificate = SelfSignedCertificate.create();
647-
648-
NetServerOptions serverOptions = new NetServerOptions()
649-
.setSsl(true)
650-
.setKeyCertOptions(certificate.keyCertOptions())
651-
.setTrustOptions(certificate.trustOptions());
652-
653-
vertx.createNetServer(serverOptions)
654-
.connectHandler(socket -> socket.end(Buffer.buffer("Hello!")))
655-
.listen(1234, "localhost");
656-
657-
NetClientOptions clientOptions = new NetClientOptions()
658-
.setSsl(true)
659-
.setKeyCertOptions(certificate.keyCertOptions())
660-
.setTrustOptions(certificate.trustOptions());
661-
662-
NetClient client = vertx.createNetClient(clientOptions);
663-
client
664-
.connect(1234, "localhost")
665-
.onComplete(ar -> {
666-
if (ar.succeeded()) {
667-
ar.result().handler(buffer -> System.out.println(buffer));
668-
} else {
669-
System.err.println("Woops: " + ar.cause().getMessage());
670-
}
671-
});
672-
}
673-
674645
public void example49() {
675646
NetClientOptions clientOptions = new NetClientOptions()
676647
.setSsl(true)
677648
.setTrustAll(true);
678649
}
679650

680-
public void example50(Vertx vertx) throws CertificateException {
681-
SelfSignedCertificate certificate = SelfSignedCertificate.create();
682-
683-
vertx.createHttpServer(new HttpServerOptions()
684-
.setSsl(true)
685-
.setKeyCertOptions(certificate.keyCertOptions())
686-
.setTrustOptions(certificate.trustOptions()))
687-
.requestHandler(req -> req.response().end("Hello!"))
688-
.listen(8080);
689-
}
690-
691651
public void example51(Vertx vertx) {
692652
NetServerOptions options = new NetServerOptions().setUseProxyProtocol(true);
693653
NetServer server = vertx.createNetServer(options);

vertx-core/src/main/java/io/vertx/core/net/SelfSignedCertificate.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
* While it helps for testing and development, it should never ever be used in production settings.
2222
*
2323
* @author <a href="https://julien.ponge.org/">Julien Ponge</a>
24+
* @deprecated this class does not work reliably and consistently on stock Java distributions
2425
*/
26+
@Deprecated(forRemoval = true)
2527
@DataObject
2628
public interface SelfSignedCertificate {
2729

vertx-core/src/test/java/io/vertx/tests/net/NetTest.java

Lines changed: 4 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,17 +1378,16 @@ public void testSpecificTlsProtocolVersion() throws Exception {
13781378

13791379
@Test
13801380
public void testTLSTrailingDotHost() throws Exception {
1381-
// We just need a vanilla cert for this test
1382-
SelfSignedCertificate cert = SelfSignedCertificate.create("host2.com");
1381+
// Reuse SNI test certificate because it is convenient
13831382
TLSTest test = new TLSTest()
1384-
.clientTrust(cert::trustOptions)
1383+
.clientTrust(Trust.SNI_JKS_HOST2)
13851384
.connectAddress(SocketAddress.inetSocketAddress(DEFAULT_HTTPS_PORT, "host2.com."))
13861385
.bindAddress(SocketAddress.inetSocketAddress(DEFAULT_HTTPS_PORT, "host2.com"))
1387-
.serverCert(cert::keyCertOptions);
1386+
.serverCert(Cert.SNI_JKS).sni(true);
13881387
test.run(true);
13891388
await();
13901389
assertEquals("host2.com", cnOf(test.clientPeerCert()));
1391-
assertNull(test.indicatedServerName);
1390+
assertEquals("host2.com", test.indicatedServerName);
13921391
}
13931392

13941393
@Test
@@ -3371,55 +3370,6 @@ public void testClientLocalAddress() {
33713370
await();
33723371
}
33733372

3374-
@Test
3375-
public void testSelfSignedCertificate() throws Exception {
3376-
assumeTrue(PlatformDependent.javaVersion() < 9);
3377-
3378-
CountDownLatch latch = new CountDownLatch(2);
3379-
3380-
SelfSignedCertificate certificate = SelfSignedCertificate.create();
3381-
3382-
NetServerOptions serverOptions = new NetServerOptions()
3383-
.setSsl(true)
3384-
.setKeyCertOptions(certificate.keyCertOptions())
3385-
.setTrustOptions(certificate.trustOptions());
3386-
3387-
NetClientOptions clientOptions = new NetClientOptions()
3388-
.setSsl(true)
3389-
.setKeyCertOptions(certificate.keyCertOptions())
3390-
.setTrustOptions(certificate.trustOptions());
3391-
3392-
NetClientOptions clientTrustAllOptions = new NetClientOptions()
3393-
.setSsl(true)
3394-
.setTrustAll(true);
3395-
3396-
server = vertx.createNetServer(serverOptions)
3397-
.connectHandler(socket -> {
3398-
socket.end(Buffer.buffer("123"));
3399-
});
3400-
server.listen(testAddress).onComplete(onSuccess(s -> {
3401-
3402-
client = vertx.createNetClient(clientOptions);
3403-
client.connect(testAddress).onComplete(onSuccess(socket -> {
3404-
socket.handler(buffer -> {
3405-
assertEquals("123", buffer.toString());
3406-
latch.countDown();
3407-
});
3408-
}));
3409-
3410-
client = vertx.createNetClient(clientTrustAllOptions);
3411-
client.connect(testAddress).onComplete(onSuccess(socket -> {
3412-
socket.handler(buffer -> {
3413-
assertEquals("123", buffer.toString());
3414-
latch.countDown();
3415-
});
3416-
}));
3417-
3418-
}));
3419-
3420-
awaitLatch(latch);
3421-
}
3422-
34233373
@Test
34243374
public void testWorkerClient() throws Exception {
34253375
String expected = TestUtils.randomAlphaString(2000);

vertx-core/src/test/java/io/vertx/tests/tls/HttpTLSTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,11 +322,11 @@ public void testTLSMatchingProtocolVersions() throws Exception {
322322
}
323323

324324
@Test
325-
// Provide an host name with a trailing dot
325+
// Provide a host name with a trailing dot
326326
public void testTLSTrailingDotHost() throws Exception {
327-
// We just need a vanilla cert for this test
328-
SelfSignedCertificate cert = SelfSignedCertificate.create("host2.com");
329-
TLSTest test = testTLS(Cert.NONE, cert::trustOptions, cert::keyCertOptions, Trust.NONE)
327+
// Reuse SNI test certificate because it is convenient
328+
TLSTest test = testTLS(Cert.NONE, Trust.SNI_JKS_HOST2, Cert.SNI_JKS, Trust.NONE)
329+
.serverSni()
330330
.requestOptions(new RequestOptions().setSsl(true).setPort(DEFAULT_HTTPS_PORT).setHost("host2.com."))
331331
.pass();
332332
assertEquals("host2.com", TestUtils.cnOf(test.clientPeerCert()));

0 commit comments

Comments
 (0)