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 # these tests assume a commonly-trusted "Admin's key", a fake key
19 # permanently stored in ./home/admin/.gnupg:
21 GNUPGHOME="$TESTDIR"/home/admin/.gnupg gpg "$@"
28 read -p "press enter to cleanup and remove tmp:"
30 echo "### stop sshd..."
33 echo "### removing temp dir..."
40 ## set up some variables to ensure that we're operating strictly in
41 ## the tests, not system-wide:
46 TEMPDIR="$TESTDIR"/tmp
47 if [ -e "$TEMPDIR" ] ; then
48 echo "tempdir '$TEMPDIR' already exists."
53 # Use the local copy of executables first, instead of system ones.
54 # This should help us test without installing.
55 export PATH="$TESTDIR"/../src:"$TESTDIR"/../src/keytrans:"$PATH"
57 export MONKEYSPHERE_SYSDATADIR="$TEMPDIR"
58 export MONKEYSPHERE_SYSCONFIGDIR="$TEMPDIR"
59 export MONKEYSPHERE_SYSSHAREDIR="$TESTDIR"/../src
60 export MONKEYSPHERE_MONKEYSPHERE_USER="$USER"
61 export MONKEYSPHERE_CHECK_KEYSERVER=false
63 SSHD_CONFIG="$TEMPDIR"/sshd_config
64 export SOCKET="$TEMPDIR"/ssh-socket
69 # setup monkeysphere temp gnupghome directories
70 mkdir -p -m 750 "$MONKEYSPHERE_SYSDATADIR"/gnupg-host
71 mkdir -p -m 700 "$MONKEYSPHERE_SYSDATADIR"/gnupg-authentication
72 cat <<EOF > "$MONKEYSPHERE_SYSDATADIR"/gnupg-authentication/gpg.conf
73 primary-keyring ${MONKEYSPHERE_SYSDATADIR}/gnupg-authentication/pubring.gpg
74 keyring ${MONKEYSPHERE_SYSDATADIR}/gnupg-host/pubring.gpg
77 # create a new host key
78 echo "### generating server key..."
79 # add gpg.conf with quick-random
80 echo "quick-random" >> "$MONKEYSPHERE_SYSCONFIGDIR"/gnupg-host/gpg.conf
81 echo | monkeysphere-server gen-key --length 1024 --expire 0 testhost
83 rm "$MONKEYSPHERE_SYSCONFIGDIR"/gnupg-host/gpg.conf
85 HOSTKEYID=$( monkeysphere-server show-key | tail -n1 | cut -f3 -d\ )
87 # certify it with the "Admin's Key".
88 # (this would normally be done via keyservers)
89 echo "### certifying server key..."
90 monkeysphere-server gpg-authentication-cmd "--armor --export $HOSTKEYID" | gpgadmin --import
91 echo y | gpgadmin --command-fd 0 --sign-key "$HOSTKEYID"
93 # FIXME: how can we test publish-key without flooding junk into the
96 # add admin as identity certifier for testhost
97 echo "### adding admin as certifier..."
98 echo y | monkeysphere-server add-identity-certifier "$TESTDIR"/home/admin/.gnupg/pubkey.gpg
100 # initialize base sshd_config
101 cp etc/ssh/sshd_config "$SSHD_CONFIG"
102 # write the sshd_config
103 cat <<EOF >> "$SSHD_CONFIG"
104 HostKey ${MONKEYSPHERE_SYSDATADIR}/ssh_host_rsa_key
105 AuthorizedKeysFile ${MONKEYSPHERE_SYSDATADIR}/authorized_keys/%u
108 # launch test sshd with the new host key.
109 echo "### starting sshd..."
110 socat EXEC:"/usr/sbin/sshd -f ${SSHD_CONFIG} -i -d -d -d -D -e" "UNIX-LISTEN:${SOCKET}" 2> "$TEMPDIR"/sshd.log &
116 # copy testuser home directory into temp dir
117 echo "### seting up testuser home..."
118 cp -r "$TESTDIR"/home/testuser "$TEMPDIR"/
120 # generate an auth subkey for the test user
121 echo "### generating key for testuser..."
122 MONKEYSPHERE_GNUPGHOME="$TEMPDIR"/testuser/.gnupg \
123 monkeysphere gen-subkey --expire 0
125 # add server key to testuser keychain
126 echo "### export server key to testuser..."
127 gpgadmin --armor --export "$HOSTKEYID" | \
128 GNUPGHOME="$TEMPDIR"/testuser/.gnupg gpg --import
130 # connect to test sshd, using monkeysphere to verify the identity
132 echo "### testuser connecting to sshd socket..."
133 PROXY_COMMAND="monkeysphere-ssh-proxycommand --no-connect %h && socat STDIO UNIX:${SOCKET}"
134 GNUPGHOME="$TEMPDIR"/testuser/.gnupg ssh -oProxyCommand="$PROXY_COMMAND" testhost
136 # create a new client side key, certify it with the "CA", use it to