I've taken Jeremy Rossi's TLS patch and updated it for current CVS, and also cleaned up the parts of it that broke regular TCP when SSL was unavailable. What I have been completely unable to do is prevent this from introducing a branch/function call into the common path for doRead/doWrite, even when TLS is not in use. In order of desirability (imho), this can be fixed by: Rewrite tcp.py, more or less completely, *without* juggling methods as it currently does. Take the _TLS_* and _NOTLS_* functions and just inline them. Create a new transport, TLS, along with all the associated methods/functions (connect/listen/etc) so as to keep TLS code out of tcp.py entirely. Patch attached. Jp -- #!/bin/bash ( LIST=(~/.sigs/*.sig) cat ${LIST[$(($RANDOM % ${#LIST[*]}))]} echo -- $'\n' `uptime | sed -e 's/.*m//'` ) > ~/.signature -- up 42 days, 19:04, 4 users, load average: 0.35, 0.16, 0.19
Jp Calderone [exarkun@intarweb.us] wrote:
I've taken Jeremy Rossi's TLS patch and updated it for current CVS, and also cleaned up the parts of it that broke regular TCP when SSL was unavailable.
What I have been completely unable to do is prevent this from introducing a branch/function call into the common path for doRead/doWrite, even when TLS is not in use.
In order of desirability (imho), this can be fixed by:
Rewrite tcp.py, more or less completely, *without* juggling methods as it currently does.
Take the _TLS_* and _NOTLS_* functions and just inline them.
Create a new transport, TLS, along with all the associated methods/functions (connect/listen/etc) so as to keep TLS code out of tcp.py entirely.
The branch/function call can be avoided by replacing the doRead/doWrite/etc methods in startTLS. While this is still not very perty ;) Example: <CUT LOTS OF CODE> def startTLS(self, ctx): if not SSL: raise RuntimeException, "No SSL support available" assert not self.TLS self._startTLS() self.socket = SSL.Connection(ctx.getContext(), self.socket) def _startTLS(self): self.TLS = 1 self.fileno = self.socket.fileno self.doRead = self._TLS_doRead self.doWrite = self._TLS_doWrite self._closeSocket = self._TLS_closeSocket def doRead(self): try: data = self.socket.recv(self.bufferSize) except socket.error, se: if se.args[0] == EWOULDBLOCK: return else: return main.CONNECTION_LOST if not data: return main.CONNECTION_LOST return self.protocol.dataReceived(data) def _TLS_doRead(self): if self.writeBlockedOnRead: self.writeBlockedOnRead = 0 return self.doWrite() try: return self._NOTLS_doRead() except SSL.ZeroReturnError: # close SSL layer, since other side has done so, if we haven't if not self.sslShutdown: try: self.socket.shutdown() self.sslShutdown = 1 except SSL.Error: pass return main.CONNECTION_DONE except SSL.WantReadError: return except SSL.WantWriteError: self.readBlockedOnWrite = 1 self.startWriting() return except SSL.Error: return main.CONNECTION_LOST <CUT LOTS MORE CODE> Jeremy
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Ugly as it is, this looks like the right answer to me... On Friday, May 2, 2003, at 07:30 AM, Skinny Puppy wrote:
The branch/function call can be avoided by replacing the doRead/doWrite/etc methods in startTLS. While this is still not very perty ;) -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (Darwin)
iD8DBQE+svG0vVGR4uSOE2wRAqo+AJ40/0hBnDnEh1267vYe7hAJV0TEUwCeNklv Qya3OyfpjxoexyNSb3iLPqc= =24qI -----END PGP SIGNATURE-----
Glyph Lefkowitz [glyph@twistedmatrix.com] wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Ugly as it is, this looks like the right answer to me...
On Friday, May 2, 2003, at 07:30 AM, Skinny Puppy wrote:
The branch/function call can be avoided by replacing the doRead/doWrite/etc methods in startTLS. While this is still not very perty ;) -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (Darwin)
iD8DBQE+svG0vVGR4uSOE2wRAqo+AJ40/0hBnDnEh1267vYe7hAJV0TEUwCeNklv Qya3OyfpjxoexyNSb3iLPqc= =24qI -----END PGP SIGNATURE-----
Ok - Done - I still don't like it. I have not run any real world tests yet, but I have used echoserv_tls.py/echoclient_tls.py and watched the traffic with tcpdump to verify the encryption. And of course the Unit Tests. Jeremy
participants (3)
-
Glyph Lefkowitz
-
Jp Calderone
-
Skinny Puppy