homek8s/infrastructure/networking/rosenpass/linkb-verify.sh

26 lines
1.4 KiB
Shell
Raw Permalink Normal View History

#!/bin/bash
# Sample Link B PSK hashes on both ends. Prints no key material: the preshared
# key line is filtered on each host and only its SHA-256 (first 16 hex) leaves.
set -u
LINKB_LINODE='/2Y0XpJYd9Vl9Al6zNAlQimEYA+xY9Y5PO6nUDkfKEA=' # linode wg0 pub (peer on the Pi)
LINKB_RPI='h1v1Rhrnq2N2kt454xQamL1Y1x0TaICa1zoKgyZHpkM=' # rpi wg-remote pub (peer on the linode)
LINKA='+e50qTPdZiyxMtYHRSdGILIrh06JflFQq5+TZRjVyic=' # siriussec (Link A sentinel)
h() { tr -d '\n' | sha256sum | cut -c1-16; }
ts=$(date -u +%FT%TZ)
pi_linkb=$(wg show wg-remote preshared-keys 2>/dev/null | grep -F "$LINKB_LINODE" | awk '{print $2}' | h)
pi_linka=$(wg show wg0 preshared-keys 2>/dev/null | grep -F "$LINKA" | awk '{print $2}' | h)
ln_linkb=$(ssh -n -i /home/sirius/.ssh/linode_admin -o BatchMode=yes -o ConnectTimeout=10 [email protected] \
"wg show wg0 preshared-keys | grep -F '$LINKB_RPI' | awk '{print \$2}'" | h)
pi_hs=$(wg show wg-remote latest-handshakes 2>/dev/null | grep -F "$LINKB_LINODE" | awk '{print $2}')
ln_hs=$(ssh -n -i /home/sirius/.ssh/linode_admin -o BatchMode=yes -o ConnectTimeout=10 [email protected] \
"wg show wg0 latest-handshakes | grep -F '$LINKB_RPI' | awk '{print \$2}'")
agree="MISMATCH"
[ "$pi_linkb" = "$ln_linkb" ] && agree="agree"
printf '%s linkB pi=%s linode=%s %s | linkA(pi)=%s | hs pi=%s linode=%s\n' \
"$ts" "$pi_linkb" "$ln_linkb" "$agree" "$pi_linka" "$pi_hs" "$ln_hs"