[edk2-devel] [PATCH V3 6/6] uefi-sct/SctPkg: TCG2 Protocol: add SubmitCommand test
Joseph Hemann
joseph.hemann at arm.com
Wed Feb 9 01:33:06 UTC 2022
-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 <Edhaya.Chandran at arm.com>
Cc: Barton Gao <gaojie at byosoft.com.cn>
Cc: Carolyn Gjertsen <Carolyn.Gjertsen at amd.com>
Cc: Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud at arm.com>
Cc: Eric Jin <eric.jin at intel.com>
Cc: Arvin Chen <arvinx.chen at intel.com>
Cc: Supreeth Venkatesh <Supreeth.Venkatesh at amd.com>
Cc: Stuart Yoder <Stuart.Yoder at arm.com>
Signed-off-by: Joseph Hemann <Joseph.hemann at arm.com>
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/Guid.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, 0x13 }}
extern EFI_GUID gTcg2ConformanceTestAssertionGuid015;
+
+#define EFI_TEST_TCG2CONFORMANCE_ASSERTION_016_GUID \
+{ 0x1689bc3a, 0x2298, 0xa116, {0x28, 0x4c, 0xc1, 0xdd, 0xaa, 0xd8, 0xef, 0x51 }}
+
+extern EFI_GUID gTcg2ConformanceTestAssertionGuid016;
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 d9c2309462d7..c8684f7915a6 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
@@ -43,6 +43,9 @@ Abstract:
#define EFI_TCG2_PROTOCOL_TEST_ENTRY_GUID0103 \
{0x907a7878, 0xb294, 0xf147, {0xe9, 0x0a, 0x65, 0x43, 0xab, 0x55, 0x76, 0x46} }
+#define EFI_TCG2_PROTOCOL_TEST_ENTRY_GUID0104 \
+ {0x9087ad78, 0x9ad2, 0x4172, {0x9a, 0xbc, 0x98, 0x23, 0x08, 0xf5, 0x6d, 0x26} }
+
#define EV_POST_CODE 0x01
#define EV_NO_ACTION 0x03
@@ -51,6 +54,61 @@ Abstract:
#define PE_COFF_IMAGE 0x0000000000000010
+// 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: Structures
+#define TPM_RC_SUCCESS (UINT32) 0x0000000
+
+// TPM_CC_Hash as definied in Table 12 of TPM Library Spec Part 2: Structures
+#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: Structures
+typedef struct {
+ UINT16 size;
+ UINT8 digest[5]; // Size of buffer in spec is defined to be variable length 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: Structures
+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 variable 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
);
+EFI_STATUS
+BBTestSubmitCommandConformanceTestCheckpoint1 (
+ IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib,
+ IN EFI_TCG2_PROTOCOL *TCG2
+ );
EFI_STATUS
BBTestGetCapabilityConformanceTest (
@@ -136,3 +199,10 @@ BBTestHashLogExtendEventConformanceTest (
IN EFI_HANDLE SupportHandle
);
+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/Guid.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 = EFI_TEST_TCG2CONFORMANCE_ASSERTI
EFI_GUID gTcg2ConformanceTestAssertionGuid014 = EFI_TEST_TCG2CONFORMANCE_ASSERTION_014_GUID;
EFI_GUID gTcg2ConformanceTestAssertionGuid015 = EFI_TEST_TCG2CONFORMANCE_ASSERTION_015_GUID;
+
+EFI_GUID gTcg2ConformanceTestAssertionGuid016 = EFI_TEST_TCG2CONFORMANCE_ASSERTION_016_GUID;
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 0f84839d0238..4bd6e34bad84 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
@@ -192,6 +192,56 @@ BBTestHashLogExtendEventConformanceTest (
return EFI_SUCCESS;
}
+/**
+ * @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 = (EFI_TCG2_PROTOCOL*)ClientInterface;
+
+ // Ensure Protocol not NULL
+ if (TCG2 == NULL)
+ return EFI_UNSUPPORTED;
+
+ //
+ // Get the Standard Library Interface
+ //
+ Status = 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 (
return EFI_SUCCESS;
}
+
+// Expected SHA256 Hash for input "hello"
+UINT8 Tpm2HashOut[32] = {0x2c,0xf2,0x4d,0xba,0x5f,0xb0,0xa3,0x0e,0x26,0xe8,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 ="hello";
+
+ // Build TPM2 Hash commmand to hash string "hello"
+ CommandInput.Tag = SctSwapBytes16(ST_NO_SESSIONS);
+ CommandInput.CommandSize = SctSwapBytes32(sizeof(TPM2_HASH_COMMAND));
+ CommandInput.CommandCode = SctSwapBytes32(TPM_CC_Hash);
+ CommandInput.data.size = SctSwapBytes16(SctAsciiStrLen(Str));
+ SctAsciiStrCpy(CommandInput.data.digest, Str);
+ CommandInput.hashAlg = SctSwapBytes16(TPM_ALG_SHA256);
+ CommandInput.hierarchy = SctSwapBytes32(TPM_RH_NULL);
+
+ // allocate buffer for response
+ SctZeroMem(&CommandResponse, sizeof(TPM2_HASH_RESPONSE));
+
+ Status = TCG2->SubmitCommand (
+ TCG2,
+ sizeof(TPM2_HASH_COMMAND),
+ &CommandInput,
+ sizeof(TPM2_HASH_RESPONSE),
+ &CommandResponse);
+
+
+ AssertionType = EFI_TEST_ASSERTION_PASSED;
+
+ // Verify SubmitCommand returns EFI_SUCCESS
+ if (Status != EFI_SUCCESS) {
+ StandardLib->RecordMessage (
+ StandardLib,
+ EFI_VERBOSE_LEVEL_DEFAULT,
+ L"\r\nTCG2 Protocol SubmitCommand Test: SubmitCommand should return EFI_SUCCESS, Status = %r",
+ Status
+ );
+
+ AssertionType = EFI_TEST_ASSERTION_FAILED;
+ }
+
+ // Verify SubmitCommand returns correct Response Tag
+ if (SctSwapBytes16(CommandResponse.Tag) != 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 = EFI_TEST_ASSERTION_FAILED;
+ }
+
+ // Verify SubmitCommand returns correct Response Code
+ if (SctSwapBytes32(CommandResponse.ResponseCode) != TPM_RC_SUCCESS) {
+ StandardLib->RecordMessage (
+ StandardLib,
+ EFI_VERBOSE_LEVEL_DEFAULT,
+ L"\r\nTCG2 Protocol SubmitCommand Test: SubmitCommand should return Correct ResponseCode, ResponseCode = %x",
+ SctSwapBytes32(CommandResponse.ResponseCode)
+ );
+
+ AssertionType = EFI_TEST_ASSERTION_FAILED;
+ }
+
+
+ // Verify SubmitCommand returns correct Response Size
+ if (SctSwapBytes32(CommandResponse.ResponseSize) != sizeof(TPM2_HASH_RESPONSE)) {
+ StandardLib->RecordMessage (
+ StandardLib,
+ EFI_VERBOSE_LEVEL_DEFAULT,
+ L"\r\nTCG2 Protocol SubmitCommand Test: SubmitCommand should return Correct ResponseSize, Size = %x",
+ SctSwapBytes32(CommandResponse.ResponseSize)
+ );
+
+ AssertionType = EFI_TEST_ASSERTION_FAILED;
+ }
+
+ // Check that the size of the buffer returned is size of SHA256 hash
+ if (SctSwapBytes16(CommandResponse.data.size) != 32) {
+ StandardLib->RecordMessage (
+ StandardLib,
+ EFI_VERBOSE_LEVEL_DEFAULT,
+ L"\r\nTCG2 Protocol SubmitCommand Test: SubmitCommand should return correct size digest for SHA256, Size = %x",
+ SctSwapBytes16(CommandResponse.data.size)
+ );
+
+ AssertionType = EFI_TEST_ASSERTION_FAILED;
+ }
+
+ // Ensure Hash returned matches expected response for input
+ if (0 != SctCompareMem(Tpm2HashOut, CommandResponse.data.digest, SHA256_LENGTH) ) {
+ StandardLib->RecordMessage (
+ StandardLib,
+ EFI_VERBOSE_LEVEL_DEFAULT,
L"\r\nTCG2 Protocol SubmitCommand Test: SubmitCommand should return expected Hash for data that was hashed."
+ );
+
+ AssertionType = EFI_TEST_ASSERTION_FAILED;
+ }
+
+ StandardLib->RecordAssertion (
+ StandardLib,
+ AssertionType,
+ gTcg2ConformanceTestAssertionGuid016,
+ L"EFI_TCG2_PROTOCOL. SubmitComand() - SubmitCommand() shall populate the response buffer and return with a status of EFI_SUCCESS when 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/TCG2ProtocolBBTestMain.c b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/TCG2ProtocolBBTestMain.c
index 892fce2691c1..48a8a450e955 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
@@ -65,6 +65,15 @@ EFI_BB_TEST_ENTRY_FIELD gBBTestEntryField[] = {
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
};
--
2.25.1
-=-=-=-=-=-=-=-=-=-=-=-
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/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-
More information about the edk2-devel-archive
mailing list