From c6bbe00d0f25c42cfa8bcef786df242fd4e77256 Mon Sep 17 00:00:00 2001 From: chubtub <43381989+chubtub@users.noreply.github.com> Date: Fri, 23 Feb 2024 02:28:13 -0500 Subject: [PATCH] Merge changes from issue-692. Implement CredentialArgumentValidator. Remove extraneous code with the additions of exitWithErrorCode(String) and FileArgumentValidator. --- .../src/main/java/hirs/swid/Main.java | 51 ++++++------------- 1 file changed, 15 insertions(+), 36 deletions(-) diff --git a/tools/tcg_rim_tool/src/main/java/hirs/swid/Main.java b/tools/tcg_rim_tool/src/main/java/hirs/swid/Main.java index f02c001d..baa8412f 100644 --- a/tools/tcg_rim_tool/src/main/java/hirs/swid/Main.java +++ b/tools/tcg_rim_tool/src/main/java/hirs/swid/Main.java @@ -56,26 +56,20 @@ public class Main { String verifyFile = commander.getVerifyFile(); String rimel = commander.getRimEventLog(); String trustStore = commander.getTruststoreFile(); - validator.setRim(verifyFile); - validator.setRimEventLog(rimel); + validator.setRim(verifyFile); + validator.setRimEventLog(rimel); + credValidator = new CredentialArgumentValidator(trustStore, + "","", true); + if (credValidator.isValid()) { validator.setTrustStoreFile(trustStore); - if (!certificateFile.isEmpty()) { - System.out.println("A single cert cannot be used for verification. " + - "The signing cert will be searched for in the trust store."); - credValidator = new CredentialArgumentValidator(trustStore, - "","", true); - if (credValidator.isValid()) { - validator.setTrustStoreFile(trustStore); - } else { - System.out.println(credValidator.getErrorMessage()); - System.exit(1); - } - if (validator.validateSwidtagFile(verifyFile)) { - System.out.println("Successfully verified " + verifyFile); - } else { - System.out.println("Failed to verify " + verifyFile); - System.exit(1); - } + } else { + exitWithErrorCode(credValidator.getErrorMessage()); + } + if (validator.validateSwidtagFile(verifyFile)) { + System.out.println("Successfully verified " + verifyFile); + } else { + exitWithErrorCode("Failed to verify " + verifyFile); + } } else { gateway = new SwidTagGateway(); if (commander.isVerbose()) { @@ -90,18 +84,8 @@ public class Main { String rimEventLog = commander.getRimEventLog(); switch (createType) { case "BASE": - if (!attributesFile.isEmpty()) { - gateway.setAttributesFile(attributesFile); - } else { - System.out.println("An attribute file is required."); - System.exit(1); - } - if (!rimEventLog.isEmpty()) { - gateway.setRimEventLog(rimEventLog); - } else { - System.out.println("A support RIM is required."); - System.exit(1); - } + gateway.setAttributesFile(attributesFile); + gateway.setRimEventLog(rimEventLog); credValidator = new CredentialArgumentValidator("" , certificateFile, privateKeyFile, false); if (defaultKey){ @@ -117,11 +101,6 @@ public class Main { } else { exitWithErrorCode(credValidator.getErrorMessage()); } - if (rimEventLog.isEmpty()) { - exitWithErrorCode("A support RIM is required."); - } else { - gateway.setRimEventLog(rimEventLog); - } List timestampArguments = commander.getTimestampArguments(); if (timestampArguments.size() > 0) { if (new TimestampArgumentValidator(timestampArguments).isValid()) {