3 ### Test script for the main server
5 ### (c) 2008 Straylight/Edgeware
8 ###----- Licensing notice ---------------------------------------------------
10 ### This file is part of Trivial IP Encryption (TrIPE).
12 ### TrIPE is free software; you can redistribute it and/or modify
13 ### it under the terms of the GNU General Public License as published by
14 ### the Free Software Foundation; either version 2 of the License, or
15 ### (at your option) any later version.
17 ### TrIPE is distributed in the hope that it will be useful,
18 ### but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ### GNU General Public License for more details.
22 ### You should have received a copy of the GNU General Public License
23 ### along with TrIPE; if not, write to the Free Software Foundation,
24 ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 ## Configure a directory ready for use by tripe.
30 m4_define([SETUPDIR], [
31 cp $abs_top_srcdir/t/keyring-$1 ./keyring
32 key extract -f-secret keyring.pub
35 ## Running standard programs with useful options.
37 [$abs_top_builddir/server/tripe -F -d. -aadmin -p0 -b127.0.0.1 -talice])
38 m4_define([TRIPECTL], [$abs_top_builddir/client/tripectl -d. -aadmin])
39 m4_define([USLIP], [$abs_top_builddir/uslip/tripe-uslip])
41 ## Sequences. (These are used for testing the replay protection machinery.)
42 m4_define([R32], [ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 dnl
43 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31])
44 m4_define([P32], [21 26 14 12 25 18 2 27 10 31 24 29 0 20 17 11 dnl
45 8 3 7 23 19 1 13 30 6 9 5 22 15 28 16 4])
47 ###--------------------------------------------------------------------------
48 ### Scaffolding for running a TrIPE server.
50 m4_define([WITH_TRIPEX], [
52 ## Remove the status file. This is how we notice that the server's died.
53 rm -f $1/server-status
54 > $1/expected-server-output
55 > $1/expected-server-errors
57 ## Keep Autotest writes crap to standard output, which we don't want going to
58 ## the server. So keep a copy of the standard output, do the pipe, and
59 ## recover the old stdout inside the group.
64 ## Wait for the socket to appear. Watch for the server crashing during
65 ## initialization. Busy waiting is evil, but it's the best I can do and
66 ## not sleep for ages. (Yes, a second on each test group is a long time.)
67 while test ! -r $1//server-status && test ! -S $1/admin; do :; done
72 ## End of the test, now run the server.
76 strace -f -o tripe.trace TRIPE $2 >server-output 2>server-errors
78 echo $stat >server-status
79 if test $stat -ne 0; then
80 echo "exit status: $stat" >>server-errors
85 ## Now check that the server's output matches our expectations.
86 mv $1/expected-server-output expout
87 mv $1/expected-server-errors experr
88 AT_CHECK([cat $1/server-output; cat >&2 $1/server-errors],,
92 m4_define([WITH_TRIPE], [WITH_TRIPEX([.], [$1], [$2])])
94 m4_define([WITH_2TRIPES],
95 [WITH_TRIPEX([$1], [$3 $4], [WITH_TRIPEX([$2], [$3 $5], [$6])])])
97 ###--------------------------------------------------------------------------
98 ### Very unpleasant coprocess handling.
100 ## COPROCESSES(TAG, PROC-A, PROC-B)
101 m4_define([COPROCESSES], [dnl
102 rm -f pipe-$1; mknod pipe-$1 p
103 { { $2 nl } <pipe-$1 | { $3 nl } >pipe-$1; } dnl
106 ## TRIPECTL_INTERACT(ARGS, SHELLSTUFF)
107 m4_define([TRIPECTL_INTERACT], [
109 COPROCESSES([client], [exec 4>&1 1>&3 $2], [TRIPECTL $1])
112 ## TRIPECTL_COMMAND(CMD, EXPECT)
113 m4_define([TRIPECTL_COMMAND], [
115 m4_if([$1], [!], [:], [echo "$1" >&4])
119 *) echo 2>&1 "submitted $1: expected $2, found $line"; exit 1 ;;
125 ###--------------------------------------------------------------------------
126 ### Make sure the thing basically works.
128 AT_SETUP([server basics])
130 AT_CHECK([echo port | TRIPE -p54321],, [INFO 54321[]nl[]OK[]nl])
133 ###--------------------------------------------------------------------------
136 AT_SETUP([server challenges])
142 AT_CHECK([chal=$(TRIPECTL GETCHAL); TRIPECTL checkchal $chal])
144 ## A wrong challenge. (This was valid once, but the probablity that the
145 ## server chose the same key is negligible.)
146 AT_CHECK([TRIPECTL checkchal AAAAAHyoOL+HMaE0Y9B3ivuszt0], [1],,
147 [tripectl: invalid-challenge[]nl])
148 echo WARN CHAL incorrect-tag >>expected-server-output
150 ## A duplicated challenge.
152 chal=$(TRIPECTL GETCHAL)
153 TRIPECTL CHECKCHAL $chal
154 TRIPECTL CHECKCHAL $chal
155 ], [1],, [tripectl: invalid-challenge[]nl])
156 echo WARN CHAL replay duplicated-sequence >>expected-server-output
158 ## Out-of-order reception. There should be a window of 32 challenges; we
159 ## make 33 and check them in a strange order.
161 echo "tripectl: invalid-challenge" >>experr
162 echo "WARN CHAL replay old-sequence" >>expected-server-output
164 echo "tripectl: invalid-challenge" >>experr
165 echo "WARN CHAL replay duplicated-sequence" >>expected-server-output
169 ## Make the challenges.
170 for i in old R32; do TRIPECTL GETCHAL >chal-$i || exit 2; done
172 ## Now check them back.
173 for i in P32; do TRIPECTL CHECKCHAL $(cat chal-$i) || exit 3; done
175 ## Check the one which should have fallen off the front.
176 TRIPECTL CHECKCHAL $(cat chal-old) && exit 4
178 ## And make sure that the others are now considered duplicates.
179 for i in R32; do TRIPECTL CHECKCHAL $(cat chal-$i) && exit 5; done
181 ## All done: tidy cruft away.
189 ###--------------------------------------------------------------------------
192 AT_SETUP([server communication])
194 export TRIPE_SLIPIF=USLIP
196 for i in alice bob; do (mkdir $i; cd $i; SETUPDIR([ec])); done
198 WITH_2TRIPES([alice], [bob], [-nslip], [-talice], [-tbob], [
200 AT_CHECK([TRIPECTL -dalice PORT],, [stdout])
203 AT_CHECK([TRIPECTL -dbob PORT],, [stdout])
206 ## Watch for the key-exchange completion announcement, and then exit.
207 COPROCESSES([wait], [
212 "NOTE KXDONE "*) break ;;
221 ## Don't panic if you don't see the unexpected-source warning. It happens
222 ## for me, but it's not important either way.
223 AT_CHECK([TRIPECTL -dalice ADD bob INET 127.0.0.1 $(cat bob/port)])
224 echo >>bob/expected-server-output \
225 "WARN PEER - unexpected-source INET 127.0.0.1 $(cat alice/port)"
226 AT_CHECK([TRIPECTL -dbob ADD alice INET 127.0.0.1 $(cat alice/port)])
228 ## Check transport pinging.
229 AT_CHECK([TRIPECTL -dalice PING bob],, [ignore])
230 AT_CHECK([TRIPECTL -dbob PING alice],, [ignore])
232 ## Wait for the completion announcement.
235 ## Check encrypted pinging.
236 AT_CHECK([TRIPECTL -dalice EPING bob],, [ignore])
237 AT_CHECK([TRIPECTL -dbob EPING alice],, [ignore])
239 ## Check that packets can flow from one to the other.
240 AT_CHECK([echo "from alice" | USLIP -p alice/bob])
241 AT_CHECK([USLIP -g bob/alice],, [from alice[]nl])
243 AT_CHECK([echo "from bob" | USLIP -p bob/alice])
244 AT_CHECK([USLIP -g alice/bob],, [from bob[]nl])
249 ###--------------------------------------------------------------------------
252 AT_SETUP([server services])
258 ## Make sure it's not running yet.
259 AT_CHECK([TRIPECTL SVCENSURE test], [1],,
260 [tripectl: unknown-service test[]nl])
262 ## Run a simple service.
263 rm -f svc-test-running tripectl-status
265 echo SVCCLAIM test 1.0.0
271 echo >&2 "SVCCLAIM failed: $line"
275 echo ok >svc-test-running
278 case "$[]1,$[]3,$[]4" in
280 echo SVCINFO try not to use this service for anything useful
287 echo SVCFAIL $[]2 this-command-always-fails
293 case "$[]1,$[]2,$[]3,$[]4" in
294 SVCCANCEL,$tag,,) break ;;
295 SVCJOB,*,test,ESCAPE)
296 echo >&2 "attempt to escape from alkatraz"
310 echo SVCFAIL $[]2 unknown-svc-command $[]4
318 echo "failure in service: $line" >&2
323 TRIPECTL; echo $? >tripectl-status
324 ]) 2>tripectl-errors &
326 ## Wait until it starts up.
327 while test ! -r svc-test-running && test ! -r tripectl-status; do :; done
329 ## Make sure it's running.
330 AT_CHECK([TRIPECTL SVCQUERY test],, [name=test version=1.0.0[]nl])
332 ## Try some simple commands.
333 AT_CHECK([TRIPECTL SVCSUBMIT test GOOD])
334 AT_CHECK([TRIPECTL SVCSUBMIT test BAD], [1],,
335 [tripectl: this-command-always-fails[]nl])
337 ## And now with commands in the background.
339 TRIPECTL_COMMAND([SVCSUBMIT test GOOD], [OK])
340 TRIPECTL_COMMAND([SVCSUBMIT -background foo test UGLY], [BGDETACH foo])
341 TRIPECTL_COMMAND([BGCANCEL foo], [OK])
342 TRIPECTL_COMMAND([SVCSUBMIT test ESCAPE],
343 [FAIL unknown-svc-command ESCAPE])
346 ## Out-of-order completion.
348 TRIPECTL_COMMAND([SVCSUBMIT -background one test FIRST], [BGDETACH one])
349 TRIPECTL_COMMAND([SVCSUBMIT -background two test SECOND], [BGDETACH two])
350 TRIPECTL_COMMAND([!], [BGOK one])
351 TRIPECTL_COMMAND([!], [BGOK two])
360 ###----- That's all, folks --------------------------------------------------