diff --git a/dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/CLIMain.java b/dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/CLIMain.java index 4ebd8f6..9599c85 100644 --- a/dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/CLIMain.java +++ b/dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/CLIMain.java @@ -16,6 +16,7 @@ import com.vecsight.dragonite.forwarder.network.server.ForwarderServer; import com.vecsight.dragonite.mux.misc.MuxGlobalConstants; import com.vecsight.dragonite.sdk.exception.DragoniteException; +import com.vecsight.dragonite.sdk.exception.EncryptionException; import com.vecsight.dragonite.sdk.misc.DragoniteGlobalConstants; import com.vecsight.dragonite.utils.misc.UpdateChecker; import org.apache.commons.cli.*; @@ -42,6 +43,14 @@ public final class CLIMain { private static Options getOptions() { final Options options = new Options(); + options.addOption(Option + .builder("k") + .longOpt("password") + .desc("Encryption password for both client and server") + .hasArg() + .argName("xxx") + .type(String.class) + .build()); options.addOption(Option .builder("s") .longOpt("server-mode") @@ -266,6 +275,9 @@ public static void main(final String[] args) { if (commandLine.hasOption("window-size-multiplier")) { config.setWindowMultiplier(((Number) commandLine.getParsedOptionValue("window-size-multiplier")).intValue()); } + if (commandLine.hasOption("k")) { + config.setPassword(commandLine.getOptionValue("k")); + } final ForwarderServer forwarderServer = new ForwarderServer(config); @@ -278,6 +290,8 @@ public static void main(final String[] args) { Logger.error(e, "Incorrect value"); } catch (SocketException | UnknownHostException e) { Logger.error(e, "Unable to initialize"); + } catch (EncryptionException e) { + Logger.error(e, "Encryption error"); } } else { Logger.error("Missing required argument(s): -f"); @@ -307,6 +321,9 @@ public static void main(final String[] args) { if (commandLine.hasOption("window-size-multiplier")) { config.setWindowMultiplier(((Number) commandLine.getParsedOptionValue("window-size-multiplier")).intValue()); } + if (commandLine.hasOption("k")) { + config.setPassword(commandLine.getOptionValue("k")); + } final ForwarderClient forwarderClient = new ForwarderClient(config); @@ -319,6 +336,8 @@ public static void main(final String[] args) { Logger.error(e, "Incorrect value"); } catch (InterruptedException | IOException | DragoniteException | IncorrectHeaderException | ServerRejectedException e) { Logger.error(e, "Unable to initialize"); + } catch (EncryptionException e) { + Logger.error(e, "Encryption error"); } } else { Logger.error("Missing required argument(s): -a / -f / -d / -u"); diff --git a/dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/config/ForwarderClientConfig.java b/dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/config/ForwarderClientConfig.java index b9e27c6..06fd2f3 100644 --- a/dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/config/ForwarderClientConfig.java +++ b/dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/config/ForwarderClientConfig.java @@ -7,7 +7,10 @@ package com.vecsight.dragonite.forwarder.config; +import com.vecsight.dragonite.forwarder.misc.ForwarderGlobalConstants; import com.vecsight.dragonite.sdk.config.DragoniteSocketParameters; +import com.vecsight.dragonite.sdk.cryptor.AESCryptor; +import com.vecsight.dragonite.sdk.exception.EncryptionException; import java.net.InetSocketAddress; @@ -20,6 +23,8 @@ public class ForwarderClientConfig { private int localPort; + private String password; + private int downMbps, upMbps; private final DragoniteSocketParameters dragoniteSocketParameters = new DragoniteSocketParameters(); @@ -67,6 +72,16 @@ public void setUpMbps(final int upMbps) { this.upMbps = upMbps; } + public String getPassword() { + return password; + } + + public void setPassword(final String password) throws EncryptionException { + checkArgument(password != null && password.length() >= ForwarderGlobalConstants.PASSWORD_MIN_LENGTH, "Invalid password"); + dragoniteSocketParameters.setPacketCryptor(new AESCryptor(password)); + this.password = password; + } + public int getMTU() { return dragoniteSocketParameters.getPacketSize(); } diff --git a/dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/config/ForwarderServerConfig.java b/dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/config/ForwarderServerConfig.java index cb0e6dc..a052320 100644 --- a/dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/config/ForwarderServerConfig.java +++ b/dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/config/ForwarderServerConfig.java @@ -7,7 +7,10 @@ package com.vecsight.dragonite.forwarder.config; +import com.vecsight.dragonite.forwarder.misc.ForwarderGlobalConstants; import com.vecsight.dragonite.sdk.config.DragoniteSocketParameters; +import com.vecsight.dragonite.sdk.cryptor.AESCryptor; +import com.vecsight.dragonite.sdk.exception.EncryptionException; import com.vecsight.dragonite.utils.system.SystemInfo; import java.net.InetSocketAddress; @@ -20,6 +23,8 @@ public class ForwarderServerConfig { private InetSocketAddress forwardingAddress; + private String password; + private int mbpsLimit = 0; private String welcomeMessage = "Welcome to " + SystemInfo.getHostname(); @@ -66,6 +71,16 @@ public void setWelcomeMessage(final String welcomeMessage) { this.welcomeMessage = welcomeMessage; } + public String getPassword() { + return password; + } + + public void setPassword(final String password) throws EncryptionException { + checkArgument(password != null && password.length() >= ForwarderGlobalConstants.PASSWORD_MIN_LENGTH, "Invalid password"); + dragoniteSocketParameters.setPacketCryptor(new AESCryptor(password)); + this.password = password; + } + public int getMTU() { return dragoniteSocketParameters.getPacketSize(); } diff --git a/dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/misc/ForwarderGlobalConstants.java b/dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/misc/ForwarderGlobalConstants.java index e464d48..755cdc8 100644 --- a/dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/misc/ForwarderGlobalConstants.java +++ b/dragonite-forwarder/src/main/java/com/vecsight/dragonite/forwarder/misc/ForwarderGlobalConstants.java @@ -34,6 +34,10 @@ public final class ForwarderGlobalConstants { public static final short MAX_FRAME_SIZE = 20480; + //Encryption shits + + public static final int PASSWORD_MIN_LENGTH = 4; + //Update shits public static final String UPDATE_API_URL = "https://github.com/dragonite-network/dragonite-java/raw/master/VERSIONS";