feat(esp_https_server): Updated the ESP_TLS_SERVER_CERT_SELECT_HOOK config

Update the ESP_TLS_SERVER_CERT_SELECT_HOOK config to ESP_HTTPS_SERVER_CERT_SELECT_HOOK
And made it depend on  ESP_TLS_SERVER_CERT_SELECT_HOOK
This commit is contained in:
hrushikesh.bhosale
2024-10-03 18:25:54 +05:30
parent b7aecdbbaf
commit ace6a490bc
9 changed files with 55 additions and 7 deletions

View File

@@ -13,4 +13,13 @@ menu "ESP HTTPS server"
This config option helps in setting the time in millisecond to wait for event to be posted to the
system default event loop. Set it to -1 if you need to set timeout to portMAX_DELAY.
config ESP_HTTPS_SERVER_CERT_SELECT_HOOK
select ESP_TLS_SERVER_CERT_SELECT_HOOK
bool "Enable certificate selection hook"
default n
help
Enable certificate selection hook for ESP HTTPS Server. When enabled, this allows the server to
dynamically select the appropriate certificate based on the client's Server Name Indication (SNI).
This is useful for hosting multiple domains on a single server with different SSL certificates.
endmenu

View File

@@ -44,6 +44,8 @@ typedef enum {
HTTPD_SSL_USER_CB_SESS_CLOSE
} httpd_ssl_user_cb_state_t;
typedef esp_tls_handshake_callback esp_https_server_cert_select_cb;
/**
* @brief Callback data struct, contains the ESP-TLS connection handle
* and the connection state at which the callback is executed
@@ -123,8 +125,8 @@ struct httpd_ssl_config {
void *ssl_userdata;
/** Certificate selection callback to use.
* The callback is only applicable when CONFIG_ESP_TLS_SERVER_CERT_SELECT_HOOK is enabled in menuconfig */
esp_tls_handshake_callback cert_select_cb;
* The callback is only applicable when CONFIG_ESP_HTTPS_SERVER_CERT_SELECT_HOOK is enabled in menuconfig */
esp_https_server_cert_select_cb cert_select_cb;
/** Application protocols the server supports in order of prefernece.
* Used for negotiating during the TLS handshake, first one the client supports is selected.

View File

@@ -278,7 +278,7 @@ static esp_err_t create_secure_context(const struct httpd_ssl_config *config, ht
cfg->userdata = config->ssl_userdata;
cfg->alpn_protos = config->alpn_protos;
#if defined(CONFIG_ESP_TLS_SERVER_CERT_SELECT_HOOK)
#if defined(CONFIG_ESP_HTTPS_SERVER_CERT_SELECT_HOOK)
cfg->cert_select_cb = config->cert_select_cb;
#endif
@@ -312,13 +312,13 @@ static esp_err_t create_secure_context(const struct httpd_ssl_config *config, ht
goto exit;
}
} else {
#if defined(CONFIG_ESP_TLS_SERVER_CERT_SELECT_HOOK)
#if defined(CONFIG_ESP_HTTPS_SERVER_CERT_SELECT_HOOK)
if (config->cert_select_cb == NULL) {
#endif
ESP_LOGE(TAG, "No Server certificate supplied");
ret = ESP_ERR_INVALID_ARG;
goto exit;
#if defined(CONFIG_ESP_TLS_SERVER_CERT_SELECT_HOOK)
#if defined(CONFIG_ESP_HTTPS_SERVER_CERT_SELECT_HOOK)
} else {
ESP_LOGW(TAG, "Server certificate not supplied, make sure to supply it in the certificate selection hook!");
}
@@ -349,7 +349,7 @@ static esp_err_t create_secure_context(const struct httpd_ssl_config *config, ht
goto exit;
}
} else {
#if defined(CONFIG_ESP_TLS_SERVER_CERT_SELECT_HOOK)
#if defined(CONFIG_ESP_HTTPS_SERVER_CERT_SELECT_HOOK)
if (config->cert_select_cb == NULL) {
ESP_LOGE(TAG, "No Server key supplied and no certificate selection hook is present");
ret = ESP_ERR_INVALID_ARG;