从 Python 中的 TLS 连接读取应用程序数据

Reading application data from a TLS connection in Python

我已经使用 PyOpenSSL 创建了一个连接对象,并且已经成功地建立了与我正在测试的库的连接。

我正在使用 bio_read 和 bio_write 方法,因为我没有使用套接字来传输数据。

我现在想将加密的应用程序数据传递给连接对象,并从连接对象取回未加密的应用程序数据。

这是一个代码片段来演示我的问题:

# Prints "SSL negotiation finished successfully"
print(conn.state_string());

# I give the connection 37 bytes of data representing encrypted app data
conn.bio_write("\x17\x03\x01...")

# I ask the connection to receive the data written to the buffer
conn.recv(65536)

接下来我要如何处理连接对象?我试过 conn.read,但尽管它存在,但它是 not documented,并且 conn.bio_read returns 一个 WantReadError。

感谢您的帮助。

我不太记得自己做错了什么,因为我已经不在工作了,但是 conn.recv(n) returns 应用程序数据。我相信 conn.read 存在但未记录的原因是该对象包装了一个套接字对象,因此此方法是套接字的方法而不是 OpenSSL.SSL.Connection。这也可以解释为什么我在调用它时会收到 read is not a member of NoneType