【问题标题】:How to get the server's selected TLS verison in python ssl如何在 python ssl 中获取服务器选择的 TLS 版本
【发布时间】:2018-09-22 01:07:40
【问题描述】:

我使用的是 python 3.6.5 和 Windows 10。我需要获取服务器选择的 TLS 版本(即将用于其余握手的版本,而不是客户端提供的版本)。我这样做了:

import socket, ssl

context =  context = ssl.create_default_context()
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
domain = 'google.com'
sslSocket = context.wrap_socket(s, server_hostname = domain)
sslSocket.connect((domain, 443))
print('the selected version by the server: ', sslSocket.cipher()[1])
print("success")
sslSocket.close()

但是输出是:

the selected version by the server:  TLSv1/SSLv3
success

我需要准确的版本。即,在与google.com 的连接中,它是TLS 1.2,如浏览器所示。如何在我的代码中获得准确的版本?

【问题讨论】:

    标签: python sockets ssl tls1.2 pyopenssl


    【解决方案1】:

    您混淆了密码和协议版本。密码描述了选择了哪些加密算法(即像 AES 加密、SHA-1 HMAC、RSA 身份验证、ECDHE 密钥交换),而协议版本则说明了使用哪个 SSL/TLS 协议版本。您当前显示的值只是协议版本,因为客户端和服务器使用的通用密码在标准中可用。

    要获取连接使用的协议版本,您需要使用SSLSocket.version()

    print('the selected version by the server: ', sslSocket.version())
    

    【讨论】:

      猜你喜欢
      • 2018-09-22
      • 1970-01-01
      • 1970-01-01
      • 2020-05-29
      • 2018-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多