blob: 5d650f06eba4f90f736868cb0f66e9d4a258970c [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
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010018#include <limits.h>
Tamas Baneccae9d2019-01-09 15:54:56 +000019#include <stdint.h>
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010020
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
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010031/**
32 * \enum psa_attest_err_t
33 *
34 * \brief Initial attestation service error types
35 *
36 */
37enum psa_attest_err_t {
Tamas Ban52d4a8e2019-01-04 22:45:39 +000038 /** Action was performed successfully */
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010039 PSA_ATTEST_ERR_SUCCESS = 0,
Tamas Ban52d4a8e2019-01-04 22:45:39 +000040 /** Boot status data is unavailable or malformed */
Tamas Baneccae9d2019-01-09 15:54:56 +000041 PSA_ATTEST_ERR_INIT_FAILED,
Tamas Ban52d4a8e2019-01-04 22:45:39 +000042 /** Token buffer is too small to store the created token there */
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010043 PSA_ATTEST_ERR_TOKEN_BUFFER_OVERFLOW,
Tamas Ban52d4a8e2019-01-04 22:45:39 +000044 /** Some of the mandatory claims are unavailable*/
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010045 PSA_ATTEST_ERR_CLAIM_UNAVAILABLE,
Tamas Ban52d4a8e2019-01-04 22:45:39 +000046 /** Some parameter or combination of parameters are recognised as invalid:
47 * - challenge size is not allowed
48 * - challenge object is unavailable
49 * - token buffer is unavailable
50 */
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010051 PSA_ATTEST_ERR_INVALID_INPUT,
Tamas Ban52d4a8e2019-01-04 22:45:39 +000052 /** Unexpected error happened during operation */
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010053 PSA_ATTEST_ERR_GENERAL,
Tamas Ban52d4a8e2019-01-04 22:45:39 +000054 /** Following entry is only to ensure the error code of integer size */
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010055 PSA_ATTEST_ERR_FORCE_INT_SIZE = INT_MAX
56};
57
58/**
Tamas Ban52d4a8e2019-01-04 22:45:39 +000059 * The allowed size of input challenge in bytes: 32, 48, 64
60 * Challenge can be a nonce from server
61 * or the hash of some combined data : nonce + attested data by caller.
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010062 */
Tamas Ban52d4a8e2019-01-04 22:45:39 +000063#define PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32 (32u)
64#define PSA_INITIAL_ATTEST_CHALLENGE_SIZE_48 (48u)
65#define PSA_INITIAL_ATTEST_CHALLENGE_SIZE_64 (64u)
66
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010067/**
68 * The list of fixed claims in the initial attestation token is still evolving,
69 * you can expect slight changes in the future.
70 *
Tamas Ban52d4a8e2019-01-04 22:45:39 +000071 * The initial attestation token is planned to be aligned with future version of
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010072 * Entity Attestation Token format:
Tamas Ban52d4a8e2019-01-04 22:45:39 +000073 * https://tools.ietf.org/html/draft-mandyam-eat-01
Tamas Ban6dfa6eb2018-08-17 12:02:51 +010074 *
75 * Current list of claims:
Tamas Ban52d4a8e2019-01-04 22:45:39 +000076 * - Challenge: Input object from caller. Can be a single nonce from server
77 * or hash of nonce and attested data. It is intended to provide
78 * freshness to reports and the caller has responsibility to
79 * arrange this. Allowed length: 32, 48, 64 bytes. The claim is
80 * modeled to be eventually represented by the EAT standard
81 * claim nonce. Until such a time as that standard exists,
82 * the claim will be represented by a custom claim. Value
83 * is encoded as byte string.
84 *
85 * - Instance ID: It represents the unique identifier of the instance. In the
86 * PSA definition it is a hash of the public attestation key
87 * of the instance. The claim is modeled to be eventually
88 * represented by the EAT standard claim UEID of type GUID.
89 * Until such a time as that standard exists, the claim will be
90 * represented by a custom claim Value is encoded as byte
91 * string.
92 *
93 * - Verification service indicator: Optional, recommended claim. It is used by
94 * a Relying Party to locate a validation service for the token.
95 * The value is a text string that can be used to locate the
96 * service or a URL specifying the address of the service. The
97 * claim is modeled to be eventually represented by the EAT
98 * standard claim origination. Until such a time as that
99 * standard exists, the claim will be represented by a custom
100 * claim. Value is encoded as text string.
101 *
102 * - Profile definition: Optional, recommended claim. It contains the name of
103 * a document that describes the 'profile' of the token, being
104 * a full description of the claims, their usage, verification
105 * and token signing. The document name may include versioning.
106 * Custom claim with a value encoded as text string.
107 *
108 * - Implementation ID: It represents the original implementation signer of the
109 * attestation key and identifies the contract between the
110 * report and verification. A verification service will use this
111 * claim to locate the details of the verification process.
112 * Custom claim with a value encoded as byte string.
113 *
114 * - Security lifecycle: It represents the current lifecycle state of the
115 * instance. Custom claim with a value encoded as integer that
116 * is divided to convey a major state and a minor state. The
117 * PSA state and implementation state are encoded as follows:
118 * - version[15:8] - PSA lifecycle state - major
119 * - version[7:0] - IMPLEMENTATION DEFINED state - minor
120 * Possible PSA lifecycle states:
121 * - Unknown (0x1000u),
122 * - PSA_RoT_Provisioning (0x2000u),
123 * - Secured (0x3000u),
124 * - Non_PSA_RoT_Debug(0x4000u),
125 * - Recoverable_PSA_RoT_Debug (0x5000u),
126 * - Decommissioned (0x6000u)
127 *
128 * - Client ID: The partition ID of that secure partition or non-secure
129 * thread who called the initial attestation API. Custom claim
130 * with a value encoded as a *signed* integer. Negative number
131 * represents non-secure caller, positive numbers represents
132 * secure callers, zero is invalid.
133 *
134 * - HW version: Optional claim. Globally unique number in EAN-13 format
135 * identifying the GDSII that went to fabrication, HW and ROM.
136 * It can be used to reference the security level of the PSA-ROT
137 * via a certification website. Custom claim with a value is
138 * encoded as text string.
139
140 * - Boot seed: It represents a random value created at system boot time that
141 * will allow differentiation of reports from different system
142 * sessions. The size is 32 bytes. Custom claim with a value is
143 * encoded as byte string.
144 *
145 * - Software components: Recommended claim. It represents the software state
146 * of the system. The value of the claim is an array of CBOR map
147 * entries, with one entry per software component within the
148 * device. Each map contains multiple claims that describe
149 * evidence about the details of the software component.
150 *
151 * - Measurement type: Optional claim. It represents the role of the
152 * software component. Value is encoded as short(!) text
153 * string.
154 *
155 * - Measurement value: It represents a hash of the invariant software
156 * component in memory at start-up time. The value must be a
157 * cryptographic hash of 256 bits or stronger.Value is
158 * encoded as byte string.
159 *
160 * - Security epoch: Optional claim. It represents the security control
161 * point of the software component. Value is encoded as
162 * unsigned integer.
163 *
164 * - 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/**
184 * Calculated based on:
185 * - COSE header
186 * - Algorithm identifier
187 * - Key ID
Tamas Ban52d4a8e2019-01-04 22:45:39 +0000188 * - Claims in initial attestation token
Tamas Ban6dfa6eb2018-08-17 12:02:51 +0100189 * - COSE Signature
190 *
191 * This size (in bytes) is a maximum value, actual token size can be smaller.
192 */
193/* FixMe: Just initial value it must be updated if claims are fixed */
194#define PSA_INITIAL_ATTEST_TOKEN_SIZE (512u)
195
196/**
197 * \brief Get initial attestation token
198 *
199 * \param[in] challenge_obj Pointer to buffer where challenge input is
200 * stored. Nonce and / or hash of attested data.
201 * Must be always
202 * \ref PSA_INITIAL_ATTEST_CHALLENGE_SIZE bytes
203 * long.
204 * \param[in] challenge_size Size of challenge object in bytes.
205 * \param[out] token Pointer to the buffer where attestation token
206 * must be stored.
207 * \param[in/out] token_size Size of allocated buffer for token, which
208 * updated by initial attestation service with
209 * final token size.
210 *
211 * \return Returns error code as specified in \ref psa_attest_err_t
212 */
213enum psa_attest_err_t
214psa_initial_attest_get_token(const uint8_t *challenge_obj,
215 uint32_t challenge_size,
216 uint8_t *token,
217 uint32_t *token_size);
218
Tamas Ban52d4a8e2019-01-04 22:45:39 +0000219/**
220 * \brief Get the exact size of initial attestation token in bytes.
221 *
222 * It just returns with the size of the IAT token. It can be used if the caller
223 * dynamically allocates memory for the token buffer.
224 *
225 * \param[in] challenge_size Size of challenge object in bytes.
226 * \param[out] token_size Size of the token in bytes, which is created by
227 * initial attestation service.
228 *
229 * \return Returns error code as specified in \ref psa_attest_err_t
230 */
231enum psa_attest_err_t
232psa_initial_attest_get_token_size(uint32_t challenge_size,
233 uint32_t *token_size);
234
Tamas Ban6dfa6eb2018-08-17 12:02:51 +0100235#ifdef __cplusplus
236}
237#endif
238
239#endif /* __PSA_INITIAL_ATTESTATION_API_H__ */