From 456342c686482f3531396eff15a5ab1e172616d9 Mon Sep 17 00:00:00 2001 From: games647 Date: Mon, 13 Jun 2022 15:38:08 +0200 Subject: [PATCH] Migrate to ProtocolLib field extractors for better compatibility diff --git a/bukkit/pom.xml b/bukkit/pom.xml index c4caae8..9b3c5c5 100644 --- a/bukkit/pom.xml +++ b/bukkit/pom.xml @@ -183,7 +183,7 @@ com.comphenix.protocol ProtocolLib - 5.0.0-20220603.031413-2 + 5.0.0-SNAPSHOT provided diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java index c9e72fc..3c66e7b 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java @@ -27,12 +27,12 @@ package com.github.games647.fastlogin.bukkit.listener.protocollib; import com.comphenix.protocol.PacketType; import com.comphenix.protocol.ProtocolLibrary; -import com.comphenix.protocol.events.InternalStructure; import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketEvent; -import com.comphenix.protocol.reflect.FuzzyReflection; import com.comphenix.protocol.wrappers.WrappedGameProfile; +import com.comphenix.protocol.wrappers.WrappedProfilePublicKey; +import com.comphenix.protocol.wrappers.WrappedProfilePublicKey.WrappedProfileKeyData; import com.github.games647.fastlogin.bukkit.BukkitLoginSession; import com.github.games647.fastlogin.bukkit.FastLoginBukkit; import com.github.games647.fastlogin.bukkit.listener.protocollib.packet.ClientPublicKey; @@ -47,7 +47,6 @@ import java.security.PublicKey; import java.security.SecureRandom; import java.security.SignatureException; import java.time.Instant; -import java.util.Optional; import org.bukkit.entity.Player; @@ -171,15 +170,15 @@ public class ProtocolLibListener extends PacketAdapter { } private boolean verifyPublicKey(PacketContainer packet) { - Optional internalStructure = packet.getOptionalStructures().readSafely(0); - if (internalStructure == null) { + WrappedProfileKeyData profileKey = packet.getProfilePublicKeys().optionRead(0) + .map(WrappedProfilePublicKey::getKeyData).orElse(null); + if (profileKey == null) { return true; } - Object instance = internalStructure.get().getHandle(); - Instant expires = FuzzyReflection.getFieldValue(instance, Instant.class, true); - PublicKey key = FuzzyReflection.getFieldValue(instance, PublicKey.class, true); - byte[] signature = FuzzyReflection.getFieldValue(instance, byte[].class, true); + Instant expires = profileKey.getExpireTime(); + PublicKey key = profileKey.getKey(); + byte[] signature = profileKey.getSignature(); ClientPublicKey clientKey = new ClientPublicKey(expires, key.getEncoded(), signature); try { return EncryptionUtil.verifyClientKey(clientKey, Instant.now()); --- bukkit/pom.xml | 2 +- .../protocollib/ProtocolLibListener.java | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/bukkit/pom.xml b/bukkit/pom.xml index c4caae89..9b3c5c5d 100644 --- a/bukkit/pom.xml +++ b/bukkit/pom.xml @@ -183,7 +183,7 @@ com.comphenix.protocol ProtocolLib - 5.0.0-20220603.031413-2 + 5.0.0-SNAPSHOT provided diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java index c9e72fc1..3c66e7ba 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java @@ -27,12 +27,12 @@ package com.github.games647.fastlogin.bukkit.listener.protocollib; import com.comphenix.protocol.PacketType; import com.comphenix.protocol.ProtocolLibrary; -import com.comphenix.protocol.events.InternalStructure; import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketEvent; -import com.comphenix.protocol.reflect.FuzzyReflection; import com.comphenix.protocol.wrappers.WrappedGameProfile; +import com.comphenix.protocol.wrappers.WrappedProfilePublicKey; +import com.comphenix.protocol.wrappers.WrappedProfilePublicKey.WrappedProfileKeyData; import com.github.games647.fastlogin.bukkit.BukkitLoginSession; import com.github.games647.fastlogin.bukkit.FastLoginBukkit; import com.github.games647.fastlogin.bukkit.listener.protocollib.packet.ClientPublicKey; @@ -47,7 +47,6 @@ import java.security.PublicKey; import java.security.SecureRandom; import java.security.SignatureException; import java.time.Instant; -import java.util.Optional; import org.bukkit.entity.Player; @@ -171,15 +170,15 @@ public class ProtocolLibListener extends PacketAdapter { } private boolean verifyPublicKey(PacketContainer packet) { - Optional internalStructure = packet.getOptionalStructures().readSafely(0); - if (internalStructure == null) { + WrappedProfileKeyData profileKey = packet.getProfilePublicKeys().optionRead(0) + .map(WrappedProfilePublicKey::getKeyData).orElse(null); + if (profileKey == null) { return true; } - Object instance = internalStructure.get().getHandle(); - Instant expires = FuzzyReflection.getFieldValue(instance, Instant.class, true); - PublicKey key = FuzzyReflection.getFieldValue(instance, PublicKey.class, true); - byte[] signature = FuzzyReflection.getFieldValue(instance, byte[].class, true); + Instant expires = profileKey.getExpireTime(); + PublicKey key = profileKey.getKey(); + byte[] signature = profileKey.getSignature(); ClientPublicKey clientKey = new ClientPublicKey(expires, key.getEncoded(), signature); try { return EncryptionUtil.verifyClientKey(clientKey, Instant.now());