From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 847477803DB for ; Tue, 9 Jan 2024 18:21:11 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=E+JdYEntmQ6B3T437AOxXo0eZ6ki9jJJxx3DURRIi48=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1704824470; v=1; b=vaon8RcX+540pNGTYM9IKT3Q0l5I2/TxAbfBDB3Hd8dfbaXOo3FbiNwzkk8Ya8hTrlPxwIBJ F5eHIK1BRfIZ2pkglj7JZbyuSy1DhHl+CjiwI907aN8qgyC3g5xPYhTvUH6oXLXCHjDNSlFrt5y S5i+E9xZyBiq72DckQYEolEo= X-Received: by 127.0.0.2 with SMTP id J8gIYY7687511xwjsphhrj5P; Tue, 09 Jan 2024 10:21:10 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.24573.1704824465918812898 for ; Tue, 09 Jan 2024 10:21:06 -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 CDB911576; Tue, 9 Jan 2024 10:21:50 -0800 (PST) X-Received: from beelzebub.ast.arm.com (unknown [10.118.29.240]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 352003F5A1; Tue, 9 Jan 2024 10:21:05 -0800 (PST) From: "Stuart Yoder" To: devel@edk2.groups.io, Edhaya.Chandran@arm.com, gaojie@byosoft.com.cn Cc: ilias.apalodimas@linaro.org, heinrich.schuchardt@canonical.com, Samer.El-Haj-Mahmoud@arm.com, Jiewen.Yao@intel.com Subject: [edk2-devel] [PATCH v2 6/6] uefi-sct/SctPkg: TCG2 Protocol: add SubmitCommand test Date: Tue, 9 Jan 2024 12:20:53 -0600 Message-Id: <20240109182053.2540542-7-stuart.yoder@arm.com> In-Reply-To: <20240109182053.2540542-1-stuart.yoder@arm.com> References: <20240109182053.2540542-1-stuart.yoder@arm.com> MIME-Version: 1.0 Precedence: Bulk 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,stuart.yoder@arm.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: rjdlawhr1NP71DAqYcDm1ZDKx7686176AA= Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=vaon8RcX; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=arm.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io From: Joseph Hemann Add test verifying the functionality of the SubmitCommand function using the TPM command TPM2_HASH_COMMAND. Signed-off-by: Joseph Hemann Signed-off-by: Stuart Yoder --- uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/Guid.h = | 5 + uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/TCG2ProtocolB= BTest.h | 71 ++++++++ uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/Guid.c = | 2 + uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/TCG2ProtocolB= BTestConformance.c | 173 ++++++++++++++++++++ uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/TCG2ProtocolB= BTestMain.c | 9 + 5 files changed, 260 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 746ff83f899c..044e549ce8f0 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 @@ -105,3 +105,8 @@ extern EFI_GUID gTcg2ConformanceTestAssertionGuid015; { 0x126a789a, 0x1932, 0x3234, {0x21, 0xab, 0x42, 0x64, 0x8a, 0x7b, 0x63, 0= x76 }}=0D =0D extern EFI_GUID gTcg2ConformanceTestAssertionGuid016;=0D +=0D +#define EFI_TEST_TCG2CONFORMANCE_ASSERTION_017_GUID \=0D +{ 0x3aac8b9a, 0x312a, 0x4dcf, {0x12, 0x76, 0x54, 0x55, 0x32, 0xcd, 0x3a, 0= xea }}=0D +=0D +extern EFI_GUID gTcg2ConformanceTestAssertionGuid017;=0D 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 5ce275dc6258..f8880599f150 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 @@ -54,6 +54,64 @@ Abstract: =0D #define PE_COFF_IMAGE 0x0000000000000010=0D =0D +// ST_NO_SESSION as defined in Table 19 of TPM Library Part 2: Structures= =0D +#define ST_NO_SESSIONS (UINT16) 0x8001=0D +=0D +// TPM_RC_SUCCESS as defined in Table 16 of TPM Library Spec Part 2: Struc= tures=0D +#define TPM_RC_SUCCESS (UINT32) 0x0000000=0D +=0D +// TPM_CC_Hash as defined in Table 12 of TPM Library Spec Part 2: Structur= es=0D +#define TPM_CC_Hash (UINT32)(0x0000017D)=0D +=0D +#define TPM_RH_NULL (UINT32) 0x40000007=0D +=0D +#define TPM_ALG_SHA256 (UINT16) 0x000B=0D +=0D +#define SHA256_LENGTH (UINT16) 0x0020=0D +=0D +#pragma pack(1)=0D +// TPM2B_MAX_BUFFER as defined in Table 86 of TPM Library Spec Part 2: Str= uctures=0D +// Size of buffer in spec is variable length, but hash test will always us= e a fixed length string=0D +// of length 43=0D +#define TEST_STRING_LEN 43=0D +typedef struct {=0D + UINT16 size;=0D + UINT8 buffer[TEST_STRING_LEN];=0D +} TPM2B_MAX_BUFFER;=0D +=0D +#pragma pack(1)=0D +// TPM2B_DIGEST as defined in Table 73 of TPM Library Spec Part 2: Structu= res=0D +typedef struct {=0D + UINT16 size;=0D + UINT8 digest[32]; // Size of buffer in spec is defined to be variable = length but for this test will always be 32=0D +} TPM2B_DIGEST;=0D +=0D +typedef struct {=0D + UINT16 tag;=0D + UINT32 hierarchy;=0D + UINT16 digest; // Size of buffer in spec is defined to be var= iable length but for this test will always be UINT16=0D +} TPMT_TK_HASHCHECK;=0D +=0D +// TPM2_Hash command Structure as defined in Section 15.4 of TPM Spec Part= 3: Commands=0D +typedef struct {=0D + UINT16 Tag;=0D + UINT32 CommandSize;=0D + UINT32 CommandCode;=0D + TPM2B_MAX_BUFFER data;=0D + UINT16 hashAlg;=0D + UINT32 hierarchy;=0D +} TPM2_HASH_COMMAND;=0D +=0D +// TPM2_Hash Response Structure as defined in Section 15.4 of TPM Spec Par= t 3: Commands=0D +typedef struct {=0D + UINT16 Tag;=0D + UINT32 ResponseSize;=0D + UINT32 ResponseCode;=0D + TPM2B_DIGEST data;=0D + TPMT_TK_HASHCHECK validation;=0D +} TPM2_HASH_RESPONSE;=0D +#pragma=0D +=0D EFI_STATUS=0D EFIAPI=0D BBTestTCG2ProtocolUnload (=0D @@ -120,6 +178,12 @@ BBTestGetEventLogConformanceTestCheckpoint2 ( IN EFI_TCG2_PROTOCOL *TCG2=0D );=0D =0D +EFI_STATUS=0D +BBTestSubmitCommandConformanceTestCheckpoint1 (=0D + IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib,=0D + IN EFI_TCG2_PROTOCOL *TCG2=0D + );=0D +=0D EFI_STATUS=0D BBTestGetCapabilityConformanceTest (=0D IN EFI_BB_TEST_PROTOCOL *This,=0D @@ -144,3 +208,10 @@ BBTestHashLogExtendEventConformanceTest ( IN EFI_HANDLE SupportHandle=0D );=0D =0D +EFI_STATUS=0D +BBTestSubmitCommandConformanceTest (=0D + IN EFI_BB_TEST_PROTOCOL *This,=0D + IN VOID *ClientInterface,=0D + IN EFI_TEST_LEVEL TestLevel,=0D + IN EFI_HANDLE SupportHandle=0D + );=0D 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 8c528aa8ddfc..9aa5315e670e 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 @@ -59,3 +59,5 @@ EFI_GUID gTcg2ConformanceTestAssertionGuid014 =3D EFI_TES= T_TCG2CONFORMANCE_ASSERTI EFI_GUID gTcg2ConformanceTestAssertionGuid015 =3D EFI_TEST_TCG2CONFORMANCE= _ASSERTION_015_GUID;=0D =0D EFI_GUID gTcg2ConformanceTestAssertionGuid016 =3D EFI_TEST_TCG2CONFORMANCE= _ASSERTION_016_GUID;=0D +=0D +EFI_GUID gTcg2ConformanceTestAssertionGuid017 =3D EFI_TEST_TCG2CONFORMANCE= _ASSERTION_017_GUID;=0D 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 ebe04d42aff5..5abf8e7934cf 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 @@ -197,6 +197,56 @@ BBTestHashLogExtendEventConformanceTest ( return EFI_SUCCESS;=0D }=0D =0D +/**=0D + * @brief Entrypoint for SubmitCommand() Function Test.=0D + * 1 checkpoint will be tested.=0D + * @param This a pointer of EFI_BB_TEST_PROTOCOL=0D + * @param ClientInterface A pointer to the interface array under test=0D + * @param TestLevel Test "thoroughness" control=0D + * @param SupportHandle A handle containing protocols required=0D + * @return EFI_SUCCESS=0D + * @return EFI_NOT_FOUND=0D + */=0D +=0D +EFI_STATUS=0D +BBTestSubmitCommandConformanceTest (=0D + IN EFI_BB_TEST_PROTOCOL *This,=0D + IN VOID *ClientInterface,=0D + IN EFI_TEST_LEVEL TestLevel,=0D + IN EFI_HANDLE SupportHandle=0D + )=0D +{=0D + EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib;=0D + EFI_STATUS Status;=0D + EFI_TCG2_PROTOCOL *TCG2;=0D +=0D + //=0D + // init=0D + //=0D + TCG2 =3D (EFI_TCG2_PROTOCOL*)ClientInterface;=0D +=0D + // Ensure Protocol not NULL=0D + if (TCG2 =3D=3D NULL)=0D + return EFI_UNSUPPORTED;=0D +=0D + //=0D + // Get the Standard Library Interface=0D + //=0D + Status =3D gtBS->HandleProtocol (=0D + SupportHandle,=0D + &gEfiStandardTestLibraryGuid,=0D + (VOID **) &StandardLib=0D + );=0D + if (EFI_ERROR(Status)) {=0D + return Status;=0D + }=0D +=0D + // Test GetRandom TPM Command=0D + BBTestSubmitCommandConformanceTestCheckpoint1 (StandardLib, TCG2);=0D +=0D + return EFI_SUCCESS;=0D +}=0D +=0D EFI_STATUS=0D BBTestGetCapabilityConformanceTestCheckpoint1 (=0D IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib,=0D @@ -1006,3 +1056,126 @@ BBTestGetEventLogConformanceTestCheckpoint2 ( =0D return EFI_SUCCESS;=0D }=0D +=0D +// Expected SHA256 Hash of the string "The quick brown fox jumps over the= lazy dog"=0D +UINT8 Tpm2HashOut[32] =3D {0xd7,0xa8,0xfb,0xb3,0x07,0xd7,0x80,0x94,0x69,0x= ca,0x9a,0xbc,0xb0,0x08,0x2e,0x4f, \=0D +0x8d,0x56,0x51,0xe4,0x6d,0x3c,0xdb,0x76,0x2d,0x02,0xd0,0xbf,0x37,0xc9,0xe5= ,0x92};=0D +=0D +EFI_STATUS=0D +BBTestSubmitCommandConformanceTestCheckpoint1 (=0D + IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib,=0D + IN EFI_TCG2_PROTOCOL *TCG2=0D + )=0D +{=0D + EFI_TEST_ASSERTION AssertionType;=0D + EFI_STATUS Status;=0D + TPM2_HASH_RESPONSE CommandResponse;=0D + TPM2_HASH_COMMAND CommandInput;=0D + CHAR8 *Str =3D"The quick brown fox jumps over the lazy dog";=0D +=0D + // Build TPM2 Hash command to hash test string=0D + CommandInput.Tag =3D SctSwapBytes16(ST_NO_SESSIONS);=0D + CommandInput.CommandSize =3D SctSwapBytes32(sizeof(TPM2_HASH_COMMAND));= =0D + CommandInput.CommandCode =3D SctSwapBytes32(TPM_CC_Hash);=0D + CommandInput.data.size =3D SctSwapBytes16(SctAsciiStrLen(Str));=0D + SctAsciiStrCpy((CHAR8 *)CommandInput.data.buffer, Str);=0D + CommandInput.hashAlg =3D SctSwapBytes16(TPM_ALG_SHA256);=0D + CommandInput.hierarchy =3D SctSwapBytes32(TPM_RH_NULL);=0D +=0D + // allocate buffer for response=0D + SctZeroMem(&CommandResponse, sizeof(TPM2_HASH_RESPONSE));=0D +=0D + Status =3D TCG2->SubmitCommand (=0D + TCG2,=0D + sizeof(TPM2_HASH_COMMAND),=0D + (UINT8 *)&CommandInput,=0D + sizeof(TPM2_HASH_RESPONSE),=0D + (UINT8 *)&CommandResponse);=0D +=0D +=0D + AssertionType =3D EFI_TEST_ASSERTION_PASSED;=0D +=0D + // Verify SubmitCommand returns EFI_SUCCESS=0D + if (Status !=3D EFI_SUCCESS) {=0D + StandardLib->RecordMessage (=0D + StandardLib,=0D + EFI_VERBOSE_LEVEL_DEFAULT,=0D + L"\r\nTCG2 Protocol SubmitCommand Test: SubmitCommand= should return EFI_SUCCESS, Status =3D %r",=0D + Status=0D + );=0D +=0D + AssertionType =3D EFI_TEST_ASSERTION_FAILED;=0D + }=0D +=0D + // Verify SubmitCommand returns correct Response Tag=0D + if (SctSwapBytes16(CommandResponse.Tag) !=3D ST_NO_SESSIONS) {=0D + StandardLib->RecordMessage (=0D + StandardLib,=0D + EFI_VERBOSE_LEVEL_DEFAULT,=0D + L"\r\nTCG2 Protocol SubmitCommand Test: SubmitCommand= should return ST_NO_SESSIONS response Tag"=0D + );=0D +=0D + AssertionType =3D EFI_TEST_ASSERTION_FAILED;=0D + }=0D +=0D + // Verify SubmitCommand returns correct Response Code=0D + if (SctSwapBytes32(CommandResponse.ResponseCode) !=3D TPM_RC_SUCCESS) {= =0D + StandardLib->RecordMessage (=0D + StandardLib,=0D + EFI_VERBOSE_LEVEL_DEFAULT,=0D + L"\r\nTCG2 Protocol SubmitCommand Test: SubmitCommand= should return Correct ResponseCode, ResponseCode =3D %x",=0D + SctSwapBytes32(CommandResponse.ResponseCode)=0D + );=0D +=0D + AssertionType =3D EFI_TEST_ASSERTION_FAILED;=0D + }=0D +=0D +=0D + // Verify SubmitCommand returns correct Response Size=0D + if (SctSwapBytes32(CommandResponse.ResponseSize) !=3D sizeof(TPM2_HASH_R= ESPONSE)) {=0D + StandardLib->RecordMessage (=0D + StandardLib,=0D + EFI_VERBOSE_LEVEL_DEFAULT,=0D + L"\r\nTCG2 Protocol SubmitCommand Test: SubmitCommand= should return Correct ResponseSize, Size =3D %x",=0D + SctSwapBytes32(CommandResponse.ResponseSize)=0D + );=0D +=0D + AssertionType =3D EFI_TEST_ASSERTION_FAILED;=0D + }=0D +=0D + // Check that the size of the buffer returned is size of SHA256 hash=0D + if (SctSwapBytes16(CommandResponse.data.size) !=3D 32) {=0D + StandardLib->RecordMessage (=0D + StandardLib,=0D + EFI_VERBOSE_LEVEL_DEFAULT,=0D + L"\r\nTCG2 Protocol SubmitCommand Test: SubmitCommand= should return correct size digest for SHA256, Size =3D %x",=0D + SctSwapBytes16(CommandResponse.data.size)=0D + );=0D +=0D + AssertionType =3D EFI_TEST_ASSERTION_FAILED;=0D + }=0D +=0D + // Ensure Hash returned matches expected response for input=0D + if (0 !=3D SctCompareMem(Tpm2HashOut, CommandResponse.data.digest, SHA25= 6_LENGTH) ) {=0D + StandardLib->RecordMessage (=0D + StandardLib,=0D + EFI_VERBOSE_LEVEL_DEFAULT,=0D + L"\r\nTCG2 Protocol SubmitCommand Test: SubmitCommand s= hould return expected Hash for data that was hashed."=0D + );=0D +=0D + AssertionType =3D EFI_TEST_ASSERTION_FAILED;=0D + }=0D +=0D + StandardLib->RecordAssertion (=0D + StandardLib,=0D + AssertionType,=0D + gTcg2ConformanceTestAssertionGuid017,=0D + 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.",=0D + L"%a:%d: Status - %r",=0D + __FILE__,=0D + (UINTN)__LINE__,=0D + Status=0D + );=0D +=0D + return EFI_SUCCESS;=0D +}=0D 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 f7b9e487eda2..25c3eab2cccd 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,=0D BBTestHashLogExtendEventConformanceTest=0D },=0D + {=0D + EFI_TCG2_PROTOCOL_TEST_ENTRY_GUID0104,=0D + L"SubmitCommand_Conf",=0D + L"Test the SubmitCommmand API",=0D + EFI_TEST_LEVEL_DEFAULT,=0D + gSupportProtocolGuid1,=0D + EFI_TEST_CASE_AUTO,=0D + BBTestSubmitCommandConformanceTest=0D + },=0D 0=0D };=0D =0D --=20 2.34.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#113492): https://edk2.groups.io/g/devel/message/113492 Mute This Topic: https://groups.io/mt/103625307/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-