Merge commit 'dkg/master'
[monkeysphere.git] / tests / basic
1 #!/usr/bin/env bash
2
3 # Tests to ensure that the monkeysphere is working
4
5 # Author: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
6 # Date: 2008-09-13 13:40:15-0400
7
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.
11
12 # NOTE: these tests have *not* themselves been tested yet
13 # (2008-09-13).  Please exercise with caution!
14
15 # these tests assume a commonly-trusted "Admin's key", a fake key
16 # permanently stored in ./home/admin/.gnupg:
17 gpgadmin() {
18     GNUPGHOME="$TESTDIR"/home/admin/.gnupg gpg "$@"
19 }
20
21
22 # cleanup:
23 cleanup() {
24     # FIXME: stop the sshd process
25
26     echo
27     echo "### removing temp dir..."
28     rm -rf "$TEMPDIR"
29
30     # FIXME: how should we clear out the temporary $VARLIB?
31
32     # FIXME: clear out ssh client config file and known hosts.
33 }
34
35 ## setup trap
36 #trap cleanup EXIT
37
38 ## set up some variables to ensure that we're operating strictly in
39 ## the tests, not system-wide:
40
41 export TESTDIR=$(pwd)
42
43 # make temp dir
44 TEMPDIR="$TESTDIR"/tmp
45 if [ -e "$TEMPDIR" ] ; then
46     echo "tempdir '$TEMPDIR' already exists."
47     exit 1
48 fi
49 mkdir "$TEMPDIR"
50
51 # Use the local copy of executables first, instead of system ones.
52 # This should help us test without installing.
53 export PATH="$TESTDIR"/../src:"$TESTDIR"/../src/keytrans:"$PATH"
54
55 export MONKEYSPHERE_SYSDATADIR="$TEMPDIR"
56 export MONKEYSPHERE_SYSCONFIGDIR="$TEMPDIR"
57 export MONKEYSPHERE_SYSSHAREDIR="$TESTDIR"/../src
58 export MONKEYSPHERE_MONKEYSPHERE_USER="$USER"
59 export MONKEYSPHERE_CHECK_KEYSERVER=false
60
61 SSHD_CONFIG="$TEMPDIR"/sshd_config
62 export SOCKET="$TEMPDIR"/ssh-socket
63
64 ### SERVER TESTS
65
66 # create the temp gnupghome directories
67 mkdir -p -m 750 "$MONKEYSPHERE_SYSDATADIR"/gnupg-host
68 mkdir -p -m 700 "$MONKEYSPHERE_SYSDATADIR"/gnupg-authentication
69
70 # add the quick-random option to the gpg host config
71 echo "quick-random" >> "$MONKEYSPHERE_SYSCONFIGDIR"/gnupg-host.conf
72
73 # create a new host key
74 echo "### generating server key..."
75 echo | monkeysphere-server gen-key --length 1024 --expire 0 testhost
76
77 HOSTKEYID=$( monkeysphere-server show-key | tail -n1 | cut -f3 -d\  )
78
79 # certify it with the "Admin's Key".
80 # (this would normally be done via keyservers)
81 echo "### certifying server key..."
82 monkeysphere-server gpg-authentication-cmd "--armor --export $HOSTKEYID" | gpgadmin --import
83 gpgadmin --sign-key "$HOSTKEYID"
84
85 # FIXME: how can we test publish-key without flooding junk into the
86 # keyservers?
87
88 # indicate that the "Admin's" key is an identity certifier for the
89 # host
90
91 echo "### adding admin as certifier..."
92 monkeysphere-server add-identity-certifier "$TESTDIR"/home/admin/.gnupg/pubkey.gpg
93
94 # initialize base sshd_config
95 cp etc/ssh/sshd_config "$TEMPDIR"/sshd_config
96 # write the sshd_config
97 cat <<EOF >> "$SSHD_CONFIG"
98 HostKey ${MONKEYSPHERE_SYSDATADIR}/ssh_host_rsa_key
99 AuthorizedKeysFile ${MONKEYSPHERE_SYSDATADIR}/authorized_keys/%u
100 EOF
101
102 # launch test sshd with the new host key.
103 echo "### starting sshd..."
104 socat EXEC:'/usr/sbin/sshd -f '"$SSHD_CONFIG"' -i -d -d -d -D -e' "UNIX-LISTEN:${SOCKET}" &
105
106
107 ### TESTUSER TESTS
108
109 # copy testuser home directory into temp dir
110 cp -r "$TESTDIR"/home/testuser "$TEMPDIR"/
111
112 # generate an auth subkey for the test user
113 echo "### generating key for testuser..."
114 MONKEYSPHERE_GNUPGHOME="$TEMPDIR"/testuser/.gnupg \
115     monkeysphere gen-subkey --expire 0
116
117 # connect to test sshd, using monkeysphere to verify the identity
118 # before connection.
119 echo "### connecting to sshd socket..."
120 PROXY_COMMAND="monkeysphere-ssh-proxycommand --no-connect %h && socat STDIO UNIX:${SOCKET}"
121 ssh -oProxyCommand="$PROXY_COMMAND" testhost
122
123 # create a new client side key, certify it with the "CA", use it to
124 # log in.
125
126 ## FIXME: implement!