我已经使用PyOpenSSL创建了一个连接对象,我已经设法与我正在测试的库建立连接。
我正在使用bio_read和bio_write方法,因为我没有使用套接字来传输数据。
我现在想要将加密的应用程序数据传递给连接对象,并从连接对象中检索未加密的应用程序数据。
这是一个代码snipet来演示我的问题:
# 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会返回一个WantReadError。
感谢您的帮助。
答案 0 :(得分:1)
I can't quite remember what I was doing wrong as I am no longer at work, but conn.recv(n)
returns the application data. I believe the reason conn.read
exists but is undocumented is that the object wraps a socket object, and so this method is a method of the socket and not OpenSSL.SSL.Connection
. This would also explain why I receive a read is not a member of NoneType
when I call it.