diff options
Diffstat (limited to 'libmproxy/proxy/connection.py')
-rw-r--r-- | libmproxy/proxy/connection.py | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/libmproxy/proxy/connection.py b/libmproxy/proxy/connection.py index 5219023b..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 "<ClientConnection: {ssl}{host}:{port}>".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() @@ -68,7 +71,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): @@ -85,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: @@ -149,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() @@ -160,7 +174,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() |