summaryrefslogtreecommitdiff
path: root/src/share/mh/revoke_key
blob: ad68d5f27a4804312ed0a7620146c3c257e558d2 (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. # FIXME: allow the end user to choose something other than
  44. # "key was compromised" (1) and to supply their own revocation
  45. # string.
  46. local revoke_commands="y
  47. 1
  48. Monkeysphere host key revocation (automated) $(date '+%F_%T%z')
  49. y
  50. "
  51. revcert=$(GNUPGHOME="$GNUPGHOME_HOST" gpg_host --command-fd 0 --armor --gen-revoke "0x${HOST_FINGERPRINT}!" <<<"$revoke_commands" ) \
  52. || failure "Failed to generate revocation certificate!"
  53. else
  54. # note: we're not using the gpg_host function because we actually
  55. # want to use gpg's UI in this case, so we want to omit --no-tty
  56. revcert=$(GNUPGHOME="$GNUPGHOME_HOST" gpg --no-greeting --quiet --armor --gen-revoke "0x${HOST_FINGERPRINT}!") \
  57. || failure "Failed to generate revocation certificate!"
  58. fi
  59. # if you run gpg --gen-revoke but cancel it or quit in the middle,
  60. # it returns success, but emits no revocation certificate:
  61. if ! [ "$revcert" ] ; then
  62. failure "Revocation canceled."
  63. fi
  64. ## ok, now we have the revocation certificate. Print it, and
  65. ## offer to publish if originally requested:
  66. printf "%s\n" "$revcert"
  67. if [ "${publish/y/Y}" = 'Y' ] ; then
  68. printf "\n" >&2
  69. read -p "Really publish this cert to $KEYSERVER ? (Y/n) " really
  70. if [ "${really/n/N}" = 'N' ] ; then
  71. printf "Not publishing.\n" >&2
  72. else
  73. local newhome=$(mkmstempdir)
  74. GNUPGHOME="$newhome" gpg --no-tty --quiet --import < "$HOST_KEY_FILE"
  75. GNUPGHOME="$newhome" gpg --no-tty --quiet --import <<< "$revcert"
  76. GNUPGHOME="$newhome" gpg --keyserver "$KEYSERVER" --send "0x${HOST_FINGERPRINT}!"
  77. rm -rf "$newhome"
  78. fi
  79. fi
  80. }