summaryrefslogtreecommitdiff
path: root/src/share/mh/import_key
blob: f7c69c3eaeb007becc0f59fc5d4fa74ec6f5c3e6 (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-2009 and are all released under the GPL,
  11. # version 3 or later.
  12. import_key() {
  13. local sshKeyFile
  14. local hostName
  15. local domain
  16. local userID
  17. sshKeyFile="$1"
  18. hostName="$2"
  19. # check that key file specified
  20. if [ -z "$sshKeyFile" ] ; then
  21. failure "Must specify ssh key file to import, or specify '-' for stdin."
  22. fi
  23. # fail if hostname not specified
  24. if [ -z "$hostName" ] ; then
  25. failure "You must specify a fully-qualified domain name for use in the host certificate user ID."
  26. fi
  27. userID="ssh://${hostName}"
  28. # create host home
  29. mkdir -p "${MHDATADIR}"
  30. mkdir -p "${GNUPGHOME_HOST}"
  31. chmod 700 "${GNUPGHOME_HOST}"
  32. # import ssh key to a private key
  33. if [ "$sshKeyFile" = '-' ] ; then
  34. log verbose "importing ssh key from stdin..."
  35. PEM2OPENPGP_USAGE_FLAGS=authenticate pem2openpgp "$userID" \
  36. | gpg_host --import
  37. else
  38. log verbose "importing ssh key from file '$sshKeyFile'..."
  39. PEM2OPENPGP_USAGE_FLAGS=authenticate pem2openpgp "$userID" \
  40. <"$sshKeyFile" \
  41. | gpg_host --import
  42. fi
  43. # load the new host fpr into the fpr variable. this is so we can
  44. # create the gpg pub key file. we have to do this from the secret key
  45. # ring since we obviously don't have the gpg pub key file yet, since
  46. # that's what we're trying to produce (see below).
  47. load_fingerprint_secret
  48. # export to gpg public key to file
  49. update_gpg_pub_file
  50. log info "host key imported:"
  51. # show info about new key
  52. show_key
  53. }