44ba3122ad6b4c5543ecd913ebe7cb4816e5256f
[monkeysphere.git] / src / share / mh / revoke_hostname
1 # -*-shell-script-*-
2 # This should be sourced by bash (though we welcome changes to make it POSIX sh compliant)
3
4 # Monkeysphere host revoke-hostname 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-2009, and are all released under the GPL,
12 # version 3 or later.
13
14 # revoke hostname user ID from host key
15
16 revoke_hostname() {
17
18 local userID
19 local fingerprint
20 local tmpuidMatch
21 local line
22 local uidIndex
23 local message
24 local revuidCommand
25
26 if [ -z "$1" ] ; then
27     failure "You must specify a hostname to revoke."
28 fi
29
30 echo "WARNING: There is a known bug in this function.
31 This function has been known to occasionally revoke the wrong hostname.
32 Please see the following bug report for more information:
33 https://labs.riseup.net/code/issues/show/422" >&2
34 printf "Are you sure you would like to proceed? (y/N) " >&2
35 read OK; OK=${OK:=N}
36 if [ ${OK/y/Y} != 'Y' ] ; then
37     failure "aborting."
38 fi
39
40 userID="ssh://${1}"
41
42 # make sure the user ID to revoke
43 uidIndex=$(find_host_userid) || \
44     failure "No non-revoked user ID found matching '$userID'."
45
46 if [ "$PROMPT" = "true" ] ; then
47     printf "The following host key user ID will be revoked:\n  %s\nAre you sure you would like to revoke this user ID? (Y/n) " "$userID" >&2
48     read OK; OK=${OK:=Y}
49     if [ "${OK/y/Y}" != 'Y' ] ; then
50         failure "User ID not revoked."
51     fi
52 else
53     log debug "revoking user ID without prompting."
54 fi
55
56 # edit-key script command to revoke user ID
57 revuidCommand="$uidIndex
58 revuid
59 y
60 4
61 Hostname removed by monkeysphere-host: $DATE
62
63 y
64 save"
65 # end script
66
67 # execute edit-key script
68 if echo "$revuidCommand" | gpg_host_edit ; then
69
70     update_gpg_pub_file
71
72     show_key
73
74     echo
75     echo "NOTE: User ID revoked, but revocation not published."
76     echo "Run '$PGRM publish-key' to publish the revocation."
77 else
78     failure "Problem revoking user ID."
79 fi
80
81 }