From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web09.8093.1634737429739754630 for ; Wed, 20 Oct 2021 06:43:49 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: joseph.hemann@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 661F2113E; Wed, 20 Oct 2021 06:43:49 -0700 (PDT) Received: from u203013-lin.austin.arm.com (u203013-lin.austin.arm.com [10.118.29.243]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5B2B13F73D; Wed, 20 Oct 2021 06:43:49 -0700 (PDT) From: "Joseph Hemann" To: devel@edk2.groups.io Cc: nd@arm.com, Joseph Hemann , G Edhaya Chandran , Barton Gao , Carolyn Gjertsen , Samer El-Haj-Mahmoud , Eric Jin , Arvin Chen , Supreeth Venkatesh Subject: [PATCH 3/6] uefi-sct/SctPkg: TCG2 Protocol: add GetActivePcrBanks test Date: Wed, 20 Oct 2021 08:43:32 -0500 Message-Id: <20211020134335.55257-4-joseph.hemann@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211020134335.55257-1-joseph.hemann@arm.com> References: <20211020134335.55257-1-joseph.hemann@arm.com> From: Joseph Hemann -add initial TCG2 protocol test for GetActivePcrBanks() -checkpoint for NULL pointer passed for buffer -checkpoint for test of function with proper input Cc: G Edhaya Chandran Cc: Barton Gao Cc: Carolyn Gjertsen Cc: Samer El-Haj-Mahmoud Cc: Eric Jin Cc: Arvin Chen Cc: Supreeth Venkatesh Signed-off-by: Joseph Hemann --- .../EFI/Protocol/TCG2/BlackBoxTest/Guid.c | 4 + .../EFI/Protocol/TCG2/BlackBoxTest/Guid.h | 10 ++ .../TCG2/BlackBoxTest/TCG2ProtocolBBTest.h | 23 +++ .../TCG2ProtocolBBTestConformance.c | 140 +++++++++++++++++- .../BlackBoxTest/TCG2ProtocolBBTestMain.c | 9 ++ 5 files changed, 185 insertions(+), 1 deletion(-) diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/Guid.c b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/Guid.c index 206662ee7933..0497f08f74f2 100644 --- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/Guid.c +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/Guid.c @@ -33,3 +33,7 @@ EFI_GUID gTcg2ConformanceTestAssertionGuid001 = EFI_TEST_TCG2CONFORMANCE_ASSERTI EFI_GUID gTcg2ConformanceTestAssertionGuid002 = EFI_TEST_TCG2CONFORMANCE_ASSERTION_002_GUID; EFI_GUID gTcg2ConformanceTestAssertionGuid003 = EFI_TEST_TCG2CONFORMANCE_ASSERTION_003_GUID; + +EFI_GUID gTcg2ConformanceTestAssertionGuid004 = EFI_TEST_TCG2CONFORMANCE_ASSERTION_004_GUID; + +EFI_GUID gTcg2ConformanceTestAssertionGuid005 = EFI_TEST_TCG2CONFORMANCE_ASSERTION_005_GUID; diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/Guid.h b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/Guid.h index b675756b9fb7..f470255ccdcf 100644 --- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/Guid.h +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/Guid.h @@ -41,3 +41,13 @@ extern EFI_GUID gTcg2ConformanceTestAssertionGuid002; extern EFI_GUID gTcg2ConformanceTestAssertionGuid003; +#define EFI_TEST_TCG2CONFORMANCE_ASSERTION_004_GUID \ +{ 0x7a1e79a3, 0x4064, 0x4372, {0xbb, 0x64, 0x55, 0xb8, 0xf2, 0xa5, 0xa3, 0x26 }} + +extern EFI_GUID gTcg2ConformanceTestAssertionGuid004; + +#define EFI_TEST_TCG2CONFORMANCE_ASSERTION_005_GUID \ +{ 0xb0e717c4, 0xb1e2, 0x49f7, {0xb2, 0xd7, 0x60, 0x58, 0x97, 0x7d, 0x09, 0x2c }} + +extern EFI_GUID gTcg2ConformanceTestAssertionGuid005; + diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/TCG2ProtocolBBTest.h b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/TCG2ProtocolBBTest.h index 674540182d2d..a6773010b64f 100644 --- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/TCG2ProtocolBBTest.h +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/TCG2ProtocolBBTest.h @@ -37,6 +37,9 @@ Abstract: #define EFI_TCG2_PROTOCOL_TEST_ENTRY_GUID0101 \ {0x39ff9c71, 0x4b41, 0x4e5b, {0xae, 0xd7, 0x87, 0xc7, 0x94, 0x18, 0x7d, 0x67} } +#define EFI_TCG2_PROTOCOL_TEST_ENTRY_GUID0102 \ + {0x847f1ae0, 0xb429, 0x49f1, {0x9e, 0x0c, 0x8f, 0x43, 0xfb, 0x55, 0x34, 0x54} } + EFI_STATUS EFIAPI BBTestTCG2ProtocolUnload ( @@ -55,6 +58,18 @@ BBTestGetCapabilityConformanceTestCheckpoint2 ( IN EFI_TCG2_PROTOCOL *TCG2 ); +EFI_STATUS +BBTestGetActivePcrBanksConformanceTestCheckpoint1 ( + IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib, + IN EFI_TCG2_PROTOCOL *TCG2 + ); + +EFI_STATUS +BBTestGetActivePcrBanksConformanceTestCheckpoint2 ( + IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib, + IN EFI_TCG2_PROTOCOL *TCG2 + ); + EFI_STATUS BBTestGetCapabilityConformanceTest ( IN EFI_BB_TEST_PROTOCOL *This, @@ -63,3 +78,11 @@ BBTestGetCapabilityConformanceTest ( IN EFI_HANDLE SupportHandle ); +EFI_STATUS +BBTestGetActivePcrBanksConformanceTest ( + IN EFI_BB_TEST_PROTOCOL *This, + IN VOID *ClientInterface, + IN EFI_TEST_LEVEL TestLevel, + IN EFI_HANDLE SupportHandle + ); + diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/TCG2ProtocolBBTestConformance.c b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/TCG2ProtocolBBTestConformance.c index fec542167171..5277f9433f7e 100644 --- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/TCG2ProtocolBBTestConformance.c +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/TCG2ProtocolBBTestConformance.c @@ -75,6 +75,54 @@ BBTestGetCapabilityConformanceTest ( return EFI_SUCCESS; } +/** + * @brief Entrypoint for GetActivePcrBanks() Function Test. + * 2 checkpoints will be tested. + * @param This a pointer of EFI_BB_TEST_PROTOCOL + * @param ClientInterface A pointer to the interface array under test + * @param TestLevel Test "thoroughness" control + * @param SupportHandle A handle containing protocols required + * @return EFI_SUCCESS + * @return EFI_NOT_FOUND + */ + +EFI_STATUS +BBTestGetActivePcrBanksConformanceTest ( + IN EFI_BB_TEST_PROTOCOL *This, + IN VOID *ClientInterface, + IN EFI_TEST_LEVEL TestLevel, + IN EFI_HANDLE SupportHandle + ) +{ + EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib; + EFI_STATUS Status; + EFI_TCG2_PROTOCOL *TCG2; + + // + // init + // + TCG2 = (EFI_TCG2_PROTOCOL*)ClientInterface; + + // + // Get the Standard Library Interface + // + Status = gtBS->HandleProtocol ( + SupportHandle, + &gEfiStandardTestLibraryGuid, + (VOID **) &StandardLib + ); + if (EFI_ERROR(Status)) { + return Status; + } + + // Test Using NULL Pointer + BBTestGetActivePcrBanksConformanceTestCheckpoint1 (StandardLib, TCG2); + + // Test with correct size field + BBTestGetActivePcrBanksConformanceTestCheckpoint2 (StandardLib, TCG2); + + return EFI_SUCCESS; +} EFI_STATUS BBTestGetCapabilityConformanceTestCheckpoint1 ( @@ -181,7 +229,7 @@ BBTestGetCapabilityConformanceTestCheckpoint2 ( AssertionType = EFI_TEST_ASSERTION_FAILED; } - EFI_TCG2_EVENT_ALGORITHM_BITMAP HashBitMapAlgos = EFI_TCG2_BOOT_HASH_ALG_SHA256 | EFI_TCG2_BOOT_HASH_ALG_SHA384 | EFI_TCG2_BOOT_HASH_ALG_SHA512; + EFI_TCG2_EVENT_ALGORITHM_BITMAP HashBitMapAlgos = EFI_TCG2_BOOT_HASH_ALG_SHA1 | EFI_TCG2_BOOT_HASH_ALG_SHA256 | EFI_TCG2_BOOT_HASH_ALG_SHA384 | EFI_TCG2_BOOT_HASH_ALG_SHA512; if (!(BootServiceCap.HashAlgorithmBitmap & HashBitMapAlgos)) { StandardLib->RecordMessage ( @@ -219,3 +267,93 @@ BBTestGetCapabilityConformanceTestCheckpoint2 ( return EFI_SUCCESS; } +EFI_STATUS +BBTestGetActivePcrBanksConformanceTestCheckpoint1 ( + IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib, + IN EFI_TCG2_PROTOCOL *TCG2 + ) +{ + EFI_TEST_ASSERTION AssertionType; + EFI_STATUS Status; + + EFI_TCG2_EVENT_ALGORITHM_BITMAP *ActivePcrBanks = NULL; + Status = TCG2->GetActivePcrBanks ( + TCG2, + ActivePcrBanks); + + // Ensure GetCapablity returns Invalid Parameter when passing in NULL pointer + if (EFI_INVALID_PARAMETER == Status) { + AssertionType = EFI_TEST_ASSERTION_PASSED; + } else { + AssertionType = EFI_TEST_ASSERTION_FAILED; + } + + StandardLib->RecordAssertion ( + StandardLib, + AssertionType, + gTcg2ConformanceTestAssertionGuid004, + L"TCG2_PROTOCOL.GetActivePcrBanks - GetActivePcrBanks() returns EFI_INVALID_PARAMETER with NULL pointer Passed in", + L"%a:%d: Status - %r", + __FILE__, + (UINTN)__LINE__, + Status + ); + + return EFI_SUCCESS; +} + +EFI_STATUS +BBTestGetActivePcrBanksConformanceTestCheckpoint2 ( + IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib, + IN EFI_TCG2_PROTOCOL *TCG2 + ) +{ + EFI_TEST_ASSERTION AssertionType; + EFI_STATUS Status; + + EFI_TCG2_EVENT_ALGORITHM_BITMAP ActivePcrBanks; + Status = TCG2->GetActivePcrBanks ( + TCG2, + &ActivePcrBanks); + + // Ensure GetActivePcrBanks returns EFI_SUCCESS + if (Status == EFI_SUCCESS) { + AssertionType = EFI_TEST_ASSERTION_PASSED; + } else { + StandardLib->RecordMessage ( + StandardLib, + EFI_VERBOSE_LEVEL_DEFAULT, + L"\r\nTCG2 Protocol GetActivePcrBanks Test: GetActivePcrBanks should return EFI_SUCCESS", + ActivePcrBanks + ); + + AssertionType = EFI_TEST_ASSERTION_FAILED; + } + + EFI_TCG2_EVENT_ALGORITHM_BITMAP BitMapAlgos = EFI_TCG2_BOOT_HASH_ALG_SHA256 | EFI_TCG2_BOOT_HASH_ALG_SHA384 | EFI_TCG2_BOOT_HASH_ALG_SHA512; + + // Ensure ActivePcrBanks has SHA256/384/512 in its Bitmap + if (!(ActivePcrBanks & BitMapAlgos)) { + StandardLib->RecordMessage ( + StandardLib, + EFI_VERBOSE_LEVEL_DEFAULT, + L"\r\nTCG2 Protocol GetActivePcrBanks Test: GetActiVePcrBanks should have SHA256/384/512 Algorithm in its Bitmap. ActivePcrBanks = %x", + ActivePcrBanks + ); + + AssertionType = EFI_TEST_ASSERTION_FAILED; + } + + StandardLib->RecordAssertion ( + StandardLib, + AssertionType, + gTcg2ConformanceTestAssertionGuid005, + L"TCG2_PROTOCOL.GetActivePcrBanks - GetActivePcrBanks should return with EFI_SUCCESS and have SHA256/384/512 Algoritms in its Bitmap", + L"%a:%d: Status - %r", + __FILE__, + (UINTN)__LINE__, + Status + ); + + return EFI_SUCCESS; +} diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/TCG2ProtocolBBTestMain.c b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/TCG2ProtocolBBTestMain.c index 97da8f58e35f..4e7b15937ebb 100644 --- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/TCG2ProtocolBBTestMain.c +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/TCG2ProtocolBBTestMain.c @@ -47,6 +47,15 @@ EFI_BB_TEST_ENTRY_FIELD gBBTestEntryField[] = { EFI_TEST_CASE_AUTO, BBTestGetCapabilityConformanceTest }, + { + EFI_TCG2_PROTOCOL_TEST_ENTRY_GUID0102, + L"GetActivePcrBanks_Conf", + L"Test the GetActivePcrBanks API", + EFI_TEST_LEVEL_DEFAULT, + gSupportProtocolGuid1, + EFI_TEST_CASE_AUTO, + BBTestGetActivePcrBanksConformanceTest + }, 0 }; -- 2.17.1