diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2012-06-03 01:54:11 -0700 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2012-06-03 01:54:11 -0700 |
commit | 0a25c2263db1a43ad3f359fbefe98dd947fca0e8 (patch) | |
tree | b330338651c9e0b455e713b9e5788d03b6f5a45f | |
parent | 491f9bdceef039ec641e6e77d0d1e7e5fef1e50b (diff) | |
download | mitmproxy-0a25c2263db1a43ad3f359fbefe98dd947fca0e8.tar.gz mitmproxy-0a25c2263db1a43ad3f359fbefe98dd947fca0e8.tar.bz2 mitmproxy-0a25c2263db1a43ad3f359fbefe98dd947fca0e8.zip |
Factor out conversion to SSL connection.
-rw-r--r-- | libmproxy/proxy.py | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py index 92bdf5f4..2481ed12 100644 --- a/libmproxy/proxy.py +++ b/libmproxy/proxy.py @@ -381,6 +381,20 @@ class ProxyHandler(SocketServer.StreamRequestHandler): raise ProxyError(502, "mitmproxy: Unable to generate dummy cert.") return ret + def convert_to_ssl(self, cert): + kwargs = dict( + certfile = cert, + keyfile = self.config.certfile or self.config.cacert, + server_side = True, + ssl_version = ssl.PROTOCOL_SSLv23, + do_handshake_on_connect = True, + ) + if sys.version_info[1] > 6: + kwargs["ciphers"] = self.config.ciphers + self.connection = ssl.wrap_socket(self.connection, **kwargs) + self.rfile = FileLike(self.connection) + self.wfile = FileLike(self.connection) + def read_request(self, client_conn): line = self.rfile.readline() if line == "\r\n" or line == "\n": # Possible leftover from previous message @@ -401,18 +415,8 @@ class ProxyHandler(SocketServer.StreamRequestHandler): '\r\n' ) self.wfile.flush() - kwargs = dict( - certfile = self.find_cert(host, port), - keyfile = self.config.certfile or self.config.cacert, - server_side = True, - ssl_version = ssl.PROTOCOL_SSLv23, - do_handshake_on_connect = True, - ) - if sys.version_info[1] > 6: - kwargs["ciphers"] = self.config.ciphers - self.connection = ssl.wrap_socket(self.connection, **kwargs) - self.rfile = FileLike(self.connection) - self.wfile = FileLike(self.connection) + certfile = self.find_cert(host, port) + self.convert_to_ssl(certfile) method, scheme, host, port, path, httpminor = parse_request_line(self.rfile.readline()) if scheme is None: scheme = "https" |