network: 22w43a

This commit is contained in:
Bixilon 2022-11-06 20:10:25 +01:00
parent 829ebd58da
commit c195ca63d6
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
12 changed files with 90 additions and 20 deletions

View File

@ -67,6 +67,7 @@ class Version(
val maxChatMessageSize get() = if (versionId < ProtocolVersions.V_16W38A) 100 else 256
val hasAttackCooldown get() = versionId >= ProtocolVersions.V_15W34A
val requiresSignedChat get() = versionId >= ProtocolVersions.V_22W17A
val requiresSignedLogin get() = requiresSignedChat && versionId < ProtocolVersions.V_22W43A
val supportsRGBChat get() = versionId >= ProtocolVersions.V_20W17A
val jsonLanguage get() = versionId >= ProtocolVersions.V_18W02A
}

View File

@ -28,18 +28,23 @@ object DefaultPluginHandler {
registerBrand(connection)
}
fun PlayConnection.getBrandChannel(): ResourceLocation {
return DefaultRegistries.DEFAULT_PLUGIN_CHANNELS_REGISTRY.forVersion(version)[DefaultPluginChannels.BRAND]!!.resourceLocation
}
private fun registerBrand(connection: PlayConnection) {
val brandChannel = DefaultRegistries.DEFAULT_PLUGIN_CHANNELS_REGISTRY.forVersion(connection.version)[DefaultPluginChannels.BRAND]!!.resourceLocation
connection.pluginManager[brandChannel] = {
connection.pluginManager[connection.getBrandChannel()] = {
connection.serverInfo.brand = it.readString()
connection.sendBrand(brandChannel, if (connection.profiles.connection.fakeBrand) ProtocolDefinition.VANILLA_BRAND else ProtocolDefinition.MINOSOFT_BRAND)
}
}
private fun PlayConnection.sendBrand(channel: ResourceLocation, brand: String) {
fun PlayConnection.sendBrand(channel: ResourceLocation, brand: String) {
val buffer = PlayOutByteBuffer(this)
buffer.writeByteArray(brand.encodeNetwork())
sendPacket(PluginC2SP(channel, buffer))
}
fun PlayConnection.sendBrand() {
sendBrand(getBrandChannel(), if (profiles.connection.fakeBrand) ProtocolDefinition.VANILLA_BRAND else ProtocolDefinition.MINOSOFT_BRAND)
}
}

View File

@ -35,8 +35,8 @@ class EncryptionC2SP private constructor(
override fun write(buffer: PlayOutByteBuffer) {
buffer.writeByteArray(secret)
if (buffer.versionId < ProtocolVersions.V_22W17A) {
buffer.writeByteArray(nonce.nullCast<ByteArray>() ?: throw IllegalArgumentException("In < 22w17a the nonce must be a bytearray!"))
if (buffer.versionId < ProtocolVersions.V_22W17A || buffer.versionId >= ProtocolVersions.V_22W43A) {
buffer.writeByteArray(nonce.nullCast<ByteArray>() ?: throw IllegalArgumentException("In nonce must be a bytearray!"))
} else {
if (nonce is ByteArray) {
buffer.writeBoolean(true)

View File

@ -36,12 +36,14 @@ class StartC2SP(
override fun write(buffer: PlayOutByteBuffer) {
buffer.writeString(username)
if (buffer.versionId < ProtocolVersions.V_22W43A) {
if (buffer.versionId >= ProtocolVersions.V_22W42A) {
buffer.writeUUID(sessionId)
}
if (buffer.versionId >= ProtocolVersions.V_22W17A) {
buffer.writeOptional(publicKey) { buffer.writePublicKey(it) }
}
}
if (buffer.versionId >= ProtocolVersions.V_1_19_1_PRE2) {
buffer.writeOptional(profileUUID) { buffer.writeUUID(it) }
}

View File

@ -0,0 +1,38 @@
/*
* Minosoft
* Copyright (C) 2020-2022 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 <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.protocol.packets.c2s.play
import de.bixilon.minosoft.protocol.PlayerPublicKey
import de.bixilon.minosoft.protocol.packets.c2s.PlayC2SPacket
import de.bixilon.minosoft.protocol.packets.factory.LoadPacket
import de.bixilon.minosoft.protocol.protocol.PlayOutByteBuffer
import de.bixilon.minosoft.util.logging.Log
import de.bixilon.minosoft.util.logging.LogLevels
import de.bixilon.minosoft.util.logging.LogMessageType
import java.util.*
@LoadPacket
class SessionDataC2SP(
val sessionId: UUID,
val publicKey: PlayerPublicKey,
) : PlayC2SPacket {
override fun write(buffer: PlayOutByteBuffer) {
buffer.writeUUID(sessionId)
buffer.writePublicKey(publicKey)
}
override fun log(reducedLog: Boolean) {
Log.log(LogMessageType.NETWORK_PACKETS_OUT, LogLevels.VERBOSE) { "Session data (sessionId=$sessionId, publicKey=$publicKey)" }
}
}

View File

@ -48,7 +48,7 @@ class EncryptionS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
val encryptedSecretKey = CryptManager.encryptData(publicKey, secretKey.encoded)
val privateKey = connection.player.privateKey
if (connection.version.requiresSignedChat && privateKey != null) {
if (connection.version.requiresSignedLogin && privateKey != null) {
val salt = SecureRandom().nextLong()
val signature = CryptManager.createSignature(connection.version)

View File

@ -25,6 +25,8 @@ import de.bixilon.minosoft.protocol.PacketErrorHandler
import de.bixilon.minosoft.protocol.network.connection.Connection
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnectionStates
import de.bixilon.minosoft.protocol.network.connection.play.plugin.DefaultPluginHandler.sendBrand
import de.bixilon.minosoft.protocol.packets.c2s.play.SessionDataC2SP
import de.bixilon.minosoft.protocol.packets.factory.LoadPacket
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
@ -166,6 +168,12 @@ class InitializeS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
connection.world.border.reset()
connection.settingsManager.sendClientSettings()
connection.sendBrand()
val publicKey = connection.player.privateKey?.playerKey
if (publicKey != null && connection.network.encrypted && connection.version.versionId >= ProtocolVersions.V_22W43A) {
connection.sendPacket(SessionDataC2SP(connection.sessionId, publicKey))
}
connection.state = PlayConnectionStates.SPAWNING
}

View File

@ -15,10 +15,11 @@ package de.bixilon.minosoft.protocol.packets.s2c.play.tab.actions
import de.bixilon.minosoft.data.entities.entities.player.additional.AdditionalDataUpdate
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
object ChatAction : AbstractAction {
override fun read(buffer: PlayInByteBuffer, entry: AdditionalDataUpdate) {
entry.publicKey = buffer.readPlayerPublicKey()
entry.publicKey = if (buffer.versionId >= ProtocolVersions.V_22W43A) buffer.readOptional { buffer.readPlayerPublicKey() } else buffer.readPlayerPublicKey()
}
}

View File

@ -360,15 +360,21 @@ class PlayInByteBuffer : InByteBuffer {
return readByteArray(ChatSignatureProperties.SIGNATURE_SIZE)
}
private fun _readPlayerPublicKey(): PlayerPublicKey {
return PlayerPublicKey(readInstant(), CryptManager.getPlayerPublicKey(readByteArray()), readByteArray())
}
fun readPlayerPublicKey(): PlayerPublicKey? {
if (versionId <= ProtocolVersions.V_22W18A) { // ToDo: find version
return readNBT()?.let { PlayerPublicKey(it.asJsonObject()) }
}
if (versionId < ProtocolVersions.V_22W42A) {
return readOptional { PlayerPublicKey(readInstant(), CryptManager.getPlayerPublicKey(readByteArray()), readByteArray()) }
}
if (versionId > ProtocolVersions.V_22W42A) {
val uuid = readUUID()
return readOptional { PlayerPublicKey(readInstant(), CryptManager.getPlayerPublicKey(readByteArray()), readByteArray()) }
}
if (versionId < ProtocolVersions.V_22W43A) {
return readOptional { _readPlayerPublicKey() }
}
return _readPlayerPublicKey()
}
fun readMessageHeader(): MessageHeader {

View File

@ -14,6 +14,7 @@ package de.bixilon.minosoft.protocol.protocol
@Suppress("UNUSED")
object ProtocolVersions {
const val V_22W43A = 864
const val V_22W42A = 863
const val V_1_19_2 = 862
const val V_1_19_2_RC2 = 861

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,12 @@
{
"864": {
"name": "22w43a",
"protocol_id": 1073741929,
"packets": {
"c2s": ["confirm_teleport", "block_nbt", "difficulty", "message_acknowledgement", "command", "signed_chat_message", "client_action", "settings", "command_suggestions", "container_button", "container_click", "close_container", "plugin", "book", "entity_nbt", "entity_interact", "generate_structure", "heartbeat", "lock_difficulty", "position", "position_rotation", "rotation", "ground_change", "move_vehicle", "steer_boat", "item_pick", "crafting_recipe", "toggle_fly", "player_action", "entity_action", "steer_vehicle", "pong", "session_data", "displayed_recipe", "recipe_book", "anvil_item_name", "resourcepack", "advancement_tab", "trade", "beacon_effect", "hotbar_slot", "command_block", "minecart_command_block", "item_stack_create", "jigsaw_block", "structure_block", "sign_text", "swing_arm", "entity_spectate", "block_interact", "use_item"],
"s2c": ["entity_object_spawn", "entity_experience_orb", "entity_player", "entity_animation", "statistics", "block_break", "block_break_animation", "block_data", "block_action", "block", "bossbar", "difficulty", "clear_title", "command_suggestions", "commands", "close_container", "container_items", "container_properties", "container_item", "item_cooldown", "chat_suggestions", "plugin", "named_sound", "hide_message", "kick", "unsigned_chat_message", "entity_status", "explosion", "unload_chunk", "game_event", "open_horse_container", "initialize_world_border", "heartbeat", "chunk", "world_event", "particle", "chunk_light", "initialize", "map", "villager_trades", "relative_move", "movement_rotation", "rotation", "move_vehicle", "book", "open_container", "sign_editor", "ping", "crafting_recipe", "player_abilities", "signed_chat_message", "end_combat_event", "enter_combat_event", "kill_combat_event", "tab_list_remove", "tab_list", "player_face", "position_rotation", "unlock_recipes", "entity_destroy", "entity_remove_effect", "resourcepack", "respawn", "head_rotation", "blocks", "advancement_tab", "play_status", "hotbar_text", "center_world_border", "interpolate_world_border", "size_world_border", "warn_time_world_border", "warn_blocks_world_border", "camera", "hotbar_slot", "chunk_center", "view_distance", "compass_position", "objective_position", "entity_data", "entity_attach", "velocity", "entity_equipment", "experience", "health", "objective", "entity_passenger", "teams", "scoreboard_score", "simulation_distance", "subtitle", "time", "title_text", "title_times", "entity_sound", "sound_event", "stop_sound", "chat_message", "tab_list_text", "nbt_response", "entity_collect", "teleport", "advancements", "entity_attributes", "features", "entity_effect", "recipes", "tags"]
}
},
"863": {
"name": "22w42a",
"protocol_id": 1073741928,