summaryrefslogtreecommitdiff
path: root/src/share/mh/import_key
blob: ada291474aefe6a61268923d488eba24c89aba46 (plain)
  1. # -*-shell-script-*-
  2. # This should be sourced by bash (though we welcome changes to make it POSIX sh compliant)
  3. # Monkeysphere host import-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. import_key() {
  13. local keyFile="$1"
  14. local serviceName="$2"
  15. # check that key file specified
  16. if [ -z "$keyFile" ] ; then
  17. failure "Must specify PEM-encoded key file to import, or specify '-' for stdin."
  18. fi
  19. # fail if hostname not specified
  20. if [ -z "$serviceName" ] ; then
  21. failure "You must specify a service name for use in the OpenPGP certificate user ID."
  22. fi
  23. # check that the service name is well formatted
  24. check_service_name "$serviceName"
  25. # create host home
  26. mkdir -p "${MHDATADIR}"
  27. mkdir -p "${GNUPGHOME_HOST}"
  28. chmod 700 "${GNUPGHOME_HOST}"
  29. # import pem-encoded key to an OpenPGP private key
  30. if [ "$keyFile" = '-' ] ; then
  31. log verbose "importing key from stdin..."
  32. PEM2OPENPGP_USAGE_FLAGS=authenticate pem2openpgp "$serviceName" \
  33. | gpg_host --import
  34. else
  35. log verbose "importing key from file '$keyFile'..."
  36. PEM2OPENPGP_USAGE_FLAGS=authenticate pem2openpgp "$serviceName" \
  37. <"$keyFile" \
  38. | gpg_host --import
  39. fi
  40. # export to gpg public key to file
  41. update_gpg_pub_file
  42. log info "host key imported:"
  43. # show info about new key
  44. show_key "$serviceName"
  45. }