diff options
-rw-r--r-- | docs/install.rst | 10 | ||||
-rw-r--r-- | mitmproxy/addonmanager.py | 4 | ||||
-rw-r--r-- | mitmproxy/addons/view.py | 27 | ||||
-rw-r--r-- | mitmproxy/net/tcp.py | 2 | ||||
-rw-r--r-- | mitmproxy/options.py | 60 | ||||
-rw-r--r-- | mitmproxy/proxy/protocol/tls.py | 6 | ||||
-rw-r--r-- | mitmproxy/test/taddons.py | 2 | ||||
-rw-r--r-- | mitmproxy/tools/cmdline.py | 2 | ||||
-rw-r--r-- | mitmproxy/tools/console/consoleaddons.py | 48 | ||||
-rw-r--r-- | mitmproxy/tools/console/eventlog.py | 6 | ||||
-rw-r--r-- | mitmproxy/tools/console/statusbar.py | 6 | ||||
-rw-r--r-- | release/setup.py | 2 | ||||
-rw-r--r-- | test/mitmproxy/addons/test_view.py | 15 | ||||
-rw-r--r-- | test/mitmproxy/proxy/protocol/test_tls.py | 3 | ||||
-rw-r--r-- | test/mitmproxy/test_addonmanager.py | 2 | ||||
-rw-r--r-- | test/mitmproxy/tools/console/test_statusbar.py | 3 |
16 files changed, 109 insertions, 89 deletions
diff --git a/docs/install.rst b/docs/install.rst index 7753dc44..6f166c8a 100644 --- a/docs/install.rst +++ b/docs/install.rst @@ -85,8 +85,8 @@ libraries. This was tested on a fully patched installation of Ubuntu 16.04. .. code:: bash - sudo apt-get install python3-dev python3-pip libffi-dev libssl-dev - sudo pip3 install mitmproxy # or pip3 install --user mitmproxy + sudo apt-get install python3-pip + sudo pip3 install mitmproxy On older Ubuntu versions, e.g., **12.04** and **14.04**, you may need to install a newer version of Python. mitmproxy requires Python 3.5 or higher. Please take @@ -104,8 +104,8 @@ libraries. This was tested on a fully patched installation of Fedora 24. .. code:: bash - sudo dnf install make gcc redhat-rpm-config python3-devel python3-pip libffi-devel openssl-devel - sudo pip3 install mitmproxy # or pip3 install --user mitmproxy + sudo dnf install python3-pip + sudo pip3 install mitmproxy Make sure to have an up-to-date version of pip by running ``pip3 install -U pip``. @@ -121,7 +121,7 @@ You can check you Python version by running ``python3 --version``. .. code:: bash - sudo zypper install python3-pip python3-devel libffi-devel openssl-devel gcc-c++ + sudo zypper install python3-pip sudo pip3 install mitmproxy diff --git a/mitmproxy/addonmanager.py b/mitmproxy/addonmanager.py index 857ed530..31665548 100644 --- a/mitmproxy/addonmanager.py +++ b/mitmproxy/addonmanager.py @@ -202,6 +202,10 @@ class AddonManager: def __str__(self): return pprint.pformat([str(i) for i in self.chain]) + def __contains__(self, item): + name = _get_name(item) + return name in self.lookup + def handle_lifecycle(self, name, message): """ Handle a lifecycle event. diff --git a/mitmproxy/addons/view.py b/mitmproxy/addons/view.py index b2db0171..8ae1f341 100644 --- a/mitmproxy/addons/view.py +++ b/mitmproxy/addons/view.py @@ -145,6 +145,21 @@ class View(collections.Sequence): self.focus = Focus(self) self.settings = Settings(self) + def load(self, loader): + loader.add_option( + "view_order", str, "time", + "Flow sort order.", + choices=list(map(lambda c: c[1], orders)), + ) + loader.add_option( + "view_order_reversed", bool, False, + "Reverse the sorting order." + ) + loader.add_option( + "console_focus_follow", bool, False, + "Focus follows new flows." + ) + def store_count(self): return len(self._store) @@ -442,14 +457,14 @@ class View(collections.Sequence): "Invalid interception filter: %s" % ctx.options.view_filter ) self.set_filter(filt) - if "console_order" in updated: - if ctx.options.console_order not in self.orders: + if "view_order" in updated: + if ctx.options.view_order not in self.orders: raise exceptions.OptionsError( - "Unknown flow order: %s" % ctx.options.console_order + "Unknown flow order: %s" % ctx.options.view_order ) - self.set_order(self.orders[ctx.options.console_order]) - if "console_order_reversed" in updated: - self.set_reversed(ctx.options.console_order_reversed) + self.set_order(self.orders[ctx.options.view_order]) + if "view_order_reversed" in updated: + self.set_reversed(ctx.options.view_order_reversed) if "console_focus_follow" in updated: self.focus_follow = ctx.options.console_focus_follow diff --git a/mitmproxy/net/tcp.py b/mitmproxy/net/tcp.py index 0c2f0e28..e109236e 100644 --- a/mitmproxy/net/tcp.py +++ b/mitmproxy/net/tcp.py @@ -855,6 +855,8 @@ class TCPServer: if self.address[0] == 'localhost': raise socket.error("Binding to 'localhost' is prohibited. Please use '::1' or '127.0.0.1' directly.") + self.socket = None + try: # First try to bind an IPv6 socket, with possible IPv4 if the OS supports it. # This allows us to accept connections for ::1 and 127.0.0.1 on the same socket. diff --git a/mitmproxy/options.py b/mitmproxy/options.py index 1ecdd6a6..b008e588 100644 --- a/mitmproxy/options.py +++ b/mitmproxy/options.py @@ -4,29 +4,6 @@ from mitmproxy import optmanager from mitmproxy import contentviews from mitmproxy.net import tcp -# We redefine these here for now to avoid importing Urwid-related guff on -# platforms that don't support it, and circular imports. We can do better using -# a lazy checker down the track. -console_palettes = [ - "lowlight", - "lowdark", - "light", - "dark", - "solarized_light", - "solarized_dark" -] -view_orders = [ - "time", - "method", - "url", - "size", -] -console_layouts = [ - "single", - "vertical", - "horizontal", -] - log_verbosity = [ "error", "warn", @@ -475,43 +452,6 @@ class Options(optmanager.OptManager): "Intercept filter expression." ) - # Console options - self.add_option( - "console_layout", str, "single", - "Console layout.", - choices=sorted(console_layouts), - ) - self.add_option( - "console_layout_headers", bool, True, - "Show layout comonent headers", - ) - self.add_option( - "console_focus_follow", bool, False, - "Focus follows new flows." - ) - self.add_option( - "console_palette", str, "solarized_dark", - "Color palette.", - choices=sorted(console_palettes), - ) - self.add_option( - "console_palette_transparent", bool, False, - "Set transparent background for palette." - ) - self.add_option( - "console_mouse", bool, True, - "Console mouse interaction." - ) - self.add_option( - "console_order", str, "time", - "Flow sort order.", - choices=view_orders, - ) - self.add_option( - "console_order_reversed", bool, False, - "Reverse the sorting order." - ) - self.add_option( "view_filter", Optional[str], None, "Limit which flows are displayed." diff --git a/mitmproxy/proxy/protocol/tls.py b/mitmproxy/proxy/protocol/tls.py index b7bc6b1c..10eea4ae 100644 --- a/mitmproxy/proxy/protocol/tls.py +++ b/mitmproxy/proxy/protocol/tls.py @@ -292,7 +292,7 @@ class TlsClientHello: if self._client_hello.extensions: for extension in self._client_hello.extensions.extensions: if extension.type == 0x10: - return list(extension.body.alpn_protocols) + return list(x.name for x in extension.body.alpn_protocols) return [] @classmethod @@ -519,8 +519,8 @@ class TlsLayer(base.Layer): # We only support http/1.1 and h2. # If the server only supports spdy (next to http/1.1), it may select that # and mitmproxy would enter TCP passthrough mode, which we want to avoid. - alpn = [x.name for x in self._client_hello.alpn_protocols if - not (x.name.startswith(b"h2-") or x.name.startswith(b"spdy"))] + alpn = [x for x in self._client_hello.alpn_protocols if + not (x.startswith(b"h2-") or x.startswith(b"spdy"))] if alpn and b"h2" in alpn and not self.config.options.http2: alpn.remove(b"h2") diff --git a/mitmproxy/test/taddons.py b/mitmproxy/test/taddons.py index 6160746a..d966f1d5 100644 --- a/mitmproxy/test/taddons.py +++ b/mitmproxy/test/taddons.py @@ -105,6 +105,8 @@ class context: Options object with the given keyword arguments, then calls the configure method on the addon with the updated value. """ + if addon not in self.master.addons: + self.master.addons.register(addon) with self.options.rollback(kwargs.keys(), reraise=True): self.options.update(**kwargs) self.master.addons.invoke_addon( diff --git a/mitmproxy/tools/cmdline.py b/mitmproxy/tools/cmdline.py index 93ce6f24..d611a8d2 100644 --- a/mitmproxy/tools/cmdline.py +++ b/mitmproxy/tools/cmdline.py @@ -48,7 +48,7 @@ def common_options(parser, opts): ) parser.add_argument( "-v", "--verbose", - action="store_const", dest="verbose", const=3, + action="store_const", dest="verbose", const='debug', help="Increase log verbosity." ) diff --git a/mitmproxy/tools/console/consoleaddons.py b/mitmproxy/tools/console/consoleaddons.py index 853447cf..49934e4d 100644 --- a/mitmproxy/tools/console/consoleaddons.py +++ b/mitmproxy/tools/console/consoleaddons.py @@ -11,6 +11,26 @@ from mitmproxy.tools.console import overlay from mitmproxy.tools.console import signals from mitmproxy.tools.console import keymap +console_palettes = [ + "lowlight", + "lowdark", + "light", + "dark", + "solarized_light", + "solarized_dark" +] +view_orders = [ + "time", + "method", + "url", + "size", +] +console_layouts = [ + "single", + "vertical", + "horizontal", +] + class Logger: def log(self, evt): @@ -60,6 +80,34 @@ class ConsoleAddon: self.master = master self.started = False + def load(self, loader): + loader.add_option( + "console_layout", str, "single", + "Console layout.", + choices=sorted(console_layouts), + ) + loader.add_option( + "console_layout_headers", bool, True, + "Show layout comonent headers", + ) + loader.add_option( + "console_focus_follow", bool, False, + "Focus follows new flows." + ) + loader.add_option( + "console_palette", str, "solarized_dark", + "Color palette.", + choices=sorted(console_palettes), + ) + loader.add_option( + "console_palette_transparent", bool, False, + "Set transparent background for palette." + ) + loader.add_option( + "console_mouse", bool, True, + "Console mouse interaction." + ) + @command.command("console.layout.options") def layout_options(self) -> typing.Sequence[str]: """ diff --git a/mitmproxy/tools/console/eventlog.py b/mitmproxy/tools/console/eventlog.py index a76b910e..c3e5dd39 100644 --- a/mitmproxy/tools/console/eventlog.py +++ b/mitmproxy/tools/console/eventlog.py @@ -22,6 +22,12 @@ class EventLog(urwid.ListBox, layoutwidget.LayoutWidget): signals.sig_add_log.connect(self.sig_add_log) signals.sig_clear_log.connect(self.sig_clear_log) + def load(self, loader): + loader.add_option( + "console_focus_follow", bool, False, + "Focus follows new flows." + ) + def set_focus(self, index): if 0 <= index < len(self.walker): super().set_focus(index) diff --git a/mitmproxy/tools/console/statusbar.py b/mitmproxy/tools/console/statusbar.py index 5bfc611c..795b3d8a 100644 --- a/mitmproxy/tools/console/statusbar.py +++ b/mitmproxy/tools/console/statusbar.py @@ -199,10 +199,10 @@ class StatusBar(urwid.WidgetWrap): r.append("[") r.append(("heading_key", "M")) r.append(":%s]" % self.master.options.default_contentview) - if self.master.options.has_changed("console_order"): + if self.master.options.has_changed("view_order"): r.append("[") r.append(("heading_key", "o")) - r.append(":%s]" % self.master.options.console_order) + r.append(":%s]" % self.master.options.view_order) opts = [] if self.master.options.anticache: @@ -244,7 +244,7 @@ class StatusBar(urwid.WidgetWrap): else: offset = self.master.view.focus.index + 1 - if self.master.options.console_order_reversed: + if self.master.options.view_order_reversed: arrow = common.SYMBOL_UP else: arrow = common.SYMBOL_DOWN diff --git a/release/setup.py b/release/setup.py index 17b02ebc..0c4e6605 100644 --- a/release/setup.py +++ b/release/setup.py @@ -8,7 +8,7 @@ setup( "click>=6.2, <7.0", "twine>=1.6.5, <1.10", "pysftp==0.2.8", - "cryptography>=1.6, <1.9", + "cryptography>=2.0.0, <2.1", ], entry_points={ "console_scripts": [ diff --git a/test/mitmproxy/addons/test_view.py b/test/mitmproxy/addons/test_view.py index e8eeb591..1e0c3b55 100644 --- a/test/mitmproxy/addons/test_view.py +++ b/test/mitmproxy/addons/test_view.py @@ -7,6 +7,7 @@ from mitmproxy import flowfilter from mitmproxy import exceptions from mitmproxy import io from mitmproxy.test import taddons +from mitmproxy.tools.console import consoleaddons def tft(*, method="get", start=0): @@ -27,7 +28,7 @@ def test_order_refresh(): tf = tflow.tflow(resp=True) with taddons.context() as tctx: - tctx.configure(v, console_order="time") + tctx.configure(v, view_order="time") v.add([tf]) tf.request.timestamp_start = 1 assert not sargs @@ -300,12 +301,12 @@ def test_order(): v.request(tft(method="put", start=4)) assert [i.request.timestamp_start for i in v] == [1, 2, 3, 4] - tctx.configure(v, console_order="method") + tctx.configure(v, view_order="method") assert [i.request.method for i in v] == ["GET", "GET", "PUT", "PUT"] v.set_reversed(True) assert [i.request.method for i in v] == ["PUT", "PUT", "GET", "GET"] - tctx.configure(v, console_order="time") + tctx.configure(v, view_order="time") assert [i.request.timestamp_start for i in v] == [4, 3, 2, 1] v.set_reversed(False) @@ -425,6 +426,8 @@ def test_signals(): def test_focus_follow(): v = view.View() with taddons.context() as tctx: + console_addon = consoleaddons.ConsoleAddon(tctx.master) + tctx.configure(console_addon) tctx.configure(v, console_focus_follow=True, view_filter="~m get") v.add([tft(start=5)]) @@ -546,11 +549,11 @@ def test_configure(): with pytest.raises(Exception, match="Invalid interception filter"): tctx.configure(v, view_filter="~~") - tctx.configure(v, console_order="method") + tctx.configure(v, view_order="method") with pytest.raises(Exception, match="Unknown flow order"): - tctx.configure(v, console_order="no") + tctx.configure(v, view_order="no") - tctx.configure(v, console_order_reversed=True) + tctx.configure(v, view_order_reversed=True) tctx.configure(v, console_focus_follow=True) assert v.focus_follow diff --git a/test/mitmproxy/proxy/protocol/test_tls.py b/test/mitmproxy/proxy/protocol/test_tls.py index 980ba7bd..e17ee46f 100644 --- a/test/mitmproxy/proxy/protocol/test_tls.py +++ b/test/mitmproxy/proxy/protocol/test_tls.py @@ -23,5 +23,4 @@ class TestClientHello: ) c = TlsClientHello(data) assert c.sni == 'example.com' - assert c.alpn_protocols[0].name == b'h2' - assert c.alpn_protocols[1].name == b'http/1.1' + assert c.alpn_protocols == [b'h2', b'http/1.1'] diff --git a/test/mitmproxy/test_addonmanager.py b/test/mitmproxy/test_addonmanager.py index accf48e0..274d2d90 100644 --- a/test/mitmproxy/test_addonmanager.py +++ b/test/mitmproxy/test_addonmanager.py @@ -137,6 +137,8 @@ def test_simple(): a.trigger("custom") assert ta.custom_called + assert ta in a + def test_load_option(): o = options.Options() diff --git a/test/mitmproxy/tools/console/test_statusbar.py b/test/mitmproxy/tools/console/test_statusbar.py index 2f7825c9..b131a5d3 100644 --- a/test/mitmproxy/tools/console/test_statusbar.py +++ b/test/mitmproxy/tools/console/test_statusbar.py @@ -13,20 +13,19 @@ def test_statusbar(monkeypatch): stickycookie="~dst example.com", stickyauth="~dst example.com", default_contentview="javascript", - console_order="url", anticache=True, anticomp=True, showhost=True, refresh_server_playback=False, replay_kill_extra=True, upstream_cert=False, - console_focus_follow=True, stream_large_bodies="3m", mode="transparent", scripts=["nonexistent"], save_stream_file="foo", ) m = master.ConsoleMaster(o) + m.options.update(view_order='url', console_focus_follow=True) monkeypatch.setattr(m.addons.get("clientplayback"), "count", lambda: 42) monkeypatch.setattr(m.addons.get("serverplayback"), "count", lambda: 42) |