2
0

suites.c 47 KB

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