Skip to content

Added psk support for configs and a test script#1

Open
jordanwiseman wants to merge 15 commits into
snaeim:mainfrom
jordanwiseman:add-psk-support
Open

Added psk support for configs and a test script#1
jordanwiseman wants to merge 15 commits into
snaeim:mainfrom
jordanwiseman:add-psk-support

Conversation

@jordanwiseman

Copy link
Copy Markdown

Add pre-shared key (PSK) support

Adds an optional use-psk flag to add peer that enables WireGuard's PresharedKey feature for an added layer of post-quantum protection on individual peer connections.

What changed

wgctl.sh

  • add peer accepts a new use-psk [psk] option. If no key is supplied, one is generated automatically via openssl rand --base64 32. An explicitly supplied PSK is validated against the standard WireGuard base64 format ([A-Za-z0-9+/]{43}=).
  • The PSK is stored in the interface's JSON database under the peer as usePSK.
  • show_interface renders a PresharedKey line in the INI output for peers that have one.
  • apply_interface writes PresharedKey = ... into the generated .conf file for PSK-enabled peers.
  • export_peer includes PresharedKey in the client-side config output when the peer has a PSK.
  • Two new error codes: ERR_MISSING_VALUE (28) for keyed options called without a value, and ERR_INVALID_PSK (29) for a malformed key.
  • openssl added to the required-tools check at startup.
  • Fixed a pre-existing bug where return #ERR_INVALID_PORT was a no-op comment instead of return $ERR_INVALID_PORT.

test_wgctl.sh (new)
A self-contained unit test suite covering the full command surface. Requires no root and no real WireGuard installation; wg, wg-quick, and openssl are replaced by mock binaries, and the script sources wgctl.sh functions directly after stripping the privilege guards with awk. Coverage includes happy-path and error-path cases for create_interface, show_interface, list_interfaces, add_peer (including PSK generation, explicit PSK, invalid PSK formats, subnet exhaustion, and duplicate detection), enable_peer/disable_peer, remove_peer, export_peer, and apply_interface.

README.md

  • Added use-psk [psk] to the add peer options reference.
  • Added an example command showing use-psk in action.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant