t_tcpip.sh revision 1.1.2.3 1 1.1.2.3 bouyer # $NetBSD: t_tcpip.sh,v 1.1.2.3 2011/02/17 12:00:54 bouyer Exp $
2 1.1.2.2 bouyer #
3 1.1.2.2 bouyer # Copyright (c) 2011 The NetBSD Foundation, Inc.
4 1.1.2.2 bouyer # All rights reserved.
5 1.1.2.2 bouyer #
6 1.1.2.2 bouyer # Redistribution and use in source and binary forms, with or without
7 1.1.2.2 bouyer # modification, are permitted provided that the following conditions
8 1.1.2.2 bouyer # are met:
9 1.1.2.2 bouyer # 1. Redistributions of source code must retain the above copyright
10 1.1.2.2 bouyer # notice, this list of conditions and the following disclaimer.
11 1.1.2.2 bouyer # 2. Redistributions in binary form must reproduce the above copyright
12 1.1.2.2 bouyer # notice, this list of conditions and the following disclaimer in the
13 1.1.2.2 bouyer # documentation and/or other materials provided with the distribution.
14 1.1.2.2 bouyer #
15 1.1.2.2 bouyer # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 1.1.2.2 bouyer # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 1.1.2.2 bouyer # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 1.1.2.2 bouyer # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 1.1.2.2 bouyer # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 1.1.2.2 bouyer # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 1.1.2.2 bouyer # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 1.1.2.2 bouyer # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 1.1.2.2 bouyer # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 1.1.2.2 bouyer # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 1.1.2.2 bouyer # POSSIBILITY OF SUCH DAMAGE.
26 1.1.2.2 bouyer #
27 1.1.2.2 bouyer
28 1.1.2.2 bouyer rumpnetsrv='rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet'
29 1.1.2.2 bouyer export RUMP_SERVER=unix://csock
30 1.1.2.2 bouyer
31 1.1.2.2 bouyer atf_test_case http cleanup
32 1.1.2.2 bouyer http_head()
33 1.1.2.2 bouyer {
34 1.1.2.2 bouyer atf_set "descr" "Start hijacked httpd and get webpage from it"
35 1.1.2.2 bouyer }
36 1.1.2.2 bouyer
37 1.1.2.2 bouyer http_body()
38 1.1.2.2 bouyer {
39 1.1.2.2 bouyer
40 1.1.2.2 bouyer atf_check -s exit:0 ${rumpnetsrv} ${RUMP_SERVER}
41 1.1.2.2 bouyer # make sure clients die after we nuke the server
42 1.1.2.3 bouyer export RUMPHIJACK_RETRYCONNECT='die'
43 1.1.2.2 bouyer
44 1.1.2.2 bouyer # start bozo in daemon mode
45 1.1.2.3 bouyer atf_check -s exit:0 env LD_PRELOAD=/usr/lib/librumphijack.so \
46 1.1.2.2 bouyer /usr/libexec/httpd -b -s $(atf_get_srcdir)
47 1.1.2.2 bouyer
48 1.1.2.2 bouyer atf_check -s exit:0 -o file:"$(atf_get_srcdir)/netstat.expout" \
49 1.1.2.2 bouyer rump.netstat -a
50 1.1.2.2 bouyer
51 1.1.2.2 bouyer # get the webpage
52 1.1.2.2 bouyer atf_check -s exit:0 env LD_PRELOAD=/usr/lib/librumphijack.so \
53 1.1.2.2 bouyer $(atf_get_srcdir)/h_netget 127.0.0.1 80 webfile
54 1.1.2.2 bouyer
55 1.1.2.2 bouyer # check that we got what we wanted
56 1.1.2.2 bouyer atf_check -o match:'HTTP/1.0 200 OK' cat webfile
57 1.1.2.2 bouyer atf_check -o match:'Content-Length: 95' cat webfile
58 1.1.2.2 bouyer atf_check -o file:"$(atf_get_srcdir)/index.html" \
59 1.1.2.2 bouyer sed -n '1,/^
$/!p' webfile
61 1.1.2.2 bouyer }
62 1.1.2.2 bouyer
63 1.1.2.2 bouyer http_cleanup()
64 1.1.2.2 bouyer {
65 1.1.2.2 bouyer rump.halt
66 1.1.2.2 bouyer }
67 1.1.2.3 bouyer
68 1.1.2.3 bouyer #
69 1.1.2.3 bouyer # Starts a SSH server and sets up the client to access it.
70 1.1.2.3 bouyer # Authentication is allowed and done using an RSA key exclusively, which
71 1.1.2.3 bouyer # is generated on the fly as part of the test case.
72 1.1.2.3 bouyer # XXX: Ideally, all the tests in this test program should be able to share
73 1.1.2.3 bouyer # the generated key, because creating it can be a very slow process on some
74 1.1.2.3 bouyer # machines.
75 1.1.2.3 bouyer #
76 1.1.2.3 bouyer # XXX2: copypasted from jmmv's sshd thingamob in the psshfs test.
77 1.1.2.3 bouyer # ideally code (and keys, like jmmv notes above) could be shared
78 1.1.2.3 bouyer #
79 1.1.2.3 bouyer start_sshd() {
80 1.1.2.3 bouyer echo "Setting up SSH server configuration"
81 1.1.2.3 bouyer sed -e "s,@SRCDIR@,$(atf_get_srcdir),g" -e "s,@WORKDIR@,$(pwd),g" \
82 1.1.2.3 bouyer $(atf_get_srcdir)/sshd_config.in >sshd_config || \
83 1.1.2.3 bouyer atf_fail "Failed to create sshd_config"
84 1.1.2.3 bouyer atf_check -s ignore -o empty -e ignore \
85 1.1.2.3 bouyer cp $(atf_get_srcdir)/ssh_host_key .
86 1.1.2.3 bouyer atf_check -s ignore -o empty -e ignore \
87 1.1.2.3 bouyer cp $(atf_get_srcdir)/ssh_host_key.pub .
88 1.1.2.3 bouyer atf_check -s eq:0 -o empty -e empty chmod 400 ssh_host_key
89 1.1.2.3 bouyer atf_check -s eq:0 -o empty -e empty chmod 444 ssh_host_key.pub
90 1.1.2.3 bouyer
91 1.1.2.3 bouyer env LD_PRELOAD=/usr/lib/librumphijack.so \
92 1.1.2.3 bouyer /usr/sbin/sshd -e -f ./sshd_config
93 1.1.2.3 bouyer while [ ! -f sshd.pid ]; do
94 1.1.2.3 bouyer sleep 0.01
95 1.1.2.3 bouyer done
96 1.1.2.3 bouyer echo "SSH server started (pid $(cat sshd.pid))"
97 1.1.2.3 bouyer
98 1.1.2.3 bouyer echo "Setting up SSH client configuration"
99 1.1.2.3 bouyer atf_check -s eq:0 -o empty -e empty \
100 1.1.2.3 bouyer ssh-keygen -f ssh_user_key -t rsa -b 1024 -N "" -q
101 1.1.2.3 bouyer atf_check -s eq:0 -o empty -e empty \
102 1.1.2.3 bouyer cp ssh_user_key.pub authorized_keys
103 1.1.2.3 bouyer echo "127.0.0.1,localhost,::1 " \
104 1.1.2.3 bouyer "$(cat $(atf_get_srcdir)/ssh_host_key.pub)" >known_hosts || \
105 1.1.2.3 bouyer atf_fail "Failed to create known_hosts"
106 1.1.2.3 bouyer atf_check -s eq:0 -o empty -e empty chmod 600 authorized_keys
107 1.1.2.3 bouyer sed -e "s,@SRCDIR@,$(atf_get_srcdir),g" -e "s,@WORKDIR@,$(pwd),g" \
108 1.1.2.3 bouyer $(atf_get_srcdir)/ssh_config.in >ssh_config || \
109 1.1.2.3 bouyer atf_fail "Failed to create ssh_config"
110 1.1.2.3 bouyer
111 1.1.2.3 bouyer echo "sshd running"
112 1.1.2.3 bouyer }
113 1.1.2.3 bouyer
114 1.1.2.3 bouyer atf_test_case ssh cleanup
115 1.1.2.3 bouyer ssh_head()
116 1.1.2.3 bouyer {
117 1.1.2.3 bouyer atf_set "descr" "Test that hijacked ssh/sshd works"
118 1.1.2.3 bouyer }
119 1.1.2.3 bouyer
120 1.1.2.3 bouyer ssh_body()
121 1.1.2.3 bouyer {
122 1.1.2.3 bouyer
123 1.1.2.3 bouyer atf_check -s exit:0 ${rumpnetsrv} ${RUMP_SERVER}
124 1.1.2.3 bouyer # make sure clients die after we nuke the server
125 1.1.2.3 bouyer export RUMPHIJACK_RETRYCONNECT='die'
126 1.1.2.3 bouyer
127 1.1.2.3 bouyer start_sshd
128 1.1.2.3 bouyer
129 1.1.2.3 bouyer # create some sort of directory for us to "ls"
130 1.1.2.3 bouyer mkdir testdir
131 1.1.2.3 bouyer cd testdir
132 1.1.2.3 bouyer jot 11 | xargs touch
133 1.1.2.3 bouyer jot 11 12 | xargs mkdir
134 1.1.2.3 bouyer cd ..
135 1.1.2.3 bouyer
136 1.1.2.3 bouyer atf_check -s exit:0 -o save:ssh.out \
137 1.1.2.3 bouyer env LD_PRELOAD=/usr/lib/librumphijack.so \
138 1.1.2.3 bouyer ssh -T -F ssh_config 127.0.0.1 env BLOCKSIZE=512 \
139 1.1.2.3 bouyer ls -li $(pwd)/testdir
140 1.1.2.3 bouyer atf_check -s exit:0 -o file:ssh.out env BLOCKSIZE=512 \
141 1.1.2.3 bouyer ls -li $(pwd)/testdir
142 1.1.2.3 bouyer }
143 1.1.2.3 bouyer
144 1.1.2.3 bouyer ssh_cleanup()
145 1.1.2.3 bouyer {
146 1.1.2.3 bouyer rump.halt
147 1.1.2.3 bouyer # sshd dies due to RUMPHIJACK_RETRYCONNECT=1d6
148 1.1.2.3 bouyer }
149 1.1.2.2 bouyer
150 1.1.2.2 bouyer atf_init_test_cases()
151 1.1.2.2 bouyer {
152 1.1.2.3 bouyer atf_add_test_case http
153 1.1.2.2 bouyer atf_add_test_case ssh
154 }
155