From: mwolson_admin Date: Mon, 7 Apr 2008 00:57:13 +0000 (-0400) Subject: ca-sign: Various improvements. X-Git-Url: http://git.hcoop.net/clinton/scripts.git/commitdiff_plain/73df01d433a07ba42606bd7b09eb9a210048181c?ds=sidebyside ca-sign: Various improvements. --- diff --git a/ca-sign b/ca-sign index 4967c87..953d289 100755 --- a/ca-sign +++ b/ca-sign @@ -4,11 +4,11 @@ # admin. If a domain is provided, then the certificate request must # apply only to that domain. # -# Usage: ca-sign days request.csr outfile.pem [domain] +# Usage: ca-sign days request.csr key.asc outfile.pem [domain] -if test -n "$5" || test -z "$3"; then +if test -n "$6" || test -z "$4"; then echo "Incorrect arguments." - echo "Usage: ca-sign days request.csr outfile.pem [domain]" + echo "Usage: ca-sign days request.csr key.asc outfile.pem [domain]" exit 1 fi @@ -30,8 +30,26 @@ CA_LOC=/afs/hcoop.net/user/h/hc/hcoop/public_html/ca # Parameters DAYS=$1 REQUEST=$2 -PEM=$3 -DOMAIN=$4 +KEY=$3 +PEM=$4 +DOMAIN=$5 + +# Make sure completed certificate does not already exist +if test -e "$PEM"; then + echo "Error: Refusing to overwrite existing certificate at" + echo " $PEM." + exit 1 +fi + +# Make sure that the key and request do exist +if test ! -f "$REQUEST"; then + echo "Error: The given certificate request file does not exist." + exit 1 +fi +if test ! -f "$KEY"; then + echo "Error: The given key file does not exist." + exit 1 +fi # Verify request STATUS=$(openssl req -noout -in "$REQUEST" -verify 2>&1) @@ -54,13 +72,17 @@ ID=$(cat -- $DIR/serial) # Exit on error set -e -# Sign. +# Sign echo "Signing certificate request $REQUEST ..." -openssl ca -config $CONF -policy $POLICY -out $PEM -in $REQUEST -days $DAYS +openssl ca -config $CONF -policy $POLICY -out "$PEM" -in "$REQUEST" \ + -days "$DAYS" echo # Make a copy of the request -cp $REQUEST $DIR/requests/$ID.csr +cp "$REQUEST" $DIR/requests/$ID.csr + +# Append key to generated certificate +cat "$KEY" >> "$PEM" # Update revocation list. echo "Updating certificate revocation list ..."