From 8f87f7e95415dff1a3216408aef25edec2ca36cf Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Wed, 13 Nov 2013 14:35:35 -0500 Subject: [PATCH] IPv6 support --- lib/interface.py | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/lib/interface.py b/lib/interface.py index 814f5323d..9e39ba3dc 100644 --- a/lib/interface.py +++ b/lib/interface.py @@ -315,18 +315,25 @@ class Interface(threading.Thread): is_new = True # get server certificate. # Do not use ssl.get_server_certificate because it does not work with proxy - s = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) - try: - s.connect((self.host, self.port)) - except Exception: - # print_error("failed to connect", self.host, self.port) - return + for res in socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM): + try: + s = socket.socket( res[0], socket.SOCK_STREAM ) + s.connect(res[4]) + except: + s = None + continue + + try: + s = ssl.wrap_socket(s, ssl_version=ssl.PROTOCOL_SSLv3, cert_reqs=ssl.CERT_NONE, ca_certs=None) + except ssl.SSLError, e: + s = None + continue + break - try: - s = ssl.wrap_socket(s, ssl_version=ssl.PROTOCOL_SSLv3, cert_reqs=ssl.CERT_NONE, ca_certs=None) - except ssl.SSLError, e: - print_error("SSL error:", self.host, e) + if s == None: + print_error("SSL error retrieving SSL certificate:", self.host, e) return + dercert = s.getpeercert(True) s.close() cert = ssl.DER_cert_to_PEM_cert(dercert) @@ -339,14 +346,19 @@ class Interface(threading.Thread): else: is_new = False + for res in socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM): + try: + s = socket.socket( res[0], socket.SOCK_STREAM ) + s.settimeout(2) + s.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) - s = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) - s.settimeout(2) - s.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) + s.connect(res[4]) + except: + s = None + continue + break - try: - s.connect(( self.host.encode('ascii'), int(self.port))) - except Exception: + if s == None: print_error("failed to connect", self.host, self.port) return