summaryrefslogtreecommitdiff
path: root/src/share/mh/import_key
blob: cab2cf55e27df17573840e54e4fcab5882fa0537 (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 keyFile
  14. local hostName
  15. local userID
  16. keyFile="$1"
  17. [ -f "$keyFile" ]
  18. hostName=${2:-$(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" <"$keyFile" \
  26. | gpg_host --import
  27. # load the new host fpr into the fpr variable
  28. load_fingerprint_secret
  29. # export the host public key to the monkeysphere ssh pub key file
  30. log debug "creating ssh public key file..."
  31. ssh-keygen -y -f "$keyFile" > "$HOST_KEY_PUB"
  32. log info "SSH host public key file: $HOST_KEY_PUB"
  33. # export to gpg public key to file
  34. create_gpg_pub_file
  35. # show info about new key
  36. show_key
  37. }