3 # Tests to ensure that the monkeysphere is working
6 # Daniel Kahn Gillmor <dkg@fifthhorseman.net>
7 # Jameson Rollins <jrollins@fifthhorseman.net>
9 # License: GPL v3 or later
11 # these tests should all be able to
12 # as a non-privileged user.
14 # all subcommands in this script should complete without failure:
17 # gpg command for test admin user
19 GNUPGHOME="$TEMPDIR"/admin/.gnupg gpg "$@"
23 # first argument is expected return code from ssh connection
29 # start the ssh daemon on the socket
30 echo "##### starting ssh server..."
31 socat EXEC:"/usr/sbin/sshd -f ${SSHD_CONFIG} -i -D -e" "UNIX-LISTEN:${SOCKET}" 2> "$TEMPDIR"/sshd.log &
34 # wait until the socket is created before continuing
35 while [ ! -S "$SOCKET" ] ; do
41 # make a client connection to the socket
42 echo "##### starting ssh client..."
44 "monkeysphere subkey-to-ssh-agent && ssh -F $TEMPDIR/testuser/.ssh/config testhost true"
47 # kill the sshd process if it's still running
52 echo "##### return $RETURN"
53 if [ "$RETURN" = "$CODE" ] ; then
54 echo "##### ssh connection test returned as desired"
57 echo "##### ssh connection test failed. expected return code $CODE"
63 # FIXME: can we be more verbose here?
65 read -p "press enter to cleanup and remove tmp:"
71 if (gpg --quick-random --version >/dev/null 2>&1) ; then
73 elif (gpg --debug-quick-random --version >/dev/null 2>&1) ; then
74 echo debug-quick-random
79 echo "### removing temp dir..."
86 trap failed_cleanup EXIT
90 ## set up some variables to ensure that we're operating strictly in
91 ## the tests, not system-wide:
96 TEMPDIR="$TESTDIR"/tmp
97 if [ -e "$TEMPDIR" ] ; then
98 echo "tempdir '$TEMPDIR' already exists."
103 # Use the local copy of executables first, instead of system ones.
104 # This should help us test without installing.
105 export PATH="$TESTDIR"/../src:"$TESTDIR"/../src/keytrans:"$PATH"
107 export MONKEYSPHERE_SYSDATADIR="$TEMPDIR"
108 export MONKEYSPHERE_SYSCONFIGDIR="$TEMPDIR"
109 export MONKEYSPHERE_SYSSHAREDIR="$TESTDIR"/../src
110 export MONKEYSPHERE_MONKEYSPHERE_USER=$(whoami)
111 export MONKEYSPHERE_CHECK_KEYSERVER=false
112 export MONKEYSPHERE_LOG_LEVEL=DEBUG
114 export SSHD_CONFIG="$TEMPDIR"/sshd_config
115 export SOCKET="$TEMPDIR"/ssh-socket
118 # Make sure $DISPLAY is set to convince ssh and monkeysphere to fall
119 # back on $SSH_ASKPASS. Make sure it's not set to the current actual
120 # $DISPLAY (if one exists) because this test suite should not be doing
121 # *anything* with any running X11 session.
122 export DISPLAY=monkeys
124 ### CONFIGURE ENVIRONMENTS
126 # copy in admin and testuser home to tmp
127 echo "### copying admin and testuser homes..."
128 cp -a "$TESTDIR"/home/admin "$TEMPDIR"/
129 cp -a "$TESTDIR"/home/testuser "$TEMPDIR"/
131 # set up environment for testuser
132 TESTHOME="$TEMPDIR"/testuser
133 export GNUPGHOME="$TESTHOME"/.gnupg
134 export SSH_ASKPASS="$TESTHOME"/.ssh/askpass
135 export MONKEYSPHERE_HOME="$TESTHOME"/.monkeysphere
136 cat <<EOF >> "$TESTHOME"/.ssh/config
137 UserKnownHostsFile $TESTHOME/.ssh/known_hosts
138 IdentityFile $TESTHOME/.ssh/no-such-identity
139 ProxyCommand $TESTHOME/.ssh/proxy-command %h %p $SOCKET
141 cat <<EOF >> "$MONKEYSPHERE_HOME"/monkeysphere.conf
142 KNOWN_HOSTS=$TESTHOME/.ssh/known_hosts
144 get_gpg_prng_arg >> "$GNUPGHOME"/gpg.conf
147 echo "### configuring sshd..."
148 cp etc/ssh/sshd_config "$SSHD_CONFIG"
149 # write the sshd_config
150 cat <<EOF >> "$SSHD_CONFIG"
151 HostKey ${MONKEYSPHERE_SYSDATADIR}/ssh_host_rsa_key
152 AuthorizedKeysFile ${MONKEYSPHERE_SYSDATADIR}/authorized_keys/%u
155 # set up monkeysphere-server
156 echo "### configuring monkeysphere..."
157 mkdir -p -m 750 "$MONKEYSPHERE_SYSDATADIR"/gnupg-host
158 mkdir -p -m 700 "$MONKEYSPHERE_SYSDATADIR"/gnupg-authentication
159 mkdir -p -m 700 "$MONKEYSPHERE_SYSDATADIR"/authorized_keys
160 mkdir -p -m 700 "$MONKEYSPHERE_SYSDATADIR"/tmp
161 cp etc/monkeysphere/monkeysphere-server.conf "$TEMPDIR"/monkeysphere-server.conf
162 cat <<EOF >> "$TEMPDIR"/monkeysphere-server.conf
163 AUTHORIZED_USER_IDS="$MONKEYSPHERE_HOME/authorized_user_ids"
165 cat <<EOF > "$MONKEYSPHERE_SYSDATADIR"/gnupg-authentication/gpg.conf
166 primary-keyring ${MONKEYSPHERE_SYSDATADIR}/gnupg-authentication/pubring.gpg
167 keyring ${MONKEYSPHERE_SYSDATADIR}/gnupg-host/pubring.gpg
173 # create a new host key
174 echo "### generating server key..."
175 # add gpg.conf with quick-random
176 get_gpg_prng_arg >> "$MONKEYSPHERE_SYSCONFIGDIR"/gnupg-host/gpg.conf
177 echo | monkeysphere-server gen-key --length 1024 --expire 0 testhost
178 # remove the gpg.conf
179 rm "$MONKEYSPHERE_SYSCONFIGDIR"/gnupg-host/gpg.conf
181 HOSTKEYID=$( monkeysphere-server show-key | tail -n1 | cut -f3 -d\ )
183 # certify it with the "Admin's Key".
184 # (this would normally be done via keyservers)
185 echo "### certifying server key..."
186 monkeysphere-server gpg-authentication-cmd "--armor --export $HOSTKEYID" | gpgadmin --import
187 echo y | gpgadmin --command-fd 0 --sign-key "$HOSTKEYID"
189 # FIXME: how can we test publish-key without flooding junk into the
192 # add admin as identity certifier for testhost
193 echo "### adding admin as certifier..."
194 echo y | monkeysphere-server add-identity-certifier "$TEMPDIR"/admin/.gnupg/pubkey.gpg
199 # generate an auth subkey for the test user that expires in 2 days
200 echo "### generating key for testuser..."
201 monkeysphere gen-subkey --expire 2
203 # add server key to testuser keychain
204 echo "### export server key to testuser..."
205 gpgadmin --armor --export "$HOSTKEYID" | gpg --import
207 # teach the "server" about the testuser's key
208 echo "### export testuser key to server..."
209 gpg --export testuser | monkeysphere-server gpg-authentication-cmd --import
210 echo "### update server authorized_keys file for this testuser..."
211 monkeysphere-server update-users $(whoami)
213 # connect to test sshd, using monkeysphere-ssh-proxycommand to verify
214 # the identity before connection. This should work in both directions!
215 echo "### ssh connection test for success..."
218 # remove the testuser's authorized_user_ids file, update, and make
219 # sure that the ssh authentication FAILS
220 echo "### removing testuser authorized_user_ids and updating..."
221 mv "$TESTHOME"/.monkeysphere/authorized_user_ids{,.bak}
222 monkeysphere-server update-users $(whoami)
223 echo "### ssh connection test for server authentication denial..."
225 mv "$TESTHOME"/.monkeysphere/authorized_user_ids{.bak,}
227 # put improper permissions on authorized_user_ids file, update, and
228 # make sure ssh authentication FAILS
229 echo "### setting group writability on authorized_user_ids and updating..."
230 chmod g+w "$TESTHOME"/.monkeysphere/authorized_user_ids
231 monkeysphere-server update-users $(whoami)
232 echo "### ssh connection test for server authentication denial..."
234 chmod g-w "$TESTHOME"/.monkeysphere/authorized_user_ids
235 echo "### setting other writability on authorized_user_ids and updating..."
236 chmod o+w "$TESTHOME"/.monkeysphere/authorized_user_ids
237 monkeysphere-server update-users $(whoami)
238 echo "### ssh connection test for server authentication denial..."
240 chmod o-w "$TESTHOME"/.monkeysphere/authorized_user_ids
246 echo "Monkeysphere basic tests completed successfully!"