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 socat EXEC:"/usr/sbin/sshd -f ${SSHD_CONFIG} -i -D -e" "UNIX-LISTEN:${SOCKET}" 2> "$TEMPDIR"/sshd.log &
29 # wait until the socket is created before continuing
30 while [ ! -S "$SOCKET" ] ; do
34 # make a client connection to the socket
36 "monkeysphere subkey-to-ssh-agent && ssh -F $TEMPDIR/testuser/.ssh/config testhost true"
39 # kill the previous sshd process if it's still running
46 # FIXME: can we be more verbose here?
48 read -p "press enter to cleanup and remove tmp:"
54 if (gpg --quick-random --version >/dev/null 2>&1) ; then
56 elif (gpg --debug-quick-random --version >/dev/null 2>&1) ; then
57 echo debug-quick-random
62 echo "### removing temp dir..."
69 trap failed_cleanup EXIT
71 ## set up some variables to ensure that we're operating strictly in
72 ## the tests, not system-wide:
77 TEMPDIR="$TESTDIR"/tmp
78 if [ -e "$TEMPDIR" ] ; then
79 echo "tempdir '$TEMPDIR' already exists."
84 # Use the local copy of executables first, instead of system ones.
85 # This should help us test without installing.
86 export PATH="$TESTDIR"/../src:"$TESTDIR"/../src/keytrans:"$PATH"
88 export MONKEYSPHERE_SYSDATADIR="$TEMPDIR"
89 export MONKEYSPHERE_SYSCONFIGDIR="$TEMPDIR"
90 export MONKEYSPHERE_SYSSHAREDIR="$TESTDIR"/../src
91 export MONKEYSPHERE_MONKEYSPHERE_USER="$USER"
92 export MONKEYSPHERE_CHECK_KEYSERVER=false
93 export MONKEYSPHERE_LOG_LEVEL=DEBUG
95 export SSHD_CONFIG="$TEMPDIR"/sshd_config
96 export SOCKET="$TEMPDIR"/ssh-socket
99 # copy in admin and testuser home to tmp
100 echo "### copying admin and testuser homes..."
101 cp -a "$TESTDIR"/home/admin "$TEMPDIR"/
102 cp -a "$TESTDIR"/home/testuser "$TEMPDIR"/
104 cat <<EOF >> "$TEMPDIR"/testuser/.ssh/config
105 UserKnownHostsFile $TEMPDIR/testuser/.ssh/known_hosts
106 IdentityFile $TEMPDIR/testuser/.ssh/no-such-identity
107 ProxyCommand $TEMPDIR/testuser/.ssh/proxy-command %h %p $SOCKET
110 cat <<EOF >> "$TEMPDIR"/testuser/.monkeysphere/monkeysphere.conf
111 KNOWN_HOSTS=$TEMPDIR/testuser/.ssh/known_hosts
114 get_gpg_prng_arg >> "$TEMPDIR"/testuser/.gnupg/gpg.conf
116 # set up a simple default monkeysphere-server.conf
117 cat <<EOF >> "$TEMPDIR"/monkeysphere-server.conf
118 AUTHORIZED_USER_IDS="$TEMPDIR/testuser/.monkeysphere/authorized_user_ids"
123 # setup monkeysphere temp gnupghome directories
124 mkdir -p -m 750 "$MONKEYSPHERE_SYSDATADIR"/gnupg-host
125 mkdir -p -m 700 "$MONKEYSPHERE_SYSDATADIR"/gnupg-authentication
126 mkdir -p -m 700 "$MONKEYSPHERE_SYSDATADIR"/authorized_keys
127 cat <<EOF > "$MONKEYSPHERE_SYSDATADIR"/gnupg-authentication/gpg.conf
128 primary-keyring ${MONKEYSPHERE_SYSDATADIR}/gnupg-authentication/pubring.gpg
129 keyring ${MONKEYSPHERE_SYSDATADIR}/gnupg-host/pubring.gpg
132 # create a new host key
133 echo "### generating server key..."
134 # add gpg.conf with quick-random
135 get_gpg_prng_arg >> "$MONKEYSPHERE_SYSCONFIGDIR"/gnupg-host/gpg.conf
136 echo | monkeysphere-server gen-key --length 1024 --expire 0 testhost
137 # remove the gpg.conf
138 rm "$MONKEYSPHERE_SYSCONFIGDIR"/gnupg-host/gpg.conf
140 HOSTKEYID=$( monkeysphere-server show-key | tail -n1 | cut -f3 -d\ )
142 # certify it with the "Admin's Key".
143 # (this would normally be done via keyservers)
144 echo "### certifying server key..."
145 monkeysphere-server gpg-authentication-cmd "--armor --export $HOSTKEYID" | gpgadmin --import
146 echo y | gpgadmin --command-fd 0 --sign-key "$HOSTKEYID"
148 # FIXME: how can we test publish-key without flooding junk into the
151 # add admin as identity certifier for testhost
152 echo "### adding admin as certifier..."
153 echo y | monkeysphere-server add-identity-certifier "$TEMPDIR"/admin/.gnupg/pubkey.gpg
155 # initialize base sshd_config
156 echo "### configuring sshd..."
157 cp etc/ssh/sshd_config "$SSHD_CONFIG"
158 # write the sshd_config
159 cat <<EOF >> "$SSHD_CONFIG"
160 HostKey ${MONKEYSPHERE_SYSDATADIR}/ssh_host_rsa_key
161 AuthorizedKeysFile ${MONKEYSPHERE_SYSDATADIR}/authorized_keys/%u
166 # generate an auth subkey for the test user
167 echo "### generating key for testuser..."
168 export GNUPGHOME="$TEMPDIR"/testuser/.gnupg
169 export SSH_ASKPASS="$TEMPDIR"/testuser/.ssh/askpass
170 export MONKEYSPHERE_HOME="$TEMPDIR"/testuser/.monkeysphere
171 monkeysphere gen-subkey --expire 0
173 # add server key to testuser keychain
174 echo "### export server key to testuser..."
175 gpgadmin --armor --export "$HOSTKEYID" | gpg --import
177 # teach the "server" about the testuser's key
178 echo "### export testuser key to server..."
179 gpg --export testuser | monkeysphere-server gpg-authentication-cmd --import
180 echo "### update server authorized_keys file for this testuser..."
181 monkeysphere-server update-users "$USER"
183 # connect to test sshd, using monkeysphere-ssh-proxycommand to verify
184 # the identity before connection. This should work in both directions!
185 echo "### ssh connection test for success..."
188 # remove the testuser's authorized_user_ids file and update
189 # authorized_keys file, this is to make sure that the ssh
190 # authentication FAILS...
191 echo "### removing testuser authorized_user_ids and reupdating authorized_keys..."
192 rm -f "$TEMPDIR"/testuser/.monkeysphere/authorized_user_ids
193 monkeysphere-server update-users "$USER"
195 # make sure the user can NOT connect
196 echo "### ssh connection test for server authentication denial..."
198 if [ "$?" != '255' ] ; then
205 echo "Monkeysphere basic tests completed successfully!"