-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen-cert.sh
executable file
·40 lines (31 loc) · 1003 Bytes
/
gen-cert.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
#!/bin/bash
set -e
if [ ! -z "$1" ]
then
DOMAIN_NAME="$1"
else
echo "Usage: $0 <domain>"
fi
# Change to the output path
SCRIPT_PATH=$(dirname `realpath $0`)
if [ ! -e "${SCRIPT_PATH}/ca_certificate/CA.pem" ]
then
echo "The CA certificates aren't available. Did you run the Setup script first?"
exit -1
fi
cd ${SCRIPT_PATH}
mkdir -p site_certs/${DOMAIN_NAME}
cd site_certs/${DOMAIN_NAME}
openssl genrsa -out ${DOMAIN_NAME}.key 2048
openssl req -new -key ${DOMAIN_NAME}.key -out ${DOMAIN_NAME}.csr
cat <<EOF > ${DOMAIN_NAME}.ext
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names
[alt_names]
DNS.1 = ${DOMAIN_NAME}
DNS.2 = *.${DOMAIN_NAME}
EOF
openssl x509 -req -in ${DOMAIN_NAME}.csr -CA ${SCRIPT_PATH}/ca_certificate/CA.pem -CAkey ${SCRIPT_PATH}/ca_certificate/CA.key \
-CAcreateserial -out ${DOMAIN_NAME}.crt -days 825 -sha256 -extfile ${DOMAIN_NAME}.ext