Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring Jetty with SSL/TLS and Keystore

I have created key and certificate, signed by root CA using OpenSSL. I'm trying to use server.key file as keystore and performing it in code:

private fun setupHttps(server : Server, port: Int) {
val https = HttpConfiguration()
https.addCustomizer(SecureRequestCustomizer())

val sslFactory = SslContextFactory()
sslFactory.keyStorePath = Paths.get(System.getProperty("user.dir"), "..", "server.key").toString()
sslFactory.setKeyStorePassword("password")

val sslConnector = ServerConnector(
    server,
    SslConnectionFactory(sslFactory, "http/1.1"),
    HttpConnectionFactory(https)
)

sslConnector.port = port
server.connectors = arrayOf(sslConnector)

}

But I had this exception:

Exception in thread "main" java.lang.IllegalStateException: no valid keystore
    at org.eclipse.jetty.util.security.CertificateUtils.getKeyStore(CertificateUtils.java:48)
    at org.eclipse.jetty.util.ssl.SslContextFactory.loadKeyStore(SslContextFactory.java:998)
    at org.eclipse.jetty.util.ssl.SslContextFactory.load(SslContextFactory.java:252)
    at org.eclipse.jetty.util.ssl.SslContextFactory.doStart(SslContextFactory.java:219)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:113)
    at org.eclipse.jetty.server.SslConnectionFactory.doStart(SslConnectionFactory.java:72)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:113)
    at org.eclipse.jetty.server.AbstractConnector.doStart(AbstractConnector.java:270)
    at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:81)
    at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:236)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.eclipse.jetty.server.Server.doStart(Server.java:431)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at ru.servicesmarket.server.LaunchKt.main(launch.kt:44)
like image 721
Timofey Avatar asked Feb 25 '17 07:02

Timofey


1 Answers

I believe this is a problem with your path / location of the keystore. This exception is thrown when the keystore is not found, which is kind of confusing.

like image 132
Moby Avatar answered Oct 09 '22 00:10

Moby