80-test_cms.t 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. #! /usr/bin/env perl
  2. # Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. #
  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
  8. use strict;
  9. use warnings;
  10. use POSIX;
  11. use File::Spec::Functions qw/catfile/;
  12. use File::Compare qw/compare_text/;
  13. use OpenSSL::Test qw/:DEFAULT srctop_dir srctop_file/;
  14. use OpenSSL::Test::Utils;
  15. setup("test_cms");
  16. plan skip_all => "CMS is not supported by this OpenSSL build"
  17. if disabled("cms");
  18. my $smdir = srctop_dir("test", "smime-certs");
  19. my $smcont = srctop_file("test", "smcont.txt");
  20. my ($no_des, $no_dh, $no_dsa, $no_ec, $no_ec2m, $no_rc2, $no_zlib)
  21. = disabled qw/des dh dsa ec ec2m rc2 zlib/;
  22. plan tests => 4;
  23. my @smime_pkcs7_tests = (
  24. [ "signed content DER format, RSA key",
  25. [ "-sign", "-in", $smcont, "-outform", "DER", "-nodetach",
  26. "-certfile", catfile($smdir, "smroot.pem"),
  27. "-signer", catfile($smdir, "smrsa1.pem"), "-out", "test.cms" ],
  28. [ "-verify", "-in", "test.cms", "-inform", "DER",
  29. "-CAfile", catfile($smdir, "smroot.pem"), "-out", "smtst.txt" ]
  30. ],
  31. [ "signed detached content DER format, RSA key",
  32. [ "-sign", "-in", $smcont, "-outform", "DER",
  33. "-signer", catfile($smdir, "smrsa1.pem"), "-out", "test.cms" ],
  34. [ "-verify", "-in", "test.cms", "-inform", "DER",
  35. "-CAfile", catfile($smdir, "smroot.pem"), "-out", "smtst.txt",
  36. "-content", $smcont ]
  37. ],
  38. [ "signed content test streaming BER format, RSA",
  39. [ "-sign", "-in", $smcont, "-outform", "DER", "-nodetach",
  40. "-stream",
  41. "-signer", catfile($smdir, "smrsa1.pem"), "-out", "test.cms" ],
  42. [ "-verify", "-in", "test.cms", "-inform", "DER",
  43. "-CAfile", catfile($smdir, "smroot.pem"), "-out", "smtst.txt" ]
  44. ],
  45. [ "signed content DER format, DSA key",
  46. [ "-sign", "-in", $smcont, "-outform", "DER", "-nodetach",
  47. "-signer", catfile($smdir, "smdsa1.pem"), "-out", "test.cms" ],
  48. [ "-verify", "-in", "test.cms", "-inform", "DER",
  49. "-CAfile", catfile($smdir, "smroot.pem"), "-out", "smtst.txt" ]
  50. ],
  51. [ "signed detached content DER format, DSA key",
  52. [ "-sign", "-in", $smcont, "-outform", "DER",
  53. "-signer", catfile($smdir, "smdsa1.pem"), "-out", "test.cms" ],
  54. [ "-verify", "-in", "test.cms", "-inform", "DER",
  55. "-CAfile", catfile($smdir, "smroot.pem"), "-out", "smtst.txt",
  56. "-content", $smcont ]
  57. ],
  58. [ "signed detached content DER format, add RSA signer (with DSA existing)",
  59. [ "-resign", "-inform", "DER", "-in", "test.cms", "-outform", "DER",
  60. "-signer", catfile($smdir, "smrsa1.pem"), "-out", "test2.cms" ],
  61. [ "-verify", "-in", "test2.cms", "-inform", "DER",
  62. "-CAfile", catfile($smdir, "smroot.pem"), "-out", "smtst.txt",
  63. "-content", $smcont ]
  64. ],
  65. [ "signed content test streaming BER format, DSA key",
  66. [ "-sign", "-in", $smcont, "-outform", "DER", "-nodetach",
  67. "-stream",
  68. "-signer", catfile($smdir, "smdsa1.pem"), "-out", "test.cms" ],
  69. [ "-verify", "-in", "test.cms", "-inform", "DER",
  70. "-CAfile", catfile($smdir, "smroot.pem"), "-out", "smtst.txt" ]
  71. ],
  72. [ "signed content test streaming BER format, 2 DSA and 2 RSA keys",
  73. [ "-sign", "-in", $smcont, "-outform", "DER", "-nodetach",
  74. "-signer", catfile($smdir, "smrsa1.pem"),
  75. "-signer", catfile($smdir, "smrsa2.pem"),
  76. "-signer", catfile($smdir, "smdsa1.pem"),
  77. "-signer", catfile($smdir, "smdsa2.pem"),
  78. "-stream", "-out", "test.cms" ],
  79. [ "-verify", "-in", "test.cms", "-inform", "DER",
  80. "-CAfile", catfile($smdir, "smroot.pem"), "-out", "smtst.txt" ]
  81. ],
  82. [ "signed content test streaming BER format, 2 DSA and 2 RSA keys, no attributes",
  83. [ "-sign", "-in", $smcont, "-outform", "DER", "-noattr", "-nodetach",
  84. "-signer", catfile($smdir, "smrsa1.pem"),
  85. "-signer", catfile($smdir, "smrsa2.pem"),
  86. "-signer", catfile($smdir, "smdsa1.pem"),
  87. "-signer", catfile($smdir, "smdsa2.pem"),
  88. "-stream", "-out", "test.cms" ],
  89. [ "-verify", "-in", "test.cms", "-inform", "DER",
  90. "-CAfile", catfile($smdir, "smroot.pem"), "-out", "smtst.txt" ]
  91. ],
  92. [ "signed content S/MIME format, RSA key SHA1",
  93. [ "-sign", "-in", $smcont, "-md", "sha1",
  94. "-certfile", catfile($smdir, "smroot.pem"),
  95. "-signer", catfile($smdir, "smrsa1.pem"), "-out", "test.cms" ],
  96. [ "-verify", "-in", "test.cms",
  97. "-CAfile", catfile($smdir, "smroot.pem"), "-out", "smtst.txt" ]
  98. ],
  99. [ "signed content test streaming S/MIME format, 2 DSA and 2 RSA keys",
  100. [ "-sign", "-in", $smcont, "-nodetach",
  101. "-signer", catfile($smdir, "smrsa1.pem"),
  102. "-signer", catfile($smdir, "smrsa2.pem"),
  103. "-signer", catfile($smdir, "smdsa1.pem"),
  104. "-signer", catfile($smdir, "smdsa2.pem"),
  105. "-stream", "-out", "test.cms" ],
  106. [ "-verify", "-in", "test.cms",
  107. "-CAfile", catfile($smdir, "smroot.pem"), "-out", "smtst.txt" ]
  108. ],
  109. [ "signed content test streaming multipart S/MIME format, 2 DSA and 2 RSA keys",
  110. [ "-sign", "-in", $smcont,
  111. "-signer", catfile($smdir, "smrsa1.pem"),
  112. "-signer", catfile($smdir, "smrsa2.pem"),
  113. "-signer", catfile($smdir, "smdsa1.pem"),
  114. "-signer", catfile($smdir, "smdsa2.pem"),
  115. "-stream", "-out", "test.cms" ],
  116. [ "-verify", "-in", "test.cms",
  117. "-CAfile", catfile($smdir, "smroot.pem"), "-out", "smtst.txt" ]
  118. ],
  119. [ "enveloped content test streaming S/MIME format, DES, 3 recipients",
  120. [ "-encrypt", "-in", $smcont,
  121. "-stream", "-out", "test.cms",
  122. catfile($smdir, "smrsa1.pem"),
  123. catfile($smdir, "smrsa2.pem"),
  124. catfile($smdir, "smrsa3.pem") ],
  125. [ "-decrypt", "-recip", catfile($smdir, "smrsa1.pem"),
  126. "-in", "test.cms", "-out", "smtst.txt" ]
  127. ],
  128. [ "enveloped content test streaming S/MIME format, DES, 3 recipients, 3rd used",
  129. [ "-encrypt", "-in", $smcont,
  130. "-stream", "-out", "test.cms",
  131. catfile($smdir, "smrsa1.pem"),
  132. catfile($smdir, "smrsa2.pem"),
  133. catfile($smdir, "smrsa3.pem") ],
  134. [ "-decrypt", "-recip", catfile($smdir, "smrsa3.pem"),
  135. "-in", "test.cms", "-out", "smtst.txt" ]
  136. ],
  137. [ "enveloped content test streaming S/MIME format, DES, 3 recipients, key only used",
  138. [ "-encrypt", "-in", $smcont,
  139. "-stream", "-out", "test.cms",
  140. catfile($smdir, "smrsa1.pem"),
  141. catfile($smdir, "smrsa2.pem"),
  142. catfile($smdir, "smrsa3.pem") ],
  143. [ "-decrypt", "-inkey", catfile($smdir, "smrsa3.pem"),
  144. "-in", "test.cms", "-out", "smtst.txt" ]
  145. ],
  146. [ "enveloped content test streaming S/MIME format, AES-256 cipher, 3 recipients",
  147. [ "-encrypt", "-in", $smcont,
  148. "-aes256", "-stream", "-out", "test.cms",
  149. catfile($smdir, "smrsa1.pem"),
  150. catfile($smdir, "smrsa2.pem"),
  151. catfile($smdir, "smrsa3.pem") ],
  152. [ "-decrypt", "-recip", catfile($smdir, "smrsa1.pem"),
  153. "-in", "test.cms", "-out", "smtst.txt" ]
  154. ],
  155. );
  156. my @smime_cms_tests = (
  157. [ "signed content test streaming BER format, 2 DSA and 2 RSA keys, keyid",
  158. [ "-sign", "-in", $smcont, "-outform", "DER", "-nodetach", "-keyid",
  159. "-signer", catfile($smdir, "smrsa1.pem"),
  160. "-signer", catfile($smdir, "smrsa2.pem"),
  161. "-signer", catfile($smdir, "smdsa1.pem"),
  162. "-signer", catfile($smdir, "smdsa2.pem"),
  163. "-stream", "-out", "test.cms" ],
  164. [ "-verify", "-in", "test.cms", "-inform", "DER",
  165. "-CAfile", catfile($smdir, "smroot.pem"), "-out", "smtst.txt" ]
  166. ],
  167. [ "signed content test streaming PEM format, 2 DSA and 2 RSA keys",
  168. [ "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
  169. "-signer", catfile($smdir, "smrsa1.pem"),
  170. "-signer", catfile($smdir, "smrsa2.pem"),
  171. "-signer", catfile($smdir, "smdsa1.pem"),
  172. "-signer", catfile($smdir, "smdsa2.pem"),
  173. "-stream", "-out", "test.cms" ],
  174. [ "-verify", "-in", "test.cms", "-inform", "PEM",
  175. "-CAfile", catfile($smdir, "smroot.pem"), "-out", "smtst.txt" ]
  176. ],
  177. [ "signed content MIME format, RSA key, signed receipt request",
  178. [ "-sign", "-in", $smcont, "-signer", catfile($smdir, "smrsa1.pem"), "-nodetach",
  179. "-receipt_request_to", "test\@openssl.org", "-receipt_request_all",
  180. "-out", "test.cms" ],
  181. [ "-verify", "-in", "test.cms",
  182. "-CAfile", catfile($smdir, "smroot.pem"), "-out", "smtst.txt" ]
  183. ],
  184. [ "signed receipt MIME format, RSA key",
  185. [ "-sign_receipt", "-in", "test.cms",
  186. "-signer", catfile($smdir, "smrsa2.pem"),
  187. "-out", "test2.cms" ],
  188. [ "-verify_receipt", "test2.cms", "-in", "test.cms",
  189. "-CAfile", catfile($smdir, "smroot.pem") ]
  190. ],
  191. [ "enveloped content test streaming S/MIME format, DES, 3 recipients, keyid",
  192. [ "-encrypt", "-in", $smcont,
  193. "-stream", "-out", "test.cms", "-keyid",
  194. catfile($smdir, "smrsa1.pem"),
  195. catfile($smdir, "smrsa2.pem"),
  196. catfile($smdir, "smrsa3.pem") ],
  197. [ "-decrypt", "-recip", catfile($smdir, "smrsa1.pem"),
  198. "-in", "test.cms", "-out", "smtst.txt" ]
  199. ],
  200. [ "enveloped content test streaming PEM format, KEK",
  201. [ "-encrypt", "-in", $smcont, "-outform", "PEM", "-aes128",
  202. "-stream", "-out", "test.cms",
  203. "-secretkey", "000102030405060708090A0B0C0D0E0F",
  204. "-secretkeyid", "C0FEE0" ],
  205. [ "-decrypt", "-in", "test.cms", "-out", "smtst.txt", "-inform", "PEM",
  206. "-secretkey", "000102030405060708090A0B0C0D0E0F",
  207. "-secretkeyid", "C0FEE0" ]
  208. ],
  209. [ "enveloped content test streaming PEM format, KEK, key only",
  210. [ "-encrypt", "-in", $smcont, "-outform", "PEM", "-aes128",
  211. "-stream", "-out", "test.cms",
  212. "-secretkey", "000102030405060708090A0B0C0D0E0F",
  213. "-secretkeyid", "C0FEE0" ],
  214. [ "-decrypt", "-in", "test.cms", "-out", "smtst.txt", "-inform", "PEM",
  215. "-secretkey", "000102030405060708090A0B0C0D0E0F" ]
  216. ],
  217. [ "data content test streaming PEM format",
  218. [ "-data_create", "-in", $smcont, "-outform", "PEM", "-nodetach",
  219. "-stream", "-out", "test.cms" ],
  220. [ "-data_out", "-in", "test.cms", "-inform", "PEM", "-out", "smtst.txt" ]
  221. ],
  222. [ "encrypted content test streaming PEM format, 128 bit RC2 key",
  223. [ "-EncryptedData_encrypt", "-in", $smcont, "-outform", "PEM",
  224. "-rc2", "-secretkey", "000102030405060708090A0B0C0D0E0F",
  225. "-stream", "-out", "test.cms" ],
  226. [ "-EncryptedData_decrypt", "-in", "test.cms", "-inform", "PEM",
  227. "-secretkey", "000102030405060708090A0B0C0D0E0F", "-out", "smtst.txt" ]
  228. ],
  229. [ "encrypted content test streaming PEM format, 40 bit RC2 key",
  230. [ "-EncryptedData_encrypt", "-in", $smcont, "-outform", "PEM",
  231. "-rc2", "-secretkey", "0001020304",
  232. "-stream", "-out", "test.cms" ],
  233. [ "-EncryptedData_decrypt", "-in", "test.cms", "-inform", "PEM",
  234. "-secretkey", "0001020304", "-out", "smtst.txt" ]
  235. ],
  236. [ "encrypted content test streaming PEM format, triple DES key",
  237. [ "-EncryptedData_encrypt", "-in", $smcont, "-outform", "PEM",
  238. "-des3", "-secretkey", "000102030405060708090A0B0C0D0E0F1011121314151617",
  239. "-stream", "-out", "test.cms" ],
  240. [ "-EncryptedData_decrypt", "-in", "test.cms", "-inform", "PEM",
  241. "-secretkey", "000102030405060708090A0B0C0D0E0F1011121314151617",
  242. "-out", "smtst.txt" ]
  243. ],
  244. [ "encrypted content test streaming PEM format, 128 bit AES key",
  245. [ "-EncryptedData_encrypt", "-in", $smcont, "-outform", "PEM",
  246. "-aes128", "-secretkey", "000102030405060708090A0B0C0D0E0F",
  247. "-stream", "-out", "test.cms" ],
  248. [ "-EncryptedData_decrypt", "-in", "test.cms", "-inform", "PEM",
  249. "-secretkey", "000102030405060708090A0B0C0D0E0F", "-out", "smtst.txt" ]
  250. ],
  251. );
  252. my @smime_cms_comp_tests = (
  253. [ "compressed content test streaming PEM format",
  254. [ "-compress", "-in", $smcont, "-outform", "PEM", "-nodetach",
  255. "-stream", "-out", "test.cms" ],
  256. [ "-uncompress", "-in", "test.cms", "-inform", "PEM", "-out", "smtst.txt" ]
  257. ]
  258. );
  259. my @smime_cms_param_tests = (
  260. [ "signed content test streaming PEM format, RSA keys, PSS signature",
  261. [ "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
  262. "-signer", catfile($smdir, "smrsa1.pem"), "-keyopt", "rsa_padding_mode:pss",
  263. "-out", "test.cms" ],
  264. [ "-verify", "-in", "test.cms", "-inform", "PEM",
  265. "-CAfile", catfile($smdir, "smroot.pem"), "-out", "smtst.txt" ]
  266. ],
  267. [ "signed content test streaming PEM format, RSA keys, PSS signature, no attributes",
  268. [ "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach", "-noattr",
  269. "-signer", catfile($smdir, "smrsa1.pem"), "-keyopt", "rsa_padding_mode:pss",
  270. "-out", "test.cms" ],
  271. [ "-verify", "-in", "test.cms", "-inform", "PEM",
  272. "-CAfile", catfile($smdir, "smroot.pem"), "-out", "smtst.txt" ]
  273. ],
  274. [ "signed content test streaming PEM format, RSA keys, PSS signature, SHA384 MGF1",
  275. [ "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
  276. "-signer", catfile($smdir, "smrsa1.pem"), "-keyopt", "rsa_padding_mode:pss",
  277. "-keyopt", "rsa_mgf1_md:sha384", "-out", "test.cms" ],
  278. [ "-verify", "-in", "test.cms", "-inform", "PEM",
  279. "-CAfile", catfile($smdir, "smroot.pem"), "-out", "smtst.txt" ]
  280. ],
  281. [ "enveloped content test streaming S/MIME format, DES, OAEP default parameters",
  282. [ "-encrypt", "-in", $smcont,
  283. "-stream", "-out", "test.cms",
  284. "-recip", catfile($smdir, "smrsa1.pem"), "-keyopt", "rsa_padding_mode:oaep" ],
  285. [ "-decrypt", "-recip", catfile($smdir, "smrsa1.pem"),
  286. "-in", "test.cms", "-out", "smtst.txt" ]
  287. ],
  288. [ "enveloped content test streaming S/MIME format, DES, OAEP SHA256",
  289. [ "-encrypt", "-in", $smcont,
  290. "-stream", "-out", "test.cms",
  291. "-recip", catfile($smdir, "smrsa1.pem"), "-keyopt", "rsa_padding_mode:oaep",
  292. "-keyopt", "rsa_oaep_md:sha256" ],
  293. [ "-decrypt", "-recip", catfile($smdir, "smrsa1.pem"),
  294. "-in", "test.cms", "-out", "smtst.txt" ]
  295. ],
  296. [ "enveloped content test streaming S/MIME format, DES, ECDH",
  297. [ "-encrypt", "-in", $smcont,
  298. "-stream", "-out", "test.cms",
  299. "-recip", catfile($smdir, "smec1.pem") ],
  300. [ "-decrypt", "-recip", catfile($smdir, "smec1.pem"),
  301. "-in", "test.cms", "-out", "smtst.txt" ]
  302. ],
  303. [ "enveloped content test streaming S/MIME format, DES, ECDH, 2 recipients, key only used",
  304. [ "-encrypt", "-in", $smcont,
  305. "-stream", "-out", "test.cms",
  306. catfile($smdir, "smec1.pem"),
  307. catfile($smdir, "smec3.pem") ],
  308. [ "-decrypt", "-inkey", catfile($smdir, "smec3.pem"),
  309. "-in", "test.cms", "-out", "smtst.txt" ]
  310. ],
  311. [ "enveloped content test streaming S/MIME format, ECDH, DES, key identifier",
  312. [ "-encrypt", "-keyid", "-in", $smcont,
  313. "-stream", "-out", "test.cms",
  314. "-recip", catfile($smdir, "smec1.pem") ],
  315. [ "-decrypt", "-recip", catfile($smdir, "smec1.pem"),
  316. "-in", "test.cms", "-out", "smtst.txt" ]
  317. ],
  318. [ "enveloped content test streaming S/MIME format, ECDH, AES128, SHA256 KDF",
  319. [ "-encrypt", "-in", $smcont,
  320. "-stream", "-out", "test.cms",
  321. "-recip", catfile($smdir, "smec1.pem"), "-aes128", "-keyopt", "ecdh_kdf_md:sha256" ],
  322. [ "-decrypt", "-recip", catfile($smdir, "smec1.pem"),
  323. "-in", "test.cms", "-out", "smtst.txt" ]
  324. ],
  325. [ "enveloped content test streaming S/MIME format, ECDH, K-283, cofactor DH",
  326. [ "-encrypt", "-in", $smcont,
  327. "-stream", "-out", "test.cms",
  328. "-recip", catfile($smdir, "smec2.pem"), "-aes128",
  329. "-keyopt", "ecdh_kdf_md:sha256", "-keyopt", "ecdh_cofactor_mode:1" ],
  330. [ "-decrypt", "-recip", catfile($smdir, "smec2.pem"),
  331. "-in", "test.cms", "-out", "smtst.txt" ]
  332. ],
  333. [ "enveloped content test streaming S/MIME format, X9.42 DH",
  334. [ "-encrypt", "-in", $smcont,
  335. "-stream", "-out", "test.cms",
  336. "-recip", catfile($smdir, "smdh.pem"), "-aes128" ],
  337. [ "-decrypt", "-recip", catfile($smdir, "smdh.pem"),
  338. "-in", "test.cms", "-out", "smtst.txt" ]
  339. ]
  340. );
  341. subtest "CMS => PKCS#7 compatibility tests\n" => sub {
  342. plan tests => scalar @smime_pkcs7_tests;
  343. foreach (@smime_pkcs7_tests) {
  344. SKIP: {
  345. my $skip_reason = check_availability($$_[0]);
  346. skip $skip_reason, 1 if $skip_reason;
  347. ok(run(app(["openssl", "cms", @{$$_[1]}]))
  348. && run(app(["openssl", "smime", @{$$_[2]}]))
  349. && compare_text($smcont, "smtst.txt") == 0,
  350. $$_[0]);
  351. }
  352. }
  353. };
  354. subtest "CMS <= PKCS#7 compatibility tests\n" => sub {
  355. plan tests => scalar @smime_pkcs7_tests;
  356. foreach (@smime_pkcs7_tests) {
  357. SKIP: {
  358. my $skip_reason = check_availability($$_[0]);
  359. skip $skip_reason, 1 if $skip_reason;
  360. ok(run(app(["openssl", "smime", @{$$_[1]}]))
  361. && run(app(["openssl", "cms", @{$$_[2]}]))
  362. && compare_text($smcont, "smtst.txt") == 0,
  363. $$_[0]);
  364. }
  365. }
  366. };
  367. subtest "CMS <=> CMS consistency tests\n" => sub {
  368. plan tests => (scalar @smime_pkcs7_tests) + (scalar @smime_cms_tests);
  369. foreach (@smime_pkcs7_tests) {
  370. SKIP: {
  371. my $skip_reason = check_availability($$_[0]);
  372. skip $skip_reason, 1 if $skip_reason;
  373. ok(run(app(["openssl", "cms", @{$$_[1]}]))
  374. && run(app(["openssl", "cms", @{$$_[2]}]))
  375. && compare_text($smcont, "smtst.txt") == 0,
  376. $$_[0]);
  377. }
  378. }
  379. foreach (@smime_cms_tests) {
  380. SKIP: {
  381. my $skip_reason = check_availability($$_[0]);
  382. skip $skip_reason, 1 if $skip_reason;
  383. ok(run(app(["openssl", "cms", @{$$_[1]}]))
  384. && run(app(["openssl", "cms", @{$$_[2]}]))
  385. && compare_text($smcont, "smtst.txt") == 0,
  386. $$_[0]);
  387. }
  388. }
  389. };
  390. subtest "CMS <=> CMS consistency tests, modified key parameters\n" => sub {
  391. plan tests =>
  392. (scalar @smime_cms_param_tests) + (scalar @smime_cms_comp_tests);
  393. foreach (@smime_cms_param_tests) {
  394. SKIP: {
  395. my $skip_reason = check_availability($$_[0]);
  396. skip $skip_reason, 1 if $skip_reason;
  397. ok(run(app(["openssl", "cms", @{$$_[1]}]))
  398. && run(app(["openssl", "cms", @{$$_[2]}]))
  399. && compare_text($smcont, "smtst.txt") == 0,
  400. $$_[0]);
  401. }
  402. }
  403. SKIP: {
  404. skip("Zlib not supported: compression tests skipped",
  405. scalar @smime_cms_comp_tests)
  406. if $no_zlib;
  407. foreach (@smime_cms_comp_tests) {
  408. SKIP: {
  409. my $skip_reason = check_availability($$_[0]);
  410. skip $skip_reason, 1 if $skip_reason;
  411. ok(run(app(["openssl", "cms", @{$$_[1]}]))
  412. && run(app(["openssl", "cms", @{$$_[2]}]))
  413. && compare_text($smcont, "smtst.txt") == 0,
  414. $$_[0]);
  415. }
  416. }
  417. }
  418. };
  419. unlink "test.cms";
  420. unlink "test2.cms";
  421. unlink "smtst.txt";
  422. sub check_availability {
  423. my $tnam = shift;
  424. return "$tnam: skipped, EC disabled\n"
  425. if ($no_ec && $tnam =~ /ECDH/);
  426. return "$tnam: skipped, ECDH disabled\n"
  427. if ($no_ec && $tnam =~ /ECDH/);
  428. return "$tnam: skipped, EC2M disabled\n"
  429. if ($no_ec2m && $tnam =~ /K-283/);
  430. return "$tnam: skipped, DH disabled\n"
  431. if ($no_dh && $tnam =~ /X9\.42/);
  432. return "$tnam: skipped, RC2 disabled\n"
  433. if ($no_rc2 && $tnam =~ /RC2/);
  434. return "$tnam: skipped, DES disabled\n"
  435. if ($no_des && $tnam =~ /DES/);
  436. return "$tnam: skipped, DSA disabled\n"
  437. if ($no_dsa && $tnam =~ / DSA/);
  438. return "";
  439. }