Skip to content

Commit

Permalink
Update for MCBE 1.20.10
Browse files Browse the repository at this point in the history
  • Loading branch information
Crasher508 committed Jul 18, 2023
1 parent bab8c15 commit 18a3877
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public void translate(BedrockPacket pk, Player player) {
if (abilityLayer.getLayerType() == AbilityLayer.Type.BASE) {
Set<Ability> 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));
}
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/org/barrelmc/barrel/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}
{
Expand All @@ -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;
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/barrelmc/barrel/server/ProxyServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -54,7 +54,7 @@ public class ProxyServer {
@Getter
private final Map<String, Player> onlinePlayers = new ConcurrentHashMap<>();
@Getter
private final BedrockCodec bedrockPacketCodec = Bedrock_v589.CODEC;
private final BedrockCodec bedrockPacketCodec = Bedrock_v594.CODEC;

@Getter
private final Path dataPath;
Expand Down

0 comments on commit 18a3877

Please sign in to comment.