6 # Debugging. Set V for clica verbosity.
11 clica --help >/dev/null 2>&1
13 echo Ensure time is set to 2019/11/01 12:34
14 echo use - date -u 110112342019
15 echo hit return when ready
18 # Calc number of months from then to (about) Nov 2037.
19 # We're sticking to a 2038 cutoff for now, to maintain support for 32b systems,
20 # but will have to give that up in only a few years.
22 tgt_secs=`date -d 'Nov 25 2037' +%s`
24 diff_months=$(( ($tgt_secs - $now_secs) / 60 / 60 / 24 / 31 ))
26 # Main suite: RSA certs
27 for tld in com org net
33 # create CAs & server certs
36 # create CA cert + templates
42 # -F create sub-signing cert
44 # -O create OCSP responder cert
45 # -3 Authority key ID extension
46 # -8 Subject Alternate Names
48 clica $V -D "$idir" -p password -B 2048 -I -N $iname -F -C http://crl.$iname/latest.crl -O http://oscp.$iname/
50 # create server leaf certs
52 clica $V -D $idir -p password -s 101 -S server1.$iname -m $diff_months \
53 -8 alternatename.server1.example.$tld,alternatename2.server1.example.$tld,*.test.ex
54 clica $V -D $idir -p password -s 102 -S revoked1.$iname -m $diff_months
55 clica $V -D $idir -p password -s 103 -S expired1.$iname -m 1
57 clica $V -D $idir -p password -s 201 -S server2.$iname -m $diff_months \
58 -3 "CN=clica CA rsa,O=example.$tld" -8 '*.test.ex'
59 clica $V -D $idir -p password -s 202 -S revoked2.$iname -m $diff_months
60 clica $V -D $idir -p password -s 203 -S expired2.$iname -m 1
64 # openssl seems to generate a file (ca_chain.pam) in an order it
65 # cannot then use (the key applies to the first cert in the file?).
66 # Generate a shuffled one.
69 cd $idir/server$n.$iname
70 openssl pkcs12 -in server$n.$iname.p12 -passin file:pwdfile -cacerts -out cacerts.pem -nokeys
71 cat server$n.$iname.pem cacerts.pem > fullchain.pem
78 # generate unlocked keys and client cert bundles
79 for server in server1 revoked1 expired1 server2 revoked2 expired2
81 SDIR=$idir/$server.$iname
82 SPFX=$SDIR/$server.$iname
83 openssl rsa -in $SPFX.key -passin file:$SDIR/pwdfile -out $SPFX.unlocked.key
84 cat $SPFX.pem $iname/CA/Signer.pem >$SPFX.chain.pem
89 # create OCSP reqs & resps
92 #give ourselves an OSCP key to work with
93 pk12util -o $CADIR/OCSP.p12 -n 'OCSP Signer rsa' -d $CADIR -K password -W password
94 openssl pkcs12 -in $CADIR/OCSP.p12 -passin pass:password -passout pass:password -nodes -nocerts -out $CADIR/OCSP.key
96 # also need variation from Signer
97 pk12util -o $CADIR/Signer.p12 -n 'Signing Cert rsa' -d $CADIR -K password -W password
98 openssl pkcs12 -in $CADIR/Signer.p12 -passin pass:password -passout pass:password -nodes -nocerts -out $CADIR/Signer.key
101 # - the "-n names" here appear to be hardcoded in clica
102 pk12util -o $CADIR/CA.p12 -n 'Certificate Authority rsa' -d $CADIR -K password -W password
103 openssl pkcs12 -in $CADIR/CA.p12 -passin pass:password -passout pass:password -nodes -nocerts -out $CADIR/CA.key
105 # create some index files for the ocsp responder to work with
106 # tab-sep, and fields can be empty
107 # 0: Revoked/Expired/Valid letter
108 # 1: Expiry date (ASN1_UTCTIME)
110 # 3: Serial no. (unique, in hex)
114 cat >$CADIR/index.valid.txt <<EOF
115 V 130110200751Z 65 unknown CN=server1.$iname
116 V 130110200751Z 66 unknown CN=revoked1.$iname
117 V 130110200751Z 67 unknown CN=expired1.$iname
118 V 130110200751Z c9 unknown CN=server2.$iname
119 V 130110200751Z ca unknown CN=revoked2.$iname
120 V 130110200751Z cb unknown CN=expired2.$iname
121 V 130110200751Z 42 unknown CN=clica Signing Cert rsa
122 V 130110200751Z 41 unknown CN=clica CA rsa
124 cat >$CADIR/index.revoked.txt <<EOF
125 R 130110200751Z 100201142709Z,superseded 65 unknown CN=server1.$iname
126 R 130110200751Z 100201142709Z,superseded 66 unknown CN=revoked1.$iname
127 R 130110200751Z 100201142709Z,superseded 67 unknown CN=expired1.$iname
128 R 130110200751Z 100201142709Z,superseded c9 unknown CN=server2.$iname
129 R 130110200751Z 100201142709Z,superseded ca unknown CN=revoked2.$iname
130 R 130110200751Z 100201142709Z,superseded cb unknown CN=expired2.$iname
131 R 130110200751Z 100201142709Z,superseded 42 unknown CN=clica Signing Cert rsa
134 # Now create all the ocsp requests and responses for the leaf certs
135 IVALID="-index $CADIR/index.valid.txt"
136 IREVOKED="-index $CADIR/index.revoked.txt"
138 echo "unique_subject = yes" > $CADIR/index.valid.txt.attr
139 echo "unique_subject = yes" > $CADIR/index.revoked.txt.attr
141 for server in server1 revoked1 expired1 server2 revoked2 expired2
143 SPFX=$idir/$server.$iname/$server.$iname
144 openssl ocsp -issuer $CADIR/Signer.pem -cert $SPFX.pem -no_nonce -reqout $SPFX.ocsp.req
145 REQIN="-reqin $SPFX.ocsp.req"
147 # These ones get used by the "traditional" testcases. OCSP resp signed by a cert which is
148 # signed by the signer of the leaf-cert being attested to.
149 OGENCOMMON="-rsigner $CADIR/OCSP.pem -rkey $CADIR/OCSP.key -CA $CADIR/Signer.pem -noverify"
151 openssl ocsp $IVALID $OGENCOMMON -ndays 3652 $REQIN -respout $SPFX.ocsp.good.resp
152 openssl ocsp $IVALID $OGENCOMMON -ndays 30 $REQIN -respout $SPFX.ocsp.dated.resp
153 openssl ocsp $IREVOKED $OGENCOMMON -ndays 3652 $REQIN -respout $SPFX.ocsp.revoked.resp
155 OGENCOMMON="-rsigner $CADIR/Signer.pem -rkey $CADIR/Signer.key -CA $CADIR/Signer.pem -noverify"
156 openssl ocsp $IVALID $OGENCOMMON -ndays 3652 $REQIN -respout $SPFX.ocsp.signer.good.resp
157 openssl ocsp $IVALID $OGENCOMMON -ndays 30 $REQIN -respout $SPFX.ocsp.signer.dated.resp
158 openssl ocsp $IREVOKED $OGENCOMMON -ndays 3652 $REQIN -respout $SPFX.ocsp.signer.revoked.resp
160 # These ones get used by the "LetsEncrypt mode" testcases. OCSP resp is signed directly by the
161 # signer of the leaf-cert being attested to.
162 OGENCOMMON="-rsigner $CADIR/Signer.pem -rkey $CADIR/Signer.key -CA $CADIR/Signer.pem -resp_no_certs -noverify"
163 openssl ocsp $IVALID $OGENCOMMON -ndays 3652 $REQIN -respout $SPFX.ocsp.signernocert.good.resp
164 openssl ocsp $IVALID $OGENCOMMON -ndays 30 $REQIN -respout $SPFX.ocsp.signernocert.dated.resp
165 openssl ocsp $IREVOKED $OGENCOMMON -ndays 3652 $REQIN -respout $SPFX.ocsp.signernocert.revoked.resp
168 # convert one good leaf-resp to PEM
170 RESP=$idir/$server.$iname/$server.$iname.ocsp.signernocert.good.resp
171 ocsptool -S $RESP -j > $RESP.pem
173 # Then, ocsp request and (valid, revoked) responses for the signer cert
174 REQ=$CADIR/Signer.ocsp.req
175 RESP=$CADIR/Signer.ocsp.signernocert.good.resp
176 openssl ocsp -issuer $CADIR/CA.pem -sha256 -cert $CADIR/Signer.pem -no_nonce -reqout $REQ
177 openssl ocsp $IVALID -rsigner $CADIR/CA.pem -rkey $CADIR/CA.key -CA $CADIR/CA.pem -resp_no_certs -noverify \
178 -ndays 3652 -reqin $REQ -respout $RESP
179 ocsptool -S $RESP -j > $RESP.pem
181 RESP=$CADIR/Signer.ocsp.signernocert.revoked.resp
182 openssl ocsp $IREVOKED -rsigner $CADIR/CA.pem -rkey $CADIR/CA.key -CA $CADIR/CA.pem -resp_no_certs -noverify \
183 -ndays 3652 -reqin $REQ -respout $RESP
184 ocsptool -S $RESP -j > $RESP.pem
186 # Finally, a full-chain all-good request and response
187 REQ=$idir/$server.$iname/fullchain.ocsp.req
188 leafcert=$idir/$server.$iname/$server.$iname.pem
189 signercert=$CADIR/Signer.pem
191 openssl ocsp -sha256 -no_nonce -reqout $REQ \
192 -issuer $signercert -cert $leafcert \
193 -issuer $cacert -cert $CADIR/Signer.pem -cert $CADIR/CA.pem
195 RESP=$idir/$server.$iname/fullchain.ocsp.resp
196 authorities=$idir/$server.$iname/ca_chain.pem
197 openssl ocsp $IVALID -rsigner $CADIR/CA.pem -rkey $CADIR/CA.key -CA $authorities -resp_no_certs -noverify \
198 -ndays 3652 -reqin $REQ -respout $RESP
199 ocsptool -S $RESP -j > $RESP.pem
204 # Create one EC leaf cert in the RSA cert tree. It will have an EC pubkey but be signed using its parent
205 # therefore its parent's algo, RSA.
206 clica $V -D example.com -p password -k ec -q nistp521 -s 1101 -S server1_ec.example.com -m $diff_months -8 'server1.example.com,*.test.ex'
207 SDIR=example.com/server1_ec.example.com
208 SPFX=$SDIR/server1_ec.example.com
209 openssl ec -in $SPFX.key -passin file:$SDIR/pwdfile -out $SPFX.unlocked.key
210 cat $SPFX.pem example.com/CA/Signer.pem >$SPFX.chain.pem
214 ###############################################################################
215 # Limited suite: EC certs
216 # separate trust root & chain
217 # .com only, server1 good only, no ocsp
218 # with server1 in SAN of leaf
222 iname="example_ec.$tld"
226 # create CAs & server certs
229 # create CA cert + templates
230 clica $V -D "$idir" -p password -B 2048 -I -N $iname -F \
232 -C http://crl.example.$tld/latest.crl -O http://oscp.example.$tld/
234 # create server certs
236 clica $V -D $idir -p password -s 2101 -S server1.$iname -m $diff_months \
238 -8 server1.example.$tld,alternatename.server1.example.$tld,alternatename2.server1.example.$tld,*.test.ex
242 # openssl seems to generate a file (ca_chain.pam) in an order it
243 # cannot then use (the key applies to the first cert in the file?).
244 # Generate a shuffled one.
245 cd $idir/server1.$iname
246 openssl pkcs12 -in server1.$iname.p12 -passin file:pwdfile -cacerts -out cacerts.pem -nokeys
247 cat server1.$iname.pem cacerts.pem > fullchain.pem
253 # generate unlocked keys and client cert bundles
254 for server in server1
256 SDIR=$idir/$server.$iname
257 SPFX=$SDIR/$server.$iname
258 openssl ec -in $SPFX.key -passin file:$SDIR/pwdfile -out $SPFX.unlocked.key
259 cat $SPFX.pem $idir/CA/Signer.pem >$SPFX.chain.pem
263 # create OCSP reqs & resps
265 #give ourselves an OSCP key to work with
266 pk12util -o $CADIR/OCSP.p12 -n 'OCSP Signer ec' -d $CADIR -K password -W password
267 openssl pkcs12 -in $CADIR/OCSP.p12 -passin pass:password -passout pass:password -nodes -nocerts -out $CADIR/OCSP.key
269 # create some index files for the ocsp responder to work with
271 # 0: Revoked/Expired/Valid letter
272 # 1: Expiry date (ASN1_UTCTIME)
274 # 3: Serial no. (unique)
278 cat >$CADIR/index.valid.txt <<EOF
279 V 130110200751Z 835 unknown CN=server1.$iname
282 # Now create all the ocsp requests and responses
283 IVALID="-index $CADIR/index.valid.txt"
284 for server in server1
286 SPFX=$idir/$server.$iname/$server.$iname
287 openssl ocsp -issuer $CADIR/Signer.pem -sha256 -cert $SPFX.pem -no_nonce -reqout $SPFX.ocsp.req
288 REQIN="-reqin $SPFX.ocsp.req"
290 OGENCOMMON="-rsigner $CADIR/OCSP.pem -rkey $CADIR/OCSP.key -CA $CADIR/Signer.pem -noverify"
291 openssl ocsp $IVALID $OGENCOMMON -ndays 3652 $REQIN -respout $SPFX.ocsp.good.resp
296 ###############################################################################
298 echo Please to reset date to now.
299 echo 'service ntpdate start (not on a systemd though...)'
306 # Create CRL files in .der and .pem
307 # empty versions, and ones with the revoked servers
308 DATENOW=`date -u +%Y%m%d%H%M%SZ`
309 for tld in com org net
311 CADIR=example.$tld/CA
312 CRLIN=$CADIR/crl.empty.in.txt
313 echo "update=$DATENOW " >$CRLIN
314 crlutil -G -d $CADIR -f $CADIR/pwdfile \
315 -n 'Signing Cert rsa' -c $CRLIN -o $CADIR/crl.empty
316 openssl crl -in $CADIR/crl.empty -inform der -out $CADIR/crl.empty.pem
319 DATENOW=`date -u +%Y%m%d%H%M%SZ`
320 for tld in com org net
322 CADIR=example.$tld/CA
323 CRLIN=$CADIR/crl.v2.in.txt
324 echo "update=$DATENOW " >$CRLIN
325 echo "addcert 102 $DATENOW" >>$CRLIN
326 echo "addcert 202 $DATENOW" >>$CRLIN
327 crlutil -G -d $CADIR -f $CADIR/pwdfile \
328 -n 'Signing Cert rsa' -c $CRLIN -o $CADIR/crl.v2
329 openssl crl -in $CADIR/crl.v2 -inform der -out $CADIR/crl.v2.pem
331 CRLIN=$CADIR/crl.Signer.in.txt
332 echo "update=$DATENOW " >$CRLIN
333 crlutil -G -d $CADIR -f $CADIR/pwdfile \
334 -n 'Certificate Authority rsa' -c $CRLIN -o $CADIR/crl.Signer
335 openssl crl -in $CADIR/crl.Signer -inform der -out $CADIR/crl.Signer.pem
337 cat $CADIR/crl.Signer.pem $CADIR/crl.v2.pem > $CADIR/crl.chain.pem
340 # Finally, a single certificate-directory
341 cd example.com/server1.example.com
345 h=`openssl x509 -hash -noout -in $f`
348 f=../../CA/Signer.pem
349 h=`openssl x509 -hash -noout -in $f`
357 find example* -type d -print0 | xargs -0 chmod 755
358 find example* -type f -print0 | xargs -0 chmod 644
360 echo "CA, Certificate, CRL and OSCP Response generation complete"