Skip to content
This repository has been archived by the owner on May 11, 2020. It is now read-only.

Commit

Permalink
add -k arg support to forwarder (#7)
Browse files Browse the repository at this point in the history
encryption support for forwarder
  • Loading branch information
wxdao authored and tobyxdd committed Oct 27, 2017
1 parent d265ff2 commit 411d54e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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")
Expand Down Expand Up @@ -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);

Expand All @@ -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");
Expand Down Expand Up @@ -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);

Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -20,6 +23,8 @@ public class ForwarderClientConfig {

private int localPort;

private String password;

private int downMbps, upMbps;

private final DragoniteSocketParameters dragoniteSocketParameters = new DragoniteSocketParameters();
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,6 +23,8 @@ public class ForwarderServerConfig {

private InetSocketAddress forwardingAddress;

private String password;

private int mbpsLimit = 0;

private String welcomeMessage = "Welcome to " + SystemInfo.getHostname();
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 411d54e

Please sign in to comment.