chiark / gitweb /
proxy/tripe-mitm.c, server/tests.at: Optionally use kernel-assigned ports.
[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
a23e7183
MW
46## Pause for a bit.
47m4_define([SLEEP], [sleep 0.2])
48
9867bea0
MW
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.
55m4_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 "$[]@"' - \
5e55d10b 64 strace -ff -tt -v -s1024 -o../$1.trace \
9867bea0
MW
65 sh -c 'cd ..; exec "$[]@"' - \
66 $2)
67 ;;
68 esac])
69
5d85da1c
MW
70## Sequences. (These are used for testing the replay protection machinery.)
71m4_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])
73m4_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
05d4b7da 79## WITH_TRIPEX(dir, args, body)
5d85da1c
MW
80m4_define([WITH_TRIPEX], [
81
05d4b7da
MW
82## If this directory doesn't exist then Bad Things will happen.
83if test ! -d $1; then
84 echo >&2 "server directory \`$1' doesn't exist"
85 exit 99
86fi
87
5d85da1c
MW
88## Remove the status file. This is how we notice that the server's died.
89rm -f $1/server-status
90> $1/expected-server-output
91> $1/expected-server-errors
92
768a2316
MW
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.
5d85da1c
MW
96exec 3>&1
97{ (
98exec 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.)
768a2316 103while test ! -r $1/server-status && test ! -S $1/admin; do :; done
5d85da1c 104
05d4b7da
MW
105## Make the port number availale.
106AT_CHECK([TRIPECTL -d$1 PORT],, [stdout])
107mv stdout $1/port
108
5d85da1c
MW
109## Test body...
110$3
111
9867bea0 112## End of the test, now run the server.
5d85da1c
MW
113) && :; } | {
114 cd $1
115 echo TRIPE $2 >&2
377824e5 116 WITH_STRACE([tripe], [TRIPE $2 >server-output.full 2>server-errors.full])
5d85da1c
MW
117 stat=$?
118 echo $stat >server-status
119 if test $stat -ne 0; then
377824e5 120 echo "exit status: $stat" >>server-errors.full
5d85da1c 121 fi
377824e5 122 grep -v '^+ tripe: ' server-errors.full >server-errors
05d4b7da
MW
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]]);
ee7a2a10 173 if (substr($[]0, 1, n) == pat[[i]])
05d4b7da
MW
174 next;
175 }
176 print $[]0;
177 }
178 ' server-output.full >server-output
5d85da1c
MW
179}
180exec 3>&-
181
182## Now check that the server's output matches our expectations.
183mv $1/expected-server-output expout
184mv $1/expected-server-errors experr
185AT_CHECK([cat $1/server-output; cat >&2 $1/server-errors],,
186 [expout], [experr])
187])
188
05d4b7da 189## WITH_TRIPE(args, body)
5d85da1c
MW
190m4_define([WITH_TRIPE], [WITH_TRIPEX([.], [$1], [$2])])
191
05d4b7da 192## WITH_2TRIPES(adir, bdir, bothargs, aargs, bargs, body)
5d85da1c
MW
193m4_define([WITH_2TRIPES],
194 [WITH_TRIPEX([$1], [$3 $4], [WITH_TRIPEX([$2], [$3 $5], [$6])])])
195
203e1b1f
MW
196## WITH_3TRIPES(adir, bdir, cdir, allargs, aargs, bargs, cargs, body)
197m4_define([WITH_3TRIPES],
198 [WITH_TRIPEX([$1], [$4 $5],
199 [WITH_TRIPEX([$2], [$4 $6],
200 [WITH_TRIPEX([$3], [$4 $7],
201 [$8])])])])
202
9e930d39
MW
203## RETRY(n, body)
204m4_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])
05d4b7da 216m4_define([COMMS_EPING], [
9e930d39
MW
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])
05d4b7da
MW
221])
222
223## COMMS_SLIP(adir, aname, bdir, bname)
224m4_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)
232m4_define([AWAIT_KXDONE], [
233
234 ## Ignore some reports caused by races.
add23883
MW
235 for i in $1!$4 $3!$2; do
236 d=${i%!*} o=${i#*!}
91a97a96 237 TRIPECTL -d$d WARN test PUSH
add23883
MW
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
91a97a96 241 done
05d4b7da
MW
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 ;;
bf67ce8d 252 NOTE:* | TRACE:* | WARN:*) ;;
05d4b7da
MW
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.
91a97a96 267 for d in $1 $3; do TRIPECTL -d$d WARN test POP; done
05d4b7da
MW
268])
269
01c21903 270## ESTABLISH(adir, aname, aopts, bdir, bname, bopts, [aport], [bport])
05d4b7da
MW
271m4_define([ESTABLISH], [
272
273 ## Set up the establishment.
274 AWAIT_KXDONE([$1], [$2], [$4], [$5], [
01c21903
MW
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])])
05d4b7da
MW
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
5d85da1c
MW
290###--------------------------------------------------------------------------
291### Very unpleasant coprocess handling.
292
293## COPROCESSES(TAG, PROC-A, PROC-B)
294m4_define([COPROCESSES], [dnl
295rm -f pipe-$1; mknod pipe-$1 p
296{ { $2 nl } <pipe-$1 | { $3 nl } >pipe-$1; } dnl
297])
298
299## TRIPECTL_INTERACT(ARGS, SHELLSTUFF)
300m4_define([TRIPECTL_INTERACT], [
768a2316 301 exec 3>&1
11715242 302 COPROCESSES([client], [exec 4>&1 1>&3 $1], [TRIPECTL $2])
5d85da1c
MW
303])
304
305## TRIPECTL_COMMAND(CMD, EXPECT)
306m4_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
321AT_SETUP([server basics])
59d05259 322SETUPDIR([alpha])
5d85da1c
MW
323AT_CHECK([echo port | TRIPE -p54321],, [INFO 54321[]nl[]OK[]nl])
324AT_CLEANUP
325
326###--------------------------------------------------------------------------
327### Challenges.
328
329AT_SETUP([server challenges])
330AT_KEYWORDS([chal])
59d05259 331SETUPDIR([alpha])
5d85da1c
MW
332
333WITH_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
380AT_CLEANUP
381
382###--------------------------------------------------------------------------
383### Communication.
384
385AT_SETUP([server communication])
386AT_KEYWORDS([comm])
387export TRIPE_SLIPIF=USLIP
388
b87bffcb
MW
389for 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 ])
a49d0131 397 for p in alice bob; do rm -rf $p.$k; mv $p $p.$k; done
b87bffcb 398done
5d85da1c
MW
399
400AT_CLEANUP
401
01c21903
MW
402###--------------------------------------------------------------------------
403### Mobile peer tracking.
404
405AT_SETUP([peer tracking])
406AT_KEYWORDS([mobile])
407export TRIPE_SLIPIF=USLIP
408
409for p in alice bob carol; do (mkdir $p; cd $p; SETUPDIR([alpha])); done
410
6d5eac37
MW
411## WITH_MITM(adir, aport, bdir, bport, body)
412m4_define([WITH_MITM], [
a23e7183
MW
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
6d5eac37 416 MITM -k$1/keyring.pub \
a23e7183
MW
417 peer:$1:$aport:127.0.0.1:$(cat $1/port) \
418 peer:$3:$bport:127.0.0.1:$(cat $3/port) \
6d5eac37 419 filt:send& mitmpid_$1_$3=$!
a23e7183
MW
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"
6d5eac37 424 trap 'kill $mitmpid_$1_$3; exit 127' EXIT INT QUIT TERM HUP
a23e7183 425 SLEEP
01c21903 426 $5
6d5eac37 427 kill $mitmpid_$1_$3; trap - EXIT INT QUIT TERM HUP
01c21903
MW
428])
429
430WITH_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
6d5eac37 435 ## this is the mitm proxy, so we may as well use that.
01c21903 436 ##
6d5eac37
MW
437 ## alice <--> :5311 <-mitm-> :5312 <--> bob
438 ## alice <--> :5321 <-mitm-> :5322 <--> carol
01c21903 439
a23e7183
MW
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])
01c21903
MW
444 ])
445
a23e7183 446 WITH_MITM([alice], [=new_bob_from_alice], [bob], [$alice_from_bob], [
01c21903
MW
447 COMMS_EPING([bob], [bob], [alice], [alice])
448 COMMS_SLIP([bob], [bob], [alice], [alice])
449 ])
450
a23e7183
MW
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])
01c21903
MW
455 ])
456
a23e7183
MW
457 WITH_MITM([alice], [$bob_from_alice], [bob], [$alice_from_bob], [
458 WITH_MITM([alice], [$carol_from_alice], [carol], [$alice_from_carol], [
01c21903
MW
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
a23e7183
MW
465 WITH_MITM([alice], [$carol_from_alice], [bob], [$alice_from_bob], [
466 WITH_MITM([alice], [$bob_from_alice], [carol], [$alice_from_carol], [
01c21903
MW
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
475AT_CLEANUP
476
f884ef9d
MW
477###--------------------------------------------------------------------------
478### Adverse communication.
479
480AT_SETUP([server retry])
481AT_KEYWORDS([backoff])
482export TRIPE_SLIPIF=USLIP
483
9cda68ab 484for i in alice bob; do (mkdir $i; cd $i; SETUPDIR([beta])); done
f884ef9d
MW
485
486WITH_2TRIPES([alice], [bob], [-nslip], [-talice], [-tbob], [
487
488 ## Set up the evil proxy.
ee07712c
MW
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 \
a23e7183
MW
493 peer:alice:\?alice.mitm:127.0.0.1:$(cat alice/port) \
494 peer:bob:\?bob.mitm:127.0.0.1:$(cat bob/port) \
ee07712c
MW
495 filt:drop:5 filt:send])&
496 read mitmpid <pipe-mitmpid
a23e7183
MW
497 SLEEP
498 alicemitm=$(cat alice.mitm) bobmitm=$(cat bob.mitm)
ee07712c
MW
499 trap 'kill $mitmpid; exit 127' EXIT INT QUIT TERM HUP
500 exec 3>&-
f884ef9d
MW
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
f884ef9d
MW
514])
515
516AT_CLEANUP
517
31b8e627
MW
518###--------------------------------------------------------------------------
519### Key management.
520
521AT_SETUP([server key-management])
522AT_KEYWORDS([keymgmt])
523export TRIPE_SLIPIF=USLIP
524
525## Determine all of the nets and the principals.
526princs=""
527nets=" "
528while 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
533done <<PRINC
534alice alpha beta
535bob alpha beta
536carol beta
537PRINC
538
539## Build the master keyring. All key tags here are of the form PRINC/NET.
540for 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
545done
546key extract -f-secret keyring.pub
547
548## Set up the principals' directories.
549for p in $princs; do
550 mkdir $p
551 cp keyring keyring.pub $p/
552done
553
554WITH_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
26936c83 603kx-group=curve25519 kx-group-order-bits=252 kx-group-elt-bits=255
de8edc7f
MW
604hash=sha256 mgf=sha256-mgf hash-sz=32
605bulk-transform=naclbox bulk-overhead=20
26936c83 606cipher=chacha20 cipher-keysz=32
de8edc7f
MW
607mac=poly1305 mac-tagsz=16
608cipher-data-limit=2147483648
31b8e627
MW
609])
610
611 AT_DATA([algs-beta-old], [dnl
612kx-group=prime kx-group-order-bits=160 kx-group-elt-bits=1023
613hash=rmd160 mgf=rmd160-mgf hash-sz=20
a93aacce 614bulk-transform=v0 bulk-overhead=22
31b8e627 615cipher=blowfish-cbc cipher-keysz=20 cipher-blksz=8
31b8e627 616mac=rmd160-hmac mac-keysz=20 mac-tagsz=10
c70a7c5c 617cipher-data-limit=67108864
31b8e627
MW
618])
619
620 AT_DATA([algs-beta-new], [dnl
621kx-group=ec kx-group-order-bits=161 kx-group-elt-bits=320
622hash=rmd160 mgf=rmd160-mgf hash-sz=20
b87bffcb 623bulk-transform=iiv bulk-overhead=14
31b8e627 624cipher=blowfish-cbc cipher-keysz=20 cipher-blksz=8
31b8e627 625mac=rmd160-hmac mac-keysz=20 mac-tagsz=10
b87bffcb 626blkc=blowfish blkc-keysz=20 blkc-blksz=8
c70a7c5c 627cipher-data-limit=67108864
31b8e627
MW
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
657AT_CLEANUP
658
5d85da1c
MW
659###--------------------------------------------------------------------------
660### Services.
661
662AT_SETUP([server services])
663AT_KEYWORDS([svc])
59d05259 664SETUPDIR([alpha])
5d85da1c
MW
665
666WITH_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)
2f20abf2 679 ;;
5d85da1c 680 *)
2f20abf2 681 echo >&2 "SVCCLAIM failed: $line"
5d85da1c
MW
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)
2f20abf2 706 echo >&2 "attempt to escape from alkatraz"
5d85da1c
MW
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
768AT_CLEANUP
769
8362ac1c 770###--------------------------------------------------------------------------
067aa5f0 771### Knock and bye.
8362ac1c
MW
772
773AT_SETUP([server knock])
774AT_KEYWORDS([knock])
775export TRIPE_SLIPIF=USLIP
776
d5cdcb8a 777for i in alice bob; do (mkdir $i; cd $i; SETUPDIR([gamma])); done
8362ac1c
MW
778
779WITH_2TRIPES([alice], [bob], [-nslip], [-talice], [-tbob], [
a23e7183 780 WITH_MITM([alice], [=bob_from_alice], [bob], [=alice_from_bob], [
8362ac1c
MW
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
a23e7183 798 AT_CHECK([TRIPECTL -dbob ADD -knock bob alice INET 127.0.0.1 $alice_from_bob])
8362ac1c
MW
799
800 wait $waiter; waitrc=$?
801 AT_CHECK([echo $waitrc],, [0[]nl])
a23e7183 802 AT_CHECK_UNQUOTED([cat knock-addr],, [INET 127.0.0.1 $bob_from_alice[]nl])
8362ac1c
MW
803
804 AWAIT_KXDONE([alice], [alice], [bob], [bob], [
a23e7183 805 AT_CHECK([TRIPECTL -dalice ADD -ephemeral bob INET 127.0.0.1 $bob_from_alice])
8362ac1c
MW
806 ])
807
808 COMMS_EPING([alice], [alice], [bob], [bob])
809 COMMS_SLIP([alice], [alice], [bob], [bob])
810 ])
811
a23e7183 812 WITH_MITM([alice], [=new_bob_from_alice], [bob], [$alice_from_bob], [
8362ac1c
MW
813 AWAIT_KXDONE([alice], [alice], [bob], [bob], [
814 AT_CHECK([TRIPECTL -dalice FORCEKX bob])
815 AT_CHECK([TRIPECTL -dbob FORCEKX alice])
816 ])
067aa5f0 817
8362ac1c
MW
818 AT_CHECK([TRIPECTL -dbob KILL alice])
819 AT_CHECK([TRIPECTL -dalice LIST],, [])
820 ])
821])
822
823AT_CLEANUP
824
8dc315cd
MW
825###--------------------------------------------------------------------------
826### Key-exchange ad bulk crypto round trip.
827
828AT_SETUP([server roundtrip])
829AT_KEYWORDS([roundtrip])
830
831while 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])
842done <<EOF
843vanilla dh dh-param -Ccatacomb-ll-256-3072 --
844suite-b ec ec-param -Cnist-p256 -- kx-group=ec bulk=iiv cipher=rijndael-counter hash=sha256
845djb x25519 empty -- kx-group=x25519 bulk=naclbox cipher=salsa20
846fancy x448 empty -- kx-group=x448 bulk=aead cipher=chacha20-poly1305 hash=shake256 mgf=shake256-xof
847weird x25519 empty -- kx-group=x25519 bulk=aead cipher=blowfish-ocb3 hash=sha256 tagsz=48
848terrible ec ec-param -Csecp112r1 -- kx-group=ec bulk=aead cipher=des-ccm mac=aead/16
849EOF
850
851AT_CLEANUP
852
5d85da1c 853###----- That's all, folks --------------------------------------------------