mirror of
https://github.com/TuxCoding/FastLogin.git
synced 2025-07-30 10:47:33 +02:00
Forward client key even if verification is disabled
This commit is contained in:
@ -34,7 +34,6 @@ import com.comphenix.protocol.reflect.FuzzyReflection;
|
|||||||
import com.comphenix.protocol.utility.MinecraftVersion;
|
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||||
import com.comphenix.protocol.wrappers.BukkitConverters;
|
import com.comphenix.protocol.wrappers.BukkitConverters;
|
||||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||||
import com.comphenix.protocol.wrappers.WrappedProfilePublicKey.WrappedProfileKeyData;
|
|
||||||
import com.github.games647.fastlogin.bukkit.BukkitLoginSession;
|
import com.github.games647.fastlogin.bukkit.BukkitLoginSession;
|
||||||
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
|
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
|
||||||
import com.github.games647.fastlogin.bukkit.listener.protocollib.packet.ClientPublicKey;
|
import com.github.games647.fastlogin.bukkit.listener.protocollib.packet.ClientPublicKey;
|
||||||
@ -51,12 +50,13 @@ import java.security.SecureRandom;
|
|||||||
import java.security.SignatureException;
|
import java.security.SignatureException;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
import javax.crypto.BadPaddingException;
|
import javax.crypto.BadPaddingException;
|
||||||
import javax.crypto.IllegalBlockSizeException;
|
import javax.crypto.IllegalBlockSizeException;
|
||||||
import javax.crypto.NoSuchPaddingException;
|
import javax.crypto.NoSuchPaddingException;
|
||||||
|
|
||||||
import lombok.var;
|
import lombok.val;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import static com.comphenix.protocol.PacketType.Login.Client.ENCRYPTION_BEGIN;
|
import static com.comphenix.protocol.PacketType.Login.Client.ENCRYPTION_BEGIN;
|
||||||
@ -205,11 +205,17 @@ public class ProtocolLibListener extends PacketAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PacketContainer packet = packetEvent.getPacket();
|
PacketContainer packet = packetEvent.getPacket();
|
||||||
var profileKey = packet.getOptionals(BukkitConverters.getWrappedPublicKeyDataConverter())
|
val profileKey = packet.getOptionals(BukkitConverters.getWrappedPublicKeyDataConverter())
|
||||||
.optionRead(0);
|
.optionRead(0);
|
||||||
|
|
||||||
var clientKey = profileKey.flatMap(opt -> opt).flatMap(this::verifyPublicKey);
|
val clientKey = profileKey.flatMap(Function.identity()).flatMap(data -> {
|
||||||
if (verifyClientKeys && !clientKey.isPresent()) {
|
Instant expires = data.getExpireTime();
|
||||||
|
PublicKey key = data.getKey();
|
||||||
|
byte[] signature = data.getSignature();
|
||||||
|
return Optional.of(ClientPublicKey.of(expires, key, signature));
|
||||||
|
});
|
||||||
|
|
||||||
|
if (verifyClientKeys && clientKey.isPresent() && verifyPublicKey(clientKey.get())) {
|
||||||
// missing or incorrect
|
// missing or incorrect
|
||||||
// expired always not allowed
|
// expired always not allowed
|
||||||
player.kickPlayer(plugin.getCore().getMessage("invalid-public-key"));
|
player.kickPlayer(plugin.getCore().getMessage("invalid-public-key"));
|
||||||
@ -226,20 +232,12 @@ public class ProtocolLibListener extends PacketAdapter {
|
|||||||
plugin.getScheduler().runAsync(nameCheckTask);
|
plugin.getScheduler().runAsync(nameCheckTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<ClientPublicKey> verifyPublicKey(WrappedProfileKeyData profileKey) {
|
private boolean verifyPublicKey(ClientPublicKey clientKey) {
|
||||||
Instant expires = profileKey.getExpireTime();
|
|
||||||
PublicKey key = profileKey.getKey();
|
|
||||||
byte[] signature = profileKey.getSignature();
|
|
||||||
ClientPublicKey clientKey = ClientPublicKey.of(expires, key, signature);
|
|
||||||
try {
|
try {
|
||||||
if (EncryptionUtil.verifyClientKey(clientKey, Instant.now())) {
|
return EncryptionUtil.verifyClientKey(clientKey, Instant.now());
|
||||||
return Optional.of(clientKey);
|
|
||||||
}
|
|
||||||
} catch (SignatureException | InvalidKeyException | NoSuchAlgorithmException ex) {
|
} catch (SignatureException | InvalidKeyException | NoSuchAlgorithmException ex) {
|
||||||
return Optional.empty();
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getUsername(PacketContainer packet) {
|
private String getUsername(PacketContainer packet) {
|
||||||
|
Reference in New Issue
Block a user