parsing event

This commit is contained in:
iadgovuser58 2024-04-09 18:02:53 -04:00 committed by chubtub
parent 9809be29ee
commit a544713448
2 changed files with 120 additions and 21 deletions

View File

@ -37,5 +37,104 @@ import java.util.List;
* 4. First 16 bytes of the structure header is an ASCII "SPDM Device Sec" * 4. First 16 bytes of the structure header is an ASCII "SPDM Device Sec"
*/ */
public class DeviceSecurityEventData { public class DeviceSecurityEventData {
// /**
// * 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 version = "";
// /**
// * Algorithm count.
// */
// @Getter
// private int numberOfAlg = 0;
// /**
// * True if event log uses Crypto Agile format.
// */
// @Getter
// private boolean cryptoAgile = false;
// /**
// * Algorithm list.
// */
// private List<String> algList;
/**
* DeviceSecurityEventData Constructor.
*
* @param deviceSecurityEventDataBytes byte array holding the spec ID Event.
*/
public DeviceSecurityEventData(final byte[] deviceSecurityEventDataBytes) {
// algList = new ArrayList<>();
byte[] signatureBytes = new byte[UefiConstants.SIZE_16];
System.arraycopy(deviceSecurityEventDataBytes, 0, signatureBytes, 0, UefiConstants.SIZE_16);
//signature = HexUtils.byteArrayToHexString(signatureBytes);
signature = new String(signatureBytes, StandardCharsets.UTF_8)
.substring(0, UefiConstants.SIZE_15);
byte[] versionBytes = new byte[UefiConstants.SIZE_4];
System.arraycopy(deviceSecurityEventDataBytes, UefiConstants.OFFSET_16, versionBytes, 0,
UefiConstants.SIZE_4);
version = HexUtils.byteArrayToHexString(versionBytes);
if (version == "1") {
} else if (version == "2") {
}
// byte[] platformClassBytes = new byte[UefiConstants.SIZE_4];
// System.arraycopy(efiSpecId, UefiConstants.OFFSET_16, platformClassBytes, 0,
// UefiConstants.SIZE_4);
// platformClass = HexUtils.byteArrayToHexString(platformClassBytes);
//
// byte[] specVersionMinorBytes = new byte[1];
// System.arraycopy(efiSpecId, UefiConstants.OFFSET_20, specVersionMinorBytes, 0, 1);
// versionMinor = HexUtils.byteArrayToHexString(specVersionMinorBytes);
//
// 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];
// System.arraycopy(efiSpecId, UefiConstants.OFFSET_24, numberOfAlgBytes, 0,
// UefiConstants.SIZE_4);
// numberOfAlg = HexUtils.leReverseInt(numberOfAlgBytes);
//
// byte[] algorithmIDBytes = new byte[UefiConstants.SIZE_2];
// int algLocation = UefiConstants.SIZE_28;
// for (int i = 0; i < numberOfAlg; i++) {
// System.arraycopy(efiSpecId, algLocation + UefiConstants.OFFSET_4 * i, algorithmIDBytes,
// 0, UefiConstants.SIZE_2);
// String alg = TcgTpmtHa.tcgAlgIdToString(HexUtils.leReverseInt(algorithmIDBytes));
// algList.add(alg);
// }
// if ((algList.size() == 1) && (algList.get(0).compareTo("SHA1") == 0)) {
// cryptoAgile = false;
// } else {
// cryptoAgile = true;
// }
}
} }

View File

@ -55,22 +55,22 @@ public class EvEfiSpdmFirmwareBlob {
*/ */
public EvEfiSpdmFirmwareBlob(final byte[] eventData) throws UnsupportedEncodingException { public EvEfiSpdmFirmwareBlob(final byte[] eventData) throws UnsupportedEncodingException {
byte[] signatureBytes = new byte[UefiConstants.SIZE_15]; byte[] signatureBytes = new byte[UefiConstants.SIZE_15];
// System.arraycopy(eventData, 0, signatureBytes, 0, UefiConstants.SIZE_15); System.arraycopy(eventData, 0, signatureBytes, 0, UefiConstants.SIZE_15);
// 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
// if (signature.contains("Spec ID Event03")) { // implies CryptAgileFormat if (signature.contains("SPDM Device Sec")) { // implies Device Security event
// specIDEvent = new EvEfiSpecIdEvent(eventData); deviceSecurityEventData = new DeviceSecurityEventData(eventData);
// bSpecIDEvent = true; bDeviceSecurityEventData = true;
// } }
} }
/** /**
* Determines if this event is a SpecIDEvent. * Determines if this event is a DeviceSecurityEventData.
* *
* @return true of the event is a SpecIDEvent. * @return true of the event is a DeviceSecurityEventData.
*/ */
public boolean isDeviceSecurityEventDataHeader() { public boolean isDeviceSecurityEventData() {
return bDeviceSecurityEventDataHeader; return bDeviceSecurityEventData;
} }
/** /**
@ -78,10 +78,10 @@ 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 specInfo = "";
// if (bSpecIDEvent) { if (bDeviceSecurityEventData) {
// specInfo += " Signature = Spec ID Event03 : "; specInfo += " Signature = SPDM Device Sec : ";
// if (specIDEvent.isCryptoAgile()) { // if (specIDEvent.isCryptoAgile()) {
// specInfo += "Log format is Crypto Agile\n"; // specInfo += "Log format is Crypto Agile\n";
// } else { // } else {
@ -90,10 +90,10 @@ public class EvEfiSpdmFirmwareBlob {
// specInfo += " Platform Profile Specification version = " // specInfo += " Platform Profile Specification version = "
// + specIDEvent.getVersionMajor() + "." + specIDEvent.getVersionMinor() // + specIDEvent.getVersionMajor() + "." + specIDEvent.getVersionMinor()
// + " using errata version " + specIDEvent.getErrata(); // + " using errata version " + specIDEvent.getErrata();
// } else { } else {
// specInfo = "EV_NO_ACTION event named " + signature specInfo = "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 specInfo;
// } }
} }