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
21 local addrevokerCommand
25 # check that key ID or file is specified
26 if [ -z "$keyID" ] ; then
27 failure "You must specify the key ID of a revoker key, or specify a file to read the key from."
30 # make a temporary directory for storing keys during import, and set
31 # the trap to delete it on exit
33 trap "rm -rf $tmpDir" EXIT
35 # if file is specified
36 if [ -f "$keyID" -o "$keyID" = '-' ] ; then
37 # load the key from stdin
38 if [ "$keyID" = '-' ] ; then
39 # make a temporary file to hold the key from stdin
40 keyID="$tmpDir"/importkey
41 log verbose "reading key from stdin..."
44 # load the key from the file
45 elif [ -f "$keyID" ] ; then
46 log verbose "reading key from file '$keyID'..."
49 # check the key is ok as monkeysphere user before loading
50 log debug "checking keys in file..."
51 fingerprint=$(su_monkeysphere_user \
52 ". ${SYSSHAREDIR}/common; list_primary_fingerprints" < "$keyID")
54 if [ $(printf "%s" "$fingerprint" | egrep -c '^[A-F0-9]{40}$') -ne 1 ] ; then
55 failure "There was not exactly one gpg key in the file."
59 gpg_host --import <"$keyID" \
60 || failure "could not read key from '$keyID'"
62 # else, get the key from the keyserver
64 # fix permissions and ownership on temporary directory which will
65 # be used by monkeysphere user for storing the downloaded key
67 chown "$MONKEYSPHERE_USER":"$MONKEYSPHERE_USER" "$tmpDir"
69 # download the key from the keyserver as the monkeysphere user
70 log verbose "searching keyserver $KEYSERVER for keyID $keyID..."
71 su_monkeysphere_user "GNUPGHOME=$tmpDir gpg --quiet --keyserver $KEYSERVER --recv-key 0x${keyID}!" \
72 || failure "Could not receive a key with this ID from the '$KEYSERVER' keyserver."
74 # get the full fingerprint of new revoker key
75 log debug "getting fingerprint of revoker key..."
76 fingerprint=$(su_monkeysphere_user "GNUPGHOME=$tmpDir gpg --list-key --with-colons --with-fingerprint 0x${keyID}!" \
77 | grep '^fpr:' | grep "$keyID" | cut -d: -f10)
80 su_monkeysphere_user "GNUPGHOME=$tmpDir gpg --fingerprint 0x${fingerprint}!"
82 if [ "$PROMPT" = "true" ] ; then
83 echo "Are you sure you want to add the above key as a"
84 read -p "revoker of the host key? (Y/n) " OK; OK=${OK:-Y}
85 if [ "${OK/y/Y}" != 'Y' ] ; then
86 failure "revoker not added."
89 log debug "adding revoker without prompting."
92 # export the new key to the host keyring
93 log debug "loading key into host keyring..."
94 su_monkeysphere_user "GNUPGHOME=$tmpDir gpg --quiet --export 0x${fingerprint}!" \
98 # edit-key script to add revoker
99 addrevokerCommand=$(cat <<EOF
108 # core ltsigns the newly imported revoker key
109 log debug "executing add revoker script..."
110 if echo "$addrevokerCommand" | gpg_host_edit ; then
114 log info "Revoker added."
116 failure "Problem adding revoker."
119 # remove the temporary directory