From b3997e3940f02e300accc682896846e5ba0f7781 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Tue, 12 Mar 2019 10:19:09 -0500 Subject: [PATCH] Add script to generate fingerprints for existing keys in api-db --- ...577-api-db-generate-ssh-key-fingerprints.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100755 helpers/577-api-db-generate-ssh-key-fingerprints.sh diff --git a/helpers/577-api-db-generate-ssh-key-fingerprints.sh b/helpers/577-api-db-generate-ssh-key-fingerprints.sh new file mode 100755 index 0000000000..adeaaa74cf --- /dev/null +++ b/helpers/577-api-db-generate-ssh-key-fingerprints.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +set -eu -o pipefail + +# disable globbing +set -f; +# set field separator to NL (only) +IFS=$'\n'; +# get all ssh keys from api-db into a bash array +SSHKEY_RECORDS=( $(mysql -u$MARIADB_USER -p$MARIADB_PASSWORD -h$HOSTNAME $MARIADB_DATABASE --batch -sse "select id, key_type, key_value from ssh_key") ); + +for SSHKEY_RECORD in "${SSHKEY_RECORDS[@]}"; +do + RECORD_ID=$(awk '{print $1}' <<< "$SSHKEY_RECORD"); + SSHKEY=$(awk '{print $2, $3}' <<< "$SSHKEY_RECORD"); + FINGERPRINT=$(ssh-keygen -lE sha256 -f - <<< "$SSHKEY" | awk '{print $2}'); + mysql -u$MARIADB_USER -p$MARIADB_PASSWORD -h$HOSTNAME $MARIADB_DATABASE -e "UPDATE ssh_key SET key_fingerprint = '$FINGERPRINT' WHERE id = $RECORD_ID"; +done;