From 5c616882ff40df1c268e34ae5aed88b205e5d21e Mon Sep 17 00:00:00 2001 From: iadgovuser26 Date: Fri, 12 Jun 2020 10:28:23 -0400 Subject: [PATCH] Cleanup test output on -x, set param default using local event log, added param checks --- tools/scripts/eventcheck.sh | 2 +- tools/scripts/identity_transform.xslt | 13 ++++--- .../java/hirs/tcg_eventlog/Commander.java | 35 ++++++++++++------- .../src/main/java/hirs/tcg_eventlog/Main.java | 11 +++--- 4 files changed, 38 insertions(+), 23 deletions(-) diff --git a/tools/scripts/eventcheck.sh b/tools/scripts/eventcheck.sh index ec301827..85fa03fc 100644 --- a/tools/scripts/eventcheck.sh +++ b/tools/scripts/eventcheck.sh @@ -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 ;; diff --git a/tools/scripts/identity_transform.xslt b/tools/scripts/identity_transform.xslt index c69ba714..d249ca61 100644 --- a/tools/scripts/identity_transform.xslt +++ b/tools/scripts/identity_transform.xslt @@ -1,7 +1,10 @@ + - - - - - + + + + + + + diff --git a/tools/tcg_eventlog_tool/src/main/java/hirs/tcg_eventlog/Commander.java b/tools/tcg_eventlog_tool/src/main/java/hirs/tcg_eventlog/Commander.java index 27f0505a..ed656870 100644 --- a/tools/tcg_eventlog_tool/src/main/java/hirs/tcg_eventlog/Commander.java +++ b/tools/tcg_eventlog_tool/src/main/java/hirs/tcg_eventlog/Commander.java @@ -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. " 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 1f8227c1..e3d5a4b6 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 @@ -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) {