spdm initial output

This commit is contained in:
iadgovuser58 2024-04-17 17:28:17 -04:00 committed by chubtub
parent 194865b4e6
commit 2fc515808d
7 changed files with 147 additions and 102 deletions

View File

@ -63,26 +63,26 @@ public class DeviceSecurityEventData {
*/ */
@Getter @Getter
private String version = ""; private String version = "";
/** // /**
* Contains the human-readable info inside the Device Security Event. // * Contains the human-readable info inside the Device Security Event.
*/ // */
@Getter // @Getter
private String dSEDinfo = ""; // private String dsedInfo = "";
/** /**
* DeviceSecurityEventDataHeader Object. * DeviceSecurityEventDataHeader Object.
*/ */
@Getter @Getter
private DeviceSecurityEventDataHeader dSEDheader = null; private DeviceSecurityEventDataHeader dsedHeader = null;
/** /**
* DeviceSecurityEventDataSubHeader Object. * DeviceSecurityEventDataSubHeader Object.
*/ */
@Getter // @Getter
private DeviceSecurityEventDataHeader dSEDsubHeader = null; // private DeviceSecurityEventDataSubHeader dsedSubHeader = null;
/** /**
* DeviceSecurityEventDataDeviceContext Object. * DeviceSecurityEventDataDeviceContext Object.
*/ */
@Getter @Getter
private DeviceSecurityEventDataDeviceContext dSEDdeviceContext = null; private DeviceSecurityEventDataDeviceContext dsedDeviceContext = null;
/** /**
* DeviceSecurityEventData Constructor. * DeviceSecurityEventData Constructor.
@ -95,56 +95,65 @@ public class DeviceSecurityEventData {
System.arraycopy(dSEDbytes, 0, signatureBytes, 0, UefiConstants.SIZE_16); System.arraycopy(dSEDbytes, 0, signatureBytes, 0, UefiConstants.SIZE_16);
//signature = HexUtils.byteArrayToHexString(signatureBytes); //signature = HexUtils.byteArrayToHexString(signatureBytes);
signature = new String(signatureBytes, StandardCharsets.UTF_8) signature = new String(signatureBytes, StandardCharsets.UTF_8)
.substring(0, UefiConstants.SIZE_15); .substring(0, UefiConstants.SIZE_15); // size 15 bc last letter is a 00 (null)
byte[] versionBytes = new byte[UefiConstants.SIZE_4]; byte[] versionBytes = new byte[UefiConstants.SIZE_2];
System.arraycopy(dSEDbytes, UefiConstants.OFFSET_16, versionBytes, 0, System.arraycopy(dSEDbytes, UefiConstants.OFFSET_16, versionBytes, 0,
UefiConstants.SIZE_4); UefiConstants.SIZE_2);
version = HexUtils.byteArrayToHexString(versionBytes); version = HexUtils.byteArrayToHexString(versionBytes);
// int byteOffset = 0;
// byteOffset = dsedHeader.getDsedHeaderByteSize();
// If version is 0x01, the event is a DEVICE_SECURITY_EVENT_DATA // If version is 0x01, the event is a DEVICE_SECURITY_EVENT_DATA
// If version is 0x02, the event is a DEVICE_SECURITY_EVENT_DATA2 // If version is 0x02, the event is a DEVICE_SECURITY_EVENT_DATA2
int byteOffset = 0; switch (version) {
dSEDheader = new DeviceSecurityEventDataHeader(dSEDbytes); case "0100":
byteOffset = dSEDheader.getDSEDheaderByteSize(); dsedHeader = new DeviceSecurityEventDataHeader(dSEDbytes);
if (version == "2") { // dsedDeviceContext = new DeviceSecurityEventDataDeviceContext(dSEDbytes,
// dSEDsubHeader = new DeviceSecurityEventDataSubHeader(dSEDbytes,byteOffset); // dsedHeader.getDSEDheaderByteSize());
// byteOffset = dSEDheader.getDSEDsubHeaderByteSize(); break;
} case "0200":
dSEDdeviceContext = new DeviceSecurityEventDataDeviceContext(dSEDbytes, byteOffset); dsedHeader = new DeviceSecurityEventDataHeader(dSEDbytes);
// dsedSubHeader = new DeviceSecurityEventDataSubHeader(dSEDbytes,byteOffset);
// byteOffset = dsedHeader.getDSEDsubHeaderByteSize();
// dsedDeviceContext = new DeviceSecurityEventDataDeviceContext(dSEDbytes, byteOffset);
break;
default:
break;
// if (version == "1") { // if (version == "1") {
// dSEDinfo =+ // dSEDinfo =+
// dSEDataHeader.getDSEDheaderInfo(); // dSEDataHeader.getDSEDheaderInfo();
// dSEDinfo =+ // dSEDinfo =+
// dSEDdeviceContext.getdSEDdeviceContextInfo(); // dsedDeviceContext.getdSEDdeviceContextInfo();
// } else if (version == "2") { // } else if (version == "2") {
// dSEDinfo =+ // dSEDinfo =+
// dSEDheader.getDSEDheaderInfo(); // dSEDheader.getDSEDheaderInfo();
// dSEDinfo =+ // dSEDinfo =+
// dSEDsubHeader.getDSEDsubHeaderInfo(); // dsedSubHeader.getDSEDsubHeaderInfo();
// dSEDinfo =+ // dSEDinfo =+
// dSEDdeviceContext.getDSEDdeviceContextInfo(); // dsedDeviceContext.getDSEDdeviceContextInfo();
// } // }
}
} }
public String toString() { public String toString() {
String specInfo = ""; String dsedInfo = "";
switch (version) {
specInfo += " Signature = SPDM Device Sec : "; case "0100":
// if (specIDEvent.isCryptoAgile()) { dsedInfo += dsedHeader.toString();
// specInfo += "Log format is Crypto Agile\n"; // dsedInfo += dsedDeviceContext.toString();
// } else { break;
// specInfo += "Log format is SHA 1 (NOT Crypto Agile)\n"; case "0200":
// } // dsedInfo += dsedHeader.toString();
// specInfo += " Platform Profile Specification version = " // dsedInfo += dsedSubHeader.toString();
// + specIDEvent.getVersionMajor() + "." + specIDEvent.getVersionMinor() // dsedInfo += dsedDeviceContext.toString();
// + " using errata version " + specIDEvent.getErrata(); break;
// specInfo += DeviceSecurityEventData.toString(); default:
// } else { dsedInfo += " Unknown SPDM Device Security Event Data version " + version + " found" + "\n";
// specInfo = "EV_EFI_SPDM_FIRMWARE_BLOB event named " + signature }
// + " encountered but support for processing it has not been added to this application.\n"; return dsedInfo;
// }
return specInfo;
} }
} }

View File

@ -30,7 +30,7 @@ import java.util.List;
* 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 { * typedef struct tdDEVICE_SECURITY_EVENT_DATA_HEADER2 { - NOT IMPLEMENTED YET
* UINT8 Signature[16]; * UINT8 Signature[16];
* UINT16 Version; * UINT16 Version;
* UINT8 AuthState; * UINT8 AuthState;
@ -73,11 +73,14 @@ import java.util.List;
*/ */
public class DeviceSecurityEventDataHeader { public class DeviceSecurityEventDataHeader {
/** // /**
* Contains the human-readable info inside the Device Security Event. // * Contains the human-readable info inside the Device Security Event.
// */
// @Getter
// private String dSEDheaderInfo = "";
/** ----------- Variables common to all Header Types -----------
*/ */
@Getter
private String dSEDheaderInfo = "";
/** /**
* Contains the size (in bytes) of the Header. * Contains the size (in bytes) of the Header.
*/ */
@ -94,21 +97,42 @@ public class DeviceSecurityEventDataHeader {
*/ */
@Getter @Getter
private String version = ""; private String version = "";
/**
* Event data length.
*/
@Getter
private String length = "";
/**
* SPDM hash algorithm.
*/
@Getter
private String spdmHashAlgo = "";
/** /**
* Device type. * Device type.
*/ */
@Getter @Getter
private String deviceType = ""; private String deviceType = "";
/**
* Device path length.
*/
@Getter
private String devicePathLength = "";
/**
* Device path.
*/
@Getter
private String devicePath = "";
/** ----------- Variables specific to Header Type 1 -----------
/**
* Type Header 1 event data length.
*/
@Getter
private String h1Length = "";
/**
* Type Header 1 SPDM hash algorithm.
*/
@Getter
private String h1SpdmHashAlgo = "";
/**
* Type Header 1 SPDM measurement block.
*/
@Getter
private String h1SpdmMeasurementBlock = "";
/** ----------- Variables specific to Header Type 2 -----------
*/
// TBD
/** /**
* DeviceSecurityEventDataHeader Constructor. * DeviceSecurityEventDataHeader Constructor.
@ -123,33 +147,26 @@ public class DeviceSecurityEventDataHeader {
signature = new String(signatureBytes, StandardCharsets.UTF_8) signature = new String(signatureBytes, StandardCharsets.UTF_8)
.substring(0, UefiConstants.SIZE_15); .substring(0, UefiConstants.SIZE_15);
byte[] versionBytes = new byte[UefiConstants.SIZE_4]; byte[] versionBytes = new byte[UefiConstants.SIZE_2];
System.arraycopy(dSEDbytes, UefiConstants.OFFSET_16, versionBytes, 0, System.arraycopy(dSEDbytes, UefiConstants.OFFSET_16, versionBytes, 0,
UefiConstants.SIZE_4); UefiConstants.SIZE_2);
version = HexUtils.byteArrayToHexString(versionBytes); version = HexUtils.byteArrayToHexString(versionBytes);
byte[] lengthBytes = new byte[UefiConstants.SIZE_4]; byte[] lengthBytes = new byte[UefiConstants.SIZE_2];
System.arraycopy(dSEDbytes, UefiConstants.OFFSET_20, lengthBytes, 0, System.arraycopy(dSEDbytes, 18, lengthBytes, 0,
UefiConstants.SIZE_4); UefiConstants.SIZE_2);
length = HexUtils.byteArrayToHexString(lengthBytes); h1Length = HexUtils.byteArrayToHexString(lengthBytes);
byte[] spdmHashAlgoBytes = new byte[UefiConstants.SIZE_8]; byte[] spdmHashAlgoBytes = new byte[UefiConstants.SIZE_4];
System.arraycopy(dSEDbytes, UefiConstants.OFFSET_24, spdmHashAlgoBytes, 0, System.arraycopy(dSEDbytes, UefiConstants.OFFSET_20, spdmHashAlgoBytes, 0,
UefiConstants.SIZE_4); UefiConstants.SIZE_4);
spdmHashAlgo = HexUtils.byteArrayToHexString(spdmHashAlgoBytes); h1SpdmHashAlgo = HexUtils.byteArrayToHexString(spdmHashAlgoBytes);
byte[] deviceTypeBytes = new byte[UefiConstants.SIZE_8]; byte[] deviceTypeBytes = new byte[UefiConstants.SIZE_4];
System.arraycopy(dSEDbytes, UefiConstants.OFFSET_24, deviceTypeBytes, 0, System.arraycopy(dSEDbytes, UefiConstants.OFFSET_24, deviceTypeBytes, 0,
UefiConstants.SIZE_4); UefiConstants.SIZE_4);
deviceType = HexUtils.byteArrayToHexString(deviceTypeBytes); deviceType = HexUtils.byteArrayToHexString(deviceTypeBytes);
// byte[] specVersionMajorBytes = new byte[1];
// System.arraycopy(efiSpecId, UefiConstants.OFFSET_21, specVersionMajorBytes, 0, 1);
// versionMajor = HexUtils.byteArrayToHexString(specVersionMajorBytes);
//
// byte[] specErrataBytes = new byte[1];
// System.arraycopy(efiSpecId, UefiConstants.OFFSET_22, specErrataBytes, 0, 1);
// errata = HexUtils.byteArrayToHexString(specErrataBytes);
// //
// byte[] numberOfAlgBytes = new byte[UefiConstants.SIZE_4]; // byte[] numberOfAlgBytes = new byte[UefiConstants.SIZE_4];
// System.arraycopy(efiSpecId, UefiConstants.OFFSET_24, numberOfAlgBytes, 0, // System.arraycopy(efiSpecId, UefiConstants.OFFSET_24, numberOfAlgBytes, 0,
@ -170,23 +187,24 @@ public class DeviceSecurityEventDataHeader {
// cryptoAgile = true; // cryptoAgile = true;
// } // }
} }
//
// /**
// * Returns a human readable description of the data within this event.
// *
// * @return a description of this event..
// */
// public String toString() {
// String specInfo = "";
// if (signature.equals("Spec ID Event#")) {
// specInfo += "Platform Profile Specification version = " + versionMajor + "." + versionMinor
// + " using errata version" + errata;
// } else {
// specInfo = "EV_NO_ACTION event named " + signature
// + " encountered but support for processing it has not been added to this application";
// }
// return specInfo;
// }
/**
* Returns a human readable description of the data within this event.
*
* @return a description of this event..
*/
public String toString() {
String dsedHeaderInfo = "";
if (version.equals("0100")) {
dsedHeaderInfo += "\n SPDM hash algorithm = " + h1SpdmHashAlgo;
dsedHeaderInfo += "\n SPDM Device";
dsedHeaderInfo += "\n Device Type: " + deviceType;
dsedHeaderInfo += "\n Device Path: " + devicePath;
dsedHeaderInfo += "\n SPDM Measurement Block " + h1SpdmMeasurementBlock;
} else if(version.equals("0200")) {
dsedHeaderInfo = "tbd";
}
return dsedHeaderInfo;
}
} }

View File

@ -80,22 +80,14 @@ public class EvEfiSpdmFirmwareBlob {
* @return Human readable description of this event. * @return Human readable description of this event.
*/ */
public String toString() { public String toString() {
String specInfo = ""; String spdmInfo = "";
if (bDeviceSecurityEventData) { if (bDeviceSecurityEventData) {
specInfo += " Signature = SPDM Device Sec : "; spdmInfo += " Signature = SPDM Device Sec";
// if (specIDEvent.isCryptoAgile()) { spdmInfo += deviceSecurityEventData.toString();
// specInfo += "Log format is Crypto Agile\n";
// } else {
// specInfo += "Log format is SHA 1 (NOT Crypto Agile)\n";
// }
// specInfo += " Platform Profile Specification version = "
// + specIDEvent.getVersionMajor() + "." + specIDEvent.getVersionMinor()
// + " using errata version " + specIDEvent.getErrata();
// specInfo += DeviceSecurityEventData.toString();
} else { } else {
specInfo = "EV_EFI_SPDM_FIRMWARE_BLOB event named " + signature spdmInfo = "EV_EFI_SPDM_FIRMWARE_BLOB event named " + signature
+ " encountered but support for processing it has not been added to this application.\n"; + " encountered but support for processing it has not been added to this application.\n";
} }
return specInfo; return spdmInfo;
} }
} }

View File

@ -0,0 +1,13 @@
package hirs.utils.tpm.eventlog.spdm;
public class SpdmMeasurement {
public SpdmMeasurement(final byte[] spdmMeasBytes) {
}
public String toString() {
return "TEMP TEST SpdmMeasurement";
}
}

View File

@ -0,0 +1,13 @@
package hirs.utils.tpm.eventlog.spdm;
public class SpdmMeasurementBlock {
public SpdmMeasurementBlock(final byte[] spdmMeasBlockBytes) {
}
public String toString() {
return "TEMP TEST spdmMeasBlockBytes";
}
}