3 # Tests to ensure that the monkeysphere is working
5 # Author: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
6 # Date: 2008-09-13 13:40:15-0400
8 # these tests might be best run under fakeroot, particularly the
9 # "server-side" tests. Using fakeroot, they should be able to be run
10 # as a non-privileged user.
12 # NOTE: these tests have *not* themselves been tested yet
13 # (2008-09-13). Please exercise with caution!
18 # gpg command for test admin user
20 GNUPGHOME="$TEMPDIR"/admin/.gnupg gpg "$@"
27 read -p "press enter to cleanup and remove tmp:"
29 echo "### stop sshd..."
32 echo "### removing temp dir..."
39 ## set up some variables to ensure that we're operating strictly in
40 ## the tests, not system-wide:
45 TEMPDIR="$TESTDIR"/tmp
46 if [ -e "$TEMPDIR" ] ; then
47 echo "tempdir '$TEMPDIR' already exists."
52 # Use the local copy of executables first, instead of system ones.
53 # This should help us test without installing.
54 export PATH="$TESTDIR"/../src:"$TESTDIR"/../src/keytrans:"$PATH"
56 export MONKEYSPHERE_SYSDATADIR="$TEMPDIR"
57 export MONKEYSPHERE_SYSCONFIGDIR="$TEMPDIR"
58 export MONKEYSPHERE_SYSSHAREDIR="$TESTDIR"/../src
59 export MONKEYSPHERE_MONKEYSPHERE_USER="$USER"
60 export MONKEYSPHERE_CHECK_KEYSERVER=false
62 SSHD_CONFIG="$TEMPDIR"/sshd_config
63 export SOCKET="$TEMPDIR"/ssh-socket
65 # copy in admin and testuser home to tmp
66 echo "### copying admin and testuser homes..."
67 cp -a "$TESTDIR"/home/admin "$TEMPDIR"/
68 cp -a "$TESTDIR"/home/testuser "$TEMPDIR"/
74 # setup monkeysphere temp gnupghome directories
75 mkdir -p -m 750 "$MONKEYSPHERE_SYSDATADIR"/gnupg-host
76 mkdir -p -m 700 "$MONKEYSPHERE_SYSDATADIR"/gnupg-authentication
77 cat <<EOF > "$MONKEYSPHERE_SYSDATADIR"/gnupg-authentication/gpg.conf
78 primary-keyring ${MONKEYSPHERE_SYSDATADIR}/gnupg-authentication/pubring.gpg
79 keyring ${MONKEYSPHERE_SYSDATADIR}/gnupg-host/pubring.gpg
82 # create a new host key
83 echo "### generating server key..."
84 # add gpg.conf with quick-random
85 echo "quick-random" >> "$MONKEYSPHERE_SYSCONFIGDIR"/gnupg-host/gpg.conf
86 echo | monkeysphere-server gen-key --length 1024 --expire 0 testhost
88 rm "$MONKEYSPHERE_SYSCONFIGDIR"/gnupg-host/gpg.conf
90 HOSTKEYID=$( monkeysphere-server show-key | tail -n1 | cut -f3 -d\ )
92 # certify it with the "Admin's Key".
93 # (this would normally be done via keyservers)
94 echo "### certifying server key..."
95 monkeysphere-server gpg-authentication-cmd "--armor --export $HOSTKEYID" | gpgadmin --import
96 echo y | gpgadmin --command-fd 0 --sign-key "$HOSTKEYID"
98 # FIXME: how can we test publish-key without flooding junk into the
101 # add admin as identity certifier for testhost
102 echo "### adding admin as certifier..."
103 echo y | monkeysphere-server add-identity-certifier "$TEMPDIR"/admin/.gnupg/pubkey.gpg
105 # initialize base sshd_config
106 cp etc/ssh/sshd_config "$SSHD_CONFIG"
107 # write the sshd_config
108 cat <<EOF >> "$SSHD_CONFIG"
109 HostKey ${MONKEYSPHERE_SYSDATADIR}/ssh_host_rsa_key
110 AuthorizedKeysFile ${MONKEYSPHERE_SYSDATADIR}/authorized_keys/%u
113 # launch test sshd with the new host key.
114 echo "### starting sshd..."
115 socat EXEC:"/usr/sbin/sshd -f ${SSHD_CONFIG} -i -d -d -d -D -e" "UNIX-LISTEN:${SOCKET}" 2> "$TEMPDIR"/sshd.log &
121 # generate an auth subkey for the test user
122 echo "### generating key for testuser..."
123 MONKEYSPHERE_GNUPGHOME="$TEMPDIR"/testuser/.gnupg \
125 monkeysphere gen-subkey --expire 0
127 # add server key to testuser keychain
128 echo "### export server key to testuser..."
129 gpgadmin --armor --export "$HOSTKEYID" | \
130 GNUPGHOME="$TEMPDIR"/testuser/.gnupg gpg --import
132 # connect to test sshd, using monkeysphere-ssh-proxycommand to verify
133 # the identity before connection. This should work in both directions!
134 echo "### testuser connecting to sshd socket..."
135 PROXY_COMMAND="monkeysphere-ssh-proxycommand --no-connect %h && socat STDIO UNIX:${SOCKET}"
136 GNUPGHOME="$TEMPDIR"/testuser/.gnupg ssh -v -v -v -oProxyCommand="$PROXY_COMMAND" testhost