tpm2-software / tpm2-tools

The source repository for the Trusted Platform Module (TPM2.0) tools
https://tpm2-software.github.io
709 stars 378 forks source link

YAML pcrs output of tpm2_eventlog not helpful #3303

Open robret77 opened 10 months ago

robret77 commented 10 months ago

The computed PCR values at the end of the tpm2_eventlog YAML output can't be parsed correctly by YAML tools like the yq command line or online YAML formatters. The PCR hex values are transformed to float. It would probably be better to encode them as a strings by surrounding the hex values with double quotes. Tested with the current release 5.6 - 2023-11-08.

Sample output of tpm2_eventlog:

$ sudo ./bin/tpm2_eventlog /sys/kernel/security/tpm0/binary_bios_measurements
...
  Event: |-
    Exit Boot Services Returned with Success
pcrs:
  sha256:
...
    1  : 0x2e9a5e07140d956a059b65ef1af6c3c14079ca6f7220a0c0d6bdf1b0412a9a1d
...

Sample output, parsed by yq and other tools:

$ sudo ./bin/tpm2_eventlog /sys/kernel/security/tpm0/binary_bios_measurements | yq
...
      "Event": "Exit Boot Services Returned with Success"
    }
  ],
  "pcrs": {
    "sha256": {
...
      "1": 2.1079134437794185e+76,
...

Expected output of tpm2_eventlog:

...
    1  : "0x2e9a5e07140d956a059b65ef1af6c3c14079ca6f7220a0c0d6bdf1b0412a9a1d"
...
williamcroberts commented 9 months ago

python's yaml package properly parses this:

{'pcrs': {'sha256': {1: 21079134437794183857440536639578330818725865347780897055713131410320316340765}}}

For untagged nodes spec their is no reason that should be interpreted as float, it should be either string or int.

This is a bug in the parser being used, but I don't disagree everything should be escaped as strings.

williamcroberts commented 9 months ago

The more I look into this, this is a jq bug. They actually roll their own parser with bison and flex. It never should choose float. Our work on next will correct all the YAML issues we have in a foolproof way, and provide a --canonical output that will output everything quoted as well as with type information.