6 echo "cleanup previous run..."
8 mkdir output/csr output/crt
10 while read cdline ; do
11 if [[ $cdline == "" || $cdline == "#"* ]] ; then
16 read -a certdata <<< "$cdline"
18 echo "*** Processing: $(date -Iseconds) - ${certdata[0]} - ${certdata[1]} ***"
19 if [[ -d "output/${certdata[1]}" ]] ; then
20 echo "*** ERROR - THIS SEEMS TO ALREADY EXIST ***" 1>&2
21 echo "*** ABORTED ***" 1>&2
25 mkdir "output/${certdata[1]}"
26 chmod o+x "output/${certdata[1]}"
28 SUBJECT="${certdata[2]}CN=${certdata[1]}/"
29 CERTGEN_DNS_ALT_NAMES=$(echo "DNS:${certdata[1]},${certdata[3]}" | sed -e 's/,/ DNS:/g')
30 cat openssl.cnf | sed -e "s/CERTGEN_DNS_ALT_NAMES/${CERTGEN_DNS_ALT_NAMES}/" > /tmp/certgen.cnf
32 cd "output/${certdata[1]}"
33 openssl genrsa -out "${certdata[1]}.key" 4096 &> /dev/null
34 openssl req -new -key "${certdata[1]}.key" -out "${certdata[1]}.csr" -utf8 -batch -subj "${SUBJECT}" -config /tmp/certgen.cnf
36 if [[ ${certdata[0]} == "CRT" ]] ; then
37 openssl x509 -req -signkey "${certdata[1]}.key" -in "${certdata[1]}.csr" -out "${certdata[1]}.crt" -extensions v3_req -extfile /tmp/certgen.cnf \
38 -days 365 -sha512 &> /dev/null
39 chmod o+r "${certdata[1]}.crt"
41 echo -n "${certdata[1]} " >> "${MYPWD}/output/fpfile.txt"
42 openssl x509 -in "${certdata[1]}.crt" -fingerprint -noout -sha512 >> "${MYPWD}/output/fpfile.txt"
43 echo "" >> "${MYPWD}/output/fpfile.txt"
49 if [[ ${certdata[0]} == "CRT" ]] ; then
50 mv "output/${certdata[1]}" "output/crt/${certdata[1]}"
52 mv "output/${certdata[1]}" "output/csr/${certdata[1]}"
58 ls -l output/*/ | grep -v "total"