18aa05055SPaul BeesleyTrusted Board Boot 28aa05055SPaul Beesley================== 340d553cfSPaul Beesley 440d553cfSPaul BeesleyThe Trusted Board Boot (TBB) feature prevents malicious firmware from running on 540d553cfSPaul Beesleythe platform by authenticating all firmware images up to and including the 640d553cfSPaul Beesleynormal world bootloader. It does this by establishing a Chain of Trust using 740d553cfSPaul BeesleyPublic-Key-Cryptography Standards (PKCS). 840d553cfSPaul Beesley 940d553cfSPaul BeesleyThis document describes the design of Trusted Firmware-A (TF-A) TBB, which is an 1040d553cfSPaul Beesleyimplementation of the `Trusted Board Boot Requirements (TBBR)`_ specification, 1134760951SPaul BeesleyArm DEN0006D. It should be used in conjunction with the 1234760951SPaul Beesley:ref:`Firmware Update (FWU)` design document, which implements a specific aspect 1334760951SPaul Beesleyof the TBBR. 1440d553cfSPaul Beesley 1540d553cfSPaul BeesleyChain of Trust 1640d553cfSPaul Beesley-------------- 1740d553cfSPaul Beesley 1840d553cfSPaul BeesleyA Chain of Trust (CoT) starts with a set of implicitly trusted components. On 1940d553cfSPaul Beesleythe Arm development platforms, these components are: 2040d553cfSPaul Beesley 2140d553cfSPaul Beesley- A SHA-256 hash of the Root of Trust Public Key (ROTPK). It is stored in the 22316c5cc6SSandrine Bailleux trusted root-key storage registers. Alternatively, a development ROTPK might 23316c5cc6SSandrine Bailleux be used and its hash embedded into the BL1 and BL2 images (only for 24316c5cc6SSandrine Bailleux development purposes). 2540d553cfSPaul Beesley 2640d553cfSPaul Beesley- The BL1 image, on the assumption that it resides in ROM so cannot be 2740d553cfSPaul Beesley tampered with. 2840d553cfSPaul Beesley 2940d553cfSPaul BeesleyThe remaining components in the CoT are either certificates or boot loader 3040d553cfSPaul Beesleyimages. The certificates follow the `X.509 v3`_ standard. This standard 3140d553cfSPaul Beesleyenables adding custom extensions to the certificates, which are used to store 3240d553cfSPaul Beesleyessential information to establish the CoT. 3340d553cfSPaul Beesley 3440d553cfSPaul BeesleyIn the TBB CoT all certificates are self-signed. There is no need for a 3540d553cfSPaul BeesleyCertificate Authority (CA) because the CoT is not established by verifying the 3640d553cfSPaul Beesleyvalidity of a certificate's issuer but by the content of the certificate 37316c5cc6SSandrine Bailleuxextensions. To sign the certificates, different signature schemes are available, 38316c5cc6SSandrine Bailleuxplease refer to the :ref:`Build Options` for more details. 3940d553cfSPaul Beesley 4040d553cfSPaul BeesleyThe certificates are categorised as "Key" and "Content" certificates. Key 4140d553cfSPaul Beesleycertificates are used to verify public keys which have been used to sign content 4240d553cfSPaul Beesleycertificates. Content certificates are used to store the hash of a boot loader 4340d553cfSPaul Beesleyimage. An image can be authenticated by calculating its hash and matching it 44316c5cc6SSandrine Bailleuxwith the hash extracted from the content certificate. Various hash algorithms 45316c5cc6SSandrine Bailleuxare supported to calculate all hashes, please refer to the :ref:`Build Options` 46316c5cc6SSandrine Bailleuxfor more details.. The public keys and hashes are included as non-standard 47316c5cc6SSandrine Bailleuxextension fields in the `X.509 v3`_ certificates. 4840d553cfSPaul Beesley 4940d553cfSPaul BeesleyThe keys used to establish the CoT are: 5040d553cfSPaul Beesley 5140d553cfSPaul Beesley- **Root of trust key** 5240d553cfSPaul Beesley 5340d553cfSPaul Beesley The private part of this key is used to sign the BL2 content certificate and 5440d553cfSPaul Beesley the trusted key certificate. The public part is the ROTPK. 5540d553cfSPaul Beesley 5640d553cfSPaul Beesley- **Trusted world key** 5740d553cfSPaul Beesley 5840d553cfSPaul Beesley The private part is used to sign the key certificates corresponding to the 5940d553cfSPaul Beesley secure world images (SCP_BL2, BL31 and BL32). The public part is stored in 6040d553cfSPaul Beesley one of the extension fields in the trusted world certificate. 6140d553cfSPaul Beesley 6240d553cfSPaul Beesley- **Non-trusted world key** 6340d553cfSPaul Beesley 6440d553cfSPaul Beesley The private part is used to sign the key certificate corresponding to the 6540d553cfSPaul Beesley non secure world image (BL33). The public part is stored in one of the 6640d553cfSPaul Beesley extension fields in the trusted world certificate. 6740d553cfSPaul Beesley 68316c5cc6SSandrine Bailleux- **BL3X keys** 6940d553cfSPaul Beesley 7040d553cfSPaul Beesley For each of SCP_BL2, BL31, BL32 and BL33, the private part is used to 71316c5cc6SSandrine Bailleux sign the content certificate for the BL3X image. The public part is stored 7240d553cfSPaul Beesley in one of the extension fields in the corresponding key certificate. 7340d553cfSPaul Beesley 7440d553cfSPaul BeesleyThe following images are included in the CoT: 7540d553cfSPaul Beesley 7640d553cfSPaul Beesley- BL1 7740d553cfSPaul Beesley- BL2 7840d553cfSPaul Beesley- SCP_BL2 (optional) 7940d553cfSPaul Beesley- BL31 8040d553cfSPaul Beesley- BL33 8140d553cfSPaul Beesley- BL32 (optional) 8240d553cfSPaul Beesley 8340d553cfSPaul BeesleyThe following certificates are used to authenticate the images. 8440d553cfSPaul Beesley 8540d553cfSPaul Beesley- **BL2 content certificate** 8640d553cfSPaul Beesley 8740d553cfSPaul Beesley It is self-signed with the private part of the ROT key. It contains a hash 8840d553cfSPaul Beesley of the BL2 image. 8940d553cfSPaul Beesley 9040d553cfSPaul Beesley- **Trusted key certificate** 9140d553cfSPaul Beesley 9240d553cfSPaul Beesley It is self-signed with the private part of the ROT key. It contains the 9340d553cfSPaul Beesley public part of the trusted world key and the public part of the non-trusted 9440d553cfSPaul Beesley world key. 9540d553cfSPaul Beesley 9640d553cfSPaul Beesley- **SCP_BL2 key certificate** 9740d553cfSPaul Beesley 9840d553cfSPaul Beesley It is self-signed with the trusted world key. It contains the public part of 9940d553cfSPaul Beesley the SCP_BL2 key. 10040d553cfSPaul Beesley 10140d553cfSPaul Beesley- **SCP_BL2 content certificate** 10240d553cfSPaul Beesley 10340d553cfSPaul Beesley It is self-signed with the SCP_BL2 key. It contains a hash of the SCP_BL2 10440d553cfSPaul Beesley image. 10540d553cfSPaul Beesley 10640d553cfSPaul Beesley- **BL31 key certificate** 10740d553cfSPaul Beesley 10840d553cfSPaul Beesley It is self-signed with the trusted world key. It contains the public part of 10940d553cfSPaul Beesley the BL31 key. 11040d553cfSPaul Beesley 11140d553cfSPaul Beesley- **BL31 content certificate** 11240d553cfSPaul Beesley 11340d553cfSPaul Beesley It is self-signed with the BL31 key. It contains a hash of the BL31 image. 11440d553cfSPaul Beesley 11540d553cfSPaul Beesley- **BL32 key certificate** 11640d553cfSPaul Beesley 11740d553cfSPaul Beesley It is self-signed with the trusted world key. It contains the public part of 11840d553cfSPaul Beesley the BL32 key. 11940d553cfSPaul Beesley 12040d553cfSPaul Beesley- **BL32 content certificate** 12140d553cfSPaul Beesley 12240d553cfSPaul Beesley It is self-signed with the BL32 key. It contains a hash of the BL32 image. 12340d553cfSPaul Beesley 12440d553cfSPaul Beesley- **BL33 key certificate** 12540d553cfSPaul Beesley 12640d553cfSPaul Beesley It is self-signed with the non-trusted world key. It contains the public 12740d553cfSPaul Beesley part of the BL33 key. 12840d553cfSPaul Beesley 12940d553cfSPaul Beesley- **BL33 content certificate** 13040d553cfSPaul Beesley 13140d553cfSPaul Beesley It is self-signed with the BL33 key. It contains a hash of the BL33 image. 13240d553cfSPaul Beesley 13340d553cfSPaul BeesleyThe SCP_BL2 and BL32 certificates are optional, but they must be present if the 13440d553cfSPaul Beesleycorresponding SCP_BL2 or BL32 images are present. 13540d553cfSPaul Beesley 13640d553cfSPaul BeesleyTrusted Board Boot Sequence 13740d553cfSPaul Beesley--------------------------- 13840d553cfSPaul Beesley 13940d553cfSPaul BeesleyThe CoT is verified through the following sequence of steps. The system panics 14040d553cfSPaul Beesleyif any of the steps fail. 14140d553cfSPaul Beesley 14240d553cfSPaul Beesley- BL1 loads and verifies the BL2 content certificate. The issuer public key is 14340d553cfSPaul Beesley read from the verified certificate. A hash of that key is calculated and 14440d553cfSPaul Beesley compared with the hash of the ROTPK read from the trusted root-key storage 14540d553cfSPaul Beesley registers. If they match, the BL2 hash is read from the certificate. 14640d553cfSPaul Beesley 147e1c5026aSPaul Beesley .. note:: 148e1c5026aSPaul Beesley The matching operation is platform specific and is currently 14940d553cfSPaul Beesley unimplemented on the Arm development platforms. 15040d553cfSPaul Beesley 15140d553cfSPaul Beesley- BL1 loads the BL2 image. Its hash is calculated and compared with the hash 15240d553cfSPaul Beesley read from the certificate. Control is transferred to the BL2 image if all 15340d553cfSPaul Beesley the comparisons succeed. 15440d553cfSPaul Beesley 15540d553cfSPaul Beesley- BL2 loads and verifies the trusted key certificate. The issuer public key is 15640d553cfSPaul Beesley read from the verified certificate. A hash of that key is calculated and 15740d553cfSPaul Beesley compared with the hash of the ROTPK read from the trusted root-key storage 15840d553cfSPaul Beesley registers. If the comparison succeeds, BL2 reads and saves the trusted and 15940d553cfSPaul Beesley non-trusted world public keys from the verified certificate. 16040d553cfSPaul Beesley 16140d553cfSPaul BeesleyThe next two steps are executed for each of the SCP_BL2, BL31 & BL32 images. 16240d553cfSPaul BeesleyThe steps for the optional SCP_BL2 and BL32 images are skipped if these images 16340d553cfSPaul Beesleyare not present. 16440d553cfSPaul Beesley 16540d553cfSPaul Beesley- BL2 loads and verifies the BL3x key certificate. The certificate signature 16640d553cfSPaul Beesley is verified using the trusted world public key. If the signature 16740d553cfSPaul Beesley verification succeeds, BL2 reads and saves the BL3x public key from the 16840d553cfSPaul Beesley certificate. 16940d553cfSPaul Beesley 17040d553cfSPaul Beesley- BL2 loads and verifies the BL3x content certificate. The signature is 17140d553cfSPaul Beesley verified using the BL3x public key. If the signature verification succeeds, 17240d553cfSPaul Beesley BL2 reads and saves the BL3x image hash from the certificate. 17340d553cfSPaul Beesley 17440d553cfSPaul BeesleyThe next two steps are executed only for the BL33 image. 17540d553cfSPaul Beesley 17640d553cfSPaul Beesley- BL2 loads and verifies the BL33 key certificate. If the signature 17740d553cfSPaul Beesley verification succeeds, BL2 reads and saves the BL33 public key from the 17840d553cfSPaul Beesley certificate. 17940d553cfSPaul Beesley 18040d553cfSPaul Beesley- BL2 loads and verifies the BL33 content certificate. If the signature 18140d553cfSPaul Beesley verification succeeds, BL2 reads and saves the BL33 image hash from the 18240d553cfSPaul Beesley certificate. 18340d553cfSPaul Beesley 18440d553cfSPaul BeesleyThe next step is executed for all the boot loader images. 18540d553cfSPaul Beesley 18640d553cfSPaul Beesley- BL2 calculates the hash of each image. It compares it with the hash obtained 18740d553cfSPaul Beesley from the corresponding content certificate. The image authentication succeeds 18840d553cfSPaul Beesley if the hashes match. 18940d553cfSPaul Beesley 19040d553cfSPaul BeesleyThe Trusted Board Boot implementation spans both generic and platform-specific 19140d553cfSPaul BeesleyBL1 and BL2 code, and in tool code on the host build machine. The feature is 19243f35ef5SPaul Beesleyenabled through use of specific build flags as described in 19343f35ef5SPaul Beesley:ref:`Build Options`. 19440d553cfSPaul Beesley 19540d553cfSPaul BeesleyOn the host machine, a tool generates the certificates, which are included in 19640d553cfSPaul Beesleythe FIP along with the boot loader images. These certificates are loaded in 19740d553cfSPaul BeesleyTrusted SRAM using the IO storage framework. They are then verified by an 19840d553cfSPaul BeesleyAuthentication module included in TF-A. 19940d553cfSPaul Beesley 20040d553cfSPaul BeesleyThe mechanism used for generating the FIP and the Authentication module are 20140d553cfSPaul Beesleydescribed in the following sections. 20240d553cfSPaul Beesley 20340d553cfSPaul BeesleyAuthentication Framework 20440d553cfSPaul Beesley------------------------ 20540d553cfSPaul Beesley 20640d553cfSPaul BeesleyThe authentication framework included in TF-A provides support to implement 20740d553cfSPaul Beesleythe desired trusted boot sequence. Arm platforms use this framework to 20834760951SPaul Beesleyimplement the boot requirements specified in the 20934760951SPaul Beesley`Trusted Board Boot Requirements (TBBR)`_ document. 21040d553cfSPaul Beesley 21140d553cfSPaul BeesleyMore information about the authentication framework can be found in the 21234760951SPaul Beesley:ref:`Authentication Framework & Chain of Trust` document. 21340d553cfSPaul Beesley 21440d553cfSPaul BeesleyCertificate Generation Tool 21540d553cfSPaul Beesley--------------------------- 21640d553cfSPaul Beesley 21740d553cfSPaul BeesleyThe ``cert_create`` tool is built and runs on the host machine as part of the 21840d553cfSPaul BeesleyTF-A build process when ``GENERATE_COT=1``. It takes the boot loader images 219616b3ce2SRobin van der Grachtand keys as inputs and generates the certificates (in DER format) required to 220616b3ce2SRobin van der Grachtestablish the CoT. The input keys must either be a file in PEM format or a 221616b3ce2SRobin van der GrachtPKCS11 URI in case a HSM is used. New keys can be generated by the tool in 222616b3ce2SRobin van der Grachtcase they are not provided. The certificates are then passed as inputs to 223616b3ce2SRobin van der Grachtthe ``fiptool`` utility for creating the FIP. 22440d553cfSPaul Beesley 225316c5cc6SSandrine BailleuxThe certificates are also stored individually in the output build directory. 22640d553cfSPaul Beesley 22743f35ef5SPaul BeesleyThe tool resides in the ``tools/cert_create`` directory. It uses the OpenSSL SSL 22843f35ef5SPaul Beesleylibrary version to generate the X.509 certificates. The specific version of the 22943f35ef5SPaul Beesleylibrary that is required is given in the :ref:`Prerequisites` document. 23043f35ef5SPaul Beesley 23143f35ef5SPaul BeesleyInstructions for building and using the tool can be found at 23243f35ef5SPaul Beesley:ref:`tools_build_cert_create`. 23340d553cfSPaul Beesley 234f97062a5SSumit GargAuthenticated Encryption Framework 235f97062a5SSumit Garg---------------------------------- 236f97062a5SSumit Garg 237f97062a5SSumit GargThe authenticated encryption framework included in TF-A provides support to 238f97062a5SSumit Gargimplement the optional firmware encryption feature. This feature can be 239f97062a5SSumit Gargoptionally enabled on platforms to implement the optional requirement: 240f97062a5SSumit GargR060_TBBR_FUNCTION as specified in the `Trusted Board Boot Requirements (TBBR)`_ 241f97062a5SSumit Gargdocument. 242f97062a5SSumit Garg 243f97062a5SSumit GargFirmware Encryption Tool 244f97062a5SSumit Garg------------------------ 245f97062a5SSumit Garg 246f97062a5SSumit GargThe ``encrypt_fw`` tool is built and runs on the host machine as part of the 247f97062a5SSumit GargTF-A build process when ``DECRYPTION_SUPPORT != none``. It takes the plain 248f97062a5SSumit Gargfirmware image as input and generates the encrypted firmware image which can 249f97062a5SSumit Gargthen be passed as input to the ``fiptool`` utility for creating the FIP. 250f97062a5SSumit Garg 251f97062a5SSumit GargThe encrypted firmwares are also stored individually in the output build 252f97062a5SSumit Gargdirectory. 253f97062a5SSumit Garg 254f97062a5SSumit GargThe tool resides in the ``tools/encrypt_fw`` directory. It uses OpenSSL SSL 255f97062a5SSumit Garglibrary version 1.0.1 or later to do authenticated encryption operation. 256f97062a5SSumit GargInstructions for building and using the tool can be found in the 257f97062a5SSumit Garg:ref:`tools_build_enctool`. 258f97062a5SSumit Garg 25940d553cfSPaul Beesley-------------- 26040d553cfSPaul Beesley 261316c5cc6SSandrine Bailleux*Copyright (c) 2015-2020, Arm Limited and Contributors. All rights reserved.* 26240d553cfSPaul Beesley 26340d553cfSPaul Beesley.. _X.509 v3: https://tools.ietf.org/rfc/rfc5280.txt 264*4290d343SSandrine Bailleux.. _Trusted Board Boot Requirements (TBBR): https://developer.arm.com/docs/den0006/latest 265