diff options
Diffstat (limited to 'libmproxy/proxy.py')
-rw-r--r-- | libmproxy/proxy.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py index 6114922e..3098aff4 100644 --- a/libmproxy/proxy.py +++ b/libmproxy/proxy.py @@ -231,6 +231,9 @@ class ProxyHandler(tcp.BaseHandler): sc.rfile.reset_timestamps() try: tsstart = utils.timestamp() + peername = sc.connection.getpeername() + if peername: + request.ip = peername[0] httpversion, code, msg, headers, content = http.read_response( sc.rfile, request.method, @@ -302,13 +305,15 @@ class ProxyHandler(tcp.BaseHandler): def find_cert(self, cc, host, port, sni): if self.config.certfile: - return certutils.SSLCert.from_pem(file(self.config.certfile, "r").read()) + with open(self.config.certfile, "rb") as f: + return certutils.SSLCert.from_pem(f.read()) else: sans = [] if not self.config.no_upstream_cert: conn = self.get_server_connection(cc, "https", host, port, sni) sans = conn.cert.altnames - host = conn.cert.cn.decode("utf8").encode("idna") + if conn.cert.cn: + host = conn.cert.cn.decode("utf8").encode("idna") ret = self.config.certstore.get_cert(host, sans, self.config.cacert) if not ret: raise ProxyError(502, "Unable to generate dummy cert.") |