Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add transparent server mode based on WireGuard #5562

Merged
merged 26 commits into from
Sep 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
151dbd6
add mode spec for WireGuard mode
decathorpe Sep 4, 2022
8238f9c
add WireGuard server implementation
decathorpe Sep 6, 2022
573b058
remove coverage excludes
mhils Sep 11, 2022
0fe25ff
simplify wireguard spec
mhils Sep 11, 2022
964a692
Merge remote-tracking branch 'origin/main' into pr-5562
mhils Sep 11, 2022
884af87
lint!
mhils Sep 11, 2022
b267d2d
remove superfluous tests
mhils Sep 11, 2022
3bc9a1b
bump to mitmproxy_wireguard 0.1.1
decathorpe Sep 12, 2022
53d14a1
proxy/test_mode_specs: remove unused import
decathorpe Sep 12, 2022
767fa18
fix wireguard server mode
decathorpe Sep 12, 2022
1160e48
WireGuard: move keyfile gen into `.start()`
mhils Sep 13, 2022
a5f75a0
fixup UDP support
mhils Sep 13, 2022
336ce6e
bump to mitmproxy_wireguard v0.1.2
decathorpe Sep 13, 2022
4000ec2
fix crash handler
mhils Sep 14, 2022
6c22471
add simple test for WireGuard server instances
decathorpe Sep 16, 2022
a857f1a
bump to mitmproxy_wireguard v0.1.5 and fix launching wg-test-client
decathorpe Sep 18, 2022
6838abe
Merge remote-tracking branch 'origin/main' into pr-5562
mhils Sep 18, 2022
77c65f4
fixups
mhils Sep 18, 2022
aa90aa6
nits
mhils Sep 18, 2022
77124b9
bump to mitmproxy_wireguard 0.1.6 for fixed test client
decathorpe Sep 18, 2022
6005811
move WireGuardDatagramTransport into dedicated module
mhils Sep 18, 2022
122f0c2
cover WireGuardServerInstance.is_running property with tests
decathorpe Sep 18, 2022
8c8cf46
enable specialized server instance creation
mhils Sep 18, 2022
7fd35e7
test wireguard conf generation
mhils Sep 18, 2022
12cbfea
deduplicate tcp/udp handlers
mhils Sep 18, 2022
0da0031
update CHANGELOG
mhils Sep 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup UDP support
  • Loading branch information
mhils committed Sep 13, 2022
commit a5f75a02a597a7fb51e8f14a12e0ca49d33e9588
17 changes: 11 additions & 6 deletions mitmproxy/net/udp.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async def wait_closed(self) -> None:

class WireGuardDatagramTransport(asyncio.DatagramTransport):
def __init__(self, server: wg.Server, local_addr: Address, remote_addr: Address):
self._server = server
self._server: wg.Server = server
self._local_addr: Address = local_addr
self._remote_addr: Address = remote_addr
self._protocol: DrainableDatagramProtocol | None = None
Expand All @@ -91,12 +91,17 @@ def __init__(self, server: wg.Server, local_addr: Address, remote_addr: Address)
def sendto(self, data, addr=None):
self._server.send_datagram(data, self._local_addr, addr or self._remote_addr)

def set_protocol(self, protocol):
assert isinstance(protocol, DrainableDatagramProtocol)
self._protocol = cast(DrainableDatagramProtocol, protocol)
def get_extra_info(self, name: str, default: Any = None) -> Any:
if name == "sockname":
return self._server.getsockname()
else:
raise NotImplementedError

def get_protocol(self):
return self._protocol
return self

async def drain(self) -> None:
pass


DatagramTransport = Union[asyncio.DatagramTransport, WireGuardDatagramTransport]
Expand Down Expand Up @@ -201,7 +206,7 @@ def __init__(
self._transport = transport
self._remote_addr = remote_addr
proto = transport.get_protocol()
assert isinstance(proto, DrainableDatagramProtocol)
assert isinstance(proto, (DrainableDatagramProtocol, WireGuardDatagramTransport))
decathorpe marked this conversation as resolved.
Show resolved Hide resolved
self._reader = reader
self._closed = asyncio.Event() if reader is not None else None

Expand Down
1 change: 1 addition & 0 deletions mitmproxy/proxy/mode_servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ def handle_udp_datagram(self, data: bytes, remote_addr: Address, local_addr: Add
handler.layer = self.make_top_layer(handler.layer.context)
handler.layer.context.client.transport_protocol = "udp"
handler.layer.context.server.transport_protocol = "udp"
handler.layer.context.server.address = local_addr

# pre-register here - we may get datagrams before the task is executed.
self.manager.connections[connection_id] = handler
Expand Down
2 changes: 2 additions & 0 deletions mitmproxy/proxy/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ async def handle_client(self) -> None:
self.transports[self.client].handler = handler
self.server_event(events.Start())
await asyncio.wait([handler])
if e := handler.exception():
self.log(f"mitmproxy has crashed!\n{traceback.format_exception(e)}", level="error")

watch.cancel()
while self.wakeup_timer:
Expand Down