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 [env TRIPE_PRIVHELPER=$abs_top_builddir/priv/tripe-privhelper \
38 $abs_top_builddir/server/tripe -F -d. -aadmin -p0 -b127.0.0.1 -talice])
39 m4_define([TRIPECTL], [$abs_top_builddir/client/tripectl -d. -aadmin])
40 m4_define([USLIP], [$abs_top_builddir/uslip/tripe-uslip])
42 ## Sequences. (These are used for testing the replay protection machinery.)
43 m4_define([R32], [ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 dnl
44 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31])
45 m4_define([P32], [21 26 14 12 25 18 2 27 10 31 24 29 0 20 17 11 dnl
46 8 3 7 23 19 1 13 30 6 9 5 22 15 28 16 4])
48 ###--------------------------------------------------------------------------
49 ### Scaffolding for running a TrIPE server.
51 ## WITH_TRIPEX(dir, args, body)
52 m4_define([WITH_TRIPEX], [
54 ## If this directory doesn't exist then Bad Things will happen.
56 echo >&2 "server directory \`$1' doesn't exist"
60 ## Remove the status file. This is how we notice that the server's died.
61 rm -f $1/server-status
62 > $1/expected-server-output
63 > $1/expected-server-errors
65 ## Autotest writes crap to standard output, which we don't want going to the
66 ## server. So keep a copy of the standard output, do the pipe, and recover
67 ## the old stdout inside the group.
72 ## Wait for the socket to appear. Watch for the server crashing during
73 ## initialization. Busy waiting is evil, but it's the best I can do and
74 ## not sleep for ages. (Yes, a second on each test group is a long time.)
75 while test ! -r $1/server-status && test ! -S $1/admin; do :; done
77 ## Make the port number availale.
78 AT_CHECK([TRIPECTL -d$1 PORT],, [stdout])
84 ## End of the test, now run the server. There's an awful hack here. If a
85 ## process running under strace exits with a signal, then strace will kill
86 ## itself with the same signal -- and therefore clobber the original
87 ## process's core file. So we arrange to run strace in one directory and
88 ## have the child process run in another.
94 ulimit -c hard >/dev/null 2>&1
95 strace -f -o ../tripe.trace \
96 TRIPE -d.. $2 >../server-output.full 2>../server-errors)
98 echo $stat >server-status
99 if test $stat -ne 0; then
100 echo "exit status: $stat" >>server-errors
103 ## We interrupt this relatively sensible macro for an especially awful
104 ## hack. The tripe server emits warnings which are often caused by lack of
105 ## synchronization between two peers. These are harmless and shouldn't
106 ## cause test failures. But we shouldn't just trim out all messages that
107 ## look like the spurious ones: if they appear when we're not expecting
108 ## them, that's bad and they should properly cause a test failure.
110 ## So we use the WARN command to insert magic directives into the server's
111 ## message stream. The directives begin with `WARN USER test'; remaining
112 ## tokens may be as follows.
114 ## PUSH Introduce a new layer of nesting. Settings between
115 ## this PUSH and the matching POP will be forgotten
116 ## following the POP.
118 ## POP End a layer of nesting. See PUSH above.
120 ## IGNORE tokens Ignore lines which begin with the tokens.
122 ## Token comparison isn't done very well, but it's good enough for these
125 ## We also trim out trace lines here, since it's useful to produce them for
126 ## debugging purposes and changing or introducing more of them shouldn't
133 $[]1 == "TRACE" { next; }
134 $[]1 == "WARN" && $[]2 == "USER" && $[]3 == "test" {
136 npatstk[[sp++]] = npat;
137 else if ($[]4 == "IGNORE") {
140 for (i = 5; i <= NF; i++) {
145 } else if ($[]4 == "POP")
146 npat = npatstk[[--sp]];
150 for (i = 0; i < npat; i++) {
151 n = length(pat[[i]]);
152 if (substr($[]0, 0, n) == pat[[i]])
157 ' server-output.full >server-output
161 ## Now check that the server's output matches our expectations.
162 mv $1/expected-server-output expout
163 mv $1/expected-server-errors experr
164 AT_CHECK([cat $1/server-output; cat >&2 $1/server-errors],,
168 ## WITH_TRIPE(args, body)
169 m4_define([WITH_TRIPE], [WITH_TRIPEX([.], [$1], [$2])])
171 ## WITH_2TRIPES(adir, bdir, bothargs, aargs, bargs, body)
172 m4_define([WITH_2TRIPES],
173 [WITH_TRIPEX([$1], [$3 $4], [WITH_TRIPEX([$2], [$3 $5], [$6])])])
175 ## WITH_3TRIPES(adir, bdir, cdir, allargs, aargs, bargs, cargs, body)
176 m4_define([WITH_3TRIPES],
177 [WITH_TRIPEX([$1], [$4 $5],
178 [WITH_TRIPEX([$2], [$4 $6],
179 [WITH_TRIPEX([$3], [$4 $7],
182 ## COMMS_EPING(adir, aname, bdir, bname)
183 m4_define([COMMS_EPING], [
184 AT_CHECK([TRIPECTL -d$1 EPING $4],, [ignore])
185 AT_CHECK([TRIPECTL -d$3 EPING $2],, [ignore])
188 ## COMMS_SLIP(adir, aname, bdir, bname)
189 m4_define([COMMS_SLIP], [
190 AT_CHECK([echo "from $1" | USLIP -p $1/$4])
191 AT_CHECK([USLIP -g $3/$2],, [from $1[]nl])
192 AT_CHECK([echo "from $3" | USLIP -p $3/$2])
193 AT_CHECK([USLIP -g $1/$4],, [from $3[]nl])
196 ## AWAIT_KXDONE(adir, aname, bdir, bname, body)
197 m4_define([AWAIT_KXDONE], [
199 ## Ignore some reports caused by races.
200 TRIPECTL -d$3 WARN test PUSH
201 TRIPECTL -d$3 WARN test IGNORE WARN KX $2 incorrect cookie
202 TRIPECTL -d$3 WARN test IGNORE WARN KX $2 unexpected pre-challenge
204 ## Watch for the key-exchange completion announcement in the background.
205 COPROCESSES([wait-$1], [
210 case "$[]1:$[]2:$[]3" in
212 NOTE:KXDONE:$4) break ;;
223 ## Collect the completion announcement.
224 wait $waiter_$1; waitrc=$?
225 AT_CHECK([echo $waitrc],, [0[]nl])
227 ## Be interested in key-exchange warnings again.
228 TRIPECTL -d$4 WARN test POP
231 ## ESTABLISH(adir, aname, aopts, bdir, bname, bopts)
232 m4_define([ESTABLISH], [
234 ## Set up the establishment.
235 AWAIT_KXDONE([$1], [$2], [$4], [$5], [
236 AT_CHECK([TRIPECTL -d$1 ADD -cork $6 $5 INET 127.0.0.1 $(cat $4/port)])
237 AT_CHECK([TRIPECTL -d$4 ADD $3 $2 INET 127.0.0.1 $(cat $1/port)])
240 ## Check transport pinging.
241 AT_CHECK([TRIPECTL -d$1 PING $5],, [ignore])
242 AT_CHECK([TRIPECTL -d$4 PING $2],, [ignore])
244 ## Check communication works.
245 COMMS_EPING([$1], [$2], [$4], [$5])
246 COMMS_SLIP([$1], [$2], [$4], [$5])
249 ###--------------------------------------------------------------------------
250 ### Very unpleasant coprocess handling.
252 ## COPROCESSES(TAG, PROC-A, PROC-B)
253 m4_define([COPROCESSES], [dnl
254 rm -f pipe-$1; mknod pipe-$1 p
255 { { $2 nl } <pipe-$1 | { $3 nl } >pipe-$1; } dnl
258 ## TRIPECTL_INTERACT(ARGS, SHELLSTUFF)
259 m4_define([TRIPECTL_INTERACT], [
261 COPROCESSES([client], [exec 4>&1 1>&3 $1], [TRIPECTL $2])
264 ## TRIPECTL_COMMAND(CMD, EXPECT)
265 m4_define([TRIPECTL_COMMAND], [
267 m4_if([$1], [!], [:], [echo "$1" >&4])
271 *) echo 2>&1 "submitted $1: expected $2, found $line"; exit 1 ;;
277 ###--------------------------------------------------------------------------
278 ### Make sure the thing basically works.
280 AT_SETUP([server basics])
282 AT_CHECK([echo port | TRIPE -p54321],, [INFO 54321[]nl[]OK[]nl])
285 ###--------------------------------------------------------------------------
288 AT_SETUP([server challenges])
294 AT_CHECK([chal=$(TRIPECTL GETCHAL); TRIPECTL checkchal $chal])
296 ## A wrong challenge. (This was valid once, but the probablity that the
297 ## server chose the same key is negligible.)
298 AT_CHECK([TRIPECTL checkchal AAAAAHyoOL+HMaE0Y9B3ivuszt0], [1],,
299 [tripectl: invalid-challenge[]nl])
300 echo WARN CHAL incorrect-tag >>expected-server-output
302 ## A duplicated challenge.
304 chal=$(TRIPECTL GETCHAL)
305 TRIPECTL CHECKCHAL $chal
306 TRIPECTL CHECKCHAL $chal
307 ], [1],, [tripectl: invalid-challenge[]nl])
308 echo WARN CHAL replay duplicated-sequence >>expected-server-output
310 ## Out-of-order reception. There should be a window of 32 challenges; we
311 ## make 33 and check them in a strange order.
313 echo "tripectl: invalid-challenge" >>experr
314 echo "WARN CHAL replay old-sequence" >>expected-server-output
316 echo "tripectl: invalid-challenge" >>experr
317 echo "WARN CHAL replay duplicated-sequence" >>expected-server-output
321 ## Make the challenges.
322 for i in old R32; do TRIPECTL GETCHAL >chal-$i || exit 2; done
324 ## Now check them back.
325 for i in P32; do TRIPECTL CHECKCHAL $(cat chal-$i) || exit 3; done
327 ## Check the one which should have fallen off the front.
328 TRIPECTL CHECKCHAL $(cat chal-old) && exit 4
330 ## And make sure that the others are now considered duplicates.
331 for i in R32; do TRIPECTL CHECKCHAL $(cat chal-$i) && exit 5; done
333 ## All done: tidy cruft away.
341 ###--------------------------------------------------------------------------
344 AT_SETUP([server communication])
346 export TRIPE_SLIPIF=USLIP
348 for p in alice bob; do (mkdir $p; cd $p; SETUPDIR([alpha])); done
350 WITH_2TRIPES([alice], [bob], [-nslip], [-talice], [-tbob], [
351 ESTABLISH([alice], [not-alice], [-key alice],
357 ###--------------------------------------------------------------------------
360 AT_SETUP([server services])
366 ## Make sure it's not running yet.
367 AT_CHECK([TRIPECTL SVCENSURE test], [1],,
368 [tripectl: unknown-service test[]nl])
370 ## Run a simple service.
371 rm -f svc-test-running tripectl-status
373 echo SVCCLAIM test 1.0.0
379 echo >&2 "SVCCLAIM failed: $line"
383 echo ok >svc-test-running
386 case "$[]1,$[]3,$[]4" in
388 echo SVCINFO try not to use this service for anything useful
395 echo SVCFAIL $[]2 this-command-always-fails
401 case "$[]1,$[]2,$[]3,$[]4" in
402 SVCCANCEL,$tag,,) break ;;
403 SVCJOB,*,test,ESCAPE)
404 echo >&2 "attempt to escape from alkatraz"
418 echo SVCFAIL $[]2 unknown-svc-command $[]4
426 echo "failure in service: $line" >&2
431 TRIPECTL; echo $? >tripectl-status
432 ]) 2>tripectl-errors &
434 ## Wait until it starts up.
435 while test ! -r svc-test-running && test ! -r tripectl-status; do :; done
437 ## Make sure it's running.
438 AT_CHECK([TRIPECTL SVCQUERY test],, [name=test version=1.0.0[]nl])
440 ## Try some simple commands.
441 AT_CHECK([TRIPECTL SVCSUBMIT test GOOD])
442 AT_CHECK([TRIPECTL SVCSUBMIT test BAD], [1],,
443 [tripectl: this-command-always-fails[]nl])
445 ## And now with commands in the background.
447 TRIPECTL_COMMAND([SVCSUBMIT test GOOD], [OK])
448 TRIPECTL_COMMAND([SVCSUBMIT -background foo test UGLY], [BGDETACH foo])
449 TRIPECTL_COMMAND([BGCANCEL foo], [OK])
450 TRIPECTL_COMMAND([SVCSUBMIT test ESCAPE],
451 [FAIL unknown-svc-command ESCAPE])
454 ## Out-of-order completion.
456 TRIPECTL_COMMAND([SVCSUBMIT -background one test FIRST], [BGDETACH one])
457 TRIPECTL_COMMAND([SVCSUBMIT -background two test SECOND], [BGDETACH two])
458 TRIPECTL_COMMAND([!], [BGOK one])
459 TRIPECTL_COMMAND([!], [BGOK two])
468 ###----- That's all, folks --------------------------------------------------