diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2013-01-01 11:24:11 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2013-01-01 11:24:11 +1300 |
commit | e42136a6ef6f29a16cb2eb5f566be317ed7f3579 (patch) | |
tree | 91ef19d2be91cd3ed34ac88b619eaa0362a3f0dc | |
parent | e2dc7ba09d54fb4fa4af796d5c37cd36174f8897 (diff) | |
download | mitmproxy-e42136a6ef6f29a16cb2eb5f566be317ed7f3579.tar.gz mitmproxy-e42136a6ef6f29a16cb2eb5f566be317ed7f3579.tar.bz2 mitmproxy-e42136a6ef6f29a16cb2eb5f566be317ed7f3579.zip |
Better error handling for transparent mode remote address resolution.
-rw-r--r-- | libmproxy/platform/osx.py | 5 | ||||
-rw-r--r-- | libmproxy/proxy.py | 5 |
2 files changed, 8 insertions, 2 deletions
diff --git a/libmproxy/platform/osx.py b/libmproxy/platform/osx.py index d1c420e2..dda5d9af 100644 --- a/libmproxy/platform/osx.py +++ b/libmproxy/platform/osx.py @@ -16,5 +16,8 @@ class Resolver: def original_addr(self, csock): peer = csock.getpeername() - stxt = subprocess.check_output(self.STATECMD, stderr=subprocess.STDOUT) + try: + stxt = subprocess.check_output(self.STATECMD, stderr=subprocess.STDOUT) + except subprocess.CalledProcessError: + return None return pf.lookup(peer[0], peer[1], stxt) diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py index 0cba4cbc..9abb9833 100644 --- a/libmproxy/proxy.py +++ b/libmproxy/proxy.py @@ -267,7 +267,10 @@ class ProxyHandler(tcp.BaseHandler): def read_request(self, client_conn): if self.config.transparent_proxy: - host, port = self.config.transparent_proxy["resolver"].original_addr(self.connection) + orig = self.config.transparent_proxy["resolver"].original_addr(self.connection) + if not orig: + raise ProxyError(502, "Transparent mode failure: could not resolve original destination.") + host, port = orig if not self.ssl_established and (port in self.config.transparent_proxy["sslports"]): scheme = "https" certfile = self.find_cert(host, port, None) |