diff --git a/tools/tcg_eventlog_tool/build.gradle b/tools/tcg_eventlog_tool/build.gradle index e2812f0a..8c33ba09 100644 --- a/tools/tcg_eventlog_tool/build.gradle +++ b/tools/tcg_eventlog_tool/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'java' apply plugin: 'findbugs' apply plugin: 'checkstyle' +apply plugin: 'nebula.ospackage' version = '1.0' @@ -11,10 +12,10 @@ repositories { dependencies { compile project(':HIRS_Utils') compile libs.jcommander - + compile libs.commons_io + compile libs.log4j2 compileOnly libs.checkstyle compileOnly libs.findbugs - testCompile libs.testng } @@ -53,3 +54,63 @@ uploadArchives { } } } + +buildscript { + repositories { + mavenCentral() + } + dependencies { + classpath 'com.netflix.nebula:gradle-ospackage-plugin:4.9.3' + } +} + +// Produce packages +ospackage { + packageName='tcgeventlogtool' + os=LINUX + arch=NOARCH + version='1.0.0' + release='1' + + into '/opt/hirs/eventlog' + user 'root' + fileMode=0755 + + from(jar.outputs.files) { + into 'lib' + } + from('lib') { + into 'lib' + } + from(configurations.runtime) { + into 'lib' + } + from('scripts') { + exclude { + FileTreeElement details -> + details.file.name.endsWith('.bat') + } + into 'scripts' + } + from('docs') { + exclude { + FileTreeElement details -> + details.file.name.endsWith('.odt') + } + into 'docs' + } + from('./') { + include { + FileTreeElement details -> + details.file.name.endsWith('.md') + } + into './' + link("/usr/local/bin/elt","/opt/hirs/eventlog/scripts/eventlog.sh",0x755 ) + } +buildRpm { + arch = I386 +} +buildDeb { + arch = I386 +} +} \ No newline at end of file diff --git a/tools/tcg_eventlog_tool/libs/HIRS_Utils-1.1.1.jar b/tools/tcg_eventlog_tool/libs/HIRS_Utils-1.1.1.jar deleted file mode 100644 index 930698d3..00000000 Binary files a/tools/tcg_eventlog_tool/libs/HIRS_Utils-1.1.1.jar and /dev/null differ diff --git a/tools/tcg_eventlog_tool/scripts/eventlog.sh b/tools/tcg_eventlog_tool/scripts/eventlog.sh new file mode 100755 index 00000000..8bd9aff4 --- /dev/null +++ b/tools/tcg_eventlog_tool/scripts/eventlog.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# Calls the the_tcg_event_tool and passes in parameters +scriptDir=$(dirname -- "$(readlink -f -- "${BASH_SOURCE[0]}")") +baseDir=${scriptDir%/*} +libDir=$baseDir"/lib/" +jar="tcg_eventlog_tool-1.0.jar"; +java -jar $libDir$jar "$@" \ No newline at end of file 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 e958416c..27f0505a 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 @@ -37,6 +37,7 @@ public class Commander { private boolean bPCRs = false; private boolean bVerify = false; private boolean bHelp = false; + private boolean bDone = false; private String inFile = ""; private String inFile2 = ""; @@ -103,12 +104,14 @@ 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; @@ -141,8 +144,8 @@ public class Commander { break; case FULL_COMMAND_PREFIX + VERSION_STRING: case COMMAND_PREFIX + "v": - System.out.print("TCG Event Log Parser version " + VERSION_NUMBER); - bValidArgs = false; + System.out.print("TCG Event Log Parser version " + VERSION_NUMBER + "\n"); + bDone = true; break; case FULL_COMMAND_PREFIX + VERIFY_STRING: case COMMAND_PREFIX + "V": @@ -153,9 +156,9 @@ public class Commander { bHex = true; break; case FULL_COMMAND_PREFIX + HELP_STRING: + case COMMAND_PREFIX + "h": bHelp = true; break; - case COMMAND_PREFIX + "h": default: printHelp(""); bValidArgs = false; @@ -171,14 +174,20 @@ public class Commander { public final boolean hasArguments() { return hasArguments; } - /** - * Getter for the input All flag. + * Getter for the validity of the commands. * @return true if the All flag was set. */ public final boolean getValidityFlag() { return bValidArgs; } + /** + * Getter for the Done flag. + * @return true if the Done flag was set. + */ + public final boolean getDoneFlag() { + return bDone; + } /** * Getter for the help flag. * @return true if the Help flag was set. @@ -193,7 +202,6 @@ public class Commander { public final boolean getPCRFlag() { return bPCRs; } - /** * Getter for the input associated with the Event flag. * @return true if the Event Flag was set. @@ -201,7 +209,6 @@ public class Commander { public final boolean getContentFlag() { return bContentHex; } - /** * Getter for the input associated with the Event Hex flag. * @return true if the Hex Flag was set. @@ -216,7 +223,6 @@ public class Commander { public final boolean getHexFlag() { return bHex; } - /** * Getter for the input associated with the EventIds flag. * @return true of EventIds Flag was set. @@ -224,7 +230,6 @@ public class Commander { public final boolean getEventIdsFlag() { return bEventIds; } - /** * Getter for the input associated with the File flag. * @return true if File Flag was set. @@ -239,7 +244,6 @@ public class Commander { public final boolean getDiffFlag() { return bDiff; } - /** * Getter for the input associated with the Verify flag. * @return true if the verify flag was set @@ -324,9 +328,9 @@ public class Commander { + "\n\t\t\t Following parameter MUST be a path and file name." + "\n\t\t\t The local Event Log file will be used if this option is not present." + "\n\t\t\t Note: Access to the local Event Log may require admin privileges.\n" - + " -e\t--event\t\t Display event descriptions (including event content) in " + + " -e\t--event\t Display event descriptions (including event content) in " + "human readable form." - + "\n\t\t\t Following optional parameter is a single pcr id used to filter" + + "\n\t\t\t Following optional parameter is a single event number used to filter" + " the output." + "\n\t\t\t All events will be displayed if the optional parameter is not +" + "provided.\n" @@ -344,7 +348,7 @@ public class Commander { + "\n\t\t\t No following parameters will display all PCRs.\n" + " -v\t--version\t Parser Version.\n" // + " -V\t--Verify\t Attempts to verify the log file against values." - + " -x\t--hex\t\t Displays output in hex format." + + " -x\t--hex\t\t Displays event in hex format. Use with -ec to get content." + "\n\t\t\t Use -e -ec and -ex options to filter output." + "\n\t\t\t All output will be human readble form if not present." + "\n\n"); 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 fd5bb6e1..1f8227c1 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,21 +26,24 @@ 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 wihtout processs due to issues with" - + " parameters provided."); - System.exit(1); +/** + * 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 wihtout processs due to issues with" + + " parameters provided."); + System.exit(1); + } + if (commander.hasArguments()) { + if (commander.getDoneFlag()) { + System.exit(0); } - if (commander.hasArguments()) { if (commander.getHelpFlag()) { commander.printHelp(""); - System.exit(1); + System.exit(0); } if (commander.getOutputFlag()) { try { @@ -80,10 +83,10 @@ final class Main { if (commander.getHexFlag()) { bHexFlag = true; } - } else { - System.out.print("Nothing to do: No Parameters provided."); - System.exit(1); - } // End commander processing +} else { + System.out.print("Nothing to do: No Parameters provided."); + System.exit(1); +} // End commander processing try { if (eventLog == null) { @@ -123,19 +126,23 @@ final class Main { + evLog.getEventList().size() + " events:\n\n"); } } + int eventCount = 0; for (TpmPcrEvent event: evLog.getEventList()) { - if ((commander.getEventNumber() == event.getPcrIndex()) + if ((commander.getEventNumber() == eventCount++) || commander.getEventNumber() == -1) { - if (bHexFlag) { - 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"); + 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"); + } + } else { + writeOut(event.toString(bEventFlag, bContentFlag, bHexEvent) + "\n"); + } } } } @@ -218,6 +225,7 @@ final class Main { byte[] evLog = openLog(logFileName1); byte[] evLog2 = openLog(logFileName2); StringBuilder sb = new StringBuilder(); + bHexFlag = commander.getHexFlag(); try { eventLog1 = new TCGEventLog(evLog); } catch (Exception e) {