suites.c 38 KB

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