]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Source/WolfSSL/examples/server/server.c
Update WolfSSL library to the latest version.
[freertos] / FreeRTOS-Plus / Source / WolfSSL / examples / server / server.c
1 /* server.c
2  *
3  * Copyright (C) 2006-2015 wolfSSL Inc.
4  *
5  * This file is part of wolfSSL. (formerly known as CyaSSL)
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-1301, USA
20  */
21
22 #ifdef HAVE_CONFIG_H
23     #include <config.h>
24 #endif
25 #include <cyassl/ssl.h> /* name change portability layer */
26
27 #include <cyassl/ctaocrypt/settings.h>
28 #ifdef HAVE_ECC
29     #include <cyassl/ctaocrypt/ecc.h>   /* ecc_fp_free */
30 #endif
31
32 #if !defined(WOLFSSL_TRACK_MEMORY) && !defined(NO_MAIN_DRIVER)
33     /* in case memory tracker wants stats */
34     #define WOLFSSL_TRACK_MEMORY
35 #endif
36
37 #if defined(CYASSL_MDK_ARM)
38         #include <stdio.h>
39         #include <string.h>
40
41         #if defined(CYASSL_MDK5)
42             #include "cmsis_os.h"
43             #include "rl_fs.h" 
44             #include "rl_net.h" 
45         #else
46             #include "rtl.h"
47         #endif
48
49         #include "cyassl_MDK_ARM.h"
50 #endif
51 #include <cyassl/openssl/ssl.h>
52 #include <cyassl/test.h>
53
54 #include "examples/server/server.h"
55
56
57 #ifdef CYASSL_CALLBACKS
58     int srvHandShakeCB(HandShakeInfo*);
59     int srvTimeoutCB(TimeoutInfo*);
60     Timeval srvTo;
61 #endif
62
63 #ifndef NO_HANDSHAKE_DONE_CB
64     int myHsDoneCb(WOLFSSL* ssl, void* user_ctx);
65 #endif
66
67
68
69 static void NonBlockingSSL_Accept(SSL* ssl)
70 {
71 #ifndef CYASSL_CALLBACKS
72     int ret = SSL_accept(ssl);
73 #else
74     int ret = CyaSSL_accept_ex(ssl, srvHandShakeCB, srvTimeoutCB, srvTo);
75 #endif
76     int error = SSL_get_error(ssl, 0);
77     SOCKET_T sockfd = (SOCKET_T)CyaSSL_get_fd(ssl);
78     int select_ret;
79
80     while (ret != SSL_SUCCESS && (error == SSL_ERROR_WANT_READ ||
81                                   error == SSL_ERROR_WANT_WRITE)) {
82         int currTimeout = 1;
83
84         if (error == SSL_ERROR_WANT_READ)
85             printf("... server would read block\n");
86         else
87             printf("... server would write block\n");
88
89 #ifdef CYASSL_DTLS
90         currTimeout = CyaSSL_dtls_get_current_timeout(ssl);
91 #endif
92         select_ret = tcp_select(sockfd, currTimeout);
93
94         if ((select_ret == TEST_RECV_READY) ||
95                                         (select_ret == TEST_ERROR_READY)) {
96             #ifndef CYASSL_CALLBACKS
97                 ret = SSL_accept(ssl);
98             #else
99                 ret = CyaSSL_accept_ex(ssl,
100                                     srvHandShakeCB, srvTimeoutCB, srvTo);
101             #endif
102             error = SSL_get_error(ssl, 0);
103         }
104         else if (select_ret == TEST_TIMEOUT && !CyaSSL_dtls(ssl)) {
105             error = SSL_ERROR_WANT_READ;
106         }
107 #ifdef CYASSL_DTLS
108         else if (select_ret == TEST_TIMEOUT && CyaSSL_dtls(ssl) &&
109                                             CyaSSL_dtls_got_timeout(ssl) >= 0) {
110             error = SSL_ERROR_WANT_READ;
111         }
112 #endif
113         else {
114             error = SSL_FATAL_ERROR;
115         }
116     }
117     if (ret != SSL_SUCCESS)
118         err_sys("SSL_accept failed");
119 }
120
121
122 static void Usage(void)
123 {
124     printf("server "    LIBCYASSL_VERSION_STRING
125            " NOTE: All files relative to wolfSSL home dir\n");
126     printf("-?          Help, print this usage\n");
127     printf("-p <num>    Port to listen on, not 0, default %d\n", yasslPort);
128     printf("-v <num>    SSL version [0-3], SSLv3(0) - TLS1.2(3)), default %d\n",
129                                  SERVER_DEFAULT_VERSION);
130     printf("-l <str>    Cipher list\n");
131     printf("-c <file>   Certificate file,           default %s\n", svrCert);
132     printf("-k <file>   Key file,                   default %s\n", svrKey);
133     printf("-A <file>   Certificate Authority file, default %s\n", cliCert);
134 #ifndef NO_DH
135     printf("-D <file>   Diffie-Hellman Params file, default %s\n", dhParam);
136     printf("-Z <num>    Minimum DH key bits,        default %d\n",
137                                  DEFAULT_MIN_DHKEY_BITS);
138 #endif
139     printf("-d          Disable client cert check\n");
140     printf("-b          Bind to any interface instead of localhost only\n");
141     printf("-s          Use pre Shared keys\n");
142     printf("-t          Track wolfSSL memory use\n");
143     printf("-u          Use UDP DTLS,"
144            " add -v 2 for DTLSv1 (default), -v 3 for DTLSv1.2\n");
145     printf("-f          Fewer packets/group messages\n");
146     printf("-R          Create server ready file, for external monitor\n");
147     printf("-r          Allow one client Resumption\n");
148     printf("-N          Use Non-blocking sockets\n");
149     printf("-S <str>    Use Host Name Indication\n");
150     printf("-w          Wait for bidirectional shutdown\n");
151 #ifdef HAVE_OCSP
152     printf("-o          Perform OCSP lookup on peer certificate\n");
153     printf("-O <url>    Perform OCSP lookup using <url> as responder\n");
154 #endif
155 #ifdef HAVE_PK_CALLBACKS 
156     printf("-P          Public Key Callbacks\n");
157 #endif
158 #ifdef HAVE_ANON
159     printf("-a          Anonymous server\n");
160 #endif
161 }
162
163 THREAD_RETURN CYASSL_THREAD server_test(void* args)
164 {
165     SOCKET_T sockfd   = 0;
166     SOCKET_T clientfd = 0;
167
168     SSL_METHOD* method = 0;
169     SSL_CTX*    ctx    = 0;
170     SSL*        ssl    = 0;
171
172     char   msg[] = "I hear you fa shizzle!";
173     char   input[80];
174     int    idx;
175     int    ch;
176     int    version = SERVER_DEFAULT_VERSION;
177     int    doCliCertCheck = 1;
178     int    useAnyAddr = 0;
179     word16 port = yasslPort;
180     int    usePsk = 0;
181     int    useAnon = 0;
182     int    doDTLS = 0;
183     int    needDH = 0;
184     int    useNtruKey   = 0;
185     int    nonBlocking  = 0;
186     int    trackMemory  = 0;
187     int    fewerPackets = 0;
188     int    pkCallbacks  = 0;
189     int    serverReadyFile = 0;
190     int    wc_shutdown     = 0;
191     int    resume = 0;            /* do resume, and resume count */
192     int    minDhKeyBits = DEFAULT_MIN_DHKEY_BITS;
193     int    ret;
194     char*  cipherList = NULL;
195     const char* verifyCert = cliCert;
196     const char* ourCert    = svrCert;
197     const char* ourKey     = svrKey;
198     const char* ourDhParam = dhParam;
199     int    argc = ((func_args*)args)->argc;
200     char** argv = ((func_args*)args)->argv;
201
202 #ifdef HAVE_SNI
203     char*  sniHostName = NULL;
204 #endif
205
206 #ifdef HAVE_OCSP
207     int    useOcsp  = 0;
208     char*  ocspUrl  = NULL;
209 #endif
210
211     ((func_args*)args)->return_code = -1; /* error state */
212
213 #ifdef NO_RSA
214     verifyCert = (char*)cliEccCert;
215     ourCert    = (char*)eccCert;
216     ourKey     = (char*)eccKey;
217 #endif
218     (void)trackMemory;
219     (void)pkCallbacks;
220     (void)needDH;
221     (void)ourKey;
222     (void)ourCert;
223     (void)ourDhParam;
224     (void)verifyCert;
225     (void)useNtruKey;
226     (void)doCliCertCheck;
227     (void)minDhKeyBits;
228
229 #ifdef CYASSL_TIRTOS
230     fdOpenSession(Task_self());
231 #endif
232
233     while ((ch = mygetopt(argc, argv, "?dbstnNufrRawPp:v:l:A:c:k:Z:S:oO:D:"))
234                          != -1) {
235         switch (ch) {
236             case '?' :
237                 Usage();
238                 exit(EXIT_SUCCESS);
239
240             case 'd' :
241                 doCliCertCheck = 0;
242                 break;
243
244             case 'b' :
245                 useAnyAddr = 1;
246                 break;
247
248             case 's' :
249                 usePsk = 1;
250                 break;
251
252             case 't' :
253             #ifdef USE_WOLFSSL_MEMORY
254                 trackMemory = 1;
255             #endif
256                 break;
257
258             case 'n' :
259                 useNtruKey = 1;
260                 break;
261
262             case 'u' :
263                 doDTLS  = 1;
264                 break;
265
266             case 'f' :
267                 fewerPackets = 1;
268                 break;
269
270             case 'R' :
271                 serverReadyFile = 1;
272                 break;
273
274             case 'r' :
275                 #ifndef NO_SESSION_CACHE
276                     resume = 1;
277                 #endif
278                 break;
279
280             case 'P' :
281             #ifdef HAVE_PK_CALLBACKS 
282                 pkCallbacks = 1;
283             #endif
284                 break;
285
286             case 'p' :
287                 port = (word16)atoi(myoptarg);
288                 #if !defined(NO_MAIN_DRIVER) || defined(USE_WINDOWS_API)
289                     if (port == 0)
290                         err_sys("port number cannot be 0");
291                 #endif
292                 break;
293
294             case 'w' :
295                 wc_shutdown = 1;
296                 break;
297
298             case 'v' :
299                 version = atoi(myoptarg);
300                 if (version < 0 || version > 3) {
301                     Usage();
302                     exit(MY_EX_USAGE);
303                 }
304                 break;
305
306             case 'l' :
307                 cipherList = myoptarg;
308                 break;
309
310             case 'A' :
311                 verifyCert = myoptarg;
312                 break;
313
314             case 'c' :
315                 ourCert = myoptarg;
316                 break;
317
318             case 'k' :
319                 ourKey = myoptarg;
320                 break;
321
322             case 'D' :
323                 #ifndef NO_DH
324                     ourDhParam = myoptarg;
325                 #endif
326                 break;
327
328             case 'Z' :
329                 #ifndef NO_DH
330                     minDhKeyBits = atoi(myoptarg);
331                     if (minDhKeyBits <= 0 || minDhKeyBits > 16000) {
332                         Usage();
333                         exit(MY_EX_USAGE);
334                     }
335                 #endif
336                 break;
337
338             case 'N':
339                 nonBlocking = 1;
340                 break;
341
342             case 'S' :
343                 #ifdef HAVE_SNI
344                     sniHostName = myoptarg;
345                 #endif
346                 break;
347
348             case 'o' :
349                 #ifdef HAVE_OCSP
350                     useOcsp = 1;
351                 #endif
352                 break;
353
354             case 'O' :
355                 #ifdef HAVE_OCSP
356                     useOcsp = 1;
357                     ocspUrl = myoptarg;
358                 #endif
359                 break;
360
361             case 'a' :
362                 #ifdef HAVE_ANON
363                     useAnon = 1;
364                 #endif
365                 break;
366
367             default:
368                 Usage();
369                 exit(MY_EX_USAGE);
370         }
371     }
372
373     myoptind = 0;      /* reset for test cases */
374
375     /* sort out DTLS versus TLS versions */
376     if (version == CLIENT_INVALID_VERSION) {
377         if (doDTLS)
378             version = CLIENT_DTLS_DEFAULT_VERSION;
379         else
380             version = CLIENT_DEFAULT_VERSION;
381     }
382     else {
383         if (doDTLS) {
384             if (version == 3)
385                 version = -2;
386             else
387                 version = -1;
388         }
389     }
390
391 #ifdef USE_CYASSL_MEMORY
392     if (trackMemory)
393         InitMemoryTracker(); 
394 #endif
395
396     switch (version) {
397 #ifndef NO_OLD_TLS
398         case 0:
399             method = SSLv3_server_method();
400             break;
401
402     #ifndef NO_TLS
403         case 1:
404             method = TLSv1_server_method();
405             break;
406
407
408         case 2:
409             method = TLSv1_1_server_method();
410             break;
411
412         #endif
413 #endif
414
415 #ifndef NO_TLS
416         case 3:
417             method = TLSv1_2_server_method();
418             break;
419 #endif
420                 
421 #ifdef CYASSL_DTLS
422     #ifndef NO_OLD_TLS
423         case -1:
424             method = DTLSv1_server_method();
425             break;
426     #endif
427
428         case -2:
429             method = DTLSv1_2_server_method();
430             break;
431 #endif
432
433         default:
434             err_sys("Bad SSL version");
435     }
436
437     if (method == NULL)
438         err_sys("unable to get method");
439
440     ctx = SSL_CTX_new(method);
441     if (ctx == NULL)
442         err_sys("unable to get ctx");
443
444 #if defined(HAVE_SESSION_TICKET) && defined(HAVE_CHACHA) && \
445                                     defined(HAVE_POLY1305)
446     if (TicketInit() != 0)
447         err_sys("unable to setup Session Ticket Key context");
448     wolfSSL_CTX_set_TicketEncCb(ctx, myTicketEncCb);
449 #endif
450
451     if (cipherList)
452         if (SSL_CTX_set_cipher_list(ctx, cipherList) != SSL_SUCCESS)
453             err_sys("server can't set cipher list 1");
454
455 #ifdef CYASSL_LEANPSK
456     usePsk = 1;
457 #endif
458
459 #if defined(NO_RSA) && !defined(HAVE_ECC)
460     usePsk = 1;
461 #endif
462
463     if (fewerPackets)
464         CyaSSL_CTX_set_group_messages(ctx);
465
466 #if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER)
467     SSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
468 #endif
469
470 #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
471     if (!usePsk && !useAnon) {
472         if (SSL_CTX_use_certificate_file(ctx, ourCert, SSL_FILETYPE_PEM)
473                                          != SSL_SUCCESS)
474             err_sys("can't load server cert file, check file and run from"
475                     " wolfSSL home dir");
476     }
477 #endif
478
479 #ifndef NO_DH
480     wolfSSL_CTX_SetMinDhKey_Sz(ctx, (word16)minDhKeyBits);
481 #endif
482
483 #ifdef HAVE_NTRU
484     if (useNtruKey) {
485         if (CyaSSL_CTX_use_NTRUPrivateKey_file(ctx, ourKey)
486                                                != SSL_SUCCESS)
487             err_sys("can't load ntru key file, "
488                     "Please run from wolfSSL home dir");
489     }
490 #endif
491
492 #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
493     if (!useNtruKey && !usePsk && !useAnon) {
494         if (SSL_CTX_use_PrivateKey_file(ctx, ourKey, SSL_FILETYPE_PEM)
495                                          != SSL_SUCCESS)
496             err_sys("can't load server private key file, check file and run "
497                 "from wolfSSL home dir");
498     }
499 #endif
500
501     if (usePsk) {
502 #ifndef NO_PSK
503         SSL_CTX_set_psk_server_callback(ctx, my_psk_server_cb);
504         SSL_CTX_use_psk_identity_hint(ctx, "cyassl server");
505         if (cipherList == NULL) {
506             const char *defaultCipherList;
507             #if defined(HAVE_AESGCM) && !defined(NO_DH)
508                 defaultCipherList = "DHE-PSK-AES128-GCM-SHA256";
509                 needDH = 1;
510             #elif defined(HAVE_NULL_CIPHER)
511                 defaultCipherList = "PSK-NULL-SHA256";
512             #else
513                 defaultCipherList = "PSK-AES128-CBC-SHA256";
514             #endif
515             if (SSL_CTX_set_cipher_list(ctx, defaultCipherList) != SSL_SUCCESS)
516                 err_sys("server can't set cipher list 2");
517         }
518 #endif
519     }
520
521     if (useAnon) {
522 #ifdef HAVE_ANON
523         CyaSSL_CTX_allow_anon_cipher(ctx);
524         if (cipherList == NULL) {
525             if (SSL_CTX_set_cipher_list(ctx, "ADH-AES128-SHA") != SSL_SUCCESS)
526                 err_sys("server can't set cipher list 4");
527         }
528 #endif
529     }
530
531 #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
532     /* if not using PSK, verify peer with certs */
533     if (doCliCertCheck && usePsk == 0 && useAnon == 0) {
534         SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER |
535                                 SSL_VERIFY_FAIL_IF_NO_PEER_CERT,0);
536         if (SSL_CTX_load_verify_locations(ctx, verifyCert, 0) != SSL_SUCCESS)
537             err_sys("can't load ca file, Please run from wolfSSL home dir");
538     }
539 #endif
540
541 #if defined(CYASSL_SNIFFER)
542     /* don't use EDH, can't sniff tmp keys */
543     if (cipherList == NULL) {
544         if (SSL_CTX_set_cipher_list(ctx, "AES256-SHA256") != SSL_SUCCESS)
545             err_sys("server can't set cipher list 3");
546     }
547 #endif
548
549 #ifdef HAVE_SNI
550     if (sniHostName)
551         if (CyaSSL_CTX_UseSNI(ctx, CYASSL_SNI_HOST_NAME, sniHostName,
552                                            XSTRLEN(sniHostName)) != SSL_SUCCESS)
553             err_sys("UseSNI failed");
554 #endif
555
556 while (1) {  /* allow resume option */
557     if (resume > 1) {  /* already did listen, just do accept */
558         if (doDTLS == 0) {
559             SOCKADDR_IN_T client;
560             socklen_t client_len = sizeof(client);
561             clientfd = accept(sockfd, (struct sockaddr*)&client,
562                              (ACCEPT_THIRD_T)&client_len);
563         } else {
564             tcp_listen(&sockfd, &port, useAnyAddr, doDTLS);
565             clientfd = udp_read_connect(sockfd);
566         }
567         #ifdef USE_WINDOWS_API
568             if (clientfd == INVALID_SOCKET) err_sys("tcp accept failed");
569         #else
570             if (clientfd == -1) err_sys("tcp accept failed");
571         #endif
572     }
573
574     ssl = SSL_new(ctx);
575     if (ssl == NULL)
576         err_sys("unable to get SSL");
577
578 #ifndef NO_HANDSHAKE_DONE_CB
579     wolfSSL_SetHsDoneCb(ssl, myHsDoneCb, NULL);
580 #endif
581 #ifdef HAVE_CRL
582     CyaSSL_EnableCRL(ssl, 0);
583     CyaSSL_LoadCRL(ssl, crlPemDir, SSL_FILETYPE_PEM, CYASSL_CRL_MONITOR |
584                                                      CYASSL_CRL_START_MON);
585     CyaSSL_SetCRL_Cb(ssl, CRL_CallBack);
586 #endif
587 #ifdef HAVE_OCSP
588     if (useOcsp) {
589         if (ocspUrl != NULL) {
590             CyaSSL_CTX_SetOCSP_OverrideURL(ctx, ocspUrl);
591             CyaSSL_CTX_EnableOCSP(ctx, CYASSL_OCSP_NO_NONCE
592                                                     | CYASSL_OCSP_URL_OVERRIDE);
593         }
594         else
595             CyaSSL_CTX_EnableOCSP(ctx, CYASSL_OCSP_NO_NONCE);
596     }
597 #endif
598 #ifdef HAVE_PK_CALLBACKS
599     if (pkCallbacks)
600         SetupPkCallbacks(ctx, ssl);
601 #endif
602
603     if (resume < 2) {  /* do listen and accept */
604         tcp_accept(&sockfd, &clientfd, (func_args*)args, port, useAnyAddr,
605                    doDTLS, serverReadyFile);
606     }
607
608     SSL_set_fd(ssl, clientfd);
609     if (usePsk == 0 || useAnon == 1 || cipherList != NULL || needDH == 1) {
610         #if !defined(NO_FILESYSTEM) && !defined(NO_DH) && !defined(NO_ASN)
611             CyaSSL_SetTmpDH_file(ssl, ourDhParam, SSL_FILETYPE_PEM);
612         #elif !defined(NO_DH)
613             SetDH(ssl);  /* repick suites with DHE, higher priority than PSK */
614         #endif
615     }
616
617 #ifndef CYASSL_CALLBACKS
618     if (nonBlocking) {
619         CyaSSL_set_using_nonblock(ssl, 1);
620         tcp_set_nonblocking(&clientfd);
621         NonBlockingSSL_Accept(ssl);
622     } else if (SSL_accept(ssl) != SSL_SUCCESS) {
623         int err = SSL_get_error(ssl, 0);
624         char buffer[CYASSL_MAX_ERROR_SZ];
625         printf("error = %d, %s\n", err, ERR_error_string(err, buffer));
626         err_sys("SSL_accept failed");
627     }
628 #else
629     NonBlockingSSL_Accept(ssl);
630 #endif
631     showPeer(ssl);
632
633     idx = SSL_read(ssl, input, sizeof(input)-1);
634     if (idx > 0) {
635         input[idx] = 0;
636         printf("Client message: %s\n", input);
637
638     }
639     else if (idx < 0) {
640         int readErr = SSL_get_error(ssl, 0);
641         if (readErr != SSL_ERROR_WANT_READ)
642             err_sys("SSL_read failed");
643     }
644
645     if (SSL_write(ssl, msg, sizeof(msg)) != sizeof(msg))
646         err_sys("SSL_write failed");
647         
648     #if defined(CYASSL_MDK_SHELL) && defined(HAVE_MDK_RTX)
649         os_dly_wait(500) ;
650     #elif defined (CYASSL_TIRTOS)
651         Task_yield();
652     #endif
653
654     if (doDTLS == 0) {
655         ret = SSL_shutdown(ssl);
656         if (wc_shutdown && ret == SSL_SHUTDOWN_NOT_DONE)
657             SSL_shutdown(ssl);    /* bidirectional shutdown */
658     }
659     SSL_free(ssl);
660     if (resume == 1) {
661         CloseSocket(clientfd);
662         resume++;           /* only do one resume for testing */
663         continue;
664     }
665     break;  /* out of while loop, done with normal and resume option */
666 }
667     SSL_CTX_free(ctx);
668
669     CloseSocket(clientfd);
670     CloseSocket(sockfd);
671     ((func_args*)args)->return_code = 0;
672
673
674 #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
675                             && defined(HAVE_THREAD_LS)
676     ecc_fp_free();  /* free per thread cache */
677 #endif
678
679 #ifdef USE_WOLFSSL_MEMORY
680     if (trackMemory)
681         ShowMemoryTracker();
682 #endif
683
684 #ifdef CYASSL_TIRTOS
685     fdCloseSession(Task_self());
686 #endif
687
688 #if defined(HAVE_SESSION_TICKET) && defined(HAVE_CHACHA) && \
689                                     defined(HAVE_POLY1305)
690     TicketCleanup();
691 #endif
692
693 #ifndef CYASSL_TIRTOS
694     return 0;
695 #endif
696 }
697
698
699 /* so overall tests can pull in test function */
700 #ifndef NO_MAIN_DRIVER
701
702     int main(int argc, char** argv)
703     {
704         func_args args;
705
706 #ifdef HAVE_CAVIUM
707         int ret = OpenNitroxDevice(CAVIUM_DIRECT, CAVIUM_DEV_ID);
708         if (ret != 0)
709             err_sys("Cavium OpenNitroxDevice failed");
710 #endif /* HAVE_CAVIUM */
711
712         StartTCP();
713
714         args.argc = argc;
715         args.argv = argv;
716
717         CyaSSL_Init();
718 #if defined(DEBUG_CYASSL) && !defined(CYASSL_MDK_SHELL)
719         CyaSSL_Debugging_ON();
720 #endif
721         if (CurrentDir("_build"))
722             ChangeDirBack(1);
723         else if (CurrentDir("server"))
724             ChangeDirBack(2);
725         else if (CurrentDir("Debug") || CurrentDir("Release"))
726             ChangeDirBack(3);
727    
728 #ifdef HAVE_STACK_SIZE
729         StackSizeCheck(&args, server_test);
730 #else 
731         server_test(&args);
732 #endif
733         CyaSSL_Cleanup();
734
735 #ifdef HAVE_CAVIUM
736         CspShutdown(CAVIUM_DEV_ID);
737 #endif
738         return args.return_code;
739     }
740
741     int myoptind = 0;
742     char* myoptarg = NULL;
743
744 #endif /* NO_MAIN_DRIVER */
745
746
747 #ifdef CYASSL_CALLBACKS
748
749     int srvHandShakeCB(HandShakeInfo* info)
750     {
751         (void)info;
752         return 0;
753     }
754
755
756     int srvTimeoutCB(TimeoutInfo* info)
757     {
758         (void)info;
759         return 0;
760     }
761
762 #endif
763
764 #ifndef NO_HANDSHAKE_DONE_CB
765     int myHsDoneCb(WOLFSSL* ssl, void* user_ctx)
766     {
767         (void)user_ctx;
768         (void)ssl;
769
770         /* printf("Notified HandShake done\n"); */
771
772         /* return negative number to end TLS connection now */
773         return 0;
774     }
775 #endif
776
777