]> ruderich.org/simon Gitweb - tlsproxy/tlsproxy.git/blob - tests/tests-normal.sh
src/*,tests/*: Update copyright year.
[tlsproxy/tlsproxy.git] / tests / tests-normal.sh
1 #!/bin/sh
2
3 # Normal tlsproxy tests.
4 #
5 # Copyright (C) 2011-2012  Simon Ruderich
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20
21 # Handle empty $srcdir.
22 [ "x$srcdir" = x ] && srcdir=.
23
24 . $srcdir/common.sh
25
26
27 # Create necessary files.
28 cleanup
29 $srcdir/../src/tlsproxy-setup >/dev/null 2>/dev/null
30
31 # Normal tests.
32 ../src/tlsproxy -d2 4711 >/dev/null &
33 server --x509certfile $srcdir/server.pem \
34        --x509keyfile $srcdir/server-key.pem
35 sleep 1
36
37
38 echo invalid hostname
39 client unknown-host 80 - && abort
40 test_proxy_failure
41 test_no_invalid_certificate
42
43 echo missing proxy and server certificate
44 client localhost 4712 invalid || abort
45 test_proxy_successful
46 test_invalid_certificate
47
48 # Create the proxy certificate.
49 $srcdir/../src/tlsproxy-add localhost $srcdir/server.pem \
50     >/dev/null 2>/dev/null
51
52 echo missing server certificate
53 mv certificate-localhost-server.pem .pem
54 client localhost 4712 invalid || abort
55 mv .pem certificate-localhost-server.pem
56 test_proxy_successful
57 test_invalid_certificate
58
59 echo missing proxy certificate
60 mv certificate-localhost-proxy.pem .pem
61 client localhost 4712 invalid || abort
62 mv .pem certificate-localhost-proxy.pem
63 test_proxy_successful
64 test_invalid_certificate
65
66 echo normal connection
67 # 'localhost' is the CN of tlsproxy's certificate.
68 client localhost 4712 localhost || abort
69 test_proxy_successful
70 test_no_invalid_certificate
71
72
73 # Stop server and try a "MITM" with a bad certificate.
74 echo
75 pkill -n gnutls-serv
76 server --x509certfile $srcdir/server-bad.pem \
77        --x509keyfile $srcdir/server-key.pem
78 sleep 1
79 rm -f certificate-localhost-proxy.pem certificate-localhost-server.pem
80
81
82 echo mitm invalid hostname
83 client unknown-host 80 - && abort
84 test_proxy_failure
85 test_no_invalid_certificate
86
87 echo mitm missing proxy and server certificate
88 client localhost 4712 invalid || abort
89 test_proxy_successful
90 test_invalid_certificate
91
92 # Create the proxy certificate.
93 $srcdir/../src/tlsproxy-add localhost $srcdir/server.pem \
94     >/dev/null 2>/dev/null
95
96 echo mitm missing server certificate
97 mv certificate-localhost-server.pem .pem
98 client localhost 4712 invalid || abort
99 mv .pem certificate-localhost-server.pem
100 test_proxy_successful
101 test_invalid_certificate
102
103 echo mitm missing proxy certificate
104 mv certificate-localhost-proxy.pem .pem
105 client localhost 4712 invalid || abort
106 mv .pem certificate-localhost-proxy.pem
107 test_proxy_successful
108 test_invalid_certificate
109
110 echo mitm normal connection
111 client localhost 4712 invalid || abort
112 test_proxy_successful
113 test_invalid_certificate
114
115
116 pkill -n gnutls-serv
117 pkill -n tlsproxy
118
119 cleanup
120 rm -f tmp
121
122 exit 0