Skip to content

Commit fc59591

Browse files
Simon Rowegaborigloi
authored andcommitted
CA-229031: improve error handling
Catch keyfiles that have multiple keys present, terminate when usage is displayed. Signed-off-by: Simon Rowe <[email protected]>
1 parent 0db1f28 commit fc59591

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

scripts/import-update-key

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@ set -e
66

77
keyfile="$1"
88
if [ -z "$keyfile" ]; then
9-
echo "Usage: $0 keyfile"
9+
echo "Usage: $0 keyfile" >&2
10+
exit 1
1011
fi
1112

1213
keyhash=$(gpg $gpgopts --with-fingerprint $keyfile | sed -ne 's#^pub [^ ]\+/\([^ ]\+\).*#\1#p')
14+
if [ ${#keyhash} -ne 8 ]; then
15+
echo "Invalid keyfile" >&2
16+
exit 2
17+
fi
1318
cp -p $keyfile /etc/pki/rpm-gpg
1419
gpg $gpgopts --import $keyfile
1520
echo -e "trust\n5\ny\n" | gpg $gpgopts --command-fd 0 --edit-key $keyhash

0 commit comments

Comments
 (0)