mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-06 14:14:33 +02:00
Added demo to showcase use of client session tickets
* Added required example test
This commit is contained in:
@@ -63,6 +63,19 @@ def test_examples_protocol_https_request(env, extra_data):
|
|||||||
raise
|
raise
|
||||||
Utility.console_log("Passed the test for \"https_request using global ca_store\"")
|
Utility.console_log("Passed the test for \"https_request using global ca_store\"")
|
||||||
|
|
||||||
|
# Check for connection using already saved client session
|
||||||
|
Utility.console_log("Testing for \"https_request using saved client session\"")
|
||||||
|
try:
|
||||||
|
dut1.expect(re.compile('https_request using saved client session'), timeout=20)
|
||||||
|
dut1.expect_all('Connection established...',
|
||||||
|
'Reading HTTP response...',
|
||||||
|
'HTTP/1.1 200 OK',
|
||||||
|
re.compile('connection closed'))
|
||||||
|
except Exception:
|
||||||
|
Utility.console_log("Failed the test for \"https_request using saved client session\"")
|
||||||
|
raise
|
||||||
|
Utility.console_log("Passed the test for \"https_request using saved client session\"")
|
||||||
|
|
||||||
# Check for connection using crt bundle with mbedtls dynamic resource enabled
|
# Check for connection using crt bundle with mbedtls dynamic resource enabled
|
||||||
dut1 = env.get_dut('https_request', 'examples/protocols/https_request', dut_class=ttfw_idf.ESP32DUT, app_config_name='ssldyn')
|
dut1 = env.get_dut('https_request', 'examples/protocols/https_request', dut_class=ttfw_idf.ESP32DUT, app_config_name='ssldyn')
|
||||||
# check and log bin size
|
# check and log bin size
|
||||||
|
@@ -67,7 +67,9 @@ static const char REQUEST[] = "GET " WEB_URL " HTTP/1.1\r\n"
|
|||||||
*/
|
*/
|
||||||
extern const uint8_t server_root_cert_pem_start[] asm("_binary_server_root_cert_pem_start");
|
extern const uint8_t server_root_cert_pem_start[] asm("_binary_server_root_cert_pem_start");
|
||||||
extern const uint8_t server_root_cert_pem_end[] asm("_binary_server_root_cert_pem_end");
|
extern const uint8_t server_root_cert_pem_end[] asm("_binary_server_root_cert_pem_end");
|
||||||
|
#ifdef CONFIG_ESP_TLS_CLIENT_SESSION_TICKETS
|
||||||
|
esp_tls_client_session_t *tls_client_session = NULL;
|
||||||
|
#endif
|
||||||
static void https_get_request(esp_tls_cfg_t cfg)
|
static void https_get_request(esp_tls_cfg_t cfg)
|
||||||
{
|
{
|
||||||
char buf[512];
|
char buf[512];
|
||||||
@@ -82,6 +84,12 @@ static void https_get_request(esp_tls_cfg_t cfg)
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef CONFIG_ESP_TLS_CLIENT_SESSION_TICKETS
|
||||||
|
/* The TLS session is successfully established, now saving the session ctx for reuse */
|
||||||
|
if (tls_client_session == NULL) {
|
||||||
|
tls_client_session = esp_tls_get_client_session(tls);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
size_t written_bytes = 0;
|
size_t written_bytes = 0;
|
||||||
do {
|
do {
|
||||||
ret = esp_tls_conn_write(tls,
|
ret = esp_tls_conn_write(tls,
|
||||||
@@ -143,6 +151,8 @@ static void https_get_request_using_crt_bundle(void)
|
|||||||
https_get_request(cfg);
|
https_get_request(cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void https_get_request_using_cacert_buf(void)
|
static void https_get_request_using_cacert_buf(void)
|
||||||
{
|
{
|
||||||
ESP_LOGI(TAG, "https_request using cacert_buf");
|
ESP_LOGI(TAG, "https_request using cacert_buf");
|
||||||
@@ -169,6 +179,19 @@ static void https_get_request_using_global_ca_store(void)
|
|||||||
esp_tls_free_global_ca_store();
|
esp_tls_free_global_ca_store();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef CONFIG_ESP_TLS_CLIENT_SESSION_TICKETS
|
||||||
|
static void https_get_request_using_already_saved_session(void)
|
||||||
|
{
|
||||||
|
ESP_LOGI(TAG, "https_request using saved client session");
|
||||||
|
esp_tls_cfg_t cfg = {
|
||||||
|
.client_session = tls_client_session,
|
||||||
|
};
|
||||||
|
https_get_request(cfg);
|
||||||
|
free(tls_client_session);
|
||||||
|
tls_client_session = NULL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static void https_request_task(void *pvparameters)
|
static void https_request_task(void *pvparameters)
|
||||||
{
|
{
|
||||||
ESP_LOGI(TAG, "Start https_request example");
|
ESP_LOGI(TAG, "Start https_request example");
|
||||||
@@ -176,7 +199,9 @@ static void https_request_task(void *pvparameters)
|
|||||||
https_get_request_using_crt_bundle();
|
https_get_request_using_crt_bundle();
|
||||||
https_get_request_using_cacert_buf();
|
https_get_request_using_cacert_buf();
|
||||||
https_get_request_using_global_ca_store();
|
https_get_request_using_global_ca_store();
|
||||||
|
#ifdef CONFIG_ESP_TLS_CLIENT_SESSION_TICKETS
|
||||||
|
https_get_request_using_already_saved_session();
|
||||||
|
#endif
|
||||||
ESP_LOGI(TAG, "Finish https_request example");
|
ESP_LOGI(TAG, "Finish https_request example");
|
||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
}
|
}
|
||||||
|
@@ -9,3 +9,4 @@ CONFIG_EXAMPLE_ETH_MDIO_GPIO=18
|
|||||||
CONFIG_EXAMPLE_ETH_PHY_RST_GPIO=5
|
CONFIG_EXAMPLE_ETH_PHY_RST_GPIO=5
|
||||||
CONFIG_EXAMPLE_ETH_PHY_ADDR=1
|
CONFIG_EXAMPLE_ETH_PHY_ADDR=1
|
||||||
CONFIG_EXAMPLE_CONNECT_IPV6=y
|
CONFIG_EXAMPLE_CONNECT_IPV6=y
|
||||||
|
CONFIG_ESP_TLS_CLIENT_SESSION_TICKETS=y
|
||||||
|
Reference in New Issue
Block a user