Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-20 06:50:08 +01:00
Implement provider to allow signed commands in 1.19.x protocols (#3493)
Dieser Commit ist enthalten in:
Ursprung
0f030c86a7
Commit
abe880dae6
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2023 ViaVersion and contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.viaversion.viaversion.api.minecraft.signature;
|
||||||
|
|
||||||
|
import com.viaversion.viaversion.api.platform.providers.Provider;
|
||||||
|
import com.viaversion.viaversion.util.Pair;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public abstract class SignableCommandArgumentsProvider implements Provider {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param command The command to get the signable arguments for.
|
||||||
|
* @return The signable arguments for the command.
|
||||||
|
*/
|
||||||
|
public abstract List<Pair<String, String>> getSignableArguments(final String command);
|
||||||
|
}
|
@ -24,6 +24,7 @@ import com.google.gson.JsonElement;
|
|||||||
import com.viaversion.viaversion.api.Via;
|
import com.viaversion.viaversion.api.Via;
|
||||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||||
import com.viaversion.viaversion.api.minecraft.ProfileKey;
|
import com.viaversion.viaversion.api.minecraft.ProfileKey;
|
||||||
|
import com.viaversion.viaversion.api.minecraft.signature.SignableCommandArgumentsProvider;
|
||||||
import com.viaversion.viaversion.api.minecraft.signature.model.DecoratableMessage;
|
import com.viaversion.viaversion.api.minecraft.signature.model.DecoratableMessage;
|
||||||
import com.viaversion.viaversion.api.minecraft.signature.model.MessageMetadata;
|
import com.viaversion.viaversion.api.minecraft.signature.model.MessageMetadata;
|
||||||
import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19_0;
|
import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19_0;
|
||||||
@ -44,6 +45,7 @@ import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.storage.NonceSto
|
|||||||
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.ClientboundPackets1_19;
|
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.ClientboundPackets1_19;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.ServerboundPackets1_19;
|
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.ServerboundPackets1_19;
|
||||||
import com.viaversion.viaversion.util.CipherUtil;
|
import com.viaversion.viaversion.util.CipherUtil;
|
||||||
|
import com.viaversion.viaversion.util.Pair;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -165,10 +167,35 @@ public final class Protocol1_19_1To1_19 extends AbstractProtocol<ClientboundPack
|
|||||||
map(Type.LONG); // Timestamp
|
map(Type.LONG); // Timestamp
|
||||||
map(Type.LONG); // Salt
|
map(Type.LONG); // Salt
|
||||||
handler(wrapper -> {
|
handler(wrapper -> {
|
||||||
final int signatures = wrapper.passthrough(Type.VAR_INT);
|
final ChatSession1_19_0 chatSession = wrapper.user().get(ChatSession1_19_0.class);
|
||||||
|
final SignableCommandArgumentsProvider argumentsProvider = Via.getManager().getProviders().get(SignableCommandArgumentsProvider.class);
|
||||||
|
|
||||||
|
final int signatures = wrapper.read(Type.VAR_INT);
|
||||||
for (int i = 0; i < signatures; i++) {
|
for (int i = 0; i < signatures; i++) {
|
||||||
wrapper.passthrough(Type.STRING); // Argument name
|
wrapper.read(Type.STRING); // Argument name
|
||||||
wrapper.passthrough(Type.BYTE_ARRAY_PRIMITIVE); // Signature
|
wrapper.read(Type.BYTE_ARRAY_PRIMITIVE); // Signature
|
||||||
|
}
|
||||||
|
|
||||||
|
if (chatSession != null && argumentsProvider != 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 List<Pair<String, String>> arguments = argumentsProvider.getSignableArguments(message);
|
||||||
|
|
||||||
|
wrapper.write(Type.VAR_INT, arguments.size()); // Signature count
|
||||||
|
for (Pair<String, String> argument : arguments) {
|
||||||
|
final MessageMetadata metadata = new MessageMetadata(sender, timestamp, salt);
|
||||||
|
final DecoratableMessage decoratableMessage = new DecoratableMessage(argument.value());
|
||||||
|
|
||||||
|
final byte[] signature = chatSession.signChatMessage(metadata, decoratableMessage);
|
||||||
|
|
||||||
|
wrapper.write(Type.STRING, argument.key()); // Argument name
|
||||||
|
wrapper.write(Type.BYTE_ARRAY_PRIMITIVE, signature); // Signature
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
wrapper.write(Type.VAR_INT, 0); // Signature count
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
map(Type.BOOLEAN); // Signed preview
|
map(Type.BOOLEAN); // Signed preview
|
||||||
|
@ -19,12 +19,14 @@ package com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1;
|
|||||||
|
|
||||||
import com.google.common.primitives.Longs;
|
import com.google.common.primitives.Longs;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
|
import com.viaversion.viaversion.api.Via;
|
||||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||||
import com.viaversion.viaversion.api.data.MappingData;
|
import com.viaversion.viaversion.api.data.MappingData;
|
||||||
import com.viaversion.viaversion.api.data.MappingDataBase;
|
import com.viaversion.viaversion.api.data.MappingDataBase;
|
||||||
import com.viaversion.viaversion.api.minecraft.PlayerMessageSignature;
|
import com.viaversion.viaversion.api.minecraft.PlayerMessageSignature;
|
||||||
import com.viaversion.viaversion.api.minecraft.RegistryType;
|
import com.viaversion.viaversion.api.minecraft.RegistryType;
|
||||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19_3;
|
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19_3;
|
||||||
|
import com.viaversion.viaversion.api.minecraft.signature.SignableCommandArgumentsProvider;
|
||||||
import com.viaversion.viaversion.api.minecraft.signature.model.DecoratableMessage;
|
import com.viaversion.viaversion.api.minecraft.signature.model.DecoratableMessage;
|
||||||
import com.viaversion.viaversion.api.minecraft.signature.model.MessageMetadata;
|
import com.viaversion.viaversion.api.minecraft.signature.model.MessageMetadata;
|
||||||
import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19_1;
|
import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19_1;
|
||||||
@ -51,7 +53,9 @@ import com.viaversion.viaversion.rewriter.CommandRewriter;
|
|||||||
import com.viaversion.viaversion.rewriter.SoundRewriter;
|
import com.viaversion.viaversion.rewriter.SoundRewriter;
|
||||||
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
|
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
|
||||||
import com.viaversion.viaversion.rewriter.TagRewriter;
|
import com.viaversion.viaversion.rewriter.TagRewriter;
|
||||||
|
import com.viaversion.viaversion.util.Pair;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
@ -217,16 +221,40 @@ public final class Protocol1_19_3To1_19_1 extends AbstractProtocol<ClientboundPa
|
|||||||
map(Type.LONG); // Timestamp
|
map(Type.LONG); // Timestamp
|
||||||
map(Type.LONG); // Salt
|
map(Type.LONG); // Salt
|
||||||
handler(wrapper -> {
|
handler(wrapper -> {
|
||||||
|
final ChatSession1_19_1 chatSession = wrapper.user().get(ChatSession1_19_1.class);
|
||||||
|
final ReceivedMessagesStorage messagesStorage = wrapper.user().get(ReceivedMessagesStorage.class);
|
||||||
|
|
||||||
final int signatures = wrapper.read(Type.VAR_INT);
|
final int signatures = wrapper.read(Type.VAR_INT);
|
||||||
wrapper.write(Type.VAR_INT, 0);
|
|
||||||
for (int i = 0; i < signatures; i++) {
|
for (int i = 0; i < signatures; i++) {
|
||||||
wrapper.read(Type.STRING); // Argument name
|
wrapper.read(Type.STRING); // Argument name
|
||||||
wrapper.read(Type.SIGNATURE_BYTES); // Signature
|
wrapper.read(Type.SIGNATURE_BYTES); // Signature
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final SignableCommandArgumentsProvider argumentsProvider = Via.getManager().getProviders().get(SignableCommandArgumentsProvider.class);
|
||||||
|
if (chatSession != null && argumentsProvider != 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 List<Pair<String, String>> arguments = argumentsProvider.getSignableArguments(message);
|
||||||
|
wrapper.write(Type.VAR_INT, arguments.size()); // Signature count
|
||||||
|
|
||||||
|
for (Pair<String, String> argument : arguments) {
|
||||||
|
final MessageMetadata metadata = new MessageMetadata(sender, timestamp, salt);
|
||||||
|
final DecoratableMessage decoratableMessage = new DecoratableMessage(argument.value());
|
||||||
|
|
||||||
|
final byte[] signature = chatSession.signChatMessage(metadata, decoratableMessage, messagesStorage.lastSignatures());
|
||||||
|
|
||||||
|
wrapper.write(Type.STRING, argument.key()); // Argument name
|
||||||
|
wrapper.write(Type.BYTE_ARRAY_PRIMITIVE, signature); // Signature
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
wrapper.write(Type.VAR_INT, 0); // Signature count
|
||||||
|
}
|
||||||
|
|
||||||
wrapper.write(Type.BOOLEAN, false); // No signed preview
|
wrapper.write(Type.BOOLEAN, false); // No signed preview
|
||||||
|
|
||||||
final ReceivedMessagesStorage messagesStorage = wrapper.user().get(ReceivedMessagesStorage.class);
|
|
||||||
messagesStorage.resetUnacknowledgedCount();
|
messagesStorage.resetUnacknowledgedCount();
|
||||||
wrapper.write(Type.PLAYER_MESSAGE_SIGNATURE_ARRAY, messagesStorage.lastSignatures());
|
wrapper.write(Type.PLAYER_MESSAGE_SIGNATURE_ARRAY, messagesStorage.lastSignatures());
|
||||||
wrapper.write(Type.OPTIONAL_PLAYER_MESSAGE_SIGNATURE, null); // No last unacknowledged
|
wrapper.write(Type.OPTIONAL_PLAYER_MESSAGE_SIGNATURE, null); // No last unacknowledged
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren