1*54fd6939SJiyong ParkTrusted Board Boot 2*54fd6939SJiyong Park================== 3*54fd6939SJiyong Park 4*54fd6939SJiyong ParkThe Trusted Board Boot (TBB) feature prevents malicious firmware from running on 5*54fd6939SJiyong Parkthe platform by authenticating all firmware images up to and including the 6*54fd6939SJiyong Parknormal world bootloader. It does this by establishing a Chain of Trust using 7*54fd6939SJiyong ParkPublic-Key-Cryptography Standards (PKCS). 8*54fd6939SJiyong Park 9*54fd6939SJiyong ParkThis document describes the design of Trusted Firmware-A (TF-A) TBB, which is an 10*54fd6939SJiyong Parkimplementation of the `Trusted Board Boot Requirements (TBBR)`_ specification, 11*54fd6939SJiyong ParkArm DEN0006D. It should be used in conjunction with the 12*54fd6939SJiyong Park:ref:`Firmware Update (FWU)` design document, which implements a specific aspect 13*54fd6939SJiyong Parkof the TBBR. 14*54fd6939SJiyong Park 15*54fd6939SJiyong ParkChain of Trust 16*54fd6939SJiyong Park-------------- 17*54fd6939SJiyong Park 18*54fd6939SJiyong ParkA Chain of Trust (CoT) starts with a set of implicitly trusted components. On 19*54fd6939SJiyong Parkthe Arm development platforms, these components are: 20*54fd6939SJiyong Park 21*54fd6939SJiyong Park- A SHA-256 hash of the Root of Trust Public Key (ROTPK). It is stored in the 22*54fd6939SJiyong Park trusted root-key storage registers. Alternatively, a development ROTPK might 23*54fd6939SJiyong Park be used and its hash embedded into the BL1 and BL2 images (only for 24*54fd6939SJiyong Park development purposes). 25*54fd6939SJiyong Park 26*54fd6939SJiyong Park- The BL1 image, on the assumption that it resides in ROM so cannot be 27*54fd6939SJiyong Park tampered with. 28*54fd6939SJiyong Park 29*54fd6939SJiyong ParkThe remaining components in the CoT are either certificates or boot loader 30*54fd6939SJiyong Parkimages. The certificates follow the `X.509 v3`_ standard. This standard 31*54fd6939SJiyong Parkenables adding custom extensions to the certificates, which are used to store 32*54fd6939SJiyong Parkessential information to establish the CoT. 33*54fd6939SJiyong Park 34*54fd6939SJiyong ParkIn the TBB CoT all certificates are self-signed. There is no need for a 35*54fd6939SJiyong ParkCertificate Authority (CA) because the CoT is not established by verifying the 36*54fd6939SJiyong Parkvalidity of a certificate's issuer but by the content of the certificate 37*54fd6939SJiyong Parkextensions. To sign the certificates, different signature schemes are available, 38*54fd6939SJiyong Parkplease refer to the :ref:`Build Options` for more details. 39*54fd6939SJiyong Park 40*54fd6939SJiyong ParkThe certificates are categorised as "Key" and "Content" certificates. Key 41*54fd6939SJiyong Parkcertificates are used to verify public keys which have been used to sign content 42*54fd6939SJiyong Parkcertificates. Content certificates are used to store the hash of a boot loader 43*54fd6939SJiyong Parkimage. An image can be authenticated by calculating its hash and matching it 44*54fd6939SJiyong Parkwith the hash extracted from the content certificate. Various hash algorithms 45*54fd6939SJiyong Parkare supported to calculate all hashes, please refer to the :ref:`Build Options` 46*54fd6939SJiyong Parkfor more details.. The public keys and hashes are included as non-standard 47*54fd6939SJiyong Parkextension fields in the `X.509 v3`_ certificates. 48*54fd6939SJiyong Park 49*54fd6939SJiyong ParkThe keys used to establish the CoT are: 50*54fd6939SJiyong Park 51*54fd6939SJiyong Park- **Root of trust key** 52*54fd6939SJiyong Park 53*54fd6939SJiyong Park The private part of this key is used to sign the BL2 content certificate and 54*54fd6939SJiyong Park the trusted key certificate. The public part is the ROTPK. 55*54fd6939SJiyong Park 56*54fd6939SJiyong Park- **Trusted world key** 57*54fd6939SJiyong Park 58*54fd6939SJiyong Park The private part is used to sign the key certificates corresponding to the 59*54fd6939SJiyong Park secure world images (SCP_BL2, BL31 and BL32). The public part is stored in 60*54fd6939SJiyong Park one of the extension fields in the trusted world certificate. 61*54fd6939SJiyong Park 62*54fd6939SJiyong Park- **Non-trusted world key** 63*54fd6939SJiyong Park 64*54fd6939SJiyong Park The private part is used to sign the key certificate corresponding to the 65*54fd6939SJiyong Park non secure world image (BL33). The public part is stored in one of the 66*54fd6939SJiyong Park extension fields in the trusted world certificate. 67*54fd6939SJiyong Park 68*54fd6939SJiyong Park- **BL3X keys** 69*54fd6939SJiyong Park 70*54fd6939SJiyong Park For each of SCP_BL2, BL31, BL32 and BL33, the private part is used to 71*54fd6939SJiyong Park sign the content certificate for the BL3X image. The public part is stored 72*54fd6939SJiyong Park in one of the extension fields in the corresponding key certificate. 73*54fd6939SJiyong Park 74*54fd6939SJiyong ParkThe following images are included in the CoT: 75*54fd6939SJiyong Park 76*54fd6939SJiyong Park- BL1 77*54fd6939SJiyong Park- BL2 78*54fd6939SJiyong Park- SCP_BL2 (optional) 79*54fd6939SJiyong Park- BL31 80*54fd6939SJiyong Park- BL33 81*54fd6939SJiyong Park- BL32 (optional) 82*54fd6939SJiyong Park 83*54fd6939SJiyong ParkThe following certificates are used to authenticate the images. 84*54fd6939SJiyong Park 85*54fd6939SJiyong Park- **BL2 content certificate** 86*54fd6939SJiyong Park 87*54fd6939SJiyong Park It is self-signed with the private part of the ROT key. It contains a hash 88*54fd6939SJiyong Park of the BL2 image. 89*54fd6939SJiyong Park 90*54fd6939SJiyong Park- **Trusted key certificate** 91*54fd6939SJiyong Park 92*54fd6939SJiyong Park It is self-signed with the private part of the ROT key. It contains the 93*54fd6939SJiyong Park public part of the trusted world key and the public part of the non-trusted 94*54fd6939SJiyong Park world key. 95*54fd6939SJiyong Park 96*54fd6939SJiyong Park- **SCP_BL2 key certificate** 97*54fd6939SJiyong Park 98*54fd6939SJiyong Park It is self-signed with the trusted world key. It contains the public part of 99*54fd6939SJiyong Park the SCP_BL2 key. 100*54fd6939SJiyong Park 101*54fd6939SJiyong Park- **SCP_BL2 content certificate** 102*54fd6939SJiyong Park 103*54fd6939SJiyong Park It is self-signed with the SCP_BL2 key. It contains a hash of the SCP_BL2 104*54fd6939SJiyong Park image. 105*54fd6939SJiyong Park 106*54fd6939SJiyong Park- **BL31 key certificate** 107*54fd6939SJiyong Park 108*54fd6939SJiyong Park It is self-signed with the trusted world key. It contains the public part of 109*54fd6939SJiyong Park the BL31 key. 110*54fd6939SJiyong Park 111*54fd6939SJiyong Park- **BL31 content certificate** 112*54fd6939SJiyong Park 113*54fd6939SJiyong Park It is self-signed with the BL31 key. It contains a hash of the BL31 image. 114*54fd6939SJiyong Park 115*54fd6939SJiyong Park- **BL32 key certificate** 116*54fd6939SJiyong Park 117*54fd6939SJiyong Park It is self-signed with the trusted world key. It contains the public part of 118*54fd6939SJiyong Park the BL32 key. 119*54fd6939SJiyong Park 120*54fd6939SJiyong Park- **BL32 content certificate** 121*54fd6939SJiyong Park 122*54fd6939SJiyong Park It is self-signed with the BL32 key. It contains a hash of the BL32 image. 123*54fd6939SJiyong Park 124*54fd6939SJiyong Park- **BL33 key certificate** 125*54fd6939SJiyong Park 126*54fd6939SJiyong Park It is self-signed with the non-trusted world key. It contains the public 127*54fd6939SJiyong Park part of the BL33 key. 128*54fd6939SJiyong Park 129*54fd6939SJiyong Park- **BL33 content certificate** 130*54fd6939SJiyong Park 131*54fd6939SJiyong Park It is self-signed with the BL33 key. It contains a hash of the BL33 image. 132*54fd6939SJiyong Park 133*54fd6939SJiyong ParkThe SCP_BL2 and BL32 certificates are optional, but they must be present if the 134*54fd6939SJiyong Parkcorresponding SCP_BL2 or BL32 images are present. 135*54fd6939SJiyong Park 136*54fd6939SJiyong ParkTrusted Board Boot Sequence 137*54fd6939SJiyong Park--------------------------- 138*54fd6939SJiyong Park 139*54fd6939SJiyong ParkThe CoT is verified through the following sequence of steps. The system panics 140*54fd6939SJiyong Parkif any of the steps fail. 141*54fd6939SJiyong Park 142*54fd6939SJiyong Park- BL1 loads and verifies the BL2 content certificate. The issuer public key is 143*54fd6939SJiyong Park read from the verified certificate. A hash of that key is calculated and 144*54fd6939SJiyong Park compared with the hash of the ROTPK read from the trusted root-key storage 145*54fd6939SJiyong Park registers. If they match, the BL2 hash is read from the certificate. 146*54fd6939SJiyong Park 147*54fd6939SJiyong Park .. note:: 148*54fd6939SJiyong Park The matching operation is platform specific and is currently 149*54fd6939SJiyong Park unimplemented on the Arm development platforms. 150*54fd6939SJiyong Park 151*54fd6939SJiyong Park- BL1 loads the BL2 image. Its hash is calculated and compared with the hash 152*54fd6939SJiyong Park read from the certificate. Control is transferred to the BL2 image if all 153*54fd6939SJiyong Park the comparisons succeed. 154*54fd6939SJiyong Park 155*54fd6939SJiyong Park- BL2 loads and verifies the trusted key certificate. The issuer public key is 156*54fd6939SJiyong Park read from the verified certificate. A hash of that key is calculated and 157*54fd6939SJiyong Park compared with the hash of the ROTPK read from the trusted root-key storage 158*54fd6939SJiyong Park registers. If the comparison succeeds, BL2 reads and saves the trusted and 159*54fd6939SJiyong Park non-trusted world public keys from the verified certificate. 160*54fd6939SJiyong Park 161*54fd6939SJiyong ParkThe next two steps are executed for each of the SCP_BL2, BL31 & BL32 images. 162*54fd6939SJiyong ParkThe steps for the optional SCP_BL2 and BL32 images are skipped if these images 163*54fd6939SJiyong Parkare not present. 164*54fd6939SJiyong Park 165*54fd6939SJiyong Park- BL2 loads and verifies the BL3x key certificate. The certificate signature 166*54fd6939SJiyong Park is verified using the trusted world public key. If the signature 167*54fd6939SJiyong Park verification succeeds, BL2 reads and saves the BL3x public key from the 168*54fd6939SJiyong Park certificate. 169*54fd6939SJiyong Park 170*54fd6939SJiyong Park- BL2 loads and verifies the BL3x content certificate. The signature is 171*54fd6939SJiyong Park verified using the BL3x public key. If the signature verification succeeds, 172*54fd6939SJiyong Park BL2 reads and saves the BL3x image hash from the certificate. 173*54fd6939SJiyong Park 174*54fd6939SJiyong ParkThe next two steps are executed only for the BL33 image. 175*54fd6939SJiyong Park 176*54fd6939SJiyong Park- BL2 loads and verifies the BL33 key certificate. If the signature 177*54fd6939SJiyong Park verification succeeds, BL2 reads and saves the BL33 public key from the 178*54fd6939SJiyong Park certificate. 179*54fd6939SJiyong Park 180*54fd6939SJiyong Park- BL2 loads and verifies the BL33 content certificate. If the signature 181*54fd6939SJiyong Park verification succeeds, BL2 reads and saves the BL33 image hash from the 182*54fd6939SJiyong Park certificate. 183*54fd6939SJiyong Park 184*54fd6939SJiyong ParkThe next step is executed for all the boot loader images. 185*54fd6939SJiyong Park 186*54fd6939SJiyong Park- BL2 calculates the hash of each image. It compares it with the hash obtained 187*54fd6939SJiyong Park from the corresponding content certificate. The image authentication succeeds 188*54fd6939SJiyong Park if the hashes match. 189*54fd6939SJiyong Park 190*54fd6939SJiyong ParkThe Trusted Board Boot implementation spans both generic and platform-specific 191*54fd6939SJiyong ParkBL1 and BL2 code, and in tool code on the host build machine. The feature is 192*54fd6939SJiyong Parkenabled through use of specific build flags as described in 193*54fd6939SJiyong Park:ref:`Build Options`. 194*54fd6939SJiyong Park 195*54fd6939SJiyong ParkOn the host machine, a tool generates the certificates, which are included in 196*54fd6939SJiyong Parkthe FIP along with the boot loader images. These certificates are loaded in 197*54fd6939SJiyong ParkTrusted SRAM using the IO storage framework. They are then verified by an 198*54fd6939SJiyong ParkAuthentication module included in TF-A. 199*54fd6939SJiyong Park 200*54fd6939SJiyong ParkThe mechanism used for generating the FIP and the Authentication module are 201*54fd6939SJiyong Parkdescribed in the following sections. 202*54fd6939SJiyong Park 203*54fd6939SJiyong ParkAuthentication Framework 204*54fd6939SJiyong Park------------------------ 205*54fd6939SJiyong Park 206*54fd6939SJiyong ParkThe authentication framework included in TF-A provides support to implement 207*54fd6939SJiyong Parkthe desired trusted boot sequence. Arm platforms use this framework to 208*54fd6939SJiyong Parkimplement the boot requirements specified in the 209*54fd6939SJiyong Park`Trusted Board Boot Requirements (TBBR)`_ document. 210*54fd6939SJiyong Park 211*54fd6939SJiyong ParkMore information about the authentication framework can be found in the 212*54fd6939SJiyong Park:ref:`Authentication Framework & Chain of Trust` document. 213*54fd6939SJiyong Park 214*54fd6939SJiyong ParkCertificate Generation Tool 215*54fd6939SJiyong Park--------------------------- 216*54fd6939SJiyong Park 217*54fd6939SJiyong ParkThe ``cert_create`` tool is built and runs on the host machine as part of the 218*54fd6939SJiyong ParkTF-A build process when ``GENERATE_COT=1``. It takes the boot loader images 219*54fd6939SJiyong Parkand keys as inputs (keys must be in PEM format) and generates the 220*54fd6939SJiyong Parkcertificates (in DER format) required to establish the CoT. New keys can be 221*54fd6939SJiyong Parkgenerated by the tool in case they are not provided. The certificates are then 222*54fd6939SJiyong Parkpassed as inputs to the ``fiptool`` utility for creating the FIP. 223*54fd6939SJiyong Park 224*54fd6939SJiyong ParkThe certificates are also stored individually in the output build directory. 225*54fd6939SJiyong Park 226*54fd6939SJiyong ParkThe tool resides in the ``tools/cert_create`` directory. It uses the OpenSSL SSL 227*54fd6939SJiyong Parklibrary version to generate the X.509 certificates. The specific version of the 228*54fd6939SJiyong Parklibrary that is required is given in the :ref:`Prerequisites` document. 229*54fd6939SJiyong Park 230*54fd6939SJiyong ParkInstructions for building and using the tool can be found at 231*54fd6939SJiyong Park:ref:`tools_build_cert_create`. 232*54fd6939SJiyong Park 233*54fd6939SJiyong ParkAuthenticated Encryption Framework 234*54fd6939SJiyong Park---------------------------------- 235*54fd6939SJiyong Park 236*54fd6939SJiyong ParkThe authenticated encryption framework included in TF-A provides support to 237*54fd6939SJiyong Parkimplement the optional firmware encryption feature. This feature can be 238*54fd6939SJiyong Parkoptionally enabled on platforms to implement the optional requirement: 239*54fd6939SJiyong ParkR060_TBBR_FUNCTION as specified in the `Trusted Board Boot Requirements (TBBR)`_ 240*54fd6939SJiyong Parkdocument. 241*54fd6939SJiyong Park 242*54fd6939SJiyong ParkFirmware Encryption Tool 243*54fd6939SJiyong Park------------------------ 244*54fd6939SJiyong Park 245*54fd6939SJiyong ParkThe ``encrypt_fw`` tool is built and runs on the host machine as part of the 246*54fd6939SJiyong ParkTF-A build process when ``DECRYPTION_SUPPORT != none``. It takes the plain 247*54fd6939SJiyong Parkfirmware image as input and generates the encrypted firmware image which can 248*54fd6939SJiyong Parkthen be passed as input to the ``fiptool`` utility for creating the FIP. 249*54fd6939SJiyong Park 250*54fd6939SJiyong ParkThe encrypted firmwares are also stored individually in the output build 251*54fd6939SJiyong Parkdirectory. 252*54fd6939SJiyong Park 253*54fd6939SJiyong ParkThe tool resides in the ``tools/encrypt_fw`` directory. It uses OpenSSL SSL 254*54fd6939SJiyong Parklibrary version 1.0.1 or later to do authenticated encryption operation. 255*54fd6939SJiyong ParkInstructions for building and using the tool can be found in the 256*54fd6939SJiyong Park:ref:`tools_build_enctool`. 257*54fd6939SJiyong Park 258*54fd6939SJiyong Park-------------- 259*54fd6939SJiyong Park 260*54fd6939SJiyong Park*Copyright (c) 2015-2020, Arm Limited and Contributors. All rights reserved.* 261*54fd6939SJiyong Park 262*54fd6939SJiyong Park.. _X.509 v3: https://tools.ietf.org/rfc/rfc5280.txt 263*54fd6939SJiyong Park.. _Trusted Board Boot Requirements (TBBR): https://developer.arm.com/docs/den0006/latest/trusted-board-boot-requirements-client-tbbr-client-armv8-a 264