Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix subspacecommunity#129] Add support to pre-shared key for each client #132

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cmd/subspace/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,13 +403,16 @@ func profileAddHandler(w *Web) {
cd {{$.Datadir}}/wireguard
wg_private_key="$(wg genkey)"
wg_public_key="$(echo $wg_private_key | wg pubkey)"
wg_psk="$(wg genpsk)"
echo "${wg_psk}" > preSharedKey/{{$.Profile.ID}}.psk

wg set wg0 peer ${wg_public_key} allowed-ips {{$.IPv4Pref}}{{$.Profile.Number}}/32,{{$.IPv6Pref}}{{$.Profile.Number}}/128
wg set wg0 peer ${wg_public_key} preshared-key preSharedKey/{{$.Profile.ID}}.psk allowed-ips {{$.IPv4Pref}}{{$.Profile.Number}}/32,{{$.IPv6Pref}}{{$.Profile.Number}}/128

cat <<WGPEER >peers/{{$.Profile.ID}}.conf
[Peer]
PublicKey = ${wg_public_key}
AllowedIPs = {{$.IPv4Pref}}{{$.Profile.Number}}/32,{{$.IPv6Pref}}{{$.Profile.Number}}/128
PresharedKey = ${wg_psk}
WGPEER

cat <<WGCLIENT >clients/{{$.Profile.ID}}.conf
Expand All @@ -422,7 +425,9 @@ Address = {{$.IPv4Pref}}{{$.Profile.Number}}/{{$.IPv4Cidr}},{{$.IPv6Pref}}{{$.Pr
PublicKey = $(cat server.public)

Endpoint = {{$.EndpointHost}}:{{$.Listenport}}
PresharedKey = ${wg_psk}
AllowedIPs = {{$.AllowedIPS}}
PersistentKeepalive = 25
WGCLIENT
`
_, err = bash(script, struct {
Expand Down
2 changes: 2 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ if ! test -d /data/wireguard; then
touch clients/null.conf # So you can cat *.conf safely
mkdir peers
touch peers/null.conf # So you can cat *.conf safely
mkdir preSharedKey
touch preSharedKey/null.psk # So you can cat *.psk safely

# Generate public/private server keys.
wg genkey | tee server.private | wg pubkey > server.public
Expand Down