From 2bd339b0bfe37d8825ed17c0d74ee35512d48590 Mon Sep 17 00:00:00 2001 From: games647 Date: Mon, 25 May 2020 13:20:34 +0200 Subject: [PATCH] Use username from Mojang for offline IDs Affected systems: BungeeCord after name change Effects: Carry on items, permissions, etc. from the old user account without access to the new one After a name change it could happen that the client still only knows the old username and will send it to the server. Mojang will provide us with an up-to-date username that we should use instead. The username is also sent to Mojang, so that they could verify the use. Therefore exploiting this behavior extensively for arbitrary usernames is not possible. Related #344 --- .../protocollib/VerifyResponseTask.java | 18 ++++++--- .../ProtocolSupportListener.java | 3 -- .../fastlogin/bukkit/task/ForceLoginTask.java | 12 +++--- .../bungee/listener/ConnectListener.java | 15 ++++---- .../fastlogin/core/shared/LoginSession.java | 37 ++++++++++++------- 5 files changed, 51 insertions(+), 34 deletions(-) diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/VerifyResponseTask.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/VerifyResponseTask.java index 6ad02bdd..e60dd253 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/VerifyResponseTask.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/VerifyResponseTask.java @@ -94,30 +94,36 @@ public class VerifyResponseTask implements Runnable { String serverId = EncryptionUtil.getServerIdHashString("", loginKey, serverKey.getPublic()); - String username = session.getUsername(); + String requestedUsername = session.getRequestUsername(); InetSocketAddress socketAddress = player.getAddress(); try { MojangResolver resolver = plugin.getCore().getResolver(); InetAddress address = socketAddress.getAddress(); - Optional response = resolver.hasJoined(username, serverId, address); + Optional response = resolver.hasJoined(requestedUsername, serverId, address); if (response.isPresent()) { - plugin.getLog().info("GameProfile {} has a verified premium account", username); + plugin.getLog().info("GameProfile {} has a verified premium account", requestedUsername); + String realUsername = response.get().getName(); + if (realUsername == null) { + disconnect("invalid-session", true, "Username field null for {}", requestedUsername); + return; + } SkinProperty[] properties = response.get().getProperties(); if (properties.length > 0) { session.setSkinProperty(properties[0]); } + session.setVerifiedUsername(realUsername); session.setUuid(response.get().getId()); session.setVerified(true); setPremiumUUID(session.getUuid()); - receiveFakeStartPacket(username); + receiveFakeStartPacket(realUsername); } else { //user tried to fake a authentication disconnect("invalid-session", true , "GameProfile {0} ({1}) tried to log in with an invalid session ServerId: {2}" - , session.getUsername(), socketAddress, serverId); + , session.getRequestUsername(), socketAddress, serverId); } } catch (IOException ioEx) { disconnect("error-kick", false, "Failed to connect to session server", ioEx); @@ -146,7 +152,7 @@ public class VerifyResponseTask implements Runnable { //check if the verify token are equal to the server sent one disconnect("invalid-verify-token", true , "GameProfile {0} ({1}) tried to login with an invalid verify token. Server: {2} Client: {3}" - , session.getUsername(), packetEvent.getPlayer().getAddress(), requestVerify, responseVerify); + , session.getRequestUsername(), packetEvent.getPlayer().getAddress(), requestVerify, responseVerify); return false; } diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocolsupport/ProtocolSupportListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocolsupport/ProtocolSupportListener.java index 5dc3a74b..0e52b159 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocolsupport/ProtocolSupportListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocolsupport/ProtocolSupportListener.java @@ -92,9 +92,6 @@ public class ProtocolSupportListener extends JoinManagement