diff --git a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventData2.java b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventData2.java index 7a2c2479..b4a2b915 100644 --- a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventData2.java +++ b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventData2.java @@ -59,8 +59,8 @@ public class DeviceSecurityEventData2 extends DeviceSecurityEvent { int subHeaderType = dsedHeader2.getSubHeaderType(); int subHeaderLength = dsedHeader2.getSubHeaderLength(); - subHeaderInfo = "\n Sub header type: " - + DeviceSecurityEventDataSubHeader.subheaderTypeToString(subHeaderType); + subHeaderInfo = " Sub header type: " + + DeviceSecurityEventDataSubHeader.subheaderTypeToString(subHeaderType) + "\n"; byte[] dsedSubHeaderBytes = new byte[subHeaderLength]; System.arraycopy(dsedBytes, dsedHeaderLength, dsedSubHeaderBytes, 0, subHeaderLength); @@ -72,22 +72,21 @@ public class DeviceSecurityEventData2 extends DeviceSecurityEvent { subHeaderInfo += dsedSubHeader.toString(); } catch(NullPointerException e) { - subHeaderInfo = "\n Could not interpret Sub header info for SPDM measurment block"; + subHeaderInfo = " Could not interpret Sub header info for SPDM measurment block\n"; } } else if (subHeaderType == DeviceSecurityEventDataSubHeader.SUBHEADERTYPE_CERT_CHAIN) { -// subHeaderInfo += "\n Cert chain to be implemented "; try { dsedSubHeader = new DeviceSecurityEventDataSubHeaderCertChain(dsedSubHeaderBytes); subHeaderInfo += dsedSubHeader.toString(); } catch(NullPointerException e) { - subHeaderInfo = "\n Could not interpret Sub header info for SPDM cert chain"; + subHeaderInfo = " Could not interpret Sub header info for SPDM cert chain\n"; } } else { - subHeaderInfo += "\n Sub header type unknown"; + subHeaderInfo += " Sub header type unknown\n"; } int dsedDevContextStartByte = dsedHeaderLength + subHeaderLength; @@ -99,7 +98,7 @@ public class DeviceSecurityEventData2 extends DeviceSecurityEvent { instantiateDeviceContext(dsedDevContextBytes); } catch(NullPointerException e) { - headerInfo = " Could not interpret Header info"; + headerInfo = " Could not interpret Header info\n"; } } 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 index c773ce05..0a9f2088 100644 --- 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 @@ -65,7 +65,7 @@ public abstract class DeviceSecurityEventDataDeviceContext { public String toString() { String dSEDdeviceContextCommonInfo = ""; - dSEDdeviceContextCommonInfo += "\n DeviceSecurityEventData Device Context:"; + dSEDdeviceContextCommonInfo += " DeviceSecurityEventData Device Context:\n"; return dSEDdeviceContextCommonInfo; } 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 index 1a8838e2..f0e56c74 100644 --- 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 @@ -109,8 +109,8 @@ public class DeviceSecurityEventDataHeader extends DeviceSecurityEventHeader { dsedHeaderInfo += super.toString(); String spdmHashAlgoStr = SpdmHa.tcgAlgIdToString(spdmHashAlgo); - dsedHeaderInfo += "\n SPDM Hash Algorithm = " + spdmHashAlgoStr; - dsedHeaderInfo += "\n SPDM Measurement Block:"; + dsedHeaderInfo += " SPDM Hash Algorithm = " + spdmHashAlgoStr + "\n"; + dsedHeaderInfo += " SPDM Measurement Block:\n"; dsedHeaderInfo += spdmMeasurementBlockInfo; return dsedHeaderInfo; diff --git a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventDataHeader2.java b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventDataHeader2.java index 56934fef..4bdb8cef 100644 --- a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventDataHeader2.java +++ b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventDataHeader2.java @@ -124,8 +124,8 @@ public class DeviceSecurityEventDataHeader2 extends DeviceSecurityEventHeader { String dsedHeader2Info = ""; dsedHeader2Info += super.toString(); - dsedHeader2Info += "\n AuthState: " + getAuthStateString(); - dsedHeader2Info += "\n Sub header UID: " + subHeaderUid; + dsedHeader2Info += " AuthState: " + getAuthStateString() + "\n"; + dsedHeader2Info += " Sub header UID: " + subHeaderUid + "\n"; return dsedHeader2Info; } diff --git a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventDataPciContext.java b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventDataPciContext.java index 4f16a1e5..280470ba 100644 --- a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventDataPciContext.java +++ b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventDataPciContext.java @@ -114,22 +114,22 @@ public class DeviceSecurityEventDataPciContext extends DeviceSecurityEventDataDe String dSEDpciContextInfo = ""; dSEDpciContextInfo += super.toString(); - dSEDpciContextInfo += "\n Device Type = PCI"; - dSEDpciContextInfo += "\n Vendor = " + translateVendor(vendorId); - dSEDpciContextInfo += "\n Device = " + translateDevice(vendorId, deviceId); - dSEDpciContextInfo += "\n RevisionID = " + revisionId; + dSEDpciContextInfo += " Device Type = PCI\n"; + dSEDpciContextInfo += " Vendor = " + translateVendor(vendorId) + "\n"; + dSEDpciContextInfo += " Device = " + translateDevice(vendorId, deviceId) + "\n"; + dSEDpciContextInfo += " RevisionID = " + revisionId + "\n"; List classCodeList = translateDeviceClass(classCode); - dSEDpciContextInfo += "\n Device Class: "; + dSEDpciContextInfo += " Device Class: \n"; if(classCodeList.size() == 3) { - dSEDpciContextInfo += "\n Class = " + classCodeList.get(0); - dSEDpciContextInfo += "\n Subclass = " + classCodeList.get(1); - dSEDpciContextInfo += "\n Programming Interface = " + classCodeList.get(2); + dSEDpciContextInfo += " Class = " + classCodeList.get(0) + "\n"; + dSEDpciContextInfo += " Subclass = " + classCodeList.get(1) + "\n"; + dSEDpciContextInfo += " Programming Interface = " + classCodeList.get(2) + "\n"; } else { dSEDpciContextInfo += " ** Class code could not be determined **"; } - dSEDpciContextInfo += "\n SubsystemVendor = " + translateVendor(subsystemVendorId); - dSEDpciContextInfo += "\n Subsystem = " + translateDevice(subsystemVendorId, subsystemId); + dSEDpciContextInfo += " SubsystemVendor = " + translateVendor(subsystemVendorId) + "\n"; + dSEDpciContextInfo += " Subsystem = " + translateDevice(subsystemVendorId, subsystemId) + "\n"; return dSEDpciContextInfo; } diff --git a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventDataSubHeaderCertChain.java b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventDataSubHeaderCertChain.java index dc7c22c3..1818e0a5 100644 --- a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventDataSubHeaderCertChain.java +++ b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventDataSubHeaderCertChain.java @@ -96,10 +96,10 @@ public class DeviceSecurityEventDataSubHeaderCertChain extends DeviceSecurityEve */ public String toString() { String dsedSubHeaderInfo = ""; - dsedSubHeaderInfo += "\n SPDM Version = " + spdmVersion; - dsedSubHeaderInfo += "\n SPDM Slot ID = " + spdmSlotId; + dsedSubHeaderInfo += " SPDM Version = " + spdmVersion + "\n"; + dsedSubHeaderInfo += " SPDM Slot ID = " + spdmSlotId + "\n"; String spdmBaseHashAlgoStr = SpdmHa.tcgAlgIdToString(spdmBaseHashAlgo); - dsedSubHeaderInfo += "\n SPDM Base Hash Algorithm = " + spdmBaseHashAlgoStr; + dsedSubHeaderInfo += " SPDM Base Hash Algorithm = " + spdmBaseHashAlgoStr + "\n"; // SPDM Certificate Chain output dsedSubHeaderInfo += spdmCertChain.toString(); diff --git a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventDataSubHeaderSpdmMeasurementBlock.java b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventDataSubHeaderSpdmMeasurementBlock.java index 19c5d42a..81742744 100644 --- a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventDataSubHeaderSpdmMeasurementBlock.java +++ b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventDataSubHeaderSpdmMeasurementBlock.java @@ -100,16 +100,16 @@ public class DeviceSecurityEventDataSubHeaderSpdmMeasurementBlock extends Device */ public String toString() { String dsedSubHeaderInfo = ""; - dsedSubHeaderInfo += "\n SPDM Version = " + spdmVersion; + dsedSubHeaderInfo += " SPDM Version = " + spdmVersion + "\n"; String spdmHashAlgoStr = SpdmHa.tcgAlgIdToString(spdmMeasurementHashAlgo); - dsedSubHeaderInfo += "\n SPDM Hash Algorithm = " + spdmHashAlgoStr; + dsedSubHeaderInfo += " SPDM Hash Algorithm = " + spdmHashAlgoStr + "\n"; // SPDM Measurement Block List output - dsedSubHeaderInfo += "\n Number of SPDM Measurement Blocks = " + spdmMeasurementBlockList.size(); + dsedSubHeaderInfo += " Number of SPDM Measurement Blocks = " + spdmMeasurementBlockList.size() + "\n"; int spdmMeasBlockCnt = 1; for (SpdmMeasurementBlock spdmMeasBlock : spdmMeasurementBlockList) { - dsedSubHeaderInfo += "\n SPDM Measurement Block # " + spdmMeasBlockCnt++ + " of " + - spdmMeasurementBlockList.size(); + dsedSubHeaderInfo += " SPDM Measurement Block # " + spdmMeasBlockCnt++ + " of " + + spdmMeasurementBlockList.size() + "\n"; dsedSubHeaderInfo += spdmMeasBlock.toString(); } diff --git a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventHeader.java b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventHeader.java index 894bd68a..71b95cab 100644 --- a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventHeader.java +++ b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/DeviceSecurityEventHeader.java @@ -147,7 +147,7 @@ public abstract class DeviceSecurityEventHeader { // get the device path if (devicePathLength != 0) { - startByte = startByte + UefiConstants.SIZE_8; + startByte = startByte + 8; byte[] devPathBytes = new byte[devicePathLength]; System.arraycopy(dsedBytes, startByte, devPathBytes, 0, devicePathLength); @@ -192,13 +192,13 @@ public abstract class DeviceSecurityEventHeader { public String toString() { String dsedHeaderCommonInfo = ""; - dsedHeaderCommonInfo += "\n SPDM Device Type = " + deviceTypeToString(deviceType); + dsedHeaderCommonInfo += " SPDM Device Type = " + deviceTypeToString(deviceType) + "\n"; if (devicePathValid) { - dsedHeaderCommonInfo += "\n SPDM Device Path:\n"; + dsedHeaderCommonInfo += " SPDM Device Path:\n"; dsedHeaderCommonInfo += devicePath; } else { - dsedHeaderCommonInfo += "\n SPDM Device Path = Unknown or invalid"; + dsedHeaderCommonInfo += " SPDM Device Path = Unknown or invalid\n"; } return dsedHeaderCommonInfo; diff --git a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/EvEfiBootServicesApp.java b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/EvEfiBootServicesApp.java index 36c13e33..31e168d9 100644 --- a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/EvEfiBootServicesApp.java +++ b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/EvEfiBootServicesApp.java @@ -117,15 +117,15 @@ public class EvEfiBootServicesApp { * @return a human readable string. */ public String toString() { - String info = "Image info: "; - info += " Image physical address: " + HexUtils.byteArrayToHexString(physicalAddress); - info += " Image length = " + imageLength; - info += " Image link time address: " + HexUtils.byteArrayToHexString(physicalAddress); - info += " Device path length = " + devicePathLength; + String info = " Image info:\n"; + info += " Image physical address = " + HexUtils.byteArrayToHexString(physicalAddress) + "\n"; + info += " Image length = " + imageLength + "\n"; + info += " Image link time address = " + HexUtils.byteArrayToHexString(physicalAddress) + "\n"; + info += " Device path length = " + devicePathLength + "\n"; if (devicePathValid) { - info += "\n" + devicePath.toString(); + info += devicePath.toString() + "\n"; } else { - info += "\n No uefi device paths were specified"; + info += " No uefi device paths were specified\n"; } return info; } diff --git a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/EvEfiHandoffTable.java b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/EvEfiHandoffTable.java index 758e91e8..9b931f24 100644 --- a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/EvEfiHandoffTable.java +++ b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/EvEfiHandoffTable.java @@ -128,14 +128,15 @@ public class EvEfiHandoffTable { */ public String toString() { StringBuilder tableInfo = new StringBuilder(); - tableInfo.append("Number of UEFI_CONFIGURATION_TABLEs = " + numberOfTables + "\n"); + tableInfo.append(" Number of UEFI_CONFIGURATION_TABLEs = " + numberOfTables + "\n"); for (int i = 0; i < numberOfTables; i++) { UefiGuid currentGuid = vendorGuids.get(i); - tableInfo.append(" Table " + i + ": " + currentGuid.toString()); - tableInfo.append(" UEFI industry standard table type = " + tableInfo.append(" Table " + i + ":\n"); + tableInfo.append(" GUID = " + currentGuid.toString() + "\n"); + tableInfo.append(" UEFI industry standard table type = " + currentGuid.getVendorTableReference() + "\n"); - tableInfo.append(" VendorTable " + i + " address: " - + HexUtils.byteArrayToHexString(vendorTables.get(i))); + tableInfo.append(" VendorTable " + i + " address: " + + HexUtils.byteArrayToHexString(vendorTables.get(i)) + "\n"); } return tableInfo.toString(); } diff --git a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/EvEfiSpdmDeviceSecurityEvent.java b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/EvEfiSpdmDeviceSecurityEvent.java index 28b42cdc..56b0d5f1 100644 --- a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/EvEfiSpdmDeviceSecurityEvent.java +++ b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/EvEfiSpdmDeviceSecurityEvent.java @@ -67,30 +67,30 @@ public class EvEfiSpdmDeviceSecurityEvent { if (dsedSignature.contains("SPDM Device Sec2")) { - spdmInfo = " Signature = SPDM Device Sec2"; + spdmInfo = " Signature = SPDM Device Sec2\n"; if (dsedVersion.equals("0200")) { dsed = new DeviceSecurityEventData2(eventData); spdmInfo += dsed.toString(); } else { - spdmInfo += " Incompatible version for DeviceSecurityEventData2: " + dsedVersion; + spdmInfo += " Incompatible version for DeviceSecurityEventData2: " + dsedVersion + "\n"; } } else if (dsedSignature.contains("SPDM Device Sec")) { // implies Device Security event - spdmInfo = " Signature = SPDM Device Sec"; + spdmInfo = " Signature = SPDM Device Sec\n"; if (dsedVersion.equals("0100")) { dsed = new DeviceSecurityEventData(eventData); spdmInfo += dsed.toString(); } else { - spdmInfo += " Incompatible version for DeviceSecurityEventData: " + dsedVersion; + spdmInfo += " Incompatible version for DeviceSecurityEventData: " + dsedVersion + "\n"; } } else { - spdmInfo = " Signature = Undetermined value: " + dsedSignature; + spdmInfo = " Signature = Undetermined value: " + dsedSignature + "\n"; } } diff --git a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/NvIndexInstanceEventLogData.java b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/NvIndexInstanceEventLogData.java index 4bd4c59b..68321113 100644 --- a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/NvIndexInstanceEventLogData.java +++ b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/events/NvIndexInstanceEventLogData.java @@ -84,21 +84,20 @@ public class NvIndexInstanceEventLogData { byte[] dsedEventData = new byte[dsedEventDataSize]; System.arraycopy(eventData, 24, dsedEventData, 0, dsedEventDataSize); - nvIndexInstanceInfo = " Signature = SPDM Device Sec2"; + nvIndexInstanceInfo = " Signature = SPDM Device Sec2\n"; if (dsedVersion.equals("0200")) { - // TODO this is throwing a nullPointerException dsed = new DeviceSecurityEventData2(dsedEventData); nvIndexInstanceInfo += dsed.toString(); } else { nvIndexInstanceInfo += " Incompatible version for DeviceSecurityEventData2: " - + dsedVersion; + + dsedVersion + "\n"; } } else { nvIndexInstanceInfo = " Signature error: should be \'SPDM Device Sec2\' but is " - + signature; + + signature + "\n"; } } diff --git a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/spdm/SpdmCertificateChain.java b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/spdm/SpdmCertificateChain.java index 91efedf3..d286e4b3 100644 --- a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/spdm/SpdmCertificateChain.java +++ b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/spdm/SpdmCertificateChain.java @@ -111,21 +111,21 @@ public class SpdmCertificateChain { // java.security.cert.CertificateException if there's a problem parsing the X509 certificate. // java.security.NoSuchAlgorithmException if there's a problem hashing the certificate. try { - byte[] certType = new byte[UefiConstants.SIZE_2]; + byte[] certType = new byte[2]; certChainDataIS.read(certType); - byte[] certLength = new byte[UefiConstants.SIZE_2]; + byte[] certLength = new byte[2]; certChainDataIS.read(certLength); - int cLength = new BigInteger(certLength).intValue() + UefiConstants.SIZE_4; +// int cLength = new BigInteger(certLength).intValue() + UefiConstants.SIZE_4; + int cLength = new BigInteger(certLength).intValue(); byte[] certData = new byte[cLength]; certChainDataIS.read(certData); // put the cert back together - byte[] certBlob = new byte[cLength + UefiConstants.SIZE_4]; + byte[] certBlob = new byte[cLength + 4]; System.arraycopy(certType, 0, certBlob, 0, 2); System.arraycopy(certLength, 0, certBlob, 2, 2); - System.arraycopy(certData, 0, certBlob, UefiConstants.OFFSET_4, cLength); - + System.arraycopy(certData, 0, certBlob, 4, cLength); cert = new UefiX509Cert(certBlob); -// cert = new X509Certificate(certBlob); + //cert = new X509Certificate(certBlob); certList.add(cert); numberOfCerts++; } catch (IOException e) { @@ -154,13 +154,13 @@ public class SpdmCertificateChain { String spdmCertChainInfo = ""; if(spdmBaseHashAlgoError != "") { - spdmCertChainInfo += "\n *** ERROR with SPDM base hash algorithm size ***"; - spdmCertChainInfo += "\n " + spdmBaseHashAlgoError; - spdmCertChainInfo += "\n Stopping processing of this cert chain"; + spdmCertChainInfo += " *** ERROR with SPDM base hash algorithm size ***\n"; + spdmCertChainInfo += " " + spdmBaseHashAlgoError + "\n"; + spdmCertChainInfo += " Stopping processing of this cert chain\n"; } else { - spdmCertChainInfo += "\n Root hash = " + HexUtils.byteArrayToHexString(rootHash); - spdmCertChainInfo += "\n Number of certs in chain = " + numberOfCerts + "\n"; + spdmCertChainInfo += " Root hash = " + HexUtils.byteArrayToHexString(rootHash) + "\n"; + spdmCertChainInfo += " Number of certs in chain = " + numberOfCerts + "\n"; int certCnt = 1; for (UefiX509Cert cert : certList) { @@ -170,9 +170,9 @@ public class SpdmCertificateChain { } if (certProcessingError != "") { - spdmCertChainInfo += " *** ERROR processing cert ***"; - spdmCertChainInfo += "\n " + certProcessingError; - spdmCertChainInfo += "\n Stopping processing of this cert chain"; + spdmCertChainInfo += " *** ERROR processing cert ***\n"; + spdmCertChainInfo += " " + certProcessingError + "\n"; + spdmCertChainInfo += " Stopping processing of this cert chain\n"; } } return spdmCertChainInfo; diff --git a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/spdm/SpdmMeasurement.java b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/spdm/SpdmMeasurement.java index 504983cd..417a6c28 100644 --- a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/spdm/SpdmMeasurement.java +++ b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/spdm/SpdmMeasurement.java @@ -119,10 +119,11 @@ public class SpdmMeasurement { public String toString() { String spdmMeasInfo = ""; - spdmMeasInfo += "\n SPDM Measurement Value Type = " + + spdmMeasInfo += " SPDM Measurement Value Type = " + dmtfSpecMeasurementValueTypeToString(dmtfSpecMeasurementValueType); spdmMeasInfo += "\n SPDM Measurement Value = " + HexUtils.byteArrayToHexString(dmtfSpecMeasurementValue); + spdmMeasInfo += "\n"; return spdmMeasInfo; } diff --git a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/spdm/SpdmMeasurementBlock.java b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/spdm/SpdmMeasurementBlock.java index 12724125..ac486ab2 100644 --- a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/spdm/SpdmMeasurementBlock.java +++ b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/spdm/SpdmMeasurementBlock.java @@ -90,11 +90,11 @@ public class SpdmMeasurementBlock { String spdmMeasBlockInfo = ""; if(spdmMeasurementBlockReadError) { - spdmMeasBlockInfo += "\n Error reading SPDM Measurement Block"; + spdmMeasBlockInfo += " Error reading SPDM Measurement Block\n"; } else { - spdmMeasBlockInfo += "\n Index = " + index; - spdmMeasBlockInfo += "\n MeasurementSpec = " + measurementSpec; + spdmMeasBlockInfo += " Index = " + index + "\n"; + spdmMeasBlockInfo += " MeasurementSpec = " + measurementSpec + "\n"; spdmMeasBlockInfo += spdmMeasurement.toString(); } diff --git a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/uefi/UefiBootOrder.java b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/uefi/UefiBootOrder.java index c1defc00..d9e12ff4 100644 --- a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/uefi/UefiBootOrder.java +++ b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/uefi/UefiBootOrder.java @@ -31,7 +31,7 @@ public class UefiBootOrder { */ public String toString() { StringBuilder orderList = new StringBuilder(); - orderList.append("BootOrder = "); + orderList.append(" BootOrder = "); for (int i = 0; i < bootOrder.length; i++) { orderList.append(String.format("Boot%04d ", (int) bootOrder[i])); } diff --git a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/uefi/UefiDevicePath.java b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/uefi/UefiDevicePath.java index a7d02311..2b96dd46 100644 --- a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/uefi/UefiDevicePath.java +++ b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/uefi/UefiDevicePath.java @@ -75,9 +75,9 @@ public class UefiDevicePath { } /** - * Returns the UEFI device sub-type. + * Returns the UEFI device subtype. * - * @return uefi sub-type + * @return uefi subtype */ public String getSubType() { return subType.trim(); @@ -102,9 +102,6 @@ public class UefiDevicePath { || (devPath.intValue() == UefiConstants.END_FLAG)) { break; } - if (devCount++ > 0) { - pInfo.append("\n"); - } pInfo.append(processDev(path, pathOffset)); devLength = path[pathOffset + UefiConstants.OFFSET_3] * UefiConstants.SIZE_256 + path[pathOffset + UefiConstants.OFFSET_2]; @@ -135,50 +132,50 @@ public class UefiDevicePath { case UefiConstants.DEV_HW: type = "Hardware Device Path"; if (devPath == UefiConstants.DEVPATH_HARWARE) { - devInfo += type + ": " + pciSubType(path, offset); + devInfo += type + ":\n" + pciSubType(path, offset); } break; case UefiConstants.DEV_ACPI: type = "ACPI Device Path"; - devInfo += type + ": " + acpiSubType(path, offset); + devInfo += type + ":\n" + acpiSubType(path, offset); break; case UefiConstants.DEV_MSG: type = "Messaging Device Path"; if (path[offset + UefiConstants.OFFSET_1] == UefiConstants.DEV_SUB_SATA) { - devInfo += type + ": " + sataSubType(path, offset); + devInfo += type + ":\n" + sataSubType(path, offset); } else if (path[offset + UefiConstants.OFFSET_1] == UefiConstants.DEV_SUB_NVM) { - devInfo += type + ": " + nvmSubType(path, offset); + devInfo += type + ":\n" + nvmSubType(path, offset); } else if (path[offset + UefiConstants.OFFSET_1] == UefiConstants.DEV_SUB_USB) { - devInfo += type + ": " + usbSubType(path, offset); + devInfo += type + ":\n" + usbSubType(path, offset); } else { - devInfo += "UEFI Messaging Device Path Type " + Integer.valueOf(unknownSubType); + devInfo += "UEFI Messaging Device Path Type " + Integer.valueOf(unknownSubType) + "\n"; } break; case UefiConstants.DEV_MEDIA: type = "Media Device Path"; if (path[offset + UefiConstants.OFFSET_1] == 0x01) { - devInfo += type + ": " + hardDriveSubType(path, offset); + devInfo += type + ":\n" + hardDriveSubType(path, offset); } else if (path[offset + UefiConstants.OFFSET_1] == UefiConstants.DEVPATH_VENDOR) { - devInfo += type + ": " + vendorSubType(path, offset); + devInfo += type + ":\n" + vendorSubType(path, offset); } else if (path[offset + UefiConstants.OFFSET_1] == UefiConstants.DEVPATH_FILE) { - devInfo += type + ": " + filePathSubType(path, offset); + devInfo += type + ":\n" + filePathSubType(path, offset); } else if (path[offset + UefiConstants.OFFSET_1] == UefiConstants.DEVPATH_PWIG_FILE) { - devInfo += type + ": " + piwgFirmVolFile(path, offset); + devInfo += type + ":\n" + piwgFirmVolFile(path, offset); } else if (path[offset + UefiConstants.OFFSET_1] == UefiConstants.DEVPATH_PWIG_VOL) { - devInfo += type + ": " + piwgFirmVolPath(path, offset); + devInfo += type + ":\n" + piwgFirmVolPath(path, offset); } else { - devInfo += "UEFI Media Device Path Type " + Integer.valueOf(unknownSubType); + devInfo += "UEFI Media Device Path Type " + Integer.valueOf(unknownSubType) + "\n"; } break; case UefiConstants.DEV_BIOS: type = "BIOS Device Path"; - devInfo += type + ": " + biosDevicePath(path, offset); + devInfo += type + ":\n" + biosDevicePath(path, offset); break; case UefiConstants.TERMINATOR: - devInfo += "End of Hardware Device Path"; + devInfo += "End of Hardware Device Path\n"; break; default: - devInfo += "UEFI Device Path Type " + Integer.valueOf(unknownSubType); + devInfo += "UEFI Device Path Type " + Integer.valueOf(unknownSubType) + "\n"; } return devInfo; } @@ -191,16 +188,17 @@ public class UefiDevicePath { * @return acpi device info */ private String acpiSubType(final byte[] path, final int offset) { - subType = ""; + subType = " Sub Type = ACPI\n"; switch (path[offset + UefiConstants.OFFSET_1]) { case 0x01: // standard version subType += acpiShortSubType(path, offset); break; case 0x02: - subType = "(expanded version): "; + subType = "(expanded version):\n"; + // tbd break; default: - subType = "Invalid ACPI Device Path sub type"; + subType = "Invalid ACPI Device Path sub type\n"; } return subType; } @@ -216,13 +214,13 @@ public class UefiDevicePath { subType = ""; byte[] hid = new byte[UefiConstants.SIZE_4]; System.arraycopy(path, UefiConstants.OFFSET_4 + offset, hid, 0, UefiConstants.SIZE_4); - subType += "\n _HID = " + HexUtils.byteArrayToHexString(hid); + subType += " _HID = " + HexUtils.byteArrayToHexString(hid) + "\n"; System.arraycopy(path, 2 * UefiConstants.SIZE_4 + offset, hid, 0, UefiConstants.SIZE_4); String uid = HexUtils.byteArrayToHexString(hid); if(uid.contains("00000000")) { uid = "No _UID exists for this device"; } - subType += "\n _UID = " + uid; + subType += " _UID = " + uid + "\n"; return subType; } @@ -234,11 +232,12 @@ public class UefiDevicePath { * @return pci device info. */ private String pciSubType(final byte[] path, final int offset) { - subType = "\n Hardware Device Path Type = PCI"; - subType += "\n PCI Function Number = "; + subType = " Sub Type = PCI\n"; + subType += " PCI Function Number = "; subType += String.format("0x%x", path[offset + UefiConstants.SIZE_4]); subType += "\n PCI Device Number = "; subType += String.format("0x%x", path[offset + UefiConstants.SIZE_5]); + subType += "\n"; return subType; } @@ -250,7 +249,8 @@ public class UefiDevicePath { * @return SATA drive info. */ private String sataSubType(final byte[] path, final int offset) { - subType = "SATA: HBA Port Number = "; + subType = " Sub Type = SATA\n"; + subType += " SATA: HBA Port Number = "; byte[] data = new byte[UefiConstants.SIZE_2]; System.arraycopy(path, UefiConstants.OFFSET_4 + offset, data, 0, UefiConstants.SIZE_2); subType += HexUtils.byteArrayToHexString(data); @@ -258,6 +258,7 @@ public class UefiDevicePath { subType += " Port Multiplier = " + HexUtils.byteArrayToHexString(data); System.arraycopy(path, UefiConstants.OFFSET_8 + offset, data, 0, UefiConstants.SIZE_2); subType += " Logical Unit Number = " + HexUtils.byteArrayToHexString(data); + subType += "\n"; return subType; } @@ -269,7 +270,8 @@ public class UefiDevicePath { * @return hard drive info. */ private String hardDriveSubType(final byte[] path, final int offset) { - subType = "Partition Number = "; + subType = " Sub Type = Hard Drive\n"; + subType += " Partition Number = "; byte[] partnumber = new byte[UefiConstants.SIZE_4]; System.arraycopy(path, UefiConstants.OFFSET_4 + offset, partnumber, 0, UefiConstants.SIZE_4); @@ -277,14 +279,14 @@ public class UefiDevicePath { byte[] data = new byte[UefiConstants.SIZE_8]; System.arraycopy(path, UefiConstants.OFFSET_8 + offset, data, 0, UefiConstants.SIZE_8); - subType += " Partition Start = " + HexUtils.byteArrayToHexString(data); + subType += "\n Partition Start = " + HexUtils.byteArrayToHexString(data); System.arraycopy(path, UefiConstants.OFFSET_16 + offset, data, 0, UefiConstants.SIZE_8); - subType += " Partition Size = " + HexUtils.byteArrayToHexString(data); + subType += "\n Partition Size = " + HexUtils.byteArrayToHexString(data); byte[] signature = new byte[UefiConstants.SIZE_16]; System.arraycopy(path, UefiConstants.OFFSET_24 + offset, signature, 0, UefiConstants.SIZE_16); - subType += "\n Partition Signature = "; + subType += "\n Partition Signature = "; if (path[UefiConstants.OFFSET_41 + offset] == UefiConstants.DRIVE_SIG_NONE) { subType += "None"; } else if (path[UefiConstants.OFFSET_41 + offset] == UefiConstants.DRIVE_SIG_32BIT) { @@ -295,14 +297,15 @@ public class UefiDevicePath { } else { subType += "invalid partition signature type"; } - subType += " Partition Format = "; + subType += "\n Partition Format = "; if (path[UefiConstants.OFFSET_40 + offset] == UefiConstants.DRIVE_TYPE_PC_AT) { - subType += " PC-AT compatible legacy MBR"; + subType += "PC-AT compatible legacy MBR"; } else if (path[UefiConstants.OFFSET_40 + offset] == UefiConstants.DRIVE_TYPE_GPT) { - subType += " GUID Partition Table"; + subType += "GUID Partition Table"; } else { - subType += " Invalid partition table type"; + subType += "Invalid partition table type"; } + subType += "\n"; return subType; } @@ -314,7 +317,8 @@ public class UefiDevicePath { * @return file path info. */ private String filePathSubType(final byte[] path, final int offset) { - subType = "File Path = "; + subType = " Sub Type = File Path\n"; + subType += " File Path = "; byte[] lengthBytes = new byte[UefiConstants.SIZE_2]; System.arraycopy(path, 2 + offset, lengthBytes, 0, UefiConstants.SIZE_2); int subTypeLength = HexUtils.leReverseInt(lengthBytes); @@ -323,6 +327,7 @@ public class UefiDevicePath { 0, subTypeLength); byte[] fileName = convertChar16tobyteArray(filePath); subType += new String(fileName, StandardCharsets.UTF_8); + subType += "\n"; return subType; } @@ -337,7 +342,8 @@ public class UefiDevicePath { * @return vendor device info. */ private String vendorSubType(final byte[] path, final int offset) { - subType = "Vendor Subtype GUID = "; + subType = " Sub Type = Vendor\n"; + subType += " Vendor Subtype GUID = "; byte[] lengthBytes = new byte[UefiConstants.SIZE_2]; System.arraycopy(path, UefiConstants.OFFSET_2 + offset, lengthBytes, 0, UefiConstants.SIZE_2); @@ -355,6 +361,7 @@ public class UefiDevicePath { } else { subType += " : No Vendor Data present"; } + subType += "\n"; return subType; } @@ -367,8 +374,8 @@ public class UefiDevicePath { * @return USB device info. */ private String usbSubType(final byte[] path, final int offset) { - subType = " USB "; - subType += " port = " + Integer.valueOf(path[offset + UefiConstants.OFFSET_4]); + subType = " Sub Type = USB\n"; + subType += " port = " + Integer.valueOf(path[offset + UefiConstants.OFFSET_4]); subType += " interface = " + Integer.valueOf(path[offset + UefiConstants.OFFSET_5]); byte[] lengthBytes = new byte[UefiConstants.SIZE_2]; System.arraycopy(path, UefiConstants.OFFSET_2 + offset, lengthBytes, @@ -377,6 +384,7 @@ public class UefiDevicePath { byte[] usbData = new byte[subTypeLength]; System.arraycopy(path, UefiConstants.OFFSET_4 + offset, usbData, 0, subTypeLength); + subType += "\n"; // Todo add further USB processing ... return subType; } @@ -393,7 +401,8 @@ public class UefiDevicePath { * @return NVM device info. */ private String nvmSubType(final byte[] path, final int offset) { - subType = "NVM Express Namespace = "; + subType = " Sub Type = NVM\n"; + subType += " NVM Express Namespace = "; byte[] lengthBytes = new byte[UefiConstants.SIZE_2]; System.arraycopy(path, UefiConstants.OFFSET_2 + offset, lengthBytes, 0, UefiConstants.SIZE_2); @@ -402,6 +411,7 @@ public class UefiDevicePath { System.arraycopy(path, UefiConstants.OFFSET_4 + offset, nvmData, 0, subTypeLength); subType += HexUtils.byteArrayToHexString(nvmData); + subType += "\n"; return subType; } @@ -416,7 +426,8 @@ public class UefiDevicePath { * @return String that represents the UEFI defined BIOS Device Type. */ private String biosDevicePath(final byte[] path, final int offset) { - subType = "Legacy BIOS : Type = "; + subType = " Sub Type = Bios Device Path\n"; + subType += " Legacy BIOS : Type = "; Byte pathType = Byte.valueOf(path[offset + 1]); switch (pathType.intValue()) { case UefiConstants.DEVPATH_BIOS_RESERVED: @@ -448,6 +459,7 @@ public class UefiDevicePath { subType += "Unknown"; break; } + subType += "\n"; return subType; } @@ -462,12 +474,13 @@ public class UefiDevicePath { * @return String that represents the PIWG Firmware Volume Path */ private String piwgFirmVolFile(final byte[] path, final int offset) { - subType = "PIWG Firmware File "; + subType = " Sub Type = PIWG Firmware Volume File\n"; byte[] guidData = new byte[UefiConstants.SIZE_16]; System.arraycopy(path, UefiConstants.OFFSET_4 + offset, guidData, 0, UefiConstants.SIZE_16); UefiGuid guid = new UefiGuid(guidData); subType += guid.toString(); + subType += "\n"; return subType; } @@ -482,12 +495,13 @@ public class UefiDevicePath { * @return String that represents the PIWG Firmware Volume Path */ private String piwgFirmVolPath(final byte[] path, final int offset) { - subType = "PIWG Firmware Volume "; + subType = " Sub Type = PIWG Firmware Volume Path\n"; byte[] guidData = new byte[UefiConstants.SIZE_16]; System.arraycopy(path, UefiConstants.OFFSET_4 + offset, guidData, 0, UefiConstants.SIZE_16); UefiGuid guid = new UefiGuid(guidData); subType += guid.toString(); + subType += "\n"; return subType; } diff --git a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/uefi/UefiVariable.java b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/uefi/UefiVariable.java index 2e56828a..d2864e95 100644 --- a/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/uefi/UefiVariable.java +++ b/HIRS_Utils/src/main/java/hirs/utils/tpm/eventlog/uefi/UefiVariable.java @@ -196,10 +196,10 @@ public class UefiVariable { public String toString() { StringBuilder efiVariable = new StringBuilder(); - efiVariable.append("UEFI Variable Name: " + efiVarName + "\n"); - efiVariable.append("UEFI Variable GUID: " + uefiVarGuid.toString() + "\n"); + efiVariable.append(" UEFI Variable Name: " + efiVarName + "\n"); + efiVariable.append(" UEFI Variable GUID: " + uefiVarGuid.toString() + "\n"); if (efiVarName != "") { - efiVariable.append("UEFI Variable Contents => " + "\n"); + efiVariable.append(" UEFI Variable Contents => " + "\n"); } String tmpName = ""; if (efiVarName.contains("Boot00")) { @@ -233,10 +233,10 @@ public class UefiVariable { break; default: if (!tmpName.isEmpty()) { - efiVariable.append(String.format("Data not provided for " + efiVariable.append(String.format(" Data not provided for " + "UEFI variable named %s ", tmpName)); } else { - efiVariable.append("Data not provided "); + efiVariable.append(" Data not provided "); } } @@ -247,7 +247,7 @@ public class UefiVariable { int certSuperListCnt = 1; for (UefiSignatureList uefiSigList : certSuperList) { efiVariable.append("UEFI Signature List # " + certSuperListCnt++ + " of " + - certSuperList.size() + ":\n"); + certSuperList.size() + ": ------------------\n"); efiVariable.append(uefiSigList.toString()); } if(invalidSignatureListEncountered) {