blob: 2c43ea7bdc1a2709570f3147c62725ec9c639b5e [file] [log] [blame]
Galanakis, Minos41f85972019-09-30 15:56:40 +01001#############################################
2Initial Attestation Service Integration Guide
3#############################################
Gyorgy Szingdb9783c2019-04-17 21:08:48 +02004
5************
6Introduction
7************
8TF-M Initial Attestation Service allows the application to prove the device
9identity during an authentication process to a verification entity. The initial
10attestation service can create a token on request, which contains a fix set of
David Hu10b66152020-05-29 22:53:13 +080011device specific data.
12
13TF-M Initial Attestation Service by default enables asymmetric key algorithm
14based attestation (*asymmetric attestation* for short). Symmetric key algorithm
15based attestation (*symmetric attestation* for short) can be enabled instead by
16selecting build option ``SYMMETRIC_INITIAL_ATTESTATION``.
17
18 - In asymmetric attestation, device must contain an attestation key pair,
19 which is unique per device. The token is signed with the private part of
20 attestation key pair. The public part of the key pair is known by the
21 verification entity. The public key is used to verify the token
22 authenticity.
23 - In symmetric attestation, device should contain a symmetric attestation
24 key to generate the authentication tag of token content. The verification
25 entity uses the same symmetric key to verify the token authenticity.
26
27The data items in the token used to verify the device integrity and assess its
28trustworthiness. Attestation key provisioning is out of scope for the
29attestation service and is expected to take part during manufacturing of the
30device.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020031
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020032***************************************
33Claims in the initial attestation token
34***************************************
35The initial attestation token is formed of claims. A claim is a data item,
36which is represented in a key - value structure. The following fixed set of
37claims are included in the token:
38
Raef Coles90b3f002019-10-09 14:13:35 +010039 - **Auth challenge**: Input object from caller. Can be a single nonce from
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020040 server or hash of nonce and attested data. It is intended to provide
41 freshness to report and the caller has responsibility to arrange
42 this. Allowed length: 32, 48, 64 bytes. The claim is modeled to be
43 eventually represented by the EAT standard claim nonce. Until such a
44 time as that standard exists, the claim will be represented by a custom
45 claim. Value is encoded as byte string.
Tamas Bandaa4c6e2019-07-01 12:39:00 +010046
David Hu10b66152020-05-29 22:53:13 +080047 - **Instance ID**: It represents the unique identifier of the instance.
48 In the PSA definition it is:
49
50 - a hash of the public attestation key of the instance in asymmetric
51 attestation.
52 - hashes of the symmetric attestation key of the instance in symmetric
53 attestation.
54
55 The claim is modeled to be eventually represented by the EAT standard
56 claim UEID of type GUID. Until such a time as that standard exists, the
57 claim will be represented by a custom claim Value is encoded as byte
58 string.
Tamas Bandaa4c6e2019-07-01 12:39:00 +010059
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020060 - **Verification service indicator**: Optional, recommended claim. It
61 is used by a Relying Party to locate a validation service for the
62 token. The value is a text string that can be used to locate the service
63 or a URL specifying the address of the service. The claim is modelled to
64 be eventually represented by the EAT standard claim origination. Until
65 such a time as that standard exists, the claim will be represented by
66 a custom claim. Value is encoded as text string.
Tamas Bandaa4c6e2019-07-01 12:39:00 +010067
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020068 - **Profile definition**: Optional, recommended claim. It contains the
69 name of a document that describes the 'profile' of the token, being
70 a full description of the claims, their usage, verification and token
71 signing. The document name may include versioning. Custom claim with a
72 value encoded as text string.
Tamas Bandaa4c6e2019-07-01 12:39:00 +010073
Raef Coles90b3f002019-10-09 14:13:35 +010074 - **Implementation ID**: Uniquely identifies the underlying immutable PSA
75 RoT. A verification service can use this claim to locate the details of
Tamas Banf8863812020-06-09 13:46:04 +010076 the verification process. Such details include the implementation's origin
Raef Coles90b3f002019-10-09 14:13:35 +010077 and associated certification state. Custom claim with a value encoded as
78 byte string.
Tamas Bandaa4c6e2019-07-01 12:39:00 +010079
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020080 - **Client ID**: The partition ID of that secure partition or non-secure
81 thread who called the initial attestation API. Custom claim with a value
82 encoded as a `signed` integer. Negative number represents non-secure
83 caller, positive numbers represents secure callers, zero is invalid.
Tamas Bandaa4c6e2019-07-01 12:39:00 +010084
Raef Coles90b3f002019-10-09 14:13:35 +010085 - **Security lifecycle**: It represents the current lifecycle state of
86 the instance. Custom claim with a value encoded as an integer.
87
88 - **Hardware version**: Optional claim. Globally unique number in EAN-13
89 format identifying the GDSII that went to fabrication, HW and ROM. It can
90 be used to reference the security level of the PSA-ROT via a certification
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020091 website. Custom claim with a value is encoded as text string.
Tamas Bandaa4c6e2019-07-01 12:39:00 +010092
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020093 - **Boot seed**: It represents a random value created at system boot
94 time that will allow differentiation of reports from different system
95 sessions. The size is 32 bytes. Custom claim with a value is encoded as
96 byte string.
Tamas Bandaa4c6e2019-07-01 12:39:00 +010097
Raef Coles90b3f002019-10-09 14:13:35 +010098 - **Software components**: Optional, but required in order to be compliant
99 with the PSA-SM. It represents the software state of the system. The value
100 of the claim is an array of CBOR map entries, with one entry per software
101 component within the device. Each map contains multiple claims that
102 describe evidence about the details of the software component.
103
104 - **No software measurements**: Optional, but required if no software
105 component claims are made. In the event that the implementation does not
106 contain any software measurements then it is mandatory to include this
107 claim to indicate this is a deliberate state. Custom claim with a value
108 encoded as an unsigned integer set to 1.
109
110Each software component claim can include the following properties. Any property
111that is not optional must be included:
Tamas Bandaa4c6e2019-07-01 12:39:00 +0100112
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200113 - **Measurement type**: Optional claim. It represents the role of the
114 software component. Value is encoded as short(!) text string.
Tamas Bandaa4c6e2019-07-01 12:39:00 +0100115
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200116 - **Measurement value**: It represents a hash of the invariant software
117 component in memory at start-up time. The value must be a cryptographic
118 hash of 256 bits or stronger. Value is encoded as byte string.
Tamas Bandaa4c6e2019-07-01 12:39:00 +0100119
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200120 - **Version**: Optional claim. It represents the issued software
121 version. Value is encoded as text string.
Tamas Bandaa4c6e2019-07-01 12:39:00 +0100122
Raef Coles90b3f002019-10-09 14:13:35 +0100123 - **Signer ID**: Optional claim, but required in order to be compliant with
124 the PSA-SM. It represents the hash of a signing authority public key.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200125 Value is encoded as byte string.
Tamas Bandaa4c6e2019-07-01 12:39:00 +0100126
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200127 - **Measurement description**: Optional claim. It represents the way in
128 which the measurement value of the software component is computed. Value
129 is encoded as text string containing an abbreviated description (name)
130 of the measurement method.
Tamas Bandaa4c6e2019-07-01 12:39:00 +0100131
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200132*********************************************
133Initial attestation token (IAT) data encoding
134*********************************************
135The initial attestation token is planned to be aligned with future version of
136`Entity Attestation Token <https://tools.ietf.org/html/draft-mandyam-eat-01>`__
137format. The token is encoded according to the
138`CBOR <https://tools.ietf.org/html/rfc7049>`__ format and signed according to
139`COSE <https://tools.ietf.org/html/rfc8152>`__ standard.
140
141**************
142Code structure
143**************
144The PSA interface for the Initial Attestation Service is located in
145``interface/include``. The only header to be included by applications that want
Jamie Foxcc31d402019-01-28 17:13:52 +0000146to use functions from the PSA API is ``psa/initial_attestation.h``.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200147
148The TF-M Initial Attestation Service source files are located in
Ken Liu738a4b02020-06-04 14:52:38 +0800149``secure_fw/partitions/initial_attestation``.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200150The CBOR library is located in ``lib/ext/qcbor`` folder.
151
152Service source files
153====================
154- CBOR library
155 - ``lib/ext/qcbor`` This library is used to create a proper CBOR token.
Tamas Banf8863812020-06-09 13:46:04 +0100156 It can be used on 32-bit and 64-bit machines. It was designed to suite
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200157 constrained devices with low memory usage and without dynamic memory
158 allocation.
159 It is a fork of this external `QCBOR library <https://github.com/laurencelundblade/QCBOR>`__.
160 - ``lib/ext/qcbor/inc/qcbor.h``: Public API documentation of CBOR
161 library.
162
163- COSE library:
Tamas Banf8863812020-06-09 13:46:04 +0100164 - ``lib/ext/t_cose``: This library is used to sign a CBOR token and create
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200165 the COSE header and signature around the initial attestation token. Only
166 a subset of the `COSE <https://tools.ietf.org/html/rfc8152>`__ standard
Tamas Banf8863812020-06-09 13:46:04 +0100167 is implemented. The COSE_Sign1 and COSE_Mac0 (only available in TF-M fork)
168 signature schemas are supported.
169 - It is a fork of this external `t_cose library <https://github.com/laurencelundblade/t_cose>`__.
170 - ``lib/ext/t_cose/src/t_cose_crypto.h``: Expose an API to bind ``t_cose``
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200171 library with available crypto library in the device.
Tamas Banf8863812020-06-09 13:46:04 +0100172 - ``lib/ext/t_cose/crypto_adapters/t_cose_psa_crypto.c``: Implements the
173 exposed API and ports ``t_cose`` to the PSA Crypto API.
Tamas Bandaa4c6e2019-07-01 12:39:00 +0100174- Initial Attestation Service:
Tamas Banc3c08492020-08-27 10:15:42 +0100175 - ``attest_core.c`` : Implements core functionalities such as implementation
176 of APIs, retrieval of claims and token creation.
Laurence Lundbladeb1bfe102019-03-07 11:09:38 -0800177 - ``attest_token_encode.c``: Implements the token creation functions such as
Tamas Bandaa4c6e2019-07-01 12:39:00 +0100178 start and finish token creation and adding claims to the token.
Tamas Banc3c08492020-08-27 10:15:42 +0100179 - ``attest_asymmetric_key.c``: Get the asymmetric attestation key from
180 platform layer and register it to the TF-M Crypto service for further
181 usage.
182 - ``tfm_attest.c``: Implements the SPM abstraction layer, and bind the
183 attestation service to the SPM implementation in TF-M project.
184 - ``tfm_attest_secure_api.c``: Implements the secure API layer to allow
185 other services in the secure domain to request functionalities
Tamas Bandaa4c6e2019-07-01 12:39:00 +0100186 from the attestation service using the PSA API interface.
Tamas Banc3c08492020-08-27 10:15:42 +0100187 - ``tfm_attest_req_mngr.c``: Includes the initialization entry of
Tamas Bandaa4c6e2019-07-01 12:39:00 +0100188 attestation service and handles attestation service requests in IPC
189 model.
David Hu10b66152020-05-29 22:53:13 +0800190 - ``attest_symmetric_key.c``: Get the symmetric initial attestation key
191 from platform layer and register it into TF-M Crypto service for further
192 usage. Also calculate the Instance ID value based on symmetric initial
193 attestation key.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200194
195Service interface definitions
196=============================
197- **Boot loader interface**: The attestation service might include data
198 in the token about the distinct software components in the device. This data
199 is provided by the boot loader and must be encoded in the TLV format,
200 definition is described below in the boot loader interface paragraph. Possible
201 claims in the boot status are describe above in the software components
202 paragraph.
203- **Hardware abstraction layer**:
204 - Headers are located in ``platform/include`` folder.
205 - ``tfm_attest_hal.h``: Expose an API to get the following claims:
206 security lifecycle, verification service indicator, profile definition.
207 - ``tfm_plat_boot_seed.h``: Expose an API to get the boot seed claim.
208 - ``tfm_plat_device_id.h``: Expose an API to get the following claims:
Tamas Banf8863812020-06-09 13:46:04 +0100209 implementation ID, hardware version.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200210- **SPM interface**:
211 - ``attestation.h``: Expose an API to bind attestation service to an SPM
212 implementation.
213- **PSA interface**:
Jamie Foxcc31d402019-01-28 17:13:52 +0000214 - ``psa/initial_attestation.h``: Public API definition of initial
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200215 attestation service.
216- **Crypto interface**:
217 - ``t_cose_crypto.h``: Expose an API to bind the ``t_cose`` implementation
218 to any cryptographic library.
219 - ``tfm_plat_crypto_keys.h``: Expose an API to get the attestation key from
220 platform layer.
221
222PSA interface
223=============
224The TF-M Initial Attestation Service exposes the following PSA
225interface:
226
227.. code-block:: c
228
Raef Coles793574c2019-10-09 10:59:42 +0100229 psa_status_t
Raef Coles70a02da2019-10-09 11:32:04 +0100230 psa_initial_attest_get_token(const uint8_t *auth_challenge,
231 size_t challenge_size,
232 uint8_t *token_buf,
233 size_t token_buf_size,
234 size_t *token_size);
David Vincze20c3e4e2019-11-11 11:16:06 +0100235
Raef Coles793574c2019-10-09 10:59:42 +0100236 psa_status_t
Raef Coles70a02da2019-10-09 11:32:04 +0100237 psa_initial_attest_get_token_size(size_t challenge_size,
238 size_t *token_size);
David Vincze20c3e4e2019-11-11 11:16:06 +0100239
Raef Coles793574c2019-10-09 10:59:42 +0100240 psa_status_t
Summer Qin0e5b2e02020-10-22 11:23:39 +0800241 tfm_initial_attest_get_public_key(uint8_t *public_key,
242 size_t public_key_buf_size,
243 size_t *public_key_len,
244 psa_ecc_family_t *elliptic_curve_type);
David Vincze20c3e4e2019-11-11 11:16:06 +0100245
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200246The caller must allocate a large enough buffer, where the token is going to be
247created by Initial Attestation Service. The size of the created token is highly
248dependent on the number of software components in the system and the provided
249attributes of these. The ``psa_initial_attest_get_token_size()`` function can be
250called to get the exact size of the created token.
251
252System integrators might need to port these interfaces to a custom secure
David Vincze20c3e4e2019-11-11 11:16:06 +0100253partition manager implementation (SPM). Implementations in TF-M project can be
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200254found here:
255
David Vincze20c3e4e2019-11-11 11:16:06 +0100256- ``interface/src/tfm_initial_attestation_func_api.c``: non-secure interface
257 implementation for library model
258- ``interface/src/tfm_initial_attestation_ipc_api.c``: non-secure interface
259 implementation for IPC model
Ken Liu738a4b02020-06-04 14:52:38 +0800260- ``secure_fw/partitions/initial_attestation/tfm_attestation_secure_api.c``:
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200261 secure interface implementation
262
263Secure Partition Manager (SPM) interface
264========================================
265The Initial Attestation Service defines the following interface towards the
266secure partition manager (SPM). System integrators **must** port this interface
267according to their SPM implementation.
268
269.. code:: c
270
271 enum psa_attest_err_t
272 attest_get_boot_data(uint8_t major_type, void *ptr, uint32_t len);
273
274 enum psa_attest_err_t
275 attest_get_caller_client_id(int32_t *caller_id);
276
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200277- ``attest_get_boot_data()``: Service can retrieve the relevant data from shared
278 memory area between boot loader and runtime software. It might be the case
279 that only SPM has direct access to the shared memory area, therefore this
280 function can be used to copy the service related data from shared memory to
281 a local memory buffer. In TF-M implementation this function must be called
282 during service initialization phase, because the shared memory region is
283 deliberately overlapping with secure main stack to spare some memory and reuse
284 this area during execution. If boot loader is not available in the system to
285 provide attributes of software components then this function must be
286 implemented in a way that just initialize service's memory buffer to:
David Vincze20c3e4e2019-11-11 11:16:06 +0100287
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200288 .. code-block:: c
David Vincze20c3e4e2019-11-11 11:16:06 +0100289
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200290 struct shared_data_tlv_header *tlv_header = (struct shared_data_tlv_header *)ptr;
291 tlv_header->tlv_magic = 2016;
292 tlv_header->tlv_tot_len = sizeof(struct shared_data_tlv_header *tlv_header);
293
294- ``attest_get_caller_client_id()``: Retrieves the ID of the caller thread.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200295- ``tfm_client.h``: Service relies on the following external definitions, which
296 must be present or included in this header file:
David Vincze20c3e4e2019-11-11 11:16:06 +0100297
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200298 .. code-block:: c
David Vincze20c3e4e2019-11-11 11:16:06 +0100299
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200300 typedef struct psa_invec {
301 const void *base;
302 size_t len;
303 } psa_invec;
David Vincze20c3e4e2019-11-11 11:16:06 +0100304
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200305 typedef struct psa_outvec {
306 void *base;
307 size_t len;
308 } psa_outvec;
309
310Hardware abstraction layer
311==========================
312The following API definitions are intended to retrieve the platform specific
313claims. System integrators **must** implement these interface according to their
314SoC and software design. Detailed definition of the claims are above
315in the claims in the initial attestation token paragraph.
316
317- ``tfm_attest_hal_get_security_lifecycle()``: Get the security lifecycle of the
318 device.
319- ``tfm_attest_hal_get_verification_service()``: Get the verification
320 service indicator for initial attestation.
321- ``tfm_attest_hal_get_profile_definition()``: Get the name of the profile
322 definition document for initial attestation.
323- ``tfm_plat_get_boot_seed()``: Get the boot seed, which is a constant random
324 number during a boot cycle.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200325- ``tfm_plat_get_implementation_id``: Get the implementation ID of the
326 device.
327- ``tfm_plat_get_hw_version``: Get the hardware version of the device.
328
329Boot loader interface
330=====================
331It is **recommended** to have a secure boot loader in the boot chain, which is
332capable of measuring the runtime firmware components (calculates the hash value
333of firmware images) and provide other attributes of these (version, type, etc).
David Vinczee13a48b2020-01-08 17:42:30 +0100334If the used boot loader is not capable of sharing these information with the
335runtime software then the ``BOOT_DATA_AVAILABLE`` compiler flag **must** be
Balint Matyi9272a432020-06-02 07:27:26 +0100336set to OFF (see `Related compile time options`_).
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200337
338The shared data between boot loader and runtime software is TLV encoded. The
339definition of TLV structure is described in ``bl2/include/tfm_boot_status.h``.
340The shared data is stored in a well known location in secure internal memory
341and this is a contract between boot loader and runtime SW.
342
343The structure of shared data must be the following:
344
345- At the beginning there must be a header: ``struct shared_data_tlv_header``
346 This contains a magic number and a size field which covers the entire size
347 of the shared data area including this header.
David Vincze20c3e4e2019-11-11 11:16:06 +0100348
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200349 .. code-block:: c
David Vincze20c3e4e2019-11-11 11:16:06 +0100350
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200351 struct shared_data_tlv_header {
352 uint16_t tlv_magic;
353 uint16_t tlv_tot_len;
354 };
David Vincze20c3e4e2019-11-11 11:16:06 +0100355
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200356- After the header there come the entries which are composed from an
357 entry header structure: ``struct shared_data_tlv_entry`` and the data. In
358 the entry header is a type field ``tlv_type`` which identify the consumer of
359 the entry in the runtime software and specify the subtype of that data item.
David Vincze53998032020-06-10 15:54:31 +0200360
361 .. Note::
362
363 There is a size field ``tlv_len`` which has different definitions in the
364 upstream MCUboot repository and in its TF-M forked version:
365
366 - Upstream MCUboot: Covers only the length of data but not the header
367 size.
368 - TF-M MCUboot: Covers the size of the entry header and the data
369 together.
370
371 This difference is handled by TF-M code based on which bootloader is used
372 along with TF-M runtime.
373
374 After the entry header structure comes the actual data.
David Vincze20c3e4e2019-11-11 11:16:06 +0100375
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200376 .. code-block:: c
David Vincze20c3e4e2019-11-11 11:16:06 +0100377
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200378 struct shared_data_tlv_entry {
379 uint16_t tlv_type;
380 uint16_t tlv_len;
381 };
David Vincze20c3e4e2019-11-11 11:16:06 +0100382
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200383- Arbitrary number and size of data entry can be in the shared memory
384 area.
385
386The figure below gives of overview about the ``tlv_type`` field in the entry
387header. The ``tlv_type`` always composed from a major and minorbnumber. Major
388number identifies the addressee in runtime software, which the databentry is
389sent to. Minor number used to encode more info about the data entry. The actual
390definition of minor number could change per major number. In case of boot
391status data, which is going to be processed by initial attestation service
392the minor number is split further to two part: ``sw_module`` and ``claim``. The
393``sw_module`` identifies the SW component in the system which the data item
394belongs to and the ``claim`` part identifies the exact type of the data.
395
396``tlv_type`` description::
397
398 |------------------------------------------------ |
399 | tlv_type (16 bits) |
400 |-------------------------------------------------|
401 | tlv_major(4 bits) | tlv_minor(12 bits) |
402 |-------------------------------------------------|
403 | MAJOR_IAS | sw_module(6 bits) | claim(6 bits) |
404 |-------------------------------------------------|
405 | MAJOR_CORE | TBD |
406 |-------------------------------------------------|
407
408Overall structure of shared data::
409
410 ---------------------------------------------------------------
411 | Magic number(uint16_t) | Shared data total length(uint16_t) |
412 ---------------------------------------------------------------
413 | Major_type(4 bits) | Minor_type(12 bits) | Length(uint16_t) |
414 ---------------------------------------------------------------
415 | Raw data |
416 ---------------------------------------------------------------
417 | . |
418 | . |
419 | . |
420 ---------------------------------------------------------------
421 | Major_type(4 bits) | Minor_type(12 bits) | Length(uint16_t) |
422 ---------------------------------------------------------------
423 | Raw data |
424 ---------------------------------------------------------------
425
426Crypto interface
427================
David Hu10b66152020-05-29 22:53:13 +0800428
429Asymmetric key algorithm based attestation
430------------------------------------------
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200431Device **must** contain an asymmetric key pair. The private part of it is used
432to sign the initial attestation token. Current implementation supports only the
433ECDSA P256 signature over SHA256. The public part of the key pair is used to
434create the key identifier (kid) in the unprotected part of the COSE header. The
435kid is used by verification entity to look up the corresponding public key to
436verify the signature in the token. The `t_cose` part of the initial attestation
437service implements the signature generation and kid creation. But the actual
438calculation of token's hash and signature is done by the Crypto service in the
439device. System integrators might need to re-implement the following functions
440if they want to use initial attestation service with a different cryptographic
441library than Crypto service:
442
443- ``t_cose_crypto_pub_key_sign()``: Calculates the signature over a hash value.
444- ``t_cose_crypto_get_ec_pub_key()``: Get the public key to create the key
445 identifier.
446- ``t_cose_crypto_hash_start()``: Start a multipart hash operation.
447- ``t_cose_crypto_hash_update()``: Add a message fragment to a multipart hash
448 operation.
449- ``t_cose_crypto_hash_finish()``:Finish the calculation of the hash of a
450 message.
451
452Interface needed by verification code:
453
454- ``t_cose_crypto_pub_key_verify()``: Verify the signature over a hash value.
455
456Key handling
David Hu10b66152020-05-29 22:53:13 +0800457^^^^^^^^^^^^
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200458The provisioning of the initial attestation key is out of scope of the service
459and this document. It is assumed that device maker provisions the unique
460asymmetric key pair during the manufacturing process. The following API is
461defined to retrieve the attestation key pair from platform layer. Software
462integrators **must** port this interface according to their SoC design and make
463sure that key pair is available by Crypto service:
464
465- ``tfm_plat_get_initial_attest_key()``: Retrieve the initial attestation key
466 pair from platform layer.
467
468In TF-M project the attestation key is retrieved by initial attestation service.
469The key is registered and unregistered to the Crypto service by attestation
470service with ``psa_import_key()`` and ``psa_destroy_key()`` API calls for
471further usage. See in ``attestation_key.c``. In other implementation if the
472attestation key is directly retrieved by the Crypto service then this key
473handling is not necessary.
474
David Hu10b66152020-05-29 22:53:13 +0800475Symmetric key algorithm based attestation
476-----------------------------------------
477Device **must** contain a symmetric key to generate the authentication tag of
478the initial attestation token. A key identifier (kid) can be encoded in the
479unprotected part of the COSE header. It helps verification entity look up the
480symmetric key to verify the authentication tag in the token.
481
482The `t_cose` part of the initial attestation service implements the
483authentication tag generation. The authentication tag generation is done by the
484Crypto service. System integrators might need to re-implement the following
485functions if platforms provide a different cryptographic library than Crypto
486service:
487
488- ``t_cose_crypto_hmac_sign_setup()``: Set up a multi-part HMAC calculation
489 operation.
490- ``t_cose_crypto_hmac_update()``: Add a message fragment to a multi-part HMAC
491 operation.
492- ``t_cose_crypto_hmac_sign_finish()``: Finish the calculation of the HMAC of a
493 message.
494
495Interface needed by verification code:
496
497- ``t_cose_crypto_hmac_verify_setup()``: Set up a multi-part HMAC verification
498 operation.
499- ``t_cose_crypto_hmac_verify_finish()``: Finish the verification of the HMAC of
500 a message.
501
502It also requires the same hash operations as listed in asymmetric key algorithm
503based initial attestation above, in attestation test cases.
504
505Key handling
506^^^^^^^^^^^^
507The provisioning of the initial attestation key is out of scope of the service
508and this document. It is assumed that device maker provisions the symmetric key
509during the manufacturing process. The following API is defined to retrieve the
510symmetric attestation key from platform layer. Software integrators **must**
511port this interface according to their SoC design and make sure that key is
512available by Crypto service:
513
514- ``tfm_plat_get_symmetric_iak()``: Get the symmetric initial attestation key
515 raw data.
516- ``tfm_plat_get_symmetric_iak_id()``: Get the key identifier of the symmetric
517 initial attestation key. The key identifier can be used as ``kid`` parameter
518 in COSE header. Optional.
519
520.. note:
521
522 Asymmetric initial attestation and symmetric initial attestation may share
523 the same HAL APIs in future development.
524
Tamas Ban01f64c52019-08-26 13:46:21 +0100525Initial Attestation Service compile time options
526================================================
527There is a defined set of flags that can be used to compile in/out certain
528service features. The ``CommonConfig.cmake`` file sets the default values of
529those flags. The list of flags are:
530
531- ``ATTEST_INCLUDE_OPTIONAL_CLAIMS``: Include also the optional claims to the
Balint Matyi9272a432020-06-02 07:27:26 +0100532 attestation token. Default value: ON.
Tamas Banabea89d2020-01-15 13:29:25 +0000533- ``ATTEST_INCLUDE_TEST_CODE``: Test code is removed from COSE library and from
Balint Matyi9272a432020-06-02 07:27:26 +0100534 attestation test suite if it is OFF. Its default value depends on the build
535 type. It is ON if build type is ``Debug``, otherwise OFF (different kinds
Tamas Banabea89d2020-01-15 13:29:25 +0000536 of ``Release`` builds).
537- ``ATTEST_INCLUDE_COSE_KEY_ID``: COSE key-id is an optional field in the COSE
538 unprotected header. Key-id is calculated and added to the COSE header based
Balint Matyi9272a432020-06-02 07:27:26 +0100539 on the value of this flag. Default value: OFF.
Balint Matyi95f58eb2020-05-22 08:52:32 +0100540- ``ATTEST_CLAIM_VALUE_CHECK``: Check attestation claims against hard-coded
541 values found in ``platform/ext/common/template/attest_hal.c``. Default value
542 is OFF. Set to ON in a platform's CMake file if the attest HAL is not yet
543 properly ported to it.
David Hu10b66152020-05-29 22:53:13 +0800544- ``SYMMETRIC_INITIAL_ATTESTATION``: Select symmetric initial attestation.
545 Default value: OFF.
Tamas Ban01f64c52019-08-26 13:46:21 +0100546
David Vinczee13a48b2020-01-08 17:42:30 +0100547Related compile time options
548----------------------------
549- ``BOOT_DATA_AVAILABLE``: The boot data is expected to be present in the shared
Balint Matyi9272a432020-06-02 07:27:26 +0100550 data area between the boot loader and the runtime firmware when it's ON.
551 Otherwise, when it's OFF does not check the content of the shared data area.
David Vinczee13a48b2020-01-08 17:42:30 +0100552 Also assume that the TLV header is present and valid (the magic number is
553 correct) and there are no other data entries. Its default value depends on
554 the BL2 flag.
555
Tamas Banff3bb582020-06-09 14:18:35 +0100556***************************************************************************
557Comparison of asymmetric and symmetric algorithm based token authentication
558***************************************************************************
559The symmetric key based authentication requires a more complex infrastructure
560for key management. Symmetric keys must be kept secret because they are
561sensitive asset, like the private key in case of asymmetric cryptographic
562algorithms. The main difference is that private keys are only stored on
563device, with proper hardware protection against external access, but symmetric
564keys must be known by both party (device and verifier), so they must also be
565stored in a central server of a relying party (who verifies the tokens).
566If keys are revealed then devices can be impersonated. If the database with
567the symmetric keys becomes compromised then all corresponding devices become
568untrusted. Since a centralised database of symmetric keys may need to be network
569connected, this can be considered to be a valuable target for attackers. The
570advantage of ECDSA based token authentication is that sensitive assets is only
571stored one place (in the device) and only one unique key per device. So if a
572device is compromised then only that single device become untrusted. In this
573case, the database of the relying party contains the corresponding public keys,
574which are not considered to be a confidential assets, so they can be shared with
575anybody. This shows the main advantage of asymmetric based authentication,
576because verification of attestation tokens can be done by a third party,
577such as cloud service providers (CSP). Thus Device Maker (DM) or Chip Maker (CM)
578does not need to operate such a service.
579
580+-------------------------+-----------------------------------------+-----------------------------------------+
581| | Symmetric | Asymmetric |
582+=========================+=========================================+=========================================+
583| Authentication mode | HMAC over SHA256 | ECDSA P256 over SHA256 |
584+-------------------------+-----------------------------------------+-----------------------------------------+
585| Supported APIs | - psa_initial_attest_get_token(..) | - psa_initial_attest_get_token(..) |
586| | - psa_initial_attest_get_token_size(..) | - psa_initial_attest_get_token_size(..) |
587| | | - tfm_initial_attest_get_public_key(..) |
588+-------------------------+-----------------------------------------+-----------------------------------------+
589| Crypto key type in HW | Symmetric key | ECDSA private key (secp256r1) |
590+-------------------------+-----------------------------------------+-----------------------------------------+
591| Secrets are stored | Device and database | Device only |
592+-------------------------+-----------------------------------------+-----------------------------------------+
593| Verification database | Same symmetric key | Public keys |
594| contains | | |
595+-------------------------+-----------------------------------------+-----------------------------------------+
596| COSE authentication tag | COSE_Mac0 | COSE_Sign1 |
597| in the token | | |
598+-------------------------+-----------------------------------------+-----------------------------------------+
599| Verification entity | CM or DM, who provisioned the | Can be anybody: third party provisioning|
600| | symmetric key | service, cloud service provider, CM, DM |
601+-------------------------+-----------------------------------------+-----------------------------------------+
602
Tamas Bandaa4c6e2019-07-01 12:39:00 +0100603************
604Verification
605************
606The initial attestation token is verified by the attestation test suite in
607``test/suites/attestation``. The test suite is responsible for verifying the
608token signature and parsing the token to verify its encoding and the presence of
609the mandatory claims. This test suite can be executed on the device. It is part
610of the regression test suite. When the user builds TF-M with any of the
611``ConfigRegression*.cmake`` configurations then this test is executed
612automatically. The test suite is configurable in the
613``test/suites/attestation/attest_token_test_values.h`` header file. In this file
614there are two attributes for each claim which are configurable (more details
615in the header file):
616
617 - Requirements of presence: optional or mandatory
618 - Expected value: Value check can be disabled or expected value can be provided
619 here.
620
621There is another possibility to verify the attestation token. This addresses
622the off-device testing when the token is already retrieved from the device and
623verification is done on the requester side. There is a Python script for this
624purpose in ``tools/iat-verifier``. It does the same checking as the
625attestation test suite. The following steps describe how to simulate an
626off-device token verification on a host computer. It is described how to
627retrieve an initial attestation token when TF-M code is executed on FVP
628and how to use the iat_verifier script to check the token. This example assumes
629that user has license for DS-5 and FVP models:
630
631 - Build TF-M with any of the ``ConfigRegression*.cmake`` build configurations
632 for MPS2 AN521 platform. More info in
Minos Galanakise4094012020-06-12 14:25:34 +0100633 :doc:`tfm_build_instruction </docs/getting_started/tfm_build_instruction>`.
Tamas Bandaa4c6e2019-07-01 12:39:00 +0100634 - Lunch FVP model in DS-5. More info in
Minos Galanakise4094012020-06-12 14:25:34 +0100635 :doc:`tfm_user_guide </docs/getting_started/tfm_user_guide>`.
Tamas Bandaa4c6e2019-07-01 12:39:00 +0100636 - Set a breakpoint in ``test/suites/attestation/attest_token_test.c``
637 in ``decode_test_internal(..)`` after the ``token_main_alt(..)`` returned,
638 i.e. on line 859. Execute the code in the model until the breakpoint hits
David Hu10b66152020-05-29 22:53:13 +0800639 second time. At this point the console prints the test case name:
640
641 - For asymmetric initial attestation, the console prints
642 ``ECDSA signature test of attest token``.
643 - For symmetric initial attestation, the console prints
644 ``Symmetric key algorithm based Initial Attestation test``.
645
Tamas Bandaa4c6e2019-07-01 12:39:00 +0100646 - At this point the token resides in the model memory and can be dumped to host
647 computer.
648 - The ADDRESS and SIZE attributes of the initial attestation token is stored in
649 the ``completed_token`` local variable. Their value can be extracted in the
650 ``(x)=Variables`` debug window.
David Hu10b66152020-05-29 22:53:13 +0800651 - Apply commands below in the ``Commands`` debug window to dump the token in
Tamas Bandaa4c6e2019-07-01 12:39:00 +0100652 binary format to the host computer:
David Hu10b66152020-05-29 22:53:13 +0800653
654 - For asymmetric initial attestation
655 ``dump memory <PATH>/iat_01.cbor <ADDRESS> +<SIZE>``
656 - For symmetric initial attestation
657 ``dump memory <PATH>/iat_hmac_02.cbor <ADDRESS> +<SIZE>``
658
659 - Execute commands below on the host computer to verify the token:
660
661 - For asymmetric initial attestation
662 ``check_iat -p -K -k platform/ext/common/template/tfm_initial_attestation_key.pem <PATH>/iat_01.cbor``
663 - For symmetric initial attestation
664 ``check_iat -m mac -p -K -k platform/ext/common/template/tfm_symmetric_iak.key <PATH>/iat_hmac_02.cbor``
665
Tamas Bandaa4c6e2019-07-01 12:39:00 +0100666 - Documentation of the iat-verifier can be found
667 :doc:`here </tools/iat-verifier/README>`.
668
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200669--------------
670
Tamas Banabea89d2020-01-15 13:29:25 +0000671*Copyright (c) 2018-2020, Arm Limited. All rights reserved.*