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