-
Notifications
You must be signed in to change notification settings - Fork 1
/
generateCertificates.sh
executable file
·47 lines (38 loc) · 1.18 KB
/
generateCertificates.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
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
CA_NAME=${1:-}
SERVICES=${2:-}
if [[ -z "$CA_NAME" || -z "${SERVICES}" ]]; then
echo "CA_NAME and SERVICE[,SERVICE,...] parameters required"
echo "Usage: $0 CA_NAME SERVICE[,SERVICE,...]"
exit 1
fi
# Some certstrap options
DEPOT_PATH=certificates
EXPIRES="10 years"
KEY_BITS=4096
certstrap_with_opts () {
certstrap --depot-path "${DEPOT_PATH}" "$@"
}
generateCA () {
if [[ -f "${DEPOT_PATH}/${CA_NAME}.crt" ]]; then
echo "CA \"${CA_NAME}\" already exists"
return
fi
echo "Generate root CA \"${CA_NAME}\""
certstrap_with_opts init --passphrase "" --expires "${EXPIRES}" --common-name "${CA_NAME}"
}
requestAndSignCertificate () {
local SERVICE=$1
echo "Create certificate request for ${SERVICE}"
certstrap_with_opts request-cert --passphrase "" --key "${DEPOT_PATH}/${CA_NAME}.key" --key-bits "${KEY_BITS}" --common-name "${SERVICE}" --domain "${SERVICE},localhost"
echo "Sign certificate request for ${SERVICE}"
certstrap_with_opts sign --passphrase "" --expires "${EXPIRES}" --CA "${CA_NAME}" "${SERVICE}"
}
generateCA
SERVICES=${SERVICES//,/$'\n'}
for SERVICE in $SERVICES
do
requestAndSignCertificate "${SERVICE}"
done