From 870afd7445e7d1f1a382ba09ab35dbd4203f417a Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Mon, 26 Oct 2009 17:25:18 +0200 Subject: [PATCH] [IMP] If SSL connection fails, close the socket. Happened when a non-ssl client tried to connect to an ssl socket: the negotiation would fail and then the socket hanged open until the client would decide to disconnect. bzr revid: p_christ@hol.gr-20091026152518-xvi8zyk02iiwy460 --- bin/service/websrv_lib.py | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/bin/service/websrv_lib.py b/bin/service/websrv_lib.py index 84d27627e3c..759b7b6f3c3 100644 --- a/bin/service/websrv_lib.py +++ b/bin/service/websrv_lib.py @@ -357,23 +357,30 @@ class SecureMultiHTTPHandler(MultiHTTPHandler): return ('server.cert','server.key') def setup(self): - import ssl - certfile, keyfile = self.getcert_fnames() - self.connection = ssl.wrap_socket(self.request, - server_side=True, - certfile=certfile, - keyfile=keyfile, - ssl_version=ssl.PROTOCOL_SSLv23) - self.rfile = self.connection.makefile('rb', self.rbufsize) - self.wfile = self.connection.makefile('wb', self.wbufsize) - self.log_message("Secure %s connection from %s",self.connection.cipher(),self.client_address) + import ssl + certfile, keyfile = self.getcert_fnames() + try: + self.connection = ssl.wrap_socket(self.request, + server_side=True, + certfile=certfile, + keyfile=keyfile, + ssl_version=ssl.PROTOCOL_SSLv23) + self.rfile = self.connection.makefile('rb', self.rbufsize) + self.wfile = self.connection.makefile('wb', self.wbufsize) + self.log_message("Secure %s connection from %s",self.connection.cipher(),self.client_address) + except: + self.request.shutdown(socket.SHUT_RDWR) + raise def finish(self): # With ssl connections, closing the filehandlers alone may not - # work because of ref counting. We explicitly tell the socket - # to shutdown. - MultiHTTPHandler.finish(self) - self.connection.shutdown(socket.SHUT_RDWR) + # work because of ref counting. We explicitly tell the socket + # to shutdown. + MultiHTTPHandler.finish(self) + try: + self.connection.shutdown(socket.SHUT_RDWR) + except: + pass import threading class ConnThreadingMixIn: