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
73 ## set up some variables to ensure that we're operating strictly in
74 ## the tests, not system-wide:
79 TEMPDIR="$TESTDIR"/tmp
80 if [ -e "$TEMPDIR" ] ; then
81 echo "tempdir '$TEMPDIR' already exists."
86 # Use the local copy of executables first, instead of system ones.
87 # This should help us test without installing.
88 export PATH="$TESTDIR"/../src:"$TESTDIR"/../src/keytrans:"$PATH"
90 export MONKEYSPHERE_SYSDATADIR="$TEMPDIR"
91 export MONKEYSPHERE_SYSCONFIGDIR="$TEMPDIR"
92 export MONKEYSPHERE_SYSSHAREDIR="$TESTDIR"/../src
93 export MONKEYSPHERE_MONKEYSPHERE_USER="$USER"
94 export MONKEYSPHERE_CHECK_KEYSERVER=false
95 export MONKEYSPHERE_LOG_LEVEL=DEBUG
97 export SSHD_CONFIG="$TEMPDIR"/sshd_config
98 export SOCKET="$TEMPDIR"/ssh-socket
101 # copy in admin and testuser home to tmp
102 echo "### copying admin and testuser homes..."
103 cp -a "$TESTDIR"/home/admin "$TEMPDIR"/
104 cp -a "$TESTDIR"/home/testuser "$TEMPDIR"/
106 # set up environment for testuser
107 export HOME="$TEMPDIR"/testuser
108 export GNUPGHOME="$HOME"/.gnupg
109 export SSH_ASKPASS="$HOME"/.ssh/askpass
110 export MONKEYSPHERE_HOME="$HOME"/.monkeysphere
112 cat <<EOF >> "$HOME"/.ssh/config
113 UserKnownHostsFile $HOME/.ssh/known_hosts
114 IdentityFile $HOME/.ssh/no-such-identity
115 ProxyCommand $HOME/.ssh/proxy-command %h %p $SOCKET
118 cat <<EOF >> "$MONKEYSPHERE_HOME"/monkeysphere.conf
119 KNOWN_HOSTS=$HOME/.ssh/known_hosts
122 get_gpg_prng_arg >> "$GNUPGHOME"/gpg.conf
124 # set up a simple default monkeysphere-server.conf
125 cat <<EOF >> "$TEMPDIR"/monkeysphere-server.conf
126 AUTHORIZED_USER_IDS="$MONKEYSPHERE_HOME/authorized_user_ids"
131 # setup monkeysphere temp gnupghome directories
132 mkdir -p -m 750 "$MONKEYSPHERE_SYSDATADIR"/gnupg-host
133 mkdir -p -m 700 "$MONKEYSPHERE_SYSDATADIR"/gnupg-authentication
134 mkdir -p -m 700 "$MONKEYSPHERE_SYSDATADIR"/authorized_keys
135 mkdir -p -m 700 "$MONKEYSPHERE_SYSDATADIR"/tmp
136 cat <<EOF > "$MONKEYSPHERE_SYSDATADIR"/gnupg-authentication/gpg.conf
137 primary-keyring ${MONKEYSPHERE_SYSDATADIR}/gnupg-authentication/pubring.gpg
138 keyring ${MONKEYSPHERE_SYSDATADIR}/gnupg-host/pubring.gpg
141 # create a new host key
142 echo "### generating server key..."
143 # add gpg.conf with quick-random
144 get_gpg_prng_arg >> "$MONKEYSPHERE_SYSCONFIGDIR"/gnupg-host/gpg.conf
145 echo | monkeysphere-server gen-key --length 1024 --expire 0 testhost
146 # remove the gpg.conf
147 rm "$MONKEYSPHERE_SYSCONFIGDIR"/gnupg-host/gpg.conf
149 HOSTKEYID=$( monkeysphere-server show-key | tail -n1 | cut -f3 -d\ )
151 # certify it with the "Admin's Key".
152 # (this would normally be done via keyservers)
153 echo "### certifying server key..."
154 monkeysphere-server gpg-authentication-cmd "--armor --export $HOSTKEYID" | gpgadmin --import
155 echo y | gpgadmin --command-fd 0 --sign-key "$HOSTKEYID"
157 # FIXME: how can we test publish-key without flooding junk into the
160 # add admin as identity certifier for testhost
161 echo "### adding admin as certifier..."
162 echo y | monkeysphere-server add-identity-certifier "$TEMPDIR"/admin/.gnupg/pubkey.gpg
164 # initialize base sshd_config
165 echo "### configuring sshd..."
166 cp etc/ssh/sshd_config "$SSHD_CONFIG"
167 # write the sshd_config
168 cat <<EOF >> "$SSHD_CONFIG"
169 HostKey ${MONKEYSPHERE_SYSDATADIR}/ssh_host_rsa_key
170 AuthorizedKeysFile ${MONKEYSPHERE_SYSDATADIR}/authorized_keys/%u
175 # generate an auth subkey for the test user
176 echo "### generating key for testuser..."
177 monkeysphere gen-subkey --expire 0
179 # add server key to testuser keychain
180 echo "### export server key to testuser..."
181 gpgadmin --armor --export "$HOSTKEYID" | gpg --import
183 # teach the "server" about the testuser's key
184 echo "### export testuser key to server..."
185 gpg --export testuser | monkeysphere-server gpg-authentication-cmd --import
186 echo "### update server authorized_keys file for this testuser..."
187 monkeysphere-server update-users testuser
189 # connect to test sshd, using monkeysphere-ssh-proxycommand to verify
190 # the identity before connection. This should work in both directions!
191 echo "### ssh connection test for success..."
194 # remove the testuser's authorized_user_ids file and update
195 # authorized_keys file, this is to make sure that the ssh
196 # authentication FAILS...
197 echo "### removing testuser authorized_user_ids and reupdating authorized_keys..."
198 rm -f "$TEMPDIR"/testuser/.monkeysphere/authorized_user_ids
199 monkeysphere-server update-users testuser
201 # make sure the user can NOT connect
202 echo "### ssh connection test for server authentication denial..."
204 if [ "$?" != '255' ] ; then
211 echo "Monkeysphere basic tests completed successfully!"