suites.c 47 KB

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