This repository has been archived by the owner on Jul 16, 2021. It is now read-only.
/
gen_server_keys.sh
executable file
·59 lines (52 loc) · 1.86 KB
/
gen_server_keys.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
# Copyright 2016 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
COMMONNAME=""
ADDRESS=""
SUBJECT="/C=US"
while getopts d:a:s: option; do
case "${option}" in
d) COMMONNAME=${OPTARG};;
a) ADDRESS=${OPTARG};;
s) SAN_DNS=${OPTARG};;
*) echo "usage: ./generate.sh -d <domain> -a <ip_address> -s <san_extension_DNS>"; exit 1;;
esac
done
if [[ -n "${COMMONNAME}" ]]; then
SUBJECT="${SUBJECT}/CN=${COMMONNAME}"
fi
# TODO(ismail): make the IPs configurable as well
ALTNAMES="[alt_names]\nDNS.1=${SAN_DNS}\nDNS.2=localhost\nIP.1=0.0.0.0"
if [[ -n "${ADDRESS}" ]]; then
ALTNAMES="${ALTNAMES}\nIP.2=${ADDRESS}"
fi
SANEXT="[SAN]\nbasicConstraints=CA:TRUE\nsubjectAltName=@alt_names\n\n${ALTNAMES}"
# Create output directory.
mkdir -p "${GOPATH}/src/github.com/google/keytransparency/genfiles"
cd "${GOPATH}/src/github.com/google/keytransparency/genfiles"
# Generate TLS keys.
openssl genrsa -des3 -passout pass:xxxx -out server.pass.key 2048
openssl rsa -passin pass:xxxx -in server.pass.key -out server.key
chmod 600 server.key
rm server.pass.key
openssl req -new \
-key server.key \
-subj "${SUBJECT}" \
-reqexts SAN \
-config <(cat /etc/ssl/openssl.cnf \
<(printf "${SANEXT}")) \
-out server.csr
openssl x509 -req -days 365 -in server.csr -signkey server.key \
-out server.crt -extensions SAN \
-extfile <(printf "${SANEXT}")