Page 1 of 1

Example of a TCP socket with SSL?

Posted: Tue Jun 06, 2023 7:19 pm
by dizcza
I already have a TCP client running on an ESP32 but I'd like to make it secure with SSL.

I found something similar for Arduino: https://github.com/khoih-prog/AsyncTCP_SSL. But, firstly, it's on Arduino and, secondly, the project is no longer maintained.

On the documentation page of ESP-IDF, I found only one related function - "esp_tls_plain_tcp_connect". But there are no examples. The only source code that uses this function is in the "components/tcp_transport/transport_ssl.c":

Code: Select all

static int tcp_connect(esp_transport_handle_t t, const char *host, int port, int timeout_ms)
{
    transport_esp_tls_t *ssl = ssl_get_context_data(t);
    esp_tls_last_error_t *err_handle = esp_transport_get_error_handle(t);

    ssl->cfg.timeout_ms = timeout_ms;
    esp_err_t err = esp_tls_plain_tcp_connect(host, strlen(host), port, &ssl->cfg, err_handle, &ssl->sockfd);
    if (err != ESP_OK) {
        ESP_LOGE(TAG, "Failed to open a new connection: %d", err);
        err_handle->last_error = err;
        ssl->sockfd = INVALID_SOCKET;
        return -1;
    }
    return 0;
}
Does anyone have a script to wrap a TCP connection with SSL in ESP-IDF?

Re: Example of a TCP socket with SSL?

Posted: Tue Jun 06, 2023 8:35 pm
by MicroController