Skip to content

Commit

Permalink
Add script to generate fingerprints for existing keys in api-db
Browse files Browse the repository at this point in the history
  • Loading branch information
rocketeerbkw committed Mar 12, 2019
1 parent 9fedd48 commit b3997e3
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions helpers/577-api-db-generate-ssh-key-fingerprints.sh
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit b3997e3

Please sign in to comment.