summaryrefslogtreecommitdiff
path: root/src/share/m/gen_subkey
blob: 9cc6028325a3621ec019b3d242bd53269e6b0573 (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. local keyType
  20. # get options
  21. while true ; do
  22. case "$1" in
  23. -l|--length)
  24. keyLength="$2"
  25. shift 2
  26. ;;
  27. *)
  28. if [ "$(echo "$1" | cut -c 1)" = '-' ] ; then
  29. failure "Unknown option '$1'.
  30. Type '$PGRM help' for usage."
  31. fi
  32. break
  33. ;;
  34. esac
  35. done
  36. # check that the keyID is unique
  37. keyID=$(check_gpg_sec_key_id "$@")
  38. # check that an authentication subkey does not already exist
  39. check_gpg_authentication_subkey "$keyID"
  40. # generate the list of commands that will be passed to edit-key
  41. # 7 for < 1.4.10
  42. # 8 for >= 1.4.10
  43. # 7 for < 2.0.13
  44. # 8 for >= 2.0.13
  45. keyType=8
  46. editCommands="addkey
  47. $keyType
  48. S
  49. E
  50. A
  51. Q
  52. $keyLength
  53. 0
  54. save"
  55. # setup the temp fifo dir for retrieving the key password
  56. log debug "creating password fifo..."
  57. fifoDir=$(msmktempdir)
  58. (umask 077 && mkfifo "$fifoDir/pass")
  59. # FIXME: are we adequately cleaning up any trailing gpg process here?
  60. trap "rm -rf $fifoDir; kill %% || true" EXIT
  61. echo "$editCommands" | gpg_user --passphrase-fd 3 3< "$fifoDir/pass" --expert --command-fd 0 --edit-key "$keyID" &
  62. log debug "Prompting for passphrase"
  63. # FIXME: this needs to fail more gracefully if the passphrase is incorrect
  64. passphrase_prompt "Please enter your passphrase for $keyID: " "$fifoDir/pass"
  65. log info "Generating subkey. This may take a long time..."
  66. trap - EXIT
  67. rm -rf "$fifoDir"
  68. wait
  69. log verbose "done."
  70. }