|
27 | 27 | ( PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION( \ |
28 | 28 | PSA_KEY_PERSISTENCE_DEFAULT, TEST_DRIVER_LOCATION ) ) |
29 | 29 |
|
| 30 | +#define TEST_SE_VOLATILE_LIFETIME \ |
| 31 | + ( PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION( \ |
| 32 | + PSA_KEY_PERSISTENCE_VOLATILE, TEST_DRIVER_LOCATION ) ) |
| 33 | + |
30 | 34 | /** The driver detected a condition that shouldn't happen. |
31 | 35 | * This is probably a bug in the library. */ |
32 | 36 | #define PSA_ERROR_DETECTED_BY_DRIVER ((psa_status_t)( -500 )) |
@@ -609,6 +613,20 @@ exit: |
609 | 613 | return( ok ); |
610 | 614 | } |
611 | 615 |
|
| 616 | +/* Check that no persistent data exists for the given location. */ |
| 617 | +static int check_no_persistent_data( psa_key_location_t location ) |
| 618 | +{ |
| 619 | + psa_storage_uid_t uid = file_uid_for_location( location ); |
| 620 | + struct psa_storage_info_t info; |
| 621 | + int ok = 0; |
| 622 | + |
| 623 | + TEST_ASSERT( psa_its_get_info( uid, &info ) == PSA_ERROR_DOES_NOT_EXIST ); |
| 624 | + ok = 1; |
| 625 | + |
| 626 | +exit: |
| 627 | + return( ok ); |
| 628 | +} |
| 629 | + |
612 | 630 | /* Check that a function's return status is "smoke-free", i.e. that |
613 | 631 | * it's an acceptable error code when calling an API function that operates |
614 | 632 | * on a key with potentially bogus parameters. */ |
@@ -829,11 +847,11 @@ exit: |
829 | 847 | /* END_CASE */ |
830 | 848 |
|
831 | 849 | /* BEGIN_CASE */ |
832 | | -void key_creation_import_export( int min_slot, int restart ) |
| 850 | +void key_creation_import_export( int lifetime_arg, int min_slot, int restart ) |
833 | 851 | { |
834 | 852 | psa_drv_se_t driver; |
835 | 853 | psa_drv_se_key_management_t key_management; |
836 | | - psa_key_lifetime_t lifetime = TEST_SE_PERSISTENT_LIFETIME; |
| 854 | + psa_key_lifetime_t lifetime = (psa_key_lifetime_t) lifetime_arg; |
837 | 855 | psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( lifetime ); |
838 | 856 | psa_key_id_t id = 1; |
839 | 857 | psa_key_handle_t handle = 0; |
@@ -864,22 +882,59 @@ void key_creation_import_export( int min_slot, int restart ) |
864 | 882 | PSA_ASSERT( psa_import_key( &attributes, |
865 | 883 | key_material, sizeof( key_material ), |
866 | 884 | &handle ) ); |
867 | | - if( ! check_persistent_data( location, |
868 | | - &ram_shadow_slot_usage, |
869 | | - sizeof( ram_shadow_slot_usage ) ) ) |
870 | | - goto exit; |
| 885 | + |
| 886 | + |
| 887 | + if( PSA_KEY_LIFETIME_IS_VOLATILE( lifetime ) ) |
| 888 | + { |
| 889 | + /* For volatile keys, check no persistent data was created */ |
| 890 | + if( ! check_no_persistent_data( location ) ) |
| 891 | + goto exit; |
| 892 | + } |
| 893 | + else |
| 894 | + { |
| 895 | + /* For persistent keys, check persistent data */ |
| 896 | + if( ! check_persistent_data( location, |
| 897 | + &ram_shadow_slot_usage, |
| 898 | + sizeof( ram_shadow_slot_usage ) ) ) |
| 899 | + goto exit; |
| 900 | + } |
| 901 | + |
| 902 | + /* Test that the key was created in the expected slot. */ |
| 903 | + TEST_ASSERT( ram_slots[min_slot].type == PSA_KEY_TYPE_RAW_DATA ); |
871 | 904 |
|
872 | 905 | /* Maybe restart, to check that the information is saved correctly. */ |
873 | 906 | if( restart ) |
874 | 907 | { |
875 | 908 | mbedtls_psa_crypto_free( ); |
876 | 909 | PSA_ASSERT( psa_register_se_driver( location, &driver ) ); |
877 | 910 | PSA_ASSERT( psa_crypto_init( ) ); |
878 | | - if( ! check_persistent_data( location, |
879 | | - &ram_shadow_slot_usage, |
880 | | - sizeof( ram_shadow_slot_usage ) ) ) |
881 | | - goto exit; |
882 | | - PSA_ASSERT( psa_open_key( id, &handle ) ); |
| 911 | + |
| 912 | + if( PSA_KEY_LIFETIME_IS_VOLATILE( lifetime ) ) |
| 913 | + { |
| 914 | + /* Check that the PSA core has no knowledge of the volatile key */ |
| 915 | + TEST_ASSERT( psa_open_key( id, &handle ) == PSA_ERROR_DOES_NOT_EXIST ); |
| 916 | + |
| 917 | + /* Drop data from our mockup driver */ |
| 918 | + ram_slots_reset(); |
| 919 | + ram_min_slot = min_slot; |
| 920 | + |
| 921 | + /* Re-import key */ |
| 922 | + PSA_ASSERT( psa_import_key( &attributes, |
| 923 | + key_material, sizeof( key_material ), |
| 924 | + &handle ) ); |
| 925 | + } |
| 926 | + else |
| 927 | + { |
| 928 | + |
| 929 | + /* Check we can re-open the persistent key */ |
| 930 | + if( ! check_persistent_data( location, |
| 931 | + &ram_shadow_slot_usage, |
| 932 | + sizeof( ram_shadow_slot_usage ) ) ) |
| 933 | + goto exit; |
| 934 | + |
| 935 | + /* Check that the PSA core still knows about the key */ |
| 936 | + PSA_ASSERT( psa_open_key( id, &handle ) ); |
| 937 | + } |
883 | 938 | } |
884 | 939 |
|
885 | 940 | /* Test that the key was created in the expected slot. */ |
|
0 commit comments