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
29 # check that key ID or file is specified
30 if [ -z "$keyID" ] ; then
31 failure "You must specify the key ID of a revoker key, or specify a file to read the key from."
34 # if file is specified
35 if [ -f "$keyID" -o "$keyID" = '-' ] ; then
36 # load the key from stdin
37 if [ "$keyID" = '-' ] ; then
38 local keyID=$(msmktempfile)
39 trap "rm -f $keyID" EXIT
40 log verbose "reading key from stdin..."
43 # load the key from the file
44 elif [ -f "$keyID" ] ; then
45 log verbose "reading key from file '$keyID'..."
48 # check the key is ok as monkeysphere user before loading
49 log debug "checking keys in file..."
50 fingerprint=$(su_monkeysphere_user \
51 ". ${SYSSHAREDIR}/common; list_primary_fingerprints" < "$keyID")
53 if [ $(printf "%s" "$fingerprint" | egrep -c '^[A-F0-9]{40}$') -ne 1 ] ; then
54 failure "There was not exactly one gpg key in the file."
58 gpg_host --import <"$keyID" \
59 || failure "could not read key from '$keyID'"
63 # else, get the key from the keyserver
65 # create a temporary directory for storing the downloaded key
66 local TMPLOC=$(msmktempdir)
67 chmod 0700 "$GNUPGHOME"
68 chown "$MONKEYSPHERE_USER":"$MONKEYSPHERE_USER" "$GNUPGHOME"
70 # download the key from the keyserver as the monkeysphere user
71 log verbose "searching keyserver $KEYSERVER for keyID $keyID..."
72 su_monkeysphere_user \
73 "GNUPGHOME=$TMPLOC gpg --quiet --keyserver $KEYSERVER --recv-key 0x${keyID}!" \
74 || failure "Could not receive a key with this ID from the '$KEYSERVER' keyserver."
76 # export the new key to the host keyring
77 log verbose "loading key $keyID..."
78 su_monkeysphere_user "GNUPGHOME=$TMPLOC gpg --quiet --export 0x${keyID}!" \
82 # get the full fingerprint of new revoker key
83 log debug "getting fingerprint of revoker key..."
84 fingerprint=$(gpg_host --list-key --with-colons --with-fingerprint "0x${keyID}!" \
85 | grep '^fpr:' | grep "$keyID" | cut -d: -f10)
87 if [ -z "$fingerprint" ] ; then
88 failure "Key '$keyID' not found."
92 gpg_host --fingerprint "0x${fingerprint}!"
94 if [ "$PROMPT" = "true" ] ; then
95 echo "Are you sure you want to add the above key as a"
96 read -p "revoker of the host key? (Y/n) " OK; OK=${OK:-Y}
97 if [ "${OK/y/Y}" != 'Y' ] ; then
98 failure "revoker not added."
101 log debug "adding revoker without prompting."
104 # edit-key script to add revoker
105 addrevokerCommand=$(cat <<EOF
112 failure "not implemented yet!"
114 # core ltsigns the newly imported revoker key
115 if echo "$addrevokerCommand" | \
120 log info "Revoker added."
122 failure "Problem adding revoker."