diff --git a/src/main/java/net/raphimc/viaproxy/injection/mixins/MixinProtocol1_19_1To1_19.java b/src/main/java/net/raphimc/viaproxy/injection/mixins/MixinProtocol1_19_1To1_19.java deleted file mode 100644 index 9bc85a3..0000000 --- a/src/main/java/net/raphimc/viaproxy/injection/mixins/MixinProtocol1_19_1To1_19.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy - * Copyright (C) 2023 RK_01/RaphiMC and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.raphimc.viaproxy.injection.mixins; - -import com.viaversion.viaversion.api.protocol.AbstractProtocol; -import com.viaversion.viaversion.api.protocol.packet.State; -import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; -import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets; -import com.viaversion.viaversion.protocols.base.ServerboundLoginPackets; -import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.ClientboundPackets1_19_1; -import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.Protocol1_19_1To1_19; -import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.ServerboundPackets1_19_1; -import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.ClientboundPackets1_19; -import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.ServerboundPackets1_19; -import net.raphimc.viaproxy.protocolhack.viaproxy.signature.model.DecoratableMessage; -import net.raphimc.viaproxy.protocolhack.viaproxy.signature.model.MessageMetadata; -import net.raphimc.viaproxy.protocolhack.viaproxy.signature.storage.ChatSession1_19_0; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.util.UUID; - -@Mixin(value = Protocol1_19_1To1_19.class, remap = false) -public abstract class MixinProtocol1_19_1To1_19 extends AbstractProtocol { - - @Inject(method = "registerPackets", at = @At("RETURN")) - private void allowSignatures(CallbackInfo ci) { - this.registerServerbound(State.LOGIN, ServerboundLoginPackets.HELLO.getId(), ServerboundLoginPackets.HELLO.getId(), new PacketHandlers() { - @Override - public void register() { - map(Type.STRING); // Name - read(Type.OPTIONAL_PROFILE_KEY); // Profile Key - handler(wrapper -> { - final ChatSession1_19_0 chatSession = wrapper.user().get(ChatSession1_19_0.class); - wrapper.write(Type.OPTIONAL_PROFILE_KEY, chatSession == null ? null : chatSession.getProfileKey()); // Profile Key - }); - read(Type.OPTIONAL_UUID); // Profile uuid - } - }, true); - this.registerClientbound(State.LOGIN, ClientboundLoginPackets.HELLO.getId(), ClientboundLoginPackets.HELLO.getId(), wrapper -> { - }, true); - this.registerServerbound(State.LOGIN, ServerboundLoginPackets.ENCRYPTION_KEY.getId(), ServerboundLoginPackets.ENCRYPTION_KEY.getId(), wrapper -> { - }, true); - - this.registerServerbound(ServerboundPackets1_19_1.CHAT_MESSAGE, ServerboundPackets1_19.CHAT_MESSAGE, new PacketHandlers() { - @Override - public void register() { - map(Type.STRING); // Message - map(Type.LONG); // Timestamp - map(Type.LONG); // Salt - read(Type.BYTE_ARRAY_PRIMITIVE); // Signature - read(Type.BOOLEAN); // Signed preview - handler(wrapper -> { - final ChatSession1_19_0 chatSession = wrapper.user().get(ChatSession1_19_0.class); - - if (chatSession != null) { - final UUID sender = wrapper.user().getProtocolInfo().getUuid(); - final String message = wrapper.get(Type.STRING, 0); - final long timestamp = wrapper.get(Type.LONG, 0); - final long salt = wrapper.get(Type.LONG, 1); - - final MessageMetadata metadata = new MessageMetadata(sender, timestamp, salt); - final DecoratableMessage decoratableMessage = new DecoratableMessage(message); - - wrapper.write(Type.BYTE_ARRAY_PRIMITIVE, chatSession.signChatMessage(metadata, decoratableMessage)); // Signature - wrapper.write(Type.BOOLEAN, decoratableMessage.isDecorated()); // Signed preview - } else { - wrapper.write(Type.BYTE_ARRAY_PRIMITIVE, new byte[0]); // Signature - wrapper.write(Type.BOOLEAN, false); // Signed preview - } - }); - read(Type.PLAYER_MESSAGE_SIGNATURE_ARRAY); // Last seen messages - read(Type.OPTIONAL_PLAYER_MESSAGE_SIGNATURE); // Last received message - } - }, true); - } - -} diff --git a/src/main/java/net/raphimc/viaproxy/injection/mixins/MixinProtocol1_19_3To1_19_1.java b/src/main/java/net/raphimc/viaproxy/injection/mixins/MixinProtocol1_19_3To1_19_1.java deleted file mode 100644 index 2a4fcb5..0000000 --- a/src/main/java/net/raphimc/viaproxy/injection/mixins/MixinProtocol1_19_3To1_19_1.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy - * Copyright (C) 2023 RK_01/RaphiMC and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.raphimc.viaproxy.injection.mixins; - -import com.google.common.primitives.Longs; -import com.viaversion.viaversion.api.protocol.AbstractProtocol; -import com.viaversion.viaversion.api.protocol.packet.State; -import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; -import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.api.type.types.BitSetType; -import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets; -import com.viaversion.viaversion.protocols.base.ServerboundLoginPackets; -import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.ClientboundPackets1_19_1; -import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.ServerboundPackets1_19_1; -import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.storage.NonceStorage; -import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ClientboundPackets1_19_3; -import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.Protocol1_19_3To1_19_1; -import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ServerboundPackets1_19_3; -import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.storage.ReceivedMessagesStorage; -import net.raphimc.viaproxy.protocolhack.viaproxy.signature.model.DecoratableMessage; -import net.raphimc.viaproxy.protocolhack.viaproxy.signature.model.MessageMetadata; -import net.raphimc.viaproxy.protocolhack.viaproxy.signature.storage.ChatSession1_19_1; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.util.UUID; -import java.util.concurrent.ThreadLocalRandom; - -@Mixin(value = Protocol1_19_3To1_19_1.class, remap = false) -public abstract class MixinProtocol1_19_3To1_19_1 extends AbstractProtocol { - - @Final - @Shadow - private static BitSetType ACKNOWLEDGED_BIT_SET_TYPE; - - @Final - @Shadow - private static byte[] EMPTY_BYTES; - - @Inject(method = "registerPackets", at = @At("RETURN")) - private void allowSignatures(CallbackInfo ci) { - this.registerServerbound(State.LOGIN, ServerboundLoginPackets.HELLO.getId(), ServerboundLoginPackets.HELLO.getId(), new PacketHandlers() { - @Override - public void register() { - map(Type.STRING); // Name - handler(wrapper -> { - final ChatSession1_19_1 chatSession = wrapper.user().get(ChatSession1_19_1.class); - wrapper.write(Type.OPTIONAL_PROFILE_KEY, chatSession == null ? null : chatSession.getProfileKey()); // Profile Key - }); - map(Type.OPTIONAL_UUID); // Profile uuid - } - }, true); - this.registerClientbound(State.LOGIN, ClientboundLoginPackets.HELLO.getId(), ClientboundLoginPackets.HELLO.getId(), new PacketHandlers() { - @Override - public void register() { - map(Type.STRING); // Server id - map(Type.BYTE_ARRAY_PRIMITIVE); // Public key - handler(wrapper -> { - wrapper.user().put(new NonceStorage(wrapper.passthrough(Type.BYTE_ARRAY_PRIMITIVE))); // Nonce - }); - } - }); - this.registerServerbound(State.LOGIN, ServerboundLoginPackets.ENCRYPTION_KEY.getId(), ServerboundLoginPackets.ENCRYPTION_KEY.getId(), new PacketHandlers() { - @Override - public void register() { - map(Type.BYTE_ARRAY_PRIMITIVE); // Public key - handler(wrapper -> { - final ChatSession1_19_1 chatSession = wrapper.user().get(ChatSession1_19_1.class); - - final byte[] verifyToken = wrapper.read(Type.BYTE_ARRAY_PRIMITIVE); // Verify token - wrapper.write(Type.BOOLEAN, chatSession == null); // is nonce - if (chatSession != null) { - final long salt = ThreadLocalRandom.current().nextLong(); - final byte[] signature = chatSession.sign(signer -> { - signer.accept(wrapper.user().get(NonceStorage.class).nonce()); - signer.accept(Longs.toByteArray(salt)); - }); - wrapper.write(Type.LONG, salt); // Salt - wrapper.write(Type.BYTE_ARRAY_PRIMITIVE, signature); // Signature - } else { - wrapper.write(Type.BYTE_ARRAY_PRIMITIVE, verifyToken); // Nonce - } - }); - } - }, true); - - this.registerServerbound(ServerboundPackets1_19_3.CHAT_MESSAGE, ServerboundPackets1_19_1.CHAT_MESSAGE, new PacketHandlers() { - @Override - public void register() { - map(Type.STRING); // Message - map(Type.LONG); // Timestamp - map(Type.LONG); // Salt - read(Type.OPTIONAL_SIGNATURE_BYTES); // Signature - handler(wrapper -> { - final ChatSession1_19_1 chatSession = wrapper.user().get(ChatSession1_19_1.class); - final ReceivedMessagesStorage messagesStorage = wrapper.user().get(ReceivedMessagesStorage.class); - - if (chatSession != null) { - final UUID sender = wrapper.user().getProtocolInfo().getUuid(); - final String message = wrapper.get(Type.STRING, 0); - final long timestamp = wrapper.get(Type.LONG, 0); - final long salt = wrapper.get(Type.LONG, 1); - - final MessageMetadata metadata = new MessageMetadata(sender, timestamp, salt); - final DecoratableMessage decoratableMessage = new DecoratableMessage(message); - - wrapper.write(Type.BYTE_ARRAY_PRIMITIVE, chatSession.signChatMessage(metadata, decoratableMessage, messagesStorage.lastSignatures())); // Signature - wrapper.write(Type.BOOLEAN, decoratableMessage.isDecorated()); // Signed preview - } else { - wrapper.write(Type.BYTE_ARRAY_PRIMITIVE, EMPTY_BYTES); // Signature - wrapper.write(Type.BOOLEAN, false); // Signed preview - } - - messagesStorage.resetUnacknowledgedCount(); - wrapper.write(Type.PLAYER_MESSAGE_SIGNATURE_ARRAY, messagesStorage.lastSignatures()); - wrapper.write(Type.OPTIONAL_PLAYER_MESSAGE_SIGNATURE, null); // No last unacknowledged - }); - read(Type.VAR_INT); // Offset - read(ACKNOWLEDGED_BIT_SET_TYPE); // Acknowledged - } - }, true); - } - -} diff --git a/src/main/java/net/raphimc/viaproxy/injection/transformer/Protocol1_18_2To1_19Transformer.java b/src/main/java/net/raphimc/viaproxy/injection/transformer/Protocol1_18_2To1_19Transformer.java deleted file mode 100644 index 7586db8..0000000 --- a/src/main/java/net/raphimc/viaproxy/injection/transformer/Protocol1_18_2To1_19Transformer.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy - * Copyright (C) 2023 RK_01/RaphiMC and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.raphimc.viaproxy.injection.transformer; - -import com.google.common.primitives.Longs; -import com.viaversion.viabackwards.api.BackwardsProtocol; -import com.viaversion.viabackwards.protocol.protocol1_18_2to1_19.Protocol1_18_2To1_19; -import com.viaversion.viaversion.api.protocol.packet.State; -import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; -import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets; -import com.viaversion.viaversion.protocols.base.ServerboundLoginPackets; -import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ServerboundPackets1_17; -import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.ClientboundPackets1_18; -import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.storage.NonceStorage; -import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.ClientboundPackets1_19; -import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.ServerboundPackets1_19; -import net.lenni0451.classtransform.InjectionCallback; -import net.lenni0451.classtransform.annotations.CShadow; -import net.lenni0451.classtransform.annotations.CTarget; -import net.lenni0451.classtransform.annotations.CTransformer; -import net.lenni0451.classtransform.annotations.injection.CInject; -import net.raphimc.viaproxy.protocolhack.viaproxy.signature.model.DecoratableMessage; -import net.raphimc.viaproxy.protocolhack.viaproxy.signature.model.MessageMetadata; -import net.raphimc.viaproxy.protocolhack.viaproxy.signature.storage.ChatSession1_19_0; - -import java.time.Instant; -import java.util.UUID; -import java.util.concurrent.ThreadLocalRandom; - -@CTransformer(Protocol1_18_2To1_19.class) -public abstract class Protocol1_18_2To1_19Transformer extends BackwardsProtocol { - - @CShadow - private static byte[] EMPTY_BYTES; - - @CInject(method = "registerPackets", target = @CTarget("RETURN")) - private void allowSignatures(InjectionCallback ic) { - this.registerServerbound(State.LOGIN, ServerboundLoginPackets.HELLO.getId(), ServerboundLoginPackets.HELLO.getId(), new PacketHandlers() { - @Override - public void register() { - map(Type.STRING); // Name - handler(wrapper -> { - final ChatSession1_19_0 chatSession = wrapper.user().get(ChatSession1_19_0.class); - wrapper.write(Type.OPTIONAL_PROFILE_KEY, chatSession == null ? null : chatSession.getProfileKey()); // Profile Key - }); - } - }, true); - this.registerClientbound(State.LOGIN, ClientboundLoginPackets.HELLO.getId(), ClientboundLoginPackets.HELLO.getId(), new PacketHandlers() { - @Override - public void register() { - map(Type.STRING); // Server id - map(Type.BYTE_ARRAY_PRIMITIVE); // Public key - handler(wrapper -> { - wrapper.user().put(new NonceStorage(wrapper.passthrough(Type.BYTE_ARRAY_PRIMITIVE))); // Nonce - }); - } - }, true); - this.registerServerbound(State.LOGIN, ServerboundLoginPackets.ENCRYPTION_KEY.getId(), ServerboundLoginPackets.ENCRYPTION_KEY.getId(), new PacketHandlers() { - @Override - public void register() { - map(Type.BYTE_ARRAY_PRIMITIVE); // Public key - handler(wrapper -> { - final ChatSession1_19_0 chatSession = wrapper.user().get(ChatSession1_19_0.class); - - final byte[] verifyToken = wrapper.read(Type.BYTE_ARRAY_PRIMITIVE); // Verify token - wrapper.write(Type.BOOLEAN, chatSession == null); // is nonce - if (chatSession != null) { - final long salt = ThreadLocalRandom.current().nextLong(); - final byte[] signature = chatSession.sign(signer -> { - signer.accept(wrapper.user().get(NonceStorage.class).nonce()); - signer.accept(Longs.toByteArray(salt)); - }); - wrapper.write(Type.LONG, salt); // Salt - wrapper.write(Type.BYTE_ARRAY_PRIMITIVE, signature); // Signature - } else { - wrapper.write(Type.BYTE_ARRAY_PRIMITIVE, verifyToken); // Nonce - } - }); - } - }, true); - - this.registerServerbound(ServerboundPackets1_17.CHAT_MESSAGE, ServerboundPackets1_19.CHAT_MESSAGE, new PacketHandlers() { - @Override - public void register() { - map(Type.STRING); // Message - handler(wrapper -> wrapper.write(Type.LONG, Instant.now().toEpochMilli())); // Timestamp - create(Type.LONG, 0L); // Salt - handler(wrapper -> { - final ChatSession1_19_0 chatSession = wrapper.user().get(ChatSession1_19_0.class); - - final String message = wrapper.get(Type.STRING, 0); - if (!message.isEmpty() && message.charAt(0) == '/') { - wrapper.setPacketType(ServerboundPackets1_19.CHAT_COMMAND); - wrapper.set(Type.STRING, 0, message.substring(1)); - wrapper.write(Type.VAR_INT, 0); // No signatures - } else { - if (chatSession != null) { - final UUID sender = wrapper.user().getProtocolInfo().getUuid(); - final Instant timestamp = Instant.now(); - final long salt = ThreadLocalRandom.current().nextLong(); - - final MessageMetadata metadata = new MessageMetadata(sender, timestamp, salt); - final DecoratableMessage decoratableMessage = new DecoratableMessage(message); - wrapper.set(Type.LONG, 0, timestamp.toEpochMilli()); // Timestamp - wrapper.set(Type.LONG, 1, salt); // Salt - wrapper.write(Type.BYTE_ARRAY_PRIMITIVE, chatSession.signChatMessage(metadata, decoratableMessage)); // Signature - } else { - wrapper.write(Type.BYTE_ARRAY_PRIMITIVE, EMPTY_BYTES); // Signature - } - } - - wrapper.write(Type.BOOLEAN, false); // No signed preview - }); - } - }, true); - } - -} diff --git a/src/main/java/net/raphimc/viaproxy/injection/transformer/Protocol1_19To1_19_1Transformer.java b/src/main/java/net/raphimc/viaproxy/injection/transformer/Protocol1_19To1_19_1Transformer.java deleted file mode 100644 index c7fdde8..0000000 --- a/src/main/java/net/raphimc/viaproxy/injection/transformer/Protocol1_19To1_19_1Transformer.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy - * Copyright (C) 2023 RK_01/RaphiMC and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.raphimc.viaproxy.injection.transformer; - -import com.viaversion.viabackwards.api.BackwardsProtocol; -import com.viaversion.viabackwards.protocol.protocol1_19to1_19_1.Protocol1_19To1_19_1; -import com.viaversion.viabackwards.protocol.protocol1_19to1_19_1.storage.ReceivedMessagesStorage; -import com.viaversion.viaversion.api.protocol.packet.State; -import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; -import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets; -import com.viaversion.viaversion.protocols.base.ServerboundLoginPackets; -import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.ClientboundPackets1_19_1; -import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.ServerboundPackets1_19_1; -import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.ClientboundPackets1_19; -import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.ServerboundPackets1_19; -import net.lenni0451.classtransform.InjectionCallback; -import net.lenni0451.classtransform.annotations.CShadow; -import net.lenni0451.classtransform.annotations.CTarget; -import net.lenni0451.classtransform.annotations.CTransformer; -import net.lenni0451.classtransform.annotations.injection.CInject; -import net.raphimc.viaproxy.protocolhack.viaproxy.signature.model.DecoratableMessage; -import net.raphimc.viaproxy.protocolhack.viaproxy.signature.model.MessageMetadata; -import net.raphimc.viaproxy.protocolhack.viaproxy.signature.storage.ChatSession1_19_1; - -import java.util.UUID; - -@CTransformer(Protocol1_19To1_19_1.class) -public abstract class Protocol1_19To1_19_1Transformer extends BackwardsProtocol { - - @CShadow - private static byte[] EMPTY_BYTES; - - @CInject(method = "registerPackets", target = @CTarget("RETURN")) - private void allowSignatures(InjectionCallback ic) { - this.registerServerbound(State.LOGIN, ServerboundLoginPackets.HELLO.getId(), ServerboundLoginPackets.HELLO.getId(), new PacketHandlers() { - @Override - public void register() { - map(Type.STRING); // Name - read(Type.OPTIONAL_PROFILE_KEY); // Profile Key - handler(wrapper -> { - final ChatSession1_19_1 chatSession = wrapper.user().get(ChatSession1_19_1.class); - wrapper.write(Type.OPTIONAL_PROFILE_KEY, chatSession == null ? null : chatSession.getProfileKey()); // Profile Key - wrapper.write(Type.OPTIONAL_UUID, chatSession == null ? null : chatSession.getUuid()); // Profile uuid - }); - } - }, true); - this.registerClientbound(State.LOGIN, ClientboundLoginPackets.HELLO.getId(), ClientboundLoginPackets.HELLO.getId(), wrapper -> { - }, true); - this.registerServerbound(State.LOGIN, ServerboundLoginPackets.ENCRYPTION_KEY.getId(), ServerboundLoginPackets.ENCRYPTION_KEY.getId(), wrapper -> { - }, true); - - this.registerServerbound(ServerboundPackets1_19.CHAT_MESSAGE, ServerboundPackets1_19_1.CHAT_MESSAGE, new PacketHandlers() { - @Override - public void register() { - map(Type.STRING); // Message - map(Type.LONG); // Timestamp - map(Type.LONG); // Salt - read(Type.BYTE_ARRAY_PRIMITIVE); // Signature - read(Type.BOOLEAN); // Signed preview - handler(wrapper -> { - final ChatSession1_19_1 chatSession = wrapper.user().get(ChatSession1_19_1.class); - final ReceivedMessagesStorage messagesStorage = wrapper.user().get(ReceivedMessagesStorage.class); - - if (chatSession != null) { - final UUID sender = wrapper.user().getProtocolInfo().getUuid(); - final String message = wrapper.get(Type.STRING, 0); - final long timestamp = wrapper.get(Type.LONG, 0); - final long salt = wrapper.get(Type.LONG, 1); - - final MessageMetadata metadata = new MessageMetadata(sender, timestamp, salt); - final DecoratableMessage decoratableMessage = new DecoratableMessage(message); - - wrapper.write(Type.BYTE_ARRAY_PRIMITIVE, chatSession.signChatMessage(metadata, decoratableMessage, messagesStorage.lastSignatures())); // Signature - wrapper.write(Type.BOOLEAN, decoratableMessage.isDecorated()); // Signed preview - } else { - wrapper.write(Type.BYTE_ARRAY_PRIMITIVE, EMPTY_BYTES); // Signature - wrapper.write(Type.BOOLEAN, false); // Signed preview - } - - messagesStorage.resetUnacknowledgedCount(); - wrapper.write(Type.PLAYER_MESSAGE_SIGNATURE_ARRAY, messagesStorage.lastSignatures()); - wrapper.write(Type.OPTIONAL_PLAYER_MESSAGE_SIGNATURE, null); // No last unacknowledged - }); - } - }, true); - } - -} diff --git a/src/main/java/net/raphimc/viaproxy/injection/transformer/Protocol1_19_1To1_19_3$1Transformer.java b/src/main/java/net/raphimc/viaproxy/injection/transformer/Protocol1_19_1To1_19_3$1Transformer.java deleted file mode 100644 index a8f80c2..0000000 --- a/src/main/java/net/raphimc/viaproxy/injection/transformer/Protocol1_19_1To1_19_3$1Transformer.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy - * Copyright (C) 2023 RK_01/RaphiMC and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.raphimc.viaproxy.injection.transformer; - -import com.viaversion.viabackwards.protocol.protocol1_19_1to1_19_3.Protocol1_19_1To1_19_3; -import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; -import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; -import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ServerboundPackets1_19_3; -import net.lenni0451.classtransform.InjectionCallback; -import net.lenni0451.classtransform.annotations.CTarget; -import net.lenni0451.classtransform.annotations.CTransformer; -import net.lenni0451.classtransform.annotations.injection.CInject; -import net.raphimc.viaproxy.protocolhack.viaproxy.signature.storage.ChatSession1_19_3; - -@CTransformer(name = "com.viaversion.viabackwards.protocol.protocol1_19_1to1_19_3.Protocol1_19_1To1_19_3$1") -public abstract class Protocol1_19_1To1_19_3$1Transformer extends PacketHandlers { - - @CInject(method = "register", target = @CTarget("RETURN")) - private void allowSignatures(InjectionCallback ic) { - handler(wrapper -> { - final ChatSession1_19_3 chatSession = wrapper.user().get(ChatSession1_19_3.class); - - if (chatSession != null) { - final PacketWrapper chatSessionUpdate = wrapper.create(ServerboundPackets1_19_3.CHAT_SESSION_UPDATE); - chatSessionUpdate.write(Type.UUID, chatSession.getSessionId()); - chatSessionUpdate.write(Type.PROFILE_KEY, chatSession.getProfileKey()); - chatSessionUpdate.sendToServer(Protocol1_19_1To1_19_3.class); - } - }); - } - -} diff --git a/src/main/java/net/raphimc/viaproxy/injection/transformer/Protocol1_19_1To1_19_3Transformer.java b/src/main/java/net/raphimc/viaproxy/injection/transformer/Protocol1_19_1To1_19_3Transformer.java deleted file mode 100644 index cf5a954..0000000 --- a/src/main/java/net/raphimc/viaproxy/injection/transformer/Protocol1_19_1To1_19_3Transformer.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy - * Copyright (C) 2023 RK_01/RaphiMC and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.raphimc.viaproxy.injection.transformer; - -import com.viaversion.viabackwards.api.BackwardsProtocol; -import com.viaversion.viabackwards.protocol.protocol1_19_1to1_19_3.Protocol1_19_1To1_19_3; -import com.viaversion.viaversion.api.minecraft.PlayerMessageSignature; -import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; -import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.api.type.types.BitSetType; -import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.ClientboundPackets1_19_1; -import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.ServerboundPackets1_19_1; -import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ClientboundPackets1_19_3; -import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ServerboundPackets1_19_3; -import net.lenni0451.classtransform.InjectionCallback; -import net.lenni0451.classtransform.annotations.CTarget; -import net.lenni0451.classtransform.annotations.CTransformer; -import net.lenni0451.classtransform.annotations.injection.CInject; -import net.raphimc.viaproxy.protocolhack.viaproxy.signature.model.MessageMetadata; -import net.raphimc.viaproxy.protocolhack.viaproxy.signature.storage.ChatSession1_19_3; - -import java.util.BitSet; - -@CTransformer(Protocol1_19_1To1_19_3.class) -public abstract class Protocol1_19_1To1_19_3Transformer extends BackwardsProtocol { - - @CInject(method = "registerPackets", target = @CTarget("RETURN")) - private void allowSignatures(InjectionCallback ic) { - this.registerServerbound(ServerboundPackets1_19_1.CHAT_MESSAGE, ServerboundPackets1_19_3.CHAT_MESSAGE, new PacketHandlers() { - @Override - public void register() { - map(Type.STRING); // Message - map(Type.LONG); // Timestamp - map(Type.LONG); // Salt - read(Type.BYTE_ARRAY_PRIMITIVE); // Signature - read(Type.BOOLEAN); // Signed preview - read(Type.PLAYER_MESSAGE_SIGNATURE_ARRAY); // Last seen messages - read(Type.OPTIONAL_PLAYER_MESSAGE_SIGNATURE); // Last received message - handler(wrapper -> { - final ChatSession1_19_3 chatSession = wrapper.user().get(ChatSession1_19_3.class); - - if (chatSession != null) { - final String message = wrapper.get(Type.STRING, 0); - final long timestamp = wrapper.get(Type.LONG, 0); - final long salt = wrapper.get(Type.LONG, 1); - - final MessageMetadata metadata = new MessageMetadata(null, timestamp, salt); - wrapper.write(Protocol1_19_1To1_19_3.OPTIONAL_SIGNATURE_BYTES_TYPE, chatSession.signChatMessage(metadata, message, new PlayerMessageSignature[0])); // Signature - } else { - wrapper.write(Protocol1_19_1To1_19_3.OPTIONAL_SIGNATURE_BYTES_TYPE, null); // Signature - } - - wrapper.write(Type.VAR_INT, 0); // Offset - wrapper.write(new BitSetType(20), new BitSet(20)); // Acknowledged - }); - } - }, true); - } - -} diff --git a/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/signature/model/DecoratableMessage.java b/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/signature/model/DecoratableMessage.java deleted file mode 100644 index 01adc2e..0000000 --- a/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/signature/model/DecoratableMessage.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy - * Copyright (C) 2023 RK_01/RaphiMC and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.raphimc.viaproxy.protocolhack.viaproxy.signature.model; - -import net.lenni0451.mcstructs.text.ATextComponent; -import net.lenni0451.mcstructs.text.components.StringComponent; - -public class DecoratableMessage { - - private final String plain; - private final ATextComponent decorated; - - public DecoratableMessage(final String plain) { - this(plain, new StringComponent(plain)); - } - - public DecoratableMessage(final String plain, final ATextComponent decorated) { - this.plain = plain; - this.decorated = decorated; - } - - public boolean isDecorated() { - return !this.decorated.equals(new StringComponent(this.plain)); - } - - public String getPlain() { - return this.plain; - } - - public ATextComponent getDecorated() { - return this.decorated; - } - -} diff --git a/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/signature/model/MessageMetadata.java b/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/signature/model/MessageMetadata.java deleted file mode 100644 index 980db84..0000000 --- a/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/signature/model/MessageMetadata.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy - * Copyright (C) 2023 RK_01/RaphiMC and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.raphimc.viaproxy.protocolhack.viaproxy.signature.model; - -import java.time.Instant; -import java.util.UUID; - -public class MessageMetadata { - - private final UUID sender; - private final Instant timestamp; - private final long salt; - - public MessageMetadata(final UUID sender, final Instant timestamp, final long salt) { - this.sender = sender; - this.timestamp = timestamp; - this.salt = salt; - } - - public MessageMetadata(final UUID sender, final long timestamp, final long salt) { - this(sender, Instant.ofEpochMilli(timestamp), salt); - } - - public UUID getSender() { - return this.sender; - } - - public Instant getTimestamp() { - return this.timestamp; - } - - public long getSalt() { - return this.salt; - } - -} diff --git a/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/signature/model/chain/v1_19_1/MessageBody.java b/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/signature/model/chain/v1_19_1/MessageBody.java deleted file mode 100644 index 6afdba2..0000000 --- a/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/signature/model/chain/v1_19_1/MessageBody.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy - * Copyright (C) 2023 RK_01/RaphiMC and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.raphimc.viaproxy.protocolhack.viaproxy.signature.model.chain.v1_19_1; - -import com.viaversion.viaversion.api.minecraft.PlayerMessageSignature; -import net.lenni0451.mcstructs.text.serializer.TextComponentSerializer; -import net.lenni0451.mcstructs.text.utils.JsonUtils; -import net.raphimc.viaproxy.protocolhack.viaproxy.signature.model.DecoratableMessage; -import net.raphimc.viaproxy.protocolhack.viaproxy.signature.util.DataConsumer; - -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.time.Instant; - -public class MessageBody { - - private final DecoratableMessage content; - private final Instant timestamp; - private final long salt; - private final PlayerMessageSignature[] lastSeenMessages; - - public MessageBody(final DecoratableMessage content, final Instant timestamp, final long salt, final PlayerMessageSignature[] lastSeenMessages) { - this.content = content; - this.timestamp = timestamp; - this.salt = salt; - this.lastSeenMessages = lastSeenMessages; - } - - public void update(final DataConsumer dataConsumer) { - try { - final MessageDigest digest = MessageDigest.getInstance("SHA-256"); - final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - final DataOutputStream dataOutputStream = new DataOutputStream(outputStream); - dataOutputStream.writeLong(this.salt); - dataOutputStream.writeLong(this.timestamp.getEpochSecond()); - - dataOutputStream.write(this.content.getPlain().getBytes(StandardCharsets.UTF_8)); - dataOutputStream.write(70); - if (this.content.isDecorated()) { - dataOutputStream.write(JsonUtils.toSortedString(TextComponentSerializer.V1_18.serializeJson(this.content.getDecorated()), null).getBytes(StandardCharsets.UTF_8)); - } - - for (PlayerMessageSignature lastSeenMessage : this.lastSeenMessages) { - dataOutputStream.writeByte(70); - dataOutputStream.writeLong(lastSeenMessage.uuid().getMostSignificantBits()); - dataOutputStream.writeLong(lastSeenMessage.uuid().getLeastSignificantBits()); - dataOutputStream.write(lastSeenMessage.signatureBytes()); - } - - digest.update(outputStream.toByteArray()); - dataConsumer.accept(digest.digest()); - } catch (NoSuchAlgorithmException | IOException e) { - throw new RuntimeException(e); - } - } - -} diff --git a/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/signature/model/chain/v1_19_1/MessageHeader.java b/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/signature/model/chain/v1_19_1/MessageHeader.java deleted file mode 100644 index a598aff..0000000 --- a/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/signature/model/chain/v1_19_1/MessageHeader.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy - * Copyright (C) 2023 RK_01/RaphiMC and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.raphimc.viaproxy.protocolhack.viaproxy.signature.model.chain.v1_19_1; - -import net.raphimc.viaproxy.protocolhack.viaproxy.signature.util.DataConsumer; - -import java.util.UUID; - -public class MessageHeader { - - private final byte[] precedingSignature; - private final UUID sender; - - public MessageHeader(final byte[] precedingSignature, final UUID sender) { - this.precedingSignature = precedingSignature; - this.sender = sender; - } - - public void update(final DataConsumer dataConsumer) { - if (this.precedingSignature != null) { - dataConsumer.accept(this.precedingSignature); - } - - dataConsumer.accept(this.sender); - } - -} diff --git a/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/signature/model/chain/v1_19_3/MessageBody.java b/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/signature/model/chain/v1_19_3/MessageBody.java deleted file mode 100644 index 6a9fda8..0000000 --- a/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/signature/model/chain/v1_19_3/MessageBody.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy - * Copyright (C) 2023 RK_01/RaphiMC and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.raphimc.viaproxy.protocolhack.viaproxy.signature.model.chain.v1_19_3; - -import com.google.common.primitives.Ints; -import com.google.common.primitives.Longs; -import com.viaversion.viaversion.api.minecraft.PlayerMessageSignature; -import net.raphimc.viaproxy.protocolhack.viaproxy.signature.util.DataConsumer; - -import java.nio.charset.StandardCharsets; -import java.time.Instant; - -public class MessageBody { - - private final String content; - private final Instant timestamp; - private final long salt; - private final PlayerMessageSignature[] lastSeenMessages; - - public MessageBody(final String content, final Instant timestamp, final long salt, final PlayerMessageSignature[] lastSeenMessages) { - this.content = content; - this.timestamp = timestamp; - this.salt = salt; - this.lastSeenMessages = lastSeenMessages; - } - - public void update(final DataConsumer dataConsumer) { - dataConsumer.accept(Longs.toByteArray(this.salt)); - dataConsumer.accept(Longs.toByteArray(this.timestamp.getEpochSecond())); - final byte[] contentData = this.content.getBytes(StandardCharsets.UTF_8); - dataConsumer.accept(Ints.toByteArray(contentData.length)); - dataConsumer.accept(contentData); - - dataConsumer.accept(Ints.toByteArray(this.lastSeenMessages.length)); - for (PlayerMessageSignature messageSignatureData : this.lastSeenMessages) { - dataConsumer.accept(messageSignatureData.signatureBytes()); - } - } - -} diff --git a/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/signature/model/chain/v1_19_3/MessageLink.java b/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/signature/model/chain/v1_19_3/MessageLink.java deleted file mode 100644 index e4f5705..0000000 --- a/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/signature/model/chain/v1_19_3/MessageLink.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy - * Copyright (C) 2023 RK_01/RaphiMC and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.raphimc.viaproxy.protocolhack.viaproxy.signature.model.chain.v1_19_3; - -import com.google.common.primitives.Ints; -import net.raphimc.viaproxy.protocolhack.viaproxy.signature.util.DataConsumer; - -import java.util.UUID; - -public class MessageLink { - - private final int index; - private final UUID sender; - private final UUID sessionId; - - public MessageLink(final UUID sender, final UUID sessionId) { - this(0, sender, sessionId); - } - - public MessageLink(final int index, final UUID sender, final UUID sessionId) { - this.index = index; - this.sender = sender; - this.sessionId = sessionId; - } - - public void update(final DataConsumer dataConsumer) { - dataConsumer.accept(this.sender); - dataConsumer.accept(this.sessionId); - dataConsumer.accept(Ints.toByteArray(this.index)); - } - - public MessageLink next() { - return this.index == Integer.MAX_VALUE ? null : new MessageLink(this.index + 1, this.sender, this.sessionId); - } - -} diff --git a/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/signature/storage/ChatSession.java b/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/signature/storage/ChatSession.java deleted file mode 100644 index aa6bb0c..0000000 --- a/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/signature/storage/ChatSession.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy - * Copyright (C) 2023 RK_01/RaphiMC and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.raphimc.viaproxy.protocolhack.viaproxy.signature.storage; - -import com.viaversion.viaversion.api.connection.StorableObject; -import com.viaversion.viaversion.api.minecraft.ProfileKey; -import net.raphimc.viaproxy.protocolhack.viaproxy.signature.util.DataConsumer; - -import java.security.PrivateKey; -import java.security.Signature; -import java.security.SignatureException; -import java.util.UUID; -import java.util.function.Consumer; - -public class ChatSession implements StorableObject { - - private final UUID uuid; - private final PrivateKey privateKey; - private final ProfileKey profileKey; - private final Signature signer; - - public ChatSession(final UUID uuid, final PrivateKey privateKey, final ProfileKey profileKey) { - this.uuid = uuid; - this.privateKey = privateKey; - this.profileKey = profileKey; - - try { - this.signer = Signature.getInstance("SHA256withRSA"); - this.signer.initSign(this.privateKey); - } catch (Throwable e) { - throw new RuntimeException("Failed to initialize signature", e); - } - } - - public UUID getUuid() { - return this.uuid; - } - - public ProfileKey getProfileKey() { - return this.profileKey; - } - - public byte[] sign(final Consumer dataConsumer) throws SignatureException { - dataConsumer.accept(bytes -> { - try { - this.signer.update(bytes); - } catch (SignatureException e) { - throw new RuntimeException(e); - } - }); - return this.signer.sign(); - } - -} diff --git a/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/signature/storage/ChatSession1_19_0.java b/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/signature/storage/ChatSession1_19_0.java deleted file mode 100644 index 49c67b6..0000000 --- a/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/signature/storage/ChatSession1_19_0.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy - * Copyright (C) 2023 RK_01/RaphiMC and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.raphimc.viaproxy.protocolhack.viaproxy.signature.storage; - -import com.viaversion.viaversion.api.minecraft.ProfileKey; -import net.lenni0451.mcstructs.text.serializer.TextComponentSerializer; -import net.lenni0451.mcstructs.text.utils.JsonUtils; -import net.raphimc.viaproxy.protocolhack.viaproxy.signature.model.DecoratableMessage; -import net.raphimc.viaproxy.protocolhack.viaproxy.signature.model.MessageMetadata; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.charset.StandardCharsets; -import java.security.PrivateKey; -import java.security.SignatureException; -import java.util.UUID; - -public class ChatSession1_19_0 extends ChatSession { - - public ChatSession1_19_0(UUID uuid, PrivateKey privateKey, ProfileKey profileKey) { - super(uuid, privateKey, profileKey); - } - - public byte[] signChatMessage(final MessageMetadata metadata, final DecoratableMessage content) throws SignatureException { - return this.sign(signer -> { - final byte[] data = new byte[32]; - final ByteBuffer buffer = ByteBuffer.wrap(data).order(ByteOrder.BIG_ENDIAN); - buffer.putLong(metadata.getSalt()); - buffer.putLong(metadata.getSender().getMostSignificantBits()).putLong(metadata.getSender().getLeastSignificantBits()); - buffer.putLong(metadata.getTimestamp().getEpochSecond()); - signer.accept(data); - signer.accept(JsonUtils.toSortedString(TextComponentSerializer.V1_18.serializeJson(content.getDecorated()), null).getBytes(StandardCharsets.UTF_8)); - }); - } - -} diff --git a/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/signature/storage/ChatSession1_19_1.java b/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/signature/storage/ChatSession1_19_1.java deleted file mode 100644 index 502c0c0..0000000 --- a/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/signature/storage/ChatSession1_19_1.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy - * Copyright (C) 2023 RK_01/RaphiMC and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.raphimc.viaproxy.protocolhack.viaproxy.signature.storage; - -import com.viaversion.viaversion.api.minecraft.PlayerMessageSignature; -import com.viaversion.viaversion.api.minecraft.ProfileKey; -import net.raphimc.viaproxy.protocolhack.viaproxy.signature.model.DecoratableMessage; -import net.raphimc.viaproxy.protocolhack.viaproxy.signature.model.MessageMetadata; -import net.raphimc.viaproxy.protocolhack.viaproxy.signature.model.chain.v1_19_1.MessageBody; -import net.raphimc.viaproxy.protocolhack.viaproxy.signature.model.chain.v1_19_1.MessageHeader; - -import java.security.PrivateKey; -import java.security.SignatureException; -import java.util.UUID; - -public class ChatSession1_19_1 extends ChatSession { - - private byte[] precedingSignature; - - public ChatSession1_19_1(UUID uuid, PrivateKey privateKey, ProfileKey profileKey) { - super(uuid, privateKey, profileKey); - } - - public byte[] signChatMessage(final MessageMetadata metadata, final DecoratableMessage content, final PlayerMessageSignature[] lastSeenMessages) throws SignatureException { - final byte[] signature = this.sign(signer -> { - final MessageHeader messageHeader = new MessageHeader(this.precedingSignature, metadata.getSender()); - final MessageBody messageBody = new MessageBody(content, metadata.getTimestamp(), metadata.getSalt(), lastSeenMessages); - messageHeader.update(signer); - messageBody.update(signer); - }); - this.precedingSignature = signature; - return signature; - } - -} diff --git a/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/signature/storage/ChatSession1_19_3.java b/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/signature/storage/ChatSession1_19_3.java deleted file mode 100644 index d5ca378..0000000 --- a/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/signature/storage/ChatSession1_19_3.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy - * Copyright (C) 2023 RK_01/RaphiMC and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.raphimc.viaproxy.protocolhack.viaproxy.signature.storage; - -import com.google.common.primitives.Ints; -import com.viaversion.viaversion.api.minecraft.PlayerMessageSignature; -import com.viaversion.viaversion.api.minecraft.ProfileKey; -import net.raphimc.viaproxy.protocolhack.viaproxy.signature.model.MessageMetadata; -import net.raphimc.viaproxy.protocolhack.viaproxy.signature.model.chain.v1_19_3.MessageBody; -import net.raphimc.viaproxy.protocolhack.viaproxy.signature.model.chain.v1_19_3.MessageLink; - -import java.security.PrivateKey; -import java.security.SignatureException; -import java.util.UUID; - -public class ChatSession1_19_3 extends ChatSession { - - private final UUID sessionId = UUID.randomUUID(); - private MessageLink link; - - public ChatSession1_19_3(UUID uuid, PrivateKey privateKey, ProfileKey profileKey) { - super(uuid, privateKey, profileKey); - - this.link = new MessageLink(uuid, this.sessionId); - } - - public byte[] signChatMessage(final MessageMetadata metadata, final String content, final PlayerMessageSignature[] lastSeenMessages) throws SignatureException { - return this.sign(signer -> { - final MessageLink messageLink = this.nextLink(); - final MessageBody messageBody = new MessageBody(content, metadata.getTimestamp(), metadata.getSalt(), lastSeenMessages); - signer.accept(Ints.toByteArray(1)); - messageLink.update(signer); - messageBody.update(signer); - }); - } - - private MessageLink nextLink() { - final MessageLink messageLink = this.link; - if (messageLink != null) { - this.link = messageLink.next(); - } - - return messageLink; - } - - public UUID getSessionId() { - return this.sessionId; - } - -} diff --git a/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/signature/util/DataConsumer.java b/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/signature/util/DataConsumer.java deleted file mode 100644 index 37ba4b5..0000000 --- a/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/signature/util/DataConsumer.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy - * Copyright (C) 2023 RK_01/RaphiMC and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.raphimc.viaproxy.protocolhack.viaproxy.signature.util; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.util.UUID; -import java.util.function.Consumer; - -@FunctionalInterface -public interface DataConsumer extends Consumer { - - default void accept(final UUID uuid) { - final byte[] serializedUuid = new byte[16]; - ByteBuffer.wrap(serializedUuid).order(ByteOrder.BIG_ENDIAN).putLong(uuid.getMostSignificantBits()).putLong(uuid.getLeastSignificantBits()); - this.accept(serializedUuid); - } - -} diff --git a/src/main/java/net/raphimc/viaproxy/proxy/external_interface/ExternalInterface.java b/src/main/java/net/raphimc/viaproxy/proxy/external_interface/ExternalInterface.java index 9fbebc3..6dce0e1 100644 --- a/src/main/java/net/raphimc/viaproxy/proxy/external_interface/ExternalInterface.java +++ b/src/main/java/net/raphimc/viaproxy/proxy/external_interface/ExternalInterface.java @@ -20,6 +20,9 @@ package net.raphimc.viaproxy.proxy.external_interface; import com.google.common.primitives.Longs; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.ProfileKey; +import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19_0; +import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19_1; +import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19_3; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import net.raphimc.mcauth.step.bedrock.StepMCChain; @@ -34,9 +37,6 @@ import net.raphimc.viaproxy.ViaProxy; import net.raphimc.viaproxy.cli.options.Options; import net.raphimc.viaproxy.plugins.PluginManager; import net.raphimc.viaproxy.plugins.events.FillPlayerDataEvent; -import net.raphimc.viaproxy.protocolhack.viaproxy.signature.storage.ChatSession1_19_0; -import net.raphimc.viaproxy.protocolhack.viaproxy.signature.storage.ChatSession1_19_1; -import net.raphimc.viaproxy.protocolhack.viaproxy.signature.storage.ChatSession1_19_3; import net.raphimc.viaproxy.proxy.session.ProxyConnection; import net.raphimc.viaproxy.saves.impl.accounts.Account; import net.raphimc.viaproxy.saves.impl.accounts.BedrockAccount; @@ -128,6 +128,8 @@ public class ExternalInterface { public static void signNonce(final byte[] nonce, final C2SLoginKeyPacket1_19 packet, final ProxyConnection proxyConnection) throws InterruptedException, ExecutionException, SignatureException { Logger.u_info("auth", proxyConnection.getC2P().remoteAddress(), proxyConnection.getGameProfile(), "Requesting nonce signature"); + final UserConnection user = proxyConnection.getUserConnection(); + if (Options.OPENAUTHMOD_AUTH) { try { final ByteBuf response = proxyConnection.sendCustomPayload(OpenAuthModConstants.SIGN_NONCE_CHANNEL, PacketTypes.writeByteArray(Unpooled.buffer(), nonce)).get(5, TimeUnit.SECONDS); @@ -138,18 +140,13 @@ public class ExternalInterface { } catch (TimeoutException e) { proxyConnection.kickClient("§cAuthentication cancelled! You need to install OpenAuthMod in order to join this server."); } - } else if (Options.CHAT_SIGNING) { - final UserConnection user = proxyConnection.getUserConnection(); - if (user.has(ChatSession1_19_0.class)) { - final long salt = ThreadLocalRandom.current().nextLong(); - packet.signature = user.get(ChatSession1_19_0.class).sign(updater -> { - updater.accept(nonce); - updater.accept(Longs.toByteArray(salt)); - }); - packet.salt = salt; - } else { - proxyConnection.kickClient("§cFailed to sign nonce"); - } + } else if (user.has(ChatSession1_19_0.class)) { + final long salt = ThreadLocalRandom.current().nextLong(); + packet.signature = user.get(ChatSession1_19_0.class).sign(updater -> { + updater.accept(nonce); + updater.accept(Longs.toByteArray(salt)); + }); + packet.salt = salt; } else { proxyConnection.kickClient("§cThis server requires a signed nonce. Please enable chat signing in the config and select a valid authentication mode."); }