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 1f91e088..3d9daaf0 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 @@ -79,11 +79,13 @@ public class Main { } else { gateway.setRimEventLog(rimEventLog); } - if (!commander.getRfc3852Filename().isEmpty() && commander.isRfc3339()) { + String filename = commander.getRfc3852Filename(); + if (!filename.isEmpty() && commander.isRfc3339()) { System.out.println("Only one timestamp format can be specified"); System.exit(1); - } else if (!commander.getRfc3852Filename().isEmpty()) { - //pass file to gateway + } else if (!filename.isEmpty()) { + gateway.setTimestampFormat("RFC3852"); + gateway.setRfc3852Filename(filename); } else if (commander.isRfc3339()) { gateway.setTimestampFormat("RFC3339"); } 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 8b3120a7..ceb4e330 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 @@ -58,6 +58,8 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.math.BigInteger; +import java.nio.file.Files; +import java.nio.file.Paths; import java.security.InvalidAlgorithmParameterException; import java.security.KeyException; import java.security.NoSuchAlgorithmException; @@ -66,6 +68,7 @@ import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.time.LocalDateTime; import java.util.ArrayList; +import java.util.Base64; import java.util.Collections; import java.util.List; import java.util.Map; @@ -87,6 +90,7 @@ public class SwidTagGateway { private boolean embeddedCert; private String rimEventLog; private String timestampFormat; + private String rfc3852Filename; private String errorRequiredFields; /** @@ -102,6 +106,7 @@ public class SwidTagGateway { embeddedCert = false; rimEventLog = ""; timestampFormat = ""; + rfc3852Filename = ""; errorRequiredFields = ""; } catch (JAXBException e) { System.out.println("Error initializing jaxbcontext: " + e.getMessage()); @@ -180,6 +185,14 @@ public class SwidTagGateway { this.timestampFormat = timestampFormat; } + /** + * Setter for RFC3852 file path + * @param rfc3852Filename + */ + public void setRfc3852Filename(String rfc3852Filename) { + this.rfc3852Filename = rfc3852Filename; + } + /** * This method generates a base RIM from the values in a JSON file. * @@ -641,11 +654,18 @@ public class SwidTagGateway { Element timeStampElement = doc.createElement("TimeStamp"); switch (timestampFormat) { case "RFC3852": - timeStampElement.setAttributeNS("http://www.w3.org/2000/xmlns/", - "xmlns:" + SwidTagConstants.RFC3852_PFX, - SwidTagConstants.RFC3852_NS); - timeStampElement.setAttribute(SwidTagConstants.DATETIME, - "Base64 blob here"); + try { + byte[] counterSignature = Base64.getEncoder().encode( + Files.readAllBytes(Paths.get(rfc3852Filename))); + timeStampElement.setAttributeNS("http://www.w3.org/2000/xmlns/", + "xmlns:" + SwidTagConstants.RFC3852_PFX, + SwidTagConstants.RFC3852_NS); + timeStampElement.setAttribute(SwidTagConstants.DATETIME, + new String(counterSignature)); + } catch (IOException e) { + e.printStackTrace(); + System.exit(1); + } break; case "RFC3339": timeStampElement.setAttributeNS("http://www.w3.org/2000/xmlns/", 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 77ea96cf..d9f165c6 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 @@ -134,7 +134,7 @@ public class Commander { } sb.append("Event log support RIM: " + this.getRimEventLog() + System.lineSeparator()); if (!this.getRfc3852Filename().isEmpty()) { - sb.append("Timestamp format: RFC3852"); + sb.append("Timestamp format: RFC3852, " + this.getRfc3852Filename()); } else if (this.isRfc3339()) { sb.append("Timestamp format: RFC3339"); } else {