decac8692f5bb7cd92a67d970e6b3bdda2ba3d27
[monkeysphere.git] / src / subcommands / mh / revoke-hostname
1 #!/usr/bin/env bash
2
3 # Monkeysphere host revoke-hostname subcommand
4 #
5 # The monkeysphere scripts are written by:
6 # Jameson Rollins <jrollins@fifthhorseman.net>
7 # Jamie McClelland <jm@mayfirst.org>
8 # Daniel Kahn Gillmor <dkg@fifthhorseman.net>
9 #
10 # They are Copyright 2008, and are all released under the GPL, version 3
11 # or later.
12
13 # revoke hostname user ID from host key
14
15 local userID
16 local fingerprint
17 local tmpuidMatch
18 local line
19 local uidIndex
20 local message
21 local revuidCommand
22
23 if [ -z "$1" ] ; then
24     failure "You must specify a hostname to revoke."
25 fi
26
27 echo "WARNING: There is a known bug in this function."
28 echo "This function has been known to occasionally revoke the wrong user ID."
29 echo "Please see the following bug report for more information:"
30 echo "http://web.monkeysphere.info/bugs/revoke-hostname-revoking-wrong-userid/"
31 read -p "Are you sure you would like to proceed? (y/N) " OK; OK=${OK:=N}
32 if [ ${OK/y/Y} != 'Y' ] ; then
33     failure "aborting."
34 fi
35
36 userID="ssh://${1}"
37
38 fingerprint=$(fingerprint_server_key)
39
40 # match to only ultimately trusted user IDs
41 tmpuidMatch="u:$(echo $userID | gpg_escape)"
42
43 # find the index of the requsted user ID
44 # NOTE: this is based on circumstantial evidence that the order of
45 # this output is the appropriate index
46 if line=$(gpg_host --list-keys --with-colons --fixed-list-mode "0x${fingerprint}!" \
47     | egrep '^(uid|uat):' | cut -f2,10 -d: | grep -n -x -F "$tmpuidMatch") ; then
48     uidIndex=${line%%:*}
49 else
50     failure "No non-revoked user ID '$userID' is found."
51 fi
52
53 echo "The following host key user ID will be revoked:"
54 echo "  $userID"
55 read -p "Are you sure you would like to revoke this user ID? (y/N) " OK; OK=${OK:=N}
56 if [ ${OK/y/Y} != 'Y' ] ; then
57     failure "User ID not revoked."
58 fi
59
60 message="Hostname removed by monkeysphere-server $DATE"
61
62 # edit-key script command to revoke user ID
63 revuidCommand=$(cat <<EOF
64 $uidIndex
65 revuid
66 y
67 4
68 $message
69
70 y
71 save
72 EOF
73     )   
74
75 # execute edit-key script
76 if echo "$revuidCommand" | \
77     gpg_host --quiet --command-fd 0 --edit-key "0x${fingerprint}!" ; then
78
79     # update the trustdb for the authentication keyring
80     gpg_authentication "--check-trustdb"
81
82     show_server_key
83
84     echo
85     echo "NOTE: User ID revoked, but revocation not published."
86     echo "Run '$PGRM publish-key' to publish the revocation."
87 else
88     failure "Problem revoking user ID."
89 fi