#include "tpm_tspi.h" int main(int argc, char **args){ BYTE *rgbPcrValue, *rgbNumPcrs, *pNumSlots, *pNumDIRs, *pManufacturer; UINT32 respDataLength; TSS_HCONTEXT hContext; TSS_HTPM hTPM; TSS_RESULT result; UINT32 exitCode, numPcrs, subCap, i, j; // Create Context result = Tspi_Context_Create(&hContext); if (result != TSS_SUCCESS) { exit(result); } // Connect to Context result = Tspi_Context_Connect(hContext, NULL); if (result != TSS_SUCCESS) { Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } // Retrieve TPM object of context result = Tspi_Context_GetTpmObject(hContext, &hTPM); if (result != TSS_SUCCESS) { Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } // Define sub capability subCap = TSS_TPMCAP_PROP_MANUFACTURER; // Retrieve manufacturer info result = Tspi_TPM_GetCapability(hTPM, TSS_TPMCAP_PROPERTY, sizeof(UINT32), (BYTE *)&subCap, &respDataLength, &pManufacturer); if (result != TSS_SUCCESS) { Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } fprintf(stdout, "This TPM Chip was manufactured by: "); for (i = 0; i < respDataLength; i++) { fprintf(stdout, "%c", pManufacturer[i]); } fprintf(stdout, "\n"); // Redefine sub capability subCap = TSS_TPMCAP_PROP_SLOTS; // Retrieve number of RSA slots result = Tspi_TPM_GetCapability(hTPM, TSS_TPMCAP_PROPERTY, sizeof(UINT32), (BYTE *)&subCap, &respDataLength, &pNumSlots); if (result != TSS_SUCCESS) { Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } fprintf(stdout, "This TPM Chip provides %u RSA slots.\n", *pNumSlots); // Redefine sub capability subCap = TSS_TPMCAP_PROP_DIR; // Retrieve number of DIR registers result = Tspi_TPM_GetCapability(hTPM, TSS_TPMCAP_PROPERTY, sizeof(UINT32), (BYTE *)&subCap, &respDataLength, &pNumDIRs); if (result != TSS_SUCCESS) { Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } fprintf(stdout, "This TPM Chip provides %u DIR registers.\n", *pNumDIRs); // Redefine sub capability subCap = TSS_TPMCAP_PROP_PCR; // Retrieve number of PCR's result = Tspi_TPM_GetCapability(hTPM, TSS_TPMCAP_PROPERTY, sizeof(UINT32), (BYTE *)&subCap, &respDataLength, &rgbNumPcrs); if (result != TSS_SUCCESS) { Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } if (respDataLength != sizeof(UINT32)) { Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(result); } numPcrs = *(UINT32 *)rgbNumPcrs; fprintf(stdout, "This TPM Chip provides %i PCR register. Current values are:\n", numPcrs); for (i = 0; i < numPcrs; i++) { result = Tspi_TPM_PcrRead(hTPM, i, &respDataLength, &rgbPcrValue); fprintf(stdout, "PCR#%02u: ", i); for (j = 0; j < respDataLength; j++) { fprintf(stdout, "%02x ", rgbPcrValue[j] & 0xff); } fprintf(stdout, "\n"); } if (result != TSS_SUCCESS) { fprintf(stderr, "Failed to read PCR.\n"); exitCode = 1; } else { fprintf(stdout, "Success.\n"); exitCode = 0; } Tspi_Context_FreeMemory(hContext, NULL); Tspi_Context_Close(hContext); exit(exitCode); }