5555#define CA_FILE "../certs/client-cert.pem"
5656
5757
58- #if defined(WOLFSSL_TLS13 ) && defined(HAVE_SECRET_CALLBACK )
59-
60- #ifndef WOLFSSL_SSLKEYLOGFILE_OUTPUT
61- #define WOLFSSL_SSLKEYLOGFILE_OUTPUT "sslkeylog.log"
62- #endif
63-
64- /* Callback function for TLS v1.3 secrets for use with Wireshark */
65- static int Tls13SecretCallback (WOLFSSL * ssl , int id , const unsigned char * secret ,
66- int secretSz , void * ctx )
67- {
68- int i ;
69- const char * str = NULL ;
70- unsigned char serverRandom [32 ];
71- int serverRandomSz ;
72- XFILE fp = stderr ;
73- if (ctx ) {
74- fp = XFOPEN ((const char * )ctx , "ab" );
75- if (fp == XBADFILE ) {
76- return BAD_FUNC_ARG ;
77- }
78- }
79-
80- serverRandomSz = (int )wolfSSL_get_server_random (ssl , serverRandom ,
81- sizeof (serverRandom ));
82-
83- if (serverRandomSz <= 0 ) {
84- printf ("Error getting server random %d\n" , serverRandomSz );
85- }
86-
87- #if 0
88- printf ("TLS Server Secret CB: Rand %d, Secret %d\n" ,
89- serverRandomSz , secretSz );
90- #endif
91-
92- switch (id ) {
93- case CLIENT_EARLY_TRAFFIC_SECRET :
94- str = "CLIENT_EARLY_TRAFFIC_SECRET" ; break ;
95- case EARLY_EXPORTER_SECRET :
96- str = "EARLY_EXPORTER_SECRET" ; break ;
97- case CLIENT_HANDSHAKE_TRAFFIC_SECRET :
98- str = "CLIENT_HANDSHAKE_TRAFFIC_SECRET" ; break ;
99- case SERVER_HANDSHAKE_TRAFFIC_SECRET :
100- str = "SERVER_HANDSHAKE_TRAFFIC_SECRET" ; break ;
101- case CLIENT_TRAFFIC_SECRET :
102- str = "CLIENT_TRAFFIC_SECRET_0" ; break ;
103- case SERVER_TRAFFIC_SECRET :
104- str = "SERVER_TRAFFIC_SECRET_0" ; break ;
105- case EXPORTER_SECRET :
106- str = "EXPORTER_SECRET" ; break ;
107- }
108-
109- fprintf (fp , "%s " , str );
110- for (i = 0 ; i < (int )serverRandomSz ; i ++ ) {
111- fprintf (fp , "%02x" , serverRandom [i ]);
112- }
113- fprintf (fp , " " );
114- for (i = 0 ; i < secretSz ; i ++ ) {
115- fprintf (fp , "%02x" , secret [i ]);
116- }
117- fprintf (fp , "\n" );
118-
119- if (fp != stderr ) {
120- XFCLOSE (fp );
121- }
122-
123- return 0 ;
124- }
125- #endif /* WOLFSSL_TLS13 && HAVE_SECRET_CALLBACK */
126-
12758static int mSockfd = SOCKET_INVALID ;
12859static int mConnd = SOCKET_INVALID ;
129- static int mShutdown = 0 ;
60+ static volatile int mShutdown = 0 ;
13061
13162#ifdef HAVE_SIGNAL
13263static void sig_handler (const int sig )
@@ -269,9 +200,6 @@ int main(int argc, char** argv)
269200 /*---------------------------------*/
270201 /* Start of wolfSSL initialization and configuration */
271202 /*---------------------------------*/
272- #if 0
273- wolfSSL_Debugging_ON ();
274- #endif
275203
276204 /* Initialize wolfSSL */
277205 if ((ret = wolfSSL_Init ()) != WOLFSSL_SUCCESS ) {
@@ -324,15 +252,6 @@ int main(int argc, char** argv)
324252 /* Attach wolfSSL to the socket */
325253 wolfSSL_set_fd (ssl , mConnd );
326254
327- #ifdef HAVE_SECRET_CALLBACK
328- /* required for getting random used */
329- wolfSSL_KeepArrays (ssl );
330-
331- /* optional logging for wireshark */
332- wolfSSL_set_tls13_secret_cb (ssl , Tls13SecretCallback ,
333- (void * )WOLFSSL_SSLKEYLOGFILE_OUTPUT );
334- #endif
335-
336255 /* Establish TLS connection */
337256 if ((ret = wolfSSL_accept (ssl )) != WOLFSSL_SUCCESS ) {
338257 fprintf (stderr , "wolfSSL_accept error = %d\n" ,
@@ -342,10 +261,6 @@ int main(int argc, char** argv)
342261
343262 printf ("Client connected successfully\n" );
344263
345- #ifdef HAVE_SECRET_CALLBACK
346- wolfSSL_FreeArrays (ssl );
347- #endif
348-
349264 /* Read the client data into our buff array */
350265 memset (buff , 0 , sizeof (buff ));
351266 if ((ret = wolfSSL_read (ssl , buff , sizeof (buff )- 1 )) < 0 ) {
0 commit comments