python - do_handshake 有什么意义

标签 python sockets ssl network-programming tls1.2

我需要创建一个执行 TLS 握手的 TLS 客户端。我使用 context.wrap_socket,它接受一个参数 do_handshake_on_connect,该参数接受 TrueFalse。但是,我一直在握手而没有将此变量设置为 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/

相关文章:

c - 当http header错误报告content-length时该怎么办

c# - TCP IP 服务器确认并再次接收数据

android - 如何通过蓝牙传输套接字文件描述符的内容?

security - 使用 Jmeter 记录 Gmail

ssl - 如何在作为客户端的 USIM sim 卡和服务器之间以 TLS-PSK 模式建立 TLS 连接?

Python-Argparse : Default agrument that can be overridden

python - 合并月份和年份列以创建日期列

java - 如何使用 JSS 将受信任的证书颁发机构添加到 Firefox

python - 类型错误 : can only concatenate list (not "str") to list

python - TensorFlow:tf.add_n 的乘积等价物