Browse code

Merge branch 'bugfix2.1' into beta2.2

David Sommerseth authored on 2010/08/18 04:42:39
Showing 5 changed files
... ...
@@ -57,7 +57,7 @@ SUBDIRS = \
57 57
 	service-win32 \
58 58
 	install-win32
59 59
 
60
-TESTS = t_lpback.sh t_cltsrv.sh
60
+TESTS = t_client.sh t_lpback.sh t_cltsrv.sh
61 61
 sbin_PROGRAMS = openvpn
62 62
 
63 63
 dist_noinst_HEADERS =
... ...
@@ -272,6 +272,13 @@ AC_ARG_WITH(route-path,
272 272
 )
273 273
 AC_DEFINE_UNQUOTED(ROUTE_PATH, "$ROUTE", [Path to route tool])
274 274
 
275
+AC_ARG_WITH(netstat-path,
276
+   [  --with-netstat-path=PATH  Path to netstat tool],
277
+   [NETSTAT="$withval"],
278
+   [AC_PATH_PROG([NETSTAT], [netstat], [netstat], [$PATH:/usr/local/sbin:/usr/sbin:/sbin:/etc])]
279
+)
280
+AC_DEFINE_UNQUOTED(NETSTAT_PATH, "$NETSTAT", [Path to netstat tool])
281
+
275 282
 AC_ARG_WITH(mem-check,
276 283
    [  --with-mem-check=TYPE  Build with debug memory checking, TYPE = dmalloc or valgrind],
277 284
    [MEMCHECK="$withval"]
... ...
@@ -374,7 +381,10 @@ if test "${WIN32}" != "yes"; then
374 374
 		 linux/types.h sys/poll.h sys/epoll.h err.h dnl
375 375
    )
376 376
    AC_CHECK_HEADERS(net/if.h,,,
377
-		 [#ifdef HAVE_SYS_SOCKET_H 
377
+		 [#ifdef HAVE_SYS_TYPES_H
378
+		  # include <sys/types.h>
379
+		  #endif
380
+		  #ifdef HAVE_SYS_SOCKET_H
378 381
 		  # include <sys/socket.h>
379 382
 		  #endif
380 383
 		 ])
... ...
@@ -919,6 +929,7 @@ if test -z "${htmldir}"; then
919 919
 fi
920 920
 # end workaround
921 921
 
922
+AC_CONFIG_FILES([t_client.sh], [chmod +x t_client.sh])
922 923
 AC_OUTPUT([
923 924
 	Makefile
924 925
 	openvpn.spec
... ...
@@ -1039,10 +1039,10 @@ verify_callback (int preverify_ok, X509_STORE_CTX * ctx)
1039 1039
 	goto end;
1040 1040
       }
1041 1041
 
1042
-      n = sk_num(X509_CRL_get_REVOKED(crl));
1042
+      n = sk_X509_REVOKED_num(X509_CRL_get_REVOKED(crl));
1043 1043
 
1044 1044
       for (i = 0; i < n; i++) {
1045
-	revoked = (X509_REVOKED *)sk_value(X509_CRL_get_REVOKED(crl), i);
1045
+	revoked = (X509_REVOKED *)sk_X509_REVOKED_value(X509_CRL_get_REVOKED(crl), i);
1046 1046
 	if (ASN1_INTEGER_cmp(revoked->serialNumber, X509_get_serialNumber(ctx->current_cert)) == 0) {
1047 1047
 	  msg (D_HANDSHAKE, "CRL CHECK FAILED: %s is REVOKED",subject);
1048 1048
 	  goto end;
... ...
@@ -1661,7 +1661,7 @@ init_ssl (const struct options *options)
1661 1661
       /* Set Certificate Verification chain */
1662 1662
       if (!options->ca_file)
1663 1663
         {
1664
-          if (ca && sk_num(ca))
1664
+          if (ca && sk_X509_num(ca))
1665 1665
             {
1666 1666
               for (i = 0; i < sk_X509_num(ca); i++)
1667 1667
                 {
1668 1668
new file mode 100644
... ...
@@ -0,0 +1,83 @@
0
+#
1
+# this is sourced from t_client.sh and defines which openvpn client tests
2
+# to run
3
+#
4
+# (sample config, copy to t_client.rc and adapt to your environment)
5
+#
6
+#
7
+# define these - if empty, no tests will run
8
+#
9
+CA_CERT="/home/openvpn-test-ca/keys/ca.crt"
10
+CLIENT_KEY="/home/openvpn-test-ca/keys/client-test.key"
11
+CLIENT_CERT="/home/openvpn-test-ca/keys/client-test.crt"
12
+#
13
+# remote host (used as macro below)
14
+#
15
+REMOTE=mytestserver
16
+#
17
+# tests to run (list suffixes for config stanzas below)
18
+#
19
+TEST_RUN_LIST="1 2"
20
+
21
+#
22
+# base confic that is the same for all the p2mp test runs
23
+#
24
+OPENVPN_BASE_P2MP="--client --ca $CA_CERT \
25
+	--cert $CLIENT_CERT --key $CLIENT_KEY \
26
+	--ns-cert-type server --nobind --comp-lzo --verb 3"
27
+
28
+# base config for p2p tests
29
+#
30
+OPENVPN_BASE_P2P="..."
31
+
32
+#
33
+#
34
+# now define the individual tests - all variables suffixed with _1, _2 etc
35
+# will be used in test run "1", "2", etc.
36
+#
37
+# if something is not defined here, the corresponding test is not run
38
+#
39
+# possible test options:
40
+#
41
+# OPENVPN_CONF_x = "how to call ./openvpn" [mandatory]
42
+# EXPECT_IFCONFIG4_x = "this IPv4 address needs to show up in ifconfig"
43
+# EXPECT_IFCONFIG6_x = "this IPv6 address needs to show up in ifconfig"
44
+# PING4_HOSTS_x = "these hosts musts ping when openvpn is up (IPv4 fping)"
45
+# PING6_HOSTS_x = "these hosts musts ping when openvpn is up (IPv6 fping6)"
46
+#
47
+# Test 1: UDP / p2mp tun
48
+#   specify IPv4+IPv6 addresses expected from server and ping targets
49
+#
50
+OPENVPN_CONF_1="$OPENVPN_BASE_P2MP --dev tun --proto udp --remote $REMOTE --port 51194"
51
+EXPECT_IFCONFIG4_1="10.100.50.6"
52
+EXPECT_IFCONFIG6_1="2001:dba:a050::1:0"
53
+PING4_HOSTS_1="10.100.50.1 10.100.0.1"
54
+PING6_HOSTS_1="2001:dba::1 2001:dba:a050::1"
55
+
56
+# Test 2: TCP / p2mp tun
57
+#
58
+OPENVPN_CONF_2="$OPENVPN_BASE_P2MP --dev tun --proto tcp --remote $REMOTE --port 51194"
59
+EXPECT_IFCONFIG4_2="10.100.51.6"
60
+EXPECT_IFCONFIG6_2="2001:dba:a051::1:0"
61
+PING4_HOSTS_2="10.100.51.1 10.100.0.1"
62
+PING6_HOSTS_1="2001:dba::1 2001:dba:a051::1"
63
+
64
+# Test 3: UDP / p2p tun
65
+# ...
66
+
67
+# Test 4: TCP / p2p tun
68
+# ...
69
+
70
+# Test 5: UDP / p2mp tap
71
+# ...
72
+
73
+# Test 6: TCP / p2mp tun
74
+# ...
75
+
76
+# Test 7: UDP / p2p tap
77
+# ...
78
+
79
+# Test 8: TCP / p2p tap
80
+# ...
81
+
82
+# Test 9: whatever you want to test... :-)
0 83
new file mode 100755
... ...
@@ -0,0 +1,298 @@
0
+#!@SHELL@
1
+#
2
+# run OpenVPN client against ``test reference'' server
3
+# - check that ping, http, ... via tunnel works
4
+# - check that interface config / routes are properly cleaned after test end
5
+#
6
+# prerequisites:
7
+# - openvpn binary in current directory
8
+# - writable current directory to create subdir for logs
9
+# - t_client.rc in current directory OR source dir that specifies tests
10
+# - for "ping4" checks: fping binary in $PATH
11
+# - for "ping6" checks: fping6 binary in $PATH
12
+#
13
+
14
+if [ ! -x ./openvpn ]
15
+then
16
+    echo "no (executable) openvpn binary in current directory. FAIL." >&2
17
+    exit 1
18
+fi
19
+
20
+if [ ! -w . ]
21
+then
22
+    echo "current directory is not writable (required for logging). FAIL." >&2
23
+    exit 1
24
+fi
25
+
26
+if [ -r ./t_client.rc ] ; then
27
+    . ./t_client.rc
28
+elif [ -r "${srcdir}"/t_client.rc ] ; then
29
+    . "${srcdir}"/t_client.rc
30
+else
31
+    echo "cannot find 't_client.rc' in current directory or" >&2
32
+    echo "source dir ('${srcdir}').  FAIL." >&2
33
+    exit 1
34
+fi
35
+
36
+if [ -z "$CA_CERT" ] ; then
37
+    echo "CA_CERT not defined in 't_client.rc'. SKIP test." >&2
38
+    exit 0
39
+fi
40
+
41
+if [ -z "$TEST_RUN_LIST" ] ; then
42
+    echo "TEST_RUN_LIST empty, no tests defined.  SKIP test." >&2
43
+    exit 0
44
+fi
45
+
46
+# make sure we have permissions to run ifconfig/route from OpenVPN
47
+# can't use "id -u" here - doesn't work on Solaris
48
+ID=`id`
49
+if expr "$ID" : "uid=0" >/dev/null
50
+then :
51
+else
52
+    echo "$0: this test must run be as root. SKIP." >&2
53
+    exit 0
54
+fi
55
+
56
+LOGDIR=t_client-`hostname`-`date +%Y%m%d-%H%M%S`
57
+if mkdir $LOGDIR
58
+then :
59
+else
60
+    echo "can't create log directory '$LOGDIR'. FAIL." >&2
61
+    exit 1
62
+fi
63
+
64
+exit_code=0
65
+
66
+# ----------------------------------------------------------
67
+# helper functions
68
+# ----------------------------------------------------------
69
+# print failure message, increase FAIL counter
70
+fail()
71
+{
72
+    echo ""
73
+    echo "FAIL: $@" >&2
74
+    fail_count=$(( $fail_count + 1 ))
75
+}
76
+
77
+# print "all interface IP addresses" + "all routes"
78
+# this is higly system dependent...
79
+get_ifconfig_route()
80
+{
81
+    # linux / iproute2? (-> if configure got a path)
82
+    if [ "@IPROUTE@" != "ip" ]
83
+    then
84
+	echo "-- linux iproute2 --"
85
+	@IPROUTE@ addr show     | grep -v valid_lft
86
+	@IPROUTE@ route show
87
+	@IPROUTE@ -6 route show | sed -e 's/expires [0-9]*sec //'
88
+	return
89
+    fi
90
+
91
+    # try uname
92
+    case `uname -s` in
93
+	Linux)
94
+	   echo "-- linux / ifconfig --"
95
+	   LANG=C @IFCONFIG@ -a |egrep  "( addr:|encap:)"
96
+	   LANG=C @NETSTAT@ -rn -4 -6
97
+	   return
98
+	   ;;
99
+	FreeBSD|NetBSD|Darwin)
100
+	   echo "-- FreeBSD/NetBSD/Darwin [MacOS X] --"
101
+	   @IFCONFIG@ -a | egrep "(flags=|inet)"
102
+	   @NETSTAT@ -rn | awk '$3 !~ /^UHL/ { print $1,$2,$3,$NF }'
103
+	   return
104
+	   ;;
105
+	OpenBSD)
106
+	   echo "-- OpenBSD --"
107
+	   @IFCONFIG@ -a | egrep "(flags=|inet)" | \
108
+		sed -e 's/pltime [0-9]*//' -e 's/vltime [0-9]*//'
109
+	   @NETSTAT@ -rn | awk '$3 !~ /^UHL/ { print $1,$2,$3,$NF }'
110
+	   return
111
+	   ;;
112
+	SunOS)
113
+	   echo "-- Solaris --"
114
+	   @IFCONFIG@ -a | egrep "(flags=|inet)"
115
+	   @NETSTAT@ -rn | awk '$3 !~ /^UHL/ { print $1,$2,$3,$6 }'
116
+	   return
117
+	   ;;
118
+    esac
119
+
120
+    echo "get_ifconfig_route(): no idea how to get info on your OS.  FAIL." >&2
121
+    exit 20
122
+}
123
+
124
+# ----------------------------------------------------------
125
+# check ifconfig
126
+#  arg1: "4" or "6" -> for message
127
+#  arg2: IPv4/IPv6 address that must show up in out of "get_ifconfig_route"
128
+check_ifconfig()
129
+{
130
+    proto=$1 ; shift
131
+    expect_list="$@"
132
+
133
+    if [ -z "$expect_list" ] ; then return ; fi
134
+
135
+    for expect in $expect_list
136
+    do
137
+	if get_ifconfig_route | fgrep "$expect" >/dev/null
138
+	then :
139
+	else
140
+	    fail "check_ifconfig(): expected IPv$proto address '$expect' not found in ifconfig output."
141
+	fi
142
+    done
143
+}
144
+
145
+# ----------------------------------------------------------
146
+# run pings
147
+#  arg1: "4" or "6" -> fping/fing6
148
+#  arg2: "want_ok" or "want_fail" (expected ping result)
149
+#  arg3... -> fping arguments (host list)
150
+run_ping_tests()
151
+{
152
+    proto=$1 ; want=$2 ; shift ; shift
153
+    targetlist="$@"
154
+
155
+    # "no targets" is fine
156
+    if [ -z "$targetlist" ] ; then return ; fi
157
+
158
+    case $proto in
159
+	4) cmd=fping ;;
160
+	6) cmd=fping6 ;;
161
+	*) echo "internal error in run_ping_tests arg 1: '$proto'" >&2
162
+	   exit 1 ;;
163
+    esac
164
+
165
+    case $want in
166
+	want_ok)   sizes_list="64 1440 3000" ;;
167
+	want_fail) sizes_list="64" ;;
168
+    esac
169
+
170
+    for bytes in $sizes_list
171
+    do
172
+	echo "run IPv$proto ping tests ($want), $bytes byte packets..."
173
+
174
+	echo "$cmd -b $bytes -C 20 -p 250 -q $targetlist" >>$LOGDIR/$SUF:fping.out
175
+	$cmd -b $bytes -C 20 -p 250 -q $targetlist >>$LOGDIR/$SUF:fping.out 2>&1
176
+
177
+	# while OpenVPN is running, pings must succeed (want='want_ok')
178
+	# before OpenVPN is up, pings must NOT succeed (want='want_fail')
179
+
180
+	rc=$?
181
+	if [ $rc = 0 ] 				# all ping OK
182
+	then
183
+	    if [ $want = "want_fail" ]		# not what we want
184
+	    then
185
+		fail "IPv$proto ping test succeeded, but needs to *fail*."
186
+	    fi
187
+	else					# ping failed
188
+	    if [ $want = "want_ok" ]		# not what we wanted
189
+	    then
190
+		fail "IPv$proto ping test ($bytes bytes) failed, but should succeed."
191
+	    fi
192
+	fi
193
+    done
194
+}
195
+
196
+# ----------------------------------------------------------
197
+# main test loop
198
+# ----------------------------------------------------------
199
+for SUF in $TEST_RUN_LIST
200
+do
201
+    echo -e "\n### test run $SUF ###\n"
202
+    fail_count=0
203
+
204
+    echo "save pre-openvpn ifconfig + route"
205
+    get_ifconfig_route >$LOGDIR/$SUF:ifconfig_route_pre.txt
206
+
207
+    # get config variables
208
+    eval openvpn_conf=\"\$OPENVPN_CONF_$SUF\"
209
+    eval expect_ifconfig4=\"\$EXPECT_IFCONFIG4_$SUF\"
210
+    eval expect_ifconfig6=\"\$EXPECT_IFCONFIG6_$SUF\"
211
+    eval ping4_hosts=\"\$PING4_HOSTS_$SUF\"
212
+    eval ping6_hosts=\"\$PING6_HOSTS_$SUF\"
213
+
214
+    echo -e "\nrun pre-openvpn ping tests - targets must not be reachable..."
215
+    run_ping_tests 4 want_fail "$ping4_hosts"
216
+    run_ping_tests 6 want_fail "$ping6_hosts"
217
+    if [ "$fail_count" = 0 ] ; then
218
+        echo -e "OK.\n"
219
+    else
220
+	echo -e "FAIL: make sure that ping hosts are ONLY reachable via VPN, SKIP test $SUF".
221
+	exit_code=31
222
+	continue
223
+    fi
224
+
225
+    echo " run ./openvpn $openvpn_conf"
226
+    ./openvpn $openvpn_conf >$LOGDIR/$SUF:openvpn.log &
227
+    opid=$!
228
+
229
+    # make sure openvpn client is terminated in case shell exits
230
+    trap "kill $opid" 0
231
+    trap "kill $opid ; trap - 0 ; exit 1" 1 2 3 15
232
+
233
+    echo "wait for connection to establish..."
234
+    sleep 10
235
+
236
+    # test whether OpenVPN process is still there
237
+    if kill -0 $opid
238
+    then :
239
+    else
240
+	echo -e "OpenVPN process has failed to start up, check log ($LOGDIR/$SUF:openvpn.log).  FAIL.\ntail of logfile follows:\n..." >&2
241
+	tail $LOGDIR/$SUF:openvpn.log >&2
242
+	trap - 0 1 2 3 15
243
+	exit 10
244
+    fi
245
+
246
+    # compare whether anything changed in ifconfig/route setup?
247
+    echo "save ifconfig+route"
248
+    get_ifconfig_route >$LOGDIR/$SUF:ifconfig_route.txt
249
+
250
+    echo -n "compare pre-openvpn ifconfig+route with current values..."
251
+    if diff $LOGDIR/$SUF:ifconfig_route_pre.txt \
252
+	    $LOGDIR/$SUF:ifconfig_route.txt >/dev/null
253
+    then
254
+	fail "no differences between ifconfig/route before OpenVPN start and now."
255
+    else
256
+	echo -e " OK!\n"
257
+    fi
258
+
259
+    # expected ifconfig values in there?
260
+    check_ifconfig 4 "$expect_ifconfig4"
261
+    check_ifconfig 6 "$expect_ifconfig6"
262
+
263
+    run_ping_tests 4 want_ok "$ping4_hosts"
264
+    run_ping_tests 6 want_ok "$ping6_hosts"
265
+    echo -e "ping tests done.\n"
266
+
267
+    echo "stopping OpenVPN"
268
+    kill $opid
269
+    wait $!
270
+    rc=$?
271
+    if [ $rc != 0 ] ; then
272
+	fail "OpenVPN return code $rc, expect 0"
273
+    fi
274
+
275
+    echo -e "\nsave post-openvpn ifconfig + route..."
276
+    get_ifconfig_route >$LOGDIR/$SUF:ifconfig_route_post.txt
277
+
278
+    echo -n "compare pre- and post-openvpn ifconfig + route..."
279
+    if diff $LOGDIR/$SUF:ifconfig_route_pre.txt \
280
+	    $LOGDIR/$SUF:ifconfig_route_post.txt >$LOGDIR/$SUF:ifconfig_route_diff.txt
281
+    then
282
+	echo -e " OK.\n"
283
+    else
284
+	cat $LOGDIR/$SUF:ifconfig_route_diff.txt >&2
285
+	fail "differences between pre- and post-ifconfig/route"
286
+    fi
287
+    if [ "$fail_count" = 0 ] ; then
288
+        echo -e "test run $SUF: all tests OK.\n"
289
+    else
290
+	echo -e "test run $SUF: $fail_count test failures. FAIL.\n";
291
+	exit_code=30
292
+    fi
293
+done
294
+
295
+# remove trap handler
296
+trap - 0 1 2 3 15
297
+exit $exit_code