3 # Tests to ensure that the monkeysphere is working
5 # Author: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
6 # Date: 2008-09-13 13:40:15-0400
8 # these tests might be best run under fakeroot, particularly the
9 # "server-side" tests. Using fakeroot, they should be able to be run
10 # as a non-privileged user.
12 # NOTE: these tests have *not* themselves been tested yet
13 # (2008-09-13). Please exercise with caution!
15 # these tests assume a commonly-trusted "Admin's key", a fake key
16 # permanently stored in ./home/admin/.gnupg:
18 GNUPGHOME="$TESTDIR"/home/admin/.gnupg gpg "$@"
24 # FIXME: stop the sshd process
27 echo "### removing temp dir..."
30 # FIXME: how should we clear out the temporary $VARLIB?
32 # FIXME: clear out ssh client config file and known hosts.
38 ## set up some variables to ensure that we're operating strictly in
39 ## the tests, not system-wide:
44 TEMPDIR="$TESTDIR"/tmp
45 if [ -e "$TEMPDIR" ] ; then
46 echo "tempdir '$TEMPDIR' already exists."
51 # Use the local copy of executables first, instead of system ones.
52 # This should help us test without installing.
53 export PATH="$TESTDIR"/../src:"$TESTDIR"/../src/keytrans:"$PATH"
55 export MONKEYSPHERE_SYSDATADIR="$TEMPDIR"
56 export MONKEYSPHERE_SYSCONFIGDIR="$TEMPDIR"
57 export MONKEYSPHERE_SYSSHAREDIR="$TESTDIR"/../src
58 export MONKEYSPHERE_MONKEYSPHERE_USER="$USER"
59 export MONKEYSPHERE_CHECK_KEYSERVER=false
61 SSHD_CONFIG="$TEMPDIR"/sshd_config
62 export SOCKET="$TEMPDIR"/ssh-socket
66 # create the temp gnupghome directories
67 mkdir -p -m 750 "$MONKEYSPHERE_SYSDATADIR"/gnupg-host
68 mkdir -p -m 700 "$MONKEYSPHERE_SYSDATADIR"/gnupg-authentication
70 # add the quick-random option to the gpg host config
71 echo "quick-random" >> "$MONKEYSPHERE_SYSCONFIGDIR"/gnupg-host.conf
73 # create a new host key
74 echo "### generating server key..."
75 echo | monkeysphere-server gen-key --length 1024 --expire 0 testhost
77 HOSTKEYID=$( monkeysphere-server show-key | tail -n1 | cut -f3 -d\ )
79 # certify it with the "Admin's Key".
80 # (this would normally be done via keyservers)
81 echo "### certifying server key..."
82 monkeysphere-server gpg-authentication-cmd "--armor --export $HOSTKEYID" | gpgadmin --import
83 gpgadmin --sign-key "$HOSTKEYID"
85 # FIXME: how can we test publish-key without flooding junk into the
88 # indicate that the "Admin's" key is an identity certifier for the
91 echo "### adding admin as certifier..."
92 monkeysphere-server add-identity-certifier "$TESTDIR"/home/admin/.gnupg/pubkey.gpg
94 # write the sshd_config
95 cat <<EOF > "$SSHD_CONFIG"
96 HostKey ${MONKEYSPHERE_SYSDATADIR}/ssh_host_rsa_key
99 # launch test sshd with the new host key.
100 echo "### starting sshd..."
101 socat EXEC:'/usr/sbin/sshd -f '"$SSHD_CONFIG"' -i -d -d -d -D -e' "UNIX-LISTEN:${SOCKET}" &
106 # copy testuser home directory into temp dir
107 cp -r "$TESTDIR"/home/testuser "$TEMPDIR"/
109 # generate an auth subkey for the test user
110 echo "### generating key for testuser..."
111 MONKEYSPHERE_GNUPGHOME="$TEMPDIR"/testuser/.gnupg \
112 monkeysphere gen-subkey --expire 0
114 # connect to test sshd, using monkeysphere to verify the identity
116 echo "### connecting to sshd socket..."
117 PROXY_COMMAND="monkeysphere-ssh-proxycommand --no-connect %h && socat STDIO UNIX:${SOCKET}"
118 ssh -oProxyCommand="$PROXY_COMMAND" testhost
120 # create a new client side key, certify it with the "CA", use it to