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
23 failure "implement me!"
28 # check that key file specified
29 if [ -z "$sshKeyFile" ] ; then
30 failure "Must specify ssh key file to import, or specify '-' for stdin."
33 # check that the keyID is unique
34 keyID=$(check_gpg_sec_key_id "$@")
36 # check that an authentication subkey does not already exist
37 check_gpg_authentication_subkey "$keyID"
39 # setup the temp fifo dir for retrieving the key password
40 log debug "creating password fifo..."
41 fifoDir=$(msmktempdir)
42 trap "rm -rf $fifoDir" EXIT
43 (umask 077 && mkfifo "$fifoDir/pass")
45 # import ssh key to as authentication subkey
46 if [ "$sshKeyFile" = '-' ] ; then
47 log verbose "importing ssh key from stdin..."
48 PEM2OPENPGP_USAGE_FLAGS=authenticate pem2openpgp "$userID" \
49 | gpg_user --passphrase-fd 3 3< "$fifoDir/pass" --expert --command-fd 0 --import &
51 log verbose "importing ssh key from file '$sshKeyFile'..."
52 PEM2OPENPGP_USAGE_FLAGS=authenticate pem2openpgp "$userID" <"$sshKeyFile" \
53 | gpg_user --passphrase-fd 3 3< "$fifoDir/pass" --expert --command-fd 0 --import &
56 # get the password if needed
57 passphrase_prompt "Please enter your passphrase for $keyID: " "$fifoDir/pass"