Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/L2jOne_C6_Interlude/config/server.properties b/L2jOne_C6_Interlude/config/server.properties
- index 1673b7c..42b8b90 100644
- --- a/L2jOne_C6_Interlude/config/server.properties
- +++ b/L2jOne_C6_Interlude/config/server.properties
- @@ -23,6 +23,11 @@
- # /!\ Don't edit this value and reload config while the server is running. It would lead to all connected clients to become unresponsive (waiting de/crypted packets, but receiving the versus).
- UseBlowfishCipher = True
- +# Guard System Encryption keys
- +# ATTENTION: Don't change this if you don't know what are you doing
- +ClientKey = ffeeddccbbaa99887766554433221100ffeeddccbbaa99887766554433221100
- +ServerKey = 00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff
- +
- # ================================================================
- # Database informations
- # ================================================================
- diff --git a/L2jOne_C6_Interlude/java/guard/GuardSystem.java b/L2jOne_C6_Interlude/java/guard/GuardSystem.java
- new file mode 100644
- index 0000000..cca1121
- --- /dev/null
- +++ b/L2jOne_C6_Interlude/java/guard/GuardSystem.java
- @@ -0,0 +1,117 @@
- +package guard;
- +
- +import java.sql.Connection;
- +import java.sql.PreparedStatement;
- +import java.sql.ResultSet;
- +import java.sql.SQLException;
- +import java.util.List;
- +import java.util.concurrent.CopyOnWriteArrayList;
- +
- +import net.sf.l2j.commons.logging.CLogger;
- +import net.sf.l2j.commons.pool.ConnectionPool;
- +
- +import net.sf.l2j.Config;
- +import net.sf.l2j.gameserver.model.actor.Player;
- +import net.sf.l2j.gameserver.network.GameClient;
- +
- +public class GuardSystem
- +{
- + private static final CLogger LOGGER = new CLogger(GuardSystem.class.getName());
- +
- + private static final String LOAD_bans = "SELECT `hwid` FROM `banned_hwids`";
- + private static final String ADD_TO_bans = "INSERT INTO `banned_hwids` VALUES (?)";
- + private static final String REMOVE_FROM_bans = "DELETE FROM `banned_hwids` WHERE `hwid` = ?";
- +
- + private List<String> _bans = new CopyOnWriteArrayList<>();
- +
- + public GuardSystem()
- + {
- + _bans.clear();
- + try (Connection conn = ConnectionPool.getConnection())
- + {
- + try (PreparedStatement ps = conn.prepareStatement(LOAD_bans))
- + {
- + try (ResultSet rs = ps.executeQuery())
- + {
- + while (rs.next())
- + _bans.add(rs.getString(1));
- + }
- + }
- + }
- + catch (SQLException ex)
- + {
- + LOGGER.warn("Failed to load banned HWIDs from DB.", ex);
- + }
- +
- + LOGGER.info("Loaded {} banned HWIDs from DB.", _bans.size());
- + }
- +
- + public void ban(Player player)
- + {
- + if (player == null || Config.ALLOWED_GUARD_SYSTEM)
- + return;
- +
- + final GameClient client = player.getClient();
- + if (client == null)
- + return;
- +
- + _bans.add(client.getHwid());
- +
- + try (Connection conn = ConnectionPool.getConnection())
- + {
- + try (PreparedStatement ps = conn.prepareStatement(ADD_TO_bans))
- + {
- + ps.setString(1, client.getHwid());
- + ps.executeUpdate();
- + }
- + }
- + catch (SQLException ex)
- + {
- + LOGGER.warn("Failed to store banned HWID in DB.", ex);
- + }
- + }
- +
- + public void unban(String hwid)
- + {
- + if (hwid == null || Config.ALLOWED_GUARD_SYSTEM)
- + return;
- +
- + if (_bans.contains(hwid))
- + {
- + _bans.remove(hwid);
- + try (Connection conn = ConnectionPool.getConnection())
- + {
- + try (PreparedStatement ps = conn.prepareStatement(REMOVE_FROM_bans))
- + {
- + ps.setString(1, hwid);
- + ps.executeUpdate();
- + }
- + }
- + catch (SQLException ex)
- + {
- + LOGGER.warn("Failed to remove banned HWID from DB.", ex);
- + }
- + }
- + }
- +
- + public boolean isBanned(String hwid)
- + {
- + return _bans.contains(hwid);
- + }
- +
- + public boolean isBanned(Player player)
- + {
- + final GameClient client = player.getClient();
- + return client != null && isBanned(client.getHwid());
- + }
- +
- + public static GuardSystem getInstance()
- + {
- + return SingletonHolder.INSTANCE;
- + }
- +
- + private static class SingletonHolder
- + {
- + protected static final GuardSystem INSTANCE = new GuardSystem();
- + }
- +}
- \ No newline at end of file
- diff --git a/L2jOne_C6_Interlude/java/guard/crypt/LameCrypt.java b/L2jOne_C6_Interlude/java/guard/crypt/LameCrypt.java
- new file mode 100644
- index 0000000..9f9e14b
- --- /dev/null
- +++ b/L2jOne_C6_Interlude/java/guard/crypt/LameCrypt.java
- @@ -0,0 +1,38 @@
- +package guard.crypt;
- +
- +import net.sf.l2j.Config;
- +
- +public class LameCrypt
- +{
- + private boolean _enabled;
- +
- + private VMPC _c;
- + private VMPC _s;
- +
- + public LameCrypt()
- + {
- + _c = new VMPC();
- + _s = new VMPC();
- + }
- +
- + public void init(byte[] iv)
- + {
- + iv = LameKey.expandKey(iv);
- + _c.setup(LameKey.expandKey(Config.CLIENT_KEY.getBytes()), iv);
- + _s.setup(LameKey.expandKey(Config.SERVER_KEY.getBytes()), iv);
- + }
- +
- + public void decrypt(final byte[] raw, final int offset, final int size)
- + {
- + if (_enabled)
- + _c.crypt(raw, offset, size);
- + }
- +
- + public void encrypt(final byte[] raw, final int offset, final int size)
- + {
- + if (!_enabled)
- + _enabled = true;
- + else
- + _s.crypt(raw, offset, size);
- + }
- +}
- \ No newline at end of file
- diff --git a/L2jOne_C6_Interlude/java/guard/crypt/LameKey.java b/L2jOne_C6_Interlude/java/guard/crypt/LameKey.java
- new file mode 100644
- index 0000000..72a7d4d
- --- /dev/null
- +++ b/L2jOne_C6_Interlude/java/guard/crypt/LameKey.java
- @@ -0,0 +1,55 @@
- +package guard.crypt;
- +
- +public class LameKey
- +{
- + private static final byte[] TKBOX =
- + {
- + -112, 22, 124, -93, 68, -116, -19, -125, -4, 101, -62, 5, 70, 25,
- + 29, 81, 65, -86, 79, -69, 2, 97, -108, -11, -84, -56, 17, 7, 31, 52, -34, -41, -110, -60, 57, -5, -6, -24,
- + 98, -100, 23, 4, -74, -37, 1, 6, -2, -14, -77, 12, -7, 3, -29, -17, -75, 49, 44, -78, 94, 21, 0, 35, -18,
- + 83, 9, -42, 60, 93, 54, 20, -49, 114, 106, -82, 113, -90, 86, -124, -73, -81, 90, 121, 115, 125, 47, 24,
- + -28, 73, 56, -31, 8, 71, 122, 58, -33, 108, -111, 102, -118, -103, -122, 88, 28, -76, 67, -115, -67, 78, 36,
- + 117, -8, -25, -97, 107, -91, -50, -53, -52, 111, -114, -58, -128, 84, -98, 63, 74, 10, 41, -32,
- + 126, 69, -68, 11, -119, -44, -39, -107, -40, 85, -87, 61, 91, -1, 50, -72, -117, 15, 55, -51, 43, 87, 105,
- + 120, -88, 116, 80, -48, -123, -127, -105, -22, 76, 109, 19, -46, -30, 112, 16, -10, 45, -63, -47, 123, -106,
- + 27, 38, 104, -70, -79, 18, -99, -16, -85, -23, 30, -66, 48, -89, -61, -113, -12, 51, -95, -15, 32, -9, 62,
- + -38, 14, -45, -80, 66, 100, 103, -104, -27, -43, 110, -83, -26, -101, 46, -120, -54, 37, 42, 13, 75, 82,
- + -109, 26, -94, -57, -64, 119, 53, 39, -13, -121, 33, 72, -126, -65, -36, -71, 118, -35, 92, 96, 89, 64, 34,
- + -20, -96, 77, 40, 127, -21, 59, -55, -102, 95, -3, 99, -59, -92
- + };
- +
- + private static final byte[] MGBOX =
- + {
- + -14, -108, 90, 75, 15, 115, -38, -37, -125, 29, -77, 9, -4, 54,
- + -72, 70, 65, -44, -48, 85, -13, -121, 118, -102, 40, 53, 113, -5, -9, 28, 3, 125, 21, -124, 10, 67, -6, -98,
- + 96, -105, -104, 126, -93, 82, -47, 41, -91, 89, -59, 122, 47, 37, -31, 59, 56, 12, -112, -58, -39, -10, -40,
- + -49, 22, -107, 33, -89, 109, 31, 88, 81, 72, 42, -66, -85, -15, 93, -101, -7, -128, -19, -27, -90,
- + -11, 111, 49, -70, 121, 79, -123, -127, -79, 35, -28, 114, -22, 44, -54, 107, 106, 30, 92, 4, -43, -82, -78,
- + -26, -61, 57, 77, 95, 58, 69, -76, 103, -56, 78, 26, -92, 48, -32, -52, 16, -67, 51, -50, -73, -29, 52, -60,
- + -118, -1, -80, 63, 2, 124, -36, -65, 8, -33, -115, -3, 108, -21, 18, 110, 36, -51, 46, -103, 94, 20, -114,
- + 80, 127, -86, 19, -119, -113, 68, -25, -120, -71, 32, 38, -95, -57, 5, 7, 105, -17, -34, -81, 24,
- + -74, -35, 100, 1, -46, -94, 43, 13, 17, -87, 11, -69, -62, -126, -63, -64, -23, -97, 27, -18, -53, 84, 0,
- + -106, -83, 39, 116, 91, 104, 14, -24, -42, 34, -88, -84, 62, 61, -2, 112, 23, 119, 73, 6, -122, 55, -99,
- + -41, 83, 99, 60, 87, 45, 120, -55, 117, -117, 98, 123, -8, 76, -16, -30, 64, -96, -109, -75, 25, 101, -110,
- + 86, 50, 71, -12, 74, -100, -116, -68, 66, -20, -45, 102, -111, 97
- + };
- +
- + public static byte[] expandKey(byte[] key)
- + {
- + short i;
- + byte t, m;
- + byte[] P = new byte[64];
- +
- + for (i = 0; i < 64; i++)
- + P[i] = key[i % key.length];
- +
- + for (i = 0; i < 256; i++)
- + {
- + t = P[i % 64];
- + m = (byte) (MGBOX[MGBOX[t & 0xFF] & 0xFF] & 0xFF ^ TKBOX[TKBOX[i] & 0xFF] & 0xFF);
- + P[i % 64] = TKBOX[m & 0xFF];
- + }
- +
- + return P;
- + }
- +}
- \ No newline at end of file
- diff --git a/L2jOne_C6_Interlude/java/guard/crypt/VMPC.java b/L2jOne_C6_Interlude/java/guard/crypt/VMPC.java
- new file mode 100644
- index 0000000..6be832f
- --- /dev/null
- +++ b/L2jOne_C6_Interlude/java/guard/crypt/VMPC.java
- @@ -0,0 +1,54 @@
- +package guard.crypt;
- +
- +public class VMPC
- +{
- + private byte _n, _s;
- + private byte[] _P = new byte[256];
- +
- + private void ksa(byte[] key)
- + {
- + byte temp;
- + for (short i = 0; i < 768; i++)
- + {
- + _s = _P[(_s + _P[i & 0xff] + key[i % key.length]) & 0xff];
- +
- + temp = _P[i & 0xff];
- + _P[i & 0xff] = _P[_s & 0xff];
- + _P[_s & 0xff] = temp;
- + }
- + }
- +
- + public void setup(byte[] key, byte[] iv)
- + {
- + _n = 0;
- + _s = 0;
- +
- + for (short i = 0; i < 256; i++)
- + _P[i] = (byte) i;
- +
- + ksa(key);
- +
- + if (iv != null && iv.length > 0)
- + {
- + ksa(iv);
- + ksa(key);
- + }
- + }
- +
- + public void crypt(byte[] raw, int offset, int size)
- + {
- + byte z, temp;
- + for (int i = 0; i < size; i++)
- + {
- + _s = _P[(_s + _P[_n & 0xff]) & 0xff];
- + z = _P[(_P[_P[_s & 0xff] & 0xff] + 1) & 0xff];
- +
- + temp = _P[_n & 0xff];
- + _P[_n & 0xff] = _P[_s & 0xff];
- + _P[_s & 0xff] = temp;
- + _n = (byte) ((_n + 1) & 0xff);
- +
- + raw[offset + i] = (byte) (raw[offset + i] ^ z);
- + }
- + }
- +}
- \ No newline at end of file
- diff --git a/L2jOne_C6_Interlude/java/net/sf/l2j/Config.java b/L2jOne_C6_Interlude/java/net/sf/l2j/Config.java
- index 2f080f7..af15f83 100644
- --- a/L2jOne_C6_Interlude/java/net/sf/l2j/Config.java
- +++ b/L2jOne_C6_Interlude/java/net/sf/l2j/Config.java
- @@ -500,6 +500,11 @@
- public static boolean ACCEPT_ALTERNATE_ID;
- public static boolean USE_BLOWFISH_CIPHER;
- + /** Guard System */
- + public static boolean ALLOWED_GUARD_SYSTEM;
- + public static String CLIENT_KEY;
- + public static String SERVER_KEY;
- +
- /** Access to database */
- public static String DATABASE_URL;
- public static String DATABASE_LOGIN;
- @@ -1175,6 +1180,10 @@
- ACCEPT_ALTERNATE_ID = server.getProperty("AcceptAlternateID", true);
- USE_BLOWFISH_CIPHER = server.getProperty("UseBlowfishCipher", true);
- + ALLOWED_GUARD_SYSTEM = server.getProperty("AllowGuardSystem", false);
- + CLIENT_KEY = server.getProperty("ClientKey", "");
- + SERVER_KEY = server.getProperty("ServerKey", "");
- +
- DATABASE_URL = server.getProperty("URL", "jdbc:mariadb://localhost/acis");
- DATABASE_LOGIN = server.getProperty("Login", "root");
- DATABASE_PASSWORD = server.getProperty("Password", "");
- diff --git a/L2jOne_C6_Interlude/java/net/sf/l2j/gameserver/GameServer.java b/L2jOne_C6_Interlude/java/net/sf/l2j/gameserver/GameServer.java
- index a7f3bc5..31b577b 100644
- --- a/L2jOne_C6_Interlude/java/net/sf/l2j/gameserver/GameServer.java
- +++ b/L2jOne_C6_Interlude/java/net/sf/l2j/gameserver/GameServer.java
- @@ -99,6 +99,8 @@
- import net.sf.l2j.util.DeadLockDetector;
- import net.sf.l2j.util.IPv4Filter;
- +import guard.GuardSystem;
- +
- public class GameServer
- {
- private static final CLogger LOGGER = new CLogger(GameServer.class.getName());
- @@ -268,6 +270,9 @@
- LOGGER.info("Loaded {} target handlers.", TargetHandler.getInstance().size());
- LOGGER.info("Loaded {} user command handlers.", UserCommandHandler.getInstance().size());
- + StringUtil.printSection("Guard System");
- + GuardSystem.getInstance();
- +
- StringUtil.printSection("System");
- Runtime.getRuntime().addShutdownHook(Shutdown.getInstance());
- diff --git a/L2jOne_C6_Interlude/java/net/sf/l2j/gameserver/network/BlowFishKeygen.java b/L2jOne_C6_Interlude/java/net/sf/l2j/gameserver/network/BlowFishKeygen.java
- index 8507b86..4289560 100644
- --- a/L2jOne_C6_Interlude/java/net/sf/l2j/gameserver/network/BlowFishKeygen.java
- +++ b/L2jOne_C6_Interlude/java/net/sf/l2j/gameserver/network/BlowFishKeygen.java
- @@ -2,6 +2,8 @@
- import net.sf.l2j.commons.random.Rnd;
- +import net.sf.l2j.Config;
- +
- public class BlowFishKeygen
- {
- private static final int CRYPT_KEYS_SIZE = 20;
- @@ -44,6 +46,6 @@
- */
- public static byte[] getRandomKey()
- {
- - return Rnd.get(CRYPT_KEYS);
- + return Config.ALLOWED_GUARD_SYSTEM ? Rnd.nextBytes(16) : Rnd.get(CRYPT_KEYS);
- }
- }
- diff --git a/L2jOne_C6_Interlude/java/net/sf/l2j/gameserver/network/GameClient.java b/L2jOne_C6_Interlude/java/net/sf/l2j/gameserver/network/GameClient.java
- index 7089d2b..c738f97 100644
- --- a/L2jOne_C6_Interlude/java/net/sf/l2j/gameserver/network/GameClient.java
- +++ b/L2jOne_C6_Interlude/java/net/sf/l2j/gameserver/network/GameClient.java
- @@ -24,6 +24,7 @@
- import net.sf.l2j.gameserver.model.World;
- import net.sf.l2j.gameserver.model.actor.Player;
- import net.sf.l2j.gameserver.model.pledge.Clan;
- +import net.sf.l2j.gameserver.network.serverpackets.GameGuardQuery;
- import net.sf.l2j.gameserver.network.serverpackets.L2GameServerPacket;
- import net.sf.l2j.gameserver.network.serverpackets.ServerClose;
- @@ -70,6 +71,7 @@
- private final ReentrantLock _activeCharLock = new ReentrantLock();
- private final GameCrypt _crypt;
- + private String _hwid;
- private final long _connectionStartTime;
- public GameClientState _state;
- @@ -90,6 +92,7 @@
- super(con);
- _state = GameClientState.CONNECTED;
- + _hwid = null;
- _connectionStartTime = System.currentTimeMillis();
- _crypt = new GameCrypt();
- @@ -174,7 +177,17 @@
- {
- LOGGER.debug("{} disconnected abnormally.", toString());
- }
- -
- +
- + public String getHwid()
- + {
- + return _hwid;
- + }
- +
- + public void setHwid(String hwid)
- + {
- + _hwid = hwid;
- + }
- +
- public byte[] enableCrypt()
- {
- byte[] key = BlowFishKeygen.getRandomKey();
- @@ -225,6 +238,7 @@
- public void setAccountName(String pAccountName)
- {
- _accountName = pAccountName;
- + sendPacket(new GameGuardQuery());
- }
- public String getAccountName()
- diff --git a/L2jOne_C6_Interlude/java/net/sf/l2j/gameserver/network/GameCrypt.java b/L2jOne_C6_Interlude/java/net/sf/l2j/gameserver/network/GameCrypt.java
- index 562853e..92bd7f7 100644
- --- a/L2jOne_C6_Interlude/java/net/sf/l2j/gameserver/network/GameCrypt.java
- +++ b/L2jOne_C6_Interlude/java/net/sf/l2j/gameserver/network/GameCrypt.java
- @@ -1,22 +1,42 @@
- package net.sf.l2j.gameserver.network;
- +import java.util.Arrays;
- +
- import net.sf.l2j.Config;
- +import guard.crypt.LameCrypt;
- +
- public class GameCrypt
- {
- + private boolean _enabled;
- private final byte[] _inKey = new byte[16];
- private final byte[] _outKey = new byte[16];
- - private boolean _isEnabled;
- + private LameCrypt _lameCrypt;
- +
- + public GameCrypt()
- + {
- + if (Config.ALLOWED_GUARD_SYSTEM)
- + _lameCrypt = new LameCrypt();
- + }
- public void setKey(byte[] key)
- {
- System.arraycopy(key, 0, _inKey, 0, 16);
- System.arraycopy(key, 0, _outKey, 0, 16);
- +
- + if (Config.ALLOWED_GUARD_SYSTEM)
- + _lameCrypt.init(Arrays.copyOfRange(key, 0, 8));
- }
- public void decrypt(byte[] raw, final int offset, final int size)
- {
- - if (!Config.USE_BLOWFISH_CIPHER || !_isEnabled)
- + if (Config.ALLOWED_GUARD_SYSTEM)
- + {
- + _lameCrypt.decrypt(raw, offset, size);
- + return;
- + }
- +
- + if (!Config.USE_BLOWFISH_CIPHER || !_enabled)
- return;
- int temp = 0;
- @@ -42,9 +62,15 @@
- public void encrypt(byte[] raw, final int offset, final int size)
- {
- - if (!_isEnabled)
- + if (Config.ALLOWED_GUARD_SYSTEM)
- {
- - _isEnabled = Config.USE_BLOWFISH_CIPHER;
- + _lameCrypt.encrypt(raw, offset, size);
- + return;
- + }
- +
- + if (!_enabled)
- + {
- + _enabled = Config.USE_BLOWFISH_CIPHER;
- return;
- }
- diff --git a/L2jOne_C6_Interlude/java/net/sf/l2j/gameserver/network/GamePacketHandler.java b/L2jOne_C6_Interlude/java/net/sf/l2j/gameserver/network/GamePacketHandler.java
- index 143b4b1..fc5b0a8 100644
- --- a/L2jOne_C6_Interlude/java/net/sf/l2j/gameserver/network/GamePacketHandler.java
- +++ b/L2jOne_C6_Interlude/java/net/sf/l2j/gameserver/network/GamePacketHandler.java
- @@ -76,6 +76,9 @@
- case 0x68:
- msg = new RequestPledgeCrest();
- break;
- + case 0xca:
- + msg = new GameGuardReply();
- + break;
- default:
- printDebug(opcode, buf, state, client);
- break;
- @@ -649,9 +652,6 @@
- case 0xc8:
- msg = new PetitionVote();
- break;
- - case 0xCA:
- - msg = new GameGuardReply();
- - break;
- case 0xcc:
- msg = new RequestSendL2FriendSay();
- break;
- diff --git a/L2jOne_C6_Interlude/java/net/sf/l2j/gameserver/network/clientpackets/GameGuardReply.java b/L2jOne_C6_Interlude/java/net/sf/l2j/gameserver/network/clientpackets/GameGuardReply.java
- index 4622e37..3d18237 100644
- --- a/L2jOne_C6_Interlude/java/net/sf/l2j/gameserver/network/clientpackets/GameGuardReply.java
- +++ b/L2jOne_C6_Interlude/java/net/sf/l2j/gameserver/network/clientpackets/GameGuardReply.java
- @@ -1,17 +1,39 @@
- package net.sf.l2j.gameserver.network.clientpackets;
- +import net.sf.l2j.Config;
- import net.sf.l2j.gameserver.model.actor.Player;
- +import guard.GuardSystem;
- +
- public class GameGuardReply extends L2GameClientPacket
- {
- + private byte[] _hwid = new byte[16];
- +
- @Override
- protected void readImpl()
- {
- + readB(_hwid);
- }
- @Override
- protected void runImpl()
- {
- + if (Config.ALLOWED_GUARD_SYSTEM)
- + {
- + String hwid = null;
- +
- + // convert HWID from byte array to string.
- + StringBuilder sb = new StringBuilder(_hwid.length * 2);
- + for(final byte b: _hwid)
- + sb.append(String.format("%02X", b));
- +
- + hwid = sb.toString();
- + if (GuardSystem.getInstance().isBanned(hwid))
- + getClient().closeNow();
- + else
- + getClient().setHwid(hwid);
- + }
- +
- final Player player = getClient().getPlayer();
- if (player == null)
- return;
Advertisement
Add Comment
Please, Sign In to add comment