summaryrefslogtreecommitdiff
path: root/src/subcommands/mh/revoke-hostname
blob: decac8692f5bb7cd92a67d970e6b3bdda2ba3d27 (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. local userID
  13. local fingerprint
  14. local tmpuidMatch
  15. local line
  16. local uidIndex
  17. local message
  18. local revuidCommand
  19. if [ -z "$1" ] ; then
  20. failure "You must specify a hostname to revoke."
  21. fi
  22. echo "WARNING: There is a known bug in this function."
  23. echo "This function has been known to occasionally revoke the wrong user ID."
  24. echo "Please see the following bug report for more information:"
  25. echo "http://web.monkeysphere.info/bugs/revoke-hostname-revoking-wrong-userid/"
  26. read -p "Are you sure you would like to proceed? (y/N) " OK; OK=${OK:=N}
  27. if [ ${OK/y/Y} != 'Y' ] ; then
  28. failure "aborting."
  29. fi
  30. userID="ssh://${1}"
  31. fingerprint=$(fingerprint_server_key)
  32. # match to only ultimately trusted user IDs
  33. tmpuidMatch="u:$(echo $userID | gpg_escape)"
  34. # find the index of the requsted user ID
  35. # NOTE: this is based on circumstantial evidence that the order of
  36. # this output is the appropriate index
  37. if line=$(gpg_host --list-keys --with-colons --fixed-list-mode "0x${fingerprint}!" \
  38. | egrep '^(uid|uat):' | cut -f2,10 -d: | grep -n -x -F "$tmpuidMatch") ; then
  39. uidIndex=${line%%:*}
  40. else
  41. failure "No non-revoked user ID '$userID' is found."
  42. fi
  43. echo "The following host key user ID will be revoked:"
  44. echo " $userID"
  45. read -p "Are you sure you would like to revoke this user ID? (y/N) " OK; OK=${OK:=N}
  46. if [ ${OK/y/Y} != 'Y' ] ; then
  47. failure "User ID not revoked."
  48. fi
  49. message="Hostname removed by monkeysphere-server $DATE"
  50. # edit-key script command to revoke user ID
  51. revuidCommand=$(cat <<EOF
  52. $uidIndex
  53. revuid
  54. y
  55. 4
  56. $message
  57. y
  58. save
  59. EOF
  60. )
  61. # execute edit-key script
  62. if echo "$revuidCommand" | \
  63. gpg_host --quiet --command-fd 0 --edit-key "0x${fingerprint}!" ; then
  64. # update the trustdb for the authentication keyring
  65. gpg_authentication "--check-trustdb"
  66. show_server_key
  67. echo
  68. echo "NOTE: User ID revoked, but revocation not published."
  69. echo "Run '$PGRM publish-key' to publish the revocation."
  70. else
  71. failure "Problem revoking user ID."
  72. fi