Skip to content

Commit 401fa7b

Browse files
committed
Merge branch 'feat/updating_configs_of_esp_https_server' into 'master'
feat(esp_https_server): Updated the ESP_TLS_SERVER_CERT_SELECT_HOOK config Closes IDF-8418 See merge request espressif/esp-idf!33966
2 parents a3922cd + ace6a49 commit 401fa7b

File tree

9 files changed

+55
-7
lines changed

9 files changed

+55
-7
lines changed

components/esp_https_server/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,13 @@ menu "ESP HTTPS server"
1313
This config option helps in setting the time in millisecond to wait for event to be posted to the
1414
system default event loop. Set it to -1 if you need to set timeout to portMAX_DELAY.
1515

16+
config ESP_HTTPS_SERVER_CERT_SELECT_HOOK
17+
select ESP_TLS_SERVER_CERT_SELECT_HOOK
18+
bool "Enable certificate selection hook"
19+
default n
20+
help
21+
Enable certificate selection hook for ESP HTTPS Server. When enabled, this allows the server to
22+
dynamically select the appropriate certificate based on the client's Server Name Indication (SNI).
23+
This is useful for hosting multiple domains on a single server with different SSL certificates.
24+
1625
endmenu

components/esp_https_server/include/esp_https_server.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ typedef enum {
4444
HTTPD_SSL_USER_CB_SESS_CLOSE
4545
} httpd_ssl_user_cb_state_t;
4646

47+
typedef esp_tls_handshake_callback esp_https_server_cert_select_cb;
48+
4749
/**
4850
* @brief Callback data struct, contains the ESP-TLS connection handle
4951
* and the connection state at which the callback is executed
@@ -123,8 +125,8 @@ struct httpd_ssl_config {
123125
void *ssl_userdata;
124126

125127
/** Certificate selection callback to use.
126-
* The callback is only applicable when CONFIG_ESP_TLS_SERVER_CERT_SELECT_HOOK is enabled in menuconfig */
127-
esp_tls_handshake_callback cert_select_cb;
128+
* The callback is only applicable when CONFIG_ESP_HTTPS_SERVER_CERT_SELECT_HOOK is enabled in menuconfig */
129+
esp_https_server_cert_select_cb cert_select_cb;
128130

129131
/** Application protocols the server supports in order of prefernece.
130132
* Used for negotiating during the TLS handshake, first one the client supports is selected.

components/esp_https_server/src/https_server.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ static esp_err_t create_secure_context(const struct httpd_ssl_config *config, ht
278278
cfg->userdata = config->ssl_userdata;
279279
cfg->alpn_protos = config->alpn_protos;
280280

281-
#if defined(CONFIG_ESP_TLS_SERVER_CERT_SELECT_HOOK)
281+
#if defined(CONFIG_ESP_HTTPS_SERVER_CERT_SELECT_HOOK)
282282
cfg->cert_select_cb = config->cert_select_cb;
283283
#endif
284284

@@ -312,13 +312,13 @@ static esp_err_t create_secure_context(const struct httpd_ssl_config *config, ht
312312
goto exit;
313313
}
314314
} else {
315-
#if defined(CONFIG_ESP_TLS_SERVER_CERT_SELECT_HOOK)
315+
#if defined(CONFIG_ESP_HTTPS_SERVER_CERT_SELECT_HOOK)
316316
if (config->cert_select_cb == NULL) {
317317
#endif
318318
ESP_LOGE(TAG, "No Server certificate supplied");
319319
ret = ESP_ERR_INVALID_ARG;
320320
goto exit;
321-
#if defined(CONFIG_ESP_TLS_SERVER_CERT_SELECT_HOOK)
321+
#if defined(CONFIG_ESP_HTTPS_SERVER_CERT_SELECT_HOOK)
322322
} else {
323323
ESP_LOGW(TAG, "Server certificate not supplied, make sure to supply it in the certificate selection hook!");
324324
}
@@ -349,7 +349,7 @@ static esp_err_t create_secure_context(const struct httpd_ssl_config *config, ht
349349
goto exit;
350350
}
351351
} else {
352-
#if defined(CONFIG_ESP_TLS_SERVER_CERT_SELECT_HOOK)
352+
#if defined(CONFIG_ESP_HTTPS_SERVER_CERT_SELECT_HOOK)
353353
if (config->cert_select_cb == NULL) {
354354
ESP_LOGE(TAG, "No Server key supplied and no certificate selection hook is present");
355355
ret = ESP_ERR_INVALID_ARG;

docs/en/api-reference/protocols/esp_https_server.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,26 @@ Application Examples
7070

7171
- :example:`protocols/https_server/wss_server` demonstrates how to create an SSL server with a simple WebSocket request handler that supports handling multiple clients, PING-PONG mechanism, and sending asynchronous messages to all clients.
7272

73+
HTTPS Server Cert Selection Hook
74+
--------------------------------
75+
76+
The ESP HTTPS Server component provides an option to set the server certification selection hook. This feature allows you to configure and use a certificate selection callback during server handshake. The callback helps to select a certificate to present to the client based on the TLS extensions supplied in the client hello message, such as ALPN and SNI. To enable this feature, please enable :ref:`CONFIG_ESP_HTTPS_SERVER_CERT_SELECT_HOOK` in the ESP HTTPS Server menuconfig. Note that you also need to enable :ref:`CONFIG_ESP_TLS_SERVER_CERT_SELECT_HOOK` from the ESP-TLS component, as this option depends on it. Please note that the ESP-TLS option is only available when Mbedtls is used as the TLS stack for ESP-TLS (default behaviour).
77+
78+
When enabled, you can set the certificate selection callback using the :cpp:member:`httpd_ssl_config::cert_select_cb` member of the :cpp:type:`httpd_ssl_config_t` structure.
79+
80+
.. code-block:: c
81+
82+
int cert_selection_callback(mbedtls_ssl_context *ssl)
83+
{
84+
/* Code that the callback should execute */
85+
return 0;
86+
}
87+
88+
httpd_ssl_config_t cfg = {
89+
cert_select_cb = cert_section_callback,
90+
};
91+
92+
7393
API Reference
7494
-------------
7595

docs/en/migration-guides/release-5.x/5.4/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ Migration from 5.3 to 5.4
1111
bluetooth-classic
1212
storage
1313
wifi
14+
protocols
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Protocols
2+
=========
3+
4+
:link_to_translation:`zh_CN:[中文]`
5+
6+
HTTPS Server
7+
------------
8+
9+
Certificate Selection Hook
10+
~~~~~~~~~~~~~~~~~~~~~~~~~~
11+
12+
In order to enable the Certificate Selection hook feature in ESP HTTPS Server, now you need to enable :ref:`CONFIG_ESP_HTTPS_SERVER_CERT_SELECT_HOOK` instead of :ref:`CONFIG_ESP_TLS_SERVER_CERT_SELECT_HOOK`.
13+
14+
The new :ref:`CONFIG_ESP_HTTPS_SERVER_CERT_SELECT_HOOK` option automatically selects :ref:`CONFIG_ESP_TLS_SERVER_CERT_SELECT_HOOK`.

docs/zh_CN/migration-guides/release-5.x/5.4/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
bluetooth-classic
1212
storage
1313
wifi
14+
protocols
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.. include:: ../../../../en/migration-guides/release-5.x/5.4/protocols.rst
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
CONFIG_ESP_HTTPS_SERVER_ENABLE=y
2-
CONFIG_ESP_TLS_SERVER_CERT_SELECT_HOOK=y
2+
CONFIG_ESP_HTTPS_SERVER_CERT_SELECT_HOOK=y
33
CONFIG_EXAMPLE_ENABLE_HTTPS_USER_CALLBACK=y
44
CONFIG_EXAMPLE_WIFI_SSID_PWD_FROM_STDIN=y

0 commit comments

Comments
 (0)