summaryrefslogtreecommitdiff
path: root/src/share/mh/import_key
blob: 99511a86095ef9f806a6aaa8b58052867c0f047a (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. # check for presense of a key
  16. [ "$HOST_FINGERPRINT" ] && \
  17. failure "An OpenPGP host key already exists."
  18. hostName=${1:-$(hostname -f)}
  19. userID="ssh://${hostName}"
  20. # create host home
  21. mkdir -p "$GNUPGHOME_HOST"
  22. chmod 700 "$GNUPGHOME_HOST"
  23. log verbose "importing ssh key..."
  24. # translate ssh key to a private key
  25. PEM2OPENPGP_USAGE_FLAGS=authenticate pem2openpgp "$userID" | \
  26. gpg_host --import
  27. # find the key fingerprint of the newly converted key
  28. HOST_FINGERPRINT=$(get_host_fingerprint)
  29. export HOST_FINGERPRINT
  30. # export public key to file
  31. gpg_host_export_to_ssh_file
  32. # show info about new key
  33. show_key
  34. }