如何获取服务器';在python ssl中选择TLS verison
我正在使用python 3.6.5和Windows 10。我需要获取服务器选择的TLS版本(即,将用于其余握手的版本,而不是客户端提供的版本)。我这样做:如何获取服务器';在python ssl中选择TLS verison,python,sockets,ssl,tls1.2,pyopenssl,Python,Sockets,Ssl,Tls1.2,Pyopenssl,我正在使用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_s
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
我需要准确的版本。i、 例如,在连接到
google.com
时,它是tls1.2
,如浏览器所示。我怎样才能在我的代码中得到准确的版本?你把密码和协议版本搞混了。密码描述选择了哪些加密算法(如AES加密、SHA-1 HMAC、RSA身份验证、ECDHE密钥交换),而协议版本说明使用了哪个SSL/TLS协议版本。当前显示的值仅为标准提供客户端和服务器使用的通用密码后的协议版本
要获取连接使用的协议版本,您需要使用:
print('the selected version by the server: ', sslSocket.version())