@@ -38,6 +38,7 @@ static int _handle_error(int err, const char * file, int line)
3838
3939#define handle_error (e ) _handle_error(e, __FUNCTION__, __LINE__)
4040
41+ #if defined(SSL_CLIENT_RECV_DISABLE_TIMEOUT)
4142/* *
4243 * \brief Read at most 'len' characters. If no error occurs,
4344 * the actual amount read is returned.
@@ -52,11 +53,11 @@ static int _handle_error(int err, const char * file, int line)
5253 */
5354static int client_net_recv ( void *ctx, unsigned char *buf, size_t len ) {
5455 Client *client = (Client*)ctx;
55- if (!client) {
56+ if (!client) {
5657 log_e (" Uninitialised!" );
5758 return -1 ;
5859 }
59-
60+
6061 // if (!client->connected()) {
6162 // log_e("Not connected!");
6263 // return -2;
@@ -68,31 +69,31 @@ static int client_net_recv( void *ctx, unsigned char *buf, size_t len ) {
6869 if (result > 0 ) {
6970 // esp_log_buffer_hexdump_internal("SSL.RD", buf, (uint16_t)result, ESP_LOG_VERBOSE);
7071 }
71-
72+
7273 return result;
7374}
74-
75- int client_net_recv_timeout ( void *ctx, unsigned char *buf,
75+ # else
76+ static int client_net_recv_timeout ( void *ctx, unsigned char *buf,
7677 size_t len, uint32_t timeout ) {
7778 Client *client = (Client*)ctx;
78- if (!client) {
79+ if (!client) {
7980 log_e (" Uninitialised!" );
8081 return -1 ;
8182 }
8283 unsigned long start = millis ();
8384 unsigned long tms = start + timeout;
84- int pending = client->available ();
85+ uint16_t pending = client->available ();
8586 // If there is data in the client, wait for message completion
8687 if ((pending > 0 ) && (pending < len))
8788 do {
88- int pending = client->available ();
89+ uint16_t pending = client->available ();
8990 if (pending < len && timeout > 0 ) {
9091 delay (1 );
9192 } else break ;
9293 } while (millis () < tms);
93-
94+
9495 int result = client->read (buf, len);
95-
96+
9697 // lwIP interface return -1 if there is no data to read
9798 // report without throwing errors or block
9899 if (result <= 0 ) return MBEDTLS_ERR_SSL_WANT_READ;
@@ -102,10 +103,10 @@ int client_net_recv_timeout( void *ctx, unsigned char *buf,
102103 if (result > 0 ) {
103104 // esp_log_buffer_hexdump_internal("SSL.RD", buf, (uint16_t)result, ESP_LOG_VERBOSE);
104105 }
105-
106+
106107 return result;
107108}
108-
109+ # endif
109110
110111/* *
111112 * \brief Write at most 'len' characters. If no error occurs,
@@ -121,20 +122,20 @@ int client_net_recv_timeout( void *ctx, unsigned char *buf,
121122 */
122123static int client_net_send ( void *ctx, const unsigned char *buf, size_t len ) {
123124 Client *client = (Client*)ctx;
124- if (!client) {
125+ if (!client) {
125126 log_e (" Uninitialised!" );
126127 return -1 ;
127128 }
128-
129+
129130 // if (!client->connected()) {
130131 // log_e("Not connected!");
131132 // return -2;
132133 // }
133-
134+
134135 // esp_log_buffer_hexdump_internal("SSL.WR", buf, (uint16_t)len, ESP_LOG_VERBOSE);
135-
136+
136137 int result = client->write (buf, len);
137-
138+
138139 log_d (" SSL client TX res=%d len=%d" , result, len);
139140 return result;
140141}
@@ -152,7 +153,7 @@ void ssl_init(sslclient_context *ssl_client, Client *client, const char * ca_pat
152153 mbedtls_ssl_conf_ciphersuites (&ssl_client->ssl_conf , mbedtls_ssl_list_ciphersuites ());
153154
154155 mbedtls_ssl_conf_dbg (&ssl_client->ssl_conf , mbedtls_debug_print, NULL );
155- mbedtls_debug_set_threshold (DEBUG_LEVEL );
156+ mbedtls_debug_set_threshold (SSL_DEBUG_LEVEL );
156157
157158 mbedtls_fs_init (ca_path);
158159}
@@ -225,7 +226,7 @@ int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t p
225226 }
226227 unsigned char psk[MBEDTLS_PSK_MAX_LEN];
227228 size_t psk_len = strlen (psKey)/2 ;
228- for (int j=0 ; j<strlen (psKey); j+= 2 ) {
229+ for (size_t j=0 ; j<strlen (psKey); j+= 2 ) {
229230 char c = psKey[j];
230231 if (c >= ' 0' && c <= ' 9' ) c -= ' 0' ;
231232 else if (c >= ' A' && c <= ' F' ) c -= ' A' - 10 ;
@@ -336,13 +337,13 @@ int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t p
336337 memset (buf, 0 , sizeof (buf));
337338 mbedtls_x509_crt_verify_info (buf, sizeof (buf), " ! " , flags);
338339 log_e (" Failed to verify peer certificate! verification info: %s" , buf);
339- stop_ssl_socket (ssl_client, rootCABuff, cli_cert, cli_key ); // It's not safe continue.
340+ stop_ssl_socket (ssl_client); // It's not safe continue.
340341
341342 return handle_error (ret);
342343 } else {
343344 log_v (" Certificate verified." );
344345 }
345-
346+
346347 if ((rootCABuff != NULL ) || ((rootCAPath != NULL ))) {
347348 log_d (" free buffer" );
348349 mbedtls_x509_crt_free (&ssl_client->ca_cert );
@@ -354,14 +355,14 @@ int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t p
354355
355356 if (cli_key != NULL ) {
356357 mbedtls_pk_free (&ssl_client->client_key );
357- }
358+ }
358359
359360 // return ssl_client->socket;
360361 return 1 ;
361362}
362363
363364
364- void stop_ssl_socket (sslclient_context *ssl_client, const char *rootCABuff, const char *cli_cert, const char *cli_key )
365+ void stop_ssl_socket (sslclient_context *ssl_client)
365366{
366367 log_v (" Cleaning SSL connection." );
367368
0 commit comments