diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2016-06-06 16:52:51 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2016-06-06 16:52:51 +1200 |
commit | 21c7218ee34bdaa43583a0daf0bfaf11498ce61b (patch) | |
tree | 8086899b1914efd0a023c9bf2892e0d4179e1549 /pathod | |
parent | 9458eaece7354665ac7a5252e7148a9b6da95159 (diff) | |
download | mitmproxy-21c7218ee34bdaa43583a0daf0bfaf11498ce61b.tar.gz mitmproxy-21c7218ee34bdaa43583a0daf0bfaf11498ce61b.tar.bz2 mitmproxy-21c7218ee34bdaa43583a0daf0bfaf11498ce61b.zip |
Close when Pathoc.connect raises an exception
Diffstat (limited to 'pathod')
-rw-r--r-- | pathod/pathoc.py | 76 |
1 files changed, 41 insertions, 35 deletions
diff --git a/pathod/pathoc.py b/pathod/pathoc.py index 5cfb4591..4c708fc9 100644 --- a/pathod/pathoc.py +++ b/pathod/pathoc.py @@ -247,7 +247,10 @@ class Pathoc(tcp.TCPClient): def socks_connect(self, connect_to): try: - client_greet = socks.ClientGreeting(socks.VERSION.SOCKS5, [socks.METHOD.NO_AUTHENTICATION_REQUIRED]) + client_greet = socks.ClientGreeting( + socks.VERSION.SOCKS5, + [socks.METHOD.NO_AUTHENTICATION_REQUIRED] + ) client_greet.to_file(self.wfile) self.wfile.flush() @@ -286,44 +289,47 @@ class Pathoc(tcp.TCPClient): if self.use_http2 and not self.ssl: raise NotImplementedError("HTTP2 without SSL is not supported.") - ret = tcp.TCPClient.connect(self) + try: + ret = tcp.TCPClient.connect(self) + if connect_to: + self.http_connect(connect_to) - if connect_to: - self.http_connect(connect_to) + self.sslinfo = None + if self.ssl: + try: + alpn_protos = [b'http/1.1'] + if self.use_http2: + alpn_protos.append(b'h2') + + self.convert_to_ssl( + sni=self.sni, + cert=self.clientcert, + method=self.ssl_version, + options=self.ssl_options, + cipher_list=self.ciphers, + alpn_protos=alpn_protos + ) + except TlsException as v: + raise PathocError(str(v)) - self.sslinfo = None - if self.ssl: - try: - alpn_protos = [b'http/1.1'] - if self.use_http2: - alpn_protos.append(b'h2') - - self.convert_to_ssl( - sni=self.sni, - cert=self.clientcert, - method=self.ssl_version, - options=self.ssl_options, - cipher_list=self.ciphers, - alpn_protos=alpn_protos + self.sslinfo = SSLInfo( + self.connection.get_peer_cert_chain(), + self.get_current_cipher(), + self.get_alpn_proto_negotiated() ) - except TlsException as v: - raise PathocError(str(v)) - - self.sslinfo = SSLInfo( - self.connection.get_peer_cert_chain(), - self.get_current_cipher(), - self.get_alpn_proto_negotiated() - ) - if showssl: - print(str(self.sslinfo), file=fp) - - if self.use_http2: - self.protocol.check_alpn() - if not self.http2_skip_connection_preface: - self.protocol.perform_client_connection_preface() + if showssl: + print(str(self.sslinfo), file=fp) - if self.timeout: - self.settimeout(self.timeout) + if self.use_http2: + self.protocol.check_alpn() + if not self.http2_skip_connection_preface: + self.protocol.perform_client_connection_preface() + + if self.timeout: + self.settimeout(self.timeout) + except Exception: + self.close() + raise return ret def stop(self): |