]> ruderich.org/simon Gitweb - tlsproxy/tlsproxy.git/blob - src/tlsproxy-add
src/*,test/*: Add missing quotes to shell scripts.
[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-2012  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 if [ "x$1" = x ]; then
24     echo "Usage: $0 <hostname> [<server-certificate>]"
25     echo
26     echo "Add the server certificate <server-certificate> (as .pem file) for "
27     echo "<hostname> to tlsproxy. <server-certificate> is not modified."
28     echo
29     echo "If <server-certificate> is not given the certificate (PEM format) "
30     echo "is read from stdin."
31     echo
32     echo "The server certificate is NOT validated in any way, you must do "
33     echo "that before using this command or you risk using a insecure "
34     echo "certificate!"
35     echo
36     echo "Must be run in the tlsproxy directory where other configuration "
37     echo "files like proxy-ca.pem are stored."
38     exit 1
39 fi
40
41 tempfile=`mktemp` || exit 1
42
43 die() {
44     rm -f "$tempfile"
45     exit 1
46 }
47
48 # Generate server certificate for given host.
49 echo 'organization = tlsproxy' > "$tempfile"
50 echo "cn = $1"                >> "$tempfile"
51 echo tls_www_server           >> "$tempfile"
52 echo encryption_key           >> "$tempfile"
53 echo signing_key              >> "$tempfile"
54 certtool --generate-certificate \
55          --load-privkey proxy-key.pem \
56          --load-ca-certificate proxy-ca.pem \
57          --load-ca-privkey proxy-ca-key.pem \
58          --template "$tempfile" \
59          --outfile "certificate-$1-proxy.pem" || die
60 rm "$tempfile"
61
62 if [ "x$2" = x ]; then
63     echo please enter server certificate
64     cat > "certificate-$1-server.pem"
65 else
66     cp "$2" "certificate-$1-server.pem"
67 fi
68
69 echo done