summaryrefslogtreecommitdiff
path: root/src/share/mh/revoke_key
blob: 271432b279f4dadbb8c9b20fea741265d757ab3b (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-key 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 host key
  13. revoke_key() {
  14. # Coming in here, we expect $HOST_FINGERPRINT to be set, and we
  15. # believe that there is in fact a key.
  16. if [ "$PROMPT" = "false" ] ; then
  17. publish=N
  18. else
  19. cat <<EOF >&2
  20. This will generate a revocation certificate for your host key
  21. (fingerprint: $HOST_FINGERPRINT) and
  22. dump the certificate to standard output.
  23. It can also directly publish the new revocation certificate
  24. to the public keyservers via $KEYSERVER if you want it to.
  25. Publishing this certificate will IMMEDIATELY and PERMANENTLY revoke
  26. your host key!
  27. EOF
  28. read -p "Publish the certificate after generation? (y/n/Q) " publish
  29. if ! [ "${publish/y/Y}" = 'Y' -o "${publish/n/N}" = 'N' ] ; then
  30. failure "aborting at user request"
  31. fi
  32. fi
  33. # our current implementation is very simple: we just want to
  34. # generate the revocation certificate on stdout. This provides
  35. # for the two most likely (but hopefully not common) scenarios:
  36. # an admin wants a revocation certificate for the host which they
  37. # can store securely offline. In this case, the admin can
  38. # redirect stdout to a file, or can simply copy/paste or
  39. # transcribe from the terminal.
  40. # Alternately, an admin might want to publish the revocation
  41. # certificate immediately, which we can help them do as well.
  42. if [ "$PROMPT" = 'false' ] ; then
  43. local revoke_commands="y
  44. 1
  45. Monkeysphere host key revocation (no prompting) $(date '+%F_%T')
  46. y
  47. "
  48. revcert=$(GNUPGHOME="$GNUPGHOME_HOST" gpg_host --command-fd 0 --armor --gen-revoke "0x${HOST_FINGERPRINT}!" <<<"$revoke_commands" ) \
  49. || failure "Failed to generate revocation certificate!"
  50. else
  51. # note: we're not using the gpg_host function because we actually
  52. # want to use gpg's UI in this case, so we want to omit --no-tty
  53. revcert=$(GNUPGHOME="$GNUPGHOME_HOST" gpg --no-greeting --quiet --armor --gen-revoke "0x${HOST_FINGERPRINT}!") \
  54. || failure "Failed to generate revocation certificate!"
  55. fi
  56. # if you run gpg --gen-revoke but cancel it or quit in the middle,
  57. # it returns success, but emits no revocation certificate:
  58. if ! [ "$revcert" ] ; then
  59. failure "Revocation canceled."
  60. fi
  61. ## ok, now we have the revocation certificate. Print it, and
  62. ## offer to publish if originally requested:
  63. printf "%s\n" "$revcert"
  64. if [ "${publish/y/Y}" = 'Y' ] ; then
  65. printf "\n" >&2
  66. read -p "Really publish this cert to $KEYSERVER ? (Y/n) " really
  67. if [ "${really/n/N}" = 'N' ] ; then
  68. printf "Not publishing.\n" >&2
  69. else
  70. local newhome=$(mkmstempdir)
  71. GNUPGHOME="$newhome" gpg --no-tty --quiet --import < "$HOST_KEY_FILE"
  72. GNUPGHOME="$newhome" gpg --no-tty --quiet --import <<< "$revcert"
  73. GNUPGHOME="$newhome" gpg --keyserver "$KEYSERVER" --send "0x${HOST_FINGERPRINT}!"
  74. rm -rf "$newhome"
  75. fi
  76. fi
  77. }