1464ae8464dce5ad6e94bc79d910f62a8b8403a7
[monkeysphere.git] / src / share / mh / add_revoker
1 # -*-shell-script-*-
2 # This should be sourced by bash (though we welcome changes to make it POSIX sh compliant)
3
4 # Monkeysphere host add-revoker subcommand
5 #
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>
10 #
11 # They are Copyright 2008, and are all released under the GPL, version 3
12 # or later.
13
14 # add a revoker to the host key
15
16 add_revoker() {
17
18 local domain=
19 local trust=full
20 local depth=1
21 local keyID
22 local importinfo
23 local fingerprint
24 local ltsignCommand
25 local trustval
26
27 keyID="$1"
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."
30 fi
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):
36
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'\'''
49
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."
53     fi
54 else
55     # create a temporary directory for storing the downloaded key
56     TMPLOC=$(mktemp -d "${MHTMPDIR}"/tmp.XXXXXXXXXX) || failure "Could not create temporary directory!"
57
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}!"
61
62     # export the new key to the host keyring
63     su_monkeysphere_user "GNUPGHOME=$TMPLOC gpg --export 0x${keyID}!" \
64         | gpg_host --import
65 fi
66
67 export keyID
68
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)
72
73 if [ -z "$fingerprint" ] ; then
74     failure "Key '$keyID' not found."
75 fi
76
77 log info "key found:"
78 gpg_host --fingerprint "0x${fingerprint}!"
79
80 echo "Are you sure you want to add the above key as a"
81 read -p "revoker of the host key? (y/N) " OK; OK=${OK:-N}
82 if [ "${OK/y/Y}" != 'Y' ] ; then
83     failure "Revoker not added."
84 fi
85
86 # edit-key script to add revoker
87 addrevokerCommand=$(cat <<EOF
88 addrevoker
89
90 EOF
91     )
92
93 # FIXME: implement!
94 failure "not implemented yet!"
95
96 # core ltsigns the newly imported revoker key
97 if echo "$addrevokerCommand" | \
98     gpg_core_edit ; then
99
100     update_gpg_pub_file
101
102     log info "Revoker added."
103 else
104     failure "Problem adding revoker."
105 fi
106
107 }