我需要创建一个执行 TLS 握手的 TLS 客户端。我使用 context.wrap_socket
,它接受一个参数 do_handshake_on_connect
,该参数接受 True
或 False
。但是,我一直在握手而没有将此变量设置为 True(我根本不传递它)。我得到服务器选择的 TLS 密码套件和版本等握手结果。
我错过了什么吗? do_handshake_on_connect
如果在我这样做时隐式完成,那有什么意义:ssl_sock.connect
我无法理解要点,恐怕我遗漏了一些东西。
import socket, ssl
context = ssl.SSLContext()
context.verify_mode = ssl.CERT_REQUIRED
context.check_hostname = True
context.load_default_certs()
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ssl_sock = context.wrap_socket(s, server_hostname='www.verisign.com')
ssl_sock.connect(('www.verisign.com', 443))
最佳答案
What is the point of do_handshake_on_connect if it is implicitly done when I do:
ssl_sock.connect
这一点在the official documantion中清楚地显示出来了.引用:
The parameter do_handshake_on_connect specifies whether to do the SSL handshake automatically after doing a socket.connect(), or whether the application program will call it explicitly, by invoking the SSLSocket.do_handshake() method. Calling SSLSocket.do_handshake() explicitly gives the program control over the blocking behavior of the socket I/O involved in the handshake.
关于python - do_handshake 有什么意义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51317060/