#!/bin/sh # Generate a Terena eScience Server CA compliant CSR. if [ $# -lt 1 ]; then echo "Usage: $0 hostname [ hostname ... ]" >&2 exit 1 fi generatedcsrs= until [ $# -eq 0 ]; do # hostname to use in the request hostname=$1 shift # generate each request in its own subdirectory if [ ! -d "$hostname" ]; then mkdir "$hostname" fi # be mindful of existing files; reuse the newkey.pem file if it # exists, otherwise openssl will generate it. key="$hostname/newkey.pem" if [ -r "$key" ]; then # reuse it usekey="-key $key" else # let openssl generate it usekey="" fi # don't overwrite existing requests csr="$hostname/newrequest.csr" if [ -f "$csr" ]; then echo "ERROR: $csr already exists, not generating a new request" >&2 continue fi # at this point, we're definitely going to create a new request # we need to generate an openssl cnf file specific to the request. cat > "$hostname/newrequest.cnf" <&2 echo "Failed command: 'openssl req -nodes -new -out $csr -text $usekey -config $hostname/newrequest.cnf'" continue fi done echo "Done. Generated CSRs:$generatedcsrs"