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 "$@"
25 # start the ssh daemon on the socket
26 echo "##### starting ssh server..."
27 socat EXEC:"/usr/sbin/sshd -f ${SSHD_CONFIG} -i -D -e" "UNIX-LISTEN:${SOCKET}" 2> "$TEMPDIR"/sshd.log &
30 # wait until the socket is created before continuing
31 while [ ! -S "$SOCKET" ] ; do
35 # make a client connection to the socket
36 echo "##### starting ssh client..."
38 "monkeysphere subkey-to-ssh-agent && ssh -F $TEMPDIR/testuser/.ssh/config testhost true"
41 # kill the previous sshd process if it's still running
48 # FIXME: can we be more verbose here?
50 read -p "press enter to cleanup and remove tmp:"
56 if (gpg --quick-random --version >/dev/null 2>&1) ; then
58 elif (gpg --debug-quick-random --version >/dev/null 2>&1) ; then
59 echo debug-quick-random
64 echo "### removing temp dir..."
71 trap failed_cleanup EXIT
75 ## set up some variables to ensure that we're operating strictly in
76 ## the tests, not system-wide:
81 TEMPDIR="$TESTDIR"/tmp
82 if [ -e "$TEMPDIR" ] ; then
83 echo "tempdir '$TEMPDIR' already exists."
88 # Use the local copy of executables first, instead of system ones.
89 # This should help us test without installing.
90 export PATH="$TESTDIR"/../src:"$TESTDIR"/../src/keytrans:"$PATH"
92 export MONKEYSPHERE_SYSDATADIR="$TEMPDIR"
93 export MONKEYSPHERE_SYSCONFIGDIR="$TEMPDIR"
94 export MONKEYSPHERE_SYSSHAREDIR="$TESTDIR"/../src
95 export MONKEYSPHERE_MONKEYSPHERE_USER=$(whoami)
96 export MONKEYSPHERE_CHECK_KEYSERVER=false
97 export MONKEYSPHERE_LOG_LEVEL=DEBUG
99 export SSHD_CONFIG="$TEMPDIR"/sshd_config
100 export SOCKET="$TEMPDIR"/ssh-socket
104 ### CONFIGURE ENVIRONMENTS
106 # copy in admin and testuser home to tmp
107 echo "### copying admin and testuser homes..."
108 cp -a "$TESTDIR"/home/admin "$TEMPDIR"/
109 cp -a "$TESTDIR"/home/testuser "$TEMPDIR"/
111 # set up environment for testuser
112 TESTHOME="$TEMPDIR"/testuser
113 export GNUPGHOME="$TESTHOME"/.gnupg
114 export SSH_ASKPASS="$TESTHOME"/.ssh/askpass
115 export MONKEYSPHERE_HOME="$TESTHOME"/.monkeysphere
116 cat <<EOF >> "$TESTHOME"/.ssh/config
117 UserKnownHostsFile $TESTHOME/.ssh/known_hosts
118 IdentityFile $TESTHOME/.ssh/no-such-identity
119 ProxyCommand $TESTHOME/.ssh/proxy-command %h %p $SOCKET
121 cat <<EOF >> "$MONKEYSPHERE_HOME"/monkeysphere.conf
122 KNOWN_HOSTS=$TESTHOME/.ssh/known_hosts
124 get_gpg_prng_arg >> "$GNUPGHOME"/gpg.conf
127 echo "### configuring sshd..."
128 cp etc/ssh/sshd_config "$SSHD_CONFIG"
129 # write the sshd_config
130 cat <<EOF >> "$SSHD_CONFIG"
131 HostKey ${MONKEYSPHERE_SYSDATADIR}/ssh_host_rsa_key
132 AuthorizedKeysFile ${MONKEYSPHERE_SYSDATADIR}/authorized_keys/%u
135 # set up monkeysphere-server
136 echo "### configuring monkeysphere..."
137 mkdir -p -m 750 "$MONKEYSPHERE_SYSDATADIR"/gnupg-host
138 mkdir -p -m 700 "$MONKEYSPHERE_SYSDATADIR"/gnupg-authentication
139 mkdir -p -m 700 "$MONKEYSPHERE_SYSDATADIR"/authorized_keys
140 mkdir -p -m 700 "$MONKEYSPHERE_SYSDATADIR"/tmp
141 cp etc/monkeysphere/monkeysphere-server.conf "$TEMPDIR"/monkeysphere-server.conf
142 cat <<EOF >> "$TEMPDIR"/monkeysphere-server.conf
143 AUTHORIZED_USER_IDS="$MONKEYSPHERE_HOME/authorized_user_ids"
145 cat <<EOF > "$MONKEYSPHERE_SYSDATADIR"/gnupg-authentication/gpg.conf
146 primary-keyring ${MONKEYSPHERE_SYSDATADIR}/gnupg-authentication/pubring.gpg
147 keyring ${MONKEYSPHERE_SYSDATADIR}/gnupg-host/pubring.gpg
153 # create a new host key
154 echo "### generating server key..."
155 # add gpg.conf with quick-random
156 get_gpg_prng_arg >> "$MONKEYSPHERE_SYSCONFIGDIR"/gnupg-host/gpg.conf
157 echo | monkeysphere-server gen-key --length 1024 --expire 0 testhost
158 # remove the gpg.conf
159 rm "$MONKEYSPHERE_SYSCONFIGDIR"/gnupg-host/gpg.conf
161 HOSTKEYID=$( monkeysphere-server show-key | tail -n1 | cut -f3 -d\ )
163 # certify it with the "Admin's Key".
164 # (this would normally be done via keyservers)
165 echo "### certifying server key..."
166 monkeysphere-server gpg-authentication-cmd "--armor --export $HOSTKEYID" | gpgadmin --import
167 echo y | gpgadmin --command-fd 0 --sign-key "$HOSTKEYID"
169 # FIXME: how can we test publish-key without flooding junk into the
172 # add admin as identity certifier for testhost
173 echo "### adding admin as certifier..."
174 echo y | monkeysphere-server add-identity-certifier "$TEMPDIR"/admin/.gnupg/pubkey.gpg
179 # generate an auth subkey for the test user that expires in 2 days
180 echo "### generating key for testuser..."
181 monkeysphere gen-subkey --expire 2
183 # add server key to testuser keychain
184 echo "### export server key to testuser..."
185 gpgadmin --armor --export "$HOSTKEYID" | gpg --import
187 # teach the "server" about the testuser's key
188 echo "### export testuser key to server..."
189 gpg --export testuser | monkeysphere-server gpg-authentication-cmd --import
190 echo "### update server authorized_keys file for this testuser..."
191 monkeysphere-server update-users $(whoami)
193 # connect to test sshd, using monkeysphere-ssh-proxycommand to verify
194 # the identity before connection. This should work in both directions!
195 echo "### ssh connection test for success..."
198 # remove the testuser's authorized_user_ids file and update
199 # authorized_keys file, this is to make sure that the ssh
200 # authentication FAILS...
201 echo "### removing testuser authorized_user_ids and reupdating authorized_keys..."
202 rm -f "$TESTHOME"/.monkeysphere/authorized_user_ids
203 monkeysphere-server update-users $(whoami)
205 # make sure the user can NOT connect
206 echo "### ssh connection test for server authentication denial..."
208 if [ "$ret" != '255' ] ; then
209 echo "### connection should have failed!"
216 echo "Monkeysphere basic tests completed successfully!"