From 41d7bc1e8955d047488678826c8b3cc50ae3d795 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Sun, 10 Oct 2021 08:01:05 -0400 Subject: trivial cleanups renamed several functions removed unused code --- cryptonomic-vpn | 57 ++++++++++++++++----------------------------------------- 1 file changed, 16 insertions(+), 41 deletions(-) diff --git a/cryptonomic-vpn b/cryptonomic-vpn index 8bc726c..196e2d1 100755 --- a/cryptonomic-vpn +++ b/cryptonomic-vpn @@ -151,8 +151,8 @@ main() exec 2>&1 # Start with the remote public key, to fail early if the server is # unavailable. - install_remote_public_key - install_local_private_key + install_remote_public_rsa_key + install_local_private_rsa_key test_new_config else die unimplemented @@ -160,27 +160,7 @@ main() exit } -match_and_drop_first_word() -{ - expect=$1 - while read word rest - do - if [ "$word" = "$expect" ] - then - printf '%s\n' "$rest" - return - fi - done - false -} - -keyscan() -{ - semi_quietly ssh-keyscan -t "${REMOTE_KEY_TYPE}" "$1" -} - -# Only write to the destination if the command is successful. -write_successfully() +write_if_successful() { local out="$1" f [ "$2" = -- ] || return @@ -214,7 +194,7 @@ simulate_write() ) } -semi_quietly() +quiet_if_successful() { local t=$(mktemp) if "$@" 2>"$t" @@ -225,25 +205,20 @@ semi_quietly() fi } -openssl() -{ - semi_quietly command openssl "$@" -} - -write_public_key() +write_public_rsa_key() { - openssl rsa -in "$1" -outform DER -pubout + quiet_if_successful openssl rsa -in "$1" -outform DER -pubout } -write_private_key() +write_private_rsa_key() { - openssl rsa -in "$1" -outform DER + quiet_if_successful openssl rsa -in "$1" -outform DER } -write_remote_key() +write_remote_rsa_key() { case "$REMOTE_KEY_TYPE" in - rsa) ssh-keygen -e -f "$1" -m PEM | openssl rsa -RSAPublicKey_in -outform DER ;; + rsa) ssh-keygen -e -f "$1" -m PEM | quiet_if_successful openssl rsa -RSAPublicKey_in -outform DER ;; *) echo "Unsupported key type." >&2; exit 1 ;; esac } @@ -255,15 +230,15 @@ sshfp_rsa_filename_string() } -install_local_private_key() +install_local_private_rsa_key() { private_key_tmp=$(mktemp) || return cp "$LOCAL_KEY" "$private_key_tmp" ssh-keygen -N '' -p -m PEM -f "$private_key_tmp" >/dev/null 2>&1 trap 'rm -f "$private_key_tmp"' EXIT - write_successfully "$LOCAL_PRIVATE_KEY_DEST" -- write_private_key "$private_key_tmp" - write_successfully "$LOCAL_PUBLIC_KEY_DEST" -- write_public_key "$private_key_tmp" + write_if_successful "$LOCAL_PRIVATE_KEY_DEST" -- write_private_rsa_key "$private_key_tmp" + write_if_successful "$LOCAL_PUBLIC_KEY_DEST" -- write_public_rsa_key "$private_key_tmp" trap - EXIT rm -f "$private_key_tmp" @@ -299,7 +274,7 @@ find_known_ssh_host_rsa_key_by_name() ) } -install_remote_public_key() +install_remote_public_rsa_key() { trap 'rm -f "$t"' EXIT t=$(mktemp) @@ -314,7 +289,7 @@ install_remote_public_key() fi REMOTE_PUBLIC_KEY_DEST=/etc/swanctl/pubkey/$(sshfp_rsa_filename_string "$t").pub - write_successfully "$REMOTE_PUBLIC_KEY_DEST" -- write_remote_key "$t" + write_if_successful "$REMOTE_PUBLIC_KEY_DEST" -- write_remote_rsa_key "$t" trap - EXIT rm -f "$t" @@ -373,7 +348,7 @@ NO_ACT() install_stronswan_config() { - write_successfully /etc/swanctl/conf.d/"$REMOTE_NAME".conf -- \ + write_if_successful /etc/swanctl/conf.d/"$REMOTE_NAME".conf -- \ strongswan_config \ "$REMOTE_NAME" \ "$REMOTE_IP" \ -- cgit v1.2.3