Skip to content

Commit befed11

Browse files
author
Cruz Monrreal
authored
Merge pull request #9668 from moranpeker/psa-init-attestation
PSA Initial Attestation service
2 parents e393c2d + 83d084a commit befed11

File tree

74 files changed

+21051
-22
lines changed

Some content is hidden

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

74 files changed

+21051
-22
lines changed

.astyleignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ components/802.15.4_RF
2424
components/wifi
2525
components/TARGET_PSA/TARGET_TFM
2626
tools
27+
components/TARGET_PSA/services/attestation/COMPONENT_PSA_SRV_IMPL/tfm_impl
28+
components/TARGET_PSA/services/attestation/qcbor
29+
components/TARGET_PSA/services/attestation/attestation.h

LICENSE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Folders containing files under different permissive license than Apache 2.0 are
66
- [cmsis](./cmsis) - MIT, BSD-3-Clause
77
- [components/802.15.4_RF/mcr20a-rf-driver](./components/802.15.4_RF/mcr20a-rf-driver) - BSD-3-Clause
88
- [components/TARGET_PSA/TARGET_TFM](./components/TARGET_PSA/TARGET_TFM) - BSD-3-Clause
9+
- [components/TARGET_PSA/TARGET_PSA/services/attestation](./components/TARGET_PSA/services/attestation) - BSD-3-Clause
910
- [features/cryptocell/FEATURE_CRYPTOCELL310](./features/cryptocell/FEATURE_CRYPTOCELL310) - ARM Object Code and Header Files License
1011
- [features/FEATURE_BOOTLOADER](./features/FEATURE_BOOTLOADER) - PBL
1112
- [features/FEATURE_BLE/targets](./features/FEATURE_BLE/targets) - BSD-style, PBL, MIT-style

TESTS/psa/attestation/main.cpp

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
/*
2+
* Copyright (c) 2019 ARM Limited. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the License); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
14+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#if ((!defined(TARGET_PSA)) || (!defined(MBEDTLS_PSA_CRYPTO_C)))
20+
#error [NOT_SUPPORTED] Mbed Crypto is OFF - skipping.
21+
#endif // TARGET_PSA
22+
23+
#include "greentea-client/test_env.h"
24+
#include "unity/unity.h"
25+
#include "utest/utest.h"
26+
#include "psa_initial_attestation_api.h"
27+
#include "psa_attest_inject_key.h"
28+
#include <string.h>
29+
#include <stdlib.h>
30+
31+
#include "entropy.h"
32+
#include "entropy_poll.h"
33+
34+
/* MAX value support macro */
35+
#if !defined(MAX)
36+
#define MAX(a,b) (((a)>(b))?(a):(b))
37+
#endif
38+
39+
#define MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE \
40+
MAX(MBEDTLS_ENTROPY_MIN_PLATFORM, MBEDTLS_ENTROPY_BLOCK_SIZE)
41+
42+
using namespace utest::v1;
43+
44+
utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
45+
{
46+
#ifndef NO_GREENTEA
47+
GREENTEA_SETUP(60, "default_auto");
48+
#endif
49+
return greentea_test_setup_handler(number_of_cases);
50+
}
51+
52+
#define PSA_ATTESTATION_PRIVATE_KEY_ID 17
53+
54+
static const uint8_t private_key_data[] = {
55+
0x49, 0xc9, 0xa8, 0xc1, 0x8c, 0x4b, 0x88, 0x56,
56+
0x38, 0xc4, 0x31, 0xcf, 0x1d, 0xf1, 0xc9, 0x94,
57+
0x13, 0x16, 0x09, 0xb5, 0x80, 0xd4, 0xfd, 0x43,
58+
0xa0, 0xca, 0xb1, 0x7d, 0xb2, 0xf1, 0x3e, 0xee
59+
};
60+
61+
static const uint8_t public_key_data[] = {
62+
0x04, 0x77, 0x72, 0x65, 0x6f, 0x81, 0x4b, 0x39,
63+
0x92, 0x79, 0xd5, 0xe1, 0xf1, 0x78, 0x1f, 0xac,
64+
0x6f, 0x09, 0x9a, 0x3c, 0x5c, 0xa1, 0xb0, 0xe3,
65+
0x53, 0x51, 0x83, 0x4b, 0x08, 0xb6, 0x5e, 0x0b,
66+
0x57, 0x25, 0x90, 0xcd, 0xaf, 0x8f, 0x76, 0x93,
67+
0x61, 0xbc, 0xf3, 0x4a, 0xcf, 0xc1, 0x1e, 0x5e,
68+
0x07, 0x4e, 0x84, 0x26, 0xbd, 0xde, 0x04, 0xbe,
69+
0x6e, 0x65, 0x39, 0x45, 0x44, 0x96, 0x17, 0xde,
70+
0x45
71+
};
72+
73+
#define TEST_TOKEN_SIZE (0x200)
74+
#define TEST_CHALLENGE_OBJ_SIZE (32u)
75+
76+
#define CHALLENGE_FOR_TEST 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, \
77+
0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, \
78+
0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, \
79+
0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF
80+
81+
static uint8_t token_buffer[TEST_TOKEN_SIZE];
82+
static uint8_t challenge_buffer[TEST_CHALLENGE_OBJ_SIZE] = {CHALLENGE_FOR_TEST};
83+
84+
static void check_initial_attestation_get_token()
85+
{
86+
psa_status_t status = PSA_SUCCESS;
87+
size_t exported_length;
88+
uint8_t exported[sizeof(public_key_data)];
89+
enum psa_attest_err_t attest_err = PSA_ATTEST_ERR_SUCCESS;
90+
uint32_t token_size;
91+
92+
status = psa_crypto_init();
93+
TEST_ASSERT_EQUAL(status, PSA_SUCCESS);
94+
status = psa_attestation_inject_key(private_key_data,
95+
sizeof(private_key_data),
96+
PSA_KEY_TYPE_ECC_KEYPAIR(PSA_ECC_CURVE_SECP256R1),
97+
exported,
98+
sizeof(exported),
99+
&exported_length);
100+
101+
TEST_ASSERT_EQUAL(status, PSA_SUCCESS);
102+
TEST_ASSERT_EQUAL(sizeof(public_key_data), exported_length);
103+
TEST_ASSERT_EQUAL(memcmp(public_key_data, exported, exported_length), 0);
104+
105+
attest_err = psa_initial_attest_get_token_size(TEST_CHALLENGE_OBJ_SIZE,
106+
&token_size);
107+
108+
TEST_ASSERT_EQUAL(attest_err, PSA_ATTEST_ERR_SUCCESS);
109+
110+
attest_err = psa_initial_attest_get_token(challenge_buffer,
111+
TEST_CHALLENGE_OBJ_SIZE,
112+
token_buffer,
113+
&token_size);
114+
115+
TEST_ASSERT_EQUAL(attest_err, PSA_ATTEST_ERR_SUCCESS);
116+
}
117+
/***************************************************************************************/
118+
119+
utest::v1::status_t case_teardown_handler(const Case *const source, const size_t passed, const size_t failed, const failure_t reason)
120+
{
121+
const psa_key_id_t key_id = PSA_ATTESTATION_PRIVATE_KEY_ID;
122+
psa_key_handle_t handle = 0;
123+
psa_open_key(PSA_KEY_LIFETIME_PERSISTENT, key_id, &handle);
124+
psa_destroy_key(handle);
125+
mbedtls_psa_crypto_free();
126+
return greentea_case_teardown_handler(source, passed, failed, reason);
127+
}
128+
129+
utest::v1::status_t case_setup_handler(const Case *const source, const size_t index_of_case)
130+
{
131+
return greentea_case_setup_handler(source, index_of_case);
132+
}
133+
134+
Case cases[] = {
135+
Case("PSA attestation get token", check_initial_attestation_get_token, case_teardown_handler),
136+
};
137+
138+
Specification specification(greentea_test_setup, cases);
139+
140+
int main()
141+
{
142+
#if (defined(COMPONENT_PSA_SRV_IPC) || defined(MBEDTLS_ENTROPY_NV_SEED))
143+
uint8_t seed[MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE] = {0};
144+
/* inject some seed for test*/
145+
for (int i = 0; i < MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE; ++i) {
146+
seed[i] = i;
147+
}
148+
149+
/* don't really care if this succeeds this is just to make crypto init pass*/
150+
mbedtls_psa_inject_entropy(seed, MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE);
151+
#endif
152+
return !Harness::run(specification);
153+
}

TESTS/psa/spm_client/COMPONENT_SPE/psa_setup.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@
2828
#include "handles_manager.h"
2929
#include "cmsis.h"
3030
#include "psa_client_tests_part1_partition.h"
31+
#include "psa_attest_srv_partition.h"
3132
#include "psa_crypto_srv_partition.h"
3233
#include "psa_platform_partition.h"
3334
#include "psa_its_partition.h"
3435

36+
extern const uint32_t attest_srv_external_sids[7];
3537
extern const uint32_t crypto_srv_external_sids[4];
3638
extern const uint32_t platform_external_sids[1];
3739

38-
spm_partition_t g_partitions[4] = {
40+
spm_partition_t g_partitions[5] = {
3941
{
4042
.partition_id = CLIENT_TESTS_PART1_ID,
4143
.thread_id = 0,
@@ -47,6 +49,17 @@ spm_partition_t g_partitions[4] = {
4749
.extern_sids_count = CLIENT_TESTS_PART1_EXT_ROT_SRV_COUNT,
4850
.irq_mapper = NULL,
4951
},
52+
{
53+
.partition_id = ATTEST_SRV_ID,
54+
.thread_id = 0,
55+
.flags_rot_srv = ATTEST_SRV_WAIT_ANY_SID_MSK,
56+
.flags_interrupts = 0,
57+
.rot_services = NULL,
58+
.rot_services_count = ATTEST_SRV_ROT_SRV_COUNT,
59+
.extern_sids = attest_srv_external_sids,
60+
.extern_sids_count = ATTEST_SRV_EXT_ROT_SRV_COUNT,
61+
.irq_mapper = NULL,
62+
},
5063
{
5164
.partition_id = CRYPTO_SRV_ID,
5265
.thread_id = 0,
@@ -91,6 +104,7 @@ const uint32_t mem_region_count = 0;
91104

92105
// forward declaration of partition initializers
93106
void client_tests_part1_init(spm_partition_t *partition);
107+
void attest_srv_init(spm_partition_t *partition);
94108
void crypto_srv_init(spm_partition_t *partition);
95109
void platform_init(spm_partition_t *partition);
96110
void its_init(spm_partition_t *partition);
@@ -102,11 +116,12 @@ uint32_t init_partitions(spm_partition_t **partitions)
102116
}
103117

104118
client_tests_part1_init(&(g_partitions[0]));
105-
crypto_srv_init(&(g_partitions[1]));
106-
platform_init(&(g_partitions[2]));
107-
its_init(&(g_partitions[3]));
119+
attest_srv_init(&(g_partitions[1]));
120+
crypto_srv_init(&(g_partitions[2]));
121+
platform_init(&(g_partitions[3]));
122+
its_init(&(g_partitions[4]));
108123

109124
*partitions = g_partitions;
110-
return 4;
125+
return 5;
111126
}
112127

TESTS/psa/spm_server/COMPONENT_SPE/psa_setup.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,17 @@
2929
#include "cmsis.h"
3030
#include "psa_server_test_part1_partition.h"
3131
#include "psa_server_test_part2_partition.h"
32+
#include "psa_attest_srv_partition.h"
3233
#include "psa_crypto_srv_partition.h"
3334
#include "psa_platform_partition.h"
3435
#include "psa_its_partition.h"
3536

3637
extern const uint32_t server_test_part1_external_sids[2];
38+
extern const uint32_t attest_srv_external_sids[7];
3739
extern const uint32_t crypto_srv_external_sids[4];
3840
extern const uint32_t platform_external_sids[1];
3941

40-
spm_partition_t g_partitions[5] = {
42+
spm_partition_t g_partitions[6] = {
4143
{
4244
.partition_id = SERVER_TEST_PART1_ID,
4345
.thread_id = 0,
@@ -60,6 +62,17 @@ spm_partition_t g_partitions[5] = {
6062
.extern_sids_count = SERVER_TEST_PART2_EXT_ROT_SRV_COUNT,
6163
.irq_mapper = NULL,
6264
},
65+
{
66+
.partition_id = ATTEST_SRV_ID,
67+
.thread_id = 0,
68+
.flags_rot_srv = ATTEST_SRV_WAIT_ANY_SID_MSK,
69+
.flags_interrupts = 0,
70+
.rot_services = NULL,
71+
.rot_services_count = ATTEST_SRV_ROT_SRV_COUNT,
72+
.extern_sids = attest_srv_external_sids,
73+
.extern_sids_count = ATTEST_SRV_EXT_ROT_SRV_COUNT,
74+
.irq_mapper = NULL,
75+
},
6376
{
6477
.partition_id = CRYPTO_SRV_ID,
6578
.thread_id = 0,
@@ -105,6 +118,7 @@ const uint32_t mem_region_count = 0;
105118
// forward declaration of partition initializers
106119
void server_test_part1_init(spm_partition_t *partition);
107120
void server_test_part2_init(spm_partition_t *partition);
121+
void attest_srv_init(spm_partition_t *partition);
108122
void crypto_srv_init(spm_partition_t *partition);
109123
void platform_init(spm_partition_t *partition);
110124
void its_init(spm_partition_t *partition);
@@ -117,11 +131,12 @@ uint32_t init_partitions(spm_partition_t **partitions)
117131

118132
server_test_part1_init(&(g_partitions[0]));
119133
server_test_part2_init(&(g_partitions[1]));
120-
crypto_srv_init(&(g_partitions[2]));
121-
platform_init(&(g_partitions[3]));
122-
its_init(&(g_partitions[4]));
134+
attest_srv_init(&(g_partitions[2]));
135+
crypto_srv_init(&(g_partitions[3]));
136+
platform_init(&(g_partitions[4]));
137+
its_init(&(g_partitions[5]));
123138

124139
*partitions = g_partitions;
125-
return 5;
140+
return 6;
126141
}
127142

TESTS/psa/spm_smoke/COMPONENT_SPE/psa_setup.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@
2828
#include "handles_manager.h"
2929
#include "cmsis.h"
3030
#include "psa_smoke_test_part1_partition.h"
31+
#include "psa_attest_srv_partition.h"
3132
#include "psa_crypto_srv_partition.h"
3233
#include "psa_platform_partition.h"
3334
#include "psa_its_partition.h"
3435

36+
extern const uint32_t attest_srv_external_sids[7];
3537
extern const uint32_t crypto_srv_external_sids[4];
3638
extern const uint32_t platform_external_sids[1];
3739

38-
spm_partition_t g_partitions[4] = {
40+
spm_partition_t g_partitions[5] = {
3941
{
4042
.partition_id = SMOKE_TEST_PART1_ID,
4143
.thread_id = 0,
@@ -47,6 +49,17 @@ spm_partition_t g_partitions[4] = {
4749
.extern_sids_count = SMOKE_TEST_PART1_EXT_ROT_SRV_COUNT,
4850
.irq_mapper = NULL,
4951
},
52+
{
53+
.partition_id = ATTEST_SRV_ID,
54+
.thread_id = 0,
55+
.flags_rot_srv = ATTEST_SRV_WAIT_ANY_SID_MSK,
56+
.flags_interrupts = 0,
57+
.rot_services = NULL,
58+
.rot_services_count = ATTEST_SRV_ROT_SRV_COUNT,
59+
.extern_sids = attest_srv_external_sids,
60+
.extern_sids_count = ATTEST_SRV_EXT_ROT_SRV_COUNT,
61+
.irq_mapper = NULL,
62+
},
5063
{
5164
.partition_id = CRYPTO_SRV_ID,
5265
.thread_id = 0,
@@ -91,6 +104,7 @@ const uint32_t mem_region_count = 0;
91104

92105
// forward declaration of partition initializers
93106
void smoke_test_part1_init(spm_partition_t *partition);
107+
void attest_srv_init(spm_partition_t *partition);
94108
void crypto_srv_init(spm_partition_t *partition);
95109
void platform_init(spm_partition_t *partition);
96110
void its_init(spm_partition_t *partition);
@@ -102,11 +116,12 @@ uint32_t init_partitions(spm_partition_t **partitions)
102116
}
103117

104118
smoke_test_part1_init(&(g_partitions[0]));
105-
crypto_srv_init(&(g_partitions[1]));
106-
platform_init(&(g_partitions[2]));
107-
its_init(&(g_partitions[3]));
119+
attest_srv_init(&(g_partitions[1]));
120+
crypto_srv_init(&(g_partitions[2]));
121+
platform_init(&(g_partitions[3]));
122+
its_init(&(g_partitions[4]));
108123

109124
*partitions = g_partitions;
110-
return 4;
125+
return 5;
111126
}
112127

0 commit comments

Comments
 (0)