Merge pull request #4279 from ronald-cron-arm/fix-invalid-id-error-code

Fix error code when creating/registering a key with invalid id
This commit is contained in:
Gilles Peskine 2021-04-06 18:46:30 +02:00 committed by GitHub
commit 889828d0b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 70 additions and 43 deletions

View file

@ -1624,9 +1624,8 @@ static psa_status_t psa_validate_key_attributes(
}
else
{
status = psa_validate_key_id( psa_get_key_id( attributes ), 0 );
if( status != PSA_SUCCESS )
return( status );
if( !psa_is_valid_key_id( psa_get_key_id( attributes ), 0 ) )
return( PSA_ERROR_INVALID_ARGUMENT );
}
status = psa_validate_key_policy( &attributes->core.policy );
@ -2150,6 +2149,17 @@ psa_status_t psa_copy_key( mbedtls_svc_key_id_t source_key,
}
#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
if( psa_key_lifetime_is_external( actual_attributes.core.lifetime ) )
{
/*
* Copying through an opaque driver is not implemented yet, consider
* a lifetime with an external location as an invalid parameter for
* now.
*/
status = PSA_ERROR_INVALID_ARGUMENT;
goto exit;
}
status = psa_copy_key_material( source_slot, target_slot );
if( status != PSA_SUCCESS )
goto exit;

View file

@ -51,21 +51,20 @@ typedef struct
static psa_global_data_t global_data;
psa_status_t psa_validate_key_id(
mbedtls_svc_key_id_t key, int vendor_ok )
int psa_is_valid_key_id( mbedtls_svc_key_id_t key, int vendor_ok )
{
psa_key_id_t key_id = MBEDTLS_SVC_KEY_ID_GET_KEY_ID( key );
if( ( PSA_KEY_ID_USER_MIN <= key_id ) &&
( key_id <= PSA_KEY_ID_USER_MAX ) )
return( PSA_SUCCESS );
return( 1 );
if( vendor_ok &&
( PSA_KEY_ID_VENDOR_MIN <= key_id ) &&
( key_id <= PSA_KEY_ID_VENDOR_MAX ) )
return( PSA_SUCCESS );
return( 1 );
return( PSA_ERROR_INVALID_HANDLE );
return( 0 );
}
/** Get the description in memory of a key given its identifier and lock it.
@ -124,9 +123,8 @@ static psa_status_t psa_get_and_lock_key_slot_in_memory(
}
else
{
status = psa_validate_key_id( key, 1 );
if( status != PSA_SUCCESS )
return( status );
if ( !psa_is_valid_key_id( key, 1 ) )
return( PSA_ERROR_INVALID_HANDLE );
for( slot_idx = 0; slot_idx < MBEDTLS_PSA_KEY_SLOT_COUNT; slot_idx++ )
{

View file

@ -205,8 +205,8 @@ psa_status_t psa_validate_key_location( psa_key_lifetime_t lifetime,
* \param[in] lifetime The key lifetime attribute.
*
* \retval #PSA_SUCCESS
* \retval #PSA_ERROR_INVALID_ARGUMENT The key is persistent but persistent
* keys are not supported.
* \retval #PSA_ERROR_NOT_SUPPORTED The key is persistent but persistent keys
* are not supported.
*/
psa_status_t psa_validate_key_persistence( psa_key_lifetime_t lifetime );
@ -217,9 +217,8 @@ psa_status_t psa_validate_key_persistence( psa_key_lifetime_t lifetime );
* vendor range are allowed, volatile key identifiers
* excepted \c 0 otherwise.
*
* \retval #PSA_SUCCESS The identifier is valid.
* \retval #PSA_ERROR_INVALID_ARGUMENT The key identifier is not valid.
* \retval <> 0 if the key identifier is valid, 0 otherwise.
*/
psa_status_t psa_validate_key_id( mbedtls_svc_key_id_t key, int vendor_ok );
int psa_is_valid_key_id( mbedtls_svc_key_id_t key, int vendor_ok );
#endif /* PSA_CRYPTO_SLOT_MANAGEMENT_H */