Skip to content

Commit

Permalink
Cleanup test output on -x, set param default using local event log, a…
Browse files Browse the repository at this point in the history
…dded param checks
  • Loading branch information
iadgovuser26 committed Jun 12, 2020
1 parent 7ab7408 commit 5c61688
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 23 deletions.
2 changes: 1 addition & 1 deletion tools/scripts/eventcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;;
Expand Down
13 changes: 8 additions & 5 deletions tools/scripts/identity_transform.xslt
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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("");
}
}

Expand All @@ -74,14 +78,22 @@ 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:
case COMMAND_PREFIX + "e":
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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -163,6 +172,7 @@ public final void parseArguments(final String[] args) {
printHelp("");
bValidArgs = false;
}
}
}
}

Expand Down Expand Up @@ -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. "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 5c61688

Please sign in to comment.