80-test_cms.t 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. #! /usr/bin/env perl
  2. # Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. #
  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
  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. [ "signed content DER format, RSA key, CAdES-BES compatible",
  192. [ "-sign", "-cades", "-in", $smcont, "-outform", "DER", "-nodetach",
  193. "-certfile", catfile($smdir, "smroot.pem"),
  194. "-signer", catfile($smdir, "smrsa1.pem"), "-out", "test.cms" ],
  195. [ "-verify", "-in", "test.cms", "-inform", "DER",
  196. "-CAfile", catfile($smdir, "smroot.pem"), "-out", "smtst.txt" ]
  197. ],
  198. [ "signed content DER format, RSA key, SHA256 md, CAdES-BES compatible",
  199. [ "-sign", "-cades", "-md", "sha256", "-in", $smcont, "-outform",
  200. "DER", "-nodetach", "-certfile", catfile($smdir, "smroot.pem"),
  201. "-signer", catfile($smdir, "smrsa1.pem"), "-out", "test.cms" ],
  202. [ "-verify", "-in", "test.cms", "-inform", "DER",
  203. "-CAfile", catfile($smdir, "smroot.pem"), "-out", "smtst.txt" ]
  204. ],
  205. [ "enveloped content test streaming S/MIME format, DES, 3 recipients, keyid",
  206. [ "-encrypt", "-in", $smcont,
  207. "-stream", "-out", "test.cms", "-keyid",
  208. catfile($smdir, "smrsa1.pem"),
  209. catfile($smdir, "smrsa2.pem"),
  210. catfile($smdir, "smrsa3.pem") ],
  211. [ "-decrypt", "-recip", catfile($smdir, "smrsa1.pem"),
  212. "-in", "test.cms", "-out", "smtst.txt" ]
  213. ],
  214. [ "enveloped content test streaming PEM format, KEK",
  215. [ "-encrypt", "-in", $smcont, "-outform", "PEM", "-aes128",
  216. "-stream", "-out", "test.cms",
  217. "-secretkey", "000102030405060708090A0B0C0D0E0F",
  218. "-secretkeyid", "C0FEE0" ],
  219. [ "-decrypt", "-in", "test.cms", "-out", "smtst.txt", "-inform", "PEM",
  220. "-secretkey", "000102030405060708090A0B0C0D0E0F",
  221. "-secretkeyid", "C0FEE0" ]
  222. ],
  223. [ "enveloped content test streaming PEM format, KEK, key only",
  224. [ "-encrypt", "-in", $smcont, "-outform", "PEM", "-aes128",
  225. "-stream", "-out", "test.cms",
  226. "-secretkey", "000102030405060708090A0B0C0D0E0F",
  227. "-secretkeyid", "C0FEE0" ],
  228. [ "-decrypt", "-in", "test.cms", "-out", "smtst.txt", "-inform", "PEM",
  229. "-secretkey", "000102030405060708090A0B0C0D0E0F" ]
  230. ],
  231. [ "data content test streaming PEM format",
  232. [ "-data_create", "-in", $smcont, "-outform", "PEM", "-nodetach",
  233. "-stream", "-out", "test.cms" ],
  234. [ "-data_out", "-in", "test.cms", "-inform", "PEM", "-out", "smtst.txt" ]
  235. ],
  236. [ "encrypted content test streaming PEM format, 128 bit RC2 key",
  237. [ "-EncryptedData_encrypt", "-in", $smcont, "-outform", "PEM",
  238. "-rc2", "-secretkey", "000102030405060708090A0B0C0D0E0F",
  239. "-stream", "-out", "test.cms" ],
  240. [ "-EncryptedData_decrypt", "-in", "test.cms", "-inform", "PEM",
  241. "-secretkey", "000102030405060708090A0B0C0D0E0F", "-out", "smtst.txt" ]
  242. ],
  243. [ "encrypted content test streaming PEM format, 40 bit RC2 key",
  244. [ "-EncryptedData_encrypt", "-in", $smcont, "-outform", "PEM",
  245. "-rc2", "-secretkey", "0001020304",
  246. "-stream", "-out", "test.cms" ],
  247. [ "-EncryptedData_decrypt", "-in", "test.cms", "-inform", "PEM",
  248. "-secretkey", "0001020304", "-out", "smtst.txt" ]
  249. ],
  250. [ "encrypted content test streaming PEM format, triple DES key",
  251. [ "-EncryptedData_encrypt", "-in", $smcont, "-outform", "PEM",
  252. "-des3", "-secretkey", "000102030405060708090A0B0C0D0E0F1011121314151617",
  253. "-stream", "-out", "test.cms" ],
  254. [ "-EncryptedData_decrypt", "-in", "test.cms", "-inform", "PEM",
  255. "-secretkey", "000102030405060708090A0B0C0D0E0F1011121314151617",
  256. "-out", "smtst.txt" ]
  257. ],
  258. [ "encrypted content test streaming PEM format, 128 bit AES key",
  259. [ "-EncryptedData_encrypt", "-in", $smcont, "-outform", "PEM",
  260. "-aes128", "-secretkey", "000102030405060708090A0B0C0D0E0F",
  261. "-stream", "-out", "test.cms" ],
  262. [ "-EncryptedData_decrypt", "-in", "test.cms", "-inform", "PEM",
  263. "-secretkey", "000102030405060708090A0B0C0D0E0F", "-out", "smtst.txt" ]
  264. ],
  265. );
  266. my @smime_cms_comp_tests = (
  267. [ "compressed content test streaming PEM format",
  268. [ "-compress", "-in", $smcont, "-outform", "PEM", "-nodetach",
  269. "-stream", "-out", "test.cms" ],
  270. [ "-uncompress", "-in", "test.cms", "-inform", "PEM", "-out", "smtst.txt" ]
  271. ]
  272. );
  273. my @smime_cms_param_tests = (
  274. [ "signed content test streaming PEM format, RSA keys, PSS signature",
  275. [ "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
  276. "-signer", catfile($smdir, "smrsa1.pem"), "-keyopt", "rsa_padding_mode:pss",
  277. "-out", "test.cms" ],
  278. [ "-verify", "-in", "test.cms", "-inform", "PEM",
  279. "-CAfile", catfile($smdir, "smroot.pem"), "-out", "smtst.txt" ]
  280. ],
  281. [ "signed content test streaming PEM format, RSA keys, PSS signature, no attributes",
  282. [ "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach", "-noattr",
  283. "-signer", catfile($smdir, "smrsa1.pem"), "-keyopt", "rsa_padding_mode:pss",
  284. "-out", "test.cms" ],
  285. [ "-verify", "-in", "test.cms", "-inform", "PEM",
  286. "-CAfile", catfile($smdir, "smroot.pem"), "-out", "smtst.txt" ]
  287. ],
  288. [ "signed content test streaming PEM format, RSA keys, PSS signature, SHA384 MGF1",
  289. [ "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
  290. "-signer", catfile($smdir, "smrsa1.pem"), "-keyopt", "rsa_padding_mode:pss",
  291. "-keyopt", "rsa_mgf1_md:sha384", "-out", "test.cms" ],
  292. [ "-verify", "-in", "test.cms", "-inform", "PEM",
  293. "-CAfile", catfile($smdir, "smroot.pem"), "-out", "smtst.txt" ]
  294. ],
  295. [ "enveloped content test streaming S/MIME format, DES, OAEP default parameters",
  296. [ "-encrypt", "-in", $smcont,
  297. "-stream", "-out", "test.cms",
  298. "-recip", catfile($smdir, "smrsa1.pem"), "-keyopt", "rsa_padding_mode:oaep" ],
  299. [ "-decrypt", "-recip", catfile($smdir, "smrsa1.pem"),
  300. "-in", "test.cms", "-out", "smtst.txt" ]
  301. ],
  302. [ "enveloped content test streaming S/MIME format, DES, OAEP SHA256",
  303. [ "-encrypt", "-in", $smcont,
  304. "-stream", "-out", "test.cms",
  305. "-recip", catfile($smdir, "smrsa1.pem"), "-keyopt", "rsa_padding_mode:oaep",
  306. "-keyopt", "rsa_oaep_md:sha256" ],
  307. [ "-decrypt", "-recip", catfile($smdir, "smrsa1.pem"),
  308. "-in", "test.cms", "-out", "smtst.txt" ]
  309. ],
  310. [ "enveloped content test streaming S/MIME format, DES, ECDH",
  311. [ "-encrypt", "-in", $smcont,
  312. "-stream", "-out", "test.cms",
  313. "-recip", catfile($smdir, "smec1.pem") ],
  314. [ "-decrypt", "-recip", catfile($smdir, "smec1.pem"),
  315. "-in", "test.cms", "-out", "smtst.txt" ]
  316. ],
  317. [ "enveloped content test streaming S/MIME format, DES, ECDH, 2 recipients, key only used",
  318. [ "-encrypt", "-in", $smcont,
  319. "-stream", "-out", "test.cms",
  320. catfile($smdir, "smec1.pem"),
  321. catfile($smdir, "smec3.pem") ],
  322. [ "-decrypt", "-inkey", catfile($smdir, "smec3.pem"),
  323. "-in", "test.cms", "-out", "smtst.txt" ]
  324. ],
  325. [ "enveloped content test streaming S/MIME format, ECDH, DES, key identifier",
  326. [ "-encrypt", "-keyid", "-in", $smcont,
  327. "-stream", "-out", "test.cms",
  328. "-recip", catfile($smdir, "smec1.pem") ],
  329. [ "-decrypt", "-recip", catfile($smdir, "smec1.pem"),
  330. "-in", "test.cms", "-out", "smtst.txt" ]
  331. ],
  332. [ "enveloped content test streaming S/MIME format, ECDH, AES128, SHA256 KDF",
  333. [ "-encrypt", "-in", $smcont,
  334. "-stream", "-out", "test.cms",
  335. "-recip", catfile($smdir, "smec1.pem"), "-aes128", "-keyopt", "ecdh_kdf_md:sha256" ],
  336. [ "-decrypt", "-recip", catfile($smdir, "smec1.pem"),
  337. "-in", "test.cms", "-out", "smtst.txt" ]
  338. ],
  339. [ "enveloped content test streaming S/MIME format, ECDH, K-283, cofactor DH",
  340. [ "-encrypt", "-in", $smcont,
  341. "-stream", "-out", "test.cms",
  342. "-recip", catfile($smdir, "smec2.pem"), "-aes128",
  343. "-keyopt", "ecdh_kdf_md:sha256", "-keyopt", "ecdh_cofactor_mode:1" ],
  344. [ "-decrypt", "-recip", catfile($smdir, "smec2.pem"),
  345. "-in", "test.cms", "-out", "smtst.txt" ]
  346. ],
  347. [ "enveloped content test streaming S/MIME format, X9.42 DH",
  348. [ "-encrypt", "-in", $smcont,
  349. "-stream", "-out", "test.cms",
  350. "-recip", catfile($smdir, "smdh.pem"), "-aes128" ],
  351. [ "-decrypt", "-recip", catfile($smdir, "smdh.pem"),
  352. "-in", "test.cms", "-out", "smtst.txt" ]
  353. ]
  354. );
  355. subtest "CMS => PKCS#7 compatibility tests\n" => sub {
  356. plan tests => scalar @smime_pkcs7_tests;
  357. foreach (@smime_pkcs7_tests) {
  358. SKIP: {
  359. my $skip_reason = check_availability($$_[0]);
  360. skip $skip_reason, 1 if $skip_reason;
  361. ok(run(app(["openssl", "cms", @{$$_[1]}]))
  362. && run(app(["openssl", "smime", @{$$_[2]}]))
  363. && compare_text($smcont, "smtst.txt") == 0,
  364. $$_[0]);
  365. }
  366. }
  367. };
  368. subtest "CMS <= PKCS#7 compatibility tests\n" => sub {
  369. plan tests => scalar @smime_pkcs7_tests;
  370. foreach (@smime_pkcs7_tests) {
  371. SKIP: {
  372. my $skip_reason = check_availability($$_[0]);
  373. skip $skip_reason, 1 if $skip_reason;
  374. ok(run(app(["openssl", "smime", @{$$_[1]}]))
  375. && run(app(["openssl", "cms", @{$$_[2]}]))
  376. && compare_text($smcont, "smtst.txt") == 0,
  377. $$_[0]);
  378. }
  379. }
  380. };
  381. subtest "CMS <=> CMS consistency tests\n" => sub {
  382. plan tests => (scalar @smime_pkcs7_tests) + (scalar @smime_cms_tests);
  383. foreach (@smime_pkcs7_tests) {
  384. SKIP: {
  385. my $skip_reason = check_availability($$_[0]);
  386. skip $skip_reason, 1 if $skip_reason;
  387. ok(run(app(["openssl", "cms", @{$$_[1]}]))
  388. && run(app(["openssl", "cms", @{$$_[2]}]))
  389. && compare_text($smcont, "smtst.txt") == 0,
  390. $$_[0]);
  391. }
  392. }
  393. foreach (@smime_cms_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. };
  404. subtest "CMS <=> CMS consistency tests, modified key parameters\n" => sub {
  405. plan tests =>
  406. (scalar @smime_cms_param_tests) + (scalar @smime_cms_comp_tests);
  407. foreach (@smime_cms_param_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. SKIP: {
  418. skip("Zlib not supported: compression tests skipped",
  419. scalar @smime_cms_comp_tests)
  420. if $no_zlib;
  421. foreach (@smime_cms_comp_tests) {
  422. SKIP: {
  423. my $skip_reason = check_availability($$_[0]);
  424. skip $skip_reason, 1 if $skip_reason;
  425. ok(run(app(["openssl", "cms", @{$$_[1]}]))
  426. && run(app(["openssl", "cms", @{$$_[2]}]))
  427. && compare_text($smcont, "smtst.txt") == 0,
  428. $$_[0]);
  429. }
  430. }
  431. }
  432. };
  433. unlink "test.cms";
  434. unlink "test2.cms";
  435. unlink "smtst.txt";
  436. sub check_availability {
  437. my $tnam = shift;
  438. return "$tnam: skipped, EC disabled\n"
  439. if ($no_ec && $tnam =~ /ECDH/);
  440. return "$tnam: skipped, ECDH disabled\n"
  441. if ($no_ec && $tnam =~ /ECDH/);
  442. return "$tnam: skipped, EC2M disabled\n"
  443. if ($no_ec2m && $tnam =~ /K-283/);
  444. return "$tnam: skipped, DH disabled\n"
  445. if ($no_dh && $tnam =~ /X9\.42/);
  446. return "$tnam: skipped, RC2 disabled\n"
  447. if ($no_rc2 && $tnam =~ /RC2/);
  448. return "$tnam: skipped, DES disabled\n"
  449. if ($no_des && $tnam =~ /DES/);
  450. return "$tnam: skipped, DSA disabled\n"
  451. if ($no_dsa && $tnam =~ / DSA/);
  452. return "";
  453. }