diff --git a/src/main/java/de/bixilon/minosoft/commands/stack/CommandStack.kt b/src/main/java/de/bixilon/minosoft/commands/stack/CommandStack.kt index 5f6d600fd..14aa2cbff 100644 --- a/src/main/java/de/bixilon/minosoft/commands/stack/CommandStack.kt +++ b/src/main/java/de/bixilon/minosoft/commands/stack/CommandStack.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger + * Copyright (C) 2020-2023 Moritz Zwerger * * 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. * @@ -16,7 +16,7 @@ package de.bixilon.minosoft.commands.stack import de.bixilon.kutil.cast.CastUtil.nullCast import de.bixilon.minosoft.commands.stack.print.PrintTarget import de.bixilon.minosoft.commands.stack.print.SystemPrintTarget -import de.bixilon.minosoft.data.chat.signature.MessageChain +import de.bixilon.minosoft.data.chat.signature.signer.MessageSigner import de.bixilon.minosoft.data.entities.entities.Entity import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection import java.security.PrivateKey @@ -55,7 +55,7 @@ class CommandStack( stack.add(CommandStackEntry(name, data)) } - fun sign(chain: MessageChain, key: PrivateKey, salt: Long, time: Instant): Map { + fun sign(chain: MessageSigner, key: PrivateKey, salt: Long, time: Instant): Map { val output: MutableMap = mutableMapOf() for (entry in stack) { output[entry.name] = entry.sign(connection, chain, key, salt, time) diff --git a/src/main/java/de/bixilon/minosoft/data/chat/signature/MessageChain.kt b/src/main/java/de/bixilon/minosoft/data/chat/signature/MessageChain.kt deleted file mode 100644 index 7a566eab5..000000000 --- a/src/main/java/de/bixilon/minosoft/data/chat/signature/MessageChain.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Minosoft - * Copyright (C) 2020-2023 Moritz Zwerger - * - * 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 . - * - * This software is not affiliated with Mojang AB, the original developer of Minecraft. - */ - -package de.bixilon.minosoft.data.chat.signature - -import de.bixilon.minosoft.data.chat.signature.signer.MessageSigner -import de.bixilon.minosoft.data.text.ChatComponent -import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection -import de.bixilon.minosoft.protocol.versions.Version -import java.security.PrivateKey -import java.time.Instant -import java.util.* - -class MessageChain(version: Version, connection: PlayConnection) { - val signer = MessageSigner.forVersion(version, connection) - - fun signMessage(privateKey: PrivateKey, message: String, preview: ChatComponent?, salt: Long, sender: UUID, time: Instant, lastSeen: LastSeenMessageList): ByteArray { - return signer.signMessage(privateKey, message, preview, salt, sender, time, lastSeen) - } -} diff --git a/src/main/java/de/bixilon/minosoft/protocol/network/connection/play/ConnectionUtil.kt b/src/main/java/de/bixilon/minosoft/protocol/network/connection/play/ConnectionUtil.kt index bba8b0e9a..84f8a905a 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/network/connection/play/ConnectionUtil.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/network/connection/play/ConnectionUtil.kt @@ -20,7 +20,7 @@ import de.bixilon.minosoft.commands.stack.CommandStack import de.bixilon.minosoft.commands.util.CommandReader import de.bixilon.minosoft.data.chat.message.InternalChatMessage import de.bixilon.minosoft.data.chat.signature.Acknowledgement -import de.bixilon.minosoft.data.chat.signature.MessageChain +import de.bixilon.minosoft.data.chat.signature.signer.MessageSigner import de.bixilon.minosoft.data.entities.entities.player.local.HealthCondition import de.bixilon.minosoft.data.text.BaseComponent import de.bixilon.minosoft.data.text.ChatComponent @@ -47,7 +47,7 @@ import java.time.Instant class ConnectionUtil( private val connection: PlayConnection, ) { - private val chain = MessageChain(connection.version, connection) + val signer = MessageSigner.forVersion(connection.version, connection) private val random = SecureRandom() fun sendDebugMessage(message: Any) { @@ -97,7 +97,7 @@ class ConnectionUtil( val acknowledgement = Acknowledgement.EMPTY val signature: ByteArray? = if (connection.network.encrypted) { - chain.signMessage(privateKey, message, null, salt, uuid, time, acknowledgement.lastSeen) + signer.signMessage(privateKey, message, null, salt, uuid, time, acknowledgement.lastSeen) } else { null } @@ -117,7 +117,7 @@ class ConnectionUtil( val key = connection.player.privateKey if (key != null && connection.network.encrypted && connection.profiles.connection.signature.signCommands) { - signature = stack.sign(chain, key.private, salt, time) + signature = stack.sign(signer, key.private, salt, time) } connection.sendPacket(CommandC2SP(command.trimWhitespaces().removePrefix("/"), time, salt, signature, false, acknowledgement))