measured_boot_poc.rst 22 KB

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