From 223d9931eb2db34972d130fb6f87e6ae342b82d1 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 15 May 2017 18:16:02 +0100 Subject: [PATCH] Consolidate getting the gpg public key --- src/freedombone-adduser | 2 +- src/freedombone-app-xmpp | 4 ++-- src/freedombone-base-email | 12 ------------ src/freedombone-restore-local | 12 ------------ src/freedombone-restore-remote | 12 ------------ src/freedombone-sec | 12 ------------ src/freedombone-utils-gpg | 12 ++++++++++++ 7 files changed, 15 insertions(+), 51 deletions(-) diff --git a/src/freedombone-adduser b/src/freedombone-adduser index 7c082b8c..8ffe7241 100755 --- a/src/freedombone-adduser +++ b/src/freedombone-adduser @@ -146,7 +146,7 @@ echo 'Expire-Date: 0' >> /home/$ADD_USERNAME/gpg-genkey.conf chown $ADD_USERNAME:$ADD_USERNAME /home/$ADD_USERNAME/gpg-genkey.conf su -c "gpg --batch --gen-key /home/$ADD_USERNAME/gpg-genkey.conf" - $ADD_USERNAME shred -zu /home/$ADD_USERNAME/gpg-genkey.conf -MY_GPG_PUBLIC_KEY_ID=$(su -c "gpg --list-keys $ADD_USERNAME@$HOSTNAME | grep 'pub '" - $ADD_USERNAME | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}') +MY_GPG_PUBLIC_KEY_ID=$(gpg_pubkey_from_email "$ADD_USERNAME" "$ADD_USERNAME@$HOSTNAME") MY_GPG_PUBLIC_KEY=/home/$ADD_USERNAME/public_key.gpg su -c "gpg --output $MY_GPG_PUBLIC_KEY --armor --export $MY_GPG_PUBLIC_KEY_ID" - $ADD_USERNAME diff --git a/src/freedombone-app-xmpp b/src/freedombone-app-xmpp index d8a1b96f..d5bae686 100755 --- a/src/freedombone-app-xmpp +++ b/src/freedombone-app-xmpp @@ -208,7 +208,7 @@ function add_user_xmpp { if [ ! -d /home/$new_username/.config/profanity ]; then mkdir -p /home/$new_username/.config/profanity fi - GPG_PUBLIC_KEY_ID=$(su -c "gpg --list-keys $new_username@$HOSTNAME | grep 'pub '" - $new_username | head -n 1 | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}') + MY_GPG_PUBLIC_KEY_ID=$(gpg_pubkey_from_email "$new_username" "$new_username@$HOSTNAME") echo "[${new_username}@${HOSTNAME}]" > $XMPP_CLIENT_ACCOUNTS echo 'enabled=true' >> $XMPP_CLIENT_ACCOUNTS echo "jid=${new_username}@${HOSTNAME}" >> $XMPP_CLIENT_ACCOUNTS @@ -1109,7 +1109,7 @@ function install_xmpp_client { fi XMPP_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_xmpp/hostname) - MY_GPG_PUBLIC_KEY_ID=$(su -c "gpg --list-keys $MY_USERNAME@$DEFAULT_DOMAIN_NAME | grep 'pub '" - $MY_USERNAME | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}') + MY_GPG_PUBLIC_KEY_ID=$(gpg_pubkey_from_email "$MY_USERNAME" "$MY_USERNAME@$DEFAULT_DOMAIN_NAME") if [[ $ONION_ONLY == 'no' ]]; then echo "[${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}]" > $XMPP_CLIENT_ACCOUNTS diff --git a/src/freedombone-base-email b/src/freedombone-base-email index 3443c290..b9ea278e 100755 --- a/src/freedombone-base-email +++ b/src/freedombone-base-email @@ -1524,18 +1524,6 @@ function gpg_key_exists { echo "yes" } -function gpg_pubkey_from_email { - key_owner_username=$1 - key_email_address=$2 - key_id= - if [[ $key_owner_username != "root" ]]; then - key_id=$(su -c "gpg --list-keys $key_email_address | grep 'pub '" - $key_owner_username | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}') - else - key_id=$(gpg --list-keys $key_email_address | grep 'pub ' | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}') - fi - echo $key_id -} - function configure_gpg { if [ ! -d /etc/exim4 ]; then return diff --git a/src/freedombone-restore-local b/src/freedombone-restore-local index a534add8..4fcacbd8 100755 --- a/src/freedombone-restore-local +++ b/src/freedombone-restore-local @@ -473,18 +473,6 @@ function restore_user_config { fi } -function gpg_pubkey_from_email { - key_owner_username=$1 - key_email_address=$2 - key_id= - if [[ $key_owner_username != "root" ]]; then - key_id=$(su -c "gpg --list-keys $key_email_address | grep 'pub '" - $key_owner_username | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}') - else - key_id=$(gpg --list-keys $key_email_address | grep 'pub ' | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}') - fi - echo $key_id -} - function restore_user_monkeysphere { if [[ $RESTORE_APP != 'all' ]]; then if [[ $RESTORE_APP != 'usermonkeysphere' ]]; then diff --git a/src/freedombone-restore-remote b/src/freedombone-restore-remote index 04e7ae22..232d9903 100755 --- a/src/freedombone-restore-remote +++ b/src/freedombone-restore-remote @@ -435,18 +435,6 @@ function restore_user_config { done } -function gpg_pubkey_from_email { - key_owner_username=$1 - key_email_address=$2 - key_id= - if [[ $key_owner_username != "root" ]]; then - key_id=$(su -c "gpg --list-keys $key_email_address | grep 'pub '" - $key_owner_username | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}') - else - key_id=$(gpg --list-keys $key_email_address | grep 'pub ' | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}') - fi - echo $key_id -} - function restore_user_monkeysphere { if [[ $RESTORE_APP != 'all' ]]; then if [[ $RESTORE_APP != 'usermonkeysphere' ]]; then diff --git a/src/freedombone-sec b/src/freedombone-sec index fe90e1a0..d43a7259 100755 --- a/src/freedombone-sec +++ b/src/freedombone-sec @@ -636,18 +636,6 @@ function update_ciphersuite { exit 0 } -function gpg_pubkey_from_email { - key_owner_username=$1 - key_email_address=$2 - key_id= - if [[ $key_owner_username != "root" ]]; then - key_id=$(su -c "gpg --list-keys $key_email_address | grep 'pub '" - $key_owner_username | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}') - else - key_id=$(gpg --list-keys $key_email_address | grep 'pub ' | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}') - fi - echo $key_id -} - function enable_monkeysphere { monkey= dialog --title $"GPG based authentication" \ diff --git a/src/freedombone-utils-gpg b/src/freedombone-utils-gpg index d43adad9..bfa7ec3d 100755 --- a/src/freedombone-utils-gpg +++ b/src/freedombone-utils-gpg @@ -28,6 +28,18 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +function gpg_pubkey_from_email { + key_owner_username=$1 + key_email_address=$2 + key_id= + if [[ $key_owner_username != "root" ]]; then + key_id=$(su -c "gpg --list-keys $key_email_address | grep 'pub '" - $key_owner_username | head -n 1 | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}') + else + key_id=$(gpg --list-keys $key_email_address | grep 'pub ' | head -n 1 | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}') + fi + echo $key_id +} + function enable_email_encryption_at_rest { for d in /home/*/ ; do USERNAME=$(echo "$d" | awk -F '/' '{print $3}')