Merge commit 'jrollins/master'
[monkeysphere.git] / src / monkeysphere
index 6d9e6c3a28469880895525d2a51e64667cb8de7c..303dc8d758d2262bb5faf3de3e39e78893154f9b 100755 (executable)
@@ -37,18 +37,17 @@ usage: $PGRM <subcommand> [options] [args]
 MonkeySphere client tool.
 
 subcommands:
 update-known_hosts (k) [HOST]...  update known_hosts file
 update-authorized_keys (a)        update authorized_keys file
 gen-subkey (g) KEYID              generate an 'a' capable subkey
-    -l|--length BITS                  key length in bits (2048)
-    -e|--expire EXPIRE                date to expire
 help (h,?)                        this help
update-known_hosts (k) [HOST]...    update known_hosts file
update-authorized_keys (a)          update authorized_keys file
gen-subkey (g) [KEYID]              generate an authentication subkey
+   --length (-l) BITS                  key length in bits (2048)
+   --expire (-e) EXPIRE                date to expire
help (h,?)                          this help
 
 EOF
 }
 
 # generate a subkey with the 'a' usage flags set
-# FIXME: this needs some tweaking to clean it up
 gen_subkey(){
     local keyLength
     local keyExpire
@@ -163,7 +162,18 @@ EOF
 )
 
     log "generating subkey..."
-    echo "$editCommands" | gpg --expert --command-fd 0 --edit-key "$keyID"
+    fifoDir=$(mktemp -d)
+    (umask 077 && mkfifo "$fifoDir/pass")
+    echo "$editCommands" | gpg --passphrase-fd 3 3< "$fifoDir/pass" --expert --command-fd 0 --edit-key "$keyID" &
+    
+    if [ "$DISPLAY" ] && which ssh-askpass >/dev/null; then
+       ssh-askpass "Please enter your passphrase for $keyID: " > "$fifoDir/pass"
+    else
+       read -s -p "Please enter your passphrase for $keyID: " PASS
+       echo "$PASS" > "$fifoDir/pass"
+    fi
+    rm -rf "$fifoDir"
+    wait
     log "done."
 }
 
@@ -278,7 +288,7 @@ case $COMMAND in
        gen_subkey "$@"
        ;;
 
-    'help'|'h'|'?')
+    '--help'|'help'|'-h'|'h'|'?')
         usage
         ;;