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.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.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c244e47dc50a086a99ad573682a3b7ee33a7c64fae050bd5bef28e644d7b527 |
|
MD5 | 99a1574eda9d9d449847f679c29d8a44 |
|
BLAKE2b-256 | 9d078fa220e274d1cd62355e8d7f7de5b82b49e64d393133de17562d35030c27 |
Hashes for mitmproxy_wireguard-0.1.5-cp37-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f21345d868c40b529ee19b6617e1c3074182c5212d1fe965f09139d6733e3286 |
|
MD5 | 6b9ed86c201bb7c4e0773cd4a8f77157 |
|
BLAKE2b-256 | 9da77c112c189c0c247f7458b6f30b5c61bfb5bb81ce4849788921b12fa1cba3 |
Hashes for mitmproxy_wireguard-0.1.5-cp37-abi3-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cde25845c65ac4bbf2dd55fe810b6a5d7996c51e3f3d72f0c10947ead9355432 |
|
MD5 | 2c8c66d15264945a7997da007afedcf0 |
|
BLAKE2b-256 | 6411c83e7ac849562a037df0cad82c1e3f542968692ef65da9925ac63d369438 |
Hashes for mitmproxy_wireguard-0.1.5-cp37-abi3-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a885261318c9d8ac60ff4839693c2a324e92f1fe7631f9f960dccb0ed0e750c |
|
MD5 | 61e9ad23ae790aaf6efd238aecb331dc |
|
BLAKE2b-256 | 5bbe0074f5744a49e20f9df2c0e7d711ae70a55d4c0962e20308230404f78c9a |
Hashes for mitmproxy_wireguard-0.1.5-cp37-abi3-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba5888ac7489577e926d25ab4a7d71af593a7eedf86ab11dff5408afb649ceaa |
|
MD5 | 66c9dfffee48c46ab2758b5ee0cae87b |
|
BLAKE2b-256 | 11bef48eb1ac33e408a74c6c0ba0dfcaf58fa01843a87e1fb076375c7895a82e |