33if [ -z " $1 " ]
44then
55 echo
6- echo ' Issue a wildcard SSL certification with Fishdrowned ROOT CA'
6+ echo ' Issue a wildcard SSL certificate with Fishdrowned ROOT CA'
77 echo
88 echo ' Usage: ./gen.cert.sh <domain> [<domain2>] [<domain3>] [<domain4>] ...'
99 echo ' <domain> The domain name of your site, like "example.dev",'
10- echo ' you will get a certification for *.example.dev'
10+ echo ' you will get a certificate for *.example.dev'
1111 echo ' Multiple domains are acceptable'
1212 exit ;
1313fi
1414
15- if [ ! -d " ./out/newcerts" ]; then
16- mkdir -p " ./out/newcerts"
17- fi
18-
19- if [ ! -f " ./out/index.txt" ]; then
20- touch " ./out/index.txt"
21- fi
22-
23- if [ ! -f " ./out/serial" ]; then
24- touch " ./out/serial"
25- echo 1000 > ./out/serial
26- fi
2715SAN=" "
2816for var in " $@ "
2917do
@@ -34,6 +22,11 @@ SAN=${SAN:0:${#SAN}-1}
3422# Move to root directory
3523cd " $( dirname " ${BASH_SOURCE[0]} " ) "
3624
25+ # Generate root certificate if not exists
26+ if [ ! -f " out/root.crt" ]; then
27+ bash gen.root.sh
28+ fi
29+
3730# Create domain directory
3831BASE_DIR=" out/$1 "
3932TIME=` date +%Y%m%d-%H%M`
@@ -48,21 +41,25 @@ openssl req -new -out "${DIR}/$1.csr.pem" \
4841 <( printf " [SAN]\nsubjectAltName=${SAN} " ) ) \
4942 -subj " /C=CN/ST=Guangdong/L=Guangzhou/O=Fishdrowned/OU=$1 /CN=*.$1 "
5043
51- # Issue certification
44+ # Issue certificate
5245# openssl ca -batch -config ./ca.cnf -notext -in "${DIR}/$1.csr.pem" -out "${DIR}/$1.cert.pem"
5346openssl ca -config ./ca.cnf -batch -notext \
5447 -in " ${DIR} /$1 .csr.pem" \
5548 -out " ${DIR} /$1 .crt" \
5649 -cert ./out/root.crt \
5750 -keyfile ./out/root.key.pem
5851
59- # Chain certification with CA
52+ # Chain certificate with CA
6053cat " ${DIR} /$1 .crt" ./out/root.crt > " ${DIR} /$1 .bundle.crt"
6154ln -snf " ./${TIME} /$1 .bundle.crt" " ${BASE_DIR} /$1 .bundle.crt"
6255ln -snf " ./${TIME} /$1 .crt" " ${BASE_DIR} /$1 .crt"
6356ln -snf " ../cert.key.pem" " ${BASE_DIR} /$1 .key.pem"
57+ ln -snf " ../root.crt" " ${BASE_DIR} /root.crt"
6458
65- # Output certifications
59+ # Output certificates
6660echo
67- echo " Certifications are located in:"
68- ls -la ` pwd` /${BASE_DIR} /* .*
61+ echo " Certificates are located in:"
62+
63+ LS=$( [[ ` ls --help | grep ' \-\-color' ` ]] && echo " ls --color" || echo " ls -G" )
64+
65+ ${LS} -la ` pwd` /${BASE_DIR} /* .*
0 commit comments