diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java index a3df527f..96081c10 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java @@ -10,6 +10,7 @@ import pro.gravit.launcher.modules.events.ClosePhase; import pro.gravit.launcher.profiles.ClientProfile; import pro.gravit.launchserver.auth.AuthProviderPair; +import pro.gravit.launchserver.auth.core.RejectAuthCoreProvider; import pro.gravit.launchserver.auth.session.MemorySessionStorage; import pro.gravit.launchserver.binary.EXEL4JLauncherBinary; import pro.gravit.launchserver.binary.EXELauncherBinary; @@ -239,7 +240,7 @@ public void reload(ReloadType type) throws Exception { @Override public Map getCommands() { Map commands = new HashMap<>(); - SubCommand reload = new SubCommand() { + SubCommand reload = new SubCommand("[type]", "reload launchserver config") { @Override public void invoke(String... args) throws Exception { if (args.length == 0) { @@ -263,7 +264,7 @@ public void invoke(String... args) throws Exception { } }; commands.put("reload", reload); - SubCommand save = new SubCommand() { + SubCommand save = new SubCommand("[]", "save launchserver config") { @Override public void invoke(String... args) throws Exception { launchServerConfigManager.writeConfig(config); @@ -272,6 +273,28 @@ public void invoke(String... args) throws Exception { } }; commands.put("save", save); + LaunchServer instance = this; + SubCommand resetauth = new SubCommand("authId", "reset auth by id") { + @Override + public void invoke(String... args) throws Exception { + verifyArgs(args, 1); + AuthProviderPair pair = config.getAuthProviderPair(args[0]); + if(pair == null) { + logger.error("Pair not found"); + return; + } + if(pair.isUseCore()){ + pair.core.close(); + } else { + pair.provider.close(); + pair.handler.close(); + pair.handler = null; + pair.provider = null; + } + pair.core = new RejectAuthCoreProvider(); + pair.core.init(instance); + } + };commands.put("resetauth", resetauth); return commands; } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/JsonCoreProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/JsonCoreProvider.java index f6852be1..8fe0d1e9 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/JsonCoreProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/JsonCoreProvider.java @@ -279,6 +279,15 @@ public String getAccessToken() { public ClientPermissions getPermissions() { return permissions; } + + @Override + public String toString() { + return "JsonUser{" + + "username='" + username + '\'' + + ", uuid=" + uuid + + ", permissions=" + permissions + + '}'; + } } public static class JsonUserSession implements UserSession { @@ -300,6 +309,15 @@ public User getUser() { public long getExpireIn() { return expireIn; } + + @Override + public String toString() { + return "JsonUserSession{" + + "id='" + id + '\'' + + "user='" + (user == null ? null : user.getUsername()) + '\'' + + ", expireIn=" + expireIn + + '}'; + } } public R jsonRequest(T request, String url, Class clazz) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MySQLCoreProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MySQLCoreProvider.java index 182f7789..f473ad74 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MySQLCoreProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MySQLCoreProvider.java @@ -22,6 +22,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.sql.*; +import java.util.Arrays; import java.util.LinkedList; import java.util.List; import java.util.UUID; @@ -453,6 +454,16 @@ public UserHardware getHardware() { hardware = result; return result; } + + @Override + public String toString() { + return "MySQLUser{" + + "uuid=" + uuid + + ", username='" + username + '\'' + + ", permissions=" + permissions + + ", hwidId=" + hwidId + + '}'; + } } public static class MySQLUserHardware implements UserHardware { @@ -487,5 +498,15 @@ public String getId() { public boolean isBanned() { return banned; } + + @Override + public String toString() { + return "MySQLUserHardware{" + + "hardwareInfo=" + hardwareInfo + + ", publicKey=" + (publicKey == null ? null : SecurityHelper.toHex(publicKey)) + + ", id=" + id + + ", banned=" + banned + + '}'; + } } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/password/JsonPasswordVerifier.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/password/JsonPasswordVerifier.java index 8bab6e45..35aa8624 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/password/JsonPasswordVerifier.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/password/JsonPasswordVerifier.java @@ -7,7 +7,7 @@ public class JsonPasswordVerifier extends PasswordVerifier { public String url; public String bearerToken; - private transient HttpClient client = HttpClient.newBuilder().build(); + private transient final HttpClient client = HttpClient.newBuilder().build(); public static class JsonPasswordRequest { public String encryptedPassword; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/auth/AuthCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/auth/AuthCommand.java index 6152e495..e93fa8f6 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/auth/AuthCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/auth/AuthCommand.java @@ -35,7 +35,7 @@ public void invoke(String... args) throws Exception { if (args.length > 2) pair = server.config.getAuthProviderPair(args[2]); else pair = server.config.getAuthProviderPair(); if (pair == null) throw new IllegalStateException(String.format("Auth %s not found", args[1])); - + if(pair.isUseCore()) throw new UnsupportedOperationException(String.format("Please use `config auth.%s.core COMMAND ARGS`", pair.name)); String login = args[0]; String password = args[1]; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/auth/UUIDToUsernameCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/auth/UUIDToUsernameCommand.java index 0fcfd6fb..76eee274 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/auth/UUIDToUsernameCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/auth/UUIDToUsernameCommand.java @@ -34,7 +34,7 @@ public void invoke(String... args) throws CommandException, IOException { if (args.length > 1) pair = server.config.getAuthProviderPair(args[1]); else pair = server.config.getAuthProviderPair(); if (pair == null) throw new IllegalStateException(String.format("Auth %s not found", args[1])); - + if(pair.isUseCore()) throw new UnsupportedOperationException(String.format("Please use `config auth.%s.core COMMAND ARGS`", pair.name)); UUID uuid = parseUUID(args[0]); // Get UUID by username diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/auth/UsernameToUUIDCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/auth/UsernameToUUIDCommand.java index 88ad88cd..ac9b1517 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/auth/UsernameToUUIDCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/auth/UsernameToUUIDCommand.java @@ -34,6 +34,7 @@ public void invoke(String... args) throws CommandException, IOException { if (args.length > 1) pair = server.config.getAuthProviderPair(args[1]); else pair = server.config.getAuthProviderPair(); if (pair == null) throw new IllegalStateException(String.format("Auth %s not found", args[1])); + if(pair.isUseCore()) throw new UnsupportedOperationException(String.format("Please use `config auth.%s.core COMMAND ARGS`", pair.name)); String username = parseUsername(args[0]); // Get UUID by username diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SaveProfilesCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SaveProfilesCommand.java index 7245703c..cc907467 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SaveProfilesCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SaveProfilesCommand.java @@ -150,7 +150,7 @@ public static MakeProfileOption[] getMakeProfileOptionsFromDir(Path dir, ClientP if (Files.exists(dir.resolve("liteloader.jar"))) { options.add(MakeProfileOption.LITELOADER); } - if (Files.exists(dir.resolve("libraries/libraries/org/lwjgl/lwjgl/3.2.2")) && Files.exists(dir.resolve("libraries/libraries/org/lwjgl/lwjgl/3.2.1"))) { + if (Files.exists(dir.resolve("libraries/org/lwjgl/lwjgl/3.2.2")) && Files.exists(dir.resolve("libraries/org/lwjgl/lwjgl/3.2.1"))) { options.add(MakeProfileOption.LWJGLMAC); } if (version.compareTo(ClientProfile.Version.MC1122) <= 0) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SecurityCheckCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SecurityCheckCommand.java index dab27863..b527480f 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SecurityCheckCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SecurityCheckCommand.java @@ -64,6 +64,9 @@ public void invoke(String... args) { } else { printCheckResult(String.format("auth.%s.handler", name), "", true); } + if(!pair.isUseCore()) { + printCheckResult(String.format("auth.%s", name), "AuthProvider/AuthHandler may be removed in future release", null); + } }); if (config.protectHandler instanceof NoProtectHandler) { printCheckResult("protectHandler", "protectHandler none", false); @@ -220,8 +223,8 @@ public void invoke(String... args) { if (checkOtherWriteAccess(IOHelper.getCodeSource(LaunchServer.class))) { logger.warn("Write access to LaunchServer.jar. Please use 'chmod 755 LaunchServer.jar'"); } - if (Files.exists(server.dir.resolve("private.key")) && checkOtherReadOrWriteAccess(server.dir.resolve("private.key"))) { - logger.warn("Write or read access to private.key. Please use 'chmod 600 private.key'"); + if (Files.exists(server.dir.resolve(".keys")) && checkOtherReadOrWriteAccess(server.dir.resolve(".keys"))) { + logger.warn("Write or read access to .keys directory. Please use 'chmod -R 600 .keys'"); } if (Files.exists(server.dir.resolve("LaunchServerConfig.json")) && checkOtherReadOrWriteAccess(server.dir.resolve("LaunchServerConfig.json"))) { logger.warn("Write or read access to LaunchServerConfig.json. Please use 'chmod 600 LaunchServerConfig.json'"); diff --git a/Launcher/src/main/java/pro/gravit/launcher/BasicLauncherEventHandler.java b/Launcher/src/main/java/pro/gravit/launcher/BasicLauncherEventHandler.java index dbdc6b78..33895dc4 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/BasicLauncherEventHandler.java +++ b/Launcher/src/main/java/pro/gravit/launcher/BasicLauncherEventHandler.java @@ -1,10 +1,13 @@ package pro.gravit.launcher; import pro.gravit.launcher.events.ExtendedTokenRequestEvent; +import pro.gravit.launcher.events.request.AuthRequestEvent; +import pro.gravit.launcher.events.request.ErrorRequestEvent; import pro.gravit.launcher.events.request.SecurityReportRequestEvent; import pro.gravit.launcher.request.Request; import pro.gravit.launcher.request.WebSocketEvent; import pro.gravit.launcher.request.websockets.ClientWebSocketService; +import pro.gravit.utils.helper.LogHelper; public class BasicLauncherEventHandler implements ClientWebSocketService.EventHandler { @@ -15,8 +18,15 @@ public boolean eventHandle(T event) { if (event1.action == SecurityReportRequestEvent.ReportAction.CRASH) { LauncherEngine.exitLauncher(80); } + else if(event1.action == SecurityReportRequestEvent.ReportAction.TOKEN_EXPIRED) { + try { + Request.restore(); + } catch (Exception e) { + LogHelper.error(e); + } + } } - if (event instanceof ExtendedTokenRequestEvent) { + else if (event instanceof ExtendedTokenRequestEvent) { ExtendedTokenRequestEvent event1 = (ExtendedTokenRequestEvent) event; String token = event1.getExtendedToken(); if (token != null) { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/SecurityReportRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/SecurityReportRequestEvent.java index 1a617865..7266ea4b 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/SecurityReportRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/SecurityReportRequestEvent.java @@ -29,6 +29,7 @@ public String getType() { public enum ReportAction { NONE, LOGOUT, + TOKEN_EXPIRED, EXIT, CRASH, OTHER diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/HardwareReportRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/HardwareReportRequest.java index d919eb44..5a7bf0ab 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/HardwareReportRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/HardwareReportRequest.java @@ -2,6 +2,9 @@ import pro.gravit.launcher.events.request.HardwareReportRequestEvent; import pro.gravit.launcher.request.Request; +import pro.gravit.utils.helper.SecurityHelper; + +import java.util.Arrays; public class HardwareReportRequest extends Request { public HardwareInfo hardware; @@ -22,5 +25,21 @@ public static class HardwareInfo { public byte[] displayId; public String baseboardSerialNumber; public String graphicCard; + + @Override + public String toString() { + return "HardwareInfo{" + + "bitness=" + bitness + + ", totalMemory=" + totalMemory + + ", logicalProcessors=" + logicalProcessors + + ", physicalProcessors=" + physicalProcessors + + ", processorMaxFreq=" + processorMaxFreq + + ", battery=" + battery + + ", hwDiskId='" + hwDiskId + '\'' + + ", displayId=" + (displayId == null ? null : SecurityHelper.toHex(displayId)) + + ", baseboardSerialNumber='" + baseboardSerialNumber + '\'' + + ", graphicCard='" + graphicCard + '\'' + + '}'; + } } }