suites.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224
  1. /* suites.c
  2. *
  3. * Copyright (C) 2006-2021 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. #ifdef HAVE_CONFIG_H
  22. #include <config.h>
  23. #endif
  24. #include <wolfssl/wolfcrypt/settings.h>
  25. #include <stdlib.h>
  26. #include <stdio.h>
  27. #include <string.h>
  28. #include <wolfssl/ssl.h>
  29. #include <tests/unit.h>
  30. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS) \
  31. && (defined(NO_MAIN_DRIVER) || defined(HAVE_STACK_SIZE))
  32. #include <wolfssl/wolfcrypt/ecc.h>
  33. #endif
  34. #define MAX_ARGS 40
  35. #define MAX_COMMAND_SZ 240
  36. #ifdef WOLFSSL_TLS13
  37. #define MAX_SUITE_SZ 200
  38. #else
  39. #define MAX_SUITE_SZ 80
  40. #endif
  41. #define NOT_BUILT_IN -123
  42. #if defined(NO_OLD_TLS) || !defined(WOLFSSL_ALLOW_SSLV3) || \
  43. !defined(WOLFSSL_ALLOW_TLSV10)
  44. #define VERSION_TOO_OLD -124
  45. #endif
  46. #include "examples/client/client.h"
  47. #include "examples/server/server.h"
  48. #if !defined(NO_WOLFSSL_SERVER) && !defined(NO_WOLFSSL_CLIENT)
  49. static WOLFSSL_CTX* cipherSuiteCtx = NULL;
  50. static char nonblockFlag[] = "-N";
  51. static char noVerifyFlag[] = "-d";
  52. static char disableEMSFlag[] = "-n";
  53. static char flagSep[] = " ";
  54. #if !defined(USE_WINDOWS_API) && !defined(WOLFSSL_TIRTOS)
  55. static char portFlag[] = "-p";
  56. static char svrPort[] = "0";
  57. #endif
  58. static char intTestFlag[] = "-H";
  59. static char forceDefCipherListFlag[] = "defCipherList";
  60. static char exitWithRetFlag[] = "exitWithRet";
  61. static char disableDHPrimeTest[] = "-2";
  62. #ifdef WOLFSSL_ASYNC_CRYPT
  63. static int devId = INVALID_DEVID;
  64. #endif
  65. #ifdef VERSION_TOO_OLD
  66. static int GetTlsVersion(const char* line)
  67. {
  68. int version = -1;
  69. const char* find = "-v ";
  70. const char* begin = strstr(line, find);
  71. if (begin) {
  72. begin += 3;
  73. if (*begin == 'd' || *begin == 'e')
  74. begin += 2;
  75. version = atoi(begin);
  76. }
  77. return version;
  78. }
  79. #ifndef WOLFSSL_ALLOW_SSLV3
  80. /* if the protocol version is sslv3 return 1, else 0 */
  81. static int IsSslVersion(const char* line)
  82. {
  83. int version = GetTlsVersion(line);
  84. return (version == 0) ? 1 : 0;
  85. }
  86. #endif /* !WOLFSSL_ALLOW_SSLV3 */
  87. #ifndef WOLFSSL_ALLOW_TLSV10
  88. /* if the protocol version is TLSv1.0 return 1, else 0 */
  89. static int IsTls10Version(const char* line)
  90. {
  91. int version = GetTlsVersion(line);
  92. return (version == 1) ? 1 : 0;
  93. }
  94. #endif /* !WOLFSSL_ALLOW_TLSV10 */
  95. #ifdef NO_OLD_TLS
  96. /* if the protocol version is less than tls 1.2 return 1, else 0 */
  97. static int IsOldTlsVersion(const char* line)
  98. {
  99. int version = GetTlsVersion(line);
  100. return (version < 3) ? 1 : 0;
  101. }
  102. #endif /* NO_OLD_TLS */
  103. #endif /* VERSION_TOO_OLD */
  104. /* if the cipher suite on line is valid store in suite and return 1, else 0 */
  105. static int IsValidCipherSuite(const char* line, char *suite, size_t suite_spc)
  106. {
  107. int found = 0;
  108. int valid = 0;
  109. const char* find = "-l ";
  110. const char* begin = strstr(line, find);
  111. const char* end;
  112. if (suite_spc < MAX_SUITE_SZ+1)
  113. return 0;
  114. suite[0] = '\0';
  115. if (begin) {
  116. begin += 3;
  117. end = XSTRSTR(begin, " ");
  118. if (end) {
  119. long len = end - begin;
  120. if (len > MAX_SUITE_SZ) {
  121. printf("suite too long!\n");
  122. return 0;
  123. }
  124. XMEMCPY(suite, begin, len);
  125. suite[len] = '\0';
  126. }
  127. else
  128. XSTRNCPY(suite, begin, MAX_SUITE_SZ);
  129. suite[MAX_SUITE_SZ] = '\0';
  130. found = 1;
  131. }
  132. if (found) {
  133. if (wolfSSL_CTX_set_cipher_list(cipherSuiteCtx, suite) == WOLFSSL_SUCCESS)
  134. valid = 1;
  135. }
  136. return valid;
  137. }
  138. static int IsValidCert(const char* line)
  139. {
  140. int ret = 1;
  141. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
  142. WOLFSSL_CTX* ctx;
  143. size_t i;
  144. const char* begin;
  145. char cert[80];
  146. #ifdef WOLFSSL_STATIC_MEMORY
  147. FILE* fStream = NULL;
  148. long chkSz = 0;
  149. #endif
  150. begin = XSTRSTR(line, "-c ");
  151. if (begin == NULL)
  152. return 1;
  153. begin += 3;
  154. for (i = 0; i < sizeof(cert) - 1 && *begin != ' ' && *begin != '\0'; i++)
  155. cert[i] = *(begin++);
  156. cert[i] = '\0';
  157. #ifdef WOLFSSL_STATIC_MEMORY
  158. fStream = XFOPEN(cert, "rb");
  159. if (fStream == NULL) {
  160. printf("Failed to open file %s\n", cert);
  161. printf("Invalid cert, skipping test\n");
  162. return 0;
  163. } else {
  164. printf("Successfully opened file\n");
  165. }
  166. XFSEEK(fStream, 0L, SEEK_END);
  167. chkSz = XFTELL(fStream);
  168. XFCLOSE(fStream);
  169. if (chkSz > LARGEST_MEM_BUCKET) {
  170. printf("File is larger than largest bucket, skipping this test\n");
  171. return 0;
  172. }
  173. #endif
  174. ctx = wolfSSL_CTX_new(wolfSSLv23_server_method_ex(NULL));
  175. if (ctx == NULL)
  176. return 0;
  177. ret = wolfSSL_CTX_use_certificate_chain_file(ctx, cert) == WOLFSSL_SUCCESS;
  178. wolfSSL_CTX_free(ctx);
  179. #endif /* !NO_FILESYSTEM && !NO_CERTS */
  180. (void)line;
  181. return ret;
  182. }
  183. static int IsValidCA(const char* line)
  184. {
  185. int ret = 1;
  186. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
  187. WOLFSSL_CTX* ctx;
  188. size_t i;
  189. const char* begin;
  190. char cert[80];
  191. begin = XSTRSTR(line, "-A ");
  192. if (begin == NULL)
  193. return 1;
  194. begin += 3;
  195. for (i = 0; i < sizeof(cert) - 1 && *begin != ' ' && *begin != '\0'; i++)
  196. cert[i] = *(begin++);
  197. cert[i] = '\0';
  198. ctx = wolfSSL_CTX_new(wolfSSLv23_server_method_ex(NULL));
  199. if (ctx == NULL)
  200. return 0;
  201. ret = wolfSSL_CTX_use_certificate_chain_file(ctx, cert) == WOLFSSL_SUCCESS;
  202. wolfSSL_CTX_free(ctx);
  203. #endif /* !NO_FILESYSTEM && !NO_CERTS */
  204. (void)line;
  205. return ret;
  206. }
  207. #ifdef WOLFSSL_NO_CLIENT_AUTH
  208. static int IsClientAuth(const char* line, int* reqClientCert)
  209. {
  210. const char* begin;
  211. begin = XSTRSTR(line, "-H verifyFail");
  212. if (begin != NULL) {
  213. return 1;
  214. }
  215. begin = XSTRSTR(line, "-d");
  216. if (begin != NULL) {
  217. *reqClientCert = 0;
  218. }
  219. else {
  220. *reqClientCert = 1;
  221. }
  222. return 0;
  223. }
  224. #endif
  225. #ifdef NO_CERTS
  226. static int IsUsingCert(const char* line)
  227. {
  228. return XSTRSTR(line, "-c ") != NULL;
  229. }
  230. #endif
  231. #if defined(NO_CERTS) || defined(WOLFSSL_NO_CLIENT_AUTH)
  232. static int IsNoClientCert(const char* line)
  233. {
  234. const char* begin;
  235. begin = XSTRSTR(line, "-x");
  236. if (begin != NULL) {
  237. return 1;
  238. }
  239. return 0;
  240. }
  241. #endif
  242. static int execute_test_case(int svr_argc, char** svr_argv,
  243. int cli_argc, char** cli_argv,
  244. int addNoVerify, int addNonBlocking,
  245. int addDisableEMS, int forceSrvDefCipherList,
  246. int forceCliDefCipherList)
  247. {
  248. #ifdef WOLFSSL_TIRTOS
  249. func_args cliArgs = {0};
  250. func_args svrArgs = {0};
  251. cliArgs.argc = cli_argc;
  252. cliArgs.argv = cli_argv;
  253. svrArgs.argc = svr_argc;
  254. svrArgs.argv = svr_argv;
  255. #else
  256. func_args cliArgs = {cli_argc, cli_argv, 0, NULL, NULL};
  257. func_args svrArgs = {svr_argc, svr_argv, 0, NULL, NULL};
  258. #endif
  259. tcp_ready ready;
  260. THREAD_TYPE serverThread;
  261. char commandLine[MAX_COMMAND_SZ];
  262. char cipherSuite[MAX_SUITE_SZ+1];
  263. int i;
  264. size_t added;
  265. static int tests = 1;
  266. #if !defined(USE_WINDOWS_API) && !defined(WOLFSSL_TIRTOS)
  267. char portNumber[8];
  268. #endif
  269. int cliTestShouldFail = 0, svrTestShouldFail = 0;
  270. #ifdef WOLFSSL_NO_CLIENT_AUTH
  271. int reqClientCert;
  272. #endif
  273. /* Is Valid Cipher and Version Checks */
  274. /* build command list for the Is checks below */
  275. commandLine[0] = '\0';
  276. added = 0;
  277. for (i = 0; i < svrArgs.argc; i++) {
  278. added += XSTRLEN(svr_argv[i]) + 2;
  279. if (added >= MAX_COMMAND_SZ) {
  280. printf("server command line too long\n");
  281. break;
  282. }
  283. strcat(commandLine, svr_argv[i]);
  284. strcat(commandLine, flagSep);
  285. }
  286. if (IsValidCipherSuite(commandLine, cipherSuite, sizeof cipherSuite) == 0) {
  287. #ifdef DEBUG_SUITE_TESTS
  288. printf("cipher suite %s not supported in build\n", cipherSuite);
  289. #endif
  290. return NOT_BUILT_IN;
  291. }
  292. if (!IsValidCert(commandLine)) {
  293. #ifdef DEBUG_SUITE_TESTS
  294. printf("certificate %s not supported in build\n", commandLine);
  295. #endif
  296. return NOT_BUILT_IN;
  297. }
  298. #ifndef WOLFSSL_ALLOW_SSLV3
  299. if (IsSslVersion(commandLine) == 1) {
  300. #ifdef DEBUG_SUITE_TESTS
  301. printf("protocol version on line %s is too old\n", commandLine);
  302. #endif
  303. return VERSION_TOO_OLD;
  304. }
  305. #endif
  306. #ifndef WOLFSSL_ALLOW_TLSV10
  307. if (IsTls10Version(commandLine) == 1) {
  308. #ifdef DEBUG_SUITE_TESTS
  309. printf("protocol version on line %s is too old\n", commandLine);
  310. #endif
  311. return VERSION_TOO_OLD;
  312. }
  313. #endif
  314. #ifdef NO_OLD_TLS
  315. if (IsOldTlsVersion(commandLine) == 1) {
  316. #ifdef DEBUG_SUITE_TESTS
  317. printf("protocol version on line %s is too old\n", commandLine);
  318. #endif
  319. return VERSION_TOO_OLD;
  320. }
  321. #endif
  322. #ifdef WOLFSSL_NO_CLIENT_AUTH
  323. if (IsClientAuth(commandLine, &reqClientCert)) {
  324. #ifdef DEBUG_SUITE_TESTS
  325. printf("client auth on line %s not supported in build\n",
  326. commandLine);
  327. #endif
  328. return NOT_BUILT_IN;
  329. }
  330. #endif
  331. #ifdef NO_CERTS
  332. if (IsUsingCert(commandLine)) {
  333. #ifdef DEBUG_SUITE_TESTS
  334. printf("certificate %s not supported in build\n", commandLine);
  335. #endif
  336. return NOT_BUILT_IN;
  337. }
  338. #endif
  339. /* Build Server Command */
  340. if (addNoVerify) {
  341. printf("repeating test with client cert request off\n");
  342. if (svrArgs.argc >= MAX_ARGS)
  343. printf("server command line too long\n");
  344. else
  345. svr_argv[svrArgs.argc++] = noVerifyFlag;
  346. }
  347. if (addNonBlocking) {
  348. printf("repeating test with non blocking on\n");
  349. if (svrArgs.argc >= MAX_ARGS)
  350. printf("server command line too long\n");
  351. else
  352. svr_argv[svrArgs.argc++] = nonblockFlag;
  353. }
  354. #if !defined(USE_WINDOWS_API) && !defined(WOLFSSL_TIRTOS)
  355. /* add port */
  356. if (svrArgs.argc + 2 > MAX_ARGS)
  357. printf("cannot add the magic port number flag to server\n");
  358. else {
  359. svr_argv[svrArgs.argc++] = portFlag;
  360. svr_argv[svrArgs.argc++] = svrPort;
  361. }
  362. #endif
  363. if (forceSrvDefCipherList) {
  364. if (svrArgs.argc + 2 > MAX_ARGS)
  365. printf("cannot add the force def cipher list flag to server\n");
  366. else {
  367. svr_argv[svrArgs.argc++] = intTestFlag;
  368. svr_argv[svrArgs.argc++] = forceDefCipherListFlag;
  369. }
  370. }
  371. #ifdef TEST_PK_PRIVKEY
  372. svr_argv[svrArgs.argc++] = (char*)"-P";
  373. #endif
  374. /* update server flags list */
  375. commandLine[0] = '\0';
  376. added = 0;
  377. for (i = 0; i < svrArgs.argc; i++) {
  378. added += XSTRLEN(svr_argv[i]) + 2;
  379. if (added >= MAX_COMMAND_SZ) {
  380. printf("server command line too long\n");
  381. break;
  382. }
  383. strcat(commandLine, svr_argv[i]);
  384. strcat(commandLine, flagSep);
  385. }
  386. printf("trying server command line[%d]: %s\n", tests, commandLine);
  387. tests++; /* test count */
  388. /* determine based on args if this test is expected to fail */
  389. if (XSTRSTR(commandLine, exitWithRetFlag) != NULL) {
  390. svrTestShouldFail = 1;
  391. }
  392. InitTcpReady(&ready);
  393. #ifdef WOLFSSL_TIRTOS
  394. fdOpenSession(Task_self());
  395. #endif
  396. /* start server */
  397. svrArgs.signal = &ready;
  398. start_thread(server_test, &svrArgs, &serverThread);
  399. wait_tcp_ready(&svrArgs);
  400. /* Build Client Command */
  401. if (addNonBlocking) {
  402. if (cliArgs.argc >= MAX_ARGS)
  403. printf("cannot add the non block flag to client\n");
  404. else
  405. cli_argv[cliArgs.argc++] = nonblockFlag;
  406. }
  407. if (addDisableEMS) {
  408. printf("repeating test without extended master secret\n");
  409. if (cliArgs.argc >= MAX_ARGS)
  410. printf("cannot add the disable EMS flag to client\n");
  411. else
  412. cli_argv[cliArgs.argc++] = disableEMSFlag;
  413. }
  414. #if !defined(USE_WINDOWS_API) && !defined(WOLFSSL_TIRTOS)
  415. if (ready.port != 0) {
  416. if (cliArgs.argc + 2 > MAX_ARGS)
  417. printf("cannot add the magic port number flag to client\n");
  418. else {
  419. snprintf(portNumber, sizeof(portNumber), "%d", (int)ready.port);
  420. cli_argv[cliArgs.argc++] = portFlag;
  421. cli_argv[cliArgs.argc++] = portNumber;
  422. }
  423. }
  424. #endif
  425. if (forceCliDefCipherList) {
  426. if (cliArgs.argc + 2 > MAX_ARGS)
  427. printf("cannot add the force def cipher list flag to client\n");
  428. else {
  429. cli_argv[cliArgs.argc++] = intTestFlag;
  430. cli_argv[cliArgs.argc++] = forceDefCipherListFlag;
  431. }
  432. }
  433. #ifdef TEST_PK_PRIVKEY
  434. cli_argv[cliArgs.argc++] = (char*)"-P";
  435. #endif
  436. commandLine[0] = '\0';
  437. added = 0;
  438. for (i = 0; i < cliArgs.argc; i++) {
  439. added += XSTRLEN(cli_argv[i]) + 2;
  440. if (added >= MAX_COMMAND_SZ) {
  441. printf("client command line too long\n");
  442. break;
  443. }
  444. strcat(commandLine, cli_argv[i]);
  445. strcat(commandLine, flagSep);
  446. }
  447. if (!IsValidCA(commandLine)) {
  448. #ifdef DEBUG_SUITE_TESTS
  449. printf("certificate %s not supported in build\n", commandLine);
  450. #endif
  451. return NOT_BUILT_IN;
  452. }
  453. #ifdef WOLFSSL_NO_CLIENT_AUTH
  454. if (reqClientCert && IsNoClientCert(commandLine)) {
  455. #ifdef DEBUG_SUITE_TESTS
  456. printf("client auth on line %s not supported in build\n",
  457. commandLine);
  458. #endif
  459. return NOT_BUILT_IN;
  460. }
  461. #endif
  462. #ifdef NO_CERTS
  463. if (IsNoClientCert(commandLine)) {
  464. #ifdef DEBUG_SUITE_TESTS
  465. printf("certificate %s not supported in build\n", commandLine);
  466. #endif
  467. return NOT_BUILT_IN;
  468. }
  469. #endif
  470. printf("trying client command line[%d]: %s\n", tests, commandLine);
  471. tests++;
  472. /* determine based on args if this test is expected to fail */
  473. if (XSTRSTR(commandLine, exitWithRetFlag) != NULL) {
  474. cliTestShouldFail = 1;
  475. }
  476. /* start client */
  477. client_test(&cliArgs);
  478. /* verify results */
  479. if ((cliArgs.return_code != 0 && cliTestShouldFail == 0) ||
  480. (cliArgs.return_code == 0 && cliTestShouldFail != 0)) {
  481. printf("client_test failed %d %s\n", cliArgs.return_code,
  482. cliTestShouldFail ? "(should fail)" : "");
  483. XEXIT(EXIT_FAILURE);
  484. }
  485. join_thread(serverThread);
  486. if ((svrArgs.return_code != 0 && svrTestShouldFail == 0) ||
  487. (svrArgs.return_code == 0 && svrTestShouldFail != 0)) {
  488. printf("server_test failed %d %s\n", svrArgs.return_code,
  489. svrTestShouldFail ? "(should fail)" : "");
  490. XEXIT(EXIT_FAILURE);
  491. }
  492. #ifdef WOLFSSL_TIRTOS
  493. fdCloseSession(Task_self());
  494. #endif
  495. FreeTcpReady(&ready);
  496. /* only run the first test for expected failure cases */
  497. /* the example server/client are not designed to handle expected failure in
  498. all cases, such as non-blocking, etc... */
  499. if (svrTestShouldFail || cliTestShouldFail) {
  500. return NOT_BUILT_IN;
  501. }
  502. return 0;
  503. }
  504. static void test_harness(void* vargs)
  505. {
  506. func_args* args = (func_args*)vargs;
  507. char* script;
  508. long sz, len;
  509. int cliMode = 0; /* server or client command flag, server first */
  510. int ret;
  511. FILE* file;
  512. char* svrArgs[MAX_ARGS];
  513. int svrArgsSz;
  514. char* cliArgs[MAX_ARGS];
  515. int cliArgsSz;
  516. char* cursor;
  517. char* comment;
  518. char lastChar = '\0';
  519. int do_it = 0;
  520. const char* fname = "tests/test.conf";
  521. const char* addArgs = NULL;
  522. if (args->argc == 1) {
  523. printf("notice: using default file %s\n", fname);
  524. }
  525. else if (args->argc == 3) {
  526. addArgs = args->argv[2];
  527. }
  528. else if (args->argc > 3) {
  529. printf("usage: harness [FILE] [ARG]\n");
  530. args->return_code = 1;
  531. return;
  532. }
  533. if (args->argc >= 2) {
  534. fname = args->argv[1];
  535. }
  536. file = fopen(fname, "rb");
  537. if (file == NULL) {
  538. fprintf(stderr, "unable to open %s\n", fname);
  539. args->return_code = 1;
  540. return;
  541. }
  542. fseek(file, 0, SEEK_END);
  543. sz = ftell(file);
  544. rewind(file);
  545. if (sz <= 0) {
  546. fprintf(stderr, "%s is empty\n", fname);
  547. fclose(file);
  548. args->return_code = 1;
  549. return;
  550. }
  551. script = (char*)malloc(sz+1);
  552. if (script == 0) {
  553. fprintf(stderr, "unable to allocate script buffer\n");
  554. fclose(file);
  555. args->return_code = 1;
  556. return;
  557. }
  558. len = fread(script, 1, sz, file);
  559. if (len != sz) {
  560. fprintf(stderr, "read error\n");
  561. fclose(file);
  562. free(script);
  563. args->return_code = 1;
  564. return;
  565. }
  566. fclose(file);
  567. script[sz] = 0;
  568. cursor = script;
  569. svrArgsSz = 1;
  570. svrArgs[0] = args->argv[0];
  571. cliArgsSz = 1;
  572. cliArgs[0] = args->argv[0];
  573. while (cursor && *cursor != 0) {
  574. switch (*cursor) {
  575. case '\n':
  576. /* A blank line triggers test case execution or switches
  577. to client mode if we don't have the client command yet */
  578. if (lastChar != '\n' && (cliArgsSz > 1 || svrArgsSz > 1)) {
  579. if (cliMode == 0)
  580. cliMode = 1; /* switch to client mode processing */
  581. else
  582. do_it = 1; /* Do It, we have server and client */
  583. }
  584. #ifdef DEBUG_SUITE_TESTS
  585. else {
  586. /* skip extra new-lines */
  587. printf("skipping extra new line\n");
  588. }
  589. #endif
  590. lastChar = *cursor;
  591. cursor++;
  592. break;
  593. case '#':
  594. lastChar = *cursor;
  595. /* Ignore lines that start with a # */
  596. comment = XSTRSEP(&cursor, "\n");
  597. #ifdef DEBUG_SUITE_TESTS
  598. printf("%s\n", comment);
  599. #else
  600. (void)comment;
  601. #endif
  602. break;
  603. case '-':
  604. default:
  605. /* Parameters start with a -. They end in either a newline
  606. * or a space. Capture until either, save in Args list. */
  607. lastChar = *cursor;
  608. if (cliMode)
  609. cliArgs[cliArgsSz++] = XSTRSEP(&cursor, " \n");
  610. else
  611. svrArgs[svrArgsSz++] = XSTRSEP(&cursor, " \n");
  612. if (cursor == NULL || *cursor == '\0') /* eof */
  613. do_it = 1;
  614. break;
  615. }
  616. if (svrArgsSz == MAX_ARGS || cliArgsSz == MAX_ARGS) {
  617. fprintf(stderr, "too many arguments, forcing test run\n");
  618. do_it = 1;
  619. }
  620. if (do_it) {
  621. /* additional arguments processing */
  622. if (cliArgsSz+2 < MAX_ARGS && svrArgsSz+2 < MAX_ARGS) {
  623. if (addArgs == NULL || XSTRSTR(addArgs, "doDH") == NULL) {
  624. /* The `-2` disable DH prime check is added to all tests by default */
  625. cliArgs[cliArgsSz++] = disableDHPrimeTest;
  626. svrArgs[svrArgsSz++] = disableDHPrimeTest;
  627. }
  628. if (addArgs && XSTRSTR(addArgs, "expFail")) {
  629. /* Tests should expect to fail */
  630. cliArgs[cliArgsSz++] = intTestFlag;
  631. cliArgs[cliArgsSz++] = exitWithRetFlag;
  632. svrArgs[svrArgsSz++] = intTestFlag;
  633. svrArgs[svrArgsSz++] = exitWithRetFlag;
  634. }
  635. }
  636. ret = execute_test_case(svrArgsSz, svrArgs,
  637. cliArgsSz, cliArgs, 0, 0, 0, 0, 0);
  638. /* don't repeat if not supported in build */
  639. if (ret == 0) {
  640. /* test with default cipher list on server side */
  641. execute_test_case(svrArgsSz, svrArgs,
  642. cliArgsSz, cliArgs, 0, 0, 0, 1, 0);
  643. /* test with default cipher list on client side */
  644. execute_test_case(svrArgsSz, svrArgs,
  645. cliArgsSz, cliArgs, 0, 0, 0, 0, 1);
  646. execute_test_case(svrArgsSz, svrArgs,
  647. cliArgsSz, cliArgs, 0, 1, 0, 0, 0);
  648. execute_test_case(svrArgsSz, svrArgs,
  649. cliArgsSz, cliArgs, 1, 0, 0, 0, 0);
  650. execute_test_case(svrArgsSz, svrArgs,
  651. cliArgsSz, cliArgs, 1, 1, 0, 0, 0);
  652. #ifdef HAVE_EXTENDED_MASTER
  653. execute_test_case(svrArgsSz, svrArgs,
  654. cliArgsSz, cliArgs, 0, 0, 1, 0, 0);
  655. execute_test_case(svrArgsSz, svrArgs,
  656. cliArgsSz, cliArgs, 0, 1, 1, 0, 0);
  657. execute_test_case(svrArgsSz, svrArgs,
  658. cliArgsSz, cliArgs, 1, 0, 1, 0, 0);
  659. execute_test_case(svrArgsSz, svrArgs,
  660. cliArgsSz, cliArgs, 1, 1, 1, 0, 0);
  661. #endif
  662. }
  663. svrArgsSz = 1;
  664. cliArgsSz = 1;
  665. cliMode = 0;
  666. do_it = 0;
  667. }
  668. }
  669. free(script);
  670. args->return_code = 0;
  671. }
  672. #endif /* !NO_WOLFSSL_SERVER && !NO_WOLFSSL_CLIENT */
  673. int SuiteTest(int argc, char** argv)
  674. {
  675. #if !defined(NO_WOLFSSL_SERVER) && !defined(NO_WOLFSSL_CLIENT)
  676. func_args args;
  677. char argv0[3][80];
  678. char* myArgv[3];
  679. printf(" Begin Cipher Suite Tests\n");
  680. /* setup */
  681. myArgv[0] = argv0[0];
  682. myArgv[1] = argv0[1];
  683. myArgv[2] = argv0[2];
  684. args.argv = myArgv;
  685. strcpy(argv0[0], "SuiteTest");
  686. #ifdef WOLFSSL_STATIC_MEMORY
  687. byte memory[200000];
  688. #endif
  689. cipherSuiteCtx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  690. if (cipherSuiteCtx == NULL) {
  691. printf("can't get cipher suite ctx\n");
  692. args.return_code = EXIT_FAILURE;
  693. goto exit;
  694. }
  695. /* load in static memory buffer if enabled */
  696. #ifdef WOLFSSL_STATIC_MEMORY
  697. if (wolfSSL_CTX_load_static_memory(&cipherSuiteCtx, NULL,
  698. memory, sizeof(memory), 0, 1)
  699. != WOLFSSL_SUCCESS) {
  700. printf("unable to load static memory and create ctx");
  701. args.return_code = EXIT_FAILURE;
  702. goto exit;
  703. }
  704. #endif
  705. #ifdef WOLFSSL_ASYNC_CRYPT
  706. if (wolfAsync_DevOpen(&devId) < 0) {
  707. printf("Async device open failed");
  708. args.return_code = EXIT_FAILURE;
  709. goto exit;
  710. }
  711. wolfSSL_CTX_SetDevId(cipherSuiteCtx, devId);
  712. #endif /* WOLFSSL_ASYNC_CRYPT */
  713. /* support for custom command line tests */
  714. if (argc > 1) {
  715. /* Examples:
  716. ./tests/unit.test tests/test-altchains.conf
  717. ./tests/unit.test tests/test-fails.conf expFail
  718. ./tests/unit.test tests/test-dhprime.conf doDH
  719. */
  720. args.argc = argc;
  721. args.argv = argv;
  722. test_harness(&args);
  723. if (args.return_code != 0) {
  724. printf("error from script %d\n", args.return_code);
  725. args.return_code = EXIT_FAILURE;
  726. }
  727. goto exit;
  728. }
  729. /* default case */
  730. args.argc = 1;
  731. printf("starting default cipher suite tests\n");
  732. test_harness(&args);
  733. if (args.return_code != 0) {
  734. printf("error from script %d\n", args.return_code);
  735. args.return_code = EXIT_FAILURE;
  736. goto exit;
  737. }
  738. /* any extra cases will need another argument */
  739. args.argc = 2;
  740. #ifdef WOLFSSL_OLDTLS_SHA2_CIPHERSUITES
  741. /* SHA-2 cipher suites in old TLS versions */
  742. strcpy(argv0[1], "tests/test-sha2.conf");
  743. printf("starting SHA-2 cipher suite in old TLS versions tests\n");
  744. test_harness(&args);
  745. if (args.return_code != 0) {
  746. printf("error from script %d\n", args.return_code);
  747. args.return_code = EXIT_FAILURE;
  748. goto exit;
  749. }
  750. #endif
  751. #ifdef WOLFSSL_TLS13
  752. /* add TLSv13 extra suites */
  753. strcpy(argv0[1], "tests/test-tls13.conf");
  754. printf("starting TLSv13 extra cipher suite tests\n");
  755. test_harness(&args);
  756. if (args.return_code != 0) {
  757. printf("error from script %d\n", args.return_code);
  758. args.return_code = EXIT_FAILURE;
  759. goto exit;
  760. }
  761. #ifdef HAVE_ECC
  762. /* add TLSv13 ECC extra suites */
  763. strcpy(argv0[1], "tests/test-tls13-ecc.conf");
  764. printf("starting TLSv13 ECC extra cipher suite tests\n");
  765. test_harness(&args);
  766. if (args.return_code != 0) {
  767. printf("error from script %d\n", args.return_code);
  768. args.return_code = EXIT_FAILURE;
  769. goto exit;
  770. }
  771. #endif
  772. #ifndef WOLFSSL_NO_TLS12
  773. /* add TLSv13 downgrade tests */
  774. strcpy(argv0[1], "tests/test-tls13-down.conf");
  775. printf("starting TLSv13 Downgrade extra tests\n");
  776. test_harness(&args);
  777. if (args.return_code != 0) {
  778. printf("error from script %d\n", args.return_code);
  779. args.return_code = EXIT_FAILURE;
  780. goto exit;
  781. }
  782. #endif
  783. #ifdef HAVE_LIBOQS
  784. /* add TLSv13 pq tests */
  785. strcpy(argv0[1], "tests/test-tls13-pq.conf");
  786. printf("starting TLSv13 post-quantum groups tests\n");
  787. test_harness(&args);
  788. if (args.return_code != 0) {
  789. printf("error from script %d\n", args.return_code);
  790. args.return_code = EXIT_FAILURE;
  791. goto exit;
  792. }
  793. #endif
  794. #endif
  795. #if defined(HAVE_CURVE25519) && defined(HAVE_ED25519) && \
  796. defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_VERIFY) && \
  797. defined(HAVE_ED25519_KEY_IMPORT) && defined(HAVE_ED25519_KEY_EXPORT)
  798. /* add ED25519 certificate cipher suite tests */
  799. strcpy(argv0[1], "tests/test-ed25519.conf");
  800. printf("starting ED25519 extra cipher suite tests\n");
  801. test_harness(&args);
  802. if (args.return_code != 0) {
  803. printf("error from script %d\n", args.return_code);
  804. args.return_code = EXIT_FAILURE;
  805. goto exit;
  806. }
  807. #endif
  808. #if defined(HAVE_CURVE448) && defined(HAVE_ED448) && \
  809. defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_VERIFY) && \
  810. defined(HAVE_ED448_KEY_IMPORT) && defined(HAVE_ED448_KEY_EXPORT)
  811. /* add ED448 certificate cipher suite tests */
  812. strcpy(argv0[1], "tests/test-ed448.conf");
  813. printf("starting ED448 extra cipher suite tests\n");
  814. test_harness(&args);
  815. if (args.return_code != 0) {
  816. printf("error from script %d\n", args.return_code);
  817. args.return_code = EXIT_FAILURE;
  818. goto exit;
  819. }
  820. #endif
  821. #if defined(HAVE_ECC) && defined(WOLFSSL_SHA512) && \
  822. (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES))
  823. /* add P-521 certificate cipher suite tests */
  824. strcpy(argv0[1], "tests/test-p521.conf");
  825. printf("starting P-521 extra cipher suite tests\n");
  826. test_harness(&args);
  827. if (args.return_code != 0) {
  828. printf("error from script %d\n", args.return_code);
  829. args.return_code = EXIT_FAILURE;
  830. goto exit;
  831. }
  832. #endif
  833. #if defined(HAVE_ECC) && !defined(NO_SHA256) && defined(WOLFSSL_CUSTOM_CURVES) && \
  834. defined(HAVE_ECC_KOBLITZ) && defined(HAVE_ECC_BRAINPOOL) && \
  835. /* Intel QuickAssist and Cavium Nitrox do not support custom curves */ \
  836. !defined(HAVE_INTEL_QA) && !defined(HAVE_CAVIUM_V)
  837. /* TLS non-NIST curves (Koblitz / Brainpool) */
  838. strcpy(argv0[1], "tests/test-ecc-cust-curves.conf");
  839. printf("starting TLS test of non-NIST curves (Koblitz / Brainpool)\n");
  840. test_harness(&args);
  841. if (args.return_code != 0) {
  842. printf("error from script %d\n", args.return_code);
  843. args.return_code = EXIT_FAILURE;
  844. goto exit;
  845. }
  846. #endif
  847. #ifdef WOLFSSL_DTLS
  848. /* add dtls extra suites */
  849. strcpy(argv0[1], "tests/test-dtls.conf");
  850. printf("starting dtls extra cipher suite tests\n");
  851. test_harness(&args);
  852. if (args.return_code != 0) {
  853. printf("error from script %d\n", args.return_code);
  854. args.return_code = EXIT_FAILURE;
  855. goto exit;
  856. }
  857. /* add dtls grouping tests */
  858. strcpy(argv0[1], "tests/test-dtls-group.conf");
  859. printf("starting dtls message grouping tests\n");
  860. test_harness(&args);
  861. if (args.return_code != 0) {
  862. printf("error from script %d\n", args.return_code);
  863. args.return_code = EXIT_FAILURE;
  864. goto exit;
  865. }
  866. /* add dtls session resumption tests */
  867. strcpy(argv0[1], "tests/test-dtls-resume.conf");
  868. printf("starting dtls session resumption tests\n");
  869. test_harness(&args);
  870. if (args.return_code != 0) {
  871. printf("error from script %d\n", args.return_code);
  872. args.return_code = EXIT_FAILURE;
  873. goto exit;
  874. }
  875. #ifdef HAVE_SECURE_RENEGOTIATION
  876. /* add dtls renegotiation tests */
  877. strcpy(argv0[1], "tests/test-dtls-reneg-client.conf");
  878. printf("starting dtls secure renegotiation client tests\n");
  879. test_harness(&args);
  880. if (args.return_code != 0) {
  881. printf("error from script %d\n", args.return_code);
  882. args.return_code = EXIT_FAILURE;
  883. goto exit;
  884. }
  885. strcpy(argv0[1], "tests/test-dtls-reneg-server.conf");
  886. printf("starting dtls secure renegotiation server tests\n");
  887. test_harness(&args);
  888. if (args.return_code != 0) {
  889. printf("error from script %d\n", args.return_code);
  890. args.return_code = EXIT_FAILURE;
  891. goto exit;
  892. }
  893. #endif
  894. #ifdef WOLFSSL_DTLS_MTU
  895. /* Add dtls different MTU size tests.
  896. * These also use grouping to force wolfSSL to
  897. * bounce off the MTU limit more */
  898. strcpy(argv0[1], "tests/test-dtls-mtu.conf");
  899. printf("starting dtls MTU tests\n");
  900. test_harness(&args);
  901. if (args.return_code != 0) {
  902. printf("error from script %d\n", args.return_code);
  903. args.return_code = EXIT_FAILURE;
  904. goto exit;
  905. }
  906. #endif
  907. #ifdef WOLFSSL_OLDTLS_SHA2_CIPHERSUITES
  908. /* add dtls extra suites */
  909. strcpy(argv0[1], "tests/test-dtls-sha2.conf");
  910. printf("starting dtls extra cipher suite tests - old TLS sha-2 cs\n");
  911. test_harness(&args);
  912. if (args.return_code != 0) {
  913. printf("error from script %d\n", args.return_code);
  914. args.return_code = EXIT_FAILURE;
  915. goto exit;
  916. }
  917. #endif
  918. #ifndef WOLFSSL_NO_DTLS_SIZE_CHECK
  919. /* failure tests */
  920. args.argc = 3;
  921. strcpy(argv0[1], "tests/test-dtls-fails.conf");
  922. strcpy(argv0[2], "expFail"); /* tests are expected to fail */
  923. printf("starting dtls tests that expect failure\n");
  924. test_harness(&args);
  925. if (args.return_code != 0) {
  926. printf("error from script %d\n", args.return_code);
  927. args.return_code = EXIT_FAILURE;
  928. goto exit;
  929. }
  930. strcpy(argv0[2], "");
  931. #endif
  932. #ifdef WOLFSSL_EXTRA_ALERTS
  933. /* failure tests */
  934. args.argc = 3;
  935. strcpy(argv0[1], "tests/test-dtls-fails-cipher.conf");
  936. strcpy(argv0[2], "expFail"); /* tests are expected to fail */
  937. printf("starting dtls cipher mismatch tests that expect failure\n");
  938. test_harness(&args);
  939. if (args.return_code != 0) {
  940. printf("error from script %d\n", args.return_code);
  941. args.return_code = EXIT_FAILURE;
  942. goto exit;
  943. }
  944. strcpy(argv0[2], "");
  945. #endif
  946. #endif
  947. #ifdef WOLFSSL_SCTP
  948. /* add dtls-sctp extra suites */
  949. strcpy(argv0[1], "tests/test-sctp.conf");
  950. printf("starting dtls-sctp extra cipher suite tests\n");
  951. test_harness(&args);
  952. if (args.return_code != 0) {
  953. printf("error from script %d\n", args.return_code);
  954. args.return_code = EXIT_FAILURE;
  955. goto exit;
  956. }
  957. #ifdef WOLFSSL_OLDTLS_SHA2_CIPHERSUITES
  958. /* add dtls-sctp extra suites */
  959. strcpy(argv0[1], "tests/test-sctp-sha2.conf");
  960. printf("starting dtls-sctp extra cipher suite tests - old TLS sha-2 cs\n");
  961. test_harness(&args);
  962. if (args.return_code != 0) {
  963. printf("error from script %d\n", args.return_code);
  964. args.return_code = EXIT_FAILURE;
  965. goto exit;
  966. }
  967. #endif
  968. #endif
  969. #ifndef WC_STRICT_SIG
  970. #if !defined(NO_RSA) && defined(HAVE_ECC) /* testing mixed ECC/RSA cert */
  971. /* add extra signature test suites */
  972. strcpy(argv0[1], "tests/test-sig.conf");
  973. printf("starting sig extra cipher suite tests\n");
  974. test_harness(&args);
  975. if (args.return_code != 0) {
  976. printf("error from script %d\n", args.return_code);
  977. args.return_code = EXIT_FAILURE;
  978. goto exit;
  979. }
  980. #endif /* HAVE_RSA and HAVE_ECC */
  981. #endif /* !WC_STRICT_SIG */
  982. #ifndef NO_PSK
  983. #ifndef WOLFSSL_NO_TLS12
  984. #if !defined(NO_RSA) || defined(HAVE_ECC)
  985. /* add psk cipher suites */
  986. strcpy(argv0[1], "tests/test-psk.conf");
  987. printf("starting psk cipher suite tests\n");
  988. test_harness(&args);
  989. if (args.return_code != 0) {
  990. printf("error from script %d\n", args.return_code);
  991. args.return_code = EXIT_FAILURE;
  992. goto exit;
  993. }
  994. #endif
  995. #endif
  996. #ifdef WOLFSSL_TLS13
  997. /* add psk extra suites */
  998. strcpy(argv0[1], "tests/test-tls13-psk.conf");
  999. printf("starting TLS 1.3 psk no identity extra cipher suite tests\n");
  1000. test_harness(&args);
  1001. if (args.return_code != 0) {
  1002. printf("error from script %d\n", args.return_code);
  1003. args.return_code = EXIT_FAILURE;
  1004. goto exit;
  1005. }
  1006. #endif
  1007. #endif
  1008. #if defined(WOLFSSL_ENCRYPTED_KEYS) && !defined(NO_DES3) && !defined(NO_MD5) &&\
  1009. !defined(NO_SHA)
  1010. /* test encrypted keys */
  1011. strcpy(argv0[1], "tests/test-enckeys.conf");
  1012. printf("starting encrypted keys extra cipher suite tests\n");
  1013. test_harness(&args);
  1014. if (args.return_code != 0) {
  1015. printf("error from script %d\n", args.return_code);
  1016. args.return_code = EXIT_FAILURE;
  1017. goto exit;
  1018. }
  1019. #endif
  1020. #ifdef HAVE_MAX_FRAGMENT
  1021. /* Max fragment cipher suite tests */
  1022. strcpy(argv0[1], "tests/test-maxfrag.conf");
  1023. printf("starting max fragment cipher suite tests\n");
  1024. test_harness(&args);
  1025. if (args.return_code != 0) {
  1026. printf("error from script %d\n", args.return_code);
  1027. args.return_code = EXIT_FAILURE;
  1028. goto exit;
  1029. }
  1030. #ifdef WOLFSSL_DTLS
  1031. strcpy(argv0[1], "tests/test-maxfrag-dtls.conf");
  1032. printf("starting dtls max fragment cipher suite tests\n");
  1033. test_harness(&args);
  1034. if (args.return_code != 0) {
  1035. printf("error from script %d\n", args.return_code);
  1036. args.return_code = EXIT_FAILURE;
  1037. goto exit;
  1038. }
  1039. #endif
  1040. #endif
  1041. #ifdef WOLFSSL_ALT_CERT_CHAINS
  1042. /* tests for alt chains */
  1043. strcpy(argv0[1], "tests/test-altchains.conf");
  1044. printf("starting certificate alternate chain cipher suite tests\n");
  1045. test_harness(&args);
  1046. if (args.return_code != 0) {
  1047. printf("error from script %d\n", args.return_code);
  1048. args.return_code = EXIT_FAILURE;
  1049. goto exit;
  1050. }
  1051. #else
  1052. /* tests for chains */
  1053. strcpy(argv0[1], "tests/test-chains.conf");
  1054. printf("starting certificate chain cipher suite tests\n");
  1055. test_harness(&args);
  1056. if (args.return_code != 0) {
  1057. printf("error from script %d\n", args.return_code);
  1058. args.return_code = EXIT_FAILURE;
  1059. goto exit;
  1060. }
  1061. #endif
  1062. #ifdef WOLFSSL_TRUST_PEER_CERT
  1063. /* tests for trusted peer cert */
  1064. strcpy(argv0[1], "tests/test-trustpeer.conf");
  1065. printf("starting trusted peer certificate cipher suite tests\n");
  1066. test_harness(&args);
  1067. if (args.return_code != 0) {
  1068. printf("error from script %d\n", args.return_code);
  1069. args.return_code = EXIT_FAILURE;
  1070. goto exit;
  1071. }
  1072. #endif
  1073. /* tests for dh prime */
  1074. args.argc = 3;
  1075. strcpy(argv0[1], "tests/test-dhprime.conf");
  1076. strcpy(argv0[2], "doDH"); /* add DH prime flag */
  1077. printf("starting dh prime tests\n");
  1078. test_harness(&args);
  1079. if (args.return_code != 0) {
  1080. printf("error from script %d\n", args.return_code);
  1081. args.return_code = EXIT_FAILURE;
  1082. goto exit;
  1083. }
  1084. /* failure tests */
  1085. args.argc = 3;
  1086. strcpy(argv0[1], "tests/test-fails.conf");
  1087. strcpy(argv0[2], "expFail"); /* tests are expected to fail */
  1088. printf("starting tests that expect failure\n");
  1089. test_harness(&args);
  1090. if (args.return_code != 0) {
  1091. printf("error from script %d\n", args.return_code);
  1092. args.return_code = EXIT_FAILURE;
  1093. goto exit;
  1094. }
  1095. exit:
  1096. if (args.return_code == 0)
  1097. printf("\n Success -- All results as expected.\n");
  1098. printf(" End Cipher Suite Tests\n");
  1099. wolfSSL_CTX_free(cipherSuiteCtx);
  1100. wolfSSL_Cleanup();
  1101. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS) \
  1102. && (defined(NO_MAIN_DRIVER) || defined(HAVE_STACK_SIZE))
  1103. wc_ecc_fp_free(); /* free per thread cache */
  1104. #endif
  1105. #ifdef WOLFSSL_ASYNC_CRYPT
  1106. wolfAsync_DevClose(&devId);
  1107. #endif
  1108. return args.return_code;
  1109. #else
  1110. return NOT_COMPILED_IN;
  1111. (void)argc;
  1112. (void)argv;
  1113. #endif /* !NO_WOLFSSL_SERVER && !NO_WOLFSSL_CLIENT */
  1114. }