suites.c 44 KB

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