Added demo to showcase use of client session tickets

* Added required example test
pull/7680/head
Aditya Patwardhan 2021-09-02 09:06:09 +05:30
rodzic b4e4b9f20d
commit 695f1b6503
3 zmienionych plików z 41 dodań i 2 usunięć

Wyświetl plik

@ -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

Wyświetl plik

@ -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);
}

Wyświetl plik

@ -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