mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-03-08 10:09:54 +00:00
Merge pull request #4198 from maulik-arm/maulik-arm/fix-4162
PSA Update return code for non-existing key in various key operations
This commit is contained in:
commit
2af9641a7d
4
ChangeLog.d/fix_return_type_for_invalid_crypto_key.txt
Normal file
4
ChangeLog.d/fix_return_type_for_invalid_crypto_key.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
Bugfix
|
||||
* PSA functions other than psa_open_key now return PSA_ERROR_INVALID_HANDLE
|
||||
rather than PSA_ERROR_DOES_NOT_EXIST for an invalid handle, bringing them
|
||||
in line with version 1.0.0 of the specification. Fix #4162.
|
|
@ -305,13 +305,15 @@ psa_status_t psa_get_and_lock_key_slot( mbedtls_svc_key_id_t key,
|
|||
|
||||
status = psa_load_persistent_key_into_slot( *p_slot );
|
||||
if( status != PSA_SUCCESS )
|
||||
{
|
||||
psa_wipe_key_slot( *p_slot );
|
||||
|
||||
if( status == PSA_ERROR_DOES_NOT_EXIST )
|
||||
status = PSA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
return( status );
|
||||
#else
|
||||
return( PSA_ERROR_DOES_NOT_EXIST );
|
||||
return( PSA_ERROR_INVALID_HANDLE );
|
||||
#endif /* defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) */
|
||||
|
||||
}
|
||||
|
||||
psa_status_t psa_unlock_key_slot( psa_key_slot_t *slot )
|
||||
|
@ -399,6 +401,9 @@ psa_status_t psa_open_key( mbedtls_svc_key_id_t key, psa_key_handle_t *handle )
|
|||
if( status != PSA_SUCCESS )
|
||||
{
|
||||
*handle = PSA_KEY_HANDLE_INIT;
|
||||
if( status == PSA_ERROR_INVALID_HANDLE )
|
||||
status = PSA_ERROR_DOES_NOT_EXIST;
|
||||
|
||||
return( status );
|
||||
}
|
||||
|
||||
|
@ -423,8 +428,12 @@ psa_status_t psa_close_key( psa_key_handle_t handle )
|
|||
|
||||
status = psa_get_and_lock_key_slot_in_memory( handle, &slot );
|
||||
if( status != PSA_SUCCESS )
|
||||
return( status );
|
||||
{
|
||||
if( status == PSA_ERROR_DOES_NOT_EXIST )
|
||||
status = PSA_ERROR_INVALID_HANDLE;
|
||||
|
||||
return( status );
|
||||
}
|
||||
if( slot->lock_count <= 1 )
|
||||
return( psa_wipe_key_slot( slot ) );
|
||||
else
|
||||
|
|
|
@ -205,7 +205,7 @@ static int test_operations_on_invalid_key( mbedtls_svc_key_id_t key )
|
|||
psa_set_key_algorithm( &attributes, PSA_ALG_CTR );
|
||||
psa_set_key_type( &attributes, PSA_KEY_TYPE_AES );
|
||||
TEST_EQUAL( psa_get_key_attributes( key, &attributes ),
|
||||
PSA_ERROR_DOES_NOT_EXIST );
|
||||
PSA_ERROR_INVALID_HANDLE );
|
||||
TEST_EQUAL(
|
||||
MBEDTLS_SVC_KEY_ID_GET_KEY_ID( psa_get_key_id( &attributes ) ), 0 );
|
||||
TEST_EQUAL(
|
||||
|
@ -217,10 +217,10 @@ static int test_operations_on_invalid_key( mbedtls_svc_key_id_t key )
|
|||
TEST_EQUAL( psa_get_key_bits( &attributes ), 0 );
|
||||
|
||||
TEST_EQUAL( psa_export_key( key, buffer, sizeof( buffer ), &length ),
|
||||
PSA_ERROR_DOES_NOT_EXIST );
|
||||
PSA_ERROR_INVALID_HANDLE );
|
||||
TEST_EQUAL( psa_export_public_key( key,
|
||||
buffer, sizeof( buffer ), &length ),
|
||||
PSA_ERROR_DOES_NOT_EXIST );
|
||||
PSA_ERROR_INVALID_HANDLE );
|
||||
|
||||
ok = 1;
|
||||
|
||||
|
|
|
@ -89,15 +89,15 @@ create_existent:PSA_KEY_LIFETIME_PERSISTENT:0x3617:1:KEEP_OPEN
|
|||
|
||||
Open failure: invalid identifier (0)
|
||||
depends_on:MBEDTLS_PSA_CRYPTO_STORAGE_C
|
||||
open_fail:0:PSA_ERROR_INVALID_HANDLE
|
||||
open_fail:0:PSA_ERROR_DOES_NOT_EXIST
|
||||
|
||||
Open failure: invalid identifier (random seed UID)
|
||||
depends_on:MBEDTLS_PSA_CRYPTO_STORAGE_C
|
||||
open_fail:PSA_CRYPTO_ITS_RANDOM_SEED_UID:PSA_ERROR_INVALID_HANDLE
|
||||
open_fail:PSA_CRYPTO_ITS_RANDOM_SEED_UID:PSA_ERROR_DOES_NOT_EXIST
|
||||
|
||||
Open failure: invalid identifier (reserved range)
|
||||
depends_on:MBEDTLS_PSA_CRYPTO_STORAGE_C
|
||||
open_fail:PSA_KEY_ID_VENDOR_MAX + 1:PSA_ERROR_INVALID_HANDLE
|
||||
open_fail:PSA_KEY_ID_VENDOR_MAX + 1:PSA_ERROR_DOES_NOT_EXIST
|
||||
|
||||
Open failure: invalid identifier (implementation range)
|
||||
depends_on:MBEDTLS_PSA_CRYPTO_STORAGE_C
|
||||
|
@ -178,16 +178,16 @@ depends_on:PSA_WANT_ALG_CTR:PSA_WANT_KEY_TYPE_AES:MBEDTLS_PSA_CRYPTO_STORAGE_C
|
|||
copy_to_occupied:PSA_KEY_LIFETIME_PERSISTENT:1:PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_COPY:PSA_ALG_CTR:PSA_KEY_TYPE_AES:"404142434445464748494a4b4c4d4e4f":PSA_KEY_LIFETIME_PERSISTENT:1:PSA_KEY_USAGE_EXPORT:PSA_ALG_CTR:PSA_KEY_TYPE_AES:"404142434445464748494a4b4c4d4e4f"
|
||||
|
||||
invalid handle: 0
|
||||
invalid_handle:INVALID_HANDLE_0:PSA_SUCCESS:PSA_ERROR_INVALID_HANDLE
|
||||
invalid_handle:INVALID_HANDLE_0:PSA_SUCCESS
|
||||
|
||||
invalid handle: never opened
|
||||
invalid_handle:INVALID_HANDLE_UNOPENED:PSA_ERROR_DOES_NOT_EXIST:PSA_ERROR_DOES_NOT_EXIST
|
||||
invalid_handle:INVALID_HANDLE_UNOPENED:PSA_ERROR_INVALID_HANDLE
|
||||
|
||||
invalid handle: already closed
|
||||
invalid_handle:INVALID_HANDLE_CLOSED:PSA_ERROR_DOES_NOT_EXIST:PSA_ERROR_DOES_NOT_EXIST
|
||||
invalid_handle:INVALID_HANDLE_CLOSED:PSA_ERROR_INVALID_HANDLE
|
||||
|
||||
invalid handle: huge
|
||||
invalid_handle:INVALID_HANDLE_HUGE:PSA_ERROR_INVALID_HANDLE:PSA_ERROR_INVALID_HANDLE
|
||||
invalid_handle:INVALID_HANDLE_HUGE:PSA_ERROR_INVALID_HANDLE
|
||||
|
||||
Open many transient keys
|
||||
many_transient_keys:42
|
||||
|
|
|
@ -178,8 +178,8 @@ void transient_slot_lifecycle( int owner_id_arg,
|
|||
|
||||
/* Test that the key is now invalid. */
|
||||
TEST_EQUAL( psa_get_key_attributes( key, &attributes ),
|
||||
PSA_ERROR_DOES_NOT_EXIST );
|
||||
TEST_EQUAL( psa_close_key( key ), PSA_ERROR_DOES_NOT_EXIST );
|
||||
PSA_ERROR_INVALID_HANDLE );
|
||||
TEST_EQUAL( psa_close_key( key ), PSA_ERROR_INVALID_HANDLE );
|
||||
|
||||
exit:
|
||||
/*
|
||||
|
@ -326,10 +326,10 @@ void persistent_slot_lifecycle( int lifetime_arg, int owner_id_arg, int id_arg,
|
|||
* existing key.
|
||||
*/
|
||||
TEST_EQUAL( psa_get_key_attributes( handle, &read_attributes ),
|
||||
PSA_ERROR_DOES_NOT_EXIST );
|
||||
TEST_EQUAL( psa_close_key( handle ), PSA_ERROR_DOES_NOT_EXIST );
|
||||
PSA_ERROR_INVALID_HANDLE );
|
||||
TEST_EQUAL( psa_close_key( handle ), PSA_ERROR_INVALID_HANDLE );
|
||||
TEST_EQUAL( psa_get_key_attributes( id, &read_attributes ),
|
||||
PSA_ERROR_DOES_NOT_EXIST );
|
||||
PSA_ERROR_INVALID_HANDLE );
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -728,13 +728,12 @@ exit:
|
|||
|
||||
/* BEGIN_CASE */
|
||||
void invalid_handle( int handle_construction,
|
||||
int close_status_arg, int usage_status_arg )
|
||||
int close_status_arg )
|
||||
{
|
||||
psa_key_handle_t valid_handle = PSA_KEY_HANDLE_INIT;
|
||||
psa_key_handle_t invalid_handle = PSA_KEY_HANDLE_INIT;
|
||||
psa_key_id_t key_id;
|
||||
psa_status_t close_status = close_status_arg;
|
||||
psa_status_t usage_status = usage_status_arg;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
uint8_t material[1] = "a";
|
||||
|
||||
|
@ -793,7 +792,7 @@ void invalid_handle( int handle_construction,
|
|||
|
||||
/* Attempt to use the invalid handle. */
|
||||
TEST_EQUAL( psa_get_key_attributes( invalid_handle, &attributes ),
|
||||
usage_status );
|
||||
PSA_ERROR_INVALID_HANDLE );
|
||||
TEST_EQUAL( psa_close_key( invalid_handle ), close_status );
|
||||
TEST_EQUAL( psa_destroy_key( invalid_handle ), close_status );
|
||||
|
||||
|
|
Loading…
Reference in a new issue