From 2a7e6c323d9269e4b15f47ac8d39ee92c985f348 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 11 Jan 2018 14:15:09 +0000 Subject: [PATCH] Getting the gpg key from an email address also checks gpg config for default-key --- src/freedombone-utils-gpg | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/freedombone-utils-gpg b/src/freedombone-utils-gpg index 86c1387b..895b132b 100755 --- a/src/freedombone-utils-gpg +++ b/src/freedombone-utils-gpg @@ -262,8 +262,34 @@ function gpg_pubkey_from_email { key_id= if [[ $key_owner_username != "root" ]]; then key_id=$(su -c "gpg --list-keys $key_email_address" - $key_owner_username | sed -n '2p' | sed 's/^[ \t]*//') + + # If the default key is specified within gpg.conf + if [ -f /home/$key_owner_username/gpg.conf ]; then + if grep -q "default-key" /home/$key_owner_username/gpg.conf; then + default_gpg_key=$(cat /home/$key_owner_username/gpg.conf | grep "default-key") + if [[ "$default_gpg_key" != *'#'* ]]; then + default_gpg_key=$(cat /home/$key_owner_username/gpg.conf | grep "default-key" | awk -F ' ' '{print $2}') + if [ ${#default_gpg_key} -gt 3 ]; then + key_id=$(su -c "gpg --list-keys $default_gpg_key" - $key_owner_username | sed -n '2p' | sed 's/^[ \t]*//') + fi + fi + fi + fi else key_id=$(gpg --list-keys $key_email_address | sed -n '2p' | sed 's/^[ \t]*//') + + # If the default key is specified within gpg.conf + if [ -f /root/gpg.conf ]; then + if grep -q "default-key" /root/gpg.conf; then + default_gpg_key=$(cat /root/gpg.conf | grep "default-key") + if [[ "$default_gpg_key" != *'#'* ]]; then + default_gpg_key=$(cat /root/gpg.conf | grep "default-key" | awk -F ' ' '{print $2}') + if [ ${#default_gpg_key} -gt 3 ]; then + key_id=$(gpg --list-keys $default_gpg_key | sed -n '2p' | sed 's/^[ \t]*//') + fi + fi + fi + fi fi echo $key_id }