Skip to content

Commit

Permalink
TLS updates
Browse files Browse the repository at this point in the history
- save TLS version
- minor TLS error handling updates
  • Loading branch information
PeterSurda committed Jun 24, 2017
1 parent b9d60f8 commit e9edf70
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/network/tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(self, address=None, sock=None,
self.ciphers = ciphers
self.tlsStarted = False
self.tlsDone = False
self.tlsVersion = "N/A"
self.isSSL = False

def state_tls_init(self):
Expand Down Expand Up @@ -96,8 +97,9 @@ def handle_read(self):
elif err.errno in _DISCONNECTED_SSL:
self.handle_close()
return
else:
raise
logger.info("SSL Error: %s", str(err))
self.handle_close()
return

def handle_write(self):
try:
Expand All @@ -116,8 +118,9 @@ def handle_write(self):
elif err.errno in _DISCONNECTED_SSL:
self.handle_close()
return 0
else:
raise
logger.info("SSL Error: %s", str(err))
self.handle_close()
return

def tls_handshake(self):
# wait for flush
Expand All @@ -138,8 +141,19 @@ def tls_handshake(self):
self.want_write = True
if not (self.want_write or self.want_read):
raise
except socket.error as err:
if err.errno in asyncore._DISCONNECTED:
self.handle_close()
else:
raise
else:
logger.debug("%s:%i: TLS handshake success%s", self.destination.host, self.destination.port, ", TLS protocol version: %s" % (self.sslSocket.version()) if sys.version_info >= (2, 7, 9) else "")
if sys.version_info >= (2, 7, 9):
self.tlsVersion = self.sslSocket.version()
logger.debug("%s:%i: TLS handshake success, TLS protocol version: %s",
self.destination.host, self.destination.port, self.sslSocket.version())
else:
self.tlsVersion = "TLSv1"
logger.debug("%s:%i: TLS handshake success", self.destination.host, self.destination.port)
# The handshake has completed, so remove this channel and...
self.del_channel()
self.set_socket(self.sslSocket)
Expand Down

0 comments on commit e9edf70

Please sign in to comment.