3 # Add new server certificates to tlsproxy (also see below).
5 # Requires certtool (from GnuTLS).
7 # Copyright (C) 2011-2013 Simon Ruderich
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.
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.
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/>.
25 if test "$#" -ne 1 && test "$#" -ne 2; then
26 echo "Usage: $0 <hostname> [<server-certificate>]"
28 echo "Add the server certificate <server-certificate> (as .pem file) for "
29 echo "<hostname> to tlsproxy. <server-certificate> is not modified."
31 echo "If <server-certificate> is not given the certificate (PEM format) "
32 echo "is read from stdin."
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 "
38 echo "Must be run in the tlsproxy directory where other configuration "
39 echo "files like proxy-ca.pem are stored."
44 trap 'rm -f "$tempfile"' EXIT
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"
61 if test "x$2" = x; then
62 echo 'Please enter server certificate (Ctrl-D to terminate input).'
63 cat > "certificate-$1-server.pem"
65 cp "$2" "certificate-$1-server.pem"