do_handshake 有什么意义
What is the point of do_handshake in
我需要创建一个执行 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.
我需要创建一个执行 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.