AES IGE mode speedup.
[openssl.git] / test / testtsa
1 #!/bin/sh
2
3 #
4 # A few very basic tests for the 'ts' time stamping authority command.
5 #
6
7 SH="/bin/sh"
8 PATH=../../apps:$PATH
9 export SH PATH
10
11 OPENSSL_CONF="../CAtsa.cnf"
12 export OPENSSL_CONF
13 # Because that's what ../apps/CA.sh really looks at
14 SSLEAY_CONFIG="-config $OPENSSL_CONF"
15 export SSLEAY_CONFIG
16
17 OPENSSL="`pwd`/../util/opensslwrap.sh"
18 export OPENSSL
19
20 error () {
21
22     echo "TSA test failed!" >&2
23     exit 1
24 }
25
26 setup_dir () {
27
28     rm -rf tsa 2>/dev/null
29     mkdir tsa
30     cd ./tsa
31 }
32
33 clean_up_dir () {
34
35     cd ..
36     rm -rf tsa
37 }
38
39 create_ca () {
40
41     echo "Creating a new CA for the TSA tests..."
42     TSDNSECT=ts_ca_dn
43     export TSDNSECT   
44     ../../util/shlib_wrap.sh ../../apps/openssl req -new -x509 -nodes \
45         -out tsaca.pem -keyout tsacakey.pem
46     test $? != 0 && error
47 }
48
49 create_tsa_cert () {
50
51     INDEX=$1
52     export INDEX
53     EXT=$2
54     TSDNSECT=ts_cert_dn
55     export TSDNSECT   
56
57     ../../util/shlib_wrap.sh ../../apps/openssl req -new \
58         -out tsa_req${INDEX}.pem -keyout tsa_key${INDEX}.pem
59     test $? != 0 && error
60 echo Using extension $EXT
61     ../../util/shlib_wrap.sh ../../apps/openssl x509 -req \
62         -in tsa_req${INDEX}.pem -out tsa_cert${INDEX}.pem \
63         -CA tsaca.pem -CAkey tsacakey.pem -CAcreateserial \
64         -extfile $OPENSSL_CONF -extensions $EXT
65     test $? != 0 && error
66 }
67
68 print_request () {
69
70     ../../util/shlib_wrap.sh ../../apps/openssl ts -query -in $1 -text
71 }
72
73 create_time_stamp_request1 () {
74
75     ../../util/shlib_wrap.sh ../../apps/openssl ts -query -data ../testtsa -policy tsa_policy1 -cert -out req1.tsq
76     test $? != 0 && error
77 }
78
79 create_time_stamp_request2 () {
80
81     ../../util/shlib_wrap.sh ../../apps/openssl ts -query -data ../testtsa -policy tsa_policy2 -no_nonce \
82         -out req2.tsq
83     test $? != 0 && error
84 }
85
86 create_time_stamp_request3 () {
87
88     ../../util/shlib_wrap.sh ../../apps/openssl ts -query -data ../CAtsa.cnf -no_nonce -out req3.tsq
89     test $? != 0 && error
90 }
91
92 print_response () {
93
94     ../../util/shlib_wrap.sh ../../apps/openssl ts -reply -in $1 -text
95     test $? != 0 && error
96 }
97
98 create_time_stamp_response () {
99
100     ../../util/shlib_wrap.sh ../../apps/openssl ts -reply -section $3 -queryfile $1 -out $2
101     test $? != 0 && error
102 }
103
104 time_stamp_response_token_test () {
105
106     RESPONSE2=$2.copy.tsr
107     TOKEN_DER=$2.token.der
108     ../../util/shlib_wrap.sh ../../apps/openssl ts -reply -in $2 -out $TOKEN_DER -token_out
109     test $? != 0 && error
110     ../../util/shlib_wrap.sh ../../apps/openssl ts -reply -in $TOKEN_DER -token_in -out $RESPONSE2
111     test $? != 0 && error
112     cmp $RESPONSE2 $2
113     test $? != 0 && error
114     ../../util/shlib_wrap.sh ../../apps/openssl ts -reply -in $2 -text -token_out
115     test $? != 0 && error
116     ../../util/shlib_wrap.sh ../../apps/openssl ts -reply -in $TOKEN_DER -token_in -text -token_out
117     test $? != 0 && error
118     ../../util/shlib_wrap.sh ../../apps/openssl ts -reply -queryfile $1 -text -token_out
119     test $? != 0 && error
120 }
121
122 verify_time_stamp_response () {
123
124     ../../util/shlib_wrap.sh ../../apps/openssl ts -verify -queryfile $1 -in $2 -CAfile tsaca.pem \
125         -untrusted tsa_cert1.pem
126     test $? != 0 && error
127     ../../util/shlib_wrap.sh ../../apps/openssl ts -verify -data $3 -in $2 -CAfile tsaca.pem \
128         -untrusted tsa_cert1.pem
129     test $? != 0 && error
130 }
131
132 verify_time_stamp_token () {
133
134     # create the token from the response first
135     ../../util/shlib_wrap.sh ../../apps/openssl ts -reply -in $2 -out $2.token -token_out
136     test $? != 0 && error
137     ../../util/shlib_wrap.sh ../../apps/openssl ts -verify -queryfile $1 -in $2.token -token_in \
138         -CAfile tsaca.pem -untrusted tsa_cert1.pem
139     test $? != 0 && error
140     ../../util/shlib_wrap.sh ../../apps/openssl ts -verify -data $3 -in $2.token -token_in \
141         -CAfile tsaca.pem -untrusted tsa_cert1.pem
142     test $? != 0 && error
143 }
144
145 verify_time_stamp_response_fail () {
146
147     ../../util/shlib_wrap.sh ../../apps/openssl ts -verify -queryfile $1 -in $2 -CAfile tsaca.pem \
148         -untrusted tsa_cert1.pem
149     # Checks if the verification failed, as it should have.
150     test $? = 0 && error
151     echo Ok
152 }
153
154 # main functions
155
156 echo "Setting up TSA test directory..."
157 setup_dir
158
159 echo "Creating CA for TSA tests..."
160 create_ca
161
162 echo "Creating tsa_cert1.pem TSA server cert..."
163 create_tsa_cert 1 tsa_cert
164
165 echo "Creating tsa_cert2.pem non-TSA server cert..."
166 create_tsa_cert 2 non_tsa_cert
167
168 echo "Creating req1.req time stamp request for file testtsa..."
169 create_time_stamp_request1
170
171 echo "Printing req1.req..."
172 print_request req1.tsq
173
174 echo "Generating valid response for req1.req..."
175 create_time_stamp_response req1.tsq resp1.tsr tsa_config1
176
177 echo "Printing response..."
178 print_response resp1.tsr
179
180 echo "Verifying valid response..."
181 verify_time_stamp_response req1.tsq resp1.tsr ../testtsa
182
183 echo "Verifying valid token..."
184 verify_time_stamp_token req1.tsq resp1.tsr ../testtsa
185
186 # The tests below are commented out, because invalid signer certificates
187 # can no longer be specified in the config file.
188
189 # echo "Generating _invalid_ response for req1.req..."
190 # create_time_stamp_response req1.tsq resp1_bad.tsr tsa_config2
191
192 # echo "Printing response..."
193 # print_response resp1_bad.tsr
194
195 # echo "Verifying invalid response, it should fail..."
196 # verify_time_stamp_response_fail req1.tsq resp1_bad.tsr
197
198 echo "Creating req2.req time stamp request for file testtsa..."
199 create_time_stamp_request2
200
201 echo "Printing req2.req..."
202 print_request req2.tsq
203
204 echo "Generating valid response for req2.req..."
205 create_time_stamp_response req2.tsq resp2.tsr tsa_config1
206
207 echo "Checking '-token_in' and '-token_out' options with '-reply'..."
208 time_stamp_response_token_test req2.tsq resp2.tsr
209
210 echo "Printing response..."
211 print_response resp2.tsr
212
213 echo "Verifying valid response..."
214 verify_time_stamp_response req2.tsq resp2.tsr ../testtsa
215
216 echo "Verifying response against wrong request, it should fail..."
217 verify_time_stamp_response_fail req1.tsq resp2.tsr
218
219 echo "Verifying response against wrong request, it should fail..."
220 verify_time_stamp_response_fail req2.tsq resp1.tsr
221
222 echo "Creating req3.req time stamp request for file CAtsa.cnf..."
223 create_time_stamp_request3
224
225 echo "Printing req3.req..."
226 print_request req3.tsq
227
228 echo "Verifying response against wrong request, it should fail..."
229 verify_time_stamp_response_fail req3.tsq resp1.tsr
230
231 echo "Cleaning up..."
232 clean_up_dir
233
234 exit 0