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 "$@"
24 socat EXEC:"/usr/sbin/sshd -f ${SSHD_CONFIG} -i -D -e" "UNIX-LISTEN:${SOCKET}" 2> "$TEMPDIR"/sshd.log &
27 # wait until the socket is created before continuing
28 while [ ! -S "$SOCKET" ] ; do
35 "monkeysphere subkey-to-ssh-agent && ssh -F $TEMPDIR/testuser/.ssh/config testhost true"
39 # FIXME: can we be more verbose here?
41 read -p "press enter to cleanup and remove tmp:"
47 if (gpg --quick-random --version >/dev/null 2>&1) ; then
49 elif (gpg --debug-quick-random --version >/dev/null 2>&1) ; then
50 echo debug-quick-random
55 if [ "$SSHD_PID" ] && ( ps "$SSHD_PID" >/dev/null ) ; then
56 echo "### stopping still-running sshd..."
60 echo "### removing temp dir..."
67 trap failed_cleanup EXIT
69 ## set up some variables to ensure that we're operating strictly in
70 ## the tests, not system-wide:
75 TEMPDIR="$TESTDIR"/tmp
76 if [ -e "$TEMPDIR" ] ; then
77 echo "tempdir '$TEMPDIR' already exists."
82 # Use the local copy of executables first, instead of system ones.
83 # This should help us test without installing.
84 export PATH="$TESTDIR"/../src:"$TESTDIR"/../src/keytrans:"$PATH"
86 export MONKEYSPHERE_SYSDATADIR="$TEMPDIR"
87 export MONKEYSPHERE_SYSCONFIGDIR="$TEMPDIR"
88 export MONKEYSPHERE_SYSSHAREDIR="$TESTDIR"/../src
89 export MONKEYSPHERE_MONKEYSPHERE_USER="$USER"
90 export MONKEYSPHERE_CHECK_KEYSERVER=false
92 export SSHD_CONFIG="$TEMPDIR"/sshd_config
93 export SOCKET="$TEMPDIR"/ssh-socket
96 # copy in admin and testuser home to tmp
97 echo "### copying admin and testuser homes..."
98 cp -a "$TESTDIR"/home/admin "$TEMPDIR"/
99 cp -a "$TESTDIR"/home/testuser "$TEMPDIR"/
101 cat <<EOF >> "$TEMPDIR"/testuser/.ssh/config
102 UserKnownHostsFile $TEMPDIR/testuser/.ssh/known_hosts
103 IdentityFile $TEMPDIR/testuser/.ssh/no-such-identity
104 ProxyCommand $TEMPDIR/testuser/.ssh/proxy-command %h %p $SOCKET
107 cat <<EOF >> "$TEMPDIR"/testuser/.monkeysphere/monkeysphere.conf
108 KNOWN_HOSTS=$TEMPDIR/testuser/.ssh/known_hosts
111 get_gpg_prng_arg >> "$TEMPDIR"/testuser/.gnupg/gpg.conf
113 # set up a simple default monkeysphere-server.conf
114 cat <<EOF >> "$TEMPDIR"/monkeysphere-server.conf
115 AUTHORIZED_USER_IDS="$TEMPDIR/testuser/.monkeysphere/authorized_user_ids"
120 # setup monkeysphere temp gnupghome directories
121 mkdir -p -m 750 "$MONKEYSPHERE_SYSDATADIR"/gnupg-host
122 mkdir -p -m 700 "$MONKEYSPHERE_SYSDATADIR"/gnupg-authentication
123 mkdir -p -m 700 "$MONKEYSPHERE_SYSDATADIR"/authorized_keys
124 cat <<EOF > "$MONKEYSPHERE_SYSDATADIR"/gnupg-authentication/gpg.conf
125 primary-keyring ${MONKEYSPHERE_SYSDATADIR}/gnupg-authentication/pubring.gpg
126 keyring ${MONKEYSPHERE_SYSDATADIR}/gnupg-host/pubring.gpg
129 # create a new host key
130 echo "### generating server key..."
131 # add gpg.conf with quick-random
132 get_gpg_prng_arg >> "$MONKEYSPHERE_SYSCONFIGDIR"/gnupg-host/gpg.conf
133 echo | monkeysphere-server gen-key --length 1024 --expire 0 testhost
134 # remove the gpg.conf
135 rm "$MONKEYSPHERE_SYSCONFIGDIR"/gnupg-host/gpg.conf
137 HOSTKEYID=$( monkeysphere-server show-key | tail -n1 | cut -f3 -d\ )
139 # certify it with the "Admin's Key".
140 # (this would normally be done via keyservers)
141 echo "### certifying server key..."
142 monkeysphere-server gpg-authentication-cmd "--armor --export $HOSTKEYID" | gpgadmin --import
143 echo y | gpgadmin --command-fd 0 --sign-key "$HOSTKEYID"
145 # FIXME: how can we test publish-key without flooding junk into the
148 # add admin as identity certifier for testhost
149 echo "### adding admin as certifier..."
150 echo y | monkeysphere-server add-identity-certifier "$TEMPDIR"/admin/.gnupg/pubkey.gpg
152 # initialize base sshd_config
153 cp etc/ssh/sshd_config "$SSHD_CONFIG"
154 # write the sshd_config
155 cat <<EOF >> "$SSHD_CONFIG"
156 HostKey ${MONKEYSPHERE_SYSDATADIR}/ssh_host_rsa_key
157 AuthorizedKeysFile ${MONKEYSPHERE_SYSDATADIR}/authorized_keys/%u
160 # launch test sshd with the new host key.
161 echo "### starting sshd..."
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
172 monkeysphere gen-subkey --expire 0
174 # add server key to testuser keychain
175 echo "### export server key to testuser..."
176 gpgadmin --armor --export "$HOSTKEYID" | gpg --import
178 # teach the "server" about the testuser's key
179 echo "### export testuser key to server..."
180 gpg --export testuser | monkeysphere-server gpg-authentication-cmd --import
181 echo "### update server authorized_keys file for this testuser..."
182 monkeysphere-server update-users "$USER"
184 # connect to test sshd, using monkeysphere-ssh-proxycommand to verify
185 # the identity before connection. This should work in both directions!
186 echo "### testuser connecting to sshd socket..."
189 # kill the previous sshd process if it's still running
192 # now remove the testuser's authorized_user_ids file and reupdate
193 # authorized_keys file...
194 echo "### removing testuser authorized_user_ids and reupdating authorized_keys..."
195 rm -f "$TEMPDIR"/testuser/.monkeysphere/authorized_user_ids
196 monkeysphere-server update-users "$USER"
199 echo "### restarting sshd..."
202 # and make sure the user can no longer connect
203 echo "### testuser attempting to connect to sshd socket..."
204 ssh_test || SSH_RETURN="$?"
205 if [ "$SSH_RETURN" != '255' ] ; then
212 echo "Monkeysphere basic tests completed successfully!"