diff options
author | Aldo Cortesi <aldo@corte.si> | 2016-11-14 08:50:29 +1300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-14 08:50:29 +1300 |
commit | 2d0a65a3f4fe5482cf6502d5dbbeba8b5125604c (patch) | |
tree | 08e2c7b7fd1b98c7912f2f87fea572ff7c4690c8 | |
parent | b636e4353a4804f92c8a3d56250874f7b081b691 (diff) | |
parent | 6fb706ec150315178b402ad1f3afe316c8c92aa8 (diff) | |
download | mitmproxy-2d0a65a3f4fe5482cf6502d5dbbeba8b5125604c.tar.gz mitmproxy-2d0a65a3f4fe5482cf6502d5dbbeba8b5125604c.tar.bz2 mitmproxy-2d0a65a3f4fe5482cf6502d5dbbeba8b5125604c.zip |
Merge pull request #1738 from Kriechi/fix-1737
restrict ALPN offers if host changes
-rw-r--r-- | mitmproxy/proxy/protocol/tls.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/mitmproxy/proxy/protocol/tls.py b/mitmproxy/proxy/protocol/tls.py index 796477b2..1cb9b3c2 100644 --- a/mitmproxy/proxy/protocol/tls.py +++ b/mitmproxy/proxy/protocol/tls.py @@ -432,7 +432,6 @@ class TlsLayer(base.Layer): def __alpn_select_callback(self, conn_, options): # This gets triggered if we haven't established an upstream connection yet. default_alpn = b'http/1.1' - # alpn_preference = b'h2' if self.alpn_for_client_connection in options: choice = bytes(self.alpn_for_client_connection) @@ -504,6 +503,17 @@ class TlsLayer(base.Layer): if alpn and b"h2" in alpn and not self.config.options.http2: alpn.remove(b"h2") + if self.client_conn.ssl_established: + # If the client has already negotiated an ALP, then force the + # server to use the same. This can only happen if the host gets + # changed after the initial connection was established. E.g.: + # * the client offers http/1.1 and h2, + # * the initial host is only capable of http/1.1, + # * then the first server connection negotiates http/1.1, + # * but after the server_conn change, the new host offers h2 + # * which results in garbage because the layers don' match. + alpn = [self.client_conn.connection.get_alpn_proto_negotiated()] + ciphers_server = self.config.options.ciphers_server if not ciphers_server and self._client_tls: ciphers_server = [] |