0
votes

I am trying to test an SSL connection between a Vertx HttpServer and HttpClient. Because I don't have any certificates, I created some self signed certificate like this:

keytool -genkeypair -alias selfsigned -keyalg RSA -keystore keystore.jks -storepass pass -keysize 2048 -validity 360

I have generated a public certificate as such:

keytool -export -alias selfsigned -keystore keystore.jks -rfc -file public.cert

And then I

keytool -import -file public.cert -alias public -keystore trustStore.jks

Then I tried adding them as JksOptions to the Server and Client in any possible order I could imagine and all of them generate the same error on the client side:

Future{cause=Failed to create SSL connection}

I don't understand what I do wrong and as much as I read about keystores and truststores, any combination didn't work for my program. If I set the client as trustAll(true), the connection happens succesfully.

Here are the settings for the server and the client:

   HttpServerOptions httpServerOptions = new HttpServerOptions();
        JksOptions options = new JksOptions();
        options
            .setPassword("pass")
            .setPath("src/main/resources/file/keystore.jks");
        httpServerOptions
            .setSsl(true)
            .setKeyStoreOptions(options);

    HttpClientOptions httpClientOptions = new HttpClientOptions();
    JksOptions options = new JksOptions();
    options
        .setPassword("pass")
        .setPath("src/main/resources/file/trustStore.jks");
    HttpClient client = vertx.createHttpClient(httpClientOptions
            .setSsl(true)
            .setTrustStoreOptions(options)
    );

The code above appears in 2 separate Verticles and is run separately. What could be the issue?

  • I have checked and the certificate does appear both in the keystore and truststore
  • The CN = localhost, cause ultimately my client websocket does the following: client.webSocket(8080, "127.0.0.1",...
  • I tried setting .setVerifyHost(false), same result
  • I have tried the solutions in the other questions and they didn't work
1
If you are going to use unsigned certificates than the only way to make this work is to add the conf you already suggested trustAll(true) - Pendula
Ah so I cannot use self-signed certificates like this for testing purposes? - Charlotte45

1 Answers

1
votes

Here are the steps needed to create self signed certificates and to use the in vertx. Preparing keystore:

keytool -genkey -alias server-alias -keyalg RSA -keypass changeit -storepass changeit -keystore keystore.jks

keytool -export -alias server-alias -storepass changeit -file server.cer -keystore keystore.jks

keytool -import -v -trustcacerts -alias server-alias -file server.cer -keystore cacerts.jks -keypass changeit -storepass changeit

Here is vertx code:

vertx.createHttpServer(new HttpServerOptions()
                .setSsl(true)
                .setKeyStoreOptions(new JksOptions().setPassword("changeit")
                        .setPath("keystore.jks")))
                .requestHandler(req -> req.response().end("Hello!"))
                .listen(9999, "127.0.0.1");

HttpClient client = vertx.createHttpClient(new HttpClientOptions()
                .setVerifyHost(false)
                .setSsl(true)
                .setTrustStoreOptions(new JksOptions().setPassword("changeit")
                .setPath("keystore.jks")));