Commit 1a33d71c authored by Alexandre's avatar Alexandre
Browse files

[DoT] Raise exception on closed and reset connection

Based on OpenSSL manual and pyOpenSSL documentation, a closed connection
raises an error SSL_ERROR_ZERO_RETURN which raises a ZeroReturnError
exception.
See <https://www.openssl.org/docs/man1.1.0/man3/SSL_get_error.html> and
<https://www.pyopenssl.org/en/stable/api/ssl.html#OpenSSL.SSL.ZeroReturnError>
parent 428bb128
......@@ -229,13 +229,23 @@ class ConnectionDOT(Connection):
if dump:
homer.dump_data(data, 'data sent')
length = len(data)
self.session.send(length.to_bytes(2, byteorder='big') + data)
try:
self.session.send(length.to_bytes(2, byteorder='big') + data)
except OpenSSL.SSL.SysCallError as e:
self.state = e.args[1]
raise homer.ConnectionDOTException('OpenSSL error : %s' % self.state)
except OpenSSL.SSL.ZeroReturnError:
self.state = 'CONN_CLOSED'
raise homer.ConnectionDOTException('The SSL connection has been closed')
def receive_data(self, dump=False):
try:
buf = self.session.recv(2)
except OpenSSL.SSL.WantReadError:
return (False, None, None)
except OpenSSL.SSL.ZeroReturnError:
self.state = 'CONN_CLOSED'
raise homer.ConnectionDOTException('The SSL connection has been closed')
size = int.from_bytes(buf, byteorder='big')
data = self.session.recv(size)
if dump:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment