Skip to content

Commit 9adda5b

Browse files
author
itayzafrir
committed
Add acl test - open other partitions' key
1 parent 2146e74 commit 9adda5b

File tree

1 file changed

+36
-1
lines changed
  • TESTS/psa/crypto_access_control/COMPONENT_NSPE

1 file changed

+36
-1
lines changed

TESTS/psa/crypto_access_control/COMPONENT_NSPE/main.cpp

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,34 @@ void inject_entropy()
5151
}
5252
#endif // defined(MBEDTLS_ENTROPY_NV_SEED) || defined(COMPONENT_PSA_SRV_IPC)
5353

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+
5482
utest::v1::status_t case_setup_handler(const Case *const source, const size_t index_of_case)
5583
{
5684
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)
83111
return verbose_test_setup_handler(number_of_cases);
84112
}
85113

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+
86121
int main(void)
87122
{
88-
return (1);
123+
return !Harness::run(specification);
89124
}

0 commit comments

Comments
 (0)