Set close_reason for exceptions in network.tls

This commit is contained in:
Dmitri Bogomolov 2020-02-14 15:35:56 +02:00 committed by Muzahid
parent 2a8e91e6a7
commit f75268bc56
Signed by untrusted user: cis-muzahid
GPG Key ID: 1DC85E7D3AB613EA
2 changed files with 8 additions and 4 deletions

View File

@ -31,6 +31,7 @@ class AdvancedDispatcher(asyncore.dispatcher):
def __init__(self, sock=None): def __init__(self, sock=None):
if not hasattr(self, '_map'): if not hasattr(self, '_map'):
asyncore.dispatcher.__init__(self, sock) asyncore.dispatcher.__init__(self, sock)
self.close_reason = None
self.read_buf = bytearray() self.read_buf = bytearray()
self.write_buf = bytearray() self.write_buf = bytearray()
self.state = "init" self.state = "init"

View File

@ -154,12 +154,13 @@ class TLSDispatcher(AdvancedDispatcher):
except AttributeError: except AttributeError:
return AdvancedDispatcher.handle_read(self) return AdvancedDispatcher.handle_read(self)
except ssl.SSLError as err: except ssl.SSLError as err:
self.close_reason = "SSL Error in handle_read"
if err.errno == ssl.SSL_ERROR_WANT_READ: if err.errno == ssl.SSL_ERROR_WANT_READ:
return return
elif err.errno in _DISCONNECTED_SSL: elif err.errno in _DISCONNECTED_SSL:
self.handle_close() self.handle_close()
return return
logger.info("SSL Error: %s", str(err)) logger.info("SSL Error: %s", err)
self.handle_close() self.handle_close()
return return
@ -184,12 +185,13 @@ class TLSDispatcher(AdvancedDispatcher):
except AttributeError: except AttributeError:
return AdvancedDispatcher.handle_write(self) return AdvancedDispatcher.handle_write(self)
except ssl.SSLError as err: except ssl.SSLError as err:
self.close_reason = "SSL Error in handle_write"
if err.errno == ssl.SSL_ERROR_WANT_WRITE: if err.errno == ssl.SSL_ERROR_WANT_WRITE:
return 0 return 0
elif err.errno in _DISCONNECTED_SSL: elif err.errno in _DISCONNECTED_SSL:
self.handle_close() self.handle_close()
return 0 return 0
logger.info("SSL Error: %s", str(err)) logger.info("SSL Error: %s", err)
self.handle_close() self.handle_close()
return return
@ -203,8 +205,8 @@ class TLSDispatcher(AdvancedDispatcher):
logger.debug("handshaking (internal)") logger.debug("handshaking (internal)")
self.sslSocket.do_handshake() self.sslSocket.do_handshake()
except ssl.SSLError as err: except ssl.SSLError as err:
logger.debug( self.close_reason = "SSL Error in tls_handshake"
'%s:%i: handshake fail', self.destination.host, self.destination.port) logger.info("%s:%i: handshake fail", *self.destination)
self.want_read = self.want_write = False self.want_read = self.want_write = False
if err.args[0] == ssl.SSL_ERROR_WANT_READ: if err.args[0] == ssl.SSL_ERROR_WANT_READ:
logger.debug("want read") logger.debug("want read")
@ -217,6 +219,7 @@ class TLSDispatcher(AdvancedDispatcher):
except socket.error as err: except socket.error as err:
# pylint: disable=protected-access # pylint: disable=protected-access
if err.errno in asyncore._DISCONNECTED: if err.errno in asyncore._DISCONNECTED:
self.close_reason = "socket.error in tls_handshake"
self.handle_close() self.handle_close()
else: else:
raise raise