mirror of
https://github.com/TuxCoding/FastLogin.git
synced 2025-07-29 18:27:36 +02:00
Make profile key optional
This commit is contained in:
@ -148,7 +148,7 @@ class EncryptionUtil {
|
||||
|
||||
public static boolean verifyClientKey(ClientPublicKey clientKey, Instant verifyTimstamp)
|
||||
throws NoSuchAlgorithmException, InvalidKeyException, SignatureException {
|
||||
if (!verifyTimstamp.isBefore(clientKey.expiry())) {
|
||||
if (clientKey.isExpired(verifyTimstamp)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -71,9 +71,10 @@ public class NameCheckTask extends JoinManagement<Player, CommandSender, Protoco
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Optional<WrappedProfileKeyData> clientKey = packetEvent.getPacket().getOptionals(BukkitConverters.getWrappedPublicKeyDataConverter()).read(0);
|
||||
Optional<WrappedProfileKeyData> clientKey = packetEvent.getPacket()
|
||||
.getOptionals(BukkitConverters.getWrappedPublicKeyDataConverter()).read(0);
|
||||
|
||||
super.onLogin(username, new ProtocolLibLoginSource(player, random, clientKey.get(), serverKey));
|
||||
super.onLogin(username, new ProtocolLibLoginSource(player, random, serverKey, clientKey.orElse(null)));
|
||||
} finally {
|
||||
ProtocolLibrary.getProtocolManager().getAsynchronousManager().signalPacketTransmission(packetEvent);
|
||||
}
|
||||
|
@ -31,8 +31,8 @@ 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.BukkitConverters;
|
||||
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;
|
||||
@ -173,7 +173,10 @@ public class ProtocolLibListener extends PacketAdapter {
|
||||
username = (String) packetEvent.getPacket().getMeta("original_name").get();
|
||||
}
|
||||
|
||||
if (!verifyPublicKey(packet)) {
|
||||
PacketContainer packet = packetEvent.getPacket();
|
||||
WrappedProfileKeyData profileKey = packet.getOptionals(BukkitConverters.getWrappedPublicKeyDataConverter())
|
||||
.read(0).orElse(null);
|
||||
if (profileKey != null && !verifyPublicKey(profileKey)) {
|
||||
plugin.getLog().warn("Invalid public key from player {}", username);
|
||||
return;
|
||||
}
|
||||
@ -185,13 +188,7 @@ public class ProtocolLibListener extends PacketAdapter {
|
||||
plugin.getScheduler().runAsync(nameCheckTask);
|
||||
}
|
||||
|
||||
private boolean verifyPublicKey(PacketContainer packet) {
|
||||
WrappedProfileKeyData profileKey = packet.getProfilePublicKeys().optionRead(0)
|
||||
.map(WrappedProfilePublicKey::getKeyData).orElse(null);
|
||||
if (profileKey == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean verifyPublicKey(WrappedProfileKeyData profileKey) {
|
||||
Instant expires = profileKey.getExpireTime();
|
||||
PublicKey key = profileKey.getKey();
|
||||
byte[] signature = profileKey.getSignature();
|
||||
|
@ -55,11 +55,11 @@ class ProtocolLibLoginSource implements LoginSource {
|
||||
private final String serverId = "";
|
||||
private byte[] verifyToken;
|
||||
|
||||
public ProtocolLibLoginSource(Player player, Random random, WrappedProfileKeyData clientPublicKey, PublicKey serverPublicKey) {
|
||||
public ProtocolLibLoginSource(Player player, Random random, PublicKey serverPublicKey, WrappedProfileKeyData clientPublicKey) {
|
||||
this.player = player;
|
||||
this.random = random;
|
||||
this.clientPublicKey = clientPublicKey;
|
||||
this.publicKey = serverPublicKey;
|
||||
this.clientPublicKey = clientPublicKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -30,4 +30,7 @@ import java.time.Instant;
|
||||
|
||||
public record ClientPublicKey(Instant expiry, PublicKey key, byte[] signature) {
|
||||
|
||||
public boolean isExpired(Instant verifyTimestamp) {
|
||||
return verifyTimestamp.isBefore(expiry);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user