build mitmproxy.exe 🎉

This commit is contained in:
Maximilian Hils 2021-01-04 20:06:55 +01:00
parent 168bccfe81
commit 605961c57f
12 changed files with 63 additions and 58 deletions

View File

@ -38,6 +38,7 @@ If you depend on these features, please raise your voice in
### Full Changelog
* New Proxy Core based on sans-io pattern (@mhils)
* mitmproxy's command line interface now supports Windows (@mhils)
* Use pyca/cryptography to generate certificates, not pyOpenSSL (@mhils)
* Remove the legacy protocol stack (@Kriechi)
* Remove all deprecated pathod and pathoc tools and modules (@Kriechi)

View File

@ -34,17 +34,15 @@ the repository maintainers directly for issues with native packages.
## Windows
All the mitmproxy tools are fully supported under [WSL (Windows Subsystem for
Linux)](https://docs.microsoft.com/en-us/windows/wsl/about). We recommend to
[install WSL](https://docs.microsoft.com/en-us/windows/wsl/install-win10), and
then follow the mitmproxy installation instructions for Linux.
To install mitmproxy on Windows, download the installer from [mitmproxy.org](https://mitmproxy.org/). After
installation, mitmproxy, mitmdump and mitmweb are also added to your PATH and can be invoked from the command line.
We also distribute native Windows packages for all tools other than the
mitmproxy console app, which only works under WSL. To install mitmproxy on
Windows, download the installer from [mitmproxy.org](https://mitmproxy.org/).
After installation, you'll find shortcuts for mitmweb and mitmdump in the start
menu. Both executables are added to your PATH and can be invoked from the
command line.
We highly recommend to [install Windows Terminal](https://aka.ms/terminal) to improve the rendering of the console interface.
All the mitmproxy tools are also supported under
[WSL (Windows Subsystem for Linux)](https://docs.microsoft.com/en-us/windows/wsl/about). After
[installing WSL](https://docs.microsoft.com/en-us/windows/wsl/install-win10), follow the mitmproxy installation
instructions for Linux.
## Advanced Installation
@ -80,9 +78,8 @@ You can use the official mitmproxy images from
### Security Considerations for Binary Packages
Our pre-compiled binary packages and Docker images include a self-contained
Python 3 environment, a recent version of OpenSSL that support ALPN and HTTP/2,
and other dependencies that would otherwise be cumbersome to compile and
install.
Python 3 environment, a recent version of OpenSSL, and other dependencies
that would otherwise be cumbersome to compile and install.
Dependencies in the binary packages are frozen on release, and can't be updated
in situ. This means that we necessarily capture any bugs or security issues that

View File

@ -4,6 +4,5 @@ Contribs:
wbxml
- https://github.com/davidpshaw/PyWBXMLDecoder
tls, BSD license
- https://github.com/mhils/tls/tree/mitmproxy
- limited to required files.
urwid
- Patches vendored from https://github.com/urwid/urwid/pull/448.

View File

@ -725,7 +725,9 @@ class Screen(BaseScreen, RealTerminal):
assert self._term_output_file == sys.stdout
handle = win32.GetStdHandle(win32.STD_OUTPUT_HANDLE)
info = win32.CONSOLE_SCREEN_BUFFER_INFO()
win32.GetConsoleScreenBufferInfo(handle, byref(info))
ok = win32.GetConsoleScreenBufferInfo(handle, byref(info))
if ok == 0:
raise IOError()
y, x = info.dwSize.Y, info.dwSize.X
else:
buf = fcntl.ioctl(self._term_output_file.fileno(),

View File

@ -13,8 +13,8 @@ from mitmproxy.http import HTTPFlow
from mitmproxy.utils import human
from mitmproxy.tcp import TCPFlow
# Detect Windows Subsystem for Linux
IS_WSL = "Microsoft" in platform.platform()
# Detect Windows Subsystem for Linux and Windows
IS_WINDOWS = "Microsoft" in platform.platform() or "Windows" in platform.platform()
def is_keypress(k):

View File

@ -1,3 +1,4 @@
import os
import re
import urwid
@ -14,6 +15,11 @@ from mitmproxy.tools.console import overlay
from mitmproxy.tools.console import signals
from mitmproxy.tools.console import statusbar
if os.name == "nt":
from mitmproxy.contrib.urwid import raw_display
else:
from urwid import raw_display
class StackWidget(urwid.Frame):
def __init__(self, window, widget, title, focus):
@ -315,10 +321,10 @@ class Window(urwid.Frame):
)
class Screen(urwid.raw_display.Screen):
class Screen(raw_display.Screen):
def write(self, data):
if common.IS_WSL:
if common.IS_WINDOWS:
# replace urwid's SI/SO, which produce artifacts under WSL.
# at some point we may figure out what they actually do.
data = re.sub("[\x0e\x0f]", "", data)

View File

@ -122,10 +122,10 @@ def run(
def mitmproxy(args=None) -> typing.Optional[int]: # pragma: no cover
if os.name == "nt":
print("Error: mitmproxy's console interface is not supported on Windows. "
"You can run mitmdump or mitmweb instead.", file=sys.stderr)
return 1
assert_utf8_env()
import urwid
urwid.set_encoding("utf8")
else:
assert_utf8_env()
from mitmproxy.tools import console
run(console.master.ConsoleMaster, cmdline.mitmproxy, args)
return None

View File

@ -121,12 +121,9 @@ class BuildEnviron:
@property
def bdists(self):
ret = {
return {
"mitmproxy": ["mitmproxy", "mitmdump", "mitmweb"],
}
if self.system == "Windows":
ret["mitmproxy"].remove("mitmproxy")
return ret
@property
def branch(self) -> str:

View File

@ -33,6 +33,9 @@
<allowWildcards>1</allowWildcards>
<origin>../build/binaries/${platform_name}/*</origin>
</distributionFile>
<distributionFile>
<origin>run.ps1</origin>
</distributionFile>
</distributionFileList>
</folder>
</folderList>
@ -51,24 +54,34 @@
</postUninstallationActionList>
<startMenuShortcutList>
<startMenuShortcut>
<comment></comment>
<name>mitmproxy ui</name>
<comment>mitmproxy command line interface</comment>
<name>mitmproxy</name>
<runAsAdmin>0</runAsAdmin>
<runInTerminal>0</runInTerminal>
<windowsExec>${installdir}\bin\mitmweb.exe</windowsExec>
<windowsExecArgs></windowsExecArgs>
<windowsExec>powershell.exe</windowsExec>
<windowsExecArgs>-File "${installdir}\bin\run.ps1" mitmproxy</windowsExecArgs>
<windowsIcon>${installdir}/logo.ico</windowsIcon>
<windowsPath>${installdir}</windowsPath>
<windowsPath>${user_home_directory}</windowsPath>
</startMenuShortcut>
<startMenuShortcut>
<comment></comment>
<comment>mitmproxy web interface</comment>
<name>mitmweb</name>
<runAsAdmin>0</runAsAdmin>
<runInTerminal>0</runInTerminal>
<windowsExec>powershell.exe</windowsExec>
<windowsExecArgs>-File "${installdir}\bin\run.ps1" mitmweb</windowsExecArgs>
<windowsIcon>${installdir}/logo.ico</windowsIcon>
<windowsPath>${user_home_directory}</windowsPath>
</startMenuShortcut>
<startMenuShortcut>
<comment>mitmproxy non-interactive interface</comment>
<name>mitmdump</name>
<runAsAdmin>0</runAsAdmin>
<runInTerminal>0</runInTerminal>
<windowsExec>${installdir}\bin\mitmdump.exe</windowsExec>
<windowsExecArgs></windowsExecArgs>
<windowsExec>powershell.exe</windowsExec>
<windowsExecArgs>-File "${installdir}\bin\run.ps1" mitmdump</windowsExecArgs>
<windowsIcon>${installdir}/logo.ico</windowsIcon>
<windowsPath>${installdir}</windowsPath>
<windowsPath>${user_home_directory}</windowsPath>
</startMenuShortcut>
</startMenuShortcutList>
</component>
@ -85,24 +98,9 @@
<finalPageActionList>
<runProgram>
<program>cmd</program>
<programArguments>/c start "mitmproxy ui" "${installdir}\bin\mitmweb.exe" &amp;</programArguments>
<progressText>Launch mitmproxy ui now</progressText>
<ruleList>
<platformTest>
<type>windows</type>
</platformTest>
</ruleList>
</runProgram>
<runProgram>
<program>${installdir}/mitmproxy</program>
<programArguments>&amp;</programArguments>
<programArguments>/c powershell -File "${installdir}\bin\run.ps1" mitmproxy &amp;</programArguments>
<progressText>Launch mitmproxy now</progressText>
<ruleList>
<platformTest>
<negate>1</negate>
<type>windows</type>
</platformTest>
</ruleList>
<workingDirectory>${user_home_directory}</workingDirectory>
</runProgram>
</finalPageActionList>
<parameterList>
@ -120,6 +118,7 @@
<width>40</width>
<postShowPageActionList>
<!-- This will skip the readytoinstall page -->
<setInstallerVariable name="next_page" value="installation"/>
</postShowPageActionList>
<preShowPageActionList>
@ -131,3 +130,4 @@
</directoryParameter>
</parameterList>
</project>

View File

@ -0,0 +1,5 @@
if (Get-Command wt -ErrorAction SilentlyContinue) {
Start-Process wt -ArgumentList "powershell.exe","-NoExit","-Command",$args[0]
} else {
Start-Process powershell -ArgumentList "-NoExit","-Command",$args[0]
}

View File

@ -8,7 +8,6 @@ import mitmproxy.options
from mitmproxy import master
from mitmproxy.tools.console import window
from mitmproxy.tools.console.master import ConsoleMaster
from test.conftest import skip_windows
def tokenize(input: str) -> List[str]:
@ -40,7 +39,6 @@ def console(monkeypatch):
return m
@skip_windows
def test_integration(tdata, console):
console.type(f":view.flows.load {tdata.path('mitmproxy/data/dumpfile-018.bin')}<enter>")
console.type("<enter><tab><tab>")

View File

@ -205,7 +205,7 @@ def test_buildenviron_windows(tmpdir):
)
assert be.platform_tag == "windows"
assert be.bdists == {
"mitmproxy": ["mitmdump", "mitmweb"],
"mitmproxy": ["mitmproxy", "mitmdump", "mitmweb"],
}
assert be.archive_name("mitmproxy") == "mitmproxy-0.0.1-windows.zip"