ca-sign: Add usage statement and more thorough param-checking
[clinton/scripts.git] / ca-sign
... / ...
CommitLineData
1#!/bin/sh -e
2#
3# Sign a certificate request as a CA. Run this on deleuze as an
4# admin.
5#
6# Usage: ca-sign days request.csr out-cert-file.pem
7
8if test -n "$3" || test -z "$2"; then
9 echo "Incorrect arguments."
10 echo "Usage: ca-sign days request.csr out-cert-file.pem"
11 exit 1
12fi
13
14DIR=/var/local/lib/ca
15CONF=$DIR/openssl.cnf
16POLICY=policy_anything
17
18# Certificate revocation list
19CRL1=$DIR/crl-v1
20CRL2=$DIR/crl-v2
21CA_LOC=/afs/hcoop.net/user/h/hc/hcoop/public_html/ca
22
23DAYS=$1
24REQUEST=$2
25PEM=$3
26ID=$(cat -- $DIR/serial)
27
28# Sign.
29echo "Signing certificate request $REQUEST ..."
30openssl ca -config $CONF -policy $POLICY -out $PEM -in $REQUEST -days $DAYS
31echo
32
33# Make a copy of the request
34cp $REQUEST $DIR/requests/$ID.csr
35
36# Update revocation list.
37echo "Updating certificate revocation list ..."
38openssl ca -config $CONF -batch -gencrl -crldays 30 -out $CRL1.pem
39openssl crl -outform DER -out $CRL1.crl -in $CRL1.pem
40openssl ca -config $CONF -batch -gencrl -crldays 30 -crlexts crl_ext \
41 -out $CRL2.pem
42openssl crl -outform DER -out $CRL2.crl -in $CRL2.pem
43cp $CRL1.crl $CRL2.crl $CA_LOC
44echo
45
46echo "Don't forget to run ca-install to install the signed certificate!"