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";
}
while [[ "$#" -gt 0 ]]; do
while [[ "$#" -gt 0 ]]; do
case $1 in
-p|--publicCertificate) oem_cert="$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:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:output indent="no" />
<xsl:strip-space elements="*"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

View File

@ -58,7 +58,11 @@ public class Commander {
if (hasArguments) {
parseArguments(args);
} 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++) {
tempValue = args[i];
if (args.length == 0) { // Process default params if none were given
bEventIds = true;
} else {
switch (tempValue) {
case FULL_COMMAND_PREFIX + CONTENT_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 (!args[i + 1].startsWith("-")) {
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;
@ -104,14 +116,6 @@ public class Commander {
} else {
inFile = 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;
}
break;
@ -137,7 +141,12 @@ public class Commander {
if (i < args.length - 1) { // Check for a filter following the -p
if (!args[i + 1].startsWith("-")) {
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;
@ -163,6 +172,7 @@ public class Commander {
printHelp("");
bValidArgs = false;
}
}
}
}
@ -336,8 +346,7 @@ public class Commander {
+ "provided.\n"
+ " -ec\t--contenthex\t Displays event content"
+ " in eventhex format when -event is used.\n"
+ " -ex\t--eventhex\t Displays event in hex format when -event is used"
+ " when -event is used.\n"
+ " -ex\t--eventhex\t Displays event in hex format when -event is used.\n"
+ " -d\t--diff\t\t Compares two TCG Event Logs and outputs a list of events"
+ " of the second log that differred.\n"
+ " -o\t--output\t Output to a file. "

View File

@ -33,7 +33,7 @@ final class Main {
public static void main(final String[] args) {
commander = new Commander(args);
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.");
System.exit(1);
}
@ -97,7 +97,7 @@ commander = new Commander(args);
if (bPcrFlag) {
String[] pcrs = evLog.getExpectedPCRValues();
int count = 0;
if (!commander.getHexFlag()) {
if (!bHexFlag) {
writeOut("Expected Platform Configuration Register (PCR) values"
+ " derived from the Event Log: \n\n");
}
@ -171,18 +171,21 @@ commander = new Commander(args);
String os = System.getProperty("os.name").toLowerCase(), fName = fileName;
byte[] rawLog = null;
boolean bDefault = false;
bHexFlag = commander.getHexFlag();
try {
if (fileName.isEmpty()) {
if (os.compareToIgnoreCase("linux") == 0) { // need to find Windows path
fName = "/sys/kernel/security/tpm0/binary_bios_measurements";
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);
rawLog = Files.readAllBytes(path);
if (!commander.getHexFlag()) {
if (!bHexFlag) {
writeOut("tcg_eventlog_tool is opening file:" + path + "\n");
}
} catch (Exception e) {