blob: 3aacb296785f8e0add51422c333fab102098a8e9 [file] [log] [blame]
Julian Hall201ce462021-04-29 11:05:34 +01001/*
Gabor Toth99e4ec52023-07-18 08:24:20 +02002 * Copyright (c) 2018-2023, Arm Limited. All rights reserved.
Julian Hall201ce462021-04-29 11:05:34 +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_H__
16#define __PSA_INITIAL_ATTESTATION_H__
17
18#include <limits.h>
Julian Hallb7db5802021-07-26 16:20:40 +010019#include <psa/crypto.h>
Julian Hallb57aa0d2021-07-13 10:34:59 +010020#include <psa/error.h>
Gabor Toth99e4ec52023-07-18 08:24:20 +020021#include <stddef.h>
22#include <stdint.h>
Julian Hall201ce462021-04-29 11:05:34 +010023
24#ifdef __cplusplus
25extern "C" {
26#endif
27
Gabor Toth99e4ec52023-07-18 08:24:20 +020028#ifdef EXPORT_PUBLIC_INTERFACE_PSA_ATTEST
29#define PSA_ATTEST_EXPORTED __attribute__((__visibility__("default")))
30#else
31#define PSA_ATTEST_EXPORTED
32#endif
33
Julian Hall201ce462021-04-29 11:05:34 +010034/**
35 * \brief PSA INITIAL ATTESTATION API version
36 *
37 * Initial attestation API version is: 1.0.0
38 */
39#define PSA_INITIAL_ATTEST_API_VERSION_MAJOR (1)
40#define PSA_INITIAL_ATTEST_API_VERSION_MINOR (0)
41
42/**
43 * The allowed size of input challenge in bytes: 32, 48, 64
44 * Challenge can be a nonce from server
45 * or the hash of some combined data : nonce + attested data by caller.
46 */
Gabor Toth99e4ec52023-07-18 08:24:20 +020047#define PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32 (32u)
48#define PSA_INITIAL_ATTEST_CHALLENGE_SIZE_48 (48u)
49#define PSA_INITIAL_ATTEST_CHALLENGE_SIZE_64 (64u)
Julian Hall201ce462021-04-29 11:05:34 +010050
51/**
52 * The maximum size of an attestation token that can be generated by the
53 * attestation service. Used to configure buffers for services that verify the
54 * produced tokens.
55 */
Gabor Toth99e4ec52023-07-18 08:24:20 +020056#define PSA_INITIAL_ATTEST_MAX_TOKEN_SIZE (4096)
Julian Hall201ce462021-04-29 11:05:34 +010057
58/**
59 * The list of fixed claims in the initial attestation token is still evolving,
60 * you can expect slight changes in the future.
61 *
62 * The initial attestation token is planned to be aligned with future version of
63 * Entity Attestation Token format:
64 * https://tools.ietf.org/html/draft-mandyam-eat-01
65 *
66 * Current list of claims:
67 * - Challenge: Input object from caller. Can be a single nonce from server
68 * or hash of nonce and attested data. It is intended to provide
69 * freshness to reports and the caller has responsibility to
70 * arrange this. Allowed length: 32, 48, 64 bytes. The claim is
71 * modeled to be eventually represented by the EAT standard
72 * claim nonce. Until such a time as that standard exists,
73 * the claim will be represented by a custom claim. Value
74 * is encoded as byte string.
75 *
76 * - Instance ID: It represents the unique identifier of the instance. In the
77 * PSA definition it is a hash of the public attestation key
78 * of the instance. The claim is modeled to be eventually
79 * represented by the EAT standard claim UEID of type GUID.
80 * Until such a time as that standard exists, the claim will be
81 * represented by a custom claim Value is encoded as byte
82 * string.
83 *
84 * - Verification service indicator: Optional, recommended claim. It is used by
85 * a Relying Party to locate a validation service for the token.
86 * The value is a text string that can be used to locate the
87 * service or a URL specifying the address of the service. The
88 * claim is modeled to be eventually represented by the EAT
89 * standard claim origination. Until such a time as that
90 * standard exists, the claim will be represented by a custom
91 * claim. Value is encoded as text string.
92 *
93 * - Profile definition: Optional, recommended claim. It contains the name of
94 * a document that describes the 'profile' of the token, being
95 * a full description of the claims, their usage, verification
96 * and token signing. The document name may include versioning.
97 * Custom claim with a value encoded as text string.
98 *
99 * - Implementation ID: It represents the original implementation signer of the
100 * attestation key and identifies the contract between the
101 * report and verification. A verification service will use this
102 * claim to locate the details of the verification process.
103 * Custom claim with a value encoded as byte string.
104 *
105 * - Security lifecycle: It represents the current lifecycle state of the
106 * instance. Custom claim with a value encoded as integer that
107 * is divided to convey a major state and a minor state. The
108 * PSA state and implementation state are encoded as follows:
109 * - version[15:8] - PSA lifecycle state - major
110 * - version[7:0] - IMPLEMENTATION DEFINED state - minor
111 * Possible PSA lifecycle states:
112 * - Unknown (0x1000u),
113 * - PSA_RoT_Provisioning (0x2000u),
114 * - Secured (0x3000u),
115 * - Non_PSA_RoT_Debug(0x4000u),
116 * - Recoverable_PSA_RoT_Debug (0x5000u),
117 * - Decommissioned (0x6000u)
118 *
119 * - Client ID: The partition ID of that secure partition or non-secure
120 * thread who called the initial attestation API. Custom claim
121 * with a value encoded as a *signed* integer. Negative number
122 * represents non-secure caller, positive numbers represents
123 * secure callers, zero is invalid.
124 *
125 * - HW version: Optional claim. Globally unique number in EAN-13 format
126 * identifying the GDSII that went to fabrication, HW and ROM.
127 * It can be used to reference the security level of the PSA-ROT
128 * via a certification website. Custom claim with a value is
129 * encoded as text string.
130
131 * - Boot seed: It represents a random value created at system boot time that
132 * will allow differentiation of reports from different system
133 * sessions. The size is 32 bytes. Custom claim with a value is
134 * encoded as byte string.
135 *
136 * - Software components: Recommended claim. It represents the software state
137 * of the system. The value of the claim is an array of CBOR map
138 * entries, with one entry per software component within the
139 * device. Each map contains multiple claims that describe
140 * evidence about the details of the software component.
141 *
142 * - Measurement type: Optional claim. It represents the role of the
143 * software component. Value is encoded as short(!) text
144 * string.
145 *
146 * - Measurement value: It represents a hash of the invariant software
147 * component in memory at start-up time. The value must be a
148 * cryptographic hash of 256 bits or stronger.Value is
149 * encoded as byte string.
150 *
151 * - Version: Optional claim. It represents the issued software version.
152 * Value is encoded as text string.
153 *
154 * - Signer ID: It represents the hash of a signing authority public key.
155 * Value is encoded as byte string.
156 *
157 * - Measurement description: Optional claim. It represents the way in which
158 * the measurement value of the software component is
159 * computed. Value is encoded as text string containing an
160 * abbreviated description (name) of the measurement method.
161 *
162 * - No software measurements: In the event that the implementation does not
163 * contain any software measurements then the software
164 * components claim above can be omitted but instead
165 * it is mandatory to include this claim to indicate this is a
166 * deliberate state. Custom claim a value is encoded as unsigned
167 * integer set to 1.
168 */
169
170/**
171 * \brief Get initial attestation token
172 *
173 * \param[in] auth_challenge Pointer to buffer where challenge input is
174 * stored. Nonce and / or hash of attested data.
175 * Must be always
176 * \ref PSA_INITIAL_ATTEST_TOKEN_SIZE bytes
177 * long.
178 * \param[in] challenge_size Size of challenge object in bytes.
179 * \param[out] token_buf Pointer to the buffer where attestation token
180 * will be stored.
181 * \param[in] token_buf_size Size of allocated buffer for token, in bytes.
182 * \param[out] token_size Size of the token that has been returned, in
183 * bytes.
184 *
185 * \return Returns error code as specified in \ref psa_status_t
186 */
Gabor Toth99e4ec52023-07-18 08:24:20 +0200187PSA_ATTEST_EXPORTED psa_status_t psa_initial_attest_get_token(const uint8_t *auth_challenge,
188 size_t challenge_size,
189 uint8_t *token_buf,
190 size_t token_buf_size,
191 size_t *token_size);
Julian Hall201ce462021-04-29 11:05:34 +0100192
193/**
194 * \brief Get the exact size of initial attestation token in bytes.
195 *
196 * It just returns with the size of the IAT token. It can be used if the caller
197 * dynamically allocates memory for the token buffer.
198 *
199 * \param[in] challenge_size Size of challenge object in bytes. This must be
200 * a supported challenge size (as above).
201 * \param[out] token_size Size of the token in bytes, which is created by
202 * initial attestation service.
203 *
204 * \return Returns error code as specified in \ref psa_status_t
205 */
Gabor Toth99e4ec52023-07-18 08:24:20 +0200206PSA_ATTEST_EXPORTED psa_status_t psa_initial_attest_get_token_size(size_t challenge_size,
207 size_t *token_size);
Julian Hall201ce462021-04-29 11:05:34 +0100208
Julian Hallb7db5802021-07-26 16:20:40 +0100209/**
210 * \brief Get the attestation public key
211 *
212 * This function is for compatibility with the PSA Arch tests that use
213 * a TF-M specific function to retieve the IAK public key from the device
214 * under test.
215 *
216 * \param[out] public_key Pointer to the buffer where the public key
217 * will be stored.
218 * \param[in] key_buf_size Size of allocated buffer for key, in bytes.
219 * \param[out] public_key_len Size of public key in bytes.
220 * \param[out] public_key_curve Type of the elliptic curve which the key
221 * belongs to.
222 *
223 * \note Currently only the ECDSA P-256 over SHA-256 algorithm is supported.
224 *
225 * \return Returns error code as specified in \ref psa_status_t
226 */
Gabor Toth99e4ec52023-07-18 08:24:20 +0200227PSA_ATTEST_EXPORTED psa_status_t
228tfm_initial_attest_get_public_key(uint8_t *public_key, size_t public_key_buf_size,
229 size_t *public_key_len, psa_ecc_family_t *elliptic_curve_type);
Julian Hallb7db5802021-07-26 16:20:40 +0100230
Julian Hall201ce462021-04-29 11:05:34 +0100231#ifdef __cplusplus
232}
233#endif
234
235#endif /* __PSA_INITIAL_ATTESTATION_H__ */