mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 18:18:25 +00:00
always decode alpn where required
This commit is contained in:
parent
fc5783c20e
commit
f997b7fe14
@ -6,6 +6,7 @@ import os
|
|||||||
from mitmproxy import stateobject
|
from mitmproxy import stateobject
|
||||||
from mitmproxy import certs
|
from mitmproxy import certs
|
||||||
from mitmproxy.net import tcp
|
from mitmproxy.net import tcp
|
||||||
|
from mitmproxy.utils import strutils
|
||||||
|
|
||||||
|
|
||||||
class ClientConnection(tcp.BaseHandler, stateobject.StateObject):
|
class ClientConnection(tcp.BaseHandler, stateobject.StateObject):
|
||||||
@ -52,9 +53,15 @@ class ClientConnection(tcp.BaseHandler, stateobject.StateObject):
|
|||||||
return bool(self.connection) and not self.finished
|
return bool(self.connection) and not self.finished
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
if self.alpn_proto_negotiated:
|
||||||
|
alpn = "[ALPN: {}] ".format(
|
||||||
|
strutils.bytes_to_escaped_str(self.alpn_proto_negotiated)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
alpn = ""
|
||||||
return "<ClientConnection: {ssl}{alpn}{address}>".format(
|
return "<ClientConnection: {ssl}{alpn}{address}>".format(
|
||||||
ssl="[ssl] " if self.ssl_established else "",
|
ssl="[ssl] " if self.ssl_established else "",
|
||||||
alpn="[ALPN: {}] ".format(self.alpn_proto_negotiated) if self.alpn_proto_negotiated else "",
|
alpn=alpn,
|
||||||
address=repr(self.address)
|
address=repr(self.address)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -71,7 +78,7 @@ class ClientConnection(tcp.BaseHandler, stateobject.StateObject):
|
|||||||
timestamp_end=float,
|
timestamp_end=float,
|
||||||
sni=str,
|
sni=str,
|
||||||
cipher_name=str,
|
cipher_name=str,
|
||||||
alpn_proto_negotiated=str,
|
alpn_proto_negotiated=bytes,
|
||||||
tls_version=str,
|
tls_version=str,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -162,9 +169,15 @@ class ServerConnection(tcp.TCPClient, stateobject.StateObject):
|
|||||||
ssl = "[ssl] "
|
ssl = "[ssl] "
|
||||||
else:
|
else:
|
||||||
ssl = ""
|
ssl = ""
|
||||||
|
if self.alpn_proto_negotiated:
|
||||||
|
alpn = "[ALPN: {}] ".format(
|
||||||
|
strutils.bytes_to_escaped_str(self.alpn_proto_negotiated)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
alpn = ""
|
||||||
return "<ServerConnection: {ssl}{alpn}{address}>".format(
|
return "<ServerConnection: {ssl}{alpn}{address}>".format(
|
||||||
ssl=ssl,
|
ssl=ssl,
|
||||||
alpn="[ALPN: {}] ".format(self.alpn_proto_negotiated) if self.alpn_proto_negotiated else "",
|
alpn=alpn,
|
||||||
address=repr(self.address)
|
address=repr(self.address)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -179,7 +192,7 @@ class ServerConnection(tcp.TCPClient, stateobject.StateObject):
|
|||||||
ssl_established=bool,
|
ssl_established=bool,
|
||||||
cert=certs.SSLCert,
|
cert=certs.SSLCert,
|
||||||
sni=str,
|
sni=str,
|
||||||
alpn_proto_negotiated=str,
|
alpn_proto_negotiated=bytes,
|
||||||
timestamp_start=float,
|
timestamp_start=float,
|
||||||
timestamp_tcp_setup=float,
|
timestamp_tcp_setup=float,
|
||||||
timestamp_ssl_setup=float,
|
timestamp_ssl_setup=float,
|
||||||
|
@ -72,7 +72,7 @@ def tclient_conn():
|
|||||||
timestamp_end=3,
|
timestamp_end=3,
|
||||||
sni="address",
|
sni="address",
|
||||||
cipher_name="cipher",
|
cipher_name="cipher",
|
||||||
alpn_proto_negotiated=None,
|
alpn_proto_negotiated=b"http/1.1",
|
||||||
tls_version="TLSv1.2",
|
tls_version="TLSv1.2",
|
||||||
))
|
))
|
||||||
c.reply = controller.DummyReply()
|
c.reply = controller.DummyReply()
|
||||||
|
@ -2,6 +2,7 @@ import urwid
|
|||||||
|
|
||||||
from mitmproxy.tools.console import common, searchable
|
from mitmproxy.tools.console import common, searchable
|
||||||
from mitmproxy.utils import human
|
from mitmproxy.utils import human
|
||||||
|
from mitmproxy.utils import strutils
|
||||||
|
|
||||||
|
|
||||||
def maybe_timestamp(base, attr):
|
def maybe_timestamp(base, attr):
|
||||||
@ -77,7 +78,7 @@ def flowdetails(state, flow):
|
|||||||
parts.append(
|
parts.append(
|
||||||
[
|
[
|
||||||
"Alt names",
|
"Alt names",
|
||||||
", ".join(str(x) for x in c.altnames)
|
", ".join(strutils.bytes_to_escaped_str(x) for x in c.altnames)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
text.extend(
|
text.extend(
|
||||||
|
@ -34,6 +34,12 @@ def flow_to_json(flow: mitmproxy.flow.Flow) -> dict:
|
|||||||
"type": flow.type,
|
"type": flow.type,
|
||||||
"modified": flow.modified(),
|
"modified": flow.modified(),
|
||||||
}
|
}
|
||||||
|
# .alpn_proto_negotiated is bytes, we need to decode that.
|
||||||
|
for conn in "client_conn", "server_conn":
|
||||||
|
if f[conn]["alpn_proto_negotiated"] is None:
|
||||||
|
continue
|
||||||
|
f[conn]["alpn_proto_negotiated"] = \
|
||||||
|
f[conn]["alpn_proto_negotiated"].decode(errors="backslashreplace")
|
||||||
if flow.error:
|
if flow.error:
|
||||||
f["error"] = flow.error.get_state()
|
f["error"] = flow.error.get_state()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user