summaryrefslogtreecommitdiff
path: root/src/share/mh/import_key
blob: 6a897b6122ff9caed1c2c7fe300842e3311b9101 (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 hostName
  14. local userID
  15. local fingerprint
  16. # check for presence of secret key
  17. # FIXME: is this the proper test to be doing here?
  18. fingerprint_host_key >/dev/null \
  19. && failure "An OpenPGP host key already exists."
  20. hostName=${1:-$(hostname -f)}
  21. userID="ssh://${hostName}"
  22. # create host home
  23. mkdir -p "$GNUPGHOME_HOST"
  24. chmod 700 "$GNUPGHOME_HOST"
  25. log verbose "importing ssh key..."
  26. # translate ssh key to a private key
  27. PEM2OPENPGP_USAGE_FLAGS=authenticate pem2openpgp "$userID" | \
  28. gpg_host --import
  29. # find the key fingerprint of the newly converted key
  30. HOST_FINGERPRINT=$(fingerprint_host_key)
  31. export HOST_FINGERPRINT
  32. # export public key to file
  33. gpg_host_export_to_ssh_file
  34. # show info about new key
  35. show_key
  36. }