Package: mitmproxy-wireguard
mitmproxy_wireguardTransparently proxy any device that can be configured as a WireGuard client!DONEmultithreaded / asynchronous WireGuard server using tokio:one worker thread for the user-space WireGuard serverone worker thread for the user-space network stackone worker thread for communicating with the Python runtimefull support for IPv4 packets (TCP and UDP)partial support for IPv6 packets (TCP and UDP)Python interface similar to the Pythonasynciomoduleintegration tests in mitmproxyTODOmore complete IPv6 supportvarious other smallTODOandFIXMEitemsArchitecture supportmitmproxy_wireguardshould work on most architectures / targets - including,
but not limited to Windows, macOS, and Linux, running on x86_64 (x64) and
aarch64 (arm64) CPUs.Binary wheels for the following targets are available from PyPI:Windows / x64 (x86_64-windows-msvc)macOS / Intel (x86_64-apple-darwin)macos / Apple Silicon (aarch64-apple-darwin) via "Universal 2" binariesLinux / x86_64 (x86_64-unknown-linux-gnu)Linux / aarch64 (aarch64-unknown-linux-gnu), i.e. for Raspberry Pi 2+ and similar devicesRequirementsmitmproxy_wireguardcurrently requires Python 3.7 or newer at runtime, since
that is the oldest version of Python that is still supported by PyO3 v0.16.
mitmproxy already requires Python 3.9 or newer, so this should not be a problem.Additionally,mitmproxy_wireguardcurrently has the following requirements at
build-time:Python 3.7+ (range of Python versions that is supported by PyO3 v0.16)Rust 1.58.0+ (the oldest supported version of Rust / MSRV is 1.58.0)maturin 0.13.xArchitectureInterfaceThe API interface of the PyO3 module is documented inmitmproxy_wireguard.pyi:Serverclass: a running WireGuard server instance, with methods forgraceful shutdown (close/wait_closed)sending UDP packetsTcpStreamclass: an established TCP connection (provides APIs identical to
Python's)asyncio.StreamReaderandasyncio.StreamWriter)start_servercoroutine: initialize, start, and return aServerinstanceHackingSetting up the development environment is relatively straightforward,
as only a Rust toolchain and Python 3 are required:# set up a new venvpython3-mvenvvenv# enter venv (use the activation script for your shell)source./venv/bin/activate# install maturin and pdocpipinstallmaturinpdocCompiling the native Rust module then becomes easy:# compile native Rust module and install it in venvmaturindevelop# compile native Rust module with optimizationsmaturindevelop--releaseOnce that's done (phew! Rust sure does take a while to compile!), the test
echo server should work correctly. It will print instructions for connecting to
it over a WireGuard VPN:python3./echo_test_server.pyThe includedmitm-wg-test-clientbinary can be used to test this echo test
server, which can be built by runningcargo buildinside thetest-clientdirectory, and launched fromtarget/debug/mitm-wg-test-client.DocsDocumentation for the Python module can be built withpdoc.The documentation is built from themitmproxy_wireguard.pyitype stubs and the
rustdoc documentation strings themselves. So to generate the documentation, the
native module needs to be rebuilt, as well:maturindevelop
pdocmitmproxy_wireguardBy default, this will build the documentation in HTML format and serve it onhttp://localhost:8080.Note: This requires version>=11.2.0of pdoc. It is the first version that
supports generating documentation for "native-only" Python modules (like ourmitmproxy_wireguardPyO3 module).Introspecting the tokio runtimeThe asynchronous runtime can be introspected usingtokio-consoleif the crate
was built with thetracingfeature:tokio-consolehttp://localhost:6669There should be no task that is busy when the program is idle, i.e. there should
be no busy waiting.Note: This requiresmaturin>=0.12.15, as earlier versions accidentally
clobbered theRUSTFLAGSthat were passed to the Rust compiler, breaking use
of theconsole_subscriberfortokio-console, which requires using the--cfg tokio_unstableflag.Code styleThe format for Rust code is enforced byrustfmt.
To apply the formatting rules, use:cargofmtThe format for Python code (i.e. the test echo server and the type stubs inmitmproxy_wireguard.pyi) is enforced withblackand can be applied with:blackecho_test_server.pymitmproxy_wireguard.pyibenches/*.py