From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by mx.groups.io with SMTP id smtpd.web12.2110.1573465366033343389 for ; Mon, 11 Nov 2019 01:42:46 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.120, mailfrom: rodrigo.gonzalez.del.cueto@intel.com) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Nov 2019 01:42:45 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,292,1569308400"; d="scan'208";a="202008300" Received: from fm73lab177-1.amr.corp.intel.com ([10.80.209.189]) by fmsmga008.fm.intel.com with ESMTP; 11 Nov 2019 01:42:45 -0800 From: Rodrigo Gonzalez del Cueto To: devel@edk2.groups.io Cc: Rodrigo Gonzalez del Cueto , Michael Kubacki , Chasel Chiu , Nate DeSimone , Liming Gao Subject: [edk2-platforms][Patch V2] MinPlatformPkg: Library for customizing TPM platform auth Date: Mon, 11 Nov 2019 01:42:30 -0800 Message-Id: <20191111094230.6414-1-rodrigo.gonzalez.del.cueto@intel.com> X-Mailer: git-send-email 2.22.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2331 In V2: + Kept callback function and registration in Tcg2PlatformDxe module. + New library defining API function: TpmPlatformAuthReadyToBootHandler for configuring the TPM's Platform Hierachy. This is now called through Tcg2PlatformDxe's ReadyToLockEventCallBack. + Ported GetAuthSize fix to both Tcg2PlatformPei and MinPlatform's TpmPlatformAuthLib instance. In order to enable some TPM use cases BIOS should enable to customize the configuration of the TPM platform, provisioning of endorsement, platform and storage hierarchy. Cc: Michael Kubacki Cc: Chasel Chiu Cc: Nate DeSimone Cc: Liming Gao Signed-off-by: Rodrigo Gonzalez del Cueto --- .../Include/Library/TpmPlatformAuthLib.h | 24 ++ .../Intel/MinPlatformPkg/MinPlatformPkg.dec | 2 + .../Intel/MinPlatformPkg/MinPlatformPkg.dsc | 5 +- .../TpmPlatformAuthLib/TpmPlatformAuthLib.c | 229 ++++++++++++++++++ .../TpmPlatformAuthLib/TpmPlatformAuthLib.inf | 49 ++++ .../Tcg/Tcg2PlatformDxe/Tcg2PlatformDxe.c | 161 ++---------- .../Tcg/Tcg2PlatformDxe/Tcg2PlatformDxe.inf | 6 +- .../Tcg/Tcg2PlatformPei/Tcg2PlatformPei.c | 100 +++++--- 8 files changed, 402 insertions(+), 174 deletions(-) create mode 100644 Platform/Intel/MinPlatformPkg/Include/Library/TpmPlatfo= rmAuthLib.h create mode 100644 Platform/Intel/MinPlatformPkg/Tcg/Library/TpmPlatformAu= thLib/TpmPlatformAuthLib.c create mode 100644 Platform/Intel/MinPlatformPkg/Tcg/Library/TpmPlatformAu= thLib/TpmPlatformAuthLib.inf diff --git a/Platform/Intel/MinPlatformPkg/Include/Library/TpmPlatformAuthL= ib.h b/Platform/Intel/MinPlatformPkg/Include/Library/TpmPlatformAuthLib.h new file mode 100644 index 00000000..f33b67b0 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Include/Library/TpmPlatformAuthLib.h @@ -0,0 +1,24 @@ +/** @file=0D +=0D +Copyright (c) 2019, Intel Corporation. All rights reserved.
=0D +SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#ifndef _TPM_PLATFORM_AUTH_LIB_H_=0D +#define _TPM_PLATFORM_AUTH_LIB_H_=0D +=0D +#include =0D +#include =0D +=0D +/**=0D + This service will perform the TPM Platform Auth configuration at the Re= adyToBoot event.=0D +=0D +**/=0D +VOID=0D +EFIAPI=0D +TpmPlatformAuthReadyToBootHandler (=0D + VOID=0D + );=0D +=0D +#endif=0D diff --git a/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dec b/Platform/In= tel/MinPlatformPkg/MinPlatformPkg.dec index a851021c..fc5979db 100644 --- a/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dec +++ b/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dec @@ -62,6 +62,8 @@ BoardInitLib|Include/Library/BoardInitLib.h MultiBoardInitSupportLib|Include/Library/MultiBoardInitSupportLib.h=0D SecBoardInitLib|Include/Library/SecBoardInitLib.h=0D =0D +TpmPlatformAuthLib|Include/Library/TpmPlatformAuthLib.h=0D +=0D TestPointLib|Include/Library/TestPointLib.h=0D TestPointCheckLib|Include/Library/TestPointCheckLib.h=0D =0D diff --git a/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc b/Platform/In= tel/MinPlatformPkg/MinPlatformPkg.dsc index 5f9363ff..fbfd1e5d 100644 --- a/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc +++ b/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc @@ -185,7 +185,10 @@ =0D !if gMinPlatformPkgTokenSpaceGuid.PcdTpm2Enable =3D=3D TRUE=0D MinPlatformPkg/Tcg/Tcg2PlatformPei/Tcg2PlatformPei.inf=0D - MinPlatformPkg/Tcg/Tcg2PlatformDxe/Tcg2PlatformDxe.inf=0D + MinPlatformPkg/Tcg/Tcg2PlatformDxe/Tcg2PlatformDxe.inf {=0D + =0D + TpmPlatformAuthLib|MinPlatformPkg/Tcg/Library/TpmPlatformAuthLib/TpmPl= atformAuthLib.inf=0D + }=0D !endif=0D =0D [BuildOptions]=0D diff --git a/Platform/Intel/MinPlatformPkg/Tcg/Library/TpmPlatformAuthLib/T= pmPlatformAuthLib.c b/Platform/Intel/MinPlatformPkg/Tcg/Library/TpmPlatform= AuthLib/TpmPlatformAuthLib.c new file mode 100644 index 00000000..8ac780e1 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Tcg/Library/TpmPlatformAuthLib/TpmPlatf= ormAuthLib.c @@ -0,0 +1,229 @@ +/** @file=0D + TPM Platform Auth configuration library.=0D +=0D + Copyright (c) 2019, Intel Corporation. All rights reserved.
=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D + @par Specification Reference:=0D + https://trustedcomputinggroup.org/resource/tcg-tpm-v2-0-provisioning-g= uidance/=0D +**/=0D +=0D +#include =0D +=0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +=0D +//=0D +// The authorization value may be no larger than the digest produced by th= e hash=0D +// algorithm used for context integrity.=0D +//=0D +#define MAX_NEW_AUTHORIZATION_SIZE SHA512_DIGEST_SIZE=0D +=0D +/**=0D + Generate high-quality entropy source through RDRAND.=0D +=0D + @param[in] Length Size of the buffer, in bytes, to fill with.=0D + @param[out] Entropy Pointer to the buffer to store the entropy da= ta.=0D +=0D + @retval EFI_SUCCESS Entropy generation succeeded.=0D + @retval EFI_NOT_READY Failed to request random data.=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +RdRandGenerateEntropy (=0D + IN UINTN Length,=0D + OUT UINT8 *Entropy=0D + )=0D +{=0D + EFI_STATUS Status;=0D + UINTN BlockCount;=0D + UINT64 Seed[2];=0D + UINT8 *Ptr;=0D +=0D + Status =3D EFI_NOT_READY;=0D + BlockCount =3D Length / 64;=0D + Ptr =3D (UINT8 *)Entropy;=0D +=0D + //=0D + // Generate high-quality seed for DRBG Entropy=0D + //=0D + while (BlockCount > 0) {=0D + Status =3D GetRandomNumber128 (Seed);=0D + if (EFI_ERROR (Status)) {=0D + return Status;=0D + }=0D + CopyMem (Ptr, Seed, 64);=0D +=0D + BlockCount--;=0D + Ptr =3D Ptr + 64;=0D + }=0D +=0D + //=0D + // Populate the remained data as request.=0D + //=0D + Status =3D GetRandomNumber128 (Seed);=0D + if (EFI_ERROR (Status)) {=0D + return Status;=0D + }=0D + CopyMem (Ptr, Seed, (Length % 64));=0D +=0D + return Status;=0D +}=0D +=0D +/**=0D + This function returns the maximum size of TPM2B_AUTH; this structure is = used for an authorization value=0D + and limits an authValue to being no larger than the largest digest produ= ced by a TPM.=0D +=0D + @param[out] AuthSize Tpm2 Auth size=0D +=0D + @retval EFI_SUCCESS Auth size returned.=0D + @retval EFI_DEVICE_ERROR Can not return platform auth due to= device error.=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +GetAuthSize (=0D + OUT UINT16 *AuthSize=0D + )=0D +{=0D + EFI_STATUS Status;=0D + TPML_PCR_SELECTION Pcrs;=0D + UINTN Index;=0D + UINT16 DigestSize;=0D +=0D + Status =3D EFI_SUCCESS;=0D +=0D + while (mAuthSize =3D=3D 0) {=0D +=0D + mAuthSize =3D SHA1_DIGEST_SIZE;=0D + ZeroMem (&Pcrs, sizeof (TPML_PCR_SELECTION));=0D + Status =3D Tpm2GetCapabilityPcrs (&Pcrs);=0D +=0D + if (EFI_ERROR (Status)) {=0D + DEBUG ((DEBUG_ERROR, "Tpm2GetCapabilityPcrs fail!\n"));=0D + break;=0D + }=0D +=0D + DEBUG ((DEBUG_ERROR, "Tpm2GetCapabilityPcrs - %08x\n", Pcrs.count));=0D +=0D + for (Index =3D 0; Index < Pcrs.count; Index++) {=0D + DEBUG ((DEBUG_ERROR, "alg - %x\n", Pcrs.pcrSelections[Index].hash));= =0D +=0D + switch (Pcrs.pcrSelections[Index].hash) {=0D + case TPM_ALG_SHA1:=0D + DigestSize =3D SHA1_DIGEST_SIZE;=0D + break;=0D + case TPM_ALG_SHA256:=0D + DigestSize =3D SHA256_DIGEST_SIZE;=0D + break;=0D + case TPM_ALG_SHA384:=0D + DigestSize =3D SHA384_DIGEST_SIZE;=0D + break;=0D + case TPM_ALG_SHA512:=0D + DigestSize =3D SHA512_DIGEST_SIZE;=0D + break;=0D + case TPM_ALG_SM3_256:=0D + DigestSize =3D SM3_256_DIGEST_SIZE;=0D + break;=0D + default:=0D + DigestSize =3D SHA1_DIGEST_SIZE;=0D + break;=0D + }=0D +=0D + if (DigestSize > mAuthSize) {=0D + mAuthSize =3D DigestSize;=0D + }=0D + }=0D + break;=0D + }=0D +=0D + *AuthSize =3D mAuthSize;=0D + return Status;=0D +}=0D +=0D +/**=0D + Set PlatformAuth to random value.=0D +**/=0D +VOID=0D +RandomizePlatformAuth (=0D + VOID=0D + )=0D +{=0D + EFI_STATUS Status;=0D + UINT16 AuthSize;=0D + UINT32 Index;=0D + UINT8 *Rand;=0D + UINTN RandSize;=0D + TPM2B_AUTH NewPlatformAuth;=0D +=0D + //=0D + // Send Tpm2HierarchyChange Auth with random value to avoid PlatformAuth= being null=0D + //=0D +=0D + GetAuthSize (&AuthSize);=0D +=0D + ZeroMem (NewPlatformAuth.buffer, AuthSize);=0D + NewPlatformAuth.size =3D AuthSize;=0D +=0D + //=0D + // Allocate one buffer to store random data.=0D + //=0D + RandSize =3D MAX_NEW_AUTHORIZATION_SIZE;=0D + Rand =3D AllocatePool (RandSize);=0D +=0D + RdRandGenerateEntropy (RandSize, Rand);=0D + CopyMem (NewPlatformAuth.buffer, Rand, AuthSize);=0D +=0D + FreePool (Rand);=0D +=0D + //=0D + // Send Tpm2HierarchyChangeAuth command with the new Auth value=0D + //=0D + Status =3D Tpm2HierarchyChangeAuth (TPM_RH_PLATFORM, NULL, &NewPlatformA= uth);=0D + DEBUG ((DEBUG_INFO, "Tpm2HierarchyChangeAuth Result: - %r\n", Status));= =0D + ZeroMem (NewPlatformAuth.buffer, AuthSize);=0D + ZeroMem (Rand, RandSize);=0D +}=0D +=0D +/**=0D + This service defines the configuration of the Platform Hierarchy Author= ization Value (platformAuth)=0D + and Platform Hierarchy Authorization Policy (platformPolicy)=0D +=0D +**/=0D +VOID=0D +EFIAPI=0D +TpmPlatformAuthReadyToBootHandler (=0D + )=0D +{=0D + EFI_STATUS Status;=0D + VOID *Interface;=0D +=0D + //=0D + // Send Tpm2HierarchyChange Auth with random value to avoid PlatformAuth= being null=0D + //=0D + RandomizePlatformAuth ();=0D +}=0D +=0D +/**=0D + The library constructor.=0D +=0D + @param ImageHandle The firmware allocated handle for the EFI image.= =0D + @param SystemTable A pointer to the EFI System Table.=0D +=0D + @retval EFI_SUCCESS The function always return EFI_SUCCESS.=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +TpmPlatformAuthLibContructor (=0D + )=0D +{=0D + return EFI_SUCCESS;=0D +}=0D diff --git a/Platform/Intel/MinPlatformPkg/Tcg/Library/TpmPlatformAuthLib/T= pmPlatformAuthLib.inf b/Platform/Intel/MinPlatformPkg/Tcg/Library/TpmPlatfo= rmAuthLib/TpmPlatformAuthLib.inf new file mode 100644 index 00000000..8a36f35e --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Tcg/Library/TpmPlatformAuthLib/TpmPlatf= ormAuthLib.inf @@ -0,0 +1,49 @@ +### @file=0D +#=0D +# TPM Platform Auth configuration library.=0D +#=0D +# Copyright (c) 2019, Intel Corporation. All rights reserved.
=0D +#=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +###=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x00010005=0D + BASE_NAME =3D TpmPlatformAuthLib=0D + FILE_GUID =3D 7794F92C-4E8E-4E57-9E4A-49A0764C7D73= =0D + MODULE_TYPE =3D DXE_DRIVER=0D + VERSION_STRING =3D 1.0=0D + LIBRARY_CLASS =3D TpmPlatformAuthLib=0D + CONSTRUCTOR =3D TpmPlatformAuthLibContructor=0D +=0D +[LibraryClasses]=0D + MemoryAllocationLib=0D + BaseLib=0D + UefiBootServicesTableLib=0D + UefiDriverEntryPoint=0D + UefiRuntimeServicesTableLib=0D + BaseMemoryLib=0D + DebugLib=0D + Tpm2CommandLib=0D + Tpm2DeviceLib=0D + RngLib=0D + UefiLib=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + MdeModulePkg/MdeModulePkg.dec=0D + SecurityPkg/SecurityPkg.dec=0D + CryptoPkg/CryptoPkg.dec=0D +=0D +[Sources]=0D + TpmPlatformAuthLib.c=0D +=0D +[Protocols]=0D + gEfiDxeSmmReadyToLockProtocolGuid ## SOMETIMES_CONSUMES ## N= OTIFY=0D +=0D +[Guids]=0D + gEfiEventExitBootServicesGuid ## SOMETIMES_CONSUMES ## E= vent=0D +=0D +[Depex]=0D + gEfiTcg2ProtocolGuid=0D diff --git a/Platform/Intel/MinPlatformPkg/Tcg/Tcg2PlatformDxe/Tcg2Platform= Dxe.c b/Platform/Intel/MinPlatformPkg/Tcg/Tcg2PlatformDxe/Tcg2PlatformDxe.c index d0d88b2e..8fb5725c 100644 --- a/Platform/Intel/MinPlatformPkg/Tcg/Tcg2PlatformDxe/Tcg2PlatformDxe.c +++ b/Platform/Intel/MinPlatformPkg/Tcg/Tcg2PlatformDxe/Tcg2PlatformDxe.c @@ -1,8 +1,8 @@ /** @file=0D - Platform specific TPM2 component.=0D + Platform specific TPM2 component for configuring the Platform Hierarchy.= =0D =0D -Copyright (c) 2017, Intel Corporation. All rights reserved.
=0D -SPDX-License-Identifier: BSD-2-Clause-Patent=0D + Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.
=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D =0D **/=0D =0D @@ -13,138 +13,15 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include =0D #include =0D #include =0D -#include =0D -#include =0D #include =0D +#include =0D #include =0D =0D -#define MAX_NEW_AUTHORIZATION_SIZE SHA512_DIGEST_SIZE=0D -=0D /**=0D - Generate high-quality entropy source through RDRAND.=0D -=0D - @param[in] Length Size of the buffer, in bytes, to fill with.=0D - @param[out] Entropy Pointer to the buffer to store the entropy da= ta.=0D -=0D - @retval EFI_SUCCESS Entropy generation succeeded.=0D - @retval EFI_NOT_READY Failed to request random data.=0D -=0D -**/=0D -EFI_STATUS=0D -EFIAPI=0D -RdRandGenerateEntropy (=0D - IN UINTN Length,=0D - OUT UINT8 *Entropy=0D - )=0D -{=0D - EFI_STATUS Status;=0D - UINTN BlockCount;=0D - UINT64 Seed[2];=0D - UINT8 *Ptr;=0D + This callback function will run at the ReadyToLock event.=0D =0D - Status =3D EFI_NOT_READY;=0D - BlockCount =3D Length / 64;=0D - Ptr =3D (UINT8 *)Entropy;=0D -=0D - //=0D - // Generate high-quality seed for DRBG Entropy=0D - //=0D - while (BlockCount > 0) {=0D - Status =3D GetRandomNumber128(Seed);=0D - if (EFI_ERROR(Status)) {=0D - return Status;=0D - }=0D - CopyMem(Ptr, Seed, 64);=0D -=0D - BlockCount--;=0D - Ptr =3D Ptr + 64;=0D - }=0D -=0D - //=0D - // Populate the remained data as request.=0D - //=0D - Status =3D GetRandomNumber128(Seed);=0D - if (EFI_ERROR(Status)) {=0D - return Status;=0D - }=0D - CopyMem(Ptr, Seed, (Length % 64));=0D -=0D - return Status;=0D -}=0D -=0D -/**=0D - Set PlatformAuth to random value.=0D -**/=0D -VOID=0D -RandomizePlatformAuth (=0D - VOID=0D - )=0D -{=0D - EFI_STATUS Status;=0D - UINT16 AuthSize;=0D - TPML_PCR_SELECTION Pcrs;=0D - UINT32 Index;=0D - UINT8 *Rand;=0D - UINTN RandSize;=0D - TPM2B_AUTH NewPlatformAuth;=0D -=0D - //=0D - // Send Tpm2HierarchyChange Auth with random value to avoid PlatformAuth= being null=0D - //=0D - ZeroMem(&Pcrs, sizeof(TPML_PCR_SELECTION));=0D - AuthSize =3D MAX_NEW_AUTHORIZATION_SIZE;=0D -=0D - Status =3D Tpm2GetCapabilityPcrs(&Pcrs);=0D - if (EFI_ERROR(Status)) {=0D - DEBUG((EFI_D_ERROR, "Tpm2GetCapabilityPcrs fail!\n"));=0D - } else {=0D - for (Index =3D 0; Index < Pcrs.count; Index++) {=0D - switch (Pcrs.pcrSelections[Index].hash) {=0D - case TPM_ALG_SHA1:=0D - AuthSize =3D SHA1_DIGEST_SIZE;=0D - break;=0D - case TPM_ALG_SHA256:=0D - AuthSize =3D SHA256_DIGEST_SIZE;=0D - break;=0D - case TPM_ALG_SHA384:=0D - AuthSize =3D SHA384_DIGEST_SIZE;=0D - break;=0D - case TPM_ALG_SHA512:=0D - AuthSize =3D SHA512_DIGEST_SIZE;=0D - break;=0D - case TPM_ALG_SM3_256:=0D - AuthSize =3D SM3_256_DIGEST_SIZE;=0D - break;=0D - }=0D - }=0D - }=0D -=0D - ZeroMem(NewPlatformAuth.buffer, AuthSize);=0D - NewPlatformAuth.size =3D AuthSize;=0D -=0D - //=0D - // Allocate one buffer to store random data.=0D - //=0D - RandSize =3D MAX_NEW_AUTHORIZATION_SIZE;=0D - Rand =3D AllocatePool(RandSize);=0D -=0D - RdRandGenerateEntropy(RandSize, Rand);=0D - CopyMem(NewPlatformAuth.buffer, Rand, AuthSize);=0D -=0D - FreePool(Rand);=0D -=0D - //=0D - // Send Tpm2HierarchyChangeAuth command with the new Auth value=0D - //=0D - Status =3D Tpm2HierarchyChangeAuth(TPM_RH_PLATFORM, NULL, &NewPlatformAu= th);=0D - DEBUG((DEBUG_INFO, "Tpm2HierarchyChangeAuth Result: - %r\n", Status));=0D - ZeroMem(NewPlatformAuth.buffer, AuthSize);=0D - ZeroMem(Rand, RandSize);=0D -}=0D -=0D -/**=0D - This is the Event call back function to notify the Library the system is= entering=0D - run time phase.=0D + Configuration of the TPM's Platform Hierarchy Authorization Value (plat= formAuth)=0D + and Platform Hierarchy Authorization Policy (platformPolicy) can be def= ined through this function.=0D =0D @param Event Pointer to this event=0D @param Context Event hanlder private data=0D @@ -172,22 +49,20 @@ ReadyToLockEventCallBack ( return ;=0D }=0D =0D - //=0D - // Send Tpm2HierarchyChange Auth with random value to avoid PlatformAuth= being null=0D - //=0D - RandomizePlatformAuth();=0D + TpmPlatformAuthReadyToBootHandler ();=0D =0D gBS->CloseEvent (Event);=0D }=0D =0D /**=0D - The driver's entry point.=0D + The driver's entry point. Will register a function for callback during = ReadyToLock event to=0D + configure the TPM's platform authorization.=0D =0D - @param[in] ImageHandle The firmware allocated handle for the EFI image.= =0D - @param[in] SystemTable A pointer to the EFI System Table.=0D + @param[in] ImageHandle The firmware allocated handle for the EFI image= .=0D + @param[in] SystemTable A pointer to the EFI System Table.=0D =0D - @retval EFI_SUCCESS The entry point is executed successfully.=0D - @retval other Some error occurs when executing this entry poin= t.=0D + @retval EFI_SUCCESS The entry point is executed successfully.=0D + @retval other Some error occurs when executing this entry poi= nt.=0D **/=0D EFI_STATUS=0D EFIAPI=0D @@ -196,17 +71,19 @@ Tcg2PlatformDxeEntryPoint ( IN EFI_SYSTEM_TABLE *SystemTable=0D )=0D {=0D - VOID *Registration;=0D - EFI_EVENT Event;=0D + VOID *Registration;=0D + EFI_EVENT Event;=0D =0D - Event =3D EfiCreateProtocolNotifyEvent (=0D + Event =3D EfiCreateProtocolNotifyEvent (=0D &gEfiDxeSmmReadyToLockProtocolGuid,=0D TPL_CALLBACK,=0D ReadyToLockEventCallBack,=0D NULL,=0D &Registration=0D );=0D +=0D ASSERT (Event !=3D NULL);=0D =0D return EFI_SUCCESS;=0D }=0D +=0D diff --git a/Platform/Intel/MinPlatformPkg/Tcg/Tcg2PlatformDxe/Tcg2Platform= Dxe.inf b/Platform/Intel/MinPlatformPkg/Tcg/Tcg2PlatformDxe/Tcg2PlatformDxe= .inf index e8ab5f35..921f7ac6 100644 --- a/Platform/Intel/MinPlatformPkg/Tcg/Tcg2PlatformDxe/Tcg2PlatformDxe.inf +++ b/Platform/Intel/MinPlatformPkg/Tcg/Tcg2PlatformDxe/Tcg2PlatformDxe.inf @@ -28,16 +28,14 @@ UefiRuntimeServicesTableLib=0D BaseMemoryLib=0D DebugLib=0D - Tpm2CommandLib=0D - Tpm2DeviceLib=0D - RngLib=0D UefiLib=0D + TpmPlatformAuthLib=0D =0D [Packages]=0D MdePkg/MdePkg.dec=0D MdeModulePkg/MdeModulePkg.dec=0D + MinPlatformPkg/MinPlatformPkg.dec=0D SecurityPkg/SecurityPkg.dec=0D - CryptoPkg/CryptoPkg.dec=0D =0D [Sources]=0D Tcg2PlatformDxe.c=0D diff --git a/Platform/Intel/MinPlatformPkg/Tcg/Tcg2PlatformPei/Tcg2Platform= Pei.c b/Platform/Intel/MinPlatformPkg/Tcg/Tcg2PlatformPei/Tcg2PlatformPei.c index 3a2d7d31..c52547e4 100644 --- a/Platform/Intel/MinPlatformPkg/Tcg/Tcg2PlatformPei/Tcg2PlatformPei.c +++ b/Platform/Intel/MinPlatformPkg/Tcg/Tcg2PlatformPei/Tcg2PlatformPei.c @@ -1,7 +1,8 @@ /** @file=0D + Platform specific TPM2 component for configuring the Platform Hierarch= y.=0D =0D -Copyright (c) 2017, Intel Corporation. All rights reserved.
=0D -SPDX-License-Identifier: BSD-2-Clause-Patent=0D + Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.
= =0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D =0D **/=0D =0D @@ -72,52 +73,97 @@ RdRandGenerateEntropy ( }=0D =0D /**=0D - Set PlatformAuth to random value.=0D + This function returns the maximum size of TPM2B_AUTH; this structure is = used for an authorization value=0D + and limits an authValue to being no larger than the largest digest produ= ced by a TPM.=0D +=0D + @param[out] AuthSize Tpm2 Auth size=0D +=0D + @retval EFI_SUCCESS Auth size returned.=0D + @retval EFI_DEVICE_ERROR Can not return platform auth due to= device error.=0D +=0D **/=0D -VOID=0D -RandomizePlatformAuth (=0D - VOID=0D +EFI_STATUS=0D +EFIAPI=0D +GetAuthSize (=0D + OUT UINT16 *AuthSize=0D )=0D {=0D - EFI_STATUS Status;=0D - UINT16 AuthSize;=0D - TPML_PCR_SELECTION Pcrs;=0D - UINT32 Index;=0D - UINT8 *Rand;=0D - UINTN RandSize;=0D - TPM2B_AUTH NewPlatformAuth;=0D + EFI_STATUS Status;=0D + TPML_PCR_SELECTION Pcrs;=0D + UINTN Index;=0D + UINT16 DigestSize;=0D =0D - //=0D - // Send Tpm2HierarchyChange Auth with random value to avoid PlatformAuth= being null=0D - //=0D - ZeroMem(&Pcrs, sizeof(TPML_PCR_SELECTION));=0D - AuthSize =3D MAX_NEW_AUTHORIZATION_SIZE;=0D + Status =3D EFI_SUCCESS;=0D +=0D + while (mAuthSize =3D=3D 0) {=0D +=0D + mAuthSize =3D SHA1_DIGEST_SIZE;=0D + ZeroMem (&Pcrs, sizeof (TPML_PCR_SELECTION));=0D + Status =3D Tpm2GetCapabilityPcrs (&Pcrs);=0D +=0D + if (EFI_ERROR (Status)) {=0D + DEBUG ((DEBUG_ERROR, "Tpm2GetCapabilityPcrs fail!\n"));=0D + break;=0D + }=0D +=0D + DEBUG ((DEBUG_ERROR, "Tpm2GetCapabilityPcrs - %08x\n", Pcrs.count));=0D =0D - Status =3D Tpm2GetCapabilityPcrs(&Pcrs);=0D - if (EFI_ERROR(Status)) {=0D - DEBUG((EFI_D_ERROR, "Tpm2GetCapabilityPcrs fail!\n"));=0D - } else {=0D for (Index =3D 0; Index < Pcrs.count; Index++) {=0D + DEBUG ((DEBUG_ERROR, "alg - %x\n", Pcrs.pcrSelections[Index].hash));= =0D +=0D switch (Pcrs.pcrSelections[Index].hash) {=0D case TPM_ALG_SHA1:=0D - AuthSize =3D SHA1_DIGEST_SIZE;=0D + DigestSize =3D SHA1_DIGEST_SIZE;=0D break;=0D case TPM_ALG_SHA256:=0D - AuthSize =3D SHA256_DIGEST_SIZE;=0D + DigestSize =3D SHA256_DIGEST_SIZE;=0D break;=0D case TPM_ALG_SHA384:=0D - AuthSize =3D SHA384_DIGEST_SIZE;=0D + DigestSize =3D SHA384_DIGEST_SIZE;=0D break;=0D case TPM_ALG_SHA512:=0D - AuthSize =3D SHA512_DIGEST_SIZE;=0D + DigestSize =3D SHA512_DIGEST_SIZE;=0D break;=0D case TPM_ALG_SM3_256:=0D - AuthSize =3D SM3_256_DIGEST_SIZE;=0D + DigestSize =3D SM3_256_DIGEST_SIZE;=0D + break;=0D + default:=0D + DigestSize =3D SHA1_DIGEST_SIZE;=0D break;=0D }=0D +=0D + if (DigestSize > mAuthSize) {=0D + mAuthSize =3D DigestSize;=0D + }=0D }=0D + break;=0D }=0D =0D + *AuthSize =3D mAuthSize;=0D + return Status;=0D +}=0D +=0D +/**=0D + Set PlatformAuth to random value.=0D +**/=0D +VOID=0D +RandomizePlatformAuth (=0D + VOID=0D + )=0D +{=0D + EFI_STATUS Status;=0D + UINT16 AuthSize;=0D + UINT32 Index;=0D + UINT8 *Rand;=0D + UINTN RandSize;=0D + TPM2B_AUTH NewPlatformAuth;=0D +=0D + //=0D + // Send Tpm2HierarchyChange Auth with random value to avoid PlatformAuth= being null=0D + //=0D +=0D + GetAuthSize (&AuthSize);=0D +=0D ZeroMem(NewPlatformAuth.buffer, AuthSize);=0D NewPlatformAuth.size =3D AuthSize;=0D =0D --=20 2.22.0.windows.1