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