libimcv: Fixed processing of PTS Simple Component Evidence
[strongswan.git] / testing / do-tests
1 #!/bin/bash
2 # Automatically execute the strongSwan test cases
3 #
4 # Copyright (C) 2004  Eric Marchionni, Patrik Rayo
5 # Zuercher Hochschule Winterthur
6 #
7 # This program is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by the
9 # Free Software Foundation; either version 2 of the License, or (at your
10 # option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
11 #
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 # for more details.
16
17 DIR=$(dirname `readlink -f $0`)
18 . $DIR/testing.conf
19 . $DIR/scripts/function.sh
20 SSHCONF="-F $DIR/ssh_config"
21
22 [ -d $DIR/hosts ] || die "Directory 'hosts' not found"
23 [ -d $DIR/tests ] || die "Directory 'tests' not found"
24 [ -d $BUILDDIR ] ||
25         die "Directory '$BUILDDIR' does not exist, please run make-testing first"
26 running_any $STRONGSWANHOSTS || die "Please start test environment before running $0"
27
28 ln -sfT $DIR $TESTDIR/testing
29
30 ##############################################################################
31 # take care of new path and file variables
32 #
33
34 [ -d $TESTRESULTSDIR ] || mkdir $TESTRESULTSDIR
35
36 TESTDATE=`date +%Y%m%d-%H%M-%S`
37
38 TODAYDIR=$TESTRESULTSDIR/$TESTDATE
39 mkdir $TODAYDIR
40 TESTRESULTSHTML=$TODAYDIR/all.html
41 INDEX=$TODAYDIR/index.html
42 DEFAULTTESTSDIR=$TESTDIR/testing/tests
43
44 SOURCEIP_ROUTING_TABLE=220
45
46 testnumber="0"
47 failed_cnt="0"
48 passed_cnt="0"
49 subdir_cnt="0"
50
51 ##############################################################################
52 # parse optional arguments
53 #
54 while getopts "v" opt
55 do
56         case "$opt" in
57         v)
58                 verbose=YES
59                 ;;
60         esac
61 done
62 shift $((OPTIND-1))
63
64
65 function print_time()
66 {
67         [ "$verbose" == "YES" ] && echo "$(date +%T.%N) ~ "
68 }
69
70 ##############################################################################
71 # copy default tests to $BUILDDIR
72 #
73
74 TESTSDIR=$BUILDDIR/tests
75 [ -d $TESTSDIR ] || mkdir $TESTSDIR
76
77 ##############################################################################
78 # assign IP for each host to hostname
79 #
80
81 for host in $STRONGSWANHOSTS
82 do
83     eval ipv4_${host}="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $1 }' | awk '{ print $1 }'`"
84     eval ipv6_${host}="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $1 }' | awk '{ print $1 }'`"
85
86     case $host in
87     moon)
88         eval ipv4_moon1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
89         eval ipv6_moon1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
90         ;;
91     sun)
92         eval ipv4_sun1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
93         eval ipv6_sun1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
94         ;;
95     alice)
96         eval ipv4_alice1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
97         eval ipv6_alice1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
98         ;;
99     venus)
100         ;;
101     bob)
102         ;;
103     carol)
104         eval ipv4_carol1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
105         eval ipv6_carol1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
106          ;;
107     dave)
108         eval ipv4_dave1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
109         eval ipv6_dave1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
110         ;;
111     winnetou)
112         ;;
113     esac
114 done
115
116
117 ##############################################################################
118 # open ssh sessions
119 #
120 for host in $STRONGSWANHOSTS
121 do
122     ssh $SSHCONF -N root@`eval echo \\\$ipv4_$host` >/dev/null 2>&1 &
123     eval ssh_pid_$host="`echo $!`"
124     do_on_exit kill `eval echo \\\$ssh_pid_$host`
125 done
126
127 ##############################################################################
128 # determine actual software versions
129 #
130
131 [ -f $SHAREDDIR/.strongswan-version ] && SWANVERSION=`cat $SHAREDDIR/.strongswan-version`
132 KERNELVERSION=`ssh $SSHCONF root@\$ipv4_winnetou uname -r 2>/dev/null`
133
134 # check if tcpdump supports --immediate-mode
135 ssh $SSHCONF root@$ipv4_winnetou tcpdump --immediate-mode -c 1 >/dev/null 2>&1
136 if [ $? -eq 0 ]
137 then
138         TCPDUMP_IM=--immediate-mode
139 fi
140
141 ##############################################################################
142 # create header for the results html file
143 #
144
145 ENVIRONMENT_HEADER=$(cat <<@EOF
146   <table border="0" cellspacing="2" cellpadding="2">
147     <tr valign="top">
148       <td><b>Host</b></td>
149       <td colspan="3">`uname -a`</td>
150     </tr>
151     <tr valign="top">
152       <td><b>Guest kernel</b></td>
153       <td colspan="3">$KERNELVERSION</td>
154     </tr>
155     <tr valign="top">
156       <td><b>strongSwan</b></td>
157       <td colspan="3">$SWANVERSION</td>
158     </tr>
159     <tr valign="top">
160       <td><b>Date</b></td>
161       <td colspan="3">$TESTDATE</td>
162     </tr>
163     <tr>
164       <td width="100">&nbsp;</td>
165       <td width="300">&nbsp;</td>
166       <td width=" 80">&nbsp;</td>
167       <td >&nbsp;</td>
168     </tr>
169 @EOF
170 )
171
172 cat > $INDEX <<@EOF
173 <html>
174 <head>
175   <title>strongSwan KVM Tests</title>
176 </head>
177 <body>
178   <h2>strongSwan KVM Tests</h2>
179   $ENVIRONMENT_HEADER
180 @EOF
181
182 cat > $TESTRESULTSHTML <<@EOF
183 <html>
184 <head>
185   <title>strongSwan KVM Tests - All Tests</title>
186 </head>
187 <body>
188   <div><a href="index.html">strongSwan KVM Tests</a> / All Tests</div>
189   <h2>All Tests</h2>
190   $ENVIRONMENT_HEADER
191     <tr align="left">
192       <th>Number</th>
193       <th>Test</th>
194       <th align="right">Time [s]</th>
195       <th>Result</th>
196     </tr>
197 @EOF
198
199 echo "Guest kernel : $KERNELVERSION"
200 echo "strongSwan   : $SWANVERSION"
201 echo "Date         : $TESTDATE"
202 echo
203
204 ##############################################################################
205 # trap CTRL-C to properly terminate a long run
206 #
207
208 function abort_tests()
209 {
210         echo -n "...aborting..." > /dev/tty
211         aborted=YES
212 }
213 trap abort_tests INT
214
215 ##############################################################################
216 # enter specific test directory
217 #
218 if [ $# -gt 0 ]
219 then
220     TESTS=$(printf "%s\n" $* | sort -u)
221 else
222     TESTS=$(ls $DEFAULTTESTSDIR)
223 fi
224
225 for SUBDIR in $TESTS
226 do
227     SUBTESTS="`basename $SUBDIR`"
228
229         if [ $SUBTESTS = $SUBDIR ]
230         then
231                 SUBTESTS="`ls $DEFAULTTESTSDIR/$SUBDIR`"
232         else
233                 if [[ $SUBTESTS == *'*'* ]]
234                 then
235                         SUBTESTS="`basename -a $DEFAULTTESTSDIR/$SUBDIR`"
236                 fi
237                 SUBDIR="`dirname $SUBDIR`"
238         fi
239
240     if [ ! -d $TODAYDIR/$SUBDIR ]
241     then
242         mkdir $TODAYDIR/$SUBDIR
243         if [ $testnumber == 0 ]
244         then
245             FIRST="<b>Category</b>"
246         else
247             FIRST="&nbsp;"
248         fi
249
250         if [ $subdir_cnt != 0 ]
251         then
252             echo "      <td align=\"right\">$subdir_cnt</td>" >> $INDEX
253             echo "      <td>&nbsp;</td>" >> $INDEX
254             echo "    </tr>" >> $INDEX
255             subdir_cnt="0"
256         fi
257         echo "    <tr>" >> $INDEX
258     echo "      <td>$FIRST</td>">> $INDEX
259     echo "      <td><a href=\"$SUBDIR/index.html\">$SUBDIR</a></td>" >> $INDEX
260
261         SUBTESTSINDEX=$TODAYDIR/$SUBDIR/index.html
262         cat > $SUBTESTSINDEX <<@EOF
263 <html>
264 <head>
265   <title>strongSwan $SUBDIR Tests</title>
266 </head>
267 <body>
268   <div><a href="../index.html">strongSwan KVM Tests</a> / $SUBDIR</div>
269   <h2>strongSwan $SUBDIR Tests</h2>
270   <table border="0" cellspacing="2" cellpadding="2">
271     <tr valign="top">
272       <td><b>Guest kernel</b></td>
273       <td colspan="3">$KERNELVERSION</td>
274     </tr>
275     <tr valign="top">
276       <td><b>strongSwan</b></td>
277       <td colspan="3">$SWANVERSION</td>
278     </tr>
279     <tr valign="top">
280       <td><b>Date</b></td>
281       <td colspan="3">$TESTDATE</td>
282     </tr>
283     <tr>
284       <td width="100">&nbsp;</td>
285       <td width="300">&nbsp;</td>
286       <td width=" 50">&nbsp;</td>
287       <td >&nbsp;</td>
288     </tr>
289     <tr align="left">
290        <th>Number</th>
291        <th>Test</th>
292        <th colspan="2">Result</th>
293     </tr>
294 @EOF
295     fi
296
297     for name in $SUBTESTS
298     do
299         let "testnumber += 1"
300         let "subdir_cnt += 1"
301         testname=$SUBDIR/$name
302         log_action " $testnumber $testname:"
303
304         teststart=$(date +%s)
305
306         if [ ! -d $DEFAULTTESTSDIR/${testname} ]
307         then
308             echo "is missing..skipped"
309             continue
310         fi
311
312         [ -f $DEFAULTTESTSDIR/${testname}/description.txt ] || die "!! File 'description.txt' is missing"
313         [ -f $DEFAULTTESTSDIR/${testname}/test.conf ]       || die "!! File 'test.conf' is missing"
314         [ -f $DEFAULTTESTSDIR/${testname}/pretest.dat ]     || die "!! File 'pretest.dat' is missing"
315         [ -f $DEFAULTTESTSDIR/${testname}/posttest.dat ]    || die "!! File 'posttest.dat' is missing"
316         [ -f $DEFAULTTESTSDIR/${testname}/evaltest.dat ]    || die "!! File 'evaltest.dat' is missing"
317
318         TESTRESULTDIR=$TODAYDIR/$testname
319         mkdir -p $TESTRESULTDIR
320         CONSOLE_LOG=$TESTRESULTDIR/console.log
321         touch $CONSOLE_LOG
322
323         TESTDIR=$TESTSDIR/${testname}
324
325         ##########################################################################
326         # copy test specific configurations to hosts and clear log files
327         #
328
329         DBDIR=/etc/db.d
330
331         $DIR/scripts/load-testconfig $testname
332         unset RADIUSHOSTS
333         unset DBHOSTS
334         unset IPV6
335         unset SWANCTL
336         source $TESTDIR/test.conf
337
338
339         ##########################################################################
340         # run tcpdump in the background
341         #
342
343         if [ "$TCPDUMPHOSTS" != "" ]
344         then
345             echo -e "TCPDUMP\n" >> $CONSOLE_LOG 2>&1
346
347             for host_iface in $TCPDUMPHOSTS
348             do
349                 host=`echo $host_iface | awk -F ":" '{print $1}'`
350                 iface=`echo $host_iface | awk -F ":" '{if ($2 != "") { print $2 } else { printf("eth0") }}'`
351                 tcpdump_cmd="tcpdump -l $TCPDUMP_IM -i $iface not port ssh and not port domain >/tmp/tcpdump.log 2>/tmp/tcpdump.err.log &"
352                 echo "$(print_time)${host}# $tcpdump_cmd" >> $CONSOLE_LOG
353                 ssh $SSHCONF root@`eval echo \\\$ipv4_$host '$tcpdump_cmd'`
354                 eval TDUP_${host}="true"
355             done
356         fi
357
358         ##########################################################################
359         # create database directory in RAM
360         #
361
362         for host in $DBHOSTS
363         do
364                 eval HOSTLOGIN=root@\$ipv4_${host}
365             ssh $SSHCONF $HOSTLOGIN "mkdir -p $DBDIR; mount -t ramfs -o size=5m ramfs $DBDIR" >/dev/null 2>&1
366             ssh $SSHCONF $HOSTLOGIN "chgrp www-data $DBDIR; chmod g+w $DBDIR" >/dev/null 2>&1
367         done
368
369         ##########################################################################
370         # flush conntrack table on all hosts
371         #
372
373         for host in $STRONGSWANHOSTS
374         do
375                 ssh $SSHCONF root@`eval echo \\\$ipv4_$host` 'conntrack -F' >/dev/null 2>&1
376         done
377
378         ##########################################################################
379         # remove leak detective log on all hosts
380         #
381
382         export LEAK_DETECTIVE_LOG=/var/log/leak-detective.log
383         for host in $STRONGSWANHOSTS
384         do
385                 ssh $SSHCONF root@`eval echo \\\$ipv4_$host` 'rm -f $LEAK_DETECTIVE_LOG' >/dev/null 2>&1
386         done
387
388         ##########################################################################
389         # flush IPsec state on all hosts
390         #
391
392         for host in $STRONGSWANHOSTS
393         do
394                 ssh $SSHCONF root@`eval echo \\\$ipv4_$host` 'ip xfrm state flush; ip xfrm policy flush' >/dev/null 2>&1
395         done
396
397         ##########################################################################
398         # execute pre-test commands
399         #
400
401         echo -n "pre.."
402         echo -e "\nPRE-TEST\n" >> $CONSOLE_LOG 2>&1
403
404         eval `awk -F "::" '{
405             if ($1 !~ /^#.*/ && $2 != "")
406             {
407                 printf("echo \"$(print_time)%s# %s\"; ", $1, $2)
408                 printf("ssh \044SSHCONF root@\044ipv4_%s \"%s\"; ", $1, $2)
409                 printf("echo;\n")
410             }
411         }' $TESTDIR/pretest.dat` >> $CONSOLE_LOG 2>&1
412
413
414         ##########################################################################
415         # stop tcpdump
416         #
417
418         function stop_tcpdump {
419             # wait for packets to get processed, but don't wait longer than 1s
420             eval ssh $SSHCONF root@\$ipv4_${1} "\"i=100; while [ \\\$i -gt 0 ]; do pkill -USR1 tcpdump; tail -1 /tmp/tcpdump.err.log | perl -n -e '/(\\d+).*?(\\d+)/; exit (\\\$1 == \\\$2)' || break; sleep 0.01; i=\\\$((\\\$i-1)); done;\""
421             echo "$(print_time)${1}# killall tcpdump" >> $CONSOLE_LOG
422             eval ssh $SSHCONF root@\$ipv4_${1} "\"killall tcpdump; while true; do killall -q -0 tcpdump || break; sleep 0.01; done;\""
423             eval TDUP_${1}="false"
424             echo "" >> $CONSOLE_LOG
425         }
426
427
428         ##########################################################################
429         # get and evaluate test results
430         #
431
432         echo -n "test.."
433         echo -e "\nTEST\n" >> $CONSOLE_LOG 2>&1
434
435         STATUS="passed"
436
437         eval `awk -F "::" '{
438                 host=$1
439                 command=$2
440                 pattern=$3
441                 hit=$4
442                 if (host ~ /^#.*/ || command == "")
443                 {
444                         next
445                 }
446                 printf("cmd_err=\044(tempfile -p test -s err); ")
447                 if (command == "tcpdump")
448                 {
449                         printf("if [ \044TDUP_%s == \"true\" ]; then stop_tcpdump %s; fi; \n", host, host)
450                         printf("cmd_out=\044(ssh \044SSHCONF root@\044ipv4_%s cat /tmp/tcpdump.log | grep \"%s\"); ", host, pattern)
451                 }
452                 else
453                 {
454                         printf("cmd_out=\044(ssh \044SSHCONF root@\044ipv4_%s %s 2>\044cmd_err | grep \"%s\"); ",  host, command, pattern)
455                 }
456                 printf("cmd_exit=\044?; ")
457                 printf("cmd_fail=0; ")
458                 if (hit ~ /^[0-9]+$/)
459                 {
460                         printf("if [ \044(echo \"\044cmd_out\" | wc -l) -ne %d ] ", hit)
461                 }
462                 else
463                 {
464                         printf("if [ \044cmd_exit -eq 0 -a \"%s\" = \"NO\"  ] ", hit)
465                         printf("|| [ \044cmd_exit -ne 0 -a \"%s\" = \"YES\" ] ", hit)
466                 }
467                 printf("; then STATUS=\"failed\"; cmd_fail=1; fi; \n")
468
469                 printf("if [ \044cmd_fail -ne 0 ]; then echo \"~~~~~~~ FAIL ~~~~~~~\"; fi; \n")
470                 if (command == "tcpdump")
471                 {
472                         printf("echo \"$(print_time)%s# cat /tmp/tcpdump.log | grep \047%s\047  [%s]\"; ", host, pattern, hit)
473                 }
474                 else
475                 {
476                         printf("echo \"$(print_time)%s# %s | grep \047%s\047  [%s]\"; ", host, command, pattern, hit)
477                 }
478                 printf("if [ -n \"\044cmd_out\" ]; then echo \"\044cmd_out\"; fi; \n")
479                 printf("cat \044cmd_err; rm -f -- \044cmd_err; \n")
480                 printf("if [ \044cmd_fail -ne 0 ]; then echo \"~~~~~~~~~~~~~~~~~~~~\"; fi; \n")
481                 printf("echo; ")
482         }' $TESTDIR/evaltest.dat` >> $CONSOLE_LOG 2>&1
483
484
485         ##########################################################################
486         # log statusall and listall output
487         # get copies of ipsec.conf, ipsec.secrets
488         # create index.html for the given test case
489
490         cat > $TESTRESULTDIR/index.html <<@EOF
491 <html>
492 <head>
493   <title>Test $testname</title>
494 </head>
495 <body>
496 <table border="0" cellpadding="0" cellspacing="0" width="600">
497   <tr><td>
498     <div><a href="../../index.html">strongSwan KVM Tests</a> / <a href="../index.html">$SUBDIR</a> / $name</div>
499     <h2>Test $testname</h2>
500     <h3>Description</h3>
501 @EOF
502
503         cat $TESTDIR/description.txt >> $TESTRESULTDIR/index.html
504
505         cat >> $TESTRESULTDIR/index.html <<@EOF
506     <ul>
507       <li><a href="console.log">console.log</a></li>
508     </ul>
509     <img src="../../images/$DIAGRAM" alt="$VIRTHOSTS">
510 @EOF
511
512         IPTABLES_CMD_V4="echo -e '=== filter table ==='; iptables  -v -n -L; echo -e '\n=== nat table ==='; iptables  -v -n -t nat -L; echo -e '\n=== mangle table ==='; iptables  -v -n -t mangle -L"
513         IPTABLES_CMD_V6="echo -e '=== filter table ==='; ip6tables -v -n -L; echo -e '\n=== nat table ==='; ip6tables -v -n -t nat -L; echo -e '\n=== mangle table ==='; ip6tables -v -n -t mangle -L"
514
515         if [ -n "$IPV6" ]
516         then
517             IPROUTE_CMD="ip -6 route list table $SOURCEIP_ROUTING_TABLE"
518             IPROUTE_DSP=$IPROUTE_CMD
519             IPTABLES_CMD="$IPTABLES_CMD_V6"
520             IPTABLES_DSP="ip6tables -L"
521             IPTABLES_SAVE_CMD="ip6tables-save"
522             IPTABLES_SAVE_DSP="ip6tables-save"
523         else
524             IPROUTE_CMD="ip route list table $SOURCEIP_ROUTING_TABLE"
525             IPROUTE_DSP=$IPROUTE_CMD
526             IPTABLES_CMD="$IPTABLES_CMD_V4"
527             IPTABLES_DSP="iptables -L"
528             IPTABLES_SAVE_CMD="iptables-save"
529             IPTABLES_SAVE_DSP="iptables-save"
530         fi
531
532         if [ $name = "net2net-ip4-in-ip6-ikev2" -o $name = "net2net-ip6-in-ip4-ikev2" ]
533         then
534             IPROUTE_CMD="ip route list table $SOURCEIP_ROUTING_TABLE; echo; ip -6 route list table $SOURCEIP_ROUTING_TABLE"
535             IPROUTE_DSP="ip (-6) route list table $SOURCEIP_ROUTING_TABLE"
536             IPTABLES_CMD="$IPTABLES_CMD_V4; echo; $IPTABLES_CMD_V6"
537             IPTABLES_DSP="iptables -L ; ip6tables -L"
538             IPTABLES_SAVE_CMD="iptables-save; echo; ip6tables-save"
539             IPTABLES_SAVE_DSP="iptables-save ; ip6tables-save"
540         fi
541
542         for host in $DBHOSTS
543         do
544             eval HOSTLOGIN=root@\$ipv4_${host}
545
546                 scp $SSHCONF $HOSTLOGIN:/etc/db.d/ipsec.sql \
547                     $TESTRESULTDIR/${host}.ipsec.sql  > /dev/null 2>&1
548         done
549
550         for host in $IPSECHOSTS
551         do
552             eval HOSTLOGIN=root@\$ipv4_${host}
553
554                 scp $SSHCONF $HOSTLOGIN:/etc/strongswan.conf \
555                     $TESTRESULTDIR/${host}.strongswan.conf  > /dev/null 2>&1
556                 if [  -n "$SWANCTL" ]
557                 then
558                         scp $SSHCONF $HOSTLOGIN:/etc/swanctl/swanctl.conf \
559                         $TESTRESULTDIR/${host}.swanctl.conf  > /dev/null 2>&1
560
561                         for subsys in conns algs certs pools authorities sas pols
562                         do
563                                 ssh $SSHCONF $HOSTLOGIN swanctl --list-$subsys \
564                                         > $TESTRESULTDIR/${host}.swanctl.$subsys 2>/dev/null
565                         done
566
567                         ssh $SSHCONF $HOSTLOGIN swanctl --stats \
568                                 > $TESTRESULTDIR/${host}.swanctl.stats 2>/dev/null
569
570                         echo "" >> $TESTRESULTDIR/${host}.swanctl.sas
571                         cat $TESTRESULTDIR/${host}.swanctl.pols >> \
572                                 $TESTRESULTDIR/${host}.swanctl.sas
573                         cat $TESTRESULTDIR/${host}.swanctl.algs >> \
574                                 $TESTRESULTDIR/${host}.swanctl.stats
575                 else
576                     for file in ipsec.conf ipsec.secrets
577                     do
578                                 scp $SSHCONF $HOSTLOGIN:/etc/$file \
579                             $TESTRESULTDIR/${host}.$file  > /dev/null 2>&1
580                     done
581
582                     for command in statusall listall
583                     do
584                                 ssh $SSHCONF $HOSTLOGIN ipsec $command \
585                             > $TESTRESULTDIR/${host}.$command 2>/dev/null
586                     done
587                 fi
588
589                 if (! [ -f $TESTRESULTDIR/${host}.ipsec.sql ] ) then
590                         scp $SSHCONF $HOSTLOGIN:/etc/ipsec.d/ipsec.sql \
591                                 $TESTRESULTDIR/${host}.ipsec.sql  > /dev/null 2>&1
592                 fi
593
594             ssh $SSHCONF $HOSTLOGIN ip -s xfrm policy \
595                     > $TESTRESULTDIR/${host}.ip.policy 2>/dev/null
596             ssh $SSHCONF $HOSTLOGIN ip -s xfrm state \
597                     > $TESTRESULTDIR/${host}.ip.state 2>/dev/null
598             ssh $SSHCONF $HOSTLOGIN $IPROUTE_CMD \
599                     > $TESTRESULTDIR/${host}.ip.route 2>/dev/null
600             ssh $SSHCONF $HOSTLOGIN $IPTABLES_CMD \
601                     > $TESTRESULTDIR/${host}.iptables 2>/dev/null
602                 ssh $SSHCONF $HOSTLOGIN $IPTABLES_SAVE_CMD \
603                     > $TESTRESULTDIR/${host}.iptables-save 2>/dev/null
604             chmod a+r $TESTRESULTDIR/*
605
606                 if [ -n "$SWANCTL" ]
607                 then
608                     cat >> $TESTRESULTDIR/index.html <<@EOF
609     <h3>$host</h3>
610       <table border="0" cellspacing="0" width="600">
611       <tr>
612         <td valign="top">
613           <ul>
614             <li><a href="$host.swanctl.conf">swanctl.conf</a></li>
615             <li><a href="$host.swanctl.conns">swanctl --list-conns</a></li>
616             <li><a href="$host.swanctl.certs">swanctl --list-certs</a></li>
617             <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
618             <li><a href="$host.ipsec.sql">ipsec.sql</a></li>
619           </ul>
620         </td>
621         <td valign="top">
622           <ul>
623             <li><a href="$host.swanctl.sas">swanctl --list-sas|--list-pols</a></li>
624             <li><a href="$host.swanctl.pools">swanctl --list-pools</a></li>
625             <li><a href="$host.swanctl.authorities">swanctl --list-authorities</a></li>
626             <li><a href="$host.swanctl.stats">swanctl --stats|--list-algs</a></li>
627             <li><a href="$host.auth.log">auth.log</a></li>
628             <li><a href="$host.daemon.log">daemon.log</a></li>
629           </ul>
630       </td>
631         <td valign="top">
632           <ul>
633             <li><a href="$host.ip.policy">ip -s xfrm policy</a></li>
634             <li><a href="$host.ip.state">ip -s xfrm state</a></li>
635             <li><a href="$host.ip.route">$IPROUTE_DSP</a></li>
636             <li><a href="$host.iptables">$IPTABLES_DSP</a></li>
637             <li><a href="$host.iptables-save">$IPTABLES_SAVE_DSP</a></li>
638           </ul>
639           &nbsp;
640       </td>
641     </tr>
642     </table>
643 @EOF
644
645                 else
646                     cat >> $TESTRESULTDIR/index.html <<@EOF
647     <h3>$host</h3>
648       <table border="0" cellspacing="0" width="600">
649       <tr>
650         <td valign="top">
651           <ul>
652             <li><a href="$host.ipsec.conf">ipsec.conf</a></li>
653             <li><a href="$host.ipsec.secrets">ipsec.secrets</a></li>
654             <li><a href="$host.ipsec.sql">ipsec.sql</a></li>
655             <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
656           </ul>
657         </td>
658         <td valign="top">
659           <ul>
660             <li><a href="$host.statusall">ipsec statusall</a></li>
661             <li><a href="$host.listall">ipsec listall</a></li>
662             <li><a href="$host.auth.log">auth.log</a></li>
663             <li><a href="$host.daemon.log">daemon.log</a></li>
664           </ul>
665       </td>
666         <td valign="top">
667           <ul>
668             <li><a href="$host.ip.policy">ip -s xfrm policy</a></li>
669             <li><a href="$host.ip.state">ip -s xfrm state</a></li>
670             <li><a href="$host.ip.route">$IPROUTE_DSP</a></li>
671             <li><a href="$host.iptables">$IPTABLES_DSP</a></li>
672             <li><a href="$host.iptables-save">$IPTABLES_SAVE_DSP</a></li>
673           </ul>
674       </td>
675     </tr>
676     </table>
677 @EOF
678                 fi
679         done
680
681         for host in $RADIUSHOSTS
682         do
683             eval HOSTLOGIN=root@\$ipv4_${host}
684
685             for file in clients.conf eap.conf radiusd.conf proxy.conf users
686             do
687                 scp $SSHCONF $HOSTLOGIN:/etc/freeradius/$file \
688                     $TESTRESULTDIR/${host}.$file  > /dev/null 2>&1
689             done
690
691                 scp $SSHCONF $HOSTLOGIN:/etc/strongswan.conf \
692                     $TESTRESULTDIR/${host}.strongswan.conf  > /dev/null 2>&1
693
694             scp $SSHCONF $HOSTLOGIN:/var/log/freeradius/radius.log \
695                 $TESTRESULTDIR/${host}.radius.log  > /dev/null 2>&1
696
697             ssh $SSHCONF $HOSTLOGIN grep imcv /var/log/daemon.log \
698                 >> $TESTRESULTDIR/${host}.daemon.log 2>/dev/null
699
700             chmod a+r $TESTRESULTDIR/*
701             cat >> $TESTRESULTDIR/index.html <<@EOF
702     <h3>$host</h3>
703       <table border="0" cellspacing="0" width="600">
704       <tr>
705         <td valign="top">
706           <ul>
707             <li><a href="$host.clients.conf">clients.conf</a></li>
708             <li><a href="$host.radiusd.conf">radiusd.conf</a></li>
709             <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
710           </ul>
711         </td>
712         <td valign="top">
713           <ul>
714             <li><a href="$host.eap.conf">eap.conf</a></li>
715             <li><a href="$host.radius.log">radius.log</a></li>
716             <li><a href="$host.daemon.log">daemon.log</a></li>
717           </ul>
718       </td>
719         <td valign="top">
720           <ul>
721             <li><a href="$host.proxy.conf">proxy.conf</a></li>
722             <li><a href="$host.users">users</a></li>
723           </ul>
724       </td>
725     </tr>
726     </table>
727 @EOF
728
729         done
730
731         cat >> $TESTRESULTDIR/index.html <<@EOF
732         <h3>tcpdump</h3>
733         <ul>
734 @EOF
735
736         for host in $TCPDUMPHOSTS
737         do
738             cat >> $TESTRESULTDIR/index.html <<@EOF
739             <li><a href="$host.tcpdump.log">$host tcpdump.log</a></li>
740 @EOF
741         done
742
743         cat >> $TESTRESULTDIR/index.html <<@EOF
744         </ul>
745 @EOF
746
747         cat >> $TESTRESULTDIR/index.html <<@EOF
748   </td></tr>
749 </table>
750 </body>
751 </html>
752 @EOF
753
754
755         ##########################################################################
756         # execute post-test commands
757         #
758
759         echo -n "post"
760         echo -e "\nPOST-TEST\n" >> $CONSOLE_LOG 2>&1
761
762         eval `awk -F "::" '{
763             if ($1 !~ /^#.*/ && $2 != "")
764             {
765                 printf("echo \"$(print_time)%s# %s\"; ", $1, $2)
766                 printf("ssh \044SSHCONF root@\044ipv4_%s \"%s\"; ", $1, $2)
767                 printf("echo;\n")
768             }
769         }' $TESTDIR/posttest.dat` >> $CONSOLE_LOG 2>&1
770
771         ##########################################################################
772         # check that IPsec state was cleaned up properly
773         #
774
775         for host in $IPSECHOSTS
776         do
777                 eval HOSTLOGIN=root@\$ipv4_${host}
778                 IPSECSTATE=`ssh $SSHCONF $HOSTLOGIN 'ip xfrm state'`
779                 # ignore IPv4/v6 states created with IPComp SAs
780                 IPSECSTATEISSUE=`echo "$IPSECSTATE" | grep 'proto.*spi' | grep -v 'proto 4'`
781                 IPSECPOLICY=`ssh $SSHCONF $HOSTLOGIN 'ip xfrm policy'`
782                 if [ -n "$IPSECSTATEISSUE" -o -n "$IPSECPOLICY" ]
783                 then
784                         echo -e "\n$host# ip xfrm state [NO]" >> $CONSOLE_LOG
785                         echo "$IPSECSTATE" >> $CONSOLE_LOG
786                         echo -e "\n$host# ip xfrm policy [NO]" >> $CONSOLE_LOG
787                         echo "$IPSECPOLICY" >> $CONSOLE_LOG
788                         STATUS="failed"
789                 fi
790         done
791
792
793         ##########################################################################
794         # make sure there were no leaks
795         #
796
797         for host in $STRONGSWANHOSTS
798         do
799                 eval HOSTLOGIN=root@\$ipv4_${host}
800                 LEAKS=`ssh $SSHCONF $HOSTLOGIN 'cat $LEAK_DETECTIVE_LOG 2>/dev/null | grep -v "No leaks detected.*"'`
801                 if [ -n "$LEAKS" ]
802                 then
803                         echo -e "\n$host# cat $LEAK_DETECTIVE_LOG [NO]" >> $CONSOLE_LOG
804                         echo "$LEAKS" >> $CONSOLE_LOG
805                         echo "<<< $host $LEAK_DETECTIVE_LOG >>>" >> $CONSOLE_LOG
806                         STATUS="failed"
807                 fi
808         done
809
810
811         ##########################################################################
812         # get a copy of /var/log/auth.log
813         #
814
815         for host in $IPSECHOSTS
816         do
817             eval HOSTLOGIN=root@\$ipv4_${host}
818             ssh $SSHCONF $HOSTLOGIN "grep -s -E 'charon|last message repeated|imcv|pt-tls-client' \
819                 /var/log/auth.log" >> $TESTRESULTDIR/${host}.auth.log
820         done
821
822
823         ##########################################################################
824         # get a copy of /var/log/daemon.log
825         #
826
827         for host in $IPSECHOSTS
828         do
829             eval HOSTLOGIN=root@\$ipv4_${host}
830             ssh $SSHCONF $HOSTLOGIN "grep -s -E 'systemd|swanctl|charon|last message repeated|imcv' \
831                 /var/log/daemon.log" >> $TESTRESULTDIR/${host}.daemon.log
832         done
833
834
835         ##########################################################################
836         # stop tcpdump if necessary
837         #
838
839         for host in $TCPDUMPHOSTS
840         do
841             if [ "`eval echo \\\$TDUP_${host}`" = "true" ]
842             then
843                         stop_tcpdump $host
844             fi
845             eval HOSTLOGIN=root@\$ipv4_${host}
846                 scp $SSHCONF $HOSTLOGIN:/tmp/tcpdump.log \
847                         $TESTRESULTDIR/${host}.tcpdump.log > /dev/null 2>&1
848         done
849
850         ##########################################################################
851         # remove database directory if needed
852         #
853
854         for host in $DBHOSTS
855         do
856                 eval HOSTLOGIN=root@\$ipv4_${host}
857             ssh $SSHCONF $HOSTLOGIN "umount $DBDIR; rm -r $DBDIR" > /dev/null 2>&1
858         done
859
860         ##########################################################################
861         # copy default host config back if necessary
862         #
863
864         $DIR/scripts/restore-defaults $testname
865
866
867         ##########################################################################
868         # set counters
869         #
870
871         if [ $STATUS = "failed" ]
872         then
873             let "failed_cnt += 1"
874         else
875             let "passed_cnt += 1"
876         fi
877
878
879         ##########################################################################
880         # write test status to html file
881         #
882         testend=$(date +%s)
883         let "testend -= teststart"
884         let "timetotal += testend"
885
886         if [ $STATUS = "passed" ]
887         then
888                 COLOR="green"
889                 log_status 0
890         else
891                 COLOR="red"
892                 log_status 1
893         fi
894
895         cat >> $TESTRESULTSHTML << @EOF
896   <tr>
897     <td>$testnumber</td>
898     <td><a href="$testname/index.html">$testname</a></td>
899     <td align="right">$testend</td>
900     <td><a href="$testname/console.log"><font color="$COLOR">$STATUS</font></a></td>
901   </tr>
902 @EOF
903         cat >> $SUBTESTSINDEX << @EOF
904   <tr>
905     <td>$testnumber</td>
906     <td><a href="$name/index.html">$name</a></td>
907     <td><a href="$name/console.log"><font color="$COLOR">$STATUS</font></a></td>
908     <td>&nbsp;</td>
909   </tr>
910 @EOF
911
912
913         ##########################################################################
914         # remove any charon.pid files that still may exist
915         #
916
917         for host in $IPSECHOSTS
918         do
919             eval HOSTLOGIN=root@\$ipv4_${host}
920             ssh $SSHCONF $HOSTLOGIN 'if [ -f /var/run/charon.pid ]; then rm /var/run/charon.pid; echo "    removed charon.pid on `hostname`"; fi'
921         done
922
923         if [ -n "$aborted" ]
924         then
925             break 2
926         fi
927
928     done
929
930 done
931
932
933 ##############################################################################
934 # finish the results html file
935 #
936
937 cat >> $TESTRESULTSHTML << @EOF
938     <tr>
939       <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
940     </tr>
941     <tr>
942       <td><b>Passed</b></td><td><b><font color="green">$passed_cnt</font></b></td><td>&nbsp;</td><td>&nbsp;</td>
943     </tr>
944     <tr>
945       <td><b>Failed</b></td><td><b><font color="red">$failed_cnt</font></b></td><td>&nbsp;</td><td>&nbsp;</td>
946     </tr>
947     <tr>
948       <td><b>Time [s]</b></td><td><b><font color="blue">$timetotal</font></b></td><td>&nbsp;</td><td>&nbsp;</td>
949     </tr>
950   </table>
951 </body>
952 </html>
953 @EOF
954
955 if [ $subdir_cnt != 0 ]
956 then
957 cat >> $INDEX << @EOF
958       <td align="right">$subdir_cnt</td>
959       <td>&nbsp;</td>
960     </tr>
961 @EOF
962 fi
963
964 let "all_cnt = $passed_cnt + $failed_cnt"
965
966 cat >> $INDEX << @EOF
967     <tr>
968       <td>&nbsp;</td>
969       <td><a href="all.html"><b>all</b></a></td>
970       <td align="right"><b>$all_cnt</b></td>
971       <td>&nbsp;</td>
972     </tr>
973     <tr>
974       <td><b>Failed</b></td>
975       <td>&nbsp;</td>
976       <td align="right"><b><font color="red">$failed_cnt</font></b></td>
977       <td>&nbsp;</td>
978     </tr>
979   </table>
980 </body>
981 </html>
982 @EOF
983
984 echo
985 echo_ok     "Passed : $passed_cnt"
986 echo_failed "Failed : $failed_cnt"
987
988 echo
989 echo "The results are available in $TODAYDIR"
990 echo "or via the link http://$ipv4_winnetou/testresults/$TESTDATE"
991
992 ENDDATE=`date +%Y%m%d-%H%M-%S`
993 echo
994 echo "Finished : $ENDDATE"