summaryrefslogtreecommitdiff
path: root/src/share/mh/import_key
blob: e5982ca62a2f9bd0f418ae82bacdc918fe777575 (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 "${MHDATADIR}"
  22. mkdir -p "${MHTMPDIR}"
  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" <"$keyFile" \
  28. | gpg_host --import
  29. # load the new host fpr into the fpr variable
  30. load_fingerprint_secret
  31. # export the host public key to the monkeysphere ssh pub key file
  32. log debug "creating ssh public key file..."
  33. ssh-keygen -y -f "$keyFile" > "$HOST_KEY_PUB"
  34. log info "SSH host public key file: $HOST_KEY_PUB"
  35. # export to gpg public key to file
  36. create_gpg_pub_file
  37. # show info about new key
  38. show_key
  39. }