From ab1df14b774f1cc1d150c7f9ef96c3a47b9c31b5 Mon Sep 17 00:00:00 2001 From: Bixilon Date: Sat, 7 Jan 2023 16:22:46 +0100 Subject: [PATCH] chat signature test --- .../data/accounts/types/test/TestAccount.kt | 40 ++++++ .../data/chat/signature/SignatureSIT.kt | 13 +- .../signature/signer/MessageSigner1Test.kt | 85 ++++++++++++ .../signature/signer/MessageSigner2Test.kt | 92 +++++++++++++ .../signature/signer/MessageSigner3Test.kt | 122 ++++++++++++++++++ .../versions/PixLyzerLoadingTest.kt | 3 +- .../connection/play/ConnectionTestUtil.kt | 4 +- .../commands/stack/CommandStackEntry.kt | 6 +- .../chat/signature/signer/MessageSigner1.kt | 8 +- .../chat/signature/signer/MessageSigner3.kt | 11 +- 10 files changed, 368 insertions(+), 16 deletions(-) create mode 100644 src/integration-test/kotlin/de/bixilon/minosoft/data/accounts/types/test/TestAccount.kt create mode 100644 src/integration-test/kotlin/de/bixilon/minosoft/data/chat/signature/signer/MessageSigner1Test.kt create mode 100644 src/integration-test/kotlin/de/bixilon/minosoft/data/chat/signature/signer/MessageSigner2Test.kt create mode 100644 src/integration-test/kotlin/de/bixilon/minosoft/data/chat/signature/signer/MessageSigner3Test.kt diff --git a/src/integration-test/kotlin/de/bixilon/minosoft/data/accounts/types/test/TestAccount.kt b/src/integration-test/kotlin/de/bixilon/minosoft/data/accounts/types/test/TestAccount.kt new file mode 100644 index 000000000..12c064081 --- /dev/null +++ b/src/integration-test/kotlin/de/bixilon/minosoft/data/accounts/types/test/TestAccount.kt @@ -0,0 +1,40 @@ +/* + * 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.accounts.types.test + +import de.bixilon.kutil.latch.CountUpAndDownLatch +import de.bixilon.kutil.uuid.UUIDUtil.toUUID +import de.bixilon.minosoft.data.accounts.Account +import de.bixilon.minosoft.data.accounts.AccountStates +import de.bixilon.minosoft.data.entities.entities.player.properties.PlayerProperties +import de.bixilon.minosoft.data.registries.identified.Namespaces.minosoft +import de.bixilon.minosoft.data.registries.identified.ResourceLocation +import java.util.* + +object TestAccount : Account("Bixilon") { + override val id: String = "id" + override val type: ResourceLocation = minosoft("test_account") + override val properties: PlayerProperties? = null + override val uuid: UUID = "9e6ce7c5-40d3-483e-8e5a-b6350987d65f".toUUID() + override var state: AccountStates + get() = AccountStates.WORKING + set(value) {} + override val supportsSkins: Boolean get() = true + + override fun join(serverId: String) = Unit + + override fun logout(clientToken: String) = Unit + + override fun check(latch: CountUpAndDownLatch?, clientToken: String) = Unit +} diff --git a/src/integration-test/kotlin/de/bixilon/minosoft/data/chat/signature/SignatureSIT.kt b/src/integration-test/kotlin/de/bixilon/minosoft/data/chat/signature/SignatureSIT.kt index c6568e78e..a479732da 100644 --- a/src/integration-test/kotlin/de/bixilon/minosoft/data/chat/signature/SignatureSIT.kt +++ b/src/integration-test/kotlin/de/bixilon/minosoft/data/chat/signature/SignatureSIT.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. * @@ -20,9 +20,11 @@ import de.bixilon.minosoft.util.yggdrasil.YggdrasilUtil import org.testng.Assert import org.testng.SkipException import org.testng.annotations.Test +import java.time.Instant @Test(groups = ["private_key"]) class SignatureSIT { + // The private key is a private environment variable in gitlab. Yes, that makes it hard to run tests outside my devices, but you have to understand that I am not publishing my private key, no matter if it is already expired fun loadYggdrasil() { YggdrasilUtil.load() @@ -35,12 +37,17 @@ class SignatureSIT { @Test(dependsOnMethods = ["loadPrivateKey"]) fun testKeyUUID() { - SignatureTestUtil.key.requireSignature("9e6ce7c5-40d3-483e-8e5a-b6350987d65f".toUUID()) // yep, that is really my private key + SignatureTestUtil.key.requireSignature("9e6ce7c5-40d3-483e-8e5a-b6350987d65f".toUUID()) // yep, that is really Bixilon's private key } @Test(dependsOnMethods = ["loadPrivateKey"]) fun testRequireSignature() { - Assert.assertThrows { SignatureTestUtil.key.requireSignature("b876ec32-e396-476b-a115-8438d83c67d4".toUUID()) } + Assert.assertThrows { SignatureTestUtil.key.requireSignature("b876ec32-e396-476b-a115-8438d83c67d4".toUUID()) } // sadly that is not possible anymore + } + + @Test(dependsOnMethods = ["loadPrivateKey"]) + fun testExpiresAt() { + Assert.assertEquals(SignatureTestUtil.key.expiresAt, Instant.ofEpochSecond(1668977246L, 93031788L)) // verify that we load the correct key and not just some key } } diff --git a/src/integration-test/kotlin/de/bixilon/minosoft/data/chat/signature/signer/MessageSigner1Test.kt b/src/integration-test/kotlin/de/bixilon/minosoft/data/chat/signature/signer/MessageSigner1Test.kt new file mode 100644 index 000000000..985bc45a3 --- /dev/null +++ b/src/integration-test/kotlin/de/bixilon/minosoft/data/chat/signature/signer/MessageSigner1Test.kt @@ -0,0 +1,85 @@ +/* + * 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.signer + +import de.bixilon.kutil.base64.Base64Util.fromBase64 +import de.bixilon.minosoft.data.accounts.types.test.TestAccount +import de.bixilon.minosoft.data.chat.signature.SignatureTestUtil +import de.bixilon.minosoft.protocol.protocol.ProtocolVersions +import de.bixilon.minosoft.protocol.versions.Version +import de.bixilon.minosoft.protocol.versions.Versions +import org.testng.annotations.Test +import org.testng.internal.junit.ArrayAsserts.assertArrayEquals +import java.time.Instant + +@Test(groups = ["signature"], dependsOnGroups = ["private_key"]) +class MessageSigner1Test { + private lateinit var version: Version + + @Test(priority = -1) + fun setup() { + version = Versions.getById(ProtocolVersions.V_1_19)!! + } + + private fun create(): MessageSigner1 { + return MessageSigner1(version) + } + + fun signing1() { + val message = "bixilon began the development during lockdown" + val time = Instant.ofEpochMilli(1673102470_1234) + val signer = create() + val signature = signer.signMessage(SignatureTestUtil.key.pair.private, message, -4886770986649219020L, TestAccount.uuid, time) + + + val expected = "".fromBase64() // TODO + assertArrayEquals(expected, signature) + } + + fun signing2() { + val message = "reversing signature code is pita" + val time = Instant.ofEpochMilli(1673103191_5678) + val signer = create() + val signature = signer.signMessage(SignatureTestUtil.key.pair.private, message, 1856442944183750824L, TestAccount.uuid, time) + + + val expected = "".fromBase64() // TODO + assertArrayEquals(expected, signature) + } + + fun signing3() { + val message = "now even with last seen messages. I don't know their purpose." + val time = Instant.ofEpochMilli(1673103854_8402) + val signer = create() + + val signature = signer.signMessage(SignatureTestUtil.key.pair.private, message, 6392082609L, TestAccount.uuid, time) + + + val expected = "".fromBase64() // TODO + assertArrayEquals(expected, signature) + } + + fun signing4() { + val message = "ʞ⍧\uDB16\uDFB1іⴎO\uD85E\uDF9A!㛽J˻5&뻝\uD8B9\uDE8F\uDA0C\uDC41\uDB9B\uDD0Fi읣މ猣랒糓\uD8EF\uDFCFk\uDA1D\uDCA4썿ߛ믣Ȣ\uDA51\uDF5B4" // random utf8 chars + val time = Instant.ofEpochMilli(1739579479_6302) + val signer = create() + + val signature = signer.signMessage(SignatureTestUtil.key.pair.private, message, 6392082609L, TestAccount.uuid, time) + + + val expected = "".fromBase64() // TODO + assertArrayEquals(expected, signature) + } + // TODO: Test 22w17a (sha1 signature) +} diff --git a/src/integration-test/kotlin/de/bixilon/minosoft/data/chat/signature/signer/MessageSigner2Test.kt b/src/integration-test/kotlin/de/bixilon/minosoft/data/chat/signature/signer/MessageSigner2Test.kt new file mode 100644 index 000000000..4cac6c610 --- /dev/null +++ b/src/integration-test/kotlin/de/bixilon/minosoft/data/chat/signature/signer/MessageSigner2Test.kt @@ -0,0 +1,92 @@ +/* + * 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.signer + +import de.bixilon.kutil.base64.Base64Util.fromBase64 +import de.bixilon.minosoft.data.accounts.types.test.TestAccount +import de.bixilon.minosoft.data.chat.signature.LastSeenMessageList +import de.bixilon.minosoft.data.chat.signature.SignatureTestUtil +import de.bixilon.minosoft.data.chat.signature.lastSeen.LastSeenMessage +import de.bixilon.minosoft.protocol.protocol.ProtocolVersions +import de.bixilon.minosoft.protocol.versions.Version +import de.bixilon.minosoft.protocol.versions.Versions +import org.testng.annotations.Test +import org.testng.internal.junit.ArrayAsserts.assertArrayEquals +import java.time.Instant +import java.util.* + +@Test(groups = ["signature"], dependsOnGroups = ["private_key"]) +class MessageSigner2Test { + private lateinit var version: Version + + @Test(priority = -1) + fun setup() { + version = Versions.getById(ProtocolVersions.V_1_19_2)!! + } + + private fun create(): MessageSigner2 { + return MessageSigner2(version) + } + + fun signing1() { + val message = "bixilon began the development during lockdown" + val time = Instant.ofEpochMilli(1673102470_1234) + val signer = create() + val signature = signer.signMessage(SignatureTestUtil.key.pair.private, message, null, -4886770986649219020L, TestAccount.uuid, time, LastSeenMessageList(emptyArray())) + + + val expected = "".fromBase64() // TODO + assertArrayEquals(expected, signature) + } + + fun signing2() { + val message = "reversing signature code is pita" + val time = Instant.ofEpochMilli(1673103191_5678) + val signer = create() + val signature = signer.signMessage(SignatureTestUtil.key.pair.private, message, null, 1856442944183750824L, TestAccount.uuid, time, LastSeenMessageList(emptyArray())) + + + val expected = "".fromBase64() // TODO + assertArrayEquals(expected, signature) + } + + fun signing3() { + val message = "now even with last seen messages. I don't know their purpose." + val time = Instant.ofEpochMilli(1673103854_8402) + val signer = create() + + val lastSeen = LastSeenMessageList(arrayOf(LastSeenMessage(UUID(0L, 0L), "/OmblHW9CwdAawdE7WtVurRs7umsa/my8EeTT/NY36lqg3HmtAsqyRQ4fXHelw6pOA4o8UroAlmx+inwiEFHXkDICEIVM69vHKapQvoAaeEVrQ4pn9vURTY3GcUVOgr12V3d00odEpwviXaF6kchG1b/pZsLsfpacMiiVHkxZoqolvUNifHQKXVS48Gu1AKkwRw6bkcOKYZpcZgffe6U273rEQQefwzIdT/8F1P04WhiH7SREexVOolkuoKo6gYxXELf5M0BUf0ssG3SS1k8Wr3ys9nzB6hSoEd/ftKqGVxoqeq7pd1GgKfaRWpka8ZNyDpdm8JqvrmlN/phpS5X4Q==".fromBase64()))) // uuid does not matter, bytes are random + val signature = signer.signMessage(SignatureTestUtil.key.pair.private, message, null, 6392082609L, TestAccount.uuid, time, lastSeen) + + + val expected = "".fromBase64() // TODO + assertArrayEquals(expected, signature) + } + + fun signing4() { + val message = "ʞ⍧\uDB16\uDFB1іⴎO\uD85E\uDF9A!㛽J˻5&뻝\uD8B9\uDE8F\uDA0C\uDC41\uDB9B\uDD0Fi읣މ猣랒糓\uD8EF\uDFCFk\uDA1D\uDCA4썿ߛ믣Ȣ\uDA51\uDF5B4" // random utf8 chars + val time = Instant.ofEpochMilli(1739579479_6302) + val signer = create() + + val signature = signer.signMessage(SignatureTestUtil.key.pair.private, message, null, 6392082609L, TestAccount.uuid, time, LastSeenMessageList(emptyArray())) + + + val expected = "".fromBase64() // TODO + assertArrayEquals(expected, signature) + } + + // TODO: Test 1.19.1 (changes to string encoding) + // TODO: Test preview + // TODO: Test previous signature (singing 2x) +} diff --git a/src/integration-test/kotlin/de/bixilon/minosoft/data/chat/signature/signer/MessageSigner3Test.kt b/src/integration-test/kotlin/de/bixilon/minosoft/data/chat/signature/signer/MessageSigner3Test.kt new file mode 100644 index 000000000..6c99503ed --- /dev/null +++ b/src/integration-test/kotlin/de/bixilon/minosoft/data/chat/signature/signer/MessageSigner3Test.kt @@ -0,0 +1,122 @@ +/* + * 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.signer + +import de.bixilon.kutil.base64.Base64Util.fromBase64 +import de.bixilon.kutil.uuid.UUIDUtil.toUUID +import de.bixilon.minosoft.data.accounts.types.test.TestAccount +import de.bixilon.minosoft.data.chat.signature.LastSeenMessageList +import de.bixilon.minosoft.data.chat.signature.SignatureTestUtil +import de.bixilon.minosoft.data.chat.signature.lastSeen.LastSeenMessage +import de.bixilon.minosoft.protocol.protocol.ProtocolVersions +import de.bixilon.minosoft.protocol.versions.Version +import de.bixilon.minosoft.protocol.versions.Versions +import org.testng.Assert.assertEquals +import org.testng.annotations.Test +import org.testng.internal.junit.ArrayAsserts.assertArrayEquals +import java.time.Instant +import java.util.* + +@Test(groups = ["signature"], dependsOnGroups = ["private_key"]) +class MessageSigner3Test { + private lateinit var version: Version + + @Test(priority = -1) + fun setup() { + version = Versions.getById(ProtocolVersions.V_1_19_3)!! + } + + private fun create(sessionId: UUID): MessageSigner3 { + return MessageSigner3(version, sessionId) + } + + fun signing1() { + val message = "bixilon began the development during lockdown" + val time = Instant.ofEpochMilli(1673102470_1234) + val signer = create("a26b7114-36c4-4eea-acac-108f516ef72d".toUUID()) + val signature = signer.signMessage(SignatureTestUtil.key.pair.private, message, -4886770986649219020L, TestAccount.uuid, time, LastSeenMessageList(emptyArray())) + + + val expected = "".fromBase64() // TODO + assertArrayEquals(expected, signature) + } + + fun signing2() { + val message = "reversing signature code is pita" + val time = Instant.ofEpochMilli(1673103191_5678) + val signer = create("79f3da83-a6a1-4d55-9aca-39d5faf4ad8b".toUUID()) + val signature = signer.signMessage(SignatureTestUtil.key.pair.private, message, 1856442944183750824L, TestAccount.uuid, time, LastSeenMessageList(emptyArray())) + + + val expected = "".fromBase64() // TODO + assertArrayEquals(expected, signature) + } + + fun signing3() { + val message = "now even with last seen messages. I don't know their purpose." + val time = Instant.ofEpochMilli(1673103854_8402) + val signer = create("5c31705b-963c-4832-b8a5-1ee617a4b362".toUUID()) + + val lastSeen = LastSeenMessageList(arrayOf(LastSeenMessage(UUID(0L, 0L), "/OmblHW9CwdAawdE7WtVurRs7umsa/my8EeTT/NY36lqg3HmtAsqyRQ4fXHelw6pOA4o8UroAlmx+inwiEFHXkDICEIVM69vHKapQvoAaeEVrQ4pn9vURTY3GcUVOgr12V3d00odEpwviXaF6kchG1b/pZsLsfpacMiiVHkxZoqolvUNifHQKXVS48Gu1AKkwRw6bkcOKYZpcZgffe6U273rEQQefwzIdT/8F1P04WhiH7SREexVOolkuoKo6gYxXELf5M0BUf0ssG3SS1k8Wr3ys9nzB6hSoEd/ftKqGVxoqeq7pd1GgKfaRWpka8ZNyDpdm8JqvrmlN/phpS5X4Q==".fromBase64()))) // uuid does not matter, bytes are random + val signature = signer.signMessage(SignatureTestUtil.key.pair.private, message, 6392082609L, TestAccount.uuid, time, lastSeen) + + + val expected = "".fromBase64() // TODO + assertArrayEquals(expected, signature) + } + + fun signing4() { + val message = "ʞ⍧\uDB16\uDFB1іⴎO\uD85E\uDF9A!㛽J˻5&뻝\uD8B9\uDE8F\uDA0C\uDC41\uDB9B\uDD0Fi읣މ猣랒糓\uD8EF\uDFCFk\uDA1D\uDCA4썿ߛ믣Ȣ\uDA51\uDF5B4" // random utf8 chars + val time = Instant.ofEpochMilli(1739579479_6302) + val signer = create("232170f7-ef39-4959-bf4a-354145b9483a".toUUID()) + + val signature = signer.signMessage(SignatureTestUtil.key.pair.private, message, 6392082609L, TestAccount.uuid, time, LastSeenMessageList(emptyArray())) + + + val expected = "".fromBase64() // TODO + assertArrayEquals(expected, signature) + } + + fun signing5() { + val messages = listOf( + Pair( + "this is the first message :)", + Instant.ofEpochMilli(1673104584_7491), + ), + Pair( + "this is the second message :)", + Instant.ofEpochMilli(1673104585_7492), + ), + Pair( + "this is the third and last message :)", + Instant.ofEpochMilli(1673104586_7493), + ) + ) + + val signer = create("de2f95c2-8730-47ba-a5aa-8db09fcec48e".toUUID()) + + val signatures: MutableList = mutableListOf() + for ((message, time) in messages) { + signatures += signer.signMessage(SignatureTestUtil.key.pair.private, message, 6392082609L, TestAccount.uuid, time, LastSeenMessageList(emptyArray())) + } + + + val expected = listOf( + "".fromBase64(), // TODO + "".fromBase64(), // TODO + "".fromBase64(), // TODO + ) + assertEquals(expected, signatures) + } +} diff --git a/src/integration-test/kotlin/de/bixilon/minosoft/data/registries/versions/PixLyzerLoadingTest.kt b/src/integration-test/kotlin/de/bixilon/minosoft/data/registries/versions/PixLyzerLoadingTest.kt index d88be3214..9683f4ab0 100644 --- a/src/integration-test/kotlin/de/bixilon/minosoft/data/registries/versions/PixLyzerLoadingTest.kt +++ b/src/integration-test/kotlin/de/bixilon/minosoft/data/registries/versions/PixLyzerLoadingTest.kt @@ -21,9 +21,8 @@ import de.bixilon.minosoft.protocol.protocol.VersionSupport import de.bixilon.minosoft.protocol.versions.Versions import de.bixilon.minosoft.test.ITUtil import org.testng.Assert -import org.testng.annotations.Test -@Test(groups = ["pixlyzer"], dependsOnGroups = ["version"], singleThreaded = false, threadPoolSize = 8) +// @Test(groups = ["pixlyzer"], dependsOnGroups = ["version"], singleThreaded = false, threadPoolSize = 8) class PixLyzerLoadingTest { private fun VersionRegistry.test() { diff --git a/src/integration-test/kotlin/de/bixilon/minosoft/protocol/network/connection/play/ConnectionTestUtil.kt b/src/integration-test/kotlin/de/bixilon/minosoft/protocol/network/connection/play/ConnectionTestUtil.kt index 97d8a03e9..d3956f5ed 100644 --- a/src/integration-test/kotlin/de/bixilon/minosoft/protocol/network/connection/play/ConnectionTestUtil.kt +++ b/src/integration-test/kotlin/de/bixilon/minosoft/protocol/network/connection/play/ConnectionTestUtil.kt @@ -17,7 +17,7 @@ import de.bixilon.kutil.observer.DataObserver import de.bixilon.kutil.reflection.ReflectionUtil.forceSet import de.bixilon.minosoft.assets.TestAssetsManager import de.bixilon.minosoft.config.profile.ProfileTestUtil.createProfiles -import de.bixilon.minosoft.data.accounts.types.offline.OfflineAccount +import de.bixilon.minosoft.data.accounts.types.test.TestAccount import de.bixilon.minosoft.data.entities.entities.player.local.LocalPlayerEntity import de.bixilon.minosoft.data.registries.registries.Registries import de.bixilon.minosoft.data.world.WorldTestUtil.createWorld @@ -36,7 +36,7 @@ object ConnectionTestUtil { fun createConnection(worldSize: Int = 0): PlayConnection { val connection = IT.OBJENESIS.newInstance(PlayConnection::class.java) - connection::account.forceSet(OfflineAccount("dummy")) + connection::account.forceSet(TestAccount) connection::version.forceSet(IT.VERSION) connection::registries.forceSet(Registries()) connection.registries.parent = IT.REGISTRIES diff --git a/src/main/java/de/bixilon/minosoft/commands/stack/CommandStackEntry.kt b/src/main/java/de/bixilon/minosoft/commands/stack/CommandStackEntry.kt index 90238eb33..df6c42c6a 100644 --- a/src/main/java/de/bixilon/minosoft/commands/stack/CommandStackEntry.kt +++ b/src/main/java/de/bixilon/minosoft/commands/stack/CommandStackEntry.kt @@ -14,7 +14,7 @@ package de.bixilon.minosoft.commands.stack import de.bixilon.minosoft.data.chat.signature.LastSeenMessageList -import de.bixilon.minosoft.data.chat.signature.MessageChain +import de.bixilon.minosoft.data.chat.signature.signer.MessageSigner import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection import java.security.PrivateKey import java.time.Instant @@ -24,7 +24,7 @@ data class CommandStackEntry( val data: Any?, ) { - fun sign(connection: PlayConnection, chain: MessageChain, key: PrivateKey, salt: Long, time: Instant): ByteArray { - return chain.signMessage(key, data.toString(), null, salt, connection.player.uuid, time, LastSeenMessageList(emptyArray())) + fun sign(connection: PlayConnection, signer: MessageSigner, key: PrivateKey, salt: Long, time: Instant): ByteArray { + return signer.signMessage(key, data.toString(), null, salt, connection.player.uuid, time, LastSeenMessageList(emptyArray())) } } diff --git a/src/main/java/de/bixilon/minosoft/data/chat/signature/signer/MessageSigner1.kt b/src/main/java/de/bixilon/minosoft/data/chat/signature/signer/MessageSigner1.kt index c37cd4e13..59f08df6d 100644 --- a/src/main/java/de/bixilon/minosoft/data/chat/signature/signer/MessageSigner1.kt +++ b/src/main/java/de/bixilon/minosoft/data/chat/signature/signer/MessageSigner1.kt @@ -16,6 +16,7 @@ package de.bixilon.minosoft.data.chat.signature.signer import com.google.common.primitives.Longs import de.bixilon.minosoft.data.chat.signature.LastSeenMessageList import de.bixilon.minosoft.data.chat.signature.signer.MessageSigningUtil.getSignatureBytes +import de.bixilon.minosoft.data.chat.signature.signer.MessageSigningUtil.update import de.bixilon.minosoft.data.text.ChatComponent import de.bixilon.minosoft.protocol.protocol.encryption.CryptManager import de.bixilon.minosoft.protocol.versions.Version @@ -28,13 +29,16 @@ class MessageSigner1( ) : MessageSigner { override fun signMessage(privateKey: PrivateKey, message: String, preview: ChatComponent?, salt: Long, sender: UUID, time: Instant, lastSeen: LastSeenMessageList): ByteArray { + return signMessage(privateKey, message, salt, sender, time) + } + + fun signMessage(privateKey: PrivateKey, message: String, salt: Long, sender: UUID, time: Instant): ByteArray { val signature = CryptManager.createSignature(version) signature.initSign(privateKey) signature.update(Longs.toByteArray(salt)) - signature.update(Longs.toByteArray(sender.mostSignificantBits)) - signature.update(Longs.toByteArray(sender.leastSignificantBits)) + signature.update(sender) signature.update(Longs.toByteArray(time.epochSecond)) signature.update(message.getSignatureBytes()) diff --git a/src/main/java/de/bixilon/minosoft/data/chat/signature/signer/MessageSigner3.kt b/src/main/java/de/bixilon/minosoft/data/chat/signature/signer/MessageSigner3.kt index aa02f6330..74bdbac2e 100644 --- a/src/main/java/de/bixilon/minosoft/data/chat/signature/signer/MessageSigner3.kt +++ b/src/main/java/de/bixilon/minosoft/data/chat/signature/signer/MessageSigner3.kt @@ -19,7 +19,6 @@ import de.bixilon.minosoft.data.chat.signature.LastSeenMessageList import de.bixilon.minosoft.data.chat.signature.signer.MessageSigningUtil.update import de.bixilon.minosoft.data.text.ChatComponent import de.bixilon.minosoft.protocol.ProtocolUtil.encodeNetwork -import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection import de.bixilon.minosoft.protocol.protocol.encryption.CryptManager import de.bixilon.minosoft.protocol.versions.Version import java.security.PrivateKey @@ -29,19 +28,23 @@ import java.util.concurrent.atomic.AtomicInteger class MessageSigner3( private val version: Version, - private val connection: PlayConnection, + private val sessionId: UUID, ) : MessageSigner { private var index = AtomicInteger() override fun signMessage(privateKey: PrivateKey, message: String, preview: ChatComponent?, salt: Long, sender: UUID, time: Instant, lastSeen: LastSeenMessageList): ByteArray { + return signMessage(privateKey, message, salt, sender, time, lastSeen) + } + + fun signMessage(privateKey: PrivateKey, message: String, salt: Long, sender: UUID, time: Instant, lastSeen: LastSeenMessageList): ByteArray { val signature = CryptManager.createSignature(version) signature.initSign(privateKey) signature.update(Ints.toByteArray(1)) - signature.update(connection.account.uuid) - signature.update(connection.sessionId) + signature.update(sender) + signature.update(sessionId) val index = index.getAndIncrement() signature.update(Ints.toByteArray(index))