]> ruderich.org/simon Gitweb - tlsproxy/tlsproxy.git/blob - tests/tests-normal.sh
tests: Remove tmp in cleanup().
[tlsproxy/tlsproxy.git] / tests / tests-normal.sh
1 #!/bin/sh
2
3 # Normal tlsproxy tests.
4 #
5 # Copyright (C) 2011-2013  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 "$srcdir/../src/tlsproxy-setup" >/dev/null 2>/dev/null
28
29 # Normal tests.
30 tlsproxy 4711
31 server --x509certfile "$srcdir/server.pem" \
32        --x509keyfile "$srcdir/server-key.pem"
33 sleep 1
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 invalid || abort 'client localhost 4712 invalid'
43 test_proxy_successful
44 test_invalid_certificate
45
46 # Create the proxy certificate.
47 "$srcdir/../src/tlsproxy-add" localhost "$srcdir/server.pem" \
48     >/dev/null 2>/dev/null
49
50 echo missing server certificate
51 mv certificate-localhost-server.pem .pem
52 client localhost 4712 invalid || abort 'client localhost 4712 invalid'
53 mv .pem certificate-localhost-server.pem
54 test_proxy_successful
55 test_invalid_certificate
56
57 echo missing proxy certificate
58 mv certificate-localhost-proxy.pem .pem
59 client localhost 4712 invalid || abort 'client localhost 4712 invalid'
60 mv .pem certificate-localhost-proxy.pem
61 test_proxy_successful
62 test_invalid_certificate
63
64 echo normal connection
65 # 'localhost' is the CN of tlsproxy's certificate.
66 client localhost 4712 localhost || abort 'client localhost 4712 localhost'
67 test_proxy_successful
68 test_no_invalid_certificate
69
70
71 # Stop server and try a "MITM" with a bad certificate.
72 echo
73 kill $pid_server || echo 'failed to kill gnutls-serv'
74 server --x509certfile "$srcdir/server-bad.pem" \
75        --x509keyfile "$srcdir/server-key.pem"
76 sleep 1
77 rm -f certificate-localhost-proxy.pem certificate-localhost-server.pem
78
79
80 echo mitm invalid hostname
81 client unknown-host 80 - && abort 'client unknown-host 80 -'
82 test_proxy_failure
83 test_no_invalid_certificate
84
85 echo mitm missing proxy and server certificate
86 client localhost 4712 invalid || abort 'client localhost 4712 invalid'
87 test_proxy_successful
88 test_invalid_certificate
89
90 # Create the proxy certificate.
91 "$srcdir/../src/tlsproxy-add" localhost "$srcdir/server.pem" \
92     >/dev/null 2>/dev/null
93
94 echo mitm missing server certificate
95 mv certificate-localhost-server.pem .pem
96 client localhost 4712 invalid || abort 'client localhost 4712 invalid'
97 mv .pem certificate-localhost-server.pem
98 test_proxy_successful
99 test_invalid_certificate
100
101 echo mitm missing proxy certificate
102 mv certificate-localhost-proxy.pem .pem
103 client localhost 4712 invalid || abort 'client localhost 4712 invalid'
104 mv .pem certificate-localhost-proxy.pem
105 test_proxy_successful
106 test_invalid_certificate
107
108 echo mitm normal connection
109 client localhost 4712 invalid || abort 'client localhost 4712 invalid'
110 test_proxy_successful
111 test_invalid_certificate
112
113
114 stop_servers
115 cleanup
116
117 exit 0