blob: c5c45237c5b0853951ae759d504fbaad0d1830f1 [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
76 the verification process. Such details include the implementations origin
77 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.
156 It can be used on 32-bit and 64-bit machines. It was designed to suite
157 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:
164 - ``lib/t_cose``: This library is used to sign a CBOR token and create
165 the COSE header and signature around the initial attestation token. Only
166 a subset of the `COSE <https://tools.ietf.org/html/rfc8152>`__ standard
167 is implemented. Only the cose_sign1 signature schema is supported.
168 - ``lib/t_cose/src/t_cose_crypto.h``: Expose an API to bind ``t_cose``
169 library with available crypto library in the device.
170 - ``lib/t_cose/src/t_cose_psa_crypto.c``: Implements the exposed API
Jamie Foxcc31d402019-01-28 17:13:52 +0000171 and ports ``t_cose`` to the PSA Crypto API.
Tamas Bandaa4c6e2019-07-01 12:39:00 +0100172- Initial Attestation Service:
173 - ``attestation_core.c`` : Implements core functionalities such as
174 implementation of APIs, retrieval of claims and token creation.
175 - ``attest_token.c``: Implements the token creation function such as
176 start and finish token creation and adding claims to the token.
David Hu10b66152020-05-29 22:53:13 +0800177 - ``attestation_key.c``: Get the asymmetric attestation key from platform
178 layer and register it to the TF-M Crypto service for further usage.
Tamas Bandaa4c6e2019-07-01 12:39:00 +0100179 - ``tfm_attestation.c``: Implements the SPM abstraction layer, and bind
180 the attestation service to the SPM implementation in TF-M project.
181 - ``tfm_attestation_secure_api.c``: Implements the secure API layer to
182 allow other services in the secure domain to request functionalities
183 from the attestation service using the PSA API interface.
184 - ``tfm_attestation_req_mngr.c``: Includes the initialization entry of
185 attestation service and handles attestation service requests in IPC
186 model.
David Hu10b66152020-05-29 22:53:13 +0800187 - ``attest_symmetric_key.c``: Get the symmetric initial attestation key
188 from platform layer and register it into TF-M Crypto service for further
189 usage. Also calculate the Instance ID value based on symmetric initial
190 attestation key.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200191
192Service interface definitions
193=============================
194- **Boot loader interface**: The attestation service might include data
195 in the token about the distinct software components in the device. This data
196 is provided by the boot loader and must be encoded in the TLV format,
197 definition is described below in the boot loader interface paragraph. Possible
198 claims in the boot status are describe above in the software components
199 paragraph.
200- **Hardware abstraction layer**:
201 - Headers are located in ``platform/include`` folder.
202 - ``tfm_attest_hal.h``: Expose an API to get the following claims:
203 security lifecycle, verification service indicator, profile definition.
204 - ``tfm_plat_boot_seed.h``: Expose an API to get the boot seed claim.
205 - ``tfm_plat_device_id.h``: Expose an API to get the following claims:
206 implementation ID, hardware version, instance ID.
207- **SPM interface**:
208 - ``attestation.h``: Expose an API to bind attestation service to an SPM
209 implementation.
210- **PSA interface**:
Jamie Foxcc31d402019-01-28 17:13:52 +0000211 - ``psa/initial_attestation.h``: Public API definition of initial
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200212 attestation service.
213- **Crypto interface**:
214 - ``t_cose_crypto.h``: Expose an API to bind the ``t_cose`` implementation
215 to any cryptographic library.
216 - ``tfm_plat_crypto_keys.h``: Expose an API to get the attestation key from
217 platform layer.
218
219PSA interface
220=============
221The TF-M Initial Attestation Service exposes the following PSA
222interface:
223
224.. code-block:: c
225
Raef Coles793574c2019-10-09 10:59:42 +0100226 psa_status_t
Raef Coles70a02da2019-10-09 11:32:04 +0100227 psa_initial_attest_get_token(const uint8_t *auth_challenge,
228 size_t challenge_size,
229 uint8_t *token_buf,
230 size_t token_buf_size,
231 size_t *token_size);
David Vincze20c3e4e2019-11-11 11:16:06 +0100232
Raef Coles793574c2019-10-09 10:59:42 +0100233 psa_status_t
Raef Coles70a02da2019-10-09 11:32:04 +0100234 psa_initial_attest_get_token_size(size_t challenge_size,
235 size_t *token_size);
David Vincze20c3e4e2019-11-11 11:16:06 +0100236
Raef Coles793574c2019-10-09 10:59:42 +0100237 psa_status_t
David Vincze20c3e4e2019-11-11 11:16:06 +0100238 tfm_initial_attest_get_public_key(uint8_t *public_key,
239 size_t public_key_buf_size,
240 size_t *public_key_len,
241 psa_ecc_curve_t *elliptic_curve_type);
242
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200243The caller must allocate a large enough buffer, where the token is going to be
244created by Initial Attestation Service. The size of the created token is highly
245dependent on the number of software components in the system and the provided
246attributes of these. The ``psa_initial_attest_get_token_size()`` function can be
247called to get the exact size of the created token.
248
249System integrators might need to port these interfaces to a custom secure
David Vincze20c3e4e2019-11-11 11:16:06 +0100250partition manager implementation (SPM). Implementations in TF-M project can be
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200251found here:
252
David Vincze20c3e4e2019-11-11 11:16:06 +0100253- ``interface/src/tfm_initial_attestation_func_api.c``: non-secure interface
254 implementation for library model
255- ``interface/src/tfm_initial_attestation_ipc_api.c``: non-secure interface
256 implementation for IPC model
Ken Liu738a4b02020-06-04 14:52:38 +0800257- ``secure_fw/partitions/initial_attestation/tfm_attestation_secure_api.c``:
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200258 secure interface implementation
259
260Secure Partition Manager (SPM) interface
261========================================
262The Initial Attestation Service defines the following interface towards the
263secure partition manager (SPM). System integrators **must** port this interface
264according to their SPM implementation.
265
266.. code:: c
267
268 enum psa_attest_err_t
269 attest_get_boot_data(uint8_t major_type, void *ptr, uint32_t len);
270
271 enum psa_attest_err_t
272 attest_get_caller_client_id(int32_t *caller_id);
273
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200274- ``attest_get_boot_data()``: Service can retrieve the relevant data from shared
275 memory area between boot loader and runtime software. It might be the case
276 that only SPM has direct access to the shared memory area, therefore this
277 function can be used to copy the service related data from shared memory to
278 a local memory buffer. In TF-M implementation this function must be called
279 during service initialization phase, because the shared memory region is
280 deliberately overlapping with secure main stack to spare some memory and reuse
281 this area during execution. If boot loader is not available in the system to
282 provide attributes of software components then this function must be
283 implemented in a way that just initialize service's memory buffer to:
David Vincze20c3e4e2019-11-11 11:16:06 +0100284
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200285 .. code-block:: c
David Vincze20c3e4e2019-11-11 11:16:06 +0100286
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200287 struct shared_data_tlv_header *tlv_header = (struct shared_data_tlv_header *)ptr;
288 tlv_header->tlv_magic = 2016;
289 tlv_header->tlv_tot_len = sizeof(struct shared_data_tlv_header *tlv_header);
290
291- ``attest_get_caller_client_id()``: Retrieves the ID of the caller thread.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200292- ``tfm_client.h``: Service relies on the following external definitions, which
293 must be present or included in this header file:
David Vincze20c3e4e2019-11-11 11:16:06 +0100294
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200295 .. code-block:: c
David Vincze20c3e4e2019-11-11 11:16:06 +0100296
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200297 typedef struct psa_invec {
298 const void *base;
299 size_t len;
300 } psa_invec;
David Vincze20c3e4e2019-11-11 11:16:06 +0100301
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200302 typedef struct psa_outvec {
303 void *base;
304 size_t len;
305 } psa_outvec;
306
307Hardware abstraction layer
308==========================
309The following API definitions are intended to retrieve the platform specific
310claims. System integrators **must** implement these interface according to their
311SoC and software design. Detailed definition of the claims are above
312in the claims in the initial attestation token paragraph.
313
314- ``tfm_attest_hal_get_security_lifecycle()``: Get the security lifecycle of the
315 device.
316- ``tfm_attest_hal_get_verification_service()``: Get the verification
317 service indicator for initial attestation.
318- ``tfm_attest_hal_get_profile_definition()``: Get the name of the profile
319 definition document for initial attestation.
320- ``tfm_plat_get_boot_seed()``: Get the boot seed, which is a constant random
321 number during a boot cycle.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200322- ``tfm_plat_get_implementation_id``: Get the implementation ID of the
323 device.
324- ``tfm_plat_get_hw_version``: Get the hardware version of the device.
325
326Boot loader interface
327=====================
328It is **recommended** to have a secure boot loader in the boot chain, which is
329capable of measuring the runtime firmware components (calculates the hash value
330of firmware images) and provide other attributes of these (version, type, etc).
David Vinczee13a48b2020-01-08 17:42:30 +0100331If the used boot loader is not capable of sharing these information with the
332runtime software then the ``BOOT_DATA_AVAILABLE`` compiler flag **must** be
Balint Matyi9272a432020-06-02 07:27:26 +0100333set to OFF (see `Related compile time options`_).
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200334
335The shared data between boot loader and runtime software is TLV encoded. The
336definition of TLV structure is described in ``bl2/include/tfm_boot_status.h``.
337The shared data is stored in a well known location in secure internal memory
338and this is a contract between boot loader and runtime SW.
339
340The structure of shared data must be the following:
341
342- At the beginning there must be a header: ``struct shared_data_tlv_header``
343 This contains a magic number and a size field which covers the entire size
344 of the shared data area including this header.
David Vincze20c3e4e2019-11-11 11:16:06 +0100345
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200346 .. code-block:: c
David Vincze20c3e4e2019-11-11 11:16:06 +0100347
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200348 struct shared_data_tlv_header {
349 uint16_t tlv_magic;
350 uint16_t tlv_tot_len;
351 };
David Vincze20c3e4e2019-11-11 11:16:06 +0100352
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200353- After the header there come the entries which are composed from an
354 entry header structure: ``struct shared_data_tlv_entry`` and the data. In
355 the entry header is a type field ``tlv_type`` which identify the consumer of
356 the entry in the runtime software and specify the subtype of that data item.
357 There is a size field ``tlv_len`` which covers the size of the entry header
358 and the data. After this structure comes the actual data.
David Vincze20c3e4e2019-11-11 11:16:06 +0100359
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200360 .. code-block:: c
David Vincze20c3e4e2019-11-11 11:16:06 +0100361
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200362 struct shared_data_tlv_entry {
363 uint16_t tlv_type;
364 uint16_t tlv_len;
365 };
David Vincze20c3e4e2019-11-11 11:16:06 +0100366
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200367- Arbitrary number and size of data entry can be in the shared memory
368 area.
369
370The figure below gives of overview about the ``tlv_type`` field in the entry
371header. The ``tlv_type`` always composed from a major and minorbnumber. Major
372number identifies the addressee in runtime software, which the databentry is
373sent to. Minor number used to encode more info about the data entry. The actual
374definition of minor number could change per major number. In case of boot
375status data, which is going to be processed by initial attestation service
376the minor number is split further to two part: ``sw_module`` and ``claim``. The
377``sw_module`` identifies the SW component in the system which the data item
378belongs to and the ``claim`` part identifies the exact type of the data.
379
380``tlv_type`` description::
381
382 |------------------------------------------------ |
383 | tlv_type (16 bits) |
384 |-------------------------------------------------|
385 | tlv_major(4 bits) | tlv_minor(12 bits) |
386 |-------------------------------------------------|
387 | MAJOR_IAS | sw_module(6 bits) | claim(6 bits) |
388 |-------------------------------------------------|
389 | MAJOR_CORE | TBD |
390 |-------------------------------------------------|
391
392Overall structure of shared data::
393
394 ---------------------------------------------------------------
395 | Magic number(uint16_t) | Shared data total length(uint16_t) |
396 ---------------------------------------------------------------
397 | Major_type(4 bits) | Minor_type(12 bits) | Length(uint16_t) |
398 ---------------------------------------------------------------
399 | Raw data |
400 ---------------------------------------------------------------
401 | . |
402 | . |
403 | . |
404 ---------------------------------------------------------------
405 | Major_type(4 bits) | Minor_type(12 bits) | Length(uint16_t) |
406 ---------------------------------------------------------------
407 | Raw data |
408 ---------------------------------------------------------------
409
410Crypto interface
411================
David Hu10b66152020-05-29 22:53:13 +0800412
413Asymmetric key algorithm based attestation
414------------------------------------------
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200415Device **must** contain an asymmetric key pair. The private part of it is used
416to sign the initial attestation token. Current implementation supports only the
417ECDSA P256 signature over SHA256. The public part of the key pair is used to
418create the key identifier (kid) in the unprotected part of the COSE header. The
419kid is used by verification entity to look up the corresponding public key to
420verify the signature in the token. The `t_cose` part of the initial attestation
421service implements the signature generation and kid creation. But the actual
422calculation of token's hash and signature is done by the Crypto service in the
423device. System integrators might need to re-implement the following functions
424if they want to use initial attestation service with a different cryptographic
425library than Crypto service:
426
427- ``t_cose_crypto_pub_key_sign()``: Calculates the signature over a hash value.
428- ``t_cose_crypto_get_ec_pub_key()``: Get the public key to create the key
429 identifier.
430- ``t_cose_crypto_hash_start()``: Start a multipart hash operation.
431- ``t_cose_crypto_hash_update()``: Add a message fragment to a multipart hash
432 operation.
433- ``t_cose_crypto_hash_finish()``:Finish the calculation of the hash of a
434 message.
435
436Interface needed by verification code:
437
438- ``t_cose_crypto_pub_key_verify()``: Verify the signature over a hash value.
439
440Key handling
David Hu10b66152020-05-29 22:53:13 +0800441^^^^^^^^^^^^
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200442The provisioning of the initial attestation key is out of scope of the service
443and this document. It is assumed that device maker provisions the unique
444asymmetric key pair during the manufacturing process. The following API is
445defined to retrieve the attestation key pair from platform layer. Software
446integrators **must** port this interface according to their SoC design and make
447sure that key pair is available by Crypto service:
448
449- ``tfm_plat_get_initial_attest_key()``: Retrieve the initial attestation key
450 pair from platform layer.
451
452In TF-M project the attestation key is retrieved by initial attestation service.
453The key is registered and unregistered to the Crypto service by attestation
454service with ``psa_import_key()`` and ``psa_destroy_key()`` API calls for
455further usage. See in ``attestation_key.c``. In other implementation if the
456attestation key is directly retrieved by the Crypto service then this key
457handling is not necessary.
458
David Hu10b66152020-05-29 22:53:13 +0800459Symmetric key algorithm based attestation
460-----------------------------------------
461Device **must** contain a symmetric key to generate the authentication tag of
462the initial attestation token. A key identifier (kid) can be encoded in the
463unprotected part of the COSE header. It helps verification entity look up the
464symmetric key to verify the authentication tag in the token.
465
466The `t_cose` part of the initial attestation service implements the
467authentication tag generation. The authentication tag generation is done by the
468Crypto service. System integrators might need to re-implement the following
469functions if platforms provide a different cryptographic library than Crypto
470service:
471
472- ``t_cose_crypto_hmac_sign_setup()``: Set up a multi-part HMAC calculation
473 operation.
474- ``t_cose_crypto_hmac_update()``: Add a message fragment to a multi-part HMAC
475 operation.
476- ``t_cose_crypto_hmac_sign_finish()``: Finish the calculation of the HMAC of a
477 message.
478
479Interface needed by verification code:
480
481- ``t_cose_crypto_hmac_verify_setup()``: Set up a multi-part HMAC verification
482 operation.
483- ``t_cose_crypto_hmac_verify_finish()``: Finish the verification of the HMAC of
484 a message.
485
486It also requires the same hash operations as listed in asymmetric key algorithm
487based initial attestation above, in attestation test cases.
488
489Key handling
490^^^^^^^^^^^^
491The provisioning of the initial attestation key is out of scope of the service
492and this document. It is assumed that device maker provisions the symmetric key
493during the manufacturing process. The following API is defined to retrieve the
494symmetric attestation key from platform layer. Software integrators **must**
495port this interface according to their SoC design and make sure that key is
496available by Crypto service:
497
498- ``tfm_plat_get_symmetric_iak()``: Get the symmetric initial attestation key
499 raw data.
500- ``tfm_plat_get_symmetric_iak_id()``: Get the key identifier of the symmetric
501 initial attestation key. The key identifier can be used as ``kid`` parameter
502 in COSE header. Optional.
503
504.. note:
505
506 Asymmetric initial attestation and symmetric initial attestation may share
507 the same HAL APIs in future development.
508
Tamas Ban01f64c52019-08-26 13:46:21 +0100509Initial Attestation Service compile time options
510================================================
511There is a defined set of flags that can be used to compile in/out certain
512service features. The ``CommonConfig.cmake`` file sets the default values of
513those flags. The list of flags are:
514
515- ``ATTEST_INCLUDE_OPTIONAL_CLAIMS``: Include also the optional claims to the
Balint Matyi9272a432020-06-02 07:27:26 +0100516 attestation token. Default value: ON.
Tamas Banabea89d2020-01-15 13:29:25 +0000517- ``ATTEST_INCLUDE_TEST_CODE``: Test code is removed from COSE library and from
Balint Matyi9272a432020-06-02 07:27:26 +0100518 attestation test suite if it is OFF. Its default value depends on the build
519 type. It is ON if build type is ``Debug``, otherwise OFF (different kinds
Tamas Banabea89d2020-01-15 13:29:25 +0000520 of ``Release`` builds).
521- ``ATTEST_INCLUDE_COSE_KEY_ID``: COSE key-id is an optional field in the COSE
522 unprotected header. Key-id is calculated and added to the COSE header based
Balint Matyi9272a432020-06-02 07:27:26 +0100523 on the value of this flag. Default value: OFF.
Balint Matyi95f58eb2020-05-22 08:52:32 +0100524- ``ATTEST_CLAIM_VALUE_CHECK``: Check attestation claims against hard-coded
525 values found in ``platform/ext/common/template/attest_hal.c``. Default value
526 is OFF. Set to ON in a platform's CMake file if the attest HAL is not yet
527 properly ported to it.
David Hu10b66152020-05-29 22:53:13 +0800528- ``SYMMETRIC_INITIAL_ATTESTATION``: Select symmetric initial attestation.
529 Default value: OFF.
Tamas Ban01f64c52019-08-26 13:46:21 +0100530
David Vinczee13a48b2020-01-08 17:42:30 +0100531Related compile time options
532----------------------------
533- ``BOOT_DATA_AVAILABLE``: The boot data is expected to be present in the shared
Balint Matyi9272a432020-06-02 07:27:26 +0100534 data area between the boot loader and the runtime firmware when it's ON.
535 Otherwise, when it's OFF does not check the content of the shared data area.
David Vinczee13a48b2020-01-08 17:42:30 +0100536 Also assume that the TLV header is present and valid (the magic number is
537 correct) and there are no other data entries. Its default value depends on
538 the BL2 flag.
539
Tamas Bandaa4c6e2019-07-01 12:39:00 +0100540************
541Verification
542************
543The initial attestation token is verified by the attestation test suite in
544``test/suites/attestation``. The test suite is responsible for verifying the
545token signature and parsing the token to verify its encoding and the presence of
546the mandatory claims. This test suite can be executed on the device. It is part
547of the regression test suite. When the user builds TF-M with any of the
548``ConfigRegression*.cmake`` configurations then this test is executed
549automatically. The test suite is configurable in the
550``test/suites/attestation/attest_token_test_values.h`` header file. In this file
551there are two attributes for each claim which are configurable (more details
552in the header file):
553
554 - Requirements of presence: optional or mandatory
555 - Expected value: Value check can be disabled or expected value can be provided
556 here.
557
558There is another possibility to verify the attestation token. This addresses
559the off-device testing when the token is already retrieved from the device and
560verification is done on the requester side. There is a Python script for this
561purpose in ``tools/iat-verifier``. It does the same checking as the
562attestation test suite. The following steps describe how to simulate an
563off-device token verification on a host computer. It is described how to
564retrieve an initial attestation token when TF-M code is executed on FVP
565and how to use the iat_verifier script to check the token. This example assumes
566that user has license for DS-5 and FVP models:
567
568 - Build TF-M with any of the ``ConfigRegression*.cmake`` build configurations
569 for MPS2 AN521 platform. More info in
Minos Galanakise4094012020-06-12 14:25:34 +0100570 :doc:`tfm_build_instruction </docs/getting_started/tfm_build_instruction>`.
Tamas Bandaa4c6e2019-07-01 12:39:00 +0100571 - Lunch FVP model in DS-5. More info in
Minos Galanakise4094012020-06-12 14:25:34 +0100572 :doc:`tfm_user_guide </docs/getting_started/tfm_user_guide>`.
Tamas Bandaa4c6e2019-07-01 12:39:00 +0100573 - Set a breakpoint in ``test/suites/attestation/attest_token_test.c``
574 in ``decode_test_internal(..)`` after the ``token_main_alt(..)`` returned,
575 i.e. on line 859. Execute the code in the model until the breakpoint hits
David Hu10b66152020-05-29 22:53:13 +0800576 second time. At this point the console prints the test case name:
577
578 - For asymmetric initial attestation, the console prints
579 ``ECDSA signature test of attest token``.
580 - For symmetric initial attestation, the console prints
581 ``Symmetric key algorithm based Initial Attestation test``.
582
Tamas Bandaa4c6e2019-07-01 12:39:00 +0100583 - At this point the token resides in the model memory and can be dumped to host
584 computer.
585 - The ADDRESS and SIZE attributes of the initial attestation token is stored in
586 the ``completed_token`` local variable. Their value can be extracted in the
587 ``(x)=Variables`` debug window.
David Hu10b66152020-05-29 22:53:13 +0800588 - Apply commands below in the ``Commands`` debug window to dump the token in
Tamas Bandaa4c6e2019-07-01 12:39:00 +0100589 binary format to the host computer:
David Hu10b66152020-05-29 22:53:13 +0800590
591 - For asymmetric initial attestation
592 ``dump memory <PATH>/iat_01.cbor <ADDRESS> +<SIZE>``
593 - For symmetric initial attestation
594 ``dump memory <PATH>/iat_hmac_02.cbor <ADDRESS> +<SIZE>``
595
596 - Execute commands below on the host computer to verify the token:
597
598 - For asymmetric initial attestation
599 ``check_iat -p -K -k platform/ext/common/template/tfm_initial_attestation_key.pem <PATH>/iat_01.cbor``
600 - For symmetric initial attestation
601 ``check_iat -m mac -p -K -k platform/ext/common/template/tfm_symmetric_iak.key <PATH>/iat_hmac_02.cbor``
602
Tamas Bandaa4c6e2019-07-01 12:39:00 +0100603 - Documentation of the iat-verifier can be found
604 :doc:`here </tools/iat-verifier/README>`.
605
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200606--------------
607
Tamas Banabea89d2020-01-15 13:29:25 +0000608*Copyright (c) 2018-2020, Arm Limited. All rights reserved.*