1
0

suites.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417
  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. rewind(file);
  575. script = (char*)malloc(sz+1);
  576. if (script == 0) {
  577. fprintf(stderr, "unable to allocate script buffer\n");
  578. fclose(file);
  579. args->return_code = 1;
  580. return;
  581. }
  582. len = fread(script, 1, sz, file);
  583. if (len != sz) {
  584. fprintf(stderr, "read error\n");
  585. fclose(file);
  586. free(script);
  587. args->return_code = 1;
  588. return;
  589. }
  590. fclose(file);
  591. script[sz] = 0;
  592. cursor = script;
  593. svrArgsSz = 1;
  594. svrArgs[0] = args->argv[0];
  595. cliArgsSz = 1;
  596. cliArgs[0] = args->argv[0];
  597. while (cursor && *cursor != 0) {
  598. switch (*cursor) {
  599. case '\n':
  600. /* A blank line triggers test case execution or switches
  601. to client mode if we don't have the client command yet */
  602. if (lastChar != '\n' && (cliArgsSz > 1 || svrArgsSz > 1)) {
  603. if (cliMode == 0)
  604. cliMode = 1; /* switch to client mode processing */
  605. else
  606. do_it = 1; /* Do It, we have server and client */
  607. }
  608. #ifdef DEBUG_SUITE_TESTS
  609. else {
  610. /* skip extra new-lines */
  611. printf("skipping extra new line\n");
  612. }
  613. #endif
  614. lastChar = *cursor;
  615. cursor++;
  616. break;
  617. case '#':
  618. lastChar = *cursor;
  619. /* Ignore lines that start with a # */
  620. comment = XSTRSEP(&cursor, "\n");
  621. #ifdef DEBUG_SUITE_TESTS
  622. printf("%s\n", comment);
  623. #else
  624. (void)comment;
  625. #endif
  626. break;
  627. case '-':
  628. default:
  629. /* Parameters start with a -. They end in either a newline
  630. * or a space. Capture until either, save in Args list. */
  631. lastChar = *cursor;
  632. if (cliMode)
  633. cliArgs[cliArgsSz++] = XSTRSEP(&cursor, " \n");
  634. else
  635. svrArgs[svrArgsSz++] = XSTRSEP(&cursor, " \n");
  636. if (cursor == NULL || *cursor == '\0') /* eof */
  637. do_it = 1;
  638. break;
  639. }
  640. if (svrArgsSz == MAX_ARGS || cliArgsSz == MAX_ARGS) {
  641. fprintf(stderr, "too many arguments, forcing test run\n");
  642. do_it = 1;
  643. }
  644. if (do_it) {
  645. /* additional arguments processing */
  646. if (cliArgsSz+2 < MAX_ARGS && svrArgsSz+2 < MAX_ARGS) {
  647. if (addArgs == NULL || XSTRSTR(addArgs, "doDH") == NULL) {
  648. /* The `-2` disable DH prime check is added to all tests by default */
  649. cliArgs[cliArgsSz++] = disableDHPrimeTest;
  650. svrArgs[svrArgsSz++] = disableDHPrimeTest;
  651. }
  652. if (addArgs && XSTRSTR(addArgs, "expFail")) {
  653. /* Tests should expect to fail */
  654. cliArgs[cliArgsSz++] = intTestFlag;
  655. cliArgs[cliArgsSz++] = exitWithRetFlag;
  656. svrArgs[svrArgsSz++] = intTestFlag;
  657. svrArgs[svrArgsSz++] = exitWithRetFlag;
  658. }
  659. }
  660. ret = execute_test_case(svrArgsSz, svrArgs,
  661. cliArgsSz, cliArgs, 0, 0, 0, 0, 0);
  662. /* don't repeat if not supported in build */
  663. if (ret == 0) {
  664. /* test with default cipher list on server side */
  665. execute_test_case(svrArgsSz, svrArgs,
  666. cliArgsSz, cliArgs, 0, 0, 0, 1, 0);
  667. /* test with default cipher list on client side */
  668. execute_test_case(svrArgsSz, svrArgs,
  669. cliArgsSz, cliArgs, 0, 0, 0, 0, 1);
  670. execute_test_case(svrArgsSz, svrArgs,
  671. cliArgsSz, cliArgs, 0, 1, 0, 0, 0);
  672. execute_test_case(svrArgsSz, svrArgs,
  673. cliArgsSz, cliArgs, 1, 0, 0, 0, 0);
  674. execute_test_case(svrArgsSz, svrArgs,
  675. cliArgsSz, cliArgs, 1, 1, 0, 0, 0);
  676. #ifdef HAVE_EXTENDED_MASTER
  677. execute_test_case(svrArgsSz, svrArgs,
  678. cliArgsSz, cliArgs, 0, 0, 1, 0, 0);
  679. execute_test_case(svrArgsSz, svrArgs,
  680. cliArgsSz, cliArgs, 0, 1, 1, 0, 0);
  681. execute_test_case(svrArgsSz, svrArgs,
  682. cliArgsSz, cliArgs, 1, 0, 1, 0, 0);
  683. execute_test_case(svrArgsSz, svrArgs,
  684. cliArgsSz, cliArgs, 1, 1, 1, 0, 0);
  685. #endif
  686. }
  687. svrArgsSz = 1;
  688. cliArgsSz = 1;
  689. cliMode = 0;
  690. do_it = 0;
  691. }
  692. }
  693. free(script);
  694. args->return_code = 0;
  695. }
  696. #endif /* !NO_WOLFSSL_SERVER && !NO_WOLFSSL_CLIENT */
  697. int SuiteTest(int argc, char** argv)
  698. {
  699. #if !defined(NO_WOLFSSL_SERVER) && !defined(NO_WOLFSSL_CLIENT) && \
  700. !defined(WOLF_CRYPTO_CB_ONLY_RSA) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  701. func_args args;
  702. char argv0[3][80];
  703. char* myArgv[3];
  704. printf(" Begin Cipher Suite Tests\n");
  705. /* setup */
  706. myArgv[0] = argv0[0];
  707. myArgv[1] = argv0[1];
  708. myArgv[2] = argv0[2];
  709. args.argv = myArgv;
  710. XSTRLCPY(argv0[0], "SuiteTest", sizeof(argv0[0]));
  711. #ifdef WOLFSSL_STATIC_MEMORY
  712. byte memory[200000];
  713. #endif
  714. cipherSuiteCtx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  715. if (cipherSuiteCtx == NULL) {
  716. printf("can't get cipher suite ctx\n");
  717. args.return_code = EXIT_FAILURE;
  718. goto exit;
  719. }
  720. /* load in static memory buffer if enabled */
  721. #ifdef WOLFSSL_STATIC_MEMORY
  722. if (wolfSSL_CTX_load_static_memory(&cipherSuiteCtx, NULL,
  723. memory, sizeof(memory), 0, 1)
  724. != WOLFSSL_SUCCESS) {
  725. printf("unable to load static memory and create ctx");
  726. args.return_code = EXIT_FAILURE;
  727. goto exit;
  728. }
  729. #endif
  730. #ifdef WOLFSSL_ASYNC_CRYPT
  731. if (wolfAsync_DevOpen(&devId) < 0) {
  732. printf("Async device open failed");
  733. args.return_code = EXIT_FAILURE;
  734. goto exit;
  735. }
  736. wolfSSL_CTX_SetDevId(cipherSuiteCtx, devId);
  737. #endif /* WOLFSSL_ASYNC_CRYPT */
  738. /* support for custom command line tests */
  739. if (argc > 1) {
  740. /* Examples:
  741. ./tests/unit.test tests/test-altchains.conf
  742. ./tests/unit.test tests/test-fails.conf expFail
  743. ./tests/unit.test tests/test-dhprime.conf doDH
  744. */
  745. args.argc = argc;
  746. args.argv = argv;
  747. test_harness(&args);
  748. if (args.return_code != 0) {
  749. printf("error from script %d\n", args.return_code);
  750. args.return_code = EXIT_FAILURE;
  751. }
  752. goto exit;
  753. }
  754. /* default case */
  755. args.argc = 1;
  756. printf("starting default cipher suite tests\n");
  757. test_harness(&args);
  758. if (args.return_code != 0) {
  759. printf("error from script %d\n", args.return_code);
  760. args.return_code = EXIT_FAILURE;
  761. goto exit;
  762. }
  763. /* any extra cases will need another argument */
  764. args.argc = 2;
  765. #ifdef WOLFSSL_OLDTLS_SHA2_CIPHERSUITES
  766. /* SHA-2 cipher suites in old TLS versions */
  767. XSTRLCPY(argv0[1], "tests/test-sha2.conf", sizeof(argv0[1]));
  768. printf("starting SHA-2 cipher suite in old TLS versions tests\n");
  769. test_harness(&args);
  770. if (args.return_code != 0) {
  771. printf("error from script %d\n", args.return_code);
  772. args.return_code = EXIT_FAILURE;
  773. goto exit;
  774. }
  775. #endif
  776. #ifdef WOLFSSL_TLS13
  777. /* add TLSv13 extra suites */
  778. XSTRLCPY(argv0[1], "tests/test-tls13.conf", sizeof(argv0[1]));
  779. printf("starting TLSv13 extra cipher suite tests\n");
  780. test_harness(&args);
  781. if (args.return_code != 0) {
  782. printf("error from script %d\n", args.return_code);
  783. args.return_code = EXIT_FAILURE;
  784. goto exit;
  785. }
  786. #ifdef HAVE_ECC
  787. /* add TLSv13 ECC extra suites */
  788. XSTRLCPY(argv0[1], "tests/test-tls13-ecc.conf", sizeof(argv0[1]));
  789. printf("starting TLSv13 ECC extra cipher suite tests\n");
  790. test_harness(&args);
  791. if (args.return_code != 0) {
  792. printf("error from script %d\n", args.return_code);
  793. args.return_code = EXIT_FAILURE;
  794. goto exit;
  795. }
  796. #endif
  797. #ifndef WOLFSSL_NO_TLS12
  798. /* add TLSv13 downgrade tests */
  799. XSTRLCPY(argv0[1], "tests/test-tls13-down.conf", sizeof(argv0[1]));
  800. printf("starting TLSv13 Downgrade extra tests\n");
  801. test_harness(&args);
  802. if (args.return_code != 0) {
  803. printf("error from script %d\n", args.return_code);
  804. args.return_code = EXIT_FAILURE;
  805. goto exit;
  806. }
  807. #endif
  808. #ifdef HAVE_PQC
  809. /* add TLSv13 pq tests */
  810. XSTRLCPY(argv0[1], "tests/test-tls13-pq.conf", sizeof(argv0[1]));
  811. printf("starting TLSv13 post-quantum groups tests\n");
  812. test_harness(&args);
  813. if (args.return_code != 0) {
  814. printf("error from script %d\n", args.return_code);
  815. args.return_code = EXIT_FAILURE;
  816. goto exit;
  817. }
  818. #ifdef HAVE_LIBOQS
  819. /* add TLSv13 pq tests */
  820. XSTRLCPY(argv0[1], "tests/test-tls13-pq-2.conf", sizeof(argv0[1]));
  821. printf("starting TLSv13 post-quantum groups tests\n");
  822. test_harness(&args);
  823. if (args.return_code != 0) {
  824. printf("error from script %d\n", args.return_code);
  825. args.return_code = EXIT_FAILURE;
  826. goto exit;
  827. }
  828. #endif
  829. #endif
  830. #ifdef HAVE_PQC
  831. /* add TLSv13 pq tests */
  832. XSTRLCPY(argv0[1], "tests/test-tls13-pq.conf", sizeof(argv0[1]));
  833. printf("starting TLSv13 post-quantum groups tests\n");
  834. test_harness(&args);
  835. if (args.return_code != 0) {
  836. printf("error from script %d\n", args.return_code);
  837. args.return_code = EXIT_FAILURE;
  838. goto exit;
  839. }
  840. #ifdef HAVE_LIBOQS
  841. /* add TLSv13 pq tests */
  842. XSTRLCPY(argv0[1], "tests/test-tls13-pq-2.conf", sizeof(argv0[1]));
  843. printf("starting TLSv13 post-quantum groups tests\n");
  844. test_harness(&args);
  845. if (args.return_code != 0) {
  846. printf("error from script %d\n", args.return_code);
  847. args.return_code = EXIT_FAILURE;
  848. goto exit;
  849. }
  850. #endif
  851. #endif
  852. #if defined(HAVE_PQC) && defined(WOLFSSL_DTLS13)
  853. /* add DTLSv13 pq tests */
  854. XSTRLCPY(argv0[1], "tests/test-dtls13-pq.conf", sizeof(argv0[1]));
  855. printf("starting DTLSv13 post-quantum groups tests\n");
  856. test_harness(&args);
  857. if (args.return_code != 0) {
  858. printf("error from script %d\n", args.return_code);
  859. args.return_code = EXIT_FAILURE;
  860. goto exit;
  861. }
  862. #ifdef HAVE_LIBOQS
  863. /* add DTLSv13 pq tests */
  864. XSTRLCPY(argv0[1], "tests/test-dtls13-pq-2.conf", sizeof(argv0[1]));
  865. printf("starting DTLSv13 post-quantum groups tests\n");
  866. test_harness(&args);
  867. if (args.return_code != 0) {
  868. printf("error from script %d\n", args.return_code);
  869. args.return_code = EXIT_FAILURE;
  870. goto exit;
  871. }
  872. #endif
  873. #endif
  874. #endif
  875. #if defined(WC_RSA_PSS) && (!defined(HAVE_FIPS) || \
  876. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) && \
  877. (!defined(HAVE_SELFTEST) || (defined(HAVE_SELFTEST_VERSION) && \
  878. (HAVE_SELFTEST_VERSION > 2)))
  879. /* add RSA-PSS certificate cipher suite tests */
  880. XSTRLCPY(argv0[1], "tests/test-rsapss.conf", sizeof(argv0[1]));
  881. printf("starting RSA-PSS extra cipher suite tests\n");
  882. test_harness(&args);
  883. if (args.return_code != 0) {
  884. printf("error from script %d\n", args.return_code);
  885. args.return_code = EXIT_FAILURE;
  886. goto exit;
  887. }
  888. #endif
  889. #if defined(HAVE_CURVE25519) && defined(HAVE_ED25519) && \
  890. defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_VERIFY) && \
  891. defined(HAVE_ED25519_KEY_IMPORT) && defined(HAVE_ED25519_KEY_EXPORT)
  892. /* add ED25519 certificate cipher suite tests */
  893. XSTRLCPY(argv0[1], "tests/test-ed25519.conf", sizeof(argv0[1]));
  894. printf("starting ED25519 extra cipher suite tests\n");
  895. test_harness(&args);
  896. if (args.return_code != 0) {
  897. printf("error from script %d\n", args.return_code);
  898. args.return_code = EXIT_FAILURE;
  899. goto exit;
  900. }
  901. #endif
  902. #if defined(HAVE_CURVE448) && defined(HAVE_ED448) && \
  903. defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_VERIFY) && \
  904. defined(HAVE_ED448_KEY_IMPORT) && defined(HAVE_ED448_KEY_EXPORT)
  905. /* add ED448 certificate cipher suite tests */
  906. XSTRLCPY(argv0[1], "tests/test-ed448.conf", sizeof(argv0[1]));
  907. printf("starting ED448 extra cipher suite tests\n");
  908. test_harness(&args);
  909. if (args.return_code != 0) {
  910. printf("error from script %d\n", args.return_code);
  911. args.return_code = EXIT_FAILURE;
  912. goto exit;
  913. }
  914. #endif
  915. #if defined(HAVE_ECC) && defined(WOLFSSL_SHA512) && \
  916. (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES))
  917. /* add P-521 certificate cipher suite tests */
  918. XSTRLCPY(argv0[1], "tests/test-p521.conf", sizeof(argv0[1]));
  919. printf("starting P-521 extra cipher suite tests\n");
  920. test_harness(&args);
  921. if (args.return_code != 0) {
  922. printf("error from script %d\n", args.return_code);
  923. args.return_code = EXIT_FAILURE;
  924. goto exit;
  925. }
  926. #endif
  927. #if defined(HAVE_ECC) && !defined(NO_SHA256) && defined(WOLFSSL_CUSTOM_CURVES) && \
  928. defined(HAVE_ECC_KOBLITZ) && defined(HAVE_ECC_BRAINPOOL) && \
  929. /* Intel QuickAssist and Cavium Nitrox do not support custom curves */ \
  930. !defined(HAVE_INTEL_QA) && !defined(HAVE_CAVIUM_V)
  931. /* TLS non-NIST curves (Koblitz / Brainpool) */
  932. XSTRLCPY(argv0[1], "tests/test-ecc-cust-curves.conf", sizeof(argv0[1]));
  933. printf("starting TLS test of non-NIST curves (Koblitz / Brainpool)\n");
  934. test_harness(&args);
  935. if (args.return_code != 0) {
  936. printf("error from script %d\n", args.return_code);
  937. args.return_code = EXIT_FAILURE;
  938. goto exit;
  939. }
  940. #endif
  941. #ifdef WOLFSSL_DTLS
  942. /* add dtls extra suites */
  943. XSTRLCPY(argv0[1], "tests/test-dtls.conf", sizeof(argv0[1]));
  944. printf("starting dtls extra cipher suite tests\n");
  945. test_harness(&args);
  946. if (args.return_code != 0) {
  947. printf("error from script %d\n", args.return_code);
  948. args.return_code = EXIT_FAILURE;
  949. goto exit;
  950. }
  951. /* add dtls grouping tests */
  952. XSTRLCPY(argv0[1], "tests/test-dtls-group.conf", sizeof(argv0[1]));
  953. printf("starting dtls message grouping tests\n");
  954. test_harness(&args);
  955. if (args.return_code != 0) {
  956. printf("error from script %d\n", args.return_code);
  957. args.return_code = EXIT_FAILURE;
  958. goto exit;
  959. }
  960. /* add dtls session resumption tests */
  961. XSTRLCPY(argv0[1], "tests/test-dtls-resume.conf", sizeof(argv0[1]));
  962. printf("starting dtls session resumption tests\n");
  963. test_harness(&args);
  964. if (args.return_code != 0) {
  965. printf("error from script %d\n", args.return_code);
  966. args.return_code = EXIT_FAILURE;
  967. goto exit;
  968. }
  969. #ifdef HAVE_SECURE_RENEGOTIATION
  970. /* add dtls renegotiation tests */
  971. XSTRLCPY(argv0[1], "tests/test-dtls-reneg-client.conf", sizeof(argv0[1]));
  972. printf("starting dtls secure renegotiation client tests\n");
  973. test_harness(&args);
  974. if (args.return_code != 0) {
  975. printf("error from script %d\n", args.return_code);
  976. args.return_code = EXIT_FAILURE;
  977. goto exit;
  978. }
  979. XSTRLCPY(argv0[1], "tests/test-dtls-reneg-server.conf", sizeof(argv0[1]));
  980. printf("starting dtls secure renegotiation server tests\n");
  981. test_harness(&args);
  982. if (args.return_code != 0) {
  983. printf("error from script %d\n", args.return_code);
  984. args.return_code = EXIT_FAILURE;
  985. goto exit;
  986. }
  987. #endif
  988. #ifdef WOLFSSL_DTLS_MTU
  989. /* Add dtls different MTU size tests.
  990. * These also use grouping to force wolfSSL to
  991. * bounce off the MTU limit more */
  992. XSTRLCPY(argv0[1], "tests/test-dtls-mtu.conf", sizeof(argv0[1]));
  993. printf("starting dtls MTU tests\n");
  994. test_harness(&args);
  995. if (args.return_code != 0) {
  996. printf("error from script %d\n", args.return_code);
  997. args.return_code = EXIT_FAILURE;
  998. goto exit;
  999. }
  1000. #endif
  1001. /* Add dtls downgrade test */
  1002. XSTRLCPY(argv0[1], "tests/test-dtls-downgrade.conf", sizeof(argv0[1]));
  1003. printf("starting dtls downgrade tests\n");
  1004. test_harness(&args);
  1005. if (args.return_code != 0) {
  1006. printf("error from script %d\n", args.return_code);
  1007. args.return_code = EXIT_FAILURE;
  1008. goto exit;
  1009. }
  1010. #ifdef WOLFSSL_OLDTLS_SHA2_CIPHERSUITES
  1011. /* add dtls extra suites */
  1012. XSTRLCPY(argv0[1], "tests/test-dtls-sha2.conf", sizeof(argv0[1]));
  1013. printf("starting dtls extra cipher suite tests - old TLS sha-2 cs\n");
  1014. test_harness(&args);
  1015. if (args.return_code != 0) {
  1016. printf("error from script %d\n", args.return_code);
  1017. args.return_code = EXIT_FAILURE;
  1018. goto exit;
  1019. }
  1020. #endif
  1021. #ifndef WOLFSSL_NO_DTLS_SIZE_CHECK
  1022. /* failure tests */
  1023. args.argc = 3;
  1024. XSTRLCPY(argv0[1], "tests/test-dtls-fails.conf", sizeof(argv0[1]));
  1025. XSTRLCPY(argv0[2], "expFail", sizeof(argv0[2])); /* tests are expected to fail */
  1026. printf("starting dtls tests that expect failure\n");
  1027. test_harness(&args);
  1028. if (args.return_code != 0) {
  1029. printf("error from script %d\n", args.return_code);
  1030. args.return_code = EXIT_FAILURE;
  1031. goto exit;
  1032. }
  1033. XSTRLCPY(argv0[2], "", sizeof(argv0[2]));
  1034. #endif
  1035. #ifdef WOLFSSL_EXTRA_ALERTS
  1036. /* failure tests */
  1037. args.argc = 3;
  1038. XSTRLCPY(argv0[1], "tests/test-dtls-fails-cipher.conf", sizeof(argv0[1]));
  1039. XSTRLCPY(argv0[2], "expFail", sizeof(argv0[2])); /* tests are expected to fail */
  1040. printf("starting dtls cipher mismatch tests that expect failure\n");
  1041. test_harness(&args);
  1042. if (args.return_code != 0) {
  1043. printf("error from script %d\n", args.return_code);
  1044. args.return_code = EXIT_FAILURE;
  1045. goto exit;
  1046. }
  1047. XSTRLCPY(argv0[2], "", sizeof(argv0[2]));
  1048. #endif
  1049. #ifdef WOLFSSL_SRTP
  1050. args.argc = 2;
  1051. strcpy(argv0[1], "tests/test-dtls-srtp.conf");
  1052. printf("starting dtls srtp suite tests\n");
  1053. test_harness(&args);
  1054. if (args.return_code != 0) {
  1055. printf("error from script %d\n", args.return_code);
  1056. args.return_code = EXIT_FAILURE;
  1057. goto exit;
  1058. }
  1059. /* failure tests */
  1060. args.argc = 3;
  1061. strcpy(argv0[1], "tests/test-dtls-srtp-fails.conf");
  1062. strcpy(argv0[2], "expFail"); /* tests are expected to fail */
  1063. printf("starting dtls srtp profile mismatch tests that expect failure\n");
  1064. test_harness(&args);
  1065. if (args.return_code != 0) {
  1066. printf("error from script %d\n", args.return_code);
  1067. args.return_code = EXIT_FAILURE;
  1068. goto exit;
  1069. }
  1070. strcpy(argv0[2], "");
  1071. #endif
  1072. #ifdef WOLFSSL_DTLS13
  1073. args.argc = 2;
  1074. strcpy(argv0[1], "tests/test-dtls13.conf");
  1075. printf("starting DTLSv1.3 suite\n");
  1076. test_harness(&args);
  1077. if (args.return_code != 0) {
  1078. printf("error from script %d\n", args.return_code);
  1079. args.return_code = EXIT_FAILURE;
  1080. goto exit;
  1081. }
  1082. #ifndef WOLFSSL_NO_TLS12
  1083. args.argc = 2;
  1084. strcpy(argv0[1], "tests/test-dtls13-downgrade.conf");
  1085. printf("starting DTLSv1.3 suite - downgrade\n");
  1086. test_harness(&args);
  1087. if (args.return_code != 0) {
  1088. printf("error from script %d\n", args.return_code);
  1089. args.return_code = EXIT_FAILURE;
  1090. goto exit;
  1091. }
  1092. args.argc = 3;
  1093. strcpy(argv0[1], "tests/test-dtls13-downgrade-fails.conf");
  1094. strcpy(argv0[2], "expFail");
  1095. printf("starting DTLSv1.3 suite - downgrade - (expFails)\n");
  1096. test_harness(&args);
  1097. if (args.return_code != 0) {
  1098. printf("error from script %d\n", args.return_code);
  1099. args.return_code = EXIT_FAILURE;
  1100. goto exit;
  1101. }
  1102. args.argc = 2;
  1103. XMEMSET(argv0[2], 0, sizeof(argv0[2]));
  1104. #endif /* WOLFSSL_NO_TLS12 */
  1105. #ifndef NO_PSK
  1106. XSTRLCPY(argv0[1], "tests/test-dtls13-psk.conf", sizeof(argv0[1]));
  1107. printf("starting DTLS 1.3 psk suite tests\n");
  1108. test_harness(&args);
  1109. if (args.return_code != 0) {
  1110. printf("error from script %d\n", args.return_code);
  1111. args.return_code = EXIT_FAILURE;
  1112. goto exit;
  1113. }
  1114. #endif /* NO_PSK */
  1115. #ifdef WOLFSSL_DTLS_CID
  1116. XSTRLCPY(argv0[1], "tests/test-dtls13-cid.conf", sizeof(argv0[1]));
  1117. printf("starting DTLS 1.3 ConnectionID suite tests\n");
  1118. test_harness(&args);
  1119. if (args.return_code != 0) {
  1120. printf("error from script %d\n", args.return_code);
  1121. args.return_code = EXIT_FAILURE;
  1122. goto exit;
  1123. }
  1124. #endif /* WOLFSSL_DTLS_CID */
  1125. #endif /* WOLFSSL_DTLS13 */
  1126. #endif
  1127. #ifdef WOLFSSL_SCTP
  1128. /* add dtls-sctp extra suites */
  1129. XSTRLCPY(argv0[1], "tests/test-sctp.conf", sizeof(argv0[1]));
  1130. printf("starting dtls-sctp extra cipher suite tests\n");
  1131. test_harness(&args);
  1132. if (args.return_code != 0) {
  1133. printf("error from script %d\n", args.return_code);
  1134. args.return_code = EXIT_FAILURE;
  1135. goto exit;
  1136. }
  1137. #ifdef WOLFSSL_OLDTLS_SHA2_CIPHERSUITES
  1138. /* add dtls-sctp extra suites */
  1139. XSTRLCPY(argv0[1], "tests/test-sctp-sha2.conf", sizeof(argv0[1]));
  1140. printf("starting dtls-sctp extra cipher suite tests - old TLS sha-2 cs\n");
  1141. test_harness(&args);
  1142. if (args.return_code != 0) {
  1143. printf("error from script %d\n", args.return_code);
  1144. args.return_code = EXIT_FAILURE;
  1145. goto exit;
  1146. }
  1147. #endif
  1148. #endif
  1149. #ifndef WC_STRICT_SIG
  1150. #if !defined(NO_RSA) && defined(HAVE_ECC) /* testing mixed ECC/RSA cert */
  1151. /* add extra signature test suites */
  1152. XSTRLCPY(argv0[1], "tests/test-sig.conf", sizeof(argv0[1]));
  1153. printf("starting sig extra cipher suite tests\n");
  1154. test_harness(&args);
  1155. if (args.return_code != 0) {
  1156. printf("error from script %d\n", args.return_code);
  1157. args.return_code = EXIT_FAILURE;
  1158. goto exit;
  1159. }
  1160. #endif /* HAVE_RSA and HAVE_ECC */
  1161. #endif /* !WC_STRICT_SIG */
  1162. #ifndef NO_PSK
  1163. #ifndef WOLFSSL_NO_TLS12
  1164. #if !defined(NO_RSA) || defined(HAVE_ECC)
  1165. /* add psk cipher suites */
  1166. XSTRLCPY(argv0[1], "tests/test-psk.conf", sizeof(argv0[1]));
  1167. printf("starting psk cipher suite tests\n");
  1168. test_harness(&args);
  1169. if (args.return_code != 0) {
  1170. printf("error from script %d\n", args.return_code);
  1171. args.return_code = EXIT_FAILURE;
  1172. goto exit;
  1173. }
  1174. #endif
  1175. #endif
  1176. #ifdef WOLFSSL_TLS13
  1177. /* add psk extra suites */
  1178. XSTRLCPY(argv0[1], "tests/test-tls13-psk.conf", sizeof(argv0[1]));
  1179. printf("starting TLS 1.3 psk no identity extra cipher suite tests\n");
  1180. test_harness(&args);
  1181. if (args.return_code != 0) {
  1182. printf("error from script %d\n", args.return_code);
  1183. args.return_code = EXIT_FAILURE;
  1184. goto exit;
  1185. }
  1186. #endif
  1187. #endif
  1188. #if defined(WOLFSSL_ENCRYPTED_KEYS) && !defined(NO_DES3) && !defined(NO_MD5) &&\
  1189. !defined(NO_SHA)
  1190. /* test encrypted keys */
  1191. XSTRLCPY(argv0[1], "tests/test-enckeys.conf", sizeof(argv0[1]));
  1192. printf("starting encrypted keys extra cipher suite tests\n");
  1193. test_harness(&args);
  1194. if (args.return_code != 0) {
  1195. printf("error from script %d\n", args.return_code);
  1196. args.return_code = EXIT_FAILURE;
  1197. goto exit;
  1198. }
  1199. #endif
  1200. #ifdef HAVE_MAX_FRAGMENT
  1201. /* Max fragment cipher suite tests */
  1202. XSTRLCPY(argv0[1], "tests/test-maxfrag.conf", sizeof(argv0[1]));
  1203. printf("starting max fragment cipher suite tests\n");
  1204. test_harness(&args);
  1205. if (args.return_code != 0) {
  1206. printf("error from script %d\n", args.return_code);
  1207. args.return_code = EXIT_FAILURE;
  1208. goto exit;
  1209. }
  1210. #ifdef WOLFSSL_DTLS
  1211. XSTRLCPY(argv0[1], "tests/test-maxfrag-dtls.conf", sizeof(argv0[1]));
  1212. printf("starting dtls max fragment cipher suite tests\n");
  1213. test_harness(&args);
  1214. if (args.return_code != 0) {
  1215. printf("error from script %d\n", args.return_code);
  1216. args.return_code = EXIT_FAILURE;
  1217. goto exit;
  1218. }
  1219. #endif
  1220. #endif
  1221. #ifdef WOLFSSL_ALT_CERT_CHAINS
  1222. /* tests for alt chains */
  1223. XSTRLCPY(argv0[1], "tests/test-altchains.conf", sizeof(argv0[1]));
  1224. printf("starting certificate alternate chain cipher suite tests\n");
  1225. test_harness(&args);
  1226. if (args.return_code != 0) {
  1227. printf("error from script %d\n", args.return_code);
  1228. args.return_code = EXIT_FAILURE;
  1229. goto exit;
  1230. }
  1231. #else
  1232. /* tests for chains */
  1233. XSTRLCPY(argv0[1], "tests/test-chains.conf", sizeof(argv0[1]));
  1234. printf("starting certificate chain cipher suite tests\n");
  1235. test_harness(&args);
  1236. if (args.return_code != 0) {
  1237. printf("error from script %d\n", args.return_code);
  1238. args.return_code = EXIT_FAILURE;
  1239. goto exit;
  1240. }
  1241. #endif
  1242. #ifdef WOLFSSL_TRUST_PEER_CERT
  1243. /* tests for trusted peer cert */
  1244. XSTRLCPY(argv0[1], "tests/test-trustpeer.conf", sizeof(argv0[1]));
  1245. printf("starting trusted peer certificate cipher suite tests\n");
  1246. test_harness(&args);
  1247. if (args.return_code != 0) {
  1248. printf("error from script %d\n", args.return_code);
  1249. args.return_code = EXIT_FAILURE;
  1250. goto exit;
  1251. }
  1252. #endif
  1253. /* tests for dh prime */
  1254. args.argc = 3;
  1255. XSTRLCPY(argv0[1], "tests/test-dhprime.conf", sizeof(argv0[1]));
  1256. XSTRLCPY(argv0[2], "doDH", sizeof(argv0[2])); /* add DH prime flag */
  1257. printf("starting dh prime tests\n");
  1258. test_harness(&args);
  1259. if (args.return_code != 0) {
  1260. printf("error from script %d\n", args.return_code);
  1261. args.return_code = EXIT_FAILURE;
  1262. goto exit;
  1263. }
  1264. /* failure tests */
  1265. args.argc = 3;
  1266. XSTRLCPY(argv0[1], "tests/test-fails.conf", sizeof(argv0[1]));
  1267. XSTRLCPY(argv0[2], "expFail", sizeof(argv0[2])); /* tests are expected to fail */
  1268. printf("starting tests that expect failure\n");
  1269. test_harness(&args);
  1270. if (args.return_code != 0) {
  1271. printf("error from script %d\n", args.return_code);
  1272. args.return_code = EXIT_FAILURE;
  1273. goto exit;
  1274. }
  1275. exit:
  1276. if (args.return_code == 0)
  1277. printf("\n Success -- All results as expected.\n");
  1278. printf(" End Cipher Suite Tests\n");
  1279. wolfSSL_CTX_free(cipherSuiteCtx);
  1280. wolfSSL_Cleanup();
  1281. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS) \
  1282. && (defined(NO_MAIN_DRIVER) || defined(HAVE_STACK_SIZE))
  1283. wc_ecc_fp_free(); /* free per thread cache */
  1284. #endif
  1285. #ifdef WOLFSSL_ASYNC_CRYPT
  1286. wolfAsync_DevClose(&devId);
  1287. #endif
  1288. return args.return_code;
  1289. #else
  1290. return NOT_COMPILED_IN;
  1291. (void)argc;
  1292. (void)argv;
  1293. #endif /* !NO_WOLFSSL_SERVER && !NO_WOLFSSL_CLIENT */
  1294. }