"Do_handshake的意义在于什么"

2024-06-01 13:24:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要创建一个执行TLS握手的TLS客户端。我使用context.wrap_socket,它接受一个参数do_handshake_on_connect,它接受True或{}。但是,我在握手时没有将这个变量设置为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))

Tags: comtruesslonwwwconnectcontexttls
1条回答
网友
1楼 · 发布于 2024-06-01 13:24:34

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.

相关问题 更多 >