Reputation: 608
I have created HTTPS server in vert.x
.
vertx.createHttpServer(
new HttpServerOptions()
.setSsl(true)
.setKeyStoreOptions(new JksOptions()
.setPath("path/to/keystore")
.setPassword("password")
)
).requestHandler( (HttpServerRequest req) -> {
System.out.println("Access.");
req.response().putHeader("Content-Type", "text/html; charset=utf-8");
req.response().end("Hello world!");
// ...
}).listen(80, "localhost");
I have created keystore with keytool
.
keytool -genkeypair -keystore keystore -storetype jks
I have succeeded in deploying verticle. But the server does not response.
Access to https://localhost gives nothing. Even the log is not printed.
What is wrong?
I have tried some options like below.
vertx.createHttpServer(
new HttpServerOptions()
.setSsl(true)
.setKeyStoreOptions(new JksOptions()
.setPath("path/to/keystore")
.setPassword("password")
)
// .setUseAlpn(true)
// .setTrustOptions(new JksOptions()
// .setPath("C:/Recoeve/keystore")
// .setPassword("Xs41Kipid$ps15")
// )
// .setClientAuthRequired(false)
// .setClientAuth(ClientAuth.NONE)
// .addEnabledSecureTransportProtocol(TCPSSLOptions.DEFAULT_ENABLED_SECURE_TRANSPORT_PROTOCOLS.get(1))
// .addEnabledSecureTransportProtocol("TLSv1.3")
// .setEnabledSecureTransportProtocols(TCPSSLOptions.DEFAULT_ENABLED_SECURE_TRANSPORT_PROTOCOLS)
).requestHandler( (HttpServerRequest req) -> {
// ...
}).listen(80, "localhost");
But the code gives runtime exception.
================================================================
Recently editted:
That was a default port problem. I though that default port of HTTPS is also 80.
Take a look at kipid's blog :: Vert.x https (SSL/TLS) server.
And for complete HTTPS server, I think I need to buy RSA keys. Keys from java command (keytool) give warning to clients on access of my server through internet browser.
Upvotes: 2
Views: 3339
Reputation: 11
You can generate the JKS certificate using the below command
keytool -genkeypair -alias aliasName -keyalg RSA -keysize 2048 -keystore keystoreName.jks -validity 3650
You can use the default port of HTTPS ie 443
Upvotes: 1
Reputation: 1
Worked for me as you posted but with the following key store generation:
keytool -genkey -alias server-alias -keyalg RSA -keypass changeit -storepass changeit -keystore keystore.jks -validity 3650
Upvotes: 0
Reputation: 1
Below code works for me:
JksOptions keyOptions = new JksOptions();
keyOptions.setPath("path-to-your/keystore.jks");
keyOptions.setPassword("changeit");
vertx.createHttpServer(
new HttpServerOptions()
.setSsl(true)
.setKeyStoreOptions(keyOptions)
).requestHandler( (HttpServerRequest req) -> {
System.out.println("Access.");
req.response().putHeader("Content-Type", "text/html; charset=utf-8");
req.response().end("Hello SSL world!");
}).listen(8443, "localhost");
Upvotes: 0