Projects / cloak
cloak
A Layer-3 tunnel over UDP. Ping 10.8.0.2 and the packet went through the socket.
Why
A SOCKS proxy is not a VPN. I wanted a TUN device on each side, real IP packets, and encryption I could read. The lab is two addresses, 10.8.0.1/24 and 10.8.0.2/24. One server, one client. Not a mesh, and not an address allocator for a third peer.
Diagrams
A solid outline is the path in the repo. A dashed outline is the alternative that shape is refusing.
Each side opens cloak0, wraps the IP packet with NaCl secretbox, and sends it over UDP. -socks keeps that same framing when TUN is unavailable.
flowchart TD
tun["cloak0 TUN"]
box["NaCl secretbox over UDP"]
peer["Peer at 10.8.0.2"]
socks["-socks, same crypto"]
tun --> box --> peer
socks --> box
class tun,box,peer,socks chosen
The program is a pair of tunnel addresses. SOCKS is the fallback for a machine without admin, not the product. A third machine does not get an address from cloak.
flowchart TD
q{What this program is}
q -->|"IP packets, one peer, socks only if TUN is missing"| tun["Layer-3 pair"]
q -->|"a proxy and no packet"| proxy["SOCKS as the product"]
q -->|"an address for a third machine"| mesh["A mesh"]
class tun chosen
class proxy,mesh rejected
Why this shape
Each side opens cloak0 and wraps IP packets with NaCl secretbox. The datagram is version | nonce | secretbox(type + stream + seq + body). The key is 64 hex characters or a passphrase run through SHA-256. TUN comes from golang.zx2c4.com/wireguard/tun, which needs an admin shell and, on Windows, wintun.dll.
-socks keeps the same crypto and exits as a userspace proxy when TUN is unavailable. I did not want a machine without admin to be unable to try the wire format. -route can add a CIDR via the tunnel gateway. A full-tunnel 0.0.0.0/0 has to exclude the UDP path to the server, or the tunnel’s own packets go into the tunnel.
Where it breaks
The key is a shared secret on the command line. There is no rotation. Losing it means both sides change the flag. And the tunnel is a pair. A third machine does not get an address from cloak. That would be a different program.