David Hu | c042793 | 2020-04-09 23:03:49 +0800 | [diff] [blame] | 1 | ################################################# |
| 2 | Symmetric key algorithm based Initial Attestation |
| 3 | ################################################# |
| 4 | |
Anton Komlev | 19b9071 | 2021-10-19 16:28:02 +0100 | [diff] [blame] | 5 | :Author: David Hu |
David Hu | c042793 | 2020-04-09 23:03:49 +0800 | [diff] [blame] | 6 | :Organization: Arm Limited |
| 7 | :Contact: david.hu@arm.com |
| 8 | |
| 9 | ************ |
| 10 | Introduction |
| 11 | ************ |
| 12 | |
| 13 | This document proposes a design of symmetric key algorithm based Initial |
| 14 | Attestation in TF-M. |
| 15 | |
| 16 | Symmetric key algorithm based Initial Attestation |
| 17 | (*symmetric Initial Attestation* for short) signs and verifies Initial |
Edison Ai | f7990c8 | 2020-07-16 18:31:48 +0800 | [diff] [blame] | 18 | Attestation Token (IAT) with a symmetric cryptography signature scheme, such as |
David Hu | c042793 | 2020-04-09 23:03:49 +0800 | [diff] [blame] | 19 | HMAC. |
| 20 | It can reduce TF-M binary size and memory footprint on ultra-constrained devices |
| 21 | without integrating asymmetric ciphers. |
| 22 | |
| 23 | This proposal follows PSA Attestation API document [1]_. |
| 24 | |
| 25 | .. note :: |
| 26 | |
| 27 | As pointed out by PSA Attestation API [1]_, the use cases of Initial |
| 28 | Attestation based on symmetric key algorithms can be limited due to |
| 29 | the associated infrastructure costs for key management and operational |
| 30 | complexities. It may also restrict the ability to interoperate with |
| 31 | scenarios that involve third parties. |
| 32 | |
| 33 | *************** |
| 34 | Design overview |
| 35 | *************** |
| 36 | |
| 37 | The symmetric Initial Attestation follows the existing IAT generation sequence |
| 38 | for Initial Attestation based on asymmetric key algorithm |
| 39 | (*asymmetric Initial Attestation* for short). |
| 40 | |
| 41 | As Profile Small design [2]_ requests, a configuration flag |
| 42 | ``SYMMETRIC_INITIAL_ATTESTATION`` selects symmetric initial attestation during |
| 43 | build. |
| 44 | |
| 45 | The top-level design is shown in :ref:`overall-diagram-figure` below. |
| 46 | |
| 47 | .. _overall-diagram-figure: |
| 48 | |
| 49 | .. figure:: media/symmetric_initial_attest/overall_diagram.png |
| 50 | :align: center |
| 51 | |
| 52 | Overall design diagram |
| 53 | |
| 54 | Symmetric Initial Attestation adds its own implementations of some steps in IAT |
| 55 | generation in Initial Attestation secure service. More details are covered in |
| 56 | `IAT generation in Initial Attestation secure service`_. |
| 57 | |
| 58 | The interfaces and procedures of Initial Attestation secure service are not |
| 59 | affected. Refer to Initial Attestation Service Integration Guide [3]_ for |
| 60 | details of the implementation of Initial Attestation secure service. |
| 61 | |
| 62 | Symmetric Initial Attestation invokes ``t_cose`` library to build up |
| 63 | ``COSE_Mac0`` structure. |
| 64 | ``COSE_Mac0`` support is added to ``t_cose`` library in TF-M since official |
| 65 | ``t_cose`` hasn't supported ``COSE_Mac0`` yet. The design of ``COSE_Mac0`` |
| 66 | support is covered in `COSE_Mac0 support in t_cose`_. |
| 67 | |
| 68 | .. note :: |
| 69 | |
| 70 | The ``COSE_Mac0`` implementation in this proposal is a prototype only for |
| 71 | Proof of Concept so far. It may be replaced after ``t_cose`` officially |
| 72 | supports ``COSE_Mac0`` message. |
| 73 | |
| 74 | Several HAL APIs are defined to fetch platform specific assets required by |
| 75 | Symmetric Initial Attestation. For example, ``tfm_plat_get_symmetric_iak()`` |
| 76 | fetches symmetric Initial Attestation Key (IAK). Those HAL APIs are summarized |
| 77 | in `HAL APIs`_. |
| 78 | |
| 79 | Decoding and verification of symmetric Initial Attestation is also included in |
| 80 | this proposal for regression test. |
| 81 | The test suites and IAT decoding are discussed in `TF-M Test suite`_. |
| 82 | |
| 83 | ``QCBOR`` library and Crypto service are also invoked. But this proposal doesn't |
| 84 | require any modification to either ``QCBOR`` or Crypto service. Therefore, |
| 85 | descriptions of ``QCBOR`` and Crypto service are skipped in this document. |
| 86 | |
| 87 | **************************************************** |
| 88 | IAT generation in Initial Attestation secure service |
| 89 | **************************************************** |
| 90 | |
| 91 | The sequence of IAT generation of symmetric Initial Attestation is shown in |
Raef Coles | b3adfeb | 2022-03-02 14:00:57 +0000 | [diff] [blame] | 92 | :ref:`ia-service-figure` below. Note that the ``Register symmetric IAK`` stage |
| 93 | is no longer required due to changes in the Crypto partition |
| 94 | (``attest_symmetric_key.c`` is now responsible only for calculating the instance |
| 95 | ID). |
David Hu | c042793 | 2020-04-09 23:03:49 +0800 | [diff] [blame] | 96 | |
| 97 | .. _ia-service-figure: |
| 98 | |
| 99 | .. figure:: media/symmetric_initial_attest/ia_service_flow.png |
| 100 | :align: center |
| 101 | |
| 102 | Symmetric IAT generation flow in Initial Attestation secure service |
| 103 | |
| 104 | In Initial Attestation secure service, symmetric Initial Attestation implements |
| 105 | the following steps in ``attest_create_token()``, which are different from those |
| 106 | of asymmetric Initial Attestation. |
| 107 | |
David Hu | c042793 | 2020-04-09 23:03:49 +0800 | [diff] [blame] | 108 | - ``attest_token_start()`` |
| 109 | - Instance ID claims |
| 110 | - ``attest_token_finish()`` |
| 111 | |
| 112 | If ``SYMMETRIC_INITIAL_ATTESTATION`` is selected, symmetric Initial Attestation |
| 113 | dedicated implementations of those steps are included in build. |
| 114 | Otherwise, asymmetric Initial Attestation dedicated implementations are included |
| 115 | instead. |
| 116 | |
| 117 | Symmetric Initial Attestation implementation resides a new file |
Raef Coles | b3adfeb | 2022-03-02 14:00:57 +0000 | [diff] [blame] | 118 | ``attest_symmetric_key.c`` to handle symmetric Instance ID related operations. |
David Hu | c042793 | 2020-04-09 23:03:49 +0800 | [diff] [blame] | 119 | Symmetric Initial Attestation dedicated ``attest_token_start()`` and |
| 120 | ``attest_token_finish()`` are added in ``attestation_token.c``. |
| 121 | |
| 122 | The details are covered in following sections. |
| 123 | |
Raef Coles | b3adfeb | 2022-03-02 14:00:57 +0000 | [diff] [blame] | 124 | Symmetric Instance ID |
| 125 | ===================== |
David Hu | c042793 | 2020-04-09 23:03:49 +0800 | [diff] [blame] | 126 | |
Raef Coles | b3adfeb | 2022-03-02 14:00:57 +0000 | [diff] [blame] | 127 | Symmetric Initial Attestation dedicated ``attest_symmetric_key.c`` implements |
| 128 | the ``attest_get_instance_id()`` function. This function returns the Instance ID |
| 129 | value, calculating it if it has not already been calculated. Refer to |
| 130 | `Instance ID claim_` for more details. |
David Hu | c042793 | 2020-04-09 23:03:49 +0800 | [diff] [blame] | 131 | |
| 132 | .. note :: |
| 133 | |
| 134 | Only symmetric IAK for HMAC algorithm is allowed so far. |
| 135 | |
| 136 | Instance ID calculation |
| 137 | ----------------------- |
| 138 | |
Raef Coles | b3adfeb | 2022-03-02 14:00:57 +0000 | [diff] [blame] | 139 | In symmetric Initial Attestation, Instance ID is also calculated the first time |
| 140 | it is requested. It can protect critical symmetric IAK from being frequently |
| 141 | fetched, which increases the risk of asset disclosure. |
David Hu | c042793 | 2020-04-09 23:03:49 +0800 | [diff] [blame] | 142 | |
| 143 | The Instance ID value is the output of hashing symmetric IAK raw data *twice*, |
| 144 | as requested in PSA Attestation API [1]_. HMAC-SHA256 may be hard-coded as the |
| 145 | hash algorithm of Instance ID calculation. |
| 146 | |
| 147 | .. note :: |
| 148 | |
| 149 | According to RFC2104 [4]_, if a HMAC key is longer than the HMAC block size, |
| 150 | the key will be first hashed. The hash output is used as the key in HMAC |
| 151 | computation. |
| 152 | |
| 153 | In current design, HMAC is used to calculate the authentication tag of |
| 154 | ``COSE_Mac0``. Assume that symmetric IAK is longer than HMAC block size |
| 155 | (HMAC-SHA256 by default), the Instance ID is actually the HMAC key for |
| 156 | ``COSE_Mac0`` authentication tag generation, if Instance ID value is the |
| 157 | output of hashing IAK only *once*. |
| 158 | Therefore, attackers may request an valid IAT from device and fake malicious |
| 159 | ones by using Instance ID to calculate valid authentication tags, to cheat |
| 160 | others. |
| 161 | |
| 162 | As a result, symmetric IAK raw data should be hashed *twice* to generate the |
| 163 | Instance ID value. |
| 164 | |
| 165 | The Instance ID calculation result is stored in a static buffer. |
| 166 | Token generation process can call ``attest_get_instance_id()`` to |
| 167 | fetch the data from that static buffer. |
| 168 | |
| 169 | attest_token_start() |
| 170 | ==================== |
| 171 | |
| 172 | Symmetric Initial Attestation dedicated ``attest_token_start()`` initializes the |
| 173 | ``COSE_Mac0`` signing context and builds up the ``COSE_Mac0`` Header. |
| 174 | |
| 175 | The workflow inside ``attest_token_start()`` is shown in |
| 176 | :ref:`attest-token-start-figure` below. |
| 177 | |
| 178 | .. _attest-token-start-figure: |
| 179 | |
| 180 | .. figure:: media/symmetric_initial_attest/attest_token_start.png |
| 181 | :align: center |
| 182 | |
| 183 | Workflow in symmetric Initial Attestation ``attest_token_start()`` |
| 184 | |
| 185 | Descriptions of each step are listed below: |
| 186 | |
| 187 | #. ``t_cose_mac0_sign_init()`` is invoked to initialize ``COSE_Mac0`` signing |
| 188 | context in ``t_cose``. |
| 189 | |
David Hu | c042793 | 2020-04-09 23:03:49 +0800 | [diff] [blame] | 190 | #. The symmetric IAK handle is set into ``COSE_Mac0`` signing context via |
| 191 | ``t_cose_mac0_set_signing_key()``. |
| 192 | |
| 193 | #. Initialize ``QCBOR`` encoder. |
| 194 | |
| 195 | #. The header parameters are encoded into ``COSE_Mac0`` structure in |
| 196 | ``t_cose_mac0_encode_parameters()``. |
| 197 | |
| 198 | #. ``QCBOREncode_OpenMap()`` prepares for encoding the ``COSE_Mac0`` payload, |
| 199 | which is filled with IAT claims. |
| 200 | |
| 201 | All the ``COSE_Mac0`` functionalities in ``t_cose`` are covered in |
| 202 | `COSE_Mac0 support in t_cose`_. |
| 203 | |
| 204 | Instance ID claim |
| 205 | ================= |
| 206 | |
| 207 | Symmetric Initial Attestation also implements Instance ID claims in |
| 208 | ``attest_add_instance_id_claim()``. |
| 209 | |
| 210 | The Instance ID value is fetched via ``attest_get_instance_id()``. |
| 211 | The value has already been calculated during symmetric IAK registration. See |
| 212 | `Instance ID calculation`_ for details. |
| 213 | |
| 214 | The other steps are the same as those in asymmetric Initial Attestation |
| 215 | implementation. The UEID type byte is set to 0x01. |
| 216 | |
| 217 | attest_token_finish() |
| 218 | ===================== |
| 219 | |
| 220 | Symmetric Initial Attestation dedicated ``attest_token_finish()`` calls |
| 221 | ``t_cose_mac0_encode_tag()`` to calculate and encode the authentication tag of |
| 222 | ``COSE_Mac0`` structure. |
| 223 | |
| 224 | The whole COSE and CBOR encoding are completed in ``attest_token_finish()``. |
| 225 | |
| 226 | The simplified flow in ``attest_token_finish()`` is shown in |
| 227 | :ref:`attest-token-finish-figure` below. |
| 228 | |
| 229 | .. _attest-token-finish-figure: |
| 230 | |
| 231 | .. figure:: media/symmetric_initial_attest/attest_token_finish.png |
| 232 | :align: center |
| 233 | |
| 234 | Workflow in symmetric Initial Attestation ``attest_token_finish()`` |
| 235 | |
| 236 | *************************** |
| 237 | COSE_Mac0 support in t_cose |
| 238 | *************************** |
| 239 | |
| 240 | ``COSE_Mac0`` supports in ``t_cose`` in TF-M include the following major |
| 241 | functionalities: |
| 242 | |
| 243 | - Encoding ``COSE_Mac0`` structure |
| 244 | - Decoding and verifying ``COSE_Mac0`` structure |
| 245 | - HMAC computation to generate and verify authentication tag |
| 246 | - Short-circuit tagging for test mode |
| 247 | |
| 248 | According to RFC8152 [5]_, ``COSE_Mac0`` and ``COSE_Sign1`` have similar |
| 249 | structures. Therefore, the prototype follows ``COSE_Sign1`` implementation to |
| 250 | build up ``COSE_Mac0`` file structure and implement ``COSE_Mac0`` encoding and |
| 251 | decoding. |
| 252 | |
| 253 | Although ``COSE_Mac0`` can share lots of data types, APIs and encoding/decoding |
| 254 | steps with ``COSE_Sign1`` in implementation, this prototype separates |
| 255 | ``COSE_Mac0`` implementation from ``COSE_Sign1``. ``COSE_Mac0`` owns its |
| 256 | dedicated signing/verification contexts, APIs and encoding/decoding process. |
| 257 | The purposes of separating ``COSE_Mac0`` and ``COSE_Sign1`` are listed below |
| 258 | |
| 259 | - It can keep changes to ``COSE_Sign1`` as small as possible and avoid conflicts |
| 260 | with development in ``COSE_Sign1```. It can decrease conflicts if ``t_cose`` |
| 261 | in TF-M is synchronized with original ``t_cose`` repository later. |
| 262 | - ``COSE_Mac0`` and ``COSE_Sign1`` are exclusive in TF-M use cases. |
| 263 | It cannot decrease TF-M memory footprint by extracting the common components |
| 264 | shared by ``COSE_Mac0`` and ``COSE_Sign1`` but can make the design |
| 265 | over-complicated. |
| 266 | |
| 267 | .. note :: |
| 268 | |
| 269 | Only HMAC is supported in current ``COSE_Mac0`` prototype. |
| 270 | |
| 271 | File structure |
| 272 | ============== |
| 273 | |
| 274 | New files are added to implement the functionalities listed above. The structure |
| 275 | of files is shown in the table below. |
| 276 | |
| 277 | .. table:: New files in ``t_cose`` |
| 278 | :widths: auto |
| 279 | :align: center |
| 280 | |
| 281 | +---------------------+--------------------------------+----------------------------------------------+ |
| 282 | | Directory | Files | Descriptions | |
| 283 | +=====================+================================+==============================================+ |
| 284 | | ``src`` | ``t_cose_mac0_sign.c`` | Encode ``COSE_Mac0`` structure | |
| 285 | | +--------------------------------+----------------------------------------------+ |
| 286 | | | ``t_cose_mac0_verify.c`` | Decode and verify ``COSE_Mac0`` structure. | |
| 287 | +---------------------+--------------------------------+----------------------------------------------+ |
| 288 | | ``inc`` | ``t_cose_mac0_sign.h`` | Data type definitions and function | |
| 289 | | | | declarations of encoding and signing | |
| 290 | | | | ``COSE_Mac0`` message. | |
| 291 | | +--------------------------------+----------------------------------------------+ |
| 292 | | | ``t_cose_mac0_verify.h`` | Data type definitions and function | |
| 293 | | | | declarations of verifying ``COSE_Mac0`` | |
| 294 | | | | message. | |
| 295 | +---------------------+--------------------------------+----------------------------------------------+ |
| 296 | |
| 297 | Other ``t_cose`` files may also be changed to add ``COSE_Mac0`` associated data |
| 298 | types and function declarations. |
| 299 | |
| 300 | HMAC operations are added in ``crypto_adapters/t_cose_psa_crypto.c``. |
| 301 | Preprocessor flags are added to select corresponding crypto for COSE message |
| 302 | signing and verification. |
| 303 | |
| 304 | - ``T_COSE_ENABLE_SIGN1`` selects ECDSA and Hash operations for |
| 305 | ``COSE_Sign1``. |
| 306 | - ``T_COSE_ENABLE_MAC0`` selects HMAC operations for ``COSE_Mac0``. |
| 307 | |
| 308 | Encoding COSE_Mac0 |
| 309 | ================== |
| 310 | |
| 311 | Following ``COSE_Sign1`` implementation, ``COSE_Mac0`` encoding exports similar |
| 312 | functions to Initial Attestation secure service. |
| 313 | The major functions are listed below. |
| 314 | |
| 315 | Initialize signing context |
| 316 | -------------------------- |
| 317 | |
| 318 | ``t_cose_mac0_sign_init()`` initializes ``COSE_Mac0`` signing context and |
| 319 | configures option flags and algorithm used in signing. |
| 320 | |
| 321 | .. code-block:: c |
| 322 | |
| 323 | static void |
| 324 | t_cose_mac0_sign_init(struct t_cose_mac0_sign_ctx *me, |
| 325 | int32_t option_flags, |
| 326 | int32_t cose_algorithm_id); |
| 327 | |
| 328 | The ``COSE_Mac0`` signing context is defined as |
| 329 | |
| 330 | .. code-block:: c |
| 331 | |
| 332 | struct t_cose_mac0_sign_ctx { |
| 333 | /* Private data structure */ |
| 334 | uint8_t protected_parameters_buffer[ |
| 335 | T_COSE_MAC0_MAX_SIZE_PROTECTED_PARAMETERS]; |
| 336 | struct q_useful_buf_c protected_parameters; /* The encoded protected parameters */ |
| 337 | int32_t cose_algorithm_id; |
| 338 | struct t_cose_key signing_key; |
| 339 | int32_t option_flags; |
| 340 | struct q_useful_buf_c kid; |
| 341 | ... |
| 342 | }; |
| 343 | |
| 344 | Set signing key |
| 345 | --------------- |
| 346 | |
| 347 | ``t_cose_mac0_set_signing_key()`` sets the key used in ``COSE_Mac0`` signing. |
| 348 | Optional ``kid``, as a key identifer, will be encoded into ``COSE_Mac0`` Header |
| 349 | unprotected bucket. |
| 350 | |
| 351 | .. code-block:: c |
| 352 | |
| 353 | static void |
| 354 | t_cose_mac0_set_signing_key(struct t_cose_mac0_sign_ctx *me, |
| 355 | struct t_cose_key signing_key, |
| 356 | struct q_useful_buf_c kid); |
| 357 | |
| 358 | Encode Header parameters |
| 359 | ------------------------ |
| 360 | |
| 361 | ``t_cose_mac0_encode_parameters()`` encodes the ``COSE_Mac0`` Header parameters |
| 362 | and outputs the encoded context to ``cbor_encode_ctx``. |
| 363 | |
| 364 | .. code-block:: c |
| 365 | |
| 366 | enum t_cose_err_t |
| 367 | t_cose_mac0_encode_parameters(struct t_cose_mac0_sign_ctx *context, |
| 368 | QCBOREncodeContext *cbor_encode_ctx); |
| 369 | |
| 370 | Calculate and add authentication tag |
| 371 | ------------------------------------ |
| 372 | |
| 373 | ``t_cose_mac0_encode_tag()`` calculates the authentication tag and finishes the |
| 374 | ``COSE_Mac0`` message. |
| 375 | |
| 376 | .. code-block:: c |
| 377 | |
| 378 | enum t_cose_err_t |
| 379 | t_cose_mac0_encode_tag(struct t_cose_mac0_sign_ctx *context, |
| 380 | QCBOREncodeContext *cbor_encode_ctx); |
| 381 | |
| 382 | Decoding COSE_Mac0 |
| 383 | ================== |
| 384 | |
| 385 | Following ``COSE_Sign1`` implementation, ``COSE_Mac0`` decoding exports similar |
| 386 | functions to test suite of Initial Attestation. |
| 387 | The major functions are listed below. |
| 388 | |
| 389 | Initialize verification context |
| 390 | ------------------------------- |
| 391 | |
| 392 | ``t_cose_mac0_verify_init()`` initializes ``COSE_Mac0`` verification context and |
| 393 | configures option flags in verification. |
| 394 | |
| 395 | .. code-block:: c |
| 396 | |
| 397 | static void |
| 398 | t_cose_mac0_verify_init(struct t_cose_mac0_verify_ctx *context, |
| 399 | int32_t option_flags); |
| 400 | |
| 401 | The ``COSE_Mac0`` verification context is defined as |
| 402 | |
| 403 | .. code-block:: c |
| 404 | |
| 405 | struct t_cose_mac0_verify_ctx { |
| 406 | /* Private data structure */ |
| 407 | struct t_cose_key verification_key; |
| 408 | int32_t option_flags; |
| 409 | }; |
| 410 | |
| 411 | Set verification key |
| 412 | -------------------- |
| 413 | |
| 414 | ``t_cose_mac0_set_verify_key()`` sets the key for verifying ``COSE_Mac0`` |
| 415 | authentication tag. |
| 416 | |
| 417 | .. code-block:: c |
| 418 | |
| 419 | static void |
| 420 | t_cose_mac0_set_verify_key(struct t_cose_mac0_verify_ctx *context, |
| 421 | struct t_cose_key verify_key); |
| 422 | |
| 423 | Decode and verify COSE_Mac0 |
| 424 | --------------------------- |
| 425 | |
| 426 | ``t_cose_mac0_verify()`` decodes the ``COSE_Mac0`` structure and verifies the |
| 427 | authentication tag. |
| 428 | |
| 429 | .. code-block:: c |
| 430 | |
| 431 | enum t_cose_err_t |
| 432 | t_cose_mac0_verify(struct t_cose_mac0_verify_ctx *context, |
| 433 | struct q_useful_buf_c cose_mac0, |
| 434 | struct q_useful_buf_c *payload, |
| 435 | struct t_cose_parameters *parameters); |
| 436 | |
| 437 | Short-circuit tagging |
| 438 | ===================== |
| 439 | |
| 440 | If ``T_COSE_OPT_SHORT_CIRCUIT_TAG`` option is enabled, ``COSE_Mac0`` encoding |
| 441 | will hash the ``COSE_Mac0`` content and add the hash output as an authentication |
| 442 | tag. It is useful when critical symmetric IAK is unavailable or cannot be |
| 443 | accessed, perhaps because it has not been provisioned or configured for the |
| 444 | particular device. It is only for test and must not be used in actual use case. |
| 445 | The ``kid`` parameter will either be skipped in ``COSE_Mac0`` Header. |
| 446 | |
| 447 | If ``T_COSE_OPT_ALLOW_SHORT_CIRCUIT`` option is enabled, ``COSE_Mac0`` decoding |
| 448 | will only verify the hash output, without requiring symmetric key for |
| 449 | authentication tag verification. |
| 450 | |
| 451 | *************** |
| 452 | TF-M Test suite |
| 453 | *************** |
| 454 | |
| 455 | Symmetric Initial Attestation adds dedicated non-secure and secure test suites. |
| 456 | The test suites also follow asymmetric Initial Attestation test suites |
| 457 | implementation but optimize the memory footprint. |
| 458 | Symmetric Initial Attestation non-secure and secure test suites request Initial |
| 459 | Attestation secure service to generate IATs. After IATs are generated |
| 460 | successfully, test suites decode IATs and parse the claims. |
| 461 | Secure test suite also verifies the authentication tag in ``COSE_Mac0`` |
| 462 | structure. |
| 463 | |
| 464 | Symmetric Initial Attestation implements its dedicated |
| 465 | ``attest_token_decode_validate_token()`` in ``attest_symmetric_iat_decoded.c`` |
| 466 | to perform IAT decoding required by test suites. |
| 467 | If ``SYMMETRIC_INITIAL_ATTESTATION`` is selected, |
| 468 | ``attest_symmetric_iat_decoded.c`` is included in build. |
| 469 | Otherwise, asymmetric Initial Attestation dedicated implementations are included |
| 470 | instead. |
| 471 | |
| 472 | The workflow of symmetric Initial Attestation dedicated |
| 473 | ``attest_token_decode_validate_token()`` is shown below. |
| 474 | |
| 475 | .. _iat-decode-figure: |
| 476 | |
| 477 | .. figure:: media/symmetric_initial_attest/iat_decode.png |
| 478 | :align: center |
| 479 | |
| 480 | Workflow in symmetric Initial Attestation ``attest_token_decode_validate_token()`` |
| 481 | |
| 482 | If the decoding is required from secure test suite, |
| 483 | ``attest_token_decode_validate_token()`` will fetch symmetric IAK to verify the |
| 484 | authentication tag in ``COSE_Mac0`` structure. |
| 485 | If the decoding is required from non-secure test suite, |
| 486 | ``attest_token_decode_validate_token()`` will decode ``COSE_Mac0`` only by |
| 487 | setting ``T_COSE_OPT_DECODE_ONLY`` option flag. Non-secure must not access the |
| 488 | symmetric IAK. |
| 489 | |
| 490 | ******** |
| 491 | HAL APIs |
| 492 | ******** |
| 493 | |
| 494 | HAL APIs are summarized below. |
| 495 | |
| 496 | Fetch device symmetric IAK |
| 497 | ========================== |
| 498 | |
| 499 | ``tfm_plat_get_symmetric_iak()`` fetches device symmetric IAK. |
| 500 | |
| 501 | .. code-block:: c |
| 502 | |
| 503 | enum tfm_plat_err_t tfm_plat_get_symmetric_iak(uint8_t *key_buf, |
| 504 | size_t buf_len, |
| 505 | size_t *key_len, |
| 506 | psa_algorithm_t *key_alg); |
| 507 | |
| 508 | **Parameters:** |
| 509 | |
| 510 | +-------------+-----------------------------------------------------------+ |
| 511 | | ``key_buf`` | Buffer to store the symmetric IAK. | |
| 512 | +-------------+-----------------------------------------------------------+ |
| 513 | | ``buf_len`` | The length of ``key_buf``. | |
| 514 | +-------------+-----------------------------------------------------------+ |
| 515 | | ``key_len`` | The length of the symmetric IAK. | |
| 516 | +-------------+-----------------------------------------------------------+ |
| 517 | | ``key_alg`` | The key algorithm. Only HMAC SHA-256 is supported so far. | |
| 518 | +-------------+-----------------------------------------------------------+ |
| 519 | |
| 520 | It returns error code specified in ``enum tfm_plat_err_t``. |
| 521 | |
| 522 | Get symmetric IAK key identifier |
| 523 | ================================ |
| 524 | |
| 525 | ``attest_plat_get_symmetric_iak_id()`` gets the key identifier of the symmetric |
| 526 | IAK as the ``kid`` parameter in COSE Header. |
| 527 | |
| 528 | Optional if device doesn't install a key identifier for symmetric IAK. |
| 529 | |
| 530 | .. code-block:: c |
| 531 | |
| 532 | enum tfm_plat_err_t attest_plat_get_symmetric_iak_id(void *kid_buf, |
| 533 | size_t buf_len, |
| 534 | size_t *kid_len); |
| 535 | |
| 536 | **Parameters:** |
| 537 | |
| 538 | +-------------+-------------------------------------+ |
| 539 | | ``kid_buf`` | Buffer to store the IAK identifier. | |
| 540 | +-------------+-------------------------------------+ |
| 541 | | ``buf_len`` | The length of ``kid_buf``. | |
| 542 | +-------------+-------------------------------------+ |
| 543 | | ``kid_len`` | The length of the IAK identifier. | |
| 544 | +-------------+-------------------------------------+ |
| 545 | |
| 546 | It returns error code specified in ``enum tfm_plat_err_t``. |
| 547 | |
| 548 | ********* |
| 549 | Reference |
| 550 | ********* |
| 551 | |
| 552 | .. [1] `PSA Attestation API 1.0 (ARM IHI 0085) <https://developer.arm.com/-/media/Files/pdf/PlatformSecurityArchitecture/Implement/IHI0085-PSA_Attestation_API-1.0.2.pdf?revision=eef78753-c77e-4b24-bcf0-65596213b4c1&la=en&hash=E5E0353D612077AFDCE3F2F3708A50C77A74B2A3>`_ |
| 553 | |
Anton Komlev | affe14f | 2022-11-01 00:07:41 +0000 | [diff] [blame] | 554 | .. [2] :doc:`Trusted Firmware-M Profile Small Design </configuration/profiles/tfm_profile_small>` |
David Hu | c042793 | 2020-04-09 23:03:49 +0800 | [diff] [blame] | 555 | |
Anton Komlev | 3356ba3 | 2022-03-31 22:02:11 +0100 | [diff] [blame] | 556 | .. [3] :doc:`Initial Attestation Service Integration Guide </integration_guide/services/tfm_attestation_integration_guide>` |
David Hu | c042793 | 2020-04-09 23:03:49 +0800 | [diff] [blame] | 557 | |
| 558 | .. [4] `HMAC: Keyed-Hashing for Message Authentication <https://tools.ietf.org/html/rfc2104>`_ |
| 559 | |
| 560 | .. [5] `CBOR Object Signing and Encryption (COSE) <https://tools.ietf.org/html/rfc8152>`_ |
| 561 | |
| 562 | ---------------- |
| 563 | |
Raef Coles | b3adfeb | 2022-03-02 14:00:57 +0000 | [diff] [blame] | 564 | *Copyright (c) 2020-2022 Arm Limited. All Rights Reserved.* |