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