suites.c 41 KB

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