-
-
Save ziwon/f0e5bf4ee3c9b7e199ac2fd52939ba12 to your computer and use it in GitHub Desktop.
Connect to a VPN using an authentication info without configuration file (ex. trusted-cert)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# shellcheck disable=SC2006 | |
set -e pipefail | |
shopt -s expand_aliases | |
alias openssl='/usr/bin/openssl' # Disable Anaconda's version of OpenSSL which is older one | |
VPN_HOST="your-vpn.fortiddns.com:8443" | |
# Clear unsername and password | |
unset username | |
unset password | |
# Read user inputs | |
echo "Connecting to $VPN_HOST.." | |
echo -n "vpn id: " | |
read -r username | |
prompt="vpn pw:" | |
while IFS= read -p "$prompt" -r -s -n 1 c; do | |
if [[ $c == $'\0' ]]; then | |
echo | |
break; | |
fi | |
prompt='*' | |
password+="$c" | |
done | |
# Execute openfortivpn from the given inputs | |
sudo openfortivpn "$VPN_HOST" \ | |
--username="$username" \ | |
--password="$password" \ | |
--trusted-cert="`echo | openssl s_client -connect "${VPN_HOST}" -servername "${VPN_HOST%:*}" 2>&1 | openssl x509 -noout -fingerprint | cut -f2 -d'=' | sed 's/://g' | awk '{print tolower($0)}'`" |
Author
ziwon
commented
Jan 24, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment