aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/complex/dns_spoofing.py2
-rw-r--r--examples/complex/har_dump.py4
-rw-r--r--mitmproxy/connections.py56
-rw-r--r--mitmproxy/io/compat.py26
-rw-r--r--mitmproxy/net/tcp.py12
-rw-r--r--mitmproxy/proxy/protocol/tls.py2
-rw-r--r--mitmproxy/test/tflow.py8
-rw-r--r--mitmproxy/tools/console/flowdetailview.py8
-rw-r--r--mitmproxy/types.py4
-rw-r--r--mitmproxy/version.py2
-rw-r--r--pathod/pathod.py2
-rw-r--r--pathod/protocols/websockets.py2
-rw-r--r--test/mitmproxy/addons/test_cut.py4
-rw-r--r--test/mitmproxy/net/test_tcp.py2
-rw-r--r--test/mitmproxy/proxy/protocol/test_websocket.py2
-rw-r--r--test/mitmproxy/proxy/test_server.py4
-rw-r--r--test/mitmproxy/test_connections.py8
17 files changed, 79 insertions, 69 deletions
diff --git a/examples/complex/dns_spoofing.py b/examples/complex/dns_spoofing.py
index 632783a7..e28934ab 100644
--- a/examples/complex/dns_spoofing.py
+++ b/examples/complex/dns_spoofing.py
@@ -33,7 +33,7 @@ parse_host_header = re.compile(r"^(?P<host>[^:]+|\[.+\])(?::(?P<port>\d+))?$")
class Rerouter:
def request(self, flow):
- if flow.client_conn.ssl_established:
+ if flow.client_conn.tls_established:
flow.request.scheme = "https"
sni = flow.client_conn.connection.get_servername()
port = 443
diff --git a/examples/complex/har_dump.py b/examples/complex/har_dump.py
index 21bcc341..66a81a7d 100644
--- a/examples/complex/har_dump.py
+++ b/examples/complex/har_dump.py
@@ -58,8 +58,8 @@ def response(flow):
connect_time = (flow.server_conn.timestamp_tcp_setup -
flow.server_conn.timestamp_start)
- if flow.server_conn.timestamp_ssl_setup is not None:
- ssl_time = (flow.server_conn.timestamp_ssl_setup -
+ if flow.server_conn.timestamp_tls_setup is not None:
+ ssl_time = (flow.server_conn.timestamp_tls_setup -
flow.server_conn.timestamp_tcp_setup)
SERVERS_SEEN.add(flow.server_conn)
diff --git a/mitmproxy/connections.py b/mitmproxy/connections.py
index 01721a71..7cc50f66 100644
--- a/mitmproxy/connections.py
+++ b/mitmproxy/connections.py
@@ -16,11 +16,11 @@ class ClientConnection(tcp.BaseHandler, stateobject.StateObject):
Attributes:
address: Remote address
- ssl_established: True if TLS is established, False otherwise
+ tls_established: True if TLS is established, False otherwise
clientcert: The TLS client certificate
mitmcert: The MITM'ed TLS server certificate presented to the client
timestamp_start: Connection start timestamp
- timestamp_ssl_setup: TLS established timestamp
+ timestamp_tls_setup: TLS established timestamp
timestamp_end: Connection end timestamp
sni: Server Name Indication sent by client during the TLS handshake
cipher_name: The current used cipher
@@ -40,13 +40,13 @@ class ClientConnection(tcp.BaseHandler, stateobject.StateObject):
self.rfile = None
self.address = None
self.clientcert = None
- self.ssl_established = None
+ self.tls_established = None
self.id = str(uuid.uuid4())
self.mitmcert = None
self.timestamp_start = time.time()
self.timestamp_end = None
- self.timestamp_ssl_setup = None
+ self.timestamp_tls_setup = None
self.sni = None
self.cipher_name = None
self.alpn_proto_negotiated = None
@@ -56,7 +56,7 @@ class ClientConnection(tcp.BaseHandler, stateobject.StateObject):
return bool(self.connection) and not self.finished
def __repr__(self):
- if self.ssl_established:
+ if self.tls_established:
tls = "[{}] ".format(self.tls_version)
else:
tls = ""
@@ -83,22 +83,14 @@ class ClientConnection(tcp.BaseHandler, stateobject.StateObject):
def __hash__(self):
return hash(self.id)
- @property
- def tls_established(self):
- return self.ssl_established
-
- @tls_established.setter
- def tls_established(self, value):
- self.ssl_established = value
-
_stateobject_attributes = dict(
id=str,
address=tuple,
- ssl_established=bool,
+ tls_established=bool,
clientcert=certs.SSLCert,
mitmcert=certs.SSLCert,
timestamp_start=float,
- timestamp_ssl_setup=float,
+ timestamp_tls_setup=float,
timestamp_end=float,
sni=str,
cipher_name=str,
@@ -125,10 +117,10 @@ class ClientConnection(tcp.BaseHandler, stateobject.StateObject):
address=address,
clientcert=None,
mitmcert=None,
- ssl_established=False,
+ tls_established=False,
timestamp_start=None,
timestamp_end=None,
- timestamp_ssl_setup=None,
+ timestamp_tls_setup=None,
sni=None,
cipher_name=None,
alpn_proto_negotiated=None,
@@ -137,7 +129,7 @@ class ClientConnection(tcp.BaseHandler, stateobject.StateObject):
def convert_to_ssl(self, cert, *args, **kwargs):
super().convert_to_ssl(cert, *args, **kwargs)
- self.timestamp_ssl_setup = time.time()
+ self.timestamp_tls_setup = time.time()
self.mitmcert = cert
sni = self.connection.get_servername()
if sni:
@@ -162,7 +154,7 @@ class ServerConnection(tcp.TCPClient, stateobject.StateObject):
address: Remote address. Can be both a domain or an IP address.
ip_address: Resolved remote IP address.
source_address: Local IP address or client's source IP address.
- ssl_established: True if TLS is established, False otherwise
+ tls_established: True if TLS is established, False otherwise
cert: The certificate presented by the remote during the TLS handshake
sni: Server Name Indication sent by the proxy during the TLS handshake
alpn_proto_negotiated: The negotiated application protocol
@@ -170,7 +162,7 @@ class ServerConnection(tcp.TCPClient, stateobject.StateObject):
via: The underlying server connection (e.g. the connection to the upstream proxy in upstream proxy mode)
timestamp_start: Connection start timestamp
timestamp_tcp_setup: TCP ACK received timestamp
- timestamp_ssl_setup: TLS established timestamp
+ timestamp_tls_setup: TLS established timestamp
timestamp_end: Connection end timestamp
"""
@@ -184,15 +176,15 @@ class ServerConnection(tcp.TCPClient, stateobject.StateObject):
self.timestamp_start = None
self.timestamp_end = None
self.timestamp_tcp_setup = None
- self.timestamp_ssl_setup = None
+ self.timestamp_tls_setup = None
def connected(self):
return bool(self.connection) and not self.finished
def __repr__(self):
- if self.ssl_established and self.sni:
+ if self.tls_established and self.sni:
tls = "[{}: {}] ".format(self.tls_version or "TLS", self.sni)
- elif self.ssl_established:
+ elif self.tls_established:
tls = "[{}] ".format(self.tls_version or "TLS")
else:
tls = ""
@@ -217,27 +209,19 @@ class ServerConnection(tcp.TCPClient, stateobject.StateObject):
def __hash__(self):
return hash(self.id)
- @property
- def tls_established(self):
- return self.ssl_established
-
- @tls_established.setter
- def tls_established(self, value):
- self.ssl_established = value
-
_stateobject_attributes = dict(
id=str,
address=tuple,
ip_address=tuple,
source_address=tuple,
- ssl_established=bool,
+ tls_established=bool,
cert=certs.SSLCert,
sni=str,
alpn_proto_negotiated=bytes,
tls_version=str,
timestamp_start=float,
timestamp_tcp_setup=float,
- timestamp_ssl_setup=float,
+ timestamp_tls_setup=float,
timestamp_end=float,
)
@@ -258,10 +242,10 @@ class ServerConnection(tcp.TCPClient, stateobject.StateObject):
alpn_proto_negotiated=None,
tls_version=None,
source_address=('', 0),
- ssl_established=False,
+ tls_established=False,
timestamp_start=None,
timestamp_tcp_setup=None,
- timestamp_ssl_setup=None,
+ timestamp_tls_setup=None,
timestamp_end=None,
via=None
))
@@ -295,7 +279,7 @@ class ServerConnection(tcp.TCPClient, stateobject.StateObject):
self.sni = sni
self.alpn_proto_negotiated = self.get_alpn_proto_negotiated()
self.tls_version = self.connection.get_protocol_version_name()
- self.timestamp_ssl_setup = time.time()
+ self.timestamp_tls_setup = time.time()
def finish(self):
tcp.TCPClient.finish(self)
diff --git a/mitmproxy/io/compat.py b/mitmproxy/io/compat.py
index da9d2a44..221288c6 100644
--- a/mitmproxy/io/compat.py
+++ b/mitmproxy/io/compat.py
@@ -1,5 +1,9 @@
"""
This module handles the import of mitmproxy flows generated by old versions.
+
+The flow file version is decoupled from the mitmproxy release cycle (since
+v3.0.0dev) and versioning. Every change or migration gets a new flow file
+version number, this prevents issues with developer builds and snapshots.
"""
import uuid
from typing import Any, Dict, Mapping, Union # noqa
@@ -119,6 +123,7 @@ def convert_200_300(data):
def convert_300_4(data):
data["version"] = 4
+ # Ths is an empty migration to transition to the new versioning scheme.
return data
@@ -149,6 +154,25 @@ def convert_4_5(data):
return data
+def convert_5_6(data):
+ data["version"] = 6
+ data["client_conn"]["tls_established"] = data["client_conn"].pop("ssl_established")
+ data["client_conn"]["timestamp_tls_setup"] = data["client_conn"].pop("timestamp_ssl_setup")
+ data["server_conn"]["tls_established"] = data["server_conn"].pop("ssl_established")
+ data["server_conn"]["timestamp_tls_setup"] = data["server_conn"].pop("timestamp_ssl_setup")
+ if data["server_conn"]["via"]:
+ data["server_conn"]["via"]["tls_established"] = data["server_conn"]["via"].pop("ssl_established", None)
+ data["server_conn"]["via"]["timestamp_tls_setup"] = data["server_conn"]["via"].pop("timestamp_ssl_setup", None)
+ return data
+
+
+# def convert_6_7(data):
+# data["version"] = 7
+# # Your changes here!
+# # Make sure to also increment FLOW_FORMAT_VERSION.
+# return data
+
+
def _convert_dict_keys(o: Any) -> Any:
if isinstance(o, dict):
return {strutils.always_str(k): _convert_dict_keys(v) for k, v in o.items()}
@@ -201,6 +225,8 @@ converters = {
(2, 0): convert_200_300,
(3, 0): convert_300_4,
4: convert_4_5,
+ 5: convert_5_6,
+ # 6: convert_6_7,
}
diff --git a/mitmproxy/net/tcp.py b/mitmproxy/net/tcp.py
index d08938c9..2a456ba0 100644
--- a/mitmproxy/net/tcp.py
+++ b/mitmproxy/net/tcp.py
@@ -301,11 +301,11 @@ class _Connection:
self.rfile = None
self.wfile = None
- self.ssl_established = False
+ self.tls_established = False
self.finished = False
def get_current_cipher(self):
- if not self.ssl_established:
+ if not self.tls_established:
return None
name = self.connection.get_cipher_name()
@@ -406,7 +406,7 @@ class TCPClient(_Connection):
for i in self.connection.get_peer_cert_chain():
self.server_certs.append(certs.SSLCert(i))
- self.ssl_established = True
+ self.tls_established = True
self.rfile.set_descriptor(self.connection)
self.wfile.set_descriptor(self.connection)
@@ -473,7 +473,7 @@ class TCPClient(_Connection):
return self.connection.gettimeout()
def get_alpn_proto_negotiated(self):
- if self.ssl_established:
+ if self.tls_established:
return self.connection.get_alpn_proto_negotiated()
else:
return b""
@@ -507,7 +507,7 @@ class BaseHandler(_Connection):
self.connection.do_handshake()
except SSL.Error as v:
raise exceptions.TlsException("SSL handshake error: %s" % repr(v))
- self.ssl_established = True
+ self.tls_established = True
cert = self.connection.get_peer_certificate()
if cert:
self.clientcert = certs.SSLCert(cert)
@@ -521,7 +521,7 @@ class BaseHandler(_Connection):
self.connection.settimeout(n)
def get_alpn_proto_negotiated(self):
- if self.ssl_established:
+ if self.tls_established:
return self.connection.get_alpn_proto_negotiated()
else:
return b""
diff --git a/mitmproxy/proxy/protocol/tls.py b/mitmproxy/proxy/protocol/tls.py
index 21bf1417..afe9b78c 100644
--- a/mitmproxy/proxy/protocol/tls.py
+++ b/mitmproxy/proxy/protocol/tls.py
@@ -524,7 +524,7 @@ 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 and self.client_conn.get_alpn_proto_negotiated():
+ if self.client_conn.tls_established and self.client_conn.get_alpn_proto_negotiated():
# 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.:
diff --git a/mitmproxy/test/tflow.py b/mitmproxy/test/tflow.py
index 05d194d6..60ec0899 100644
--- a/mitmproxy/test/tflow.py
+++ b/mitmproxy/test/tflow.py
@@ -157,9 +157,9 @@ def tclient_conn():
address=("127.0.0.1", 22),
clientcert=None,
mitmcert=None,
- ssl_established=False,
+ tls_established=False,
timestamp_start=946681200,
- timestamp_ssl_setup=946681201,
+ timestamp_tls_setup=946681201,
timestamp_end=946681206,
sni="address",
cipher_name="cipher",
@@ -184,9 +184,9 @@ def tserver_conn():
cert=None,
timestamp_start=946681202,
timestamp_tcp_setup=946681203,
- timestamp_ssl_setup=946681204,
+ timestamp_tls_setup=946681204,
timestamp_end=946681205,
- ssl_established=False,
+ tls_established=False,
sni="address",
alpn_proto_negotiated=None,
tls_version="TLSv1.2",
diff --git a/mitmproxy/tools/console/flowdetailview.py b/mitmproxy/tools/console/flowdetailview.py
index 32ac4b60..443ca526 100644
--- a/mitmproxy/tools/console/flowdetailview.py
+++ b/mitmproxy/tools/console/flowdetailview.py
@@ -119,11 +119,11 @@ def flowdetails(state, flow: http.HTTPFlow):
maybe_timestamp(cc, "timestamp_start")
)
)
- if cc.ssl_established:
+ if cc.tls_established:
parts.append(
(
"Client conn. TLS handshake",
- maybe_timestamp(cc, "timestamp_ssl_setup")
+ maybe_timestamp(cc, "timestamp_tls_setup")
)
)
@@ -140,11 +140,11 @@ def flowdetails(state, flow: http.HTTPFlow):
maybe_timestamp(sc, "timestamp_tcp_setup")
)
)
- if sc.ssl_established:
+ if sc.tls_established:
parts.append(
(
"Server conn. TLS handshake",
- maybe_timestamp(sc, "timestamp_ssl_setup")
+ maybe_timestamp(sc, "timestamp_tls_setup")
)
)
diff --git a/mitmproxy/types.py b/mitmproxy/types.py
index 8ae8b309..3875128d 100644
--- a/mitmproxy/types.py
+++ b/mitmproxy/types.py
@@ -267,14 +267,14 @@ class _CutSpecType(_BaseType):
"client_conn.address.host",
"client_conn.tls_version",
"client_conn.sni",
- "client_conn.ssl_established",
+ "client_conn.tls_established",
"server_conn.address.port",
"server_conn.address.host",
"server_conn.ip_address.host",
"server_conn.tls_version",
"server_conn.sni",
- "server_conn.ssl_established",
+ "server_conn.tls_established",
]
def completion(self, manager: _CommandBase, t: type, s: str) -> typing.Sequence[str]:
diff --git a/mitmproxy/version.py b/mitmproxy/version.py
index 20a303e8..a37f07cf 100644
--- a/mitmproxy/version.py
+++ b/mitmproxy/version.py
@@ -9,7 +9,7 @@ MITMPROXY = "mitmproxy " + VERSION
# Serialization format version. This is displayed nowhere, it just needs to be incremented by one
# for each change in the file format.
-FLOW_FORMAT_VERSION = 5
+FLOW_FORMAT_VERSION = 6
def get_version(dev: bool = False, build: bool = False, refresh: bool = False) -> str:
diff --git a/pathod/pathod.py b/pathod/pathod.py
index f8e64f9e..8abeaf41 100644
--- a/pathod/pathod.py
+++ b/pathod/pathod.py
@@ -170,7 +170,7 @@ class PathodHandler(tcp.BaseHandler):
),
cipher=None,
)
- if self.ssl_established:
+ if self.tls_established:
retlog["cipher"] = self.get_current_cipher()
m = utils.MemBool()
diff --git a/pathod/protocols/websockets.py b/pathod/protocols/websockets.py
index 2d1f1bf6..63e6ee0b 100644
--- a/pathod/protocols/websockets.py
+++ b/pathod/protocols/websockets.py
@@ -30,7 +30,7 @@ class WebsocketsProtocol:
),
cipher=None,
)
- if self.pathod_handler.ssl_established:
+ if self.pathod_handler.tls_established:
retlog["cipher"] = self.pathod_handler.get_current_cipher()
self.pathod_handler.addlog(retlog)
ld = language.websockets.NESTED_LEADER
diff --git a/test/mitmproxy/addons/test_cut.py b/test/mitmproxy/addons/test_cut.py
index 97577c60..cbcc8a8c 100644
--- a/test/mitmproxy/addons/test_cut.py
+++ b/test/mitmproxy/addons/test_cut.py
@@ -40,14 +40,14 @@ def test_extract():
["client_conn.address.host", "127.0.0.1"],
["client_conn.tls_version", "TLSv1.2"],
["client_conn.sni", "address"],
- ["client_conn.ssl_established", "false"],
+ ["client_conn.tls_established", "false"],
["server_conn.address.port", "22"],
["server_conn.address.host", "address"],
["server_conn.ip_address.host", "192.168.0.1"],
["server_conn.tls_version", "TLSv1.2"],
["server_conn.sni", "address"],
- ["server_conn.ssl_established", "false"],
+ ["server_conn.tls_established", "false"],
]
for spec, expected in tests:
ret = cut.extract(spec, tf)
diff --git a/test/mitmproxy/net/test_tcp.py b/test/mitmproxy/net/test_tcp.py
index e9084be4..2c792bc0 100644
--- a/test/mitmproxy/net/test_tcp.py
+++ b/test/mitmproxy/net/test_tcp.py
@@ -408,7 +408,7 @@ class TestSNI(tservers.ServerTestBase):
c = tcp.TCPClient(("127.0.0.1", self.port))
with c.connect():
c.convert_to_ssl(sni="mitmproxyäöüß.example.com")
- assert c.ssl_established
+ assert c.tls_established
assert "doesn't match" not in str(c.ssl_verification_error)
diff --git a/test/mitmproxy/proxy/protocol/test_websocket.py b/test/mitmproxy/proxy/protocol/test_websocket.py
index d9389faf..02dc0f76 100644
--- a/test/mitmproxy/proxy/protocol/test_websocket.py
+++ b/test/mitmproxy/proxy/protocol/test_websocket.py
@@ -102,7 +102,7 @@ class _WebSocketTestBase:
if self.ssl:
self.client.convert_to_ssl()
- assert self.client.ssl_established
+ assert self.client.tls_established
request = http.Request(
"relative",
diff --git a/test/mitmproxy/proxy/test_server.py b/test/mitmproxy/proxy/test_server.py
index 8dce9bcd..802054af 100644
--- a/test/mitmproxy/proxy/test_server.py
+++ b/test/mitmproxy/proxy/test_server.py
@@ -709,7 +709,7 @@ class TestProxy(tservers.HTTPProxyTest):
first_flow = self.master.state.flows[0]
second_flow = self.master.state.flows[1]
assert first_flow.server_conn.timestamp_tcp_setup
- assert first_flow.server_conn.timestamp_ssl_setup is None
+ assert first_flow.server_conn.timestamp_tls_setup is None
assert second_flow.server_conn.timestamp_tcp_setup
assert first_flow.server_conn.timestamp_tcp_setup == second_flow.server_conn.timestamp_tcp_setup
@@ -728,7 +728,7 @@ class TestProxySSL(tservers.HTTPProxyTest):
f = self.pathod("304:b@10k")
assert f.status_code == 304
first_flow = self.master.state.flows[0]
- assert first_flow.server_conn.timestamp_ssl_setup
+ assert first_flow.server_conn.timestamp_tls_setup
def test_via(self):
# tests that the ssl timestamp is present when ssl is used
diff --git a/test/mitmproxy/test_connections.py b/test/mitmproxy/test_connections.py
index 83f0bd34..74d964f6 100644
--- a/test/mitmproxy/test_connections.py
+++ b/test/mitmproxy/test_connections.py
@@ -41,10 +41,10 @@ class TestClientConnection:
def test_tls_established_property(self):
c = tflow.tclient_conn()
c.tls_established = True
- assert c.ssl_established
+ assert c.tls_established
assert c.tls_established
c.tls_established = False
- assert not c.ssl_established
+ assert not c.tls_established
assert not c.tls_established
def test_make_dummy(self):
@@ -113,10 +113,10 @@ class TestServerConnection:
def test_tls_established_property(self):
c = tflow.tserver_conn()
c.tls_established = True
- assert c.ssl_established
+ assert c.tls_established
assert c.tls_established
c.tls_established = False
- assert not c.ssl_established
+ assert not c.tls_established
assert not c.tls_established
def test_make_dummy(self):