suites.c 37 KB

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