From b0539f5cb47b4d22478a660de986fecabe2425da Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Wed, 8 Feb 2017 20:49:14 +0100 Subject: [PATCH] SSL handshake fewer errors - don't unnecessarily raise exceptions if SSL handshake fails --- src/class_receiveDataThread.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/class_receiveDataThread.py b/src/class_receiveDataThread.py index ef7e32e3..987d7573 100644 --- a/src/class_receiveDataThread.py +++ b/src/class_receiveDataThread.py @@ -305,13 +305,16 @@ class receiveDataThread(threading.Thread): continue logger.error("SSL socket handhake failed: %s, shutting down connection", str(e)) self.sendDataThreadQueue.put((0, 'shutdown','tls handshake fail %s' % (str(e)))) - return + return False except Exception: logger.error("SSL socket handhake failed, shutting down connection", exc_info=True) self.sendDataThreadQueue.put((0, 'shutdown','tls handshake fail')) - return + return False # SSL in the background should be blocking, otherwise the error handling is difficult self.sslSock.settimeout(None) + return True + # no SSL + return True def peerValidityChecks(self): if self.remoteProtocolVersion < 3: @@ -346,7 +349,9 @@ class receiveDataThread(threading.Thread): # there is no reason to run this function a second time return - self.sslHandshake() + if not self.sslHandshake(): + return + if self.peerValidityChecks() == False: time.sleep(2) self.sendDataThreadQueue.put((0, 'shutdown','no data'))