mirror of
https://github.com/espressif/esp-idf.git
synced 2025-09-30 19:19:21 +00:00
esp-tls: Add support for the CERTIFICATE SELECTION HOOK. The hook has access to required information so that the application can make a more informed decision on which certificate to serve (such as alpn value, server certificate type, etc.)
Closes https://github.com/espressif/esp-idf/pull/9833 Signed-off-by: Aditya Patwardhan <aditya.patwardhan@espressif.com>
This commit is contained in:
@@ -512,12 +512,21 @@ esp_err_t set_server_config(esp_tls_cfg_server_t *cfg, esp_tls_t *tls)
|
||||
return ESP_ERR_MBEDTLS_SSL_CONFIG_DEFAULTS_FAILED;
|
||||
}
|
||||
|
||||
mbedtls_ssl_conf_set_user_data_p(&tls->conf, cfg->userdata);
|
||||
|
||||
#ifdef CONFIG_MBEDTLS_SSL_ALPN
|
||||
if (cfg->alpn_protos) {
|
||||
mbedtls_ssl_conf_alpn_protocols(&tls->conf, cfg->alpn_protos);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_ESP_TLS_SERVER_CERT_SELECT_HOOK)
|
||||
if (cfg->cert_select_cb != NULL) {
|
||||
ESP_LOGI(TAG, "Initializing server side certificate selection callback");
|
||||
mbedtls_ssl_conf_cert_cb(&tls->conf, cfg->cert_select_cb);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (cfg->cacert_buf != NULL) {
|
||||
esp_ret = set_ca_cert(tls, cfg->cacert_buf, cfg->cacert_bytes);
|
||||
if (esp_ret != ESP_OK) {
|
||||
@@ -569,7 +578,16 @@ esp_err_t set_server_config(esp_tls_cfg_server_t *cfg, esp_tls_t *tls)
|
||||
return esp_ret;
|
||||
}
|
||||
} else {
|
||||
#if defined(CONFIG_ESP_TLS_SERVER_CERT_SELECT_HOOK)
|
||||
if (cfg->cert_select_cb == NULL) {
|
||||
ESP_LOGE(TAG, "Missing server certificate and/or key and no certificate selection callback is defined");
|
||||
} else {
|
||||
ESP_LOGD(TAG, "Missing server certificate and/or key, but certificate selection callback is defined. Callback MUST ALWAYS call mbedtls_ssl_set_hs_own_cert, or the handshake will abort!");
|
||||
return ESP_OK;
|
||||
}
|
||||
#else
|
||||
ESP_LOGE(TAG, "Missing server certificate and/or key");
|
||||
#endif
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
@@ -790,6 +808,7 @@ int esp_mbedtls_server_session_create(esp_tls_cfg_server_t *cfg, int sockfd, esp
|
||||
tls->conn_state = ESP_TLS_FAIL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
tls->read = esp_mbedtls_read;
|
||||
tls->write = esp_mbedtls_write;
|
||||
int ret;
|
||||
|
Reference in New Issue
Block a user