blob: 6a7b8d8e17c27f1c704ba1b9c418ae70a24bbfcb [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,
Tamas Ban52d4a8e2019-01-04 22:45:39 +000048 /** Some of the mandatory claims are unavailable*/
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010049 PSA_ATTEST_ERR_CLAIM_UNAVAILABLE,
Tamas Ban52d4a8e2019-01-04 22:45:39 +000050 /** Some parameter or combination of parameters are recognised as invalid:
51 * - challenge size is not allowed
52 * - challenge object is unavailable
53 * - token buffer is unavailable
54 */
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010055 PSA_ATTEST_ERR_INVALID_INPUT,
Tamas Ban52d4a8e2019-01-04 22:45:39 +000056 /** Unexpected error happened during operation */
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010057 PSA_ATTEST_ERR_GENERAL,
Tamas Ban52d4a8e2019-01-04 22:45:39 +000058 /** Following entry is only to ensure the error code of integer size */
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010059 PSA_ATTEST_ERR_FORCE_INT_SIZE = INT_MAX
60};
61
62/**
Tamas Ban52d4a8e2019-01-04 22:45:39 +000063 * The allowed size of input challenge in bytes: 32, 48, 64
64 * Challenge can be a nonce from server
65 * or the hash of some combined data : nonce + attested data by caller.
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010066 */
Tamas Ban52d4a8e2019-01-04 22:45:39 +000067#define PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32 (32u)
68#define PSA_INITIAL_ATTEST_CHALLENGE_SIZE_48 (48u)
69#define PSA_INITIAL_ATTEST_CHALLENGE_SIZE_64 (64u)
70
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010071/**
72 * The list of fixed claims in the initial attestation token is still evolving,
73 * you can expect slight changes in the future.
74 *
Tamas Ban52d4a8e2019-01-04 22:45:39 +000075 * The initial attestation token is planned to be aligned with future version of
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010076 * Entity Attestation Token format:
Tamas Ban52d4a8e2019-01-04 22:45:39 +000077 * https://tools.ietf.org/html/draft-mandyam-eat-01
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010078 *
79 * Current list of claims:
Tamas Ban52d4a8e2019-01-04 22:45:39 +000080 * - Challenge: Input object from caller. Can be a single nonce from server
81 * or hash of nonce and attested data. It is intended to provide
82 * freshness to reports and the caller has responsibility to
83 * arrange this. Allowed length: 32, 48, 64 bytes. The claim is
84 * modeled to be eventually represented by the EAT standard
85 * claim nonce. Until such a time as that standard exists,
86 * the claim will be represented by a custom claim. Value
87 * is encoded as byte string.
88 *
89 * - Instance ID: It represents the unique identifier of the instance. In the
90 * PSA definition it is a hash of the public attestation key
91 * of the instance. The claim is modeled to be eventually
92 * represented by the EAT standard claim UEID of type GUID.
93 * Until such a time as that standard exists, the claim will be
94 * represented by a custom claim Value is encoded as byte
95 * string.
96 *
97 * - Verification service indicator: Optional, recommended claim. It is used by
98 * a Relying Party to locate a validation service for the token.
99 * The value is a text string that can be used to locate the
100 * service or a URL specifying the address of the service. The
101 * claim is modeled to be eventually represented by the EAT
102 * standard claim origination. Until such a time as that
103 * standard exists, the claim will be represented by a custom
104 * claim. Value is encoded as text string.
105 *
106 * - Profile definition: Optional, recommended claim. It contains the name of
107 * a document that describes the 'profile' of the token, being
108 * a full description of the claims, their usage, verification
109 * and token signing. The document name may include versioning.
110 * Custom claim with a value encoded as text string.
111 *
112 * - Implementation ID: It represents the original implementation signer of the
113 * attestation key and identifies the contract between the
114 * report and verification. A verification service will use this
115 * claim to locate the details of the verification process.
116 * Custom claim with a value encoded as byte string.
117 *
118 * - Security lifecycle: It represents the current lifecycle state of the
119 * instance. Custom claim with a value encoded as integer that
120 * is divided to convey a major state and a minor state. The
121 * PSA state and implementation state are encoded as follows:
122 * - version[15:8] - PSA lifecycle state - major
123 * - version[7:0] - IMPLEMENTATION DEFINED state - minor
124 * Possible PSA lifecycle states:
125 * - Unknown (0x1000u),
126 * - PSA_RoT_Provisioning (0x2000u),
127 * - Secured (0x3000u),
128 * - Non_PSA_RoT_Debug(0x4000u),
129 * - Recoverable_PSA_RoT_Debug (0x5000u),
130 * - Decommissioned (0x6000u)
131 *
132 * - Client ID: The partition ID of that secure partition or non-secure
133 * thread who called the initial attestation API. Custom claim
134 * with a value encoded as a *signed* integer. Negative number
135 * represents non-secure caller, positive numbers represents
136 * secure callers, zero is invalid.
137 *
138 * - HW version: Optional claim. Globally unique number in EAN-13 format
139 * identifying the GDSII that went to fabrication, HW and ROM.
140 * It can be used to reference the security level of the PSA-ROT
141 * via a certification website. Custom claim with a value is
142 * encoded as text string.
143
144 * - Boot seed: It represents a random value created at system boot time that
145 * will allow differentiation of reports from different system
146 * sessions. The size is 32 bytes. Custom claim with a value is
147 * encoded as byte string.
148 *
149 * - Software components: Recommended claim. It represents the software state
150 * of the system. The value of the claim is an array of CBOR map
151 * entries, with one entry per software component within the
152 * device. Each map contains multiple claims that describe
153 * evidence about the details of the software component.
154 *
155 * - Measurement type: Optional claim. It represents the role of the
156 * software component. Value is encoded as short(!) text
157 * string.
158 *
159 * - Measurement value: It represents a hash of the invariant software
160 * component in memory at start-up time. The value must be a
161 * cryptographic hash of 256 bits or stronger.Value is
162 * encoded as byte string.
163 *
Tamas Ban52d4a8e2019-01-04 22:45:39 +0000164 * - Version: Optional claim. It represents the issued software version.
165 * Value is encoded as text string.
166 *
167 * - Signer ID: It represents the hash of a signing authority public key.
168 * Value is encoded as byte string.
169 *
170 * - Measurement description: Optional claim. It represents the way in which
171 * the measurement value of the software component is
172 * computed. Value is encoded as text string containing an
173 * abbreviated description (name) of the measurement method.
174 *
175 * - No software measurements: In the event that the implementation does not
176 * contain any software measurements then the software
177 * components claim above can be omitted but instead
178 * it is mandatory to include this claim to indicate this is a
179 * deliberate state. Custom claim a value is encoded as unsigned
180 * integer set to 1.
Tamas Ban6dfa6eb2018-08-17 12:02:51 +0100181 */
182
183/**
Tamas Ban6dfa6eb2018-08-17 12:02:51 +0100184 * \brief Get initial attestation token
185 *
186 * \param[in] challenge_obj Pointer to buffer where challenge input is
187 * stored. Nonce and / or hash of attested data.
188 * Must be always
Gyorgy Szing40a7af02019-02-06 14:19:47 +0100189 * \ref PSA_INITIAL_ATTEST_TOKEN_SIZE bytes
Tamas Ban6dfa6eb2018-08-17 12:02:51 +0100190 * long.
191 * \param[in] challenge_size Size of challenge object in bytes.
192 * \param[out] token Pointer to the buffer where attestation token
193 * must be stored.
Gyorgy Szing40a7af02019-02-06 14:19:47 +0100194 * \param[in,out] token_size Size of allocated buffer for token, which
Tamas Ban6dfa6eb2018-08-17 12:02:51 +0100195 * updated by initial attestation service with
196 * final token size.
197 *
198 * \return Returns error code as specified in \ref psa_attest_err_t
199 */
200enum psa_attest_err_t
201psa_initial_attest_get_token(const uint8_t *challenge_obj,
202 uint32_t challenge_size,
203 uint8_t *token,
204 uint32_t *token_size);
205
Tamas Ban52d4a8e2019-01-04 22:45:39 +0000206/**
207 * \brief Get the exact size of initial attestation token in bytes.
208 *
209 * It just returns with the size of the IAT token. It can be used if the caller
210 * dynamically allocates memory for the token buffer.
211 *
212 * \param[in] challenge_size Size of challenge object in bytes.
213 * \param[out] token_size Size of the token in bytes, which is created by
214 * initial attestation service.
215 *
216 * \return Returns error code as specified in \ref psa_attest_err_t
217 */
218enum psa_attest_err_t
219psa_initial_attest_get_token_size(uint32_t challenge_size,
220 uint32_t *token_size);
221
David Vincze20c3e4e2019-11-11 11:16:06 +0100222/**
223 * \brief Get the initial attestation public key.
224 *
225 * \param[out] public_key Pointer to the buffer where the public key
226 * will be stored.
227 * \param[in] key_buf_size Size of allocated buffer for key, in bytes.
228 * \param[out] public_key_len Size of public key in bytes.
229 * \param[out] public_key_curve Type of the elliptic curve which the key
230 * belongs to.
231 *
232 * \note Currently only the ECDSA P-256 over SHA-256 algorithm is supported.
233 *
234 * \return Returns error code as specified in \ref psa_attest_err_t
235 */
236enum psa_attest_err_t
237tfm_initial_attest_get_public_key(uint8_t *public_key,
238 size_t public_key_buf_size,
239 size_t *public_key_len,
240 psa_ecc_curve_t *elliptic_curve_type);
241
Tamas Ban6dfa6eb2018-08-17 12:02:51 +0100242#ifdef __cplusplus
243}
244#endif
245
Jamie Foxcc31d402019-01-28 17:13:52 +0000246#endif /* __PSA_INITIAL_ATTESTATION_H__ */