From ff906b29ee848f519c3936ad8e3fc699e2a3ca82 Mon Sep 17 00:00:00 2001 From: Kalyan Kona Date: Mon, 11 Jul 2022 18:32:26 -0700 Subject: [PATCH] fix build issues: 1) redefinition from wbcl 2) add preprocessor for dllexport 3) rename the conflicting functions --- PCPTool.v11/dll/AttestationApi.cpp | 32 +++--- PCPTool.v11/dll/PCPWbcl.cpp | 10 +- PCPTool.v11/dll/dll.vcxproj | 9 +- PCPTool.v11/exe/Support.cpp | 6 +- PCPTool.v11/exe/exe.vcxproj | 8 +- PCPTool.v11/inc/TpmAtt.h | 162 ++--------------------------- 6 files changed, 40 insertions(+), 187 deletions(-) diff --git a/PCPTool.v11/dll/AttestationApi.cpp b/PCPTool.v11/dll/AttestationApi.cpp index ba621b17..4c456f22 100644 --- a/PCPTool.v11/dll/AttestationApi.cpp +++ b/PCPTool.v11/dll/AttestationApi.cpp @@ -424,7 +424,7 @@ TpmAttiComputeSoftPCRs( goto Cleanup; } - if (FAILED(hr = WbclApiInitIterator(pbEventLog, + if (FAILED(hr = WbclApiInitIteratorInternal(pbEventLog, cbEventLog, &wbclIterator))) { @@ -453,9 +453,9 @@ TpmAttiComputeSoftPCRs( } for (; hr == S_OK; - hr = WbclApiMoveToNextElement(&wbclIterator)) + hr = WbclApiMoveToNextElementInternal(&wbclIterator)) { - hr = WbclApiGetCurrentElement( + hr = WbclApiGetCurrentElementInternal( &wbclIterator, &PcrIndex, &EventType, @@ -632,7 +632,7 @@ TpmAttiFilterLog( // Make OACR happy *pcbResult = 0; - if (FAILED(hr = WbclApiInitIterator(pbEventLog, + if (FAILED(hr = WbclApiInitIteratorInternal(pbEventLog, cbEventLog, &wbclIterator))) { @@ -650,9 +650,9 @@ TpmAttiFilterLog( // 1st pass to find out how much space we will need for (; hr == S_OK; - hr = WbclApiMoveToNextElement(&wbclIterator)) + hr = WbclApiMoveToNextElementInternal(&wbclIterator)) { - hr = WbclApiGetCurrentElement( + hr = WbclApiGetCurrentElementInternal( &wbclIterator, &pcrIndex, &eventType, @@ -694,7 +694,7 @@ TpmAttiFilterLog( goto Cleanup; } - if (FAILED(hr = WbclApiInitIterator(pbEventLog, + if (FAILED(hr = WbclApiInitIteratorInternal(pbEventLog, cbEventLog, &wbclIterator))) { @@ -723,9 +723,9 @@ TpmAttiFilterLog( // 2nd pass to copy the entries for (; hr == S_OK; - hr = WbclApiMoveToNextElement(&wbclIterator)) + hr = WbclApiMoveToNextElementInternal(&wbclIterator)) { - hr = WbclApiGetCurrentElement( + hr = WbclApiGetCurrentElementInternal( &wbclIterator, &pcrIndex, &eventType, @@ -1119,7 +1119,7 @@ TpmAttGeneratePlatformAttestation( goto Cleanup; } - if (FAILED(hr = WbclApiInitIterator(pbLog, cbLog, &wbclIterator))) + if (FAILED(hr = WbclApiInitIteratorInternal(pbLog, cbLog, &wbclIterator))) { goto Cleanup; } @@ -2039,7 +2039,7 @@ TpmAttCreateAttestationfromLog( goto Cleanup; } - if (FAILED(hr = WbclApiInitIterator(pbLog, + if (FAILED(hr = WbclApiInitIteratorInternal(pbLog, cbLog, &wbclIterator))) { @@ -2048,9 +2048,9 @@ TpmAttCreateAttestationfromLog( // parse the log for (; hr == S_OK; - hr = WbclApiMoveToNextElement(&wbclIterator)) + hr = WbclApiMoveToNextElementInternal(&wbclIterator)) { - hr = WbclApiGetCurrentElement( + hr = WbclApiGetCurrentElementInternal( &wbclIterator, &pcrIndex, &eventType, @@ -2399,7 +2399,7 @@ TpmAttGetPlatformAttestationProperties( pAttestation->cbSignature]; cbPlatformLog = pAttestation->cbLog; - if (FAILED(hr = WbclApiInitIterator(pbPlatformLog, + if (FAILED(hr = WbclApiInitIteratorInternal(pbPlatformLog, cbPlatformLog, &wbclIterator))) { @@ -2417,9 +2417,9 @@ TpmAttGetPlatformAttestationProperties( // 2nd pass to copy the entries for (; hr == S_OK; - hr = WbclApiMoveToNextElement(&wbclIterator)) + hr = WbclApiMoveToNextElementInternal(&wbclIterator)) { - hr = WbclApiGetCurrentElement( + hr = WbclApiGetCurrentElementInternal( &wbclIterator, &pcrIndex, &eventType, diff --git a/PCPTool.v11/dll/PCPWbcl.cpp b/PCPTool.v11/dll/PCPWbcl.cpp index 5acc37e2..7f3818d3 100644 --- a/PCPTool.v11/dll/PCPWbcl.cpp +++ b/PCPTool.v11/dll/PCPWbcl.cpp @@ -511,7 +511,7 @@ Return value: // HRESULT -WbclApiInitIterator( +WbclApiInitIteratorInternal( _In_bytecount_(logSize) PVOID pLogBuffer, _In_ UINT32 logSize, _Out_ WBCL_Iterator* pWbclIterator @@ -589,7 +589,7 @@ Return value: // // Extract information for the first event in the log. // - hr = WbclApiGetCurrentElement(pWbclIterator, + hr = WbclApiGetCurrentElementInternal(pWbclIterator, &pcrIndex, &eventType, NULL, @@ -696,7 +696,7 @@ Return value: // Move to the first log entry after the descriptor. // WbclApiMoveToNextElement() does boundary checks. // - hr = WbclApiMoveToNextElement(pWbclIterator); + hr = WbclApiMoveToNextElementInternal(pWbclIterator); if (hr != S_OK) { hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); @@ -710,7 +710,7 @@ Return value: } HRESULT -WbclApiGetCurrentElement( +WbclApiGetCurrentElementInternal( _In_ WBCL_Iterator* pWbclIterator, _Out_ UINT32* pcrIndex, _Out_ UINT32* eventType, @@ -787,7 +787,7 @@ Return value: } HRESULT -WbclApiMoveToNextElement( +WbclApiMoveToNextElementInternal( _In_ WBCL_Iterator* pWbclIterator) /*++ diff --git a/PCPTool.v11/dll/dll.vcxproj b/PCPTool.v11/dll/dll.vcxproj index 8f023c4f..f2708343 100644 --- a/PCPTool.v11/dll/dll.vcxproj +++ b/PCPTool.v11/dll/dll.vcxproj @@ -29,26 +29,26 @@ DynamicLibrary true - v140 + v143 Unicode DynamicLibrary true - v140 + v143 Unicode DynamicLibrary false - v140 + v143 true Unicode DynamicLibrary false - v140 + v143 true Unicode @@ -103,6 +103,7 @@ Disabled WIN32;_DEBUG;_WINDOWS;_USRDLL;DLL_EXPORTS;%(PreprocessorDefinitions) $(SolutionDir)\inc;%(AdditionalIncludeDirectories) + false Windows diff --git a/PCPTool.v11/exe/Support.cpp b/PCPTool.v11/exe/Support.cpp index 9e5d4b8b..d509837a 100644 --- a/PCPTool.v11/exe/Support.cpp +++ b/PCPTool.v11/exe/Support.cpp @@ -850,7 +850,7 @@ PcpToolDisplayLog( PcpToolLevelPrefix(level + 1); wprintf(L"\n", cbWBCL); - if (FAILED(hr = WbclApiInitIterator(pbWBCL, + if (FAILED(hr = WbclApiInitIteratorInternal(pbWBCL, cbWBCL, &wbclIterator))) { @@ -862,7 +862,7 @@ PcpToolDisplayLog( } for (; hr == S_OK; - hr = WbclApiMoveToNextElement(&wbclIterator)) + hr = WbclApiMoveToNextElementInternal(&wbclIterator)) { BYTE eventDataDigest[MAX_DIGEST_SIZE] = { 0 }; UINT32 PcrIndex; @@ -871,7 +871,7 @@ PcpToolDisplayLog( PBYTE pbEventData; PBYTE pbDigest; - hr = WbclApiGetCurrentElement( + hr = WbclApiGetCurrentElementInternal( &wbclIterator, &PcrIndex, &EventType, diff --git a/PCPTool.v11/exe/exe.vcxproj b/PCPTool.v11/exe/exe.vcxproj index f39a8cdb..d20d11ec 100644 --- a/PCPTool.v11/exe/exe.vcxproj +++ b/PCPTool.v11/exe/exe.vcxproj @@ -29,26 +29,26 @@ Application true - v140 + v143 Unicode Application true - v140 + v143 Unicode Application false - v140 + v143 true Unicode Application false - v140 + v143 true Unicode diff --git a/PCPTool.v11/inc/TpmAtt.h b/PCPTool.v11/inc/TpmAtt.h index 6d6f5e46..d8696e4c 100644 --- a/PCPTool.v11/inc/TpmAtt.h +++ b/PCPTool.v11/inc/TpmAtt.h @@ -24,7 +24,11 @@ Module Name: #ifndef TPMATT_H #define TPMATT_H +#ifdef DLL_EXPORTS #define DllExport __declspec(dllexport) +#else +#define DllExport +#endif // Platform attestation properties #define PCP_ATTESTATION_PROPERTIES_CONTAINS_BOOT_COUNT (0x00000001) @@ -170,127 +174,6 @@ typedef struct _PCP_KEY_ATTESTATION_BLOB { #define TPM_STATIC_CONFIG_KEYATTEST_KEYS L"SYSTEM\\CurrentControlSet\\Services\\Tpm\\KeyAttestationKeys" #define TPM_VOLATILE_CONFIG_DATA L"System\\CurrentControlSet\\Control\\IntegrityServices" -// SIPA event structures - -// -// Describes the VSM/SMART identity public key. -// -typedef struct tag_SIPAEVENT_VSM_IDK_RSA_INFO -{ - // - // Length of the RSA IDK modulus in bits. - // - ULONG32 KeyBitLength; - - // - // Length of the RSA IDK public exponent in bytes. - // - ULONG32 PublicExpLengthBytes; - - // - // Length of the modulus field in bytes. - // - ULONG32 ModulusSizeBytes; - - // - // The layout of the PublicKeyData field is as follows: - // PublicExponent[PublicExpLengthBytes] in Big-endian. - // Modulus[ModulusSizeBytes] in Big-endian. - // - BYTE PublicKeyData[ANYSIZE_ARRAY]; - -} SIPAEVENT_VSM_IDK_RSA_INFO, *PSIPAEVENT_VSM_IDK_RSA_INFO; - -// -// Payload structure for the SIPAEVENT_VSM_IDK_INFO event. -// -typedef struct tag_SIPAEVENT_VSM_IDK_INFO_PAYLOAD -{ - // - // Specifies the algorithm used for IDK. Should be one of VSM_IDK_ALG_ID values. - // - ULONG32 KeyAlgID; - - // - // Algorithm-specific description of the public key. - // - union - { - // - // Description of the RSA public key. - // - SIPAEVENT_VSM_IDK_RSA_INFO RsaKeyInfo; - } DUMMYUNIONNAME; - -} SIPAEVENT_VSM_IDK_INFO_PAYLOAD, *PSIPAEVENT_VSM_IDK_INFO_PAYLOAD; - -// -// Payload structure used to carry information about any policy blob. -// -typedef struct tag_SIPAEVENT_SI_POLICY_PAYLOAD -{ - // - // Policy version - // - ULONGLONG PolicyVersion; - - // - // Indicates the length (in bytes) of the policy name stored as part of VarLengthData. - // - UINT16 PolicyNameLength; - - // - // Indicates hash algorithm ID used to produce policy digest. - // Contains one of the TPM_ALG_ID values, typically the TPM_ALG_SHA256. - // - UINT16 HashAlgID; - - // - // Indicates the hash digest length (in bytes). Digest is stored as part of VarLengthData. - // - UINT32 DigestLength; - - // - // VarLengthData layout is: - // - // (Policy name is stored as a WCHAR string with a terminating zero). - // BYTE PolicyName[PolicyNameLength]. - // - // BYTE Digest[DigestLength] - // - _Field_size_bytes_(PolicyNameLength + DigestLength) - BYTE VarLengthData[ANYSIZE_ARRAY]; - -} SIPAEVENT_SI_POLICY_PAYLOAD, *PSIPAEVENT_SI_POLICY_PAYLOAD; - -// -// Payload structure used to carry information about revocation lists. -// -typedef struct tag_SIPAEVENT_REVOCATION_LIST_PAYLOAD -{ - // - // Creation time. - // - LONGLONG CreationTime; - - // - // Indicates the hash digest length (in bytes). - // - UINT32 DigestLength; - - // - // Indicates hash algorithm ID used to produce the revocation list digest. - // Contains one of the TPM_ALG_ID values, typically the TPM_ALG_SHA256. - // - UINT16 HashAlgID; - - // - // Hash digest of the revocation list. - // - _Field_size_bytes_(DigestLength) - BYTE Digest[ANYSIZE_ARRAY]; - -} SIPAEVENT_REVOCATION_LIST_PAYLOAD, *PSIPAEVENT_REVOCATION_LIST_PAYLOAD; // WBCL parser APIs #pragma pack(push,1) @@ -315,38 +198,7 @@ typedef UINT16 WBCL_DIGEST_ALG_ID; #define WBCL_DIGEST_ALG_BITMAP_SHA_2_384 0x00000004 #define WBCL_DIGEST_ALG_BITMAP_SHA_2_512 0x00000008 -// -// An iterator object for WBCL log. -// -typedef struct _WBCL_Iterator -{ - // Pointer to the first element of the log. - PVOID firstElementPtr; - - // Log size in bytes. - UINT32 logSize; - - // Pointer to the current element of the log. - PVOID currentElementPtr; - - // Size of the current log entry pointed to by currentElementPtr. - UINT32 currentElementSize; - - // Size of the digest field of event log entries. - UINT16 digestSize; - - // Indicates the log format. - UINT16 logFormat; - - // number of algorithms stored in the following digest table. - UINT32 numberOfDigests; - - // points to the table in the header that contains the mapping of algorithm ids to digest sizes. - PVOID digestSizes; - // Hash algorithm ID used for the log. The value corresponds to one of the TPM 2.0 ALG_ID values. - WBCL_DIGEST_ALG_ID hashAlgorithm; -} WBCL_Iterator, *PWBCL_Iterator; #pragma pack(pop) #if defined(__cplusplus) @@ -355,12 +207,12 @@ extern "C" { // WBCL parser functions (wbcl.h) -DllExport HRESULT WbclApiInitIterator( +DllExport HRESULT WbclApiInitIteratorInternal( _In_ PVOID pLogBuffer, _In_ UINT32 logSize, _Out_ WBCL_Iterator* pWbclIterator); -DllExport HRESULT WbclApiGetCurrentElement( +DllExport HRESULT WbclApiGetCurrentElementInternal( _In_ WBCL_Iterator* pWbclIterator, _Out_ UINT32* pcrIndex, _Out_ UINT32* eventType, @@ -369,7 +221,7 @@ DllExport HRESULT WbclApiGetCurrentElement( _Outptr_opt_result_bytebuffer_(*pcbElementDataSize) BYTE** ppbElementData ); -DllExport HRESULT WbclApiMoveToNextElement( +DllExport HRESULT WbclApiMoveToNextElementInternal( _In_ WBCL_Iterator* pWbclIterator); #ifndef NCRYPT_PCP_PLATFORM_BINDING_PCRALGID_PROPERTY