Merge commit 'jrollins/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 mkdir "$TEMPDIR"
46
47 # Use the local copy of executables first, instead of system ones.
48 # This should help us test without installing.
49 export PATH="$TESTDIR"/../src:"$TESTDIR"/../src/keytrans:"$PATH"
50
51 export MONKEYSPHERE_SYSDATADIR="$TEMPDIR"
52 export MONKEYSPHERE_SYSCONFIGDIR="$TEMPDIR"
53 export MONKEYSPHERE_SYSSHAREDIR="$TESTDIR"/../src
54 export MONKEYSPHERE_MONKEYSPHERE_USER="$USER"
55 export SOCKET="$TEMPDIR"/ssh-socket
56
57 ### SERVER TESTS
58
59 # create the temp gnupghome directories
60 mkdir -p -m 750 "$MONKEYSPHERE_SYSDATADIR"/gnupg-host
61 mkdir -p -m 700 "$MONKEYSPHERE_SYSDATADIR"/gnupg-authentication
62
63 # create a new host key
64 echo "-- generating server key..."
65 echo | monkeysphere-server gen-key --length 1024 --expire 0
66
67 HOSTKEYID=$( monkeysphere-server show-key | tail -n1 | cut -f3 -d\  )
68
69 # certify it with the "Admin's Key".
70 # (this would normally be done via keyservers)
71 echo "-- certifying server key..."
72 monkeysphere-server gpg-authentication-cmd "--armor --export $HOSTKEYID" | gpgadmin --import
73 gpgadmin --sign-key "$HOSTKEYID"
74
75 # FIXME: how can we test publish-key without flooding junk into the
76 # keyservers?
77
78 # indicate that the "Admin's" key is an identity certifier for the
79 # host
80
81 echo "-- adding admin as certifier..."
82 monkeysphere-server add-identity-certifier "$TESTDIR"/home/admin/.gnupg/pubkey.gpg
83
84 # initialize base sshd_config
85 cp etc/ssh/sshd_config "$TEMPDIR"/sshd_config
86 # write the sshd_config
87 cat <<EOF >> "$TEMPDIR"/sshd_config
88 HostKey ${MONKEYSPHERE_SYSDATADIR}/ssh_host_rsa_key
89 AuthorizedKeysFile ${MONKEYSPHERE_SYSDATADIR}/authorized_keys/%u
90 EOF
91
92 # launch sshd with the new host key.
93 echo "-- starting sshd..."
94 socat EXEC:'/usr/sbin/sshd -f '"$TEMPDIR"/sshd_config' -i -d -d -d -D -e' "UNIX-LISTEN:${TEMPDIR/socket}" &
95
96
97 ### TESTUSER TESTS
98
99 # copy testuser home directory into temp dir
100 cp -r "$TESTDIR"/home/testuser "$TEMPDIR"/
101
102 # generate an auth subkey for the test user
103 echo "-- generating key for testuser..."
104 MONKEYSPHERE_GNUPGHOME="$TEMPDIR"/testuser/.gnupg \
105     monkeysphere gen-subkey --expire 0
106
107 # connect to sample sshd host key, using monkeysphere to verify the
108 # identity before connection.
109
110 ## FIXME: implement!
111
112 # create a new client side key, certify it with the "CA", use it to
113 # log in.
114
115 ## FIXME: implement!
116