X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=src%2Fshare%2Fmh%2Fadd_revoker;h=c83cb24e3cff294a1ca8e3594b27332c63f7bbd3;hb=134b8c66bec679556bec90c4eef937d464a7950e;hp=2275f6119688bbaf199f32086111b4f080e72942;hpb=e13bbc823bc8fe7a28303e45055643e15d0849cd;p=monkeysphere.git diff --git a/src/share/mh/add_revoker b/src/share/mh/add_revoker index 2275f61..c83cb24 100644 --- a/src/share/mh/add_revoker +++ b/src/share/mh/add_revoker @@ -15,14 +15,10 @@ add_revoker() { -local domain= -local trust=full -local depth=1 local keyID -local importinfo +local tmpDir local fingerprint -local ltsignCommand -local trustval +local addrevokerCommand keyID="$1" @@ -31,12 +27,17 @@ if [ -z "$keyID" ] ; then failure "You must specify the key ID of a revoker key, or specify a file to read the key from." fi +# make a temporary directory for storing keys during import, and set +# the trap to delete it on exit +tmpDir=$(msmktempdir) +trap "rm -rf $tmpDir" EXIT + # if file is specified if [ -f "$keyID" -o "$keyID" = '-' ] ; then # load the key from stdin if [ "$keyID" = '-' ] ; then - local keyID=$(msmktempfile) - trap "rm -f $keyID" EXIT + # make a temporary file to hold the key from stdin + keyID="$tmpDir"/importkey log verbose "reading key from stdin..." cat > "$keyID" @@ -58,62 +59,63 @@ if [ -f "$keyID" -o "$keyID" = '-' ] ; then gpg_host --import <"$keyID" \ || failure "could not read key from '$keyID'" - keyID="$fingerprint" - # else, get the key from the keyserver else - # create a temporary directory for storing the downloaded key - local TMPLOC=$(msmktempdir) - chmod 0700 "$GNUPGHOME" - chown "$MONKEYSPHERE_USER":"$MONKEYSPHERE_USER" "$GNUPGHOME" + # fix permissions and ownership on temporary directory which will + # be used by monkeysphere user for storing the downloaded key + chmod 0700 "$tmpDir" + chown "$MONKEYSPHERE_USER":"$MONKEYSPHERE_GROUP" "$tmpDir" # download the key from the keyserver as the monkeysphere user log verbose "searching keyserver $KEYSERVER for keyID $keyID..." - su_monkeysphere_user \ - "GNUPGHOME=$TMPLOC gpg --quiet --keyserver $KEYSERVER --recv-key 0x${keyID}!" \ + su_monkeysphere_user "GNUPGHOME=$tmpDir gpg --quiet --keyserver $KEYSERVER --recv-key 0x${keyID}!" \ || failure "Could not receive a key with this ID from the '$KEYSERVER' keyserver." - # export the new key to the host keyring - log verbose "loading key $keyID..." - su_monkeysphere_user "GNUPGHOME=$TMPLOC gpg --quiet --export 0x${keyID}!" \ - | gpg_host --import -fi - -# get the full fingerprint of new revoker key -log debug "getting fingerprint of revoker key..." -fingerprint=$(gpg_host --list-key --with-colons --with-fingerprint "0x${keyID}!" \ - | grep '^fpr:' | grep "$keyID" | cut -d: -f10) - -if [ -z "$fingerprint" ] ; then - failure "Key '$keyID' not found." -fi - -log info "key found:" -gpg_host --fingerprint "0x${fingerprint}!" + # get the full fingerprint of new revoker key + log debug "getting fingerprint of revoker key..." + fingerprint=$(su_monkeysphere_user "GNUPGHOME=$tmpDir gpg --list-key --with-colons --with-fingerprint 0x${keyID}!" \ + | grep '^fpr:' | cut -d: -f10) + + # test that there is only a single fingerprint + if (( $(echo "$fingerprint" | wc -l) != 1 )) ; then + cat <