diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2012-06-13 18:16:47 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2012-06-13 18:16:47 +1200 |
commit | 8a9352b3f7e49f169b8bffeab765c3e74d9d7833 (patch) | |
tree | 2750aeee2524fae35a585725078ac38515f32a41 /libmproxy/proxy.py | |
parent | d032504b17daf9e057172afa2e36b9206db5cac1 (diff) | |
download | mitmproxy-8a9352b3f7e49f169b8bffeab765c3e74d9d7833.tar.gz mitmproxy-8a9352b3f7e49f169b8bffeab765c3e74d9d7833.tar.bz2 mitmproxy-8a9352b3f7e49f169b8bffeab765c3e74d9d7833.zip |
First draft conversion of server to PyOpenSSL.
Diffstat (limited to 'libmproxy/proxy.py')
-rw-r--r-- | libmproxy/proxy.py | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py index 8b2f6aab..83ec0d56 100644 --- a/libmproxy/proxy.py +++ b/libmproxy/proxy.py @@ -22,6 +22,7 @@ import sys, os, string, socket, time import shutil, tempfile, threading import optparse, SocketServer, ssl import utils, flow, certutils, version, wsgi +from OpenSSL import SSL class ProxyError(Exception): @@ -239,7 +240,7 @@ class FileLike: def flush(self): pass - + def read(self, length): result = '' while len(result) < length: @@ -247,11 +248,16 @@ class FileLike: data = self.o.read(length) except AttributeError: break + except SSL.ZeroReturnError: + break if not data: break result += data return result + def write(self, v): + self.o.sendall(v) + def readline(self, size = None): result = '' bytes_read = 0 @@ -463,16 +469,21 @@ class ProxyHandler(SocketServer.StreamRequestHandler): 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) + ctx = SSL.Context(SSL.SSLv23_METHOD) + ctx.use_privatekey_file(self.config.certfile or self.config.cacert) + ctx.use_certificate_file(cert) + self.connection = SSL.Connection(ctx, self.connection) + self.connection.set_accept_state() + #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) |