2 # Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the OpenSSL license (the "License"). You may not use
5 # this file except in compliance with the License. You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
14 use File::Spec::Functions qw/splitdir curdir catfile/;
16 use OpenSSL::Test qw/:DEFAULT cmdstr srctop_file/;
17 use OpenSSL::Test::Utils;
21 plan skip_all => "TS is not supported by this OpenSSL build"
24 # All these are modified inside indir further down. They need to exist
25 # here, however, to be available in all subroutines.
28 my @RUN = ("openssl", "ts");
34 $ENV{TSDNSECT} = "ts_cert_dn";
36 ok(run(app(["openssl", "req", "-new",
37 "-out", "tsa_req${INDEX}.pem",
38 "-keyout", "tsa_key${INDEX}.pem"])));
39 note "using extension $EXT";
40 ok(run(app(["openssl", "x509", "-req",
41 "-in", "tsa_req${INDEX}.pem",
42 "-out", "tsa_cert${INDEX}.pem",
43 "-CA", "tsaca.pem", "-CAkey", "tsacakey.pem",
45 "-extfile", $ENV{OPENSSL_CONF}, "-extensions", $EXT])));
48 sub create_time_stamp_response {
49 my $queryfile = shift;
50 my $outputfile = shift;
53 ok(run(app([@RUN, "-reply", "-section", "$datafile",
54 "-queryfile", "$queryfile", "-out", "$outputfile"])));
57 sub verify_time_stamp_response {
58 my $queryfile = shift;
59 my $inputfile = shift;
62 ok(run(app([@RUN, "-verify", "-queryfile", "$queryfile",
63 "-in", "$inputfile", "-CAfile", "tsaca.pem",
64 "-untrusted", "tsa_cert1.pem"])));
65 ok(run(app([@RUN, "-verify", "-data", "$datafile",
66 "-in", "$inputfile", "-CAfile", "tsaca.pem",
67 "-untrusted", "tsa_cert1.pem"])));
70 sub verify_time_stamp_response_fail {
71 my $queryfile = shift;
72 my $inputfile = shift;
74 ok(!run(app([@RUN, "-verify", "-queryfile", "$queryfile",
75 "-in", "$inputfile", "-CAfile", "tsaca.pem",
76 "-untrusted", "tsa_cert1.pem"])));
83 note "setting up TSA test directory";
86 $ENV{OPENSSL_CONF} = srctop_file("test", "CAtsa.cnf");
87 # Because that's what ../apps/CA.pl really looks at
88 $ENV{OPENSSL_CONFIG} = "-config ".$ENV{OPENSSL_CONF};
89 $ENV{OPENSSL} = cmdstr(app(["openssl"]), display => 1);
90 $testtsa = srctop_file("test", "recipes", "80-test_tsa.t");
91 $CAtsa = srctop_file("test", "CAtsa.cnf");
94 $ENV{TSDNSECT} = "ts_ca_dn";
96 unless ok(run(app(["openssl", "req", "-new", "-x509", "-nodes",
97 "-out", "tsaca.pem", "-keyout", "tsacakey.pem"])),
98 'creating a new CA for the TSA tests');
101 unless subtest 'creating tsa_cert1.pem TSA server cert' => sub {
102 create_tsa_cert("1", "tsa_cert")
106 unless subtest 'creating tsa_cert2.pem non-TSA server cert' => sub {
107 create_tsa_cert("2", "non_tsa_cert")
111 unless ok(run(app([@RUN, "-query", "-data", $testtsa,
112 "-tspolicy", "tsa_policy1", "-cert",
113 "-out", "req1.tsq"])),
114 'creating req1.req time stamp request for file testtsa');
116 ok(run(app([@RUN, "-query", "-in", "req1.tsq", "-text"])),
117 'printing req1.req');
119 subtest 'generating valid response for req1.req' => sub {
120 create_time_stamp_response("req1.tsq", "resp1.tsr", "tsa_config1")
123 ok(run(app([@RUN, "-reply", "-in", "resp1.tsr", "-text"])),
124 'printing response');
126 subtest 'verifying valid response' => sub {
127 verify_time_stamp_response("req1.tsq", "resp1.tsr", $testtsa)
131 unless subtest 'verifying valid token' => sub {
132 ok(run(app([@RUN, "-reply", "-in", "resp1.tsr",
133 "-out", "resp1.tsr.token", "-token_out"])));
134 ok(run(app([@RUN, "-verify", "-queryfile", "req1.tsq",
135 "-in", "resp1.tsr.token", "-token_in",
136 "-CAfile", "tsaca.pem",
137 "-untrusted", "tsa_cert1.pem"])));
138 ok(run(app([@RUN, "-verify", "-data", $testtsa,
139 "-in", "resp1.tsr.token", "-token_in",
140 "-CAfile", "tsaca.pem",
141 "-untrusted", "tsa_cert1.pem"])));
145 unless ok(run(app([@RUN, "-query", "-data", $testtsa,
146 "-tspolicy", "tsa_policy2", "-no_nonce",
147 "-out", "req2.tsq"])),
148 'creating req2.req time stamp request for file testtsa');
150 ok(run(app([@RUN, "-query", "-in", "req2.tsq", "-text"])),
151 'printing req2.req');
154 unless subtest 'generating valid response for req2.req' => sub {
155 create_time_stamp_response("req2.tsq", "resp2.tsr", "tsa_config1")
159 unless subtest 'checking -token_in and -token_out options with -reply' => sub {
160 my $RESPONSE2="resp2.tsr.copy.tsr";
161 my $TOKEN_DER="resp2.tsr.token.der";
163 ok(run(app([@RUN, "-reply", "-in", "resp2.tsr",
164 "-out", "$TOKEN_DER", "-token_out"])));
165 ok(run(app([@RUN, "-reply", "-in", "$TOKEN_DER",
166 "-token_in", "-out", "$RESPONSE2"])));
167 is(compare($RESPONSE2, "resp2.tsr"), 0);
168 ok(run(app([@RUN, "-reply", "-in", "resp2.tsr",
169 "-text", "-token_out"])));
170 ok(run(app([@RUN, "-reply", "-in", "$TOKEN_DER",
171 "-token_in", "-text", "-token_out"])));
172 ok(run(app([@RUN, "-reply", "-queryfile", "req2.tsq",
173 "-text", "-token_out"])));
176 ok(run(app([@RUN, "-reply", "-in", "resp2.tsr", "-text"])),
177 'printing response');
179 subtest 'verifying valid response' => sub {
180 verify_time_stamp_response("req2.tsq", "resp2.tsr", $testtsa)
183 subtest 'verifying response against wrong request, it should fail' => sub {
184 verify_time_stamp_response_fail("req1.tsq", "resp2.tsr")
187 subtest 'verifying response against wrong request, it should fail' => sub {
188 verify_time_stamp_response_fail("req2.tsq", "resp1.tsr")
192 unless ok(run(app([@RUN, "-query", "-data", $CAtsa,
193 "-no_nonce", "-out", "req3.tsq"])),
194 "creating req3.req time stamp request for file CAtsa.cnf");
196 ok(run(app([@RUN, "-query", "-in", "req3.tsq", "-text"])),
197 'printing req3.req');
199 subtest 'verifying response against wrong request, it should fail' => sub {
200 verify_time_stamp_response_fail("req3.tsq", "resp1.tsr")
203 }, create => 1, cleanup => 1