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