0

尝试用resteasy-netty4搭建https服务器时遇到问题(http服务还可以)

resteasy version 3.0.16.Final
java version 1.8

通过 stackoverflow 和 google 搜索,我得到了一些解决方案,例如 Simple Java Https Server

所以,原来的demo运行成功了,可惜在和NettyJaxrsServer集成之后就不行了。

我创建了一个 sslcontext,如下所示:

    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();
    }

并调用 org.immortal.hydra.gateway.server.JaxrsGatewayServer#setSSLContext 来启用 https 服务器。

启动没问题,但服务失败。

    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)

如果您有任何解决此问题的建议,请告诉我。

4

1 回答 1

0

看起来您正在设置 SSL 上下文,但随后返回默认上下文。尝试改变

return SSLContext.getDefault();

return sslContext;

通过启用 SSL 日志记录来了解如何调试 ssl 也很有用:http: //docs.oracle.com/javase/7/docs/technotes/guides/security/jsse/ReadDebug.html

于 2016-05-28T17:54:20.963 回答