From d75c5c440560918cb311e9796b621e174737ccac Mon Sep 17 00:00:00 2001 From: Valerio Setti Date: Tue, 13 Dec 2022 11:51:32 +0100 Subject: [PATCH] test: pake: fail in case the opaque key is destroyed unexpectedly Signed-off-by: Valerio Setti --- programs/ssl/ssl_client2.c | 8 +++++++- programs/ssl/ssl_server2.c | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/programs/ssl/ssl_client2.c b/programs/ssl/ssl_client2.c index 02fbbd341..02ee7cf69 100644 --- a/programs/ssl/ssl_client2.c +++ b/programs/ssl/ssl_client2.c @@ -3338,8 +3338,14 @@ exit: psa_key_attributes_t check_attributes = PSA_KEY_ATTRIBUTES_INIT; /* Verify that the key is still valid before destroying it */ - if( psa_get_key_attributes( ecjpake_pw_slot, &check_attributes ) == + if( psa_get_key_attributes( ecjpake_pw_slot, &check_attributes ) != PSA_SUCCESS ) + { + if( ret == 0 ) + ret = 1; + mbedtls_printf( "The EC J-PAKE password key has unexpectedly been already destroyed\n" ); + } + else { psa_destroy_key( ecjpake_pw_slot ); } diff --git a/programs/ssl/ssl_server2.c b/programs/ssl/ssl_server2.c index d8c20c29f..06c80908c 100644 --- a/programs/ssl/ssl_server2.c +++ b/programs/ssl/ssl_server2.c @@ -4448,8 +4448,14 @@ exit: psa_key_attributes_t check_attributes = PSA_KEY_ATTRIBUTES_INIT; /* Verify that the key is still valid before destroying it */ - if( psa_get_key_attributes( ecjpake_pw_slot, &check_attributes ) == + if( psa_get_key_attributes( ecjpake_pw_slot, &check_attributes ) != PSA_SUCCESS ) + { + if( ret == 0 ) + ret = 1; + mbedtls_printf( "The EC J-PAKE password key has unexpectedly been already destroyed\n" ); + } + else { psa_destroy_key( ecjpake_pw_slot ); }