kopia lustrzana https://github.com/espressif/esp-idf
Merge branch 'feature/esp-tls_optimize_memory' into 'master'
esp-tls: add api to free client session Closes AEG-57 See merge request espressif/esp-idf!18103pull/9062/head
commit
5d88df658d
|
@ -40,6 +40,7 @@ static const char *TAG = "esp-tls";
|
|||
#define _esp_tls_conn_delete esp_mbedtls_conn_delete
|
||||
#define _esp_tls_net_init esp_mbedtls_net_init
|
||||
#define _esp_tls_get_client_session esp_mbedtls_get_client_session
|
||||
#define _esp_tls_free_client_session esp_mbedtls_free_client_session
|
||||
#define _esp_tls_get_ssl_context esp_mbedtls_get_ssl_context
|
||||
#ifdef CONFIG_ESP_TLS_SERVER
|
||||
#define _esp_tls_server_session_create esp_mbedtls_server_session_create
|
||||
|
@ -564,6 +565,11 @@ esp_tls_client_session_t *esp_tls_get_client_session(esp_tls_t *tls)
|
|||
{
|
||||
return _esp_tls_get_client_session(tls);
|
||||
}
|
||||
|
||||
void esp_tls_free_client_session(esp_tls_client_session_t *client_session)
|
||||
{
|
||||
_esp_tls_free_client_session(client_session);
|
||||
}
|
||||
#endif /* CONFIG_ESP_TLS_CLIENT_SESSION_TICKETS */
|
||||
|
||||
|
||||
|
|
|
@ -633,6 +633,16 @@ esp_err_t esp_tls_plain_tcp_connect(const char *host, int hostlen, int port, con
|
|||
* NULL on Failure
|
||||
*/
|
||||
esp_tls_client_session_t *esp_tls_get_client_session(esp_tls_t *tls);
|
||||
|
||||
/**
|
||||
* @brief Free the client session
|
||||
*
|
||||
* This function should be called after esp_tls_get_client_session().
|
||||
*
|
||||
* @param[in] client_session context as esp_tls_client_session_t
|
||||
*
|
||||
*/
|
||||
void esp_tls_free_client_session(esp_tls_client_session_t *client_session);
|
||||
#endif /* CONFIG_ESP_TLS_CLIENT_SESSION_TICKETS */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -174,6 +174,14 @@ esp_tls_client_session_t *esp_mbedtls_get_client_session(esp_tls_t *tls)
|
|||
|
||||
return client_session;
|
||||
}
|
||||
|
||||
void esp_mbedtls_free_client_session(esp_tls_client_session_t *client_session)
|
||||
{
|
||||
if (client_session) {
|
||||
mbedtls_ssl_session_free(&(client_session->saved_session));
|
||||
free(client_session);
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_ESP_TLS_CLIENT_SESSION_TICKETS */
|
||||
|
||||
int esp_mbedtls_handshake(esp_tls_t *tls, const esp_tls_cfg_t *cfg)
|
||||
|
|
|
@ -110,6 +110,11 @@ esp_err_t set_client_config(const char *hostname, size_t hostlen, esp_tls_cfg_t
|
|||
* Internal Callback for mbedtls_get_client_session
|
||||
*/
|
||||
esp_tls_client_session_t *esp_mbedtls_get_client_session(esp_tls_t *tls);
|
||||
|
||||
/**
|
||||
* Internal Callback for mbedtls_free_client_session
|
||||
*/
|
||||
void esp_mbedtls_free_client_session(esp_tls_client_session_t *client_session);
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
|
|
@ -85,7 +85,7 @@ extern const uint8_t local_server_cert_pem_start[] asm("_binary_local_server_cer
|
|||
extern const uint8_t local_server_cert_pem_end[] asm("_binary_local_server_cert_pem_end");
|
||||
|
||||
#ifdef CONFIG_EXAMPLE_CLIENT_SESSION_TICKETS
|
||||
esp_tls_client_session_t *tls_client_session = NULL;
|
||||
static esp_tls_client_session_t *tls_client_session = NULL;
|
||||
static bool save_client_session = false;
|
||||
#endif
|
||||
|
||||
|
@ -110,7 +110,7 @@ static void https_get_request(esp_tls_cfg_t cfg, const char *WEB_SERVER_URL, con
|
|||
#ifdef CONFIG_EXAMPLE_CLIENT_SESSION_TICKETS
|
||||
/* The TLS session is successfully established, now saving the session ctx for reuse */
|
||||
if (save_client_session) {
|
||||
free(tls_client_session);
|
||||
esp_tls_free_client_session(tls_client_session);
|
||||
tls_client_session = esp_tls_get_client_session(tls);
|
||||
}
|
||||
#endif
|
||||
|
@ -220,7 +220,7 @@ static void https_get_request_using_already_saved_session(const char *url)
|
|||
.client_session = tls_client_session,
|
||||
};
|
||||
https_get_request(cfg, url, LOCAL_SRV_REQUEST);
|
||||
free(tls_client_session);
|
||||
esp_tls_free_client_session(tls_client_session);
|
||||
save_client_session = false;
|
||||
tls_client_session = NULL;
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue