chiark / gitweb /
server/tests.at (AWAIT_KXDONE): More warning suppressions.
[tripe] / server / tests.at
1 ### -*-autotest-*-
2 ###
3 ### Test script for the main server
4 ###
5 ### (c) 2008 Straylight/Edgeware
6 ###
7
8 ###----- Licensing notice ---------------------------------------------------
9 ###
10 ### This file is part of Trivial IP Encryption (TrIPE).
11 ###
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.
16 ###
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.
21 ###
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.
25
26 m4_define([nl], [
27 ])
28
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
33 ])
34
35 ## Running standard programs with useful options.
36 m4_define([TRIPE],
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])
41 m4_define([PKSTREAM],
42   [$abs_top_builddir/pkstream/pkstream -b127.0.0.1 -p127.0.0.1])
43 m4_define([MITM], [$abs_top_builddir/proxy/tripe-mitm])
44
45 ## Sequences.  (These are used for testing the replay protection machinery.)
46 m4_define([R32], [ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15   dnl
47                   16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31])
48 m4_define([P32], [21 26 14 12 25 18  2 27 10 31 24 29  0 20 17 11   dnl
49                    8  3  7 23 19  1 13 30  6  9  5 22 15 28 16  4])
50
51 ###--------------------------------------------------------------------------
52 ### Scaffolding for running a TrIPE server.
53
54 ## WITH_TRIPEX(dir, args, body)
55 m4_define([WITH_TRIPEX], [
56
57 ## If this directory doesn't exist then Bad Things will happen.
58 if test ! -d $1; then
59   echo >&2 "server directory \`$1' doesn't exist"
60   exit 99
61 fi
62
63 ## Remove the status file.  This is how we notice that the server's died.
64 rm -f $1/server-status
65 > $1/expected-server-output
66 > $1/expected-server-errors
67
68 ## Autotest writes crap to standard output, which we don't want going to the
69 ## server.  So keep a copy of the standard output, do the pipe, and recover
70 ## the old stdout inside the group.
71 exec 3>&1
72 { (
73 exec 1>&3 3>&-
74
75 ## Wait for the socket to appear.  Watch for the server crashing during
76 ## initialization.  Busy waiting is evil, but it's the best I can do and
77 ## not sleep for ages.  (Yes, a second on each test group is a long time.)
78 while test ! -r $1/server-status && test ! -S $1/admin; do :; done
79
80 ## Make the port number availale.
81 AT_CHECK([TRIPECTL -d$1 PORT],, [stdout])
82 mv stdout $1/port
83
84 ## Test body...
85 $3
86
87 ## End of the test, now run the server.  There's an awful hack here.  If a
88 ## process running under strace exits with a signal, then strace will kill
89 ## itself with the same signal -- and therefore clobber the original
90 ## process's core file.  So we arrange to run strace in one directory and
91 ## have the child process run in another.
92 ) && :; } | {
93   cd $1
94   echo TRIPE $2 >&2
95   case "${TRIPE_TEST_STRACE-nil}" in
96     nil)
97       TRIPE -d. $2 >server-output.full 2>server-errors
98       ;;
99     *)
100       mkdir -p strace-hack/
101       (cd strace-hack/
102        ulimit -c hard >/dev/null 2>&1
103        strace -f -o ../tripe.trace \
104          TRIPE -d.. $2 >../server-output.full 2>../server-errors)
105       ;;
106   esac
107   stat=$?
108   echo $stat >server-status
109   if test $stat -ne 0; then
110     echo "exit status: $stat" >>server-errors
111   fi
112
113   ## We interrupt this relatively sensible macro for an especially awful
114   ## hack.  The tripe server emits warnings which are often caused by lack of
115   ## synchronization between two peers.  These are harmless and shouldn't
116   ## cause test failures.  But we shouldn't just trim out all messages that
117   ## look like the spurious ones: if they appear when we're not expecting
118   ## them, that's bad and they should properly cause a test failure.
119   ##
120   ## So we use the WARN command to insert magic directives into the server's
121   ## message stream.  The directives begin with `WARN USER test'; remaining
122   ## tokens may be as follows.
123   ##
124   ## PUSH               Introduce a new layer of nesting.  Settings between
125   ##                    this PUSH and the matching POP will be forgotten
126   ##                    following the POP.
127   ##
128   ## POP                End a layer of nesting.  See PUSH above.
129   ##
130   ## IGNORE tokens      Ignore lines which begin with the tokens.
131   ##
132   ## Token comparison isn't done very well, but it's good enough for these
133   ## purposes.
134   ##
135   ## We also trim out trace lines here, since it's useful to produce them for
136   ## debugging purposes and changing or introducing more of them shouldn't
137   ## cause failures.
138   awk '
139         BEGIN {
140           sp = 0;
141           npat = 0;
142         }
143         $[]1 == "TRACE" { next; }
144         $[]1 == "WARN" && $[]2 == "USER" && $[]3 == "test" {
145           if ($[]4 == "PUSH")
146             npatstk[[sp++]] = npat;
147           else if ($[]4 == "IGNORE") {
148             s = "";
149             p = "";
150             for (i = 5; i <= NF; i++) {
151               p = p s $[]i;
152               s = " ";
153             }
154             pat[[npat++]] = p;
155           } else if ($[]4 == "POP")
156             npat = npatstk[[--sp]];
157           next;
158         }
159         {
160           for (i = 0; i < npat; i++) {
161             n = length(pat[[i]]);
162             if (substr($[]0, 1, n) == pat[[i]])
163               next;
164           }
165           print $[]0;
166         }
167   ' server-output.full >server-output
168 }
169 exec 3>&-
170
171 ## Now check that the server's output matches our expectations.
172 mv $1/expected-server-output expout
173 mv $1/expected-server-errors experr
174 AT_CHECK([cat $1/server-output; cat >&2 $1/server-errors],,
175          [expout], [experr])
176 ])
177
178 ## WITH_TRIPE(args, body)
179 m4_define([WITH_TRIPE], [WITH_TRIPEX([.], [$1], [$2])])
180
181 ## WITH_2TRIPES(adir, bdir, bothargs, aargs, bargs, body)
182 m4_define([WITH_2TRIPES],
183           [WITH_TRIPEX([$1], [$3 $4], [WITH_TRIPEX([$2], [$3 $5], [$6])])])
184
185 ## WITH_3TRIPES(adir, bdir, cdir, allargs, aargs, bargs, cargs, body)
186 m4_define([WITH_3TRIPES],
187           [WITH_TRIPEX([$1], [$4 $5],
188           [WITH_TRIPEX([$2], [$4 $6],
189           [WITH_TRIPEX([$3], [$4 $7],
190           [$8])])])])
191
192 ## RETRY(n, body)
193 m4_define([RETRY], [
194   n=0 rc=1
195   while test $n -lt $1; do
196     if $2
197     then rc=0; break
198     fi
199     n=$(( $n + 1 ))
200   done
201   exit $rc
202 ])
203
204 ## COMMS_EPING(adir, aname, bdir, bname, [n])
205 m4_define([COMMS_EPING], [
206   AT_CHECK([RETRY([m4_default([$5], [1])],
207     [TRIPECTL -d$1 EPING $4])],, [ignore])
208   AT_CHECK([RETRY([m4_default([$5], [1])],
209     [TRIPECTL -d$3 EPING $2])],, [ignore])
210 ])
211
212 ## COMMS_SLIP(adir, aname, bdir, bname)
213 m4_define([COMMS_SLIP], [
214   AT_CHECK([echo "from $1" | USLIP -p $1/$4])
215   AT_CHECK([USLIP -g $3/$2],, [from $1[]nl])
216   AT_CHECK([echo "from $3" | USLIP -p $3/$2])
217   AT_CHECK([USLIP -g $1/$4],, [from $3[]nl])
218 ])
219
220 ## AWAIT_KXDONE(adir, aname, bdir, bname, body)
221 m4_define([AWAIT_KXDONE], [
222
223   ## Ignore some reports caused by races.
224   for d in $1 $3; do
225     TRIPECTL -d$d WARN test PUSH
226     TRIPECTL -d$d WARN test IGNORE WARN KX $2 incorrect cookie
227     TRIPECTL -d$d WARN test IGNORE WARN KX $2 unexpected pre-challenge
228     TRIPECTL -d$d WARN test IGNORE WARN KX $2 unexpected challenge
229   done
230
231   ## Watch for the key-exchange completion announcement in the background.
232   COPROCESSES([wait-$1], [
233     echo WATCH +n
234     while read line; do
235       set x $line; shift
236       echo >&2 ">>> $line"
237       case "$[]1:$[]2:$[]3" in
238         OK::) ;;
239         NOTE:KXDONE:$4) break ;;
240         NOTE:*) ;;
241         *) exit 63 ;;
242       esac
243     done
244   ], [
245     TRIPECTL -d$1
246   ]) & waiter_$1=$!
247
248   $5
249
250   ## Collect the completion announcement.
251   wait $waiter_$1; waitrc=$?
252   AT_CHECK([echo $waitrc],, [0[]nl])
253
254   ## Be interested in key-exchange warnings again.
255   for d in $1 $3; do TRIPECTL -d$d WARN test POP; done
256 ])
257
258 ## ESTABLISH(adir, aname, aopts, bdir, bname, bopts, [aport], [bport])
259 m4_define([ESTABLISH], [
260
261   ## Set up the establishment.
262   AWAIT_KXDONE([$1], [$2], [$4], [$5], [
263     AT_CHECK([TRIPECTL -d$1 ADD -cork $6 $5 INET 127.0.0.1 \
264       m4_if([$8], [], [$(cat $4/port)], [$8])])
265     AT_CHECK([TRIPECTL -d$4 ADD $3 $2 INET 127.0.0.1 \
266       m4_if([$7], [], [$(cat $1/port)], [$7])])
267   ])
268
269   ## Check transport pinging.
270   AT_CHECK([TRIPECTL -d$1 PING $5],, [ignore])
271   AT_CHECK([TRIPECTL -d$4 PING $2],, [ignore])
272
273   ## Check communication works.
274   COMMS_EPING([$1], [$2], [$4], [$5])
275   COMMS_SLIP([$1], [$2], [$4], [$5])
276 ])
277
278 ###--------------------------------------------------------------------------
279 ### Very unpleasant coprocess handling.
280
281 ## COPROCESSES(TAG, PROC-A, PROC-B)
282 m4_define([COPROCESSES], [dnl
283 rm -f pipe-$1; mknod pipe-$1 p
284 { { $2 nl } <pipe-$1 | { $3 nl } >pipe-$1; } dnl
285 ])
286
287 ## TRIPECTL_INTERACT(ARGS, SHELLSTUFF)
288 m4_define([TRIPECTL_INTERACT], [
289   exec 3>&1
290   COPROCESSES([client], [exec 4>&1 1>&3 $1], [TRIPECTL $2])
291 ])
292
293 ## TRIPECTL_COMMAND(CMD, EXPECT)
294 m4_define([TRIPECTL_COMMAND], [
295   AT_CHECK([
296     m4_if([$1], [!], [:], [echo "$1" >&4])
297     read line
298     case "$line" in
299       "$2") ;;
300       *) echo 2>&1 "submitted $1: expected $2, found $line"; exit 1 ;;
301     esac
302   ])
303   exec 3>&-
304 ])
305
306 ###--------------------------------------------------------------------------
307 ### Make sure the thing basically works.
308
309 AT_SETUP([server basics])
310 SETUPDIR([alpha])
311 AT_CHECK([echo port | TRIPE -p54321],, [INFO 54321[]nl[]OK[]nl])
312 AT_CLEANUP
313
314 ###--------------------------------------------------------------------------
315 ### Challenges.
316
317 AT_SETUP([server challenges])
318 AT_KEYWORDS([chal])
319 SETUPDIR([alpha])
320
321 WITH_TRIPE(, [
322   ## A simple test.
323   AT_CHECK([chal=$(TRIPECTL GETCHAL); TRIPECTL checkchal $chal])
324
325   ## A wrong challenge.  (This was valid once, but the probablity that the
326   ## server chose the same key is negligible.)
327   AT_CHECK([TRIPECTL checkchal AAAAAHyoOL+HMaE0Y9B3ivuszt0], [1],,
328            [tripectl: invalid-challenge[]nl])
329   echo WARN CHAL incorrect-tag >>expected-server-output
330
331   ## A duplicated challenge.
332   AT_CHECK([
333     chal=$(TRIPECTL GETCHAL)
334     TRIPECTL CHECKCHAL $chal
335     TRIPECTL CHECKCHAL $chal
336   ], [1],, [tripectl: invalid-challenge[]nl])
337   echo WARN CHAL replay duplicated-sequence >>expected-server-output
338
339   ## Out-of-order reception.  There should be a window of 32 challenges; we
340   ## make 33 and check them in a strange order.
341   rm -f experr
342   echo "tripectl: invalid-challenge" >>experr
343   echo "WARN CHAL replay old-sequence" >>expected-server-output
344   for i in P32; do
345     echo "tripectl: invalid-challenge" >>experr
346     echo "WARN CHAL replay duplicated-sequence" >>expected-server-output
347   done
348   AT_CHECK([
349
350     ## Make the challenges.
351     for i in old R32; do TRIPECTL GETCHAL >chal-$i || exit 2; done
352
353     ## Now check them back.
354     for i in P32; do TRIPECTL CHECKCHAL $(cat chal-$i) || exit 3; done
355
356     ## Check the one which should have fallen off the front.
357     TRIPECTL CHECKCHAL $(cat chal-old) && exit 4
358
359     ## And make sure that the others are now considered duplicates.
360     for i in R32; do TRIPECTL CHECKCHAL $(cat chal-$i) && exit 5; done
361
362     ## All done: tidy cruft away.
363     rm -f chal-*
364     exit 0
365   ], [0],, [experr])
366 ])
367
368 AT_CLEANUP
369
370 ###--------------------------------------------------------------------------
371 ### Communication.
372
373 AT_SETUP([server communication])
374 AT_KEYWORDS([comm])
375 export TRIPE_SLIPIF=USLIP
376
377 for k in alpha beta-new; do
378   for p in alice bob; do (
379     rm -rf $p; mkdir $p; cd $p; SETUPDIR([$k])
380   ); done
381   WITH_2TRIPES([alice], [bob], [-nslip], [-talice], [-tbob], [
382     ESTABLISH([alice], [not-alice], [-key alice],
383               [bob], [bob], [])
384   ])
385 done
386
387 AT_CLEANUP
388
389 ###--------------------------------------------------------------------------
390 ### Mobile peer tracking.
391
392 AT_SETUP([peer tracking])
393 AT_KEYWORDS([mobile])
394 export TRIPE_SLIPIF=USLIP
395
396 for p in alice bob carol; do (mkdir $p; cd $p; SETUPDIR([alpha])); done
397
398 ## WITH_PKSTREAM(adir, aport, bdir, bport, body)
399 m4_define([WITH_PKSTREAM], [
400   echo >&2 "pkstream: $1 <--> :$2 <-pkstream-> :$4 <--> $3"
401   PKSTREAM -l$4 127.0.0.1:$4 127.0.0.1:$(cat $3/port)& pkstream_$3_$1=$!
402   sleep 1
403   PKSTREAM -c127.0.0.1:$4 127.0.0.1:$2 127.0.0.1:$(cat $1/port)&
404   pkstream_$1_$3=$!
405   set +x
406   $5
407   kill $pkstream_$3_$1 $pkstream_$1_$3
408 ])
409
410 WITH_3TRIPES([alice], [bob], [carol], [-nslip],
411              [-talice], [-tbob], [-tcarol], [
412
413   ## We need an indirection layer between the two peers so that we can
414   ## simulate the effects of NAT remapping.  The nearest thing we have to
415   ## this is pkstream, so we may as well use that.
416   ##
417   ## alice <--> :5311 <-pkstream-> :5312 <--> bob
418   ## alice <--> :5321 <-pkstream-> :5322 <--> carol
419
420   WITH_PKSTREAM([alice], [5311], [bob], [5312], [
421     ESTABLISH([alice], [alice], [], [bob], [bob], [-mobile], [5312], [5311])
422   ])
423
424   WITH_PKSTREAM([alice], [5319], [bob], [5312], [
425     COMMS_EPING([bob], [bob], [alice], [alice])
426     COMMS_SLIP([bob], [bob], [alice], [alice])
427   ])
428
429   WITH_PKSTREAM([alice], [5321], [carol], [5322], [
430     ESTABLISH([alice], [alice], [], [carol], [carol], [-mobile],
431         [5322], [5321])
432   ])
433
434   WITH_PKSTREAM([alice], [5311], [bob], [5312], [
435   WITH_PKSTREAM([alice], [5321], [carol], [5322], [
436     COMMS_EPING([bob], [bob], [alice], [alice])
437     COMMS_EPING([carol], [carol], [alice], [alice])
438     COMMS_SLIP([bob], [bob], [alice], [alice])
439     COMMS_SLIP([carol], [carol], [alice], [alice])
440   ])])
441
442   WITH_PKSTREAM([alice], [5321], [bob], [5312], [
443   WITH_PKSTREAM([alice], [5311], [carol], [5322], [
444     COMMS_EPING([bob], [bob], [alice], [alice])
445     COMMS_EPING([carol], [carol], [alice], [alice])
446     COMMS_SLIP([bob], [bob], [alice], [alice])
447     COMMS_SLIP([carol], [carol], [alice], [alice])
448   ])])
449   wait
450 ])
451
452 AT_CLEANUP
453
454 ###--------------------------------------------------------------------------
455 ### Adverse communication.
456
457 AT_SETUP([server retry])
458 AT_KEYWORDS([backoff])
459 export TRIPE_SLIPIF=USLIP
460
461 for i in alice bob; do (mkdir $i; cd $i; SETUPDIR([beta])); done
462
463 WITH_2TRIPES([alice], [bob], [-nslip], [-talice], [-tbob], [
464
465   ## Set up the evil proxy.
466   alicemitm=24516 bobmitm=14016
467   MITM -kalice/keyring.pub >mitm.out 2>mitm.err \
468     peer:alice:$alicemitm:127.0.0.1:$(cat alice/port) \
469     peer:bob:$bobmitm:127.0.0.1:$(cat bob/port) \
470     filt:drop:5 filt:send& mitmpid=$!
471   strace -omitm.trace -p$mitmpid& mitmtrace=$!
472   trap 'kill $mitmpid $mitmtrace; exit 127' EXIT INT QUIT TERM HUP
473
474   ## Try to establish keys anyway.
475   AWAIT_KXDONE([alice], [alice], [bob], [bob], [
476     AT_CHECK([TRIPECTL -dalice ADD -cork bob   INET 127.0.0.1 $alicemitm])
477     AT_CHECK([TRIPECTL -dbob   ADD       alice INET 127.0.0.1 $bobmitm])
478   ])
479
480   ## Check pinging.
481   COMMS_EPING([alice], [alice], [bob], [bob], [10])
482   COMMS_EPING([bob], [bob], [alice], [alice], [10])
483
484   ## Tear down the MITM proxy.
485   kill $mitmpid
486   wait $mitmpid
487   wait $mitmtrace
488 ])
489
490 AT_CLEANUP
491
492 ###--------------------------------------------------------------------------
493 ### Key management.
494
495 AT_SETUP([server key-management])
496 AT_KEYWORDS([keymgmt])
497 export TRIPE_SLIPIF=USLIP
498
499 ## Determine all of the nets and the principals.
500 princs=""
501 nets=" "
502 while read princ pnets; do
503   princs="$princs $princ"
504   for n in $pnets; do
505     case " $nets " in *" $n "*) ;; *) nets="$nets$n " ;; esac
506   done
507 done <<PRINC
508 alice   alpha   beta
509 bob     alpha   beta
510 carol   beta
511 PRINC
512
513 ## Build the master keyring.  All key tags here are of the form PRINC/NET.
514 for n in $nets; do
515   key -k$abs_top_srcdir/t/keyring-$n extract keyring-$n $princs
516   for p in $princs; do key -kkeyring-$n tag $p $p/$n; done
517   key merge keyring-$n
518   rm keyring-$n
519 done
520 key extract -f-secret keyring.pub
521
522 ## Set up the principals' directories.
523 for p in $princs; do
524   mkdir $p
525   cp keyring keyring.pub $p/
526 done
527
528 WITH_3TRIPES([alice], [bob], [carol], [-nslip -Tmx],
529         [-talice/alpha], [-tbob/alpha], [-tcarol/beta], [
530
531   ## Establish this little merry-go-round.
532   ESTABLISH([alice], [alice], [-key alice/alpha],
533         [bob], [bob], [-key bob/alpha])
534   ESTABLISH([alice], [alice], [-key alice/beta],
535         [carol], [carol], [-priv alice/beta -key carol/beta])
536   ESTABLISH([bob], [bob], [-key bob/beta],
537         [carol], [carol], [-priv bob/beta -key carol/beta])
538
539   ## Tweak Bob's alpha key.
540   for p in $princs; do
541     TRIPECTL -d$p WARN test COMMENT tweak bob/alpha
542   done
543
544   key -k$abs_top_srcdir/t/keyring-alpha extract keyring-bob-new bob-new
545   key merge keyring-bob-new
546   key tag -r bob-new bob/alpha
547   key extract -f-secret keyring.pub
548   for p in alice bob; do cp keyring keyring.pub $p/; done
549
550   ## Kick the peers to see whether they update.
551   AWAIT_KXDONE([alice], [alice], [bob], [bob], [
552     TRIPECTL -dalice RELOAD
553     TRIPECTL -dbob RELOAD
554     TRIPECTL -dalice FORCEKX bob
555     TRIPECTL -dbob FORCEKX alice
556   ])
557
558   COMMS_EPING([alice], [alice], [bob], [bob])
559   COMMS_EPING([bob], [bob], [alice], [alice])
560
561   ## Update the beta ring.
562   key merge $abs_top_srcdir/t/keyring-beta-new
563   for p in $princs; do key tag -r $p $p/beta; done
564   key extract -f-secret keyring.pub
565
566   ## Update alice's and carol's private keys, bob's public.  This should be
567   ## insufficient for them to switch, but the results could be interesting.
568   for p in $princs; do
569     TRIPECTL -d$p WARN test COMMENT tweak beta step 1
570   done
571
572   for p in alice carol; do cp keyring $p/; done
573   cp keyring.pub bob/
574   for p in $princs; do TRIPECTL -d$p RELOAD; done
575
576   AT_DATA([algs-alpha], [dnl
577 kx-group=ec kx-group-order-bits=256 kx-group-elt-bits=512
578 hash=rmd160 mgf=rmd160-mgf hash-sz=20
579 bulk-transform=v0 bulk-overhead=22
580 cipher=blowfish-cbc cipher-keysz=20 cipher-blksz=8
581 cipher-data-limit=67108864
582 mac=rmd160-hmac mac-keysz=20 mac-tagsz=10
583 ])
584
585   AT_DATA([algs-beta-old], [dnl
586 kx-group=prime kx-group-order-bits=160 kx-group-elt-bits=1023
587 hash=rmd160 mgf=rmd160-mgf hash-sz=20
588 bulk-transform=v0 bulk-overhead=22
589 cipher=blowfish-cbc cipher-keysz=20 cipher-blksz=8
590 cipher-data-limit=67108864
591 mac=rmd160-hmac mac-keysz=20 mac-tagsz=10
592 ])
593
594   AT_DATA([algs-beta-new], [dnl
595 kx-group=ec kx-group-order-bits=161 kx-group-elt-bits=320
596 hash=rmd160 mgf=rmd160-mgf hash-sz=20
597 bulk-transform=iiv bulk-overhead=14
598 cipher=blowfish-cbc cipher-keysz=20 cipher-blksz=8
599 cipher-data-limit=67108864
600 mac=rmd160-hmac mac-keysz=20 mac-tagsz=10
601 blkc=blowfish blkc-keysz=20 blkc-blksz=8
602 ])
603
604   cp algs-alpha expout;    AT_CHECK([TRIPECTL -dalice ALGS],,       [expout])
605   cp algs-beta-old expout; AT_CHECK([TRIPECTL -dalice ALGS carol],, [expout])
606   cp algs-beta-old expout; AT_CHECK([TRIPECTL -dbob   ALGS carol],, [expout])
607   cp algs-beta-new expout; AT_CHECK([TRIPECTL -dcarol ALGS],,       [expout])
608   cp algs-beta-old expout; AT_CHECK([TRIPECTL -dcarol ALGS alice],, [expout])
609
610   ## Now copy the full keys.  We expect this to provoke key exchange.
611   for p in $princs; do
612     TRIPECTL -d$p WARN test COMMENT tweak beta step 2
613   done
614
615   for p in $princs; do cp keyring keyring.pub $p/; done
616
617   AWAIT_KXDONE([alice], [alice], [carol], [carol], [
618     TRIPECTL -dalice RELOAD
619     AWAIT_KXDONE([bob], [bob], [carol], [carol], [
620       TRIPECTL -dbob RELOAD
621       TRIPECTL -dcarol RELOAD
622     ])
623   ])
624
625   cp algs-alpha expout;    AT_CHECK([TRIPECTL -dalice ALGS],,       [expout])
626   cp algs-beta-new expout; AT_CHECK([TRIPECTL -dalice ALGS carol],, [expout])
627   cp algs-beta-new expout; AT_CHECK([TRIPECTL -dbob   ALGS carol],, [expout])
628   cp algs-beta-new expout; AT_CHECK([TRIPECTL -dcarol ALGS],,       [expout])
629 ])
630
631 AT_CLEANUP
632
633 ###--------------------------------------------------------------------------
634 ### Services.
635
636 AT_SETUP([server services])
637 AT_KEYWORDS([svc])
638 SETUPDIR([alpha])
639
640 WITH_TRIPE(, [
641
642   ## Make sure it's not running yet.
643   AT_CHECK([TRIPECTL SVCENSURE test], [1],,
644            [tripectl: unknown-service test[]nl])
645
646   ## Run a simple service.
647   rm -f svc-test-running tripectl-status
648   COPROCESSES([svc], [
649     echo SVCCLAIM test 1.0.0
650     read line
651     case "$line" in
652       OK)
653         ;;
654       *)
655         echo >&2 "SVCCLAIM failed: $line"
656         exit 1
657         ;;
658     esac
659     echo ok >svc-test-running
660     while read line; do
661       set -- $line
662       case "$[]1,$[]3,$[]4" in
663         SVCJOB,test,HELP)
664           echo SVCINFO try not to use this service for anything useful
665           echo SVCOK $[]2
666           ;;
667         SVCJOB,test,GOOD)
668           echo SVCOK $[]2
669           ;;
670         SVCJOB,test,BAD)
671           echo SVCFAIL $[]2 this-command-always-fails
672           ;;
673         SVCJOB,test,UGLY)
674           tag=$2
675           while read line; do
676             set -- $line
677             case "$[]1,$[]2,$[]3,$[]4" in
678               SVCCANCEL,$tag,,) break ;;
679               SVCJOB,*,test,ESCAPE)
680                 echo >&2 "attempt to escape from alkatraz"
681                 exit 1
682                 ;;
683             esac
684           done
685           ;;
686         SVCJOB,test,FIRST)
687           firsttag=$[]2
688           ;;
689         SVCJOB,test,SECOND)
690           echo SVCOK $firsttag
691           echo SVCOK $[]2
692           ;;
693         SVCJOB,*)
694           echo SVCFAIL $[]2 unknown-svc-command $[]4
695           ;;
696         SVCCLAIM,*)
697           break
698           ;;
699         OK,* | INFO,*)
700           ;;
701         FAIL,*)
702           echo "failure in service: $line" >&2
703           ;;
704       esac
705     done
706   ], [
707     TRIPECTL; echo $? >tripectl-status
708   ]) 2>tripectl-errors &
709
710   ## Wait until it starts up.
711   while test ! -r svc-test-running && test ! -r tripectl-status; do :; done
712
713   ## Make sure it's running.
714   AT_CHECK([TRIPECTL SVCQUERY test],, [name=test version=1.0.0[]nl])
715
716   ## Try some simple commands.
717   AT_CHECK([TRIPECTL SVCSUBMIT test GOOD])
718   AT_CHECK([TRIPECTL SVCSUBMIT test BAD], [1],,
719            [tripectl: this-command-always-fails[]nl])
720
721   ## And now with commands in the background.
722   TRIPECTL_INTERACT([
723     TRIPECTL_COMMAND([SVCSUBMIT test GOOD], [OK])
724     TRIPECTL_COMMAND([SVCSUBMIT -background foo test UGLY], [BGDETACH foo])
725     TRIPECTL_COMMAND([BGCANCEL foo], [OK])
726     TRIPECTL_COMMAND([SVCSUBMIT test ESCAPE],
727                      [FAIL unknown-svc-command ESCAPE])
728   ])
729
730   ## Out-of-order completion.
731   TRIPECTL_INTERACT([
732     TRIPECTL_COMMAND([SVCSUBMIT -background one test FIRST], [BGDETACH one])
733     TRIPECTL_COMMAND([SVCSUBMIT -background two test SECOND], [BGDETACH two])
734     TRIPECTL_COMMAND([!], [BGOK one])
735     TRIPECTL_COMMAND([!], [BGOK two])
736   ])
737
738   ## All done.
739   exit 0
740 ])
741
742 AT_CLEANUP
743
744 ###----- That's all, folks --------------------------------------------------