suites.c 46 KB

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