suites.c 44 KB

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