Close or destroy keys explicitly in tests

This commit is contained in:
Gilles Peskine 2019-05-28 14:08:50 +02:00
parent 1153e7bd57
commit 76b29a77fb
3 changed files with 26 additions and 1 deletions

View file

@ -1291,6 +1291,7 @@ void import_rsa_made_up( int bits_arg, int keypair, int expected_status_arg )
psa_set_key_type( &attributes, type );
status = psa_import_key( &attributes, p, length, &handle );
TEST_EQUAL( status, expected_status );
if( status == PSA_SUCCESS )
PSA_ASSERT( psa_destroy_key( handle ) );
@ -2100,6 +2101,9 @@ void copy_fail( int source_usage_arg,
TEST_EQUAL( psa_copy_key( source_handle,
&target_attributes, &target_handle ),
expected_status_arg );
PSA_ASSERT( psa_destroy_key( source_handle ) );
exit:
psa_reset_key_attributes( &source_attributes );
psa_reset_key_attributes( &target_attributes );
@ -2587,6 +2591,8 @@ void mac_bad_order( )
PSA_ERROR_BAD_STATE );
PSA_ASSERT( psa_mac_abort( &operation ) );
PSA_ASSERT( psa_destroy_key( handle ) );
exit:
PSA_DONE( );
}
@ -2908,6 +2914,8 @@ void cipher_bad_order( )
PSA_ERROR_BAD_STATE );
PSA_ASSERT( psa_cipher_abort( &operation ) );
PSA_ASSERT( psa_destroy_key( handle ) );
exit:
PSA_DONE( );
}
@ -5016,6 +5024,7 @@ void persistent_key_load_key_from_storage( data_t *data,
}
/* Shutdown and restart */
PSA_ASSERT( psa_close_key( handle ) );
PSA_DONE();
PSA_ASSERT( psa_crypto_init() );

View file

@ -108,6 +108,9 @@ void save_large_persistent_key( int data_too_large, int expected_status )
TEST_EQUAL( psa_import_key( &attributes, data, data_length, &handle ),
expected_status );
if( expected_status == PSA_SUCCESS )
PSA_ASSERT( psa_destroy_key( handle ) );
exit:
mbedtls_free( data );
PSA_DONE();
@ -161,6 +164,8 @@ void persistent_key_destroy( int key_id_arg, int restart,
PSA_ASSERT( psa_import_key( &attributes, second_data->x, second_data->len,
&handle ) );
PSA_ASSERT( psa_destroy_key( handle ) );
exit:
PSA_DONE();
psa_destroy_persistent_key( key_id );
@ -206,6 +211,8 @@ void persistent_key_import( int key_id_arg, int type_arg, data_t *data,
TEST_EQUAL( psa_get_key_usage_flags( &attributes ), 0 );
TEST_EQUAL( psa_get_key_algorithm( &attributes ), 0 );
PSA_ASSERT( psa_destroy_key( handle ) );
exit:
psa_reset_key_attributes( &attributes );
psa_destroy_persistent_key( key_id );

View file

@ -228,6 +228,7 @@ void persistent_slot_lifecycle( int lifetime_arg, int id_arg,
&reexported_length ),
PSA_ERROR_NOT_PERMITTED );
}
PSA_ASSERT( psa_close_key( handle ) );
break;
case CLOSE_BY_DESTROY:
TEST_EQUAL( psa_open_key( id, &handle ),
@ -302,6 +303,8 @@ void create_existent( int lifetime_arg, int id_arg,
ASSERT_COMPARE( material1, sizeof( material1 ),
reexported, reexported_length );
PSA_ASSERT( psa_close_key( handle1 ) );
exit:
PSA_DONE( );
psa_purge_key_storage( );
@ -428,7 +431,7 @@ void copy_across_lifetimes( int source_lifetime_arg, int source_id_arg,
* sure that the material is still alive. */
if( target_lifetime != PSA_KEY_LIFETIME_VOLATILE )
{
PSA_DONE( );
mbedtls_psa_crypto_free( );
PSA_ASSERT( psa_crypto_init( ) );
PSA_ASSERT( psa_open_key( target_id, &target_handle ) );
}
@ -463,6 +466,8 @@ void copy_across_lifetimes( int source_lifetime_arg, int source_id_arg,
PSA_ERROR_NOT_PERMITTED );
}
PSA_ASSERT( psa_destroy_key( target_handle ) );
exit:
PSA_DONE( );
mbedtls_free( export_buffer );
@ -566,6 +571,10 @@ void copy_to_occupied( int source_lifetime_arg, int source_id_arg,
export_buffer, length );
}
PSA_ASSERT( psa_destroy_key( source_handle ) );
if( target_handle != source_handle )
PSA_ASSERT( psa_destroy_key( target_handle ) );
exit:
PSA_DONE( );
mbedtls_free( export_buffer );