From 18a3877ff087b97144d1a4232a1c73babb6b8056 Mon Sep 17 00:00:00 2001 From: Crasher508 Date: Tue, 18 Jul 2023 10:02:52 +0200 Subject: [PATCH] Update for MCBE 1.20.10 --- README.md | 2 +- .../bedrock/ServerToClientHandshakePacket.java | 17 +++++++++++------ .../bedrock/UpdateAbilitiesPacket.java | 4 ++-- .../java/org/barrelmc/barrel/player/Player.java | 11 +++++------ .../org/barrelmc/barrel/server/ProxyServer.java | 4 ++-- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index f946950..691b1a3 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ - Java 11 - Minecraft: Java Edition v1.19.1/1.19.2 -- Bedrock Edition server v1.20 +- Bedrock Edition server v1.20.10 ## Need implemented diff --git a/src/main/java/org/barrelmc/barrel/network/translator/bedrock/ServerToClientHandshakePacket.java b/src/main/java/org/barrelmc/barrel/network/translator/bedrock/ServerToClientHandshakePacket.java index d571da7..4c4336d 100644 --- a/src/main/java/org/barrelmc/barrel/network/translator/bedrock/ServerToClientHandshakePacket.java +++ b/src/main/java/org/barrelmc/barrel/network/translator/bedrock/ServerToClientHandshakePacket.java @@ -1,14 +1,17 @@ package org.barrelmc.barrel.network.translator.bedrock; -import com.nimbusds.jwt.SignedJWT; import org.cloudburstmc.protocol.bedrock.packet.BedrockPacket; import org.cloudburstmc.protocol.bedrock.packet.ClientToServerHandshakePacket; import org.cloudburstmc.protocol.bedrock.util.EncryptionUtils; import org.barrelmc.barrel.network.translator.interfaces.BedrockPacketTranslator; import org.barrelmc.barrel.player.Player; +import org.cloudburstmc.protocol.bedrock.util.JsonUtils; +import org.jose4j.json.JsonUtil; +import org.jose4j.json.internal.json_simple.JSONObject; +import org.jose4j.jws.JsonWebSignature; +import org.jose4j.jwx.HeaderParameterNames; import javax.crypto.SecretKey; -import java.net.URI; import java.security.interfaces.ECPublicKey; import java.util.Base64; @@ -22,13 +25,15 @@ public boolean immediate() { @Override public void translate(BedrockPacket pk, Player player) { try { - SignedJWT saltJwt = SignedJWT.parse(((org.cloudburstmc.protocol.bedrock.packet.ServerToClientHandshakePacket) pk).getJwt()); - URI x5u = saltJwt.getHeader().getX509CertURL(); - ECPublicKey serverKey = EncryptionUtils.generateKey(x5u.toASCIIString()); + JsonWebSignature jws = new JsonWebSignature(); + jws.setCompactSerialization(((org.cloudburstmc.protocol.bedrock.packet.ServerToClientHandshakePacket) pk).getJwt()); + JSONObject saltJwt = new JSONObject(JsonUtil.parseJson(jws.getUnverifiedPayload())); + String x5u = jws.getHeader(HeaderParameterNames.X509_URL); + ECPublicKey serverKey = EncryptionUtils.parseKey(x5u); SecretKey key = EncryptionUtils.getSecretKey( player.getPrivateKey(), serverKey, - Base64.getDecoder().decode(saltJwt.getJWTClaimsSet().getStringClaim("salt")) + Base64.getDecoder().decode(JsonUtils.childAsType(saltJwt, "salt", String.class)) ); player.getBedrockClientSession().enableEncryption(key); } catch (Exception e) { diff --git a/src/main/java/org/barrelmc/barrel/network/translator/bedrock/UpdateAbilitiesPacket.java b/src/main/java/org/barrelmc/barrel/network/translator/bedrock/UpdateAbilitiesPacket.java index 03401f7..4a6b2b9 100644 --- a/src/main/java/org/barrelmc/barrel/network/translator/bedrock/UpdateAbilitiesPacket.java +++ b/src/main/java/org/barrelmc/barrel/network/translator/bedrock/UpdateAbilitiesPacket.java @@ -23,8 +23,8 @@ public void translate(BedrockPacket pk, Player player) { if (abilityLayer.getLayerType() == AbilityLayer.Type.BASE) { Set abilityValues = abilityLayer.getAbilityValues(); if (abilityValues.contains(Ability.NO_CLIP) && player.getGameMode() == GameType.CREATIVE) { - player.setGameMode(GameType.SURVIVAL_VIEWER); - player.getJavaSession().send(new ClientboundGameEventPacket(GameEvent.CHANGE_GAMEMODE, TranslatorUtils.translateGamemodeToJE(GameType.SURVIVAL_VIEWER))); + player.setGameMode(GameType.SPECTATOR); + player.getJavaSession().send(new ClientboundGameEventPacket(GameEvent.CHANGE_GAMEMODE, TranslatorUtils.translateGamemodeToJE(GameType.SPECTATOR))); } player.getJavaSession().send(new ClientboundPlayerAbilitiesPacket(abilityValues.contains(Ability.INVULNERABLE), abilityValues.contains(Ability.MAY_FLY), abilityValues.contains(Ability.FLYING), abilityValues.contains(Ability.INSTABUILD), 0.05f, 0.1f)); } diff --git a/src/main/java/org/barrelmc/barrel/player/Player.java b/src/main/java/org/barrelmc/barrel/player/Player.java index 14cc5a8..00778ee 100644 --- a/src/main/java/org/barrelmc/barrel/player/Player.java +++ b/src/main/java/org/barrelmc/barrel/player/Player.java @@ -12,7 +12,6 @@ import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.ClientboundSetChunkCacheCenterPacket; import com.github.steveice10.mc.protocol.packet.login.serverbound.ServerboundHelloPacket; import com.github.steveice10.packetlib.Session; -import com.nimbusds.jwt.SignedJWT; import io.netty.bootstrap.Bootstrap; import io.netty.channel.Channel; import io.netty.channel.nio.NioEventLoopGroup; @@ -240,7 +239,7 @@ public LoginPacket getOnlineLoginPacket() throws Exception { jsonArray.add(jwt); jsonArray.addAll(minecraftNetChain); for (int i = 0; i < jsonArray.size(); i++) { - loginPacket.getChain().add(SignedJWT.parse((String) jsonArray.get(i))); + loginPacket.getChain().add((String) jsonArray.get(i)); } } { @@ -256,7 +255,7 @@ public LoginPacket getOnlineLoginPacket() throws Exception { this.UUID = extraData.getString("identity"); } - loginPacket.setExtra(SignedJWT.parse(this.getSkinData())); + loginPacket.setExtra(this.getSkinData()); loginPacket.setProtocolVersion(ProxyServer.getInstance().getBedrockPacketCodec().getProtocolVersion()); return loginPacket; } @@ -293,7 +292,7 @@ protected void initSession(BedrockClientSession session) { ProxyServer.getInstance().getOnlinePlayers().put(javaLoginPacket.getUsername(), this); } - public LoginPacket getLoginPacket() throws Exception { + public LoginPacket getLoginPacket() { LoginPacket loginPacket = new LoginPacket(); KeyPair ecdsa384KeyPair = EncryptionUtils.createKeyPair(); @@ -321,10 +320,10 @@ public LoginPacket getLoginPacket() throws Exception { JSONArray chainDataJsonArray = new JSONArray(); chainDataJsonArray.add(jwt); for (int i = 0; i < chainDataJsonArray.size(); i++) { - loginPacket.getChain().add(SignedJWT.parse((String) chainDataJsonArray.get(i))); + loginPacket.getChain().add((String) chainDataJsonArray.get(i)); } - loginPacket.setExtra(SignedJWT.parse(this.getSkinData())); + loginPacket.setExtra(this.getSkinData()); loginPacket.setProtocolVersion(ProxyServer.getInstance().getBedrockPacketCodec().getProtocolVersion()); return loginPacket; } diff --git a/src/main/java/org/barrelmc/barrel/server/ProxyServer.java b/src/main/java/org/barrelmc/barrel/server/ProxyServer.java index a8b1b8f..b612e7a 100644 --- a/src/main/java/org/barrelmc/barrel/server/ProxyServer.java +++ b/src/main/java/org/barrelmc/barrel/server/ProxyServer.java @@ -33,7 +33,7 @@ import org.barrelmc.barrel.player.Player; import org.barrelmc.barrel.utils.FileManager; import org.cloudburstmc.protocol.bedrock.codec.BedrockCodec; -import org.cloudburstmc.protocol.bedrock.codec.v589.Bedrock_v589; +import org.cloudburstmc.protocol.bedrock.codec.v594.Bedrock_v594; import org.yaml.snakeyaml.Yaml; import java.io.FileInputStream; @@ -54,7 +54,7 @@ public class ProxyServer { @Getter private final Map onlinePlayers = new ConcurrentHashMap<>(); @Getter - private final BedrockCodec bedrockPacketCodec = Bedrock_v589.CODEC; + private final BedrockCodec bedrockPacketCodec = Bedrock_v594.CODEC; @Getter private final Path dataPath;