VPN
The WireGuard handshake, message by message
Building the two messages of the WireGuard handshake, so two peers can agree on fresh transport keys from their key pairs alone, and testing it against an independent implementation.
Testing the forwarding loops with fakes
Moving the packet forwarding loops behind two small interfaces, so they can be tested without root, a TUN device, or a network.
The building blocks of the WireGuard handshake
Implementing and testing the hash functions, key derivation, and handshake state that the WireGuard handshake is built from, before writing the handshake itself.
X25519 key pairs
Giving each peer its own X25519 key pair, with genkey and pubkey commands that match WireGuard's, as the first step towards a key exchange.
Rejecting replayed messages
Making sure each tunnel message is accepted at most once, with a sliding window of recent counters that still allows packets to arrive out of order.
One key per direction
Fixing the nonce reuse from the previous post by deriving a separate key for each direction of the tunnel with HKDF-SHA256.
Encrypting tunnel traffic with ChaCha20-Poly1305
Encrypting every tunneled packet with ChaCha20-Poly1305 in WireGuard's message format, and the known weakness I left in on purpose.
Configuring the tunnel and getting the MTU right
Letting the VPN configure its own TUN device, validating the tunnel address, and working out an MTU that leaves room for the tunnel's own headers.
Hardening, tests and CI
Dropping packets from strangers, better error messages, the first tests for the UDP transport, and a CI pipeline that runs on every pull request.
Two peers, one command: running the VPN in Docker
Packaging the VPN as a small Docker image and running two peers with Docker Compose, including what a container needs to create a TUN device.
Forwarding packets in both directions
Connecting the TUN device to the UDP transport, and making sure the program shuts down cleanly when it's stopped.
Reading packets from a TUN device
Creating a TUN device in Go, a minimal UDP transport, and a two-machine test lab built from Linux network namespaces.
Building a VPN in Go: the plan
Why I'm writing a point-to-point VPN from scratch in Go, what it will and won't do, and how I'm going to build it.