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_SERVER_CONFIG="$TEMPDIR"/monkeysphere-server.conf
95 export MONKEYSPHERE_SYSSHAREDIR="$TESTDIR"/../src
96 export MONKEYSPHERE_MONKEYSPHERE_USER=$(whoami)
97 export MONKEYSPHERE_CHECK_KEYSERVER=false
98 export MONKEYSPHERE_LOG_LEVEL=DEBUG
100 export SSHD_CONFIG="$TEMPDIR"/sshd_config
101 export SOCKET="$TEMPDIR"/ssh-socket
105 ### CONFIGURE ENVIRONMENTS
107 # copy in admin and testuser home to tmp
108 echo "### copying admin and testuser homes..."
109 cp -a "$TESTDIR"/home/admin "$TEMPDIR"/
110 cp -a "$TESTDIR"/home/testuser "$TEMPDIR"/
112 # set up environment for testuser
113 TESTHOME="$TEMPDIR"/testuser
114 export GNUPGHOME="$TESTHOME"/.gnupg
115 export SSH_ASKPASS="$TESTHOME"/.ssh/askpass
116 export MONKEYSPHERE_HOME="$TESTHOME"/.monkeysphere
117 cat <<EOF >> "$TESTHOME"/.ssh/config
118 UserKnownHostsFile $TESTHOME/.ssh/known_hosts
119 IdentityFile $TESTHOME/.ssh/no-such-identity
120 ProxyCommand $TESTHOME/.ssh/proxy-command %h %p $SOCKET
122 cat <<EOF >> "$MONKEYSPHERE_HOME"/monkeysphere.conf
123 KNOWN_HOSTS=$TESTHOME/.ssh/known_hosts
125 get_gpg_prng_arg >> "$GNUPGHOME"/gpg.conf
128 echo "### configuring sshd..."
129 cp etc/ssh/sshd_config "$SSHD_CONFIG"
130 # write the sshd_config
131 cat <<EOF >> "$SSHD_CONFIG"
132 HostKey ${MONKEYSPHERE_SYSDATADIR}/ssh_host_rsa_key
133 AuthorizedKeysFile ${MONKEYSPHERE_SYSDATADIR}/authorized_keys/%u
136 # set up monkeysphere-server
137 echo "### configuring monkeysphere..."
138 mkdir -p -m 750 "$MONKEYSPHERE_SYSDATADIR"/gnupg-host
139 mkdir -p -m 700 "$MONKEYSPHERE_SYSDATADIR"/gnupg-authentication
140 mkdir -p -m 700 "$MONKEYSPHERE_SYSDATADIR"/authorized_keys
141 mkdir -p -m 700 "$MONKEYSPHERE_SYSDATADIR"/tmp
142 cp etc/monkeysphere/monkeysphere-server.conf "$MONKEYSPHERE_SERVER_CONFIG"
143 cat <<EOF >> "$MONKEYSPHERE_SERVER_CONFIG"
144 AUTHORIZED_USER_IDS="$MONKEYSPHERE_HOME/authorized_user_ids"
146 cat <<EOF > "$MONKEYSPHERE_SYSDATADIR"/gnupg-authentication/gpg.conf
147 primary-keyring ${MONKEYSPHERE_SYSDATADIR}/gnupg-authentication/pubring.gpg
148 keyring ${MONKEYSPHERE_SYSDATADIR}/gnupg-host/pubring.gpg
154 # create a new host key
155 echo "### generating server key..."
156 # add gpg.conf with quick-random
157 get_gpg_prng_arg >> "$MONKEYSPHERE_SYSCONFIGDIR"/gnupg-host/gpg.conf
158 echo | monkeysphere-server gen-key --length 1024 --expire 0 testhost
159 # remove the gpg.conf
160 rm "$MONKEYSPHERE_SYSCONFIGDIR"/gnupg-host/gpg.conf
162 HOSTKEYID=$( monkeysphere-server show-key | tail -n1 | cut -f3 -d\ )
164 # certify it with the "Admin's Key".
165 # (this would normally be done via keyservers)
166 echo "### certifying server key..."
167 monkeysphere-server gpg-authentication-cmd "--armor --export $HOSTKEYID" | gpgadmin --import
168 echo y | gpgadmin --command-fd 0 --sign-key "$HOSTKEYID"
170 # FIXME: how can we test publish-key without flooding junk into the
173 # add admin as identity certifier for testhost
174 echo "### adding admin as certifier..."
175 echo y | monkeysphere-server add-identity-certifier "$TEMPDIR"/admin/.gnupg/pubkey.gpg
180 # generate an auth subkey for the test user that expires in 2 days
181 echo "### generating key for testuser..."
182 monkeysphere gen-subkey --expire 2
184 # add server key to testuser keychain
185 echo "### export server key to testuser..."
186 gpgadmin --armor --export "$HOSTKEYID" | gpg --import
188 # teach the "server" about the testuser's key
189 echo "### export testuser key to server..."
190 gpg --export testuser | monkeysphere-server gpg-authentication-cmd --import
191 echo "### update server authorized_keys file for this testuser..."
192 monkeysphere-server update-users $(whoami)
194 # connect to test sshd, using monkeysphere-ssh-proxycommand to verify
195 # the identity before connection. This should work in both directions!
196 echo "### ssh connection test for success..."
199 # remove the testuser's authorized_user_ids file and update
200 # authorized_keys file, this is to make sure that the ssh
201 # authentication FAILS...
202 echo "### removing testuser authorized_user_ids and reupdating authorized_keys..."
203 rm -f "$TESTHOME"/.monkeysphere/authorized_user_ids
204 monkeysphere-server update-users $(whoami)
206 # make sure the user can NOT connect
207 echo "### ssh connection test for server authentication denial..."
209 if [ "$ret" != '255' ] ; then
210 echo "### connection should have failed!"
217 echo "Monkeysphere basic tests completed successfully!"