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

问题描述 投票:1回答:1

我正在使用带有python 3.6的ssl库。我正在使用我用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?

编辑:请求的屏幕截图

enter image description here

enter image description here

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

 # 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')
python python-3.x ssl openssl tls1.2
1个回答
1
投票

这个密码与TLS 1.2兼容,它是RFC 5289中定义的普通密码。

我认为我们需要解释一些Python的文档来了解get_ciphers()正在返回的内容,因为它没有被解释。但cipher()给了我们答案:

SSLSocket.cipher()

返回一个三值元组,其中包含正在使用的密码的名称,定义其使用的SSL协议的版本以及正在使用的密码位数。如果尚未建立连接,则返回None。

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

© www.soinside.com 2019 - 2024. All rights reserved.