我一直在尝试让我的 pyOpenSSL 客户端在连续建立多个连接(它正在发送 http 请求)到 Tomcat 应用程序服务器时使用 TLS/SSL 会话恢复,但没有成功。我很确定服务器端的一切都很好,因为我有几个其他客户端进行了类似的连接,并且他们都能够进行会话恢复。
对于第一个连接,我创建了 ssl 上下文。然后我只是将上下文重用于后续连接
# Just do this for the first and then reuse the context for subsequent connections.
ssl_context = SSL.Context(SSL.SSLv23_METHOD)
ssl_context.set_options(SSL.OP_NO_SSLv2)
# Do this for every connection
sock = socket.create_connection((self.host, self.port), self.timeout)
sslconn = SSL.Connection(ssl_context, sock)
sslconn.set_connect_state()
sslconn.do_handshake()