From f8b031719e06a8b8c48e2a2b69911d9445fd741d Mon Sep 17 00:00:00 2001 From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com> Date: Sat, 20 May 2023 01:58:39 +0200 Subject: [PATCH] Implemented partial encryption --- README.md | 2 +- .../injection/access/IClientConnection.java | 2 +- .../mixin/base/MixinClientConnection.java | 15 +++++++++------ .../ViaFabricPlusEncryptionProvider.java | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index c38d701c..be2fa22f 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ ViaFabricPlus is intended to replace [multiconnect](https://github.com/Earthcomp - Alpha (a1.0.15 - a1.2.6) - Classic (c0.0.15 - c0.30 including [CPE](https://wiki.vg/Classic_Protocol_Extension)) - Snapshots (3D Shareware, 20w14infinite, Combat Test 8C) -- Bedrock (1.19.70) +- Bedrock (1.19.80) # For users ### Detailed instructions for use are available here [here](.github/USAGE.md) diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/access/IClientConnection.java b/src/main/java/de/florianmichael/viafabricplus/injection/access/IClientConnection.java index e28afda4..608468bb 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/access/IClientConnection.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/access/IClientConnection.java @@ -26,7 +26,7 @@ import java.security.NoSuchAlgorithmException; public interface IClientConnection { - void viafabricplus_setupPreNettyEncryption(); + void viafabricplus_setupPreNettyDecryption(); InetSocketAddress viafabricplus_capturedAddress(); void viafabricplus_captureAddress(final InetSocketAddress socketAddress); diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/MixinClientConnection.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/MixinClientConnection.java index f1a90551..dabbaee9 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/MixinClientConnection.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/MixinClientConnection.java @@ -62,9 +62,6 @@ public abstract class MixinClientConnection extends SimpleChannelInboundHandler< @Unique private Cipher viafabricplus_decryptionCipher; - @Unique - private Cipher viafabricplus_encryptionCipher; - @Unique private boolean viafabricplus_compressionEnabled = false; @@ -81,7 +78,7 @@ public abstract class MixinClientConnection extends SimpleChannelInboundHandler< if (ProtocolHack.getTargetVersion(channel).isOlderThanOrEqualTo(LegacyProtocolVersion.r1_6_4)) { ci.cancel(); this.viafabricplus_decryptionCipher = decryptionCipher; - this.viafabricplus_encryptionCipher = encryptionCipher; + this.viafabricplus_setupPreNettyEncryption(encryptionCipher); } } @@ -111,10 +108,16 @@ public abstract class MixinClientConnection extends SimpleChannelInboundHandler< DisconnectConnectionCallback.EVENT.invoker().onDisconnect(); } + @Unique + public void viafabricplus_setupPreNettyEncryption(final Cipher encryptionCipher) { + this.encrypted = true; + this.channel.pipeline().addBefore(ViaFabricPlusVLBPipeline.VIA_LEGACY_PRE_NETTY_LENGTH_REMOVER_HANDLER_NAME, "encrypt", new PacketEncryptor(encryptionCipher)); + } + @Override - public void viafabricplus_setupPreNettyEncryption() { + public void viafabricplus_setupPreNettyDecryption() { + this.encrypted = true; this.channel.pipeline().addBefore(ViaFabricPlusVLBPipeline.VIA_LEGACY_PRE_NETTY_LENGTH_PREPENDER_HANDLER_NAME, "decrypt", new PacketDecryptor(this.viafabricplus_decryptionCipher)); - this.channel.pipeline().addBefore(ViaFabricPlusVLBPipeline.VIA_LEGACY_PRE_NETTY_LENGTH_REMOVER_HANDLER_NAME, "encrypt", new PacketEncryptor(this.viafabricplus_encryptionCipher)); } @Override diff --git a/src/main/java/de/florianmichael/viafabricplus/protocolhack/provider/vialegacy/ViaFabricPlusEncryptionProvider.java b/src/main/java/de/florianmichael/viafabricplus/protocolhack/provider/vialegacy/ViaFabricPlusEncryptionProvider.java index 9a56b25a..1e4e2765 100644 --- a/src/main/java/de/florianmichael/viafabricplus/protocolhack/provider/vialegacy/ViaFabricPlusEncryptionProvider.java +++ b/src/main/java/de/florianmichael/viafabricplus/protocolhack/provider/vialegacy/ViaFabricPlusEncryptionProvider.java @@ -29,7 +29,7 @@ public class ViaFabricPlusEncryptionProvider extends EncryptionProvider { public void enableDecryption(UserConnection user) { final ClientConnection clientConnection = user.getChannel().attr(ProtocolHack.LOCAL_MINECRAFT_CONNECTION).get(); if (clientConnection != null) { - ((IClientConnection) clientConnection).viafabricplus_setupPreNettyEncryption(); + ((IClientConnection) clientConnection).viafabricplus_setupPreNettyDecryption(); } } }