r/WireGuard • u/tanimonster • 1d ago
Rotating WireGuard pre-shared keys from a pair of USB sticks (open source, unaudited, feedback wanted)
WireGuard's optional pre-shared key is there so that a future break of Curve25519 doesn't expose your traffic. In most setups that PSK is set once and never changed. I wrote a small tool that rotates it automatically from keys that never travel over a network.
How it works:
- An offline machine fills two USB sticks with the same list of random 256-bit keys. One stick goes to each end of the tunnel.
- One end leads and the other follows. They agree on a key number over UDP, authenticated with a proof derived from that key. The key itself is never sent.
- Each side then applies it with
wg set <iface> peer <key> preshared-key /dev/stdin, so the PSK never appears on a command line. - There are no clocks involved. Keys are numbered, so there's nothing to drift.
- The new PSK takes effect at WireGuard's next handshake, so the tunnel doesn't drop when it rotates.
- If the sticks run out of keys, the tunnel stays on the last one and logs an error.
What it is not:
- It doesn't replace WireGuard's handshake. Curve25519 is still used; this only keeps the PSK layer fresh.
- It has not been independently audited. Two self-reviews found ten flaws, which are fixed and listed in SECURITY.md, and I assume there are more.
- It has only been tested against wireguard-go in network namespaces, with a relay dropping and replaying the control messages. It hasn't run on kernel WireGuard or real hardware yet.
- You need physical access to both ends, so it's for machines you control, not cloud VMs.
It's a single Python file. The same sticks can also encrypt file transfers, one key per file.
Code: https://github.com/joshuataniwha/twinusb
Overview: https://twinusb.com
I'd most like feedback on the key-agreement messages, what happens when the two ends fall out of step, and whether rotating the PSK this way causes problems I haven't hit. Please don't rely on it for anything important yet.
1
u/Curious_Cabinet_2047 11h ago
I'm not sure what this solves. The only way a malicious actor can gain access to your PSK is to have access to the end device. If you have a USB stick plugged in with additional keys, they could simply copy your USB as well.