summaryrefslogtreecommitdiff
path: root/src/share/mh/import_key
blob: cca40fa09e7424af87f82a7f638901b052bf98b8 (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 domain
  15. local userID
  16. hostName="$1"
  17. # use the default hostname if not specified
  18. if [ -z "$hostName" ] ; then
  19. hostName=$(hostname -f)
  20. # test that the domain is not obviously illegitimate
  21. domain=${foo##*.}
  22. case $domain in
  23. 'local'|'localdomain')
  24. failure "Host domain '$domain' is not legitimate. Aborting key import."
  25. ;;
  26. esac
  27. # test that there are at least two parts
  28. if (( $(echo "$hostName" | tr . ' ' | wc -w) < 2 )) ; then
  29. failure "Host name '$hostName' is not legitimate. Aborting key import."
  30. fi
  31. fi
  32. userID="ssh://${hostName}"
  33. # create host home
  34. mkdir -p "${MHDATADIR}"
  35. mkdir -p "${GNUPGHOME_HOST}"
  36. chmod 700 "${GNUPGHOME_HOST}"
  37. log verbose "importing ssh key..."
  38. # translate ssh key to a private key
  39. PEM2OPENPGP_USAGE_FLAGS=authenticate pem2openpgp "$userID" \
  40. | gpg_host --import
  41. # load the new host fpr into the fpr variable. this is so we can
  42. # create the gpg pub key file. we have to do this from the secret key
  43. # ring since we obviously don't have the gpg pub key file yet, since
  44. # that's what we're trying to produce (see below).
  45. load_fingerprint_secret
  46. # export to gpg public key to file
  47. update_gpg_pub_file
  48. log info "host key imported:"
  49. # show info about new key
  50. show_key
  51. }