blob: d3457cd9059c5dd414629369da8cdfe6dea64df0 [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.
359 There is a size field ``tlv_len`` which covers the size of the entry header
360 and the data. After this structure comes the actual data.
David Vincze20c3e4e2019-11-11 11:16:06 +0100361
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200362 .. code-block:: c
David Vincze20c3e4e2019-11-11 11:16:06 +0100363
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200364 struct shared_data_tlv_entry {
365 uint16_t tlv_type;
366 uint16_t tlv_len;
367 };
David Vincze20c3e4e2019-11-11 11:16:06 +0100368
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200369- Arbitrary number and size of data entry can be in the shared memory
370 area.
371
372The figure below gives of overview about the ``tlv_type`` field in the entry
373header. The ``tlv_type`` always composed from a major and minorbnumber. Major
374number identifies the addressee in runtime software, which the databentry is
375sent to. Minor number used to encode more info about the data entry. The actual
376definition of minor number could change per major number. In case of boot
377status data, which is going to be processed by initial attestation service
378the minor number is split further to two part: ``sw_module`` and ``claim``. The
379``sw_module`` identifies the SW component in the system which the data item
380belongs to and the ``claim`` part identifies the exact type of the data.
381
382``tlv_type`` description::
383
384 |------------------------------------------------ |
385 | tlv_type (16 bits) |
386 |-------------------------------------------------|
387 | tlv_major(4 bits) | tlv_minor(12 bits) |
388 |-------------------------------------------------|
389 | MAJOR_IAS | sw_module(6 bits) | claim(6 bits) |
390 |-------------------------------------------------|
391 | MAJOR_CORE | TBD |
392 |-------------------------------------------------|
393
394Overall structure of shared data::
395
396 ---------------------------------------------------------------
397 | Magic number(uint16_t) | Shared data total length(uint16_t) |
398 ---------------------------------------------------------------
399 | Major_type(4 bits) | Minor_type(12 bits) | Length(uint16_t) |
400 ---------------------------------------------------------------
401 | Raw data |
402 ---------------------------------------------------------------
403 | . |
404 | . |
405 | . |
406 ---------------------------------------------------------------
407 | Major_type(4 bits) | Minor_type(12 bits) | Length(uint16_t) |
408 ---------------------------------------------------------------
409 | Raw data |
410 ---------------------------------------------------------------
411
412Crypto interface
413================
David Hu10b66152020-05-29 22:53:13 +0800414
415Asymmetric key algorithm based attestation
416------------------------------------------
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200417Device **must** contain an asymmetric key pair. The private part of it is used
418to sign the initial attestation token. Current implementation supports only the
419ECDSA P256 signature over SHA256. The public part of the key pair is used to
420create the key identifier (kid) in the unprotected part of the COSE header. The
421kid is used by verification entity to look up the corresponding public key to
422verify the signature in the token. The `t_cose` part of the initial attestation
423service implements the signature generation and kid creation. But the actual
424calculation of token's hash and signature is done by the Crypto service in the
425device. System integrators might need to re-implement the following functions
426if they want to use initial attestation service with a different cryptographic
427library than Crypto service:
428
429- ``t_cose_crypto_pub_key_sign()``: Calculates the signature over a hash value.
430- ``t_cose_crypto_get_ec_pub_key()``: Get the public key to create the key
431 identifier.
432- ``t_cose_crypto_hash_start()``: Start a multipart hash operation.
433- ``t_cose_crypto_hash_update()``: Add a message fragment to a multipart hash
434 operation.
435- ``t_cose_crypto_hash_finish()``:Finish the calculation of the hash of a
436 message.
437
438Interface needed by verification code:
439
440- ``t_cose_crypto_pub_key_verify()``: Verify the signature over a hash value.
441
442Key handling
David Hu10b66152020-05-29 22:53:13 +0800443^^^^^^^^^^^^
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200444The provisioning of the initial attestation key is out of scope of the service
445and this document. It is assumed that device maker provisions the unique
446asymmetric key pair during the manufacturing process. The following API is
447defined to retrieve the attestation key pair from platform layer. Software
448integrators **must** port this interface according to their SoC design and make
449sure that key pair is available by Crypto service:
450
451- ``tfm_plat_get_initial_attest_key()``: Retrieve the initial attestation key
452 pair from platform layer.
453
454In TF-M project the attestation key is retrieved by initial attestation service.
455The key is registered and unregistered to the Crypto service by attestation
456service with ``psa_import_key()`` and ``psa_destroy_key()`` API calls for
457further usage. See in ``attestation_key.c``. In other implementation if the
458attestation key is directly retrieved by the Crypto service then this key
459handling is not necessary.
460
David Hu10b66152020-05-29 22:53:13 +0800461Symmetric key algorithm based attestation
462-----------------------------------------
463Device **must** contain a symmetric key to generate the authentication tag of
464the initial attestation token. A key identifier (kid) can be encoded in the
465unprotected part of the COSE header. It helps verification entity look up the
466symmetric key to verify the authentication tag in the token.
467
468The `t_cose` part of the initial attestation service implements the
469authentication tag generation. The authentication tag generation is done by the
470Crypto service. System integrators might need to re-implement the following
471functions if platforms provide a different cryptographic library than Crypto
472service:
473
474- ``t_cose_crypto_hmac_sign_setup()``: Set up a multi-part HMAC calculation
475 operation.
476- ``t_cose_crypto_hmac_update()``: Add a message fragment to a multi-part HMAC
477 operation.
478- ``t_cose_crypto_hmac_sign_finish()``: Finish the calculation of the HMAC of a
479 message.
480
481Interface needed by verification code:
482
483- ``t_cose_crypto_hmac_verify_setup()``: Set up a multi-part HMAC verification
484 operation.
485- ``t_cose_crypto_hmac_verify_finish()``: Finish the verification of the HMAC of
486 a message.
487
488It also requires the same hash operations as listed in asymmetric key algorithm
489based initial attestation above, in attestation test cases.
490
491Key handling
492^^^^^^^^^^^^
493The provisioning of the initial attestation key is out of scope of the service
494and this document. It is assumed that device maker provisions the symmetric key
495during the manufacturing process. The following API is defined to retrieve the
496symmetric attestation key from platform layer. Software integrators **must**
497port this interface according to their SoC design and make sure that key is
498available by Crypto service:
499
500- ``tfm_plat_get_symmetric_iak()``: Get the symmetric initial attestation key
501 raw data.
502- ``tfm_plat_get_symmetric_iak_id()``: Get the key identifier of the symmetric
503 initial attestation key. The key identifier can be used as ``kid`` parameter
504 in COSE header. Optional.
505
506.. note:
507
508 Asymmetric initial attestation and symmetric initial attestation may share
509 the same HAL APIs in future development.
510
Tamas Ban01f64c52019-08-26 13:46:21 +0100511Initial Attestation Service compile time options
512================================================
513There is a defined set of flags that can be used to compile in/out certain
514service features. The ``CommonConfig.cmake`` file sets the default values of
515those flags. The list of flags are:
516
517- ``ATTEST_INCLUDE_OPTIONAL_CLAIMS``: Include also the optional claims to the
Balint Matyi9272a432020-06-02 07:27:26 +0100518 attestation token. Default value: ON.
Tamas Banabea89d2020-01-15 13:29:25 +0000519- ``ATTEST_INCLUDE_TEST_CODE``: Test code is removed from COSE library and from
Balint Matyi9272a432020-06-02 07:27:26 +0100520 attestation test suite if it is OFF. Its default value depends on the build
521 type. It is ON if build type is ``Debug``, otherwise OFF (different kinds
Tamas Banabea89d2020-01-15 13:29:25 +0000522 of ``Release`` builds).
523- ``ATTEST_INCLUDE_COSE_KEY_ID``: COSE key-id is an optional field in the COSE
524 unprotected header. Key-id is calculated and added to the COSE header based
Balint Matyi9272a432020-06-02 07:27:26 +0100525 on the value of this flag. Default value: OFF.
Balint Matyi95f58eb2020-05-22 08:52:32 +0100526- ``ATTEST_CLAIM_VALUE_CHECK``: Check attestation claims against hard-coded
527 values found in ``platform/ext/common/template/attest_hal.c``. Default value
528 is OFF. Set to ON in a platform's CMake file if the attest HAL is not yet
529 properly ported to it.
David Hu10b66152020-05-29 22:53:13 +0800530- ``SYMMETRIC_INITIAL_ATTESTATION``: Select symmetric initial attestation.
531 Default value: OFF.
Tamas Ban01f64c52019-08-26 13:46:21 +0100532
David Vinczee13a48b2020-01-08 17:42:30 +0100533Related compile time options
534----------------------------
535- ``BOOT_DATA_AVAILABLE``: The boot data is expected to be present in the shared
Balint Matyi9272a432020-06-02 07:27:26 +0100536 data area between the boot loader and the runtime firmware when it's ON.
537 Otherwise, when it's OFF does not check the content of the shared data area.
David Vinczee13a48b2020-01-08 17:42:30 +0100538 Also assume that the TLV header is present and valid (the magic number is
539 correct) and there are no other data entries. Its default value depends on
540 the BL2 flag.
541
Tamas Banff3bb582020-06-09 14:18:35 +0100542***************************************************************************
543Comparison of asymmetric and symmetric algorithm based token authentication
544***************************************************************************
545The symmetric key based authentication requires a more complex infrastructure
546for key management. Symmetric keys must be kept secret because they are
547sensitive asset, like the private key in case of asymmetric cryptographic
548algorithms. The main difference is that private keys are only stored on
549device, with proper hardware protection against external access, but symmetric
550keys must be known by both party (device and verifier), so they must also be
551stored in a central server of a relying party (who verifies the tokens).
552If keys are revealed then devices can be impersonated. If the database with
553the symmetric keys becomes compromised then all corresponding devices become
554untrusted. Since a centralised database of symmetric keys may need to be network
555connected, this can be considered to be a valuable target for attackers. The
556advantage of ECDSA based token authentication is that sensitive assets is only
557stored one place (in the device) and only one unique key per device. So if a
558device is compromised then only that single device become untrusted. In this
559case, the database of the relying party contains the corresponding public keys,
560which are not considered to be a confidential assets, so they can be shared with
561anybody. This shows the main advantage of asymmetric based authentication,
562because verification of attestation tokens can be done by a third party,
563such as cloud service providers (CSP). Thus Device Maker (DM) or Chip Maker (CM)
564does not need to operate such a service.
565
566+-------------------------+-----------------------------------------+-----------------------------------------+
567| | Symmetric | Asymmetric |
568+=========================+=========================================+=========================================+
569| Authentication mode | HMAC over SHA256 | ECDSA P256 over SHA256 |
570+-------------------------+-----------------------------------------+-----------------------------------------+
571| Supported APIs | - psa_initial_attest_get_token(..) | - psa_initial_attest_get_token(..) |
572| | - psa_initial_attest_get_token_size(..) | - psa_initial_attest_get_token_size(..) |
573| | | - tfm_initial_attest_get_public_key(..) |
574+-------------------------+-----------------------------------------+-----------------------------------------+
575| Crypto key type in HW | Symmetric key | ECDSA private key (secp256r1) |
576+-------------------------+-----------------------------------------+-----------------------------------------+
577| Secrets are stored | Device and database | Device only |
578+-------------------------+-----------------------------------------+-----------------------------------------+
579| Verification database | Same symmetric key | Public keys |
580| contains | | |
581+-------------------------+-----------------------------------------+-----------------------------------------+
582| COSE authentication tag | COSE_Mac0 | COSE_Sign1 |
583| in the token | | |
584+-------------------------+-----------------------------------------+-----------------------------------------+
585| Verification entity | CM or DM, who provisioned the | Can be anybody: third party provisioning|
586| | symmetric key | service, cloud service provider, CM, DM |
587+-------------------------+-----------------------------------------+-----------------------------------------+
588
Tamas Bandaa4c6e2019-07-01 12:39:00 +0100589************
590Verification
591************
592The initial attestation token is verified by the attestation test suite in
593``test/suites/attestation``. The test suite is responsible for verifying the
594token signature and parsing the token to verify its encoding and the presence of
595the mandatory claims. This test suite can be executed on the device. It is part
596of the regression test suite. When the user builds TF-M with any of the
597``ConfigRegression*.cmake`` configurations then this test is executed
598automatically. The test suite is configurable in the
599``test/suites/attestation/attest_token_test_values.h`` header file. In this file
600there are two attributes for each claim which are configurable (more details
601in the header file):
602
603 - Requirements of presence: optional or mandatory
604 - Expected value: Value check can be disabled or expected value can be provided
605 here.
606
607There is another possibility to verify the attestation token. This addresses
608the off-device testing when the token is already retrieved from the device and
609verification is done on the requester side. There is a Python script for this
610purpose in ``tools/iat-verifier``. It does the same checking as the
611attestation test suite. The following steps describe how to simulate an
612off-device token verification on a host computer. It is described how to
613retrieve an initial attestation token when TF-M code is executed on FVP
614and how to use the iat_verifier script to check the token. This example assumes
615that user has license for DS-5 and FVP models:
616
617 - Build TF-M with any of the ``ConfigRegression*.cmake`` build configurations
618 for MPS2 AN521 platform. More info in
Minos Galanakise4094012020-06-12 14:25:34 +0100619 :doc:`tfm_build_instruction </docs/getting_started/tfm_build_instruction>`.
Tamas Bandaa4c6e2019-07-01 12:39:00 +0100620 - Lunch FVP model in DS-5. More info in
Minos Galanakise4094012020-06-12 14:25:34 +0100621 :doc:`tfm_user_guide </docs/getting_started/tfm_user_guide>`.
Tamas Bandaa4c6e2019-07-01 12:39:00 +0100622 - Set a breakpoint in ``test/suites/attestation/attest_token_test.c``
623 in ``decode_test_internal(..)`` after the ``token_main_alt(..)`` returned,
624 i.e. on line 859. Execute the code in the model until the breakpoint hits
David Hu10b66152020-05-29 22:53:13 +0800625 second time. At this point the console prints the test case name:
626
627 - For asymmetric initial attestation, the console prints
628 ``ECDSA signature test of attest token``.
629 - For symmetric initial attestation, the console prints
630 ``Symmetric key algorithm based Initial Attestation test``.
631
Tamas Bandaa4c6e2019-07-01 12:39:00 +0100632 - At this point the token resides in the model memory and can be dumped to host
633 computer.
634 - The ADDRESS and SIZE attributes of the initial attestation token is stored in
635 the ``completed_token`` local variable. Their value can be extracted in the
636 ``(x)=Variables`` debug window.
David Hu10b66152020-05-29 22:53:13 +0800637 - Apply commands below in the ``Commands`` debug window to dump the token in
Tamas Bandaa4c6e2019-07-01 12:39:00 +0100638 binary format to the host computer:
David Hu10b66152020-05-29 22:53:13 +0800639
640 - For asymmetric initial attestation
641 ``dump memory <PATH>/iat_01.cbor <ADDRESS> +<SIZE>``
642 - For symmetric initial attestation
643 ``dump memory <PATH>/iat_hmac_02.cbor <ADDRESS> +<SIZE>``
644
645 - Execute commands below on the host computer to verify the token:
646
647 - For asymmetric initial attestation
648 ``check_iat -p -K -k platform/ext/common/template/tfm_initial_attestation_key.pem <PATH>/iat_01.cbor``
649 - For symmetric initial attestation
650 ``check_iat -m mac -p -K -k platform/ext/common/template/tfm_symmetric_iak.key <PATH>/iat_hmac_02.cbor``
651
Tamas Bandaa4c6e2019-07-01 12:39:00 +0100652 - Documentation of the iat-verifier can be found
653 :doc:`here </tools/iat-verifier/README>`.
654
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200655--------------
656
Tamas Banabea89d2020-01-15 13:29:25 +0000657*Copyright (c) 2018-2020, Arm Limited. All rights reserved.*