Python 3.6 SSL-使用TLSv1.0而不是TLSv1.2密码-(2路身份验证和自签名证书)

Python 3.6 SSL-使用TLSv1.0而不是TLSv1.2密码-(2路身份验证和自签名证书),python,python-3.x,ssl,openssl,tls1.2,Python,Python 3.x,Ssl,Openssl,Tls1.2,我将ssl库与Python3.6一起使用。我使用的是使用openssl生成的自签名ECDSA证书 服务器/客户端代码: # Create a context in TLSv1.2, requiring a certificate (2-way auth) context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2) context.options |= ssl.OP_NO_TLSv1 context.options |= ssl.OP_NO_TLSv1_1 con

我将ssl库与Python3.6一起使用。我使用的是使用openssl生成的自签名ECDSA证书

服务器/客户端代码:

# Create a context in TLSv1.2, requiring a certificate (2-way auth)
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
context.options |= ssl.OP_NO_TLSv1
context.options |= ssl.OP_NO_TLSv1_1
context.verify_mode = ssl.CERT_REQUIRED
context.check_hostname = True # This line ommited in server code

# Set the list of allowed ciphers to those with key length of at least 128
# TODO Figure out why this isn't working
context.set_ciphers('TLSv1.2+HIGH+SHA256+ECDSA')

# Print some info about the connection
for cipher in context.get_ciphers():
    print(cipher)
输出:

{'id': 50380835, 'name': 'ECDHE-ECDSA-AES128-SHA256', 'protocol': 'TLSv1/SSLv3', 'description': 'ECDHE-ECDSA-AES128-SHA256 TLSv1.2 Kx=ECDH     Au=ECDSA Enc=AES(128)  Mac=SHA256', 'strength_bits': 128, 'alg_bits': 128}
当前密码:

 connection.cipher()
('ECDHE-ECDSA-AES128-SHA256','TLSv1/SSLv3',128)

我的问题:为什么选择的密码不是TLSv1.2

编辑:请求的屏幕截图

基于另一个线程,我尝试将代码更改为以下内容,但没有成功

 # Create a context in TLSv1.2, requiring a certificate (2-way auth)
    self.context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
    self.context.options |= ssl.OP_NO_SSLv2
    self.context.options |= ssl.OP_NO_SSLv3
    self.context.options |= ssl.OP_NO_TLSv1
    self.context.options |= ssl.OP_NO_TLSv1_1
    self.context.verify_mode = ssl.CERT_REQUIRED
    # self.context.check_hostname = True

    # Set the list of allowed ciphers to those with high key length
    # I went with  SHA384 because it seemed to have more security
    self.context.set_ciphers('TLSv1.2+ECDSA+HIGH')

此密码与TLS 1.2兼容,它是中定义的普通密码

我认为我们需要对Python的文档进行一些解释,以了解get_ciphers()返回的内容与未解释的内容完全相同。但cipher()可能给了我们答案:

SSLSocket.cipher()

返回一个三值元组,其中包含正在使用的密码的名称,定义其用法的SSL协议版本,,以及 正在使用的秘密比特数。如果没有连接 已建立,则不返回任何值

网络捕获将确认TLS协议版本。

您正在查找的


下面是Eugène Adell的回答,关于为什么
SSLSocket.cipher()
没有给你你期望的东西,python,它的文档说:

。。。返回字符串,该字符串指示首先定义密码的SSL/TLS协议版本。当前为SSLv2或TLSv1/SSLv3。在某些情况下,它可能会返回“TLSv1.2”,但不会返回;改为使用SSL\u CIPHER\u description()


添加了一些截图。它似乎在使用ssh!似乎没有什么意义。SSL通信通常在端口443上,您可以尝试仅在此端口上捕获。如果它工作正常,打开捕获并打开客户机Hello数据包。