chiark / gitweb /
Release 1.5.3.
[tripe] / server / tests.at
CommitLineData
5d85da1c
MW
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###
11ad66c2
MW
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.
5d85da1c 16###
11ad66c2
MW
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.
5d85da1c
MW
21###
22### You should have received a copy of the GNU General Public License
11ad66c2 23### along with TrIPE. If not, see <https://www.gnu.org/licenses/>.
5d85da1c
MW
24
25m4_define([nl], [
26])
27
28## Configure a directory ready for use by tripe.
29m4_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.
35m4_define([TRIPE],
388e0319 36 [env TRIPE_PRIVHELPER=$abs_top_builddir/priv/tripe-privhelper \
3eb084b2 37 $abs_top_builddir/server/tripe -F -d. -aadmin -p0 -b127.0.0.1 \
4606744f 38 ${TRIPE_TEST_TRACEOPTS+-T$TRIPE_TEST_TRACEOPTS}])
5d85da1c
MW
39m4_define([TRIPECTL], [$abs_top_builddir/client/tripectl -d. -aadmin])
40m4_define([USLIP], [$abs_top_builddir/uslip/tripe-uslip])
f884ef9d 41m4_define([MITM], [$abs_top_builddir/proxy/tripe-mitm])
8dc315cd
MW
42m4_define([BULKTEST],
43 [$abs_top_builddir/server/tripe-test \
44 ${TRIPE_TEST_TRACEOPTS+-T$TRIPE_TEST_TRACEOPTS}])
5d85da1c 45
9867bea0
MW
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.
52m4_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 "$[]@"' - \
5e55d10b 61 strace -ff -tt -v -s1024 -o../$1.trace \
9867bea0
MW
62 sh -c 'cd ..; exec "$[]@"' - \
63 $2)
64 ;;
65 esac])
66
5d85da1c
MW
67## Sequences. (These are used for testing the replay protection machinery.)
68m4_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])
70m4_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
05d4b7da 76## WITH_TRIPEX(dir, args, body)
5d85da1c
MW
77m4_define([WITH_TRIPEX], [
78
05d4b7da
MW
79## If this directory doesn't exist then Bad Things will happen.
80if test ! -d $1; then
81 echo >&2 "server directory \`$1' doesn't exist"
82 exit 99
83fi
84
5d85da1c
MW
85## Remove the status file. This is how we notice that the server's died.
86rm -f $1/server-status
87> $1/expected-server-output
88> $1/expected-server-errors
89
768a2316
MW
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.
5d85da1c
MW
93exec 3>&1
94{ (
95exec 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.)
768a2316 100while test ! -r $1/server-status && test ! -S $1/admin; do :; done
5d85da1c 101
05d4b7da
MW
102## Make the port number availale.
103AT_CHECK([TRIPECTL -d$1 PORT],, [stdout])
104mv stdout $1/port
105
5d85da1c
MW
106## Test body...
107$3
108
9867bea0 109## End of the test, now run the server.
5d85da1c
MW
110) && :; } | {
111 cd $1
112 echo TRIPE $2 >&2
377824e5 113 WITH_STRACE([tripe], [TRIPE $2 >server-output.full 2>server-errors.full])
5d85da1c
MW
114 stat=$?
115 echo $stat >server-status
116 if test $stat -ne 0; then
377824e5 117 echo "exit status: $stat" >>server-errors.full
5d85da1c 118 fi
377824e5 119 grep -v '^+ tripe: ' server-errors.full >server-errors
05d4b7da
MW
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]]);
ee7a2a10 170 if (substr($[]0, 1, n) == pat[[i]])
05d4b7da
MW
171 next;
172 }
173 print $[]0;
174 }
175 ' server-output.full >server-output
5d85da1c
MW
176}
177exec 3>&-
178
179## Now check that the server's output matches our expectations.
180mv $1/expected-server-output expout
181mv $1/expected-server-errors experr
182AT_CHECK([cat $1/server-output; cat >&2 $1/server-errors],,
183 [expout], [experr])
184])
185
05d4b7da 186## WITH_TRIPE(args, body)
5d85da1c
MW
187m4_define([WITH_TRIPE], [WITH_TRIPEX([.], [$1], [$2])])
188
05d4b7da 189## WITH_2TRIPES(adir, bdir, bothargs, aargs, bargs, body)
5d85da1c
MW
190m4_define([WITH_2TRIPES],
191 [WITH_TRIPEX([$1], [$3 $4], [WITH_TRIPEX([$2], [$3 $5], [$6])])])
192
203e1b1f
MW
193## WITH_3TRIPES(adir, bdir, cdir, allargs, aargs, bargs, cargs, body)
194m4_define([WITH_3TRIPES],
195 [WITH_TRIPEX([$1], [$4 $5],
196 [WITH_TRIPEX([$2], [$4 $6],
197 [WITH_TRIPEX([$3], [$4 $7],
198 [$8])])])])
199
9e930d39
MW
200## RETRY(n, body)
201m4_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])
05d4b7da 213m4_define([COMMS_EPING], [
9e930d39
MW
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])
05d4b7da
MW
218])
219
220## COMMS_SLIP(adir, aname, bdir, bname)
221m4_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)
229m4_define([AWAIT_KXDONE], [
230
231 ## Ignore some reports caused by races.
add23883
MW
232 for i in $1!$4 $3!$2; do
233 d=${i%!*} o=${i#*!}
91a97a96 234 TRIPECTL -d$d WARN test PUSH
add23883
MW
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
91a97a96 238 done
05d4b7da
MW
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 ;;
bf67ce8d 249 NOTE:* | TRACE:* | WARN:*) ;;
05d4b7da
MW
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.
91a97a96 264 for d in $1 $3; do TRIPECTL -d$d WARN test POP; done
05d4b7da
MW
265])
266
01c21903 267## ESTABLISH(adir, aname, aopts, bdir, bname, bopts, [aport], [bport])
05d4b7da
MW
268m4_define([ESTABLISH], [
269
270 ## Set up the establishment.
271 AWAIT_KXDONE([$1], [$2], [$4], [$5], [
01c21903
MW
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])])
05d4b7da
MW
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
5d85da1c
MW
287###--------------------------------------------------------------------------
288### Very unpleasant coprocess handling.
289
290## COPROCESSES(TAG, PROC-A, PROC-B)
291m4_define([COPROCESSES], [dnl
292rm -f pipe-$1; mknod pipe-$1 p
293{ { $2 nl } <pipe-$1 | { $3 nl } >pipe-$1; } dnl
294])
295
296## TRIPECTL_INTERACT(ARGS, SHELLSTUFF)
297m4_define([TRIPECTL_INTERACT], [
768a2316 298 exec 3>&1
11715242 299 COPROCESSES([client], [exec 4>&1 1>&3 $1], [TRIPECTL $2])
5d85da1c
MW
300])
301
302## TRIPECTL_COMMAND(CMD, EXPECT)
303m4_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
318AT_SETUP([server basics])
59d05259 319SETUPDIR([alpha])
5d85da1c
MW
320AT_CHECK([echo port | TRIPE -p54321],, [INFO 54321[]nl[]OK[]nl])
321AT_CLEANUP
322
323###--------------------------------------------------------------------------
324### Challenges.
325
326AT_SETUP([server challenges])
327AT_KEYWORDS([chal])
59d05259 328SETUPDIR([alpha])
5d85da1c
MW
329
330WITH_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
377AT_CLEANUP
378
379###--------------------------------------------------------------------------
380### Communication.
381
382AT_SETUP([server communication])
383AT_KEYWORDS([comm])
384export TRIPE_SLIPIF=USLIP
385
b87bffcb
MW
386for 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 ])
a49d0131 394 for p in alice bob; do rm -rf $p.$k; mv $p $p.$k; done
b87bffcb 395done
5d85da1c
MW
396
397AT_CLEANUP
398
01c21903
MW
399###--------------------------------------------------------------------------
400### Mobile peer tracking.
401
402AT_SETUP([peer tracking])
403AT_KEYWORDS([mobile])
404export TRIPE_SLIPIF=USLIP
405
406for p in alice bob carol; do (mkdir $p; cd $p; SETUPDIR([alpha])); done
407
6d5eac37
MW
408## WITH_MITM(adir, aport, bdir, bport, body)
409m4_define([WITH_MITM], [
410 echo >&2 "mitm: $1 <--> :$2 <-mitm-> :$4 <--> $3"
411 MITM -k$1/keyring.pub \
412 peer:$1:$2:127.0.0.1:$(cat $1/port) \
413 peer:$3:$4:127.0.0.1:$(cat $3/port) \
414 filt:send& mitmpid_$1_$3=$!
415 trap 'kill $mitmpid_$1_$3; exit 127' EXIT INT QUIT TERM HUP
01c21903 416 sleep 1
01c21903 417 $5
6d5eac37 418 kill $mitmpid_$1_$3; trap - EXIT INT QUIT TERM HUP
01c21903
MW
419])
420
421WITH_3TRIPES([alice], [bob], [carol], [-nslip],
422 [-talice], [-tbob], [-tcarol], [
423
424 ## We need an indirection layer between the two peers so that we can
425 ## simulate the effects of NAT remapping. The nearest thing we have to
6d5eac37 426 ## this is the mitm proxy, so we may as well use that.
01c21903 427 ##
6d5eac37
MW
428 ## alice <--> :5311 <-mitm-> :5312 <--> bob
429 ## alice <--> :5321 <-mitm-> :5322 <--> carol
01c21903 430
6d5eac37 431 WITH_MITM([alice], [5311], [bob], [5312], [
01c21903
MW
432 ESTABLISH([alice], [alice], [], [bob], [bob], [-mobile], [5312], [5311])
433 ])
434
6d5eac37 435 WITH_MITM([alice], [5319], [bob], [5312], [
01c21903
MW
436 COMMS_EPING([bob], [bob], [alice], [alice])
437 COMMS_SLIP([bob], [bob], [alice], [alice])
438 ])
439
6d5eac37 440 WITH_MITM([alice], [5321], [carol], [5322], [
01c21903
MW
441 ESTABLISH([alice], [alice], [], [carol], [carol], [-mobile],
442 [5322], [5321])
443 ])
444
6d5eac37
MW
445 WITH_MITM([alice], [5311], [bob], [5312], [
446 WITH_MITM([alice], [5321], [carol], [5322], [
01c21903
MW
447 COMMS_EPING([bob], [bob], [alice], [alice])
448 COMMS_EPING([carol], [carol], [alice], [alice])
449 COMMS_SLIP([bob], [bob], [alice], [alice])
450 COMMS_SLIP([carol], [carol], [alice], [alice])
451 ])])
452
6d5eac37
MW
453 WITH_MITM([alice], [5321], [bob], [5312], [
454 WITH_MITM([alice], [5311], [carol], [5322], [
01c21903
MW
455 COMMS_EPING([bob], [bob], [alice], [alice])
456 COMMS_EPING([carol], [carol], [alice], [alice])
457 COMMS_SLIP([bob], [bob], [alice], [alice])
458 COMMS_SLIP([carol], [carol], [alice], [alice])
459 ])])
460 wait
461])
462
463AT_CLEANUP
464
f884ef9d
MW
465###--------------------------------------------------------------------------
466### Adverse communication.
467
468AT_SETUP([server retry])
469AT_KEYWORDS([backoff])
470export TRIPE_SLIPIF=USLIP
471
9cda68ab 472for i in alice bob; do (mkdir $i; cd $i; SETUPDIR([beta])); done
f884ef9d
MW
473
474WITH_2TRIPES([alice], [bob], [-nslip], [-talice], [-tbob], [
475
476 ## Set up the evil proxy.
477 alicemitm=24516 bobmitm=14016
ee07712c
MW
478 mknod pipe-mitmpid p
479 WITH_STRACE([mitm],
480 [sh -c 'echo $$ >pipe-mitmpid; exec "$@"' - \
481 MITM -kalice/keyring.pub >mitm.out 2>mitm.err \
482 peer:alice:$alicemitm:127.0.0.1:$(cat alice/port) \
483 peer:bob:$bobmitm:127.0.0.1:$(cat bob/port) \
484 filt:drop:5 filt:send])&
485 read mitmpid <pipe-mitmpid
486 trap 'kill $mitmpid; exit 127' EXIT INT QUIT TERM HUP
487 exec 3>&-
f884ef9d
MW
488
489 ## Try to establish keys anyway.
490 AWAIT_KXDONE([alice], [alice], [bob], [bob], [
491 AT_CHECK([TRIPECTL -dalice ADD -cork bob INET 127.0.0.1 $alicemitm])
492 AT_CHECK([TRIPECTL -dbob ADD alice INET 127.0.0.1 $bobmitm])
493 ])
494
495 ## Check pinging.
496 COMMS_EPING([alice], [alice], [bob], [bob], [10])
497 COMMS_EPING([bob], [bob], [alice], [alice], [10])
498
499 ## Tear down the MITM proxy.
500 kill $mitmpid
f884ef9d
MW
501])
502
503AT_CLEANUP
504
31b8e627
MW
505###--------------------------------------------------------------------------
506### Key management.
507
508AT_SETUP([server key-management])
509AT_KEYWORDS([keymgmt])
510export TRIPE_SLIPIF=USLIP
511
512## Determine all of the nets and the principals.
513princs=""
514nets=" "
515while read princ pnets; do
516 princs="$princs $princ"
517 for n in $pnets; do
518 case " $nets " in *" $n "*) ;; *) nets="$nets$n " ;; esac
519 done
520done <<PRINC
521alice alpha beta
522bob alpha beta
523carol beta
524PRINC
525
526## Build the master keyring. All key tags here are of the form PRINC/NET.
527for n in $nets; do
528 key -k$abs_top_srcdir/t/keyring-$n extract keyring-$n $princs
529 for p in $princs; do key -kkeyring-$n tag $p $p/$n; done
530 key merge keyring-$n
531 rm keyring-$n
532done
533key extract -f-secret keyring.pub
534
535## Set up the principals' directories.
536for p in $princs; do
537 mkdir $p
538 cp keyring keyring.pub $p/
539done
540
541WITH_3TRIPES([alice], [bob], [carol], [-nslip -Tmx],
542 [-talice/alpha], [-tbob/alpha], [-tcarol/beta], [
543
544 ## Establish this little merry-go-round.
545 ESTABLISH([alice], [alice], [-key alice/alpha],
546 [bob], [bob], [-key bob/alpha])
547 ESTABLISH([alice], [alice], [-key alice/beta],
548 [carol], [carol], [-priv alice/beta -key carol/beta])
549 ESTABLISH([bob], [bob], [-key bob/beta],
550 [carol], [carol], [-priv bob/beta -key carol/beta])
551
552 ## Tweak Bob's alpha key.
553 for p in $princs; do
554 TRIPECTL -d$p WARN test COMMENT tweak bob/alpha
555 done
556
557 key -k$abs_top_srcdir/t/keyring-alpha extract keyring-bob-new bob-new
558 key merge keyring-bob-new
559 key tag -r bob-new bob/alpha
560 key extract -f-secret keyring.pub
561 for p in alice bob; do cp keyring keyring.pub $p/; done
562
563 ## Kick the peers to see whether they update.
564 AWAIT_KXDONE([alice], [alice], [bob], [bob], [
565 TRIPECTL -dalice RELOAD
566 TRIPECTL -dbob RELOAD
567 TRIPECTL -dalice FORCEKX bob
568 TRIPECTL -dbob FORCEKX alice
569 ])
570
571 COMMS_EPING([alice], [alice], [bob], [bob])
572 COMMS_EPING([bob], [bob], [alice], [alice])
573
574 ## Update the beta ring.
575 key merge $abs_top_srcdir/t/keyring-beta-new
576 for p in $princs; do key tag -r $p $p/beta; done
577 key extract -f-secret keyring.pub
578
579 ## Update alice's and carol's private keys, bob's public. This should be
580 ## insufficient for them to switch, but the results could be interesting.
581 for p in $princs; do
582 TRIPECTL -d$p WARN test COMMENT tweak beta step 1
583 done
584
585 for p in alice carol; do cp keyring $p/; done
586 cp keyring.pub bob/
587 for p in $princs; do TRIPECTL -d$p RELOAD; done
588
589 AT_DATA([algs-alpha], [dnl
26936c83 590kx-group=curve25519 kx-group-order-bits=252 kx-group-elt-bits=255
de8edc7f
MW
591hash=sha256 mgf=sha256-mgf hash-sz=32
592bulk-transform=naclbox bulk-overhead=20
26936c83 593cipher=chacha20 cipher-keysz=32
de8edc7f
MW
594mac=poly1305 mac-tagsz=16
595cipher-data-limit=2147483648
31b8e627
MW
596])
597
598 AT_DATA([algs-beta-old], [dnl
599kx-group=prime kx-group-order-bits=160 kx-group-elt-bits=1023
600hash=rmd160 mgf=rmd160-mgf hash-sz=20
a93aacce 601bulk-transform=v0 bulk-overhead=22
31b8e627 602cipher=blowfish-cbc cipher-keysz=20 cipher-blksz=8
31b8e627 603mac=rmd160-hmac mac-keysz=20 mac-tagsz=10
c70a7c5c 604cipher-data-limit=67108864
31b8e627
MW
605])
606
607 AT_DATA([algs-beta-new], [dnl
608kx-group=ec kx-group-order-bits=161 kx-group-elt-bits=320
609hash=rmd160 mgf=rmd160-mgf hash-sz=20
b87bffcb 610bulk-transform=iiv bulk-overhead=14
31b8e627 611cipher=blowfish-cbc cipher-keysz=20 cipher-blksz=8
31b8e627 612mac=rmd160-hmac mac-keysz=20 mac-tagsz=10
b87bffcb 613blkc=blowfish blkc-keysz=20 blkc-blksz=8
c70a7c5c 614cipher-data-limit=67108864
31b8e627
MW
615])
616
617 cp algs-alpha expout; AT_CHECK([TRIPECTL -dalice ALGS],, [expout])
618 cp algs-beta-old expout; AT_CHECK([TRIPECTL -dalice ALGS carol],, [expout])
619 cp algs-beta-old expout; AT_CHECK([TRIPECTL -dbob ALGS carol],, [expout])
620 cp algs-beta-new expout; AT_CHECK([TRIPECTL -dcarol ALGS],, [expout])
621 cp algs-beta-old expout; AT_CHECK([TRIPECTL -dcarol ALGS alice],, [expout])
622
623 ## Now copy the full keys. We expect this to provoke key exchange.
624 for p in $princs; do
625 TRIPECTL -d$p WARN test COMMENT tweak beta step 2
626 done
627
628 for p in $princs; do cp keyring keyring.pub $p/; done
629
630 AWAIT_KXDONE([alice], [alice], [carol], [carol], [
631 TRIPECTL -dalice RELOAD
632 AWAIT_KXDONE([bob], [bob], [carol], [carol], [
633 TRIPECTL -dbob RELOAD
634 TRIPECTL -dcarol RELOAD
635 ])
636 ])
637
638 cp algs-alpha expout; AT_CHECK([TRIPECTL -dalice ALGS],, [expout])
639 cp algs-beta-new expout; AT_CHECK([TRIPECTL -dalice ALGS carol],, [expout])
640 cp algs-beta-new expout; AT_CHECK([TRIPECTL -dbob ALGS carol],, [expout])
641 cp algs-beta-new expout; AT_CHECK([TRIPECTL -dcarol ALGS],, [expout])
642])
643
644AT_CLEANUP
645
5d85da1c
MW
646###--------------------------------------------------------------------------
647### Services.
648
649AT_SETUP([server services])
650AT_KEYWORDS([svc])
59d05259 651SETUPDIR([alpha])
5d85da1c
MW
652
653WITH_TRIPE(, [
654
655 ## Make sure it's not running yet.
656 AT_CHECK([TRIPECTL SVCENSURE test], [1],,
657 [tripectl: unknown-service test[]nl])
658
659 ## Run a simple service.
660 rm -f svc-test-running tripectl-status
661 COPROCESSES([svc], [
662 echo SVCCLAIM test 1.0.0
663 read line
664 case "$line" in
665 OK)
2f20abf2 666 ;;
5d85da1c 667 *)
2f20abf2 668 echo >&2 "SVCCLAIM failed: $line"
5d85da1c
MW
669 exit 1
670 ;;
671 esac
672 echo ok >svc-test-running
673 while read line; do
674 set -- $line
675 case "$[]1,$[]3,$[]4" in
676 SVCJOB,test,HELP)
677 echo SVCINFO try not to use this service for anything useful
678 echo SVCOK $[]2
679 ;;
680 SVCJOB,test,GOOD)
681 echo SVCOK $[]2
682 ;;
683 SVCJOB,test,BAD)
684 echo SVCFAIL $[]2 this-command-always-fails
685 ;;
686 SVCJOB,test,UGLY)
687 tag=$2
688 while read line; do
689 set -- $line
690 case "$[]1,$[]2,$[]3,$[]4" in
691 SVCCANCEL,$tag,,) break ;;
692 SVCJOB,*,test,ESCAPE)
2f20abf2 693 echo >&2 "attempt to escape from alkatraz"
5d85da1c
MW
694 exit 1
695 ;;
696 esac
697 done
698 ;;
699 SVCJOB,test,FIRST)
700 firsttag=$[]2
701 ;;
702 SVCJOB,test,SECOND)
703 echo SVCOK $firsttag
704 echo SVCOK $[]2
705 ;;
706 SVCJOB,*)
707 echo SVCFAIL $[]2 unknown-svc-command $[]4
708 ;;
709 SVCCLAIM,*)
710 break
711 ;;
712 OK,* | INFO,*)
713 ;;
714 FAIL,*)
715 echo "failure in service: $line" >&2
716 ;;
717 esac
718 done
719 ], [
720 TRIPECTL; echo $? >tripectl-status
721 ]) 2>tripectl-errors &
722
723 ## Wait until it starts up.
724 while test ! -r svc-test-running && test ! -r tripectl-status; do :; done
725
726 ## Make sure it's running.
727 AT_CHECK([TRIPECTL SVCQUERY test],, [name=test version=1.0.0[]nl])
728
729 ## Try some simple commands.
730 AT_CHECK([TRIPECTL SVCSUBMIT test GOOD])
731 AT_CHECK([TRIPECTL SVCSUBMIT test BAD], [1],,
732 [tripectl: this-command-always-fails[]nl])
733
734 ## And now with commands in the background.
735 TRIPECTL_INTERACT([
736 TRIPECTL_COMMAND([SVCSUBMIT test GOOD], [OK])
737 TRIPECTL_COMMAND([SVCSUBMIT -background foo test UGLY], [BGDETACH foo])
738 TRIPECTL_COMMAND([BGCANCEL foo], [OK])
739 TRIPECTL_COMMAND([SVCSUBMIT test ESCAPE],
740 [FAIL unknown-svc-command ESCAPE])
741 ])
742
743 ## Out-of-order completion.
744 TRIPECTL_INTERACT([
745 TRIPECTL_COMMAND([SVCSUBMIT -background one test FIRST], [BGDETACH one])
746 TRIPECTL_COMMAND([SVCSUBMIT -background two test SECOND], [BGDETACH two])
747 TRIPECTL_COMMAND([!], [BGOK one])
748 TRIPECTL_COMMAND([!], [BGOK two])
749 ])
750
751 ## All done.
752 exit 0
753])
754
755AT_CLEANUP
756
8362ac1c 757###--------------------------------------------------------------------------
067aa5f0 758### Knock and bye.
8362ac1c
MW
759
760AT_SETUP([server knock])
761AT_KEYWORDS([knock])
762export TRIPE_SLIPIF=USLIP
763
d5cdcb8a 764for i in alice bob; do (mkdir $i; cd $i; SETUPDIR([gamma])); done
8362ac1c
MW
765
766WITH_2TRIPES([alice], [bob], [-nslip], [-talice], [-tbob], [
767 WITH_MITM([alice], [5311], [bob], [5312], [
768
769 COPROCESSES([wait-knock], [
770 echo WATCH +n
771 while read line; do
772 set x $line; shift
773 echo >&2 ">>> $line"
774 case "$1:$2:$3" in
775 OK::) ;;
776 NOTE:KNOCK:bob) shift 3; echo "$*" >knock-addr; break ;;
777 NOTE:* | TRACE:* | WARN:*) ;;
778 *) exit 63 ;;
779 esac
780 done
781 ], [
782 TRIPECTL -dalice
783 ])& waiter=$!
784
785 AT_CHECK([TRIPECTL -dbob ADD -knock bob alice INET 127.0.0.1 5312])
786
787 wait $waiter; waitrc=$?
788 AT_CHECK([echo $waitrc],, [0[]nl])
789 AT_CHECK([cat knock-addr],, [INET 127.0.0.1 5311[]nl])
790
791 AWAIT_KXDONE([alice], [alice], [bob], [bob], [
067aa5f0 792 AT_CHECK([TRIPECTL -dalice ADD -ephemeral bob INET 127.0.0.1 5311])
8362ac1c
MW
793 ])
794
795 COMMS_EPING([alice], [alice], [bob], [bob])
796 COMMS_SLIP([alice], [alice], [bob], [bob])
797 ])
798
799 WITH_MITM([alice], [5319], [bob], [5312], [
800 AWAIT_KXDONE([alice], [alice], [bob], [bob], [
801 AT_CHECK([TRIPECTL -dalice FORCEKX bob])
802 AT_CHECK([TRIPECTL -dbob FORCEKX alice])
803 ])
067aa5f0 804
8362ac1c
MW
805 AT_CHECK([TRIPECTL -dbob KILL alice])
806 AT_CHECK([TRIPECTL -dalice LIST],, [])
807 ])
808])
809
810AT_CLEANUP
811
8dc315cd
MW
812###--------------------------------------------------------------------------
813### Key-exchange ad bulk crypto round trip.
814
815AT_SETUP([server roundtrip])
816AT_KEYWORDS([roundtrip])
817
818while read label genalg paramalg spec; do
819 paramopts=${spec%--*} attrs=${spec#*--}
820 key -kkeyring.$label add -a$paramalg -eforever $paramopts -tparam tripe-param $attrs
821 key -kkeyring.$label add -a$genalg -pparam -eforever -talice tripe
822 key -kkeyring.$label extract -f-secret keyring.$label-pub
823 { sh -c "echo $$"; date; } >msg
824 AT_CHECK([BULKTEST -kkeyring.$label -talice \
825 ies-encrypt 99 "$(cat msg)nl"], [0], [stdout], [stderr])
826 cp msg expout; mv stdout ct
827 AT_CHECK([BULKTEST -kkeyring.$label -talice \
828 ies-decrypt 99 "$(cat ct)"], [0], [expout], [stderr])
829done <<EOF
830vanilla dh dh-param -Ccatacomb-ll-256-3072 --
831suite-b ec ec-param -Cnist-p256 -- kx-group=ec bulk=iiv cipher=rijndael-counter hash=sha256
832djb x25519 empty -- kx-group=x25519 bulk=naclbox cipher=salsa20
833fancy x448 empty -- kx-group=x448 bulk=aead cipher=chacha20-poly1305 hash=shake256 mgf=shake256-xof
834weird x25519 empty -- kx-group=x25519 bulk=aead cipher=blowfish-ocb3 hash=sha256 tagsz=48
835terrible ec ec-param -Csecp112r1 -- kx-group=ec bulk=aead cipher=des-ccm mac=aead/16
836EOF
837
838AT_CLEANUP
839
5d85da1c 840###----- That's all, folks --------------------------------------------------