Java JSSE SSLEngine无法恢复SSL会话

ben*_*nyl 2 java ssl jsse sslengine

我正在编写一个使用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
Run Code Online (Sandbox Code Playgroud)

**我更愿意发布可以提供帮助的代码的任何部分(即使是完整的代码,尽管我说它很大..)

当我执行我的程序时,第一个连接成功但第二个连接导致异常:

javax.net.ssl.SSLHandshakeException: No existing session to resume
Run Code Online (Sandbox Code Playgroud)

我错过了ssl会话恢复所需的一些成分吗?

use*_*421 5

如果使用SSLContext.createEngine(host,port)创建SSLEngine,SSLEngine将仅恢复会话.否则它无法知道它在与谁交谈,所以无法知道SSLSession要加入什么.