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 "$@"
23 # FIXME: can we be more verbose here?
32 read -p "press enter to cleanup and remove tmp:"
34 if ( ps $SSHD_PID >/dev/null ) ; then
35 echo "### stopping still-running sshd..."
39 echo "### removing temp dir..."
46 trap failed_cleanup EXIT
48 ## set up some variables to ensure that we're operating strictly in
49 ## the tests, not system-wide:
54 TEMPDIR="$TESTDIR"/tmp
55 if [ -e "$TEMPDIR" ] ; then
56 echo "tempdir '$TEMPDIR' already exists."
61 # Use the local copy of executables first, instead of system ones.
62 # This should help us test without installing.
63 export PATH="$TESTDIR"/../src:"$TESTDIR"/../src/keytrans:"$PATH"
65 export MONKEYSPHERE_SYSDATADIR="$TEMPDIR"
66 export MONKEYSPHERE_SYSCONFIGDIR="$TEMPDIR"
67 export MONKEYSPHERE_SYSSHAREDIR="$TESTDIR"/../src
68 export MONKEYSPHERE_MONKEYSPHERE_USER="$USER"
69 export MONKEYSPHERE_CHECK_KEYSERVER=false
71 SSHD_CONFIG="$TEMPDIR"/sshd_config
72 export SOCKET="$TEMPDIR"/ssh-socket
74 # copy in admin and testuser home to tmp
75 echo "### copying admin and testuser homes..."
76 cp -a "$TESTDIR"/home/admin "$TEMPDIR"/
77 cp -a "$TESTDIR"/home/testuser "$TEMPDIR"/
79 cat <<EOF >> "$TEMPDIR"/testuser/.ssh/config
80 UserKnownHostsFile $TEMPDIR/testuser/.ssh/known_hosts
81 ProxyCommand $TEMPDIR/testuser/.ssh/proxy-command %h %p $SOCKET
84 cat <<EOF >> "$TEMPDIR"/testuser/.monkeysphere/monkeysphere.conf
85 KNOWN_HOSTS=$TEMPDIR/testuser/.ssh/known_hosts
88 # set up a simple default monkeysphere-server.conf
89 cat <<EOF >> "$TEMPDIR"/monkeysphere-server.conf
90 AUTHORIZED_USER_IDS="$TEMPDIR/testuser/.monkeysphere/authorized_user_ids"
95 # setup monkeysphere temp gnupghome directories
96 mkdir -p -m 750 "$MONKEYSPHERE_SYSDATADIR"/gnupg-host
97 mkdir -p -m 700 "$MONKEYSPHERE_SYSDATADIR"/gnupg-authentication
98 mkdir -p -m 700 "$MONKEYSPHERE_SYSDATADIR"/authorized_keys
99 cat <<EOF > "$MONKEYSPHERE_SYSDATADIR"/gnupg-authentication/gpg.conf
100 primary-keyring ${MONKEYSPHERE_SYSDATADIR}/gnupg-authentication/pubring.gpg
101 keyring ${MONKEYSPHERE_SYSDATADIR}/gnupg-host/pubring.gpg
104 # create a new host key
105 echo "### generating server key..."
106 # add gpg.conf with quick-random
107 echo "quick-random" >> "$MONKEYSPHERE_SYSCONFIGDIR"/gnupg-host/gpg.conf
108 echo | monkeysphere-server gen-key --length 1024 --expire 0 testhost
109 # remove the gpg.conf
110 rm "$MONKEYSPHERE_SYSCONFIGDIR"/gnupg-host/gpg.conf
112 HOSTKEYID=$( monkeysphere-server show-key | tail -n1 | cut -f3 -d\ )
114 # certify it with the "Admin's Key".
115 # (this would normally be done via keyservers)
116 echo "### certifying server key..."
117 monkeysphere-server gpg-authentication-cmd "--armor --export $HOSTKEYID" | gpgadmin --import
118 echo y | gpgadmin --command-fd 0 --sign-key "$HOSTKEYID"
120 # FIXME: how can we test publish-key without flooding junk into the
123 # add admin as identity certifier for testhost
124 echo "### adding admin as certifier..."
125 echo y | monkeysphere-server add-identity-certifier "$TEMPDIR"/admin/.gnupg/pubkey.gpg
127 # initialize base sshd_config
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 # launch test sshd with the new host key.
136 echo "### starting sshd..."
137 socat EXEC:"/usr/sbin/sshd -f ${SSHD_CONFIG} -i -D -e" "UNIX-LISTEN:${SOCKET}" 2> "$TEMPDIR"/sshd.log &
142 # generate an auth subkey for the test user
143 echo "### generating key for testuser..."
144 export GNUPGHOME="$TEMPDIR"/testuser/.gnupg
145 export SSH_ASKPASS="$TEMPDIR"/testuser/.ssh/askpass
146 export MONKEYSPHERE_HOME="$TEMPDIR"/testuser/.monkeysphere
148 monkeysphere gen-subkey --expire 0
150 # add server key to testuser keychain
151 echo "### export server key to testuser..."
152 gpgadmin --armor --export "$HOSTKEYID" | gpg --import
154 # teach the "server" about the testuser's key
155 echo "### export testuser key to server..."
156 gpg --export testuser | monkeysphere-server gpg-authentication-cmd --import
157 echo "### update server authorized_keys file for this testuser..."
158 monkeysphere-server update-users "$USER"
160 # connect to test sshd, using monkeysphere-ssh-proxycommand to verify
161 # the identity before connection. This should work in both directions!
162 echo "### testuser connecting to sshd socket..."
165 "monkeysphere subkey-to-ssh-agent && ssh -F $TEMPDIR/testuser/.ssh/config testhost"