Skip to content

Commit 08155d0

Browse files
Merge pull request #183 from scidsg/pgp-validation
Pgp validation
2 parents 0667833 + 74d4ac3 commit 08155d0

File tree

2 files changed

+66
-10
lines changed

2 files changed

+66
-10
lines changed

assets/scripts/install-public-plus-tor.sh

+33-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fi
1010
apt update && apt -y dist-upgrade && apt -y autoremove
1111

1212
# Install required packages
13-
apt-get -y install git python3 python3-venv python3-pip certbot python3-certbot-nginx nginx tor libnginx-mod-http-geoip geoip-database unattended-upgrades gunicorn libssl-dev net-tools fail2ban ufw
13+
apt-get -y install git python3 python3-venv python3-pip certbot python3-certbot-nginx nginx tor libnginx-mod-http-geoip geoip-database unattended-upgrades gunicorn libssl-dev net-tools fail2ban ufw gnupg
1414

1515
# Function to display error message and exit
1616
error_exit() {
@@ -82,12 +82,40 @@ echo "
8282
8383
👇 Please paste your public PGP key and press Enter."
8484

85-
PGP_PUBLIC_KEY=""
86-
while IFS= read -r LINE < /dev/tty; do
87-
PGP_PUBLIC_KEY+="$LINE"$'\n'
88-
[[ $LINE == "-----END PGP PUBLIC KEY BLOCK-----" ]] && break
85+
# Loop until a valid PGP public key is provided
86+
while true; do
87+
PGP_PUBLIC_KEY=""
88+
while IFS= read -r LINE < /dev/tty; do
89+
PGP_PUBLIC_KEY+="$LINE"$'\n'
90+
[[ $LINE == "-----END PGP PUBLIC KEY BLOCK-----" ]] && break
91+
done
92+
93+
# Save the provided PGP key to a temporary file
94+
TEMP_PGP_KEY_FILE=$(mktemp)
95+
echo "$PGP_PUBLIC_KEY" > "$TEMP_PGP_KEY_FILE"
96+
97+
# Validate the PGP public key
98+
if gpg --import "$TEMP_PGP_KEY_FILE" &>/dev/null; then
99+
PGP_KEY_ID=$(gpg --list-keys --with-colons | grep pub | head -n 1 | cut -d':' -f5)
100+
if [[ -n "$PGP_KEY_ID" ]]; then
101+
echo "Valid PGP public key provided."
102+
break # Exit the loop if a valid key is provided
103+
else
104+
echo "No valid PGP public key ID found. Please provide a valid PGP public key."
105+
fi
106+
else
107+
echo "⛔️ Invalid PGP public key. Please provide a valid PGP public key."
108+
fi
109+
110+
# Remove the temporary PGP key file after validation attempt
111+
rm "$TEMP_PGP_KEY_FILE"
112+
# Prompt to try again
113+
echo "Please try again."
89114
done
90115

116+
# Remove the temporary PGP key file after successful validation
117+
rm "$TEMP_PGP_KEY_FILE"
118+
91119
echo "
92120
👍 Public PGP key received.
93121
Continuing with installation process..."

assets/scripts/install-tor-only.sh

+33-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fi
1010
apt update && apt -y dist-upgrade && apt -y autoremove
1111

1212
# Install required packages
13-
apt-get -y install git python3 python3-venv python3-pip nginx tor libnginx-mod-http-geoip geoip-database unattended-upgrades gunicorn libssl-dev net-tools fail2ban ufw
13+
apt-get -y install git python3 python3-venv python3-pip nginx tor libnginx-mod-http-geoip geoip-database unattended-upgrades gunicorn libssl-dev net-tools fail2ban ufw gnupg
1414

1515
# Function to display error message and exit
1616
error_exit() {
@@ -79,12 +79,40 @@ echo "
7979
8080
👇 Please paste your public PGP key and press Enter."
8181

82-
PGP_PUBLIC_KEY=""
83-
while IFS= read -r LINE < /dev/tty; do
84-
PGP_PUBLIC_KEY+="$LINE"$'\n'
85-
[[ $LINE == "-----END PGP PUBLIC KEY BLOCK-----" ]] && break
82+
# Loop until a valid PGP public key is provided
83+
while true; do
84+
PGP_PUBLIC_KEY=""
85+
while IFS= read -r LINE < /dev/tty; do
86+
PGP_PUBLIC_KEY+="$LINE"$'\n'
87+
[[ $LINE == "-----END PGP PUBLIC KEY BLOCK-----" ]] && break
88+
done
89+
90+
# Save the provided PGP key to a temporary file
91+
TEMP_PGP_KEY_FILE=$(mktemp)
92+
echo "$PGP_PUBLIC_KEY" > "$TEMP_PGP_KEY_FILE"
93+
94+
# Validate the PGP public key
95+
if gpg --import "$TEMP_PGP_KEY_FILE" &>/dev/null; then
96+
PGP_KEY_ID=$(gpg --list-keys --with-colons | grep pub | head -n 1 | cut -d':' -f5)
97+
if [[ -n "$PGP_KEY_ID" ]]; then
98+
echo "Valid PGP public key provided."
99+
break # Exit the loop if a valid key is provided
100+
else
101+
echo "No valid PGP public key ID found. Please provide a valid PGP public key."
102+
fi
103+
else
104+
echo "⛔️ Invalid PGP public key. Please provide a valid PGP public key."
105+
fi
106+
107+
# Remove the temporary PGP key file after validation attempt
108+
rm "$TEMP_PGP_KEY_FILE"
109+
# Prompt to try again
110+
echo "Please try again."
86111
done
87112

113+
# Remove the temporary PGP key file after successful validation
114+
rm "$TEMP_PGP_KEY_FILE"
115+
88116
echo "
89117
👍 Public PGP key received.
90118
Continuing with installation process..."

0 commit comments

Comments
 (0)