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