From 23fcf2cdec2c9ffbed89453952ea4c29f97ff865 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Fri, 3 Feb 2017 10:05:35 +0100 Subject: [PATCH] SSL handshake python version compatibility - error handling should now work with < 2.7.9 --- src/class_receiveDataThread.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/class_receiveDataThread.py b/src/class_receiveDataThread.py index 6004de5c..764ad0ba 100644 --- a/src/class_receiveDataThread.py +++ b/src/class_receiveDataThread.py @@ -266,17 +266,29 @@ class receiveDataThread(threading.Thread): self.sslSock.do_handshake() logger.debug("TLS handshake success") break - except ssl.SSLWantReadError: - logger.debug("Waiting for SSL socket handhake read") - select.select([self.sslSock], [], [], 10) - except ssl.SSLWantWriteError: - logger.debug("Waiting for SSL socket handhake write") - select.select([], [self.sslSock], [], 10) except ssl.SSLError as e: + if sys.hexversion >= 0x02070900: + if isinstance (e, ssl.SSLWantReadError): + logger.debug("Waiting for SSL socket handhake read") + select.select([self.sslSock], [], [], 10) + continue + elif isinstance (e, ssl.SSLWantWriteError): + logger.debug("Waiting for SSL socket handhake write") + select.select([], [self.sslSock], [], 10) + continue + else: + if e.args[0] == ssl.SSL_ERROR_WANT_READ: + logger.debug("Waiting for SSL socket handhake read") + select.select([self.sslSock], [], [], 10) + continue + elif e.args[0] == ssl.SSL_ERROR_WANT_WRITE: + logger.debug("Waiting for SSL socket handhake write") + select.select([], [self.sslSock], [], 10) + 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 - except: + except Exception: logger.error("SSL socket handhake failed, shutting down connection", exc_info=True) self.sendDataThreadQueue.put((0, 'shutdown','tls handshake fail')) return