Example of a TCP socket with SSL?

dizcza
Posts: 55
Joined: Tue Sep 07, 2021 6:59 pm

Example of a TCP socket with SSL?

Postby dizcza » Tue Jun 06, 2023 7:19 pm

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?

MicroController
Posts: 1116
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Example of a TCP socket with SSL?

Postby MicroController » Tue Jun 06, 2023 8:35 pm


Who is online

Users browsing this forum: Majestic-12 [Bot] and 63 guests