diff --git a/examples/protocols/https_request/example_test.py b/examples/protocols/https_request/example_test.py index 970cf5533c..9fc9771b6f 100644 --- a/examples/protocols/https_request/example_test.py +++ b/examples/protocols/https_request/example_test.py @@ -63,6 +63,19 @@ def test_examples_protocol_https_request(env, extra_data): raise 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 dut1 = env.get_dut('https_request', 'examples/protocols/https_request', dut_class=ttfw_idf.ESP32DUT, app_config_name='ssldyn') # check and log bin size diff --git a/examples/protocols/https_request/main/https_request_example_main.c b/examples/protocols/https_request/main/https_request_example_main.c index d333145953..6fa5fbaec9 100644 --- a/examples/protocols/https_request/main/https_request_example_main.c +++ b/examples/protocols/https_request/main/https_request_example_main.c @@ -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_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) { char buf[512]; @@ -82,6 +84,12 @@ static void https_get_request(esp_tls_cfg_t cfg) 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; do { ret = esp_tls_conn_write(tls, @@ -143,6 +151,8 @@ static void https_get_request_using_crt_bundle(void) https_get_request(cfg); } + + static void https_get_request_using_cacert_buf(void) { 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(); } +#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) { 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_cacert_buf(); 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"); vTaskDelete(NULL); } diff --git a/examples/protocols/https_request/sdkconfig.ci b/examples/protocols/https_request/sdkconfig.ci index 42f4b389e1..19398a6bb6 100644 --- a/examples/protocols/https_request/sdkconfig.ci +++ b/examples/protocols/https_request/sdkconfig.ci @@ -9,3 +9,4 @@ CONFIG_EXAMPLE_ETH_MDIO_GPIO=18 CONFIG_EXAMPLE_ETH_PHY_RST_GPIO=5 CONFIG_EXAMPLE_ETH_PHY_ADDR=1 CONFIG_EXAMPLE_CONNECT_IPV6=y +CONFIG_ESP_TLS_CLIENT_SESSION_TICKETS=y