我正在编写一个使用 SSLEngine 和 NIO 的应用程序,我编写了客户端和服务器。 客户端能够连接到服务器,连接后我希望他能够执行 session 恢复/重新协商,但目前没有运气..
由于使用 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 session 恢复所需的一些要素?
最佳答案
如果您使用 SSLContext.createEngine(host, port) 创建 SSLEngine,SSLEngine 将仅恢复 session 。 。否则,它无法知道正在与谁通话,因此无法知道要加入哪个 SSLSession
。
关于Java JSSE SSLEngine 无法恢复 SSL session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44946148/