tests/basic now tests for adding and revoking hostnames.
[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 userID="ssh://${1}"
31
32 # make sure the user ID to revoke
33 uidIndex=$(find_host_userid) || \
34     failure "No non-revoked user ID found matching '$userID'."
35
36 if [ "$PROMPT" = "true" ] ; then
37     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
38     read OK; OK=${OK:=Y}
39     if [ "${OK/y/Y}" != 'Y' ] ; then
40         failure "User ID not revoked."
41     fi
42 else
43     log debug "revoking user ID without prompting."
44 fi
45
46 # actually revoke:
47 if <"$GNUPGHOME_HOST/secring.gpg" "$SYSSHAREDIR/keytrans" revokeuserid \
48     "$HOST_FINGERPRINT" "$userID" | gpg_host --import ; then
49     gpg_host --check-trustdb
50
51     update_gpg_pub_file
52
53     show_key
54
55     echo
56     echo "NOTE: User ID revoked, but revocation not published."
57     echo "Run '$PGRM publish-key' to publish the revocation."
58 else
59     failure "Problem revoking user ID."
60 fi
61
62 }