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