-
Notifications
You must be signed in to change notification settings - Fork 3
/
create_certs.sh
63 lines (53 loc) · 1.85 KB
/
create_certs.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
60
61
62
63
#!/bin/bash
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
# Generates self-signed certificates for a given domain name or IP address. This is intended
# for generation of non-production certificates only. Deposits the generated certificates
# into the tts-config directory, ready for creation of the configuration secret.
#
# cfssl is a prerequisite.
#
# Example execution:
# bash create_certs.sh example.com
# Fail if no domain name or IP address supplied
if [ -z "$1" ]; then
echo "No domain name or IP address supplied\nUsage: bash create_certs.sh example.com"
exit 1
fi
# Fail gracefully if cfssl is not installed
if ! command -v cfssl &> /dev/null
then
echo "cfssl is not installed!"
echo "Ubuntu/Debian: sudo apt install golang-cfssl"
echo "Mac: brew install cfssl"
echo "Windows: Download installer from https://github.com/cloudflare/cfssl/releases"
exit 1
fi
echo "Creating self-signed certificates for $1"
# Use default names
NAMES="\"names\": [{\"C\": \"NL\", \"ST\": \"Noord-Holland\", \"L\": \"Amsterdam\", \"O\": \"The Things Demo\"}]"
# Create the JSON files needed for certificate generation
CA_JSON=ca.json
CERT_JSON=cert.json
echo "Generating $CA_JSON"
echo "{$NAMES}" >> $CA_JSON
echo "Generating $CERT_JSON for host $1"
echo "{\"hosts\": [\"$1\"],$NAMES}" >> $CERT_JSON
# Generate ca.pem and then cert.pem and key.pem
echo "Generating CA"
cfssl genkey -initca $CA_JSON | cfssljson -bare ca
echo "Generating Certificate and Key"
cfssl gencert -ca ca.pem -ca-key ca-key.pem $CERT_JSON | cfssljson -bare cert
mv cert-key.pem key.pem
# Clean-up
echo "Removing $CA_JSON"
rm $CA_JSON
echo "Removing $CERT_JSON"
rm $CERT_JSON
echo "Removing CSRs"
rm *.csr
echo "Removing CA private key"
rm ca-key.pem
# Deploy
echo "Moving certificates and key to tts-config"
mv *.pem tts-config/.