Commit 82054bb9 authored by Michael Menzel's avatar Michael Menzel
Browse files

secret key as start param

parent f60749a6
...@@ -28,6 +28,8 @@ import org.slf4j.Logger; ...@@ -28,6 +28,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import static net.sourceforge.argparse4j.impl.Arguments.store; import static net.sourceforge.argparse4j.impl.Arguments.store;
...@@ -41,13 +43,13 @@ import static net.sourceforge.argparse4j.impl.Arguments.store; ...@@ -41,13 +43,13 @@ import static net.sourceforge.argparse4j.impl.Arguments.store;
*/ */
public final class BackendServer { public final class BackendServer {
public static String secretKey = "abcddferti5iwiei";
private static int port; private static int port;
private static final Logger logger = LoggerFactory.getLogger(BackendServer.class); private static final Logger logger = LoggerFactory.getLogger(BackendServer.class);
public static Path basePath; public static Path basePath;
public static String dbfilepath; public static String dbfilepath;
public static String customtrackpath; public static String customtrackpath;
public static void main(String[] args) { public static void main(String[] args) {
logger.info("Starting Enhort backend server"); logger.info("Starting Enhort backend server");
...@@ -62,6 +64,7 @@ public final class BackendServer { ...@@ -62,6 +64,7 @@ public final class BackendServer {
parser.addArgument("--db").help("Path to sqlite metadata database").action(store()); parser.addArgument("--db").help("Path to sqlite metadata database").action(store());
parser.addArgument("--custom").help("Path to custom files").action(store()); parser.addArgument("--custom").help("Path to custom files").action(store());
parser.addArgument("-p", "--port").help("Port to listen on").setDefault(42412).action(store()); parser.addArgument("-p", "--port").help("Port to listen on").setDefault(42412).action(store());
parser.addArgument("-s", "--secret").help("Keyfile for encrpytion.").setDefault("/home/mmnz21/enhort/key.dat").action(store());
try { try {
input = parser.parseArgs(args); input = parser.parseArgs(args);
...@@ -79,7 +82,7 @@ public final class BackendServer { ...@@ -79,7 +82,7 @@ public final class BackendServer {
System.exit(1); System.exit(1);
} }
port = input.getInt("port"); port = Integer.parseInt(input.getString("port"));
if(input.getString("data_path") != null && input.getString("db") != null) { if(input.getString("data_path") != null && input.getString("db") != null) {
basePath = new File(input.getString("data_path")).toPath(); basePath = new File(input.getString("data_path")).toPath();
...@@ -102,6 +105,13 @@ public final class BackendServer { ...@@ -102,6 +105,13 @@ public final class BackendServer {
}).run(); }).run();
try {
secretKey = Files.readAllLines(new File(input.getString("secret")).toPath()).get(0);
} catch (IOException e) {
logger.warn("No secret key. Using unsafe hard-coded key for encryption.");
}
//run an inital client controller, which will listen to clients //run an inital client controller, which will listen to clients
ClientController server = new ClientController(port); ClientController server = new ClientController(port);
......
...@@ -28,11 +28,13 @@ import org.slf4j.Logger; ...@@ -28,11 +28,13 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import javax.crypto.SealedObject; import javax.crypto.SealedObject;
import java.io.*; import java.io.EOFException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.BindException; import java.net.BindException;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.nio.file.Files;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
...@@ -125,15 +127,7 @@ class ClientController implements Runnable{ ...@@ -125,15 +127,7 @@ class ClientController implements Runnable{
logger.error("[" + clientID + "]: " + "Exception {}", e.getMessage(), e); logger.error("[" + clientID + "]: " + "Exception {}", e.getMessage(), e);
} }
secret = BackendServer.secretKey;
try {
secret = Files.readAllLines(new File("/home/mmnz21/enhort/key.dat").toPath()).get(0);
} catch (IOException e) {
//e.printStackTrace();
logger.info("using local key");
secret = "abcddferti5iwiei";
}
} }
@Override @Override
......
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