TLS handshake fix
- TLS handshake in python is apparently always asynchronous, so it needs proper handling of SSLWantReadError and SSLWantWriteError - also adds a timeout and a proper shutdown if handshake fails
This commit is contained in:
parent
541979a159
commit
4f543e14c1
|
@ -294,14 +294,18 @@ class receiveDataThread(threading.Thread):
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
self.sslSock.do_handshake()
|
self.sslSock.do_handshake()
|
||||||
|
logger.debug("TLS handshake success")
|
||||||
break
|
break
|
||||||
except ssl.SSLError as e:
|
except ssl.SSLWantReadError:
|
||||||
if e.errno == 2:
|
logger.debug("Waiting for SSL socket handhake read")
|
||||||
select.select([self.sslSock], [self.sslSock], [])
|
select.select([self.sslSock], [], [], 10)
|
||||||
else:
|
except ssl.SSLWantWriteError:
|
||||||
break
|
logger.debug("Waiting for SSL socket handhake write")
|
||||||
|
select.select([], [self.sslSock], [], 10)
|
||||||
except:
|
except:
|
||||||
break
|
logger.debug("SSL socket handhake failed, shutting down connection")
|
||||||
|
self.sendDataThreadQueue.put((0, 'shutdown','tls handshake fail'))
|
||||||
|
return
|
||||||
# Command the corresponding sendDataThread to set its own connectionIsOrWasFullyEstablished variable to True also
|
# Command the corresponding sendDataThread to set its own connectionIsOrWasFullyEstablished variable to True also
|
||||||
self.sendDataThreadQueue.put((0, 'connectionIsOrWasFullyEstablished', (self.services, self.sslSock)))
|
self.sendDataThreadQueue.put((0, 'connectionIsOrWasFullyEstablished', (self.services, self.sslSock)))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user