]> ruderich.org/simon Gitweb - tlsproxy/tlsproxy.git/blob - src/tlsproxy-add
Update copyright year.
[tlsproxy/tlsproxy.git] / src / tlsproxy-add
1 #!/bin/sh
2
3 # Add new server certificates to tlsproxy (also see below).
4 #
5 # Requires certtool (from GnuTLS).
6 #
7 # Copyright (C) 2011-2014  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 if test "$#" -ne 1 && test "$#" -ne 2; then
26     echo "Usage: $0 <hostname> [<server-certificate>]"
27     echo
28     echo "Add the server certificate <server-certificate> (as .pem file) for "
29     echo "<hostname> to tlsproxy. <server-certificate> is not modified."
30     echo
31     echo "If <server-certificate> is not given the certificate (PEM format) "
32     echo "is read from stdin."
33     echo
34     echo "The server certificate is NOT validated in any way, you must do "
35     echo "that before using this command or you risk using an insecure "
36     echo "certificate!"
37     echo
38     echo "Must be run in the tlsproxy directory where other configuration "
39     echo "files like proxy-ca.pem are stored."
40     exit 1
41 fi
42
43 tempfile=`mktemp`
44 trap 'rm -f "$tempfile"' EXIT
45
46 # Generate server certificate for given host.
47 echo 'organization = tlsproxy' > "$tempfile"
48 echo "cn = $1"                >> "$tempfile"
49 echo tls_www_server           >> "$tempfile"
50 echo encryption_key           >> "$tempfile"
51 echo signing_key              >> "$tempfile"
52 echo 'expiration_days = 3650' >> "$tempfile"
53 certtool --generate-certificate \
54          --load-privkey proxy-key.pem \
55          --load-ca-certificate proxy-ca.pem \
56          --load-ca-privkey proxy-ca-key.pem \
57          --template "$tempfile" \
58          --outfile "certificate-$1-proxy.pem"
59 rm "$tempfile"
60
61 if test "x$2" = x; then
62     echo 'Please enter server certificate (Ctrl-D to terminate input).'
63     cat > "certificate-$1-server.pem"
64 else
65     cp "$2" "certificate-$1-server.pem"
66 fi
67
68 echo done