0

I have encountered a problem when I try to set up a https server with resteasy-netty4 (http service is OK)

resteasy version 3.0.16.Final
java version 1.8

By searching from stackoverflow and google, I got some solutions, such as Simple Java Https Server.

So, the original demo is running successful, but unfortunately, it didn't work after integrating with NettyJaxrsServer.

I created a sslcontext as below:

    public SSLContext getSSLContext1() throws Exception {
        SSLContext sslContext = SSLContext.getInstance("TLS");

        // initialise the keystore
        char[] password = "password".toCharArray();
        KeyStore ks = KeyStore.getInstance("JKS");
        FileInputStream fis = new FileInputStream("{PARENT_PATH}\\testkey.jks");
        ks.load(fis, password);

        // setup the key manager factory
        KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
        kmf.init(ks, password);

        // setup the trust manager factory
        TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
        tmf.init(ks);

        // setup the HTTPS context and parameters
        sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);

        return SSLContext.getDefault();
    }

and call org.immortal.hydra.gateway.server.JaxrsGatewayServer#setSSLContext to enable https server.

It was okay to start up, but failed to serve.

    Caused by: javax.net.ssl.SSLHandshakeException: no cipher suites in common
    at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
    at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1666)
    at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:304)
    at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:292)
    at sun.security.ssl.ServerHandshaker.chooseCipherSuite(ServerHandshaker.java:1036)
    at sun.security.ssl.ServerHandshaker.clientHello(ServerHandshaker.java:739)
    at sun.security.ssl.ServerHandshaker.processMessage(ServerHandshaker.java:221)
    at sun.security.ssl.Handshaker.processLoop(Handshaker.java:979)
    at sun.security.ssl.Handshaker$1.run(Handshaker.java:919)
    at sun.security.ssl.Handshaker$1.run(Handshaker.java:916)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.security.ssl.Handshaker$DelegatedTask.run(Handshaker.java:1369)
    at io.netty.handler.ssl.SslHandler.runDelegatedTasks(SslHandler.java:1124)
    at io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1009)

If you have any suggestions to fix this, please let me know.

kenmistry
  • 1,934
  • 1
  • 15
  • 24
Vincent
  • 13
  • 5

1 Answers1

0

It looks like you're setting up the SSL context but then returning the default one. Try changing

return SSLContext.getDefault();

to

return sslContext;

Also it's useful to learn how to debug ssl by enabling SSL logging: http://docs.oracle.com/javase/7/docs/technotes/guides/security/jsse/ReadDebug.html

John H
  • 702
  • 3
  • 7
  • debug log are ===>>>>>>> 09:31:41.817 DEBUG [id: 0xdb992ffd, L:/127.0.0.1:8080 - R:/127.0.0.1:56889] HANDSHAKEN: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 - SslHandler.debug – Vincent May 29 '16 at 01:33