2 # Copyright 2015-2023 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the Apache License 2.0 (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/catfile/;
15 use File::Compare qw/compare_text compare/;
16 use OpenSSL::Test qw/:DEFAULT srctop_dir srctop_file bldtop_dir bldtop_file with data_file/;
18 use OpenSSL::Test::Utils;
24 use lib srctop_dir('Configurations');
25 use lib bldtop_dir('.');
27 my $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0);
29 plan skip_all => "CMS is not supported by this OpenSSL build"
32 my $provpath = bldtop_dir("providers");
34 # Some tests require legacy algorithms to be included.
35 my @legacyprov = ("-provider-path", $provpath,
36 "-provider", "default",
37 "-provider", "legacy" );
38 my @defaultprov = ("-provider-path", $provpath,
39 "-provider", "default");
42 my $provname = 'default';
44 my $datadir = srctop_dir("test", "recipes", "80-test_cms_data");
45 my $smdir = srctop_dir("test", "smime-certs");
46 my $smcont = srctop_file("test", "smcont.txt");
47 my $smcont_zero = srctop_file("test", "smcont_zero.txt");
48 my ($no_des, $no_dh, $no_dsa, $no_ec, $no_ec2m, $no_rc2, $no_zlib)
49 = disabled qw/des dh dsa ec ec2m rc2 zlib/;
51 $no_rc2 = 1 if disabled("legacy");
55 ok(run(test(["pkcs7_test"])), "test pkcs7");
58 @config = ( "-config", srctop_file("test", "fips-and-base.cnf") );
62 $ENV{OPENSSL_TEST_LIBCTX} = "1";
63 my @prov = ("-provider-path", $provpath,
65 "-provider", $provname);
67 my $smrsa1024 = catfile($smdir, "smrsa1024.pem");
68 my $smrsa1 = catfile($smdir, "smrsa1.pem");
69 my $smroot = catfile($smdir, "smroot.pem");
71 my @smime_pkcs7_tests = (
73 [ "signed content DER format, RSA key",
74 [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER", "-nodetach",
75 "-certfile", $smroot, "-signer", $smrsa1, "-out", "{output}.cms" ],
76 [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "DER",
77 "-CAfile", $smroot, "-out", "{output}.txt" ],
81 [ "signed detached content DER format, RSA key",
82 [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER",
83 "-signer", $smrsa1, "-out", "{output}.cms" ],
84 [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "DER",
85 "-CAfile", $smroot, "-out", "{output}.txt",
86 "-content", $smcont ],
90 [ "signed content test streaming BER format, RSA",
91 [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER", "-nodetach",
93 "-signer", $smrsa1, "-out", "{output}.cms" ],
94 [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "DER",
95 "-CAfile", $smroot, "-out", "{output}.txt" ],
99 [ "signed content DER format, DSA key",
100 [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER", "-nodetach",
101 "-signer", catfile($smdir, "smdsa1.pem"), "-out", "{output}.cms" ],
102 [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "DER",
103 "-CAfile", $smroot, "-out", "{output}.txt" ],
107 [ "signed detached content DER format, DSA key",
108 [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER",
109 "-signer", catfile($smdir, "smdsa1.pem"), "-out", "{output}.cms" ],
110 [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "DER",
111 "-CAfile", $smroot, "-out", "{output}.txt",
112 "-content", $smcont ],
116 [ "signed detached content DER format, add RSA signer (with DSA existing)",
117 [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER",
118 "-signer", catfile($smdir, "smdsa1.pem"), "-out", "{output}.cms" ],
119 [ "{cmd1}", @prov, "-resign", "-in", "{output}.cms", "-inform", "DER", "-outform", "DER",
120 "-signer", $smrsa1, "-out", "{output}2.cms" ],
121 [ "{cmd2}", @prov, "-verify", "-in", "{output}2.cms", "-inform", "DER",
122 "-CAfile", $smroot, "-out", "{output}.txt",
123 "-content", $smcont ],
127 [ "signed content test streaming BER format, DSA key",
128 [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER",
129 "-nodetach", "-stream",
130 "-signer", catfile($smdir, "smdsa1.pem"), "-out", "{output}.cms" ],
131 [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "DER",
132 "-CAfile", $smroot, "-out", "{output}.txt" ],
136 [ "signed content test streaming BER format, 2 DSA and 2 RSA keys",
137 [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER",
138 "-nodetach", "-stream",
140 "-signer", catfile($smdir, "smrsa2.pem"),
141 "-signer", catfile($smdir, "smdsa1.pem"),
142 "-signer", catfile($smdir, "smdsa2.pem"),
143 "-out", "{output}.cms" ],
144 [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "DER",
145 "-CAfile", $smroot, "-out", "{output}.txt" ],
149 [ "signed content test streaming BER format, 2 DSA and 2 RSA keys, no attributes",
150 [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER",
151 "-noattr", "-nodetach", "-stream",
153 "-signer", catfile($smdir, "smrsa2.pem"),
154 "-signer", catfile($smdir, "smdsa1.pem"),
155 "-signer", catfile($smdir, "smdsa2.pem"),
156 "-out", "{output}.cms" ],
157 [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "DER",
158 "-CAfile", $smroot, "-out", "{output}.txt" ],
162 [ "signed content S/MIME format, RSA key SHA1",
163 [ "{cmd1}", @defaultprov, "-sign", "-in", $smcont, "-md", "sha1",
164 "-certfile", $smroot,
165 "-signer", $smrsa1, "-out", "{output}.cms" ],
166 [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms",
167 "-CAfile", $smroot, "-out", "{output}.txt" ],
171 [ "signed zero-length content S/MIME format, RSA key SHA1",
172 [ "{cmd1}", @defaultprov, "-sign", "-in", $smcont_zero, "-md", "sha1",
173 "-certfile", $smroot, "-signer", $smrsa1, "-out", "{output}.cms" ],
174 [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms",
175 "-CAfile", $smroot, "-out", "{output}.txt" ],
179 [ "signed content test streaming S/MIME format, 2 DSA and 2 RSA keys",
180 [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-nodetach",
182 "-signer", catfile($smdir, "smrsa2.pem"),
183 "-signer", catfile($smdir, "smdsa1.pem"),
184 "-signer", catfile($smdir, "smdsa2.pem"),
185 "-stream", "-out", "{output}.cms" ],
186 [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms",
187 "-CAfile", $smroot, "-out", "{output}.txt" ],
191 [ "signed content test streaming multipart S/MIME format, 2 DSA and 2 RSA keys",
192 [ "{cmd1}", @prov, "-sign", "-in", $smcont,
194 "-signer", catfile($smdir, "smrsa2.pem"),
195 "-signer", catfile($smdir, "smdsa1.pem"),
196 "-signer", catfile($smdir, "smdsa2.pem"),
197 "-stream", "-out", "{output}.cms" ],
198 [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms",
199 "-CAfile", $smroot, "-out", "{output}.txt" ],
203 [ "enveloped content test streaming S/MIME format, DES, 3 recipients",
204 [ "{cmd1}", @defaultprov, "-encrypt", "-in", $smcont,
205 "-stream", "-out", "{output}.cms",
207 catfile($smdir, "smrsa2.pem"),
208 catfile($smdir, "smrsa3.pem") ],
209 [ "{cmd2}", @defaultprov, "-decrypt", "-recip", $smrsa1,
210 "-in", "{output}.cms", "-out", "{output}.txt" ],
214 [ "enveloped content test streaming S/MIME format, DES, 3 recipients, 3rd used",
215 [ "{cmd1}", @defaultprov, "-encrypt", "-in", $smcont,
216 "-stream", "-out", "{output}.cms",
218 catfile($smdir, "smrsa2.pem"),
219 catfile($smdir, "smrsa3.pem") ],
220 [ "{cmd2}", @defaultprov, "-decrypt", "-recip", catfile($smdir, "smrsa3.pem"),
221 "-in", "{output}.cms", "-out", "{output}.txt" ],
225 [ "enveloped content test streaming S/MIME format, DES, 3 recipients, cert and key files used",
226 [ "{cmd1}", @defaultprov, "-encrypt", "-in", $smcont,
227 "-stream", "-out", "{output}.cms",
229 catfile($smdir, "smrsa2.pem"),
230 catfile($smdir, "smrsa3-cert.pem") ],
231 [ "{cmd2}", @defaultprov, "-decrypt",
232 "-recip", catfile($smdir, "smrsa3-cert.pem"),
233 "-inkey", catfile($smdir, "smrsa3-key.pem"),
234 "-in", "{output}.cms", "-out", "{output}.txt" ],
238 [ "enveloped content test streaming S/MIME format, AES-256 cipher, 3 recipients",
239 [ "{cmd1}", @prov, "-encrypt", "-in", $smcont,
240 "-aes256", "-stream", "-out", "{output}.cms",
242 catfile($smdir, "smrsa2.pem"),
243 catfile($smdir, "smrsa3.pem") ],
244 [ "{cmd2}", @prov, "-decrypt", "-recip", $smrsa1,
245 "-in", "{output}.cms", "-out", "{output}.txt" ],
251 my @smime_cms_tests = (
253 [ "signed content test streaming BER format, 2 DSA and 2 RSA keys, keyid",
254 [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER",
255 "-nodetach", "-keyid",
257 "-signer", catfile($smdir, "smrsa2.pem"),
258 "-signer", catfile($smdir, "smdsa1.pem"),
259 "-signer", catfile($smdir, "smdsa2.pem"),
260 "-stream", "-out", "{output}.cms" ],
261 [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "DER",
262 "-CAfile", $smroot, "-out", "{output}.txt" ],
266 [ "signed content test streaming PEM format, 2 DSA and 2 RSA keys",
267 [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
269 "-signer", catfile($smdir, "smrsa2.pem"),
270 "-signer", catfile($smdir, "smdsa1.pem"),
271 "-signer", catfile($smdir, "smdsa2.pem"),
272 "-stream", "-out", "{output}.cms" ],
273 [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "PEM",
274 "-CAfile", $smroot, "-out", "{output}.txt" ],
278 [ "signed content MIME format, RSA key, signed receipt request",
279 [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-nodetach",
281 "-receipt_request_to", "test\@openssl.org", "-receipt_request_all",
282 "-out", "{output}.cms" ],
283 [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms",
284 "-CAfile", $smroot, "-out", "{output}.txt" ],
288 [ "signed receipt MIME format, RSA key",
289 [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-nodetach",
291 "-receipt_request_to", "test\@openssl.org", "-receipt_request_all",
292 "-out", "{output}.cms" ],
293 [ "{cmd1}", @prov, "-sign_receipt", "-in", "{output}.cms",
294 "-signer", catfile($smdir, "smrsa2.pem"), "-out", "{output}2.cms" ],
295 [ "{cmd2}", @prov, "-verify_receipt", "{output}2.cms", "-in", "{output}.cms",
299 [ "enveloped content test streaming S/MIME format, DES, 3 recipients, keyid",
300 [ "{cmd1}", @defaultprov, "-encrypt", "-in", $smcont,
301 "-stream", "-out", "{output}.cms", "-keyid",
303 catfile($smdir, "smrsa2.pem"),
304 catfile($smdir, "smrsa3.pem") ],
305 [ "{cmd2}", @defaultprov, "-decrypt", "-recip", $smrsa1,
306 "-in", "{output}.cms", "-out", "{output}.txt" ],
310 [ "enveloped content test streaming PEM format, AES-256-CBC cipher, KEK",
311 [ "{cmd1}", @prov, "-encrypt", "-in", $smcont, "-outform", "PEM", "-aes128",
312 "-stream", "-out", "{output}.cms",
313 "-secretkey", "000102030405060708090A0B0C0D0E0F",
314 "-secretkeyid", "C0FEE0" ],
315 [ "{cmd2}", @prov, "-decrypt", "-in", "{output}.cms", "-out", "{output}.txt",
317 "-secretkey", "000102030405060708090A0B0C0D0E0F",
318 "-secretkeyid", "C0FEE0" ],
322 [ "enveloped content test streaming PEM format, AES-256-GCM cipher, KEK",
323 [ "{cmd1}", @prov, "-encrypt", "-in", $smcont, "-outform", "PEM", "-aes-128-gcm",
324 "-stream", "-out", "{output}.cms",
325 "-secretkey", "000102030405060708090A0B0C0D0E0F",
326 "-secretkeyid", "C0FEE0" ],
327 [ "{cmd2}", "-decrypt", "-in", "{output}.cms", "-out", "{output}.txt",
329 "-secretkey", "000102030405060708090A0B0C0D0E0F",
330 "-secretkeyid", "C0FEE0" ],
334 [ "enveloped content test streaming PEM format, KEK, key only",
335 [ "{cmd1}", @prov, "-encrypt", "-in", $smcont, "-outform", "PEM", "-aes128",
336 "-stream", "-out", "{output}.cms",
337 "-secretkey", "000102030405060708090A0B0C0D0E0F",
338 "-secretkeyid", "C0FEE0" ],
339 [ "{cmd2}", @prov, "-decrypt", "-in", "{output}.cms", "-out", "{output}.txt",
341 "-secretkey", "000102030405060708090A0B0C0D0E0F" ],
345 [ "data content test streaming PEM format",
346 [ "{cmd1}", @prov, "-data_create", "-in", $smcont, "-outform", "PEM",
347 "-nodetach", "-stream", "-out", "{output}.cms" ],
348 [ "{cmd2}", @prov, "-data_out", "-in", "{output}.cms", "-inform", "PEM",
349 "-out", "{output}.txt" ],
353 [ "encrypted content test streaming PEM format, 128 bit RC2 key",
354 [ "{cmd1}", @legacyprov, "-EncryptedData_encrypt",
355 "-in", $smcont, "-outform", "PEM",
356 "-rc2", "-secretkey", "000102030405060708090A0B0C0D0E0F",
357 "-stream", "-out", "{output}.cms" ],
358 [ "{cmd2}", @legacyprov, "-EncryptedData_decrypt", "-in", "{output}.cms",
360 "-secretkey", "000102030405060708090A0B0C0D0E0F",
361 "-out", "{output}.txt" ],
365 [ "encrypted content test streaming PEM format, 40 bit RC2 key",
366 [ "{cmd1}", @legacyprov, "-EncryptedData_encrypt",
367 "-in", $smcont, "-outform", "PEM",
368 "-rc2", "-secretkey", "0001020304",
369 "-stream", "-out", "{output}.cms" ],
370 [ "{cmd2}", @legacyprov, "-EncryptedData_decrypt", "-in", "{output}.cms",
372 "-secretkey", "0001020304", "-out", "{output}.txt" ],
376 [ "encrypted content test streaming PEM format, triple DES key",
377 [ "{cmd1}", @prov, "-EncryptedData_encrypt", "-in", $smcont, "-outform", "PEM",
378 "-des3", "-secretkey", "000102030405060708090A0B0C0D0E0F1011121314151617",
379 "-stream", "-out", "{output}.cms" ],
380 [ "{cmd2}", @prov, "-EncryptedData_decrypt", "-in", "{output}.cms",
382 "-secretkey", "000102030405060708090A0B0C0D0E0F1011121314151617",
383 "-out", "{output}.txt" ],
387 [ "encrypted content test streaming PEM format, 128 bit AES key",
388 [ "{cmd1}", @prov, "-EncryptedData_encrypt", "-in", $smcont, "-outform", "PEM",
389 "-aes128", "-secretkey", "000102030405060708090A0B0C0D0E0F",
390 "-stream", "-out", "{output}.cms" ],
391 [ "{cmd2}", @prov, "-EncryptedData_decrypt", "-in", "{output}.cms",
393 "-secretkey", "000102030405060708090A0B0C0D0E0F",
394 "-out", "{output}.txt" ],
399 my @smime_cms_cades_tests = (
401 [ "signed content DER format, RSA key, CAdES-BES compatible",
402 [ "{cmd1}", @prov, "-sign", "-cades", "-in", $smcont, "-outform", "DER",
404 "-certfile", $smroot, "-signer", $smrsa1, "-out", "{output}.cms" ],
405 [ "{cmd2}", @prov, "-verify", "-cades", "-in", "{output}.cms", "-inform", "DER",
406 "-CAfile", $smroot, "-out", "{output}.txt" ],
410 [ "signed content DER format, RSA key, SHA256 md, CAdES-BES compatible",
411 [ "{cmd1}", @prov, "-sign", "-cades", "-md", "sha256", "-in", $smcont, "-outform",
412 "DER", "-nodetach", "-certfile", $smroot,
413 "-signer", $smrsa1, "-out", "{output}.cms" ],
414 [ "{cmd2}", @prov, "-verify", "-cades", "-in", "{output}.cms", "-inform", "DER",
415 "-CAfile", $smroot, "-out", "{output}.txt" ],
419 [ "signed content DER format, RSA key, SHA512 md, CAdES-BES compatible",
420 [ "{cmd1}", @prov, "-sign", "-cades", "-md", "sha512", "-in", $smcont, "-outform",
421 "DER", "-nodetach", "-certfile", $smroot,
422 "-signer", $smrsa1, "-out", "{output}.cms" ],
423 [ "{cmd2}", @prov, "-verify", "-cades", "-in", "{output}.cms", "-inform", "DER",
424 "-CAfile", $smroot, "-out", "{output}.txt" ],
428 [ "signed content DER format, RSA key, SHA256 md, CAdES-BES compatible",
429 [ "{cmd1}", @prov, "-sign", "-cades", "-binary", "-nodetach", "-nosmimecap", "-md", "sha256",
430 "-in", $smcont, "-outform", "DER",
431 "-certfile", $smroot, "-signer", $smrsa1,
432 "-outform", "DER", "-out", "{output}.cms" ],
433 [ "{cmd2}", @prov, "-verify", "-cades", "-in", "{output}.cms", "-inform", "DER",
434 "-CAfile", $smroot, "-out", "{output}.txt" ],
438 [ "resigned content DER format, RSA key, SHA256 md, CAdES-BES compatible",
439 [ "{cmd1}", @prov, "-sign", "-cades", "-binary", "-nodetach", "-nosmimecap", "-md", "sha256",
440 "-in", $smcont, "-outform", "DER",
441 "-certfile", $smroot, "-signer", $smrsa1,
442 "-outform", "DER", "-out", "{output}.cms" ],
443 [ "{cmd1}", @prov, "-resign", "-cades", "-binary", "-nodetach", "-nosmimecap", "-md", "sha256",
444 "-inform", "DER", "-in", "{output}.cms",
445 "-certfile", $smroot, "-signer", catfile($smdir, "smrsa2.pem"),
446 "-outform", "DER", "-out", "{output}2.cms" ],
448 [ "{cmd2}", @prov, "-verify", "-cades", "-in", "{output}2.cms", "-inform", "DER",
449 "-CAfile", $smroot, "-out", "{output}.txt" ],
454 my @smime_cms_cades_ko_tests = (
455 [ "sign content DER format, RSA key, not CAdES-BES compatible",
456 [ @prov, "-sign", "-in", $smcont, "-outform", "DER", "-nodetach",
457 "-certfile", $smroot, "-signer", $smrsa1, "-out", "cades-ko.cms" ],
458 "fail to verify token since requiring CAdES-BES compatibility",
459 [ @prov, "-verify", "-cades", "-in", "cades-ko.cms", "-inform", "DER",
460 "-CAfile", $smroot, "-out", "cades-ko.txt" ],
465 # cades options test - check that some combinations are rejected
466 my @smime_cms_cades_invalid_option_tests = (
468 [ "-cades", "-noattr" ],
470 [ "-verify", "-cades", "-noattr" ],
472 [ "-verify", "-cades", "-noverify" ],
476 my @smime_cms_comp_tests = (
478 [ "compressed content test streaming PEM format",
479 [ "{cmd1}", @prov, "-compress", "-in", $smcont, "-outform", "PEM", "-nodetach",
480 "-stream", "-out", "{output}.cms" ],
481 [ "{cmd2}", @prov, "-uncompress", "-in", "{output}.cms", "-inform", "PEM",
482 "-out", "{output}.txt" ],
488 my @smime_cms_param_tests = (
489 [ "signed content test streaming PEM format, RSA keys, PSS signature",
490 [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
492 "-keyopt", "rsa_padding_mode:pss",
493 "-out", "{output}.cms" ],
494 [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "PEM",
495 "-CAfile", $smroot, "-out", "{output}.txt" ],
499 [ "signed content test streaming PEM format, RSA keys, PSS signature, saltlen=max",
500 [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
502 "-keyopt", "rsa_padding_mode:pss", "-keyopt", "rsa_pss_saltlen:max",
503 "-out", "{output}.cms" ],
504 sub { my %opts = @_; rsapssSaltlen("$opts{output}.cms") == 222; },
505 [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "PEM",
506 "-CAfile", $smroot, "-out", "{output}.txt" ],
510 [ "signed content test streaming PEM format, RSA keys, PSS signature, no attributes",
511 [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
512 "-noattr", "-signer", $smrsa1,
513 "-keyopt", "rsa_padding_mode:pss",
514 "-out", "{output}.cms" ],
515 [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "PEM",
516 "-CAfile", $smroot, "-out", "{output}.txt" ],
520 [ "signed content test streaming PEM format, RSA keys, PSS signature, SHA384 MGF1",
521 [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
523 "-keyopt", "rsa_padding_mode:pss", "-keyopt", "rsa_mgf1_md:sha384",
524 "-out", "{output}.cms" ],
525 [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "PEM",
526 "-CAfile", $smroot, "-out", "{output}.txt" ],
530 [ "signed content test streaming PEM format, RSA keys, PSS signature, saltlen=16",
531 [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
532 "-signer", $smrsa1, "-md", "sha256",
533 "-keyopt", "rsa_padding_mode:pss", "-keyopt", "rsa_pss_saltlen:16",
534 "-out", "{output}.cms" ],
535 sub { my %opts = @_; rsapssSaltlen("$opts{output}.cms") == 16; },
536 [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "PEM",
537 "-CAfile", $smroot, "-out", "{output}.txt" ],
541 [ "signed content test streaming PEM format, RSA keys, PSS signature, saltlen=digest",
542 [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
543 "-signer", $smrsa1, "-md", "sha256",
544 "-keyopt", "rsa_padding_mode:pss", "-keyopt", "rsa_pss_saltlen:digest",
545 "-out", "{output}.cms" ],
546 # digest is SHA-256, which produces 32 bytes of output
547 sub { my %opts = @_; rsapssSaltlen("$opts{output}.cms") == 32; },
548 [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "PEM",
549 "-CAfile", $smroot, "-out", "{output}.txt" ],
553 [ "enveloped content test streaming S/MIME format, DES, OAEP default parameters",
554 [ "{cmd1}", @defaultprov, "-encrypt", "-in", $smcont,
555 "-stream", "-out", "{output}.cms",
557 "-keyopt", "rsa_padding_mode:oaep" ],
558 [ "{cmd2}", @defaultprov, "-decrypt", "-recip", $smrsa1,
559 "-in", "{output}.cms", "-out", "{output}.txt" ],
563 [ "enveloped content test streaming S/MIME format, DES, OAEP SHA256",
564 [ "{cmd1}", @defaultprov, "-encrypt", "-in", $smcont,
565 "-stream", "-out", "{output}.cms",
567 "-keyopt", "rsa_padding_mode:oaep",
568 "-keyopt", "rsa_oaep_md:sha256" ],
569 [ "{cmd2}", @defaultprov, "-decrypt", "-recip", $smrsa1,
570 "-in", "{output}.cms", "-out", "{output}.txt" ],
574 [ "enveloped content test streaming S/MIME format, DES, ECDH",
575 [ "{cmd1}", @defaultprov, "-encrypt", "-in", $smcont,
576 "-stream", "-out", "{output}.cms",
577 "-recip", catfile($smdir, "smec1.pem") ],
578 [ "{cmd2}", @defaultprov, "-decrypt", "-recip", catfile($smdir, "smec1.pem"),
579 "-in", "{output}.cms", "-out", "{output}.txt" ],
583 [ "enveloped content test streaming S/MIME format, DES, ECDH, 2 recipients, key only used",
584 [ "{cmd1}", @defaultprov, "-encrypt", "-in", $smcont,
585 "-stream", "-out", "{output}.cms",
586 catfile($smdir, "smec1.pem"),
587 catfile($smdir, "smec3.pem") ],
588 [ "{cmd2}", @defaultprov, "-decrypt", "-inkey", catfile($smdir, "smec3.pem"),
589 "-in", "{output}.cms", "-out", "{output}.txt" ],
593 [ "enveloped content test streaming S/MIME format, ECDH, DES, key identifier",
594 [ "{cmd1}", @defaultprov, "-encrypt", "-keyid", "-in", $smcont,
595 "-stream", "-out", "{output}.cms",
596 "-recip", catfile($smdir, "smec1.pem") ],
597 [ "{cmd2}", @defaultprov, "-decrypt", "-recip", catfile($smdir, "smec1.pem"),
598 "-in", "{output}.cms", "-out", "{output}.txt" ],
602 [ "enveloped content test streaming S/MIME format, ECDH, AES-128-CBC, SHA256 KDF",
603 [ "{cmd1}", @prov, "-encrypt", "-in", $smcont,
604 "-stream", "-out", "{output}.cms",
605 "-recip", catfile($smdir, "smec1.pem"), "-aes128",
606 "-keyopt", "ecdh_kdf_md:sha256" ],
607 [ "{cmd2}", @prov, "-decrypt", "-recip", catfile($smdir, "smec1.pem"),
608 "-in", "{output}.cms", "-out", "{output}.txt" ],
612 [ "enveloped content test streaming S/MIME format, ECDH, AES-128-GCM cipher, SHA256 KDF",
613 [ "{cmd1}", @prov, "-encrypt", "-in", $smcont,
614 "-stream", "-out", "{output}.cms",
615 "-recip", catfile($smdir, "smec1.pem"), "-aes-128-gcm", "-keyopt", "ecdh_kdf_md:sha256" ],
616 [ "{cmd2}", "-decrypt", "-recip", catfile($smdir, "smec1.pem"),
617 "-in", "{output}.cms", "-out", "{output}.txt" ],
621 [ "enveloped content test streaming S/MIME format, ECDH, K-283, cofactor DH",
622 [ "{cmd1}", @prov, "-encrypt", "-in", $smcont,
623 "-stream", "-out", "{output}.cms",
624 "-recip", catfile($smdir, "smec2.pem"), "-aes128",
625 "-keyopt", "ecdh_kdf_md:sha256", "-keyopt", "ecdh_cofactor_mode:1" ],
626 [ "{cmd2}", @prov, "-decrypt", "-recip", catfile($smdir, "smec2.pem"),
627 "-in", "{output}.cms", "-out", "{output}.txt" ],
631 [ "enveloped content test streaming S/MIME format, X9.42 DH",
632 [ "{cmd1}", @prov, "-encrypt", "-in", $smcont,
633 "-stream", "-out", "{output}.cms",
634 "-recip", catfile($smdir, "smdh.pem"), "-aes128" ],
635 [ "{cmd2}", @prov, "-decrypt", "-recip", catfile($smdir, "smdh.pem"),
636 "-in", "{output}.cms", "-out", "{output}.txt" ],
641 my @smime_cms_param_tests_autodigestmax = (
642 [ "signed content test streaming PEM format, RSA keys, PSS signature, saltlen=auto-digestmax, digestsize < maximum salt length",
643 [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
644 "-signer", $smrsa1, "-md", "sha256",
645 "-keyopt", "rsa_padding_mode:pss", "-keyopt", "rsa_pss_saltlen:auto-digestmax",
646 "-out", "{output}.cms" ],
647 # digest is SHA-256, which produces 32, bytes of output
648 sub { my %opts = @_; rsapssSaltlen("$opts{output}.cms") == 32; },
649 [ "{cmd2}", @defaultprov, "-verify", "-in", "{output}.cms", "-inform", "PEM",
650 "-CAfile", $smroot, "-out", "{output}.txt" ],
654 [ "signed content test streaming PEM format, RSA keys, PSS signature, saltlen=auto-digestmax, digestsize > maximum salt length",
655 [ "{cmd1}", @defaultprov, "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
656 "-signer", $smrsa1024, "-md", "sha512",
657 "-keyopt", "rsa_padding_mode:pss", "-keyopt", "rsa_pss_saltlen:auto-digestmax",
658 "-out", "{output}.cms" ],
659 # digest is SHA-512, which produces 64, bytes of output, but an RSA-PSS
660 # signature with a 1024 bit RSA key can only accommodate 62
661 sub { my %opts = @_; rsapssSaltlen("$opts{output}.cms") == 62; },
662 [ "{cmd2}", @defaultprov, "-verify", "-in", "{output}.cms", "-inform", "PEM",
663 "-CAfile", $smroot, "-out", "{output}.txt" ],
669 my @contenttype_cms_test = (
670 [ "signed content test - check that content type is added to additional signerinfo, RSA keys",
671 [ "{cmd1}", @prov, "-sign", "-binary", "-nodetach", "-stream", "-in", $smcont,
672 "-outform", "DER", "-signer", $smrsa1, "-md", "SHA256",
673 "-out", "{output}.cms" ],
674 [ "{cmd1}", @prov, "-resign", "-binary", "-nodetach", "-in", "{output}.cms",
675 "-inform", "DER", "-outform", "DER",
676 "-signer", catfile($smdir, "smrsa2.pem"), "-md", "SHA256",
677 "-out", "{output}2.cms" ],
678 sub { my %opts = @_; contentType_matches("$opts{output}2.cms") == 2; },
679 [ "{cmd2}", @prov, "-verify", "-in", "{output}2.cms", "-inform", "DER",
680 "-CAfile", $smroot, "-out", "{output}.txt" ]
684 my @incorrect_attribute_cms_test = (
685 "bad_signtime_attr.cms",
688 "ct_multiple_attr.cms"
691 # Runs a standard loop on the input array
696 foreach (@{$opts{tests}}) {
698 $opts{output} = "$opts{prefix}-$cnt1";
700 my $skip_reason = check_availability($$_[0]);
701 skip $skip_reason, 1 if $skip_reason;
703 1 while unlink "$opts{output}.txt";
705 foreach (@$_[1..$#$_]) {
706 if (ref $_ eq 'CODE') {
711 while ($x =~ /\{([^\}]+)\}/) {
712 $x = $`.$opts{$1}.$' if exists $opts{$1};
717 diag "CMD: openssl ", join(" ", @cmd);
718 $ok &&= run(app(["openssl", @cmd]));
719 $opts{input} = $opts{output};
731 diag "Comparing $smcont with $opts{output}.txt";
732 return compare_text($smcont, "$opts{output}.txt") == 0;
738 diag "Checking for zero-length file";
739 return (-e "$opts{output}.txt" && -z "$opts{output}.txt");
742 subtest "CMS => PKCS#7 compatibility tests\n" => sub {
743 plan tests => scalar @smime_pkcs7_tests;
745 runner_loop(prefix => 'cms2pkcs7', cmd1 => 'cms', cmd2 => 'smime',
746 tests => [ @smime_pkcs7_tests ]);
748 subtest "CMS <= PKCS#7 compatibility tests\n" => sub {
749 plan tests => scalar @smime_pkcs7_tests;
751 runner_loop(prefix => 'pkcs72cms', cmd1 => 'smime', cmd2 => 'cms',
752 tests => [ @smime_pkcs7_tests ]);
755 subtest "CMS <=> CMS consistency tests\n" => sub {
756 plan tests => (scalar @smime_pkcs7_tests) + (scalar @smime_cms_tests);
758 runner_loop(prefix => 'cms2cms-1', cmd1 => 'cms', cmd2 => 'cms',
759 tests => [ @smime_pkcs7_tests ]);
760 runner_loop(prefix => 'cms2cms-2', cmd1 => 'cms', cmd2 => 'cms',
761 tests => [ @smime_cms_tests ]);
764 subtest "CMS <=> CMS consistency tests, modified key parameters\n" => sub {
766 (scalar @smime_cms_param_tests) + (scalar @smime_cms_comp_tests) +
767 (scalar @smime_cms_param_tests_autodigestmax) + 1;
769 ok(run(app(["openssl", "cms", @prov,
770 "-sign", "-in", $smcont,
774 "-keyopt", "rsa_padding_mode:pss",
775 "-keyopt", "rsa_pss_saltlen:auto-digestmax",
776 "-out", "digestmaxtest.cms"])));
777 # Providers that do not support rsa_pss_saltlen:auto-digestmax will parse
779 my $no_autodigestmax = rsapssSaltlen("digestmaxtest.cms") == 0;
780 1 while unlink "digestmaxtest.cms";
782 runner_loop(prefix => 'cms2cms-mod', cmd1 => 'cms', cmd2 => 'cms',
783 tests => [ @smime_cms_param_tests ]);
785 skip("Zlib not supported: compression tests skipped",
786 scalar @smime_cms_comp_tests)
789 runner_loop(prefix => 'cms2cms-comp', cmd1 => 'cms', cmd2 => 'cms',
790 tests => [ @smime_cms_comp_tests ]);
794 skip("rsa_pss_saltlen:auto-digestmax not supported",
795 scalar @smime_cms_param_tests_autodigestmax)
796 if $no_autodigestmax;
798 runner_loop(prefix => 'cms2cms-comp', 'cmd1' => 'cms', cmd2 => 'cms',
799 tests => [ @smime_cms_param_tests_autodigestmax ]);
803 # Returns the number of matches of a Content Type Attribute in a binary file.
804 sub contentType_matches {
805 # Read in a binary file
807 open (HEX_IN, "$in") or die("open failed for $in : $!");
812 # Find ASN1 data for a Content Type Attribute (with a OID of PKCS7 data)
813 my @c = $str =~ /\x30\x18\x06\x09\x2A\x86\x48\x86\xF7\x0D\x01\x09\x03\x31\x0B\x06\x09\x2A\x86\x48\x86\xF7\x0D\x01\x07\x01/gs;
823 my @asn1parse = run(app(["openssl", "asn1parse", "-in", $in, "-dump"]),
826 return -1 if $exit != 0;
828 my $pssparam_offset = -1;
829 while ($_ = shift @asn1parse) {
831 next unless /:rsassaPss/;
832 # This line contains :rsassaPss, the next line contains a raw dump of the
833 # RSA_PSS_PARAMS sequence; obtain its offset
834 $_ = shift @asn1parse;
836 $pssparam_offset = int($1);
840 if ($pssparam_offset == -1) {
841 note "Failed to determine RSA_PSS_PARAM offset in CMS. " +
842 "Was the file correctly signed with RSASSA-PSS?";
846 my @pssparam = run(app(["openssl", "asn1parse", "-in", $in,
847 "-strparse", $pssparam_offset]),
850 return -1 if $exit != 0;
853 # Can't use asn1parse -item RSA_PSS_PARAMS here, because that's deprecated.
854 # This assumes the salt length is the last field, which may possibly be
855 # incorrect if there is a non-standard trailer field, but there almost never
857 if ($pssparam[-1] =~ /prim:\s+INTEGER\s+:([A-Fa-f0-9]+)/) {
861 if ($saltlen == -1) {
862 note "Failed to determine salt length from RSA_PSS_PARAM struct. " +
863 "Was the file correctly signed with RSASSA-PSS?";
870 subtest "CMS Check the content type attribute is added for additional signers\n" => sub {
871 plan tests => (scalar @contenttype_cms_test);
873 runner_loop(prefix => 'cms2cms-added', cmd1 => 'cms', cmd2 => 'cms',
874 tests => [ @contenttype_cms_test ]);
877 subtest "CMS Check that bad attributes fail when verifying signers\n" => sub {
879 (scalar @incorrect_attribute_cms_test);
882 foreach my $name (@incorrect_attribute_cms_test) {
883 my $out = "incorrect-$cnt.txt";
885 ok(!run(app(["openssl", "cms", @prov, "-verify", "-in",
886 catfile($datadir, $name), "-inform", "DER", "-CAfile",
887 $smroot, "-out", $out ])),
892 subtest "CMS Check that bad encryption algorithm fails\n" => sub {
896 skip "DES or Legacy isn't supported in this build", 1
897 if disabled("des") || disabled("legacy");
899 my $out = "smtst.txt";
901 ok(!run(app(["openssl", "cms", @legacyprov, "-encrypt",
903 "-stream", "-recip", $smrsa1,
906 "Decrypt message from OpenSSL 1.1.1");
910 subtest "CMS Decrypt message encrypted with OpenSSL 1.1.1\n" => sub {
914 skip "EC or DES isn't supported in this build", 1
915 if disabled("ec") || disabled("des");
917 my $out = "smtst.txt";
919 ok(run(app(["openssl", "cms", @defaultprov, "-decrypt",
920 "-inkey", catfile($smdir, "smec3.pem"),
921 "-in", catfile($datadir, "ciphertext_from_1_1_1.cms"),
923 && compare_text($smcont, $out) == 0,
924 "Decrypt message from OpenSSL 1.1.1");
928 subtest "CAdES <=> CAdES consistency tests\n" => sub {
929 plan tests => (scalar @smime_cms_cades_tests);
931 runner_loop(prefix => 'cms-cades', cmd1 => 'cms', cmd2 => 'cms',
932 tests => [ @smime_cms_cades_tests ]);
935 subtest "CAdES; cms incompatible arguments tests\n" => sub {
936 plan tests => (scalar @smime_cms_cades_invalid_option_tests);
938 foreach (@smime_cms_cades_invalid_option_tests) {
939 ok(!run(app(["openssl", "cms", @{$$_[0]} ] )));
943 subtest "CAdES ko tests\n" => sub {
944 plan tests => 2 * scalar @smime_cms_cades_ko_tests;
946 foreach (@smime_cms_cades_ko_tests) {
948 my $skip_reason = check_availability($$_[0]);
949 skip $skip_reason, 1 if $skip_reason;
950 1 while unlink "cades-ko.txt";
952 ok(run(app(["openssl", "cms", @{$$_[1]}])), $$_[0]);
953 ok(!run(app(["openssl", "cms", @{$$_[3]}])), $$_[2]);
958 subtest "CMS binary input tests\n" => sub {
959 my $input = srctop_file("test", "smcont.bin");
960 my $signed = "smcont.signed";
961 my $verified = "smcont.verified";
965 ok(run(app(["openssl", "cms", "-sign", "-md", "sha256", "-signer", $smrsa1,
966 "-binary", "-in", $input, "-out", $signed])),
967 "sign binary input with -binary");
968 ok(run(app(["openssl", "cms", "-verify", "-CAfile", $smroot,
969 "-binary", "-in", $signed, "-out", $verified])),
970 "verify binary input with -binary");
971 is(compare($input, $verified), 0, "binary input retained with -binary");
973 ok(run(app(["openssl", "cms", "-sign", "-md", "sha256", "-signer", $smrsa1,
974 "-in", $input, "-out", $signed.".nobin"])),
975 "sign binary input without -binary");
976 ok(run(app(["openssl", "cms", "-verify", "-CAfile", $smroot,
977 "-in", $signed.".nobin", "-out", $verified.".nobin"])),
978 "verify binary input without -binary");
979 is(compare($input, $verified.".nobin"), 1, "binary input not retained without -binary");
980 ok(!run(app(["openssl", "cms", "-verify", "-CAfile", $smroot, "-crlfeol",
981 "-binary", "-in", $signed, "-out", $verified.".crlfeol"])),
982 "verify binary input wrong crlfeol");
984 ok(run(app(["openssl", "cms", "-sign", "-md", "sha256", "-signer", $smrsa1,
986 "-binary", "-in", $input, "-out", $signed.".crlf"])),
987 "sign binary input with -binary -crlfeol");
988 ok(run(app(["openssl", "cms", "-verify", "-CAfile", $smroot, "-crlfeol",
989 "-binary", "-in", $signed.".crlf", "-out", $verified.".crlf"])),
990 "verify binary input with -binary -crlfeol");
991 is(compare($input, $verified.".crlf"), 0,
992 "binary input retained with -binary -crlfeol");
993 ok(!run(app(["openssl", "cms", "-verify", "-CAfile", $smroot,
994 "-binary", "-in", $signed.".crlf", "-out", $verified.".crlf2"])),
995 "verify binary input with -binary missing -crlfeol");
998 subtest "CMS signed digest, DER format" => sub {
1001 # Pre-computed SHA256 digest of $smcont in hexadecimal form
1002 my $digest = "ff236ef61b396355f75a4cc6e1c306d4c309084ae271a9e2ad6888f10a101b32";
1004 my $sig_file = "signature.der";
1005 ok(run(app(["openssl", "cms", @prov, "-sign", "-digest", $digest,
1007 "-certfile", catfile($smdir, "smroot.pem"),
1008 "-signer", catfile($smdir, "smrsa1.pem"),
1009 "-out", $sig_file])),
1010 "CMS sign pre-computed digest, DER format");
1012 ok(run(app(["openssl", "cms", @prov, "-verify", "-in", $sig_file,
1014 "-CAfile", catfile($smdir, "smroot.pem"),
1015 "-content", $smcont])),
1016 "Verify CMS signed digest, DER format");
1019 subtest "CMS signed digest, S/MIME format" => sub {
1022 # Pre-computed SHA256 digest of $smcont in hexadecimal form
1023 my $digest = "ff236ef61b396355f75a4cc6e1c306d4c309084ae271a9e2ad6888f10a101b32";
1025 my $sig_file = "signature.smime";
1026 ok(run(app(["openssl", "cms", @prov, "-sign", "-digest", $digest,
1027 "-outform", "SMIME",
1028 "-certfile", catfile($smdir, "smroot.pem"),
1029 "-signer", catfile($smdir, "smrsa1.pem"),
1030 "-out", $sig_file])),
1031 "CMS sign pre-computed digest, S/MIME format");
1033 ok(run(app(["openssl", "cms", @prov, "-verify", "-in", $sig_file,
1035 "-CAfile", catfile($smdir, "smroot.pem"),
1036 "-content", $smcont])),
1037 "Verify CMS signed digest, S/MIME format");
1040 subtest "CMS code signing test" => sub {
1042 my $sig_file = "signature.p7s";
1043 ok(run(app(["openssl", "cms", @prov, "-sign", "-in", $smcont,
1044 "-certfile", catfile($smdir, "smroot.pem"),
1045 "-signer", catfile($smdir, "smrsa1.pem"),
1046 "-out", $sig_file])),
1047 "accept perform CMS signature with smime certificate");
1049 ok(run(app(["openssl", "cms", @prov, "-verify", "-in", $sig_file,
1050 "-CAfile", catfile($smdir, "smroot.pem"),
1051 "-content", $smcont])),
1052 "accept verify CMS signature with smime certificate");
1054 ok(!run(app(["openssl", "cms", @prov, "-verify", "-in", $sig_file,
1055 "-CAfile", catfile($smdir, "smroot.pem"),
1056 "-purpose", "codesign",
1057 "-content", $smcont])),
1058 "fail verify CMS signature with smime certificate for purpose code signing");
1060 ok(!run(app(["openssl", "cms", @prov, "-verify", "-in", $sig_file,
1061 "-CAfile", catfile($smdir, "smroot.pem"),
1062 "-purpose", "football",
1063 "-content", $smcont])),
1064 "fail verify CMS signature with invalid purpose argument");
1066 ok(run(app(["openssl", "cms", @prov, "-sign", "-in", $smcont,
1067 "-certfile", catfile($smdir, "smroot.pem"),
1068 "-signer", catfile($smdir, "csrsa1.pem"),
1069 "-out", $sig_file])),
1070 "accept perform CMS signature with code signing certificate");
1072 ok(run(app(["openssl", "cms", @prov, "-verify", "-in", $sig_file,
1073 "-CAfile", catfile($smdir, "smroot.pem"),
1074 "-purpose", "codesign",
1075 "-content", $smcont])),
1076 "accept verify CMS signature with code signing certificate for purpose code signing");
1078 ok(!run(app(["openssl", "cms", @prov, "-verify", "-in", $sig_file,
1079 "-CAfile", catfile($smdir, "smroot.pem"),
1080 "-content", $smcont])),
1081 "fail verify CMS signature with code signing certificate for purpose smime_sign");
1084 # Test case for missing MD algorithm (must not segfault)
1086 with({ exit_checker => sub { return shift == 4; } },
1088 ok(run(app(['openssl', 'smime', '-verify', '-noverify',
1090 '-in', data_file("pkcs7-md4.pem"),
1092 "Check failure of EVP_DigestInit in PKCS7 signed is handled");
1094 ok(run(app(['openssl', 'smime', '-decrypt',
1096 '-in', data_file("pkcs7-md4-encrypted.pem"),
1097 '-recip', srctop_file("test", "certs", "ee-cert.pem"),
1098 '-inkey', srctop_file("test", "certs", "ee-key.pem")
1100 "Check failure of EVP_DigestInit in PKCS7 signedAndEnveloped is handled");
1103 sub check_availability {
1106 return "$tnam: skipped, EC disabled\n"
1107 if ($no_ec && $tnam =~ /ECDH/);
1108 return "$tnam: skipped, ECDH disabled\n"
1109 if ($no_ec && $tnam =~ /ECDH/);
1110 return "$tnam: skipped, EC2M disabled\n"
1111 if ($no_ec2m && $tnam =~ /K-283/);
1112 return "$tnam: skipped, DH disabled\n"
1113 if ($no_dh && $tnam =~ /X9\.42/);
1114 return "$tnam: skipped, RC2 disabled\n"
1115 if ($no_rc2 && $tnam =~ /RC2/);
1116 return "$tnam: skipped, DES disabled\n"
1117 if ($no_des && $tnam =~ /DES/);
1118 return "$tnam: skipped, DSA disabled\n"
1119 if ($no_dsa && $tnam =~ / DSA/);
1124 # Test case for the locking problem reported in #19643.
1125 # This will fail if the fix is in and deadlock on Windows (and possibly
1126 # other platforms) if not.
1127 ok(!run(app(['openssl', 'cms', '-verify',
1128 '-CAfile', srctop_file("test/certs", "pkitsta.pem"),
1129 '-policy', 'anyPolicy',
1130 '-in', srctop_file("test/smime-eml",
1131 "SignedInvalidMappingFromanyPolicyTest7.eml")
1135 # Check that we get the expected failure return code
1136 with({ exit_checker => sub { return shift == 6; } },
1138 ok(run(app(['openssl', 'cms', '-encrypt',
1139 '-in', srctop_file("test", "smcont.txt"),
1140 '-aes128', '-stream', '-recip',
1141 srctop_file("test/smime-certs", "badrsa.pem"),
1143 "Check failure during BIO setup with -stream is handled correctly");
1146 # Test case for return value mis-check reported in #21986
1147 with({ exit_checker => sub { return shift == 3; } },
1150 skip "DSA is not supported in this build", 1 if $no_dsa;
1152 ok(run(app(['openssl', 'cms', '-sign',
1153 '-in', srctop_file("test", "smcont.txt"),
1154 '-signer', srctop_file("test/smime-certs", "smdsa1.pem"),
1155 '-md', 'SHAKE256'])),
1160 # Test for problem reported in #22225
1161 with({ exit_checker => sub { return shift == 3; } },
1163 ok(run(app(['openssl', 'cms', '-encrypt',
1164 '-in', srctop_file("test", "smcont.txt"),
1165 '-aes-256-ctr', '-recip',
1166 catfile($smdir, "smec1.pem"),
1168 "Check for failure when cipher does not have an assigned OID (issue#22225)");
1171 # Test encrypt to three recipients, and decrypt using key-only;
1172 # i.e. do not follow the recommended practice of providing the
1173 # recipient cert in the decrypt op.
1175 # Use RSAES-OAEP for key-transport, not RSAES-PKCS-v1_5.
1177 # Because the cert is not provided during decrypt, all RSA ciphertexts
1178 # are decrypted in turn, and when/if there is a valid decryption, it
1179 # is assumed the correct content-key has been recovered.
1181 # That process may fail with RSAES-PKCS-v1_5 b/c there is a
1182 # non-negligible chance that decrypting a random input using
1183 # RSAES-PKCS-v1_5 can result in a valid plaintext (so two content-keys
1184 # could be recovered and the wrong one might be used).
1186 # See https://github.com/openssl/project/issues/380
1187 subtest "encrypt to three recipients with RSA-OAEP, key only decrypt" => sub {
1190 my $pt = srctop_file("test", "smcont.txt");
1191 my $ct = "smtst.cms";
1192 my $ptpt = "smtst.txt";
1194 ok(run(app(['openssl', 'cms',
1196 '-encrypt', '-aes128',
1200 '-recip', catfile($smdir, "smrsa1.pem"),
1201 '-keyopt', 'rsa_padding_mode:oaep',
1202 '-recip', catfile($smdir, "smrsa2.pem"),
1203 '-keyopt', 'rsa_padding_mode:oaep',
1204 '-recip', catfile($smdir, "smrsa3-cert.pem"),
1205 '-keyopt', 'rsa_padding_mode:oaep',
1207 "encrypt to three recipients with RSA-OAEP (avoid openssl/project issue#380)");
1208 ok(run(app(['openssl', 'cms',
1210 '-decrypt', '-aes128',
1213 '-inkey', catfile($smdir, "smrsa3-key.pem"),
1215 "decrypt with key only");
1216 is(compare($pt, $ptpt), 0, "compare original message with decrypted ciphertext");