[Twisted-Python] TLSMemoryBIOProtocol _shutdownTLS what to do when not successfull

Adi Roiban adi at roiban.ro
Wed Jan 16 08:47:17 MST 2013


Hi,

Here is this code in t.p.t.TLSMemoryBIOProtocol

    def _shutdownTLS(self):
        """
        Initiate, or reply to, the shutdown handshake of the TLS layer.
        """
        self._flushSendBIO()
        shutdownSuccess = self._tlsConnection.shutdown()
        self._flushSendBIO()
        if shutdownSuccess:
            # Both sides have shutdown, so we can start closing lower-level
            # transport. This will also happen if we haven't started
            # negotiation at all yet, in which case shutdown succeeds
            # immediately.
            self.transport.loseConnection()


>From my tests using Curl as a client, self._tlsConnection.shutdown()
always returns False.

-----

I need to call

self._tlsConnection.set_shutdown(SENT_SHUTDOWN | RECEIVED_SHUTDOWN)

before calling

shutdownSuccess = self._tlsConnection.shutdown()

and then  self._tlsConnection.shutdown() returns True, otherwise it
returns False.

    def loseConnection(self):
        """
        Send a TLS close alert and close the underlying connection.
        """
        if self.disconnecting:
            return
        self.disconnecting = True
        if not self._writeBlockedOnRead and self._producer is None:
            from OpenSSL.SSL import RECEIVED_SHUTDOWN
            self._tlsConnection.set_shutdown(RECEIVED_SHUTDOWN)
            self._shutdownTLS()

    def _shutdownTLS(self):
        """
        Initiate, or reply to, the shutdown handshake of the TLS layer.
        """
        self._flushSendBIO()
        shutdownSuccess = self._tlsConnection.shutdown()
        self._flushSendBIO()
        if shutdownSuccess:
            # Both sides have shutdown, so we can start closing lower-level
            # transport. This will also happen if we haven't started
            # negotiation at all yet, in which case shutdown succeeds
            # immediately.
            self.transport.loseConnection()


----


How should the connection be handled when
self._tlsConnection.shutdown() returns False?

>From my tests, it looks like when shutdownSuccess is False, the
self.transport.loseConnection() is never closed.

Many thanks,
Adi

-- 
Adi Roiban




More information about the Twisted-Python mailing list