From 89f22f735944989912a7a0394dd7e80d420cb0f3 Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Mon, 27 Jul 2015 11:46:49 +0200 Subject: refactor connection & protocol handling --- libmproxy/proxy/connection.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'libmproxy/proxy') diff --git a/libmproxy/proxy/connection.py b/libmproxy/proxy/connection.py index 5219023b..54b3688e 100644 --- a/libmproxy/proxy/connection.py +++ b/libmproxy/proxy/connection.py @@ -68,7 +68,15 @@ class ClientConnection(tcp.BaseHandler, stateobject.StateObject): return f def convert_to_ssl(self, *args, **kwargs): - tcp.BaseHandler.convert_to_ssl(self, *args, **kwargs) + def alpn_select_callback(conn_, options): + if alpn_select in options: + return bytes(alpn_select) + else: # pragma no cover + return options[0] + + # TODO: read ALPN from server and select same proto for client conn + + tcp.BaseHandler.convert_to_ssl(self, alpn_select=alpn_select_callback, *args, **kwargs) self.timestamp_ssl_setup = utils.timestamp() def finish(self): @@ -160,7 +168,10 @@ class ServerConnection(tcp.TCPClient, stateobject.StateObject): self.address.host.encode("idna")) + ".pem" if os.path.exists(path): clientcert = path - self.convert_to_ssl(cert=clientcert, sni=sni, **kwargs) + + # TODO: read ALPN from client and use same list for server conn + + self.convert_to_ssl(cert=clientcert, sni=sni, alpn_protos=['h2'], **kwargs) self.sni = sni self.timestamp_ssl_setup = utils.timestamp() -- cgit v1.2.3 From 4f38c6b90e239d192863dee271e267b498c72206 Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Thu, 30 Jul 2015 13:52:50 +0200 Subject: attach application protocol to connection --- libmproxy/proxy/connection.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'libmproxy/proxy') diff --git a/libmproxy/proxy/connection.py b/libmproxy/proxy/connection.py index 54b3688e..a0bf2af9 100644 --- a/libmproxy/proxy/connection.py +++ b/libmproxy/proxy/connection.py @@ -23,6 +23,7 @@ class ClientConnection(tcp.BaseHandler, stateobject.StateObject): self.timestamp_start = utils.timestamp() self.timestamp_end = None self.timestamp_ssl_setup = None + self.protocol = None def __repr__(self): return "".format( @@ -58,6 +59,8 @@ class ClientConnection(tcp.BaseHandler, stateobject.StateObject): return copy.copy(self) def send(self, message): + if isinstance(message, list): + message = b''.join(message) self.wfile.write(message) self.wfile.flush() @@ -93,6 +96,7 @@ class ServerConnection(tcp.TCPClient, stateobject.StateObject): self.timestamp_end = None self.timestamp_tcp_setup = None self.timestamp_ssl_setup = None + self.protocol = None def __repr__(self): if self.ssl_established and self.sni: @@ -157,6 +161,8 @@ class ServerConnection(tcp.TCPClient, stateobject.StateObject): self.timestamp_tcp_setup = utils.timestamp() def send(self, message): + if isinstance(message, list): + message = b''.join(message) self.wfile.write(message) self.wfile.flush() -- cgit v1.2.3