measured_boot_poc.rst 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. Interaction between Measured Boot and an fTPM (PoC)
  2. ===================================================
  3. Measured Boot is the process of cryptographically measuring the code and
  4. critical data used at boot time, for example using a TPM, so that the
  5. security state can be attested later.
  6. The current implementation of the driver included in Trusted Firmware-A
  7. (TF-A) stores the measurements into a `TGC event log`_ in secure
  8. memory. No other means of recording measurements (such as a discrete TPM) is
  9. supported right now.
  10. The driver also provides mechanisms to pass the Event Log to normal world if
  11. needed.
  12. This manual provides instructions to build a proof of concept (PoC) with the
  13. sole intention of showing how Measured Boot can be used in conjunction with
  14. a firmware TPM (fTPM) service implemented on top of OP-TEE.
  15. .. note::
  16. The instructions given in this document are meant to be used to build
  17. a PoC to show how Measured Boot on TF-A can interact with a third
  18. party (f)TPM service and they try to be as general as possible. Different
  19. platforms might have different needs and configurations (e.g. different
  20. SHA algorithms) and they might also use different types of TPM services
  21. (or even a different type of service to provide the attestation)
  22. and therefore the instuctions given here might not apply in such scenarios.
  23. Components
  24. ~~~~~~~~~~
  25. The PoC is built on top of the `OP-TEE Toolkit`_, which has support to build
  26. TF-A with support for Measured Boot enabled (and run it on a Foundation Model)
  27. since commit cf56848.
  28. The aforementioned toolkit builds a set of images that contain all the components
  29. needed to test that the Event Log was properly created. One of these images will
  30. contain a third party fTPM service which in turn will be used to process the
  31. Event Log.
  32. The reason to choose OP-TEE Toolkit to build our PoC around it is mostly
  33. for convenience. As the fTPM service used is an OP-TEE TA, it was easy to add
  34. build support for it to the toolkit and then build the PoC around it.
  35. The most relevant components installed in the image that are closely related to
  36. Measured Boot/fTPM functionality are:
  37. - **OP-TEE**: As stated earlier, the fTPM service used in this PoC is built as an
  38. OP-TEE TA and therefore we need to include the OP-TEE OS image.
  39. Support to interfacing with Measured Boot was added to version 3.9.0 of
  40. OP-TEE by implementing the ``PTA_SYSTEM_GET_TPM_EVENT_LOG`` syscall, which
  41. allows the former to pass a copy of the Event Log to any TA requesting it.
  42. OP-TEE knows the location of the Event Log by reading the DTB bindings
  43. received from TF-A. Visit :ref:`DTB binding for Event Log properties`
  44. for more details on this.
  45. - **fTPM Service**: We use a third party fTPM service in order to validate
  46. the Measured Boot functionality. The chosen fTPM service is a sample
  47. implementation for Aarch32 architecture included on the `ms-tpm-20-ref`_
  48. reference implementation from Microsoft. The service was updated in order
  49. to extend the Measured Boot Event Log at boot up and it uses the
  50. aforementioned ``PTA_SYSTEM_GET_TPM_EVENT_LOG`` call to retrieve a copy
  51. of the former.
  52. .. note::
  53. Arm does not provide an fTPM implementation. The fTPM service used here
  54. is a third party one which has been updated to support Measured Boot
  55. service as provided by TF-A. As such, it is beyond the scope of this
  56. manual to test and verify the correctness of the output generated by the
  57. fTPM service.
  58. - **TPM Kernel module**: In order to interact with the fTPM service, we need
  59. a kernel module to forward the request from user space to the secure world.
  60. - `tpm2-tools`_: This is a set of tools that allow to interact with the
  61. fTPM service. We use this in order to read the PCRs with the measurements.
  62. Building the PoC for the Arm FVP platform
  63. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  64. As mentioned before, this PoC is based on the OP-TEE Toolkit with some
  65. extensions to enable Measured Boot and an fTPM service. Therefore, we can rely
  66. on the instructions to build the original OP-TEE Toolkit. As a general rule,
  67. the following steps should suffice:
  68. (1) Start by following the `Get and build the solution`_ instructions to build
  69. the OP-TEE toolkit. On step 3, you need to get the manifest for FVP
  70. platform from the main branch:
  71. .. code:: shell
  72. $ repo init -u https://github.com/OP-TEE/manifest.git -m fvp.xml
  73. Then proceed synching the repos as stated in step 3. Continue following
  74. the instructions and stop before step 5.
  75. (2) Next you should obtain the `Armv8-A Foundation Platform (For Linux Hosts Only)`_.
  76. The binary should be untar'ed to the root of the repo tree, i.e., like
  77. this: ``<fvp-project>/Foundation_Platformpkg``. In the end, after cloning
  78. all source code, getting the toolchains and "installing"
  79. Foundation_Platformpkg, you should have a folder structure that looks like
  80. this:
  81. .. code:: shell
  82. $ ls -la
  83. total 80
  84. drwxrwxr-x 20 tf-a_user tf-a_user 4096 Jul 1 12:16 .
  85. drwxr-xr-x 23 tf-a_user tf-a_user 4096 Jul 1 10:40 ..
  86. drwxrwxr-x 12 tf-a_user tf-a_user 4096 Jul 1 10:45 build
  87. drwxrwxr-x 16 tf-a_user tf-a_user 4096 Jul 1 12:16 buildroot
  88. drwxrwxr-x 51 tf-a_user tf-a_user 4096 Jul 1 10:45 edk2
  89. drwxrwxr-x 6 tf-a_user tf-a_user 4096 Jul 1 12:14 edk2-platforms
  90. drwxr-xr-x 7 tf-a_user tf-a_user 4096 Jul 1 10:52 Foundation_Platformpkg
  91. drwxrwxr-x 17 tf-a_user tf-a_user 4096 Jul 2 10:40 grub
  92. drwxrwxr-x 25 tf-a_user tf-a_user 4096 Jul 2 10:39 linux
  93. drwxrwxr-x 15 tf-a_user tf-a_user 4096 Jul 1 10:45 mbedtls
  94. drwxrwxr-x 6 tf-a_user tf-a_user 4096 Jul 1 10:45 ms-tpm-20-ref
  95. drwxrwxr-x 8 tf-a_user tf-a_user 4096 Jul 1 10:45 optee_client
  96. drwxrwxr-x 10 tf-a_user tf-a_user 4096 Jul 1 10:45 optee_examples
  97. drwxrwxr-x 12 tf-a_user tf-a_user 4096 Jul 1 12:13 optee_os
  98. drwxrwxr-x 8 tf-a_user tf-a_user 4096 Jul 1 10:45 optee_test
  99. drwxrwxr-x 7 tf-a_user tf-a_user 4096 Jul 1 10:45 .repo
  100. drwxrwxr-x 4 tf-a_user tf-a_user 4096 Jul 1 12:12 toolchains
  101. drwxrwxr-x 21 tf-a_user tf-a_user 4096 Jul 1 12:15 trusted-firmware-a
  102. (3) Now enter into ``ms-tpm-20-ref`` and get its dependencies:
  103. .. code:: shell
  104. $ cd ms-tpm-20-ref
  105. $ git submodule init
  106. $ git submodule update
  107. Submodule path 'external/wolfssl': checked out '9c87f979a7f1d3a6d786b260653d566c1d31a1c4'
  108. (4) Now, you should be able to continue with step 5 in "`Get and build the solution`_"
  109. instructions. In order to enable support for Measured Boot, you need to
  110. set the ``MEASURED_BOOT`` build option:
  111. .. code:: shell
  112. $ MEASURED_BOOT=y make -j `nproc`
  113. .. note::
  114. The build process will likely take a long time. It is strongly recommended to
  115. pass the ``-j`` option to make to run the process faster.
  116. After this step, you should be ready to run the image.
  117. Running and using the PoC on the Armv8-A Foundation AEM FVP
  118. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  119. With everything built, you can now run the image:
  120. .. code:: shell
  121. $ make run-only
  122. .. note::
  123. Using ``make run`` will build and run the image and it can be used instead
  124. of simply ``make``. However, once the image is built, it is recommended to
  125. use ``make run-only`` to avoid re-running all the building rules, which
  126. would take time.
  127. When FVP is launched, two terminal windows will appear. ``FVP terminal_0``
  128. is the userspace terminal whereas ``FVP terminal_1`` is the counterpart for
  129. the secure world (where TAs will print their logs, for instance).
  130. Log into the image shell with user ``root``, no password will be required.
  131. Then we can issue the ``ftpm`` command, which is an alias that
  132. (1) loads the ftpm kernel module and
  133. (2) calls ``tpm2_pcrread``, which will access the fTPM service to read the
  134. PCRs.
  135. When loading the ftpm kernel module, the fTPM TA is loaded into the secure
  136. world. This TA then requests a copy of the Event Log generated during the
  137. booting process so it can retrieve all the entries on the log and record them
  138. first thing.
  139. .. note::
  140. For this PoC, nothing loaded after BL33 and NT_FW_CONFIG is recorded
  141. in the Event Log.
  142. The secure world terminal should show the debug logs for the fTPM service,
  143. including all the measurements available in the Event Log as they are being
  144. processed:
  145. .. code:: shell
  146. M/TA: Preparing to extend the following TPM Event Log:
  147. M/TA: TCG_EfiSpecIDEvent:
  148. M/TA: PCRIndex : 0
  149. M/TA: EventType : 3
  150. M/TA: Digest : 00
  151. M/TA: : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  152. M/TA: : 00 00 00
  153. M/TA: EventSize : 33
  154. M/TA: Signature : Spec ID Event03
  155. M/TA: PlatformClass : 0
  156. M/TA: SpecVersion : 2.0.2
  157. M/TA: UintnSize : 1
  158. M/TA: NumberOfAlgorithms : 1
  159. M/TA: DigestSizes :
  160. M/TA: #0 AlgorithmId : SHA256
  161. M/TA: DigestSize : 32
  162. M/TA: VendorInfoSize : 0
  163. M/TA: PCR_Event2:
  164. M/TA: PCRIndex : 0
  165. M/TA: EventType : 3
  166. M/TA: Digests Count : 1
  167. M/TA: #0 AlgorithmId : SHA256
  168. M/TA: Digest : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  169. M/TA: : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  170. M/TA: EventSize : 17
  171. M/TA: Signature : StartupLocality
  172. M/TA: StartupLocality : 0
  173. M/TA: PCR_Event2:
  174. M/TA: PCRIndex : 0
  175. M/TA: EventType : 1
  176. M/TA: Digests Count : 1
  177. M/TA: #0 AlgorithmId : SHA256
  178. M/TA: Digest : 58 26 32 6e 64 45 64 da 45 de 35 db 96 fd ed 63
  179. M/TA: : 2a 6a d4 0d aa 94 b0 b1 55 e4 72 e7 1f 0a e0 d5
  180. M/TA: EventSize : 5
  181. M/TA: Event : BL_2
  182. M/TA: PCR_Event2:
  183. M/TA: PCRIndex : 0
  184. M/TA: EventType : 1
  185. M/TA: Digests Count : 1
  186. M/TA: #0 AlgorithmId : SHA256
  187. M/TA: Digest : cf f9 7d a3 5c 73 ac cb 7b a0 25 80 6a 6e 50 a5
  188. M/TA: : 6b 2e d2 8c c9 36 92 7d 46 c5 b9 c3 a4 6c 51 7c
  189. M/TA: EventSize : 6
  190. M/TA: Event : BL_31
  191. M/TA: PCR_Event2:
  192. M/TA: PCRIndex : 0
  193. M/TA: EventType : 1
  194. M/TA: Digests Count : 1
  195. M/TA: #0 AlgorithmId : SHA256
  196. M/TA: Digest : 23 b0 a3 5d 54 d9 43 1a 5c b9 89 63 1c da 06 c2
  197. M/TA: : e5 de e7 7e 99 17 52 12 7d f7 45 ca 4f 4a 39 c0
  198. M/TA: EventSize : 10
  199. M/TA: Event : HW_CONFIG
  200. M/TA: PCR_Event2:
  201. M/TA: PCRIndex : 0
  202. M/TA: EventType : 1
  203. M/TA: Digests Count : 1
  204. M/TA: #0 AlgorithmId : SHA256
  205. M/TA: Digest : 4e e4 8e 5a e6 50 ed e0 b5 a3 54 8a 1f d6 0e 8a
  206. M/TA: : ea 0e 71 75 0e a4 3f 82 76 ce af cd 7c b0 91 e0
  207. M/TA: EventSize : 14
  208. M/TA: Event : SOC_FW_CONFIG
  209. M/TA: PCR_Event2:
  210. M/TA: PCRIndex : 0
  211. M/TA: EventType : 1
  212. M/TA: Digests Count : 1
  213. M/TA: #0 AlgorithmId : SHA256
  214. M/TA: Digest : 01 b0 80 47 a1 ce 86 cd df 89 d2 1f 2e fc 6c 22
  215. M/TA: : f8 19 ec 6e 1e ec 73 ba 5a be d0 96 e3 5f 6d 75
  216. M/TA: EventSize : 6
  217. M/TA: Event : BL_32
  218. M/TA: PCR_Event2:
  219. M/TA: PCRIndex : 0
  220. M/TA: EventType : 1
  221. M/TA: Digests Count : 1
  222. M/TA: #0 AlgorithmId : SHA256
  223. M/TA: Digest : 5d c6 ef 35 5a 90 81 b4 37 e6 3b 52 da 92 ab 8e
  224. M/TA: : d9 6e 93 98 2d 40 87 96 1b 5a a7 ee f1 f4 40 63
  225. M/TA: EventSize : 18
  226. M/TA: Event : BL32_EXTRA1_IMAGE
  227. M/TA: PCR_Event2:
  228. M/TA: PCRIndex : 0
  229. M/TA: EventType : 1
  230. M/TA: Digests Count : 1
  231. M/TA: #0 AlgorithmId : SHA256
  232. M/TA: Digest : 39 b7 13 b9 93 db 32 2f 1b 48 30 eb 2c f2 5c 25
  233. M/TA: : 00 0f 38 dc 8e c8 02 cd 79 f2 48 d2 2c 25 ab e2
  234. M/TA: EventSize : 6
  235. M/TA: Event : BL_33
  236. M/TA: PCR_Event2:
  237. M/TA: PCRIndex : 0
  238. M/TA: EventType : 1
  239. M/TA: Digests Count : 1
  240. M/TA: #0 AlgorithmId : SHA256
  241. M/TA: Digest : 25 10 60 5d d4 bc 9d 82 7a 16 9f 8a cc 47 95 a6
  242. M/TA: : fd ca a0 c1 2b c9 99 8f 51 20 ff c6 ed 74 68 5a
  243. M/TA: EventSize : 13
  244. M/TA: Event : NT_FW_CONFIG
  245. These logs correspond to the measurements stored by TF-A during the measured
  246. boot process and therefore, they should match the logs dumped by the former
  247. during the boot up process. These can be seen on the terminal_0:
  248. .. code:: shell
  249. NOTICE: Booting Trusted Firmware
  250. NOTICE: BL1: v2.5(release):v2.5
  251. NOTICE: BL1: Built : 10:41:20, Jul 2 2021
  252. NOTICE: BL1: Booting BL2
  253. NOTICE: BL2: v2.5(release):v2.5
  254. NOTICE: BL2: Built : 10:41:20, Jul 2 2021
  255. NOTICE: TCG_EfiSpecIDEvent:
  256. NOTICE: PCRIndex : 0
  257. NOTICE: EventType : 3
  258. NOTICE: Digest : 00
  259. NOTICE: : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  260. NOTICE: : 00 00 00
  261. NOTICE: EventSize : 33
  262. NOTICE: Signature : Spec ID Event03
  263. NOTICE: PlatformClass : 0
  264. NOTICE: SpecVersion : 2.0.2
  265. NOTICE: UintnSize : 1
  266. NOTICE: NumberOfAlgorithms : 1
  267. NOTICE: DigestSizes :
  268. NOTICE: #0 AlgorithmId : SHA256
  269. NOTICE: DigestSize : 32
  270. NOTICE: VendorInfoSize : 0
  271. NOTICE: PCR_Event2:
  272. NOTICE: PCRIndex : 0
  273. NOTICE: EventType : 3
  274. NOTICE: Digests Count : 1
  275. NOTICE: #0 AlgorithmId : SHA256
  276. NOTICE: Digest : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  277. NOTICE: : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  278. NOTICE: EventSize : 17
  279. NOTICE: Signature : StartupLocality
  280. NOTICE: StartupLocality : 0
  281. NOTICE: PCR_Event2:
  282. NOTICE: PCRIndex : 0
  283. NOTICE: EventType : 1
  284. NOTICE: Digests Count : 1
  285. NOTICE: #0 AlgorithmId : SHA256
  286. NOTICE: Digest : 58 26 32 6e 64 45 64 da 45 de 35 db 96 fd ed 63
  287. NOTICE: : 2a 6a d4 0d aa 94 b0 b1 55 e4 72 e7 1f 0a e0 d5
  288. NOTICE: EventSize : 5
  289. NOTICE: Event : BL_2
  290. NOTICE: PCR_Event2:
  291. NOTICE: PCRIndex : 0
  292. NOTICE: EventType : 1
  293. NOTICE: Digests Count : 1
  294. NOTICE: #0 AlgorithmId : SHA256
  295. NOTICE: Digest : cf f9 7d a3 5c 73 ac cb 7b a0 25 80 6a 6e 50 a5
  296. NOTICE: : 6b 2e d2 8c c9 36 92 7d 46 c5 b9 c3 a4 6c 51 7c
  297. NOTICE: EventSize : 6
  298. NOTICE: Event : BL_31
  299. NOTICE: PCR_Event2:
  300. NOTICE: PCRIndex : 0
  301. NOTICE: EventType : 1
  302. NOTICE: Digests Count : 1
  303. NOTICE: #0 AlgorithmId : SHA256
  304. NOTICE: Digest : 23 b0 a3 5d 54 d9 43 1a 5c b9 89 63 1c da 06 c2
  305. NOTICE: : e5 de e7 7e 99 17 52 12 7d f7 45 ca 4f 4a 39 c0
  306. NOTICE: EventSize : 10
  307. NOTICE: Event : HW_CONFIG
  308. NOTICE: PCR_Event2:
  309. NOTICE: PCRIndex : 0
  310. NOTICE: EventType : 1
  311. NOTICE: Digests Count : 1
  312. NOTICE: #0 AlgorithmId : SHA256
  313. NOTICE: Digest : 4e e4 8e 5a e6 50 ed e0 b5 a3 54 8a 1f d6 0e 8a
  314. NOTICE: : ea 0e 71 75 0e a4 3f 82 76 ce af cd 7c b0 91 e0
  315. NOTICE: EventSize : 14
  316. NOTICE: Event : SOC_FW_CONFIG
  317. NOTICE: PCR_Event2:
  318. NOTICE: PCRIndex : 0
  319. NOTICE: EventType : 1
  320. NOTICE: Digests Count : 1
  321. NOTICE: #0 AlgorithmId : SHA256
  322. NOTICE: Digest : 01 b0 80 47 a1 ce 86 cd df 89 d2 1f 2e fc 6c 22
  323. NOTICE: : f8 19 ec 6e 1e ec 73 ba 5a be d0 96 e3 5f 6d 75
  324. NOTICE: EventSize : 6
  325. NOTICE: Event : BL_32
  326. NOTICE: PCR_Event2:
  327. NOTICE: PCRIndex : 0
  328. NOTICE: EventType : 1
  329. NOTICE: Digests Count : 1
  330. NOTICE: #0 AlgorithmId : SHA256
  331. NOTICE: Digest : 5d c6 ef 35 5a 90 81 b4 37 e6 3b 52 da 92 ab 8e
  332. NOTICE: : d9 6e 93 98 2d 40 87 96 1b 5a a7 ee f1 f4 40 63
  333. NOTICE: EventSize : 18
  334. NOTICE: Event : BL32_EXTRA1_IMAGE
  335. NOTICE: PCR_Event2:
  336. NOTICE: PCRIndex : 0
  337. NOTICE: EventType : 1
  338. NOTICE: Digests Count : 1
  339. NOTICE: #0 AlgorithmId : SHA256
  340. NOTICE: Digest : 39 b7 13 b9 93 db 32 2f 1b 48 30 eb 2c f2 5c 25
  341. NOTICE: : 00 0f 38 dc 8e c8 02 cd 79 f2 48 d2 2c 25 ab e2
  342. NOTICE: EventSize : 6
  343. NOTICE: Event : BL_33
  344. NOTICE: PCR_Event2:
  345. NOTICE: PCRIndex : 0
  346. NOTICE: EventType : 1
  347. NOTICE: Digests Count : 1
  348. NOTICE: #0 AlgorithmId : SHA256
  349. NOTICE: Digest : 25 10 60 5d d4 bc 9d 82 7a 16 9f 8a cc 47 95 a6
  350. NOTICE: : fd ca a0 c1 2b c9 99 8f 51 20 ff c6 ed 74 68 5a
  351. NOTICE: EventSize : 13
  352. NOTICE: Event : NT_FW_CONFIG
  353. NOTICE: BL1: Booting BL31
  354. NOTICE: BL31: v2.5(release):v2.5
  355. NOTICE: BL31: Built : 10:41:20, Jul 2 2021
  356. Following up with the fTPM startup process, we can see that all the
  357. measurements in the Event Log are extended and recorded in the appropriate PCR:
  358. .. code:: shell
  359. M/TA: TPM2_PCR_EXTEND_COMMAND returned value:
  360. M/TA: ret_tag = 0x8002, size = 0x00000013, rc = 0x00000000
  361. M/TA: TPM2_PCR_EXTEND_COMMAND returned value:
  362. M/TA: ret_tag = 0x8002, size = 0x00000013, rc = 0x00000000
  363. M/TA: TPM2_PCR_EXTEND_COMMAND returned value:
  364. M/TA: ret_tag = 0x8002, size = 0x00000013, rc = 0x00000000
  365. M/TA: TPM2_PCR_EXTEND_COMMAND returned value:
  366. M/TA: ret_tag = 0x8002, size = 0x00000013, rc = 0x00000000
  367. M/TA: TPM2_PCR_EXTEND_COMMAND returned value:
  368. M/TA: ret_tag = 0x8002, size = 0x00000013, rc = 0x00000000
  369. M/TA: TPM2_PCR_EXTEND_COMMAND returned value:
  370. M/TA: ret_tag = 0x8002, size = 0x00000013, rc = 0x00000000
  371. M/TA: TPM2_PCR_EXTEND_COMMAND returned value:
  372. M/TA: ret_tag = 0x8002, size = 0x00000013, rc = 0x00000000
  373. M/TA: TPM2_PCR_EXTEND_COMMAND returned value:
  374. M/TA: ret_tag = 0x8002, size = 0x00000013, rc = 0x00000000
  375. M/TA: TPM2_PCR_EXTEND_COMMAND returned value:
  376. M/TA: ret_tag = 0x8002, size = 0x00000013, rc = 0x00000000
  377. M/TA: 9 Event logs processed
  378. After the fTPM TA is loaded, the call to ``insmod`` issued by the ``ftpm``
  379. alias to load the ftpm kernel module returns, and then the TPM PCRs are read
  380. by means of ``tpm_pcrread`` command. Note that we are only interested in the
  381. SHA256 logs here, as this is the algorithm we used on TF-A for the measurements
  382. (see the field ``AlgorithmId`` on the logs above):
  383. .. code:: shell
  384. sha256:
  385. 0 : 0xA6EB3A7417B8CFA9EBA2E7C22AD5A4C03CDB8F3FBDD7667F9C3EF2EA285A8C9F
  386. 1 : 0x0000000000000000000000000000000000000000000000000000000000000000
  387. 2 : 0x0000000000000000000000000000000000000000000000000000000000000000
  388. 3 : 0x0000000000000000000000000000000000000000000000000000000000000000
  389. 4 : 0x0000000000000000000000000000000000000000000000000000000000000000
  390. 5 : 0x0000000000000000000000000000000000000000000000000000000000000000
  391. 6 : 0x0000000000000000000000000000000000000000000000000000000000000000
  392. 7 : 0x0000000000000000000000000000000000000000000000000000000000000000
  393. 8 : 0x0000000000000000000000000000000000000000000000000000000000000000
  394. 9 : 0x0000000000000000000000000000000000000000000000000000000000000000
  395. 10: 0x0000000000000000000000000000000000000000000000000000000000000000
  396. 11: 0x0000000000000000000000000000000000000000000000000000000000000000
  397. 12: 0x0000000000000000000000000000000000000000000000000000000000000000
  398. 13: 0x0000000000000000000000000000000000000000000000000000000000000000
  399. 14: 0x0000000000000000000000000000000000000000000000000000000000000000
  400. 15: 0x0000000000000000000000000000000000000000000000000000000000000000
  401. 16: 0x0000000000000000000000000000000000000000000000000000000000000000
  402. 17: 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
  403. 18: 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
  404. 19: 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
  405. 20: 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
  406. 21: 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
  407. 22: 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
  408. 23: 0x0000000000000000000000000000000000000000000000000000000000000000
  409. In this PoC we are only interested in PCR0, which must be non-null. This is
  410. because the boot process records all the images in this PCR (see field ``PCRIndex``
  411. on the Event Log above). The rest of the records must be 0 at this point.
  412. .. note::
  413. The fTPM service used has support only for 16 PCRs, therefore the content
  414. of PCRs above 15 can be ignored.
  415. .. note::
  416. As stated earlier, Arm does not provide an fTPM implementation and therefore
  417. we do not validate here if the content of PCR0 is correct or not. For this
  418. PoC, we are only focused on the fact that the event log could be passed to a third
  419. party fTPM and its records were properly extended.
  420. Fine-tuning the fTPM TA
  421. ~~~~~~~~~~~~~~~~~~~~~~~
  422. As stated earlier, the OP-TEE Toolkit includes support to build a third party fTPM
  423. service. The build options for this service are tailored for the PoC and defined in
  424. the build environment variable ``FTPM_FLAGS`` (see ``<toolkit_home>/build/common.mk``)
  425. but they can be modified if needed to better adapt it to a specific scenario.
  426. The most relevant options for Measured Boot support are:
  427. - **CFG_TA_DEBUG**: Enables debug logs in the Terminal_1 console.
  428. - **CFG_TEE_TA_LOG_LEVEL**: Defines the log level used for the debug messages.
  429. - **CFG_TA_MEASURED_BOOT**: Enables support for measured boot on the fTPM.
  430. - **CFG_TA_EVENT_LOG_SIZE**: Defines the size, in bytes, of the larger event log that
  431. the fTPM is able to store, as this buffer is allocated at build time. This must be at
  432. least the same as the size of the event log generated by TF-A. If this build option
  433. is not defined, the fTPM falls back to a default value of 1024 bytes, which is enough
  434. for this PoC, so this variable is not defined in FTPM_FLAGS.
  435. --------------
  436. *Copyright (c) 2021, Arm Limited. All rights reserved.*
  437. .. _OP-TEE Toolkit: https://github.com/OP-TEE/build
  438. .. _ms-tpm-20-ref: https://github.com/microsoft/ms-tpm-20-ref
  439. .. _Get and build the solution: https://optee.readthedocs.io/en/latest/building/gits/build.html#get-and-build-the-solution
  440. .. _Armv8-A Foundation Platform (For Linux Hosts Only): https://developer.arm.com/tools-and-software/simulation-models/fixed-virtual-platforms/arm-ecosystem-models
  441. .. _tpm2-tools: https://github.com/tpm2-software/tpm2-tools
  442. .. _TGC event log: https://trustedcomputinggroup.org/resource/tcg-efi-platform-specification/