suites.c 42 KB

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