3 # tlsproxy tests for the -u option.
5 # Copyright (C) 2011-2013 Simon Ruderich
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.
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.
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/>.
21 test "x$srcdir" = x && srcdir=.
25 # Create necessary files.
27 "$srcdir/../src/tlsproxy-setup" >/dev/null 2>/dev/null
30 ../src/tlsproxy -d2 -u 4711 >/dev/null &
31 server --x509certfile "$srcdir/server.pem" \
32 --x509keyfile "$srcdir/server-key.pem"
37 client unknown-host 80 - && abort 'client unknown-host 80 -'
39 test_no_invalid_certificate
41 echo missing proxy and server certificate
42 client localhost 4712 'test server' || abort 'client localhost 4712 test server'
44 test_invalid_certificate
46 # Create the proxy certificate.
47 "$srcdir/../src/tlsproxy-add" localhost "$srcdir/server.pem" \
48 >/dev/null 2>/dev/null
50 echo missing server certificate
51 mv certificate-localhost-server.pem .pem
52 client localhost 4712 'test server' || abort 'client localhost 4712 test server'
53 mv .pem certificate-localhost-server.pem
55 test_invalid_certificate
57 echo missing proxy certificate
58 mv certificate-localhost-proxy.pem .pem
59 # "invalid" to prevent user error if the proxy certificate gets deleted (but
60 # the server certificate is still readable).
61 client localhost 4712 invalid || abort 'client localhost 4712 invalid'
62 mv .pem certificate-localhost-proxy.pem
64 test_invalid_certificate
66 echo normal connection
67 # 'localhost' is the CN of tlsproxy's certificate.
68 client localhost 4712 localhost || abort 'client localhost 4712 localhost'
70 test_no_invalid_certificate
73 # Stop server and try a "MITM" with a bad certificate.
76 server --x509certfile "$srcdir/server-bad.pem" \
77 --x509keyfile "$srcdir/server-key.pem"
79 rm -f certificate-localhost-proxy.pem certificate-localhost-server.pem
82 echo mitm invalid hostname
83 client unknown-host 80 - && abort 'client unknown-host 80 -'
85 test_no_invalid_certificate
87 echo mitm missing proxy and server certificate
88 client localhost 4712 'test server bad' || abort 'client localhost 4712 test server bad'
90 test_invalid_certificate
92 # Create the proxy certificate.
93 "$srcdir/../src/tlsproxy-add" localhost "$srcdir/server.pem" \
94 >/dev/null 2>/dev/null
96 echo mitm missing server certificate
97 mv certificate-localhost-server.pem .pem
98 client localhost 4712 'test server bad' || abort 'client localhost 4712 test server bad'
99 mv .pem certificate-localhost-server.pem
100 test_proxy_successful
101 test_invalid_certificate
103 echo mitm missing proxy certificate
104 mv certificate-localhost-proxy.pem .pem
105 # "invalid" to prevent user error if the proxy certificate gets deleted (but
106 # the server certificate is still readable).
107 client localhost 4712 invalid || abort 'client localhost 4712 invalid'
108 mv .pem certificate-localhost-proxy.pem
109 test_proxy_successful
110 test_invalid_certificate
112 echo mitm normal connection
113 client localhost 4712 invalid || abort 'client localhost 4712 invalid'
114 test_proxy_successful
115 test_invalid_certificate