-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-certificate-for-domain
More file actions
executable file
·47 lines (37 loc) · 1.46 KB
/
create-certificate-for-domain
File metadata and controls
executable file
·47 lines (37 loc) · 1.46 KB
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
#!/usr/bin/env bash
if [ -z "$1" ]
then
echo "Please supply a subdomain to create a certificate for..."
echo "e.g. dev.local"
exit
fi
# Create a new private key if one doesnt exist, or use the existing one if it does
if [ -f device.key ]; then
KEY_OPT="-key"
else
KEY_OPT="-keyout"
fi
# Set variables for certificate generation
DOMAIN=$1
mkdir -p certs/$DOMAIN
SUBJECT="//C=CA/ST=None/L=NB/O=None/CN=$DOMAIN"
# Max 365 as there are limits in Chrome and Safari
NUM_OF_DAYS=365
# Generate the certificate signing request
openssl req -new -newkey rsa:2048 -sha256 -nodes $KEY_OPT device.key -subj "$SUBJECT" -out device.csr
sed s/%%DOMAIN%%/$DOMAIN/g v3.ext > /tmp/__v3.ext
# Generate the certificate from the signing request (signed with the root CA certificate)
openssl x509 -req -in device.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out device.crt -days $NUM_OF_DAYS -sha256 -extfile /tmp/__v3.ext
# Move output files to final filenames
mv device.csr certs/$DOMAIN/$DOMAIN.csr
cp device.crt certs/$DOMAIN/$DOMAIN.crt
cp device.key certs/$DOMAIN/device.key
# Remove temp file
rm -f device.crt
openssl pkcs12 -export -out certs/$DOMAIN/$DOMAIN.pfx -inkey certs/$DOMAIN/device.key -in certs/$DOMAIN/$DOMAIN.crt -passout pass:
echo
echo "###########################################################################"
echo Done!
echo "###########################################################################"
echo "For IIS, import the generated PFX file."
echo