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