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
39 if [ $flag -eq 1 ]; then
40 echo $line|
grep "^-----END.*$bound" 2>/dev
/null
1>/dev
/null
41 if [ $?
-eq 0 ] ; then
49 echo $line|
grep "^-----BEGIN.*$bound" 2>/dev
/null
1>/dev
/null
58 echo "usage: $0 -newcert|-newreq|-newreq-nodes|-newca|-sign|-verify" >&2
61 if [ -z "$OPENSSL" ]; then OPENSSL
=openssl
; fi
63 if [ -z "$DAYS" ] ; then DAYS
="-days 365" ; fi # 1 year
64 CADAYS
="-days 1095" # 3 years
65 REQ
="$OPENSSL req $SSLEAY_CONFIG"
66 CA
="$OPENSSL ca $SSLEAY_CONFIG"
67 VERIFY
="$OPENSSL verify"
69 PKCS12
="openssl pkcs12"
71 if [ -z "$CATOP" ] ; then CATOP
=.
/demoCA
; fi
78 while [ "$1" != "" ] ; do
85 # create a certificate
86 $REQ -new -x509 -keyout newkey.pem
-out newcert.pem
$DAYS
88 echo "Certificate is in newcert.pem, private key is in newkey.pem"
91 # create a certificate request
92 $REQ -new -keyout newkey.pem
-out newreq.pem
$DAYS
94 echo "Request is in newreq.pem, private key is in newkey.pem"
97 # create a certificate request
98 $REQ -new -nodes -keyout newreq.pem
-out newreq.pem
$DAYS
100 echo "Request (and private key) is in newreq.pem"
103 # if explicitly asked for or it doesn't exist then setup the directory
104 # structure that Eric likes to manage things
106 if [ "$NEW" -o ! -f ${CATOP}/serial
]; then
107 # create the directory hierarchy
109 mkdir
-p ${CATOP}/certs
110 mkdir
-p ${CATOP}/crl
111 mkdir
-p ${CATOP}/newcerts
112 mkdir
-p ${CATOP}/private
113 touch ${CATOP}/index.txt
115 if [ ! -f ${CATOP}/private
/$CAKEY ]; then
116 echo "CA certificate filename (or enter to create)"
119 # ask user for existing CA certificate
121 cp_pem
$FILE ${CATOP}/private
/$CAKEY PRIVATE
122 cp_pem
$FILE ${CATOP}/$CACERT CERTIFICATE
124 if [ ! -f "${CATOP}/serial" ]; then
125 $X509 -in ${CATOP}/$CACERT -noout -next_serial \
129 echo "Making CA certificate ..."
130 $REQ -new -keyout ${CATOP}/private
/$CAKEY \
132 $CA -create_serial -out ${CATOP}/$CACERT $CADAYS -batch \
133 -keyfile ${CATOP}/private
/$CAKEY -selfsign \
135 -infiles ${CATOP}/$CAREQ
141 $CA -policy policy_anything
-infiles newreq.pem
145 if [ -z "$2" ] ; then
146 CNAME
="My Certificate"
150 $PKCS12 -in newcert.pem
-inkey newreq.pem
-certfile ${CATOP}/$CACERT \
151 -out newcert.p12
-export -name "$CNAME"
156 $CA -policy policy_anything
-out newcert.pem
-infiles newreq.pem
159 echo "Signed certificate is in newcert.pem"
162 $CA -policy policy_anything
-out newcert.pem
-extensions v3_ca
-infiles newreq.pem
164 echo "Signed CA certificate is in newcert.pem"
167 echo "Cert passphrase will be requested twice - bug?"
168 $X509 -x509toreq -in newreq.pem
-signkey newreq.pem
-out tmp.pem
169 $CA -policy policy_anything
-out newcert.pem
-infiles tmp.pem
172 echo "Signed certificate is in newcert.pem"
177 $VERIFY -CAfile $CATOP/$CACERT newcert.pem
182 $VERIFY -CAfile $CATOP/$CACERT $j
191 echo "Unknown arg $i" >&2