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