+perl -MDigest::SHA1 -e 1 2>/dev/null || { echo "You must have the perl module Digest::SHA1 installed to run this test.
+On debian-derived systems, you can set this up with:
+ apt-get install libdigest-sha1-perl" ; exit 1; }
+
+## FIXME: other checks?
+
+######################################################################
+### FUNCTIONS
+
+# gpg command for test admin user
+gpgadmin() {
+ chmod 0700 "$TEMPDIR"/admin
+ GNUPGHOME="$TEMPDIR"/admin/.gnupg gpg --no-tty "$@"
+}
+
+# test ssh connection
+# first argument is expected return code from ssh connection
+ssh_test() {
+ local RETURN=0
+
+ umask 0077
+
+ CODE=${1:-0}
+
+ # start the ssh daemon on the socket
+ echo "##### starting ssh server..."
+ socat EXEC:"/usr/sbin/sshd -f ${SSHD_CONFIG} -i -D -e" "UNIX-LISTEN:${SOCKET}" 2> "$TEMPDIR"/sshd.log &
+ SSHD_PID="$!"
+
+ # wait until the socket is created before continuing
+ while [ ! -S "$SOCKET" ] ; do
+ sleep 1
+ done
+
+ # make a client connection to the socket
+ echo "##### starting ssh client..."
+ ssh-agent bash -c \
+ "monkeysphere subkey-to-ssh-agent && ssh -F $TEMPDIR/testuser/.ssh/config testhost true" \
+ || RETURN="$?"
+
+ # kill the sshd process if it's still running
+ kill "$SSHD_PID"
+ SSHD_PID=
+
+ echo "##### return $RETURN"
+ if [ "$RETURN" = "$CODE" ] ; then
+ echo "##### ssh connection test returned as desired"
+ return 0
+ else
+ echo "##### ssh connection test failed. expected return code $CODE"
+ return 1
+ fi