Skip to content

Commit c463401

Browse files
committed
Merge branch 'feature/add_esp_tls_mbedtls_api' into 'master'
esp-tls: Add API for mbedtls to get and set ciphersuites See merge request sdk/ESP8266_RTOS_SDK!1673
2 parents e5b5196 + 8552799 commit c463401

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

components/esp-tls/esp_tls.c

+5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ static const char *TAG = "esp-tls";
5454
#define _esp_tls_set_global_ca_store esp_mbedtls_set_global_ca_store /*!< Callback function for setting global CA store data for TLS/SSL */
5555
#define _esp_tls_get_global_ca_store esp_mbedtls_get_global_ca_store
5656
#define _esp_tls_free_global_ca_store esp_mbedtls_free_global_ca_store /*!< Callback function for freeing global ca store for TLS/SSL */
57+
#define _esp_tls_get_ciphersuites_list esp_mbedtls_get_ciphersuites_list
5758
#elif CONFIG_ESP_TLS_USING_WOLFSSL /* CONFIG_ESP_TLS_USING_MBEDTLS */
5859
#define _esp_create_ssl_handle esp_create_wolfssl_handle
5960
#define _esp_tls_handshake esp_wolfssl_handshake
@@ -437,6 +438,10 @@ mbedtls_x509_crt *esp_tls_get_global_ca_store(void)
437438
return _esp_tls_get_global_ca_store();
438439
}
439440

441+
const int *esp_tls_get_ciphersuites_list(void)
442+
{
443+
return _esp_tls_get_ciphersuites_list();
444+
}
440445
#endif /* CONFIG_ESP_TLS_USING_MBEDTLS */
441446
#ifdef CONFIG_ESP_TLS_SERVER
442447
/**

components/esp-tls/esp_tls.h

+11-2
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ typedef struct esp_tls_cfg {
200200
esp_err_t (*crt_bundle_attach)(void *conf);
201201
/*!< Function pointer to esp_crt_bundle_attach. Enables the use of certification
202202
bundle for server verification, must be enabled in menuconfig */
203-
203+
const int *ciphersuites_list; /*!< Pointer to a zero-terminated array of IANA identifiers of TLS ciphersuites.
204+
Please check the list validity by esp_tls_get_ciphersuites_list() API */
204205
} esp_tls_cfg_t;
205206

206207
#ifdef CONFIG_ESP_TLS_SERVER
@@ -574,6 +575,15 @@ esp_err_t esp_tls_get_and_clear_last_error(esp_tls_error_handle_t h, int *esp_tl
574575
*/
575576
mbedtls_x509_crt *esp_tls_get_global_ca_store(void);
576577

578+
/**
579+
* @brief Get supported TLS ciphersuites list.
580+
*
581+
* See https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-4 for the list of ciphersuites
582+
*
583+
* @return Pointer to a zero-terminated array of IANA identifiers of TLS ciphersuites.
584+
*
585+
*/
586+
const int *esp_tls_get_ciphersuites_list(void);
577587
#endif /* CONFIG_ESP_TLS_USING_MBEDTLS */
578588
#ifdef CONFIG_ESP_TLS_SERVER
579589
/**
@@ -602,7 +612,6 @@ int esp_tls_server_session_create(esp_tls_cfg_server_t *cfg, int sockfd, esp_tls
602612
*/
603613
void esp_tls_server_session_delete(esp_tls_t *tls);
604614
#endif /* ! CONFIG_ESP_TLS_SERVER */
605-
606615
#ifdef __cplusplus
607616
}
608617
#endif

components/esp-tls/esp_tls_mbedtls.c

+10
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,11 @@ esp_err_t set_client_config(const char *hostname, size_t hostlen, esp_tls_cfg_t
473473
ESP_LOGE(TAG, "You have to provide both clientcert_buf and clientkey_buf for mutual authentication");
474474
return ESP_ERR_INVALID_STATE;
475475
}
476+
477+
if (cfg->ciphersuites_list != NULL && cfg->ciphersuites_list[0] != 0) {
478+
ESP_LOGD(TAG, "Set the ciphersuites list");
479+
mbedtls_ssl_conf_ciphersuites(&tls->conf, cfg->ciphersuites_list);
480+
}
476481
return ESP_OK;
477482
}
478483

@@ -569,3 +574,8 @@ void esp_mbedtls_free_global_ca_store(void)
569574
global_cacert = NULL;
570575
}
571576
}
577+
578+
const int *esp_mbedtls_get_ciphersuites_list(void)
579+
{
580+
return mbedtls_ssl_list_ciphersuites();
581+
}

components/esp-tls/private_include/esp_tls_mbedtls.h

+5
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,8 @@ mbedtls_x509_crt *esp_mbedtls_get_global_ca_store(void);
102102
* Callback function for freeing global ca store for TLS/SSL using mbedtls
103103
*/
104104
void esp_mbedtls_free_global_ca_store(void);
105+
106+
/**
107+
* Internal Callback for esp_tls_get_ciphersuites_list
108+
*/
109+
const int *esp_mbedtls_get_ciphersuites_list(void);

0 commit comments

Comments
 (0)