summaryrefslogtreecommitdiff
path: root/src/share/mh/gen_key
blob: 873ed0298d24ae1e7a02e34359878eae73ee5967 (plain)
  1. # -*-shell-script-*-
  2. # This should be sourced by bash (though we welcome changes to make it POSIX sh compliant)
  3. # Monkeysphere host gen-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. gen_key() {
  13. local hostName=$(hostname -f)
  14. local keyType="RSA"
  15. local keyLength="2048"
  16. local keyUsage="auth"
  17. local keyExpire="0"
  18. local userID
  19. # get options
  20. while true ; do
  21. case "$1" in
  22. -l|--length)
  23. keyLength="$2"
  24. shift 2
  25. ;;
  26. *)
  27. if [ "$(echo "$1" | cut -c 1)" = '-' ] ; then
  28. failure "Unknown option '$1'.
  29. Type '$PGRM help' for usage."
  30. fi
  31. break
  32. ;;
  33. esac
  34. done
  35. hostName="$1"
  36. userID="ssh://${hostName}"
  37. # create host home
  38. mkdir -p "$GNUPGHOME_HOST"
  39. chmod 700 "$GNUPGHOME_HOST"
  40. log debug "generating host key..."
  41. gpg_host --batch --gen-key <<EOF
  42. Key-Type: $keyType
  43. Key-Length: $keyLength
  44. Key-Usage: $keyUsage
  45. Name-Real: $userID
  46. Expire-Date: $keyExpire
  47. %commit
  48. %echo done
  49. EOF
  50. # load the new host fpr into the fpr variable
  51. load_fingerprint_secret
  52. # export to ssh secret key file
  53. create_ssh_sec_file
  54. # export to ssh public key file
  55. create_ssh_pub_file
  56. # export to gpg public key to file
  57. create_gpg_pub_file
  58. # show info about new key
  59. show_key
  60. }