7963e85259198ffe2e455adda02f9e95447f157b
[openssl.git] / test / testtsa.com
1 $!
2 $! A few very basic tests for the 'ts' time stamping authority command.
3 $!
4 $
5 $       __arch := VAX
6 $       if f$getsyi("cpu") .ge. 128 then __arch := AXP
7 $       exe_dir := sys$disk:[-.'__arch'.exe.apps]
8 $
9 $       openssl := mcr 'f$parse(exe_dir+"openssl.exe")'
10 $       OPENSSL_CONF := [-]CAtsa.cnf
11 $
12 $ error:
13 $       subroutine
14 $               write sys$error "TSA test failed!"
15 $               exit 3
16 $       endsubroutine
17 $
18 $ setup_dir:
19 $       subroutine
20 $
21 $               if f$search("tsa.dir") .nes ""
22 $               then
23 $                       @[-.util]deltree [.tsa]*.*
24 $                       set file/prot=(S:RWED,O:RWED,G:RWED,W:RWED) tsa.dir;*
25 $                       delete tsa.dir;*
26 $               endif
27 $
28 $               create/dir [.tsa]
29 $               set default [.tsa]
30 $       endsubroutine
31 $
32 $ clean_up_dir:
33 $       subroutine
34 $
35 $               set default [-]
36 $               @[-.util]deltree [.tsa]*.*
37 $               set file/prot=(S:RWED,O:RWED,G:RWED,W:RWED) tsa.dir;*
38 $               delete tsa.dir;*
39 $       endsubroutine
40 $
41 $ create_ca:
42 $       subroutine
43 $
44 $               write sys$output "Creating a new CA for the TSA tests..."
45 $               @[--.util]deltree [.demoCA]*.*
46 $
47 $               open/write file VMStsa-response.create_ca
48 $               write file ""
49 $               write file "HU"
50 $               write file "Budapest"
51 $               write file "Budapest"
52 $               write file "Gov-CA Ltd."
53 $               write file "ca1"
54 $               close file
55 $               open/read sys$ca_input VMStsa-response.create_ca
56 $               @[--.apps]CA.com -input sys$ca_input -newca
57 $               save_severity = $severity
58 $               close sys$ca_input
59 $               if save_severity .ne. 1 then call error
60 $       endsubroutine
61 $
62 $ create_tsa_cert:
63 $       subroutine
64 $
65 $               INDEX=p1
66 $               EXT=p2
67 $               open/write file VMStsa-response1.create_tsa_cert
68 $               write file "HU"
69 $               write file "Budapest"
70 $               write file "Buda"
71 $               write file "Hun-TSA Ltd."
72 $               write file "tsa",INDEX
73 $               close file
74 $               define/user sys$input VMStsa-response.create_tsa_cert
75 $               openssl req -new -
76                         -out tsa_req'INDEX'.pem -keyout tsa_key'INDEX'.pem
77 $               if $severity .ne. 1 then call error
78 $
79 $               open/write file VMStsa-response2.create_tsa_cert
80 $               write file "y"
81 $               write file "y"
82 $               close file
83 $               define/user sys$input VMStsa-response.create_tsa_cert
84 $               openssl ca -in tsa_req'INDEX'.pem -out tsa_cert'INDEX'.pem -
85                         -extensions "''EXT'"
86 $               if $severity .ne. 1 then call error
87 $       endsubroutine
88 $
89 $ print_request:
90 $       subroutine
91 $
92 $               openssl ts -query -in 'p1' -text
93 $       endsubroutine
94 $
95 $ create_time_stamp_request1: subroutine
96 $
97 $               openssl ts -query -data [-]testtsa.com -policy tsa_policy1 -
98                         -cert -out req1.tsq
99 $               if $severity .ne. 1 then call error
100 $       endsubroutine
101 $
102 $ create_time_stamp_request2: subroutine
103 $
104 $               openssl ts -query -data [-]testtsa.com -policy tsa_policy2 -
105                         -no_nonce -out req2.tsq
106 $               if $severity .ne. 1 then call error
107 $       endsubroutine
108 $
109 $ create_time_stamp_request3: subroutine
110 $
111 $               openssl ts -query -data [-]CAtsa.cnf -no_nonce -out req3.tsq
112 $               if $severity .ne. 1 then call error
113 $       endsubroutine
114 $
115 $ print_response:
116 $       subroutine
117 $
118 $               openssl ts -reply -in 'p1' -text
119 $               if $severity .ne. 1 then call error
120 $       endsubroutine
121 $
122 $ create_time_stamp_response:
123 $       subroutine
124 $
125 $               openssl ts -reply -section 'p3' -queryfile 'p1' -out 'p2'
126 $               if $severity .ne. 1 then call error
127 $       endsubroutine
128 $
129 $ time_stamp_response_token_test:
130 $       subroutine
131 $
132 $               RESPONSE2:='p2'.copy_tsr
133 $               TOKEN_DER:='p2'.token_der
134 $               openssl ts -reply -in 'p2' -out 'TOKEN_DER' -token_out
135 $               if $severity .ne. 1 then call error
136 $               openssl ts -reply -in 'TOKEN_DER' -token_in -out 'RESPONSE2'
137 $               if $severity .ne. 1 then call error
138 $               backup/compare 'RESPONSE2' 'p2'
139 $               if $severity .ne. 1 then call error
140 $               openssl ts -reply -in 'p2' -text -token_out
141 $               if $severity .ne. 1 then call error
142 $               openssl ts -reply -in 'TOKEN_DER' -token_in -text -token_out
143 $               if $severity .ne. 1 then call error
144 $               openssl ts -reply -queryfile 'p1' -text -token_out
145 $               if $severity .ne. 1 then call error
146 $       endsubroutine
147 $
148 $ verify_time_stamp_response:
149 $       subroutine
150 $
151 $               openssl ts -verify -queryfile 'p1' -in 'p2' -
152                         -CAfile [.demoCA]cacert.pem -untrusted tsa_cert1.pem
153 $               if $severity .ne. 1 then call error
154 $               openssl ts -verify -data 'p3' -in 'p2' -
155                         -CAfile [.demoCA]cacert.pem -untrusted tsa_cert1.pem
156 $               if $severity .ne. 1 then call error
157 $       endsubroutine
158 $
159 $ verify_time_stamp_token:
160 $       subroutine
161 $
162 $               # create the token from the response first
163 $               openssl ts -reply -in 'p2' -out 'p2'.token -token_out
164 $               if $severity .ne. 1 then call error
165 $               openssl ts -verify -queryfile 'p1' -in 'p2'.token -token_in \
166                         -CAfile [.demoCA]cacert.pem -untrusted tsa_cert1.pem
167 $               if $severity .ne. 1 then call error
168 $               openssl ts -verify -data 'p3' -in 'p2'.token -token_in \
169                         -CAfile [.demoCA]cacert.pem -untrusted tsa_cert1.pem
170 $               if $severity .ne. 1 then call error
171 $       endsubroutine
172 $
173 $ verify_time_stamp_response_fail:
174 $       subroutine
175 $
176 $               openssl ts -verify -queryfile 'p1' -in 'p2' -
177                         -CAfile [.demoCA]cacert.pem -untrusted tsa_cert1.pem
178 $               # Checks if the verification failed, as it should have.
179 $               if $severity .ne. 1 then call error
180 $               write sys$output "Ok"
181 $       endsubroutine
182 $
183 $       ! Main body ----------------------------------------------------------
184 $
185 $       write sys$output "Setting up TSA test directory..."
186 $       call setup_dir
187 $
188 $       write sys$output "Creating CA for TSA tests..."
189 $       call create_ca
190 $
191 $       write sys$output "Creating tsa_cert1.pem TSA server cert..."
192 $       call create_tsa_cert 1 tsa_cert
193 $
194 $       write sys$output "Creating tsa_cert2.pem non-TSA server cert..."
195 $       call create_tsa_cert 2 non_tsa_cert
196 $
197 $       write sys$output "Creating req1.req time stamp request for file testtsa..."
198 $       call create_time_stamp_request1
199 $
200 $       write sys$output "Printing req1.req..."
201 $       call print_request req1.tsq
202 $
203 $       write sys$output "Generating valid response for req1.req..."
204 $       call create_time_stamp_response req1.tsq resp1.tsr tsa_config1
205 $
206 $       write sys$output "Printing response..."
207 $       call print_response resp1.tsr
208 $
209 $       write sys$output "Verifying valid response..."
210 $       call verify_time_stamp_response req1.tsq resp1.tsr ../testtsa
211 $
212 $       write sys$output "Verifying valid token..."
213 $       call verify_time_stamp_token req1.tsq resp1.tsr ../testtsa
214 $
215 $       ! The tests below are commented out, because invalid signer certificates
216 $       ! can no longer be specified in the config file.
217 $
218 $       ! write sys$output "Generating _invalid_ response for req1.req..."
219 $       ! call create_time_stamp_response req1.tsq resp1_bad.tsr tsa_config2
220 $
221 $       ! write sys$output "Printing response..."
222 $       ! call print_response resp1_bad.tsr
223 $
224 $       ! write sys$output "Verifying invalid response, it should fail..."
225 $       ! call verify_time_stamp_response_fail req1.tsq resp1_bad.tsr
226 $
227 $       write sys$output "Creating req2.req time stamp request for file testtsa..."
228 $       call create_time_stamp_request2
229 $
230 $       write sys$output "Printing req2.req..."
231 $       call print_request req2.tsq
232 $
233 $       write sys$output "Generating valid response for req2.req..."
234 $       call create_time_stamp_response req2.tsq resp2.tsr tsa_config1
235 $
236 $       write sys$output "Checking '-token_in' and '-token_out' options with '-reply'..."
237 $       call time_stamp_response_token_test req2.tsq resp2.tsr
238 $
239 $       write sys$output "Printing response..."
240 $       call print_response resp2.tsr
241 $
242 $       write sys$output "Verifying valid response..."
243 $       call verify_time_stamp_response req2.tsq resp2.tsr ../testtsa
244 $
245 $       write sys$output "Verifying response against wrong request, it should fail..."
246 $       call verify_time_stamp_response_fail req1.tsq resp2.tsr
247 $
248 $       write sys$output "Verifying response against wrong request, it should fail..."
249 $       call verify_time_stamp_response_fail req2.tsq resp1.tsr
250 $
251 $       write sys$output "Creating req3.req time stamp request for file CAtsa.cnf..."
252 $       call create_time_stamp_request3
253 $
254 $       write sys$output "Printing req3.req..."
255 $       call print_request req3.tsq
256 $
257 $       write sys$output "Verifying response against wrong request, it should fail..."
258 $       call verify_time_stamp_response_fail req3.tsq resp1.tsr
259 $
260 $       write sys$output "Cleaning up..."
261 $       call clean_up_dir
262 $
263 $       exit