wolfSSL / wolfTPM

wolfTPM is a highly portable TPM 2.0 library, designed for embedded use.
https://www.wolfssl.com
GNU General Public License v2.0
244 stars 60 forks source link

Endianness not accounted in AppendBytesand ParseBytes #104

Closed tomoveu closed 4 years ago

tomoveu commented 4 years ago

I stumbled upon a marshalling/unmarshalling(append/parse) issue, when fixing the print for the signed_timestamp example #103

TPM2_Packet_AppendBytes and TPM2_Packet_ParseBytes do only a memory copy, when the response buffers from the TPM come in Big Endian format. Without proper Endianness handling, we can not parse the data correctly. For example, the TPM_GENERATE_VALUE test fails and the attested time print does not show meaningful data.

wolfTPM2_GetTime: success
    Error, attested data not generated by the TPM = 0x474354FF

when expected value is

wolftpm/tpm2.h: TPM_GENERATED_VALUE = 0xff544347 How this problem remained hidden, since AppendBytes and ParseBytes are used for other TPM2 commands?

Because both AppendBytes and ParseBytes do not convert endianness and we just ask the TPM to do stuff for us, the data was just consumed by the TPM.

For example, TPM2_Create spits key in Big Endian format that we do not convert, but then we also TPM2_Load without data manipulations, so it remains in BigEndian, so the result is as if the data is already parsed(marshalled) and the TPM just consumes it.

@dgarske please check this finding and let me know if more information is needed

tomoveu commented 4 years ago

The new parsing with endianness function added by @dgarske in #103 fix the issue for TPM attest structures