6 echo "cleanup previous run..."
8 mkdir output/csr output/crt output/sgn
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]}"
27 cd "output/${certdata[1]}"
29 # Handle "CA" type here.
30 if [[ ${certdata[0]} == "CA" ]] ; then
31 mkdir -m 0700 certs crl newcerts
34 openssl req -batch -new -newkey rsa:4096 -keyout ca.key -out ca.csr -nodes -subj "${certdata[2]}" -reqexts v3_ca_req -config "${MYPWD}/openssl.cnf" &>/dev/null
35 openssl ca -batch -create_serial -out ca.crt -days 3650 -keyfile ca.key -selfsign -extensions v3_ca -config "${MYPWD}/openssl.cnf" -infiles ca.csr
40 # Handle non "CA" types here.
41 export CA_PATH="$MYPWD/ca/"
42 SUBJECT="${certdata[2]}CN=${certdata[1]}/"
43 DNS_NAMES="${certdata[1]},${certdata[3]}"
46 cat "${MYPWD}/openssl.cnf" > /tmp/certgen.cnf
48 for name in $DNS_NAMES; do
49 if [[ "" == $name ]] ; then
52 COUNTER=$((COUNTER+1))
53 echo "DNS.${COUNTER} = $name" >> /tmp/certgen.cnf
59 openssl genrsa -out "${certdata[1]}.key" 4096 &> /dev/null
60 openssl req -new -key "${certdata[1]}.key" -out "${certdata[1]}.csr" -utf8 -batch -subj "${SUBJECT}" -config /tmp/certgen.cnf
62 if [[ ${certdata[0]} == "SGN" ]] ; then
63 if [[ ! -d "${CA_PATH}" ]] ; then
64 echo "*** ERROR - NO CA DATA FOUND ***" 1>&2
65 echo "*** maybe generate a CA and move it to ${CA_PATH} ***" 1>&2
66 echo "copy template: mv output/SomeNet ${CA_PATH}" 1>&2
67 echo "*** ABORTED ***" 1>&2
71 openssl ca -batch -create_serial -out "${certdata[1]}.crt" -days 365 -keyfile "${MYPWD}/ca/ca.key" -extensions v3_ca \
72 -config "${MYPWD}/openssl.cnf" -infiles "${certdata[1]}.csr"
73 cat "${MYPWD}/ca/ca.crt" >> "${certdata[1]}.crt"
75 elif [[ ${certdata[0]} == "CRT" ]] ; then
76 openssl x509 -req -signkey "${certdata[1]}.key" -in "${certdata[1]}.csr" -out "${certdata[1]}.crt" -extensions v3_req -extfile /tmp/certgen.cnf \
77 -days 365 -sha512 &> /dev/null
78 chmod o+r "${certdata[1]}.crt"
80 echo -n "${certdata[1]} " >> "${MYPWD}/output/fpfile.txt"
81 openssl x509 -in "${certdata[1]}.crt" -fingerprint -noout -sha512 >> "${MYPWD}/output/fpfile.txt"
82 echo "" >> "${MYPWD}/output/fpfile.txt"
88 if [[ ${certdata[0]} == "SGN" ]] ; then
89 mv "output/${certdata[1]}" "output/sgn/${certdata[1]}"
90 elif [[ ${certdata[0]} == "CRT" ]] ; then
91 mv "output/${certdata[1]}" "output/crt/${certdata[1]}"
93 mv "output/${certdata[1]}" "output/csr/${certdata[1]}"
99 ls -l "${MYPWD}/output/"*/ | grep -v "total"