Chapter 2. API Reference
• [in] tls: pointer to esp-tls as esp-tls handle.
esp_err_t esp_tls_get_conn_sockfd(esp_tls_t
Returns the connection socket file descriptor from
Return - ESP_OK on success and value of sockfd will be updated with socket file descriptor for connection
• ESP_ERR_INVALID_ARG if (tls == NULL || sockfd == NULL)
Parameters
• [in] tls: handle to
• [out] sockfd: int pointer to sockfd value.
esp_err_t
esp_tls_init_global_ca_store(void)
Create a global CA store, initially empty.
This function should be called if the application wants to use the same CA store for multiple connections. This
function initialises the global CA store which can be then set by calling esp_tls_set_global_ca_store(). To be
effective, this function must be called before any call to esp_tls_set_global_ca_store().
Return
• ESP_OK if creating global CA store was successful.
• ESP_ERR_NO_MEM if an error occured when allocating the mbedTLS resources.
esp_err_t
esp_tls_set_global_ca_store(const unsigned char *cacert_pem_buf, const un-
Set the global CA store with the buffer provided in pem format.
This function should be called if the application wants to set the global CA store for multiple connections
i.e. to add the certificates in the provided buffer to the certificate chain. This function implicitly calls
esp_tls_init_global_ca_store() if it has not already been called. The application must call this function be-
fore calling esp_tls_conn_new().
Return
• ESP_OK if adding certificates was successful.
• Other if an error occured or an action must be taken by the calling process.
Parameters
• [in] cacert_pem_buf: Buffer which has certificates in pem format. This buffer is used for
creating a global CA store, which can be used by other tls connections.
• [in] cacert_pem_bytes: Length of the buffer.
void esp_tls_free_global_ca_store(void)
Free the global CA store currently being used.
The memory being used by the global CA store to store all the parsed certificates is freed up. The application
can call this API if it no longer needs the global CA store.
esp_err_t
esp_tls_get_and_clear_last_error(esp_tls_error_handle_t h, int *esp_tls_code, int
Returns last error in
esp_tls
upon return.
Return
• ESP_ERR_INVALID_STATE if invalid parameters
• ESP_OK (0) if no error occurred
• specific error code (based on ESP_ERR_ESP_TLS_BASE) otherwise
Parameters
• [in] h: esp-tls error handle.
• [out] esp_tls_code: last error code returned from mbedtls api (set to zero if none) This
pointer could be NULL if caller does not care about esp_tls_code
• [out] esp_tls_flags: last certification verification flags (set to zero if none) This pointer
could be NULL if caller does not care about esp_tls_code
esp_err_t
esp_tls_get_and_clear_error_type(esp_tls_error_handle_t h, esp_tls_error_type_t
Returns the last error captured in
return.
Espressif Systems
*tls, int *sockfd)
esp_tls
esp_tls
context
signed int cacert_pem_bytes)
with detailed mbedtls related error codes. The error information is cleared internally
esp_tls
of a specific type The error information is cleared internally upon
524
Submit Document Feedback
session.
*esp_tls_flags)
err_type, int *error_code)
Release v4.4
Need help?
Do you have a question about the ESP32-S2 and is the answer not in the manual?