Skip to content

Commit 31496c1

Browse files
committed
feat(esp-tls): Update esp_tls for improved wolfssl support
1 parent 25c40d4 commit 31496c1

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

components/esp-tls/esp_tls.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ static ssize_t tcp_write(esp_tls_t *tls, const char *data, size_t datalen)
134134

135135
ssize_t esp_tls_conn_read(esp_tls_t *tls, void *data, size_t datalen)
136136
{
137-
if (!tls) {
137+
if (!tls || !data) {
138138
return -1;
139139
}
140140
return tls->read(tls, (char *)data, datalen);
@@ -461,7 +461,10 @@ static inline esp_err_t tcp_connect(const char *host, int hostlen, int port, con
461461

462462
static int esp_tls_low_level_conn(const char *hostname, int hostlen, int port, const esp_tls_cfg_t *cfg, esp_tls_t *tls)
463463
{
464-
464+
if (!tls) {
465+
ESP_LOGE(TAG, "empty esp_tls parameter");
466+
return -1;
467+
}
465468
esp_err_t esp_ret;
466469
/* These states are used to keep a tab on connection progress in case of non-blocking connect,
467470
and in case of blocking connect these cases will get executed one after the other */
@@ -516,6 +519,7 @@ static int esp_tls_low_level_conn(const char *hostname, int hostlen, int port, c
516519
}
517520
}
518521
/* By now, the connection has been established */
522+
ESP_LOGD(TAG, "\ncreate_ssl_handle for host: %s:%d\n", hostname, port);
519523
esp_ret = create_ssl_handle(hostname, hostlen, cfg, tls);
520524
if (esp_ret != ESP_OK) {
521525
ESP_LOGE(TAG, "create_ssl_handle failed");
@@ -715,11 +719,17 @@ int esp_tls_server_session_create(esp_tls_cfg_server_t *cfg, int sockfd, esp_tls
715719
/**
716720
* @brief Close the server side TLS/SSL connection and free any allocated resources.
717721
*/
722+
#ifdef CONFIG_ESP_TLS_USING_WOLFSSL
723+
int esp_tls_server_session_delete(esp_tls_t *tls)
724+
{
725+
return _esp_tls_server_session_delete(tls);
726+
}
727+
#else
718728
void esp_tls_server_session_delete(esp_tls_t *tls)
719729
{
720730
return _esp_tls_server_session_delete(tls);
721731
}
722-
732+
#endif
723733
ssize_t esp_tls_get_bytes_avail(esp_tls_t *tls)
724734
{
725735
return _esp_tls_get_bytes_avail(tls);

components/esp-tls/esp_tls.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include "mbedtls/ctr_drbg.h"
2020
#endif
2121
#elif CONFIG_ESP_TLS_USING_WOLFSSL
22+
/* ESP_TLS_HAS_WOLFSSL defined only for versions properly supporting wolfSSL */
23+
#define ESP_TLS_HAS_WOLFSSL
2224
#include "wolfssl/wolfcrypt/settings.h"
2325
#include "wolfssl/ssl.h"
2426
#endif
@@ -774,8 +776,11 @@ int esp_tls_server_session_create(esp_tls_cfg_server_t *cfg, int sockfd, esp_tls
774776
*
775777
* @param[in] tls pointer to esp_tls_t
776778
*/
779+
#ifdef CONFIG_ESP_TLS_USING_WOLFSSL
780+
int esp_tls_server_session_delete(esp_tls_t *tls);
781+
#else
777782
void esp_tls_server_session_delete(esp_tls_t *tls);
778-
783+
#endif
779784
/**
780785
* @brief Creates a plain TCP connection, returning a valid socket fd on success or an error handle
781786
*

0 commit comments

Comments
 (0)