diff options
author | Jameson Graef Rollins <jrollins@finestructure.net> | 2009-02-19 15:19:02 -0500 |
---|---|---|
committer | Jameson Graef Rollins <jrollins@finestructure.net> | 2009-02-19 15:19:02 -0500 |
commit | bd64869a3b68ff8a020c381371a8ab1e24a5a0e4 (patch) | |
tree | b790ed7dc580224304386ac1d2c98d07248eaf3c /src/share/m/import_subkey | |
parent | c073811aa573d0e3486c39ed9514c46e0a7a077f (diff) |
The monkeysphere {import,gen}_subkey functions were not up-to-date.
did a lot of work to bring them up-to-date, and better handle argument
checking. also updated man page, changelog, and tests/basic.
Diffstat (limited to 'src/share/m/import_subkey')
-rw-r--r-- | src/share/m/import_subkey | 62 |
1 files changed, 34 insertions, 28 deletions
diff --git a/src/share/m/import_subkey b/src/share/m/import_subkey index 8b04456..d71c258 100644 --- a/src/share/m/import_subkey +++ b/src/share/m/import_subkey @@ -14,40 +14,46 @@ # import an existing ssh key as a gpg subkey import_subkey() { - local keyFile="~/.ssh/id_rsa" - local keyExpire + local sshKeyFile local keyID - local gpgOut - local userID - - # get options - while true ; do - case "$1" in - -f|--keyfile) - keyFile="$2" - shift 2 - ;; - -e|--expire) - keyExpire="$2" - shift 2 - ;; - *) - if [ "$(echo "$1" | cut -c 1)" = '-' ] ; then - failure "Unknown option '$1'. -Type '$PGRM help' for usage." - fi - break - ;; - esac - done - - log verbose "importing ssh key..." + local gpgSecOut + local fifoDir + + sshKeyFile="$1" + shift + + # check that key file specified + if [ -z "$sshKeyFile" ] ; then + failure "Must specify ssh key file to import, or specify '-' for stdin." + fi + + # check that the keyID is unique + keyID=$(check_gpg_sec_key_id "$@") + + # check that an authentication subkey does not already exist + check_gpg_authentication_subkey "$keyID" + + # setup the temp fifo dir for retrieving the key password + log debug "creating password fifo..." fifoDir=$(msmktempdir) + trap "rm -rf $fifoDir" EXIT (umask 077 && mkfifo "$fifoDir/pass") - ssh2openpgp | gpg --passphrase-fd 3 3< "$fifoDir/pass" --expert --command-fd 0 --import & + # import ssh key to as authentication subkey + if [ "$sshKeyFile" = '-' ] ; then + log verbose "importing ssh key from stdin..." + ssh2openpgp \ + | gpg --passphrase-fd 3 3< "$fifoDir/pass" --expert --command-fd 0 --import & + else + log verbose "importing ssh key from file '$sshKeyFile'..." + ssh2openpgp <"$sshKeyFile" \ + | gpg --passphrase-fd 3 3< "$fifoDir/pass" --expert --command-fd 0 --import & + fi + + # get the password if needed passphrase_prompt "Please enter your passphrase for $keyID: " "$fifoDir/pass" + trap - EXIT rm -rf "$fifoDir" wait log verbose "done." |