Merge pull request #861 from nsacyber/v3_issue_860-spdm

fix checkstyle changes that were lost during merge conflict of pciids PR
This commit is contained in:
D2B8CA1B27286366A8607B6858C0565962613D18D0546480078B520CD7AD705A 2024-10-24 16:42:54 -04:00 committed by GitHub
commit 775ab4acc6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
23 changed files with 251 additions and 223 deletions

View File

@ -76,7 +76,7 @@ public final class PciIds {
} }
} }
if(dbFile != null) { if (dbFile != null) {
InputStream is = null; InputStream is = null;
try { try {
is = new FileInputStream(dbFile); is = new FileInputStream(dbFile);
@ -97,9 +97,9 @@ public final class PciIds {
} }
// if pciids file is not found on the system or not accessible, then attempt to grab it from code // if pciids file is not found on the system or not accessible, then attempt to grab it from code
if(pciidsFileStatus == UefiConstants.FILESTATUS_NOT_ACCESSIBLE) { if (pciidsFileStatus == UefiConstants.FILESTATUS_NOT_ACCESSIBLE) {
InputStream isFromCode = PciIds.class.getResourceAsStream(PCIIDS_FILENAME); InputStream isFromCode = PciIds.class.getResourceAsStream(PCIIDS_FILENAME);
if(isFromCode != null) { if (isFromCode != null) {
try { try {
DB.loadStream(isFromCode); DB.loadStream(isFromCode);
pciidsFileStatus = UefiConstants.FILESTATUS_FROM_CODE; pciidsFileStatus = UefiConstants.FILESTATUS_FROM_CODE;
@ -115,20 +115,21 @@ public final class PciIds {
} }
// if pciids file is not accessible on system or from within code, then log error // if pciids file is not accessible on system or from within code, then log error
if(pciidsFileStatus == UefiConstants.FILESTATUS_NOT_ACCESSIBLE) { if (pciidsFileStatus == UefiConstants.FILESTATUS_NOT_ACCESSIBLE) {
log.info("PCI IDs file was NOT accessible from within the system or within the code"); log.info("PCI IDs file was NOT accessible from within the system or within the code");
} }
} }
} }
/** /**
* Default private constructor so checkstyles doesn't complain * Default private constructor so checkstyles doesn't complain.
*/ */
private PciIds() { } private PciIds() { }
/** /**
* Look up the vendor name from the PCI IDs list, if the input string contains an ID. * Look up the vendor name from the PCI IDs list, if the input string contains an ID.
* If any part of this fails, return the original manufacturer value. * If any part of this fails, return the original manufacturer value.
*
* @param refManufacturer DERUTF8String, likely from a ComponentIdentifier * @param refManufacturer DERUTF8String, likely from a ComponentIdentifier
* @return DERUTF8String with the discovered vendor name, or the original manufacturer value. * @return DERUTF8String with the discovered vendor name, or the original manufacturer value.
*/ */
@ -148,6 +149,7 @@ public final class PciIds {
/** /**
* Look up the vendor name from the PCI IDs list, if the input string contains an ID. * Look up the vendor name from the PCI IDs list, if the input string contains an ID.
* If any part of this fails, return the original manufacturer value. * If any part of this fails, return the original manufacturer value.
*
* @param refManufacturer String, likely from a ComponentResult * @param refManufacturer String, likely from a ComponentResult
* @return String with the discovered vendor name, or the original manufacturer value. * @return String with the discovered vendor name, or the original manufacturer value.
*/ */
@ -168,6 +170,7 @@ public final class PciIds {
* Look up the device name from the PCI IDs list, if the input strings contain IDs. * Look up the device name from the PCI IDs list, if the input strings contain IDs.
* The Device lookup requires the Vendor ID AND the Device ID to be valid values. * The Device lookup requires the Vendor ID AND the Device ID to be valid values.
* If any part of this fails, return the original model value. * If any part of this fails, return the original model value.
*
* @param refManufacturer ASN1UTF8String, likely from a ComponentIdentifier * @param refManufacturer ASN1UTF8String, likely from a ComponentIdentifier
* @param refModel ASN1UTF8String, likely from a ComponentIdentifier * @param refModel ASN1UTF8String, likely from a ComponentIdentifier
* @return ASN1UTF8String with the discovered device name, or the original model value. * @return ASN1UTF8String with the discovered device name, or the original model value.
@ -194,6 +197,7 @@ public final class PciIds {
* Look up the device name from the PCI IDs list, if the input strings contain IDs. * Look up the device name from the PCI IDs list, if the input strings contain IDs.
* The Device lookup requires the Vendor ID AND the Device ID to be valid values. * The Device lookup requires the Vendor ID AND the Device ID to be valid values.
* If any part of this fails, return the original model value. * If any part of this fails, return the original model value.
*
* @param refManufacturer String, likely from a ComponentResult * @param refManufacturer String, likely from a ComponentResult
* @param refModel String, likely from a ComponentResult * @param refModel String, likely from a ComponentResult
* @return String with the discovered device name, or the original model value. * @return String with the discovered device name, or the original model value.
@ -218,15 +222,16 @@ public final class PciIds {
/** /**
* Look up the device class name from the PCI IDs list, if the input string contains an ID. * Look up the device class name from the PCI IDs list, if the input string contains an ID.
* If any part of this fails, return the original manufacturer value. * If any part of this fails, return the original manufacturer value.
*
* @param refClassCode String, formatted as 2 characters (1 byte) for each of the 3 categories * @param refClassCode String, formatted as 2 characters (1 byte) for each of the 3 categories
* Example "010802": * . Example "010802":
* Class: "01" * . Class: "01"
* Subclass: "08" * . Subclass: "08"
* Programming Interface: "02" * . Programming Interface: "02"
* @return List<String> 3-element list with the class code * @return List<String> 3-element list with the class code
* 1st element: human-readable description of Class * . 1st element: human-readable description of Class
* 2nd element: human-readable description of Subclass * . 2nd element: human-readable description of Subclass
* 3rd element: human-readable description of Programming Interface * . 3rd element: human-readable description of Programming Interface
*/ */
public static List<String> translateDeviceClass(final String refClassCode) { public static List<String> translateDeviceClass(final String refClassCode) {
List<String> translatedClassCode = new ArrayList<>(); List<String> translatedClassCode = new ArrayList<>();
@ -235,9 +240,24 @@ public final class PciIds {
if (!pciidsFileStatus.equals(UefiConstants.FILESTATUS_NOT_ACCESSIBLE) if (!pciidsFileStatus.equals(UefiConstants.FILESTATUS_NOT_ACCESSIBLE)
&& classCode != null && classCode != null
&& classCode.trim().matches("^[0-9A-Fa-f]{6}$")) { && classCode.trim().matches("^[0-9A-Fa-f]{6}$")) {
String deviceClass = classCode.substring(0, 2).toLowerCase();
String deviceSubclass = classCode.substring(2, 4).toLowerCase(); final int startIndexOfDeviceClass = 0;
String programInterface = classCode.substring(4, 6).toLowerCase(); final int endIndexOfDeviceClass = 2;
String deviceClass =
classCode.substring(startIndexOfDeviceClass, endIndexOfDeviceClass).toLowerCase();
final int startIndexOfDeviceSubclass = 2;
final int endIndexOfDeviceSubclass = 4;
String deviceSubclass =
classCode.substring(startIndexOfDeviceSubclass, endIndexOfDeviceSubclass)
.toLowerCase();
final int startIndexOfProgramInterface = 4;
final int endIndexOfProgramInterface = 6;
final String programInterface =
classCode.substring(startIndexOfProgramInterface, endIndexOfProgramInterface)
.toLowerCase();
translatedClassCode.add(deviceClass); translatedClassCode.add(deviceClass);
translatedClassCode.add(deviceSubclass); translatedClassCode.add(deviceSubclass);
translatedClassCode.add(programInterface); translatedClassCode.add(programInterface);

View File

@ -12,8 +12,8 @@ import java.math.BigInteger;
* Class to for the TCG defined TPMT_HA structure used to support the Crypto Agile Log format. * Class to for the TCG defined TPMT_HA structure used to support the Crypto Agile Log format.
* <p> * <p>
* typedef struct { * typedef struct {
* TPMI_ALG_HASH hashAlg; * . TPMI_ALG_HASH hashAlg;
* TPMU_HA digest; * . TPMU_HA digest;
* } TPMT_HA; * } TPMT_HA;
*/ */
public class TcgTpmtHa { public class TcgTpmtHa {

View File

@ -39,16 +39,16 @@ import static hirs.utils.tpm.eventlog.uefi.UefiConstants.FILESTATUS_FROM_FILESYS
* TCG_PCR_EVENT is used when the Event log uses the SHA1 Format as described in the * TCG_PCR_EVENT is used when the Event log uses the SHA1 Format as described in the
* TCG Platform Firmware Profile (PFP) specification. * TCG Platform Firmware Profile (PFP) specification.
* typedef struct { * typedef struct {
* TCG_PCRINDEX PCRIndex; //PCR Index value that either * . TCG_PCRINDEX PCRIndex; //PCR Index value that either
* //matches the PCRIndex of a * . //matches the PCRIndex of a
* //previous extend operation or * . //previous extend operation or
* //indicates that this Event Log * . //indicates that this Event Log
* //entry is not associated with * . //entry is not associated with
* //an extend operation * . //an extend operation
* TCG_EVENTTYPE EventType; //See Log event types defined in toStrng() * . TCG_EVENTTYPE EventType; //See Log event types defined in toStrng()
* TCG_DIGEST digest; //The hash of the event data * . TCG_DIGEST digest; //The hash of the event data
* UINT32 EventSize; //Size of the event data * . UINT32 EventSize; //Size of the event data
* UINT8 Event[EventSize]; //The event data * . UINT8 Event[EventSize]; //The event data
* } TCG_PCR_EVENT; * } TCG_PCR_EVENT;
*/ */
@Log4j2 @Log4j2

View File

@ -15,11 +15,11 @@ import java.security.cert.CertificateException;
* TCG Platform Firmware Profile specification. * TCG Platform Firmware Profile specification.
* typedef struct { * typedef struct {
* UINT32 PCRIndex; //PCR Index value that either * UINT32 PCRIndex; //PCR Index value that either
* //matches the PCRIndex of a * . //matches the PCRIndex of a
* //previous extend operation or * . //previous extend operation or
* //indicates that this Event Log * . //indicates that this Event Log
* //entry is not associated with * . //entry is not associated with
* //an extend operation * . //an extend operation
* UINT32 EventType; //See Log event types * UINT32 EventType; //See Log event types
* BYTE digest[20]; //The SHA1 hash of the event data * BYTE digest[20]; //The SHA1 hash of the event data
* UINT32 EventSize; //Size of the event data * UINT32 EventSize; //Size of the event data

View File

@ -16,30 +16,30 @@ import java.util.ArrayList;
* TCG Platform Firmware Profile specification. * TCG Platform Firmware Profile specification.
* This class will only process SHA-256 digests. * This class will only process SHA-256 digests.
* typedef struct { * typedef struct {
* UINT32 PCRIndex; //PCR Index value that either * . UINT32 PCRIndex; //PCR Index value that either
* //matches the PCRIndex of a * . //matches the PCRIndex of a
* //previous extend operation or * . //previous extend operation or
* //indicates that this Event Log * . //indicates that this Event Log
* //entry is not associated with * . //entry is not associated with
* //an extend operation * . //an extend operation
* UINT32 EventType; //See Log event types * . UINT32 EventType; //See Log event types
* TPML_DIGEST_VALUES digest; //The hash of the event data * . TPML_DIGEST_VALUES digest; //The hash of the event data
* UINT32 EventSize; //Size of the event data * . UINT32 EventSize; //Size of the event data
* BYTE Event[1]; //The event data * . BYTE Event[1]; //The event data
* } TCG_PCR_EVENT2; //The event data structure to be added * } TCG_PCR_EVENT2; //The event data structure to be added
* typedef struct { * typedef struct {
* UINT32 count; * . UINT32 count;
* TPMT_HA digests[HASH_COUNT]; * . TPMT_HA digests[HASH_COUNT];
* } TPML_DIGEST_VALUES; * } TPML_DIGEST_VALUES;
* typedef struct { * typedef struct {
* TPMI_ALG_HASH hashAlg; * . TPMI_ALG_HASH hashAlg;
* TPMU_HA digest; * . TPMU_HA digest;
* } TPMT_HA; * } TPMT_HA;
* typedef union { * typedef union {
* BYTE sha1[SHA1_DIGEST_SIZE]; * . BYTE sha1[SHA1_DIGEST_SIZE];
* BYTE sha256[SHA256_DIGEST_SIZE]; * . BYTE sha256[SHA256_DIGEST_SIZE];
* BYTE sha384[SHA384_DIGEST_SIZE]; * . BYTE sha384[SHA384_DIGEST_SIZE];
* BYTE sha512[SHA512_DIGEST_SIZE]; * . BYTE sha512[SHA512_DIGEST_SIZE];
* } TPMU_HA; * } TPMU_HA;
* define SHA1_DIGEST_SIZE 20 * define SHA1_DIGEST_SIZE 20
* define SHA256_DIGEST_SIZE 32 * define SHA256_DIGEST_SIZE 32

View File

@ -8,34 +8,34 @@ import lombok.Setter;
* Abstract base class to process the DEVICE_SECURITY_EVENT_DATA or ..DATA2 event. * Abstract base class to process the DEVICE_SECURITY_EVENT_DATA or ..DATA2 event.
* Parses event data per PFP v1.06 Rev52 Tables 20 and 26. * Parses event data per PFP v1.06 Rev52 Tables 20 and 26.
* The event data comes in 2 forms: * The event data comes in 2 forms:
* 1) DEVICE_SECURITY_EVENT_DATA or * . 1) DEVICE_SECURITY_EVENT_DATA or
* 2) DEVICE_SECURITY_EVENT_DATA2 * . 2) DEVICE_SECURITY_EVENT_DATA2
* The first 2 fields of the respective headers are the same in both ..DATA and ..DATA2. * The first 2 fields of the respective headers are the same in both ..DATA and ..DATA2.
* Field 1: * Field 1:
* The first 16 bytes of the event data header MUST be a String based identifier (Signature), * . The first 16 bytes of the event data header MUST be a String based identifier (Signature),
* per PFP. The only currently defined Signatures are "SPDM Device Sec" and "SPDM Device Sec2", * . per PFP. The only currently defined Signatures are "SPDM Device Sec" and "SPDM Device Sec2",
* which implies the data is a DEVICE_SECURITY_EVENT_DATA or ..DATA2, respectively. * . which implies the data is a DEVICE_SECURITY_EVENT_DATA or ..DATA2, respectively.
* Field 2: * Field 2:
* The Version field also indicates whether the Device Security Event is ..DATA or ..DATA2. * . The Version field also indicates whether the Device Security Event is ..DATA or ..DATA2.
* *
* DEVICE SECURITY EVENT structures defined by PFP v1.06 Rev 52: * DEVICE SECURITY EVENT structures defined by PFP v1.06 Rev 52:
* <p> * <p>
* typedef struct tdDEVICE_SECURITY_EVENT_DATA { * typedef struct tdDEVICE_SECURITY_EVENT_DATA {
* DEVICE_SECURITY_EVENT_DATA_HEADER EventDataHeader; * . DEVICE_SECURITY_EVENT_DATA_HEADER EventDataHeader;
* DEVICE_SECURITY_EVENT_DATA_DEVICE_CONTEXT DeviceContext; * . DEVICE_SECURITY_EVENT_DATA_DEVICE_CONTEXT DeviceContext;
* } DEVICE_SECURITY_EVENT_DATA; * } DEVICE_SECURITY_EVENT_DATA;
* <p> * <p>
* typedef struct tdDEVICE_SECURITY_EVENT_DATA2 { * typedef struct tdDEVICE_SECURITY_EVENT_DATA2 {
* DEVICE_SECURITY_EVENT_DATA_HEADER2 EventDataHeader; * . DEVICE_SECURITY_EVENT_DATA_HEADER2 EventDataHeader;
* DEVICE_SECURITY_EVENT_DATA_SUB_HEADER EventDataSubHeader; * . DEVICE_SECURITY_EVENT_DATA_SUB_HEADER EventDataSubHeader;
* DEVICE_SECURITY_EVENT_DATA_DEVICE_CONTEXT DeviceContext; * . DEVICE_SECURITY_EVENT_DATA_DEVICE_CONTEXT DeviceContext;
* } DEVICE_SECURITY_EVENT_DATA2; * } DEVICE_SECURITY_EVENT_DATA2;
* <p> * <p>
* typedef struct tdDEVICE_SECURITY_EVENT_DATA_HEADER or HEADER2 { * typedef struct tdDEVICE_SECURITY_EVENT_DATA_HEADER or HEADER2 {
* UINT8 Signature[16]; * . UINT8 Signature[16];
* UINT16 Version; * . UINT16 Version;
* ... ... * . ... ...
* (The rest of the components are different for HEADER vs HEADER2) * . (The rest of the components are different for HEADER vs HEADER2)
* } * }
* <p> * <p>
*/ */
@ -64,7 +64,8 @@ public abstract class DeviceSecurityEvent {
/** /**
* Track status of pci.ids * Track status of pci.ids
* This is only used for events that access the pci.ids file. * This is only used for events that access the pci.ids file.
* (In this class, this is only needed if DeviceSecurityEvent includes a DeviceSecurityEventDataPciContext) * (In this class, this is only needed if DeviceSecurityEvent includes
* a DeviceSecurityEventDataPciContext)
* Default is normal status (normal status is from-filesystem). * Default is normal status (normal status is from-filesystem).
* Status will only change IF this is an event that uses this file, * Status will only change IF this is an event that uses this file,
* and if that event causes a different status. * and if that event causes a different status.

View File

@ -7,8 +7,8 @@ import lombok.Getter;
* Parses event data per PFP v1.06 Rev52 Table 20. * Parses event data per PFP v1.06 Rev52 Table 20.
* <p> * <p>
* typedef struct tdDEVICE_SECURITY_EVENT_DATA { * typedef struct tdDEVICE_SECURITY_EVENT_DATA {
* DEVICE_SECURITY_EVENT_DATA_HEADER EventDataHeader; * . DEVICE_SECURITY_EVENT_DATA_HEADER EventDataHeader;
* DEVICE_SECURITY_EVENT_DATA_DEVICE_CONTEXT DeviceContext; * . DEVICE_SECURITY_EVENT_DATA_DEVICE_CONTEXT DeviceContext;
* } DEVICE_SECURITY_EVENT_DATA; * } DEVICE_SECURITY_EVENT_DATA;
* <p> * <p>
*/ */

View File

@ -7,9 +7,9 @@ import lombok.Getter;
* Parses event data per PFP v1.06 Rev52 Table 26. * Parses event data per PFP v1.06 Rev52 Table 26.
* <p> * <p>
* typedef struct tdDEVICE_SECURITY_EVENT_DATA2 { * typedef struct tdDEVICE_SECURITY_EVENT_DATA2 {
* DEVICE_SECURITY_EVENT_DATA_HEADER2 EventDataHeader; * . DEVICE_SECURITY_EVENT_DATA_HEADER2 EventDataHeader;
* DEVICE_SECURITY_EVENT_DATA_SUB_HEADER EventDataSubHeader; * . DEVICE_SECURITY_EVENT_DATA_SUB_HEADER EventDataSubHeader;
* DEVICE_SECURITY_EVENT_DATA_DEVICE_CONTEXT DeviceContext; * . DEVICE_SECURITY_EVENT_DATA_DEVICE_CONTEXT DeviceContext;
* } DEVICE_SECURITY_EVENT_DATA2; * } DEVICE_SECURITY_EVENT_DATA2;
* <p> * <p>
*/ */

View File

@ -10,8 +10,8 @@ import lombok.Getter;
* or USB connection. * or USB connection.
* <p> * <p>
* typedef union tdDEVICE_SECURITY_EVENT_DATA_DEVICE_CONTEXT { * typedef union tdDEVICE_SECURITY_EVENT_DATA_DEVICE_CONTEXT {
* DEVICE_SECURITY_EVENT_DATA_PCI_CONTEXT PciContext; * . DEVICE_SECURITY_EVENT_DATA_PCI_CONTEXT PciContext;
* DEVICE_SECURITY_EVENT_DATA_USB_CONTEXT UsbContext; * . DEVICE_SECURITY_EVENT_DATA_USB_CONTEXT UsbContext;
* } DEVICE_SECURITY_EVENT_DATA_DEVICE_CONTEXT; * } DEVICE_SECURITY_EVENT_DATA_DEVICE_CONTEXT;
* <p> * <p>
*/ */

View File

@ -17,14 +17,14 @@ import java.io.IOException;
* HEADERS defined by PFP v1.06 Rev 52: * HEADERS defined by PFP v1.06 Rev 52:
* <p> * <p>
* typedef struct tdDEVICE_SECURITY_EVENT_DATA_HEADER { * typedef struct tdDEVICE_SECURITY_EVENT_DATA_HEADER {
* UINT8 Signature[16]; * . UINT8 Signature[16];
* UINT16 Version; * . UINT16 Version;
* UINT16 Length; * . UINT16 Length;
* UINT32 SpdmHashAlg; * . UINT32 SpdmHashAlg;
* UINT32 DeviceType; * . UINT32 DeviceType;
* SPDM_MEASUREMENT_BLOCK SpdmMeasurementBlock; * . SPDM_MEASUREMENT_BLOCK SpdmMeasurementBlock;
* UINT64 DevicePathLength; * . UINT64 DevicePathLength;
* UNIT8 DevicePath[DevicePathLength] * . UNIT8 DevicePath[DevicePathLength]
* } DEVICE_SECURITY_EVENT_DATA_HEADER; * } DEVICE_SECURITY_EVENT_DATA_HEADER;
* <p> * <p>
* Assumption: there is only 1 SpdmMeasurementBlock per event. Need more test patterns to verify. * Assumption: there is only 1 SpdmMeasurementBlock per event. Need more test patterns to verify.

View File

@ -11,17 +11,17 @@ import lombok.Getter;
* HEADERS defined by PFP v1.06 Rev 52: * HEADERS defined by PFP v1.06 Rev 52:
* <p> * <p>
* typedef struct tdDEVICE_SECURITY_EVENT_DATA_HEADER2 { * typedef struct tdDEVICE_SECURITY_EVENT_DATA_HEADER2 {
* UINT8 Signature[16]; * . UINT8 Signature[16];
* UINT16 Version; * . UINT16 Version;
* UINT8 AuthState; * . UINT8 AuthState;
* UINT8 Reserved * . UINT8 Reserved
* UINT32 Length; * . UINT32 Length;
* UINT32 DeviceType; * . UINT32 DeviceType;
* UINT32 SubHeaderType; * . UINT32 SubHeaderType;
* UINT32 SubHeaderLength; * . UINT32 SubHeaderLength;
* UINT64 SubHeaderUID; * . UINT64 SubHeaderUID;
* UINT64 DevicePathLength; * . UINT64 DevicePathLength;
* UNIT8 DevicePath[DevicePathLength] * . UNIT8 DevicePath[DevicePathLength]
* } DEVICE_SECURITY_EVENT_DATA_HEADER2; * } DEVICE_SECURITY_EVENT_DATA_HEADER2;
* <p> * <p>
*/ */

View File

@ -15,28 +15,28 @@ import static hirs.utils.PciIds.translateVendor;
* Class to process the DEVICE_SECURITY_EVENT_DATA_PCI_CONTEXT event per PFP. * Class to process the DEVICE_SECURITY_EVENT_DATA_PCI_CONTEXT event per PFP.
* <p> * <p>
* typedef struct tdDEVICE_SECURITY_EVENT_DATA_PCI_CONTEXT { * typedef struct tdDEVICE_SECURITY_EVENT_DATA_PCI_CONTEXT {
* UINT16 Version; * . UINT16 Version;
* UINT16 Length; * . UINT16 Length;
* UINT16 VendorId; * . UINT16 VendorId;
* UINT16 DeviceId; * . UINT16 DeviceId;
* UINT16 RevisionId; * . UINT16 RevisionId;
* UINT16 ClassCode[3]; * . UINT16 ClassCode[3];
* UINT16 SubsystemVendorId; * . UINT16 SubsystemVendorId;
* UINT16 SubsystemId; * . UINT16 SubsystemId;
* <p> * <p>
* The following fields are defined by the PCI Express Base Specification rev4.0 v1.0. * The following fields are defined by the PCI Express Base Specification rev4.0 v1.0.
* VendorId * . VendorId
* DeviceId * . DeviceId
* RevisionId * . RevisionId
* ClassCode * . ClassCode
* SubsystemVendorId * . SubsystemVendorId
* SubsystemId * . SubsystemId
* Vendor id and device id are registered to specific manufacturers. * Vendor id and device id are registered to specific manufacturers.
* https://admin.pci-ids.ucw.cz/read/PC/ * . https://admin.pci-ids.ucw.cz/read/PC/
* Ex. vendor id 8086 and device id 0b60: https://admin.pci-ids.ucw.cz/read/PC/8086/0b60 * . Ex. vendor id 8086 and device id 0b60: https://admin.pci-ids.ucw.cz/read/PC/8086/0b60
* Class code can be looked up on the web. * Class code can be looked up on the web.
* https://admin.pci-ids.ucw.cz/read/PD/ * . https://admin.pci-ids.ucw.cz/read/PD/
* The revision ID is controlled by the vendor and cannot be looked up. * . The revision ID is controlled by the vendor and cannot be looked up.
*/ */
public class DeviceSecurityEventDataPciContext extends DeviceSecurityEventDataDeviceContext { public class DeviceSecurityEventDataPciContext extends DeviceSecurityEventDataDeviceContext {

View File

@ -5,9 +5,9 @@ package hirs.utils.tpm.eventlog.events;
* *
* <p> * <p>
* typedef union tdDEVICE_SECURITY_EVENT_DATA_SUB_HEADER { * typedef union tdDEVICE_SECURITY_EVENT_DATA_SUB_HEADER {
* DEVICE_SECURITY_EVENT_DATA_SUB_HEADER_SPDM_MEASUREMENT_BLOCK SpdmMeasurementBlock; * . DEVICE_SECURITY_EVENT_DATA_SUB_HEADER_SPDM_MEASUREMENT_BLOCK SpdmMeasurementBlock;
* DEVICE_SECURITY_EVENT_DATA_SUB_HEADER_SPDM_CERT_CHAIN SpdmCertChain; * . DEVICE_SECURITY_EVENT_DATA_SUB_HEADER_SPDM_CERT_CHAIN SpdmCertChain;
* DEVICE_SECURITY_EVENT_DATA_SUB_HEADER_OEM_MEASUREMENT OemMeasurement; * . DEVICE_SECURITY_EVENT_DATA_SUB_HEADER_OEM_MEASUREMENT OemMeasurement;
* } DEVICE_SECURITY_EVENT_DATA_SUB_HEADER; * } DEVICE_SECURITY_EVENT_DATA_SUB_HEADER;
* <p> * <p>
*/ */

View File

@ -9,11 +9,11 @@ import hirs.utils.tpm.eventlog.spdm.SpdmHa;
* *
* <p> * <p>
* typedef union tdDEVICE_SECURITY_EVENT_DATA_SUB_HEADER_SPDM_CERT_CHAIN { * typedef union tdDEVICE_SECURITY_EVENT_DATA_SUB_HEADER_SPDM_CERT_CHAIN {
* UINT16 SpdmVersion; * . UINT16 SpdmVersion;
* UINT8 SpdmSlotId; * . UINT8 SpdmSlotId;
* UINT8 Reserved; * . UINT8 Reserved;
* UINT32 SpdmBaseHashAlgo; * . UINT32 SpdmBaseHashAlgo;
* SPDM_CERT_CHAIN SpdmCertChain; * . SPDM_CERT_CHAIN SpdmCertChain;
* } DEVICE_SECURITY_EVENT_DATA_SUB_HEADER_SPDM_CERT_CHAIN; * } DEVICE_SECURITY_EVENT_DATA_SUB_HEADER_SPDM_CERT_CHAIN;
* <p> * <p>
* SpdmVersion: SpdmBaseHashAlgo * SpdmVersion: SpdmBaseHashAlgo

View File

@ -15,21 +15,21 @@ import java.util.List;
* *
* <p> * <p>
* typedef union tdDEVICE_SECURITY_EVENT_DATA_SUB_HEADER_SPDM_MEASUREMENT_BLOCK { * typedef union tdDEVICE_SECURITY_EVENT_DATA_SUB_HEADER_SPDM_MEASUREMENT_BLOCK {
* UINT16 SpdmVersion; * . UINT16 SpdmVersion;
* UINT8 SpdmMeasurementBlockCount; * . UINT8 SpdmMeasurementBlockCount;
* UINT8 Reserved; * . UINT8 Reserved;
* UINT32 SpdmMeasurementHashAlgo; * . UINT32 SpdmMeasurementHashAlgo;
* SPDM_MEASUREMENT_BLOCK SpdmMeasurementBlock[SpdmMeasurementBlockCount]; * . SPDM_MEASUREMENT_BLOCK SpdmMeasurementBlock[SpdmMeasurementBlockCount];
* } DEVICE_SECURITY_EVENT_DATA_SUB_HEADER_SPDM_MEASUREMENT_BLOCK; * } DEVICE_SECURITY_EVENT_DATA_SUB_HEADER_SPDM_MEASUREMENT_BLOCK;
* <p> * <p>
* <p> * <p>
* SpdmMeasurementBlock is an array of SPDM_MEASUREMENT_BLOCKs * SpdmMeasurementBlock is an array of SPDM_MEASUREMENT_BLOCKs
* The size of each block is the same and can be found by either: * . The size of each block is the same and can be found by either:
* 1) 4 + SpdmMeasurementBlock MeasurementSize * . 1) 4 + SpdmMeasurementBlock MeasurementSize
* OR * . OR
* 2) 4 + hash length of the hash algorithm found in * . 2) 4 + hash length of the hash algorithm found in
* DEVICE_SECURITY_EVENT_DATA_SUB_HEADER_SPDM_MEASUREMENT_BLOCK SpdmMeasurementHashAlgo * . DEVICE_SECURITY_EVENT_DATA_SUB_HEADER_SPDM_MEASUREMENT_BLOCK SpdmMeasurementHashAlgo
* where 4 is the size of the SpdmMeasurementBlock header * . where 4 is the size of the SpdmMeasurementBlock header
*/ */
public class DeviceSecurityEventDataSubHeaderSpdmMeasurementBlock extends DeviceSecurityEventDataSubHeader { public class DeviceSecurityEventDataSubHeaderSpdmMeasurementBlock extends DeviceSecurityEventDataSubHeader {

View File

@ -17,36 +17,36 @@ import java.nio.charset.StandardCharsets;
* Certain fields are common to both ..HEADER and ..HEADER2, and are noted below the structures. * Certain fields are common to both ..HEADER and ..HEADER2, and are noted below the structures.
* <p> * <p>
* typedef struct tdDEVICE_SECURITY_EVENT_DATA_HEADER { * typedef struct tdDEVICE_SECURITY_EVENT_DATA_HEADER {
* UINT8 Signature[16]; * . UINT8 Signature[16];
* UINT16 Version; * . UINT16 Version;
* UINT16 Length; * . UINT16 Length;
* UINT32 SpdmHashAlg; * . UINT32 SpdmHashAlg;
* UINT32 DeviceType; * . UINT32 DeviceType;
* SPDM_MEASUREMENT_BLOCK SpdmMeasurementBlock; * . SPDM_MEASUREMENT_BLOCK SpdmMeasurementBlock;
* UINT64 DevicePathLength; * . UINT64 DevicePathLength;
* UNIT8 DevicePath[DevicePathLength] * . UNIT8 DevicePath[DevicePathLength]
* } DEVICE_SECURITY_EVENT_DATA_HEADER; * } DEVICE_SECURITY_EVENT_DATA_HEADER;
* <p> * <p>
* typedef struct tdDEVICE_SECURITY_EVENT_DATA_HEADER2 { - NOT IMPLEMENTED YET * typedef struct tdDEVICE_SECURITY_EVENT_DATA_HEADER2 { - NOT IMPLEMENTED YET
* UINT8 Signature[16]; * . UINT8 Signature[16];
* UINT16 Version; * . UINT16 Version;
* UINT8 AuthState; * . UINT8 AuthState;
* UINT8 Reserved; * . UINT8 Reserved;
* UINT32 Length; * . UINT32 Length;
* UINT32 DeviceType; * . UINT32 DeviceType;
* UINT32 SubHeaderType; * . UINT32 SubHeaderType;
* UINT32 SubHeaderLength; * . UINT32 SubHeaderLength;
* UINT32 SubHeaderUID; * . UINT32 SubHeaderUID;
* UINT64 DevicePathLength; * . UINT64 DevicePathLength;
* UNIT8 DevicePath[DevicePathLength] * . UNIT8 DevicePath[DevicePathLength]
* } DEVICE_SECURITY_EVENT_DATA_HEADER2; * } DEVICE_SECURITY_EVENT_DATA_HEADER2;
* <p> * <p>
* Fields common to both ..HEADER and ..HEADER2: * Fields common to both ..HEADER and ..HEADER2:
* Signature * . Signature
* Version * . Version
* DeviceType * . DeviceType
* DevicePathLength * . DevicePathLength
* DevicePath * . DevicePath
* <p> * <p>
*/ */
public abstract class DeviceSecurityEventHeader { public abstract class DeviceSecurityEventHeader {

View File

@ -9,17 +9,17 @@ import java.nio.charset.StandardCharsets;
/** /**
* Abstract class to process any SPDM event that is solely a DEVICE_SECURITY_EVENT_DATA or * Abstract class to process any SPDM event that is solely a DEVICE_SECURITY_EVENT_DATA or
* DEVICE_SECURITY_EVENT_DATA2. The event field MUST be a * DEVICE_SECURITY_EVENT_DATA2. The event field MUST be a
* 1) DEVICE_SECURITY_EVENT_DATA or * . 1) DEVICE_SECURITY_EVENT_DATA or
* 2) DEVICE_SECURITY_EVENT_DATA2 * . 2) DEVICE_SECURITY_EVENT_DATA2
* DEVICE_SECURITY_EVENT_DATA has 2 structures: * DEVICE_SECURITY_EVENT_DATA has 2 structures:
* 1) DEVICE_SECURITY_EVENT_DATA_HEADER * . 1) DEVICE_SECURITY_EVENT_DATA_HEADER
* 2) DEVICE_SECURITY_EVENT_DATA_DEVICE_CONTEXT, which has 2 structures * . 2) DEVICE_SECURITY_EVENT_DATA_DEVICE_CONTEXT, which has 2 structures
* a) DEVICE_SECURITY_EVENT_DATA_PCI_CONTEXT * . a) DEVICE_SECURITY_EVENT_DATA_PCI_CONTEXT
* b) DEVICE_SECURITY_EVENT_DATA_USB_CONTEXT * . b) DEVICE_SECURITY_EVENT_DATA_USB_CONTEXT
* DEVICE_SECURITY_EVENT_DATA2 has 3 structures: * DEVICE_SECURITY_EVENT_DATA2 has 3 structures:
* 1) DEVICE_SECURITY_EVENT_DATA_HEADER2 * . 1) DEVICE_SECURITY_EVENT_DATA_HEADER2
* 2) DEVICE_SECURITY_EVENT_DATA_SUB_HEADER * . 2) DEVICE_SECURITY_EVENT_DATA_SUB_HEADER
* 3) DEVICE_SECURITY_EVENT_DATA_DEVICE_CONTEXT, which has 2 structures (see above) * . 3) DEVICE_SECURITY_EVENT_DATA_DEVICE_CONTEXT, which has 2 structures (see above)
* The first 16 bytes of the event data header MUST be a String based identifier (Signature), * The first 16 bytes of the event data header MUST be a String based identifier (Signature),
* NUL-terminated, per PFP. The only currently defined Signature is "SPDM Device Sec", * NUL-terminated, per PFP. The only currently defined Signature is "SPDM Device Sec",
* which implies the data is a DEVICE_SECURITY_EVENT_DATA or ..DATA2. * which implies the data is a DEVICE_SECURITY_EVENT_DATA or ..DATA2.

View File

@ -11,16 +11,16 @@ import java.nio.charset.StandardCharsets;
* Class to process the EV_NO_ACTION event. * Class to process the EV_NO_ACTION event.
* The first 16 bytes of the event data MUST be a String based identifier (Signature). * The first 16 bytes of the event data MUST be a String based identifier (Signature).
* Currently defined Signatures are * Currently defined Signatures are
* "Spec ID Event03" * . "Spec ID Event03"
* - implies the data is a TCG_EfiSpecIDEvent * . - implies the data is a TCG_EfiSpecIDEvent
* - TCG_EfiSpecIDEvent is the first event in a TPM Event Log and is used to determine * . - TCG_EfiSpecIDEvent is the first event in a TPM Event Log and is used to determine
* if the format of the Log (SHA1 vs Crypto Agile). * . if the format of the Log (SHA1 vs Crypto Agile).
* "StartupLocality" * . "StartupLocality"
* - implies the data represents locality info (use lookup to interpret) * . - implies the data represents locality info (use lookup to interpret)
* "NvIndexInstance" * . "NvIndexInstance"
* - implies the data is a NV_INDEX_INSTANCE_EVENT_LOG_DATA * . - implies the data is a NV_INDEX_INSTANCE_EVENT_LOG_DATA
* "NvIndexDynamic" * . "NvIndexDynamic"
* - implies the data is a NV_INDEX_DYNAMIC_EVENT_LOG_DATA * . - implies the data is a NV_INDEX_DYNAMIC_EVENT_LOG_DATA
* <p> * <p>
* Notes: * Notes:
* 1. First 16 bytes of the structure is an ASCII with a fixed Length of 16 * 1. First 16 bytes of the structure is an ASCII with a fixed Length of 16

View File

@ -1,8 +1,6 @@
package hirs.utils.tpm.eventlog.events; package hirs.utils.tpm.eventlog.events;
import hirs.utils.HexUtils; import hirs.utils.HexUtils;
import hirs.utils.tpm.eventlog.uefi.UefiConstants;
import lombok.Getter;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -15,14 +13,14 @@ import java.nio.charset.StandardCharsets;
* Certain fields are common to both ..HEADER and ..HEADER2, and are noted below the structures. * Certain fields are common to both ..HEADER and ..HEADER2, and are noted below the structures.
* <p> * <p>
* typedef struct tdNV_INDEX_DYNAMIC_EVENT_LOG_DATA { * typedef struct tdNV_INDEX_DYNAMIC_EVENT_LOG_DATA {
* BYTE Signature[16]; * . BYTE Signature[16];
* UINT16 Version; * . UINT16 Version;
* UINT8[6] Reserved; * . UINT8[6] Reserved;
* UINT64 UID; * . UINT64 UID;
* UINT16 DescriptionSize; * . UINT16 DescriptionSize;
* UINT8 Description[DescriptionSize]; * . UINT8 Description[DescriptionSize];
* UINT16 DataSize; * . UINT16 DataSize;
* UINT8 Data[DataSize]; * . UINT8 Data[DataSize];
* } NV_INDEX_DYNAMIC_EVENT_LOG_DATA; * } NV_INDEX_DYNAMIC_EVENT_LOG_DATA;
* <p> * <p>
*/ */
@ -45,13 +43,16 @@ public class NvIndexDynamicEventLogData {
*/ */
public NvIndexDynamicEventLogData(final byte[] eventData) { public NvIndexDynamicEventLogData(final byte[] eventData) {
byte[] signatureBytes = new byte[16]; final int signatureBytesSize = 16;
System.arraycopy(eventData, 0, signatureBytes, 0, 16); byte[] signatureBytes = new byte[signatureBytesSize];
System.arraycopy(eventData, 0, signatureBytes, 0, signatureBytesSize);
signature = new String(signatureBytes, StandardCharsets.UTF_8); signature = new String(signatureBytes, StandardCharsets.UTF_8);
signature = signature.replaceAll("[^\\P{C}\t\r\n]", ""); // remove null characters signature = signature.replaceAll("[^\\P{C}\t\r\n]", ""); // remove null characters
byte[] versionBytes = new byte[2]; final int versionBytesSize = 2;
System.arraycopy(eventData, 16, versionBytes, 0, 2); final int eventDataSrcIndex1 = 16;
byte[] versionBytes = new byte[versionBytesSize];
System.arraycopy(eventData, eventDataSrcIndex1, versionBytes, 0, versionBytesSize);
String nvIndexVersion = HexUtils.byteArrayToHexString(versionBytes); String nvIndexVersion = HexUtils.byteArrayToHexString(versionBytes);
if (nvIndexVersion.isEmpty()) { if (nvIndexVersion.isEmpty()) {
nvIndexVersion = "version not readable"; nvIndexVersion = "version not readable";
@ -61,22 +62,28 @@ public class NvIndexDynamicEventLogData {
// 6 bytes of Reserved data // 6 bytes of Reserved data
byte[] uidBytes = new byte[8]; final int uidBytesSize = 8;
System.arraycopy(eventData, 24, uidBytes, 0, 8); final int eventDataSrcIndex2 = 24;
byte[] uidBytes = new byte[uidBytesSize];
System.arraycopy(eventData, eventDataSrcIndex2, uidBytes, 0, uidBytesSize);
String uid = HexUtils.byteArrayToHexString(uidBytes); String uid = HexUtils.byteArrayToHexString(uidBytes);
nvIndexDynamicInfo += " UID = " + uid + "\n"; nvIndexDynamicInfo += " UID = " + uid + "\n";
byte[] descriptionSizeBytes = new byte[2]; final int descriptionSizeBytesLength = 2;
System.arraycopy(eventData, 32, descriptionSizeBytes, 0, 2); final int eventDataSrcIndex3 = 32;
byte[] descriptionSizeBytes = new byte[descriptionSizeBytesLength];
System.arraycopy(eventData, eventDataSrcIndex3, descriptionSizeBytes, 0, descriptionSizeBytesLength);
int descriptionSize = HexUtils.leReverseInt(descriptionSizeBytes); int descriptionSize = HexUtils.leReverseInt(descriptionSizeBytes);
final int eventDataSrcIndex4 = 34;
byte[] descriptionBytes = new byte[descriptionSize]; byte[] descriptionBytes = new byte[descriptionSize];
System.arraycopy(eventData, 34, descriptionBytes, 0, descriptionSize); System.arraycopy(eventData, eventDataSrcIndex4, descriptionBytes, 0, descriptionSize);
String description = new String(descriptionBytes, StandardCharsets.UTF_8); String description = new String(descriptionBytes, StandardCharsets.UTF_8);
description = description.replaceAll("[^\\P{C}\t\r\n]", ""); // remove null characters description = description.replaceAll("[^\\P{C}\t\r\n]", ""); // remove null characters
nvIndexDynamicInfo += " Description = " + description + "\n"; nvIndexDynamicInfo += " Description = " + description + "\n";
int dataSizeStartByte = 34 + descriptionSize; final int dataSizeOffset = 34;
int dataSizeStartByte = dataSizeOffset + descriptionSize;
byte[] dataSizeBytes = new byte[2]; byte[] dataSizeBytes = new byte[2];
System.arraycopy(eventData, dataSizeStartByte, dataSizeBytes, 0, 2); System.arraycopy(eventData, dataSizeStartByte, dataSizeBytes, 0, 2);
int dataSize = HexUtils.leReverseInt(dataSizeBytes); int dataSize = HexUtils.leReverseInt(dataSizeBytes);

View File

@ -15,10 +15,10 @@ import java.nio.charset.StandardCharsets;
* Certain fields are common to both ..HEADER and ..HEADER2, and are noted below the structures. * Certain fields are common to both ..HEADER and ..HEADER2, and are noted below the structures.
* <p> * <p>
* typedef struct tdNV_INDEX_INSTANCE_EVENT_LOG_DATA { * typedef struct tdNV_INDEX_INSTANCE_EVENT_LOG_DATA {
* BYTE Signature[16]; * . BYTE Signature[16];
* UINT16 Version; * . UINT16 Version;
* UINT8[6] Reserved; * . UINT8[6] Reserved;
* DEVICE_SECURITY_EVENT_DATA2 Data; * . DEVICE_SECURITY_EVENT_DATA2 Data;
* } NV_INDEX_INSTANCE_EVENT_LOG_DATA; * } NV_INDEX_INSTANCE_EVENT_LOG_DATA;
* <p> * <p>
*/ */

View File

@ -15,22 +15,22 @@ import java.util.ArrayList;
* <p> * <p>
* Certificate chain format, defined by SPDM v1.03, Sect 10.6.1, Table 33: * Certificate chain format, defined by SPDM v1.03, Sect 10.6.1, Table 33:
* Certificate chain format { * Certificate chain format {
* Length 2 bytes; * . Length 2 bytes;
* Reserved 2 bytes; * . Reserved 2 bytes;
* RootHash <H> bytes; * . RootHash <H> bytes;
* Certificates <Length> - (4 + <H>) bytes; * . Certificates <Length> - (4 + <H>) bytes;
* } * }
* <p> * <p>
* Length: total length of cert chain including all fields in this block * Length: total length of cert chain including all fields in this block
* H: the output size of the hash algorithm selected by the most recent ALGORITHMS response * H: the output size of the hash algorithm selected by the most recent ALGORITHMS response
* this field shall be in hash byte order * . this field shall be in hash byte order
* hash algorithm is included in the DEVICE_SECURITY_EVENT_DATA_SUB_HEADER_SPDM_CERT_CHAIN * . hash algorithm is included in the DEVICE_SECURITY_EVENT_DATA_SUB_HEADER_SPDM_CERT_CHAIN
* structure as the member "SpdmBaseHashAlg" * . structure as the member "SpdmBaseHashAlg"
* RootHash: the digest of the Root Certificate. * RootHash: the digest of the Root Certificate.
* size is determined by hash algorithm selected by the most recent SPDM ALGORITHMS response; * . size is determined by hash algorithm selected by the most recent SPDM ALGORITHMS response;
* the hash algorithm is the DEVICE_SECURITY_EVENT_DATA_SUB_HEADER_SPDM_CERT_CHAIN SpdmBaseHashAlgo * . the hash algorithm is the DEVICE_SECURITY_EVENT_DATA_SUB_HEADER_SPDM_CERT_CHAIN SpdmBaseHashAlgo
* Certificates: Complete cert chain consisting of 1 or more ASN.1 DER-encoded X.509 v3 certs * Certificates: Complete cert chain consisting of 1 or more ASN.1 DER-encoded X.509 v3 certs
* this field shall be in Encoded ASN.1 byte order * . this field shall be in Encoded ASN.1 byte order
*/ */
public class SpdmCertificateChain { public class SpdmCertificateChain {

View File

@ -8,21 +8,21 @@ import lombok.Getter;
* <p> * <p>
* Measurement, defined by SPDM v1.03, Sect 10.11.1, Table 54: * Measurement, defined by SPDM v1.03, Sect 10.11.1, Table 54:
* DMTF measurement spec format { * DMTF measurement spec format {
* DMTFSpecMeasurementValueType 1 byte; * . DMTFSpecMeasurementValueType 1 byte;
* DMTFSpecMeasurementValueSize 2 bytes; * . DMTFSpecMeasurementValueSize 2 bytes;
* DMTFSpecMeasurementValue <DMTFSpecMeasurementValueSize> bytes; * . DMTFSpecMeasurementValue <DMTFSpecMeasurementValueSize> bytes;
* } * }
* <p> * <p>
* DMTFSpecMeasurementValueType[7] * DMTFSpecMeasurementValueType[7]
* Indicates how bits [0:6] are represented * . Indicates how bits [0:6] are represented
* Bit = 0: Digest * . Bit = 0: Digest
* Bit = 1: Raw bit stream * . Bit = 1: Raw bit stream
* DMTFSpecMeasurementValueType[6:0] (see SPDM Spec, Table 55 "DMTFSpecMeasurementValueType[6:0]") * DMTFSpecMeasurementValueType[6:0] (see SPDM Spec, Table 55 "DMTFSpecMeasurementValueType[6:0]")
* Immutable ROM 0x0 * . Immutable ROM 0x0
* Mutable firmware 0x1 * . Mutable firmware 0x1
* Hardware configuration 0x2 * . Hardware configuration 0x2
* Firmware configuration 0x3 * . Firmware configuration 0x3
* etc. * . etc.
* <p> * <p>
*/ */
public class SpdmMeasurement { public class SpdmMeasurement {

View File

@ -273,9 +273,9 @@ public final class UefiConstants {
public static final String FILESTATUS_FROM_FILESYSTEM = "fileFromFilesystem"; public static final String FILESTATUS_FROM_FILESYSTEM = "fileFromFilesystem";
/** /**
* file status, where file was not found on local machine, so file from code was used. * file status, where file was not found on local machine, so file from code was used.
* For instance, if vendor-table.json is not found in filesystem at location * . For instance, if vendor-table.json is not found in filesystem at location
* /etc/hirs/aca/default-properties/, it will be grabbed from code at * . /etc/hirs/aca/default-properties/, it will be grabbed from code at
* HIRS_AttestationCA/src/main/resources/. * . HIRS_AttestationCA/src/main/resources/.
*/ */
public static final String FILESTATUS_FROM_CODE = "fileFromCode"; public static final String FILESTATUS_FROM_CODE = "fileFromCode";
/** /**