SSL handshake python version compatibility

- error handling should now work with < 2.7.9
This commit is contained in:
Peter Šurda 2017-02-03 10:05:35 +01:00
parent c979481564
commit 23fcf2cdec
Signed by untrusted user: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87

View File

@ -266,17 +266,29 @@ class receiveDataThread(threading.Thread):
self.sslSock.do_handshake()
logger.debug("TLS handshake success")
break
except ssl.SSLWantReadError:
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)
except ssl.SSLWantWriteError:
continue
elif isinstance (e, ssl.SSLWantWriteError):
logger.debug("Waiting for SSL socket handhake write")
select.select([], [self.sslSock], [], 10)
except ssl.SSLError as e:
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