From 97ccab04730c0904860799fdfead6ed14d6a2bc4 Mon Sep 17 00:00:00 2001 From: chubtub <43381989+chubtub@users.noreply.github.com> Date: Tue, 20 Sep 2022 00:19:01 -0400 Subject: [PATCH] Modify Main and Commander classes to support options for RFC3161 and RFC3339 --- .../src/main/java/hirs/swid/Main.java | 5 +++++ .../src/main/java/hirs/swid/SwidTagGateway.java | 10 ++++++++++ .../main/java/hirs/swid/utils/Commander.java | 17 +++++++++++++++++ 3 files changed, 32 insertions(+) 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 b1fe58bc..4fccb799 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 @@ -81,6 +81,11 @@ public class Main { } else { gateway.setRimEventLog(rimEventLog); } + if (commander.isRfc3161()) { + gateway.setTimestampFormat("RFC3161"); + } else { + gateway.setTimestampFormat("RFC3339"); + } gateway.generateSwidTag(commander.getOutFile()); break; default: diff --git a/tools/tcg_rim_tool/src/main/java/hirs/swid/SwidTagGateway.java b/tools/tcg_rim_tool/src/main/java/hirs/swid/SwidTagGateway.java index 49097dcd..6a6b9681 100644 --- a/tools/tcg_rim_tool/src/main/java/hirs/swid/SwidTagGateway.java +++ b/tools/tcg_rim_tool/src/main/java/hirs/swid/SwidTagGateway.java @@ -86,6 +86,7 @@ public class SwidTagGateway { private String pemCertificateFile; private boolean embeddedCert; private String rimEventLog; + private String timestampFormat; private String errorRequiredFields; /** @@ -100,6 +101,7 @@ public class SwidTagGateway { pemCertificateFile = ""; embeddedCert = false; rimEventLog = ""; + timestampFormat = ""; errorRequiredFields = ""; } catch (JAXBException e) { System.out.println("Error initializing jaxbcontext: " + e.getMessage()); @@ -170,6 +172,14 @@ public class SwidTagGateway { this.rimEventLog = rimEventLog; } + /** + * Setter for timestamp format in XML signature + * @param timestampFormat + */ + public void setTimestampFormat(String timestampFormat) { + this.timestampFormat = timestampFormat; + } + /** * This method generates a base RIM from the values in a JSON file. * diff --git a/tools/tcg_rim_tool/src/main/java/hirs/swid/utils/Commander.java b/tools/tcg_rim_tool/src/main/java/hirs/swid/utils/Commander.java index a769409b..9cf3d2d0 100644 --- a/tools/tcg_rim_tool/src/main/java/hirs/swid/utils/Commander.java +++ b/tools/tcg_rim_tool/src/main/java/hirs/swid/utils/Commander.java @@ -45,6 +45,12 @@ public class Commander { @Parameter(names = {"-l", "--rimel "}, order = 9, description = "The TCG eventlog file to use as a support RIM.") private String rimEventLog = ""; + @Parameter(names = {"--rfc3161"}, order = 10, + description = "Add a timestamp to the signature that is compliant with RFC3161.") + private boolean rfc3161 = false; + @Parameter(names = {"--rfc3339"}, order = 11, + description = "Add a timestamp to the signature that is compliant with RFC3339.") + private boolean rfc3339 = false; public boolean isHelp() { return help; @@ -82,6 +88,10 @@ public class Commander { public String getRimEventLog() { return rimEventLog; } + public boolean isRfc3161() { return rfc3161; } + + public boolean isRfc3339() { return rfc3339; } + public String printHelpExamples() { StringBuilder sb = new StringBuilder(); sb.append("Create a base RIM using the values in attributes.json; " + @@ -123,6 +133,13 @@ public class Commander { sb.append("Signing credential: (none given)" + System.lineSeparator()); } sb.append("Event log support RIM: " + this.getRimEventLog() + System.lineSeparator()); + if (isRfc3161()) { + sb.append("Timestamp format: RFC3161"); + } else if (isRfc3339()) { + sb.append("Timestamp format: RFC3339"); + } else { + sb.append("Timestamp format: defaulting to RFC3339"); + } return sb.toString(); } }