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 "$@"
27 read -p "press enter to cleanup and remove tmp:"
29 # FIXME: stop the sshd process
32 echo "### removing temp dir..."
35 # FIXME: how should we clear out the temporary $VARLIB?
37 # FIXME: clear out ssh client config file and known hosts.
43 ## set up some variables to ensure that we're operating strictly in
44 ## the tests, not system-wide:
49 TEMPDIR="$TESTDIR"/tmp
50 if [ -e "$TEMPDIR" ] ; then
51 echo "tempdir '$TEMPDIR' already exists."
56 # Use the local copy of executables first, instead of system ones.
57 # This should help us test without installing.
58 export PATH="$TESTDIR"/../src:"$TESTDIR"/../src/keytrans:"$PATH"
60 export MONKEYSPHERE_SYSDATADIR="$TEMPDIR"
61 export MONKEYSPHERE_SYSCONFIGDIR="$TEMPDIR"
62 export MONKEYSPHERE_SYSSHAREDIR="$TESTDIR"/../src
63 export MONKEYSPHERE_MONKEYSPHERE_USER="$USER"
64 export MONKEYSPHERE_CHECK_KEYSERVER=false
66 SSHD_CONFIG="$TEMPDIR"/sshd_config
67 export SOCKET="$TEMPDIR"/ssh-socket
72 # setup monkeysphere temp gnupghome directories
73 mkdir -p -m 750 "$MONKEYSPHERE_SYSDATADIR"/gnupg-host
74 mkdir -p -m 700 "$MONKEYSPHERE_SYSDATADIR"/gnupg-authentication
75 cat <<EOF > "$MONKEYSPHERE_SYSDATADIR"/gnupg-authentication/gpg.conf
76 primary-keyring ${MONKEYSPHERE_SYSDATADIR}/gnupg-authentication/pubring.gpg
77 keyring ${MONKEYSPHERE_SYSDATADIR}/gnupg-host/pubring.gpg
80 # create a new host key
81 echo "### generating server key..."
82 # add gpg.conf with quick-random
83 echo "quick-random" >> "$MONKEYSPHERE_SYSCONFIGDIR"/gnupg-host/gpg.conf
84 echo | monkeysphere-server gen-key --length 1024 --expire 0 testhost
86 rm "$MONKEYSPHERE_SYSCONFIGDIR"/gnupg-host/gpg.conf
88 HOSTKEYID=$( monkeysphere-server show-key | tail -n1 | cut -f3 -d\ )
90 # certify it with the "Admin's Key".
91 # (this would normally be done via keyservers)
92 echo "### certifying server key..."
93 monkeysphere-server gpg-authentication-cmd "--armor --export $HOSTKEYID" | gpgadmin --import
94 echo y | gpgadmin --command-fd 0 --sign-key "$HOSTKEYID"
96 # FIXME: how can we test publish-key without flooding junk into the
99 # indicate that the "Admin's" key is an identity certifier for the
102 echo "### adding admin as certifier..."
103 echo y | monkeysphere-server add-identity-certifier "$TESTDIR"/home/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 &
120 # copy testuser home directory into temp dir
121 echo "### seting up testuser home..."
122 cp -r "$TESTDIR"/home/testuser "$TEMPDIR"/
124 # generate an auth subkey for the test user
125 echo "### generating key for testuser..."
126 MONKEYSPHERE_GNUPGHOME="$TEMPDIR"/testuser/.gnupg \
127 monkeysphere gen-subkey --expire 0
129 # add server key to testuser keychain
130 echo "### export server key to testuser..."
131 gpgadmin --armor --export "$HOSTKEYID" | \
132 GNUPGHOME="$TEMPDIR"/testuser/.gnupg gpg --import
134 #GNUPGHOME="$TEMPDIR"/testuser/.gnupg gpg --list-keys
137 # connect to test sshd, using monkeysphere to verify the identity
139 echo "### testuser connecting to sshd socket..."
140 PROXY_COMMAND="monkeysphere-ssh-proxycommand --no-connect %h && socat STDIO UNIX:${SOCKET}"
141 GNUPGHOME="$TEMPDIR"/testuser/.gnupg ssh -oProxyCommand="$PROXY_COMMAND" testhost
143 # create a new client side key, certify it with the "CA", use it to