2
0

echoserver.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. /* echoserver.c
  2. *
  3. * Copyright (C) 2006-2024 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. #ifdef HAVE_CONFIG_H
  22. #include <config.h>
  23. #endif
  24. #ifndef WOLFSSL_USER_SETTINGS
  25. #include <wolfssl/options.h>
  26. #endif
  27. #include <wolfssl/wolfcrypt/settings.h>
  28. #undef TEST_OPENSSL_COEXIST /* can't use this option with this example */
  29. #undef OPENSSL_COEXIST /* can't use this option with this example */
  30. #include <wolfssl/ssl.h> /* name change portability layer */
  31. #include <wolfssl/wolfcrypt/settings.h>
  32. #ifdef HAVE_ECC
  33. #include <wolfssl/wolfcrypt/ecc.h> /* ecc_fp_free */
  34. #endif
  35. #if defined(WOLFSSL_MDK_ARM) || defined(WOLFSSL_KEIL_TCP_NET)
  36. #include <stdio.h>
  37. #include <string.h>
  38. #include "cmsis_os.h"
  39. #include "rl_fs.h"
  40. #include "rl_net.h"
  41. #include "wolfssl_MDK_ARM.h"
  42. #endif
  43. #include <wolfssl/ssl.h>
  44. #include <wolfssl/test.h>
  45. #ifndef NO_MAIN_DRIVER
  46. #define ECHO_OUT
  47. #endif
  48. #include "examples/echoserver/echoserver.h"
  49. #ifndef NO_WOLFSSL_SERVER
  50. #ifdef NO_FILESYSTEM
  51. #ifdef NO_RSA
  52. #error currently the example only tries to load in a RSA buffer
  53. #endif
  54. #undef USE_CERT_BUFFERS_2048
  55. #define USE_CERT_BUFFERS_2048
  56. #include <wolfssl/certs_test.h>
  57. #endif
  58. #ifdef WOLFSSL_ASYNC_CRYPT
  59. static int devId = INVALID_DEVID;
  60. #endif
  61. #define SVR_COMMAND_SIZE 256
  62. static void SignalReady(void* args, word16 port)
  63. {
  64. #if defined(NO_MAIN_DRIVER) && defined(WOLFSSL_COND)
  65. /* signal ready to tcp_accept */
  66. func_args* server_args = (func_args*)args;
  67. tcp_ready* ready = server_args->signal;
  68. THREAD_CHECK_RET(wolfSSL_CondStart(&ready->cond));
  69. ready->ready = 1;
  70. ready->port = port;
  71. THREAD_CHECK_RET(wolfSSL_CondSignal(&ready->cond));
  72. THREAD_CHECK_RET(wolfSSL_CondEnd(&ready->cond));
  73. #endif /* NO_MAIN_DRIVER && WOLFSSL_COND */
  74. (void)args;
  75. (void)port;
  76. }
  77. THREAD_RETURN WOLFSSL_THREAD echoserver_test(void* args)
  78. {
  79. SOCKET_T sockfd = 0;
  80. WOLFSSL_METHOD* method = 0;
  81. WOLFSSL_CTX* ctx = 0;
  82. int ret = 0;
  83. int doDTLS = 0;
  84. int doPSK;
  85. int outCreated = 0;
  86. int shutDown = 0;
  87. int useAnyAddr = 0;
  88. word16 port;
  89. int argc = ((func_args*)args)->argc;
  90. char** argv = ((func_args*)args)->argv;
  91. char buffer[WOLFSSL_MAX_ERROR_SZ];
  92. #ifdef HAVE_TEST_SESSION_TICKET
  93. MyTicketCtx myTicketCtx;
  94. #endif
  95. #ifdef ECHO_OUT
  96. FILE* fout = stdout;
  97. if (argc >= 2) {
  98. fout = fopen(argv[1], "w");
  99. outCreated = 1;
  100. }
  101. if (!fout) err_sys("can't open output file");
  102. #endif
  103. (void)outCreated;
  104. (void)argc;
  105. (void)argv;
  106. ((func_args*)args)->return_code = -1; /* error state */
  107. #ifdef WOLFSSL_DTLS
  108. doDTLS = 1;
  109. #endif
  110. #if (defined(NO_RSA) && !defined(HAVE_ECC) && !defined(HAVE_ED25519) && \
  111. !defined(HAVE_ED448)) || defined(WOLFSSL_LEANPSK)
  112. doPSK = 1;
  113. #else
  114. doPSK = 0;
  115. #endif
  116. #if defined(NO_MAIN_DRIVER) && !defined(WOLFSSL_SNIFFER) && \
  117. !defined(WOLFSSL_MDK_SHELL) && !defined(WOLFSSL_TIRTOS) && \
  118. !defined(USE_WINDOWS_API)
  119. /* Let tcp_listen assign port */
  120. port = 0;
  121. #else
  122. /* Use default port */
  123. port = wolfSSLPort;
  124. #endif
  125. #if defined(USE_ANY_ADDR)
  126. useAnyAddr = 1;
  127. #endif
  128. #ifdef WOLFSSL_TIRTOS
  129. fdOpenSession(Task_self());
  130. #endif
  131. tcp_listen(&sockfd, &port, useAnyAddr, doDTLS, 0);
  132. #if defined(WOLFSSL_DTLS)
  133. #ifdef WOLFSSL_DTLS13
  134. method = wolfDTLSv1_3_server_method();
  135. #elif !defined(WOLFSSL_NO_TLS12)
  136. method = wolfDTLSv1_2_server_method();
  137. #endif
  138. #elif !defined(NO_TLS)
  139. #if defined(WOLFSSL_TLS13) && defined(WOLFSSL_SNIFFER)
  140. method = wolfTLSv1_2_server_method();
  141. #else
  142. method = wolfSSLv23_server_method();
  143. #endif
  144. #elif defined(WOLFSSL_ALLOW_SSLV3)
  145. method = wolfSSLv3_server_method();
  146. #else
  147. #error "no valid server method built in"
  148. #endif
  149. ctx = wolfSSL_CTX_new(method);
  150. /* wolfSSL_CTX_set_session_cache_mode(ctx, WOLFSSL_SESS_CACHE_OFF); */
  151. #ifdef WOLFSSL_ENCRYPTED_KEYS
  152. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  153. #endif
  154. #ifdef HAVE_TEST_SESSION_TICKET
  155. if (TicketInit() != 0)
  156. err_sys("unable to setup Session Ticket Key context");
  157. wolfSSL_CTX_set_TicketEncCb(ctx, myTicketEncCb);
  158. XMEMSET(&myTicketCtx, 0, sizeof(myTicketCtx));
  159. wolfSSL_CTX_set_TicketEncCtx(ctx, &myTicketCtx);
  160. #endif
  161. #ifndef NO_FILESYSTEM
  162. if (doPSK == 0) {
  163. #if defined(HAVE_ECC) && !defined(WOLFSSL_SNIFFER)
  164. /* ecc */
  165. if (wolfSSL_CTX_use_certificate_file(ctx, eccCertFile, WOLFSSL_FILETYPE_PEM)
  166. != WOLFSSL_SUCCESS)
  167. err_sys("can't load server cert file, "
  168. "Please run from wolfSSL home dir");
  169. if (wolfSSL_CTX_use_PrivateKey_file(ctx, eccKeyFile, WOLFSSL_FILETYPE_PEM)
  170. != WOLFSSL_SUCCESS)
  171. err_sys("can't load server key file, "
  172. "Please run from wolfSSL home dir");
  173. #elif defined(HAVE_ED25519) && !defined(WOLFSSL_SNIFFER)
  174. /* ed25519 */
  175. if (wolfSSL_CTX_use_certificate_chain_file(ctx, edCertFile)
  176. != WOLFSSL_SUCCESS)
  177. err_sys("can't load server cert file, "
  178. "Please run from wolfSSL home dir");
  179. if (wolfSSL_CTX_use_PrivateKey_file(ctx, edKeyFile, WOLFSSL_FILETYPE_PEM)
  180. != WOLFSSL_SUCCESS)
  181. err_sys("can't load server key file, "
  182. "Please run from wolfSSL home dir");
  183. #elif defined(HAVE_ED448) && !defined(WOLFSSL_SNIFFER)
  184. /* ed448 */
  185. if (wolfSSL_CTX_use_certificate_chain_file(ctx, ed448CertFile)
  186. != WOLFSSL_SUCCESS)
  187. err_sys("can't load server cert file, "
  188. "Please run from wolfSSL home dir");
  189. if (wolfSSL_CTX_use_PrivateKey_file(ctx, ed448KeyFile,
  190. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS)
  191. err_sys("can't load server key file, "
  192. "Please run from wolfSSL home dir");
  193. #elif defined(NO_CERTS)
  194. /* do nothing, just don't load cert files */
  195. #else
  196. /* normal */
  197. if (wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, WOLFSSL_FILETYPE_PEM)
  198. != WOLFSSL_SUCCESS)
  199. err_sys("can't load server cert file, "
  200. "Please run from wolfSSL home dir");
  201. if (wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, WOLFSSL_FILETYPE_PEM)
  202. != WOLFSSL_SUCCESS)
  203. err_sys("can't load server key file, "
  204. "Please run from wolfSSL home dir");
  205. #endif
  206. } /* doPSK */
  207. #elif !defined(NO_CERTS)
  208. if (!doPSK) {
  209. if (wolfSSL_CTX_use_certificate_buffer(ctx, server_cert_der_2048,
  210. sizeof_server_cert_der_2048, WOLFSSL_FILETYPE_ASN1)
  211. != WOLFSSL_SUCCESS)
  212. err_sys("can't load server cert buffer");
  213. if (wolfSSL_CTX_use_PrivateKey_buffer(ctx, server_key_der_2048,
  214. sizeof_server_key_der_2048, WOLFSSL_FILETYPE_ASN1)
  215. != WOLFSSL_SUCCESS)
  216. err_sys("can't load server key buffer");
  217. }
  218. #endif
  219. #if defined(WOLFSSL_SNIFFER)
  220. /* Only set if not running testsuite */
  221. if (XSTRSTR(argv[0], "testsuite") == NULL) {
  222. /* don't use EDH, can't sniff tmp keys */
  223. wolfSSL_CTX_set_cipher_list(ctx, "AES256-SHA");
  224. }
  225. #endif
  226. if (doPSK) {
  227. #ifndef NO_PSK
  228. const char *defaultCipherList;
  229. wolfSSL_CTX_set_psk_server_callback(ctx, my_psk_server_cb);
  230. wolfSSL_CTX_use_psk_identity_hint(ctx, "cyassl server");
  231. #ifdef HAVE_NULL_CIPHER
  232. defaultCipherList = "PSK-NULL-SHA256";
  233. #elif defined(HAVE_AESGCM) && !defined(NO_DH)
  234. #ifdef WOLFSSL_TLS13
  235. defaultCipherList = "TLS13-AES128-GCM-SHA256"
  236. #ifndef WOLFSSL_NO_TLS12
  237. ":DHE-PSK-AES128-GCM-SHA256"
  238. #endif
  239. ;
  240. #else
  241. defaultCipherList = "DHE-PSK-AES128-GCM-SHA256";
  242. #endif
  243. #elif defined(HAVE_AESGCM) && defined(WOLFSSL_TLS13)
  244. defaultCipherList = "TLS13-AES128-GCM-SHA256"
  245. #ifndef WOLFSSL_NO_TLS12
  246. ":PSK-AES128-GCM-SHA256"
  247. #endif
  248. ;
  249. #else
  250. defaultCipherList = "PSK-AES128-CBC-SHA256";
  251. #endif
  252. if (wolfSSL_CTX_set_cipher_list(ctx, defaultCipherList) != WOLFSSL_SUCCESS)
  253. err_sys("server can't set cipher list 2");
  254. wolfSSL_CTX_set_psk_callback_ctx(ctx, (void*)defaultCipherList);
  255. #endif
  256. }
  257. #ifdef WOLFSSL_ASYNC_CRYPT
  258. ret = wolfAsync_DevOpen(&devId);
  259. if (ret < 0) {
  260. fprintf(stderr, "Async device open failed\nRunning without async\n");
  261. }
  262. wolfSSL_CTX_SetDevId(ctx, devId);
  263. #endif /* WOLFSSL_ASYNC_CRYPT */
  264. SignalReady(args, port);
  265. while (!shutDown) {
  266. WOLFSSL* ssl = NULL;
  267. WOLFSSL* write_ssl = NULL; /* may have separate w/ HAVE_WRITE_DUP */
  268. char command[SVR_COMMAND_SIZE+1];
  269. int clientfd;
  270. int firstRead = 1;
  271. int gotFirstG = 0;
  272. int err = 0;
  273. SOCKADDR_IN_T client;
  274. socklen_t client_len = sizeof(client);
  275. #ifndef WOLFSSL_DTLS
  276. clientfd = accept(sockfd, (struct sockaddr*)&client,
  277. (ACCEPT_THIRD_T)&client_len);
  278. #else
  279. clientfd = sockfd;
  280. {
  281. /* For DTLS, peek at the next datagram so we can get the client's
  282. * address and set it into the ssl object later to generate the
  283. * cookie. */
  284. int n;
  285. byte b[1500];
  286. n = (int)recvfrom(clientfd, (char*)b, sizeof(b), MSG_PEEK,
  287. (struct sockaddr*)&client, &client_len);
  288. if (n <= 0)
  289. err_sys("recvfrom failed");
  290. }
  291. #endif
  292. if (WOLFSSL_SOCKET_IS_INVALID(clientfd)) err_sys("tcp accept failed");
  293. ssl = wolfSSL_new(ctx);
  294. if (ssl == NULL) err_sys("SSL_new failed");
  295. wolfSSL_set_fd(ssl, clientfd);
  296. #ifdef WOLFSSL_DTLS
  297. wolfSSL_dtls_set_peer(ssl, &client, client_len);
  298. #endif
  299. #if !defined(NO_FILESYSTEM) && !defined(NO_DH) && !defined(NO_ASN)
  300. wolfSSL_SetTmpDH_file(ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
  301. #elif !defined(NO_DH)
  302. SetDH(ssl); /* will repick suites with DHE, higher than PSK */
  303. #endif
  304. do {
  305. err = 0; /* Reset error */
  306. ret = wolfSSL_accept(ssl);
  307. if (ret != WOLFSSL_SUCCESS) {
  308. err = wolfSSL_get_error(ssl, 0);
  309. #ifdef WOLFSSL_ASYNC_CRYPT
  310. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  311. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  312. if (ret < 0) break;
  313. }
  314. #endif
  315. }
  316. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  317. if (ret != WOLFSSL_SUCCESS) {
  318. fprintf(stderr, "SSL_accept error = %d, %s\n", err,
  319. wolfSSL_ERR_error_string((unsigned long)err, buffer));
  320. fprintf(stderr, "SSL_accept failed\n");
  321. wolfSSL_free(ssl);
  322. CloseSocket(clientfd);
  323. continue;
  324. }
  325. #if defined(PEER_INFO)
  326. showPeer(ssl);
  327. #endif
  328. #ifdef HAVE_WRITE_DUP
  329. write_ssl = wolfSSL_write_dup(ssl);
  330. if (write_ssl == NULL) {
  331. fprintf(stderr, "wolfSSL_write_dup failed\n");
  332. wolfSSL_free(ssl);
  333. CloseSocket(clientfd);
  334. continue;
  335. }
  336. #else
  337. write_ssl = ssl;
  338. #endif
  339. while (1) {
  340. int echoSz;
  341. do {
  342. err = 0; /* reset error */
  343. ret = wolfSSL_read(ssl, command, sizeof(command)-1);
  344. if (ret <= 0) {
  345. err = wolfSSL_get_error(ssl, 0);
  346. #ifdef WOLFSSL_ASYNC_CRYPT
  347. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  348. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  349. if (ret < 0) break;
  350. }
  351. #endif
  352. }
  353. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  354. if (ret <= 0) {
  355. if (err != WOLFSSL_ERROR_WANT_READ && err != WOLFSSL_ERROR_ZERO_RETURN){
  356. fprintf(stderr, "SSL_read echo error %d, %s!\n", err,
  357. wolfSSL_ERR_error_string((unsigned long)err, buffer));
  358. }
  359. break;
  360. }
  361. echoSz = ret;
  362. if (firstRead == 1) {
  363. firstRead = 0; /* browser may send 1 byte 'G' to start */
  364. if (echoSz == 1 && command[0] == 'G') {
  365. gotFirstG = 1;
  366. continue;
  367. }
  368. }
  369. else if (gotFirstG == 1 && strncmp(command, "ET /", 4) == 0) {
  370. strncpy(command, "GET", 4);
  371. /* fall through to normal GET */
  372. }
  373. if ( strncmp(command, "quit", 4) == 0) {
  374. printf("client sent quit command: shutting down!\n");
  375. shutDown = 1;
  376. break;
  377. }
  378. if ( strncmp(command, "break", 5) == 0) {
  379. printf("client sent break command: closing session!\n");
  380. break;
  381. }
  382. #ifdef PRINT_SESSION_STATS
  383. if ( strncmp(command, "printstats", 10) == 0) {
  384. wolfSSL_PrintSessionStats();
  385. break;
  386. }
  387. #endif
  388. if (strncmp(command, "GET", 3) == 0) {
  389. const char resp[] =
  390. "HTTP/1.0 200 ok\r\nContent-type: text/html\r\n\r\n"
  391. "<html><body BGCOLOR=\"#ffffff\"><pre>\r\n"
  392. "greetings from wolfSSL\r\n</pre></body></html>\r\n\r\n";
  393. echoSz = (int)strlen(resp) + 1;
  394. if (echoSz > (int)sizeof(command)) {
  395. /* Internal error. */
  396. err_sys("HTTP response greater than buffer.");
  397. }
  398. strncpy(command, resp, sizeof(command));
  399. do {
  400. err = 0; /* reset error */
  401. ret = wolfSSL_write(write_ssl, command, echoSz);
  402. if (ret <= 0) {
  403. err = wolfSSL_get_error(write_ssl, 0);
  404. #ifdef WOLFSSL_ASYNC_CRYPT
  405. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  406. ret = wolfSSL_AsyncPoll(write_ssl, WOLF_POLL_FLAG_CHECK_HW);
  407. if (ret < 0) break;
  408. }
  409. #endif
  410. }
  411. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  412. if (ret != echoSz) {
  413. fprintf(stderr, "SSL_write get error = %d, %s\n", err,
  414. wolfSSL_ERR_error_string((unsigned long)err, buffer));
  415. err_sys("SSL_write get failed");
  416. }
  417. break;
  418. }
  419. command[echoSz] = 0;
  420. #ifdef ECHO_OUT
  421. LIBCALL_CHECK_RET(fputs(command, fout));
  422. #endif
  423. do {
  424. err = 0; /* reset error */
  425. ret = wolfSSL_write(write_ssl, command, echoSz);
  426. if (ret <= 0) {
  427. err = wolfSSL_get_error(write_ssl, 0);
  428. #ifdef WOLFSSL_ASYNC_CRYPT
  429. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  430. ret = wolfSSL_AsyncPoll(write_ssl, WOLF_POLL_FLAG_CHECK_HW);
  431. if (ret < 0) break;
  432. }
  433. #endif
  434. }
  435. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  436. if (ret != echoSz) {
  437. fprintf(stderr, "SSL_write echo error = %d, %s\n", err,
  438. wolfSSL_ERR_error_string((unsigned long)err, buffer));
  439. err_sys("SSL_write echo failed");
  440. }
  441. }
  442. #ifndef WOLFSSL_DTLS
  443. wolfSSL_shutdown(ssl);
  444. #endif
  445. #ifdef HAVE_WRITE_DUP
  446. wolfSSL_free(write_ssl);
  447. #endif
  448. wolfSSL_free(ssl);
  449. CloseSocket(clientfd);
  450. #ifdef WOLFSSL_DTLS
  451. tcp_listen(&sockfd, &port, useAnyAddr, doDTLS, 0);
  452. SignalReady(args, port);
  453. #endif
  454. }
  455. CloseSocket(sockfd);
  456. wolfSSL_CTX_free(ctx);
  457. #ifdef ECHO_OUT
  458. if (outCreated)
  459. fclose(fout);
  460. #endif
  461. ((func_args*)args)->return_code = 0;
  462. #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
  463. && defined(HAVE_THREAD_LS)
  464. wc_ecc_fp_free(); /* free per thread cache */
  465. #endif
  466. #ifdef WOLFSSL_TIRTOS
  467. fdCloseSession(Task_self());
  468. #endif
  469. #ifdef HAVE_TEST_SESSION_TICKET
  470. TicketCleanup();
  471. #endif
  472. #ifdef WOLFSSL_ASYNC_CRYPT
  473. wolfAsync_DevClose(&devId);
  474. #endif
  475. WOLFSSL_RETURN_FROM_THREAD(0);
  476. }
  477. #endif /* !NO_WOLFSSL_SERVER */
  478. /* so overall tests can pull in test function */
  479. #ifndef NO_MAIN_DRIVER
  480. int main(int argc, char** argv)
  481. {
  482. func_args args;
  483. #ifdef HAVE_WNR
  484. if (wc_InitNetRandom(wnrConfig, NULL, 5000) != 0)
  485. err_sys("Whitewood netRandom global config failed");
  486. #endif
  487. StartTCP();
  488. args.argc = argc;
  489. args.argv = argv;
  490. args.return_code = 0;
  491. wolfSSL_Init();
  492. #if defined(DEBUG_WOLFSSL) && !defined(WOLFSSL_MDK_SHELL)
  493. wolfSSL_Debugging_ON();
  494. #endif
  495. ChangeToWolfRoot();
  496. #ifndef NO_WOLFSSL_SERVER
  497. echoserver_test(&args);
  498. #endif
  499. wolfSSL_Cleanup();
  500. #ifdef HAVE_WNR
  501. if (wc_FreeNetRandom() < 0)
  502. err_sys("Failed to free netRandom context");
  503. #endif /* HAVE_WNR */
  504. return args.return_code;
  505. }
  506. #endif /* NO_MAIN_DRIVER */