From nobody Mon Feb 9 09:52: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+82152+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+82152+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1634314634; cv=none; d=zohomail.com; s=zohoarc; b=M4MmprukYf7zEQk/ck7dtc5HsjAYuRHxRO1FCv4zRM+gbUs6Iy1C9/dNAWNW1UVADOKYoVUnlHvByunQwjATtUxCdM3P/UDJY8oJ1RoBmukJd8xifxTl1znI1IkINYy2iZhQh8SPmETfVI4SDne7a3yFh4zTAbvD7UAimPwHpao= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1634314634; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=iqzg3sFCcm6Lq7ccLV8Yac4eabVHuW/c2qRLx3IEWuo=; b=HTHtW7fgN+6PCQUJLoCKRc2Xi2iNHZS6nZJy2+BxAO+FTpPRoUySzPdtBNj2jifrm+raeLvE0tnrQmuTFR27gGF0vymnRUkyyCoMGUZsfcpxPWBmV9mjh1JXQY0xlgG9InMxEOduEF9Fqv4dxCXh2T239QddY0jVvJgk8I2B7FU= 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+82152+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 1634314634483702.3110006917358; Fri, 15 Oct 2021 09:17:14 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id h2rpYY1788612xWRxmDGo07I; Fri, 15 Oct 2021 09:17:14 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.66.1634314632763374656 for ; Fri, 15 Oct 2021 09:17:13 -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 777BE14BF; Fri, 15 Oct 2021 09:17:12 -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 6EFA23F66F; Fri, 15 Oct 2021 09:17:12 -0700 (PDT) From: "Joseph Hemann" To: devel@edk2.groups.io Cc: nd@arm.com, Joseph Hemann Subject: [edk2-devel] [PATCH 6/6] uefi-sct/SctPkg: TCG2 Protocol: add SubmitCommand test Date: Fri, 15 Oct 2021 11:17:06 -0500 Message-Id: <20211015161706.23885-7-joseph.hemann@arm.com> In-Reply-To: <20211015161706.23885-1-joseph.hemann@arm.com> References: <20211015161706.23885-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: MDFNfsNFAIgEw0AaklnN3PoTx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634314634; bh=OBnldCgVGksiShQReLEVnA0T35VK0o/DYlf0P4r5mKU=; h=Cc:Date:From:Reply-To:Subject:To; b=Q6ep6BqT1ScC/k/j6GC8p2la0UIjkTBJlOYiYF4lV9bte86wwUFG+UDrz3LVy6UWbZm UfS1AtWcUhBhlM5BzJXXK74gjOFUS3TViNRK5sxMSNTjB0SBS1sAwkZU7D6iOLusFcy8l 0dgqkNZTx1eRMRNbSjd5YUDNk9oKXDIAZLg= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634314635024100020 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 Signed-off-by: Joseph Hemann Change-Id: I364001c915b9d8d8b79eb4381d828400a1ef72a0 --- .../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 89c41517..b5a4e5c7 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 2cb71510..ccc5a4be 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 69fb3589..0fdf753f 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 a3477ec9..9386d193 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 892fce26..419e2a3e 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 (#82152): https://edk2.groups.io/g/devel/message/82152 Mute This Topic: https://groups.io/mt/86343165/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-