blob: 4dd247bbc2cbdcc46723e76cd34d3b93ec1c6f56 [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
Jamie Foxcc31d402019-01-28 17:13:52 +000015#ifndef __PSA_INITIAL_ATTESTATION_H__
16#define __PSA_INITIAL_ATTESTATION_H__
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010017
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010018#include <limits.h>
Tamas Baneccae9d2019-01-09 15:54:56 +000019#include <stdint.h>
David Vincze20c3e4e2019-11-11 11:16:06 +010020#include <stddef.h>
21#include "psa/crypto.h"
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010022
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27/**
28 * \brief PSA INITIAL ATTESTATION API version
Tamas Ban8bdd4582019-02-18 10:57:31 +000029 *
30 * Initial attestation API version is: 1.0-beta-0
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010031 */
Tamas Ban8bdd4582019-02-18 10:57:31 +000032#define PSA_INITIAL_ATTEST_API_VERSION_MAJOR (1)
33#define PSA_INITIAL_ATTEST_API_VERSION_MINOR (0)
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010034
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010035/**
36 * \enum psa_attest_err_t
37 *
38 * \brief Initial attestation service error types
39 *
40 */
41enum psa_attest_err_t {
Tamas Ban52d4a8e2019-01-04 22:45:39 +000042 /** Action was performed successfully */
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010043 PSA_ATTEST_ERR_SUCCESS = 0,
Tamas Ban52d4a8e2019-01-04 22:45:39 +000044 /** Boot status data is unavailable or malformed */
Tamas Baneccae9d2019-01-09 15:54:56 +000045 PSA_ATTEST_ERR_INIT_FAILED,
Tamas Ban52d4a8e2019-01-04 22:45:39 +000046 /** Token buffer is too small to store the created token there */
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010047 PSA_ATTEST_ERR_TOKEN_BUFFER_OVERFLOW,
David Vinczeff6da532019-11-21 00:19:50 +010048 /** Attestation key buffer is too small to store the obtained key there */
49 PSA_ATTEST_ERR_KEY_BUFFER_OVERFLOW,
50 /** Some of the mandatory claims are unavailable */
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010051 PSA_ATTEST_ERR_CLAIM_UNAVAILABLE,
Tamas Ban52d4a8e2019-01-04 22:45:39 +000052 /** Some parameter or combination of parameters are recognised as invalid:
53 * - challenge size is not allowed
54 * - challenge object is unavailable
55 * - token buffer is unavailable
56 */
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010057 PSA_ATTEST_ERR_INVALID_INPUT,
Tamas Ban52d4a8e2019-01-04 22:45:39 +000058 /** Unexpected error happened during operation */
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010059 PSA_ATTEST_ERR_GENERAL,
Tamas Ban52d4a8e2019-01-04 22:45:39 +000060 /** Following entry is only to ensure the error code of integer size */
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010061 PSA_ATTEST_ERR_FORCE_INT_SIZE = INT_MAX
62};
63
64/**
Tamas Ban52d4a8e2019-01-04 22:45:39 +000065 * The allowed size of input challenge in bytes: 32, 48, 64
66 * Challenge can be a nonce from server
67 * or the hash of some combined data : nonce + attested data by caller.
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010068 */
Tamas Ban52d4a8e2019-01-04 22:45:39 +000069#define PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32 (32u)
70#define PSA_INITIAL_ATTEST_CHALLENGE_SIZE_48 (48u)
71#define PSA_INITIAL_ATTEST_CHALLENGE_SIZE_64 (64u)
72
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010073/**
74 * The list of fixed claims in the initial attestation token is still evolving,
75 * you can expect slight changes in the future.
76 *
Tamas Ban52d4a8e2019-01-04 22:45:39 +000077 * The initial attestation token is planned to be aligned with future version of
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010078 * Entity Attestation Token format:
Tamas Ban52d4a8e2019-01-04 22:45:39 +000079 * https://tools.ietf.org/html/draft-mandyam-eat-01
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010080 *
81 * Current list of claims:
Tamas Ban52d4a8e2019-01-04 22:45:39 +000082 * - Challenge: Input object from caller. Can be a single nonce from server
83 * or hash of nonce and attested data. It is intended to provide
84 * freshness to reports and the caller has responsibility to
85 * arrange this. Allowed length: 32, 48, 64 bytes. The claim is
86 * modeled to be eventually represented by the EAT standard
87 * claim nonce. Until such a time as that standard exists,
88 * the claim will be represented by a custom claim. Value
89 * is encoded as byte string.
90 *
91 * - Instance ID: It represents the unique identifier of the instance. In the
92 * PSA definition it is a hash of the public attestation key
93 * of the instance. The claim is modeled to be eventually
94 * represented by the EAT standard claim UEID of type GUID.
95 * Until such a time as that standard exists, the claim will be
96 * represented by a custom claim Value is encoded as byte
97 * string.
98 *
99 * - Verification service indicator: Optional, recommended claim. It is used by
100 * a Relying Party to locate a validation service for the token.
101 * The value is a text string that can be used to locate the
102 * service or a URL specifying the address of the service. The
103 * claim is modeled to be eventually represented by the EAT
104 * standard claim origination. Until such a time as that
105 * standard exists, the claim will be represented by a custom
106 * claim. Value is encoded as text string.
107 *
108 * - Profile definition: Optional, recommended claim. It contains the name of
109 * a document that describes the 'profile' of the token, being
110 * a full description of the claims, their usage, verification
111 * and token signing. The document name may include versioning.
112 * Custom claim with a value encoded as text string.
113 *
114 * - Implementation ID: It represents the original implementation signer of the
115 * attestation key and identifies the contract between the
116 * report and verification. A verification service will use this
117 * claim to locate the details of the verification process.
118 * Custom claim with a value encoded as byte string.
119 *
120 * - Security lifecycle: It represents the current lifecycle state of the
121 * instance. Custom claim with a value encoded as integer that
122 * is divided to convey a major state and a minor state. The
123 * PSA state and implementation state are encoded as follows:
124 * - version[15:8] - PSA lifecycle state - major
125 * - version[7:0] - IMPLEMENTATION DEFINED state - minor
126 * Possible PSA lifecycle states:
127 * - Unknown (0x1000u),
128 * - PSA_RoT_Provisioning (0x2000u),
129 * - Secured (0x3000u),
130 * - Non_PSA_RoT_Debug(0x4000u),
131 * - Recoverable_PSA_RoT_Debug (0x5000u),
132 * - Decommissioned (0x6000u)
133 *
134 * - Client ID: The partition ID of that secure partition or non-secure
135 * thread who called the initial attestation API. Custom claim
136 * with a value encoded as a *signed* integer. Negative number
137 * represents non-secure caller, positive numbers represents
138 * secure callers, zero is invalid.
139 *
140 * - HW version: Optional claim. Globally unique number in EAN-13 format
141 * identifying the GDSII that went to fabrication, HW and ROM.
142 * It can be used to reference the security level of the PSA-ROT
143 * via a certification website. Custom claim with a value is
144 * encoded as text string.
145
146 * - Boot seed: It represents a random value created at system boot time that
147 * will allow differentiation of reports from different system
148 * sessions. The size is 32 bytes. Custom claim with a value is
149 * encoded as byte string.
150 *
151 * - Software components: Recommended claim. It represents the software state
152 * of the system. The value of the claim is an array of CBOR map
153 * entries, with one entry per software component within the
154 * device. Each map contains multiple claims that describe
155 * evidence about the details of the software component.
156 *
157 * - Measurement type: Optional claim. It represents the role of the
158 * software component. Value is encoded as short(!) text
159 * string.
160 *
161 * - Measurement value: It represents a hash of the invariant software
162 * component in memory at start-up time. The value must be a
163 * cryptographic hash of 256 bits or stronger.Value is
164 * encoded as byte string.
165 *
Tamas Ban52d4a8e2019-01-04 22:45:39 +0000166 * - Version: Optional claim. It represents the issued software version.
167 * Value is encoded as text string.
168 *
169 * - Signer ID: It represents the hash of a signing authority public key.
170 * Value is encoded as byte string.
171 *
172 * - Measurement description: Optional claim. It represents the way in which
173 * the measurement value of the software component is
174 * computed. Value is encoded as text string containing an
175 * abbreviated description (name) of the measurement method.
176 *
177 * - No software measurements: In the event that the implementation does not
178 * contain any software measurements then the software
179 * components claim above can be omitted but instead
180 * it is mandatory to include this claim to indicate this is a
181 * deliberate state. Custom claim a value is encoded as unsigned
182 * integer set to 1.
Tamas Ban6dfa6eb2018-08-17 12:02:51 +0100183 */
184
185/**
Tamas Ban6dfa6eb2018-08-17 12:02:51 +0100186 * \brief Get initial attestation token
187 *
188 * \param[in] challenge_obj Pointer to buffer where challenge input is
189 * stored. Nonce and / or hash of attested data.
190 * Must be always
Gyorgy Szing40a7af02019-02-06 14:19:47 +0100191 * \ref PSA_INITIAL_ATTEST_TOKEN_SIZE bytes
Tamas Ban6dfa6eb2018-08-17 12:02:51 +0100192 * long.
193 * \param[in] challenge_size Size of challenge object in bytes.
194 * \param[out] token Pointer to the buffer where attestation token
195 * must be stored.
Gyorgy Szing40a7af02019-02-06 14:19:47 +0100196 * \param[in,out] token_size Size of allocated buffer for token, which
Tamas Ban6dfa6eb2018-08-17 12:02:51 +0100197 * updated by initial attestation service with
198 * final token size.
199 *
200 * \return Returns error code as specified in \ref psa_attest_err_t
201 */
202enum psa_attest_err_t
203psa_initial_attest_get_token(const uint8_t *challenge_obj,
204 uint32_t challenge_size,
205 uint8_t *token,
206 uint32_t *token_size);
207
Tamas Ban52d4a8e2019-01-04 22:45:39 +0000208/**
209 * \brief Get the exact size of initial attestation token in bytes.
210 *
211 * It just returns with the size of the IAT token. It can be used if the caller
212 * dynamically allocates memory for the token buffer.
213 *
214 * \param[in] challenge_size Size of challenge object in bytes.
215 * \param[out] token_size Size of the token in bytes, which is created by
216 * initial attestation service.
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_size(uint32_t challenge_size,
222 uint32_t *token_size);
223
David Vincze20c3e4e2019-11-11 11:16:06 +0100224/**
225 * \brief Get the initial attestation public key.
226 *
227 * \param[out] public_key Pointer to the buffer where the public key
228 * will be stored.
229 * \param[in] key_buf_size Size of allocated buffer for key, in bytes.
230 * \param[out] public_key_len Size of public key in bytes.
231 * \param[out] public_key_curve Type of the elliptic curve which the key
232 * belongs to.
233 *
234 * \note Currently only the ECDSA P-256 over SHA-256 algorithm is supported.
235 *
236 * \return Returns error code as specified in \ref psa_attest_err_t
237 */
238enum psa_attest_err_t
239tfm_initial_attest_get_public_key(uint8_t *public_key,
240 size_t public_key_buf_size,
241 size_t *public_key_len,
242 psa_ecc_curve_t *elliptic_curve_type);
243
Tamas Ban6dfa6eb2018-08-17 12:02:51 +0100244#ifdef __cplusplus
245}
246#endif
247
Jamie Foxcc31d402019-01-28 17:13:52 +0000248#endif /* __PSA_INITIAL_ATTESTATION_H__ */