summaryrefslogtreecommitdiff
path: root/src/share/mh/import_key
blob: 2e73a8c6cc32878a11e413ca706f5290d91e55c7 (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 presense 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. (umask 077 && \
  28. pem2openpgp "$userID" | gpg_host --import)
  29. # find the key fingerprint of the newly converted key
  30. fingerprint=$(fingerprint_host_key)
  31. # export public key to file
  32. log debug "exporting openpgp public key..."
  33. gpg_host --export-options export-minimal --armor --export "0x${fingerprint}!" > "${MHDATADIR}/ssh_host_rsa_key.pub.gpg"
  34. log info "SSH host public key in OpenPGP form: ${MHDATADIR}/ssh_host_rsa_key.pub.gpg"
  35. # show info about new key
  36. show_key
  37. }