From 2c41c402138f00154668d64fd7ec5694cb631d43 Mon Sep 17 00:00:00 2001 From: ME1312 Date: Fri, 19 Apr 2019 11:46:39 -0400 Subject: [PATCH] Move encryption keys to a variable --- .../net/ME1312/SubServers/Bungee/Network/Client.java | 4 ++-- .../Bungee/Network/Packet/PacketAuthorization.java | 3 ++- .../SubServers/Bungee/Network/SubDataServer.java | 2 ++ .../Bukkit/Network/Packet/PacketAuthorization.java | 6 ++++-- .../Client/Bukkit/Network/SubDataClient.java | 10 ++++++---- .../Sponge/Network/Packet/PacketAuthorization.java | 7 ++++--- .../Client/Sponge/Network/SubDataClient.java | 10 ++++++---- .../Host/Network/Packet/PacketAuthorization.java | 12 ++++-------- .../SubServers/Host/Network/SubDataClient.java | 10 ++++++---- .../Sync/Network/Packet/PacketAuthorization.java | 10 ++++++---- .../SubServers/Sync/Network/SubDataClient.java | 10 ++++++---- 11 files changed, 48 insertions(+), 36 deletions(-) diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Client.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Client.java index acfd1e43..2d4925c0 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Client.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Client.java @@ -86,7 +86,7 @@ public class Client { private void recievePacket(Value input) { try { - YAMLSection data = subdata.getCipher().decrypt(subdata.plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), input); + YAMLSection data = subdata.getCipher().decrypt(subdata.password, input); for (PacketIn packet : SubDataServer.decodePacket(this, data)) { boolean auth = authorized == null; if (auth || packet instanceof PacketAuthorization) { @@ -134,7 +134,7 @@ public class Client { public void sendPacket(PacketOut packet) { if (Util.isNull(packet)) throw new NullPointerException(); if (!isClosed()) try { - out.packValue(subdata.getCipher().encrypt(subdata.plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), SubDataServer.encodePacket(this, packet))); + out.packValue(subdata.getCipher().encrypt(subdata.password, SubDataServer.encodePacket(this, packet))); out.flush(); } catch (Throwable e) { e.printStackTrace(); diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketAuthorization.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketAuthorization.java index f83d0349..a8408f6c 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketAuthorization.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketAuthorization.java @@ -6,6 +6,7 @@ import net.ME1312.SubServers.Bungee.Library.Version.Version; import net.ME1312.SubServers.Bungee.Network.Client; import net.ME1312.SubServers.Bungee.Network.PacketIn; import net.ME1312.SubServers.Bungee.Network.PacketOut; +import net.ME1312.SubServers.Bungee.Network.SubDataServer; import net.ME1312.SubServers.Bungee.SubPlugin; /** @@ -49,7 +50,7 @@ public final class PacketAuthorization implements PacketIn, PacketOut { @Override public void execute(Client client, YAMLSection data) { try { - if (data.getRawString("password").equals(plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"))) { + if (data.getRawString("password").equals(Util.reflect(SubDataServer.class.getDeclaredField("password"), plugin.subdata))) { client.authorize(); client.sendPacket(new PacketAuthorization(0, "Successfully Logged in")); } else { diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/SubDataServer.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/SubDataServer.java index f3a7986a..ac9fa2e9 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/SubDataServer.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/SubDataServer.java @@ -34,6 +34,7 @@ public final class SubDataServer { private ServerSocket server; private Cipher cipher; protected SubPlugin plugin; + String password; /** * SubData Server Instance @@ -55,6 +56,7 @@ public final class SubDataServer { } if (UPnP.isUPnPAvailable() && plugin.config.get().getSection("Settings").getSection("UPnP", new YAMLSection()).getBoolean("Forward-SubData", false)) UPnP.openPortTCP(port); this.plugin = plugin; + this.password = plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"); this.cipher = (cipher != null)?cipher:new Cipher() { @Override public String getName() { diff --git a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Network/Packet/PacketAuthorization.java b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Network/Packet/PacketAuthorization.java index 8751a310..e375a6d3 100644 --- a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Network/Packet/PacketAuthorization.java +++ b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Network/Packet/PacketAuthorization.java @@ -15,16 +15,18 @@ import java.lang.reflect.Method; public final class PacketAuthorization implements PacketIn, PacketOut { private SubPlugin plugin; + private String password; - public PacketAuthorization(SubPlugin plugin) { + public PacketAuthorization(SubPlugin plugin, String password) { if (Util.isNull(plugin)) throw new NullPointerException(); this.plugin = plugin; + this.password = password; } @Override public YAMLSection generate() { YAMLSection json = new YAMLSection(); - json.set("password", plugin.config.get().getSection("Settings").getSection("SubData").getString("Password")); + json.set("password", password); return json; } diff --git a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Network/SubDataClient.java b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Network/SubDataClient.java index d39cd56c..961cf33b 100644 --- a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Network/SubDataClient.java +++ b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Network/SubDataClient.java @@ -38,6 +38,7 @@ public final class SubDataClient { private NamedContainer socket; private String name; private Cipher cipher; + private String password; private SubPlugin plugin; private LinkedList> queue; @@ -58,6 +59,7 @@ public final class SubDataClient { this.name = (name == null || name.length() > 0)?name:null; this.out = MessagePack.newDefaultPacker(socket.get().getOutputStream()); this.queue = new LinkedList>(); + this.password = plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"); this.cipher = (cipher != null)?cipher:new Cipher() { @Override public String getName() { @@ -77,7 +79,7 @@ public final class SubDataClient { if (!defaults) loadDefaults(); loop(); - sendPacket(new NamedContainer<>(null, new PacketAuthorization(plugin))); + sendPacket(new NamedContainer<>(null, new PacketAuthorization(plugin, password))); } private void init() { @@ -98,7 +100,7 @@ public final class SubDataClient { } private void loadDefaults() { defaults = true; - registerPacket(new PacketAuthorization(plugin), "SubData", "Authorization"); + registerPacket(new PacketAuthorization(plugin, null), "SubData", "Authorization"); registerPacket(new PacketCommandServer(), "SubServers", "CommandServer"); registerPacket(new PacketCreateServer(), "SubServers", "CreateServer"); registerPacket(new PacketDownloadGroupInfo(), "SubServers", "DownloadGroupInfo"); @@ -160,7 +162,7 @@ public final class SubDataClient { private void recieve(Value input) { try { - YAMLSection data = cipher.decrypt(plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), input); + YAMLSection data = cipher.decrypt(password, input); for (PacketIn packet : decodePacket(data)) { if (plugin.isEnabled()) Bukkit.getScheduler().runTask(plugin, () -> { try { @@ -332,7 +334,7 @@ public final class SubDataClient { try { YAMLSection data = encodePacket(packet.get()); if (packet.name() != null) data.set("f", packet.name()); - out.packValue(getCipher().encrypt(plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), data)); + out.packValue(getCipher().encrypt(password, data)); out.flush(); } catch (Throwable e) { e.printStackTrace(); diff --git a/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/Network/Packet/PacketAuthorization.java b/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/Network/Packet/PacketAuthorization.java index 5df32483..f43ab93f 100644 --- a/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/Network/Packet/PacketAuthorization.java +++ b/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/Network/Packet/PacketAuthorization.java @@ -17,17 +17,18 @@ import java.lang.reflect.Method; public final class PacketAuthorization implements PacketIn, PacketOut { private SubPlugin plugin; private Logger log = null; + private String password; - public PacketAuthorization(SubPlugin plugin) { + public PacketAuthorization(SubPlugin plugin, String password) { if (Util.isNull(plugin)) throw new NullPointerException(); this.plugin = plugin; - Util.isException(() -> this.log = Util.reflect(SubDataClient.class.getDeclaredField("log"), null)); + this.password = password; } @Override public YAMLSection generate() { YAMLSection json = new YAMLSection(); - json.set("password", plugin.config.get().getSection("Settings").getSection("SubData").getString("Password")); + json.set("password", password); return json; } diff --git a/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/Network/SubDataClient.java b/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/Network/SubDataClient.java index 7dcab99c..d1dc5799 100644 --- a/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/Network/SubDataClient.java +++ b/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/Network/SubDataClient.java @@ -41,6 +41,7 @@ public final class SubDataClient { private NamedContainer socket; private String name; private Cipher cipher; + private String password; private SubPlugin plugin; private LinkedList> queue; @@ -61,6 +62,7 @@ public final class SubDataClient { this.name = (name == null || name.length() > 0)?name:null; this.out = MessagePack.newDefaultPacker(socket.get().getOutputStream()); this.queue = new LinkedList>(); + this.password = plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"); this.cipher = (cipher != null)?cipher:new Cipher() { @Override public String getName() { @@ -80,7 +82,7 @@ public final class SubDataClient { if (!defaults) loadDefaults(); loop(); - sendPacket(new NamedContainer<>(null, new PacketAuthorization(plugin))); + sendPacket(new NamedContainer<>(null, new PacketAuthorization(plugin, password))); } private void init() { @@ -102,7 +104,7 @@ public final class SubDataClient { defaults = true; log = LoggerFactory.getLogger("SubData"); - registerPacket(new PacketAuthorization(plugin), "SubData", "Authorization"); + registerPacket(new PacketAuthorization(plugin, null), "SubData", "Authorization"); registerPacket(new PacketCommandServer(), "SubServers", "CommandServer"); registerPacket(new PacketCreateServer(), "SubServers", "CreateServer"); registerPacket(new PacketDownloadGroupInfo(), "SubServers", "DownloadGroupInfo"); @@ -164,7 +166,7 @@ public final class SubDataClient { private void recieve(Value input) { try { - YAMLSection data = getCipher().decrypt(plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), input); + YAMLSection data = getCipher().decrypt(password, input); for (PacketIn packet : decodePacket(data)) { Sponge.getScheduler().createTaskBuilder().execute(() -> { try { @@ -336,7 +338,7 @@ public final class SubDataClient { try { YAMLSection data = encodePacket(packet.get()); if (packet.name() != null) data.set("f", packet.name()); - out.packValue(getCipher().encrypt(plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), data)); + out.packValue(getCipher().encrypt(password, data)); out.flush(); } catch (Throwable e) { e.printStackTrace(); diff --git a/SubServers.Host/src/net/ME1312/SubServers/Host/Network/Packet/PacketAuthorization.java b/SubServers.Host/src/net/ME1312/SubServers/Host/Network/Packet/PacketAuthorization.java index b45b3944..210b5bfb 100644 --- a/SubServers.Host/src/net/ME1312/SubServers/Host/Network/Packet/PacketAuthorization.java +++ b/SubServers.Host/src/net/ME1312/SubServers/Host/Network/Packet/PacketAuthorization.java @@ -20,22 +20,18 @@ import java.lang.reflect.Method; public final class PacketAuthorization implements PacketIn, PacketOut { private ExHost host; private Logger log = null; + private String password; - /** - * New PacketAuthorization - * - * @param host SubServers.Host - */ - public PacketAuthorization(ExHost host) { + public PacketAuthorization(ExHost host, String password) { if (Util.isNull(host)) throw new NullPointerException(); this.host = host; - Util.isException(() -> this.log = Util.reflect(SubDataClient.class.getDeclaredField("log"), null)); + this.password = password; } @Override public YAMLSection generate() { YAMLSection json = new YAMLSection(); - json.set("password", host.config.get().getSection("Settings").getSection("SubData").getString("Password")); + json.set("password", password); return json; } diff --git a/SubServers.Host/src/net/ME1312/SubServers/Host/Network/SubDataClient.java b/SubServers.Host/src/net/ME1312/SubServers/Host/Network/SubDataClient.java index 54282f63..aae6a8c8 100644 --- a/SubServers.Host/src/net/ME1312/SubServers/Host/Network/SubDataClient.java +++ b/SubServers.Host/src/net/ME1312/SubServers/Host/Network/SubDataClient.java @@ -44,6 +44,7 @@ public final class SubDataClient { private NamedContainer socket; private String name; private Cipher cipher; + private String password; private ExHost host; private LinkedList> queue; @@ -64,6 +65,7 @@ public final class SubDataClient { this.name = name; this.out = MessagePack.newDefaultPacker(socket.get().getOutputStream()); this.queue = new LinkedList>(); + this.password = host.config.get().getSection("Settings").getSection("SubData").getRawString("Password"); this.cipher = (cipher != null)?cipher:new Cipher() { @Override public String getName() { @@ -83,7 +85,7 @@ public final class SubDataClient { if (!defaults) loadDefaults(); loop(); - sendPacket(new NamedContainer<>(null, new PacketAuthorization(host))); + sendPacket(new NamedContainer<>(null, new PacketAuthorization(host, password))); } private void init() { @@ -107,7 +109,7 @@ public final class SubDataClient { defaults = true; log = new Logger("SubData"); - registerPacket(new PacketAuthorization(host), "SubData", "Authorization"); + registerPacket(new PacketAuthorization(host, null), "SubData", "Authorization"); registerPacket(new PacketCommandServer(), "SubServers", "CommandServer"); registerPacket(new PacketCreateServer(), "SubServers", "CreateServer"); registerPacket(new PacketDownloadGroupInfo(), "SubServers", "DownloadGroupInfo"); @@ -184,7 +186,7 @@ public final class SubDataClient { private void recieve(Value input) { try { - YAMLSection data = cipher.decrypt(host.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), input); + YAMLSection data = cipher.decrypt(password, input); for (PacketIn packet : decodePacket(data)) { try { packet.execute((data.contains("c"))?data.getSection("c"):null); @@ -354,7 +356,7 @@ public final class SubDataClient { try { YAMLSection data = encodePacket(packet.get()); if (packet.name() != null) data.set("f", packet.name()); - out.packValue(getCipher().encrypt(host.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), data)); + out.packValue(getCipher().encrypt(password, data)); out.flush(); } catch (Throwable e) { log.error.println(e); diff --git a/SubServers.Sync/src/net/ME1312/SubServers/Sync/Network/Packet/PacketAuthorization.java b/SubServers.Sync/src/net/ME1312/SubServers/Sync/Network/Packet/PacketAuthorization.java index 9e83a074..cf9fab9f 100644 --- a/SubServers.Sync/src/net/ME1312/SubServers/Sync/Network/Packet/PacketAuthorization.java +++ b/SubServers.Sync/src/net/ME1312/SubServers/Sync/Network/Packet/PacketAuthorization.java @@ -13,17 +13,19 @@ import java.lang.reflect.Method; public final class PacketAuthorization implements PacketIn, PacketOut { private SubPlugin plugin; + private String password; - public PacketAuthorization(SubPlugin plugin) { + public PacketAuthorization(SubPlugin plugin, String password) { if (Util.isNull(plugin)) throw new NullPointerException(); this.plugin = plugin; + this.password = password; } @Override public YAMLSection generate() { - YAMLSection data = new YAMLSection(); - data.set("password", plugin.config.get().getSection("Settings").getSection("SubData").getString("Password")); - return data; + YAMLSection json = new YAMLSection(); + json.set("password", password); + return json; } @Override diff --git a/SubServers.Sync/src/net/ME1312/SubServers/Sync/Network/SubDataClient.java b/SubServers.Sync/src/net/ME1312/SubServers/Sync/Network/SubDataClient.java index bcc02055..cbc0cf26 100644 --- a/SubServers.Sync/src/net/ME1312/SubServers/Sync/Network/SubDataClient.java +++ b/SubServers.Sync/src/net/ME1312/SubServers/Sync/Network/SubDataClient.java @@ -47,6 +47,7 @@ public final class SubDataClient { private NamedContainer socket; private String name = null; private Cipher cipher; + private String password; private SubPlugin plugin; private LinkedList> queue; @@ -65,6 +66,7 @@ public final class SubDataClient { this.plugin = plugin; this.name = (name == null || name.length() > 0)?name:null; this.out = MessagePack.newDefaultPacker(socket.get().getOutputStream()); + this.password = plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"); this.cipher = (cipher != null)?cipher:new Cipher() { @Override public String getName() { @@ -85,7 +87,7 @@ public final class SubDataClient { if (!defaults) loadDefaults(); loop(); - sendPacket(new NamedContainer<>(null, new PacketAuthorization(plugin))); + sendPacket(new NamedContainer<>(null, new PacketAuthorization(plugin, password))); } private void init() { @@ -131,7 +133,7 @@ public final class SubDataClient { } private void loadDefaults() { defaults = true; - registerPacket(new PacketAuthorization(plugin), "SubData", "Authorization"); + registerPacket(new PacketAuthorization(plugin, null), "SubData", "Authorization"); registerPacket(new PacketCommandServer(), "SubServers", "CommandServer"); registerPacket(new PacketCreateServer(), "SubServers", "CreateServer"); registerPacket(new PacketDownloadGroupInfo(), "SubServers", "DownloadGroupInfo"); @@ -193,7 +195,7 @@ public final class SubDataClient { private void recieve(Value input) { try { - YAMLSection data = cipher.decrypt(plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), input); + YAMLSection data = cipher.decrypt(password, input); for (PacketIn packet : decodePacket(data)) { try { packet.execute((data.contains("c")) ? data.getSection("c") : null); @@ -374,7 +376,7 @@ public final class SubDataClient { try { YAMLSection data = encodePacket(packet.get()); if (packet.name() != null) data.set("f", packet.name()); - out.packValue(getCipher().encrypt(plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), data)); + out.packValue(getCipher().encrypt(password, data)); out.flush(); } catch (Throwable e) { e.printStackTrace();