From nobody Mon Feb 9 03:13:29 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+86462+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+86462+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1644370398; cv=none; d=zohomail.com; s=zohoarc; b=OWYuKcmgxxf40sblceihBqRGIuKU7DJq6KPgMn//S6hZoPnl6JpnfW0c8sZwpfc39E8VLxPouvsFiSDw9ZF8Cdojso1DZyA/Rzc/lYm8U6abcAAj0fkTQI5c4iztBsdoxcz6Hrcc4p2ZF3p0nTfnBz3YHe0mPx+teF5HpeNa3+8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644370398; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=5nSYRv51Re4B+jdj6M42jnXx8MwO4vTS/4kBbLBRaWg=; b=e0vaRrtUiP04ghMBwBk065rGdmvnGbMnef6l9B6Pmhh2K0ZOZ9hjj8LOoz9CzdIb7qUxov4kH6/1rDmy8f3YAKNuKOlPMC2ij50x9whxwDS4fKYLzQkJmLwK/4aWFOG/ThvsrpOX8WYOj+Tub5fG1/hQoiuyLWm1kebzpY8FPVs= 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+86462+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 1644370398721261.473947094443; Tue, 8 Feb 2022 17:33:18 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id oiNmYY1788612x6ioYYN28G1; Tue, 08 Feb 2022 17:33:18 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web08.20737.1644370396909074044 for ; Tue, 08 Feb 2022 17:33:17 -0800 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 913351515; Tue, 8 Feb 2022 17:33:16 -0800 (PST) X-Received: from u203013-lin.austin.arm.com (u203013-lin.austin.arm.com [10.118.28.29]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 869023F718; Tue, 8 Feb 2022 17:33:16 -0800 (PST) From: "Joseph Hemann" To: devel@edk2.groups.io Cc: G Edhaya Chandran , Barton Gao , Carolyn Gjertsen , Samer El-Haj-Mahmoud , Eric Jin , Arvin Chen , Supreeth Venkatesh , Stuart Yoder Subject: [edk2-devel] [PATCH V3 6/6] uefi-sct/SctPkg: TCG2 Protocol: add SubmitCommand test Date: Tue, 8 Feb 2022 19:33:06 -0600 Message-Id: <20220209013306.425846-7-Joseph.hemann@arm.com> In-Reply-To: <20220209013306.425846-1-Joseph.hemann@arm.com> References: <20220209013306.425846-1-Joseph.hemann@arm.com> MIME-Version: 1.0 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: 1ub323MH3VerZSgxLmCqFtRTx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1644370398; bh=rYZsCBM/icjU3LXbV3KBQi71qM1Q+dKd/B201VqBHrA=; h=Cc:Date:From:Reply-To:Subject:To; b=icNiXu/pSnLRckU6xx7zMey34+ZfOuNhLc22An/o12nxbuLMRUvRxp2+cHz/0HElY8e sJtEXTOv+1iZkC9PNXohKS+Cvdug72gWUnHDNYdY+xXUKShIh5jLA1ixBOqQ7PSK70XE/ 1MEifyplEPTuAuLjaUtomKyLMqmiZYUDcOQ= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1644370400174100002 Content-Type: text/plain; charset="utf-8" -add initial TCG2 protocol test for SubmitCommand() -checkpoint for test function with TPM2_Hash Command V2: -Change command submitted from GetRandom to TPM2_HASH -combined to 2 assertions into 1 Cc: G Edhaya Chandran Cc: Barton Gao Cc: Carolyn Gjertsen Cc: Samer El-Haj-Mahmoud Cc: Eric Jin Cc: Arvin Chen Cc: Supreeth Venkatesh Cc: Stuart Yoder Signed-off-by: Joseph Hemann Change-Id: Ibab68cae1d49953d1076c5628ea80319ba7ca831 --- .../SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/Guid.h | 5 + .../UEFI/EFI/Protocol/TCG2/BlackBoxTest/TCG2ProtocolBBTest.h | 70 ++++= +++++++ .../SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/Guid.c | 2 + .../Protocol/TCG2/BlackBoxTest/TCG2ProtocolBBTestConformance.c | 172 ++++= ++++++++++++++++++++++++ .../EFI/Protocol/TCG2/BlackBoxTest/TCG2ProtocolBBTestMain.c | 9 ++ 5 files changed, 258 insertions(+) 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 d3a18aeebf09..507cecc67593 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 @@ -100,3 +100,8 @@ extern EFI_GUID gTcg2ConformanceTestAssertionGuid014; { 0xa76d2903, 0xbbcc, 0x8a72, {0x90, 0x23, 0xd3, 0xaa, 0xba, 0xb1, 0x52, 0= x13 }} =20 extern EFI_GUID gTcg2ConformanceTestAssertionGuid015; + +#define EFI_TEST_TCG2CONFORMANCE_ASSERTION_016_GUID \ +{ 0x1689bc3a, 0x2298, 0xa116, {0x28, 0x4c, 0xc1, 0xdd, 0xaa, 0xd8, 0xef, 0= x51 }} + +extern EFI_GUID gTcg2ConformanceTestAssertionGuid016; 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 d9c2309462d7..c8684f7915a6 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,61 @@ 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_Hash as definied in Table 12 of TPM Library Spec Part 2: Structu= res +#define TPM_CC_Hash (UINT32)(0x0000017D) + +#define TPM_RH_NULL (UINT32) 0x40000007 + +#define TPM_ALG_SHA256 (UINT16) 0x000B + +#define SHA256_LENGTH (UINT16) 0x0020 + +#pragma pack(1) +// TPM2B_MAX_BUFFER as definied in Table 86 of TPM Library Spec Part 2: St= ructures +typedef struct { + UINT16 size; + UINT8 digest[5]; // Size of buffer in spec is defined to be variable l= ength but for this test will always be 5 +} TPM2B_MAX_BUFFER; + +#pragma pack(1) +// TPM2B_DIGEST as definied in Table 73 of TPM Library Spec Part 2: Struct= ures +typedef struct { + UINT16 size; + UINT8 digest[32]; // Size of buffer in spec is defined to be variable = length but for this test will always be 32 +} TPM2B_DIGEST; + +typedef struct { + UINT16 tag; + UINT32 hierarchy; + UINT16 digest; //Size of buffer in spec is defined to be vari= able length but for this test will always be UINT16 +} TPMT_TK_HASHCHECK; + +// TPM2_Hash command Structure as defined in Sectin 15.4 of TPM Spec Part = 3: Commands +typedef struct { + UINT16 Tag; + UINT32 CommandSize; + UINT32 CommandCode; + TPM2B_MAX_BUFFER data; + UINT16 hashAlg; + UINT32 hierarchy; +} TPM2_HASH_COMMAND; + +// TPM2_Hash Response Structure as defined in Sectin 15.4 of TPM Spec Part= 3: Commands +typedef struct { + UINT16 Tag; + UINT32 ResponseSize; + UINT32 ResponseCode; + TPM2B_DIGEST data; + TPMT_TK_HASHCHECK validation; +} TPM2_HASH_RESPONSE; +#pragma + EFI_STATUS EFIAPI BBTestTCG2ProtocolUnload ( @@ -111,6 +169,11 @@ BBTestGetEventLogConformanceTestCheckpoint2 ( IN EFI_TCG2_PROTOCOL *TCG2 ); =20 +EFI_STATUS +BBTestSubmitCommandConformanceTestCheckpoint1 ( + IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib, + IN EFI_TCG2_PROTOCOL *TCG2 + ); =20 EFI_STATUS BBTestGetCapabilityConformanceTest ( @@ -136,3 +199,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/G= uid.c b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/Guid.c index b5a4e5c7218e..87541743fb9e 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 @@ -57,3 +57,5 @@ EFI_GUID gTcg2ConformanceTestAssertionGuid013 =3D EFI_TES= T_TCG2CONFORMANCE_ASSERTI EFI_GUID gTcg2ConformanceTestAssertionGuid014 =3D EFI_TEST_TCG2CONFORMANCE= _ASSERTION_014_GUID; =20 EFI_GUID gTcg2ConformanceTestAssertionGuid015 =3D EFI_TEST_TCG2CONFORMANCE= _ASSERTION_015_GUID; + +EFI_GUID gTcg2ConformanceTestAssertionGuid016 =3D EFI_TEST_TCG2CONFORMANCE= _ASSERTION_016_GUID; 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 0f84839d0238..4bd6e34bad84 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 @@ -192,6 +192,56 @@ 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; + + // Ensure Protocol not NULL + if (TCG2 =3D=3D NULL) + return EFI_UNSUPPORTED; + + // + // 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, @@ -972,3 +1022,125 @@ BBTestGetEventLogConformanceTestCheckpoint2 ( =20 return EFI_SUCCESS; } + +// Expected SHA256 Hash for input "hello" +UINT8 Tpm2HashOut[32] =3D {0x2c,0xf2,0x4d,0xba,0x5f,0xb0,0xa3,0x0e,0x26,0x= e8,0x3b,0x2a,0xc5,0xb9,0xe2,0x9e,\ +0x1b,0x16,0x1e,0x5c,0x1f,0xa7,0x42,0x5e,0x73,0x04,0x33,0x62,0x93,0x8b,0x98= ,0x24}; + +EFI_STATUS +BBTestSubmitCommandConformanceTestCheckpoint1 ( + IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib, + IN EFI_TCG2_PROTOCOL *TCG2 + ) +{ + EFI_TEST_ASSERTION AssertionType; + EFI_STATUS Status; + TPM2_HASH_RESPONSE CommandResponse; + TPM2_HASH_COMMAND CommandInput; + char *Str =3D"hello"; + + // Build TPM2 Hash commmand to hash string "hello" + CommandInput.Tag =3D SctSwapBytes16(ST_NO_SESSIONS); + CommandInput.CommandSize =3D SctSwapBytes32(sizeof(TPM2_HASH_COMMAND)); + CommandInput.CommandCode =3D SctSwapBytes32(TPM_CC_Hash); + CommandInput.data.size =3D SctSwapBytes16(SctAsciiStrLen(Str)); + SctAsciiStrCpy(CommandInput.data.digest, Str); + CommandInput.hashAlg =3D SctSwapBytes16(TPM_ALG_SHA256); + CommandInput.hierarchy =3D SctSwapBytes32(TPM_RH_NULL); + + // allocate buffer for response + SctZeroMem(&CommandResponse, sizeof(TPM2_HASH_RESPONSE)); + + Status =3D TCG2->SubmitCommand ( + TCG2, + sizeof(TPM2_HASH_COMMAND), + &CommandInput, + sizeof(TPM2_HASH_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; + } + + // 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; + } + + // Verify SubmitCommand returns correct Response Code + 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; + } + + + // Verify SubmitCommand returns correct Response Size + if (SctSwapBytes32(CommandResponse.ResponseSize) !=3D sizeof(TPM2_HASH_R= ESPONSE)) { + 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 the size of the buffer returned is size of SHA256 hash + if (SctSwapBytes16(CommandResponse.data.size) !=3D 32) { + StandardLib->RecordMessage ( + StandardLib, + EFI_VERBOSE_LEVEL_DEFAULT, + L"\r\nTCG2 Protocol SubmitCommand Test: SubmitCommand= should return correct size digest for SHA256, Size =3D %x", + SctSwapBytes16(CommandResponse.data.size) + ); + + AssertionType =3D EFI_TEST_ASSERTION_FAILED; + } + + // Ensure Hash returned matches expected response for input + if (0 !=3D SctCompareMem(Tpm2HashOut, CommandResponse.data.digest, SHA25= 6_LENGTH) ) { + StandardLib->RecordMessage ( + StandardLib, + EFI_VERBOSE_LEVEL_DEFAULT, L"\r\nTC= G2 Protocol SubmitCommand Test: SubmitCommand should return expected Hash f= or data that was hashed." + ); + + AssertionType =3D EFI_TEST_ASSERTION_FAILED; + } + + StandardLib->RecordAssertion ( + StandardLib, + AssertionType, + gTcg2ConformanceTestAssertionGuid016, + L"EFI_TCG2_PROTOCOL. SubmitComand() - SubmitCommand() sha= ll populate the response buffer and return with a status of EFI_SUCCESS whe= n valid command parameters are passed in.", + 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..48a8a450e955 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,15 @@ 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.25.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 (#86462): https://edk2.groups.io/g/devel/message/86462 Mute This Topic: https://groups.io/mt/89012621/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-