GitLab wurde erfolgreich aktualisiert. Dank regelmäßiger Updates bleibt das THM GitLab sicher und Sie profitieren von den neuesten Funktionen. Danke für Ihre Geduld.

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

secret key as start param

parent f60749a6
......@@ -28,6 +28,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
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 static String secretKey = "abcddferti5iwiei";
private static int port;
private static final Logger logger = LoggerFactory.getLogger(BackendServer.class);
public static Path basePath;
public static String dbfilepath;
public static String customtrackpath;
public static void main(String[] args) {
logger.info("Starting Enhort backend server");
......@@ -62,6 +64,7 @@ public final class BackendServer {
parser.addArgument("--db").help("Path to sqlite metadata database").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("-s", "--secret").help("Keyfile for encrpytion.").setDefault("/home/mmnz21/enhort/key.dat").action(store());
try {
input = parser.parseArgs(args);
......@@ -79,7 +82,7 @@ public final class BackendServer {
System.exit(1);
}
port = input.getInt("port");
port = Integer.parseInt(input.getString("port"));
if(input.getString("data_path") != null && input.getString("db") != null) {
basePath = new File(input.getString("data_path")).toPath();
......@@ -102,6 +105,13 @@ public final class BackendServer {
}).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
ClientController server = new ClientController(port);
......
......@@ -28,11 +28,13 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.ServerSocket;
import java.net.Socket;
import java.nio.file.Files;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.atomic.AtomicInteger;
......@@ -125,15 +127,7 @@ class ClientController implements Runnable{
logger.error("[" + clientID + "]: " + "Exception {}", e.getMessage(), e);
}
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";
}
secret = BackendServer.secretKey;
}
@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