From nobody Mon Feb 9 11:46:44 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+82428+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+82428+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1634737433; cv=none; d=zohomail.com; s=zohoarc; b=PeLZ4vcJCZ1z7kR3QNHZn2vJMgTQWhvY55K9+x8VoYZ2jMG1+8jrbMmoVOD8BotlOHo7Q4whqShMcG8SIif7GnjK3noUb9Z5lQTmkPuQk7LAFk/TxHa2f7S14lobDgeeXb/hUWXLf9/HzkCg3GZqeHKkaAaG/XI7sVI5P0J2Dac= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1634737433; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=DbaQdx31qN+1wK1KbhXcUIYloUOcA9BG9ykmQEL3USE=; b=LkYGTcjnT6GSKMiC7f0PbjwiLjQ6dL8ADq/Q96LmC1J4ZT7meek38fv7gff4OpafLIQ5Pp5rAG6omcN1Ry3D6S0U/sSuwymg6b5BikI/2vVQo2yBRmSgnHDL2S2LLfbWLA8W18Z7U3fFUlfd6qumxjUqkWX1ndd049oSQeJNcnA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+82428+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1634737433042727.7209497839735; Wed, 20 Oct 2021 06:43:53 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id Vt59YY1788612xgih2I6ynsl; Wed, 20 Oct 2021 06:43:52 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.8168.1634737432070334329 for ; Wed, 20 Oct 2021 06:43:52 -0700 X-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 C2D971063; Wed, 20 Oct 2021 06:43:51 -0700 (PDT) X-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 B720F3F73D; Wed, 20 Oct 2021 06:43:51 -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: [edk2-devel] [PATCH 6/6] uefi-sct/SctPkg: TCG2 Protocol: add SubmitCommand test Date: Wed, 20 Oct 2021 08:43:35 -0500 Message-Id: <20211020134335.55257-7-joseph.hemann@arm.com> In-Reply-To: <20211020134335.55257-1-joseph.hemann@arm.com> References: <20211020134335.55257-1-joseph.hemann@arm.com> Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,joseph.hemann@arm.com X-Gm-Message-State: 55KwruygFSqToqUnPezn89wXx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634737432; bh=plNl9GMMRL+x3h0E0u+vqCsVFV+YeMJVIfPBWkPcSj4=; h=Cc:Date:From:Reply-To:Subject:To; b=TGAGgNxd1Cp0XBo15NYTAmLCsMyQv3A+ddGckKD9SrOwgbxUMpnTKhkcsFhg607XGnJ kKLbifPsW/y7Fku/qkxuvykuptUNBglrBaqH/aR+THN0jUh6VPIDOl0XW5+VR4cTKeRc/ 5XPsqkMYoZEUz8unJ6bQj8to5vBNZC/mDRA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634737434597100002 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Joseph Hemann -add initial TCG2 protocol test for SubmitCommand() -checkpoint for test function with GET_RANDOM Command 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 | 49 +++++ .../TCG2ProtocolBBTestConformance.c | 178 ++++++++++++++++++ .../BlackBoxTest/TCG2ProtocolBBTestMain.c | 10 + 5 files changed, 251 insertions(+) diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/G= uid.c b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/Guid.c index 89c4151752cd..b5a4e5c7218e 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 @@ -53,3 +53,7 @@ EFI_GUID gTcg2ConformanceTestAssertionGuid011 =3D EFI_TES= T_TCG2CONFORMANCE_ASSERTI EFI_GUID gTcg2ConformanceTestAssertionGuid012 =3D EFI_TEST_TCG2CONFORMANCE= _ASSERTION_012_GUID; =20 EFI_GUID gTcg2ConformanceTestAssertionGuid013 =3D EFI_TEST_TCG2CONFORMANCE= _ASSERTION_013_GUID; + +EFI_GUID gTcg2ConformanceTestAssertionGuid014 =3D EFI_TEST_TCG2CONFORMANCE= _ASSERTION_014_GUID; + +EFI_GUID gTcg2ConformanceTestAssertionGuid015 =3D EFI_TEST_TCG2CONFORMANCE= _ASSERTION_015_GUID; diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/G= uid.h b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/Guid.h index 2cb715105529..ccc5a4bef957 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 @@ -90,3 +90,13 @@ extern EFI_GUID gTcg2ConformanceTestAssertionGuid012; { 0x45fa1a42, 0x912a, 0x5124, {0x84, 0xf4, 0x41, 0x67, 0xab, 0xb5, 0x89, 0= x90 }} =20 extern EFI_GUID gTcg2ConformanceTestAssertionGuid013; + +#define EFI_TEST_TCG2CONFORMANCE_ASSERTION_014_GUID \ +{ 0x1689bc3a, 0x2298, 0xa116, {0x28, 0x4c, 0xc1, 0xdd, 0xaa, 0xd8, 0xef, 0= x51 }} + +extern EFI_GUID gTcg2ConformanceTestAssertionGuid014; + +#define EFI_TEST_TCG2CONFORMANCE_ASSERTION_015_GUID \ +{ 0x126a789a, 0x1932, 0x3234, {0x21, 0xab, 0x42, 0x64, 0x8a, 0x7b, 0x63, 0= x76 }} + +extern EFI_GUID gTcg2ConformanceTestAssertionGuid015; diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/T= CG2ProtocolBBTest.h b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/Black= BoxTest/TCG2ProtocolBBTest.h index 69fb358922df..0fdf753f95fa 100644 --- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/TCG2Prot= ocolBBTest.h +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/TCG2Prot= ocolBBTest.h @@ -43,6 +43,9 @@ Abstract: #define EFI_TCG2_PROTOCOL_TEST_ENTRY_GUID0103 \ {0x907a7878, 0xb294, 0xf147, {0xe9, 0x0a, 0x65, 0x43, 0xab, 0x55, 0x76, 0= x46} } =20 +#define EFI_TCG2_PROTOCOL_TEST_ENTRY_GUID0104 \ + {0x9087ad78, 0x9ad2, 0x4172, {0x9a, 0xbc, 0x98, 0x23, 0x08, 0xf5, 0x6d, 0= x26} } + #define EV_POST_CODE 0x01 =20 #define EV_NO_ACTION 0x03 @@ -51,6 +54,39 @@ Abstract: =20 #define PE_COFF_IMAGE 0x0000000000000010 =20 +// ST_NO_SESSION as definied in Table 19 of TPM Library Part 2: Structures +#define ST_NO_SESSIONS (UINT16) 0x8001 + +// TPM_RC_SUCCESS as definied in Table 16 of TPM Library Spec Part 2: Stru= ctures +#define TPM_RC_SUCCESS (UINT32) 0x0000000 + +// TPM_CC_GetRandom as definied in Table 12 of TPM Library Spec Part 2: St= ructures +#define TPM_CC_GetRandom (UINT32) 0x0000017B + +#pragma pack(1) +// TPM2B_DIGEST as definied in Table 73 of TPM Library Spec Part 2: Struct= ures +typedef struct { + UINT16 size; + UINT8 digest[8]; // Size of buffer in spec is defined to be variable l= ength but for this test will always be 8 +} TPM2B_DIGEST; + +// GetRandomCommand Structure as defined in Sectin 16.1 of TPM Spec Part 3= : Commands +typedef struct { + UINT16 Tag; + UINT32 CommandSize; + UINT32 CommandCode; + UINT16 BytesRequested; +} GET_RANDOM_COMMAND; + +// GetRandomResponse Structure as defined in Sectin 16.1 of TPM Spec Part = 3: Commands +typedef struct { + UINT16 Tag; + UINT32 ResponseSize; + UINT32 ResponseCode; + TPM2B_DIGEST randomBytes; +} GET_RANDOM_RESPONSE; +#pragma + EFI_STATUS EFIAPI BBTestTCG2ProtocolUnload ( @@ -105,6 +141,12 @@ BBTestHashLogExtendEventConformanceTestCheckpoint4 ( IN EFI_TCG2_PROTOCOL *TCG2 ); =20 +EFI_STATUS +BBTestSubmitCommandConformanceTestCheckpoint1 ( + IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib, + IN EFI_TCG2_PROTOCOL *TCG2 + ); + EFI_STATUS BBTestGetCapabilityConformanceTest ( IN EFI_BB_TEST_PROTOCOL *This, @@ -129,3 +171,10 @@ BBTestHashLogExtendEventConformanceTest ( IN EFI_HANDLE SupportHandle ); =20 +EFI_STATUS +BBTestSubmitCommandConformanceTest ( + 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/T= CG2ProtocolBBTestConformance.c b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol= /TCG2/BlackBoxTest/TCG2ProtocolBBTestConformance.c index d3aaf979c087..b764e22116d0 100644 --- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/TCG2Prot= ocolBBTestConformance.c +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/TCG2Prot= ocolBBTestConformance.c @@ -177,6 +177,52 @@ BBTestHashLogExtendEventConformanceTest ( return EFI_SUCCESS; } =20 +/** + * @brief Entrypoint for SubmitCommand() Function Test. + * 1 checkpoint 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 +BBTestSubmitCommandConformanceTest ( + 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 =3D (EFI_TCG2_PROTOCOL*)ClientInterface; + + // + // Get the Standard Library Interface + // + Status =3D gtBS->HandleProtocol ( + SupportHandle, + &gEfiStandardTestLibraryGuid, + (VOID **) &StandardLib + ); + if (EFI_ERROR(Status)) { + return Status; + } + + // Test GetRandom TPM Command + BBTestSubmitCommandConformanceTestCheckpoint1 (StandardLib, TCG2); + + return EFI_SUCCESS; +} + EFI_STATUS BBTestGetCapabilityConformanceTestCheckpoint1 ( IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib, @@ -837,3 +883,135 @@ BBTestHashLogExtendEventConformanceTestCheckpoint4 ( =20 return EFI_SUCCESS; } + +EFI_STATUS +BBTestSubmitCommandConformanceTestCheckpoint1 ( + IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib, + IN EFI_TCG2_PROTOCOL *TCG2 + ) +{ + EFI_TEST_ASSERTION AssertionType; + EFI_STATUS Status; + GET_RANDOM_RESPONSE CommandResponse; + GET_RANDOM_COMMAND CommandInput; + int IsNonZero =3D 0; + + // Build TPM2 GetRandom command for 8 random bytes + CommandInput.Tag =3D SctSwapBytes16(ST_NO_SESSIONS); + CommandInput.CommandSize =3D SctSwapBytes32(sizeof(GET_RANDOM_COMMAND)); + CommandInput.CommandCode =3D SctSwapBytes32(TPM_CC_GetRandom); + CommandInput.BytesRequested =3D SctSwapBytes16(8); + + // zero out randomBytes to ensure SubmitCommand returns random bytes + SctZeroMem(&CommandResponse, sizeof(GET_RANDOM_RESPONSE)); + + Status =3D TCG2->SubmitCommand ( + TCG2, + sizeof(GET_RANDOM_COMMAND), + &CommandInput, + sizeof(GET_RANDOM_RESPONSE), + &CommandResponse); + + AssertionType =3D EFI_TEST_ASSERTION_PASSED; + + // Verify SubmitCommand returns EFI_SUCCESS + if (Status !=3D EFI_SUCCESS) { + StandardLib->RecordMessage ( + StandardLib, + EFI_VERBOSE_LEVEL_DEFAULT, + L"\r\nTCG2 Protocol SubmitCommand Test: SubmitCommand= should return EFI_SUCCESS, Status =3D %r", + Status + ); + + AssertionType =3D EFI_TEST_ASSERTION_FAILED; + } + + StandardLib->RecordAssertion ( + StandardLib, + AssertionType, + gTcg2ConformanceTestAssertionGuid014, + L"TCG2_PROTOCOL.SubmitCommand - SubmitCommand() should re= turn EFI_SUCCESS", + L"%a:%d: Status - %r", + __FILE__, + (UINTN)__LINE__, + Status + ); + + AssertionType =3D EFI_TEST_ASSERTION_PASSED; + + // Verify SubmitCommand returns correct Response Tag + if (SctSwapBytes16(CommandResponse.Tag) !=3D ST_NO_SESSIONS) { + StandardLib->RecordMessage ( + StandardLib, + EFI_VERBOSE_LEVEL_DEFAULT, + L"\r\nTCG2 Protocol SubmitCommand Test: SubmitCommand= should return ST_NO_SESSIONS response Tag" + ); + + AssertionType =3D EFI_TEST_ASSERTION_FAILED; + } + + if (SctSwapBytes32(CommandResponse.ResponseCode) !=3D TPM_RC_SUCCESS) { + StandardLib->RecordMessage ( + StandardLib, + EFI_VERBOSE_LEVEL_DEFAULT, + L"\r\nTCG2 Protocol SubmitCommand Test: SubmitCommand= should return Correct ResponseCode, ResponseCode =3D %x", + SctSwapBytes32(CommandResponse.ResponseCode) + ); + + AssertionType =3D EFI_TEST_ASSERTION_FAILED; + } + + if (SctSwapBytes32(CommandResponse.ResponseSize) !=3D sizeof(GET_RANDOM_= RESPONSE)) { + StandardLib->RecordMessage ( + StandardLib, + EFI_VERBOSE_LEVEL_DEFAULT, + L"\r\nTCG2 Protocol SubmitCommand Test: SubmitCommand= should return Correct ResponseSize, Size =3D %x", + SctSwapBytes32(CommandResponse.ResponseSize) + ); + + AssertionType =3D EFI_TEST_ASSERTION_FAILED; + } + + // Check that number of random bytes returned equals amount requested + if (SctSwapBytes16(CommandResponse.randomBytes.size) !=3D 8) { + StandardLib->RecordMessage ( + StandardLib, + EFI_VERBOSE_LEVEL_DEFAULT, + L"\r\nTCG2 Protocol SubmitCommand Test: SubmitCommand= should return correct amount of random bytes, Size =3D %x", + SctSwapBytes16(CommandResponse.randomBytes.size) + ); + + AssertionType =3D EFI_TEST_ASSERTION_FAILED; + } + + // If random bytes are returned at least one should be non-zero + for (int i =3D 0; i < 8; i++) { + if (CommandResponse.randomBytes.digest[i] !=3D 0) { + IsNonZero =3D 1; + } + } + + if (!IsNonZero) { + StandardLib->RecordMessage ( + StandardLib, + EFI_VERBOSE_LEVEL_DEFAULT, + L"\r\nTCG2 Protocol SubmitCommand Test: SubmitCommand= should return RandomBytes", + Status + ); + + AssertionType =3D EFI_TEST_ASSERTION_FAILED; + } + + StandardLib->RecordAssertion ( + StandardLib, + AssertionType, + gTcg2ConformanceTestAssertionGuid015, + L"TCG2_PROTOCOL.SubmitCommand - SubmitCommand() should re= turn EFI_SUCCESS", + L"%a:%d: Status - %r", + __FILE__, + (UINTN)__LINE__, + Status + ); + + return EFI_SUCCESS; +} diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/T= CG2ProtocolBBTestMain.c b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/B= lackBoxTest/TCG2ProtocolBBTestMain.c index 892fce2691c1..419e2a3e5ad2 100644 --- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/TCG2Prot= ocolBBTestMain.c +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/TCG2Prot= ocolBBTestMain.c @@ -65,6 +65,16 @@ EFI_BB_TEST_ENTRY_FIELD gBBTestEntryField[] =3D { EFI_TEST_CASE_AUTO, BBTestHashLogExtendEventConformanceTest }, + { + EFI_TCG2_PROTOCOL_TEST_ENTRY_GUID0104, + L"SubmitCommand_Conf", + L"Test the SubmitCommmand API", + EFI_TEST_LEVEL_DEFAULT, + gSupportProtocolGuid1, + EFI_TEST_CASE_AUTO, + BBTestSubmitCommandConformanceTest + }, + 0 }; =20 --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#82428): https://edk2.groups.io/g/devel/message/82428 Mute This Topic: https://groups.io/mt/86464914/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-