From 07bca1fc2f82b97efdabf4277c6e6f3e53d10768 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 11 Jan 2018 13:32:25 +0000 Subject: [PATCH] Use the default gpg key if specified within the config file --- src/freedombone-controlpanel-user | 13 +++++++++++++ src/freedombone-utils-gpg | 13 +++++++++++++ src/freedombone-utils-keys | 13 +++++++++++++ 3 files changed, 39 insertions(+) diff --git a/src/freedombone-controlpanel-user b/src/freedombone-controlpanel-user index 3f257aad..692f049b 100755 --- a/src/freedombone-controlpanel-user +++ b/src/freedombone-controlpanel-user @@ -37,6 +37,19 @@ MY_EMAIL_ADDRESS=$USER@$HOSTNAME GPG_ID=$(gpg --list-keys $MY_EMAIL_ADDRESS | sed -n '2p' | sed 's/^[ \t]*//') GPG_BACKUP_ID=$(gpg --list-keys "(backup key)" | sed -n '2p' | sed 's/^[ \t]*//') +# If the default key is specified within gpg.conf +if [ -f ~/.gnupg/gpg.conf ]; then + if grep -q "default-key" ~/.gnupg/gpg.conf; then + default_gpg_key=$(cat ~/.gnupg/gpg.conf | grep "default-key") + if [[ "$default_gpg_key" != *'#'* ]]; then + default_gpg_key=$(cat ~/.gnupg/gpg.conf | grep "default-key" | awk -F ' ' '{print $2}') + if [ ${#default_gpg_key} -gt 3 ]; then + GPG_ID=$(gpg --list-keys $default_gpg_key | sed -n '2p' | sed 's/^[ \t]*//') + fi + fi + fi +fi + # Start including files UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-* diff --git a/src/freedombone-utils-gpg b/src/freedombone-utils-gpg index a35c68dc..86c1387b 100755 --- a/src/freedombone-utils-gpg +++ b/src/freedombone-utils-gpg @@ -38,6 +38,19 @@ function gpg_update_mutt { CURR_EMAIL_ADDRESS=$key_username@$HOSTNAME CURR_GPG_ID=$(gpg --homedir=/home/$key_username/.gnupg --list-keys $CURR_EMAIL_ADDRESS | sed -n '2p' | sed 's/^[ \t]*//') + # If the default key is specified within gpg.conf + if [ -f /home/$key_username/gpg.conf ]; then + if grep -q "default-key" /home/$key_username/gpg.conf; then + default_gpg_key=$(cat /home/$key_username/gpg.conf | grep "default-key") + if [[ "$default_gpg_key" != *'#'* ]]; then + default_gpg_key=$(cat /home/$key_username/gpg.conf | grep "default-key" | awk -F ' ' '{print $2}') + if [ ${#default_gpg_key} -gt 3 ]; then + CURR_GPG_ID=$(gpg --homedir=/home/$key_username/.gnupg --list-keys $default_gpg_key | sed -n '2p' | sed 's/^[ \t]*//') + fi + fi + fi + fi + sed -i "s|set pgp_encrypt_only_command.*|set pgp_encrypt_only_command=\"/usr/lib/mutt/pgpewrap gpg --batch --quiet --no-verbose --output - --encrypt --textmode --armor --trust-model always --encrypt-to $CURR_GPG_ID -- -r %r -- %f\"|g" /home/$key_username/.muttrc sed -i "s|set pgp_encrypt_sign_command.*|set pgp_encrypt_sign_command=\"/usr/lib/mutt/pgpewrap gpg %?p?--passphrase-fd 0? --batch --quiet --no-verbose --textmode --output - --encrypt --sign %?a?-u %a? --armor --trust-model always --encrypt-to $CURR_GPG_ID -- -r %r -- %f\"|g" /home/$key_username/.muttrc diff --git a/src/freedombone-utils-keys b/src/freedombone-utils-keys index 33dba28b..70f81c95 100755 --- a/src/freedombone-utils-keys +++ b/src/freedombone-utils-keys @@ -101,6 +101,19 @@ function interactive_gpg_from_usb { CURR_GPG_ID=$(gpg --homedir=$HOME_DIR/.gnupg --list-keys $CURR_EMAIL_ADDRESS | sed -n '2p' | sed 's/^[ \t]*//') CURR_GPG_BACKUP_ID=$(gpg --homedir=$HOME_DIR/.gnupg --list-keys "(backup key)" | sed -n '2p' | sed 's/^[ \t]*//') + # If the default key is specified within gpg.conf + if [ -f $HOME_DIR/gpg.conf ]; then + if grep -q "default-key" $HOME_DIR/gpg.conf; then + default_gpg_key=$(cat $HOME_DIR/gpg.conf | grep "default-key") + if [[ "$default_gpg_key" != *'#'* ]]; then + default_gpg_key=$(cat $HOME_DIR/gpg.conf | grep "default-key" | awk -F ' ' '{print $2}') + if [ ${#default_gpg_key} -gt 3 ]; then + CURR_GPG_ID=$(gpg --homedir=$HOME_DIR/.gnupg --list-keys $default_gpg_key | sed -n '2p' | sed 's/^[ \t]*//') + fi + fi + fi + fi + echo $'Making backup copy of existing gpg keys' if [ -d $HOME_DIR/.gnupg ]; then if [ -d $HOME_DIR/.gnupg_old ]; then