cms-test.pl 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  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-cms > $null_path");
  99. if ($? == 0)
  100. {
  101. print "CMS disabled\n";
  102. exit 0;
  103. }
  104. system ("$ossl_path no-ec > $null_path");
  105. if ($? == 0)
  106. {
  107. $no_ec = 1;
  108. }
  109. elsif ($? == $failure_code)
  110. {
  111. $no_ec = 0;
  112. }
  113. else
  114. {
  115. die "Error checking for EC support\n";
  116. }
  117. system ("$ossl_path no-ec2m > $null_path");
  118. if ($? == 0)
  119. {
  120. $no_ec2m = 1;
  121. }
  122. elsif ($? == $failure_code)
  123. {
  124. $no_ec2m = 0;
  125. }
  126. else
  127. {
  128. die "Error checking for EC2M support\n";
  129. }
  130. system ("$ossl_path no-ec > $null_path");
  131. if ($? == 0)
  132. {
  133. $no_ecdh = 1;
  134. }
  135. elsif ($? == $failure_code)
  136. {
  137. $no_ecdh = 0;
  138. }
  139. else
  140. {
  141. die "Error checking for ECDH support\n";
  142. }
  143. my @smime_pkcs7_tests = (
  144. [
  145. "signed content DER format, RSA key",
  146. "-sign -in smcont.txt -outform \"DER\" -nodetach"
  147. . " -certfile $smdir/smroot.pem"
  148. . " -signer $smdir/smrsa1.pem -out test.cms",
  149. "-verify -in test.cms -inform \"DER\" "
  150. . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
  151. ],
  152. [
  153. "signed detached content DER format, RSA key",
  154. "-sign -in smcont.txt -outform \"DER\""
  155. . " -signer $smdir/smrsa1.pem -out test.cms",
  156. "-verify -in test.cms -inform \"DER\" "
  157. . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt -content smcont.txt"
  158. ],
  159. [
  160. "signed content test streaming BER format, RSA",
  161. "-sign -in smcont.txt -outform \"DER\" -nodetach"
  162. . " -stream -signer $smdir/smrsa1.pem -out test.cms",
  163. "-verify -in test.cms -inform \"DER\" "
  164. . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
  165. ],
  166. [
  167. "signed content DER format, DSA key",
  168. "-sign -in smcont.txt -outform \"DER\" -nodetach"
  169. . " -signer $smdir/smdsa1.pem -out test.cms",
  170. "-verify -in test.cms -inform \"DER\" "
  171. . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
  172. ],
  173. [
  174. "signed detached content DER format, DSA key",
  175. "-sign -in smcont.txt -outform \"DER\""
  176. . " -signer $smdir/smdsa1.pem -out test.cms",
  177. "-verify -in test.cms -inform \"DER\" "
  178. . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt -content smcont.txt"
  179. ],
  180. [
  181. "signed detached content DER format, add RSA signer",
  182. "-resign -inform \"DER\" -in test.cms -outform \"DER\""
  183. . " -signer $smdir/smrsa1.pem -out test2.cms",
  184. "-verify -in test2.cms -inform \"DER\" "
  185. . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt -content smcont.txt"
  186. ],
  187. [
  188. "signed content test streaming BER format, DSA key",
  189. "-sign -in smcont.txt -outform \"DER\" -nodetach"
  190. . " -stream -signer $smdir/smdsa1.pem -out test.cms",
  191. "-verify -in test.cms -inform \"DER\" "
  192. . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
  193. ],
  194. [
  195. "signed content test streaming BER format, 2 DSA and 2 RSA keys",
  196. "-sign -in smcont.txt -outform \"DER\" -nodetach"
  197. . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
  198. . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
  199. . " -stream -out test.cms",
  200. "-verify -in test.cms -inform \"DER\" "
  201. . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
  202. ],
  203. [
  204. "signed content test streaming BER format, 2 DSA and 2 RSA keys, no attributes",
  205. "-sign -in smcont.txt -outform \"DER\" -noattr -nodetach"
  206. . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
  207. . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
  208. . " -stream -out test.cms",
  209. "-verify -in test.cms -inform \"DER\" "
  210. . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
  211. ],
  212. [
  213. "signed content test streaming S/MIME format, 2 DSA and 2 RSA keys",
  214. "-sign -in smcont.txt -nodetach"
  215. . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
  216. . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
  217. . " -stream -out test.cms",
  218. "-verify -in test.cms " . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
  219. ],
  220. [
  221. "signed content test streaming multipart S/MIME format, 2 DSA and 2 RSA keys",
  222. "-sign -in smcont.txt"
  223. . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
  224. . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
  225. . " -stream -out test.cms",
  226. "-verify -in test.cms " . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
  227. ],
  228. [
  229. "enveloped content test streaming S/MIME format, 3 recipients",
  230. "-encrypt -in smcont.txt"
  231. . " -stream -out test.cms"
  232. . " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ",
  233. "-decrypt -recip $smdir/smrsa1.pem -in test.cms -out smtst.txt"
  234. ],
  235. [
  236. "enveloped content test streaming S/MIME format, 3 recipients, 3rd used",
  237. "-encrypt -in smcont.txt"
  238. . " -stream -out test.cms"
  239. . " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ",
  240. "-decrypt -recip $smdir/smrsa3.pem -in test.cms -out smtst.txt"
  241. ],
  242. [
  243. "enveloped content test streaming S/MIME format, 3 recipients, key only used",
  244. "-encrypt -in smcont.txt"
  245. . " -stream -out test.cms"
  246. . " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ",
  247. "-decrypt -inkey $smdir/smrsa3.pem -in test.cms -out smtst.txt"
  248. ],
  249. [
  250. "enveloped content test streaming S/MIME format, AES-256 cipher, 3 recipients",
  251. "-encrypt -in smcont.txt"
  252. . " -aes256 -stream -out test.cms"
  253. . " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ",
  254. "-decrypt -recip $smdir/smrsa1.pem -in test.cms -out smtst.txt"
  255. ],
  256. );
  257. my @smime_cms_tests = (
  258. [
  259. "signed content test streaming BER format, 2 DSA and 2 RSA keys, keyid",
  260. "-sign -in smcont.txt -outform \"DER\" -nodetach -keyid"
  261. . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
  262. . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
  263. . " -stream -out test.cms",
  264. "-verify -in test.cms -inform \"DER\" "
  265. . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
  266. ],
  267. [
  268. "signed content test streaming PEM format, 2 DSA and 2 RSA keys",
  269. "-sign -in smcont.txt -outform PEM -nodetach"
  270. . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
  271. . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
  272. . " -stream -out test.cms",
  273. "-verify -in test.cms -inform PEM "
  274. . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
  275. ],
  276. [
  277. "signed content MIME format, RSA key, signed receipt request",
  278. "-sign -in smcont.txt -signer $smdir/smrsa1.pem -nodetach"
  279. . " -receipt_request_to test\@openssl.org -receipt_request_all"
  280. . " -out test.cms",
  281. "-verify -in test.cms "
  282. . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
  283. ],
  284. [
  285. "signed receipt MIME format, RSA key",
  286. "-sign_receipt -in test.cms"
  287. . " -signer $smdir/smrsa2.pem"
  288. . " -out test2.cms",
  289. "-verify_receipt test2.cms -in test.cms"
  290. . " \"-CAfile\" $smdir/smroot.pem"
  291. ],
  292. [
  293. "enveloped content test streaming S/MIME format, 3 recipients, keyid",
  294. "-encrypt -in smcont.txt"
  295. . " -stream -out test.cms -keyid"
  296. . " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ",
  297. "-decrypt -recip $smdir/smrsa1.pem -in test.cms -out smtst.txt"
  298. ],
  299. [
  300. "enveloped content test streaming PEM format, KEK",
  301. "-encrypt -in smcont.txt -outform PEM -aes128"
  302. . " -stream -out test.cms "
  303. . " -secretkey 000102030405060708090A0B0C0D0E0F "
  304. . " -secretkeyid C0FEE0",
  305. "-decrypt -in test.cms -out smtst.txt -inform PEM"
  306. . " -secretkey 000102030405060708090A0B0C0D0E0F "
  307. . " -secretkeyid C0FEE0"
  308. ],
  309. [
  310. "enveloped content test streaming PEM format, KEK, key only",
  311. "-encrypt -in smcont.txt -outform PEM -aes128"
  312. . " -stream -out test.cms "
  313. . " -secretkey 000102030405060708090A0B0C0D0E0F "
  314. . " -secretkeyid C0FEE0",
  315. "-decrypt -in test.cms -out smtst.txt -inform PEM"
  316. . " -secretkey 000102030405060708090A0B0C0D0E0F "
  317. ],
  318. [
  319. "data content test streaming PEM format",
  320. "-data_create -in smcont.txt -outform PEM -nodetach"
  321. . " -stream -out test.cms",
  322. "-data_out -in test.cms -inform PEM -out smtst.txt"
  323. ],
  324. [
  325. "encrypted content test streaming PEM format, 128 bit RC2 key",
  326. "\"-EncryptedData_encrypt\" -in smcont.txt -outform PEM"
  327. . " -rc2 -secretkey 000102030405060708090A0B0C0D0E0F"
  328. . " -stream -out test.cms",
  329. "\"-EncryptedData_decrypt\" -in test.cms -inform PEM "
  330. . " -secretkey 000102030405060708090A0B0C0D0E0F -out smtst.txt"
  331. ],
  332. [
  333. "encrypted content test streaming PEM format, 40 bit RC2 key",
  334. "\"-EncryptedData_encrypt\" -in smcont.txt -outform PEM"
  335. . " -rc2 -secretkey 0001020304"
  336. . " -stream -out test.cms",
  337. "\"-EncryptedData_decrypt\" -in test.cms -inform PEM "
  338. . " -secretkey 0001020304 -out smtst.txt"
  339. ],
  340. [
  341. "encrypted content test streaming PEM format, triple DES key",
  342. "\"-EncryptedData_encrypt\" -in smcont.txt -outform PEM"
  343. . " -des3 -secretkey 000102030405060708090A0B0C0D0E0F1011121314151617"
  344. . " -stream -out test.cms",
  345. "\"-EncryptedData_decrypt\" -in test.cms -inform PEM "
  346. . " -secretkey 000102030405060708090A0B0C0D0E0F1011121314151617"
  347. . " -out smtst.txt"
  348. ],
  349. [
  350. "encrypted content test streaming PEM format, 128 bit AES key",
  351. "\"-EncryptedData_encrypt\" -in smcont.txt -outform PEM"
  352. . " -aes128 -secretkey 000102030405060708090A0B0C0D0E0F"
  353. . " -stream -out test.cms",
  354. "\"-EncryptedData_decrypt\" -in test.cms -inform PEM "
  355. . " -secretkey 000102030405060708090A0B0C0D0E0F -out smtst.txt"
  356. ],
  357. );
  358. my @smime_cms_comp_tests = (
  359. [
  360. "compressed content test streaming PEM format",
  361. "-compress -in smcont.txt -outform PEM -nodetach"
  362. . " -stream -out test.cms",
  363. "-uncompress -in test.cms -inform PEM -out smtst.txt"
  364. ]
  365. );
  366. my @smime_cms_param_tests = (
  367. [
  368. "signed content test streaming PEM format, RSA keys, PSS signature",
  369. "-sign -in smcont.txt -outform PEM -nodetach"
  370. . " -signer $smdir/smrsa1.pem -keyopt rsa_padding_mode:pss"
  371. . " -out test.cms",
  372. "-verify -in test.cms -inform PEM "
  373. . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
  374. ],
  375. [
  376. "signed content test streaming PEM format, RSA keys, PSS signature, no attributes",
  377. "-sign -in smcont.txt -outform PEM -nodetach -noattr"
  378. . " -signer $smdir/smrsa1.pem -keyopt rsa_padding_mode:pss"
  379. . " -out test.cms",
  380. "-verify -in test.cms -inform PEM "
  381. . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
  382. ],
  383. [
  384. "signed content test streaming PEM format, RSA keys, PSS signature, SHA384 MGF1",
  385. "-sign -in smcont.txt -outform PEM -nodetach"
  386. . " -signer $smdir/smrsa1.pem -keyopt rsa_padding_mode:pss"
  387. . " -keyopt rsa_mgf1_md:sha384 -out test.cms",
  388. "-verify -in test.cms -inform PEM "
  389. . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
  390. ],
  391. [
  392. "enveloped content test streaming S/MIME format, OAEP default parameters",
  393. "-encrypt -in smcont.txt"
  394. . " -stream -out test.cms"
  395. . " -recip $smdir/smrsa1.pem -keyopt rsa_padding_mode:oaep",
  396. "-decrypt -recip $smdir/smrsa1.pem -in test.cms -out smtst.txt"
  397. ],
  398. [
  399. "enveloped content test streaming S/MIME format, OAEP SHA256",
  400. "-encrypt -in smcont.txt"
  401. . " -stream -out test.cms"
  402. . " -recip $smdir/smrsa1.pem -keyopt rsa_padding_mode:oaep"
  403. . " -keyopt rsa_oaep_md:sha256",
  404. "-decrypt -recip $smdir/smrsa1.pem -in test.cms -out smtst.txt"
  405. ],
  406. [
  407. "enveloped content test streaming S/MIME format, ECDH",
  408. "-encrypt -in smcont.txt"
  409. . " -stream -out test.cms"
  410. . " -recip $smdir/smec1.pem",
  411. "-decrypt -recip $smdir/smec1.pem -in test.cms -out smtst.txt"
  412. ],
  413. [
  414. "enveloped content test streaming S/MIME format, ECDH, key identifier",
  415. "-encrypt -keyid -in smcont.txt"
  416. . " -stream -out test.cms"
  417. . " -recip $smdir/smec1.pem",
  418. "-decrypt -recip $smdir/smec1.pem -in test.cms -out smtst.txt"
  419. ],
  420. [
  421. "enveloped content test streaming S/MIME format, ECDH, AES128, SHA256 KDF",
  422. "-encrypt -in smcont.txt"
  423. . " -stream -out test.cms"
  424. . " -recip $smdir/smec1.pem -aes128 -keyopt ecdh_kdf_md:sha256",
  425. "-decrypt -recip $smdir/smec1.pem -in test.cms -out smtst.txt"
  426. ],
  427. [
  428. "enveloped content test streaming S/MIME format, ECDH, K-283, cofactor DH",
  429. "-encrypt -in smcont.txt"
  430. . " -stream -out test.cms"
  431. . " -recip $smdir/smec2.pem -aes128"
  432. . " -keyopt ecdh_kdf_md:sha256 -keyopt ecdh_cofactor_mode:1",
  433. "-decrypt -recip $smdir/smec2.pem -in test.cms -out smtst.txt"
  434. ],
  435. [
  436. "enveloped content test streaming S/MIME format, X9.42 DH",
  437. "-encrypt -in smcont.txt"
  438. . " -stream -out test.cms"
  439. . " -recip $smdir/smdh.pem -aes128",
  440. "-decrypt -recip $smdir/smdh.pem -in test.cms -out smtst.txt"
  441. ]
  442. );
  443. print "CMS => PKCS#7 compatibility tests\n";
  444. run_smime_tests( \$badcmd, \@smime_pkcs7_tests, $cmscmd, $pk7cmd );
  445. print "CMS <= PKCS#7 compatibility tests\n";
  446. run_smime_tests( \$badcmd, \@smime_pkcs7_tests, $pk7cmd, $cmscmd );
  447. print "CMS <=> CMS consistency tests\n";
  448. run_smime_tests( \$badcmd, \@smime_pkcs7_tests, $cmscmd, $cmscmd );
  449. run_smime_tests( \$badcmd, \@smime_cms_tests, $cmscmd, $cmscmd );
  450. print "CMS <=> CMS consistency tests, modified key parameters\n";
  451. run_smime_tests( \$badcmd, \@smime_cms_param_tests, $cmscmd, $cmscmd );
  452. if ( `$ossl_path version -f` =~ /ZLIB/ ) {
  453. run_smime_tests( \$badcmd, \@smime_cms_comp_tests, $cmscmd, $cmscmd );
  454. }
  455. else {
  456. print "Zlib not supported: compression tests skipped\n";
  457. }
  458. print "Running modified tests for OpenSSL 0.9.8 cms backport\n" if($ossl8);
  459. if ($badcmd) {
  460. print "$badcmd TESTS FAILED!!\n";
  461. }
  462. else {
  463. print "ALL TESTS SUCCESSFUL.\n";
  464. }
  465. unlink "test.cms";
  466. unlink "test2.cms";
  467. unlink "smtst.txt";
  468. unlink "cms.out";
  469. unlink "cms.err";
  470. sub run_smime_tests {
  471. my ( $rv, $aref, $scmd, $vcmd ) = @_;
  472. foreach $smtst (@$aref) {
  473. my ( $tnam, $rscmd, $rvcmd ) = @$smtst;
  474. if ($ossl8)
  475. {
  476. # Skip smime resign: 0.9.8 smime doesn't support -resign
  477. next if ($scmd =~ /smime/ && $rscmd =~ /-resign/);
  478. # Disable streaming: option not supported in 0.9.8
  479. $tnam =~ s/streaming//;
  480. $rscmd =~ s/-stream//;
  481. $rvcmd =~ s/-stream//;
  482. }
  483. if ($no_ec && $tnam =~ /ECDH/)
  484. {
  485. print "$tnam: skipped, EC disabled\n";
  486. next;
  487. }
  488. if ($no_ecdh && $tnam =~ /ECDH/)
  489. {
  490. print "$tnam: skipped, ECDH disabled\n";
  491. next;
  492. }
  493. if ($no_ec2m && $tnam =~ /K-283/)
  494. {
  495. print "$tnam: skipped, EC2M disabled\n";
  496. next;
  497. }
  498. system("$scmd$rscmd$redir");
  499. if ($?) {
  500. print "$tnam: generation error\n";
  501. $$rv++;
  502. exit 1 if $halt_err;
  503. next;
  504. }
  505. system("$vcmd$rvcmd$redir");
  506. if ($?) {
  507. print "$tnam: verify error\n";
  508. $$rv++;
  509. exit 1 if $halt_err;
  510. next;
  511. }
  512. if (!cmp_files("smtst.txt", "smcont.txt")) {
  513. print "$tnam: content verify error\n";
  514. $$rv++;
  515. exit 1 if $halt_err;
  516. next;
  517. }
  518. print "$tnam: OK\n";
  519. }
  520. }
  521. sub cmp_files {
  522. use FileHandle;
  523. my ( $f1, $f2 ) = @_;
  524. my $fp1 = FileHandle->new();
  525. my $fp2 = FileHandle->new();
  526. my ( $rd1, $rd2 );
  527. if ( !open( $fp1, "<$f1" ) ) {
  528. print STDERR "Can't Open file $f1\n";
  529. return 0;
  530. }
  531. if ( !open( $fp2, "<$f2" ) ) {
  532. print STDERR "Can't Open file $f2\n";
  533. return 0;
  534. }
  535. binmode $fp1;
  536. binmode $fp2;
  537. my $ret = 0;
  538. for ( ; ; ) {
  539. $n1 = sysread $fp1, $rd1, 4096;
  540. $n2 = sysread $fp2, $rd2, 4096;
  541. last if ( $n1 != $n2 );
  542. last if ( $rd1 ne $rd2 );
  543. if ( $n1 == 0 ) {
  544. $ret = 1;
  545. last;
  546. }
  547. }
  548. close $fp1;
  549. close $fp2;
  550. return $ret;
  551. }