mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2026-07-21 11:34:11 +00:00
tests|programs: call check_context_after_session_reset whenever mbedtls_ssl_session_reset
Call mbedtls_test_ssl_check_context_after_session_reset both in programs (ssl_client2 and ssl_server2) and tests to ensure that the SSL context has been properly handled when mbedtls_ssl_session_reset was called. Signed-off-by: Valerio Setti <vsetti@baylibre.com>
This commit is contained in:
@@ -22,6 +22,7 @@ int main(void)
|
||||
#else /* !MBEDTLS_SSL_TEST_IMPOSSIBLE && MBEDTLS_SSL_CLI_C */
|
||||
|
||||
#include "test/psa_crypto_helpers.h"
|
||||
#include "test/ssl_helpers.h"
|
||||
|
||||
/* Size of memory to be allocated for the heap, when using the library's memory
|
||||
* management and MBEDTLS_MEMORY_BUFFER_ALLOC_C is enabled. */
|
||||
@@ -2800,12 +2801,21 @@ send_request:
|
||||
memset(peer_crt_info, 0, sizeof(peer_crt_info));
|
||||
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
|
||||
|
||||
/* Dump the SSL context before resetting it. This will be used below
|
||||
* to check if the reset function worked properly. */
|
||||
mbedtls_ssl_context ssl_before = ssl;
|
||||
if ((ret = mbedtls_ssl_session_reset(&ssl)) != 0) {
|
||||
mbedtls_printf(" failed\n ! mbedtls_ssl_session_reset returned -0x%x\n\n",
|
||||
(unsigned int) -ret);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (mbedtls_test_ssl_check_context_after_session_reset(&ssl_before, &ssl) != 0) {
|
||||
mbedtls_printf(
|
||||
" failed\n ! mbedtls_ssl_session_reset didn't properly reset ssl context\n\n");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
while ((ret = mbedtls_ssl_handshake(&ssl)) != 0) {
|
||||
if (ret != MBEDTLS_ERR_SSL_WANT_READ &&
|
||||
ret != MBEDTLS_ERR_SSL_WANT_WRITE &&
|
||||
|
||||
@@ -52,6 +52,7 @@ int main(void)
|
||||
#endif
|
||||
|
||||
#include "test/psa_crypto_helpers.h"
|
||||
#include "test/ssl_helpers.h"
|
||||
|
||||
#include "mbedtls/pk.h"
|
||||
#if defined(MBEDTLS_PK_HAVE_PRIVATE_HEADER)
|
||||
@@ -3271,7 +3272,15 @@ reset:
|
||||
|
||||
mbedtls_net_free(&client_fd);
|
||||
|
||||
/* Dump the SSL context before resetting it. This will be used below
|
||||
* to check if the reset function worked properly. */
|
||||
mbedtls_ssl_context ssl_before = ssl;
|
||||
mbedtls_ssl_session_reset(&ssl);
|
||||
if (mbedtls_test_ssl_check_context_after_session_reset(&ssl_before, &ssl) != 0) {
|
||||
mbedtls_printf(
|
||||
" failed\n ! mbedtls_ssl_session_reset didn't properly reset ssl context\n\n");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/*
|
||||
* 3. Wait until a client connects
|
||||
|
||||
@@ -1035,6 +1035,14 @@ int mbedtls_test_ssl_endpoint_init(
|
||||
void mbedtls_test_ssl_endpoint_free(
|
||||
mbedtls_test_ssl_endpoint *ep)
|
||||
{
|
||||
mbedtls_ssl_context ssl_before;
|
||||
|
||||
/* Dump the SSL context before resetting it */
|
||||
memcpy(&ssl_before, &(ep->ssl), sizeof(mbedtls_ssl_context));
|
||||
|
||||
mbedtls_ssl_session_reset(&(ep->ssl));
|
||||
/* Check that required fields were properly reset */
|
||||
mbedtls_test_ssl_check_context_after_session_reset(&ssl_before, &(ep->ssl));
|
||||
mbedtls_ssl_free(&(ep->ssl));
|
||||
mbedtls_ssl_config_free(&(ep->conf));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user