diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2012-06-14 21:57:55 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2012-06-14 21:57:55 +1200 |
commit | 176d819559e01125c6fe2a34c86cb47c62f49b27 (patch) | |
tree | be582879c1c84c543f71da7be1f6f9a91320c132 | |
parent | 8dabf88ae53cd8c2a3246a880008305bd7bd292c (diff) | |
download | mitmproxy-176d819559e01125c6fe2a34c86cb47c62f49b27.tar.gz mitmproxy-176d819559e01125c6fe2a34c86cb47c62f49b27.tar.bz2 mitmproxy-176d819559e01125c6fe2a34c86cb47c62f49b27.zip |
Move server comms to OpenSSL.
-rw-r--r-- | libmproxy/proxy.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py index c3daca14..ea38b1e8 100644 --- a/libmproxy/proxy.py +++ b/libmproxy/proxy.py @@ -20,7 +20,7 @@ """ import sys, os, string, socket, time import shutil, tempfile, threading -import optparse, SocketServer, ssl +import optparse, SocketServer import utils, flow, certutils, version, wsgi from OpenSSL import SSL @@ -310,14 +310,19 @@ class ServerConnection: clientcert = None else: clientcert = None - server = ssl.wrap_socket(server, certfile = clientcert) + context = SSL.Context(SSL.SSLv23_METHOD) + if clientcert: + context.use_certificate_file(clientcert) + server = SSL.Connection(context, server) server.connect((addr, self.port)) if self.scheme == "https": - self.cert = server.getpeercert(True) + self.cert = server.get_peer_certificate() + self.rfile, self.wfile = FileLike(server), FileLike(server) + else: + self.rfile, self.wfile = server.makefile('rb'), server.makefile('wb') except socket.error, err: raise ProxyError(502, 'Error connecting to "%s": %s' % (self.host, err)) self.sock = server - self.rfile, self.wfile = server.makefile('rb'), server.makefile('wb') def send(self, request): self.requestcount += 1 |