WireGuard interface for mitmproxy
Project description
mitmproxy_wireguard
Transparently proxy any device that can be configured as a WireGuard client!
Work-In-Progress.
Interface
The API interface of the PyO3 module is documented in mitmproxy_wireguard.pyi
:
Server
class: a running WireGuard server instance, with methods for- graceful shutdown (
close
/wait_closed
) - sending UDP packets
- graceful shutdown (
TcpStream
class: an established TCP connection (provides APIs identical to Python's)asyncio.StreamReader
andasyncio.StreamWriter
)start_server
coroutine: initialize, start, and return aServer
instance
Architecture
DONE
- multi-threaded / asynchronous WireGuard server using tokio:
- one worker thread for the user-space WireGuard server
- one worker thread for the user-space network stack
- one worker thread for communicating with the Python runtime
- basic TCP/IPv4 functionality, IPv6 only partially supported
- basic UDP functionality
- Python interface similar to the one provided by
asyncio.start_server
- basic support for reading WireGuard configuration files
TODO
- better and more complete IPv6 support
- unit tests
- various other
TODO
andFIXME
items (documented in the code)
Hacking
Setting up the development environment is relatively straightforward, as only a Rust toolchain and Python 3 are required:
# set up a new venv
python3 -m venv venv
# enter venv (use the activation script for your shell)
source ./venv/bin/activate
# install maturin and pdoc
pip install maturin pdoc
Compiling the native Rust module then becomes easy:
# compile native Rust module and install it in venv
maturin develop
# compile native Rust module with optimizations
maturin develop --release
Once 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.py
Docs
Documentation for the Python module can be built with pdoc
.
The documentation is built from the mitmproxy_wireguard.pyi
type stubs and the
rustdoc documentation strings themselves. So to generate the documentation, the
native module needs to be rebuilt, as well:
maturin develop
pdoc mitmproxy_wireguard
By default, this will build the documentation in HTML format and serve it on http://localhost:8080.
Note: This requires version >=11.2.0
of pdoc. It is the first version that
supports generating documentation for "native-only" Python modules (like our
mitmproxy_wireguard
PyO3 module).
Introspecting the tokio runtime
The asynchronous runtime can be introspected using tokio-console
if the crate
was built with the tracing
feature:
tokio-console http://localhost:6669
There should be no task that is busy when the program is idle, i.e. there should be no busy waiting.
Note: This requires maturin>=0.12.15
, as earlier versions accidentally
clobbered the RUSTFLAGS
that were passed to the Rust compiler, breaking use
of the console_subscriber
for tokio-console
, which requires using the
--cfg tokio_unstable
flag.
Code style
The format for Rust code is enforced by rustfmt
.
To apply the formatting rules, use:
cargo fmt
The format for Python code (i.e. the test echo server and the type stubs in
mitmproxy_wireguard.pyi
) is enforced with black
and can be applied with:
black echo_test_server.py mitmproxy_wireguard.pyi benches/*.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for mitmproxy_wireguard-0.1.9.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | f25b2e5eda3e2afa821be63068f2a4e71303243fdff3631dcaa73f8a8c6ebde2 |
|
MD5 | 5bb06a5e757a88543b3e1f9668f34d50 |
|
BLAKE2b-256 | 960ac1290426c92ac7228332cbeb00103090a13f9efe6fa81bb4ca98dd25a325 |
Hashes for mitmproxy_wireguard-0.1.9-cp37-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7aa24097f76df0a1eb2e4b987b2464b42ded3139f10e43a082094dfe74910dba |
|
MD5 | ced4fd92229c44b322435cf383d65282 |
|
BLAKE2b-256 | a4af720ba1cc59d8e85e775919ebb8babcadfc21003a2b30120be0b7222bca75 |
Hashes for mitmproxy_wireguard-0.1.9-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21097b0921cb47da1bc4ea692e6a0fc5c2fe1a271df01c21c288df7869c177ca |
|
MD5 | 37d8da54a7f3de779a5b6a859bf7ca26 |
|
BLAKE2b-256 | 177f3540e964b620b5de2f3e72e0abf303496e0ff3e6506c51913117a62bc23d |
Hashes for mitmproxy_wireguard-0.1.9-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 405a85521a470be297639b0f80518f23dc0d6eb532626b05f453952c1d8ef949 |
|
MD5 | 2f8d32e4414ea1c1aea6e6a605e84619 |
|
BLAKE2b-256 | 9a08f82b20a4dc7e78b9de93fbea655e709c8e700a7165778a2e43ae756389d0 |
Hashes for mitmproxy_wireguard-0.1.9-cp37-abi3-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6229bb26321de382dfed4d21c59ccca0bce13f4f3bac0eaa4e469d125596357 |
|
MD5 | 13e71faa564123e73e5716313d1b7a3d |
|
BLAKE2b-256 | 98671cf6807b6c38adfc5645aa5ad474369dedfd678e18f66ee6a990131c582a |
Hashes for mitmproxy_wireguard-0.1.9-cp37-abi3-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1f5a235d25245d0e895642711c0428e704bbab1eabcf82695a4d102817a4ee1 |
|
MD5 | 470c89a837ef86192a9a16c2fca0c5ef |
|
BLAKE2b-256 | a826ff52076a9c78cf6aa347c0b721b5b6e54cd0cb7a356ac74d05de42d95ded |