blob: 9c0c162422428ca94e8b9894476a50a3eb20ea1e [file] [log] [blame]
Tamas Ban6dfa6eb2018-08-17 12:02:51 +01001/*
Tamas Ban52d4a8e2019-01-04 22:45:39 +00002 * Copyright (c) 2018-2019, Arm Limited. All rights reserved.
Tamas Ban6dfa6eb2018-08-17 12:02:51 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8/***************************************************************************/
9/* DRAFT UNDER REVIEW */
10/* These APIs are still evolving and are meant as a prototype for review.*/
11/* The APIs will change depending on feedback and will be firmed up */
12/* to a stable set of APIs once all the feedback has been considered. */
13/***************************************************************************/
14
15#ifndef __PSA_INITIAL_ATTESTATION_API_H__
16#define __PSA_INITIAL_ATTESTATION_API_H__
17
18#include "tfm_api.h"
19#include <limits.h>
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25/**
26 * \brief PSA INITIAL ATTESTATION API version
27 */
28#define PSA_INITIAL_ATTEST_API_VERSION_MAJOR (0)
29#define PSA_INITIAL_ATTEST_API_VERSION_MINOR (1)
30
31/* The return value is shared with the TFM partition status value. The ATTEST
32 * return codes shouldn't overlap with predefined TFM status values.
33 */
34#define PSA_ATTEST_ERR_OFFSET (TFM_PARTITION_SPECIFIC_ERROR_MIN)
35
36/**
37 * \enum psa_attest_err_t
38 *
39 * \brief Initial attestation service error types
40 *
41 */
42enum psa_attest_err_t {
Tamas Ban52d4a8e2019-01-04 22:45:39 +000043 /** Action was performed successfully */
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010044 PSA_ATTEST_ERR_SUCCESS = 0,
Tamas Ban52d4a8e2019-01-04 22:45:39 +000045 /** Boot status data is unavailable or malformed */
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010046 PSA_ATTEST_ERR_INIT_FAILED = PSA_ATTEST_ERR_OFFSET,
Tamas Ban52d4a8e2019-01-04 22:45:39 +000047 /** Token buffer is too small to store the created token there */
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010048 PSA_ATTEST_ERR_TOKEN_BUFFER_OVERFLOW,
Tamas Ban52d4a8e2019-01-04 22:45:39 +000049 /** Some of the mandatory claims are unavailable*/
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010050 PSA_ATTEST_ERR_CLAIM_UNAVAILABLE,
Tamas Ban52d4a8e2019-01-04 22:45:39 +000051 /** Some parameter or combination of parameters are recognised as invalid:
52 * - challenge size is not allowed
53 * - challenge object is unavailable
54 * - token buffer is unavailable
55 */
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010056 PSA_ATTEST_ERR_INVALID_INPUT,
Tamas Ban52d4a8e2019-01-04 22:45:39 +000057 /** Unexpected error happened during operation */
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010058 PSA_ATTEST_ERR_GENERAL,
Tamas Ban52d4a8e2019-01-04 22:45:39 +000059 /** Following entry is only to ensure the error code of integer size */
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010060 PSA_ATTEST_ERR_FORCE_INT_SIZE = INT_MAX
61};
62
63/**
Tamas Ban52d4a8e2019-01-04 22:45:39 +000064 * The allowed size of input challenge in bytes: 32, 48, 64
65 * Challenge can be a nonce from server
66 * or the hash of some combined data : nonce + attested data by caller.
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010067 */
Tamas Ban52d4a8e2019-01-04 22:45:39 +000068#define PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32 (32u)
69#define PSA_INITIAL_ATTEST_CHALLENGE_SIZE_48 (48u)
70#define PSA_INITIAL_ATTEST_CHALLENGE_SIZE_64 (64u)
71
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010072#define PSA_INITIAL_ATTEST_MAX_CHALLENGE_SIZE (64u)
73
74/**
75 * The list of fixed claims in the initial attestation token is still evolving,
76 * you can expect slight changes in the future.
77 *
Tamas Ban52d4a8e2019-01-04 22:45:39 +000078 * The initial attestation token is planned to be aligned with future version of
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010079 * Entity Attestation Token format:
Tamas Ban52d4a8e2019-01-04 22:45:39 +000080 * https://tools.ietf.org/html/draft-mandyam-eat-01
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010081 *
82 * Current list of claims:
Tamas Ban52d4a8e2019-01-04 22:45:39 +000083 * - Challenge: Input object from caller. Can be a single nonce from server
84 * or hash of nonce and attested data. It is intended to provide
85 * freshness to reports and the caller has responsibility to
86 * arrange this. Allowed length: 32, 48, 64 bytes. The claim is
87 * modeled to be eventually represented by the EAT standard
88 * claim nonce. Until such a time as that standard exists,
89 * the claim will be represented by a custom claim. Value
90 * is encoded as byte string.
91 *
92 * - Instance ID: It represents the unique identifier of the instance. In the
93 * PSA definition it is a hash of the public attestation key
94 * of the instance. The claim is modeled to be eventually
95 * represented by the EAT standard claim UEID of type GUID.
96 * Until such a time as that standard exists, the claim will be
97 * represented by a custom claim Value is encoded as byte
98 * string.
99 *
100 * - Verification service indicator: Optional, recommended claim. It is used by
101 * a Relying Party to locate a validation service for the token.
102 * The value is a text string that can be used to locate the
103 * service or a URL specifying the address of the service. The
104 * claim is modeled to be eventually represented by the EAT
105 * standard claim origination. Until such a time as that
106 * standard exists, the claim will be represented by a custom
107 * claim. Value is encoded as text string.
108 *
109 * - Profile definition: Optional, recommended claim. It contains the name of
110 * a document that describes the 'profile' of the token, being
111 * a full description of the claims, their usage, verification
112 * and token signing. The document name may include versioning.
113 * Custom claim with a value encoded as text string.
114 *
115 * - Implementation ID: It represents the original implementation signer of the
116 * attestation key and identifies the contract between the
117 * report and verification. A verification service will use this
118 * claim to locate the details of the verification process.
119 * Custom claim with a value encoded as byte string.
120 *
121 * - Security lifecycle: It represents the current lifecycle state of the
122 * instance. Custom claim with a value encoded as integer that
123 * is divided to convey a major state and a minor state. The
124 * PSA state and implementation state are encoded as follows:
125 * - version[15:8] - PSA lifecycle state - major
126 * - version[7:0] - IMPLEMENTATION DEFINED state - minor
127 * Possible PSA lifecycle states:
128 * - Unknown (0x1000u),
129 * - PSA_RoT_Provisioning (0x2000u),
130 * - Secured (0x3000u),
131 * - Non_PSA_RoT_Debug(0x4000u),
132 * - Recoverable_PSA_RoT_Debug (0x5000u),
133 * - Decommissioned (0x6000u)
134 *
135 * - Client ID: The partition ID of that secure partition or non-secure
136 * thread who called the initial attestation API. Custom claim
137 * with a value encoded as a *signed* integer. Negative number
138 * represents non-secure caller, positive numbers represents
139 * secure callers, zero is invalid.
140 *
141 * - HW version: Optional claim. Globally unique number in EAN-13 format
142 * identifying the GDSII that went to fabrication, HW and ROM.
143 * It can be used to reference the security level of the PSA-ROT
144 * via a certification website. Custom claim with a value is
145 * encoded as text string.
146
147 * - Boot seed: It represents a random value created at system boot time that
148 * will allow differentiation of reports from different system
149 * sessions. The size is 32 bytes. Custom claim with a value is
150 * encoded as byte string.
151 *
152 * - Software components: Recommended claim. It represents the software state
153 * of the system. The value of the claim is an array of CBOR map
154 * entries, with one entry per software component within the
155 * device. Each map contains multiple claims that describe
156 * evidence about the details of the software component.
157 *
158 * - Measurement type: Optional claim. It represents the role of the
159 * software component. Value is encoded as short(!) text
160 * string.
161 *
162 * - Measurement value: It represents a hash of the invariant software
163 * component in memory at start-up time. The value must be a
164 * cryptographic hash of 256 bits or stronger.Value is
165 * encoded as byte string.
166 *
167 * - Security epoch: Optional claim. It represents the security control
168 * point of the software component. Value is encoded as
169 * unsigned integer.
170 *
171 * - Version: Optional claim. It represents the issued software version.
172 * Value is encoded as text string.
173 *
174 * - Signer ID: It represents the hash of a signing authority public key.
175 * Value is encoded as byte string.
176 *
177 * - Measurement description: Optional claim. It represents the way in which
178 * the measurement value of the software component is
179 * computed. Value is encoded as text string containing an
180 * abbreviated description (name) of the measurement method.
181 *
182 * - No software measurements: In the event that the implementation does not
183 * contain any software measurements then the software
184 * components claim above can be omitted but instead
185 * it is mandatory to include this claim to indicate this is a
186 * deliberate state. Custom claim a value is encoded as unsigned
187 * integer set to 1.
Tamas Ban6dfa6eb2018-08-17 12:02:51 +0100188 */
189
190/**
191 * Calculated based on:
192 * - COSE header
193 * - Algorithm identifier
194 * - Key ID
Tamas Ban52d4a8e2019-01-04 22:45:39 +0000195 * - Claims in initial attestation token
Tamas Ban6dfa6eb2018-08-17 12:02:51 +0100196 * - COSE Signature
197 *
198 * This size (in bytes) is a maximum value, actual token size can be smaller.
199 */
200/* FixMe: Just initial value it must be updated if claims are fixed */
201#define PSA_INITIAL_ATTEST_TOKEN_SIZE (512u)
202
203/**
204 * \brief Get initial attestation token
205 *
206 * \param[in] challenge_obj Pointer to buffer where challenge input is
207 * stored. Nonce and / or hash of attested data.
208 * Must be always
209 * \ref PSA_INITIAL_ATTEST_CHALLENGE_SIZE bytes
210 * long.
211 * \param[in] challenge_size Size of challenge object in bytes.
212 * \param[out] token Pointer to the buffer where attestation token
213 * must be stored.
214 * \param[in/out] token_size Size of allocated buffer for token, which
215 * updated by initial attestation service with
216 * final token size.
217 *
218 * \return Returns error code as specified in \ref psa_attest_err_t
219 */
220enum psa_attest_err_t
221psa_initial_attest_get_token(const uint8_t *challenge_obj,
222 uint32_t challenge_size,
223 uint8_t *token,
224 uint32_t *token_size);
225
Tamas Ban52d4a8e2019-01-04 22:45:39 +0000226/**
227 * \brief Get the exact size of initial attestation token in bytes.
228 *
229 * It just returns with the size of the IAT token. It can be used if the caller
230 * dynamically allocates memory for the token buffer.
231 *
232 * \param[in] challenge_size Size of challenge object in bytes.
233 * \param[out] token_size Size of the token in bytes, which is created by
234 * initial attestation service.
235 *
236 * \return Returns error code as specified in \ref psa_attest_err_t
237 */
238enum psa_attest_err_t
239psa_initial_attest_get_token_size(uint32_t challenge_size,
240 uint32_t *token_size);
241
Tamas Ban6dfa6eb2018-08-17 12:02:51 +0100242#ifdef __cplusplus
243}
244#endif
245
246#endif /* __PSA_INITIAL_ATTESTATION_API_H__ */