3 # CA - wrapper around ca to make it easier to use ... basically ca requires
4 # some setup stuff to be done before you can use it and this makes
5 # things easier between now and when Eric is convinced to fix it :-)
7 # CA -newca ... will setup the right stuff
8 # CA -newreq ... will generate a certificate request
9 # CA -sign ... will sign the generated request and output
11 # At the end of that grab newreq.pem and newcert.pem (one has the key
12 # and the other the certificate) and cat them together and that is what
13 # you want/need ... I'll make even this a little cleaner later.
16 # 12-Jan-96 tjh Added more things ... including CA -signcert which
17 # converts a certificate to a request and then signs it.
18 # 10-Jan-96 eay Fixed a few more bugs and added the SSLEAY_CONFIG
19 # environment variable so this can be driven from
21 # 25-Jul-96 eay Cleaned up filenames some more.
22 # 11-Jun-96 eay Fixed a few filename missmatches.
23 # 03-May-96 eay Modified to use 'ssleay cmd' instead of 'cmd'.
24 # 18-Apr-96 tjh Original hacking
30 # default openssl.cnf file has setup as per the following
31 # demoCA ... where everything is stored
33 if [ -z "$OPENSSL" ]; then OPENSSL=openssl; fi
35 DAYS="-days 3650" # 10 years
36 CADAYS="-days 3650" # 10 years
37 REQ="$OPENSSL req $SSLEAY_CONFIG"
38 CA="$OPENSSL ca $SSLEAY_CONFIG"
39 VERIFY="$OPENSSL verify"
51 echo "usage: CA -newcert|-newreq|-newca|-sign|-verify" >&2
55 # create a certificate
56 $REQ -new -x509 -keyout newkey.pem -out newcert.pem $DAYS
58 echo "Certificate is in newcert.pem, private key is in newkey.pem"
61 # create a certificate request
62 $REQ -new -keyout newkey.pem -out newreq.pem $DAYS
64 echo "Request is in newreq.pem, private key is in newkey.pem"
67 # if explicitly asked for or it doesn't exist then setup the directory
68 # structure that Eric likes to manage things
70 if [ "$NEW" -o ! -f ${CATOP}/serial ]; then
71 # create the directory hierarchy
75 mkdir ${CATOP}/newcerts
76 mkdir ${CATOP}/private
77 echo "00" > ${CATOP}/serial
78 touch ${CATOP}/index.txt
80 if [ ! -f ${CATOP}/private/$CAKEY ]; then
81 echo "CA certificate filename (or enter to create)"
84 # ask user for existing CA certificate
86 cp $FILE ${CATOP}/private/$CAKEY
89 echo "Making CA certificate ..."
90 $REQ -new -keyout ${CATOP}/private/$CAKEY \
92 $CA -out ${CATOP}/$CACERT $CADAYS -batch \
93 -keyfile ${CATOP}/private/$CAKEY -selfsign \
95 -infiles ${CATOP}/$CAREQ
101 $CA -policy policy_anything -infiles newreq.pem
105 $CA -policy policy_anything -out newcert.pem -infiles newreq.pem
108 echo "Signed certificate is in newcert.pem"
111 echo "Cert passphrase will be requested twice - bug?"
112 $X509 -x509toreq -in newreq.pem -signkey newreq.pem -out tmp.pem
113 $CA -policy policy_anything -out newcert.pem -infiles tmp.pem
115 echo "Signed certificate is in newcert.pem"
120 $VERIFY -CAfile $CATOP/$CACERT newcert.pem
125 $VERIFY -CAfile $CATOP/$CACERT $j
134 echo "Unknown arg $i";