From: "Joseph Hemann" <joseph.hemann@arm.com>
To: devel@edk2.groups.io
Cc: nd@arm.com, Joseph Hemann <Joseph.hemann@arm.com>
Subject: [PATCH 5/6] uefi-sct/SctPkg: TCG2 Protocol: add GetEventLog test
Date: Sun, 9 Jan 2022 14:58:26 -0600 [thread overview]
Message-ID: <20220109205827.3608758-6-Joseph.hemann@arm.com> (raw)
In-Reply-To: <20220109205827.3608758-1-Joseph.hemann@arm.com>
-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
Signed-off-by: Joseph Hemann <Joseph.hemann@arm.com>
Change-Id: I5ca3a46b3d36e8f11848a788f6cfdcabeb5b04c8
---
.../EFI/Protocol/TCG2/BlackBoxTest/Guid.c | 8 +
.../EFI/Protocol/TCG2/BlackBoxTest/Guid.h | 20 ++
.../TCG2/BlackBoxTest/TCG2ProtocolBBTest.h | 15 ++
.../TCG2ProtocolBBTestConformance.c | 204 +++++++++++++++++-
uefi-sct/SctPkg/UEFI/Protocol/TCG2.h | 46 ++++
5 files changed, 292 insertions(+), 1 deletion(-)
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 ed013744..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
@@ -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/Guid.h b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/Guid.h
index 45c2b2b2..d3a18aee 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 1b56852e..d9c23094 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/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/TCG2ProtocolBBTestConformance.c b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/TCG2ProtocolBBTestConformance.c
index 874e4eb8..a7bec793 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;
}
@@ -759,3 +765,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;
+}
diff --git a/uefi-sct/SctPkg/UEFI/Protocol/TCG2.h b/uefi-sct/SctPkg/UEFI/Protocol/TCG2.h
index 923549e2..ac66fa0e 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) (
--
2.25.1
next prev parent reply other threads:[~2022-01-09 20:58 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-09 20:58 [PATCH V2 0/6] Implementation of TCG2 Protocol test Joseph Hemann
2022-01-09 20:58 ` [PATCH 1/6] uefi-sct/SctPkg: TCG2 Protocol: add header with TCG2 protocol definitions Joseph Hemann
2022-01-09 20:58 ` [PATCH 2/6] uefi-sct/SctPkg: TCG2 Protocol: add GetCapability Test Joseph Hemann
2022-02-01 18:32 ` [edk2-devel] " Stuart Yoder
2022-02-07 17:59 ` Joseph Hemann
2022-01-09 20:58 ` [PATCH 3/6] uefi-sct/SctPkg: TCG2 Protocol: add GetActivePcrBanks test Joseph Hemann
2022-01-09 20:58 ` [PATCH 4/6] uefi-sct/SctPkg: TCG2 Protocol: add HashLogExtendEvent test Joseph Hemann
2022-01-09 20:58 ` Joseph Hemann [this message]
2022-01-09 20:58 ` [PATCH 6/6] uefi-sct/SctPkg: TCG2 Protocol: add SubmitCommand test Joseph Hemann
-- strict thread matches above, loose matches on Subject: below --
2021-10-20 13:43 [PATCH 0/6] Implementation of TCG2 Protocol test Joseph Hemann
2021-10-20 13:43 ` [PATCH 5/6] uefi-sct/SctPkg: TCG2 Protocol: add GetEventLog test Joseph Hemann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220109205827.3608758-6-Joseph.hemann@arm.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox