Commit f0dc4aa6 authored by Michael Menzel's avatar Michael Menzel

encryption key as param

parent 474e9069
......@@ -33,13 +33,11 @@ import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SealedObject;
import java.io.File;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.nio.file.Files;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Optional;
......@@ -71,19 +69,7 @@ public final class BackendConnector {
this.ip = ip;
id = clientID.getAndIncrement();
try {
secret = Files.readAllLines(new File("/home/mmnz21/enhort/key.dat").toPath()).get(0);
} catch (IOException e) {
try {
secret = Files.readAllLines(new File("/home/menzel/key.dat").toPath()).get(0);
} catch (IOException e1) {
logger.info("using unsafe hard-coded key");
secret = "abcddferti5iwiei";
}
}
secret = Settings.getSecret();
}
......
......@@ -13,6 +13,7 @@ public class Settings {
private static int port;
private static Logger logger = LoggerFactory.getLogger(StatisticsCollector.class);
private static String secret;
public static String getBackendip() {
return backendip;
......@@ -49,5 +50,13 @@ public class Settings {
public static void setPort(Integer p) {
port = p;
}
public static void setSecret(String s) {
secret = s;
}
public static String getSecret() {
return secret;
}
}
......@@ -29,6 +29,9 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import java.io.File;
import java.nio.file.Files;
import static net.sourceforge.argparse4j.impl.Arguments.store;
/**
......@@ -55,6 +58,7 @@ public class Webinterface {
parser.addArgument("-p", "--port").help("Port connect to").setDefault(42412).action(store());
parser.addArgument("--contigs-path").help("Path to contigs files.").action(store()).required(true);
parser.addArgument("--stat-path").help("Path to store statistics.").setDefault("tmp").action(store());
parser.addArgument("--secret").help("Path to key file for encryption").action(store());
try {
input = parser.parseArgs(args);
......@@ -68,6 +72,14 @@ public class Webinterface {
Settings.setStatfile_path(input.getString("stat_path"));
Settings.setPort(Integer.parseInt(input.getString("port")));
try {
Settings.setSecret(Files.readAllLines(new File(input.getString("secret")).toPath()).get(0));
} catch (Exception e) {
logger.warn("Using unsave hard-coded key for encryption.");
Settings.setSecret("abcddferti5iwiei");
}
try {
SpringApplication.run(Webinterface.class, args);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment