2 # This should be sourced by bash (though we welcome changes to make it POSIX sh compliant)
4 # Monkeysphere gen-subkey subcommand
6 # The monkeysphere scripts are written by:
7 # Jameson Rollins <jrollins@finestructure.net>
8 # Jamie McClelland <jm@mayfirst.org>
9 # Daniel Kahn Gillmor <dkg@fifthhorseman.net>
11 # They are Copyright 2008-2009, and are all released under the GPL,
14 # generate a subkey with the 'a' usage flags set
32 if [ "$(echo "$1" | cut -c 1)" = '-' ] ; then
33 failure "Unknown option '$1'.
34 Type '$PGRM help' for usage."
41 # check that the keyID is unique
42 keyID=$(check_gpg_sec_key_id "$@")
44 # check that an authentication subkey does not already exist
45 check_gpg_authentication_subkey "$keyID"
47 # determine which keyType to use from gpg version
49 case $(gpg --version | head -1 | awk '{ print $3 }' | cut -d. -f1) in
51 if is_gpg_version_greater_equal 1.4.10 ; then
56 if is_gpg_version_greater_equal 2.0.13 ; then
65 # generate the list of commands that will be passed to edit-key
76 # setup the temp fifo dir for retrieving the key password
77 log debug "creating password fifo..."
78 fifoDir=$(msmktempdir)
79 (umask 077 && mkfifo "$fifoDir/pass")
81 # FIXME: are we adequately cleaning up any trailing gpg process here?
82 trap "rm -rf $fifoDir; kill %% || true" EXIT
83 echo "$editCommands" | gpg_user --passphrase-fd 3 3< "$fifoDir/pass" --expert --command-fd 0 --edit-key "$keyID" &
85 log debug "Prompting for passphrase"
86 # FIXME: this needs to fail more gracefully if the passphrase is incorrect
87 passphrase_prompt "Please enter your passphrase for $keyID: " "$fifoDir/pass"
88 log info "Generating subkey. This may take a long time..."