[edk2-devel] [PATCH V3 5/6] uefi-sct/SctPkg: TCG2 Protocol: add GetEventLog test

Joseph Hemann joseph.hemann at arm.com
Wed Feb 9 01:33:05 UTC 2022


-add initial TCG2 protocol test for GetEventLog()
  -checkpoint for test function with invalid eventlog format
  -checkpoint for test function with valid eventlog format

V2:
-Change checkpoint names from HashLogExtendEvent to GetEventLog

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: I5ca3a46b3d36e8f11848a788f6cfdcabeb5b04c8
---
 .../SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/Guid.h  |  20 +++
 .../UEFI/EFI/Protocol/TCG2/BlackBoxTest/TCG2ProtocolBBTest.h    |  15 ++
 uefi-sct/SctPkg/UEFI/Protocol/TCG2.h                            |  46 +++++++
 .../SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/Guid.c  |   8 ++
 .../Protocol/TCG2/BlackBoxTest/TCG2ProtocolBBTestConformance.c  | 204 +++++++++++++++++++++++++++-
 5 files changed, 292 insertions(+), 1 deletion(-)

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 45c2b2b22282..d3a18aeebf09 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
@@ -80,3 +80,23 @@ extern EFI_GUID gTcg2ConformanceTestAssertionGuid010;
 { 0x9cd6d636, 0x603a, 0x4b78, {0x80, 0xa3, 0xa3, 0xb9, 0xcc, 0x6a, 0x0b, 0x08 }}
 
 extern EFI_GUID gTcg2ConformanceTestAssertionGuid011;
+
+#define EFI_TEST_TCG2CONFORMANCE_ASSERTION_012_GUID \
+{ 0x0a938567, 0xb234, 0xad21, {0x2a, 0xa6, 0x11, 0x65, 0xaa, 0xde, 0x12, 0xc2 }}
+
+extern EFI_GUID gTcg2ConformanceTestAssertionGuid012;
+
+#define EFI_TEST_TCG2CONFORMANCE_ASSERTION_013_GUID \
+{ 0x45fa1a42, 0x912a, 0x5124, {0x84, 0xf4, 0x41, 0x67, 0xab, 0xb5, 0x89, 0x90 }}
+
+extern EFI_GUID gTcg2ConformanceTestAssertionGuid013;
+
+#define EFI_TEST_TCG2CONFORMANCE_ASSERTION_014_GUID \
+{ 0xfc80408e, 0x9a3c, 0x4054, {0x96, 0xf9, 0x31, 0x23, 0x35, 0xc2, 0x31, 0x35 }}
+
+extern EFI_GUID gTcg2ConformanceTestAssertionGuid014;
+
+#define EFI_TEST_TCG2CONFORMANCE_ASSERTION_015_GUID \
+{ 0xa76d2903, 0xbbcc, 0x8a72, {0x90, 0x23, 0xd3, 0xaa, 0xba, 0xb1, 0x52, 0x13 }}

+
+extern EFI_GUID gTcg2ConformanceTestAssertionGuid015;
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 1b56852eea1f..d9c2309462d7 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
@@ -45,6 +45,8 @@ Abstract:
 
 #define EV_POST_CODE 0x01
 
+#define EV_NO_ACTION 0x03

+
 #define EFI_TCG2_EXTEND_ONLY 0x0000000000000001
 
 #define PE_COFF_IMAGE 0x0000000000000010
@@ -97,6 +99,19 @@ BBTestHashLogExtendEventConformanceTestCheckpoint2 (
   IN EFI_TCG2_PROTOCOL                     *TCG2
   );
 
+EFI_STATUS

+BBTestGetEventLogConformanceTestCheckpoint1 (

+  IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL    *StandardLib,

+  IN EFI_TCG2_PROTOCOL                     *TCG2

+  );

+

+EFI_STATUS

+BBTestGetEventLogConformanceTestCheckpoint2 (

+  IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL    *StandardLib,

+  IN EFI_TCG2_PROTOCOL                     *TCG2

+  );

+

+
 EFI_STATUS
 BBTestGetCapabilityConformanceTest (
   IN EFI_BB_TEST_PROTOCOL       *This,
diff --git a/uefi-sct/SctPkg/UEFI/Protocol/TCG2.h b/uefi-sct/SctPkg/UEFI/Protocol/TCG2.h
index 923549e2e96b..ac66fa0e107d 100644
--- a/uefi-sct/SctPkg/UEFI/Protocol/TCG2.h
+++ b/uefi-sct/SctPkg/UEFI/Protocol/TCG2.h
@@ -50,6 +50,8 @@ Abstract:
 
 #define EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 0x00000002
 
+#define HASH_NUMBER 0x04
+
 typedef struct _EFI_TCG2_PROTOCOL EFI_TCG2_PROTOCOL;
 
 typedef UINT64 EFI_PHYSICAL_ADDRESS;
@@ -114,6 +116,50 @@ typedef struct tdEFI_TCG2_EVENT {
   UINT8 Event[];
 } EFI_TCG2_EVENT;
 
+typedef struct {
+  UINT16     hashAlg;
+  UINT8      digest[];
+} TPMT_HA;
+
+typedef struct tdTPML_DIGEST_VALUES {
+  UINT32 Count;                    // number of digests
+  TPMT_HA Digests[HASH_NUMBER];    // Count digests
+} TPML_DIGEST_VALUES;
+
+// This Declaration is for parsing the eventlog header which is defined to be 20 bytes in TCG EFI Protocol Spec
+typedef UINT8 TCG_DIGEST[20];
+
+typedef struct tdTCG_PCR_EVENT2 {
+  TCG_PCRINDEX PCRIndex;       // PCRIndex event extended to
+  TCG_EVENTTYPE EventType;     // Type of event (see [2])
+  TPML_DIGEST_VALUES Digests;  // List of digests extended to //PCRIndex
+  UINT32 EventSize;            // Size of the event data
+  UINT8 *Event;                // The event data
+} TCG_PCR_EVENT2;
+
+typedef struct tdTCG_PCR_EVENT {
+  UINT32 PCRIndex; // PCRIndex event extended to
+  UINT32 EventType; // Type of event (see EFI specs)
+  TCG_DIGEST Digest; // Value extended into PCRIndex
+  UINT32 EventSize; // Size of the event data
+  UINT8 Event[0]; // The event data
+} TCG_PCR_EVENT;
+// Structure to be added to the Event Log
+
+typedef struct tdTCG_EfiSpecIdEventAlgorithmSize {
+  UINT16 algorithmId;
+  UINT16 digestSize;
+} TCG_EfiSpecIdEventAlgorithmSize;
+
+typedef struct tdTCG_EfiSpecIdEventStruct {
+   UINT8 signature[16];
+   UINT32 platformClass;
+   UINT8 specVersionMinor;
+   UINT8 specVersionMajor;
+   UINT8 specErrata;
+   UINT8 uintnSize;
+} TCG_EfiSpecIDEventStruct;
+
 typedef
 EFI_STATUS
 (EFIAPI * EFI_TCG2_HASH_LOG_EXTEND_EVENT) (
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 ed013744e209..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
@@ -49,3 +49,11 @@ EFI_GUID gTcg2ConformanceTestAssertionGuid009 = EFI_TEST_TCG2CONFORMANCE_ASSERTI
 EFI_GUID gTcg2ConformanceTestAssertionGuid010 = EFI_TEST_TCG2CONFORMANCE_ASSERTION_010_GUID;
 
 EFI_GUID gTcg2ConformanceTestAssertionGuid011 = EFI_TEST_TCG2CONFORMANCE_ASSERTION_011_GUID;
+
+EFI_GUID gTcg2ConformanceTestAssertionGuid012 = EFI_TEST_TCG2CONFORMANCE_ASSERTION_012_GUID;
+
+EFI_GUID gTcg2ConformanceTestAssertionGuid013 = EFI_TEST_TCG2CONFORMANCE_ASSERTION_013_GUID;
+
+EFI_GUID gTcg2ConformanceTestAssertionGuid014 = EFI_TEST_TCG2CONFORMANCE_ASSERTION_014_GUID;
+
+EFI_GUID gTcg2ConformanceTestAssertionGuid015 = EFI_TEST_TCG2CONFORMANCE_ASSERTION_015_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 c95aa4a6a043..0f84839d0238 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
@@ -137,7 +137,7 @@ BBTestGetActivePcrBanksConformanceTest (
 
 /**
  *  @brief Entrypoint for HashLogExtendEvent() Function Test.
- *         2 checkpoints will be tested.
+ *         4 checkpoints 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
@@ -183,6 +183,12 @@ BBTestHashLogExtendEventConformanceTest (
   //Test with correct size field
   BBTestHashLogExtendEventConformanceTestCheckpoint2 (StandardLib, TCG2);
 
+  // Test GetEventLog using invalid EventLog Format
+  BBTestGetEventLogConformanceTestCheckpoint1 (StandardLib, TCG2);
+
+  // Test GetEventLog using valid EventLog Format
+  BBTestGetEventLogConformanceTestCheckpoint2 (StandardLib, TCG2);
+
   return EFI_SUCCESS;
 }
 
@@ -770,3 +776,199 @@ BBTestHashLogExtendEventConformanceTestCheckpoint2 (
 
   return EFI_SUCCESS;
 }
+
+#define EFI_TCG2_INVALID_EVENT_LOG_FORMAT 0x20
+
+EFI_STATUS
+BBTestGetEventLogConformanceTestCheckpoint1 (
+  IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL    *StandardLib,
+  IN EFI_TCG2_PROTOCOL                     *TCG2
+  )
+{
+  EFI_TEST_ASSERTION                    AssertionType;
+  EFI_STATUS                            Status;
+  EFI_TCG2_EVENT_LOG_FORMAT             EventLogFormat;
+  EFI_PHYSICAL_ADDRESS                  *EventLogLocation;
+  EFI_PHYSICAL_ADDRESS                  *EventLogLastEntry;
+  BOOLEAN                               *EventLogTruncated;
+
+  // Ensure Get EventLog returns Invalid Parameter when passed invalid format
+  EventLogFormat = EFI_TCG2_INVALID_EVENT_LOG_FORMAT;
+
+  Status = TCG2->GetEventLog (
+                           TCG2,
+                           EventLogFormat,
+                           EventLogLocation,
+                           EventLogLastEntry,
+                           EventLogTruncated);
+
+  if (EFI_INVALID_PARAMETER != Status) {
+    AssertionType = EFI_TEST_ASSERTION_FAILED;
+  } else {
+    AssertionType = EFI_TEST_ASSERTION_PASSED;
+  }
+
+  StandardLib->RecordAssertion (
+                 StandardLib,
+                 AssertionType,
+                 gTcg2ConformanceTestAssertionGuid012,
+                 L"TCG2_PROTOCOL.GetEventLog - GetEventLog() should return EFI_INVALID_PARAMETER when passed in invalid EventLog Format",
+                 L"%a:%d: Status - %r",
+                 __FILE__,
+                 (UINTN)__LINE__,
+                 Status
+                 );
+
+  return EFI_SUCCESS;
+}
+
+EFI_STATUS
+BBTestGetEventLogConformanceTestCheckpoint2 (
+  IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL    *StandardLib,
+  IN EFI_TCG2_PROTOCOL                     *TCG2
+  )
+{
+  EFI_TEST_ASSERTION                    AssertionType;
+  EFI_STATUS                            Status;
+  EFI_TCG2_EVENT_LOG_FORMAT             EventLogFormat;
+  EFI_PHYSICAL_ADDRESS                  EventLogLocation;
+  EFI_PHYSICAL_ADDRESS                  EventLogLastEntry;
+  BOOLEAN                               EventLogTruncated;
+  TCG_PCR_EVENT                         *EventLogHeader;
+  TCG_EfiSpecIDEventStruct              *EventLogHeaderSpecEvent;
+  TCG_PCR_EVENT2                        *LastEvent;
+  UINT8 *data = "Spec ID Event03\0\0";
+
+  EventLogFormat = EFI_TCG2_EVENT_LOG_FORMAT_TCG_2;
+
+  // Call GetEventLog with valid EventLogFormat
+  Status = TCG2->GetEventLog (
+                           TCG2,
+                           EventLogFormat,
+                           &EventLogLocation,
+                           &EventLogLastEntry,
+                           &EventLogTruncated);
+
+  AssertionType = EFI_TEST_ASSERTION_PASSED;
+
+  // Verify GetEventLog returns EFI_SUCCESS
+  if (Status != EFI_SUCCESS) {
+    StandardLib->RecordMessage (
+                     StandardLib,
+                     EFI_VERBOSE_LEVEL_DEFAULT,
+                     L"\r\nTCG2 Protocol GetEventLog Test: GetEventLog should return EFI_SUCCESS with valid EventLogFormat, Status = %r",
+                     Status
+                     );
+
+    AssertionType = EFI_TEST_ASSERTION_FAILED;
+
+  }
+
+  StandardLib->RecordAssertion (
+                 StandardLib,
+                 AssertionType,
+                 gTcg2ConformanceTestAssertionGuid013,
+                 L"TCG2_PROTOCOL.GetEventLog - GetEventLog() should return EFI_SUCCESS",
+                 L"%a:%d: Status - %r",
+                 __FILE__,
+                 (UINTN)__LINE__,
+                 Status
+                 );
+
+  // If GetEventLog doesn't return EFI_SUCCESS abort test
+  if (Status != EFI_SUCCESS) {
+    return Status;
+  }
+
+  EventLogHeader = (TCG_PCR_EVENT *) EventLogLocation;
+  EventLogHeaderSpecEvent = (TCG_EfiSpecIDEventStruct *) EventLogHeader->Event;
+
+  AssertionType = EFI_TEST_ASSERTION_PASSED;
+
+
+  // Verify valid eventlog header is returned
+  // Verify EventLogHeader PCR index == 0
+  if (EventLogHeader->PCRIndex != 0) {
+    StandardLib->RecordMessage (
+                     StandardLib,
+                     EFI_VERBOSE_LEVEL_DEFAULT,
+                     L"\r\nTCG2 Protocol GetEventLog Test: EventLogHeader should have PCR index == 0"
+                     );
+
+    AssertionType = EFI_TEST_ASSERTION_FAILED;
+  }
+
+  // Verify EventLogHeader event type = EV_NO_ACTION
+  if (EventLogHeader->EventType != EV_NO_ACTION) {
+    StandardLib->RecordMessage (
+                     StandardLib,
+                     EFI_VERBOSE_LEVEL_DEFAULT,
+                     L"\r\nTCG2 Protocol GetEventLog Test: EventLogHeader should be EventType == EV_NO_ACTION"
+                     );
+
+    AssertionType = EFI_TEST_ASSERTION_FAILED;
+  }
+
+  // Verify EventLog Signature
+  Status = SctStrCmp(EventLogHeaderSpecEvent->signature, data);
+
+  if (Status != EFI_SUCCESS) {
+    StandardLib->RecordMessage (
+                     StandardLib,
+                     EFI_VERBOSE_LEVEL_DEFAULT,
+                     L"\r\nTCG2 Protocol GetEventLog Test: EventLogHeader Signature did not match \'Spec ID Event03\'"
+                     );
+
+    AssertionType = EFI_TEST_ASSERTION_FAILED;
+  }
+
+  StandardLib->RecordAssertion (
+                 StandardLib,
+                 AssertionType,
+                 gTcg2ConformanceTestAssertionGuid014,
+                 L"TCG2_PROTOCOL.GetEventLog - GetEventLog() should return correct EventLogHeader",
+                 L"%a:%d: Status - %r",
+                 __FILE__,
+                 (UINTN)__LINE__,
+                 Status
+                 );
+
+
+  // Verify Event recorded in checkpoint2 was recorded in Eventlog
+  LastEvent = (TCG_PCR_EVENT2 *) EventLogLastEntry;
+
+  // Verify Last Event PCR = 16
+  if (LastEvent->PCRIndex != 16) {
+    StandardLib->RecordMessage (
+                     StandardLib,
+                     EFI_VERBOSE_LEVEL_DEFAULT,
+                     L"\r\nTCG2 Protocol GetEventLog Test: PCR Index of Last event should be 16"
+                     );
+
+    AssertionType = EFI_TEST_ASSERTION_FAILED;
+  }
+
+  // Verify last event type = EV_POST_CODE
+  if (LastEvent->EventType != EV_POST_CODE) {
+    StandardLib->RecordMessage (
+                     StandardLib,
+                     EFI_VERBOSE_LEVEL_DEFAULT,
+                     L"\r\nTCG2 Protocol GetEventLog Test: PCR Index of last event should be type EV_POST_CODE"
+                     );
+
+    AssertionType = EFI_TEST_ASSERTION_FAILED;
+  }
+
+  StandardLib->RecordAssertion (
+                 StandardLib,
+                 AssertionType,
+                 gTcg2ConformanceTestAssertionGuid015,
+                 L"TCG2_PROTOCOL.GetEventLog - GetEventLog() should record Event from Checkpoint2 as last EventLogEntry",
+                 L"%a:%d: Status - %r",
+                 __FILE__,
+                 (UINTN)__LINE__,
+                 Status
+                 );
+
+  return EFI_SUCCESS;
+}
-- 
2.25.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#86461): https://edk2.groups.io/g/devel/message/86461
Mute This Topic: https://groups.io/mt/89012620/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