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 (
Configuration
class: minimal configuration support compatible with standard WireGuard configuration filesTcpStream
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.toml
. Some used configuration
options are only available on nightly Rust. To apply the formatting rules, use:
cargo +nightly 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.0a11.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | eaa22f8af41d180e64916715bcbac33b9e80f172502c7a4eda414b68bd1cccdc |
|
MD5 | c3918187b3bc5d8051df53f25550609b |
|
BLAKE2b-256 | 4c2710b2e8035441dc4b585ebfb5a1a9c1a85248575b4203f080110f2f192619 |
Hashes for mitmproxy_wireguard-0.1.0a11-cp37-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cae9880a0f354ed948d5dcba88f8a678fce7ecc590e1fc060e82e5e1b88a737d |
|
MD5 | 6ebbbb5045193a123977f819c7ec6a2c |
|
BLAKE2b-256 | be24387063032fad8174a07992403da11b8f969522b79eeaf7caa6e5ed4d3252 |
Hashes for mitmproxy_wireguard-0.1.0a11-cp37-abi3-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e209091a597a2b5aef6cf43d053989d68a0094ce8c54fc7539e32783201deb5a |
|
MD5 | 7398803f418744f2c28fc7c476eadf85 |
|
BLAKE2b-256 | dc4a579b7da44f40a352b115e386e10ffdc394d32abd6ad27941b64557784ebc |
Hashes for mitmproxy_wireguard-0.1.0a11-cp37-abi3-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01c1eaf70c0793df357fc05fa97d3b75da81b4a9086c6f4fc57df11e968fc360 |
|
MD5 | c222c9ea2bc069cf2716ccaa80927722 |
|
BLAKE2b-256 | 0f0bea84863186d883019b0a1d89c74c186aaee3572a76d07c259dc249e94fca |
Hashes for mitmproxy_wireguard-0.1.0a11-cp37-abi3-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 213799b8df925f0a89b977c963005c581db7c9074613227b56ab2f010ab9c9a6 |
|
MD5 | 2f4d9c81dd6c37d48fad2cef241446a4 |
|
BLAKE2b-256 | 8a302c1d25ec93514fef8a36518f91f34bf3a3b62f3beb1761874e98cdf63b50 |
Hashes for mitmproxy_wireguard-0.1.0a11-cp37-abi3-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79b68057347ac83b834fc429c0f12a27d0792442f40a39a055afce555b540516 |
|
MD5 | d89f3b04999727c6c42a64a8d374a615 |
|
BLAKE2b-256 | 947dd4e8750e2c7e58250313a6ccc701d678bab0eda1d4fa605bdc3fc6c7430d |
Hashes for mitmproxy_wireguard-0.1.0a11-cp37-abi3-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3e7f796a8100320b8e22923ce17c16b083b6f1fe4bcb09ff48a4f03a88ed863 |
|
MD5 | 7f8a34874f1e95352a8da0c0696ca5af |
|
BLAKE2b-256 | 0fa3944558afae2e6f60b2908fa7528443d0f65a5f910cbd48cb0212c3b81b3b |