mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge 07ff5af5dc
into 3c99557eee
This commit is contained in:
commit
5a34f57bf0
@ -914,6 +914,21 @@ esp_err_t set_client_config(const char *hostname, size_t hostlen, esp_tls_cfg_t
|
|||||||
* @brief Create TLS/SSL server session
|
* @brief Create TLS/SSL server session
|
||||||
*/
|
*/
|
||||||
int esp_mbedtls_server_session_create(esp_tls_cfg_server_t *cfg, int sockfd, esp_tls_t *tls)
|
int esp_mbedtls_server_session_create(esp_tls_cfg_server_t *cfg, int sockfd, esp_tls_t *tls)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
if ((ret = esp_mbedtls_server_session_create_start(cfg, sockfd, tls)) != 0) return ret;
|
||||||
|
while ((ret = esp_mbedtls_server_session_create_continue_async(tls)) != 0) {
|
||||||
|
if (ret != ESP_TLS_ERR_SSL_WANT_READ && ret != ESP_TLS_ERR_SSL_WANT_WRITE) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initialization part of esp_mbedtls_server_session_create
|
||||||
|
*/
|
||||||
|
int esp_mbedtls_server_session_create_start(esp_tls_cfg_server_t *cfg, int sockfd, esp_tls_t *tls)
|
||||||
{
|
{
|
||||||
if (tls == NULL || cfg == NULL) {
|
if (tls == NULL || cfg == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -932,9 +947,18 @@ int esp_mbedtls_server_session_create(esp_tls_cfg_server_t *cfg, int sockfd, esp
|
|||||||
|
|
||||||
tls->read = esp_mbedtls_read;
|
tls->read = esp_mbedtls_read;
|
||||||
tls->write = esp_mbedtls_write;
|
tls->write = esp_mbedtls_write;
|
||||||
int ret;
|
return 0;
|
||||||
while ((ret = mbedtls_ssl_handshake(&tls->ssl)) != 0) {
|
}
|
||||||
if (ret != ESP_TLS_ERR_SSL_WANT_READ && ret != ESP_TLS_ERR_SSL_WANT_WRITE) {
|
|
||||||
|
/**
|
||||||
|
* @brief Asyncronous continue of esp_mbedtls_server_session_create, to be
|
||||||
|
* called in a loop by the user until it returns 0, ESP_TLS_ERR_SSL_WANT_READ
|
||||||
|
* or ESP_TLS_ERR_SSL_WANT_WRITE
|
||||||
|
*/
|
||||||
|
int esp_mbedtls_server_session_create_continue_async(esp_tls_t *tls)
|
||||||
|
{
|
||||||
|
int ret = mbedtls_ssl_handshake(&tls->ssl);
|
||||||
|
if (ret != 0 && ret != ESP_TLS_ERR_SSL_WANT_READ && ret != ESP_TLS_ERR_SSL_WANT_WRITE) {
|
||||||
ESP_LOGE(TAG, "mbedtls_ssl_handshake returned -0x%04X", -ret);
|
ESP_LOGE(TAG, "mbedtls_ssl_handshake returned -0x%04X", -ret);
|
||||||
mbedtls_print_error_msg(ret);
|
mbedtls_print_error_msg(ret);
|
||||||
ESP_INT_EVENT_TRACKER_CAPTURE(tls->error_handle, ESP_TLS_ERR_TYPE_MBEDTLS, -ret);
|
ESP_INT_EVENT_TRACKER_CAPTURE(tls->error_handle, ESP_TLS_ERR_TYPE_MBEDTLS, -ret);
|
||||||
@ -942,9 +966,9 @@ int esp_mbedtls_server_session_create(esp_tls_cfg_server_t *cfg, int sockfd, esp
|
|||||||
tls->conn_state = ESP_TLS_FAIL;
|
tls->conn_state = ESP_TLS_FAIL;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
return ret;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Close the server side TLS/SSL connection and free any allocated resources.
|
* @brief Close the server side TLS/SSL connection and free any allocated resources.
|
||||||
*/
|
*/
|
||||||
|
@ -69,6 +69,22 @@ void *esp_mbedtls_get_ssl_context(esp_tls_t *tls);
|
|||||||
*/
|
*/
|
||||||
int esp_mbedtls_server_session_create(esp_tls_cfg_server_t *cfg, int sockfd, esp_tls_t *tls);
|
int esp_mbedtls_server_session_create(esp_tls_cfg_server_t *cfg, int sockfd, esp_tls_t *tls);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialization part of internal callback for mbedtls_server_session_create
|
||||||
|
*
|
||||||
|
* /note :- The function can only be used with mbedtls ssl library
|
||||||
|
*/
|
||||||
|
int esp_mbedtls_server_session_create_start(esp_tls_cfg_server_t *cfg, int sockfd, esp_tls_t *tls);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asynchronous continue of internal callback for mbedtls_server_session_create,
|
||||||
|
* to be called in a loop by the user until it returns 0,
|
||||||
|
* ESP_TLS_ERR_SSL_WANT_READ or ESP_TLS_ERR_SSL_WANT_WRITE
|
||||||
|
*
|
||||||
|
* /note :- The function can only be used with mbedtls ssl library
|
||||||
|
*/
|
||||||
|
int esp_mbedtls_server_session_create_continue_async(esp_tls_t *tls);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal Callback for mbedtls_server_session_delete
|
* Internal Callback for mbedtls_server_session_delete
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user