cms-test.pl 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. # test/cms-test.pl
  2. # Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
  3. # project.
  4. #
  5. # ====================================================================
  6. # Copyright (c) 2008 The OpenSSL Project. All rights reserved.
  7. #
  8. # Redistribution and use in source and binary forms, with or without
  9. # modification, are permitted provided that the following conditions
  10. # are met:
  11. #
  12. # 1. Redistributions of source code must retain the above copyright
  13. # notice, this list of conditions and the following disclaimer.
  14. #
  15. # 2. Redistributions in binary form must reproduce the above copyright
  16. # notice, this list of conditions and the following disclaimer in
  17. # the documentation and/or other materials provided with the
  18. # distribution.
  19. #
  20. # 3. All advertising materials mentioning features or use of this
  21. # software must display the following acknowledgment:
  22. # "This product includes software developed by the OpenSSL Project
  23. # for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
  24. #
  25. # 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
  26. # endorse or promote products derived from this software without
  27. # prior written permission. For written permission, please contact
  28. # licensing@OpenSSL.org.
  29. #
  30. # 5. Products derived from this software may not be called "OpenSSL"
  31. # nor may "OpenSSL" appear in their names without prior written
  32. # permission of the OpenSSL Project.
  33. #
  34. # 6. Redistributions of any form whatsoever must retain the following
  35. # acknowledgment:
  36. # "This product includes software developed by the OpenSSL Project
  37. # for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
  38. #
  39. # THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
  40. # EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  41. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  42. # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
  43. # ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  44. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  45. # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  46. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  47. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  48. # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  49. # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  50. # OF THE POSSIBILITY OF SUCH DAMAGE.
  51. # ====================================================================
  52. # CMS, PKCS7 consistency test script. Run extensive tests on
  53. # OpenSSL PKCS#7 and CMS implementations.
  54. my $ossl_path;
  55. my $redir = " 2> cms.err > cms.out";
  56. # Make VMS work
  57. if ( $^O eq "VMS" && -f "OSSLX:openssl.exe" ) {
  58. $ossl_path = "pipe mcr OSSLX:openssl";
  59. $null_path = "NL:";
  60. # On VMS, the lowest 3 bits of the exit code indicates severity
  61. # 1 is success (perl translates it to 0 for $?), 2 is error
  62. # (perl doesn't translate it)
  63. $failure_code = 512; # 2 << 8 = 512
  64. }
  65. # Make MSYS work
  66. elsif ( $^O eq "MSWin32" && -f "../apps/openssl.exe" ) {
  67. $ossl_path = "cmd /c ..\\apps\\openssl";
  68. $null_path = "NUL";
  69. $failure_code = 256;
  70. }
  71. elsif ( -f "../apps/openssl$ENV{EXE_EXT}" ) {
  72. $ossl_path = "../util/shlib_wrap.sh ../apps/openssl";
  73. $null_path = "/dev/null";
  74. $failure_code = 256;
  75. }
  76. elsif ( -f "..\\out32dll\\openssl.exe" ) {
  77. $ossl_path = "..\\out32dll\\openssl.exe";
  78. $null_path = "NUL";
  79. $failure_code = 256;
  80. }
  81. elsif ( -f "..\\out32\\openssl.exe" ) {
  82. $ossl_path = "..\\out32\\openssl.exe";
  83. $null_path = "NUL";
  84. $failure_code = 256;
  85. }
  86. else {
  87. die "Can't find OpenSSL executable";
  88. }
  89. my $pk7cmd = "$ossl_path smime ";
  90. my $cmscmd = "$ossl_path cms ";
  91. my $smdir = "smime-certs";
  92. my $halt_err = 1;
  93. my $badcmd = 0;
  94. my $no_ec;
  95. my $no_ec2m;
  96. my $no_ecdh;
  97. my $ossl8 = `$ossl_path version -v` =~ /0\.9\.8/;
  98. system ("$ossl_path no-ec > $null_path");
  99. if ($? == 0)
  100. {
  101. $no_ec = 1;
  102. }
  103. elsif ($? == $failure_code)
  104. {
  105. $no_ec = 0;
  106. }
  107. else
  108. {
  109. die "Error checking for EC support\n";
  110. }
  111. system ("$ossl_path no-ec2m > $null_path");
  112. if ($? == 0)
  113. {
  114. $no_ec2m = 1;
  115. }
  116. elsif ($? == $failure_code)
  117. {
  118. $no_ec2m = 0;
  119. }
  120. else
  121. {
  122. die "Error checking for EC2M support\n";
  123. }
  124. system ("$ossl_path no-ec > $null_path");
  125. if ($? == 0)
  126. {
  127. $no_ecdh = 1;
  128. }
  129. elsif ($? == $failure_code)
  130. {
  131. $no_ecdh = 0;
  132. }
  133. else
  134. {
  135. die "Error checking for ECDH support\n";
  136. }
  137. my @smime_pkcs7_tests = (
  138. [
  139. "signed content DER format, RSA key",
  140. "-sign -in smcont.txt -outform \"DER\" -nodetach"
  141. . " -certfile $smdir/smroot.pem"
  142. . " -signer $smdir/smrsa1.pem -out test.cms",
  143. "-verify -in test.cms -inform \"DER\" "
  144. . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
  145. ],
  146. [
  147. "signed detached content DER format, RSA key",
  148. "-sign -in smcont.txt -outform \"DER\""
  149. . " -signer $smdir/smrsa1.pem -out test.cms",
  150. "-verify -in test.cms -inform \"DER\" "
  151. . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt -content smcont.txt"
  152. ],
  153. [
  154. "signed content test streaming BER format, RSA",
  155. "-sign -in smcont.txt -outform \"DER\" -nodetach"
  156. . " -stream -signer $smdir/smrsa1.pem -out test.cms",
  157. "-verify -in test.cms -inform \"DER\" "
  158. . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
  159. ],
  160. [
  161. "signed content DER format, DSA key",
  162. "-sign -in smcont.txt -outform \"DER\" -nodetach"
  163. . " -signer $smdir/smdsa1.pem -out test.cms",
  164. "-verify -in test.cms -inform \"DER\" "
  165. . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
  166. ],
  167. [
  168. "signed detached content DER format, DSA key",
  169. "-sign -in smcont.txt -outform \"DER\""
  170. . " -signer $smdir/smdsa1.pem -out test.cms",
  171. "-verify -in test.cms -inform \"DER\" "
  172. . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt -content smcont.txt"
  173. ],
  174. [
  175. "signed detached content DER format, add RSA signer",
  176. "-resign -inform \"DER\" -in test.cms -outform \"DER\""
  177. . " -signer $smdir/smrsa1.pem -out test2.cms",
  178. "-verify -in test2.cms -inform \"DER\" "
  179. . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt -content smcont.txt"
  180. ],
  181. [
  182. "signed content test streaming BER format, DSA key",
  183. "-sign -in smcont.txt -outform \"DER\" -nodetach"
  184. . " -stream -signer $smdir/smdsa1.pem -out test.cms",
  185. "-verify -in test.cms -inform \"DER\" "
  186. . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
  187. ],
  188. [
  189. "signed content test streaming BER format, 2 DSA and 2 RSA keys",
  190. "-sign -in smcont.txt -outform \"DER\" -nodetach"
  191. . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
  192. . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
  193. . " -stream -out test.cms",
  194. "-verify -in test.cms -inform \"DER\" "
  195. . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
  196. ],
  197. [
  198. "signed content test streaming BER format, 2 DSA and 2 RSA keys, no attributes",
  199. "-sign -in smcont.txt -outform \"DER\" -noattr -nodetach"
  200. . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
  201. . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
  202. . " -stream -out test.cms",
  203. "-verify -in test.cms -inform \"DER\" "
  204. . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
  205. ],
  206. [
  207. "signed content test streaming S/MIME format, 2 DSA and 2 RSA keys",
  208. "-sign -in smcont.txt -nodetach"
  209. . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
  210. . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
  211. . " -stream -out test.cms",
  212. "-verify -in test.cms " . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
  213. ],
  214. [
  215. "signed content test streaming multipart S/MIME format, 2 DSA and 2 RSA keys",
  216. "-sign -in smcont.txt"
  217. . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
  218. . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
  219. . " -stream -out test.cms",
  220. "-verify -in test.cms " . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
  221. ],
  222. [
  223. "enveloped content test streaming S/MIME format, 3 recipients",
  224. "-encrypt -in smcont.txt"
  225. . " -stream -out test.cms"
  226. . " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ",
  227. "-decrypt -recip $smdir/smrsa1.pem -in test.cms -out smtst.txt"
  228. ],
  229. [
  230. "enveloped content test streaming S/MIME format, 3 recipients, 3rd used",
  231. "-encrypt -in smcont.txt"
  232. . " -stream -out test.cms"
  233. . " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ",
  234. "-decrypt -recip $smdir/smrsa3.pem -in test.cms -out smtst.txt"
  235. ],
  236. [
  237. "enveloped content test streaming S/MIME format, 3 recipients, key only used",
  238. "-encrypt -in smcont.txt"
  239. . " -stream -out test.cms"
  240. . " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ",
  241. "-decrypt -inkey $smdir/smrsa3.pem -in test.cms -out smtst.txt"
  242. ],
  243. [
  244. "enveloped content test streaming S/MIME format, AES-256 cipher, 3 recipients",
  245. "-encrypt -in smcont.txt"
  246. . " -aes256 -stream -out test.cms"
  247. . " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ",
  248. "-decrypt -recip $smdir/smrsa1.pem -in test.cms -out smtst.txt"
  249. ],
  250. );
  251. my @smime_cms_tests = (
  252. [
  253. "signed content test streaming BER format, 2 DSA and 2 RSA keys, keyid",
  254. "-sign -in smcont.txt -outform \"DER\" -nodetach -keyid"
  255. . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
  256. . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
  257. . " -stream -out test.cms",
  258. "-verify -in test.cms -inform \"DER\" "
  259. . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
  260. ],
  261. [
  262. "signed content test streaming PEM format, 2 DSA and 2 RSA keys",
  263. "-sign -in smcont.txt -outform PEM -nodetach"
  264. . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
  265. . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
  266. . " -stream -out test.cms",
  267. "-verify -in test.cms -inform PEM "
  268. . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
  269. ],
  270. [
  271. "signed content MIME format, RSA key, signed receipt request",
  272. "-sign -in smcont.txt -signer $smdir/smrsa1.pem -nodetach"
  273. . " -receipt_request_to test\@openssl.org -receipt_request_all"
  274. . " -out test.cms",
  275. "-verify -in test.cms "
  276. . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
  277. ],
  278. [
  279. "signed receipt MIME format, RSA key",
  280. "-sign_receipt -in test.cms"
  281. . " -signer $smdir/smrsa2.pem"
  282. . " -out test2.cms",
  283. "-verify_receipt test2.cms -in test.cms"
  284. . " \"-CAfile\" $smdir/smroot.pem"
  285. ],
  286. [
  287. "enveloped content test streaming S/MIME format, 3 recipients, keyid",
  288. "-encrypt -in smcont.txt"
  289. . " -stream -out test.cms -keyid"
  290. . " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ",
  291. "-decrypt -recip $smdir/smrsa1.pem -in test.cms -out smtst.txt"
  292. ],
  293. [
  294. "enveloped content test streaming PEM format, KEK",
  295. "-encrypt -in smcont.txt -outform PEM -aes128"
  296. . " -stream -out test.cms "
  297. . " -secretkey 000102030405060708090A0B0C0D0E0F "
  298. . " -secretkeyid C0FEE0",
  299. "-decrypt -in test.cms -out smtst.txt -inform PEM"
  300. . " -secretkey 000102030405060708090A0B0C0D0E0F "
  301. . " -secretkeyid C0FEE0"
  302. ],
  303. [
  304. "enveloped content test streaming PEM format, KEK, key only",
  305. "-encrypt -in smcont.txt -outform PEM -aes128"
  306. . " -stream -out test.cms "
  307. . " -secretkey 000102030405060708090A0B0C0D0E0F "
  308. . " -secretkeyid C0FEE0",
  309. "-decrypt -in test.cms -out smtst.txt -inform PEM"
  310. . " -secretkey 000102030405060708090A0B0C0D0E0F "
  311. ],
  312. [
  313. "data content test streaming PEM format",
  314. "-data_create -in smcont.txt -outform PEM -nodetach"
  315. . " -stream -out test.cms",
  316. "-data_out -in test.cms -inform PEM -out smtst.txt"
  317. ],
  318. [
  319. "encrypted content test streaming PEM format, 128 bit RC2 key",
  320. "\"-EncryptedData_encrypt\" -in smcont.txt -outform PEM"
  321. . " -rc2 -secretkey 000102030405060708090A0B0C0D0E0F"
  322. . " -stream -out test.cms",
  323. "\"-EncryptedData_decrypt\" -in test.cms -inform PEM "
  324. . " -secretkey 000102030405060708090A0B0C0D0E0F -out smtst.txt"
  325. ],
  326. [
  327. "encrypted content test streaming PEM format, 40 bit RC2 key",
  328. "\"-EncryptedData_encrypt\" -in smcont.txt -outform PEM"
  329. . " -rc2 -secretkey 0001020304"
  330. . " -stream -out test.cms",
  331. "\"-EncryptedData_decrypt\" -in test.cms -inform PEM "
  332. . " -secretkey 0001020304 -out smtst.txt"
  333. ],
  334. [
  335. "encrypted content test streaming PEM format, triple DES key",
  336. "\"-EncryptedData_encrypt\" -in smcont.txt -outform PEM"
  337. . " -des3 -secretkey 000102030405060708090A0B0C0D0E0F1011121314151617"
  338. . " -stream -out test.cms",
  339. "\"-EncryptedData_decrypt\" -in test.cms -inform PEM "
  340. . " -secretkey 000102030405060708090A0B0C0D0E0F1011121314151617"
  341. . " -out smtst.txt"
  342. ],
  343. [
  344. "encrypted content test streaming PEM format, 128 bit AES key",
  345. "\"-EncryptedData_encrypt\" -in smcont.txt -outform PEM"
  346. . " -aes128 -secretkey 000102030405060708090A0B0C0D0E0F"
  347. . " -stream -out test.cms",
  348. "\"-EncryptedData_decrypt\" -in test.cms -inform PEM "
  349. . " -secretkey 000102030405060708090A0B0C0D0E0F -out smtst.txt"
  350. ],
  351. );
  352. my @smime_cms_comp_tests = (
  353. [
  354. "compressed content test streaming PEM format",
  355. "-compress -in smcont.txt -outform PEM -nodetach"
  356. . " -stream -out test.cms",
  357. "-uncompress -in test.cms -inform PEM -out smtst.txt"
  358. ]
  359. );
  360. my @smime_cms_param_tests = (
  361. [
  362. "signed content test streaming PEM format, RSA keys, PSS signature",
  363. "-sign -in smcont.txt -outform PEM -nodetach"
  364. . " -signer $smdir/smrsa1.pem -keyopt rsa_padding_mode:pss"
  365. . " -out test.cms",
  366. "-verify -in test.cms -inform PEM "
  367. . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
  368. ],
  369. [
  370. "signed content test streaming PEM format, RSA keys, PSS signature, no attributes",
  371. "-sign -in smcont.txt -outform PEM -nodetach -noattr"
  372. . " -signer $smdir/smrsa1.pem -keyopt rsa_padding_mode:pss"
  373. . " -out test.cms",
  374. "-verify -in test.cms -inform PEM "
  375. . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
  376. ],
  377. [
  378. "signed content test streaming PEM format, RSA keys, PSS signature, SHA384 MGF1",
  379. "-sign -in smcont.txt -outform PEM -nodetach"
  380. . " -signer $smdir/smrsa1.pem -keyopt rsa_padding_mode:pss"
  381. . " -keyopt rsa_mgf1_md:sha384 -out test.cms",
  382. "-verify -in test.cms -inform PEM "
  383. . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
  384. ],
  385. [
  386. "enveloped content test streaming S/MIME format, OAEP default parameters",
  387. "-encrypt -in smcont.txt"
  388. . " -stream -out test.cms"
  389. . " -recip $smdir/smrsa1.pem -keyopt rsa_padding_mode:oaep",
  390. "-decrypt -recip $smdir/smrsa1.pem -in test.cms -out smtst.txt"
  391. ],
  392. [
  393. "enveloped content test streaming S/MIME format, OAEP SHA256",
  394. "-encrypt -in smcont.txt"
  395. . " -stream -out test.cms"
  396. . " -recip $smdir/smrsa1.pem -keyopt rsa_padding_mode:oaep"
  397. . " -keyopt rsa_oaep_md:sha256",
  398. "-decrypt -recip $smdir/smrsa1.pem -in test.cms -out smtst.txt"
  399. ],
  400. [
  401. "enveloped content test streaming S/MIME format, ECDH",
  402. "-encrypt -in smcont.txt"
  403. . " -stream -out test.cms"
  404. . " -recip $smdir/smec1.pem",
  405. "-decrypt -recip $smdir/smec1.pem -in test.cms -out smtst.txt"
  406. ],
  407. [
  408. "enveloped content test streaming S/MIME format, ECDH, key identifier",
  409. "-encrypt -keyid -in smcont.txt"
  410. . " -stream -out test.cms"
  411. . " -recip $smdir/smec1.pem",
  412. "-decrypt -recip $smdir/smec1.pem -in test.cms -out smtst.txt"
  413. ],
  414. [
  415. "enveloped content test streaming S/MIME format, ECDH, AES128, SHA256 KDF",
  416. "-encrypt -in smcont.txt"
  417. . " -stream -out test.cms"
  418. . " -recip $smdir/smec1.pem -aes128 -keyopt ecdh_kdf_md:sha256",
  419. "-decrypt -recip $smdir/smec1.pem -in test.cms -out smtst.txt"
  420. ],
  421. [
  422. "enveloped content test streaming S/MIME format, ECDH, K-283, cofactor DH",
  423. "-encrypt -in smcont.txt"
  424. . " -stream -out test.cms"
  425. . " -recip $smdir/smec2.pem -aes128"
  426. . " -keyopt ecdh_kdf_md:sha256 -keyopt ecdh_cofactor_mode:1",
  427. "-decrypt -recip $smdir/smec2.pem -in test.cms -out smtst.txt"
  428. ],
  429. [
  430. "enveloped content test streaming S/MIME format, X9.42 DH",
  431. "-encrypt -in smcont.txt"
  432. . " -stream -out test.cms"
  433. . " -recip $smdir/smdh.pem -aes128",
  434. "-decrypt -recip $smdir/smdh.pem -in test.cms -out smtst.txt"
  435. ]
  436. );
  437. print "CMS => PKCS#7 compatibility tests\n";
  438. run_smime_tests( \$badcmd, \@smime_pkcs7_tests, $cmscmd, $pk7cmd );
  439. print "CMS <= PKCS#7 compatibility tests\n";
  440. run_smime_tests( \$badcmd, \@smime_pkcs7_tests, $pk7cmd, $cmscmd );
  441. print "CMS <=> CMS consistency tests\n";
  442. run_smime_tests( \$badcmd, \@smime_pkcs7_tests, $cmscmd, $cmscmd );
  443. run_smime_tests( \$badcmd, \@smime_cms_tests, $cmscmd, $cmscmd );
  444. print "CMS <=> CMS consistency tests, modified key parameters\n";
  445. run_smime_tests( \$badcmd, \@smime_cms_param_tests, $cmscmd, $cmscmd );
  446. if ( `$ossl_path version -f` =~ /ZLIB/ ) {
  447. run_smime_tests( \$badcmd, \@smime_cms_comp_tests, $cmscmd, $cmscmd );
  448. }
  449. else {
  450. print "Zlib not supported: compression tests skipped\n";
  451. }
  452. print "Running modified tests for OpenSSL 0.9.8 cms backport\n" if($ossl8);
  453. if ($badcmd) {
  454. print "$badcmd TESTS FAILED!!\n";
  455. }
  456. else {
  457. print "ALL TESTS SUCCESSFUL.\n";
  458. }
  459. unlink "test.cms";
  460. unlink "test2.cms";
  461. unlink "smtst.txt";
  462. unlink "cms.out";
  463. unlink "cms.err";
  464. sub run_smime_tests {
  465. my ( $rv, $aref, $scmd, $vcmd ) = @_;
  466. foreach $smtst (@$aref) {
  467. my ( $tnam, $rscmd, $rvcmd ) = @$smtst;
  468. if ($ossl8)
  469. {
  470. # Skip smime resign: 0.9.8 smime doesn't support -resign
  471. next if ($scmd =~ /smime/ && $rscmd =~ /-resign/);
  472. # Disable streaming: option not supported in 0.9.8
  473. $tnam =~ s/streaming//;
  474. $rscmd =~ s/-stream//;
  475. $rvcmd =~ s/-stream//;
  476. }
  477. if ($no_ec && $tnam =~ /ECDH/)
  478. {
  479. print "$tnam: skipped, EC disabled\n";
  480. next;
  481. }
  482. if ($no_ecdh && $tnam =~ /ECDH/)
  483. {
  484. print "$tnam: skipped, ECDH disabled\n";
  485. next;
  486. }
  487. if ($no_ec2m && $tnam =~ /K-283/)
  488. {
  489. print "$tnam: skipped, EC2M disabled\n";
  490. next;
  491. }
  492. system("$scmd$rscmd$redir");
  493. if ($?) {
  494. print "$tnam: generation error\n";
  495. $$rv++;
  496. exit 1 if $halt_err;
  497. next;
  498. }
  499. system("$vcmd$rvcmd$redir");
  500. if ($?) {
  501. print "$tnam: verify error\n";
  502. $$rv++;
  503. exit 1 if $halt_err;
  504. next;
  505. }
  506. if (!cmp_files("smtst.txt", "smcont.txt")) {
  507. print "$tnam: content verify error\n";
  508. $$rv++;
  509. exit 1 if $halt_err;
  510. next;
  511. }
  512. print "$tnam: OK\n";
  513. }
  514. }
  515. sub cmp_files {
  516. use FileHandle;
  517. my ( $f1, $f2 ) = @_;
  518. my $fp1 = FileHandle->new();
  519. my $fp2 = FileHandle->new();
  520. my ( $rd1, $rd2 );
  521. if ( !open( $fp1, "<$f1" ) ) {
  522. print STDERR "Can't Open file $f1\n";
  523. return 0;
  524. }
  525. if ( !open( $fp2, "<$f2" ) ) {
  526. print STDERR "Can't Open file $f2\n";
  527. return 0;
  528. }
  529. binmode $fp1;
  530. binmode $fp2;
  531. my $ret = 0;
  532. for ( ; ; ) {
  533. $n1 = sysread $fp1, $rd1, 4096;
  534. $n2 = sysread $fp2, $rd2, 4096;
  535. last if ( $n1 != $n2 );
  536. last if ( $rd1 ne $rd2 );
  537. if ( $n1 == 0 ) {
  538. $ret = 1;
  539. last;
  540. }
  541. }
  542. close $fp1;
  543. close $fp2;
  544. return $ret;
  545. }