Azure / azure-utpm-c

TPM C library for use with Azure IoT SDKs
MIT License
12 stars 14 forks source link

Initialize_TPM_Codec never returns when using TPM emulator #109

Closed pulkomandy closed 1 year ago

pulkomandy commented 2 years ago

Hello,

I am developping an application using Azure IoT SDK. We plan to use a TPM but for now the hardware isn't available, so we are trying to use the TPM emulator to test our cloud infrastructure until then. We are using it on Linux and connecting it to https://sourceforge.net/projects/ibmswtpm2/

We got the provisioning working, but we are not able to then connect to the Azure IoT cloud. Our code calls IoTHubDeviceClient_CreateFromDeviceAuth in azure-iot-sdk-c, which ends up calling Initialize_TPM_Codec in utpm.

That function never returns (we waited for several minutes, surely it shouldn't take that long).

I guess (but this is only a guess) this could be because of trying to initialize the TPM codec a second time, after it has already been done for the provisioning. I don't know if the TPM emulator implements or need some form of arbitration as a real TPM would. Or maybe we are asking too much of the emulator and it is not designed to be pushed this far?

Do you have any recommendations? How can I help with debugging this issue and understanding why there is a lockup? If this usage is not possible, shouldn't the function return an error code instead of just blocking forever?

pulkomandy commented 2 years ago

I managed to get it working.

I was calling the IoTHubDeviceClient_CreateFromDeviceAuth before prov_device_destroy.

As a result, the provisioning was locking the TPM and the IoTHub part of the SDK could never access it. And there doesn't seem to be a timeout on this, so I just ended in a deadlock.

CIPop commented 1 year ago

Thanks @pulkomandy for sharing the solution!