blob: 5d2986146e966731cef29fcd3d6b1e7159e72c60 [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:
175 - ``attestation_core.c`` : Implements core functionalities such as
176 implementation of APIs, retrieval of claims and token creation.
177 - ``attest_token.c``: Implements the token creation function such as
178 start and finish token creation and adding claims to the token.
David Hu10b66152020-05-29 22:53:13 +0800179 - ``attestation_key.c``: Get the asymmetric attestation key from platform
180 layer and register it to the TF-M Crypto service for further usage.
Tamas Bandaa4c6e2019-07-01 12:39:00 +0100181 - ``tfm_attestation.c``: Implements the SPM abstraction layer, and bind
182 the attestation service to the SPM implementation in TF-M project.
183 - ``tfm_attestation_secure_api.c``: Implements the secure API layer to
184 allow other services in the secure domain to request functionalities
185 from the attestation service using the PSA API interface.
186 - ``tfm_attestation_req_mngr.c``: Includes the initialization entry of
187 attestation service and handles attestation service requests in IPC
188 model.
David Hu10b66152020-05-29 22:53:13 +0800189 - ``attest_symmetric_key.c``: Get the symmetric initial attestation key
190 from platform layer and register it into TF-M Crypto service for further
191 usage. Also calculate the Instance ID value based on symmetric initial
192 attestation key.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200193
194Service interface definitions
195=============================
196- **Boot loader interface**: The attestation service might include data
197 in the token about the distinct software components in the device. This data
198 is provided by the boot loader and must be encoded in the TLV format,
199 definition is described below in the boot loader interface paragraph. Possible
200 claims in the boot status are describe above in the software components
201 paragraph.
202- **Hardware abstraction layer**:
203 - Headers are located in ``platform/include`` folder.
204 - ``tfm_attest_hal.h``: Expose an API to get the following claims:
205 security lifecycle, verification service indicator, profile definition.
206 - ``tfm_plat_boot_seed.h``: Expose an API to get the boot seed claim.
207 - ``tfm_plat_device_id.h``: Expose an API to get the following claims:
Tamas Banf8863812020-06-09 13:46:04 +0100208 implementation ID, hardware version.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200209- **SPM interface**:
210 - ``attestation.h``: Expose an API to bind attestation service to an SPM
211 implementation.
212- **PSA interface**:
Jamie Foxcc31d402019-01-28 17:13:52 +0000213 - ``psa/initial_attestation.h``: Public API definition of initial
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200214 attestation service.
215- **Crypto interface**:
216 - ``t_cose_crypto.h``: Expose an API to bind the ``t_cose`` implementation
217 to any cryptographic library.
218 - ``tfm_plat_crypto_keys.h``: Expose an API to get the attestation key from
219 platform layer.
220
221PSA interface
222=============
223The TF-M Initial Attestation Service exposes the following PSA
224interface:
225
226.. code-block:: c
227
Raef Coles793574c2019-10-09 10:59:42 +0100228 psa_status_t
Raef Coles70a02da2019-10-09 11:32:04 +0100229 psa_initial_attest_get_token(const uint8_t *auth_challenge,
230 size_t challenge_size,
231 uint8_t *token_buf,
232 size_t token_buf_size,
233 size_t *token_size);
David Vincze20c3e4e2019-11-11 11:16:06 +0100234
Raef Coles793574c2019-10-09 10:59:42 +0100235 psa_status_t
Raef Coles70a02da2019-10-09 11:32:04 +0100236 psa_initial_attest_get_token_size(size_t challenge_size,
237 size_t *token_size);
David Vincze20c3e4e2019-11-11 11:16:06 +0100238
Raef Coles793574c2019-10-09 10:59:42 +0100239 psa_status_t
David Vincze20c3e4e2019-11-11 11:16:06 +0100240 tfm_initial_attest_get_public_key(uint8_t *public_key,
241 size_t public_key_buf_size,
242 size_t *public_key_len,
243 psa_ecc_curve_t *elliptic_curve_type);
244
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200245The caller must allocate a large enough buffer, where the token is going to be
246created by Initial Attestation Service. The size of the created token is highly
247dependent on the number of software components in the system and the provided
248attributes of these. The ``psa_initial_attest_get_token_size()`` function can be
249called to get the exact size of the created token.
250
251System integrators might need to port these interfaces to a custom secure
David Vincze20c3e4e2019-11-11 11:16:06 +0100252partition manager implementation (SPM). Implementations in TF-M project can be
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200253found here:
254
David Vincze20c3e4e2019-11-11 11:16:06 +0100255- ``interface/src/tfm_initial_attestation_func_api.c``: non-secure interface
256 implementation for library model
257- ``interface/src/tfm_initial_attestation_ipc_api.c``: non-secure interface
258 implementation for IPC model
Ken Liu738a4b02020-06-04 14:52:38 +0800259- ``secure_fw/partitions/initial_attestation/tfm_attestation_secure_api.c``:
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200260 secure interface implementation
261
262Secure Partition Manager (SPM) interface
263========================================
264The Initial Attestation Service defines the following interface towards the
265secure partition manager (SPM). System integrators **must** port this interface
266according to their SPM implementation.
267
268.. code:: c
269
270 enum psa_attest_err_t
271 attest_get_boot_data(uint8_t major_type, void *ptr, uint32_t len);
272
273 enum psa_attest_err_t
274 attest_get_caller_client_id(int32_t *caller_id);
275
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200276- ``attest_get_boot_data()``: Service can retrieve the relevant data from shared
277 memory area between boot loader and runtime software. It might be the case
278 that only SPM has direct access to the shared memory area, therefore this
279 function can be used to copy the service related data from shared memory to
280 a local memory buffer. In TF-M implementation this function must be called
281 during service initialization phase, because the shared memory region is
282 deliberately overlapping with secure main stack to spare some memory and reuse
283 this area during execution. If boot loader is not available in the system to
284 provide attributes of software components then this function must be
285 implemented in a way that just initialize service's memory buffer to:
David Vincze20c3e4e2019-11-11 11:16:06 +0100286
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200287 .. code-block:: c
David Vincze20c3e4e2019-11-11 11:16:06 +0100288
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200289 struct shared_data_tlv_header *tlv_header = (struct shared_data_tlv_header *)ptr;
290 tlv_header->tlv_magic = 2016;
291 tlv_header->tlv_tot_len = sizeof(struct shared_data_tlv_header *tlv_header);
292
293- ``attest_get_caller_client_id()``: Retrieves the ID of the caller thread.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200294- ``tfm_client.h``: Service relies on the following external definitions, which
295 must be present or included in this header file:
David Vincze20c3e4e2019-11-11 11:16:06 +0100296
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200297 .. code-block:: c
David Vincze20c3e4e2019-11-11 11:16:06 +0100298
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200299 typedef struct psa_invec {
300 const void *base;
301 size_t len;
302 } psa_invec;
David Vincze20c3e4e2019-11-11 11:16:06 +0100303
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200304 typedef struct psa_outvec {
305 void *base;
306 size_t len;
307 } psa_outvec;
308
309Hardware abstraction layer
310==========================
311The following API definitions are intended to retrieve the platform specific
312claims. System integrators **must** implement these interface according to their
313SoC and software design. Detailed definition of the claims are above
314in the claims in the initial attestation token paragraph.
315
316- ``tfm_attest_hal_get_security_lifecycle()``: Get the security lifecycle of the
317 device.
318- ``tfm_attest_hal_get_verification_service()``: Get the verification
319 service indicator for initial attestation.
320- ``tfm_attest_hal_get_profile_definition()``: Get the name of the profile
321 definition document for initial attestation.
322- ``tfm_plat_get_boot_seed()``: Get the boot seed, which is a constant random
323 number during a boot cycle.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200324- ``tfm_plat_get_implementation_id``: Get the implementation ID of the
325 device.
326- ``tfm_plat_get_hw_version``: Get the hardware version of the device.
327
328Boot loader interface
329=====================
330It is **recommended** to have a secure boot loader in the boot chain, which is
331capable of measuring the runtime firmware components (calculates the hash value
332of firmware images) and provide other attributes of these (version, type, etc).
David Vinczee13a48b2020-01-08 17:42:30 +0100333If the used boot loader is not capable of sharing these information with the
334runtime software then the ``BOOT_DATA_AVAILABLE`` compiler flag **must** be
Balint Matyi9272a432020-06-02 07:27:26 +0100335set to OFF (see `Related compile time options`_).
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200336
337The shared data between boot loader and runtime software is TLV encoded. The
338definition of TLV structure is described in ``bl2/include/tfm_boot_status.h``.
339The shared data is stored in a well known location in secure internal memory
340and this is a contract between boot loader and runtime SW.
341
342The structure of shared data must be the following:
343
344- At the beginning there must be a header: ``struct shared_data_tlv_header``
345 This contains a magic number and a size field which covers the entire size
346 of the shared data area including this header.
David Vincze20c3e4e2019-11-11 11:16:06 +0100347
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200348 .. code-block:: c
David Vincze20c3e4e2019-11-11 11:16:06 +0100349
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200350 struct shared_data_tlv_header {
351 uint16_t tlv_magic;
352 uint16_t tlv_tot_len;
353 };
David Vincze20c3e4e2019-11-11 11:16:06 +0100354
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200355- After the header there come the entries which are composed from an
356 entry header structure: ``struct shared_data_tlv_entry`` and the data. In
357 the entry header is a type field ``tlv_type`` which identify the consumer of
358 the entry in the runtime software and specify the subtype of that data item.
David Vincze53998032020-06-10 15:54:31 +0200359
360 .. Note::
361
362 There is a size field ``tlv_len`` which has different definitions in the
363 upstream MCUboot repository and in its TF-M forked version:
364
365 - Upstream MCUboot: Covers only the length of data but not the header
366 size.
367 - TF-M MCUboot: Covers the size of the entry header and the data
368 together.
369
370 This difference is handled by TF-M code based on which bootloader is used
371 along with TF-M runtime.
372
373 After the entry header structure comes the actual data.
David Vincze20c3e4e2019-11-11 11:16:06 +0100374
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200375 .. code-block:: c
David Vincze20c3e4e2019-11-11 11:16:06 +0100376
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200377 struct shared_data_tlv_entry {
378 uint16_t tlv_type;
379 uint16_t tlv_len;
380 };
David Vincze20c3e4e2019-11-11 11:16:06 +0100381
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200382- Arbitrary number and size of data entry can be in the shared memory
383 area.
384
385The figure below gives of overview about the ``tlv_type`` field in the entry
386header. The ``tlv_type`` always composed from a major and minorbnumber. Major
387number identifies the addressee in runtime software, which the databentry is
388sent to. Minor number used to encode more info about the data entry. The actual
389definition of minor number could change per major number. In case of boot
390status data, which is going to be processed by initial attestation service
391the minor number is split further to two part: ``sw_module`` and ``claim``. The
392``sw_module`` identifies the SW component in the system which the data item
393belongs to and the ``claim`` part identifies the exact type of the data.
394
395``tlv_type`` description::
396
397 |------------------------------------------------ |
398 | tlv_type (16 bits) |
399 |-------------------------------------------------|
400 | tlv_major(4 bits) | tlv_minor(12 bits) |
401 |-------------------------------------------------|
402 | MAJOR_IAS | sw_module(6 bits) | claim(6 bits) |
403 |-------------------------------------------------|
404 | MAJOR_CORE | TBD |
405 |-------------------------------------------------|
406
407Overall structure of shared data::
408
409 ---------------------------------------------------------------
410 | Magic number(uint16_t) | Shared data total length(uint16_t) |
411 ---------------------------------------------------------------
412 | Major_type(4 bits) | Minor_type(12 bits) | Length(uint16_t) |
413 ---------------------------------------------------------------
414 | Raw data |
415 ---------------------------------------------------------------
416 | . |
417 | . |
418 | . |
419 ---------------------------------------------------------------
420 | Major_type(4 bits) | Minor_type(12 bits) | Length(uint16_t) |
421 ---------------------------------------------------------------
422 | Raw data |
423 ---------------------------------------------------------------
424
425Crypto interface
426================
David Hu10b66152020-05-29 22:53:13 +0800427
428Asymmetric key algorithm based attestation
429------------------------------------------
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200430Device **must** contain an asymmetric key pair. The private part of it is used
431to sign the initial attestation token. Current implementation supports only the
432ECDSA P256 signature over SHA256. The public part of the key pair is used to
433create the key identifier (kid) in the unprotected part of the COSE header. The
434kid is used by verification entity to look up the corresponding public key to
435verify the signature in the token. The `t_cose` part of the initial attestation
436service implements the signature generation and kid creation. But the actual
437calculation of token's hash and signature is done by the Crypto service in the
438device. System integrators might need to re-implement the following functions
439if they want to use initial attestation service with a different cryptographic
440library than Crypto service:
441
442- ``t_cose_crypto_pub_key_sign()``: Calculates the signature over a hash value.
443- ``t_cose_crypto_get_ec_pub_key()``: Get the public key to create the key
444 identifier.
445- ``t_cose_crypto_hash_start()``: Start a multipart hash operation.
446- ``t_cose_crypto_hash_update()``: Add a message fragment to a multipart hash
447 operation.
448- ``t_cose_crypto_hash_finish()``:Finish the calculation of the hash of a
449 message.
450
451Interface needed by verification code:
452
453- ``t_cose_crypto_pub_key_verify()``: Verify the signature over a hash value.
454
455Key handling
David Hu10b66152020-05-29 22:53:13 +0800456^^^^^^^^^^^^
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200457The provisioning of the initial attestation key is out of scope of the service
458and this document. It is assumed that device maker provisions the unique
459asymmetric key pair during the manufacturing process. The following API is
460defined to retrieve the attestation key pair from platform layer. Software
461integrators **must** port this interface according to their SoC design and make
462sure that key pair is available by Crypto service:
463
464- ``tfm_plat_get_initial_attest_key()``: Retrieve the initial attestation key
465 pair from platform layer.
466
467In TF-M project the attestation key is retrieved by initial attestation service.
468The key is registered and unregistered to the Crypto service by attestation
469service with ``psa_import_key()`` and ``psa_destroy_key()`` API calls for
470further usage. See in ``attestation_key.c``. In other implementation if the
471attestation key is directly retrieved by the Crypto service then this key
472handling is not necessary.
473
David Hu10b66152020-05-29 22:53:13 +0800474Symmetric key algorithm based attestation
475-----------------------------------------
476Device **must** contain a symmetric key to generate the authentication tag of
477the initial attestation token. A key identifier (kid) can be encoded in the
478unprotected part of the COSE header. It helps verification entity look up the
479symmetric key to verify the authentication tag in the token.
480
481The `t_cose` part of the initial attestation service implements the
482authentication tag generation. The authentication tag generation is done by the
483Crypto service. System integrators might need to re-implement the following
484functions if platforms provide a different cryptographic library than Crypto
485service:
486
487- ``t_cose_crypto_hmac_sign_setup()``: Set up a multi-part HMAC calculation
488 operation.
489- ``t_cose_crypto_hmac_update()``: Add a message fragment to a multi-part HMAC
490 operation.
491- ``t_cose_crypto_hmac_sign_finish()``: Finish the calculation of the HMAC of a
492 message.
493
494Interface needed by verification code:
495
496- ``t_cose_crypto_hmac_verify_setup()``: Set up a multi-part HMAC verification
497 operation.
498- ``t_cose_crypto_hmac_verify_finish()``: Finish the verification of the HMAC of
499 a message.
500
501It also requires the same hash operations as listed in asymmetric key algorithm
502based initial attestation above, in attestation test cases.
503
504Key handling
505^^^^^^^^^^^^
506The provisioning of the initial attestation key is out of scope of the service
507and this document. It is assumed that device maker provisions the symmetric key
508during the manufacturing process. The following API is defined to retrieve the
509symmetric attestation key from platform layer. Software integrators **must**
510port this interface according to their SoC design and make sure that key is
511available by Crypto service:
512
513- ``tfm_plat_get_symmetric_iak()``: Get the symmetric initial attestation key
514 raw data.
515- ``tfm_plat_get_symmetric_iak_id()``: Get the key identifier of the symmetric
516 initial attestation key. The key identifier can be used as ``kid`` parameter
517 in COSE header. Optional.
518
519.. note:
520
521 Asymmetric initial attestation and symmetric initial attestation may share
522 the same HAL APIs in future development.
523
Tamas Ban01f64c52019-08-26 13:46:21 +0100524Initial Attestation Service compile time options
525================================================
526There is a defined set of flags that can be used to compile in/out certain
527service features. The ``CommonConfig.cmake`` file sets the default values of
528those flags. The list of flags are:
529
530- ``ATTEST_INCLUDE_OPTIONAL_CLAIMS``: Include also the optional claims to the
Balint Matyi9272a432020-06-02 07:27:26 +0100531 attestation token. Default value: ON.
Tamas Banabea89d2020-01-15 13:29:25 +0000532- ``ATTEST_INCLUDE_TEST_CODE``: Test code is removed from COSE library and from
Balint Matyi9272a432020-06-02 07:27:26 +0100533 attestation test suite if it is OFF. Its default value depends on the build
534 type. It is ON if build type is ``Debug``, otherwise OFF (different kinds
Tamas Banabea89d2020-01-15 13:29:25 +0000535 of ``Release`` builds).
536- ``ATTEST_INCLUDE_COSE_KEY_ID``: COSE key-id is an optional field in the COSE
537 unprotected header. Key-id is calculated and added to the COSE header based
Balint Matyi9272a432020-06-02 07:27:26 +0100538 on the value of this flag. Default value: OFF.
Balint Matyi95f58eb2020-05-22 08:52:32 +0100539- ``ATTEST_CLAIM_VALUE_CHECK``: Check attestation claims against hard-coded
540 values found in ``platform/ext/common/template/attest_hal.c``. Default value
541 is OFF. Set to ON in a platform's CMake file if the attest HAL is not yet
542 properly ported to it.
David Hu10b66152020-05-29 22:53:13 +0800543- ``SYMMETRIC_INITIAL_ATTESTATION``: Select symmetric initial attestation.
544 Default value: OFF.
Tamas Ban01f64c52019-08-26 13:46:21 +0100545
David Vinczee13a48b2020-01-08 17:42:30 +0100546Related compile time options
547----------------------------
548- ``BOOT_DATA_AVAILABLE``: The boot data is expected to be present in the shared
Balint Matyi9272a432020-06-02 07:27:26 +0100549 data area between the boot loader and the runtime firmware when it's ON.
550 Otherwise, when it's OFF does not check the content of the shared data area.
David Vinczee13a48b2020-01-08 17:42:30 +0100551 Also assume that the TLV header is present and valid (the magic number is
552 correct) and there are no other data entries. Its default value depends on
553 the BL2 flag.
554
Tamas Banff3bb582020-06-09 14:18:35 +0100555***************************************************************************
556Comparison of asymmetric and symmetric algorithm based token authentication
557***************************************************************************
558The symmetric key based authentication requires a more complex infrastructure
559for key management. Symmetric keys must be kept secret because they are
560sensitive asset, like the private key in case of asymmetric cryptographic
561algorithms. The main difference is that private keys are only stored on
562device, with proper hardware protection against external access, but symmetric
563keys must be known by both party (device and verifier), so they must also be
564stored in a central server of a relying party (who verifies the tokens).
565If keys are revealed then devices can be impersonated. If the database with
566the symmetric keys becomes compromised then all corresponding devices become
567untrusted. Since a centralised database of symmetric keys may need to be network
568connected, this can be considered to be a valuable target for attackers. The
569advantage of ECDSA based token authentication is that sensitive assets is only
570stored one place (in the device) and only one unique key per device. So if a
571device is compromised then only that single device become untrusted. In this
572case, the database of the relying party contains the corresponding public keys,
573which are not considered to be a confidential assets, so they can be shared with
574anybody. This shows the main advantage of asymmetric based authentication,
575because verification of attestation tokens can be done by a third party,
576such as cloud service providers (CSP). Thus Device Maker (DM) or Chip Maker (CM)
577does not need to operate such a service.
578
579+-------------------------+-----------------------------------------+-----------------------------------------+
580| | Symmetric | Asymmetric |
581+=========================+=========================================+=========================================+
582| Authentication mode | HMAC over SHA256 | ECDSA P256 over SHA256 |
583+-------------------------+-----------------------------------------+-----------------------------------------+
584| Supported APIs | - psa_initial_attest_get_token(..) | - psa_initial_attest_get_token(..) |
585| | - psa_initial_attest_get_token_size(..) | - psa_initial_attest_get_token_size(..) |
586| | | - tfm_initial_attest_get_public_key(..) |
587+-------------------------+-----------------------------------------+-----------------------------------------+
588| Crypto key type in HW | Symmetric key | ECDSA private key (secp256r1) |
589+-------------------------+-----------------------------------------+-----------------------------------------+
590| Secrets are stored | Device and database | Device only |
591+-------------------------+-----------------------------------------+-----------------------------------------+
592| Verification database | Same symmetric key | Public keys |
593| contains | | |
594+-------------------------+-----------------------------------------+-----------------------------------------+
595| COSE authentication tag | COSE_Mac0 | COSE_Sign1 |
596| in the token | | |
597+-------------------------+-----------------------------------------+-----------------------------------------+
598| Verification entity | CM or DM, who provisioned the | Can be anybody: third party provisioning|
599| | symmetric key | service, cloud service provider, CM, DM |
600+-------------------------+-----------------------------------------+-----------------------------------------+
601
Tamas Bandaa4c6e2019-07-01 12:39:00 +0100602************
603Verification
604************
605The initial attestation token is verified by the attestation test suite in
606``test/suites/attestation``. The test suite is responsible for verifying the
607token signature and parsing the token to verify its encoding and the presence of
608the mandatory claims. This test suite can be executed on the device. It is part
609of the regression test suite. When the user builds TF-M with any of the
610``ConfigRegression*.cmake`` configurations then this test is executed
611automatically. The test suite is configurable in the
612``test/suites/attestation/attest_token_test_values.h`` header file. In this file
613there are two attributes for each claim which are configurable (more details
614in the header file):
615
616 - Requirements of presence: optional or mandatory
617 - Expected value: Value check can be disabled or expected value can be provided
618 here.
619
620There is another possibility to verify the attestation token. This addresses
621the off-device testing when the token is already retrieved from the device and
622verification is done on the requester side. There is a Python script for this
623purpose in ``tools/iat-verifier``. It does the same checking as the
624attestation test suite. The following steps describe how to simulate an
625off-device token verification on a host computer. It is described how to
626retrieve an initial attestation token when TF-M code is executed on FVP
627and how to use the iat_verifier script to check the token. This example assumes
628that user has license for DS-5 and FVP models:
629
630 - Build TF-M with any of the ``ConfigRegression*.cmake`` build configurations
631 for MPS2 AN521 platform. More info in
Minos Galanakise4094012020-06-12 14:25:34 +0100632 :doc:`tfm_build_instruction </docs/getting_started/tfm_build_instruction>`.
Tamas Bandaa4c6e2019-07-01 12:39:00 +0100633 - Lunch FVP model in DS-5. More info in
Minos Galanakise4094012020-06-12 14:25:34 +0100634 :doc:`tfm_user_guide </docs/getting_started/tfm_user_guide>`.
Tamas Bandaa4c6e2019-07-01 12:39:00 +0100635 - Set a breakpoint in ``test/suites/attestation/attest_token_test.c``
636 in ``decode_test_internal(..)`` after the ``token_main_alt(..)`` returned,
637 i.e. on line 859. Execute the code in the model until the breakpoint hits
David Hu10b66152020-05-29 22:53:13 +0800638 second time. At this point the console prints the test case name:
639
640 - For asymmetric initial attestation, the console prints
641 ``ECDSA signature test of attest token``.
642 - For symmetric initial attestation, the console prints
643 ``Symmetric key algorithm based Initial Attestation test``.
644
Tamas Bandaa4c6e2019-07-01 12:39:00 +0100645 - At this point the token resides in the model memory and can be dumped to host
646 computer.
647 - The ADDRESS and SIZE attributes of the initial attestation token is stored in
648 the ``completed_token`` local variable. Their value can be extracted in the
649 ``(x)=Variables`` debug window.
David Hu10b66152020-05-29 22:53:13 +0800650 - Apply commands below in the ``Commands`` debug window to dump the token in
Tamas Bandaa4c6e2019-07-01 12:39:00 +0100651 binary format to the host computer:
David Hu10b66152020-05-29 22:53:13 +0800652
653 - For asymmetric initial attestation
654 ``dump memory <PATH>/iat_01.cbor <ADDRESS> +<SIZE>``
655 - For symmetric initial attestation
656 ``dump memory <PATH>/iat_hmac_02.cbor <ADDRESS> +<SIZE>``
657
658 - Execute commands below on the host computer to verify the token:
659
660 - For asymmetric initial attestation
661 ``check_iat -p -K -k platform/ext/common/template/tfm_initial_attestation_key.pem <PATH>/iat_01.cbor``
662 - For symmetric initial attestation
663 ``check_iat -m mac -p -K -k platform/ext/common/template/tfm_symmetric_iak.key <PATH>/iat_hmac_02.cbor``
664
Tamas Bandaa4c6e2019-07-01 12:39:00 +0100665 - Documentation of the iat-verifier can be found
666 :doc:`here </tools/iat-verifier/README>`.
667
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200668--------------
669
Tamas Banabea89d2020-01-15 13:29:25 +0000670*Copyright (c) 2018-2020, Arm Limited. All rights reserved.*