80-test_cms.t 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  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, saltlen=max",
  282. [ "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
  283. "-signer", catfile($smdir, "smrsa1.pem"), "-keyopt", "rsa_padding_mode:pss",
  284. "-keyopt", "rsa_pss_saltlen:max", "-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, no attributes",
  289. [ "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach", "-noattr",
  290. "-signer", catfile($smdir, "smrsa1.pem"), "-keyopt", "rsa_padding_mode:pss",
  291. "-out", "test.cms" ],
  292. [ "-verify", "-in", "test.cms", "-inform", "PEM",
  293. "-CAfile", catfile($smdir, "smroot.pem"), "-out", "smtst.txt" ]
  294. ],
  295. [ "signed content test streaming PEM format, RSA keys, PSS signature, SHA384 MGF1",
  296. [ "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
  297. "-signer", catfile($smdir, "smrsa1.pem"), "-keyopt", "rsa_padding_mode:pss",
  298. "-keyopt", "rsa_mgf1_md:sha384", "-out", "test.cms" ],
  299. [ "-verify", "-in", "test.cms", "-inform", "PEM",
  300. "-CAfile", catfile($smdir, "smroot.pem"), "-out", "smtst.txt" ]
  301. ],
  302. [ "enveloped content test streaming S/MIME format, DES, OAEP default parameters",
  303. [ "-encrypt", "-in", $smcont,
  304. "-stream", "-out", "test.cms",
  305. "-recip", catfile($smdir, "smrsa1.pem"), "-keyopt", "rsa_padding_mode:oaep" ],
  306. [ "-decrypt", "-recip", catfile($smdir, "smrsa1.pem"),
  307. "-in", "test.cms", "-out", "smtst.txt" ]
  308. ],
  309. [ "enveloped content test streaming S/MIME format, DES, OAEP SHA256",
  310. [ "-encrypt", "-in", $smcont,
  311. "-stream", "-out", "test.cms",
  312. "-recip", catfile($smdir, "smrsa1.pem"), "-keyopt", "rsa_padding_mode:oaep",
  313. "-keyopt", "rsa_oaep_md:sha256" ],
  314. [ "-decrypt", "-recip", catfile($smdir, "smrsa1.pem"),
  315. "-in", "test.cms", "-out", "smtst.txt" ]
  316. ],
  317. [ "enveloped content test streaming S/MIME format, DES, ECDH",
  318. [ "-encrypt", "-in", $smcont,
  319. "-stream", "-out", "test.cms",
  320. "-recip", catfile($smdir, "smec1.pem") ],
  321. [ "-decrypt", "-recip", catfile($smdir, "smec1.pem"),
  322. "-in", "test.cms", "-out", "smtst.txt" ]
  323. ],
  324. [ "enveloped content test streaming S/MIME format, DES, ECDH, 2 recipients, key only used",
  325. [ "-encrypt", "-in", $smcont,
  326. "-stream", "-out", "test.cms",
  327. catfile($smdir, "smec1.pem"),
  328. catfile($smdir, "smec3.pem") ],
  329. [ "-decrypt", "-inkey", catfile($smdir, "smec3.pem"),
  330. "-in", "test.cms", "-out", "smtst.txt" ]
  331. ],
  332. [ "enveloped content test streaming S/MIME format, ECDH, DES, key identifier",
  333. [ "-encrypt", "-keyid", "-in", $smcont,
  334. "-stream", "-out", "test.cms",
  335. "-recip", catfile($smdir, "smec1.pem") ],
  336. [ "-decrypt", "-recip", catfile($smdir, "smec1.pem"),
  337. "-in", "test.cms", "-out", "smtst.txt" ]
  338. ],
  339. [ "enveloped content test streaming S/MIME format, ECDH, AES128, SHA256 KDF",
  340. [ "-encrypt", "-in", $smcont,
  341. "-stream", "-out", "test.cms",
  342. "-recip", catfile($smdir, "smec1.pem"), "-aes128", "-keyopt", "ecdh_kdf_md:sha256" ],
  343. [ "-decrypt", "-recip", catfile($smdir, "smec1.pem"),
  344. "-in", "test.cms", "-out", "smtst.txt" ]
  345. ],
  346. [ "enveloped content test streaming S/MIME format, ECDH, K-283, cofactor DH",
  347. [ "-encrypt", "-in", $smcont,
  348. "-stream", "-out", "test.cms",
  349. "-recip", catfile($smdir, "smec2.pem"), "-aes128",
  350. "-keyopt", "ecdh_kdf_md:sha256", "-keyopt", "ecdh_cofactor_mode:1" ],
  351. [ "-decrypt", "-recip", catfile($smdir, "smec2.pem"),
  352. "-in", "test.cms", "-out", "smtst.txt" ]
  353. ],
  354. [ "enveloped content test streaming S/MIME format, X9.42 DH",
  355. [ "-encrypt", "-in", $smcont,
  356. "-stream", "-out", "test.cms",
  357. "-recip", catfile($smdir, "smdh.pem"), "-aes128" ],
  358. [ "-decrypt", "-recip", catfile($smdir, "smdh.pem"),
  359. "-in", "test.cms", "-out", "smtst.txt" ]
  360. ]
  361. );
  362. subtest "CMS => PKCS#7 compatibility tests\n" => sub {
  363. plan tests => scalar @smime_pkcs7_tests;
  364. foreach (@smime_pkcs7_tests) {
  365. SKIP: {
  366. my $skip_reason = check_availability($$_[0]);
  367. skip $skip_reason, 1 if $skip_reason;
  368. ok(run(app(["openssl", "cms", @{$$_[1]}]))
  369. && run(app(["openssl", "smime", @{$$_[2]}]))
  370. && compare_text($smcont, "smtst.txt") == 0,
  371. $$_[0]);
  372. }
  373. }
  374. };
  375. subtest "CMS <= PKCS#7 compatibility tests\n" => sub {
  376. plan tests => scalar @smime_pkcs7_tests;
  377. foreach (@smime_pkcs7_tests) {
  378. SKIP: {
  379. my $skip_reason = check_availability($$_[0]);
  380. skip $skip_reason, 1 if $skip_reason;
  381. ok(run(app(["openssl", "smime", @{$$_[1]}]))
  382. && run(app(["openssl", "cms", @{$$_[2]}]))
  383. && compare_text($smcont, "smtst.txt") == 0,
  384. $$_[0]);
  385. }
  386. }
  387. };
  388. subtest "CMS <=> CMS consistency tests\n" => sub {
  389. plan tests => (scalar @smime_pkcs7_tests) + (scalar @smime_cms_tests);
  390. foreach (@smime_pkcs7_tests) {
  391. SKIP: {
  392. my $skip_reason = check_availability($$_[0]);
  393. skip $skip_reason, 1 if $skip_reason;
  394. ok(run(app(["openssl", "cms", @{$$_[1]}]))
  395. && run(app(["openssl", "cms", @{$$_[2]}]))
  396. && compare_text($smcont, "smtst.txt") == 0,
  397. $$_[0]);
  398. }
  399. }
  400. foreach (@smime_cms_tests) {
  401. SKIP: {
  402. my $skip_reason = check_availability($$_[0]);
  403. skip $skip_reason, 1 if $skip_reason;
  404. ok(run(app(["openssl", "cms", @{$$_[1]}]))
  405. && run(app(["openssl", "cms", @{$$_[2]}]))
  406. && compare_text($smcont, "smtst.txt") == 0,
  407. $$_[0]);
  408. }
  409. }
  410. };
  411. subtest "CMS <=> CMS consistency tests, modified key parameters\n" => sub {
  412. plan tests =>
  413. (scalar @smime_cms_param_tests) + (scalar @smime_cms_comp_tests);
  414. foreach (@smime_cms_param_tests) {
  415. SKIP: {
  416. my $skip_reason = check_availability($$_[0]);
  417. skip $skip_reason, 1 if $skip_reason;
  418. ok(run(app(["openssl", "cms", @{$$_[1]}]))
  419. && run(app(["openssl", "cms", @{$$_[2]}]))
  420. && compare_text($smcont, "smtst.txt") == 0,
  421. $$_[0]);
  422. }
  423. }
  424. SKIP: {
  425. skip("Zlib not supported: compression tests skipped",
  426. scalar @smime_cms_comp_tests)
  427. if $no_zlib;
  428. foreach (@smime_cms_comp_tests) {
  429. SKIP: {
  430. my $skip_reason = check_availability($$_[0]);
  431. skip $skip_reason, 1 if $skip_reason;
  432. ok(run(app(["openssl", "cms", @{$$_[1]}]))
  433. && run(app(["openssl", "cms", @{$$_[2]}]))
  434. && compare_text($smcont, "smtst.txt") == 0,
  435. $$_[0]);
  436. }
  437. }
  438. }
  439. };
  440. unlink "test.cms";
  441. unlink "test2.cms";
  442. unlink "smtst.txt";
  443. sub check_availability {
  444. my $tnam = shift;
  445. return "$tnam: skipped, EC disabled\n"
  446. if ($no_ec && $tnam =~ /ECDH/);
  447. return "$tnam: skipped, ECDH disabled\n"
  448. if ($no_ec && $tnam =~ /ECDH/);
  449. return "$tnam: skipped, EC2M disabled\n"
  450. if ($no_ec2m && $tnam =~ /K-283/);
  451. return "$tnam: skipped, DH disabled\n"
  452. if ($no_dh && $tnam =~ /X9\.42/);
  453. return "$tnam: skipped, RC2 disabled\n"
  454. if ($no_rc2 && $tnam =~ /RC2/);
  455. return "$tnam: skipped, DES disabled\n"
  456. if ($no_des && $tnam =~ /DES/);
  457. return "$tnam: skipped, DSA disabled\n"
  458. if ($no_dsa && $tnam =~ / DSA/);
  459. return "";
  460. }