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-2010, and are all released under the GPL,
14 # add a revoker to the host key
22 local addrevokerCommand
24 # check that key ID or file is specified
26 failure "You must specify the key ID of a revoker key, or specify a file to read the key from."
31 keyID=$(check_key_input "$@")
33 # make a temporary directory for storing keys during import, and set
34 # the trap to delete it on exit
36 trap "rm -rf $tmpDir" EXIT
38 # if file is specified
39 if [ -f "$revokerKeyID" -o "$revokerKeyID" = '-' ] ; then
40 # load the key from stdin
41 if [ "$revokerKeyID" = '-' ] ; then
42 # make a temporary file to hold the key from stdin
43 revokerKeyID="$tmpDir"/importkey
44 log verbose "reading revoker key from stdin..."
47 # load the key from the file
48 elif [ -f "$revokerKeyID" ] ; then
49 log verbose "reading revoker key from file '$revokerKeyID'..."
52 # check the key is ok as monkeysphere user before loading
53 log debug "checking keys in file..."
54 fingerprint=$(su_monkeysphere_user \
55 ". ${SYSSHAREDIR}/common; list_primary_fingerprints" < "$revokerKeyID")
57 if [ $(printf "%s" "$fingerprint" | egrep -c '^[A-F0-9]{40}$') -ne 1 ] ; then
58 failure "There was not exactly one gpg key in the file."
62 gpg_host --import <"$revokerKeyID" \
63 || failure "could not read revoker key from '$revokerKeyID'"
65 # else, get the revoker key from the keyserver
67 # fix permissions and ownership on temporary directory which will
68 # be used by monkeysphere user for storing the downloaded key
70 chown "$MONKEYSPHERE_USER":"$MONKEYSPHERE_GROUP" "$tmpDir"
72 # download the key from the keyserver as the monkeysphere user
73 log verbose "searching keyserver $KEYSERVER for revoker keyID $revokerKeyID..."
74 su_monkeysphere_user "GNUPGHOME=$tmpDir gpg --quiet --keyserver $KEYSERVER --recv-key 0x${revokerKeyID}!" \
75 || failure "Could not receive a key with this ID from keyserver '$KEYSERVER'."
77 # get the full fingerprint of new revoker key
78 log debug "getting fingerprint of revoker key..."
79 fingerprint=$(su_monkeysphere_user "GNUPGHOME=$tmpDir gpg --list-key --with-colons --with-fingerprint ${revokerKeyID}" \
80 | grep '^fpr:' | cut -d: -f10)
82 # test that there is only a single fingerprint
83 if (( $(echo "$fingerprint" | wc -l) != 1 )) ; then
85 More than one fingerprint found:
87 Please use a more specific key ID.
92 log info "revoker key found:"
93 su_monkeysphere_user "GNUPGHOME=$tmpDir gpg --fingerprint 0x${fingerprint}!"
95 if [ "$PROMPT" = "true" ] ; then
96 printf "Are you sure you want to add the above key as a revoker\nof the key '$keyID'? (Y/n) " >&2
98 if [ "${OK/y/Y}" != 'Y' ] ; then
99 failure "revoker not added."
102 log debug "adding revoker without prompting."
105 # export the new key to the host keyring
106 log debug "loading revoker key into host keyring..."
107 su_monkeysphere_user "GNUPGHOME=$tmpDir gpg --quiet --export 0x${fingerprint}!" \
111 # edit-key script to add revoker
112 addrevokerCommand="addrevoker
119 # core ltsigns the newly imported revoker key
120 log debug "executing add revoker script..."
121 if echo "$addrevokerCommand" | gpg_host_edit "0x${keyID}!" ; then
125 log info "Revoker added."
127 failure "Problem adding revoker."
130 # remove the temporary directory