mirror of
https://github.com/nsacyber/HIRS.git
synced 2025-04-16 15:29:16 +00:00
Merge pull request #667 from nsacyber/v3_issue-660
[#660] Add -V|--version for easy access to rimtool version number
This commit is contained in:
commit
b12f0654ea
@ -5,7 +5,13 @@ import hirs.swid.utils.TimestampArgumentValidator;
|
||||
import hirs.utils.rim.ReferenceManifestValidator;
|
||||
import com.beust.jcommander.JCommander;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class Main {
|
||||
|
||||
@ -19,6 +25,14 @@ public class Main {
|
||||
if (commander.isHelp()) {
|
||||
jc.usage();
|
||||
System.out.println(commander.printHelpExamples());
|
||||
} else if (commander.isVersion()) {
|
||||
try {
|
||||
byte[] content = Files.readAllBytes(Paths.get(SwidTagConstants.VERSION_FILE));
|
||||
String version = new String(content);
|
||||
System.out.println("TCG rimtool version: " + version);
|
||||
} catch (IOException e) {
|
||||
parseVersionFromJar();
|
||||
}
|
||||
} else {
|
||||
if (!commander.getVerifyFile().isEmpty()) {
|
||||
validator = new ReferenceManifestValidator();
|
||||
@ -103,4 +117,21 @@ public class Main {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method parses the version number from the jar filename in the absence of
|
||||
* the VERSION file expected with an rpm installation.
|
||||
*/
|
||||
private static void parseVersionFromJar() {
|
||||
System.out.println("Installation file VERSION not found.");
|
||||
String filename = new File(Main.class.getProtectionDomain()
|
||||
.getCodeSource()
|
||||
.getLocation()
|
||||
.getPath()).getName();
|
||||
Pattern pattern = Pattern.compile("(?<=tcg_rim_tool-)[0-9]\\.[0-9]\\.[0-9]");
|
||||
Matcher matcher = pattern.matcher(filename);
|
||||
if (matcher.find()) {
|
||||
System.out.println("TCG rimtool version: " + matcher.group());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,13 +12,18 @@ import javax.xml.namespace.QName;
|
||||
*/
|
||||
public class SwidTagConstants {
|
||||
|
||||
public static final String DEFAULT_KEYSTORE_FILE = "/opt/hirs/rimtool/data/keystore.jks";
|
||||
public static final String INSTALLATION_DIRECTORY = "/opt/rimtool";
|
||||
public static final String VERSION_FILE = INSTALLATION_DIRECTORY + "/VERSION";
|
||||
public static final String DEFAULT_KEYSTORE_FILE =
|
||||
INSTALLATION_DIRECTORY + "/data/keystore.jks";
|
||||
public static final String DEFAULT_KEYSTORE_PASSWORD = "password";
|
||||
public static final String DEFAULT_PRIVATE_KEY_ALIAS = "selfsigned";
|
||||
public static final String DEFAULT_ATTRIBUTES_FILE = "/opt/hirs/rimtool/data/rim_fields.json";
|
||||
public static final String DEFAULT_ATTRIBUTES_FILE =
|
||||
INSTALLATION_DIRECTORY + "/data/rim_fields.json";
|
||||
public static final String DEFAULT_ENGLISH = "en";
|
||||
|
||||
public static final String SIGNATURE_ALGORITHM_RSA_SHA256 = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256";
|
||||
public static final String SIGNATURE_ALGORITHM_RSA_SHA256 =
|
||||
"http://www.w3.org/2001/04/xmldsig-more#rsa-sha256";
|
||||
|
||||
public static final String SCHEMA_PACKAGE = "hirs.utils.xjc";
|
||||
public static final String SCHEMA_LANGUAGE = XMLConstants.W3C_XML_SCHEMA_NS_URI;
|
||||
|
@ -17,6 +17,11 @@ public class Commander {
|
||||
@Parameter(names = {"-c", "--create \"base\""}, order = 0,
|
||||
description = "The type of RIM to create. A base RIM will be created by default.")
|
||||
private String createType = "";
|
||||
@Parameter(names = {"-v", "--verify <path>"}, order = 3,
|
||||
description = "Specify a RIM file to verify.")
|
||||
private String verifyFile = "";
|
||||
@Parameter(names = {"-V", "--version"}, description = "Output the current version.")
|
||||
private boolean version = false;
|
||||
@Parameter(names = {"-a", "--attributes <path>"}, order = 1,
|
||||
description = "The configuration file holding attributes "
|
||||
+ "to populate the base RIM with.")
|
||||
@ -25,9 +30,6 @@ public class Commander {
|
||||
description = "The file to write the RIM out to. "
|
||||
+ "The RIM will be written to stdout by default.")
|
||||
private String outFile = "";
|
||||
@Parameter(names = {"-v", "--verify <path>"}, order = 3,
|
||||
description = "Specify a RIM file to verify.")
|
||||
private String verifyFile = "";
|
||||
@Parameter(names = {"-t", "--truststore <path>"}, order = 4,
|
||||
description = "The truststore to sign the base RIM created "
|
||||
+ "or to validate the signed base RIM.")
|
||||
@ -62,6 +64,13 @@ public class Commander {
|
||||
return createType;
|
||||
}
|
||||
|
||||
public String getVerifyFile() {
|
||||
return verifyFile;
|
||||
}
|
||||
|
||||
public boolean isVersion() {
|
||||
return version;
|
||||
}
|
||||
public String getAttributesFile() {
|
||||
return attributesFile;
|
||||
}
|
||||
@ -70,10 +79,6 @@ public class Commander {
|
||||
return outFile;
|
||||
}
|
||||
|
||||
public String getVerifyFile() {
|
||||
return verifyFile;
|
||||
}
|
||||
|
||||
public String getTruststoreFile() { return truststoreFile; }
|
||||
|
||||
public String getPrivateKeyFile() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user