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