2 # This should be sourced by bash (though we welcome changes to make it POSIX sh compliant)
4 # Monkeysphere host add-revoker subcommand
6 # The monkeysphere scripts are written by:
7 # Jameson Rollins <jrollins@finestructure.net>
8 # Jamie McClelland <jm@mayfirst.org>
9 # Daniel Kahn Gillmor <dkg@fifthhorseman.net>
11 # They are Copyright 2008, and are all released under the GPL, version 3
14 # add a revoker to the host key
28 if [ -z "$keyID" ] ; then
29 failure "You must specify the key ID of a revoker key, or specify a file to read the key from."
31 if [ -f "$keyID" ] ; then
32 log info "Reading key from file '$keyID':"
33 importinfo=$(gpg_host --import < "$keyID" 2>&1) || failure "could not read key from '$keyID'"
34 # FIXME: if this is tried when the key database is not
35 # up-to-date, i got these errors (using set -x):
37 # ++ su -m monkeysphere -c '\''gpg --import'\''
38 # Warning: using insecure memory!
39 # gpg: key D21739E9: public key "Daniel Kahn Gillmor <dkg@fifthhorseman.net>" imported
40 # gpg: Total number processed: 1
41 # gpg: imported: 1 (RSA: 1)
42 # gpg: can'\''t create `/var/monkeysphere/gnupg-host/pubring.gpg.tmp'\'': Permission denied
43 # gpg: failed to rebuild keyring cache: Permission denied
44 # gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
45 # gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u
46 # gpg: next trustdb check due at 2009-01-10'
47 # + failure 'could not read key from '\''/root/dkg.gpg'\'''
48 # + echo 'could not read key from '\''/root/dkg.gpg'\'''
50 keyID=$(echo "$importinfo" | grep '^gpg: key ' | cut -f2 -d: | cut -f3 -d\ )
51 if [ -z "$keyID" ] || [ $(echo "$keyID" | wc -l) -ne 1 ] ; then
52 failure "There was not exactly one gpg key in the file."
55 # create a temporary directory for storing the downloaded key
56 TMPLOC=$(mktemp -d "${MHTMPDIR}"/tmp.XXXXXXXXXX) || failure "Could not create temporary directory!"
58 # download the key from the keyserver as the monkeysphere user
59 su_monkeysphere_user \
60 "GNUPGHOME=$TMPLOC gpg --keyserver $KEYSERVER --recv-key 0x${keyID}!"
62 # export the new key to the host keyring
63 su_monkeysphere_user "GNUPGHOME=$TMPLOC gpg --export 0x${keyID}!" \
69 # get the full fingerprint of the revoker key ID
70 fingerprint=$(gpg_host --list-key --with-colons --with-fingerprint "0x${keyID}!" \
71 | grep '^fpr:' | grep "$keyID" | cut -d: -f10)
73 if [ -z "$fingerprint" ] ; then
74 failure "Key '$keyID' not found."
78 gpg_host --fingerprint "0x${fingerprint}!"
80 if [ "$PROMPT" = "true" ] ; then
81 echo "Are you sure you want to add the above key as a"
82 read -p "revoker of the host key? (y/N) " OK; OK=${OK:-N}
83 if [ "${OK/y/Y}" != 'Y' ] ; then
84 failure "revoker not added."
87 log debug "adding revoker without prompting."
90 # edit-key script to add revoker
91 addrevokerCommand=$(cat <<EOF
98 failure "not implemented yet!"
100 # core ltsigns the newly imported revoker key
101 if echo "$addrevokerCommand" | \
106 log info "Revoker added."
108 failure "Problem adding revoker."