@@ -51,6 +51,34 @@ void inject_entropy()
51
51
}
52
52
#endif // defined(MBEDTLS_ENTROPY_NV_SEED) || defined(COMPONENT_PSA_SRV_IPC)
53
53
54
+ void test_open_other_partition_key (void )
55
+ {
56
+ static const psa_key_id_t key_id = 999 ;
57
+ static const psa_key_type_t key_type = PSA_KEY_TYPE_AES;
58
+ static const psa_key_usage_t key_usage = PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT;
59
+ static const psa_algorithm_t key_alg = PSA_ALG_CBC_NO_PADDING;
60
+ static const size_t key_bits = 128 ;
61
+ psa_key_handle_t key_handle = 0 ;
62
+
63
+ /* via test partition - create a key, set key policy, generate key material and close */
64
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_create_persistent_key (key_id, &key_handle));
65
+ TEST_ASSERT_NOT_EQUAL (0 , key_handle);
66
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_set_key_policy (key_handle, key_usage, key_alg));
67
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_generate_key (key_handle, key_type, key_bits));
68
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_close_key (key_handle));
69
+
70
+ /* via test partition - reopen the key created by the test partition */
71
+ key_handle = 0 ;
72
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_open_persistent_key (key_id, &key_handle));
73
+ TEST_ASSERT_NOT_EQUAL (0 , key_handle);
74
+
75
+ /* via test partition - close the key created by the test partition */
76
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_close_key (key_handle));
77
+
78
+ /* try to open the key created by the test partition */
79
+ TEST_ASSERT_EQUAL (PSA_ERROR_DOES_NOT_EXIST, psa_open_key (PSA_KEY_LIFETIME_PERSISTENT, key_id, &key_handle));
80
+ }
81
+
54
82
utest::v1::status_t case_setup_handler (const Case *const source, const size_t index_of_case)
55
83
{
56
84
psa_status_t status = mbed_psa_reboot_and_request_new_security_state (PSA_LIFECYCLE_ASSEMBLY_AND_TEST);
@@ -83,7 +111,14 @@ utest::v1::status_t test_setup(const size_t number_of_cases)
83
111
return verbose_test_setup_handler (number_of_cases);
84
112
}
85
113
114
+ Case cases[] = {
115
+ Case (" open other partitions' key" ,
116
+ case_setup_handler, test_open_other_partition_key, case_teardown_handler),
117
+ };
118
+
119
+ Specification specification (test_setup, cases);
120
+
86
121
int main (void )
87
122
{
88
- return ( 1 );
123
+ return ! Harness::run (specification );
89
124
}
0 commit comments