-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgenerate_ca.sh
executable file
·40 lines (33 loc) · 1.1 KB
/
generate_ca.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
#!/usr/bin/env bash
set -e
set -o pipefail
# Requires - openssl
_CERTS_DIR_PATH="${CERTS_DIR_PATH:-".certs"}"
mkdir -p "$_CERTS_DIR_PATH"
pushd "$_CERTS_DIR_PATH" || exit
_SKIP_ROOTCA_KEY="${SKIP_ROOT_CA_KEY:-"false"}"
_ROOTCA_KEY_PATH="${ROOTCA_KEY_PATH:-"ca.key"}"
_ROOTCA_PEM_PATH="${CERT_OUT_PATH:-"ca.pem"}"
_ROOTCA_CERT_EXPIRE_DAYS="${ROOTCA_CERT_EXPIRE_DAYS:-"3650"}"
### Root CA
if [[ "$_SKIP_ROOTCA_KEY" != "true" ]]; then
if [[ ! -f "$_ROOTCA_KEY_PATH" ]]; then
echo "Generating private key for rootCA"
# 2048 bit key is hardcoded on purpose - https://expeditedsecurity.com/blog/measuring-ssl-rsa-keys/
openssl genrsa -out "$_ROOTCA_KEY_PATH" 2048
fi
if [[ ! -f "$_ROOTCA_PEM_PATH" ]]; then
echo "Generating the rootCA Certificate ${_ROOTCA_PEM_PATH} and signing it with the private key ${_ROOTCA_KEY_PATH}"
openssl req -new \
-x509 \
-days "$_ROOTCA_CERT_EXPIRE_DAYS" \
-key "$_ROOTCA_KEY_PATH" \
-out "$_ROOTCA_PEM_PATH" \
-subj "/C=IL/O=rootCaOrg"
fi
fi
echo "
rootCA Certificate: ${_ROOTCA_PEM_PATH}
rootCA Private Key: ${_ROOTCA_KEY_PATH}
"
popd || exit