58 lines
1.3 KiB
Bash
Raw Permalink Normal View History

2022-02-17 13:36:55 -05:00
#! /bin/sh
# Depends on OpenSSL 1.1+ and basez (apt install -y basez openssl)
set -e
2022-03-22 08:20:13 -04:00
umask u=rw,go=
2022-02-17 13:36:55 -05:00
bold=$(tput bold)
normal=$(tput sgr0)
basedir=$(pwd)
if [ ! -d "$basedir/authorized_clients" ] || [ ! -f "$basedir/hostname" ]; then
2022-03-22 08:20:13 -04:00
printf '%s\n' 'Run script inside hidden service directory'
2022-02-17 13:36:55 -05:00
exit 1
fi
2022-03-22 08:20:13 -04:00
printf '%s\n' 'Enter key pair name and press enter'
2022-02-17 13:36:55 -05:00
read -r name
private_key="$(openssl genpkey -algorithm x25519)"
public=$(echo -n "$private_key" | \
openssl pkey -pubout | \
2022-03-22 08:20:13 -04:00
grep -v ' PUBLIC KEY' | \
2022-02-17 13:36:55 -05:00
base64pem -d | \
tail --bytes=32 | \
base32 | \
sed 's/=//g')
auth="descriptor:x25519:$(echo -n $public)"
2022-03-22 08:20:13 -04:00
echo $auth | sudo -u debian-tor tee "$basedir/authorized_clients/$name.auth"
2022-02-17 13:36:55 -05:00
private=$(echo -n "$private_key" | \
2022-03-22 08:20:13 -04:00
grep -v ' PRIVATE KEY' | \
2022-02-17 13:36:55 -05:00
base64pem -d | \
tail --bytes=32 | \
base32 | \
sed 's/=//g')
2022-03-22 08:20:13 -04:00
auth_private="$(cat $basedir/hostname | awk -F '.' '{print $1}'):descriptor:x25519:$private"
echo $auth_private | sudo -u debian-tor tee "$basedir/$name.auth_private"
2022-02-17 13:36:55 -05:00
client_command="$(echo "cat << EOF > ./$name.auth_private\n$auth_private\nEOF\nchmod 600 $name.auth_private")"
printf "%s\n" "Run following on client (within “auth” folder)"
echo "$bold$client_command$normal"
2022-03-22 08:20:13 -04:00
printf "%s $bold%s$normal %s\n" 'Dont forget to run' 'systemctl restart tor' 'on server'
2022-02-17 13:36:55 -05:00
2022-03-22 08:20:13 -04:00
printf '%s\n' 'Done'