summaryrefslogtreecommitdiff
path: root/src/share/mh/revoke_hostname
blob: 12158287d47d490d045fb1530cb5fa46cf73e72d (plain)
  1. # -*-shell-script-*-
  2. # This should be sourced by bash (though we welcome changes to make it POSIX sh compliant)
  3. # Monkeysphere host revoke-hostname subcommand
  4. #
  5. # The monkeysphere scripts are written by:
  6. # Jameson Rollins <jrollins@finestructure.net>
  7. # Jamie McClelland <jm@mayfirst.org>
  8. # Daniel Kahn Gillmor <dkg@fifthhorseman.net>
  9. #
  10. # They are Copyright 2008-2009, and are all released under the GPL,
  11. # version 3 or later.
  12. # revoke hostname user ID from host key
  13. revoke_hostname() {
  14. local userID
  15. local fingerprint
  16. local tmpuidMatch
  17. local line
  18. local uidIndex
  19. local message
  20. local revuidCommand
  21. if [ -z "$1" ] ; then
  22. failure "You must specify a hostname to revoke."
  23. fi
  24. echo "WARNING: There is a known bug in this function."
  25. echo "This function has been known to occasionally revoke the wrong hostname."
  26. echo "Please see the following bug report for more information:"
  27. echo "https://labs.riseup.net/code/issues/show/422"
  28. read -p "Are you sure you would like to proceed? (y/N) " OK; OK=${OK:=N}
  29. if [ ${OK/y/Y} != 'Y' ] ; then
  30. failure "aborting."
  31. fi
  32. userID="ssh://${1}"
  33. # make sure the user ID to revoke
  34. uidIndex=$(find_host_userid) || \
  35. failure "No non-revoked user ID found matching '$userID'."
  36. if [ "$PROMPT" = "true" ] ; then
  37. cat <<EOF
  38. The following host key user ID will be revoked:
  39. $userID
  40. EOF
  41. read -p "Are you sure you would like to revoke this user ID? (Y/n) " OK; OK=${OK:=Y}
  42. if [ "${OK/y/Y}" != 'Y' ] ; then
  43. failure "User ID not revoked."
  44. fi
  45. else
  46. log debug "revoking user ID without prompting."
  47. fi
  48. # edit-key script command to revoke user ID
  49. revuidCommand=$(cat <<EOF
  50. $uidIndex
  51. revuid
  52. y
  53. 4
  54. Hostname removed by monkeysphere-host: $DATE
  55. y
  56. save
  57. EOF
  58. )
  59. # execute edit-key script
  60. if echo "$revuidCommand" | gpg_host_edit ; then
  61. update_gpg_pub_file
  62. show_key
  63. echo
  64. echo "NOTE: User ID revoked, but revocation not published."
  65. echo "Run '$PGRM publish-key' to publish the revocation."
  66. else
  67. failure "Problem revoking user ID."
  68. fi
  69. }