From 422834a8bbe0e0630a2fed46982eef033f6067dd Mon Sep 17 00:00:00 2001 From: iadgovuser58 <124906646+iadgovuser58@users.noreply.github.com> Date: Mon, 8 Apr 2024 12:28:03 -0400 Subject: [PATCH] spdm event structures --- .../events/DeviceSecurityEventData.java | 41 +++++ .../DeviceSecurityEventDataDeviceContext.java | 17 ++ .../events/DeviceSecurityEventDataHeader.java | 162 ++++++++++++++++++ .../DeviceSecurityEventDataPciContext.java | 4 + .../events/EvEfiSpdmFirmwareBlob.java | 23 +-- .../evDeviceSecurityEventDataHeader.java | 4 - .../evDeviceSecurityEventDataPciContext.java | 4 - 7 files changed, 233 insertions(+), 22 deletions(-) create mode 100644 HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventData.java create mode 100644 HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventDataDeviceContext.java create mode 100644 HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventDataHeader.java create mode 100644 HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventDataPciContext.java delete mode 100644 HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/evDeviceSecurityEventDataHeader.java delete mode 100644 HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/evDeviceSecurityEventDataPciContext.java diff --git a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventData.java b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventData.java new file mode 100644 index 00000000..478faa4a --- /dev/null +++ b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventData.java @@ -0,0 +1,41 @@ +package hirs.utils.tpm.eventlog.events; + +import hirs.utils.HexUtils; +import hirs.utils.tpm.eventlog.TcgTpmtHa; +import hirs.utils.tpm.eventlog.uefi.UefiConstants; +import lombok.Getter; + +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; + + +/** + * Class to process the DeviceSecurityEventData event + * DEVICE_SECURITY_EVENT_DATA has 2 structures: + * 1) DEVICE_SECURITY_EVENT_DATA_HEADER + * 2) DEVICE_SECURITY_EVENT_DATA_PCI_CONTEXT + * DEVICE_SECURITY_EVENT_DATA_HEADER + * The first 16 bytes of the event data header MUST be a String based identifier (Signature), + * NUL-terminated. The only currently defined Signature is "SPDM Device Sec" which implies + * the event data is a DEVICE_SECURITY_EVENT_DATA. DEVICE_SECURITY_EVENT_DATA_HEADER contains + * the measurement(s) and hash algorithm (SpdmHashAlg) identifier returned by the SPDM + * "GET_MEASUREMENTS" function. + * DEVICE_SECURITY_EVENT_DATA_DEVICE_CONTEXT + * DEVICE_SECURITY_EVENT_DATA_DEVICE_CONTEXT is a common SPDM structure which includes the + * identification of the device, device vendor, subsystem, etc. + *
+ * typedef struct tdDEVICE_SECURITY_EVENT_DATA { + * DEVICE_SECURITY_EVENT_DATA_HEADER EventDataHeader; + * DEVICE_SECURITY_EVENT_DATA_DEVICE_CONTEXT DeviceContext; + * } DEVICE_SECURITY_EVENT_DATA; + *
+ * Notes: Parses event data for an DEVICE_SECURITY_EVENT_DATA per PFP Spec. + * 1. Has an EventType of EV_EFI_SPDM_FIRMWARE_BLOB (0x800000E1) + * 2. Digest of 48 bytes + * 3. Event content defined as DEVICE_SECURITY_EVENT_DATA Struct. + * 4. First 16 bytes of the structure is an ASCII "SPDM Device Sec" + */ +public class DeviceSecurityEventData { + +} diff --git a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventDataDeviceContext.java b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventDataDeviceContext.java new file mode 100644 index 00000000..bd12cb92 --- /dev/null +++ b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventDataDeviceContext.java @@ -0,0 +1,17 @@ +package hirs.utils.tpm.eventlog.events; + +/** + * Class to process the DeviceSecurityEventDataDeviceContext event + * DEVICE_SECURITY_EVENT_DATA has 2 structures: + * 1) DEVICE_SECURITY_EVENT_DATA_PCI_CONTEXT + * 2) DEVICE_SECURITY_EVENT_DATA_USB_CONTEXT + *
+ * typedef struct tdDEVICE_SECURITY_EVENT_DATA { + * DEVICE_SECURITY_EVENT_DATA_PCI_CONTEXT PciContext; + * DEVICE_SECURITY_EVENT_DATA_PCI_CONTEXT UsbContext; + * } DEVICE_SECURITY_EVENT_DATA; + *
+ */ +public class DeviceSecurityEventDataDeviceContext { +} + diff --git a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventDataHeader.java b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventDataHeader.java new file mode 100644 index 00000000..a6d83580 --- /dev/null +++ b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventDataHeader.java @@ -0,0 +1,162 @@ +package hirs.utils.tpm.eventlog.events; + +import hirs.utils.HexUtils; +import hirs.utils.tpm.eventlog.TcgTpmtHa; +import hirs.utils.tpm.eventlog.uefi.UefiConstants; +import lombok.Getter; + +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; + +/** + * Class to process the DeviceSecurityEventDataHeader. + * The first 16 bytes of the event data header MUST be a String based identifier (Signature), + * NUL-terminated. The only currently defined Signature is "SPDM Device Sec" which implies + * the event data is a DEVICE_SECURITY_EVENT_DATA. DEVICE_SECURITY_EVENT_DATA_HEADER contains + * the measurement(s) and hash algorithm (SpdmHashAlg) identifier returned by the SPDM + * "GET_MEASUREMENTS" function. + *
+ * typedef struct tdDEVICE_SECURITY_EVENT_DATA_HEADER { + * UINT8 Signature[16]; + * UINT16 Version; + * UINT16 Length; + * UINT32 SpdmHashAlg; + * UINT32 DeviceType; + * SPDM_MEASUREMENT_BLOCK SpdmMeasurementBlock; + * UINT64 DevicePathLength; + * UNIT8 DevicePath[DevicePathLength] + * } DEVICE_SECURITY_EVENT_DATA_HEADER; + *
+ * typedef struct tdSPDM_MEASUREMENT_BLOCK { + * tbd tbdalgorithmId; + * tbd tbddigestSize; + * } SPDM_MEASUREMENT_BLOCK; + *
+ * typedef struct tdDEVICEPATHLENGTH { + * tbd tbdalgorithmId; + * tbd tbddigestSize; + * } DEVICEPATHLENGTH; + *
+ * define TPM_ALG_SHA1 (TPM_ALG_ID)(0x0004) + * define TPM_ALG_SHA256 (TPM_ALG_ID)(0x000B) + * define TPM_ALG_SHA384 (TPM_ALG_ID)(0x000C) + * define TPM_ALG_SHA512 (TPM_ALG_ID)(0x000D) + *
+// * Notes: Parses event data for an EfiSpecID per Table 5 TCG_EfiSpecIdEvent Example.
+// * 1. Should be the first Structure in the log
+// * 2. Has an EventType of EV_NO_ACTION (0x00000003)
+// * 3. Digest of 20 bytes of all 0's
+// * 4. Event content defined as TCG_EfiSpecIDEvent Struct.
+// * 5. First 16 bytes of the structure is an ASCII "Spec ID Event03"
+// * 6. The version of the log is used to determine which format the Log
+// * is to use (sha1 or Crypto Agile)
+ */
+public class DeviceSecurityEventDataHeader {
+// /**
+// * Minor Version.
+// */
+// @Getter
+// private String versionMinor = "";
+// /**
+// * Major Version.
+// */
+// @Getter
+// private String versionMajor = "";
+// /**
+// * Specification errata version.
+// */
+// @Getter
+// private String errata = "";
+// /**
+// * Signature (text) data.
+// */
+// @Getter
+// private String signature = "";
+// /**
+// * Platform class.
+// */
+// @Getter
+// private String platformClass = "";
+// /**
+// * Algorithm count.
+// */
+// @Getter
+// private int numberOfAlg = 0;
+// /**
+// * True if event log uses Crypto Agile format.
+// */
+// @Getter
+// private boolean cryptoAgile = false;
+// /**
+// * Algorithm list.
+// */
+// private List