{
}
/**
- * Specif the file name of the object to grab.
+ * Specify the file name of the object to grab.
* @param fileName the name of the file associated with the rim
- * @return
+ * @return instance of the manifest in relation to the filename.
*/
- public ReferenceManifestSelector byFileName(final int fileName) {
+ public ReferenceManifestSelector byFileName(final String fileName) {
setFieldValue(RIM_FILENAME_FIELD, fileName);
return this;
}
diff --git a/HIRS_Utils/src/main/java/hirs/tpm/eventlog/TCGEventLog.java b/HIRS_Utils/src/main/java/hirs/tpm/eventlog/TCGEventLog.java
index b849c9e3..a7f43de1 100644
--- a/HIRS_Utils/src/main/java/hirs/tpm/eventlog/TCGEventLog.java
+++ b/HIRS_Utils/src/main/java/hirs/tpm/eventlog/TCGEventLog.java
@@ -252,7 +252,7 @@ public final class TCGEventLog {
public String[] getExpectedPCRValues() {
String[] pcrs = new String[PCR_COUNT];
for (int i = 0; i < PCR_COUNT; i++) {
- pcrs[i] = HexUtils.byteArrayToHexString(pcrList[i]);
+ pcrs[i] = Hex.encodeHexString(pcrList[i]);
}
return pcrs;
}
diff --git a/HIRS_Utils/src/main/java/hirs/tpm/eventlog/TpmPcrEvent.java b/HIRS_Utils/src/main/java/hirs/tpm/eventlog/TpmPcrEvent.java
index f9252e1a..f7aec6ef 100644
--- a/HIRS_Utils/src/main/java/hirs/tpm/eventlog/TpmPcrEvent.java
+++ b/HIRS_Utils/src/main/java/hirs/tpm/eventlog/TpmPcrEvent.java
@@ -2,6 +2,7 @@ package hirs.tpm.eventlog;
import java.io.ByteArrayInputStream;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
@@ -25,51 +26,82 @@ import hirs.tpm.eventlog.uefi.UefiConstants;
import hirs.tpm.eventlog.uefi.UefiFirmware;
import hirs.tpm.eventlog.uefi.UefiVariable;
import hirs.utils.HexUtils;
+import org.apache.commons.codec.binary.Hex;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
/**
* Class to process a TCG_PCR_EVENT.
* TCG_PCR_EVENT is used when the Event log uses the SHA1 Format as described in the
* TCG Platform Firmware Profile (PFP) specification.
* typedef struct {
- * TCG_PCRINDEX PCRIndex; //PCR Index value that either
- * //matches the PCRIndex of a
- * //previous extend operation or
- * //indicates that this Event Log
- * //entry is not associated with
- * //an extend operation
- * TCG_EVENTTYPE EventType; //See Log event types defined in toStrng()
- * TCG_DIGEST digest; //The hash of the event data
- * UINT32 EventSize; //Size of the event data
- * UINT8 Event[EventSize]; //The event data
+ * TCG_PCRINDEX PCRIndex; //PCR Index value that either
+ * //matches the PCRIndex of a
+ * //previous extend operation or
+ * //indicates that this Event Log
+ * //entry is not associated with
+ * //an extend operation
+ * TCG_EVENTTYPE EventType; //See Log event types defined in toStrng()
+ * TCG_DIGEST digest; //The hash of the event data
+ * UINT32 EventSize; //Size of the event data
+ * UINT8 Event[EventSize]; //The event data
* } TCG_PCR_EVENT;
*/
public class TpmPcrEvent {
- /** Log format. SHA1=1, Crytpo agile=2. */
- private int logFormat = -1;
- /** PCR index. */
- private int pcrIndex = -1;
- /** Event Type (long). */
- private long eventType = 0;
- /** Event digest. */
- private byte[] digest = null;
- /** Even data (no content). */
- private byte[] event;
- /** Even content data. */
- private byte[] eventContent;
- /** TCG Event Log spec version. */
- private String version = "Unknown";
- /** TCG Event Log errata version. */
- private String errata = "Unknown";
- /** Description for toString support. */
- private String description = "";
- /** Length (in bytes) of a pcr. */
- private int digestLength = 0;
- /** Event hash for SHA1 event logs. */
- private byte[] eventDataSha1hash;
- /** Event hash for Crypto Agile events. */
- private byte[] eventDataSha256hash;
- /** Indent Offset. */
+ private static final Logger LOGGER = LogManager.getLogger(TpmPcrEvent.class);
+ /**
+ * Indent Offset.
+ */
private static final int INDENT_3 = 3;
+ /**
+ * Log format. SHA1=1, Crytpo agile=2.
+ */
+ private int logFormat = -1;
+ /**
+ * PCR index.
+ */
+ private int pcrIndex = -1;
+ /**
+ * Event Type (long).
+ */
+ private long eventType = 0;
+ /**
+ * Event digest.
+ */
+ private byte[] digest = null;
+ /**
+ * Event data (no content).
+ */
+ private byte[] event;
+ /**
+ * Event content data.
+ */
+ private byte[] eventContent;
+ /**
+ * TCG Event Log spec version.
+ */
+ private String version = "Unknown";
+ /**
+ * TCG Event Log errata version.
+ */
+ private String errata = "Unknown";
+ /**
+ * Description for toString support.
+ */
+ private String description = "";
+ /**
+ * Length (in bytes) of a pcr.
+ */
+ private int digestLength = 0;
+ /**
+ * Event hash for SHA1 event logs.
+ */
+ private byte[] eventDataSha1hash;
+ /**
+ * Event hash for Crypto Agile events.
+ */
+ private byte[] eventDataSha256hash;
+ private EvPostCode evPostCode;
/**
* Constructor.
@@ -104,6 +136,14 @@ public class TpmPcrEvent {
return digestCopy;
}
+ /**
+ * Returns a hex representation of the event digest.
+ * @return hex string
+ */
+ public String getEventDigestStr() {
+ return Hex.encodeHexString(this.digest);
+ }
+
/**
* Sets the event PCR index value from a TCG Event.
*
@@ -122,22 +162,25 @@ public class TpmPcrEvent {
return pcrIndex;
}
- /** Sets the Log Format for this TCG Event.
- * 1 = SHA1 Format, 2 = Crypto Agile format.
- * @param format indicates log format.
- */
- protected void setLogFormat(final int format) {
- logFormat = format;
- }
+ /**
+ * Sets the Log Format for this TCG Event.
+ * 1 = SHA1 Format, 2 = Crypto Agile format.
+ *
+ * @param format indicates log format.
+ */
+ protected void setLogFormat(final int format) {
+ logFormat = format;
+ }
- /**
- * Gets the Log Format for this TCG Event.
- * 1 = SHA1 Format, 2 = Crypto Agile format.
- * @return number representing the format.
- */
- public int getLogFormat() {
- return logFormat;
- }
+ /**
+ * Gets the Log Format for this TCG Event.
+ * 1 = SHA1 Format, 2 = Crypto Agile format.
+ *
+ * @return number representing the format.
+ */
+ public int getLogFormat() {
+ return logFormat;
+ }
/**
* Sets the EventType.
@@ -157,6 +200,14 @@ public class TpmPcrEvent {
return eventType;
}
+ /**
+ * Returns a formatted string of the type for the event.
+ * @return a string formatted to be human readable
+ */
+ public String getEventTypeStr() {
+ return String.format("0x%s %s", Long.toHexString(eventType), eventString((int) eventType));
+ }
+
/**
* Returns the version of the TCG Log Event specification pertaining to the log.
* only updated if the event is a TCG_EfiSpecIdEvent.
@@ -190,11 +241,13 @@ public class TpmPcrEvent {
/**
* Gets the Event Data (no event content) for the event.
* event log format.
+ *
* @return byte array holding the event structure.
*/
public byte[] getEvent() {
return java.util.Arrays.copyOf(event, event.length);
}
+
/**
* Sets the event content after processing.
*
@@ -202,17 +255,168 @@ public class TpmPcrEvent {
*/
protected void setEventContent(final byte[] eventData) {
eventContent = new byte[eventData.length];
+ evPostCode = new EvPostCode(eventContent);
System.arraycopy(eventData, 0, eventContent, 0, eventData.length);
}
/**
* Gets the event Content Data (not the entire event structure).
+ *
* @return byte array holding the events content field
*/
public byte[] getEventContent() {
return java.util.Arrays.copyOf(eventContent, eventContent.length);
}
+ /**
+ * A getter that parses the content based on the type and returns the proper string
+ * value for the content.
+ * @return an appended string of human readable data
+ */
+ public String getEventContentStr() {
+ StringBuilder sb = new StringBuilder();
+
+ switch ((int) this.eventType) {
+ case EvConstants.EV_PREBOOT_CERT:
+ sb.append(" EV_PREBOOT_CERT");
+ break;
+ case EvConstants.EV_POST_CODE:
+ sb.append(new EvPostCode(eventContent).toString());
+ break;
+ case EvConstants.EV_UNUSED:
+ break;
+ case EvConstants.EV_NO_ACTION:
+ EvNoAction noAction = null;
+ try {
+ noAction = new EvNoAction(eventContent);
+ sb.append(noAction.toString());
+ if (noAction.isSpecIDEvent()) {
+ // this should be in the constructor
+ EvEfiSpecIdEvent specID = noAction.getEvEfiSpecIdEvent();
+ version = String.format("%s.%s",
+ specID.getVersionMajor(),
+ specID.getVersionMinor());
+ errata = specID.getErrata();
+ }
+ } catch (UnsupportedEncodingException ueEx) {
+ LOGGER.error(ueEx);
+ sb.append(ueEx.toString());
+ }
+ break;
+ case EvConstants.EV_SEPARATOR:
+ if (EvPostCode.isAscii(eventContent)
+ && !this.isBlank(eventContent)) {
+ sb.append(String.format("Separator event content = %s",
+ new String(eventContent, StandardCharsets.UTF_8)));
+ }
+ break;
+ case EvConstants.EV_EVENT_TAG:
+ sb.append(new EvEventTag(eventContent).toString());
+ break;
+ case EvConstants.EV_S_CRTM_CONTENTS:
+ sb.append(new EvSCrtmContents(eventContent).toString());
+ break;
+ case EvConstants.EV_S_CRTM_VERSION:
+ try {
+ sb.append(new EvSCrtmVersion(eventContent).toString());
+ } catch (UnsupportedEncodingException ueEx) {
+ LOGGER.error(ueEx);
+ sb.append(ueEx.toString());
+ }
+ break;
+ case EvConstants.EV_CPU_MICROCODE:
+ case EvConstants.EV_PLATFORM_CONFIG_FLAGS:
+ case EvConstants.EV_TABLE_OF_DEVICES:
+ break;
+ case EvConstants.EV_COMPACT_HASH:
+ try {
+ sb.append(new EvCompactHash(eventContent).toString());
+ } catch (UnsupportedEncodingException ueEx) {
+ LOGGER.error(ueEx);
+ sb.append(ueEx.toString());
+ }
+ break;
+ case EvConstants.EV_IPL:
+ sb.append(new EvIPL(eventContent).toString());
+ break;
+ case EvConstants.EV_IPL_PARTITION_DATA:
+ case EvConstants.EV_NONHOST_CODE:
+ case EvConstants.EV_NONHOST_CONFIG:
+ case EvConstants.EV_NONHOST_INFO:
+ case EvConstants.EV_EV_OMIT_BOOT_DEVICES_EVENTS:
+ case EvConstants.EV_EFI_EVENT_BASE:
+ break;
+ case EvConstants.EV_EFI_VARIABLE_DRIVER_CONFIG:
+ UefiVariable efiVar = null;
+ try {
+ efiVar = new UefiVariable(eventContent);
+ String efiVarDescription = efiVar.toString().replace("\n", "\n ");
+ sb.append(efiVarDescription.substring(0,
+ efiVarDescription.length() - INDENT_3));
+ } catch (CertificateException cEx) {
+ LOGGER.error(cEx);
+ sb.append(cEx.toString());
+ } catch (NoSuchAlgorithmException noSaEx) {
+ LOGGER.error(noSaEx);
+ sb.append(noSaEx.toString());
+ } catch (IOException ioEx) {
+ LOGGER.error(ioEx);
+ sb.append(ioEx.toString());
+ }
+ break;
+ case EvConstants.EV_EFI_VARIABLE_BOOT:
+ case EvConstants.EV_EFI_VARIABLE_AUTHORITY:
+ try {
+ sb.append(new UefiVariable(eventContent).toString());
+ } catch (CertificateException cEx) {
+ LOGGER.error(cEx);
+ sb.append(cEx.toString());
+ } catch (NoSuchAlgorithmException noSaEx) {
+ LOGGER.error(noSaEx);
+ sb.append(noSaEx.toString());
+ } catch (IOException ioEx) {
+ LOGGER.error(ioEx);
+ sb.append(ioEx.toString());
+ }
+ break;
+ case EvConstants.EV_EFI_BOOT_SERVICES_APPLICATION:
+ case EvConstants.EV_EFI_BOOT_SERVICES_DRIVER: // same as EV_EFI_BOOT_SERVICES_APP
+ try {
+ sb.append(new EvEfiBootServicesApp(eventContent).toString());
+ } catch (UnsupportedEncodingException ueEx) {
+ LOGGER.error(ueEx);
+ sb.append(ueEx.toString());
+ }
+ break;
+ case EvConstants.EV_EFI_RUNTIME_SERVICES_DRIVER:
+ break;
+ case EvConstants.EV_EFI_GPT_EVENT:
+ try {
+ sb.append(new EvEfiGptPartition(eventContent).toString());
+ } catch (UnsupportedEncodingException ueEx) {
+ LOGGER.error(ueEx);
+ sb.append(ueEx.toString());
+ }
+ break;
+ case EvConstants.EV_EFI_ACTION:
+ case EvConstants.EV_ACTION:
+ sb.append(new String(eventContent, StandardCharsets.UTF_8));
+ break;
+ case EvConstants.EV_EFI_PLATFORM_FIRMWARE_BLOB:
+ sb.append(new UefiFirmware(eventContent).toString());
+ break;
+ case EvConstants.EV_EFI_HANDOFF_TABLES:
+ sb.append(new EvEfiHandoffTable(eventContent).toString());
+ break;
+ case EvConstants.EV_EFI_HCRTM_EVENT:
+ break;
+ default:
+ sb.append("Unknown Event found\n");
+ }
+
+ return sb.toString();
+ }
+
/**
* Sets the Digest Length.
* Also the number of bytes expected within each PCR.
@@ -234,25 +438,26 @@ public class TpmPcrEvent {
/**
* Parses the event content and creates a human readable description of each event.
- * @param event the byte array holding the event data.
+ *
+ * @param event the byte array holding the event data.
* @param eventContent the byte array holding the event content.
- * @param eventNumber event position within the event log.
+ * @param eventNumber event position within the event log.
* @return String description of the event.
- * @throws CertificateException if the event contains an event that cannot be processed.
+ * @throws CertificateException if the event contains an event that cannot be processed.
* @throws NoSuchAlgorithmException if an event contains an unsupported algorithm.
- * @throws IOException if the event cannot be parsed.
+ * @throws IOException if the event cannot be parsed.
*/
- public String processEvent(final byte[] event, final byte[] eventContent, final int eventNumber)
- throws CertificateException, NoSuchAlgorithmException, IOException {
+ public String processEvent(final byte[] event, final byte[] eventContent, final int eventNumber)
+ throws CertificateException, NoSuchAlgorithmException, IOException {
int eventID = (int) eventType;
description += "Event# " + eventNumber + ": ";
description += "Index PCR[" + getPcrIndex() + "]\n";
description += "Event Type: 0x" + Long.toHexString(eventType) + " " + eventString(eventID);
description += "\n";
if (logFormat == 1) { // Digest
- description += "digest (SHA-1): " + HexUtils.byteArrayToHexString(this.digest);
+ description += "digest (SHA-1): " + Hex.encodeHexString(this.digest);
} else {
- description += "digest (SHA256): " + HexUtils.byteArrayToHexString(this.digest);
+ description += "digest (SHA256): " + Hex.encodeHexString(this.digest);
}
if (eventID != UefiConstants.SIZE_4) {
description += "\n";
@@ -269,11 +474,11 @@ public class TpmPcrEvent {
switch (eventID) {
case EvConstants.EV_PREBOOT_CERT:
description += " EV_PREBOOT_CERT" + "\n";
- break;
+ break;
case EvConstants.EV_POST_CODE:
EvPostCode postCode = new EvPostCode(eventContent);
- description += "Event Content:\n" + postCode.toString();
- break;
+ description += "Event Content:\n" + postCode.toString();
+ break;
case EvConstants.EV_UNUSED:
break;
case EvConstants.EV_NO_ACTION:
@@ -287,15 +492,15 @@ public class TpmPcrEvent {
break;
case EvConstants.EV_SEPARATOR:
if (EvPostCode.isAscii(eventContent)) {
- String seperatorEventData = new String(eventContent, StandardCharsets.UTF_8);
- if (!this.isEmpty(eventContent)) {
- description += "Seperator event content = " + seperatorEventData;
+ String separatorEventData = new String(eventContent, StandardCharsets.UTF_8);
+ if (!this.isBlank(eventContent)) {
+ description += "Separator event content = " + separatorEventData;
}
- }
+ }
break;
case EvConstants.EV_ACTION:
description += "Event Content:\n"
- + new String(eventContent, StandardCharsets.UTF_8);
+ + new String(eventContent, StandardCharsets.UTF_8);
break;
case EvConstants.EV_EVENT_TAG:
EvEventTag eventTag = new EvEventTag(eventContent);
@@ -316,7 +521,7 @@ public class TpmPcrEvent {
case EvConstants.EV_TABLE_OF_DEVICES:
break;
case EvConstants.EV_COMPACT_HASH:
- EvCompactHash compactHash = new EvCompactHash(eventContent);
+ EvCompactHash compactHash = new EvCompactHash(eventContent);
description += "Event Content:\n" + compactHash.toString();
break;
case EvConstants.EV_IPL:
@@ -339,7 +544,7 @@ public class TpmPcrEvent {
UefiVariable efiVar = new UefiVariable(eventContent);
String efiVarDescription = efiVar.toString().replace("\n", "\n ");
description += "Event Content:\n " + efiVarDescription.substring(0,
- efiVarDescription.length() - INDENT_3);
+ efiVarDescription.length() - INDENT_3);
break;
case EvConstants.EV_EFI_VARIABLE_BOOT:
description += "Event Content:\n" + new UefiVariable(eventContent).toString();
@@ -362,7 +567,7 @@ public class TpmPcrEvent {
break;
case EvConstants.EV_EFI_PLATFORM_FIRMWARE_BLOB:
description += "Event Content:\n"
- + new UefiFirmware(eventContent).toString();
+ + new UefiFirmware(eventContent).toString();
break;
case EvConstants.EV_EFI_HANDOFF_TABLES:
EvEfiHandoffTable efiTable = new EvEfiHandoffTable(eventContent);
@@ -373,7 +578,8 @@ public class TpmPcrEvent {
case EvConstants.EV_EFI_VARIABLE_AUTHORITY:
description += "Event Content:\n" + new UefiVariable(eventContent).toString();
break;
- default: description += " Unknown Event found" + "\n";
+ default:
+ description += " Unknown Event found" + "\n";
}
return description;
}
@@ -381,152 +587,158 @@ public class TpmPcrEvent {
/**
* Converts the Event ID into a String As defined in the TCG PC Client FW Profile.
* Event IDs have values larger than an integer,so a Long is used hold the value.
+ *
* @param event the event id.
* @return TCG defined String that represents the event id
*/
- private static String eventString(final long event) {
+ private static String eventString(final long event) {
- if (event == EvConstants.EV_PREBOOT_CERT) {
- return "EV_PREBOOT_CERT";
- } else if (event == EvConstants.EV_POST_CODE) {
- return "EV_POST_CODE";
- } else if (event == EvConstants.EV_UNUSED) {
- return "EV_Unused";
- } else if (event == EvConstants.EV_NO_ACTION) {
- return "EV_NO_ACTION";
- } else if (event == EvConstants.EV_SEPARATOR) {
- return "EV_SEPARATOR";
- } else if (event == EvConstants.EV_ACTION) {
- return "EV_ACTION";
- } else if (event == EvConstants.EV_EVENT_TAG) {
- return "EV_EVENT_TAG";
- } else if (event == EvConstants.EV_S_CRTM_CONTENTS) {
- return "EV_S_CRTM_CONTENTS";
- } else if (event == EvConstants.EV_S_CRTM_VERSION) {
- return "EV_S_CRTM_VERSION";
- } else if (event == EvConstants.EV_CPU_MICROCODE) {
- return "EV_CPU_MICROCODE";
- } else if (event == EvConstants.EV_PLATFORM_CONFIG_FLAGS) {
- return "EV_PLATFORM_CONFIG_FLAGS ";
- } else if (event == EvConstants.EV_TABLE_OF_DEVICES) {
- return "EV_TABLE_OF_DEVICES";
- } else if (event == EvConstants.EV_COMPACT_HASH) {
- return "EV_COMPACT_HASH";
- } else if (event == EvConstants.EV_IPL) {
- return "EV_IPL";
- } else if (event == EvConstants.EV_IPL_PARTITION_DATA) {
- return "EV_IPL_PARTITION_DATA";
- } else if (event == EvConstants.EV_NONHOST_CODE) {
- return "EV_NONHOST_CODE";
- } else if (event == EvConstants.EV_NONHOST_CONFIG) {
- return "EV_NONHOST_CONFIG";
- } else if (event == EvConstants.EV_NONHOST_INFO) {
- return "EV_NONHOST_INFO";
- } else if (event == EvConstants.EV_EV_OMIT_BOOT_DEVICES_EVENTS) {
- return "EV_EV_OMIT_BOOT_DEVICES_EVENTS";
- } else if (event == EvConstants.EV_EFI_EVENT_BASE) {
- return "EV_EFI_EVENT_BASE";
- } else if (event == EvConstants.EV_EFI_VARIABLE_DRIVER_CONFIG) {
- return "EV_EFI_VARIABLE_DRIVER_CONFIG";
- } else if (event == EvConstants.EV_EFI_VARIABLE_BOOT) {
- return "EV_EFI_VARIABLE_BOOT";
- } else if (event == EvConstants.EV_EFI_BOOT_SERVICES_APPLICATION) {
- return "EV_EFI_BOOT_SERVICES_APPLICATION";
- } else if (event == EvConstants.EV_EFI_BOOT_SERVICES_DRIVER) {
- return "EV_EFI_BOOT_SERVICES_DRIVER";
- } else if (event == EvConstants.EV_EFI_RUNTIME_SERVICES_DRIVER) {
- return "EV_EFI_RUNTIME_SERVICES_DRIVER";
- } else if (event == EvConstants.EV_EFI_GPT_EVENT) {
- return "EV_EFI_GPT_EVENT";
- } else if (event == EvConstants.EV_EFI_ACTION) {
- return "EV_EFI_ACTION";
- } else if (event == EvConstants.EV_EFI_PLATFORM_FIRMWARE_BLOB) {
- return "EV_EFI_PLATFORM_FIRMWARE_BLOB";
- } else if (event == EvConstants.EV_EFI_HANDOFF_TABLES) {
- return "EV_EFI_HANDOFF_TABLES";
- } else if (event == EvConstants.EV_EFI_HCRTM_EVENT) {
- return "EV_EFI_HCRTM_EVENT";
- } else if (event == EvConstants.EV_EFI_VARIABLE_AUTHORITY) {
- return "EV_EFI_VARIABLE_AUTHORITY";
- } else {
- return "Unknown Event ID " + event + " encountered";
- }
- }
+ if (event == EvConstants.EV_PREBOOT_CERT) {
+ return "EV_PREBOOT_CERT";
+ } else if (event == EvConstants.EV_POST_CODE) {
+ return "EV_POST_CODE";
+ } else if (event == EvConstants.EV_UNUSED) {
+ return "EV_Unused";
+ } else if (event == EvConstants.EV_NO_ACTION) {
+ return "EV_NO_ACTION";
+ } else if (event == EvConstants.EV_SEPARATOR) {
+ return "EV_SEPARATOR";
+ } else if (event == EvConstants.EV_ACTION) {
+ return "EV_ACTION";
+ } else if (event == EvConstants.EV_EVENT_TAG) {
+ return "EV_EVENT_TAG";
+ } else if (event == EvConstants.EV_S_CRTM_CONTENTS) {
+ return "EV_S_CRTM_CONTENTS";
+ } else if (event == EvConstants.EV_S_CRTM_VERSION) {
+ return "EV_S_CRTM_VERSION";
+ } else if (event == EvConstants.EV_CPU_MICROCODE) {
+ return "EV_CPU_MICROCODE";
+ } else if (event == EvConstants.EV_PLATFORM_CONFIG_FLAGS) {
+ return "EV_PLATFORM_CONFIG_FLAGS ";
+ } else if (event == EvConstants.EV_TABLE_OF_DEVICES) {
+ return "EV_TABLE_OF_DEVICES";
+ } else if (event == EvConstants.EV_COMPACT_HASH) {
+ return "EV_COMPACT_HASH";
+ } else if (event == EvConstants.EV_IPL) {
+ return "EV_IPL";
+ } else if (event == EvConstants.EV_IPL_PARTITION_DATA) {
+ return "EV_IPL_PARTITION_DATA";
+ } else if (event == EvConstants.EV_NONHOST_CODE) {
+ return "EV_NONHOST_CODE";
+ } else if (event == EvConstants.EV_NONHOST_CONFIG) {
+ return "EV_NONHOST_CONFIG";
+ } else if (event == EvConstants.EV_NONHOST_INFO) {
+ return "EV_NONHOST_INFO";
+ } else if (event == EvConstants.EV_EV_OMIT_BOOT_DEVICES_EVENTS) {
+ return "EV_EV_OMIT_BOOT_DEVICES_EVENTS";
+ } else if (event == EvConstants.EV_EFI_EVENT_BASE) {
+ return "EV_EFI_EVENT_BASE";
+ } else if (event == EvConstants.EV_EFI_VARIABLE_DRIVER_CONFIG) {
+ return "EV_EFI_VARIABLE_DRIVER_CONFIG";
+ } else if (event == EvConstants.EV_EFI_VARIABLE_BOOT) {
+ return "EV_EFI_VARIABLE_BOOT";
+ } else if (event == EvConstants.EV_EFI_BOOT_SERVICES_APPLICATION) {
+ return "EV_EFI_BOOT_SERVICES_APPLICATION";
+ } else if (event == EvConstants.EV_EFI_BOOT_SERVICES_DRIVER) {
+ return "EV_EFI_BOOT_SERVICES_DRIVER";
+ } else if (event == EvConstants.EV_EFI_RUNTIME_SERVICES_DRIVER) {
+ return "EV_EFI_RUNTIME_SERVICES_DRIVER";
+ } else if (event == EvConstants.EV_EFI_GPT_EVENT) {
+ return "EV_EFI_GPT_EVENT";
+ } else if (event == EvConstants.EV_EFI_ACTION) {
+ return "EV_EFI_ACTION";
+ } else if (event == EvConstants.EV_EFI_PLATFORM_FIRMWARE_BLOB) {
+ return "EV_EFI_PLATFORM_FIRMWARE_BLOB";
+ } else if (event == EvConstants.EV_EFI_HANDOFF_TABLES) {
+ return "EV_EFI_HANDOFF_TABLES";
+ } else if (event == EvConstants.EV_EFI_HCRTM_EVENT) {
+ return "EV_EFI_HCRTM_EVENT";
+ } else if (event == EvConstants.EV_EFI_VARIABLE_AUTHORITY) {
+ return "EV_EFI_VARIABLE_AUTHORITY";
+ } else {
+ return "Unknown Event ID " + event + " encountered";
+ }
+ }
- /**
- * Human readable output of a check of input against the current event hash.
- * @return human readable string.
- */
- private String eventHashCheck() {
- String result = "";
- if (logFormat == 1) {
- if (Arrays.equals(this.digest, eventDataSha1hash)) { result
- += "Event digest matched hash of the event data " + "\n";
- } else {
- result += "Event digest DID NOT match the hash of the event data :"
- + HexUtils.byteArrayToHexString(getEventDigest()) + "\n";
- }
+ /**
+ * Human readable output of a check of input against the current event hash.
+ *
+ * @return human readable string.
+ */
+ private String eventHashCheck() {
+ String result = "";
+ if (logFormat == 1) {
+ if (Arrays.equals(this.digest, eventDataSha1hash)) {
+ result
+ += "Event digest matched hash of the event data " + "\n";
} else {
- if (Arrays.equals(this.digest, eventDataSha256hash)) {
- result += "Event digest matched hash of the event data " + "\n";
- } else {
- result += "Event digest DID NOT match the hash of the event data :"
- + HexUtils.byteArrayToHexString(getEventDigest()) + "\n";
- }
- }
- return result;
- }
+ result += "Event digest DID NOT match the hash of the event data :"
+ + Hex.encodeHexString(getEventDigest()) + "\n";
+ }
+ } else {
+ if (Arrays.equals(this.digest, eventDataSha256hash)) {
+ result += "Event digest matched hash of the event data " + "\n";
+ } else {
+ result += "Event digest DID NOT match the hash of the event data :"
+ + Hex.encodeHexString(getEventDigest()) + "\n";
+ }
+ }
+ return result;
+ }
- /**
- * Checks a byte array for all zeros.
- * @param array holds data to check.
- * @return true of all zeros are found.
- */
- public boolean isEmpty(final byte[] array) {
- for (int i = 0; i < array.length; i++) {
- if (array[i] != 0) {
- return false;
- }
- }
- return true;
- }
+ /**
+ * Checks a byte array for all zeros.
+ *
+ * @param array holds data to check.
+ * @return true of all zeros are found.
+ */
+ public boolean isBlank(final byte[] array) {
+ for (int i = 0; i < array.length; i++) {
+ if (array[i] != 0) {
+ return false;
+ }
+ }
+ return true;
+ }
- /**
- * Human readable string representing the contents of the Event Log.
- * @return Description of the log.
- */
- public String toString() {
+ /**
+ * Human readable string representing the contents of the Event Log.
+ *
+ * @return Description of the log.
+ */
+ public String toString() {
return description + "\n";
- }
+ }
- /**
- * Human readable string representing the contents of the Event Log.
- * @param bEvent event Flag.
- * @param bContent content flag.
- * @param bHexEvent hex event flag.
- * @return Description of the log.
- */
- public String toString(final boolean bEvent, final boolean bContent, final boolean bHexEvent) {
- StringBuilder sb = new StringBuilder();
- if (bEvent) {
- sb.append(description);
- }
- if (bHexEvent) {
- if (bEvent || bContent) {
- sb.append("\n");
- }
- byte[] eventData = getEvent();
- sb.append("Event (Hex no Content) (" + eventData.length + " bytes): "
- + HexUtils.byteArrayToHexString(eventData));
- }
- if (bContent) {
- byte[] evContent = getEventContent();
- if (bEvent) {
- sb.append("\n");
- }
- sb.append("Event content (Hex) (" + evContent.length + " bytes): "
- + HexUtils.byteArrayToHexString(evContent));
- }
+ /**
+ * Human readable string representing the contents of the Event Log.
+ *
+ * @param bEvent event Flag.
+ * @param bContent content flag.
+ * @param bHexEvent hex event flag.
+ * @return Description of the log.
+ */
+ public String toString(final boolean bEvent, final boolean bContent, final boolean bHexEvent) {
+ StringBuilder sb = new StringBuilder();
+ if (bEvent) {
+ sb.append(description);
+ }
+ if (bHexEvent) {
+ if (bEvent || bContent) {
+ sb.append("\n");
+ }
+ byte[] eventData = getEvent();
+ sb.append("Event (Hex no Content) (" + eventData.length + " bytes): "
+ + Hex.encodeHexString(eventData));
+ }
+ if (bContent) {
+ byte[] evContent = getEventContent();
+ if (bEvent) {
+ sb.append("\n");
+ }
+ sb.append("Event content (Hex) (" + evContent.length + " bytes): "
+ + Hex.encodeHexString(evContent));
+ }
return sb.toString() + "\n";
- }
+ }
}
diff --git a/HIRS_Utils/src/main/java/hirs/tpm/eventlog/events/EvPostCode.java b/HIRS_Utils/src/main/java/hirs/tpm/eventlog/events/EvPostCode.java
index 6deb1ef3..fca2257b 100644
--- a/HIRS_Utils/src/main/java/hirs/tpm/eventlog/events/EvPostCode.java
+++ b/HIRS_Utils/src/main/java/hirs/tpm/eventlog/events/EvPostCode.java
@@ -34,19 +34,18 @@ public class EvPostCode {
public EvPostCode(final byte[] postCode) {
// 2 ways post code has been implemented, check for the ascii string first
if (isAscii(postCode)) {
- String info = new String(postCode, StandardCharsets.UTF_8);
- codeInfo = info;
+ codeInfo = new String(postCode, StandardCharsets.UTF_8);
bisString = true;
- } else {
- blob = new UefiFirmware(postCode);
- }
+ } else {
+ blob = new UefiFirmware(postCode);
+ }
}
/**
* Returns the UEFI Defined Firmware Blob information.
* @return UEFI Defined Firmware Blob information.
*/
- public UefiFirmware getfirmwareBlob() {
+ public UefiFirmware getFirmwareBlob() {
return blob;
}
@@ -75,12 +74,11 @@ public class EvPostCode {
* @return true if byte array is a string.
*/
public static boolean isAscii(final byte[] postCode) {
- boolean bisAscii = true;
for (byte b : postCode) {
if (!Character.isDefined(b)) {
return false;
}
}
- return bisAscii;
+ return true;
}
}
diff --git a/HIRS_Utils/src/main/java/hirs/tpm/eventlog/uefi/UefiFirmware.java b/HIRS_Utils/src/main/java/hirs/tpm/eventlog/uefi/UefiFirmware.java
index 5dd1d7c8..83f86987 100644
--- a/HIRS_Utils/src/main/java/hirs/tpm/eventlog/uefi/UefiFirmware.java
+++ b/HIRS_Utils/src/main/java/hirs/tpm/eventlog/uefi/UefiFirmware.java
@@ -1,73 +1,90 @@
package hirs.tpm.eventlog.uefi;
import java.math.BigInteger;
+
import hirs.utils.HexUtils;
/**
* Class to process the PFP defined UEFI_PLATFORM_FIRMWARE_BLOB structure.
- *
+ *
* typedef struct tdUEFI_PLATFORM_FIRMWARE_BLOB {
- * UEFI_PHYSICAL_ADDRESS BlobBase;
- * UINT64 BlobLength;
+ * UEFI_PHYSICAL_ADDRESS BlobBase;
+ * UINT64 BlobLength;
* } UEFI_PLATFORM_FIRMWARE_BLOB;
*/
public class UefiFirmware {
- private boolean berror = false;
- /** byte array holding the firmwares physical address. */
- private byte[] physicalAddress = null;
- /** byte array holding the uefi address length. */
- private byte[] addressLength = null;
- /** uefi physical address. */
- private int blobAddress = 0;
- /** uefi address length. */
- private int blobLength = 0;
+ private boolean bError = false;
+ /**
+ * byte array holding the firmwares physical address.
+ */
+ private byte[] physicalAddress = null;
+ /**
+ * byte array holding the uefi address length.
+ */
+ private byte[] addressLength = null;
+ /**
+ * uefi physical address.
+ */
+ private int blobAddress = 0;
+ /**
+ * uefi address length.
+ */
+ private int blobLength = 0;
- /**
- * UefiFirmware constructor.
- * @param blob byte array holding a Firmware Blob.
- */
- public UefiFirmware(final byte[] blob) {
- if (blob.length != UefiConstants.SIZE_16) {
- berror = true;
- } else {
- physicalAddress = new byte[UefiConstants.SIZE_8];
- addressLength = new byte[UefiConstants.SIZE_8];
- System.arraycopy(blob, 0, physicalAddress, 0, UefiConstants.SIZE_8);
- System.arraycopy(blob, UefiConstants.SIZE_8, addressLength, 0, UefiConstants.SIZE_8);
- byte[] lelength = HexUtils.leReverseByte(addressLength);
- BigInteger bigIntLength = new BigInteger(lelength);
- blobLength = bigIntLength.intValue();
- byte[]leAddress = HexUtils.leReverseByte(physicalAddress);
- BigInteger bigIntAddress = new BigInteger(leAddress);
- blobAddress = bigIntAddress.intValue();
- }
-}
-/**
- * Returns the uefi firmware blobs physical address.
- * @return uefi firmware address.
- */
-public int getPhysicalAddress() {
- return blobAddress;
- }
-/**
- * Returns the length of the blobs physical address.
- * @return length of the address.
- */
-public int getBlobLength() {
- return blobLength;
-}
-/**
- * Returns a description of the firmware blobs location.
- * @return a description of the the firmware blobs location.
- */
-public String toString() {
- String blobInfo = "";
- if (!berror) {
- blobInfo += " Platform Firwmare Blob Address = " + Integer.toHexString(blobAddress);
- blobInfo += " length = " + blobLength;
- } else {
- blobInfo += " Invalid Firmware Blob event encountered";
- }
- return blobInfo;
- }
+ /**
+ * UefiFirmware constructor.
+ *
+ * @param blob byte array holding a Firmware Blob.
+ */
+ public UefiFirmware(final byte[] blob) {
+ if (blob.length != UefiConstants.SIZE_16) {
+ bError = true;
+ } else {
+ physicalAddress = new byte[UefiConstants.SIZE_8];
+ addressLength = new byte[UefiConstants.SIZE_8];
+ System.arraycopy(blob, 0, physicalAddress, 0, UefiConstants.SIZE_8);
+ System.arraycopy(blob, UefiConstants.SIZE_8, addressLength, 0, UefiConstants.SIZE_8);
+ byte[] lelength = HexUtils.leReverseByte(addressLength);
+ BigInteger bigIntLength = new BigInteger(lelength);
+ blobLength = bigIntLength.intValue();
+ byte[] leAddress = HexUtils.leReverseByte(physicalAddress);
+ BigInteger bigIntAddress = new BigInteger(leAddress);
+ blobAddress = bigIntAddress.intValue();
+ }
+ }
+
+ /**
+ * Returns the uefi firmware blobs physical address.
+ *
+ * @return uefi firmware address.
+ */
+ public int getPhysicalAddress() {
+ return blobAddress;
+ }
+
+ /**
+ * Returns the length of the blobs physical address.
+ *
+ * @return length of the address.
+ */
+ public int getBlobLength() {
+ return blobLength;
+ }
+
+ /**
+ * Returns a description of the firmware blobs location.
+ *
+ * @return a description of the the firmware blobs location.
+ */
+ public String toString() {
+ StringBuilder blobInfo = new StringBuilder();
+ if (!bError) {
+ blobInfo.append(String.format(" Platform Firmware Blob Address = %s",
+ Integer.toHexString(blobAddress)));
+ blobInfo.append(String.format(" length = %d", blobLength));
+ } else {
+ blobInfo.append(" Invalid Firmware Blob event encountered");
+ }
+ return blobInfo.toString();
+ }
}
diff --git a/tools/tcg_eventlog_tool/src/main/java/hirs/tcg_eventlog/Main.java b/tools/tcg_eventlog_tool/src/main/java/hirs/tcg_eventlog/Main.java
index e3d5a4b6..81da7c90 100644
--- a/tools/tcg_eventlog_tool/src/main/java/hirs/tcg_eventlog/Main.java
+++ b/tools/tcg_eventlog_tool/src/main/java/hirs/tcg_eventlog/Main.java
@@ -26,145 +26,147 @@ final class Main {
private static byte[] eventLog = null;
private static boolean bContentFlag, bEventFlag, bHexEvent, bHexFlag, bPcrFlag = false;
-/**
- * Main Constructor.
- * @param args command line parameters.
- */
-public static void main(final String[] args) {
-commander = new Commander(args);
- if (!commander.getValidityFlag()) {
- System.out.print("Program exiting without processs due to issues with"
- + " parameters provided.");
- System.exit(1);
- }
- if (commander.hasArguments()) {
- if (commander.getDoneFlag()) {
- System.exit(0);
- }
- if (commander.getHelpFlag()) {
- commander.printHelp("");
- System.exit(0);
- }
- if (commander.getOutputFlag()) {
- try {
- outputStream = new FileOutputStream(commander.getOutputFileName());
- } catch (FileNotFoundException e) {
- System.out.print("Error opening output file" + commander.getOutputFileName()
- + "\nError was " + e.getMessage());
- System.exit(1);
- }
- }
- if (commander.getFileFlag()) {
- eventLog = openLog(commander.getInFileName());
- }
- if (commander.getContentFlag()) {
- bContentFlag = true;
- }
- if (commander.getDiffFlag()) {
- bEventFlag = true;
- String results = compareLogs(commander.getInFileName(),
- commander.getInFile2Name());
- writeOut(results);
- System.exit(0);
- }
- if (commander.getEventIdsFlag()) {
- bEventFlag = true;
- }
- if (commander.getEventHexFlag()) {
- bHexEvent = true;
- }
- if (commander.getPCRFlag()) {
- bPcrFlag = true;
- }
- if (commander.getVerifyFile()) {
- System.out.print("Verify option is not yet implemented");
+ /**
+ * Main Constructor.
+ *
+ * @param args command line parameters.
+ */
+ public static void main(final String[] args) {
+ commander = new Commander(args);
+ if (!commander.getValidityFlag()) {
+ System.out.print("Program exiting without processs due to issues with"
+ + " parameters provided.");
System.exit(1);
}
- if (commander.getHexFlag()) {
- bHexFlag = true;
- }
-} else {
- System.out.print("Nothing to do: No Parameters provided.");
- System.exit(1);
-} // End commander processing
-
- try {
- if (eventLog == null) {
- eventLog = openLog("");
- }
- // Main Event processing
- TCGEventLog evLog = new TCGEventLog(eventLog, bEventFlag, bContentFlag, bHexEvent);
- if (bPcrFlag) {
- String[] pcrs = evLog.getExpectedPCRValues();
- int count = 0;
- if (!bHexFlag) {
- writeOut("Expected Platform Configuration Register (PCR) values"
- + " derived from the Event Log: \n\n");
+ if (commander.hasArguments()) {
+ if (commander.getDoneFlag()) {
+ System.exit(0);
}
- for (String pcr: pcrs) {
- if (count++ == commander.getPcrNumber() || (commander.getPcrNumber() == -1)) {
- if (bHexFlag) {
- writeOut(pcr.toString() + "\n");
- } else {
- writeOut(" pcr " + (count - 1) + " = " + pcr.toString() + "\n");
+ if (commander.getHelpFlag()) {
+ commander.printHelp("");
+ System.exit(0);
+ }
+ if (commander.getOutputFlag()) {
+ try {
+ outputStream = new FileOutputStream(commander.getOutputFileName());
+ } catch (FileNotFoundException e) {
+ System.out.print("Error opening output file" + commander.getOutputFileName()
+ + "\nError was " + e.getMessage());
+ System.exit(1);
+ }
+ }
+ if (commander.getFileFlag()) {
+ eventLog = openLog(commander.getInFileName());
+ }
+ if (commander.getContentFlag()) {
+ bContentFlag = true;
+ }
+ if (commander.getDiffFlag()) {
+ bEventFlag = true;
+ String results = compareLogs(commander.getInFileName(),
+ commander.getInFile2Name());
+ writeOut(results);
+ System.exit(0);
+ }
+ if (commander.getEventIdsFlag()) {
+ bEventFlag = true;
+ }
+ if (commander.getEventHexFlag()) {
+ bHexEvent = true;
+ }
+ if (commander.getPCRFlag()) {
+ bPcrFlag = true;
+ }
+ if (commander.getVerifyFile()) {
+ System.out.print("Verify option is not yet implemented");
+ System.exit(1);
+ }
+ if (commander.getHexFlag()) {
+ bHexFlag = true;
+ }
+ } else {
+ System.out.print("Nothing to do: No Parameters provided.");
+ System.exit(1);
+ } // End commander processing
+
+ try {
+ if (eventLog == null) {
+ eventLog = openLog("");
+ }
+ // Main Event processing
+ TCGEventLog evLog = new TCGEventLog(eventLog, bEventFlag, bContentFlag, bHexEvent);
+ if (bPcrFlag) {
+ String[] pcrs = evLog.getExpectedPCRValues();
+ int count = 0;
+ if (!bHexFlag) {
+ writeOut("Expected Platform Configuration Register (PCR) values"
+ + " derived from the Event Log: \n\n");
+ }
+ for (String pcr : pcrs) {
+ if (count++ == commander.getPcrNumber() || (commander.getPcrNumber() == -1)) {
+ if (bHexFlag) {
+ writeOut(pcr.toString() + "\n");
+ } else {
+ writeOut(" pcr " + (count - 1) + " = " + pcr.toString() + "\n");
+ }
}
}
- }
- if (!bHexFlag) {
- writeOut("\n----------------- End PCR Values ----------------- \n\n");
- }
- }
-
- // General event log output
- if (bEventFlag) {
- if (!bHexFlag) {
- if (evLog.isCryptoAgile()) {
- writeOut("\nEvent Log follows the \"Crypto Agile\" format and has "
- + evLog.getEventList().size() + " events:\n\n");
- } else {
- writeOut("\nEvent Log follows the \"SHA1\" format and has "
- + evLog.getEventList().size() + " events:\n\n");
+ if (!bHexFlag) {
+ writeOut("\n----------------- End PCR Values ----------------- \n\n");
}
}
- int eventCount = 0;
- for (TpmPcrEvent event: evLog.getEventList()) {
+
+ // General event log output
+ if (bEventFlag) {
+ if (!bHexFlag) {
+ if (evLog.isCryptoAgile()) {
+ writeOut("\nEvent Log follows the \"Crypto Agile\" format and has "
+ + evLog.getEventList().size() + " events:\n\n");
+ } else {
+ writeOut("\nEvent Log follows the \"SHA1\" format and has "
+ + evLog.getEventList().size() + " events:\n\n");
+ }
+ }
+ int eventCount = 0;
+ for (TpmPcrEvent event : evLog.getEventList()) {
if ((commander.getEventNumber() == eventCount++)
- || commander.getEventNumber() == -1) {
+ || commander.getEventNumber() == -1) {
if ((commander.getPcrNumber() == event.getPcrIndex())
|| commander.getPcrNumber() == -1) {
if (bHexFlag) {
- if (bEventFlag || bHexEvent) {
- writeOut(HexUtils.byteArrayToHexString(event.getEvent()) + "\n");
- }
- if (bContentFlag) {
- writeOut(HexUtils.byteArrayToHexString(event.getEventContent())
- + "\n");
- }
+ if (bEventFlag || bHexEvent) {
+ writeOut(HexUtils.byteArrayToHexString(event.getEvent()) + "\n");
+ }
+ if (bContentFlag) {
+ writeOut(HexUtils.byteArrayToHexString(event.getEventContent())
+ + "\n");
+ }
} else {
- writeOut(event.toString(bEventFlag, bContentFlag, bHexEvent) + "\n");
+ writeOut(event.toString(bEventFlag, bContentFlag, bHexEvent) + "\n");
}
}
+ }
}
}
+ } catch (IOException i) {
+ System.out.print("IO error processing Event Log " + commander.getInFileName()
+ + "\nError was " + i.toString());
+ System.exit(1);
+ } catch (CertificateException c) {
+ System.out.print("Certificate error processing Event Log " + commander.getInFileName()
+ + "\nError was " + c.toString());
+ System.exit(1);
+ } catch (NoSuchAlgorithmException a) {
+ System.out.print("Algorithm error processing Event Log " + commander.getInFileName()
+ + "\nError was " + a.toString());
+ System.exit(1);
}
- } catch (IOException i) {
- System.out.print("IO error processing Event Log " + commander.getInFileName()
- + "\nError was " + i.toString());
- System.exit(1);
- } catch (CertificateException c) {
- System.out.print("Certificate error processing Event Log " + commander.getInFileName()
- + "\nError was " + c.toString());
- System.exit(1);
- } catch (NoSuchAlgorithmException a) {
- System.out.print("Algorithm error processing Event Log " + commander.getInFileName()
- + "\nError was " + a.toString());
- System.exit(1);
}
-}
/**
* Opens a TCG Event log file.
- * @param fileName Name of the log file. Will use a OS specific default.
+ *
+ * @param fileName Name of the log file. Will use a OS specific default.
* @return a byte array holding the entire log
*/
public static byte[] openLog(final String fileName) {
@@ -186,10 +188,10 @@ commander = new Commander(args);
Path path = Paths.get(fName);
rawLog = Files.readAllBytes(path);
if (!bHexFlag) {
- writeOut("tcg_eventlog_tool is opening file:" + path + "\n");
+ writeOut("tcg_eventlog_tool is opening file:" + path + "\n");
}
} catch (Exception e) {
- String error = "Error reading event Log File: " + e.toString();
+ String error = "Error reading event Log File: " + e.toString();
if (bDefault) {
error += "\nTry using the -f option to specify an Event Log File";
}
@@ -201,6 +203,7 @@ commander = new Commander(args);
/**
* Write data out to the system and/or a file.
+ *
* @param data
*/
private static void writeOut(final String data) {
@@ -219,6 +222,7 @@ commander = new Commander(args);
/**
* Compares 2 Event Logs and returns a string based upon the results.
* Uses the Events digest field for comparisons.
+ *
* @param logFileName1 Log file to use as a reference.
* @param logFileName2 Log file to compare to the reference.
* @return A sting containing human readable results.
@@ -232,12 +236,12 @@ commander = new Commander(args);
try {
eventLog1 = new TCGEventLog(evLog);
} catch (Exception e) {
- sb.append("\nError processing event log " + logFileName1 + " : " + e.getMessage());
+ sb.append("\nError processing event log " + logFileName1 + " : " + e.getMessage());
return sb.toString();
}
try {
eventLog2 = new TCGEventLog(evLog2);
- ArrayList errors = diffEventLogs(eventLog1.getEventList(),
+ ArrayList errors = diffEventLogs(eventLog1.getEventList(),
eventLog2.getEventList(), commander.getPcrNumber());
if (errors.isEmpty() && !bHexFlag) {
sb.append("\nEvent Log " + logFileName1 + " MATCHED EventLog " + logFileName2);
@@ -245,8 +249,8 @@ commander = new Commander(args);
if (!errors.isEmpty() && !bHexFlag) {
sb.append("\nEvent Log " + logFileName1
+ " did NOT match EventLog " + logFileName2 + "\n");
- sb.append("There were " + errors.size() + " event mismatches: \n\n");
- }
+ sb.append("There were " + errors.size() + " event mismatches: \n\n");
+ }
for (TpmPcrEvent error : errors) {
if (bHexFlag) {
if (bEventFlag || bHexEvent) {
@@ -254,51 +258,53 @@ commander = new Commander(args);
}
if (bContentFlag) {
sb.append(HexUtils.byteArrayToHexString(error.getEventContent())
- + "\n");
+ + "\n");
}
- } else {
- sb.append(error.toString(bEventFlag, bContentFlag, bHexEvent) + "\n");
- }
+ } else {
+ sb.append(error.toString(bEventFlag, bContentFlag, bHexEvent) + "\n");
+ }
}
}
} catch (IOException i) {
System.out.print("IO error processing Event Log " + commander.getInFileName()
- + "\nError was " + i.toString());
+ + "\nError was " + i.toString());
System.exit(1);
} catch (CertificateException c) {
System.out.print("Certificate error processing Event Log " + commander.getInFileName()
- + "\nError was " + c.toString());
+ + "\nError was " + c.toString());
+ System.exit(1);
+ } catch (NoSuchAlgorithmException a) {
+ System.out.print("Algorithm error processing Event Log " + commander.getInFileName()
+ + "\nError was " + a.toString());
System.exit(1);
- } catch (NoSuchAlgorithmException a) {
- System.out.print("Algorithm error processing Event Log " + commander.getInFileName()
- + "\nError was " + a.toString());
- System.exit(1);
}
return sb.toString();
}
+
/**
* Compare this event log against a second event log.
* Returns a String Array of event descriptions in which the digests from the first
- * did no match the second. Return value is null if all events matched.
- * @param eventList initial events.
+ * did no match the second. Return value is null if all events matched.
+ *
+ * @param eventList initial events.
* @param eventList2 events to compare against.
- * @param pcr used as a filter. Use -1 to check all pcrs.
+ * @param pcr used as a filter. Use -1 to check all pcrs.
* @return array list of strings. Null of no events mismatched.
*/
public static ArrayList diffEventLogs(final ArrayList eventList,
- final ArrayList eventList2, final int pcr) {
+ final ArrayList eventList2, final int pcr) {
ArrayList results = new ArrayList();
for (TpmPcrEvent event2 : eventList2) {
if (pcr >= 0) {
if (event2.getPcrIndex() == pcr) {
if (!digestMatch(eventList, event2)) {
results.add(event2);
- }
+ }
}
} else {
if (!digestMatch(eventList, event2)) {
results.add(event2);
- }
+ }
}
}
return results;
@@ -306,8 +312,9 @@ commander = new Commander(args);
/**
* Checks a digest from a single event against all digests with the same index in an Event Log.
+ *
* @param eventLog The Reference Event log.
- * @param event single event to match.
+ * @param event single event to match.
* @return
*/
private static boolean digestMatch(final ArrayList eventLog,
From 778380f70c2583433f74c8c7f53626a9e54e6b68 Mon Sep 17 00:00:00 2001
From: Cyrus <24922493+cyrus-dev@users.noreply.github.com>
Date: Fri, 25 Sep 2020 08:57:12 -0400
Subject: [PATCH 03/12] This should finish off the code changes for issues
#280.
---
...eferenceManifestDetailsPageController.java | 71 ++++++++++---------
.../ReferenceManifestPageController.java | 26 +++----
.../main/webapp/WEB-INF/jsp/rim-details.jsp | 20 +++++-
.../src/main/webapp/common/rim_details.css | 36 ++++++++++
4 files changed, 101 insertions(+), 52 deletions(-)
create mode 100644 HIRS_AttestationCAPortal/src/main/webapp/common/rim_details.css
diff --git a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ReferenceManifestDetailsPageController.java b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ReferenceManifestDetailsPageController.java
index 9a7da962..64cd88cc 100644
--- a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ReferenceManifestDetailsPageController.java
+++ b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ReferenceManifestDetailsPageController.java
@@ -4,21 +4,21 @@ import hirs.data.persist.BaseReferenceManifest;
import hirs.data.persist.ReferenceManifest;
import hirs.data.persist.SupportReferenceManifest;
import hirs.data.persist.SwidResource;
-import hirs.persist.DBManagerException;
import hirs.persist.ReferenceManifestManager;
import hirs.tpm.eventlog.TCGEventLog;
import hirs.attestationca.portal.page.Page;
import hirs.attestationca.portal.page.PageController;
import hirs.attestationca.portal.page.PageMessages;
import hirs.attestationca.portal.page.params.ReferenceManifestDetailsPageParams;
+
import java.io.IOException;
-import java.nio.file.NoSuchFileException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
+import java.util.Set;
import java.util.UUID;
import org.apache.logging.log4j.LogManager;
@@ -57,13 +57,13 @@ public class ReferenceManifestDetailsPageController
* Returns the filePath for the view and the data model for the page.
*
* @param params The object to map url parameters into.
- * @param model The data model for the request. Can contain data from
- * redirect.
+ * @param model The data model for the request. Can contain data from
+ * redirect.
* @return the path for the view and data model for the page.
*/
@Override
public ModelAndView initPage(final ReferenceManifestDetailsPageParams params,
- final Model model) {
+ final Model model) {
// get the basic information to render the page
ModelAndView mav = getBaseModelAndView();
PageMessages messages = new PageMessages();
@@ -106,16 +106,16 @@ public class ReferenceManifestDetailsPageController
* This method takes the place of an entire class for a string builder.
* Gathers all information and returns it for displays.
*
- * @param uuid database reference for the requested RIM.
+ * @param uuid database reference for the requested RIM.
* @param referenceManifestManager the reference manifest manager.
* @return mapping of the RIM information from the database.
- * @throws java.io.IOException error for reading file bytes.
+ * @throws java.io.IOException error for reading file bytes.
* @throws NoSuchAlgorithmException If an unknown Algorithm is encountered.
- * @throws CertificateException if a certificate doesn't parse.
+ * @throws CertificateException if a certificate doesn't parse.
*/
public static HashMap getRimDetailInfo(final UUID uuid,
- final ReferenceManifestManager referenceManifestManager) throws IOException,
- CertificateException, NoSuchAlgorithmException {
+ final ReferenceManifestManager referenceManifestManager) throws IOException,
+ CertificateException, NoSuchAlgorithmException {
HashMap data = new HashMap<>();
ReferenceManifest rim = ReferenceManifest
@@ -169,7 +169,6 @@ public class ReferenceManifestDetailsPageController
data.put("pcUriLocal", bRim.getPcURILocal());
data.put("rimLinkHash", bRim.getRimLinkHash());
data.put("rimType", bRim.getRimType());
- data.put("associatedRim", bRim.getAssociatedRim());
List resources = bRim.parseResource();
String resourceFilename = null;
@@ -177,45 +176,49 @@ public class ReferenceManifestDetailsPageController
// going to have to pull the filename and grab that from the DB
// to get the id to make the link
- try {
- for (SwidResource swidRes : resources) {
- resourceFilename = swidRes.getName();
- ReferenceManifest dbRim = ReferenceManifest.select(
- referenceManifestManager).byFileName(resourceFilename).getRIM();
+ for (SwidResource swidRes : resources) {
+ resourceFilename = swidRes.getName();
+ ReferenceManifest dbRim = ReferenceManifest.select(
+ referenceManifestManager).byFileName(resourceFilename).getRIM();
- if (dbRim != null) {
- logProcessor = new TCGEventLog(dbRim.getRimBytes());
- swidRes.setPcrValues(Arrays.asList(
- logProcessor.getExpectedPCRValues()));
+ if (dbRim != null) {
+ logProcessor = new TCGEventLog(dbRim.getRimBytes());
+ swidRes.setPcrValues(Arrays.asList(
+ logProcessor.getExpectedPCRValues()));
- if (bRim.getAssociatedRim() == null) {
- bRim.setAssociatedRim(dbRim.getId());
- }
- } else {
- swidRes.setPcrValues(new ArrayList<>());
+ if (bRim.getAssociatedRim() == null) {
+ bRim.setAssociatedRim(dbRim.getId());
}
+ } else {
+ swidRes.setPcrValues(new ArrayList<>());
}
- } catch (NoSuchFileException nsfEx) {
- LOGGER.error(String.format("File Not found!: %s",
- resourceFilename));
- LOGGER.error(nsfEx);
- } catch (DBManagerException dbmEx) {
- LOGGER.error(dbmEx);
}
data.put("associatedRim", bRim.getAssociatedRim());
data.put("swidFiles", resources);
} else if (rim instanceof SupportReferenceManifest) {
SupportReferenceManifest sRim = (SupportReferenceManifest) rim;
- data.put("baseRim", sRim.getFileName());
+
+ if (sRim.getAssociatedRim() == null) {
+ Set rims = ReferenceManifest
+ .select(referenceManifestManager).getRIMs();
+ for (ReferenceManifest dbRim : rims) {
+ if (dbRim instanceof BaseReferenceManifest
+ && dbRim.getTagId().equals(sRim.getTagId())) {
+ sRim.setAssociatedRim(dbRim.getId());
+ break;
+ }
+ }
+ }
+ data.put("baseRim", sRim.getTagId());
data.put("associatedRim", sRim.getAssociatedRim());
data.put("rimType", sRim.getRimType());
TCGEventLog logProcessor = new TCGEventLog(sRim.getRimBytes());
data.put("events", logProcessor.getEventList());
} else {
- LOGGER.error(String.format("Unable to find Reference Integrity "
- + "Manifest with ID: %s", uuid));
+ LOGGER.error(String.format("Unable to find Reference Integrity "
+ + "Manifest with ID: %s", uuid));
}
return data;
diff --git a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ReferenceManifestPageController.java b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ReferenceManifestPageController.java
index f9a08d69..9c8eb677 100644
--- a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ReferenceManifestPageController.java
+++ b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ReferenceManifestPageController.java
@@ -28,7 +28,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
-import java.nio.file.Path;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletResponse;
@@ -189,7 +188,6 @@ public class ReferenceManifestPageController
Map model = new HashMap<>();
PageMessages messages = new PageMessages();
String fileName;
- Path filePath;
Pattern pattern;
Matcher matcher;
boolean supportRIM = false;
@@ -208,26 +206,24 @@ public class ReferenceManifestPageController
.select(referenceManifestManager).getRIMs();
// update information for associated support rims
- if (supportRIM) {
- for (ReferenceManifest element : rims) {
+ for (ReferenceManifest element : rims) {
+ if (supportRIM) {
if (element instanceof BaseReferenceManifest) {
BaseReferenceManifest bRim = (BaseReferenceManifest) element;
for (SwidResource swid : bRim.parseResource()) {
if (swid.getName().equals(rim.getFileName())) {
rim.setFirmwareVersion(swid.getSize());
- rim.setPlatformManufacturer(element.getPlatformManufacturer());
- rim.setPlatformModel(element.getPlatformModel());
- rim.setTagId(element.getTagId());
- rim.setAssociatedRim(element.getId());
+ rim.setPlatformManufacturer(bRim.getPlatformManufacturer());
+ rim.setPlatformModel(bRim.getPlatformModel());
+ rim.setTagId(bRim.getTagId());
+ rim.setAssociatedRim(bRim.getId());
break;
}
}
}
- }
- } else {
- BaseReferenceManifest bRim = (BaseReferenceManifest) rim;
- for (SwidResource swid : bRim.parseResource()) {
- for (ReferenceManifest element : rims) {
+ } else {
+ BaseReferenceManifest bRim = (BaseReferenceManifest) rim;
+ for (SwidResource swid : bRim.parseResource()) {
if (element instanceof SupportReferenceManifest) {
SupportReferenceManifest sRim = (SupportReferenceManifest) element;
if (swid.getName().equals(sRim.getFileName())) {
@@ -239,8 +235,8 @@ public class ReferenceManifestPageController
try {
referenceManifestManager.update(sRim);
} catch (DBManagerException dbmEx) {
- LOGGER.error(String.format("Couldn't update Base RIM %s with "
- + "associated UUID %s", rim.getTagId(),
+ LOGGER.error(String.format("Couldn't update Support RIM "
+ + "%s with associated UUID %s", rim.getTagId(),
sRim.getId()), dbmEx);
}
break;
diff --git a/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/rim-details.jsp b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/rim-details.jsp
index 46629bed..e801ab21 100644
--- a/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/rim-details.jsp
+++ b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/rim-details.jsp
@@ -28,7 +28,6 @@
${initialData.associatedRim}
-
Base RIM not uploaded from the ACA RIM Page
@@ -54,18 +53,18 @@
${count} |
- ${event.getPcrIndex()} |
+ PCR${event.getPcrIndex()} |
${event.getEventTypeStr()} |
${event.getEventDigestStr()} |
${event.getEventContentStr()} |
-