summaryrefslogtreecommitdiff
path: root/src/share/m/gen_subkey
blob: 05004f66ee07a1e065b05d1d2765283552d87459 (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. (umask 077 && mkfifo "$fifoDir/pass")
  53. # FIXME: are we adequately cleaning up any trailing gpg process here?
  54. trap "rm -rf $fifoDir; kill %% || true" EXIT
  55. echo "$editCommands" | gpg_user --passphrase-fd 3 3< "$fifoDir/pass" --expert --command-fd 0 --edit-key "$keyID" &
  56. log debug "Prompting for passphrase"
  57. # FIXME: this needs to fail more gracefully if the passphrase is incorrect
  58. passphrase_prompt "Please enter your passphrase for $keyID: " "$fifoDir/pass"
  59. log info "Generating subkey. This may take a long time..."
  60. trap - EXIT
  61. rm -rf "$fifoDir"
  62. wait
  63. log verbose "done."
  64. }