Testsuite: regen certs, now with additional LetsEncrypt-style OCSP proofs
[exim.git] / test / aux-fixed / exim-ca / genall
CommitLineData
f5d78688
JH
1#!/bin/bash
2#
3
f2f2c91b
JH
4set -e
5set -x
6
74e2fb4b
JH
7clica --help >/dev/null 2>&1
8
f5d78688
JH
9echo Ensure time is set to 2012/11/01 12:34
10echo use - date -u 110112342012
11echo hit return when ready
12read junk
13for tld in com org net
14do
f2f2c91b
JH
15 idir="example.$tld"
16 rm -fr "$idir"
17 clica -D "$idir" -p password -B 1024 -I -N example.$tld -F \
74e2fb4b 18 -C http://crl.example.$tld/latest.crl -O http://oscp.example.$tld/
2b4a568d
JH
19
20 clica -D example.$tld -p password -s 101 -S server1.example.$tld \
f2f2c91b 21 -8 alternatename.server1.example.$tld,alternatename2.server1.example.$tld,*.test.ex
f5d78688
JH
22 clica -D example.$tld -p password -s 102 -S revoked1.example.$tld
23 clica -D example.$tld -p password -s 103 -S expired1.example.$tld -m 1
24 clica -D example.$tld -p password -s 201 -S server2.example.$tld
25 clica -D example.$tld -p password -s 202 -S revoked2.example.$tld
26 clica -D example.$tld -p password -s 203 -S expired2.example.$tld -m 1
82525c6f
JH
27
28
29 # openssl seems to generate a file (ca_chain.pam) in an order it
30 # cannot then use (the key applies to the first cert in the file?).
31 # Generate a shuffled one.
32 cd example.$tld/server1.example.$tld
f2f2c91b
JH
33 openssl pkcs12 -in server1.example.$tld.p12 -passin file:pwdfile -cacerts -out cacerts.pem -nokeys
34 cat server1.example.$tld.pem cacerts.pem > fullchain.pem
82525c6f
JH
35 rm cacerts.pem
36 cd ../..
f5d78688
JH
37done
38
39# and loop again
40for tld in com org net
41do
42 CADIR=example.$tld/CA
43 #give ourselves an OSCP key to work with
44 pk12util -o $CADIR/OCSP.p12 -n 'OCSP Signer' -d $CADIR -K password -W password
45 openssl pkcs12 -in $CADIR/OCSP.p12 -passin pass:password -passout pass:password -nodes -nocerts -out $CADIR/OCSP.key
46
74e2fb4b
JH
47 # also need variation from Signer
48 pk12util -o $CADIR/Signer.p12 -n 'Signing Cert' -d $CADIR -K password -W password
49 openssl pkcs12 -in $CADIR/Signer.p12 -passin pass:password -passout pass:password -nodes -nocerts -out $CADIR/Signer.key
f5d78688
JH
50
51 # create some index files for the ocsp responder to work with
74e2fb4b
JH
52# tab-sep
53# 0: Revoked/Expired/Valid letter
54# 1: Expiry date (ASN1_UTCTIME)
55# 2: Revocation date
56# 3: Serial no. (unique)
57# 4: file
58# 5: DN, index
59
f5d78688
JH
60 cat >$CADIR/index.valid.txt <<EOF
61V 130110200751Z 65 unknown CN=server1.example.$tld
62V 130110200751Z 66 unknown CN=revoked1.example.$tld
63V 130110200751Z 67 unknown CN=expired1.example.$tld
64V 130110200751Z c9 unknown CN=server2.example.$tld
65V 130110200751Z ca unknown CN=revoked2.example.$tld
66V 130110200751Z cb unknown CN=expired2.example.$tld
67EOF
68 cat >$CADIR/index.revoked.txt <<EOF
69R 130110200751Z 100201142709Z,superseded 65 unknown CN=server1.example.$tld
70R 130110200751Z 100201142709Z,superseded 66 unknown CN=revoked1.example.$tld
71R 130110200751Z 100201142709Z,superseded 67 unknown CN=expired1.example.$tld
72R 130110200751Z 100201142709Z,superseded c9 unknown CN=server2.example.$tld
73R 130110200751Z 100201142709Z,superseded ca unknown CN=revoked2.example.$tld
74R 130110200751Z 100201142709Z,superseded cb unknown CN=expired2.example.$tld
75EOF
76
77 # Now create all the ocsp requests and responses
f5d78688
JH
78 for server in server1 revoked1 expired1 server2 revoked2 expired2
79 do
80 SPFX=example.$tld/$server.example.$tld/$server.example.$tld
74e2fb4b
JH
81 openssl ocsp -issuer $CADIR/Signer.pem -cert $SPFX.pem -no_nonce -sha256 -reqout $SPFX.ocsp.req
82
83 OGENCOMMON="-rsigner $CADIR/OCSP.pem -rkey $CADIR/OCSP.key -CA $CADIR/Signer.pem -noverify"
84 openssl ocsp -index $CADIR/index.valid.txt $OGENCOMMON -ndays 3652 -sha256 -reqin $SPFX.ocsp.req -respout $SPFX.ocsp.good.resp
85 openssl ocsp -index $CADIR/index.valid.txt $OGENCOMMON -ndays 30 -sha256 -reqin $SPFX.ocsp.req -respout $SPFX.ocsp.dated.resp
86 openssl ocsp -index $CADIR/index.revoked.txt $OGENCOMMON -ndays 3652 -sha256 -reqin $SPFX.ocsp.req -respout $SPFX.ocsp.revoked.resp
87
88 OGENCOMMON="-rsigner $CADIR/Signer.pem -rkey $CADIR/Signer.key -CA $CADIR/Signer.pem -noverify"
89 openssl ocsp -index $CADIR/index.valid.txt $OGENCOMMON -ndays 3652 -sha256 -reqin $SPFX.ocsp.req -respout $SPFX.ocsp.signer.good.resp
90 openssl ocsp -index $CADIR/index.valid.txt $OGENCOMMON -ndays 30 -sha256 -reqin $SPFX.ocsp.req -respout $SPFX.ocsp.signer.dated.resp
91 openssl ocsp -index $CADIR/index.revoked.txt $OGENCOMMON -ndays 3652 -sha256 -reqin $SPFX.ocsp.req -respout $SPFX.ocsp.signer.revoked.resp
92
93 OGENCOMMON="-rsigner $CADIR/Signer.pem -rkey $CADIR/Signer.key -CA $CADIR/Signer.pem -resp_no_certs -noverify"
94 openssl ocsp -index $CADIR/index.valid.txt $OGENCOMMON -ndays 3652 -sha256 -reqin $SPFX.ocsp.req -respout $SPFX.ocsp.signernocert.good.resp
95 openssl ocsp -index $CADIR/index.valid.txt $OGENCOMMON -ndays 30 -sha256 -reqin $SPFX.ocsp.req -respout $SPFX.ocsp.signernocert.dated.resp
96 openssl ocsp -index $CADIR/index.revoked.txt $OGENCOMMON -ndays 3652 -sha256 -reqin $SPFX.ocsp.req -respout $SPFX.ocsp.signernocert.revoked.resp
f5d78688
JH
97 done
98done
99
100# and loop again to generate unlocked keys and client cert bundles
101for tld in com org net
102do
89f2a269
JH
103 for server in server1 revoked1 expired1 server2 revoked2 expired2
104 do
f5d78688
JH
105 SDIR=example.$tld/$server.example.$tld
106 SPFX=$SDIR/$server.example.$tld
107 openssl rsa -in $SPFX.key -passin file:$SDIR/pwdfile -out $SPFX.unlocked.key
108 cat $SPFX.pem example.$tld/CA/Signer.pem >$SPFX.chain.pem
109 done
110done
111
112echo Please to reset date to now.
f2f2c91b 113echo 'service ntpdate start (not on a systemd though...)'
f5d78688
JH
114echo
115echo Then hit return
116read junk
117
118# Create CRL files in .der and .pem
119# empty versions, and ones with the revoked servers
120for tld in com org net
121do
122 CADIR=example.$tld/CA
123 CRLIN=$CADIR/crl.empty.in.txt
124 DATENOW=`date -u +%Y%m%d%H%M%SZ`
125 echo "update=$DATENOW " >$CRLIN
126 crlutil -G -d $CADIR -f $CADIR/pwdfile \
127 -n 'Signing Cert' -c $CRLIN -o $CADIR/crl.empty
128 openssl crl -in $CADIR/crl.empty -inform der -out $CADIR/crl.empty.pem
129done
130sleep 2
131for tld in com org net
132do
133 CADIR=example.$tld/CA
134 CRLIN=$CADIR/crl.v2.in.txt
135 DATENOW=`date -u +%Y%m%d%H%M%SZ`
136 echo "update=$DATENOW " >$CRLIN
137 echo "addcert 102 $DATENOW" >>$CRLIN
138 echo "addcert 202 $DATENOW" >>$CRLIN
139 crlutil -G -d $CADIR -f $CADIR/pwdfile \
140 -n 'Signing Cert' -c $CRLIN -o $CADIR/crl.v2
141 openssl crl -in $CADIR/crl.v2 -inform der -out $CADIR/crl.v2.pem
142done
143
a7fec7a7
JH
144# Finally, a single certificate-directory
145cd example.com/server1.example.com
f2f2c91b 146mkdir -p certdir
a7fec7a7
JH
147cd certdir
148f=../../CA/CA.pem
149h=`openssl x509 -hash -noout -in $f`
f2f2c91b 150rm -f $h.0
a7fec7a7
JH
151ln -s $f $h.0
152f=../../CA/Signer.pem
153h=`openssl x509 -hash -noout -in $f`
f2f2c91b 154rm -f $h.0
a7fec7a7 155ln -s $f $h.0
f2f2c91b
JH
156cd ../../..
157
158pwd
159ls -l
a7fec7a7 160
89f2a269
JH
161find example.* -type d -print0 | xargs -0 chmod 755
162find example.* -type f -print0 | xargs -0 chmod 644
163
f5d78688 164echo "CA, Certificate, CRL and OSCP Response generation complete"