summaryrefslogtreecommitdiff
path: root/src/share/mh/publish_key
blob: 52c8b8685384d6d826832673603c629799c81338 (plain)
  1. # -*-shell-script-*-
  2. # This should be sourced by bash (though we welcome changes to make it POSIX sh compliant)
  3. # Monkeysphere host publish-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-2010, and are all released under the GPL,
  11. # version 3 or later.
  12. # publish keys to keyserver
  13. publish_key() {
  14. local keyID="$1"
  15. local GNUPGHOME
  16. if [ "$PROMPT" != "false" ] ; then
  17. printf "Really publish key '$keyID' to $KEYSERVER? (Y/n) " >&2
  18. read OK; OK=${OK:=Y}
  19. if [ "${OK/y/Y}" != 'Y' ] ; then
  20. log error "key not published."
  21. return
  22. fi
  23. else
  24. log debug "publishing key '$keyID' without prompting."
  25. fi
  26. # create a temporary gnupg directory from which to publish the key
  27. export GNUPGHOME=$(msmktempdir)
  28. chmod 0700 "$GNUPGHOME"
  29. chown "$MONKEYSPHERE_USER":"$MONKEYSPHERE_GROUP" "$GNUPGHOME"
  30. # trap to remove tmp dir if break
  31. trap "rm -rf $GNUPGHOME" EXIT
  32. # import the key into the tmp dir
  33. su_monkeysphere_user \
  34. "gpg --quiet --import" <"$HOST_KEY_FILE"
  35. KEYSERVER_OPTIONS=""
  36. for anchorfile in "${SYSCONFIGDIR}/monkeysphere-host-x509-anchors.crt" "${SYSCONFIGDIR}/monkeysphere-x509-anchors.crt"; do
  37. if [ -z "$KEYSERVER_OPTIONS" ] && [ -r "$anchorfile" ] ; then
  38. KEYSERVER_OPTIONS="--keyserver-options 'ca-cert-file=$anchorfile'"
  39. fi
  40. done
  41. # publish key
  42. su_monkeysphere_user \
  43. "gpg --keyserver $KEYSERVER $KEYSERVER_OPTIONS --send-keys '0x${keyID}!'"
  44. # remove the tmp file
  45. trap - EXIT
  46. rm -rf "$GNUPGHOME"
  47. }