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 fingerprint=$(su_monkeysphere_user \
50 ". ${SYSSHAREDIR}/common; list_primary_fingerprints" < "$keyID")
52 if [ $(printf "%s" "$fingerprint" | egrep -c '^[A-F0-9]{40}$') -ne 1 ] ; then
53 failure "There was not exactly one gpg key in the file."
57 gpg_host --import <"$keyID" \
58 || failure "could not read key from '$keyID'"
62 # else, get the key from the keyserver
64 # create a temporary directory for storing the downloaded key
65 local TMPLOC=$(msmktempdir)
66 chmod 0700 "$GNUPGHOME"
67 chown "$MONKEYSPHERE_USER":"$MONKEYSPHERE_USER" "$GNUPGHOME"
69 # download the key from the keyserver as the monkeysphere user
70 log verbose "searching keyserver $KEYSERVER for keyID $keyID..."
71 su_monkeysphere_user \
72 "GNUPGHOME=$TMPLOC gpg --quiet --keyserver $KEYSERVER --recv-key 0x${keyID}!" \
73 || failure "Could not receive a key with this ID from the '$KEYSERVER' keyserver."
75 # export the new key to the host keyring
76 log verbose "loading key $keyID..."
77 su_monkeysphere_user "GNUPGHOME=$TMPLOC gpg --quiet --export 0x${keyID}!" \
81 # get the full fingerprint of new revoker key
82 log debug "getting fingerprint of revoker key..."
83 fingerprint=$(gpg_host --list-key --with-colons --with-fingerprint "0x${keyID}!" \
84 | grep '^fpr:' | grep "$keyID" | cut -d: -f10)
86 if [ -z "$fingerprint" ] ; then
87 failure "Key '$keyID' not found."
91 gpg_host --fingerprint "0x${fingerprint}!"
93 if [ "$PROMPT" = "true" ] ; then
94 echo "Are you sure you want to add the above key as a"
95 read -p "revoker of the host key? (Y/n) " OK; OK=${OK:-Y}
96 if [ "${OK/y/Y}" != 'Y' ] ; then
97 failure "revoker not added."
100 log debug "adding revoker without prompting."
103 # edit-key script to add revoker
104 addrevokerCommand=$(cat <<EOF
111 failure "not implemented yet!"
113 # core ltsigns the newly imported revoker key
114 if echo "$addrevokerCommand" | \
119 log info "Revoker added."
121 failure "Problem adding revoker."