feat(vpn/wireguard): display the public key as a QR code - #234
Open
RISK-alt wants to merge 1 commit into
Open
Conversation
Registering a machine with a VPN peer currently means transferring the WireGuard public key by hand: 44 base64 characters, retyped or copied between machines. `wireguard-<vpn-name>-pubkey` now renders that key as a QR code below the text it already prints, so it can be scanned instead. No new dependency: qrencode is already part of the project's package set in modules/tools/default.nix. `importkey` already calls `pubkey`, so the QR code also appears right after key generation, which is where it is most useful. Two implementation details worth noting: - `-t ANSIUTF8` rather than `-t UTF8`. UTF8 emits no colour escape at all, so the blocks inherit the terminal palette and the code comes out inverted on a light background, which most phone scanners reject. ANSIUTF8 pins the colours, keeping the polarity correct on any theme. - The public key is bound to a shell variable instead of being computed twice. The private key is read from the YubiKey, whose touch policy is `always`, so a second call would ask for another touch to run a single command.
RISK-alt
requested review from
jdauphant-dinum,
olebrouster-dinum,
plegrand-dinum and
rlahfa-dinum
as code owners
August 8, 2026 14:49
rlahfa-dinum
approved these changes
Aug 10, 2026
rlahfa-dinum
left a comment
Contributor
There was a problem hiding this comment.
Looks reasonable to me.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
wireguard-<vpn-name>-pubkeynow renders the WireGuard public key as a QR code, below the text it already prints.Why
Registering a machine with a VPN peer means moving a 44-character base64 key across machines by hand. A scannable code removes the retyping, and the typos that come with it.
importkeyalready callspubkey, so the QR code also shows up right after key generation, which is where it is most useful. No new dependency is introduced:qrencodeis already part of the project's package set inmodules/tools/default.nix.Implementation notes
-t ANSIUTF8rather than-t UTF8.UTF8emits no colour escape at all, so the blocks take the terminal's own palette; on a light background the quiet zone renders dark, the code is inverted, and most phone scanners refuse to read it.ANSIUTF8emits\e[40;37;1m, pinning background and foreground, so the polarity stays correct on any theme.The key is bound to a shell variable instead of being computed twice. The private key is read from the YubiKey, whose touch policy is
always(set inimportkeyvia--touch-policy always), so a second call would ask for another physical touch to run a single command.Testing
Verified locally:
nixfmt -sc,statix check --config statix.tomlandreuse --root . lintall pass — the same commands the CI workflows run.pubkeyderivation builds. The module was instantiated on its own with a dummy WireGuard profile and the generated script inspected:qrencoderesolves to a store path, so it does not rely on$PATH.wg genkey | wg pubkey) encoded with theqrencodeversion pinned by the derivation, then decoded back withzbarimg, returns the identical 44-character string.ANSIUTF8output was scanned with a phone from a terminal, on both a light and a dark theme.Not verified: the full path through the YubiKey, for lack of the hardware. That path is untouched by this PR — the only new code is the two lines after
wg pubkey.I did not run
nix-build -A testslocally: no test intests/enablessecurix.vpn.wireguard, so the suite would not exercise this code path. Happy to add a test if you would like one.Closes #223