joholl / tpmstream

A tool to help you understand TPM commands and responses.
https://joholl.github.io/tpmstream-web
BSD 2-Clause "Simplified" License
34 stars 3 forks source link

TPM_CC.NV_Read not properly decoded #6

Closed 0x8008135 closed 1 year ago

0x8008135 commented 2 years ago

Hello,

The TPM_CC.NV_Read command is not properly decoded as it seems to be missing the NVIndex field in the query as show below:

CMD=8002000000230000014E400000010180000000000009400000090000010000007E0000

Command                                   .                                                                   
TPMI_ST_COMMAND_TAG                       |   .tag                                       8002                 TPM_ST.SESSIONS
UINT32                                    |   .commandSize                               00000023             35
TPM_CC                                    |   .commandCode                               0000014e             TPM_CC.NV_Read
TPMS_COMMAND_HANDLES_NV_READ              |   .handles                                                        
TPMI_RH_NV_AUTH                           |   |   .authHandle                            40000001             TPM_RH.OWNER
UINT32                                    |   .authSize                                  01800000             25165824
TPMS_AUTH_COMMAND                         |   .authorizationArea[0]                                           
TPMI_SH_AUTH_SESSION                      |   |   .sessionHandle                         00000009             9
TPM2B_NONCE                               |   |   .nonce                                                      
UINT16                                    |   |   |   .size                              4000                 16384
list[BYTE]                                |   |   |   .buffer                            00090000010000007e0000

The Command Decoder from the TPM2 Parser of Microsoft decode it as such :

Header:
Tpm2Lib.CommandHeader
  Tag                   Sessions                  TpmSt
  CommandSize           35 (0x23)                 uint
  CommandCode           NvRead                    TpmCc

Command Parameters:
Tpm2Lib.Tpm2NvReadRequest
  authHandle            -                         TpmHandle
    handle              1073741825 (0x40000001)   uint
  nvIndex               -                         TpmHandle
    handle              25165824 (0x1800000)      uint
  size                  126 (0x7e)                ushort
  offset                0 (0x0)                   ushort

Sessions [1]
0: 0xTpm2Lib.SessionIn
  handle                -                         TpmHandle
    handle              1073741833 (0x40000009)   uint
  nonceCaller           0x                        byte[0]
  attributes            ContinueSession           SessionAttr
  auth                  0x                        byte[0]

Regards

joholl commented 1 year ago

You are right, according to the spec, there are two handles:

This needs to be fixed here. I might pick this up in the future. Alternatively, patches welcome :)

Thanks for bringing this up!