]> ruderich.org/simon Gitweb - tlsproxy/tlsproxy.git/blob - tests/tests-passthrough.sh
Update copyright year.
[tlsproxy/tlsproxy.git] / tests / tests-passthrough.sh
1 #!/bin/sh
2
3 # tlsproxy tests for the -u option.
4 #
5 # Copyright (C) 2011-2014  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 test "x$srcdir" = x && srcdir=.
22 . "$srcdir/common.sh"
23
24
25 # Create necessary files.
26 cleanup
27 tlsproxy_setup
28
29 # Normal tests.
30 tlsproxy_background -u 4711
31 server_background --x509certfile "$srcdir/server.pem" \
32                   --x509keyfile "$srcdir/server-key.pem"
33 wait_for_ports 4711 4712
34
35
36 echo invalid hostname
37 client unknown-host 80 - && abort 'client unknown-host 80 -'
38 test_proxy_failure
39 test_no_invalid_certificate
40
41 echo missing proxy and server certificate
42 client localhost 4712 'test server' || abort 'client localhost 4712 test server'
43 test_proxy_successful
44 test_invalid_certificate
45
46 # Create the proxy certificate.
47 tlsproxy_add localhost server.pem
48
49 echo missing server certificate
50 mv certificate-localhost-server.pem .pem
51 client localhost 4712 'test server' || abort 'client localhost 4712 test server'
52 mv .pem certificate-localhost-server.pem
53 test_proxy_successful
54 test_invalid_certificate
55
56 echo missing proxy certificate
57 mv certificate-localhost-proxy.pem certificate-www.localhost-proxy.pem
58 # "invalid" to prevent user error if the proxy certificate gets deleted (but
59 # the server certificate is still readable).
60 client localhost 4712 invalid || abort 'client localhost 4712 invalid'
61 mv certificate-www.localhost-proxy.pem certificate-localhost-proxy.pem
62 test_proxy_successful
63 test_invalid_certificate
64
65 echo normal connection
66 # 'localhost' is the CN of tlsproxy's certificate.
67 client localhost 4712 localhost || abort 'client localhost 4712 localhost'
68 test_proxy_successful
69 test_no_invalid_certificate
70
71
72 # Stop server and try a "MITM" with a bad certificate.
73 echo
74 kill $pid_server || echo 'failed to kill gnutls-serv'
75 sleep 3 # necessary on some systems like OpenBSD
76 server_background --x509certfile "$srcdir/server-bad.pem" \
77                   --x509keyfile "$srcdir/server-key.pem"
78 wait_for_ports 4712
79 rm -f certificate-localhost-proxy.pem certificate-localhost-server.pem
80
81
82 echo mitm invalid hostname
83 client unknown-host 80 - && abort 'client unknown-host 80 -'
84 test_proxy_failure
85 test_no_invalid_certificate
86
87 echo mitm missing proxy and server certificate
88 client localhost 4712 'test server bad' || abort 'client localhost 4712 test server bad'
89 test_proxy_successful
90 test_invalid_certificate
91
92 # Create the proxy certificate.
93 tlsproxy_add localhost server.pem
94
95 echo mitm missing server certificate
96 mv certificate-localhost-server.pem certificate-www.localhost-server.pem
97 client localhost 4712 'test server bad' || abort 'client localhost 4712 test server bad'
98 mv certificate-www.localhost-server.pem certificate-localhost-server.pem
99 test_proxy_successful
100 test_invalid_certificate
101
102 echo mitm missing proxy certificate
103 mv certificate-localhost-proxy.pem certificate-www.localhost-proxy.pem
104 # "invalid" to prevent user error if the proxy certificate gets deleted (but
105 # the server certificate is still readable).
106 client localhost 4712 invalid || abort 'client localhost 4712 invalid'
107 mv certificate-www.localhost-proxy.pem certificate-localhost-proxy.pem
108 test_proxy_successful
109 test_invalid_certificate
110
111 echo mitm normal connection
112 client localhost 4712 invalid || abort 'client localhost 4712 invalid'
113 test_proxy_successful
114 test_invalid_certificate
115
116
117 # stop_servers in trap-handler
118 cleanup
119
120 exit 0