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]}"
27 SUBJECT="${certdata[2]}CN=${certdata[1]}/"
28 CERTGEN_DNS_ALT_NAMES=$(echo "DNS:${certdata[1]},${certdata[3]}" | sed -e 's/,/ DNS:/g')
29 cat openssl.cnf | sed -e "s/CERTGEN_DNS_ALT_NAMES/${CERTGEN_DNS_ALT_NAMES}/" > /tmp/certgen.cnf
31 cd "output/${certdata[1]}"
32 openssl genrsa -out "${certdata[1]}.key" 4096 &> /dev/null
33 openssl req -new -key "${certdata[1]}.key" -out "${certdata[1]}.csr" -utf8 -batch -subj "${SUBJECT}" -config /tmp/certgen.cnf
35 if [[ ${certdata[0]} == "CRT" ]] ; then
36 openssl x509 -req -signkey "${certdata[1]}.key" -in "${certdata[1]}.csr" -out "${certdata[1]}.crt" -extensions v3_req -extfile /tmp/certgen.cnf \
37 -days 365 -sha512 &> /dev/null
38 echo -n "${certdata[1]} " >> "${MYPWD}/output/fpfile.txt"
39 openssl x509 -in "${certdata[1]}.crt" -fingerprint -noout -sha512 >> "${MYPWD}/output/fpfile.txt"
40 echo "" >> "${MYPWD}/output/fpfile.txt"
46 if [[ ${certdata[0]} == "CRT" ]] ; then
47 mv "output/${certdata[1]}" "output/crt/${certdata[1]}"
49 mv "output/${certdata[1]}" "output/csr/${certdata[1]}"
55 ls -l output/*/ | grep -v "total"