From 5c616882ff40df1c268e34ae5aed88b205e5d21e Mon Sep 17 00:00:00 2001 From: iadgovuser26 Date: Fri, 12 Jun 2020 10:28:23 -0400 Subject: [PATCH 1/2] 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 ec3018279..85fa03fc6 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 c69ba714d..d249ca61b 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 27f0505a5..ed656870c 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 Commander(final String[] args) { if (hasArguments) { parseArguments(args); } else { - printHelp(""); + String[] defualtArgs=new String[1]; + defualtArgs[0] = "-e"; + hasArguments = true; + parseArguments(defualtArgs); + // printHelp(""); } } @@ -74,6 +78,9 @@ public final void parseArguments(final String[] args) { 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 final void parseArguments(final String[] args) { 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 final void parseArguments(final String[] args) { } 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 final void parseArguments(final String[] args) { 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 final void parseArguments(final String[] args) { printHelp(""); bValidArgs = false; } + } } } @@ -336,8 +346,7 @@ public final void printHelp(final String message) { + "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 1f8227c1f..e3d5a4b67 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 @@ public static void main(final String[] 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 @@ public static byte[] openLog(final String fileName) { 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) { From 6f965c508fe1322fc0b946d917f4f255672bb518 Mon Sep 17 00:00:00 2001 From: iadgovuser26 Date: Thu, 18 Jun 2020 09:51:03 -0400 Subject: [PATCH 2/2] set package name to tcg_eventlog_tool --- tools/tcg_eventlog_tool/build.gradle | 2 +- .../src/main/java/hirs/tcg_eventlog/Commander.java | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/tools/tcg_eventlog_tool/build.gradle b/tools/tcg_eventlog_tool/build.gradle index 8c33ba098..9a44691a1 100644 --- a/tools/tcg_eventlog_tool/build.gradle +++ b/tools/tcg_eventlog_tool/build.gradle @@ -66,7 +66,7 @@ buildscript { // Produce packages ospackage { - packageName='tcgeventlogtool' + packageName='tcg_eventlog_tool' os=LINUX arch=NOARCH version='1.0.0' 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 ed656870c..fa0ec66bb 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 @@ -24,6 +24,7 @@ public class Commander { private static final String VERIFY_STRING = "Verify"; private static final String VERSION_STRING = "version"; private static final String VERSION_NUMBER = "1.0"; + private static final String REGEX = "[0-9]+"; private boolean hasArguments = false; private boolean bValidArgs = true; @@ -58,7 +59,7 @@ public Commander(final String[] args) { if (hasArguments) { parseArguments(args); } else { - String[] defualtArgs=new String[1]; + String[] defualtArgs = new String[1]; defualtArgs[0] = "-e"; hasArguments = true; parseArguments(defualtArgs); @@ -79,7 +80,7 @@ public final void parseArguments(final String[] args) { tempValue = args[i]; if (args.length == 0) { // Process default params if none were given - bEventIds = true; + bEventIds = true; } else { switch (tempValue) { case FULL_COMMAND_PREFIX + CONTENT_STRING: @@ -88,11 +89,10 @@ public final void parseArguments(final String[] args) { if (i < args.length - 1) { // Check for a filter following the -e if (!args[i + 1].startsWith("-")) { eventFilter = args[i++ + 1]; - if(eventFilter.chars().allMatch( Character::isDigit )) { + if (eventFilter.matches(REGEX)) { eventNumber = Integer.parseInt(eventFilter); } else { System.out.println("invalid parameter following -e: " + eventFilter); - System.exit(1); } } } @@ -141,11 +141,10 @@ public final void parseArguments(final String[] args) { if (i < args.length - 1) { // Check for a filter following the -p if (!args[i + 1].startsWith("-")) { pcrFilter = args[i++ + 1 ]; - if(pcrFilter.chars().allMatch( Character::isDigit )) { + if (pcrFilter.matches(REGEX)) { pcrNumber = Integer.parseInt(pcrFilter); } else { System.out.println("invalid parameter following -p: " + pcrFilter); - System.exit(1); } } }