summaryrefslogtreecommitdiff
path: root/src/share/m/gen_subkey
blob: a0fa3ce77228b5f6b7efc876ccf3a22098a2d38c (plain)
  1. # -*-shell-script-*-
  2. # This should be sourced by bash (though we welcome changes to make it POSIX sh compliant)
  3. # Monkeysphere gen-subkey 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. # generate a subkey with the 'a' usage flags set
  13. gen_subkey(){
  14. local keyLength
  15. local gpgSecOut
  16. local keyID
  17. local editCommands
  18. local fifoDir
  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. # check that the keyID is unique
  36. keyID=$(check_gpg_sec_key_id "$@")
  37. # check that an authentication subkey does not already exist
  38. check_gpg_authentication_subkey "$keyID"
  39. # generate the list of commands that will be passed to edit-key
  40. editCommands="addkey
  41. 7
  42. S
  43. E
  44. A
  45. Q
  46. $keyLength
  47. 0
  48. save"
  49. # setup the temp fifo dir for retrieving the key password
  50. log debug "creating password fifo..."
  51. fifoDir=$(msmktempdir)
  52. trap "rm -rf $fifoDir" EXIT
  53. (umask 077 && mkfifo "$fifoDir/pass")
  54. log verbose "generating subkey..."
  55. echo "$editCommands" | gpg_user --passphrase-fd 3 3< "$fifoDir/pass" --expert --command-fd 0 --edit-key "$keyID" &
  56. # FIXME: this needs to fail more gracefully if the passphrase is incorrect
  57. passphrase_prompt "Please enter your passphrase for $keyID: " "$fifoDir/pass"
  58. trap - EXIT
  59. rm -rf "$fifoDir"
  60. wait
  61. log verbose "done."
  62. }