]> ruderich.org/simon Gitweb - tlsproxy/tlsproxy.git/blob - src/tlsproxy-setup
155b8c90786c9aff26a520b0d9caad45dfbec69d
[tlsproxy/tlsproxy.git] / src / tlsproxy-setup
1 #!/bin/sh
2
3 # Create necessary files to run tlsproxy in the current directory.
4 #
5 # Requires certtool (from GnuTLS).
6 #
7 # Copyright (C) 2011-2013  Simon Ruderich
8 #
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
22
23 set -e
24
25
26 if test "$#" -ge 1 && test x"$*" != 'x--force'; then
27     echo "Usage: $0 [--force]" >&2
28     exit 1
29 fi
30
31 # Prevent accidental overwrites.
32 if test x"$1" != 'x--force'; then
33     for x in proxy-ca-key.pem proxy-ca.pem \
34              proxy-key.pem proxy-invalid.pem proxy-dh.pem; do
35         if test -f "$x"; then
36             echo "File '$x' already exists. Use --force to overwrite." >&2
37             exit 2
38         fi
39     done
40 fi
41
42
43 tempfile=`mktemp`
44 trap 'rm -f "$tempfile"' EXIT
45
46 # Generate proxy CA key file.
47 certtool --generate-privkey \
48          --sec-param high \
49          --outfile proxy-ca-key.pem
50 # Generate proxy CA.
51 echo 'cn = tlsproxy CA' > "$tempfile"
52 echo ca                >> "$tempfile"
53 echo cert_signing_key  >> "$tempfile"
54 echo 'expiration_days = 3650' >> "$tempfile"
55 certtool --generate-self-signed \
56          --load-privkey proxy-ca-key.pem \
57          --template "$tempfile" \
58          --outfile proxy-ca.pem
59
60 # Generate proxy key file.
61 certtool --generate-privkey \
62          --sec-param high \
63          --outfile proxy-key.pem
64
65 # Generate proxy "invalid" server certificate. It's used for problematic
66 # connections.
67 echo 'organization = tlsproxy' > "$tempfile"
68 echo 'cn = invalid'           >> "$tempfile"
69 echo tls_www_server           >> "$tempfile"
70 echo encryption_key           >> "$tempfile"
71 echo signing_key              >> "$tempfile"
72 echo 'expiration_days = 3650' >> "$tempfile"
73 certtool --generate-self-signed \
74          --load-privkey proxy-key.pem \
75          --template "$tempfile" \
76          --outfile proxy-invalid.pem
77
78 rm "$tempfile"
79
80 # Generate proxy Diffie-Hellman parameters.
81 certtool --generate-dh-params \
82          --sec-param high \
83          --outfile proxy-dh.pem
84
85 echo done