Compare commits

...

1 Commits

Author SHA1 Message Date
5676e99dec Require player re-join to confirm auto-login request
Fixes #159
Fixes #242
Fixes #256
Fixes #286
2020-03-20 16:06:42 +01:00
18 changed files with 192 additions and 68 deletions

View File

@ -30,6 +30,14 @@ public class BukkitLoginSession extends LoginSession {
this.verifyToken = verifyToken.clone();
}
public BukkitLoginSession(String username, String serverId, byte[] verifyToken, StoredProfile profile) {
// confirmation login
super(username, profile);
this.serverId = serverId;
this.verifyToken = verifyToken.clone();
}
//available for BungeeCord
public BukkitLoginSession(String username, boolean registered) {
this(username, "", EMPTY_ARRAY, registered, null);

View File

@ -1,10 +1,9 @@
package com.github.games647.fastlogin.bukkit.command;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.core.ConfirmationState;
import com.github.games647.fastlogin.core.StoredProfile;
import java.util.UUID;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -36,31 +35,44 @@ public class PremiumCommand extends ToggleCommand {
return;
}
if (forwardPremiumCommand(sender, sender.getName())) {
Player player = (Player) sender;
String playerName = sender.getName();
if (forwardPremiumCommand(sender, playerName)) {
return;
}
UUID id = ((Player) sender).getUniqueId();
if (plugin.getConfig().getBoolean("premium-warning") && !plugin.getCore().getPendingConfirms().contains(id)) {
sender.sendMessage(plugin.getCore().getMessage("premium-warning"));
plugin.getCore().getPendingConfirms().add(id);
return;
// non-bungee mode
if (plugin.getConfig().getBoolean("premium-confirm")) {
ConfirmationState state = plugin.getCore().getPendingConfirms().get(playerName);
if (state == null) {
// no pending confirmation
plugin.getCore().getPendingConfirms().put(playerName, ConfirmationState.REQUIRE_RELOGIN);
player.kickPlayer(plugin.getCore().getMessage("premium-confirm"));
} else if (state == ConfirmationState.REQUIRE_AUTH_PLUGIN_LOGIN) {
// player logged in successful using premium authentication
activate(sender, playerName);
}
} else {
activate(sender, playerName);
}
}
plugin.getCore().getPendingConfirms().remove(id);
//todo: load async
StoredProfile profile = plugin.getCore().getStorage().loadProfile(sender.getName());
if (profile.isPremium()) {
plugin.getCore().sendLocaleMessage("already-exists", sender);
} else {
//todo: resolve uuid
profile.setPremium(true);
plugin.getScheduler().runAsync(() -> {
plugin.getCore().getStorage().save(profile);
});
private void activate(CommandSender sender, String playerName) {
plugin.getCore().getPendingConfirms().remove(playerName);
plugin.getCore().sendLocaleMessage("add-premium", sender);
}
//todo: load async
StoredProfile profile = plugin.getCore().getStorage().loadProfile(playerName);
if (profile.isPremium()) {
plugin.getCore().sendLocaleMessage("already-exists", sender);
} else {
//todo: resolve uuid
profile.setPremium(true);
plugin.getScheduler().runAsync(() -> {
plugin.getCore().getStorage().save(profile);
});
plugin.getCore().sendLocaleMessage("add-premium", sender);
}
}
private void onPremiumOther(CommandSender sender, Command command, String[] args) {

View File

@ -51,7 +51,6 @@ public class ConnectionListener implements Listener {
Player player = quitEvent.getPlayer();
removeBlacklistStatus(player);
plugin.getCore().getPendingConfirms().remove(player.getUniqueId());
plugin.getPremiumPlayers().remove(player.getUniqueId());
}

View File

@ -7,11 +7,11 @@ import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.bukkit.event.BukkitFastLoginPreLoginEvent;
import com.github.games647.fastlogin.core.StoredProfile;
import com.github.games647.fastlogin.core.shared.JoinManagement;
import com.github.games647.fastlogin.core.shared.event.FastLoginPreLoginEvent;
import java.security.PublicKey;
import java.util.Random;
import com.github.games647.fastlogin.core.shared.event.FastLoginPreLoginEvent;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -81,6 +81,26 @@ public class NameCheckTask extends JoinManagement<Player, CommandSender, Protoco
}
}
@Override
public void requestConfirmationLogin(ProtocolLibLoginSource source, StoredProfile profile, String username) {
try {
source.setOnlineMode();
} catch (Exception ex) {
plugin.getLog().error("Cannot send encryption packet. Falling back to cracked login for: {}", profile, ex);
return;
}
String serverId = source.getServerId();
byte[] verify = source.getVerifyToken();
BukkitLoginSession playerSession = new BukkitLoginSession(username, serverId, verify, profile);
plugin.getLoginSessions().put(player.getAddress().toString(), playerSession);
//cancel only if the player has a paid account otherwise login as normal offline player
synchronized (packetEvent.getAsyncMarker().getProcessingLock()) {
packetEvent.setCancelled(true);
}
}
@Override
public void startCrackedSession(ProtocolLibLoginSource source, StoredProfile profile, String username) {
BukkitLoginSession loginSession = new BukkitLoginSession(username, profile);

View File

@ -29,10 +29,6 @@ public class ProtocolLoginSource implements LoginSource {
return loginStartEvent.getAddress();
}
public PlayerLoginStartEvent getLoginStartEvent() {
return loginStartEvent;
}
@Override
public String toString() {
return this.getClass().getSimpleName() + '{' +

View File

@ -6,11 +6,11 @@ import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.bukkit.event.BukkitFastLoginPreLoginEvent;
import com.github.games647.fastlogin.core.StoredProfile;
import com.github.games647.fastlogin.core.shared.JoinManagement;
import com.github.games647.fastlogin.core.shared.event.FastLoginPreLoginEvent;
import java.net.InetSocketAddress;
import java.util.Optional;
import com.github.games647.fastlogin.core.shared.event.FastLoginPreLoginEvent;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -84,9 +84,14 @@ public class ProtocolSupportListener extends JoinManagement<Player, CommandSende
BukkitLoginSession playerSession = new BukkitLoginSession(username, registered, profile);
plugin.getLoginSessions().put(source.getAddress().toString(), playerSession);
if (plugin.getConfig().getBoolean("premiumUuid")) {
source.getLoginStartEvent().setOnlineMode(true);
}
}
@Override
public void requestConfirmationLogin(ProtocolLoginSource source, StoredProfile profile, String username) {
source.setOnlineMode();
BukkitLoginSession playerSession = new BukkitLoginSession(username, profile);
plugin.getLoginSessions().put(source.getAddress().toString(), playerSession);
}
@Override

View File

@ -12,6 +12,10 @@ public class BungeeLoginSession extends LoginSession {
super(username, registered, profile);
}
public BungeeLoginSession(String username, StoredProfile profile) {
super(username, profile);
}
public synchronized void setRegistered(boolean registered) {
this.registered = registered;
}
@ -22,6 +26,7 @@ public class BungeeLoginSession extends LoginSession {
public synchronized void setAlreadySaved(boolean alreadySaved) {
this.alreadySaved = alreadySaved;
this.confirmationLogin = false;
}
public synchronized boolean isAlreadyLogged() {

View File

@ -4,6 +4,7 @@ import com.github.games647.craftapi.UUIDAdapter;
import com.github.games647.fastlogin.bungee.FastLoginBungee;
import com.github.games647.fastlogin.bungee.task.AsyncPremiumCheck;
import com.github.games647.fastlogin.bungee.task.ForceLoginTask;
import com.github.games647.fastlogin.core.ConfirmationState;
import com.github.games647.fastlogin.core.StoredProfile;
import com.github.games647.fastlogin.core.shared.LoginSession;
@ -107,6 +108,6 @@ public class ConnectListener implements Listener {
public void onDisconnect(PlayerDisconnectEvent disconnectEvent) {
ProxiedPlayer player = disconnectEvent.getPlayer();
plugin.getSession().remove(player.getPendingConnection());
plugin.getCore().getPendingConfirms().remove(player.getUniqueId());
plugin.getCore().getPendingConfirms().remove(player.getName(), ConfirmationState.REQUIRE_AUTH_PLUGIN_LOGIN);
}
}

View File

@ -3,6 +3,7 @@ package com.github.games647.fastlogin.bungee.listener;
import com.github.games647.fastlogin.bungee.BungeeLoginSession;
import com.github.games647.fastlogin.bungee.FastLoginBungee;
import com.github.games647.fastlogin.bungee.task.AsyncToggleMessage;
import com.github.games647.fastlogin.core.ConfirmationState;
import com.github.games647.fastlogin.core.StoredProfile;
import com.github.games647.fastlogin.core.message.ChangePremiumMessage;
import com.github.games647.fastlogin.core.message.NamespaceKey;
@ -14,7 +15,6 @@ import com.google.common.io.ByteStreams;
import java.util.Arrays;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.connection.Server;
import net.md_5.bungee.api.event.PluginMessageEvent;
@ -58,37 +58,54 @@ public class PluginMessageListener implements Listener {
plugin.getScheduler().runAsync(() -> readMessage(forPlayer, channel, data));
}
private void readMessage(ProxiedPlayer forPlayer, String channel, byte[] data) {
FastLoginCore<ProxiedPlayer, CommandSender, FastLoginBungee> core = plugin.getCore();
private void readMessage(ProxiedPlayer fromPlayer, String channel, byte[] data) {
ByteArrayDataInput dataInput = ByteStreams.newDataInput(data);
if (successChannel.equals(channel)) {
onSuccessMessage(forPlayer);
onSuccessMessage(fromPlayer);
} else if (changeChannel.equals(channel)) {
ChangePremiumMessage changeMessage = new ChangePremiumMessage();
changeMessage.readFrom(dataInput);
String playerName = changeMessage.getPlayerName();
boolean isSourceInvoker = changeMessage.isSourceInvoker();
if (changeMessage.shouldEnable()) {
if (playerName.equals(forPlayer.getName()) && plugin.getCore().getConfig().get("premium-warning", true)
&& !core.getPendingConfirms().contains(forPlayer.getUniqueId())) {
String message = core.getMessage("premium-warning");
forPlayer.sendMessage(TextComponent.fromLegacyText(message));
core.getPendingConfirms().add(forPlayer.getUniqueId());
return;
}
core.getPendingConfirms().remove(forPlayer.getUniqueId());
Runnable task = new AsyncToggleMessage(core, forPlayer, playerName, true, isSourceInvoker);
plugin.getScheduler().runAsync(task);
} else {
Runnable task = new AsyncToggleMessage(core, forPlayer, playerName, false, isSourceInvoker);
plugin.getScheduler().runAsync(task);
}
onChangeMessage(fromPlayer, changeMessage.shouldEnable(), playerName, isSourceInvoker);
}
}
private void onChangeMessage(ProxiedPlayer fromPlayer, boolean shouldEnable, String playerName, boolean isSourceInvoker) {
FastLoginCore<ProxiedPlayer, CommandSender, FastLoginBungee> core = plugin.getCore();
if (shouldEnable) {
if (!isSourceInvoker) {
// fromPlayer is not the target player
activePremiumLogin(fromPlayer, playerName, false);
return;
}
if (plugin.getCore().getConfig().getBoolean("premium-confirm", true)) {
ConfirmationState state = plugin.getCore().getPendingConfirms().get(playerName);
if (state == null) {
// no pending confirmation
core.sendLocaleMessage("premium-confirm", fromPlayer);
core.getPendingConfirms().put(playerName, ConfirmationState.REQUIRE_RELOGIN);
} else if (state == ConfirmationState.REQUIRE_AUTH_PLUGIN_LOGIN) {
// player logged in successful using premium authentication
activePremiumLogin(fromPlayer, playerName, true);
}
} else {
activePremiumLogin(fromPlayer, playerName, true);
}
} else {
Runnable task = new AsyncToggleMessage(core, fromPlayer, playerName, false, isSourceInvoker);
plugin.getScheduler().runAsync(task);
}
}
private void activePremiumLogin(ProxiedPlayer fromPlayer, String playerName, boolean isSourceInvoker) {
plugin.getCore().getPendingConfirms().remove(playerName);
Runnable task = new AsyncToggleMessage(plugin.getCore(), fromPlayer, playerName, true, isSourceInvoker);
plugin.getScheduler().runAsync(task);
}
private void onSuccessMessage(ProxiedPlayer forPlayer) {
if (forPlayer.getPendingConnection().isOnlineMode()) {
//bukkit module successfully received and force logged in the user
@ -98,9 +115,12 @@ public class PluginMessageListener implements Listener {
loginSession.setRegistered(true);
if (!loginSession.isAlreadySaved()) {
playerProfile.setPremium(true);
plugin.getCore().getStorage().save(playerProfile);
loginSession.setAlreadySaved(true);
playerProfile.setId(loginSession.getUuid());
playerProfile.setPremium(true);
plugin.getCore().getStorage().save(playerProfile);
}
}
}

View File

@ -60,6 +60,12 @@ public class AsyncPremiumCheck extends JoinManagement<ProxiedPlayer, CommandSend
plugin.getCore().getPendingLogin().put(ip + username, new Object());
}
@Override
public void requestConfirmationLogin(BungeeLoginSource source, StoredProfile profile, String username) {
source.setOnlineMode();
plugin.getSession().put(source.getConnection(), new BungeeLoginSession(username, profile));
}
@Override
public void startCrackedSession(BungeeLoginSource source, StoredProfile profile, String username) {
plugin.getSession().put(source.getConnection(), new BungeeLoginSession(username, false, profile));

View File

@ -0,0 +1,15 @@
package com.github.games647.fastlogin.core;
public enum ConfirmationState {
/**
* Require server login where we request onlinemode authentication
*/
REQUIRE_RELOGIN,
/**
* The command have to be invoked again to confirm that the player who joined through onlinemode knows
* the password of the cracked account
*/
REQUIRE_AUTH_PLUGIN_LOGIN
}

View File

@ -29,6 +29,9 @@ public class ChangePremiumMessage implements ChannelMessage {
return willEnable;
}
/**
* @return true if the player invoker = target
*/
public boolean isSourceInvoker() {
return isSourceInvoker;
}

View File

@ -4,6 +4,7 @@ import com.github.games647.craftapi.resolver.MojangResolver;
import com.github.games647.craftapi.resolver.http.RotatingProxySelector;
import com.github.games647.fastlogin.core.AuthStorage;
import com.github.games647.fastlogin.core.CommonUtil;
import com.github.games647.fastlogin.core.ConfirmationState;
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
import com.github.games647.fastlogin.core.hooks.DefaultPasswordGenerator;
import com.github.games647.fastlogin.core.hooks.PasswordGenerator;
@ -24,7 +25,6 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@ -47,7 +47,7 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
private final Map<String, String> localeMessages = new ConcurrentHashMap<>();
private final ConcurrentMap<String, Object> pendingLogin = CommonUtil.buildCache(5, -1);
private final Collection<UUID> pendingConfirms = new HashSet<>();
private final ConcurrentMap<String, ConfirmationState> pendingConfirms = CommonUtil.buildCache(1, 1024);
private final T plugin;
private final MojangResolver resolver = new MojangResolver();
@ -204,11 +204,18 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
this.passwordGenerator = passwordGenerator;
}
/**
* @return list of player names that are currently during the login process and might fail and so could be used
* for second attempt logins
*/
public ConcurrentMap<String, Object> getPendingLogin() {
return pendingLogin;
}
public Collection<UUID> getPendingConfirms() {
/**
* @return list of player names that request onlinemode authentication but are not yet approved
*/
public ConcurrentMap<String, ConfirmationState> getPendingConfirms() {
return pendingConfirms;
}

View File

@ -28,10 +28,16 @@ public abstract class ForceLoginManagement<P extends C, C, L extends LoginSessio
StoredProfile playerProfile = session.getProfile();
try {
if (isOnlineMode()) {
if (session.isConfirmationPending()) {
// do not perform force actions, because this confirmation login we have to verify that it's the
// owner of the account
return;
}
//premium player
AuthPlugin<P> authPlugin = core.getAuthPluginHook();
if (authPlugin == null) {
//maybe only bungeecord plugin
//maybe only bungeecord plugin without any auth plugins on Bungee
onForceActionSuccess(session);
} else {
boolean success = true;

View File

@ -2,6 +2,7 @@ package com.github.games647.fastlogin.core.shared;
import com.github.games647.craftapi.model.Profile;
import com.github.games647.craftapi.resolver.RateLimitException;
import com.github.games647.fastlogin.core.ConfirmationState;
import com.github.games647.fastlogin.core.StoredProfile;
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
import com.github.games647.fastlogin.core.shared.event.FastLoginPreLoginEvent;
@ -37,7 +38,14 @@ public abstract class JoinManagement<P extends C, C, S extends LoginSource> {
if (profile.isPremium()) {
requestPremiumLogin(source, profile, username, true);
} else {
startCrackedSession(source, profile, username);
ConfirmationState confirmationState = core.getPendingConfirms().get(username);
if (confirmationState == ConfirmationState.REQUIRE_RELOGIN) {
core.getPendingConfirms().put(username, ConfirmationState.REQUIRE_AUTH_PLUGIN_LOGIN);
requestPremiumLogin(source, profile, username, true);
} else {
// cracked player, but wants to change to premium
startCrackedSession(source, profile, username);
}
}
} else {
if (core.getPendingLogin().remove(ip + username) != null && config.get("secondAttemptCracked", false)) {
@ -108,5 +116,7 @@ public abstract class JoinManagement<P extends C, C, S extends LoginSource> {
public abstract void requestPremiumLogin(S source, StoredProfile profile, String username, boolean registered);
public abstract void requestConfirmationLogin(S source, StoredProfile profile, String username);
public abstract void startCrackedSession(S source, StoredProfile profile, String username);
}

View File

@ -13,12 +13,19 @@ public abstract class LoginSession {
protected boolean registered;
protected boolean confirmationLogin;
public LoginSession(String username, boolean registered, StoredProfile profile) {
this.username = username;
this.registered = registered;
this.profile = profile;
}
public LoginSession(String username, StoredProfile profile) {
this(username, true, profile);
this.confirmationLogin = true;
}
public String getUsername() {
return username;
}
@ -54,6 +61,10 @@ public abstract class LoginSession {
this.uuid = uuid;
}
public synchronized boolean isConfirmationPending() {
return confirmationLogin;
}
@Override
public synchronized String toString() {
return this.getClass().getSimpleName() + '{' +

View File

@ -115,11 +115,11 @@ nameChangeCheck: false
# ChangeSkin, SkinRestorer, ...
forwardSkin: true
# Displays a warning message that this message SHOULD only be invoked by
# users who actually are the owner of this account. So not by cracked players
#
# If they still want to invoke the command, they have to invoke /premium again
premium-warning: true
# Players have to rejoin to verify that they can join through onlinemode authentication.
# After that they have to confirm again using the /premium command that they are also the owner of the auth plugin
# account.
# If the onlinemode authentication fails or the player waits to long, it will fallback to offlinemode authentication.
premium-confirm: true
# If you have autoRegister or nameChangeCheck enabled, you could be rate-limited by Mojang.
# The requests of the both options will be only made by FastLogin if the username is unknown to the server

View File

@ -89,9 +89,9 @@ invalid-requst: '&4Invalid request'
# Message if the Bukkit isn't fully started to inject the packets
not-started: '&cServer is not fully started yet. Please retry'
# Warning message if a user invoked /premium command
premium-warning: '&c&lWARNING: &6This command should &lonly&6 be invoked if you are the owner of this paid Minecraft account
Type &a/premium&6 again to confirm'
# Premium confirmation message if the player tries to activate the command
premium-confirm: '&6Please relogin and type the command again to apply the changes.
If the request fails or you wait to long, it will fallback to offlinemode.'
# ========= Bungee/Waterfall only ================================