@@ -155,6 +155,80 @@ void test_create_key_same_id_different_partitions(void)
155
155
TEST_ASSERT_EQUAL (PSA_SUCCESS, psa_close_key (key_handle_local));
156
156
}
157
157
158
+ void test_use_other_partition_key_manage_key (void )
159
+ {
160
+ static const psa_key_id_t key_id = 999 ;
161
+ static const psa_key_type_t key_type = PSA_KEY_TYPE_AES;
162
+ static const psa_algorithm_t key_alg = PSA_ALG_CBC_NO_PADDING;
163
+ static const psa_key_usage_t key_usage = PSA_KEY_USAGE_EXPORT;
164
+ static const size_t key_bits = 128 ;
165
+ static const unsigned char key_data[] = {
166
+ 0x2b , 0x7e , 0x15 , 0x16 , 0x28 , 0xae , 0xd2 , 0xa6 ,
167
+ 0xab , 0xf7 , 0x15 , 0x88 , 0x09 , 0xcf , 0x4f , 0x3c
168
+ };
169
+ psa_key_handle_t key_handle = 0 ;
170
+ psa_key_policy_t policy = PSA_KEY_POLICY_INIT;
171
+ unsigned char output[sizeof (key_data)] = { 0 };
172
+ size_t len, got_key_bits;
173
+ psa_key_type_t got_key_type;
174
+ psa_key_lifetime_t got_lifetime;
175
+
176
+ /* via test partition - create a key without generating any key material */
177
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_create_persistent_key (key_id, &key_handle));
178
+ TEST_ASSERT_NOT_EQUAL (0 , key_handle);
179
+
180
+ /* try to set the key policy for the key that was created by the test partition */
181
+ psa_key_policy_set_usage (&policy, key_usage, key_alg);
182
+ TEST_ASSERT_EQUAL (PSA_ERROR_INVALID_HANDLE, psa_set_key_policy (key_handle, &policy));
183
+
184
+ /* via test partition - set key policy */
185
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_set_key_policy (key_handle, key_usage, key_alg));
186
+
187
+ /* try to generate key data for the key that was created by the test partition */
188
+ TEST_ASSERT_EQUAL (PSA_ERROR_INVALID_HANDLE, psa_generate_key (key_handle, key_type, key_bits, NULL , 0 ));
189
+
190
+ /* via test partition - generate key material and close the key */
191
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_generate_key (key_handle, key_type, key_bits));
192
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_close_key (key_handle));
193
+
194
+ /* via test partition - reopen the key created by the test partition and keep it open */
195
+ key_handle = 0 ;
196
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_open_persistent_key (key_id, &key_handle));
197
+ TEST_ASSERT_NOT_EQUAL (0 , key_handle);
198
+
199
+ /* try to work with the handle created for a key created by the test partition */
200
+ got_key_type = 0 ;
201
+ got_key_bits = 0 ;
202
+ got_lifetime = 0 ;
203
+ policy = psa_key_policy_init ();
204
+ TEST_ASSERT_EQUAL (PSA_ERROR_INVALID_HANDLE, psa_get_key_policy (key_handle, &policy));
205
+ TEST_ASSERT_EQUAL (PSA_ERROR_INVALID_HANDLE, psa_get_key_lifetime (key_handle, &got_lifetime));
206
+ TEST_ASSERT_EQUAL (PSA_ERROR_INVALID_HANDLE, psa_close_key (key_handle));
207
+ TEST_ASSERT_EQUAL (PSA_ERROR_INVALID_HANDLE, psa_destroy_key (key_handle));
208
+ TEST_ASSERT_EQUAL (PSA_ERROR_INVALID_HANDLE, psa_get_key_information (key_handle, &got_key_type, &got_key_bits));
209
+ TEST_ASSERT_EQUAL (PSA_ERROR_INVALID_HANDLE, psa_export_key (key_handle, output, sizeof (output), &len));
210
+ TEST_ASSERT_EQUAL (PSA_ERROR_INVALID_HANDLE, psa_export_public_key (key_handle, output, sizeof (output), &len));
211
+
212
+ /* via test partition - destroy the key created by the test partition */
213
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_destroy_key (key_handle));
214
+
215
+ /* via test partition - create a key, set key policy but no key material */
216
+ key_handle = 0 ;
217
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_create_persistent_key (key_id, &key_handle));
218
+ TEST_ASSERT_NOT_EQUAL (0 , key_handle);
219
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_set_key_policy (key_handle, key_usage, key_alg));
220
+
221
+ /* try to import key data into the key that was created by the test partition */
222
+ TEST_ASSERT_EQUAL (PSA_ERROR_INVALID_HANDLE, psa_import_key (key_handle, key_type,
223
+ key_data, sizeof (key_data)));
224
+
225
+ /* via test partition - import key data for the key created by the test partition */
226
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_import_key (key_handle, key_type, key_data, sizeof (key_data)));
227
+
228
+ /* via test partition - close the key created by the test partition */
229
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_close_key (key_handle));
230
+ }
231
+
158
232
utest::v1::status_t case_setup_handler (const Case *const source, const size_t index_of_case)
159
233
{
160
234
psa_status_t status = mbed_psa_reboot_and_request_new_security_state (PSA_LIFECYCLE_ASSEMBLY_AND_TEST);
@@ -192,6 +266,8 @@ Case cases[] = {
192
266
case_setup_handler, test_open_other_partition_key, case_teardown_handler),
193
267
Case (" create key with same id different partitions" ,
194
268
case_setup_handler, test_create_key_same_id_different_partitions, case_teardown_handler),
269
+ Case (" use other partitions' key - key manage" ,
270
+ case_setup_handler, test_use_other_partition_key_manage_key, case_teardown_handler),
195
271
};
196
272
197
273
Specification specification (test_setup, cases);
0 commit comments