Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/349.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JSSE SSLEngine无法恢复SSL会话_Java_Ssl_Jsse_Sslengine - Fatal编程技术网

Java JSSE SSLEngine无法恢复SSL会话

Java JSSE SSLEngine无法恢复SSL会话,java,ssl,jsse,sslengine,Java,Ssl,Jsse,Sslengine,我正在编写一个应用程序,它使用SSLEngine和NIO,我同时编写客户端和服务器。 客户端能够连接到服务器,在他连接后,我希望他能够执行会话恢复/重新协商,但目前运气不佳 由于使用SSLEngine的代码相当大(SSLEngine的使用非常复杂!),我将编写一个简单的伪代码来演示这种情况: Server: global sslcontext initialized once await new client client.sslEngine = create new s

我正在编写一个应用程序,它使用SSLEngine和NIO,我同时编写客户端和服务器。 客户端能够连接到服务器,在他连接后,我希望他能够执行会话恢复/重新协商,但目前运气不佳

由于使用SSLEngine的代码相当大(SSLEngine的使用非常复杂!),我将编写一个简单的伪代码来演示这种情况:

Server:
    global sslcontext initialized once
    await new client
    client.sslEngine = create new server ssl engine using the global sslcontext
    client.handleHandshake and wait for it to be done
    handle client.

Client:
    global sslcontext initialized once
    sslEngine = create new client ssl engine using the global sslcontext
    performHandshake and wait for it to be done
    disconnect (close gracefully the connection)
    sslEngine = create new client ssl engine using the global sslcontext
    configure engine to not allow session creation
    performHandshake and wait for it to be done
**我更愿意发布代码中任何有帮助的部分(即使是完整的代码,尽管正如我所说,它是巨大的…)

执行程序时,第一次连接成功,但第二次连接导致异常:

javax.net.ssl.SSLHandshakeException: No existing session to resume

我是否遗漏了ssl会话恢复所需的某些要素?

只有使用创建会话时,SSLEngine才会恢复会话。否则,它无法知道它在和谁说话,因此无法知道要加入什么
SSLSession

SSLContext应该是singleton。 您可以使用SslContextBuilder。工作按会话ID恢复会话

private  SslContext sslContext;
...

if (serverSSLContext == null) {
    serverSSLContext = SslContextBuilder.forServer(new File("cert.crt"), new File("cert.key")).build();
}
channelPipeLine.addLast(serverSSLContext.newHandler(channelPipeLine.channel().alloc()));

非常感谢你-你刚刚完成了3天的无休止的谷歌搜索:)@bennyl它没有记录,也不是很明显,但当你想到它时,它一定是这样的…我不认为它一定是那样的-因为SSLEngine与传输层是分离的,我认为,通过使用相同的SSLContext创建两个SSLEngine,它们将共享相同的SSLSession缓存…@bennyl SSLEngine只有一种方法可以知道目标IP:端口,这就是它。从清晨到傍晚,它看不到插座通道或插座。