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
90 # setup monkeysphere temp gnupghome directories
91 mkdir -p -m 750 "$MONKEYSPHERE_SYSDATADIR"/gnupg-host
92 mkdir -p -m 700 "$MONKEYSPHERE_SYSDATADIR"/gnupg-authentication
93 mkdir -p -m 700 "$MONKEYSPHERE_SYSDATADIR"/authorized_keys
94 cat <<EOF > "$MONKEYSPHERE_SYSDATADIR"/gnupg-authentication/gpg.conf
95 primary-keyring ${MONKEYSPHERE_SYSDATADIR}/gnupg-authentication/pubring.gpg
96 keyring ${MONKEYSPHERE_SYSDATADIR}/gnupg-host/pubring.gpg
99 # create a new host key
100 echo "### generating server key..."
101 # add gpg.conf with quick-random
102 echo "quick-random" >> "$MONKEYSPHERE_SYSCONFIGDIR"/gnupg-host/gpg.conf
103 echo | monkeysphere-server gen-key --length 1024 --expire 0 testhost
104 # remove the gpg.conf
105 rm "$MONKEYSPHERE_SYSCONFIGDIR"/gnupg-host/gpg.conf
107 HOSTKEYID=$( monkeysphere-server show-key | tail -n1 | cut -f3 -d\ )
109 # certify it with the "Admin's Key".
110 # (this would normally be done via keyservers)
111 echo "### certifying server key..."
112 monkeysphere-server gpg-authentication-cmd "--armor --export $HOSTKEYID" | gpgadmin --import
113 echo y | gpgadmin --command-fd 0 --sign-key "$HOSTKEYID"
115 # FIXME: how can we test publish-key without flooding junk into the
118 # add admin as identity certifier for testhost
119 echo "### adding admin as certifier..."
120 echo y | monkeysphere-server add-identity-certifier "$TEMPDIR"/admin/.gnupg/pubkey.gpg
122 # initialize base sshd_config
123 cp etc/ssh/sshd_config "$SSHD_CONFIG"
124 # write the sshd_config
125 cat <<EOF >> "$SSHD_CONFIG"
126 HostKey ${MONKEYSPHERE_SYSDATADIR}/ssh_host_rsa_key
127 AuthorizedKeysFile ${MONKEYSPHERE_SYSDATADIR}/authorized_keys/%u
130 # launch test sshd with the new host key.
131 echo "### starting sshd..."
132 socat EXEC:"/usr/sbin/sshd -f ${SSHD_CONFIG} -i -D -e" "UNIX-LISTEN:${SOCKET}" 2> "$TEMPDIR"/sshd.log &
137 # generate an auth subkey for the test user
138 echo "### generating key for testuser..."
139 export GNUPGHOME="$TEMPDIR"/testuser/.gnupg
140 export SSH_ASKPASS="$TEMPDIR"/testuser/.ssh/askpass
141 export MONKEYSPHERE_HOME="$TEMPDIR"/testuser/.monkeysphere
143 monkeysphere gen-subkey --expire 0
145 # add server key to testuser keychain
146 echo "### export server key to testuser..."
147 gpgadmin --armor --export "$HOSTKEYID" | gpg --import
149 # teach the "server" about the testuser's key
150 echo "### export testuser key to server..."
151 gpg --export testuser | monkeysphere-server gpg-authentication-cmd --import
152 echo "### update server authorized_keys file for testuser..."
153 monkeysphere-server update-users testuser
155 # connect to test sshd, using monkeysphere-ssh-proxycommand to verify
156 # the identity before connection. This should work in both directions!
157 echo "### testuser connecting to sshd socket..."
160 "monkeysphere subkey-to-ssh-agent && ssh -F $TEMPDIR/testuser/.ssh/config testhost"