Merge commit 'dkg/master'
[monkeysphere.git] / src / monkeysphere
index 4a611c806e4ea8dd3d4405a643821b543d0aef44..57597e29f696bb2e60c5cbc822c218e06873e770 100755 (executable)
@@ -48,7 +48,6 @@ 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
@@ -101,6 +100,11 @@ gen_subkey(){
     else
        keyID="$1"
     fi
+    if [ -z "$keyID" ] ; then
+       failure "You have no secret key available.  You should create an OpenPGP
+key before joining the monkeysphere. You can do this with:
+   gpg --gen-key"
+    fi
 
     # get key output, and fail if not found
     gpgOut=$(gpg --quiet --fixed-list-mode --list-secret-keys --with-colons \
@@ -158,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."
 }
 
@@ -186,7 +201,16 @@ mkdir -p -m 0700 "$MONKEYSPHERE_HOME"
 # set empty config variables with ones from the environment, or from
 # config file, or with defaults
 GNUPGHOME=${MONKEYSPHERE_GNUPGHOME:=${GNUPGHOME:="${HOME}/.gnupg"}}
-KEYSERVER=${MONKEYSPHERE_KEYSERVER:=${KEYSERVER:="subkeys.pgp.net"}}
+KEYSERVER=${MONKEYSPHERE_KEYSERVER:="$KEYSERVER"}
+# if keyserver not specified in env or monkeysphere.conf,
+# look in gpg.conf
+if [ -z "$KEYSERVER" ] ; then
+    if [ -f "${GNUPGHOME}/gpg.conf" ] ; then
+       KEYSERVER=$(grep -e "^[[:space:]]*keyserver " "${GNUPGHOME}/gpg.conf" | tail -1 | awk '{ print $2 }')
+    fi
+fi
+# if it's still not specified, use the default
+KEYSERVER=${KEYSERVER:="subkeys.pgp.net"}
 CHECK_KEYSERVER=${MONKEYSPHERE_CHECK_KEYSERVER:=${CHECK_KEYSERVER:="true"}}
 KNOWN_HOSTS=${MONKEYSPHERE_KNOWN_HOSTS:=${KNOWN_HOSTS:="${HOME}/.ssh/known_hosts"}}
 HASH_KNOWN_HOSTS=${MONKEYSPHERE_HASH_KNOWN_HOSTS:=${HASH_KNOWN_HOSTS:="true"}}