Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python中测量TLS握手性能时间_Python_Sockets_Ssl_Network Programming_Tls1.2 - Fatal编程技术网

在python中测量TLS握手性能时间

在python中测量TLS握手性能时间,python,sockets,ssl,network-programming,tls1.2,Python,Sockets,Ssl,Network Programming,Tls1.2,我有一个简单的脚本,它在python中执行TLS握手,其方式类似于在python中执行TLS握手的方式: 我想测量TLS握手所需的时间。因此,我假设在connect函数之前启动一个计时器,然后减去经过的时间,如下所示: start = time.process_time() sslSocket.connect((domainName, 443)) perfTime = time.process_time() - start 我查看了connect文档,它是这样说的: 连接到地址处的远程套接字。

我有一个简单的脚本,它在python中执行TLS握手,其方式类似于在python中执行TLS握手的方式:

我想测量TLS握手所需的时间。因此,我假设在
connect
函数之前启动一个计时器,然后减去经过的时间,如下所示:

start = time.process_time()
sslSocket.connect((domainName, 443))
perfTime = time.process_time() - start
我查看了
connect
文档,它是这样说的:

连接到地址处的远程套接字。(地址的格式取决于 在地址系列上-参见上文。)如果连接中断 通过一个信号,该方法等待连接完成,或者引发 如果信号处理程序未引发 异常,并且套接字正在阻塞或超时。对于 在非阻塞套接字中,该方法引发InterruptedError异常 如果连接被信号中断(或引发异常 通过信号处理程序)

我的问题是:代码中的
connect
函数是否执行TLS握手?这就是我想要衡量的性能:TLS握手。connect是TCP级别,但我将套接字包装在TLS上下文中。请向我澄清如何在我的简单代码中测量TLS握手性能

试试这个:

ssl_sock = context.wrap_socket(s, do_handshake_on_connect=False)
然后,手动执行SSL握手:

...
ssl_sock.connect(('www.verisign.com', 443))
start = time.process_time()
ssl_sock.do_handshake()
perfTime = time.process_time() - start
print("Handshaking time " + perfTime)

相反,您应该尝试使用在握手过程中特定时间发生的回调。我不知道使用
ssl
库,但是使用
pyopenssl
one-go-look查看
set\u-info\u-callback
方法。
...
ssl_sock.connect(('www.verisign.com', 443))
start = time.process_time()
ssl_sock.do_handshake()
perfTime = time.process_time() - start
print("Handshaking time " + perfTime)