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!
18 # gpg command for test admin user
20 GNUPGHOME="$TEMPDIR"/admin/.gnupg gpg "$@"
27 read -p "press enter to cleanup and remove tmp:"
29 if ( jobs %1 >/dev/null 2>/dev/null ) ; then
30 echo "### stopping still-running sshd..."
34 echo "### removing temp dir..."
43 ## set up some variables to ensure that we're operating strictly in
44 ## the tests, not system-wide:
49 TEMPDIR="$TESTDIR"/tmp
50 if [ -e "$TEMPDIR" ] ; then
51 echo "tempdir '$TEMPDIR' already exists."
56 # Use the local copy of executables first, instead of system ones.
57 # This should help us test without installing.
58 export PATH="$TESTDIR"/../src:"$TESTDIR"/../src/keytrans:"$PATH"
60 export MONKEYSPHERE_SYSDATADIR="$TEMPDIR"
61 export MONKEYSPHERE_SYSCONFIGDIR="$TEMPDIR"
62 export MONKEYSPHERE_SYSSHAREDIR="$TESTDIR"/../src
63 export MONKEYSPHERE_MONKEYSPHERE_USER="$USER"
64 export MONKEYSPHERE_CHECK_KEYSERVER=false
66 SSHD_CONFIG="$TEMPDIR"/sshd_config
67 export SOCKET="$TEMPDIR"/ssh-socket
69 # copy in admin and testuser home to tmp
70 echo "### copying admin and testuser homes..."
71 cp -a "$TESTDIR"/home/admin "$TEMPDIR"/
72 cp -a "$TESTDIR"/home/testuser "$TEMPDIR"/
74 cat <<EOF > "$TEMPDIR"/testuser/.ssh/config
75 UserKnownHostsFile $TEMPDIR/testuser/.ssh/known_hosts
78 cat <<EOF > "$TEMPDIR"/testuser/.monkeysphere/monkeysphere.conf
79 KNOWN_HOSTS=$TEMPDIR/testuser/.ssh/known_hosts
85 # setup monkeysphere temp gnupghome directories
86 mkdir -p -m 750 "$MONKEYSPHERE_SYSDATADIR"/gnupg-host
87 mkdir -p -m 700 "$MONKEYSPHERE_SYSDATADIR"/gnupg-authentication
88 cat <<EOF > "$MONKEYSPHERE_SYSDATADIR"/gnupg-authentication/gpg.conf
89 primary-keyring ${MONKEYSPHERE_SYSDATADIR}/gnupg-authentication/pubring.gpg
90 keyring ${MONKEYSPHERE_SYSDATADIR}/gnupg-host/pubring.gpg
93 # create a new host key
94 echo "### generating server key..."
95 # add gpg.conf with quick-random
96 echo "quick-random" >> "$MONKEYSPHERE_SYSCONFIGDIR"/gnupg-host/gpg.conf
97 echo | monkeysphere-server gen-key --length 1024 --expire 0 testhost
99 rm "$MONKEYSPHERE_SYSCONFIGDIR"/gnupg-host/gpg.conf
101 HOSTKEYID=$( monkeysphere-server show-key | tail -n1 | cut -f3 -d\ )
103 # certify it with the "Admin's Key".
104 # (this would normally be done via keyservers)
105 echo "### certifying server key..."
106 monkeysphere-server gpg-authentication-cmd "--armor --export $HOSTKEYID" | gpgadmin --import
107 echo y | gpgadmin --command-fd 0 --sign-key "$HOSTKEYID"
109 # FIXME: how can we test publish-key without flooding junk into the
112 # add admin as identity certifier for testhost
113 echo "### adding admin as certifier..."
114 echo y | monkeysphere-server add-identity-certifier "$TEMPDIR"/admin/.gnupg/pubkey.gpg
116 # initialize base sshd_config
117 cp etc/ssh/sshd_config "$SSHD_CONFIG"
118 # write the sshd_config
119 cat <<EOF >> "$SSHD_CONFIG"
120 HostKey ${MONKEYSPHERE_SYSDATADIR}/ssh_host_rsa_key
121 AuthorizedKeysFile ${MONKEYSPHERE_SYSDATADIR}/authorized_keys/%u
124 # launch test sshd with the new host key.
125 echo "### starting sshd..."
126 socat EXEC:"/usr/sbin/sshd -f ${SSHD_CONFIG} -i -d -d -d -D -e" "UNIX-LISTEN:${SOCKET}" 2> "$TEMPDIR"/sshd.log &
130 # generate an auth subkey for the test user
131 echo "### generating key for testuser..."
132 MONKEYSPHERE_GNUPGHOME="$TEMPDIR"/testuser/.gnupg \
134 monkeysphere gen-subkey --expire 0
136 # add server key to testuser keychain
137 echo "### export server key to testuser..."
138 gpgadmin --armor --export "$HOSTKEYID" | \
139 GNUPGHOME="$TEMPDIR"/testuser/.gnupg gpg --import
141 # connect to test sshd, using monkeysphere-ssh-proxycommand to verify
142 # the identity before connection. This should work in both directions!
143 echo "### testuser connecting to sshd socket..."
144 PROXY_COMMAND="monkeysphere-ssh-proxycommand --no-connect %h && socat STDIO UNIX:${SOCKET}"
145 GNUPGHOME="$TEMPDIR"/testuser/.gnupg \
146 MONKEYSPHERE_HOME="$TEMPDIR"/testuser/.monkeysphere \
147 ssh -F "$TEMPDIR"/testuser/.ssh/config -v -v -v -oProxyCommand="$PROXY_COMMAND" testhost