aboutsummaryrefslogtreecommitdiffstats
path: root/mitmproxy/proxy
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2019-11-12 02:59:01 +0100
committerMaximilian Hils <git@maximilianhils.com>2019-11-12 04:38:13 +0100
commitbdc15cbe0c0cd5175af1b58078d65d400cca71d1 (patch)
treeeb65d9f2e2c7c7d934a6d7bca53a24341d0b5a43 /mitmproxy/proxy
parentf97996126f7a7606f8601f0318f0a70a4e818c6c (diff)
downloadmitmproxy-bdc15cbe0c0cd5175af1b58078d65d400cca71d1.tar.gz
mitmproxy-bdc15cbe0c0cd5175af1b58078d65d400cca71d1.tar.bz2
mitmproxy-bdc15cbe0c0cd5175af1b58078d65d400cca71d1.zip
update mypy
Diffstat (limited to 'mitmproxy/proxy')
-rw-r--r--mitmproxy/proxy/config.py6
-rw-r--r--mitmproxy/proxy/protocol/http2.py18
-rw-r--r--mitmproxy/proxy/protocol/tls.py25
-rw-r--r--mitmproxy/proxy/root_context.py3
-rw-r--r--mitmproxy/proxy/server.py2
5 files changed, 30 insertions, 24 deletions
diff --git a/mitmproxy/proxy/config.py b/mitmproxy/proxy/config.py
index ae2ec68b..e98faabf 100644
--- a/mitmproxy/proxy/config.py
+++ b/mitmproxy/proxy/config.py
@@ -34,9 +34,9 @@ class ProxyConfig:
def __init__(self, options: moptions.Options) -> None:
self.options = options
- self.check_filter: HostMatcher = None
- self.check_tcp: HostMatcher = None
- self.certstore: certs.CertStore = None
+ self.certstore: certs.CertStore
+ self.check_filter: typing.Optional[HostMatcher] = None
+ self.check_tcp: typing.Optional[HostMatcher] = None
self.upstream_server: typing.Optional[server_spec.ServerSpec] = None
self.configure(options, set(options.keys()))
options.changed.connect(self.configure)
diff --git a/mitmproxy/proxy/protocol/http2.py b/mitmproxy/proxy/protocol/http2.py
index 42b61f4d..a5870e6c 100644
--- a/mitmproxy/proxy/protocol/http2.py
+++ b/mitmproxy/proxy/protocol/http2.py
@@ -1,7 +1,7 @@
import threading
import time
import functools
-from typing import Dict, Callable, Any, List # noqa
+from typing import Dict, Callable, Any, List, Optional # noqa
import h2.exceptions
from h2 import connection
@@ -382,15 +382,15 @@ class Http2SingleStreamLayer(httpbase._HttpTransmissionLayer, basethread.BaseThr
ctx, name="Http2SingleStreamLayer-{}".format(stream_id)
)
self.h2_connection = h2_connection
- self.zombie: float = None
+ self.zombie: Optional[float] = None
self.client_stream_id: int = stream_id
- self.server_stream_id: int = None
+ self.server_stream_id: Optional[int] = None
self.request_headers = request_headers
- self.response_headers: mitmproxy.net.http.Headers = None
+ self.response_headers: Optional[mitmproxy.net.http.Headers] = None
self.pushed = False
- self.timestamp_start: float = None
- self.timestamp_end: float = None
+ self.timestamp_start: Optional[float] = None
+ self.timestamp_end: Optional[float] = None
self.request_arrived = threading.Event()
self.request_data_queue: queue.Queue[bytes] = queue.Queue()
@@ -404,9 +404,9 @@ class Http2SingleStreamLayer(httpbase._HttpTransmissionLayer, basethread.BaseThr
self.no_body = False
- self.priority_exclusive: bool = None
- self.priority_depends_on: int = None
- self.priority_weight: int = None
+ self.priority_exclusive: bool
+ self.priority_depends_on: Optional[int] = None
+ self.priority_weight: Optional[int] = None
self.handled_priority_event: Any = None
def kill(self):
diff --git a/mitmproxy/proxy/protocol/tls.py b/mitmproxy/proxy/protocol/tls.py
index 3a60f79f..282df60d 100644
--- a/mitmproxy/proxy/protocol/tls.py
+++ b/mitmproxy/proxy/protocol/tls.py
@@ -198,12 +198,12 @@ CIPHER_ID_NAME_MAP = {
# We manually need to specify this, otherwise OpenSSL may select a non-HTTP2 cipher by default.
# https://ssl-config.mozilla.org/#config=old
DEFAULT_CLIENT_CIPHERS = (
- b"ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:"
- b"ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:"
- b"DHE-RSA-AES256-GCM-SHA384:DHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:"
- b"ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:"
- b"ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA256:AES128-GCM-SHA256:"
- b"AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA"
+ "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:"
+ "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:"
+ "DHE-RSA-AES256-GCM-SHA384:DHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:"
+ "ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:"
+ "ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA256:AES128-GCM-SHA256:"
+ "AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA"
)
@@ -320,14 +320,18 @@ class TlsLayer(base.Layer):
return self._server_tls
@property
- def server_sni(self):
+ def server_sni(self) -> Optional[str]:
"""
The Server Name Indication we want to send with the next server TLS handshake.
"""
if self._custom_server_sni is False:
return None
+ elif self._custom_server_sni:
+ return self._custom_server_sni
+ elif self._client_hello and self._client_hello.sni:
+ return self._client_hello.sni.decode("idna")
else:
- return self._custom_server_sni or self._client_hello and self._client_hello.sni.decode("idna")
+ return None
@property
def alpn_for_client_connection(self):
@@ -388,11 +392,12 @@ class TlsLayer(base.Layer):
# raises ann error.
self.client_conn.rfile.peek(1)
except exceptions.TlsException as e:
+ sni_str = self._client_hello.sni and self._client_hello.sni.decode("idna")
raise exceptions.ClientHandshakeException(
"Cannot establish TLS with client (sni: {sni}): {e}".format(
- sni=self._client_hello.sni.decode("idna"), e=repr(e)
+ sni=sni_str, e=repr(e)
),
- self._client_hello.sni.decode("idna") or repr(self.server_conn.address)
+ sni_str or repr(self.server_conn.address)
)
def _establish_tls_with_server(self):
diff --git a/mitmproxy/proxy/root_context.py b/mitmproxy/proxy/root_context.py
index 74a048ad..3d4e8660 100644
--- a/mitmproxy/proxy/root_context.py
+++ b/mitmproxy/proxy/root_context.py
@@ -57,7 +57,8 @@ class RootContext:
except exceptions.TlsProtocolException as e:
self.log("Cannot parse Client Hello: %s" % repr(e), "error")
else:
- is_filtered = self.config.check_filter((client_hello.sni.decode("idna"), 443))
+ sni_str = client_hello.sni and client_hello.sni.decode("idna")
+ is_filtered = self.config.check_filter((sni_str, 443))
if is_filtered:
return protocol.RawTCPLayer(top_layer, ignore=True)
diff --git a/mitmproxy/proxy/server.py b/mitmproxy/proxy/server.py
index 44ae5697..3688b677 100644
--- a/mitmproxy/proxy/server.py
+++ b/mitmproxy/proxy/server.py
@@ -35,6 +35,7 @@ class DummyServer:
class ProxyServer(tcp.TCPServer):
allow_reuse_address = True
bound = True
+ channel: controller.Channel
def __init__(self, config: config.ProxyConfig) -> None:
"""
@@ -53,7 +54,6 @@ class ProxyServer(tcp.TCPServer):
raise exceptions.ServerException(
'Error starting proxy server: ' + repr(e)
) from e
- self.channel: controller.Channel = None
def set_channel(self, channel):
self.channel = channel