Fix encryption disabling & some refactoring

This commit is contained in:
Govindass 2020-10-22 12:32:08 +03:00
parent 157e2b08c7
commit df8608802d
8 changed files with 36 additions and 21 deletions

View File

@ -1,6 +1,5 @@
package net.limework.core.events;
import org.bukkit.Bukkit;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;

View File

@ -1,6 +1,6 @@
package net.limework.core.managers;
import net.limework.Data.Encryption;
import net.limework.data.Encryption;
import net.limework.core.LimeworkSpigotCore;
import net.limework.core.events.RedisMessageEvent;
import net.md_5.bungee.api.chat.TextComponent;
@ -12,7 +12,6 @@ import org.bukkit.command.CommandSender;
import org.bukkit.configuration.Configuration;
import org.bukkit.entity.Player;
import org.cryptomator.siv.UnauthenticCiphertextException;
import org.jetbrains.annotations.NotNull;
import org.json.JSONObject;
import redis.clients.jedis.BinaryJedis;
import redis.clients.jedis.BinaryJedisPubSub;
@ -20,6 +19,7 @@ import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import javax.crypto.IllegalBlockSizeException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@ -125,19 +125,28 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable, Command
public void onMessage(byte[] channel, byte[] message) {
String channelString = new String(channel);
try {
String decrypted = null;
try {
decrypted = encryption.decrypt(message);
} catch (UnauthenticCiphertextException | IllegalBlockSizeException e) {
e.printStackTrace();
String receivedMessage = null;
//if encryption is enabled, decrypt the message, else just convert binary to string
if (this.encryption.isEncryptionEnabled()) {
try {
receivedMessage = encryption.decrypt(message);
} catch (UnauthenticCiphertextException | IllegalBlockSizeException e) {
e.printStackTrace();
}
} else {
//encryption is disabled, so let's just get the string
receivedMessage = new String(message, StandardCharsets.UTF_8);
}
if (receivedMessage != null) {
JSONObject j = new JSONObject(receivedMessage);
//System.out.println("Message got from channel: "+channel +" and the Message: " +json.toString());
plugin.getServer().getPluginManager().callEvent(new RedisMessageEvent(channelString, j.getString("Message")));
}
assert decrypted != null;
JSONObject j = new JSONObject(decrypted);
//System.out.println("Message got from channel: "+channel +" and the Message: " +json.toString());
plugin.getServer().getPluginManager().callEvent(new RedisMessageEvent(channelString, j.getString("Message")));
} catch (Exception e) {
e.printStackTrace();
Bukkit.getLogger().warning(ChatColor.translateAlternateColorCodes('&', "&2[&aGBot&a] &cI Got a Message that Was empty from channel " + channel + " Please check your code that you used to send the message. ^ ignore the error."));
Bukkit.getLogger().warning(ChatColor.translateAlternateColorCodes('&', "&2[&aRedisk&a] &cI got a message that was empty from channel " + channel + " please check your code that you used to send the message. ^ ignore the error."));
}
}
@ -176,11 +185,12 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable, Command
return encryption;
}
// the /reloadredis command
@Override
public boolean onCommand(CommandSender sender, Command cmd, String lable, String[] args) {
if (sender instanceof Player) {
sender.sendMessage(TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&'
, "&c&lYou can not execute this command!!!!!!")));
, "&cYou cannot execute this command.")));
return true;
}
isKilled.set(true);

View File

@ -1,5 +1,4 @@
package net.limework.core.skript.elements;
;
import ch.njol.skript.lang.Literal;
import ch.njol.skript.lang.SkriptEvent;
import ch.njol.skript.lang.SkriptParser;
@ -7,11 +6,8 @@ import org.bukkit.event.Event;
public class EvtRedis extends SkriptEvent {
@Override
public boolean init(Literal<?>[] literals, int i, SkriptParser.ParseResult parseResult) {
return true;
}

View File

@ -1,4 +1,4 @@
package net.limework.Data;
package net.limework.data;
import org.bukkit.configuration.Configuration;
import org.cryptomator.siv.SivMode;

View File

@ -1,17 +1,27 @@
Redis:
Password: "yHy0d2zdBlRmaSPj3CiBwEv5V3XxBTLTrCsGW7ntBnzhfxPxXJS6Q1aTtR6DSfAtCZr2VxWnsungXHTcF94a4bsWEpGAvjL6XMU"
#a secure password that cannot be cracked, please change it!
#it is also recommended to firewall your redis server with iptables so it can only be accessed by specific IP addresses
Password: "yHy0d2zdBlRmaSPj3CiBwEv5V3XxBTLTrCsGW7ntBnzhfxPxXJS6Q1aTtR6DSfAtCZr2VxWnsungXHTcF94a4bsWEpGAvjL9XMU"
Host: "127.0.0.1"
MaxConnections: 20
Threads: 10
#the default Redis port
Port: 6379
#time out in milliseconds, how long it should take before it decides that it is unable to connect when sending a message
#90000 = 90 seconds
TimeOut: 90000
#also known as TLS, only use this if you're running Redis 6.0.6 or higher, older versions will not work correctly
useSSL: false
#useful if SSL is disabled
#may be useful if you cannot use SSL due to use of older version of Redis
#however this will not encrypt the initial authentication password, only the messages sent
#also currently EncryptMessages is broken, meaning it must always be true or else it won't work
EncryptMessages: true
EncryptionKey: "16CHARACTERS KEY"
MacKey: "16CHARACTERS KEY"
#the channels from which this server can receive messages
#you can always send messages to all channels!
#you can add as many channels as you wish!
Channels:
- "Channel1"
- "Channel2"