Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to check that TLS handshake was finalize in Twisted
    primarykey
    data
    text
    <p>This is a follow up of this question: <a href="https://stackoverflow.com/questions/4942121">SSL handshake failures when no data was sent over Twisted TLSConnection</a></p> <p>I have implemented a simple SSL server that closes the connection as soon as the client is connected.</p> <p>I am testing it with openssl and I got this handshake failure:</p> <pre><code>$ openssl s_client -connect localhost:12345 CONNECTED(00000003) 2329:error:140790E5:SSL routines:SSL23_WRITE :ssl handshake failure:s23_lib.c:188: </code></pre> <p>The problem is that <code>TLS.Connection.loseConnection</code> does not wait for the ongoing handshake to be done and just disconnects the client.</p> <p>A callback attached to <code>OpenSSL.SSL.Connection.do_handshake</code> would have been great... but unfortunately I don't know if this can be done... or how to do it.</p> <p>Any hints in how I could test that a TLS handshake was done is much appreciated. Many thanks!</p> <p>Here is the code</p> <pre><code>class ApplicationProtocol(Protocol): '''Protocol that closes the connection when connection is made.''' def connectionMade(self): self.transport.loseConnection() # Here is a barebone TLS Server serverFactory = ServerFactory() serverFactory.protocol = ApplicationProtocol server_cert_path = 'server.pem' serverContextFactory = DefaultOpenSSLContextFactory( privateKeyFileName = server_cert_path, certificateFileName = server_cert_path, sslmethod=SSL.SSLv23_METHOD) tlsFactory = TLSMemoryBIOFactory(serverContextFactory, False, serverFactory) reactor.listenTCP(12345, tlsFactory) #reactor.listenSSL(12345, serverFactory, serverContextFactory) </code></pre> <hr> <p>For now I solve this really dirty and not 100% valid.</p> <pre><code>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() # If we don't know if the handshake was done, we wait for a bit # and the close the connection. # This is done to avoid closing the connection in the middle of a # handshake. if not self._handshakeDone: reactor.callLater(0.5, close_connection) else: close_connection() TLSMemoryBIOProtocol.loseConnection = tls_lose_connection </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload