【问题标题】:Java JSSE SSLEngine cannot resume SSL sessionJava JSSE SSLEngine 无法恢复 SSL 会话
【发布时间】:2012-05-23 05:17:04
【问题描述】:

我正在编写一个使用 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 会话所需的一些要素?

【问题讨论】:

    标签: java ssl jsse sslengine


    【解决方案1】:

    SSLContext 应该是单例的。 你可以使用netty 4.0.44.FinalSslContextBuilder。按 sessionId 恢复会话。

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

    【讨论】:

      【解决方案2】:

      只有在您使用SSLContext.createEngine(host, port) 创建时,SSLEngine 才会恢复会话。否则它无法知道它在与谁交谈,因此无法知道SSLSession 要加入什么。

      【讨论】:

      • 非常感谢 - 你刚刚完成了 3 天无休止的谷歌搜索 :)
      • @bennyl 没有文档记录,也不是很明显,但是仔细想想一定是这样的......
      • 我不认为它必须是那样 - 因为 SSLEngine 与传输层分离,我认为通过使用相同的 SSLContext 来创建 2 个 SSLEngine,它们将共享相同的 SSLSession 缓存。 .
      • @bennyl SSLEngine只有一种方法可以知道目标IP:端口,就是这样。从清晨到深夜,它没有看到 SocketChannel 或 Socket。
      猜你喜欢
      • 2012-03-29
      • 1970-01-01
      • 1970-01-01
      • 2012-04-29
      • 2011-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多