TF-M Reference Manual  1.2.0
TrustedFirmware-M
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
attest_asymmetric_ns_interface_testsuite.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #include "attest_ns_tests.h"
10 #include "attest.h"
11 #include "../attest_tests_common.h"
12 #include "../attest_token_test_values.h"
13 #include "../attest_token_test.h"
14 
15 static uint8_t token_buffer[TEST_TOKEN_SIZE];
16 static const uint8_t challenge_buffer[TEST_CHALLENGE_OBJ_SIZE] = {
18 
19 /* Define test suite for attestation service tests */
20 /* List of tests */
21 #ifdef INCLUDE_TEST_CODE /* Remove them from release build */
22 static void tfm_attest_test_2001(struct test_result_t *ret);
23 static void tfm_attest_test_2002(struct test_result_t *ret);
24 static void tfm_attest_test_2003(struct test_result_t *ret);
25 #endif
26 static void tfm_attest_test_2004(struct test_result_t *ret);
27 static void tfm_attest_test_2005(struct test_result_t *ret);
28 
29 static struct test_t attestation_interface_tests[] = {
30 #ifdef INCLUDE_TEST_CODE /* Remove them from release build */
31  {&tfm_attest_test_2001, "TFM_ATTEST_TEST_2001",
32  "Minimal token test of attest token", {TEST_PASSED} },
33  {&tfm_attest_test_2002, "TFM_ATTEST_TEST_2002",
34  "Minimal token size test of attest token", {TEST_PASSED} },
35  {&tfm_attest_test_2003, "TFM_ATTEST_TEST_2003",
36  "Short circuit signature test of attest token", {TEST_PASSED} },
37 #endif
38  {&tfm_attest_test_2004, "TFM_ATTEST_TEST_2004",
39  "ECDSA signature test of attest token", {TEST_PASSED} },
40  {&tfm_attest_test_2005, "TFM_ATTEST_TEST_2005",
41  "Negative test cases for initial attestation service", {TEST_PASSED} },
42 };
43 
44 void
46 {
47  uint32_t list_size;
48 
49  list_size = (sizeof(attestation_interface_tests) /
50  sizeof(attestation_interface_tests[0]));
51 
52  set_testsuite("Initial Attestation Service non-secure interface tests"
53  "(TFM_ATTEST_TEST_2XXX)",
54  attestation_interface_tests, list_size, p_test_suite);
55 }
56 
57 #ifdef INCLUDE_TEST_CODE /* Remove them from release build */
58 
66 static void tfm_attest_test_2001(struct test_result_t *ret)
67 {
68  int32_t err;
69 
70  err = minimal_test();
71  if (err != 0) {
72  TEST_LOG("minimal_test() returned: %d\r\n", err);
73  TEST_FAIL("Attest token minimal_test() has failed");
74  return;
75  }
76 
77  ret->val = TEST_PASSED;
78 }
79 
84 static void tfm_attest_test_2002(struct test_result_t *ret)
85 {
86  int32_t err;
87 
88  err = minimal_get_size_test();
89  if (err != 0) {
90  TEST_LOG("minimal_get_size_test() returned: %d\r\n", err);
91  TEST_FAIL("Attest token minimal_get_size_test() has failed");
92  return;
93  }
94 
95  ret->val = TEST_PASSED;
96 }
97 
105 static void tfm_attest_test_2003(struct test_result_t *ret)
106 {
107  int32_t err;
108 
110  if (err != 0) {
111  TEST_LOG("decode_test_short_circuit_sig() returned: %d\r\n", err);
112  TEST_FAIL("Attest token decode_test_short_circuit_sig() has failed");
113  return;
114  }
115 
116  ret->val = TEST_PASSED;
117 }
118 #endif /* INCLUDE_TEST_CODE */
119 
129 static void tfm_attest_test_2004(struct test_result_t *ret)
130 {
131  int32_t err;
132 
133  err = decode_test_normal_sig();
134  if (err != 0) {
135  TEST_LOG("decode_test_normal_sig() returned: %d\r\n", err);
136  TEST_FAIL("Attest token decode_test_normal_sig() has failed");
137  return;
138  }
139 
140  ret->val = TEST_PASSED;
141 }
142 
151 static void tfm_attest_test_2005(struct test_result_t *ret)
152 {
153  psa_status_t err;
154  size_t token_buf_size = TEST_TOKEN_SIZE;
155  size_t token_size;
156 
157  /* Call with with bigger challenge object than allowed */
158  err = psa_initial_attest_get_token(challenge_buffer,
160  token_buffer,
161  token_buf_size,
162  &token_size);
163 
164  if (err != PSA_ERROR_INVALID_ARGUMENT) {
165  TEST_FAIL("Attestation should fail with too big challenge object");
166  return;
167  }
168 
169  /* Call with smaller buffer size than size of test token */
170  token_buf_size = TOO_SMALL_TOKEN_BUFFER;
171  err = psa_initial_attest_get_token(challenge_buffer,
173  token_buffer,
174  token_buf_size,
175  &token_size);
176 
177  if (err != PSA_ERROR_BUFFER_TOO_SMALL) {
178  TEST_FAIL("Attestation should fail with too small token buffer");
179  return;
180  }
181 
182  ret->val = TEST_PASSED;
183 }
int_fast16_t decode_test_short_circuit_sig(void)
Test by checking short-circuit signed values of claims.
#define PSA_ERROR_BUFFER_TOO_SMALL
Definition: crypto_values.h:77
#define TEST_FAIL(info_msg)
enum test_suite_err_t set_testsuite(const char *name, struct test_t *test_list, uint32_t size, struct test_suite_t *p_ts)
Sets test suite parameters.
#define INVALID_CHALLENGE_OBJECT_SIZE
Size of challenge object that is invalid.
#define TOKEN_TEST_NONCE_BYTES
int_fast16_t minimal_get_size_test(void)
Test token size calculation.
#define PSA_ERROR_INVALID_ARGUMENT
#define TEST_CHALLENGE_OBJ_SIZE
Size of challenge object in bytes used for test.
struct test_result_t ret
#define TEST_TOKEN_SIZE
Size of token buffer in bytes.
void register_testsuite_ns_attestation_interface(struct test_suite_t *p_test_suite)
Register testsuite for the initial attestation service.
int_fast16_t minimal_test(void)
Minimal token creation test using a short-circuit signature.
#define TOO_SMALL_TOKEN_BUFFER
Smaller buffer size which is not big enough to store the created token by attestation service...
psa_status_t psa_initial_attest_get_token(const uint8_t *auth_challenge, size_t challenge_size, uint8_t *token_buf, size_t token_buf_size, size_t *token_size)
Get initial attestation token.
#define TEST_LOG(...)
enum test_status_t val
int_fast16_t decode_test_normal_sig(void)
Test by checking signed values of claims.
int32_t psa_status_t
Function return status.
Definition: crypto_types.h:43