Wip: working extract-cert, fix generate-key parameter passing

This commit is contained in:
Paul Schaub 2023-01-09 14:56:53 +01:00
parent e602cc16cc
commit efec4d9110
12 changed files with 430 additions and 122 deletions

View file

@ -4,31 +4,37 @@
package sop.external.operation;
import sop.external.ExternalSOP;
import sop.operation.Version;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;
public class VersionExternal implements Version {
private final Runtime runtime = Runtime.getRuntime();
private final String binary;
private final Properties environment;
public VersionExternal(String binaryName) {
public VersionExternal(String binaryName, Properties environment) {
this.binary = binaryName;
this.environment = environment;
}
@Override
public String getName() {
String[] command = new String[] {binary, "version"};
String[] env = ExternalSOP.propertiesToEnv(environment).toArray(new String[0]);
try {
Process process = runtime.exec(command);
Process process = runtime.exec(command, env);
BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = stdInput.readLine().trim();
if (line.contains(" ")) {
return line.substring(0, line.lastIndexOf(" "));
}
ExternalSOP.finish(process);
return line;
} catch (IOException e) {
throw new RuntimeException(e);
@ -38,13 +44,15 @@ public class VersionExternal implements Version {
@Override
public String getVersion() {
String[] command = new String[] {binary, "version"};
String[] env = ExternalSOP.propertiesToEnv(environment).toArray(new String[0]);
try {
Process process = runtime.exec(command);
Process process = runtime.exec(command, env);
BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = stdInput.readLine().trim();
if (line.contains(" ")) {
return line.substring(line.lastIndexOf(" ") + 1);
}
ExternalSOP.finish(process);
return line;
} catch (IOException e) {
throw new RuntimeException(e);
@ -54,14 +62,16 @@ public class VersionExternal implements Version {
@Override
public String getBackendVersion() {
String[] command = new String[] {binary, "version", "--backend"};
String[] env = ExternalSOP.propertiesToEnv(environment).toArray(new String[0]);
try {
Process process = runtime.exec(command);
Process process = runtime.exec(command, env);
BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()));
StringBuilder sb = new StringBuilder();
String line;
while ((line = stdInput.readLine()) != null) {
sb.append(line).append('\n');
}
ExternalSOP.finish(process);
return sb.toString();
} catch (IOException e) {
throw new RuntimeException(e);
@ -71,14 +81,16 @@ public class VersionExternal implements Version {
@Override
public String getExtendedVersion() {
String[] command = new String[] {binary, "version", "--extended"};
String[] env = ExternalSOP.propertiesToEnv(environment).toArray(new String[0]);
try {
Process process = runtime.exec(command);
Process process = runtime.exec(command, env);
BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()));
StringBuilder sb = new StringBuilder();
String line;
while ((line = stdInput.readLine()) != null) {
sb.append(line).append('\n');
}
ExternalSOP.finish(process);
return sb.toString();
} catch (IOException e) {
throw new RuntimeException(e);