80-test_cms.t 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955
  1. #! /usr/bin/env perl
  2. # Copyright 2015-2022 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 compare/;
  13. use OpenSSL::Test qw/:DEFAULT srctop_dir srctop_file bldtop_dir bldtop_file/;
  14. use OpenSSL::Test::Utils;
  15. BEGIN {
  16. setup("test_cms");
  17. }
  18. use lib srctop_dir('Configurations');
  19. use lib bldtop_dir('.');
  20. my $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0);
  21. plan skip_all => "CMS is not supported by this OpenSSL build"
  22. if disabled("cms");
  23. my $provpath = bldtop_dir("providers");
  24. # Some tests require legacy algorithms to be included.
  25. my @legacyprov = ("-provider-path", $provpath,
  26. "-provider", "default",
  27. "-provider", "legacy" );
  28. my @defaultprov = ("-provider-path", $provpath,
  29. "-provider", "default");
  30. my @config = ( );
  31. my $provname = 'default';
  32. my $datadir = srctop_dir("test", "recipes", "80-test_cms_data");
  33. my $smdir = srctop_dir("test", "smime-certs");
  34. my $smcont = srctop_file("test", "smcont.txt");
  35. my $smcont_zero = srctop_file("test", "smcont_zero.txt");
  36. my ($no_des, $no_dh, $no_dsa, $no_ec, $no_ec2m, $no_rc2, $no_zlib)
  37. = disabled qw/des dh dsa ec ec2m rc2 zlib/;
  38. $no_rc2 = 1 if disabled("legacy");
  39. plan tests => 15;
  40. ok(run(test(["pkcs7_test"])), "test pkcs7");
  41. unless ($no_fips) {
  42. @config = ( "-config", srctop_file("test", "fips-and-base.cnf") );
  43. $provname = 'fips';
  44. }
  45. $ENV{OPENSSL_TEST_LIBCTX} = "1";
  46. my @prov = ("-provider-path", $provpath,
  47. @config,
  48. "-provider", $provname);
  49. my $smrsa1 = catfile($smdir, "smrsa1.pem");
  50. my $smroot = catfile($smdir, "smroot.pem");
  51. my @smime_pkcs7_tests = (
  52. [ "signed content DER format, RSA key",
  53. [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER", "-nodetach",
  54. "-certfile", $smroot, "-signer", $smrsa1, "-out", "{output}.cms" ],
  55. [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "DER",
  56. "-CAfile", $smroot, "-out", "{output}.txt" ],
  57. \&final_compare
  58. ],
  59. [ "signed detached content DER format, RSA key",
  60. [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER",
  61. "-signer", $smrsa1, "-out", "{output}.cms" ],
  62. [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "DER",
  63. "-CAfile", $smroot, "-out", "{output}.txt",
  64. "-content", $smcont ],
  65. \&final_compare
  66. ],
  67. [ "signed content test streaming BER format, RSA",
  68. [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER", "-nodetach",
  69. "-stream",
  70. "-signer", $smrsa1, "-out", "{output}.cms" ],
  71. [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "DER",
  72. "-CAfile", $smroot, "-out", "{output}.txt" ],
  73. \&final_compare
  74. ],
  75. [ "signed content DER format, DSA key",
  76. [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER", "-nodetach",
  77. "-signer", catfile($smdir, "smdsa1.pem"), "-out", "{output}.cms" ],
  78. [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "DER",
  79. "-CAfile", $smroot, "-out", "{output}.txt" ],
  80. \&final_compare
  81. ],
  82. [ "signed detached content DER format, DSA key",
  83. [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER",
  84. "-signer", catfile($smdir, "smdsa1.pem"), "-out", "{output}.cms" ],
  85. [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "DER",
  86. "-CAfile", $smroot, "-out", "{output}.txt",
  87. "-content", $smcont ],
  88. \&final_compare
  89. ],
  90. [ "signed detached content DER format, add RSA signer (with DSA existing)",
  91. [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER",
  92. "-signer", catfile($smdir, "smdsa1.pem"), "-out", "{output}.cms" ],
  93. [ "{cmd1}", @prov, "-resign", "-in", "{output}.cms", "-inform", "DER", "-outform", "DER",
  94. "-signer", $smrsa1, "-out", "{output}2.cms" ],
  95. [ "{cmd2}", @prov, "-verify", "-in", "{output}2.cms", "-inform", "DER",
  96. "-CAfile", $smroot, "-out", "{output}.txt",
  97. "-content", $smcont ],
  98. \&final_compare
  99. ],
  100. [ "signed content test streaming BER format, DSA key",
  101. [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER",
  102. "-nodetach", "-stream",
  103. "-signer", catfile($smdir, "smdsa1.pem"), "-out", "{output}.cms" ],
  104. [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "DER",
  105. "-CAfile", $smroot, "-out", "{output}.txt" ],
  106. \&final_compare
  107. ],
  108. [ "signed content test streaming BER format, 2 DSA and 2 RSA keys",
  109. [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER",
  110. "-nodetach", "-stream",
  111. "-signer", $smrsa1,
  112. "-signer", catfile($smdir, "smrsa2.pem"),
  113. "-signer", catfile($smdir, "smdsa1.pem"),
  114. "-signer", catfile($smdir, "smdsa2.pem"),
  115. "-out", "{output}.cms" ],
  116. [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "DER",
  117. "-CAfile", $smroot, "-out", "{output}.txt" ],
  118. \&final_compare
  119. ],
  120. [ "signed content test streaming BER format, 2 DSA and 2 RSA keys, no attributes",
  121. [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER",
  122. "-noattr", "-nodetach", "-stream",
  123. "-signer", $smrsa1,
  124. "-signer", catfile($smdir, "smrsa2.pem"),
  125. "-signer", catfile($smdir, "smdsa1.pem"),
  126. "-signer", catfile($smdir, "smdsa2.pem"),
  127. "-out", "{output}.cms" ],
  128. [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "DER",
  129. "-CAfile", $smroot, "-out", "{output}.txt" ],
  130. \&final_compare
  131. ],
  132. [ "signed content S/MIME format, RSA key SHA1",
  133. [ "{cmd1}", @defaultprov, "-sign", "-in", $smcont, "-md", "sha1",
  134. "-certfile", $smroot,
  135. "-signer", $smrsa1, "-out", "{output}.cms" ],
  136. [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms",
  137. "-CAfile", $smroot, "-out", "{output}.txt" ],
  138. \&final_compare
  139. ],
  140. [ "signed zero-length content S/MIME format, RSA key SHA1",
  141. [ "{cmd1}", @defaultprov, "-sign", "-in", $smcont_zero, "-md", "sha1",
  142. "-certfile", $smroot, "-signer", $smrsa1, "-out", "{output}.cms" ],
  143. [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms",
  144. "-CAfile", $smroot, "-out", "{output}.txt" ],
  145. \&zero_compare
  146. ],
  147. [ "signed content test streaming S/MIME format, 2 DSA and 2 RSA keys",
  148. [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-nodetach",
  149. "-signer", $smrsa1,
  150. "-signer", catfile($smdir, "smrsa2.pem"),
  151. "-signer", catfile($smdir, "smdsa1.pem"),
  152. "-signer", catfile($smdir, "smdsa2.pem"),
  153. "-stream", "-out", "{output}.cms" ],
  154. [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms",
  155. "-CAfile", $smroot, "-out", "{output}.txt" ],
  156. \&final_compare
  157. ],
  158. [ "signed content test streaming multipart S/MIME format, 2 DSA and 2 RSA keys",
  159. [ "{cmd1}", @prov, "-sign", "-in", $smcont,
  160. "-signer", $smrsa1,
  161. "-signer", catfile($smdir, "smrsa2.pem"),
  162. "-signer", catfile($smdir, "smdsa1.pem"),
  163. "-signer", catfile($smdir, "smdsa2.pem"),
  164. "-stream", "-out", "{output}.cms" ],
  165. [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms",
  166. "-CAfile", $smroot, "-out", "{output}.txt" ],
  167. \&final_compare
  168. ],
  169. [ "enveloped content test streaming S/MIME format, DES, 3 recipients",
  170. [ "{cmd1}", @defaultprov, "-encrypt", "-in", $smcont,
  171. "-stream", "-out", "{output}.cms",
  172. $smrsa1,
  173. catfile($smdir, "smrsa2.pem"),
  174. catfile($smdir, "smrsa3.pem") ],
  175. [ "{cmd2}", @defaultprov, "-decrypt", "-recip", $smrsa1,
  176. "-in", "{output}.cms", "-out", "{output}.txt" ],
  177. \&final_compare
  178. ],
  179. [ "enveloped content test streaming S/MIME format, DES, 3 recipients, 3rd used",
  180. [ "{cmd1}", @defaultprov, "-encrypt", "-in", $smcont,
  181. "-stream", "-out", "{output}.cms",
  182. $smrsa1,
  183. catfile($smdir, "smrsa2.pem"),
  184. catfile($smdir, "smrsa3.pem") ],
  185. [ "{cmd2}", @defaultprov, "-decrypt", "-recip", catfile($smdir, "smrsa3.pem"),
  186. "-in", "{output}.cms", "-out", "{output}.txt" ],
  187. \&final_compare
  188. ],
  189. [ "enveloped content test streaming S/MIME format, DES, 3 recipients, key only used",
  190. [ "{cmd1}", @defaultprov, "-encrypt", "-in", $smcont,
  191. "-stream", "-out", "{output}.cms",
  192. $smrsa1,
  193. catfile($smdir, "smrsa2.pem"),
  194. catfile($smdir, "smrsa3.pem") ],
  195. [ "{cmd2}", @defaultprov, "-decrypt", "-inkey", catfile($smdir, "smrsa3.pem"),
  196. "-in", "{output}.cms", "-out", "{output}.txt" ],
  197. \&final_compare
  198. ],
  199. [ "enveloped content test streaming S/MIME format, AES-256 cipher, 3 recipients",
  200. [ "{cmd1}", @prov, "-encrypt", "-in", $smcont,
  201. "-aes256", "-stream", "-out", "{output}.cms",
  202. $smrsa1,
  203. catfile($smdir, "smrsa2.pem"),
  204. catfile($smdir, "smrsa3.pem") ],
  205. [ "{cmd2}", @prov, "-decrypt", "-recip", $smrsa1,
  206. "-in", "{output}.cms", "-out", "{output}.txt" ],
  207. \&final_compare
  208. ],
  209. );
  210. my @smime_cms_tests = (
  211. [ "signed content test streaming BER format, 2 DSA and 2 RSA keys, keyid",
  212. [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "DER",
  213. "-nodetach", "-keyid",
  214. "-signer", $smrsa1,
  215. "-signer", catfile($smdir, "smrsa2.pem"),
  216. "-signer", catfile($smdir, "smdsa1.pem"),
  217. "-signer", catfile($smdir, "smdsa2.pem"),
  218. "-stream", "-out", "{output}.cms" ],
  219. [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "DER",
  220. "-CAfile", $smroot, "-out", "{output}.txt" ],
  221. \&final_compare
  222. ],
  223. [ "signed content test streaming PEM format, 2 DSA and 2 RSA keys",
  224. [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
  225. "-signer", $smrsa1,
  226. "-signer", catfile($smdir, "smrsa2.pem"),
  227. "-signer", catfile($smdir, "smdsa1.pem"),
  228. "-signer", catfile($smdir, "smdsa2.pem"),
  229. "-stream", "-out", "{output}.cms" ],
  230. [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "PEM",
  231. "-CAfile", $smroot, "-out", "{output}.txt" ],
  232. \&final_compare
  233. ],
  234. [ "signed content MIME format, RSA key, signed receipt request",
  235. [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-nodetach",
  236. "-signer", $smrsa1,
  237. "-receipt_request_to", "test\@openssl.org", "-receipt_request_all",
  238. "-out", "{output}.cms" ],
  239. [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms",
  240. "-CAfile", $smroot, "-out", "{output}.txt" ],
  241. \&final_compare
  242. ],
  243. [ "signed receipt MIME format, RSA key",
  244. [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-nodetach",
  245. "-signer", $smrsa1,
  246. "-receipt_request_to", "test\@openssl.org", "-receipt_request_all",
  247. "-out", "{output}.cms" ],
  248. [ "{cmd1}", @prov, "-sign_receipt", "-in", "{output}.cms",
  249. "-signer", catfile($smdir, "smrsa2.pem"), "-out", "{output}2.cms" ],
  250. [ "{cmd2}", @prov, "-verify_receipt", "{output}2.cms", "-in", "{output}.cms",
  251. "-CAfile", $smroot ]
  252. ],
  253. [ "enveloped content test streaming S/MIME format, DES, 3 recipients, keyid",
  254. [ "{cmd1}", @defaultprov, "-encrypt", "-in", $smcont,
  255. "-stream", "-out", "{output}.cms", "-keyid",
  256. $smrsa1,
  257. catfile($smdir, "smrsa2.pem"),
  258. catfile($smdir, "smrsa3.pem") ],
  259. [ "{cmd2}", @defaultprov, "-decrypt", "-recip", $smrsa1,
  260. "-in", "{output}.cms", "-out", "{output}.txt" ],
  261. \&final_compare
  262. ],
  263. [ "enveloped content test streaming PEM format, AES-256-CBC cipher, KEK",
  264. [ "{cmd1}", @prov, "-encrypt", "-in", $smcont, "-outform", "PEM", "-aes128",
  265. "-stream", "-out", "{output}.cms",
  266. "-secretkey", "000102030405060708090A0B0C0D0E0F",
  267. "-secretkeyid", "C0FEE0" ],
  268. [ "{cmd2}", @prov, "-decrypt", "-in", "{output}.cms", "-out", "{output}.txt",
  269. "-inform", "PEM",
  270. "-secretkey", "000102030405060708090A0B0C0D0E0F",
  271. "-secretkeyid", "C0FEE0" ],
  272. \&final_compare
  273. ],
  274. [ "enveloped content test streaming PEM format, AES-256-GCM cipher, KEK",
  275. [ "{cmd1}", @prov, "-encrypt", "-in", $smcont, "-outform", "PEM", "-aes-128-gcm",
  276. "-stream", "-out", "{output}.cms",
  277. "-secretkey", "000102030405060708090A0B0C0D0E0F",
  278. "-secretkeyid", "C0FEE0" ],
  279. [ "{cmd2}", "-decrypt", "-in", "{output}.cms", "-out", "{output}.txt",
  280. "-inform", "PEM",
  281. "-secretkey", "000102030405060708090A0B0C0D0E0F",
  282. "-secretkeyid", "C0FEE0" ],
  283. \&final_compare
  284. ],
  285. [ "enveloped content test streaming PEM format, KEK, key only",
  286. [ "{cmd1}", @prov, "-encrypt", "-in", $smcont, "-outform", "PEM", "-aes128",
  287. "-stream", "-out", "{output}.cms",
  288. "-secretkey", "000102030405060708090A0B0C0D0E0F",
  289. "-secretkeyid", "C0FEE0" ],
  290. [ "{cmd2}", @prov, "-decrypt", "-in", "{output}.cms", "-out", "{output}.txt",
  291. "-inform", "PEM",
  292. "-secretkey", "000102030405060708090A0B0C0D0E0F" ],
  293. \&final_compare
  294. ],
  295. [ "data content test streaming PEM format",
  296. [ "{cmd1}", @prov, "-data_create", "-in", $smcont, "-outform", "PEM",
  297. "-nodetach", "-stream", "-out", "{output}.cms" ],
  298. [ "{cmd2}", @prov, "-data_out", "-in", "{output}.cms", "-inform", "PEM",
  299. "-out", "{output}.txt" ],
  300. \&final_compare
  301. ],
  302. [ "encrypted content test streaming PEM format, 128 bit RC2 key",
  303. [ "{cmd1}", @legacyprov, "-EncryptedData_encrypt",
  304. "-in", $smcont, "-outform", "PEM",
  305. "-rc2", "-secretkey", "000102030405060708090A0B0C0D0E0F",
  306. "-stream", "-out", "{output}.cms" ],
  307. [ "{cmd2}", @legacyprov, "-EncryptedData_decrypt", "-in", "{output}.cms",
  308. "-inform", "PEM",
  309. "-secretkey", "000102030405060708090A0B0C0D0E0F",
  310. "-out", "{output}.txt" ],
  311. \&final_compare
  312. ],
  313. [ "encrypted content test streaming PEM format, 40 bit RC2 key",
  314. [ "{cmd1}", @legacyprov, "-EncryptedData_encrypt",
  315. "-in", $smcont, "-outform", "PEM",
  316. "-rc2", "-secretkey", "0001020304",
  317. "-stream", "-out", "{output}.cms" ],
  318. [ "{cmd2}", @legacyprov, "-EncryptedData_decrypt", "-in", "{output}.cms",
  319. "-inform", "PEM",
  320. "-secretkey", "0001020304", "-out", "{output}.txt" ],
  321. \&final_compare
  322. ],
  323. [ "encrypted content test streaming PEM format, triple DES key",
  324. [ "{cmd1}", @prov, "-EncryptedData_encrypt", "-in", $smcont, "-outform", "PEM",
  325. "-des3", "-secretkey", "000102030405060708090A0B0C0D0E0F1011121314151617",
  326. "-stream", "-out", "{output}.cms" ],
  327. [ "{cmd2}", @prov, "-EncryptedData_decrypt", "-in", "{output}.cms",
  328. "-inform", "PEM",
  329. "-secretkey", "000102030405060708090A0B0C0D0E0F1011121314151617",
  330. "-out", "{output}.txt" ],
  331. \&final_compare
  332. ],
  333. [ "encrypted content test streaming PEM format, 128 bit AES key",
  334. [ "{cmd1}", @prov, "-EncryptedData_encrypt", "-in", $smcont, "-outform", "PEM",
  335. "-aes128", "-secretkey", "000102030405060708090A0B0C0D0E0F",
  336. "-stream", "-out", "{output}.cms" ],
  337. [ "{cmd2}", @prov, "-EncryptedData_decrypt", "-in", "{output}.cms",
  338. "-inform", "PEM",
  339. "-secretkey", "000102030405060708090A0B0C0D0E0F",
  340. "-out", "{output}.txt" ],
  341. \&final_compare
  342. ],
  343. );
  344. my @smime_cms_cades_tests = (
  345. [ "signed content DER format, RSA key, CAdES-BES compatible",
  346. [ "{cmd1}", @prov, "-sign", "-cades", "-in", $smcont, "-outform", "DER",
  347. "-nodetach",
  348. "-certfile", $smroot, "-signer", $smrsa1, "-out", "{output}.cms" ],
  349. [ "{cmd2}", @prov, "-verify", "-cades", "-in", "{output}.cms", "-inform", "DER",
  350. "-CAfile", $smroot, "-out", "{output}.txt" ],
  351. \&final_compare
  352. ],
  353. [ "signed content DER format, RSA key, SHA256 md, CAdES-BES compatible",
  354. [ "{cmd1}", @prov, "-sign", "-cades", "-md", "sha256", "-in", $smcont, "-outform",
  355. "DER", "-nodetach", "-certfile", $smroot,
  356. "-signer", $smrsa1, "-out", "{output}.cms" ],
  357. [ "{cmd2}", @prov, "-verify", "-cades", "-in", "{output}.cms", "-inform", "DER",
  358. "-CAfile", $smroot, "-out", "{output}.txt" ],
  359. \&final_compare
  360. ],
  361. [ "signed content DER format, RSA key, SHA512 md, CAdES-BES compatible",
  362. [ "{cmd1}", @prov, "-sign", "-cades", "-md", "sha512", "-in", $smcont, "-outform",
  363. "DER", "-nodetach", "-certfile", $smroot,
  364. "-signer", $smrsa1, "-out", "{output}.cms" ],
  365. [ "{cmd2}", @prov, "-verify", "-cades", "-in", "{output}.cms", "-inform", "DER",
  366. "-CAfile", $smroot, "-out", "{output}.txt" ],
  367. \&final_compare
  368. ],
  369. [ "signed content DER format, RSA key, SHA256 md, CAdES-BES compatible",
  370. [ "{cmd1}", @prov, "-sign", "-cades", "-binary", "-nodetach", "-nosmimecap", "-md", "sha256",
  371. "-in", $smcont, "-outform", "DER",
  372. "-certfile", $smroot, "-signer", $smrsa1,
  373. "-outform", "DER", "-out", "{output}.cms" ],
  374. [ "{cmd2}", @prov, "-verify", "-cades", "-in", "{output}.cms", "-inform", "DER",
  375. "-CAfile", $smroot, "-out", "{output}.txt" ],
  376. \&final_compare
  377. ],
  378. [ "resigned content DER format, RSA key, SHA256 md, CAdES-BES compatible",
  379. [ "{cmd1}", @prov, "-sign", "-cades", "-binary", "-nodetach", "-nosmimecap", "-md", "sha256",
  380. "-in", $smcont, "-outform", "DER",
  381. "-certfile", $smroot, "-signer", $smrsa1,
  382. "-outform", "DER", "-out", "{output}.cms" ],
  383. [ "{cmd1}", @prov, "-resign", "-cades", "-binary", "-nodetach", "-nosmimecap", "-md", "sha256",
  384. "-inform", "DER", "-in", "{output}.cms",
  385. "-certfile", $smroot, "-signer", catfile($smdir, "smrsa2.pem"),
  386. "-outform", "DER", "-out", "{output}2.cms" ],
  387. [ "{cmd2}", @prov, "-verify", "-cades", "-in", "{output}2.cms", "-inform", "DER",
  388. "-CAfile", $smroot, "-out", "{output}.txt" ],
  389. \&final_compare
  390. ],
  391. );
  392. my @smime_cms_cades_ko_tests = (
  393. [ "sign content DER format, RSA key, not CAdES-BES compatible",
  394. [ @prov, "-sign", "-in", $smcont, "-outform", "DER", "-nodetach",
  395. "-certfile", $smroot, "-signer", $smrsa1, "-out", "{output}.cms" ],
  396. "fail to verify token since requiring CAdES-BES compatibility",
  397. [ @prov, "-verify", "-cades", "-in", "{output}.cms", "-inform", "DER",
  398. "-CAfile", $smroot, "-out", "{output}.txt" ],
  399. \&final_compare
  400. ]
  401. );
  402. # cades options test - check that some combinations are rejected
  403. my @smime_cms_cades_invalid_option_tests = (
  404. [
  405. [ "-cades", "-noattr" ],
  406. ],[
  407. [ "-verify", "-cades", "-noattr" ],
  408. ],[
  409. [ "-verify", "-cades", "-noverify" ],
  410. ],
  411. );
  412. my @smime_cms_comp_tests = (
  413. [ "compressed content test streaming PEM format",
  414. [ "{cmd1}", @prov, "-compress", "-in", $smcont, "-outform", "PEM", "-nodetach",
  415. "-stream", "-out", "{output}.cms" ],
  416. [ "{cmd2}", @prov, "-uncompress", "-in", "{output}.cms", "-inform", "PEM",
  417. "-out", "{output}.txt" ],
  418. \&final_compare
  419. ]
  420. );
  421. my @smime_cms_param_tests = (
  422. [ "signed content test streaming PEM format, RSA keys, PSS signature",
  423. [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
  424. "-signer", $smrsa1,
  425. "-keyopt", "rsa_padding_mode:pss",
  426. "-out", "{output}.cms" ],
  427. [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "PEM",
  428. "-CAfile", $smroot, "-out", "{output}.txt" ],
  429. \&final_compare
  430. ],
  431. [ "signed content test streaming PEM format, RSA keys, PSS signature, saltlen=max",
  432. [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
  433. "-signer", $smrsa1,
  434. "-keyopt", "rsa_padding_mode:pss", "-keyopt", "rsa_pss_saltlen:max",
  435. "-out", "{output}.cms" ],
  436. [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "PEM",
  437. "-CAfile", $smroot, "-out", "{output}.txt" ],
  438. \&final_compare
  439. ],
  440. [ "signed content test streaming PEM format, RSA keys, PSS signature, no attributes",
  441. [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
  442. "-noattr", "-signer", $smrsa1,
  443. "-keyopt", "rsa_padding_mode:pss",
  444. "-out", "{output}.cms" ],
  445. [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "PEM",
  446. "-CAfile", $smroot, "-out", "{output}.txt" ],
  447. \&final_compare
  448. ],
  449. [ "signed content test streaming PEM format, RSA keys, PSS signature, SHA384 MGF1",
  450. [ "{cmd1}", @prov, "-sign", "-in", $smcont, "-outform", "PEM", "-nodetach",
  451. "-signer", $smrsa1,
  452. "-keyopt", "rsa_padding_mode:pss", "-keyopt", "rsa_mgf1_md:sha384",
  453. "-out", "{output}.cms" ],
  454. [ "{cmd2}", @prov, "-verify", "-in", "{output}.cms", "-inform", "PEM",
  455. "-CAfile", $smroot, "-out", "{output}.txt" ],
  456. \&final_compare
  457. ],
  458. [ "enveloped content test streaming S/MIME format, DES, OAEP default parameters",
  459. [ "{cmd1}", @defaultprov, "-encrypt", "-in", $smcont,
  460. "-stream", "-out", "{output}.cms",
  461. "-recip", $smrsa1,
  462. "-keyopt", "rsa_padding_mode:oaep" ],
  463. [ "{cmd2}", @defaultprov, "-decrypt", "-recip", $smrsa1,
  464. "-in", "{output}.cms", "-out", "{output}.txt" ],
  465. \&final_compare
  466. ],
  467. [ "enveloped content test streaming S/MIME format, DES, OAEP SHA256",
  468. [ "{cmd1}", @defaultprov, "-encrypt", "-in", $smcont,
  469. "-stream", "-out", "{output}.cms",
  470. "-recip", $smrsa1,
  471. "-keyopt", "rsa_padding_mode:oaep",
  472. "-keyopt", "rsa_oaep_md:sha256" ],
  473. [ "{cmd2}", @defaultprov, "-decrypt", "-recip", $smrsa1,
  474. "-in", "{output}.cms", "-out", "{output}.txt" ],
  475. \&final_compare
  476. ],
  477. [ "enveloped content test streaming S/MIME format, DES, ECDH",
  478. [ "{cmd1}", @defaultprov, "-encrypt", "-in", $smcont,
  479. "-stream", "-out", "{output}.cms",
  480. "-recip", catfile($smdir, "smec1.pem") ],
  481. [ "{cmd2}", @defaultprov, "-decrypt", "-recip", catfile($smdir, "smec1.pem"),
  482. "-in", "{output}.cms", "-out", "{output}.txt" ],
  483. \&final_compare
  484. ],
  485. [ "enveloped content test streaming S/MIME format, DES, ECDH, 2 recipients, key only used",
  486. [ "{cmd1}", @defaultprov, "-encrypt", "-in", $smcont,
  487. "-stream", "-out", "{output}.cms",
  488. catfile($smdir, "smec1.pem"),
  489. catfile($smdir, "smec3.pem") ],
  490. [ "{cmd2}", @defaultprov, "-decrypt", "-inkey", catfile($smdir, "smec3.pem"),
  491. "-in", "{output}.cms", "-out", "{output}.txt" ],
  492. \&final_compare
  493. ],
  494. [ "enveloped content test streaming S/MIME format, ECDH, DES, key identifier",
  495. [ "{cmd1}", @defaultprov, "-encrypt", "-keyid", "-in", $smcont,
  496. "-stream", "-out", "{output}.cms",
  497. "-recip", catfile($smdir, "smec1.pem") ],
  498. [ "{cmd2}", @defaultprov, "-decrypt", "-recip", catfile($smdir, "smec1.pem"),
  499. "-in", "{output}.cms", "-out", "{output}.txt" ],
  500. \&final_compare
  501. ],
  502. [ "enveloped content test streaming S/MIME format, ECDH, AES-128-CBC, SHA256 KDF",
  503. [ "{cmd1}", @prov, "-encrypt", "-in", $smcont,
  504. "-stream", "-out", "{output}.cms",
  505. "-recip", catfile($smdir, "smec1.pem"), "-aes128",
  506. "-keyopt", "ecdh_kdf_md:sha256" ],
  507. [ "{cmd2}", @prov, "-decrypt", "-recip", catfile($smdir, "smec1.pem"),
  508. "-in", "{output}.cms", "-out", "{output}.txt" ],
  509. \&final_compare
  510. ],
  511. [ "enveloped content test streaming S/MIME format, ECDH, AES-128-GCM cipher, SHA256 KDF",
  512. [ "{cmd1}", @prov, "-encrypt", "-in", $smcont,
  513. "-stream", "-out", "{output}.cms",
  514. "-recip", catfile($smdir, "smec1.pem"), "-aes-128-gcm", "-keyopt", "ecdh_kdf_md:sha256" ],
  515. [ "{cmd2}", "-decrypt", "-recip", catfile($smdir, "smec1.pem"),
  516. "-in", "{output}.cms", "-out", "{output}.txt" ],
  517. \&final_compare
  518. ],
  519. [ "enveloped content test streaming S/MIME format, ECDH, K-283, cofactor DH",
  520. [ "{cmd1}", @prov, "-encrypt", "-in", $smcont,
  521. "-stream", "-out", "{output}.cms",
  522. "-recip", catfile($smdir, "smec2.pem"), "-aes128",
  523. "-keyopt", "ecdh_kdf_md:sha256", "-keyopt", "ecdh_cofactor_mode:1" ],
  524. [ "{cmd2}", @prov, "-decrypt", "-recip", catfile($smdir, "smec2.pem"),
  525. "-in", "{output}.cms", "-out", "{output}.txt" ],
  526. \&final_compare
  527. ],
  528. [ "enveloped content test streaming S/MIME format, X9.42 DH",
  529. [ "{cmd1}", @prov, "-encrypt", "-in", $smcont,
  530. "-stream", "-out", "{output}.cms",
  531. "-recip", catfile($smdir, "smdh.pem"), "-aes128" ],
  532. [ "{cmd2}", @prov, "-decrypt", "-recip", catfile($smdir, "smdh.pem"),
  533. "-in", "{output}.cms", "-out", "{output}.txt" ],
  534. \&final_compare
  535. ]
  536. );
  537. my @contenttype_cms_test = (
  538. [ "signed content test - check that content type is added to additional signerinfo, RSA keys",
  539. [ "{cmd1}", @prov, "-sign", "-binary", "-nodetach", "-stream", "-in", $smcont,
  540. "-outform", "DER", "-signer", $smrsa1, "-md", "SHA256",
  541. "-out", "{output}.cms" ],
  542. [ "{cmd1}", @prov, "-resign", "-binary", "-nodetach", "-in", "{output}.cms",
  543. "-inform", "DER", "-outform", "DER",
  544. "-signer", catfile($smdir, "smrsa2.pem"), "-md", "SHA256",
  545. "-out", "{output}2.cms" ],
  546. sub { my %opts = @_; contentType_matches("$opts{output}2.cms") == 2; },
  547. [ "{cmd2}", @prov, "-verify", "-in", "{output}2.cms", "-inform", "DER",
  548. "-CAfile", $smroot, "-out", "{output}.txt" ]
  549. ],
  550. );
  551. my @incorrect_attribute_cms_test = (
  552. "bad_signtime_attr.cms",
  553. "no_ct_attr.cms",
  554. "no_md_attr.cms",
  555. "ct_multiple_attr.cms"
  556. );
  557. # Runs a standard loop on the input array
  558. sub runner_loop {
  559. my %opts = ( @_ );
  560. my $cnt1 = 0;
  561. foreach (@{$opts{tests}}) {
  562. $cnt1++;
  563. $opts{output} = "$opts{prefix}-$cnt1";
  564. SKIP: {
  565. my $skip_reason = check_availability($$_[0]);
  566. skip $skip_reason, 1 if $skip_reason;
  567. my $ok = 1;
  568. 1 while unlink "$opts{output}.txt";
  569. foreach (@$_[1..$#$_]) {
  570. if (ref $_ eq 'CODE') {
  571. $ok &&= $_->(%opts);
  572. } else {
  573. my @cmd = map {
  574. my $x = $_;
  575. while ($x =~ /\{([^\}]+)\}/) {
  576. $x = $`.$opts{$1}.$' if exists $opts{$1};
  577. }
  578. $x;
  579. } @$_;
  580. diag "CMD: openssl ", join(" ", @cmd);
  581. $ok &&= run(app(["openssl", @cmd]));
  582. $opts{input} = $opts{output};
  583. }
  584. }
  585. ok($ok, $$_[0]);
  586. }
  587. }
  588. }
  589. sub final_compare {
  590. my %opts = @_;
  591. diag "Comparing $smcont with $opts{output}.txt";
  592. return compare_text($smcont, "$opts{output}.txt") == 0;
  593. }
  594. sub zero_compare {
  595. my %opts = @_;
  596. diag "Checking for zero-length file";
  597. return (-e "$opts{output}.txt" && -z "$opts{output}.txt");
  598. }
  599. subtest "CMS => PKCS#7 compatibility tests\n" => sub {
  600. plan tests => scalar @smime_pkcs7_tests;
  601. runner_loop(prefix => 'cms2pkcs7', cmd1 => 'cms', cmd2 => 'smime',
  602. tests => [ @smime_pkcs7_tests ]);
  603. };
  604. subtest "CMS <= PKCS#7 compatibility tests\n" => sub {
  605. plan tests => scalar @smime_pkcs7_tests;
  606. runner_loop(prefix => 'pkcs72cms', cmd1 => 'smime', cmd2 => 'cms',
  607. tests => [ @smime_pkcs7_tests ]);
  608. };
  609. subtest "CMS <=> CMS consistency tests\n" => sub {
  610. plan tests => (scalar @smime_pkcs7_tests) + (scalar @smime_cms_tests);
  611. runner_loop(prefix => 'cms2cms-1', cmd1 => 'cms', cmd2 => 'cms',
  612. tests => [ @smime_pkcs7_tests ]);
  613. runner_loop(prefix => 'cms2cms-2', cmd1 => 'cms', cmd2 => 'cms',
  614. tests => [ @smime_cms_tests ]);
  615. };
  616. subtest "CMS <=> CMS consistency tests, modified key parameters\n" => sub {
  617. plan tests =>
  618. (scalar @smime_cms_param_tests) + (scalar @smime_cms_comp_tests);
  619. runner_loop(prefix => 'cms2cms-mod', cmd1 => 'cms', cmd2 => 'cms',
  620. tests => [ @smime_cms_param_tests ]);
  621. SKIP: {
  622. skip("Zlib not supported: compression tests skipped",
  623. scalar @smime_cms_comp_tests)
  624. if $no_zlib;
  625. runner_loop(prefix => 'cms2cms-comp', cmd1 => 'cms', cmd2 => 'cms',
  626. tests => [ @smime_cms_comp_tests ]);
  627. }
  628. };
  629. # Returns the number of matches of a Content Type Attribute in a binary file.
  630. sub contentType_matches {
  631. # Read in a binary file
  632. my ($in) = @_;
  633. open (HEX_IN, "$in") or die("open failed for $in : $!");
  634. binmode(HEX_IN);
  635. local $/;
  636. my $str = <HEX_IN>;
  637. # Find ASN1 data for a Content Type Attribute (with a OID of PKCS7 data)
  638. 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;
  639. close(HEX_IN);
  640. return scalar(@c);
  641. }
  642. subtest "CMS Check the content type attribute is added for additional signers\n" => sub {
  643. plan tests => (scalar @contenttype_cms_test);
  644. runner_loop(prefix => 'cms2cms-added', cmd1 => 'cms', cmd2 => 'cms',
  645. tests => [ @contenttype_cms_test ]);
  646. };
  647. subtest "CMS Check that bad attributes fail when verifying signers\n" => sub {
  648. plan tests =>
  649. (scalar @incorrect_attribute_cms_test);
  650. my $cnt = 0;
  651. foreach my $name (@incorrect_attribute_cms_test) {
  652. my $out = "incorrect-$cnt.txt";
  653. ok(!run(app(["openssl", "cms", @prov, "-verify", "-in",
  654. catfile($datadir, $name), "-inform", "DER", "-CAfile",
  655. $smroot, "-out", $out ])),
  656. $name);
  657. }
  658. };
  659. subtest "CMS Decrypt message encrypted with OpenSSL 1.1.1\n" => sub {
  660. plan tests => 1;
  661. SKIP: {
  662. skip "EC or DES isn't supported in this build", 1
  663. if disabled("ec") || disabled("des");
  664. my $out = "smtst.txt";
  665. ok(run(app(["openssl", "cms", @defaultprov, "-decrypt",
  666. "-inkey", catfile($smdir, "smec3.pem"),
  667. "-in", catfile($datadir, "ciphertext_from_1_1_1.cms"),
  668. "-out", $out ]))
  669. && compare_text($smcont, $out) == 0,
  670. "Decrypt message from OpenSSL 1.1.1");
  671. }
  672. };
  673. subtest "CAdES <=> CAdES consistency tests\n" => sub {
  674. plan tests => (scalar @smime_cms_cades_tests);
  675. runner_loop(prefix => 'cms-cades', cmd1 => 'cms', cmd2 => 'cms',
  676. tests => [ @smime_cms_cades_tests ]);
  677. };
  678. subtest "CAdES; cms incompatible arguments tests\n" => sub {
  679. plan tests => (scalar @smime_cms_cades_invalid_option_tests);
  680. foreach (@smime_cms_cades_invalid_option_tests) {
  681. ok(!run(app(["openssl", "cms", @{$$_[0]} ] )));
  682. }
  683. };
  684. subtest "CAdES ko tests\n" => sub {
  685. plan tests => 2 * scalar @smime_cms_cades_ko_tests;
  686. foreach (@smime_cms_cades_ko_tests) {
  687. SKIP: {
  688. my $skip_reason = check_availability($$_[0]);
  689. skip $skip_reason, 1 if $skip_reason;
  690. ok(run(app(["openssl", "cms", @{$$_[1]}])), $$_[0]);
  691. ok(!run(app(["openssl", "cms", @{$$_[3]}])), $$_[2]);
  692. }
  693. }
  694. };
  695. subtest "CMS binary input tests\n" => sub {
  696. my $input = srctop_file("test", "smcont.bin");
  697. my $signed = "smcont.signed";
  698. my $verified = "smcont.verified";
  699. plan tests => 11;
  700. ok(run(app(["openssl", "cms", "-sign", "-md", "sha256", "-signer", $smrsa1,
  701. "-binary", "-in", $input, "-out", $signed])),
  702. "sign binary input with -binary");
  703. ok(run(app(["openssl", "cms", "-verify", "-CAfile", $smroot,
  704. "-binary", "-in", $signed, "-out", $verified])),
  705. "verify binary input with -binary");
  706. is(compare($input, $verified), 0, "binary input retained with -binary");
  707. ok(run(app(["openssl", "cms", "-sign", "-md", "sha256", "-signer", $smrsa1,
  708. "-in", $input, "-out", $signed.".nobin"])),
  709. "sign binary input without -binary");
  710. ok(run(app(["openssl", "cms", "-verify", "-CAfile", $smroot,
  711. "-in", $signed.".nobin", "-out", $verified.".nobin"])),
  712. "verify binary input without -binary");
  713. is(compare($input, $verified.".nobin"), 1, "binary input not retained without -binary");
  714. ok(!run(app(["openssl", "cms", "-verify", "-CAfile", $smroot, "-crlfeol",
  715. "-binary", "-in", $signed, "-out", $verified.".crlfeol"])),
  716. "verify binary input wrong crlfeol");
  717. ok(run(app(["openssl", "cms", "-sign", "-md", "sha256", "-signer", $smrsa1,
  718. "-crlfeol",
  719. "-binary", "-in", $input, "-out", $signed.".crlf"])),
  720. "sign binary input with -binary -crlfeol");
  721. ok(run(app(["openssl", "cms", "-verify", "-CAfile", $smroot, "-crlfeol",
  722. "-binary", "-in", $signed.".crlf", "-out", $verified.".crlf"])),
  723. "verify binary input with -binary -crlfeol");
  724. is(compare($input, $verified.".crlf"), 0,
  725. "binary input retained with -binary -crlfeol");
  726. ok(!run(app(["openssl", "cms", "-verify", "-CAfile", $smroot,
  727. "-binary", "-in", $signed.".crlf", "-out", $verified.".crlf2"])),
  728. "verify binary input with -binary missing -crlfeol");
  729. };
  730. subtest "CMS signed digest, DER format" => sub {
  731. plan tests => 2;
  732. # Pre-computed SHA256 digest of $smcont in hexadecimal form
  733. my $digest = "ff236ef61b396355f75a4cc6e1c306d4c309084ae271a9e2ad6888f10a101b32";
  734. my $sig_file = "signature.der";
  735. ok(run(app(["openssl", "cms", @prov, "-sign", "-digest", $digest,
  736. "-outform", "DER",
  737. "-certfile", catfile($smdir, "smroot.pem"),
  738. "-signer", catfile($smdir, "smrsa1.pem"),
  739. "-out", $sig_file])),
  740. "CMS sign pre-computed digest, DER format");
  741. ok(run(app(["openssl", "cms", @prov, "-verify", "-in", $sig_file,
  742. "-inform", "DER",
  743. "-CAfile", catfile($smdir, "smroot.pem"),
  744. "-content", $smcont])),
  745. "Verify CMS signed digest, DER format");
  746. };
  747. subtest "CMS signed digest, S/MIME format" => sub {
  748. plan tests => 2;
  749. # Pre-computed SHA256 digest of $smcont in hexadecimal form
  750. my $digest = "ff236ef61b396355f75a4cc6e1c306d4c309084ae271a9e2ad6888f10a101b32";
  751. my $sig_file = "signature.smime";
  752. ok(run(app(["openssl", "cms", @prov, "-sign", "-digest", $digest,
  753. "-outform", "SMIME",
  754. "-certfile", catfile($smdir, "smroot.pem"),
  755. "-signer", catfile($smdir, "smrsa1.pem"),
  756. "-out", $sig_file])),
  757. "CMS sign pre-computed digest, S/MIME format");
  758. ok(run(app(["openssl", "cms", @prov, "-verify", "-in", $sig_file,
  759. "-inform", "SMIME",
  760. "-CAfile", catfile($smdir, "smroot.pem"),
  761. "-content", $smcont])),
  762. "Verify CMS signed digest, S/MIME format");
  763. };
  764. subtest "CMS code signing test" => sub {
  765. plan tests => 7;
  766. my $sig_file = "signature.p7s";
  767. ok(run(app(["openssl", "cms", @prov, "-sign", "-in", $smcont,
  768. "-certfile", catfile($smdir, "smroot.pem"),
  769. "-signer", catfile($smdir, "smrsa1.pem"),
  770. "-out", $sig_file])),
  771. "accept perform CMS signature with smime certificate");
  772. ok(run(app(["openssl", "cms", @prov, "-verify", "-in", $sig_file,
  773. "-CAfile", catfile($smdir, "smroot.pem"),
  774. "-content", $smcont])),
  775. "accept verify CMS signature with smime certificate");
  776. ok(!run(app(["openssl", "cms", @prov, "-verify", "-in", $sig_file,
  777. "-CAfile", catfile($smdir, "smroot.pem"),
  778. "-purpose", "codesign",
  779. "-content", $smcont])),
  780. "fail verify CMS signature with smime certificate for purpose code signing");
  781. ok(!run(app(["openssl", "cms", @prov, "-verify", "-in", $sig_file,
  782. "-CAfile", catfile($smdir, "smroot.pem"),
  783. "-purpose", "football",
  784. "-content", $smcont])),
  785. "fail verify CMS signature with invalid purpose argument");
  786. ok(run(app(["openssl", "cms", @prov, "-sign", "-in", $smcont,
  787. "-certfile", catfile($smdir, "smroot.pem"),
  788. "-signer", catfile($smdir, "csrsa1.pem"),
  789. "-out", $sig_file])),
  790. "accept perform CMS signature with code signing certificate");
  791. ok(run(app(["openssl", "cms", @prov, "-verify", "-in", $sig_file,
  792. "-CAfile", catfile($smdir, "smroot.pem"),
  793. "-purpose", "codesign",
  794. "-content", $smcont])),
  795. "accept verify CMS signature with code signing certificate for purpose code signing");
  796. ok(!run(app(["openssl", "cms", @prov, "-verify", "-in", $sig_file,
  797. "-CAfile", catfile($smdir, "smroot.pem"),
  798. "-content", $smcont])),
  799. "fail verify CMS signature with code signing certificate for purpose smime_sign");
  800. };
  801. sub check_availability {
  802. my $tnam = shift;
  803. return "$tnam: skipped, EC disabled\n"
  804. if ($no_ec && $tnam =~ /ECDH/);
  805. return "$tnam: skipped, ECDH disabled\n"
  806. if ($no_ec && $tnam =~ /ECDH/);
  807. return "$tnam: skipped, EC2M disabled\n"
  808. if ($no_ec2m && $tnam =~ /K-283/);
  809. return "$tnam: skipped, DH disabled\n"
  810. if ($no_dh && $tnam =~ /X9\.42/);
  811. return "$tnam: skipped, RC2 disabled\n"
  812. if ($no_rc2 && $tnam =~ /RC2/);
  813. return "$tnam: skipped, DES disabled\n"
  814. if ($no_des && $tnam =~ /DES/);
  815. return "$tnam: skipped, DSA disabled\n"
  816. if ($no_dsa && $tnam =~ / DSA/);
  817. return "";
  818. }