Fix client lacking encryption support
This commit is contained in:
parent
84cef345eb
commit
bdb087fabc
3 changed files with 45 additions and 6 deletions
|
@ -1,3 +1,3 @@
|
||||||
class Constants {
|
class Constants {
|
||||||
static const VERSION = "1.3.010625+0228";
|
static const VERSION = "1.3.010625+1127";
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,11 @@ enum EncryptionType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class PacketsConsts {
|
||||||
|
/// Version of the packets system. Bumped when there is a major change to protocol
|
||||||
|
static const VERSION = 2;
|
||||||
|
}
|
||||||
|
|
||||||
class PacketServer {
|
class PacketServer {
|
||||||
static ServerSocket? socket;
|
static ServerSocket? socket;
|
||||||
static bool shouldRestart = true;
|
static bool shouldRestart = true;
|
||||||
|
@ -46,9 +51,6 @@ class PacketServer {
|
||||||
static String PSK = "";
|
static String PSK = "";
|
||||||
static String TEA_SALT = "Harbinger 01/05/2025 @ 03:59:17 AM";
|
static String TEA_SALT = "Harbinger 01/05/2025 @ 03:59:17 AM";
|
||||||
|
|
||||||
/// Version of the packets system. Bumped when there is a major change to protocol
|
|
||||||
static const VERSION = 2;
|
|
||||||
|
|
||||||
/// Packet Data Format:
|
/// Packet Data Format:
|
||||||
///
|
///
|
||||||
/// 4 bytes (int) - Version
|
/// 4 bytes (int) - Version
|
||||||
|
@ -163,7 +165,7 @@ class PacketServer {
|
||||||
|
|
||||||
// NOTE: Added a length indicator because SocketServer is apparently... really really dumb in its impl, and has no way to know when all data has been received, so no special event. We just have to check for it based on this initial value.
|
// NOTE: Added a length indicator because SocketServer is apparently... really really dumb in its impl, and has no way to know when all data has been received, so no special event. We just have to check for it based on this initial value.
|
||||||
layer.clear();
|
layer.clear();
|
||||||
layer.writeInt(VERSION);
|
layer.writeInt(PacketsConsts.VERSION);
|
||||||
layer.writeLong(nbtData.lengthInBytes + layer.currentPosition + 8);
|
layer.writeLong(nbtData.lengthInBytes + layer.currentPosition + 8);
|
||||||
layer.writeBytes(nbtData);
|
layer.writeBytes(nbtData);
|
||||||
|
|
||||||
|
@ -199,6 +201,11 @@ class PacketClient {
|
||||||
String lastIP = "";
|
String lastIP = "";
|
||||||
int port = 25306;
|
int port = 25306;
|
||||||
int packetSequence = 0;
|
int packetSequence = 0;
|
||||||
|
EncryptionType encryptionType = EncryptionType.NONE;
|
||||||
|
Uint8List aesKey = Uint8List(0);
|
||||||
|
|
||||||
|
/// Used for xtea encryption
|
||||||
|
String PSK = "";
|
||||||
|
|
||||||
PacketClient();
|
PacketClient();
|
||||||
|
|
||||||
|
@ -251,7 +258,22 @@ class PacketClient {
|
||||||
|
|
||||||
while (!success) {
|
while (!success) {
|
||||||
layer.clear();
|
layer.clear();
|
||||||
|
layer.writeInt(PacketsConsts.VERSION);
|
||||||
layer.writeLong(packetSequence);
|
layer.writeLong(packetSequence);
|
||||||
|
layer.writeByte(encryptionType.value);
|
||||||
|
|
||||||
|
if (encryptionType == EncryptionType.AES) {
|
||||||
|
AESCipher aes = AESCipher.useKey(aesKey);
|
||||||
|
AESData encData = await aes.encrypt(nbtData);
|
||||||
|
layer.writeInt(encData.iv.length);
|
||||||
|
layer.writeBytes(encData.iv);
|
||||||
|
|
||||||
|
nbtData = Uint8List.fromList(encData.data);
|
||||||
|
} else if (encryptionType == EncryptionType.XTEA) {
|
||||||
|
XTEA xtea = XTEA(PSK);
|
||||||
|
nbtData = Uint8List.fromList(await xtea.encipher(nbtData.toList()));
|
||||||
|
}
|
||||||
|
|
||||||
layer.writeLong(nbtData.lengthInBytes);
|
layer.writeLong(nbtData.lengthInBytes);
|
||||||
layer.writeBytes(nbtData);
|
layer.writeBytes(nbtData);
|
||||||
var tmpBytes = layer.bytes;
|
var tmpBytes = layer.bytes;
|
||||||
|
@ -281,6 +303,14 @@ class PacketClient {
|
||||||
reply.readLong(); // This is unused outside of the sanity check above.
|
reply.readLong(); // This is unused outside of the sanity check above.
|
||||||
int sequence = reply.readLong();
|
int sequence = reply.readLong();
|
||||||
int successReceipt = reply.readByte();
|
int successReceipt = reply.readByte();
|
||||||
|
EncryptionType encType = EncryptionType.valueOf(layer.readByte());
|
||||||
|
List<int> encIV = [];
|
||||||
|
|
||||||
|
if (encType == EncryptionType.AES) {
|
||||||
|
int ivLen = layer.readInt();
|
||||||
|
encIV = layer.readBytes(ivLen);
|
||||||
|
}
|
||||||
|
|
||||||
int numBytes = reply.readLong();
|
int numBytes = reply.readLong();
|
||||||
List<int> pktBytes = reply.readBytes(numBytes);
|
List<int> pktBytes = reply.readBytes(numBytes);
|
||||||
|
|
||||||
|
@ -288,6 +318,15 @@ class PacketClient {
|
||||||
success = true;
|
success = true;
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
|
if (encType == EncryptionType.AES) {
|
||||||
|
AESCipher aes = AESCipher.useKey(aesKey);
|
||||||
|
AESData encData = AESData(iv: encIV, data: pktBytes);
|
||||||
|
pktBytes = (await aes.decrypt(encData)).toList();
|
||||||
|
} else if (encType == EncryptionType.XTEA) {
|
||||||
|
XTEA xtea = XTEA(PSK);
|
||||||
|
pktBytes = await xtea.decipher(pktBytes);
|
||||||
|
}
|
||||||
|
|
||||||
NBTTag = await NbtIo.readFromStream(Uint8List.fromList(pktBytes));
|
NBTTag = await NbtIo.readFromStream(Uint8List.fromList(pktBytes));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
name: libac_dart
|
name: libac_dart
|
||||||
description: "Aria's Creations code library"
|
description: "Aria's Creations code library"
|
||||||
version: 1.3.010625+0228
|
version: 1.3.010625+1127
|
||||||
homepage: "https://zontreck.com"
|
homepage: "https://zontreck.com"
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue