Skip to content

Commit a87c7c8

Browse files
author
Cruz Monrreal
authored
Merge pull request #9312 from kfnta/psa_compliance
PSA compliance tests suite
2 parents a00de86 + 4edb6da commit a87c7c8

File tree

322 files changed

+27342
-9
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

322 files changed

+27342
-9
lines changed

.astyleignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ components/802.15.4_RF
2424
components/wifi
2525
components/TARGET_PSA/TARGET_TFM
2626
tools
27+
components/TARGET_PSA/TESTS
2728
components/TARGET_PSA/services/attestation/COMPONENT_PSA_SRV_IMPL/tfm_impl
2829
components/TARGET_PSA/services/attestation/qcbor
29-
components/TARGET_PSA/services/attestation/attestation.h
30+
components/TARGET_PSA/services/attestation/attestation.h
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# PSA Initial Attestation Testcase checklist
2+
3+
| Test | Return value | API | Test Algorithm | Test Cases |
4+
|-----------|--------------------------------------|-------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
5+
| test_a001 | PSA_ATTEST_ERR_SUCCESS | psa_initial_attest_get_token()<br />psa_initial_attest_get_token_size() | 1. Provide correct inputs to API with described challenge sizes <br />2. Expect API to return this define as return value each time <br />3. Verify the token | 1. Challenge_size = 32 <br />2. Challenge_size = 48 <br />3. Challenge_size = 64 |
6+
| | PSA_ATTEST_ERR_INVALID_INPUT | psa_initial_attest_get_token()<br />psa_initial_attest_get_token_size() | 1. Provide described challenge sizes to the API along with other valid parameters <br />2. Expect API to return this define as return value each time | 1. Challenge_size is zero <br />2. Invalid challenge size between 0 and 32 <br />3. Invalid challenge size between 32 and 64 <br />4. Challenge_size is greater than MAX_CHALLENGE_SIZE |
7+
| | PSA_ATTEST_ERR_TOKEN_BUFFER_OVERFLOW | psa_initial_attest_get_token() | 1. Provide described taken size to the API along with other valid parameters <br />2. Expect API to return this define as return value each time | Pass the token_size which less than actual/required token size |
8+
| | PSA_ATTEST_ERR_INIT_FAILED | psa_initial_attest_get_token()<br />psa_initial_attest_get_token_size() | Can't simulate. Test can't generate stimulus where attestation initialisation fails | |
9+
| | PSA_ATTEST_ERR_CLAIM_UNAVAILABLE | psa_initial_attest_get_token() | Can't simulate. Test can't generate stimulus where claim can unavailable | |
10+
| | PSA_ATTEST_ERR_GENERAL | psa_initial_attest_get_token()<br />psa_initial_attest_get_token_size() | Can't simulate. Test can't generate stimulus where unexpected error happened during API operation | |
11+
12+
## Note
13+
14+
1. In verifying the token, only the data type of claims and presence of the mandatory claims are checked and the values of the claims are not checked.
15+
2. Checks related to token signature validation will be part of future release
16+
17+
# License
18+
Arm PSA test suite is distributed under Apache v2.0 License.
19+
20+
--------------
21+
22+
*Copyright (c) 2019, Arm Limited and Contributors. All rights reserved.*
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include "val_interfaces.h"
2+
#include "pal_mbed_os_intf.h"
3+
4+
void test_entry_a001(val_api_t *val_api, psa_api_t *psa_api);
5+
6+
int main(void)
7+
{
8+
test_start(test_entry_a001, COMPLIANCE_TEST_ATTESTATION);
9+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/** @file
2+
* Copyright (c) 2019, Arm Limited or its affiliates. All rights reserved.
3+
* SPDX-License-Identifier : Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
**/
17+
18+
#include "val_interfaces.h"
19+
#include "val_target.h"
20+
#include "test_a001.h"
21+
#include "test_data.h"
22+
23+
client_test_t test_a001_attestation_list[] = {
24+
NULL,
25+
psa_initial_attestation_get_token_test,
26+
psa_initial_attestation_get_token_size_test,
27+
NULL,
28+
};
29+
30+
static int g_test_count = 1;
31+
32+
int32_t psa_initial_attestation_get_token_test(security_t caller)
33+
{
34+
int num_checks = sizeof(check1)/sizeof(check1[0]);
35+
uint32_t i, status, token_size;
36+
uint8_t challenge[PSA_INITIAL_ATTEST_CHALLENGE_SIZE_64+1];
37+
uint8_t token_buffer[TOKEN_SIZE];
38+
39+
for (i = 0; i < num_checks; i++)
40+
{
41+
val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
42+
val->print(PRINT_TEST, check1[i].test_desc, 0);
43+
44+
memset(challenge, 0x2a, sizeof(challenge));
45+
memset(token_buffer, 0, sizeof(token_buffer));
46+
47+
status = val->attestation_function(VAL_INITIAL_ATTEST_GET_TOKEN_SIZE,
48+
check1[i].challenge_size, &token_size);
49+
if (status != PSA_SUCCESS)
50+
{
51+
if (check1[i].challenge_size != PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32 ||
52+
check1[i].challenge_size != PSA_INITIAL_ATTEST_CHALLENGE_SIZE_48 ||
53+
check1[i].challenge_size != PSA_INITIAL_ATTEST_CHALLENGE_SIZE_64)
54+
{
55+
token_size = check1[i].token_size;
56+
check1[i].challenge_size = check1[i].actual_challenge_size;
57+
}
58+
else
59+
return status;
60+
}
61+
62+
status = val->attestation_function(VAL_INITIAL_ATTEST_GET_TOKEN, challenge,
63+
check1[i].challenge_size, token_buffer, &token_size);
64+
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(1));
65+
66+
if (check1[i].expected_status != PSA_SUCCESS)
67+
continue;
68+
69+
/* Validate the token */
70+
status = val->attestation_function(VAL_INITIAL_ATTEST_VERIFY_TOKEN, challenge,
71+
check1[i].challenge_size, token_buffer, token_size);
72+
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(2));
73+
}
74+
75+
return VAL_STATUS_SUCCESS;
76+
}
77+
78+
int32_t psa_initial_attestation_get_token_size_test(security_t caller)
79+
{
80+
int num_checks = sizeof(check2)/sizeof(check2[0]);
81+
uint32_t i, status, token_size;
82+
83+
for (i = 0; i < num_checks; i++)
84+
{
85+
val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
86+
val->print(PRINT_TEST, check2[i].test_desc, 0);
87+
88+
status = val->attestation_function(VAL_INITIAL_ATTEST_GET_TOKEN_SIZE,
89+
check2[i].challenge_size, &token_size);
90+
91+
TEST_ASSERT_EQUAL(status, check2[i].expected_status, TEST_CHECKPOINT_NUM(1));
92+
93+
if (check2[i].expected_status != PSA_SUCCESS)
94+
continue;
95+
96+
if (token_size < check2[i].challenge_size)
97+
{
98+
val->print(PRINT_ERROR, "Token size less than challenge size\n", 0);
99+
return VAL_STATUS_INSUFFICIENT_SIZE;
100+
}
101+
}
102+
103+
return VAL_STATUS_SUCCESS;
104+
}
105+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/** @file
2+
* Copyright (c) 2019, Arm Limited or its affiliates. All rights reserved.
3+
* SPDX-License-Identifier : Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
**/
17+
#ifndef _TEST_A001_CLIENT_TESTS_H_
18+
#define _TEST_A001_CLIENT_TESTS_H_
19+
20+
#include "val_attestation.h"
21+
#define test_entry CONCAT(test_entry_, a001)
22+
#define val CONCAT(val,test_entry)
23+
#define psa CONCAT(psa,test_entry)
24+
25+
#define TOKEN_SIZE 512
26+
27+
extern val_api_t *val;
28+
extern psa_api_t *psa;
29+
extern client_test_t test_a001_attestation_list[];
30+
31+
int32_t psa_initial_attestation_get_token_test(security_t caller);
32+
int32_t psa_initial_attestation_get_token_size_test(security_t caller);
33+
#endif /* _TEST_A001_CLIENT_TESTS_H_ */
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/** @file
2+
* Copyright (c) 2019, Arm Limited or its affiliates. All rights reserved.
3+
* SPDX-License-Identifier : Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
**/
17+
18+
#include "val_attestation.h"
19+
20+
typedef struct {
21+
char test_desc[100];
22+
uint32_t challenge_size;
23+
uint32_t actual_challenge_size;
24+
uint32_t token_size;
25+
psa_status_t expected_status;
26+
} test_data;
27+
28+
29+
static test_data check1[] = {
30+
{"Test psa_initial_attestation_get_token with Challenge 32\n",
31+
PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32, PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32, TOKEN_SIZE, PSA_SUCCESS
32+
},
33+
34+
{"Test psa_initial_attestation_get_token with Challenge 48\n",
35+
PSA_INITIAL_ATTEST_CHALLENGE_SIZE_48, PSA_INITIAL_ATTEST_CHALLENGE_SIZE_48, TOKEN_SIZE, PSA_SUCCESS
36+
},
37+
38+
{"Test psa_initial_attestation_get_token with Challenge 64\n",
39+
PSA_INITIAL_ATTEST_CHALLENGE_SIZE_64, PSA_INITIAL_ATTEST_CHALLENGE_SIZE_64, TOKEN_SIZE, PSA_SUCCESS
40+
},
41+
42+
{"Test psa_initial_attestation_get_token with zero challenge size\n",
43+
0, 0, TOKEN_SIZE, PSA_ATTEST_ERR_INVALID_INPUT
44+
},
45+
46+
{"Test psa_initial_attestation_get_token with small challenge size\n",
47+
PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32-1, PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32-1,
48+
TOKEN_SIZE, PSA_ATTEST_ERR_INVALID_INPUT
49+
},
50+
51+
{"Test psa_initial_attestation_get_token with invalid challenge size\n",
52+
PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32+1, PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32+1,
53+
TOKEN_SIZE, PSA_ATTEST_ERR_INVALID_INPUT
54+
},
55+
56+
{"Test psa_initial_attestation_get_token with large challenge size\n",
57+
MAX_CHALLENGE_SIZE+1, MAX_CHALLENGE_SIZE+1, TOKEN_SIZE, PSA_ATTEST_ERR_INVALID_INPUT
58+
},
59+
60+
{"Test psa_initial_attestation_get_token with zero as token size\n",
61+
PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32-1, PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32,
62+
0, PSA_ATTEST_ERR_INVALID_INPUT
63+
},
64+
65+
{"Test psa_initial_attestation_get_token with small token size\n",
66+
PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32-1, PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32,
67+
PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32-1, PSA_ATTEST_ERR_TOKEN_BUFFER_OVERFLOW
68+
},
69+
};
70+
71+
static test_data check2[] = {
72+
{"Test psa_initial_attestation_get_token_size with Challenge 32\n",
73+
PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32, PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32, TOKEN_SIZE, PSA_SUCCESS
74+
},
75+
76+
{"Test psa_initial_attestation_get_token_size with Challenge 48\n",
77+
PSA_INITIAL_ATTEST_CHALLENGE_SIZE_48, PSA_INITIAL_ATTEST_CHALLENGE_SIZE_48, TOKEN_SIZE, PSA_SUCCESS
78+
},
79+
80+
{"Test psa_initial_attestation_get_token_size with Challenge 64\n",
81+
PSA_INITIAL_ATTEST_CHALLENGE_SIZE_64, PSA_INITIAL_ATTEST_CHALLENGE_SIZE_64, TOKEN_SIZE, PSA_SUCCESS
82+
},
83+
84+
{"Test psa_initial_attestation_get_token_size with zero challenge size\n",
85+
0, 0,
86+
TOKEN_SIZE, PSA_ATTEST_ERR_INVALID_INPUT
87+
},
88+
89+
{"Test psa_initial_attestation_get_token_size with small challenge size\n",
90+
PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32-1, PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32-1,
91+
TOKEN_SIZE, PSA_ATTEST_ERR_INVALID_INPUT
92+
},
93+
94+
{"Test psa_initial_attestation_get_token_size with invalid challenge size\n",
95+
PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32+1, PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32+1,
96+
TOKEN_SIZE, PSA_ATTEST_ERR_INVALID_INPUT
97+
},
98+
99+
{"Test psa_initial_attestation_get_token_size with large challenge size\n",
100+
MAX_CHALLENGE_SIZE+1, MAX_CHALLENGE_SIZE+1,
101+
TOKEN_SIZE, PSA_ATTEST_ERR_INVALID_INPUT
102+
},
103+
};
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/** @file
2+
* Copyright (c) 2019, Arm Limited or its affiliates. All rights reserved.
3+
* SPDX-License-Identifier : Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
**/
17+
18+
#include "val_interfaces.h"
19+
#include "val_target.h"
20+
#include "test_a001.h"
21+
22+
#define TEST_NUM VAL_CREATE_TEST_ID(VAL_INITIAL_ATTESTATION_BASE, 1)
23+
#define TEST_DESC "Testing initial attestation APIs\n"
24+
TEST_PUBLISH(TEST_NUM, test_entry);
25+
val_api_t *val = NULL;
26+
psa_api_t *psa = NULL;
27+
28+
void test_entry(val_api_t *val_api, psa_api_t *psa_api)
29+
{
30+
int32_t status = VAL_STATUS_SUCCESS;
31+
32+
val = val_api;
33+
psa = psa_api;
34+
35+
/* test init */
36+
val->test_init(TEST_NUM, TEST_DESC, TEST_FIELD(TEST_ISOLATION_L1, WD_HIGH_TIMEOUT));
37+
if (!IS_TEST_START(val->get_status()))
38+
{
39+
goto test_exit;
40+
}
41+
42+
/* Execute list of tests available in test[num]_attestation_list from Non-secure side*/
43+
status = val->execute_non_secure_tests(TEST_NUM, test_a001_attestation_list, FALSE);
44+
45+
if (VAL_ERROR(status))
46+
{
47+
goto test_exit;
48+
}
49+
50+
test_exit:
51+
val->test_exit();
52+
}

0 commit comments

Comments
 (0)