2 # This should be sourced by bash (though we welcome changes to make it POSIX sh compliant)
4 # Monkeysphere import-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 # import an existing ssh key as a gpg subkey
25 # check that key file specified
26 if [ -z "$sshKeyFile" ] ; then
27 failure "Must specify ssh key file to import, or specify '-' for stdin."
30 # check that the keyID is unique
31 keyID=$(check_gpg_sec_key_id "$@")
33 # check that an authentication subkey does not already exist
34 check_gpg_authentication_subkey "$keyID"
36 # setup the temp fifo dir for retrieving the key password
37 log debug "creating password fifo..."
38 fifoDir=$(msmktempdir)
39 trap "rm -rf $fifoDir" EXIT
40 (umask 077 && mkfifo "$fifoDir/pass")
42 # import ssh key to as authentication subkey
43 if [ "$sshKeyFile" = '-' ] ; then
44 log verbose "importing ssh key from stdin..."
46 | gpg --passphrase-fd 3 3< "$fifoDir/pass" --expert --command-fd 0 --import &
48 log verbose "importing ssh key from file '$sshKeyFile'..."
49 ssh2openpgp <"$sshKeyFile" \
50 | gpg --passphrase-fd 3 3< "$fifoDir/pass" --expert --command-fd 0 --import &
53 # get the password if needed
54 passphrase_prompt "Please enter your passphrase for $keyID: " "$fifoDir/pass"