This is a follow-up to this question: SSL communication failed when no data was sent via Twisted TLSConnection
I installed a simple SSL server that closes the connection as soon as the client connects.
I am testing it with openssl and I got this handshake rejection:
$ openssl s_client -connect localhost:12345 CONNECTED(00000003) 2329:error:140790E5:SSL routines:SSL23_WRITE :ssl handshake failure:s23_lib.c:188:
The problem is that TLS.Connection.loseConnection does not wait for the completion of the current handshake and simply disconnects the client.
A callback bound to OpenSSL.SSL.Connection.do_handshake would be great ... but unfortunately I don't know if this can be done ... or how to do it.
Any tips on how I can verify what was done using TLS are greatly appreciated. Thank you very much!
Here is the code
class ApplicationProtocol(Protocol): '''Protocol that closes the connection when connection is made.''' def connectionMade(self): self.transport.loseConnection()
At the moment, I decide it is really dirty, not 100% valid.
def tls_lose_connection(self): """ Monkey patching for TLSMemoryBIOProtocol to wait for handshake to end, before closing the connection. Send a TLS close alert and close the underlying connection. """ def close_connection(): self.disconnecting = True if not self._writeBlockedOnRead: self._tlsConnection.shutdown() self._flushSendBIO() self.transport.loseConnection()
source share