PyOpenSSL 和 openssl 1.1.1g

问题描述

我正在尝试解决一个问题,即我使用 pyopenssl(20.0.1 - 最新版本)的 python 程序在 SSL 握手(104,'ECONNRESET')期间出现异常。

我的代码如下:

ctx = SSL.Context(SSL.TLSv1_2_METHOD)
ctx.check_hostname = False
ctx.verify_mode = SSL.VERIFY_NONE
ctx.set_options(SSL.OP_NO_TLSv1_3)

sock.setblocking(1)
sock_ssl = SSL.Connection(ctx,sock)
sock_ssl.set_connect_state()
sock_ssl.set_tlsext_host_name(hostname_idna)

try:
    sock_ssl.do_handshake()
except Exception as e:
    logger.error("SSL Handshake error when connecting to {}:{}): {}".format(hostname,port,e))

cert = sock_ssl.get_peer_certificate()

我在两个不同的平台上执行此操作,每个平台都使用 Python 3.6.6 但不同的 openssl 版本:

# openssl version
OpenSSL 1.1.1g FIPS  21 Apr 2020

#openssl ciphers -v | awk '{print $2}' | sort | uniq
SSLv3
TLSv1
TLSv1.2
TLSv1.3

使用 OpenSSL 1.1.1g 时 SSL 握手失败,使用 ECONNRESET 时,使用 OpenSSL 1.1.1d 时 SSL 握手成功。

当我尝试直接执行 SSL 握手时,我确实得到了以下输出

# openssl s_client -connect www.xxxlutz.at:443 -tls1_2
CONNECTED(00000003)
write:errno=104
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 0 bytes and written 215 bytes
Verification: OK
---
New,(NONE),Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
    Protocol  : TLSv1.2
    Cipher    : 0000
    Session-ID: 
    Session-ID-ctx: 
    Master-Key: 
    PSK identity: None
    PSK identity hint: None
    SRP username: None
    Start Time: 1621432160
    Timeout   : 7200 (sec)
    Verify return code: 0 (ok)
    Extended master secret: no

与旧版 openssl 相同的 SSL 握手会产生截然不同的输出(列出的证书等)

我错过了什么吗?似乎 openssl 版本 1.1.1g 需要一些额外的信息来执行成功的握手?

谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)