mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
feat(esp-tls): Add unified private key interface via esp_key_config_t
Add ESP_KEY_SOURCE_BUFFER and ESP_KEY_SOURCE_PSA key sources so all
hardware backends (DS, ECDSA, secure element) are accessed via PSA
key IDs through a single esp_tls_cfg_t.client_key field.
(cherry picked from commit 36090b7161)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
if(NOT ${IDF_TARGET} STREQUAL "linux")
|
||||
set(req lwip esp_event)
|
||||
set(req lwip esp_event esp_security)
|
||||
else()
|
||||
set(req linux esp_event)
|
||||
set(req linux esp_event esp_security)
|
||||
endif()
|
||||
|
||||
idf_component_register(SRCS "esp_http_client.c"
|
||||
|
||||
@@ -938,12 +938,6 @@ esp_http_client_handle_t esp_http_client_init(const esp_http_client_config_t *co
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_ESP_TLS_USE_SECURE_ELEMENT
|
||||
if (config->use_secure_element) {
|
||||
esp_transport_ssl_use_secure_element(ssl);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_ESP_TLS_USE_DS_PERIPHERAL
|
||||
if (config->ds_data != NULL) {
|
||||
esp_transport_ssl_set_ds_data(ssl, config->ds_data);
|
||||
@@ -962,26 +956,32 @@ esp_http_client_handle_t esp_http_client_init(const esp_http_client_config_t *co
|
||||
}
|
||||
#endif
|
||||
|
||||
if (config->client_key_pem) {
|
||||
if (!config->client_key_len) {
|
||||
esp_transport_ssl_set_client_key_data(ssl, config->client_key_pem, strlen(config->client_key_pem));
|
||||
} else {
|
||||
esp_transport_ssl_set_client_key_data_der(ssl, config->client_key_pem, config->client_key_len);
|
||||
/* Check for unified key config */
|
||||
if (config->client_key != NULL) {
|
||||
esp_transport_ssl_set_client_key_config(ssl, config->client_key);
|
||||
} else {
|
||||
/* Legacy key configuration */
|
||||
if (config->client_key_pem) {
|
||||
if (!config->client_key_len) {
|
||||
esp_transport_ssl_set_client_key_data(ssl, config->client_key_pem, strlen(config->client_key_pem));
|
||||
} else {
|
||||
esp_transport_ssl_set_client_key_data_der(ssl, config->client_key_pem, config->client_key_len);
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef CONFIG_MBEDTLS_HARDWARE_ECDSA_SIGN
|
||||
if (config->use_ecdsa_peripheral) {
|
||||
if (config->use_ecdsa_peripheral) {
|
||||
#if SOC_ECDSA_SUPPORT_CURVE_P384
|
||||
esp_transport_ssl_set_client_key_ecdsa_peripheral_extended(ssl, config->ecdsa_key_efuse_blk, config->ecdsa_key_efuse_blk_high);
|
||||
esp_transport_ssl_set_client_key_ecdsa_peripheral_extended(ssl, config->ecdsa_key_efuse_blk, config->ecdsa_key_efuse_blk_high);
|
||||
#else
|
||||
esp_transport_ssl_set_client_key_ecdsa_peripheral(ssl, config->ecdsa_key_efuse_blk);
|
||||
esp_transport_ssl_set_client_key_ecdsa_peripheral(ssl, config->ecdsa_key_efuse_blk);
|
||||
#endif
|
||||
// Set the ECDSA curve
|
||||
esp_transport_ssl_set_ecdsa_curve(ssl, config->ecdsa_curve);
|
||||
}
|
||||
// Set the ECDSA curve
|
||||
esp_transport_ssl_set_ecdsa_curve(ssl, config->ecdsa_curve);
|
||||
}
|
||||
#endif
|
||||
if (config->client_key_password && config->client_key_password_len > 0) {
|
||||
esp_transport_ssl_set_client_key_password(ssl, config->client_key_password, config->client_key_password_len);
|
||||
if (config->client_key_password && config->client_key_password_len > 0) {
|
||||
esp_transport_ssl_set_client_key_password(ssl, config->client_key_password, config->client_key_password_len);
|
||||
}
|
||||
}
|
||||
|
||||
if (config->skip_cert_common_name_check) {
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "sdkconfig.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_key_config.h"
|
||||
#include <sys/socket.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -200,6 +201,7 @@ typedef struct {
|
||||
DER Certificate - Length of the buffer pointed to by client_cert_der. Should be the length of the certificate. */
|
||||
const char *client_key_pem; /*!< SSL client key, PEM format as string, if the server requires to verify client */
|
||||
size_t client_key_len; /*!< Length of the buffer pointed to by client_key_pem. May be 0 for null-terminated pem */
|
||||
const esp_key_config_t *client_key; /*!< Unified client key configuration. Takes precedence over client_key_pem when set */
|
||||
const char *client_key_password; /*!< Client key decryption password string */
|
||||
size_t client_key_password_len; /*!< String length of the password pointed to by client_key_password */
|
||||
esp_http_client_proto_ver_t tls_version; /*!< TLS protocol version of the connection, e.g., TLS 1.2, TLS 1.3 (default - no preference) */
|
||||
@@ -237,9 +239,6 @@ typedef struct {
|
||||
const char **alpn_protos; /*!< Application protocols required for HTTP2. If HTTP2/ALPN support is required, a list of protocols that should be negotiated. The format is length followed by protocol
|
||||
name. For the most common cases the following is ok: const char **alpn_protos = { "h2", NULL }; - where 'h2' is the protocol name */
|
||||
#endif
|
||||
#if CONFIG_ESP_TLS_USE_SECURE_ELEMENT
|
||||
bool use_secure_element; /*!< Enable this option to use secure element */
|
||||
#endif
|
||||
#if CONFIG_ESP_TLS_USE_DS_PERIPHERAL
|
||||
void *ds_data; /*!< Pointer for digital signature peripheral context, see ESP-TLS Documentation for more details */
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user