Read in counter signature file contents, encode in base64, and place in Timestamp element

This commit is contained in:
chubtub 2022-12-08 08:10:58 -05:00
parent 054699d14d
commit 307d0b3fe4
3 changed files with 31 additions and 9 deletions

View File

@ -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");
}

View File

@ -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/",

View File

@ -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 {