[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
This commit is contained in:
+21
-14
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user