Update demo.
[openssl.git] / demos / tunala / test.sh
1 #!/bin/sh
2
3 HTTP="localhost:8080"
4 CLIENT_PORT="9020"
5 SERVER_PORT="9021"
6
7 sub_test ()
8 {
9         echo "STARTING - $VER $CIPHER"
10         ./tunala -listen localhost:$CLIENT_PORT -proxy localhost:$SERVER_PORT \
11                 -cacert CA.pem -cert A-client.pem -server 0 \
12                 -dh_special standard -v_peer -v_strict \
13                 $VER -cipher $CIPHER 1> tc1.txt 2> tc2.txt &
14         ./tunala -listen localhost:$SERVER_PORT -proxy $HTTP \
15                 -cacert CA.pem -cert A-server.pem -server 1 \
16                 -dh_special standard -v_peer -v_strict \
17                 $VER -cipher $CIPHER 1> ts1.txt 2> ts2.txt &
18         # Wait for the servers to be listening before starting the wget test
19         DONE="no"
20         while [ "$DONE" != "yes" ]; do
21                 L1=`netstat -a | egrep "LISTEN[\t ]*$" | grep ":$CLIENT_PORT"`
22                 L2=`netstat -a | egrep "LISTEN[\t ]*$" | grep ":$SERVER_PORT"`
23                 if [ "x$L1" != "x" ]; then
24                         DONE="yes"
25                 elif [ "x$L2" != "x" ]; then
26                         DONE="yes"
27                 else
28                         sleep 1
29                 fi
30         done
31         HTML=`wget -O - -T 1 http://localhost:$CLIENT_PORT 2> /dev/null | grep "<HTML>"`
32         if [ "x$HTML" != "x" ]; then
33                 echo "OK - $CIPHER ($VER)"
34         else
35                 echo "FAIL - $CIPHER ($VER)"
36                 killall tunala
37                 exit 1
38         fi
39         killall tunala
40         # Wait for the servers to stop before returning - otherwise the next
41         # test my fail to start ... (fscking race conditions)
42         DONE="yes"
43         while [ "$DONE" != "no" ]; do
44                 L1=`netstat -a | egrep "LISTEN[\t ]*$" | grep ":$CLIENT_PORT"`
45                 L2=`netstat -a | egrep "LISTEN[\t ]*$" | grep ":$SERVER_PORT"`
46                 if [ "x$L1" != "x" ]; then
47                         DONE="yes"
48                 elif [ "x$L2" != "x" ]; then
49                         DONE="yes"
50                 else
51                         DONE="no"
52                 fi
53         done
54         exit 0
55 }
56
57 run_test ()
58 {
59         (sub_test 1> /dev/null) || exit 1
60 }
61
62 run_ssl_test ()
63 {
64 killall tunala 1> /dev/null 2> /dev/null
65 echo ""
66 echo "Starting all $PRETTY tests"
67 if [ "$PRETTY" != "SSLv2" ]; then
68         if [ "$PRETTY" != "SSLv3" ]; then
69                 export VER="-no_ssl2 -no_ssl3"
70                 export OSSL="-tls1"
71         else
72                 export VER="-no_ssl2 -no_tls1"
73                 export OSSL="-ssl3"
74         fi
75 else
76         export VER="-no_ssl3 -no_tls1"
77         export OSSL="-ssl2"
78 fi
79 LIST="`../../apps/openssl ciphers $OSSL | sed -e 's/:/ /g'`"
80 #echo "$LIST"
81 for i in $LIST; do \
82         DSS=`echo "$i" | grep "DSS"`
83         if [ "x$DSS" != "x" ]; then
84                 echo "---- skipping $i (no DSA cert/keys) ----"
85         else
86                 export CIPHER=$i
87                 run_test
88                 echo "SUCCESS: $i"
89         fi
90 done;
91 }
92
93 # Welcome the user
94 echo "Tests will assume an http server running at $HTTP"
95
96 # TLSv1 test
97 export PRETTY="TLSv1"
98 run_ssl_test
99
100 # SSLv3 test
101 export PRETTY="SSLv3"
102 run_ssl_test
103
104 # SSLv2 test
105 export PRETTY="SSLv2"
106 run_ssl_test
107