Cleanup test output on -x, set param default using local event log, added param checks

This commit is contained in:
iadgovuser26 2020-06-12 10:28:23 -04:00
parent 7ab7408b59
commit 5c616882ff
4 changed files with 38 additions and 23 deletions

View File

@ -16,7 +16,7 @@ function eventcheck_help() {
echo "-h --help : help listing"; echo "-h --help : help listing";
} }
while [[ "$#" -gt 0 ]]; do while [[ "$#" -gt 0 ]]; do
case $1 in case $1 in
-p|--publicCertificate) oem_cert="$2"; shift ;; -p|--publicCertificate) oem_cert="$2"; shift ;;
-r|--rim) oem_rim=$2; shift ;; -r|--rim) oem_rim=$2; shift ;;

View File

@ -1,7 +1,10 @@
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()"> <xsl:output indent="no" />
<xsl:copy> <xsl:strip-space elements="*"/>
<xsl:apply-templates select="@*|node()"/> <xsl:template match="@*|node()">
</xsl:copy> <xsl:copy>
</xsl:template> <xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet> </xsl:stylesheet>

View File

@ -58,7 +58,11 @@ public class Commander {
if (hasArguments) { if (hasArguments) {
parseArguments(args); parseArguments(args);
} else { } else {
printHelp(""); String[] defualtArgs=new String[1];
defualtArgs[0] = "-e";
hasArguments = true;
parseArguments(defualtArgs);
// printHelp("");
} }
} }
@ -74,6 +78,9 @@ public class Commander {
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
tempValue = args[i]; tempValue = args[i];
if (args.length == 0) { // Process default params if none were given
bEventIds = true;
} else {
switch (tempValue) { switch (tempValue) {
case FULL_COMMAND_PREFIX + CONTENT_STRING: case FULL_COMMAND_PREFIX + CONTENT_STRING:
case FULL_COMMAND_PREFIX + EVENTIDS_STRING: case FULL_COMMAND_PREFIX + EVENTIDS_STRING:
@ -81,7 +88,12 @@ public class Commander {
if (i < args.length - 1) { // Check for a filter following the -e if (i < args.length - 1) { // Check for a filter following the -e
if (!args[i + 1].startsWith("-")) { if (!args[i + 1].startsWith("-")) {
eventFilter = args[i++ + 1]; eventFilter = args[i++ + 1];
eventNumber = Integer.parseInt(eventFilter); if(eventFilter.chars().allMatch( Character::isDigit )) {
eventNumber = Integer.parseInt(eventFilter);
} else {
System.out.println("invalid parameter following -e: " + eventFilter);
System.exit(1);
}
} }
} }
bEventIds = true; bEventIds = true;
@ -104,14 +116,6 @@ public class Commander {
} else { } else {
inFile = args[i++ + 1]; inFile = args[i++ + 1];
inFile2 = args[i++ + 1]; inFile2 = args[i++ + 1];
/*
if (args.length > i + 1) {
if (!args[i + 1].contains("-")) { // pcr filter provided
eventFilter = args[i++ + 1];
eventNumber = Integer.parseInt(eventFilter);
}
}
*/
bDiff = true; bDiff = true;
} }
break; break;
@ -137,7 +141,12 @@ public class Commander {
if (i < args.length - 1) { // Check for a filter following the -p if (i < args.length - 1) { // Check for a filter following the -p
if (!args[i + 1].startsWith("-")) { if (!args[i + 1].startsWith("-")) {
pcrFilter = args[i++ + 1 ]; pcrFilter = args[i++ + 1 ];
pcrNumber = Integer.parseInt(pcrFilter); if(pcrFilter.chars().allMatch( Character::isDigit )) {
pcrNumber = Integer.parseInt(pcrFilter);
} else {
System.out.println("invalid parameter following -p: " + pcrFilter);
System.exit(1);
}
} }
} }
bPCRs = true; bPCRs = true;
@ -163,6 +172,7 @@ public class Commander {
printHelp(""); printHelp("");
bValidArgs = false; bValidArgs = false;
} }
}
} }
} }
@ -336,8 +346,7 @@ public class Commander {
+ "provided.\n" + "provided.\n"
+ " -ec\t--contenthex\t Displays event content" + " -ec\t--contenthex\t Displays event content"
+ " in eventhex format when -event is used.\n" + " in eventhex format when -event is used.\n"
+ " -ex\t--eventhex\t Displays event in hex format when -event is used" + " -ex\t--eventhex\t Displays event in hex format when -event is used.\n"
+ " when -event is used.\n"
+ " -d\t--diff\t\t Compares two TCG Event Logs and outputs a list of events" + " -d\t--diff\t\t Compares two TCG Event Logs and outputs a list of events"
+ " of the second log that differred.\n" + " of the second log that differred.\n"
+ " -o\t--output\t Output to a file. " + " -o\t--output\t Output to a file. "

View File

@ -33,7 +33,7 @@ final class Main {
public static void main(final String[] args) { public static void main(final String[] args) {
commander = new Commander(args); commander = new Commander(args);
if (!commander.getValidityFlag()) { if (!commander.getValidityFlag()) {
System.out.print("Program exiting wihtout processs due to issues with" System.out.print("Program exiting without processs due to issues with"
+ " parameters provided."); + " parameters provided.");
System.exit(1); System.exit(1);
} }
@ -97,7 +97,7 @@ commander = new Commander(args);
if (bPcrFlag) { if (bPcrFlag) {
String[] pcrs = evLog.getExpectedPCRValues(); String[] pcrs = evLog.getExpectedPCRValues();
int count = 0; int count = 0;
if (!commander.getHexFlag()) { if (!bHexFlag) {
writeOut("Expected Platform Configuration Register (PCR) values" writeOut("Expected Platform Configuration Register (PCR) values"
+ " derived from the Event Log: \n\n"); + " derived from the Event Log: \n\n");
} }
@ -171,18 +171,21 @@ commander = new Commander(args);
String os = System.getProperty("os.name").toLowerCase(), fName = fileName; String os = System.getProperty("os.name").toLowerCase(), fName = fileName;
byte[] rawLog = null; byte[] rawLog = null;
boolean bDefault = false; boolean bDefault = false;
bHexFlag = commander.getHexFlag();
try { try {
if (fileName.isEmpty()) { if (fileName.isEmpty()) {
if (os.compareToIgnoreCase("linux") == 0) { // need to find Windows path if (os.compareToIgnoreCase("linux") == 0) { // need to find Windows path
fName = "/sys/kernel/security/tpm0/binary_bios_measurements"; fName = "/sys/kernel/security/tpm0/binary_bios_measurements";
bDefault = true; bDefault = true;
writeOut("Local Event Log being used: " + fileName + "\n"); if (!bHexFlag) {
writeOut("Local Event Log being used: " + fileName + "\n");
}
} }
} }
Path path = Paths.get(fName); Path path = Paths.get(fName);
rawLog = Files.readAllBytes(path); rawLog = Files.readAllBytes(path);
if (!commander.getHexFlag()) { if (!bHexFlag) {
writeOut("tcg_eventlog_tool is opening file:" + path + "\n"); writeOut("tcg_eventlog_tool is opening file:" + path + "\n");
} }
} catch (Exception e) { } catch (Exception e) {