From ce28ac40578581779db6b49571269ec407ea2ddc Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 16 Oct 2019 16:38:44 +0700 Subject: [PATCH 001/192] =?UTF-8?q?[FEATURE]=20=D0=BF=D0=B5=D1=80=D0=B5?= =?UTF-8?q?=D1=85=D0=BE=D0=B4=20=D0=BD=D0=B0=20EC=20=D0=BA=D0=BB=D1=8E?= =?UTF-8?q?=D1=87=D0=B8.=20=D0=9E=D1=82=D0=BA=D0=B0=D0=B7=20=D0=BE=D1=82?= =?UTF-8?q?=20RSA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launchserver/LaunchServer.java | 11 +- .../launchserver/LaunchServerBuilder.java | 10 +- .../launchserver/LaunchServerStarter.java | 32 ++-- .../binary/LauncherConfigurator.java | 4 + .../binary/tasks/MainBuildTask.java | 1 + .../command/service/GetModulusCommand.java | 2 +- .../config/LaunchServerRuntimeConfig.java | 6 +- .../socket/response/auth/AuthResponse.java | 8 +- .../launchserver/StartLaunchServerTest.java | 9 +- Launcher/build.gradle | 1 + .../dialog/overlay/settings/settings.js | 2 +- .../pro/gravit/launcher/LauncherEngine.java | 15 +- .../launcher/client/FunctionalBridge.java | 9 + .../launcher/guard/LauncherGravitGuard.java | 2 +- .../launcher/guard/LauncherWrapperGuard.java | 2 +- .../pro/gravit/launcher/AutogenConfig.java | 1 + .../pro/gravit/launcher/LauncherConfig.java | 14 +- .../launcher/request/auth/AuthRequest.java | 12 +- ...thRSAPassword.java => AuthECPassword.java} | 4 +- LauncherCore/build.gradle | 1 + .../gravit/utils/helper/SecurityHelper.java | 179 +++++++----------- .../gravit/launcher/server/ServerWrapper.java | 4 +- modules | 2 +- 23 files changed, 164 insertions(+), 167 deletions(-) rename LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/password/{AuthRSAPassword.java => AuthECPassword.java} (72%) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java index b13fe974..a891822f 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java @@ -13,6 +13,8 @@ import java.security.InvalidAlgorithmParameterException; import java.security.KeyPair; import java.security.NoSuchAlgorithmException; +import java.security.interfaces.ECPrivateKey; +import java.security.interfaces.ECPublicKey; import java.security.interfaces.RSAPrivateKey; import java.security.interfaces.RSAPublicKey; import java.security.spec.InvalidKeySpecException; @@ -220,9 +222,9 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO public LaunchServerRuntimeConfig runtime; - public final RSAPublicKey publicKey; + public final ECPublicKey publicKey; - public final RSAPrivateKey privateKey; + public final ECPrivateKey privateKey; // Launcher binary public final JARLauncherBinary launcherBinary; @@ -279,7 +281,7 @@ public void collect() } } - public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, LaunchServerConfig config, LaunchServerRuntimeConfig runtimeConfig, LaunchServerConfigManager launchServerConfigManager, LaunchServerModulesManager modulesManager, RSAPublicKey publicKey, RSAPrivateKey privateKey, CommandHandler commandHandler) throws IOException, InvalidKeySpecException { + public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, LaunchServerConfig config, LaunchServerRuntimeConfig runtimeConfig, LaunchServerConfigManager launchServerConfigManager, LaunchServerModulesManager modulesManager, ECPublicKey publicKey, ECPrivateKey privateKey, CommandHandler commandHandler) throws IOException, InvalidKeySpecException { this.dir = directories.dir; this.env = env; this.config = config; @@ -306,9 +308,6 @@ public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, La modulesManager.invokeEvent(new NewLaunchServerInstanceEvent(this)); // Print keypair fingerprints - CRC32 crc = new CRC32(); - crc.update(publicKey.getModulus().toByteArray()); // IDEA говорит, что это Java 9 API. WTF? - LogHelper.subInfo("Modulus CRC32: 0x%08x", crc.getValue()); // Load class bindings. launcherEXEBinaryClass = defaultLauncherEXEBinaryClass; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerBuilder.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerBuilder.java index 310ac179..030e1633 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerBuilder.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerBuilder.java @@ -1,6 +1,8 @@ package pro.gravit.launchserver; import java.nio.file.Path; +import java.security.interfaces.ECPrivateKey; +import java.security.interfaces.ECPublicKey; import java.security.interfaces.RSAPrivateKey; import java.security.interfaces.RSAPublicKey; @@ -16,8 +18,8 @@ public class LaunchServerBuilder { private LaunchServer.LaunchServerEnv env; private LaunchServerModulesManager modulesManager; private LaunchServer.LaunchServerDirectories directories = new LaunchServer.LaunchServerDirectories(); - private RSAPublicKey publicKey; - private RSAPrivateKey privateKey; + private ECPublicKey publicKey; + private ECPrivateKey privateKey; private LaunchServer.LaunchServerConfigManager launchServerConfigManager; public LaunchServerBuilder setConfig(LaunchServerConfig config) { @@ -55,12 +57,12 @@ public LaunchServerBuilder setDir(Path dir) { return this; } - public LaunchServerBuilder setPublicKey(RSAPublicKey publicKey) { + public LaunchServerBuilder setPublicKey(ECPublicKey publicKey) { this.publicKey = publicKey; return this; } - public LaunchServerBuilder setPrivateKey(RSAPrivateKey privateKey) { + public LaunchServerBuilder setPrivateKey(ECPrivateKey privateKey) { this.privateKey = privateKey; return this; } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java index 344f71f3..040466bd 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java @@ -7,9 +7,12 @@ import java.nio.file.Files; import java.nio.file.Path; import java.security.KeyPair; -import java.security.interfaces.RSAPrivateKey; -import java.security.interfaces.RSAPublicKey; +import java.security.SecureRandom; +import java.security.Security; +import java.security.interfaces.ECPrivateKey; +import java.security.interfaces.ECPublicKey; +import org.bouncycastle.jce.provider.BouncyCastleProvider; import pro.gravit.launcher.Launcher; import pro.gravit.launcher.hwid.HWIDProvider; import pro.gravit.launcher.modules.events.PreConfigPhase; @@ -35,8 +38,11 @@ import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.SecurityHelper; +import javax.crypto.Cipher; + public class LaunchServerStarter { public static void main(String[] args) throws Exception { + Security.addProvider(new BouncyCastleProvider()); JVMHelper.checkStackTrace(LaunchServerStarter.class); JVMHelper.verifySystemProperties(LaunchServer.class, true); LogHelper.addOutput(IOHelper.WORKING_DIR.resolve("LaunchServer.log")); @@ -51,8 +57,8 @@ public static void main(String[] args) throws Exception { Path configFile, runtimeConfigFile; Path publicKeyFile =dir.resolve("public.key"); Path privateKeyFile = dir.resolve("private.key"); - RSAPublicKey publicKey; - RSAPrivateKey privateKey; + ECPublicKey publicKey; + ECPrivateKey privateKey; LaunchServerRuntimeConfig runtimeConfig; LaunchServerConfig config; @@ -84,19 +90,17 @@ public static void main(String[] args) throws Exception { LogHelper.warning("JLine2 isn't in classpath, using std"); } if (IOHelper.isFile(publicKeyFile) && IOHelper.isFile(privateKeyFile)) { - LogHelper.info("Reading RSA keypair"); - publicKey = SecurityHelper.toPublicRSAKey(IOHelper.read(publicKeyFile)); - privateKey = SecurityHelper.toPrivateRSAKey(IOHelper.read(privateKeyFile)); - if (!publicKey.getModulus().equals(privateKey.getModulus())) - throw new IOException("Private and public key modulus mismatch"); + LogHelper.info("Reading EC keypair"); + publicKey = SecurityHelper.toPublicECKey(IOHelper.read(publicKeyFile)); + privateKey = SecurityHelper.toPrivateECKey(IOHelper.read(privateKeyFile)); } else { - LogHelper.info("Generating RSA keypair"); - KeyPair pair = SecurityHelper.genRSAKeyPair(); - publicKey = (RSAPublicKey) pair.getPublic(); - privateKey = (RSAPrivateKey) pair.getPrivate(); + LogHelper.info("Generating EC keypair"); + KeyPair pair = SecurityHelper.genECKeyPair(new SecureRandom()); + publicKey = (ECPublicKey) pair.getPublic(); + privateKey = (ECPrivateKey) pair.getPrivate(); // Write key pair list - LogHelper.info("Writing RSA keypair list"); + LogHelper.info("Writing EC keypair list"); IOHelper.write(publicKeyFile, publicKey.getEncoded()); IOHelper.write(privateKeyFile, privateKey.getEncoded()); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherConfigurator.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherConfigurator.java index 49e53c53..e1aac82e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherConfigurator.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherConfigurator.java @@ -65,6 +65,10 @@ public void setAddress(String address) { setStringField("address", address); } + public void setPasswordEncryptKey(String pass) { + setStringField("passwordEncryptKey", pass); + } + public void setProjectName(String name) { setStringField("projectname", name); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java index f420cd7b..df570184 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java @@ -134,6 +134,7 @@ public Path process(Path inputJar) throws IOException { launcherConfigurator.setGuardType(server.config.launcher.guardType); launcherConfigurator.setWarningMissArchJava(server.config.launcher.warningMissArchJava); launcherConfigurator.setEnv(server.config.env); + launcherConfigurator.setPasswordEncryptKey(server.runtime.passwordEncryptKey); String launcherSalt = SecurityHelper.randomStringToken(); byte[] launcherSecureHash = SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA256, server.runtime.clientCheckSecret.concat(".").concat(launcherSalt)); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GetModulusCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GetModulusCommand.java index c40eda10..b7454ecc 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GetModulusCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GetModulusCommand.java @@ -21,6 +21,6 @@ public String getUsageDescription() { @Override public void invoke(String... args) throws Exception { - LogHelper.info("You publickey modulus: %s", server.publicKey.getModulus().toString(16)); + //LogHelper.info("You publickey modulus: %s", server.publicKey.getModulus().toString(16)); } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerRuntimeConfig.java b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerRuntimeConfig.java index 0e600258..7e1798f9 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerRuntimeConfig.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerRuntimeConfig.java @@ -4,18 +4,18 @@ import pro.gravit.utils.helper.SecurityHelper; public class LaunchServerRuntimeConfig { - public String clientToken; + public String passwordEncryptKey; public String oemUnlockKey; public String registerApiKey; public String clientCheckSecret; public void verify() { - if (clientToken == null) LogHelper.error("[RuntimeConfig] clientToken must not be null"); + if (passwordEncryptKey == null) LogHelper.error("[RuntimeConfig] passwordEncryptKey must not be null"); if (clientCheckSecret == null) { LogHelper.warning("[RuntimeConfig] clientCheckSecret must not be null"); clientCheckSecret = SecurityHelper.randomStringToken(); } } public void reset() { - clientToken = SecurityHelper.randomStringToken(); + passwordEncryptKey = SecurityHelper.randomStringToken(); registerApiKey = SecurityHelper.randomStringToken(); clientCheckSecret = SecurityHelper.randomStringToken(); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java index e4ec148a..7d03fb55 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java @@ -14,7 +14,7 @@ import pro.gravit.launcher.profiles.ClientProfile; import pro.gravit.launcher.request.auth.AuthRequest; import pro.gravit.launcher.request.auth.password.AuthPlainPassword; -import pro.gravit.launcher.request.auth.password.AuthRSAPassword; +import pro.gravit.launcher.request.auth.password.AuthECPassword; import pro.gravit.launchserver.auth.AuthException; import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.auth.hwid.HWIDException; @@ -59,11 +59,11 @@ public void execute(ChannelHandlerContext ctx, Client clientData) throws Excepti AuthProvider.authError("Don't skip Launcher Update"); return; } - if(password instanceof AuthRSAPassword) + if(password instanceof AuthECPassword) { try { - password = new AuthPlainPassword(IOHelper.decode(SecurityHelper.newRSADecryptCipher(server.privateKey). - doFinal(((AuthRSAPassword) password).password))); + password = new AuthPlainPassword(IOHelper.decode(SecurityHelper.decrypt(server.runtime.passwordEncryptKey + , ((AuthECPassword) password).password))); } catch (IllegalBlockSizeException | BadPaddingException ignored) { throw new AuthException("Password decryption error"); } diff --git a/LaunchServer/src/test/java/pro/gravit/launchserver/StartLaunchServerTest.java b/LaunchServer/src/test/java/pro/gravit/launchserver/StartLaunchServerTest.java index 4af453ca..d19ab520 100644 --- a/LaunchServer/src/test/java/pro/gravit/launchserver/StartLaunchServerTest.java +++ b/LaunchServer/src/test/java/pro/gravit/launchserver/StartLaunchServerTest.java @@ -3,6 +3,9 @@ import java.io.IOException; import java.nio.file.Path; import java.security.KeyPair; +import java.security.SecureRandom; +import java.security.interfaces.ECPrivateKey; +import java.security.interfaces.ECPublicKey; import java.security.interfaces.RSAPrivateKey; import java.security.interfaces.RSAPublicKey; @@ -35,9 +38,9 @@ public static void prepare() throws Exception Launcher.gsonManager.initGson(); LaunchServerRuntimeConfig runtimeConfig = new LaunchServerRuntimeConfig(); LaunchServerBuilder builder = new LaunchServerBuilder(); - KeyPair pair = SecurityHelper.genRSAKeyPair(); - RSAPublicKey publicKey = (RSAPublicKey) pair.getPublic(); - RSAPrivateKey privateKey = (RSAPrivateKey) pair.getPrivate(); + KeyPair pair = SecurityHelper.genECKeyPair(new SecureRandom()); + ECPublicKey publicKey = (ECPublicKey) pair.getPublic(); + ECPrivateKey privateKey = (ECPrivateKey) pair.getPrivate(); builder.setDir(dir) .setEnv(LaunchServer.LaunchServerEnv.TEST) .setConfig(config) diff --git a/Launcher/build.gradle b/Launcher/build.gradle index 4d368664..a989aea5 100644 --- a/Launcher/build.gradle +++ b/Launcher/build.gradle @@ -50,6 +50,7 @@ task javadocJar(type: Jar) { pack project(':LauncherAuthlib') bundle 'com.github.oshi:oshi-core:3.13.0' bundle 'org.apache.httpcomponents:httpclient:4.5.7' + bundle 'org.bouncycastle:bcprov-jdk15:1.46' pack 'io.netty:netty-codec-http:4.1.36.Final' pack 'org.ow2.asm:asm-tree:7.1' } diff --git a/Launcher/runtime/dialog/overlay/settings/settings.js b/Launcher/runtime/dialog/overlay/settings/settings.js index 514b5739..22c0c0a6 100644 --- a/Launcher/runtime/dialog/overlay/settings/settings.js +++ b/Launcher/runtime/dialog/overlay/settings/settings.js @@ -155,7 +155,7 @@ var settingsOverlay = { }, setPassword: function(password) { - var encrypted = SecurityHelper.newRSAEncryptCipher(Launcher.getConfig().publicKey).doFinal(IOHelper.encode(password)); + var encrypted = FunctionalBridge.encryptPassword(password); return encrypted; }, diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index a1556111..657de117 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -1,12 +1,11 @@ package pro.gravit.launcher; +import java.security.*; import java.util.Objects; import java.util.concurrent.atomic.AtomicBoolean; -import pro.gravit.launcher.client.ClientModuleManager; -import pro.gravit.launcher.client.DirBridge; -import pro.gravit.launcher.client.FunctionalBridge; -import pro.gravit.launcher.client.LauncherUpdateController; +import org.bouncycastle.jce.provider.BouncyCastleProvider; +import pro.gravit.launcher.client.*; import pro.gravit.launcher.client.events.ClientEngineInitPhase; import pro.gravit.launcher.client.events.ClientPreGuiPhase; import pro.gravit.launcher.guard.LauncherGuardManager; @@ -22,10 +21,9 @@ import pro.gravit.launcher.request.auth.RestoreSessionRequest; import pro.gravit.launcher.request.update.UpdateRequest; import pro.gravit.launcher.request.websockets.StandartClientWebSocketService; -import pro.gravit.utils.helper.CommonHelper; -import pro.gravit.utils.helper.EnvHelper; -import pro.gravit.utils.helper.JVMHelper; -import pro.gravit.utils.helper.LogHelper; +import pro.gravit.utils.helper.*; + +import javax.crypto.Cipher; public class LauncherEngine { @@ -36,6 +34,7 @@ public static void main(String... args) throws Throwable { //if(!LauncherAgent.isStarted()) throw new SecurityException("JavaAgent not set"); LogHelper.printVersion("Launcher"); LogHelper.printLicense("Launcher"); + Security.addProvider(new BouncyCastleProvider()); LauncherEngine.modulesManager = new ClientModuleManager(); LauncherConfig.getAutogenConfig().initModules(); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/FunctionalBridge.java b/Launcher/src/main/java/pro/gravit/launcher/client/FunctionalBridge.java index 560b5abe..2cdf51ab 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/FunctionalBridge.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/FunctionalBridge.java @@ -1,11 +1,13 @@ package pro.gravit.launcher.client; import java.nio.file.Path; +import java.util.Arrays; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; +import pro.gravit.launcher.Launcher; import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.api.AuthService; import pro.gravit.launcher.events.request.AuthRequestEvent; @@ -19,7 +21,9 @@ import pro.gravit.launcher.managers.HasherStore; import pro.gravit.launcher.request.Request; import pro.gravit.utils.Version; +import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; +import pro.gravit.utils.helper.SecurityHelper; public class FunctionalBridge { @LauncherAPI @@ -133,4 +137,9 @@ public static String getLauncherVersion() { Version.BUILD ); } + @LauncherAPI + public static byte[] encryptPassword(String string) throws Exception { + byte[] encode = IOHelper.encode(string); + return SecurityHelper.encrypt(Launcher.getConfig().passwordEncryptKey, encode); + } } diff --git a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherGravitGuard.java b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherGravitGuard.java index 30f24026..10735c83 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherGravitGuard.java +++ b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherGravitGuard.java @@ -76,7 +76,7 @@ public void addCustomEnv(ClientLauncherContext context) { LauncherConfig config = Launcher.getConfig(); env.put("GUARD_BRIDGE", GravitGuardBridge.class.getName()); env.put("GUARD_USERNAME", context.playerProfile.username); - env.put("GUARD_PUBLICKEY", config.publicKey.getModulus().toString(16)); + //env.put("GUARD_PUBLICKEY", config.publicKey.getModulus().toString(16)); env.put("GUARD_PROJECTNAME", config.projectname); if (protectToken != null) env.put("GUARD_TOKEN", protectToken); diff --git a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherWrapperGuard.java b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherWrapperGuard.java index 01eccbc1..e6922146 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherWrapperGuard.java +++ b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherWrapperGuard.java @@ -63,7 +63,7 @@ public void addCustomEnv(ClientLauncherContext context) { env.put("JAVA_HOME", System.getProperty("java.home")); LauncherConfig config = Launcher.getConfig(); env.put("GUARD_USERNAME", context.playerProfile.username); - env.put("GUARD_PUBLICKEY", config.publicKey.getModulus().toString(16)); + //env.put("GUARD_PUBLICKEY", config.publicKey.getModulus().toString(16)); env.put("GUARD_PROJECTNAME", config.projectname); if (protectToken != null) env.put("GUARD_TOKEN", protectToken); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/AutogenConfig.java b/LauncherAPI/src/main/java/pro/gravit/launcher/AutogenConfig.java index 05edd785..290a1e38 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/AutogenConfig.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/AutogenConfig.java @@ -12,6 +12,7 @@ public class AutogenConfig { public String guardLicenseEncryptKey; public String secureCheckHash; public String secureCheckSalt; + public String passwordEncryptKey; public int env; public boolean isWarningMissArchJava; // 0 - Dev (дебаг включен по умолчанию, все сообщения) diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java b/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java index 6019b49d..6b012e79 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java @@ -1,6 +1,8 @@ package pro.gravit.launcher; import java.io.IOException; +import java.security.interfaces.ECPrivateKey; +import java.security.interfaces.ECPublicKey; import java.security.interfaces.RSAPublicKey; import java.security.spec.InvalidKeySpecException; import java.util.Collections; @@ -31,7 +33,7 @@ public static AutogenConfig getAutogenConfig() { public String secretKeyClient; public String oemUnlockKey; @LauncherAPI - public final RSAPublicKey publicKey; + public final ECPublicKey publicKey; @LauncherAPI public final Map runtime; @@ -46,12 +48,14 @@ public static AutogenConfig getAutogenConfig() { public final String secureCheckHash; public final String secureCheckSalt; + public final String passwordEncryptKey; @LauncherAPI public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException { - publicKey = SecurityHelper.toPublicRSAKey(input.readByteArray(SecurityHelper.CRYPTO_MAX_LENGTH)); + publicKey = SecurityHelper.toPublicECKey(input.readByteArray(SecurityHelper.CRYPTO_MAX_LENGTH)); secureCheckHash = config.secureCheckHash; secureCheckSalt = config.secureCheckSalt; + passwordEncryptKey = config.passwordEncryptKey; projectname = config.projectname; clientPort = config.clientPort; secretKeyClient = config.secretKeyClient; @@ -84,7 +88,7 @@ public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException } @LauncherAPI - public LauncherConfig(String address, RSAPublicKey publicKey, Map runtime, String projectname) { + public LauncherConfig(String address, ECPublicKey publicKey, Map runtime, String projectname) { this.address = address; this.publicKey = Objects.requireNonNull(publicKey, "publicKey"); this.runtime = Collections.unmodifiableMap(new HashMap<>(runtime)); @@ -99,10 +103,11 @@ public LauncherConfig(String address, RSAPublicKey publicKey, Map runtime) { + public LauncherConfig(String address, ECPublicKey publicKey, Map runtime) { this.address = address; this.publicKey = Objects.requireNonNull(publicKey, "publicKey"); this.runtime = Collections.unmodifiableMap(new HashMap<>(runtime)); @@ -117,6 +122,7 @@ public LauncherConfig(String address, RSAPublicKey publicKey, Map HEX.indexOf(ch) >= 0); } private static Cipher newCipher(String algo) { - // IDK Why, but collapsing catch blocks makes ProGuard generate invalid stackmap try { return Cipher.getInstance(algo); } catch (NoSuchAlgorithmException | NoSuchPaddingException e) { @@ -206,6 +180,19 @@ private static Cipher newCipher(String algo) { } } + /** + * @param algo Cipher algo + * @return Cipher instance + * @throws SecurityException: JCE cannot authenticate the provider BC if BouncyCastle is in unsigned jar + */ + private static Cipher newBCCipher(String algo) { + try { + return Cipher.getInstance(algo, new BouncyCastleProvider()); + } catch (NoSuchAlgorithmException | NoSuchPaddingException e) { + throw new InternalError(e); + } + } + public static MessageDigest newDigest(DigestAlgorithm algo) { VerifyHelper.verify(algo, a -> a != DigestAlgorithm.PLAIN, "PLAIN digest"); @@ -221,8 +208,8 @@ public static SecureRandom newRandom() { return new SecureRandom(); } - private static Cipher newRSACipher(int mode, RSAKey key) { - Cipher cipher = newCipher(RSA_CIPHER_ALGO); + private static Cipher newECCipher(int mode, ECKey key) { + Cipher cipher = newBCCipher(EC_CIPHER_ALGO); try { cipher.init(mode, (Key) key); } catch (InvalidKeyException e) { @@ -231,35 +218,24 @@ private static Cipher newRSACipher(int mode, RSAKey key) { return cipher; } - @LauncherAPI - public static Cipher newRSADecryptCipher(RSAPrivateKey key) { - return newRSACipher(Cipher.DECRYPT_MODE, key); - } - - @LauncherAPI - public static Cipher newRSAEncryptCipher(RSAPublicKey key) { - return newRSACipher(Cipher.ENCRYPT_MODE, key); - } - - private static KeyFactory newRSAKeyFactory() { + private static KeyFactory newECKeyFactory() { try { - return KeyFactory.getInstance(RSA_ALGO); + return KeyFactory.getInstance(EC_ALGO); } catch (NoSuchAlgorithmException e) { throw new InternalError(e); } } - private static Signature newRSASignature() { + private static Signature newECSignature() { try { - return Signature.getInstance(RSA_SIGN_ALGO); + return Signature.getInstance(EC_SIGN_ALGO); } catch (NoSuchAlgorithmException e) { throw new InternalError(e); } } - - public static Signature newRSASignSignature(RSAPrivateKey key) { - Signature signature = newRSASignature(); + public static Signature newECSignSignature(ECPrivateKey key) { + Signature signature = newECSignature(); try { signature.initSign(key); } catch (InvalidKeyException e) { @@ -269,8 +245,8 @@ public static Signature newRSASignSignature(RSAPrivateKey key) { } - public static Signature newRSAVerifySignature(RSAPublicKey key) { - Signature signature = newRSASignature(); + public static Signature newECVerifySignature(ECPublicKey key) { + Signature signature = newECSignature(); try { signature.initVerify(key); } catch (InvalidKeyException e) { @@ -394,9 +370,8 @@ public static String randomUsername(Random random) { return VerifyHelper.verifyUsername(prefix + new String(chars) + suffix); } - - public static byte[] sign(byte[] bytes, RSAPrivateKey privateKey) { - Signature signature = newRSASignSignature(privateKey); + public static byte[] sign(byte[] bytes, ECPrivateKey privateKey) { + Signature signature = newECSignSignature(privateKey); try { signature.update(bytes); return signature.sign(); @@ -405,23 +380,6 @@ public static byte[] sign(byte[] bytes, RSAPrivateKey privateKey) { } } - public static byte[] sign(InputStream input, RSAPrivateKey privateKey) throws IOException { - Signature signature = newRSASignSignature(privateKey); - updateSignature(input, signature); - try { - return signature.sign(); - } catch (SignatureException e) { - throw new InternalError(e); - } - } - - - public static byte[] sign(Path path, RSAPrivateKey privateKey) throws IOException { - try (InputStream input = IOHelper.newInput(path)) { - return sign(input, privateKey); - } - } - public static String toHex(byte[] bytes) { int offset = 0; @@ -436,13 +394,12 @@ public static String toHex(byte[] bytes) { return new String(hex); } - - public static RSAPrivateKey toPrivateRSAKey(byte[] bytes) throws InvalidKeySpecException { - return (RSAPrivateKey) newRSAKeyFactory().generatePrivate(new PKCS8EncodedKeySpec(bytes)); + public static ECPublicKey toPublicECKey(byte[] bytes) throws InvalidKeySpecException { + return (ECPublicKey) newECKeyFactory().generatePublic(new X509EncodedKeySpec(bytes)); } - public static RSAPublicKey toPublicRSAKey(byte[] bytes) throws InvalidKeySpecException { - return (RSAPublicKey) newRSAKeyFactory().generatePublic(new X509EncodedKeySpec(bytes)); + public static ECPrivateKey toPrivateECKey(byte[] bytes) throws InvalidKeySpecException { + return (ECPrivateKey) newECKeyFactory().generatePrivate(new PKCS8EncodedKeySpec(bytes)); } private static void updateSignature(InputStream input, Signature signature) throws IOException { @@ -456,34 +413,41 @@ private static void updateSignature(InputStream input, Signature signature) thro } - public static void verifySign(byte[] bytes, byte[] sign, RSAPublicKey publicKey) throws SignatureException { + public static void verifySign(byte[] bytes, byte[] sign, ECPublicKey publicKey) throws SignatureException { if (!isValidSign(bytes, sign, publicKey)) throw new SignatureException("Invalid sign"); } - public static void verifySign(InputStream input, byte[] sign, RSAPublicKey publicKey) throws SignatureException, IOException { + public static void verifySign(InputStream input, byte[] sign, ECPublicKey publicKey) throws SignatureException, IOException { if (!isValidSign(input, sign, publicKey)) throw new SignatureException("Invalid stream sign"); } - public static void verifySign(Path path, byte[] sign, RSAPublicKey publicKey) throws SignatureException, IOException { - if (!isValidSign(path, sign, publicKey)) - throw new SignatureException(String.format("Invalid file sign: '%s'", path)); - } - - - public static void verifySign(URL url, byte[] sign, RSAPublicKey publicKey) throws SignatureException, IOException { - if (!isValidSign(url, sign, publicKey)) - throw new SignatureException(String.format("Invalid URL sign: '%s'", url)); - } - - public static String verifyToken(String token) { return VerifyHelper.verify(token, SecurityHelper::isValidToken, String.format("Invalid token: '%s'", token)); } + public static Cipher newECDecryptCipher(ECPrivateKey privateKey) + { + try { + return newECCipher(Cipher.DECRYPT_MODE, privateKey); + } catch (SecurityException e) + { + throw new InternalError(e); + } + } + public static Cipher newECEncryptCipher(ECPublicKey publicKey) + { + try { + return newECCipher(Cipher.ENCRYPT_MODE, publicKey); + } catch (SecurityException e) + { + throw new InternalError(e); + } + } + private SecurityHelper() { } @@ -521,6 +485,9 @@ public static byte[] decrypt(byte[] raw, byte[] encrypted) throws Exception { cipher.init(Cipher.DECRYPT_MODE, sKeySpec); return cipher.doFinal(encrypted); } + public static byte[] decrypt(String seed, byte[] encrypted) throws Exception { + return decrypt( getRawKey(seed.getBytes()), encrypted); + } public static byte[] HexToByte(String hexString) { int len = hexString.length() / 2; diff --git a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java index 3949e2ad..42602a1f 100644 --- a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java +++ b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java @@ -52,7 +52,7 @@ public ServerWrapper(Type type, Path configPath) { public boolean auth() { try { LauncherConfig cfg = Launcher.getConfig(); - AuthRequest request = new AuthRequest(config.login, SecurityHelper.newRSAEncryptCipher(cfg.publicKey).doFinal(IOHelper.encode(config.password)), config.auth_id, AuthRequest.ConnectTypes.SERVER); + AuthRequest request = new AuthRequest(config.login, SecurityHelper.newECEncryptCipher(cfg.publicKey).doFinal(IOHelper.encode(config.password)), config.auth_id, AuthRequest.ConnectTypes.SERVER); permissions = request.request().permissions; ProfilesRequestEvent result = new ProfilesRequest().request(); for (ClientProfile p : result.profiles) { @@ -190,7 +190,7 @@ public void updateLauncherConfig() { LauncherConfig cfg = null; try { - cfg = new LauncherConfig(config.address, SecurityHelper.toPublicRSAKey(IOHelper.read(publicKeyFile)), new HashMap<>(), config.projectname); + cfg = new LauncherConfig(config.address, SecurityHelper.toPublicECKey(IOHelper.read(publicKeyFile)), new HashMap<>(), config.projectname); cfg.isNettyEnabled = true; cfg.address = config.address; } catch (InvalidKeySpecException | IOException e) { diff --git a/modules b/modules index 960e178b..a770ac08 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 960e178bc658835dc8aff93ee51e10e52bc7afb5 +Subproject commit a770ac083f9e940122f888fa6ffd9e0485d3292b From a84f489f0d1aaefcf81d93db4a25d9065b4b764d Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 16 Oct 2019 16:58:22 +0700 Subject: [PATCH 002/192] =?UTF-8?q?[FIX]=20=D0=A0=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=20=D0=B1=D0=B5=D0=B7=20BouncyCastle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/pro/gravit/launcher/LauncherEngine.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index 657de117..a5f425a4 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -34,7 +34,12 @@ public static void main(String... args) throws Throwable { //if(!LauncherAgent.isStarted()) throw new SecurityException("JavaAgent not set"); LogHelper.printVersion("Launcher"); LogHelper.printLicense("Launcher"); - Security.addProvider(new BouncyCastleProvider()); + try { + Security.addProvider(new BouncyCastleProvider()); + } catch (Exception ignored) + { + LogHelper.warning("BouncyCastle not found"); + } LauncherEngine.modulesManager = new ClientModuleManager(); LauncherConfig.getAutogenConfig().initModules(); From 35a94ae59f45bdd8bc530b8c6b787706cbd59cb9 Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 16 Oct 2019 17:08:48 +0700 Subject: [PATCH 003/192] =?UTF-8?q?[FIX]=20=D0=92=D1=8B=D1=80=D0=B5=D0=B7?= =?UTF-8?q?=D0=B0=D0=BD=D0=B0=20=D0=BB=D0=B8=D1=86=D0=B5=D0=BD=D0=B7=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=BD=D0=B0=20=D0=B7=D0=B0=D1=89=D0=B8=D1=82=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../binary/LauncherConfigurator.java | 28 ------------------- .../binary/tasks/MainBuildTask.java | 4 --- .../config/LaunchServerConfig.java | 7 ----- .../launcher/bridge/GravitGuardBridge.java | 22 --------------- .../launcher/guard/LauncherGuardManager.java | 2 +- ...GravitGuard.java => LauncherStdGuard.java} | 10 ++----- .../launcher/guard/LauncherWrapperGuard.java | 1 - 7 files changed, 4 insertions(+), 70 deletions(-) delete mode 100644 Launcher/src/main/java/pro/gravit/launcher/bridge/GravitGuardBridge.java rename Launcher/src/main/java/pro/gravit/launcher/guard/{LauncherGravitGuard.java => LauncherStdGuard.java} (87%) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherConfigurator.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherConfigurator.java index e1aac82e..9494a143 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherConfigurator.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherConfigurator.java @@ -150,32 +150,4 @@ private void setBooleanField(String name, boolean b) constructor.instructions.add(new InsnNode(b ? Opcodes.ICONST_1 : Opcodes.ICONST_0)); constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, autoGenConfigName, name, Type.BOOLEAN_TYPE.getInternalName())); } - - public void setGuardLicense(String name, String key, String encryptKey) { - constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); - constructor.instructions.add(new LdcInsnNode(name)); - constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, autoGenConfigName, "guardLicenseName", stringDesc)); - - constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); - constructor.instructions.add(new LdcInsnNode(key)); - constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, autoGenConfigName, "guardLicenseKey", stringDesc)); - - constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); - constructor.instructions.add(new LdcInsnNode(encryptKey)); - constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, autoGenConfigName, "guardLicenseEncryptKey", stringDesc)); - } - - public void nullGuardLicense() { - constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); - constructor.instructions.add(new InsnNode(Opcodes.ACONST_NULL)); - constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, autoGenConfigName, "guardLicenseName", stringDesc)); - - constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); - constructor.instructions.add(new InsnNode(Opcodes.ACONST_NULL)); - constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, autoGenConfigName, "guardLicenseKey", stringDesc)); - - constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); - constructor.instructions.add(new InsnNode(Opcodes.ACONST_NULL)); - constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, autoGenConfigName, "guardLicenseEncryptKey", stringDesc)); - } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java index df570184..b111755d 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java @@ -124,10 +124,6 @@ public Path process(Path inputJar) throws IOException { BuildContext context = new BuildContext(output, launcherConfigurator, this); server.buildHookManager.hook(context); launcherConfigurator.setAddress(server.config.netty.address); - if (server.config.guardLicense != null) - launcherConfigurator.setGuardLicense(server.config.guardLicense.name, server.config.guardLicense.key, server.config.guardLicense.encryptKey); - else - launcherConfigurator.nullGuardLicense(); launcherConfigurator.setProjectName(server.config.projectName); launcherConfigurator.setSecretKey(SecurityHelper.randomStringAESKey()); launcherConfigurator.setClientPort(32148 + SecurityHelper.newRandom().nextInt(512)); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java index a3e5aa04..7f7e01f5 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java @@ -84,7 +84,6 @@ public AuthProviderPair getAuthProviderPair() { public ExeConf launch4j; public NettyConfig netty; - public GuardLicenseConf guardLicense; public String whitelistRejectString; public LauncherConf launcher; @@ -280,12 +279,6 @@ public NettyBindAddress(String address, int port) { this.port = port; } } - - public static class GuardLicenseConf { - public String name; - public String key; - public String encryptKey; - } public static LaunchServerConfig getDefault(LaunchServer.LaunchServerEnv env) { LaunchServerConfig newConfig = new LaunchServerConfig(); diff --git a/Launcher/src/main/java/pro/gravit/launcher/bridge/GravitGuardBridge.java b/Launcher/src/main/java/pro/gravit/launcher/bridge/GravitGuardBridge.java deleted file mode 100644 index ec8e9fa5..00000000 --- a/Launcher/src/main/java/pro/gravit/launcher/bridge/GravitGuardBridge.java +++ /dev/null @@ -1,22 +0,0 @@ -package pro.gravit.launcher.bridge; - -import java.io.IOException; -import java.net.HttpURLConnection; -import java.net.URL; - -import pro.gravit.launcher.LauncherAPI; - -@LauncherAPI -public class GravitGuardBridge { - @LauncherAPI - public static native void callGuard(); - - @LauncherAPI - public static int sendHTTPRequest(String strurl) throws IOException { - URL url = new URL(strurl); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod("GET"); - connection.setRequestProperty("Content-Language", "en-US"); - return connection.getResponseCode(); - } -} diff --git a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherGuardManager.java b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherGuardManager.java index 92718c25..6f0ce1d9 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherGuardManager.java +++ b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherGuardManager.java @@ -12,7 +12,7 @@ public static void initGuard(boolean clientInstance) { LauncherConfig config = Launcher.getConfig(); switch (config.guardType) { case "gravitguard": { - guard = new LauncherGravitGuard(); + guard = new LauncherStdGuard(); break; } case "wrapper": { diff --git a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherGravitGuard.java b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherStdGuard.java similarity index 87% rename from Launcher/src/main/java/pro/gravit/launcher/guard/LauncherGravitGuard.java rename to Launcher/src/main/java/pro/gravit/launcher/guard/LauncherStdGuard.java index 10735c83..d93d9baa 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherGravitGuard.java +++ b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherStdGuard.java @@ -8,7 +8,6 @@ import pro.gravit.launcher.Launcher; import pro.gravit.launcher.LauncherConfig; -import pro.gravit.launcher.bridge.GravitGuardBridge; import pro.gravit.launcher.client.ClientLauncher; import pro.gravit.launcher.client.ClientLauncherContext; import pro.gravit.launcher.client.DirBridge; @@ -16,14 +15,14 @@ import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.UnpackHelper; -//Используется для всех типов защит, совместимых с новым GravitGuard API -public class LauncherGravitGuard implements LauncherGuardInterface { +//Стандартный интерфейс для всех AntiInject +public class LauncherStdGuard implements LauncherGuardInterface { public String protectToken; public Path javaBinPath; @Override public String getName() { - return "gravitguard"; + return "stdguard"; } @Override @@ -58,7 +57,6 @@ public void init(boolean clientInstance) { } catch (IOException e) { throw new SecurityException(e); } - if (clientInstance && JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) GravitGuardBridge.callGuard(); } @Override @@ -74,9 +72,7 @@ public void addCustomEnv(ClientLauncherContext context) { else env.put("JAVA_HOME", javaBinPath.toAbsolutePath().toString()); LauncherConfig config = Launcher.getConfig(); - env.put("GUARD_BRIDGE", GravitGuardBridge.class.getName()); env.put("GUARD_USERNAME", context.playerProfile.username); - //env.put("GUARD_PUBLICKEY", config.publicKey.getModulus().toString(16)); env.put("GUARD_PROJECTNAME", config.projectname); if (protectToken != null) env.put("GUARD_TOKEN", protectToken); diff --git a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherWrapperGuard.java b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherWrapperGuard.java index e6922146..550a1925 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherWrapperGuard.java +++ b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherWrapperGuard.java @@ -63,7 +63,6 @@ public void addCustomEnv(ClientLauncherContext context) { env.put("JAVA_HOME", System.getProperty("java.home")); LauncherConfig config = Launcher.getConfig(); env.put("GUARD_USERNAME", context.playerProfile.username); - //env.put("GUARD_PUBLICKEY", config.publicKey.getModulus().toString(16)); env.put("GUARD_PROJECTNAME", config.projectname); if (protectToken != null) env.put("GUARD_TOKEN", protectToken); From 4a0485d1de96d84e38cd97f87ad52e8598b88223 Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 16 Oct 2019 17:48:36 +0700 Subject: [PATCH 004/192] =?UTF-8?q?[FEATURE]=20=D0=9A=D0=BB=D1=8E=D1=87?= =?UTF-8?q?=D0=B8=20=D1=83=20=D0=BA=D0=BB=D0=B8=D0=B5=D0=BD=D1=82=D0=B0,?= =?UTF-8?q?=20=D0=BD=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BF?= =?UTF-8?q?=D0=B0=D0=BF=D0=BA=D0=B8=20=D0=BB=D0=B0=D1=83=D0=BD=D1=87=D0=B5?= =?UTF-8?q?=D1=80=D0=B0=20=D0=BD=D0=B0=D1=81=D1=82=D1=80=D0=B0=D0=B8=D0=B2?= =?UTF-8?q?=D0=B0=D0=B5=D1=82=D1=81=D1=8F=20=D1=87=D0=B5=D1=80=D0=B5=D0=B7?= =?UTF-8?q?=20projectName?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Launcher/runtime/config.js | 8 +---- .../pro/gravit/launcher/LauncherEngine.java | 30 +++++++++++++++++++ .../launcher/client/ClientLauncher.java | 1 + .../pro/gravit/launcher/client/DirBridge.java | 16 ++++++++++ 4 files changed, 48 insertions(+), 7 deletions(-) diff --git a/Launcher/runtime/config.js b/Launcher/runtime/config.js index 1f1f81b4..c63a5dc4 100644 --- a/Launcher/runtime/config.js +++ b/Launcher/runtime/config.js @@ -1,6 +1,6 @@ var config = { //*** Настройки лаунчера ***// - dir: "GravitLauncher", // Название папки лаунчера + // Название папки лаунчера настраивается в LaunchServer.conf(строка projectName) title: "GravitLauncher", // Заголовок окна icons: ["favicon.png"], // Путь/Пути до иконки окна @@ -36,12 +36,6 @@ var config = { settingsMagic: 0xC0DE5, // Магия вне хогвартса }; -DirBridge.dir = DirBridge.getLauncherDir(config.dir); -DirBridge.dirStore = DirBridge.getStoreDir(config.dir); -DirBridge.dirProjectStore = DirBridge.getProjectStoreDir(config.dir); -if (!IOHelper.isDir(DirBridge.dir)) { - java.nio.file.Files.createDirectory(DirBridge.dir); -} DirBridge.defaultUpdatesDir = DirBridge.dir.resolve("updates"); if (!IOHelper.isDir(DirBridge.defaultUpdatesDir)) { java.nio.file.Files.createDirectory(DirBridge.defaultUpdatesDir); diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index a5f425a4..8b538ea2 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -1,6 +1,11 @@ package pro.gravit.launcher; +import java.io.IOException; +import java.nio.file.Path; import java.security.*; +import java.security.interfaces.ECPrivateKey; +import java.security.interfaces.ECPublicKey; +import java.security.spec.InvalidKeySpecException; import java.util.Objects; import java.util.concurrent.atomic.AtomicBoolean; @@ -72,9 +77,33 @@ public static void initGson(ClientModuleManager modulesManager) { Launcher.gsonManager.initGson(); } + public void readKeys() throws IOException, InvalidKeySpecException { + if(privateKey != null || publicKey != null) return; + Path dir = DirBridge.dir; + Path publicKeyFile =dir.resolve("public.key"); + Path privateKeyFile = dir.resolve("private.key"); + if (IOHelper.isFile(publicKeyFile) && IOHelper.isFile(privateKeyFile)) { + LogHelper.info("Reading EC keypair"); + publicKey = SecurityHelper.toPublicECKey(IOHelper.read(publicKeyFile)); + privateKey = SecurityHelper.toPrivateECKey(IOHelper.read(privateKeyFile)); + } else { + LogHelper.info("Generating EC keypair"); + KeyPair pair = SecurityHelper.genECKeyPair(new SecureRandom()); + publicKey = (ECPublicKey) pair.getPublic(); + privateKey = (ECPrivateKey) pair.getPrivate(); + + // Write key pair list + LogHelper.info("Writing EC keypair list"); + IOHelper.write(publicKeyFile, publicKey.getEncoded()); + IOHelper.write(privateKeyFile, privateKey.getEncoded()); + } + } + // Instance private final AtomicBoolean started = new AtomicBoolean(false); public RuntimeProvider runtimeProvider; + public ECPublicKey publicKey; + public ECPrivateKey privateKey; public static ClientModuleManager modulesManager; @@ -119,6 +148,7 @@ public void start(String... args) throws Throwable { Objects.requireNonNull(args, "args"); if (started.getAndSet(true)) throw new IllegalStateException("Launcher has been already started"); + readKeys(); LauncherEngine.modulesManager.invokeEvent(new ClientEngineInitPhase(this)); runtimeProvider.preLoad(); LauncherGuardManager.initGuard(false); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index ff1db902..b81d0bd3 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -461,6 +461,7 @@ public static void main(String... args) throws Throwable { if (engine.runtimeProvider == null) engine.runtimeProvider = new JSRuntimeProvider(); engine.runtimeProvider.init(true); engine.runtimeProvider.preLoad(); + engine.readKeys(); HWIDProvider.registerHWIDs(); LauncherGuardManager.initGuard(true); LogHelper.debug("Reading ClientLauncher params"); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/DirBridge.java b/Launcher/src/main/java/pro/gravit/launcher/client/DirBridge.java index 194ea88e..3175bc43 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/DirBridge.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/DirBridge.java @@ -5,9 +5,11 @@ import java.nio.file.Path; import java.nio.file.Paths; +import pro.gravit.launcher.Launcher; import pro.gravit.launcher.LauncherAPI; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.JVMHelper; +import pro.gravit.utils.helper.LogHelper; public class DirBridge { @@ -98,4 +100,18 @@ public static Path getLegacyLauncherDir(String projectname) { public static void setUseLegacyDir(boolean b) { useLegacyDir = b; } + + static { + String projectName = Launcher.getConfig().projectname; + try { + DirBridge.dir = getLauncherDir(projectName); + if(!IOHelper.exists(DirBridge.dir)) Files.createDirectories(DirBridge.dir); + DirBridge.dirStore = getStoreDir(projectName); + if(!IOHelper.exists(DirBridge.dirStore)) Files.createDirectories(DirBridge.dirStore); + DirBridge.dirProjectStore = getProjectStoreDir(projectName); + if(!IOHelper.exists(DirBridge.dirProjectStore)) Files.createDirectories(DirBridge.dirProjectStore); + } catch (IOException e) { + LogHelper.error(e); + } + } } From f0a235f12c86699eec62760260e9495600c046dd Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 16 Oct 2019 17:55:03 +0700 Subject: [PATCH 005/192] =?UTF-8?q?[FEATURE]=20=D0=98=D1=81=D0=BF=D0=BE?= =?UTF-8?q?=D0=BB=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5=20JS=20=D0=BF=D1=80=D0=B8?= =?UTF-8?q?=20=D0=B7=D0=B0=D0=BF=D1=83=D1=81=D0=BA=D0=B5=20=D0=BA=D0=BB?= =?UTF-8?q?=D0=B8=D0=B5=D0=BD=D1=82=D0=B0=20=D0=B1=D0=BE=D0=BB=D1=8C=D1=88?= =?UTF-8?q?=D0=B5=20=D0=BD=D0=B5=20=D1=82=D1=80=D0=B5=D0=B1=D1=83=D0=B5?= =?UTF-8?q?=D1=82=D1=81=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/pro/gravit/launcher/client/ClientLauncher.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index b81d0bd3..d1e90194 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -458,9 +458,6 @@ public static void main(String... args) throws Throwable { EnvHelper.checkDangerousParams(); JVMHelper.checkStackTrace(ClientLauncher.class); LogHelper.printVersion("Client Launcher"); - if (engine.runtimeProvider == null) engine.runtimeProvider = new JSRuntimeProvider(); - engine.runtimeProvider.init(true); - engine.runtimeProvider.preLoad(); engine.readKeys(); HWIDProvider.registerHWIDs(); LauncherGuardManager.initGuard(true); From cd4e89dc15dd3dfe66f0c79b7b49f4d45fe97fb4 Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 16 Oct 2019 22:40:36 +0700 Subject: [PATCH 006/192] =?UTF-8?q?[FEATURE]=20=D0=91=D0=B0=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D1=8B=D0=B5=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA?= =?UTF-8?q?=D0=B8=20HWID=20=D0=BD=D0=B0=20=D0=BB=D0=B6=D0=B8=D0=B2=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launchserver/dao/UserHWID.java | 10 +-- .../java/pro/gravit/launcher/hwid/HWID.java | 5 +- .../gravit/launcher/hwid/HWIDCheckHelper.java | 71 +++++++++++++++++++ .../java/pro/gravit/launcher/hwid/NoHWID.java | 14 ++-- .../pro/gravit/launcher/hwid/OshiHWID.java | 38 +++++++--- 5 files changed, 118 insertions(+), 20 deletions(-) create mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWIDCheckHelper.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserHWID.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserHWID.java index d81dddf3..db0b8846 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserHWID.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserHWID.java @@ -41,11 +41,6 @@ public OshiHWID toHWID() return oshi; } - @Override - public String getSerializeString() { - return toHWID().getSerializeString(); - } - @Override public int getLevel() { return toHWID().getLevel(); @@ -60,4 +55,9 @@ public int compare(HWID hwid) { public boolean isNull() { return toHWID().isNull(); } + + @Override + public void normalize() { + + } } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWID.java b/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWID.java index 32616752..b107e716 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWID.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWID.java @@ -1,11 +1,14 @@ package pro.gravit.launcher.hwid; public interface HWID { - String getSerializeString(); int getLevel(); //Уровень доверия, насколько уникальные значения + int getAntiLevel(); //Уровень лживости, насколько фальшивые значения + int compare(HWID hwid); boolean isNull(); + + void normalize(); } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWIDCheckHelper.java b/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWIDCheckHelper.java new file mode 100644 index 00000000..79052ed7 --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWIDCheckHelper.java @@ -0,0 +1,71 @@ +package pro.gravit.launcher.hwid; + +public class HWIDCheckHelper { + public static int checkString(String str) + { + int result = 0; + //Считаем символы + char lastChar = '\0'; + int combo = 0; + int maxCombo = 0; + //Считаем род символов + int lastCharType = -1; + int lastCharTypeCombo = 0; + int wtfCharTypeCombo = 0; + boolean skipLastCharType = true; + for(char c : str.toCharArray()) + { + if(c == lastChar || Math.abs(c - lastChar) == 1 || + ( ( lastChar == '0' || lastChar == '9' ) && ( c == 'A' || c == 'a' ))) //Переход с 0 или 9 на A или a + { + lastChar = c; + combo++; + } + else + { + if(maxCombo < combo) + maxCombo = combo; + lastChar = c; + combo = 1; + } + int charType = getCharType(c); + if(lastCharType == charType) { + lastCharTypeCombo++; + //Нам подсунули серию из идущих подряд спец символов. Что за? + if((charType == -1 || charType == 3) && lastCharTypeCombo > 2) + { + wtfCharTypeCombo+=3; + } + //Нам подсунули серию из слишком большого числа идущих подряд чисел. Что за? + if((charType == 0) && lastCharTypeCombo > 4) + { + wtfCharTypeCombo++; + } + } + else + { + if(skipLastCharType && ( charType == -1 || charType == 3 )) + { + skipLastCharType = false; + } + else + { + skipLastCharType = true; + lastCharType = charType; + } + } + } + //Считаем результат + if(maxCombo > 3) result+= maxCombo * 3; + if(wtfCharTypeCombo > 1) result+= wtfCharTypeCombo * 2; + return result; + } + public static int getCharType(char c) + { + if(c >= '0' && c <= '9') return 0; + if(c >= 'A' && c <= 'Z') return 1; + if(c >= 'a' && c <= 'z') return 2; + if(c == ' ' || c == '-' || c == '_') return 3; + return -1; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/NoHWID.java b/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/NoHWID.java index d03c1d82..853ec6e2 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/NoHWID.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/NoHWID.java @@ -1,16 +1,17 @@ package pro.gravit.launcher.hwid; public class NoHWID implements HWID { - @Override - public String getSerializeString() { - return ""; - } @Override public int getLevel() { return 0; } + @Override + public int getAntiLevel() { + return 0; + } + @Override public int compare(HWID hwid) { return 0; @@ -20,4 +21,9 @@ public int compare(HWID hwid) { public boolean isNull() { return true; } + + @Override + public void normalize() { + //Skip + } } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/OshiHWID.java b/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/OshiHWID.java index a3f36dac..3d0656a7 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/OshiHWID.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/OshiHWID.java @@ -20,23 +20,23 @@ public class OshiHWID implements HWID { @LauncherAPI public String macAddr; - @Override - public String getSerializeString() { - return gson.toJson(this); - } - @Override public int getLevel() //Уровень доверия, насколько уникальные значения { int result = 0; - if (totalMemory != 0) result += 8; - if (serialNumber != null && !serialNumber.equals("unknown")) result += 12; - if (HWDiskSerial != null && !HWDiskSerial.equals("unknown")) result += 30; - if (processorID != null && !processorID.equals("unknown")) result += 10; - if (macAddr != null && !macAddr.equals("00:00:00:00:00:00")) result += 15; + if (totalMemory != 0) result += 32; + if (serialNumber != null) result += isRealSerialNumber() ? 20 : 3; + if (HWDiskSerial != null && !HWDiskSerial.isEmpty()) result += 38; + if (processorID != null && !processorID.isEmpty()) result += 20; + if (macAddr != null && !macAddr.isEmpty()) result += 25; return result; } + @Override + public int getAntiLevel() { + return HWIDCheckHelper.checkString(serialNumber) + HWIDCheckHelper.checkString(HWDiskSerial); + } + @Override public int compare(HWID hwid) { if (hwid instanceof OshiHWID) { @@ -58,6 +58,24 @@ public boolean isNull() { return getLevel() < 15; } + @Override + public void normalize() { + HWDiskSerial = HWDiskSerial.trim(); + serialNumber = serialNumber.trim(); + processorID = processorID.trim(); + macAddr = macAddr.trim(); + } + public boolean isRealSerialNumber() + { + if(serialNumber.isEmpty()) return false; + if(serialNumber.equals("System Serial Number")) return false; + if(serialNumber.equals("To be filled by O.E.M.")) return false; + if(serialNumber.equals("unknown")) return false; + if(serialNumber.equals("None")) return false; + if(serialNumber.equals("Default string")) return false; + return true; + } + @Override public boolean equals(Object o) { if (this == o) return true; From 80e24715f688067dc82f03f9b7b6822cadb42646 Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 16 Oct 2019 22:50:35 +0700 Subject: [PATCH 007/192] =?UTF-8?q?[FEATURE]=20=D0=9F=D0=BE=D0=B4=D0=BF?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D1=8B=20=D1=87=D0=B8=D1=81?= =?UTF-8?q?=D0=BB=D0=B0=20=D1=81=D1=80=D0=B0=D0=B2=D0=BD=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20HWID=20=D0=BF=D1=80=D0=B8=20compareMode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/pro/gravit/launcher/hwid/OshiHWID.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/OshiHWID.java b/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/OshiHWID.java index 3d0656a7..efced953 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/OshiHWID.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/OshiHWID.java @@ -27,7 +27,7 @@ public int getLevel() //Уровень доверия, насколько уни if (totalMemory != 0) result += 32; if (serialNumber != null) result += isRealSerialNumber() ? 20 : 3; if (HWDiskSerial != null && !HWDiskSerial.isEmpty()) result += 38; - if (processorID != null && !processorID.isEmpty()) result += 20; + if (processorID != null && !processorID.isEmpty()) result += 15; if (macAddr != null && !macAddr.isEmpty()) result += 25; return result; } @@ -43,10 +43,10 @@ public int compare(HWID hwid) { int rate = 0; OshiHWID oshi = (OshiHWID) hwid; if (Math.abs(oshi.totalMemory - totalMemory) < 1024 * 1024) rate += 5; - if (oshi.totalMemory == totalMemory) rate += 15; - if (oshi.HWDiskSerial.equals(HWDiskSerial)) rate += 45; - if (oshi.processorID.equals(processorID)) rate += 18; - if (oshi.serialNumber.equals(serialNumber)) rate += 15; + if (oshi.totalMemory == totalMemory) rate += 32; + if (oshi.HWDiskSerial.equals(HWDiskSerial) && !HWDiskSerial.isEmpty()) rate += 38; + if (oshi.processorID.equals(processorID) && !processorID.isEmpty()) rate += 15; + if (oshi.serialNumber.equals(serialNumber)) rate += isRealSerialNumber() ? 20 : 3; if (!oshi.macAddr.isEmpty() && oshi.macAddr.equals(macAddr)) rate += 19; return rate; } From a7db7184db752ff0886f6c1cb42022fabe798d5c Mon Sep 17 00:00:00 2001 From: Gravit Date: Thu, 17 Oct 2019 01:19:14 +0700 Subject: [PATCH 008/192] =?UTF-8?q?[FIX]=20=D0=9E=D1=88=D0=B8=D0=B1=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=B8=D0=BB=D1=8F=D1=86=D0=B8?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java | 2 +- .../src/main/java/pro/gravit/launchserver/dao/UserHWID.java | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java index 283af7d5..7c5d6e06 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java @@ -154,7 +154,7 @@ public void onCheckInfo(OshiHWID hwid, String username, Connection c) throws HWI db_hwid.totalMemory = Long.valueOf(set.getString(hwidFieldTotalMemory)); db_hwid.macAddr = set.getString(hwidFieldMAC); if (LogHelper.isDevEnabled()) { - LogHelper.dev("Compare HWID: %s vs %s", hwid.getSerializeString(), db_hwid.getSerializeString()); + LogHelper.dev("Compare HWID: %s vs %s", hwid.toString(), db_hwid.toString()); } int compare_point = hwid.compare(db_hwid); if (compare_point < compare) continue; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserHWID.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserHWID.java index db0b8846..a68298bc 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserHWID.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserHWID.java @@ -46,6 +46,11 @@ public int getLevel() { return toHWID().getLevel(); } + @Override + public int getAntiLevel() { + return 0; + } + @Override public int compare(HWID hwid) { return toHWID().compare(hwid); From 8a52340b1a1f70b16358d46233063b6b1a062658 Mon Sep 17 00:00:00 2001 From: Gravit Date: Thu, 17 Oct 2019 01:43:40 +0700 Subject: [PATCH 009/192] =?UTF-8?q?[FEATURE]=20=D0=A1=D0=B5=D0=BA=D1=80?= =?UTF-8?q?=D0=B5=D1=82=D0=BD=D0=B0=D1=8F=20=D0=BC=D0=B0=D0=B3=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/pro/gravit/utils/helper/JVMHelper.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java index 22204cf1..e65b913d 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java @@ -7,6 +7,7 @@ import java.lang.management.RuntimeMXBean; import java.net.MalformedURLException; import java.net.URL; +import java.security.cert.X509Certificate; import java.util.Arrays; import java.util.Collection; import java.util.Locale; @@ -110,6 +111,13 @@ public static URL[] getClassPathURL() { return list; } + public static X509Certificate[] getCertificates(Class clazz) + { + Object[] signers = clazz.getSigners(); + if(signers == null) return new X509Certificate[] {}; + return Arrays.stream(signers).filter((c) -> c instanceof X509Certificate).map((c) -> (X509Certificate) c).toArray(X509Certificate[]::new); + } + public static void checkStackTrace(Class mainClass) { LogHelper.debug("Testing stacktrace"); Exception e = new Exception("Testing stacktrace"); From 5a2aedbe06a2f13ccc840fe04e28d250403a3ba3 Mon Sep 17 00:00:00 2001 From: Gravit Date: Thu, 17 Oct 2019 20:22:24 +0700 Subject: [PATCH 010/192] =?UTF-8?q?[FEATURE]=20LauncherTrustManager=20?= =?UTF-8?q?=D0=B8=20=D0=B1=D0=B0=D0=B7=D0=BE=D0=B2=D1=8B=D0=B5=20=D1=81?= =?UTF-8?q?=D0=B5=D1=80=D1=82=D0=B8=D1=84=D0=B8=D0=BA=D0=B0=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launchserver/LaunchServer.java | 7 +- .../launchserver/LaunchServerBuilder.java | 9 +- .../launchserver/LaunchServerStarter.java | 15 +++- .../manangers/CertificateManager.java | 49 +++++++++-- .../impl/LaunchServerModulesManager.java | 6 +- .../defaults/GravitCentralRootCA.crt | 33 +++++++ .../launchserver/StartLaunchServerTest.java | 4 +- .../modules/impl/SimpleModuleManager.java | 38 +++++++- .../pro/gravit/utils/helper/JVMHelper.java | 2 +- .../utils/verify/LauncherTrustManager.java | 88 +++++++++++++++++++ 10 files changed, 233 insertions(+), 18 deletions(-) create mode 100644 LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/GravitCentralRootCA.crt create mode 100644 LauncherCore/src/main/java/pro/gravit/utils/verify/LauncherTrustManager.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java index a891822f..a1d7de7b 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java @@ -13,6 +13,7 @@ import java.security.InvalidAlgorithmParameterException; import java.security.KeyPair; import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; import java.security.interfaces.ECPrivateKey; import java.security.interfaces.ECPublicKey; import java.security.interfaces.RSAPrivateKey; @@ -274,14 +275,16 @@ public static class LaunchServerDirectories public Path updatesDir; public Path profilesDir; public Path dir; + public Path trustStore; public void collect() { if(updatesDir == null) updatesDir = dir.resolve("updates"); if(profilesDir == null) profilesDir = dir.resolve("profiles"); + if(trustStore == null) trustStore = dir.resolve("truststore"); } } - public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, LaunchServerConfig config, LaunchServerRuntimeConfig runtimeConfig, LaunchServerConfigManager launchServerConfigManager, LaunchServerModulesManager modulesManager, ECPublicKey publicKey, ECPrivateKey privateKey, CommandHandler commandHandler) throws IOException, InvalidKeySpecException { + public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, LaunchServerConfig config, LaunchServerRuntimeConfig runtimeConfig, LaunchServerConfigManager launchServerConfigManager, LaunchServerModulesManager modulesManager, ECPublicKey publicKey, ECPrivateKey privateKey, CommandHandler commandHandler, CertificateManager certificateManager) throws IOException { this.dir = directories.dir; this.env = env; this.config = config; @@ -293,6 +296,7 @@ public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, La this.privateKey = privateKey; this.commandHandler = commandHandler; this.runtime = runtimeConfig; + this.certificateManager = certificateManager; taskPool = new Timer("Timered task worker thread", true); launcherLibraries = dir.resolve("launcher-libraries"); launcherLibrariesCompile = dir.resolve("launcher-libraries-compile"); @@ -331,7 +335,6 @@ public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, La reconfigurableManager = new ReconfigurableManager(); authHookManager = new AuthHookManager(); configManager = new ConfigManager(); - certificateManager = new CertificateManager(); //Generate or set new Certificate API certificateManager.orgName = config.projectName; if(config.certificate != null && config.certificate.enabled) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerBuilder.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerBuilder.java index 030e1633..3b21bea1 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerBuilder.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerBuilder.java @@ -8,6 +8,7 @@ import pro.gravit.launchserver.config.LaunchServerConfig; import pro.gravit.launchserver.config.LaunchServerRuntimeConfig; +import pro.gravit.launchserver.manangers.CertificateManager; import pro.gravit.launchserver.modules.impl.LaunchServerModulesManager; import pro.gravit.utils.command.CommandHandler; @@ -20,6 +21,7 @@ public class LaunchServerBuilder { private LaunchServer.LaunchServerDirectories directories = new LaunchServer.LaunchServerDirectories(); private ECPublicKey publicKey; private ECPrivateKey privateKey; + private CertificateManager certificateManager; private LaunchServer.LaunchServerConfigManager launchServerConfigManager; public LaunchServerBuilder setConfig(LaunchServerConfig config) { @@ -101,6 +103,11 @@ public void writeRuntimeConfig(LaunchServerRuntimeConfig config) { } }; } - return new LaunchServer(directories, env, config, runtimeConfig, launchServerConfigManager, modulesManager, publicKey, privateKey, commandHandler); + return new LaunchServer(directories, env, config, runtimeConfig, launchServerConfigManager, modulesManager, publicKey, privateKey, commandHandler, certificateManager); + } + + public LaunchServerBuilder setCertificateManager(CertificateManager certificateManager) { + this.certificateManager = certificateManager; + return this; } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java index 040466bd..a35e2116 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java @@ -9,6 +9,7 @@ import java.security.KeyPair; import java.security.SecureRandom; import java.security.Security; +import java.security.cert.CertificateException; import java.security.interfaces.ECPrivateKey; import java.security.interfaces.ECPublicKey; @@ -27,6 +28,7 @@ import pro.gravit.launchserver.config.LaunchServerConfig; import pro.gravit.launchserver.config.LaunchServerRuntimeConfig; import pro.gravit.launchserver.dao.provider.DaoProvider; +import pro.gravit.launchserver.manangers.CertificateManager; import pro.gravit.launchserver.manangers.LaunchServerGsonManager; import pro.gravit.launchserver.modules.impl.LaunchServerModulesManager; import pro.gravit.launchserver.socket.WebSocketService; @@ -37,12 +39,12 @@ import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.SecurityHelper; +import pro.gravit.utils.verify.LauncherTrustManager; import javax.crypto.Cipher; public class LaunchServerStarter { public static void main(String[] args) throws Exception { - Security.addProvider(new BouncyCastleProvider()); JVMHelper.checkStackTrace(LaunchServerStarter.class); JVMHelper.verifySystemProperties(LaunchServer.class, true); LogHelper.addOutput(IOHelper.WORKING_DIR.resolve("LaunchServer.log")); @@ -52,18 +54,24 @@ public static void main(String[] args) throws Exception { LogHelper.error("StarterAgent is not started!"); LogHelper.error("You should add to JVM options this option: `-javaagent:LaunchServer.jar`"); } - Path dir = IOHelper.WORKING_DIR; Path configFile, runtimeConfigFile; Path publicKeyFile =dir.resolve("public.key"); Path privateKeyFile = dir.resolve("private.key"); ECPublicKey publicKey; ECPrivateKey privateKey; + Security.addProvider(new BouncyCastleProvider()); + CertificateManager certificateManager = new CertificateManager(); + try { + certificateManager.readTrustStore(dir.resolve("truststore")); + } catch (CertificateException e) { + throw new IOException(e); + } LaunchServerRuntimeConfig runtimeConfig; LaunchServerConfig config; LaunchServer.LaunchServerEnv env = LaunchServer.LaunchServerEnv.PRODUCTION; - LaunchServerModulesManager modulesManager = new LaunchServerModulesManager(dir.resolve("modules"), dir.resolve("config")); + LaunchServerModulesManager modulesManager = new LaunchServerModulesManager(dir.resolve("modules"), dir.resolve("config"), certificateManager.trustManager); modulesManager.autoload(); modulesManager.initModules(null); registerAll(); @@ -173,6 +181,7 @@ public void writeRuntimeConfig(LaunchServerRuntimeConfig config) throws IOExcept .setConfig(config) .setModulesManager(modulesManager) .setLaunchServerConfigManager(launchServerConfigManager) + .setCertificateManager(certificateManager) .build(); server.run(); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/CertificateManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/CertificateManager.java index 88620405..c6fafca8 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/CertificateManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/CertificateManager.java @@ -1,25 +1,31 @@ package pro.gravit.launchserver.manangers; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.Reader; -import java.io.Writer; +import java.io.*; import java.math.BigInteger; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; import java.security.InvalidAlgorithmParameterException; import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.NoSuchAlgorithmException; import java.security.PrivateKey; import java.security.PublicKey; +import java.security.cert.CertificateException; +import java.security.cert.CertificateFactory; +import java.security.cert.X509Certificate; import java.security.spec.ECGenParameterSpec; import java.time.Instant; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.temporal.ChronoUnit; +import java.util.ArrayList; import java.util.Date; +import java.util.List; import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; import org.bouncycastle.asn1.x500.X500Name; @@ -43,6 +49,7 @@ import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.SecurityHelper; +import pro.gravit.utils.verify.LauncherTrustManager; public class CertificateManager { public X509CertificateHolder ca; @@ -51,9 +58,7 @@ public class CertificateManager { public X509CertificateHolder server; public AsymmetricKeyParameter serverKey; - - //public X509CertificateHolder server; - //public AsymmetricKeyParameter serverKey; + public LauncherTrustManager trustManager; public int validDays = 60; public int minusHours = 6; @@ -172,4 +177,34 @@ public X509CertificateHolder readCertificate(Reader reader) throws IOException { } return ret; } + + public void readTrustStore(Path dir) throws IOException, CertificateException { + if(!IOHelper.isDir(dir)) + { + Files.createDirectories(dir); + try(OutputStream outputStream = IOHelper.newOutput(dir.resolve("GravitCentralRootCA.crt")); + InputStream inputStream = IOHelper.newInput(IOHelper.getResourceURL("pro/gravit/launchserver/defaults/GravitCentralRootCA.crt"))) + { + IOHelper.transfer(inputStream, outputStream); + } + } + List certificates = new ArrayList<>(); + CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); + IOHelper.walk(dir, new SimpleFileVisitor() { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + if(file.toFile().getName().endsWith(".crt")) + { + try(InputStream inputStream = IOHelper.newInput(file)) + { + certificates.add((X509Certificate) certFactory.generateCertificate(inputStream)); + } catch (CertificateException e) { + throw new IOException(e); + } + } + return super.visitFile(file, attrs); + } + }, false); + trustManager = new LauncherTrustManager(certificates.toArray(new X509Certificate[0])); + } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerModulesManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerModulesManager.java index 0cc68190..24558e99 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerModulesManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerModulesManager.java @@ -7,12 +7,14 @@ import pro.gravit.launcher.modules.LauncherModuleInfo; import pro.gravit.launcher.modules.impl.SimpleModuleManager; import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launchserver.manangers.CertificateManager; import pro.gravit.utils.helper.LogHelper; +import pro.gravit.utils.verify.LauncherTrustManager; public class LaunchServerModulesManager extends SimpleModuleManager { public LaunchServerCoreModule coreModule; - public LaunchServerModulesManager(Path modulesDir, Path configDir) { - super(modulesDir, configDir); + public LaunchServerModulesManager(Path modulesDir, Path configDir, LauncherTrustManager trustManager) { + super(modulesDir, configDir, trustManager); coreModule = new LaunchServerCoreModule(); modules.add(coreModule); } diff --git a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/GravitCentralRootCA.crt b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/GravitCentralRootCA.crt new file mode 100644 index 00000000..c683d07b --- /dev/null +++ b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/GravitCentralRootCA.crt @@ -0,0 +1,33 @@ +-----BEGIN CERTIFICATE----- +MIIFyjCCA7KgAwIBAgIRALnsjNjfvOTXfla3fX1fNEUwDQYJKoZIhvcNAQELBQAw +WTELMAkGA1UEBhMCUlUxFzAVBgNVBAoTDkdyYXZpdFRydXN0IENBMRAwDgYDVQQL +EwdSb290IENBMR8wHQYDVQQDExZHcmF2aXQgQ2VudHJhbCBSb290IENBMCAXDTE5 +MDYwOTAyNDIwMFoYDzIwNTEwNjA5MDI0MjAwWjBZMQswCQYDVQQGEwJSVTEXMBUG +A1UEChMOR3Jhdml0VHJ1c3QgQ0ExEDAOBgNVBAsTB1Jvb3QgQ0ExHzAdBgNVBAMT +FkdyYXZpdCBDZW50cmFsIFJvb3QgQ0EwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAw +ggIKAoICAQDA3Qm9OH8Xz3YM3bKkZuQI7T/aL3ulMOdY5GFADYgHrOVZXVSJi/4P +PruBsut4WXN6TGQdpJtNZ2kyWTYzENGTm/TMzBcIchor1M3JW5Uv/C0r5gSEU1uP +DPe7oEpeKtb3FXML/pGoGpLv/sonTKky4AKZnK7B15bZ+oVZNwh7UKANpNrVA8k5 +0gb4BisFcegLidYL9Y00H1x5WzUxldQAA1IQuwdkL3NP0NPQrSVJ2Ka2EtebE2HP +fXHtbftvvnvSWyh4CXAxTfEmJgut0gSPQPm9wVt6pIWWd4O0hHwVmxkKQidgnP6A ++d05FnJGsBw0ztMCifIteqNiHF0D8E0GuSz6NtcuV47J3p43qkvKr2vPc8o6WMN8 +PAb0eVHc/AX8qqOwYQyHlj4M0SDhCltHeeYRWmuZmRFIIelv6VAocaQLlPQrhJNp +feIzmXLy60a+84vpe/eQKQx+D8a1elarQkoHMxI7x/9AJvxcnJ4KuXc2rkiu3Zv9 +KMhixtkLc+pA6jY023U211v+c20RjTqwKIZoMFc7BZipoinAOn1bdsTzXlhOMv1O +zj5WoW6DsQQONMZNyLQAkaX6SYZE/kQVJ9YMPhNdaXjxxzfrY05IrWAaWhtPbW8z +5nb4/JyO+bJq3v2rav9p03s8P/lQ4k/0af5vOkGkEO0+YKx97ZP8FQIDAQABo4GK +MIGHMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFFjMGCvHXAE/vGJih+Lfdo2s +YnzsMAsGA1UdDwQEAwIBBjA1BgNVHR8ELjAsMCqgKKAmhiRodHRwOi8vY2EuZ3Jh +dml0LnByby9jZW50cmFscm9vdC5jcmwwEQYJYIZIAYb4QgEBBAQDAgAHMA0GCSqG +SIb3DQEBCwUAA4ICAQAexCGpThx85skEllva1UskmdlRh3rud9u59AUiwNZF0b0I ++7eeyLNaLHarg2Zm30TSCF53ksyPTE5QNdmozs1fl3MddFqunkbUm4G6hwedZMSi +4IXIb2QK3z3gZG5ZNdHaDG2u00Jdkc39h3jQFp1rpn4+0DcnYJAe+lw5G+XHURY2 +j15wcmUFp/Ywgw3pfCWmH5+rxq21e/LG8JiQrxekkFI2GUD+Qw7+Hq3o1Fgg3kfh +Lg4B5WEbEICQ1FC+dHYHasEI3q3c96Qpqu2k3pO0l1fr6Cys+AGjoI2WrgXkGlmA +F+Wi2ndoZbvspGAwxmrNMtLE3OYNuMXFF410QSPf4o9QqpGDC3a2mccTXb231a18 +5vDJixeZpuzEm5ECXg8j6aj53X3rtm7C8yfOsg5UTKJJj+pSNz4YTp91IDHm0nTP +2KhrgS7jujgKdJn9xv07e/API3kLWkVmMwHBiaSCIaHOfAN0RJMQVV+YgnSp2sIa +OATWgSKH0qTkleE/v7k+USs0a+KV8wmC5wwliqH+uLO++yIP/9bjDctyLulQX5Ee ++EhD7tb1R/yyWY4uhkzlsr3N2Kl34aQAEBMn8Z1mHsyyu1FcbEaNLU8jcS3pHPVM +gQRn3m1iDnQlFciAMxW0pW6mW/4xKYzhXk5BTSolnqMVylxHgWXuBwdDDQQVnQ== +-----END CERTIFICATE----- \ No newline at end of file diff --git a/LaunchServer/src/test/java/pro/gravit/launchserver/StartLaunchServerTest.java b/LaunchServer/src/test/java/pro/gravit/launchserver/StartLaunchServerTest.java index d19ab520..31f9d75d 100644 --- a/LaunchServer/src/test/java/pro/gravit/launchserver/StartLaunchServerTest.java +++ b/LaunchServer/src/test/java/pro/gravit/launchserver/StartLaunchServerTest.java @@ -16,6 +16,7 @@ import pro.gravit.launcher.Launcher; import pro.gravit.launchserver.config.LaunchServerConfig; import pro.gravit.launchserver.config.LaunchServerRuntimeConfig; +import pro.gravit.launchserver.manangers.CertificateManager; import pro.gravit.launchserver.manangers.LaunchServerGsonManager; import pro.gravit.launchserver.modules.impl.LaunchServerModulesManager; import pro.gravit.utils.command.StdCommandHandler; @@ -32,7 +33,7 @@ public class StartLaunchServerTest { @BeforeAll public static void prepare() throws Exception { - LaunchServerModulesManager modulesManager = new LaunchServerModulesManager(modulesDir, configDir); + LaunchServerModulesManager modulesManager = new LaunchServerModulesManager(modulesDir, configDir, null); LaunchServerConfig config = LaunchServerConfig.getDefault(LaunchServer.LaunchServerEnv.TEST); Launcher.gsonManager = new LaunchServerGsonManager(modulesManager); Launcher.gsonManager.initGson(); @@ -47,6 +48,7 @@ public static void prepare() throws Exception .setRuntimeConfig(runtimeConfig) .setPublicKey(publicKey) .setPrivateKey(privateKey) + .setCertificateManager(new CertificateManager()) .setLaunchServerConfigManager(new LaunchServer.LaunchServerConfigManager() { @Override public LaunchServerConfig readConfig() throws IOException { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java index e8285f4d..08c9d1c3 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java @@ -7,6 +7,12 @@ import java.nio.file.Path; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.SignatureException; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -22,7 +28,9 @@ import pro.gravit.utils.PublicURLClassLoader; import pro.gravit.utils.Version; import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.LogHelper; +import pro.gravit.utils.verify.LauncherTrustManager; public class SimpleModuleManager implements LauncherModulesManager { protected final List modules = new ArrayList<>(); @@ -30,6 +38,7 @@ public class SimpleModuleManager implements LauncherModulesManager { protected final SimpleModuleContext context; protected final ModulesConfigManager modulesConfigManager; protected final Path modulesDir; + protected final LauncherTrustManager trustManager; protected LauncherInitContext initContext; protected PublicURLClassLoader classLoader = new PublicURLClassLoader(new URL[]{}); @@ -113,6 +122,13 @@ public SimpleModuleManager(Path modulesDir, Path configDir) { modulesConfigManager = new SimpleModulesConfigManager(configDir); context = new SimpleModuleContext(this, modulesConfigManager); this.modulesDir = modulesDir; + this.trustManager = null; + } + public SimpleModuleManager(Path modulesDir, Path configDir, LauncherTrustManager trustManager) { + modulesConfigManager = new SimpleModulesConfigManager(configDir); + context = new SimpleModuleContext(this, modulesConfigManager); + this.modulesDir = modulesDir; + this.trustManager = trustManager; } @Override @@ -142,7 +158,10 @@ public LauncherModule loadModule(Path file) throws IOException { return null; } classLoader.addURL(file.toUri().toURL()); - LauncherModule module = (LauncherModule) Class.forName(moduleClass, true, classLoader).newInstance(); + @SuppressWarnings("unchecked cast") + Class clazz = (Class) Class.forName(moduleClass, false, classLoader); + checkModuleClass(clazz); + LauncherModule module = clazz.newInstance(); loadModule(module); return module; } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) { @@ -152,6 +171,23 @@ public LauncherModule loadModule(Path file) throws IOException { } } + protected void checkModuleClass(Class clazz) throws SecurityException + { + if(trustManager == null) return; + X509Certificate[] certificates = JVMHelper.getCertificates(clazz); + if(certificates == null) + { + LogHelper.warning("Module class %s not signed", clazz.getName()); + } + try { + trustManager.checkCertificate(certificates, (c,s) -> { + + }); + } catch (CertificateException | NoSuchProviderException | NoSuchAlgorithmException | InvalidKeyException | SignatureException e) { + throw new SecurityException(e); + } + } + @Override public LauncherModule getModule(String name) { for(LauncherModule module : modules) diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java index e65b913d..934e8518 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java @@ -114,7 +114,7 @@ public static URL[] getClassPathURL() { public static X509Certificate[] getCertificates(Class clazz) { Object[] signers = clazz.getSigners(); - if(signers == null) return new X509Certificate[] {}; + if(signers == null) return null; return Arrays.stream(signers).filter((c) -> c instanceof X509Certificate).map((c) -> (X509Certificate) c).toArray(X509Certificate[]::new); } diff --git a/LauncherCore/src/main/java/pro/gravit/utils/verify/LauncherTrustManager.java b/LauncherCore/src/main/java/pro/gravit/utils/verify/LauncherTrustManager.java new file mode 100644 index 00000000..2e1debbb --- /dev/null +++ b/LauncherCore/src/main/java/pro/gravit/utils/verify/LauncherTrustManager.java @@ -0,0 +1,88 @@ +package pro.gravit.utils.verify; + +import pro.gravit.utils.helper.LogHelper; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.SignatureException; +import java.security.cert.CertificateEncodingException; +import java.security.cert.CertificateException; +import java.security.cert.CertificateFactory; +import java.security.cert.X509Certificate; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +public class LauncherTrustManager { + private final X509Certificate[] trustSigners; + private final List trustCache = new ArrayList<>(); + + public LauncherTrustManager(X509Certificate[] trustSigners) { + this.trustSigners = trustSigners; + } + public LauncherTrustManager(byte[][] encodedCertificate) throws CertificateException { + CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); + trustSigners = Arrays.stream(encodedCertificate).map((cert) -> { + try(InputStream input = new ByteArrayInputStream(cert)) + { + return (X509Certificate) certFactory.generateCertificate(input); + } catch (IOException | CertificateException e) { + LogHelper.error(e); + return null; + } + }).toArray(X509Certificate[]::new); + } + public interface CertificateChecker + { + void check(X509Certificate cert, X509Certificate signer) throws CertificateException, SecurityException; + } + + public void checkCertificate(X509Certificate[] certs, CertificateChecker checker) throws CertificateException, NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyException, SignatureException { + if(certs == null) throw new SecurityException("Object not signed"); + for(int i=0;i< certs.length;++i) + { + X509Certificate cert = certs[i]; + if(trustCache.contains(cert)) + { + //Добавляем в кеш все проверенные сертификаты + for(int j=0;j < i;++j) + trustCache.add(certs[j]); + return; + } + X509Certificate signer = (i+1 < certs.length) ? certs[i+1] : null; + cert.checkValidity(); + if(signer != null) + { + cert.verify(signer.getPublicKey()); + } + else + { + if(!isTrusted(cert)) + { + throw new CertificateException(String.format("Certificate %s is not signed by a trusted signer", cert.getSubjectDN().getName())); + } + } + checker.check(cert, signer); + } + Collections.addAll(trustCache, certs); + } + public boolean isTrusted(X509Certificate certificate) throws CertificateEncodingException { + //Java API не дает возможности вызвать getFingerprint + //Oracle использует хак с кастом к sun.security.x509.X509CertImpl для проверки равенства сертификатов + //Мы пойдем более медленным путем + for(X509Certificate cert : trustSigners) + { + if(cert.getSerialNumber().equals(certificate.getSerialNumber()) //Проверка serialNumber (быстро) + && Arrays.equals(cert.getEncoded(), certificate.getEncoded())) //Полная проверка (медленно) + { + return true; + } + } + return false; + } +} From 4c1ba67c71b2488d48be846e54762e621b9ade93 Mon Sep 17 00:00:00 2001 From: Gravit Date: Thu, 17 Oct 2019 20:23:54 +0700 Subject: [PATCH 011/192] =?UTF-8?q?[ANY]=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index a770ac08..01bace9b 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit a770ac083f9e940122f888fa6ffd9e0485d3292b +Subproject commit 01bace9b86428588a5a6c96280913991911b3336 From 7c5616ef2b9ac7e9d56f38aa854cb9635be222e4 Mon Sep 17 00:00:00 2001 From: Gravit Date: Thu, 17 Oct 2019 20:29:28 +0700 Subject: [PATCH 012/192] =?UTF-8?q?[ANY]=20=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=85=D0=BB=D0=B0=D0=BC=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gravit/launcher/ssl/LauncherKeyStore.java | 19 --------- .../launcher/ssl/LauncherSSLContext.java | 42 ------------------- .../launcher/ssl/LauncherTrustManager.java | 15 ------- 3 files changed, 76 deletions(-) delete mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/ssl/LauncherKeyStore.java delete mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/ssl/LauncherSSLContext.java delete mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/ssl/LauncherTrustManager.java diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/ssl/LauncherKeyStore.java b/LauncherAPI/src/main/java/pro/gravit/launcher/ssl/LauncherKeyStore.java deleted file mode 100644 index fa3acb42..00000000 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/ssl/LauncherKeyStore.java +++ /dev/null @@ -1,19 +0,0 @@ -package pro.gravit.launcher.ssl; - -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.cert.CertificateException; - -public class LauncherKeyStore { - public static KeyStore getKeyStore(String keystore, String password) throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException { - KeyStore ks = KeyStore.getInstance("JKS"); - try (InputStream ksIs = new FileInputStream(keystore)) { - ks.load(ksIs, password.toCharArray()); - } - return ks; - } -} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/ssl/LauncherSSLContext.java b/LauncherAPI/src/main/java/pro/gravit/launcher/ssl/LauncherSSLContext.java deleted file mode 100644 index 40439578..00000000 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/ssl/LauncherSSLContext.java +++ /dev/null @@ -1,42 +0,0 @@ -package pro.gravit.launcher.ssl; - -import java.security.KeyManagementException; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.SecureRandom; -import java.security.UnrecoverableKeyException; - -import javax.net.ssl.KeyManagerFactory; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLServerSocketFactory; -import javax.net.ssl.SSLSocketFactory; -import javax.net.ssl.TrustManager; - -public class LauncherSSLContext { - public SSLServerSocketFactory ssf; - public SSLSocketFactory sf; - - public LauncherSSLContext(KeyStore ks, String keypassword) throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, KeyManagementException { - TrustManager[] trustAllCerts = new TrustManager[]{ - new LauncherTrustManager() - }; - KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory - .getDefaultAlgorithm()); - kmf.init(ks, keypassword.toCharArray()); - SSLContext sc = SSLContext.getInstance("TLSv1.2"); - sc.init(kmf.getKeyManagers(), trustAllCerts, new SecureRandom()); - ssf = sc.getServerSocketFactory(); - sf = sc.getSocketFactory(); - } - - public LauncherSSLContext() throws NoSuchAlgorithmException, KeyManagementException { - TrustManager[] trustAllCerts = new TrustManager[]{ - new LauncherTrustManager() - }; - SSLContext sc = SSLContext.getInstance("TLSv1.2"); - sc.init(null, trustAllCerts, new SecureRandom()); - ssf = null; - sf = sc.getSocketFactory(); - } -} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/ssl/LauncherTrustManager.java b/LauncherAPI/src/main/java/pro/gravit/launcher/ssl/LauncherTrustManager.java deleted file mode 100644 index 48389921..00000000 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/ssl/LauncherTrustManager.java +++ /dev/null @@ -1,15 +0,0 @@ -package pro.gravit.launcher.ssl; - -import javax.net.ssl.X509TrustManager; - -public class LauncherTrustManager implements X509TrustManager { - public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) { - } - - public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) { - } - - public java.security.cert.X509Certificate[] getAcceptedIssuers() { - return null; - } -} From d897a692f7dec9aefa122ff0f8a59b875904f3ce Mon Sep 17 00:00:00 2001 From: Gravit Date: Thu, 17 Oct 2019 20:58:52 +0700 Subject: [PATCH 013/192] =?UTF-8?q?[FIX]=20=D0=A4=D0=B8=D0=BA=D1=81=D1=8B?= =?UTF-8?q?=20=D1=81=D0=B8=D1=81=D1=82=D0=B5=D0=BC=D1=8B=20=D1=81=D0=B5?= =?UTF-8?q?=D1=80=D1=82=D0=B8=D1=84=D0=B8=D0=BA=D0=B0=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launchserver/LaunchServerStarter.java | 10 +++++-- .../manangers/CertificateManager.java | 30 +++++++++++++++---- .../handlers/NettyServerSocketHandler.java | 29 ------------------ .../modules/impl/SimpleModuleManager.java | 13 ++++++-- .../utils/verify/LauncherTrustManager.java | 6 ++++ 5 files changed, 48 insertions(+), 40 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java index a35e2116..e9619c7d 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java @@ -32,6 +32,7 @@ import pro.gravit.launchserver.manangers.LaunchServerGsonManager; import pro.gravit.launchserver.modules.impl.LaunchServerModulesManager; import pro.gravit.launchserver.socket.WebSocketService; +import pro.gravit.utils.Version; import pro.gravit.utils.command.CommandHandler; import pro.gravit.utils.command.JLineCommandHandler; import pro.gravit.utils.command.StdCommandHandler; @@ -41,9 +42,8 @@ import pro.gravit.utils.helper.SecurityHelper; import pro.gravit.utils.verify.LauncherTrustManager; -import javax.crypto.Cipher; - public class LaunchServerStarter { + public static boolean allowUnsigned = Boolean.getBoolean("launchserver.allowUnsigned"); public static void main(String[] args) throws Exception { JVMHelper.checkStackTrace(LaunchServerStarter.class); JVMHelper.verifySystemProperties(LaunchServer.class, true); @@ -67,6 +67,12 @@ public static void main(String[] args) throws Exception { } catch (CertificateException e) { throw new IOException(e); } + { + LauncherTrustManager.CheckMode mode = (Version.RELEASE == Version.Type.LTS || Version.RELEASE == Version.Type.STABLE) ? + (allowUnsigned ? LauncherTrustManager.CheckMode.WARN_IN_NOT_SIGNED : LauncherTrustManager.CheckMode.EXCEPTION_IN_NOT_SIGNED) : + (allowUnsigned ? LauncherTrustManager.CheckMode.NONE_IN_NOT_SIGNED : LauncherTrustManager.CheckMode.WARN_IN_NOT_SIGNED); + certificateManager.checkClass(LaunchServer.class, mode); + } LaunchServerRuntimeConfig runtimeConfig; LaunchServerConfig config; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/CertificateManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/CertificateManager.java index c6fafca8..69b76a4a 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/CertificateManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/CertificateManager.java @@ -8,12 +8,7 @@ import java.nio.file.Path; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; -import java.security.InvalidAlgorithmParameterException; -import java.security.KeyPair; -import java.security.KeyPairGenerator; -import java.security.NoSuchAlgorithmException; -import java.security.PrivateKey; -import java.security.PublicKey; +import java.security.*; import java.security.cert.CertificateException; import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; @@ -48,6 +43,8 @@ import org.bouncycastle.util.io.pem.PemWriter; import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.JVMHelper; +import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.SecurityHelper; import pro.gravit.utils.verify.LauncherTrustManager; @@ -207,4 +204,25 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO }, false); trustManager = new LauncherTrustManager(certificates.toArray(new X509Certificate[0])); } + + public void checkClass(Class clazz, LauncherTrustManager.CheckMode mode) throws SecurityException + { + if(trustManager == null) return; + X509Certificate[] certificates = JVMHelper.getCertificates(clazz); + if(certificates == null) + { + if(mode == LauncherTrustManager.CheckMode.EXCEPTION_IN_NOT_SIGNED) + throw new SecurityException(String.format("Class %s not signed", clazz.getName())); + else if(mode == LauncherTrustManager.CheckMode.WARN_IN_NOT_SIGNED) + LogHelper.warning("Class %s not signed", clazz.getName()); + return; + } + try { + trustManager.checkCertificate(certificates, (c,s) -> { + + }); + } catch (CertificateException | NoSuchProviderException | NoSuchAlgorithmException | InvalidKeyException | SignatureException e) { + throw new SecurityException(e); + } + } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/NettyServerSocketHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/NettyServerSocketHandler.java index f041aa39..329b3ca1 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/NettyServerSocketHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/NettyServerSocketHandler.java @@ -1,24 +1,9 @@ package pro.gravit.launchserver.socket.handlers; -import java.io.IOException; import java.net.InetSocketAddress; import java.net.Socket; -import java.security.KeyManagementException; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.SecureRandom; -import java.security.UnrecoverableKeyException; -import java.security.cert.CertificateException; import java.util.Set; - -import javax.net.ssl.KeyManagerFactory; -import javax.net.ssl.SSLContext; import javax.net.ssl.SSLServerSocketFactory; -import javax.net.ssl.TrustManager; - -import pro.gravit.launcher.ssl.LauncherKeyStore; -import pro.gravit.launcher.ssl.LauncherTrustManager; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.config.LaunchServerConfig; import pro.gravit.launchserver.socket.LauncherNettyServer; @@ -46,20 +31,6 @@ public void close() { //TODO: Close Impl } - public SSLContext SSLContextInit() throws NoSuchAlgorithmException, UnrecoverableKeyException, KeyStoreException, KeyManagementException, IOException, CertificateException { - TrustManager[] trustAllCerts = new TrustManager[]{ - new LauncherTrustManager() - }; - KeyStore ks = LauncherKeyStore.getKeyStore("keystore", "PSP1000"); - - KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory - .getDefaultAlgorithm()); - kmf.init(ks, "PSP1000".toCharArray()); - SSLContext sc = SSLContext.getInstance("TLSv1.2"); - sc.init(kmf.getKeyManagers(), trustAllCerts, new SecureRandom()); - return sc; - } - @Override public void run() { /*SSLContext sc = null; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java index 08c9d1c3..81847cd2 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java @@ -40,6 +40,7 @@ public class SimpleModuleManager implements LauncherModulesManager { protected final Path modulesDir; protected final LauncherTrustManager trustManager; protected LauncherInitContext initContext; + protected LauncherTrustManager.CheckMode checkMode = LauncherTrustManager.CheckMode.WARN_IN_NOT_SIGNED; protected PublicURLClassLoader classLoader = new PublicURLClassLoader(new URL[]{}); @@ -160,7 +161,7 @@ public LauncherModule loadModule(Path file) throws IOException { classLoader.addURL(file.toUri().toURL()); @SuppressWarnings("unchecked cast") Class clazz = (Class) Class.forName(moduleClass, false, classLoader); - checkModuleClass(clazz); + checkModuleClass(clazz, checkMode); LauncherModule module = clazz.newInstance(); loadModule(module); return module; @@ -171,13 +172,19 @@ public LauncherModule loadModule(Path file) throws IOException { } } - protected void checkModuleClass(Class clazz) throws SecurityException + + + public void checkModuleClass(Class clazz, LauncherTrustManager.CheckMode mode) throws SecurityException { if(trustManager == null) return; X509Certificate[] certificates = JVMHelper.getCertificates(clazz); if(certificates == null) { - LogHelper.warning("Module class %s not signed", clazz.getName()); + if(mode == LauncherTrustManager.CheckMode.EXCEPTION_IN_NOT_SIGNED) + throw new SecurityException(String.format("Class %s not signed", clazz.getName())); + else if(mode == LauncherTrustManager.CheckMode.WARN_IN_NOT_SIGNED) + LogHelper.warning("Class %s not signed", clazz.getName()); + return; } try { trustManager.checkCertificate(certificates, (c,s) -> { diff --git a/LauncherCore/src/main/java/pro/gravit/utils/verify/LauncherTrustManager.java b/LauncherCore/src/main/java/pro/gravit/utils/verify/LauncherTrustManager.java index 2e1debbb..3cfe00b5 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/verify/LauncherTrustManager.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/verify/LauncherTrustManager.java @@ -37,6 +37,12 @@ public LauncherTrustManager(byte[][] encodedCertificate) throws CertificateExcep } }).toArray(X509Certificate[]::new); } + + public enum CheckMode + { + EXCEPTION_IN_NOT_SIGNED, WARN_IN_NOT_SIGNED, NONE_IN_NOT_SIGNED + } + public interface CertificateChecker { void check(X509Certificate cert, X509Certificate signer) throws CertificateException, SecurityException; From cd1a9718de221e2607dccc373e225a256c42975e Mon Sep 17 00:00:00 2001 From: Zaxar163 <35835496+Zaxar163@users.noreply.github.com> Date: Thu, 17 Oct 2019 16:37:05 +0200 Subject: [PATCH 014/192] =?UTF-8?q?[FEATURE]=20=D0=A4=D0=B8=D0=BA=D1=81=20?= =?UTF-8?q?ForgeSM=20=D1=87=D0=B5=D1=80=D0=B5=D0=B7=20=D0=B0=D0=B3=D0=B5?= =?UTF-8?q?=D0=BD=D1=82.=20(#342)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [FEATURE] Фикс завершения работы через агент... Патчим класс форжового SM * [ANY] Обновлены модули. * [FIX] Возможность модулям определить, запущены ли они после старта клиента. * [FIX] Ошибка компиляции. * [FIX] Ещё 1 способ System.exit в обход SecurityManager. * [FIX] Фикс патча asm. * [FIX] FMLPatcher работает! * [ANY] Обновлены модули. * [FIX] Немного finalа... * [ANY] Обновлены модули. * [ANY] Обновлены модули --- .../pro/gravit/launcher/LauncherAgent.java | 8 +- .../pro/gravit/launcher/LauncherEngine.java | 1 + .../launcher/client/ClientLauncher.java | 3 +- .../gravit/launcher/patches/FMLPatcher.java | 106 ++++++++++++++++++ .../gravit/launcher/utils/NativeJVMHalt.java | 32 +++++- .../java/cpw/mods/fml/SafeExitJVMLegacy.java | 11 -- .../net/minecraftforge/fml/SafeExitJVM.java | 11 -- 7 files changed, 138 insertions(+), 34 deletions(-) create mode 100644 Launcher/src/main/java/pro/gravit/launcher/patches/FMLPatcher.java delete mode 100644 LauncherAuthlib/src/main/java/cpw/mods/fml/SafeExitJVMLegacy.java delete mode 100644 LauncherAuthlib/src/main/java/net/minecraftforge/fml/SafeExitJVM.java diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherAgent.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherAgent.java index 317bd48a..a86ac483 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherAgent.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherAgent.java @@ -6,6 +6,8 @@ import java.nio.file.Path; import java.util.jar.JarFile; +import pro.gravit.launcher.patches.FMLPatcher; +import pro.gravit.launcher.utils.NativeJVMHalt; import pro.gravit.utils.helper.LogHelper; @LauncherAPI @@ -31,10 +33,8 @@ public static void premain(String agentArgument, Instrumentation instrumentation System.out.println("Launcher Agent"); checkAgentStacktrace(); inst = instrumentation; - //SafeExitJVMLegacy.class.getName(); - //SafeExitJVM.class.getName(); - //NativeJVMHalt.class.getName(); - //NativeJVMHalt.initFunc(); + NativeJVMHalt.initFunc(); + FMLPatcher.apply(); isAgentStarted = true; } public static void checkAgentStacktrace() diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index 8b538ea2..38fd00b8 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -31,6 +31,7 @@ import javax.crypto.Cipher; public class LauncherEngine { + public static final AtomicBoolean IS_CLIENT = new AtomicBoolean(false); public static void main(String... args) throws Throwable { JVMHelper.checkStackTrace(LauncherEngine.class); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index d1e90194..7bfba319 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -442,13 +442,12 @@ public ClientLaunchContext(Params params, ClientProfile profile, HashedDir asset @LauncherAPI public static void main(String... args) throws Throwable { + LauncherEngine.IS_CLIENT.set(true); LauncherEngine engine = LauncherEngine.clientInstance(); - //Launcher.modulesManager = new ClientModuleManager(engine); LauncherEngine.modulesManager = new ClientModuleManager(); LauncherConfig.getAutogenConfig().initModules(); //INIT LauncherEngine.modulesManager.initModules(null); initGson(LauncherEngine.modulesManager); - //Launcher.modulesManager.preInitModules(); if (!LauncherAgent.isStarted()) { NativeJVMHalt.haltA(100); return; diff --git a/Launcher/src/main/java/pro/gravit/launcher/patches/FMLPatcher.java b/Launcher/src/main/java/pro/gravit/launcher/patches/FMLPatcher.java new file mode 100644 index 00000000..a5a8978d --- /dev/null +++ b/Launcher/src/main/java/pro/gravit/launcher/patches/FMLPatcher.java @@ -0,0 +1,106 @@ +package pro.gravit.launcher.patches; + +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; +import java.nio.ByteBuffer; +import java.util.Random; +import java.util.Vector; + +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.Label; +import org.objectweb.asm.MethodVisitor; +import org.objectweb.asm.Opcodes; + +import pro.gravit.utils.helper.SecurityHelper; + +public class FMLPatcher extends ClassLoader implements Opcodes { + public static final MethodType EXITMH = MethodType.methodType(void.class, int.class); + public static volatile FMLPatcher INSTANCE = null; + public static final String[] PACKAGES = new String[] { "cpw.mods.fml.", "net.minecraftforge.fml.", "cpw.mods." }; + public static final Vector MHS = new Vector<>(); + + public static void apply() { + INSTANCE = new FMLPatcher(ClassLoader.getSystemClassLoader()); + for (String s : PACKAGES) { + String rMethod = randomStr(16); + try { + MHS.add(MethodHandles.publicLookup().findStatic(INSTANCE.def(s + randomStr(16), rMethod), rMethod, + EXITMH)); + } catch (NoSuchMethodException | IllegalAccessException e) { + // Simple ignore - other Forge + } + } + } + + public static void exit(final int code) throws Throwable { + for (MethodHandle mh : MHS) + try { + mh.invoke(code); + } catch (Throwable ignored) { + } + } + + private static byte[] gen(final String name, final String exName) { // "cpw/mods/fml/SafeExitJVMLegacy", "exit" + + final ClassWriter classWriter = new ClassWriter(0); + MethodVisitor methodVisitor; + + classWriter.visit(V1_8, ACC_PUBLIC | ACC_SUPER, name, null, "java/lang/Object", null); + + { + methodVisitor = classWriter.visitMethod(ACC_PUBLIC, "", "()V", null, null); + methodVisitor.visitCode(); + methodVisitor.visitVarInsn(ALOAD, 0); + methodVisitor.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "", "()V", false); + methodVisitor.visitInsn(RETURN); + methodVisitor.visitMaxs(1, 1); + methodVisitor.visitEnd(); + } + { + methodVisitor = classWriter.visitMethod(ACC_PUBLIC | ACC_STATIC, exName, "(I)V", null, null); + methodVisitor.visitCode(); + final Label label0 = new Label(); + final Label label1 = new Label(); + final Label label2 = new Label(); + methodVisitor.visitTryCatchBlock(label0, label1, label2, "java/lang/Throwable"); + methodVisitor.visitLabel(label0); + methodVisitor.visitMethodInsn(INVOKESTATIC, "java/lang/Runtime", "getRuntime", "()Ljava/lang/Runtime;", + false); + methodVisitor.visitVarInsn(ILOAD, 0); + methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Runtime", "halt", "(I)V", false); + methodVisitor.visitLabel(label1); + final Label label3 = new Label(); + methodVisitor.visitJumpInsn(GOTO, label3); + methodVisitor.visitLabel(label2); + methodVisitor.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/Throwable" }); + methodVisitor.visitVarInsn(ASTORE, 1); + methodVisitor.visitVarInsn(ILOAD, 0); + methodVisitor.visitMethodInsn(INVOKESTATIC, "java/lang/System", "exit", "(I)V", false); + methodVisitor.visitLabel(label3); + methodVisitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null); + methodVisitor.visitInsn(RETURN); + methodVisitor.visitMaxs(2, 2); + methodVisitor.visitEnd(); + } + classWriter.visitEnd(); + return classWriter.toByteArray(); + } + + public static String randomStr(final int lenght) { + final String alphabet = "abcdefghijklmnopqrstuvwxyz"; + final StringBuilder sb = new StringBuilder(lenght); + final Random random = SecurityHelper.newRandom(); + for (int i = 0; i < lenght; i++) + sb.append(alphabet.charAt(random.nextInt(26))); + return sb.toString(); + } + + public FMLPatcher(final ClassLoader cl) { + super(cl); + } + + public Class def(final String name, final String exName) { + return super.defineClass(name, ByteBuffer.wrap(gen(name.replace('.', '/'), exName)), null); + } +} diff --git a/Launcher/src/main/java/pro/gravit/launcher/utils/NativeJVMHalt.java b/Launcher/src/main/java/pro/gravit/launcher/utils/NativeJVMHalt.java index 14fa7a04..d2d248a7 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/utils/NativeJVMHalt.java +++ b/Launcher/src/main/java/pro/gravit/launcher/utils/NativeJVMHalt.java @@ -1,7 +1,12 @@ package pro.gravit.launcher.utils; -import cpw.mods.fml.SafeExitJVMLegacy; -import net.minecraftforge.fml.SafeExitJVM; +import java.awt.event.WindowEvent; + +import javax.swing.JFrame; +import javax.swing.WindowConstants; + +import pro.gravit.launcher.patches.FMLPatcher; +import pro.gravit.utils.helper.JVMHelper; public final class NativeJVMHalt { public NativeJVMHalt(int haltCode) { @@ -21,19 +26,34 @@ private boolean aaabBooleanC_D() { public static void haltA(int code) { NativeJVMHalt halt = new NativeJVMHalt(code); try { - SafeExitJVMLegacy.exit(code); + JVMHelper.RUNTIME.exit(code); } catch (Throwable ignored) { + try { + new WindowShutdown(); + } catch (Throwable ignored1) { + } } try { - SafeExitJVM.exit(code); - } catch (Throwable ignored) { - } + FMLPatcher.exit(code); + } catch (Throwable ignored) { } + halt.aaabbb38C_D(); boolean a = halt.aaabBooleanC_D(); System.out.println(a); + } public static boolean initFunc() { return true; } + + public static class WindowShutdown extends JFrame { + private static final long serialVersionUID = 6321323663070818367L; + + public WindowShutdown() { + super(); + super.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + super.processWindowEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING)); + } + } } diff --git a/LauncherAuthlib/src/main/java/cpw/mods/fml/SafeExitJVMLegacy.java b/LauncherAuthlib/src/main/java/cpw/mods/fml/SafeExitJVMLegacy.java deleted file mode 100644 index 76673b94..00000000 --- a/LauncherAuthlib/src/main/java/cpw/mods/fml/SafeExitJVMLegacy.java +++ /dev/null @@ -1,11 +0,0 @@ -package cpw.mods.fml; - -import pro.gravit.utils.helper.JVMHelper; - -// FMLSecurityManager запрещает делать System.exit из классов -// Не входящих в пакеты самого Forge -public class SafeExitJVMLegacy { - public static void exit(int code) { - JVMHelper.RUNTIME.halt(code); - } -} diff --git a/LauncherAuthlib/src/main/java/net/minecraftforge/fml/SafeExitJVM.java b/LauncherAuthlib/src/main/java/net/minecraftforge/fml/SafeExitJVM.java deleted file mode 100644 index 448ff164..00000000 --- a/LauncherAuthlib/src/main/java/net/minecraftforge/fml/SafeExitJVM.java +++ /dev/null @@ -1,11 +0,0 @@ -package net.minecraftforge.fml; - -import pro.gravit.utils.helper.JVMHelper; - -// FMLSecurityManager запрещает делать System.exit из классов -// Не входящих в пакеты самого Forge -public class SafeExitJVM { - public static void exit(int code) { - JVMHelper.RUNTIME.halt(code); - } -} From 05d5b72d05eddfaf5d94a9f706aa0f816330de53 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Thu, 17 Oct 2019 18:14:03 +0200 Subject: [PATCH 015/192] =?UTF-8?q?[ANY]=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B8?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index 01bace9b..3417974a 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 01bace9b86428588a5a6c96280913991911b3336 +Subproject commit 3417974a1e903115c27b5b2b51bd43c7bbd877d1 From bcbc46238ce5491a6cbd76e6eb2f4bbab3307470 Mon Sep 17 00:00:00 2001 From: Gravit Date: Fri, 18 Oct 2019 19:10:04 +0700 Subject: [PATCH 016/192] [FEATURE] SecureAutogenConfig --- .../command/basic/TestCommand.java | 6 +++ .../pro/gravit/launcher/LauncherEngine.java | 6 --- .../launcher/client/ClientModuleManager.java | 12 ++++- .../pro/gravit/launcher/LauncherConfig.java | 11 +++++ .../gravit/launcher/SecureAutogenConfig.java | 44 +++++++++++++++++++ .../gravit/launcher/hwid/HWIDCheckHelper.java | 11 +++-- .../gravit/utils/helper/SecurityHelper.java | 7 +-- 7 files changed, 81 insertions(+), 16 deletions(-) create mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/SecureAutogenConfig.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/basic/TestCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/basic/TestCommand.java index 6f7fd287..4511a8d9 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/basic/TestCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/basic/TestCommand.java @@ -5,10 +5,12 @@ import org.bouncycastle.cert.X509CertificateHolder; +import pro.gravit.launcher.hwid.HWIDCheckHelper; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.command.Command; import pro.gravit.launchserver.socket.handlers.NettyServerSocketHandler; import pro.gravit.utils.helper.CommonHelper; +import pro.gravit.utils.helper.LogHelper; public class TestCommand extends Command { public TestCommand(LaunchServer server) { @@ -55,5 +57,9 @@ public void invoke(String... args) throws Exception { server.certificateManager.writePrivateKey(Paths.get(name.concat(".key")), pair.getPrivate()); server.certificateManager.writeCertificate(Paths.get(name.concat(".crt")), cert); } + if(args[0].equals("hwidcheck")) + { + LogHelper.info("HWID String %s bad rating %d", args[1], HWIDCheckHelper.checkString(args[1])); + } } } diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index 38fd00b8..17f36147 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -40,12 +40,6 @@ public static void main(String... args) throws Throwable { //if(!LauncherAgent.isStarted()) throw new SecurityException("JavaAgent not set"); LogHelper.printVersion("Launcher"); LogHelper.printLicense("Launcher"); - try { - Security.addProvider(new BouncyCastleProvider()); - } catch (Exception ignored) - { - LogHelper.warning("BouncyCastle not found"); - } LauncherEngine.modulesManager = new ClientModuleManager(); LauncherConfig.getAutogenConfig().initModules(); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientModuleManager.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientModuleManager.java index a5f6343f..1d5ba556 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientModuleManager.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientModuleManager.java @@ -4,12 +4,15 @@ import java.nio.file.Path; import java.util.Collection; +import pro.gravit.launcher.Launcher; import pro.gravit.launcher.modules.LauncherModule; import pro.gravit.launcher.modules.impl.SimpleModuleManager; +import pro.gravit.utils.verify.LauncherTrustManager; public class ClientModuleManager extends SimpleModuleManager { public ClientModuleManager() { - super(null, null); + super(null, null, Launcher.getConfig().trustManager); + checkMode = LauncherTrustManager.CheckMode.EXCEPTION_IN_NOT_SIGNED; } @Override @@ -26,6 +29,13 @@ public void autoload(Path dir) throws IOException { public LauncherModule loadModule(Path file) throws IOException { throw new UnsupportedOperationException(); } + + @Override + public LauncherModule loadModule(LauncherModule module) { + checkModuleClass(module.getClass(), LauncherTrustManager.CheckMode.EXCEPTION_IN_NOT_SIGNED); + return super.loadModule(module); + } + public void callWrapper(ProcessBuilder processBuilder, Collection jvmArgs) { for(LauncherModule module : modules) diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java b/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java index 6b012e79..9dc70fb4 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java @@ -1,6 +1,7 @@ package pro.gravit.launcher; import java.io.IOException; +import java.security.cert.CertificateException; import java.security.interfaces.ECPrivateKey; import java.security.interfaces.ECPublicKey; import java.security.interfaces.RSAPublicKey; @@ -16,9 +17,11 @@ import pro.gravit.launcher.serialize.stream.StreamObject; import pro.gravit.utils.helper.SecurityHelper; import pro.gravit.utils.helper.VerifyHelper; +import pro.gravit.utils.verify.LauncherTrustManager; public final class LauncherConfig extends StreamObject { private static final AutogenConfig config = new AutogenConfig(); + private static final SecureAutogenConfig secureConfig = new SecureAutogenConfig(); public static AutogenConfig getAutogenConfig() { @@ -32,6 +35,7 @@ public static AutogenConfig getAutogenConfig() { public final int clientPort; public String secretKeyClient; public String oemUnlockKey; + public final LauncherTrustManager trustManager; @LauncherAPI public final ECPublicKey publicKey; @@ -60,6 +64,11 @@ public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException clientPort = config.clientPort; secretKeyClient = config.secretKeyClient; oemUnlockKey = config.oemUnlockKey; + try { + trustManager = new LauncherTrustManager(secureConfig.certificates); + } catch (CertificateException e) { + throw new IOException(e); + } isWarningMissArchJava = config.isWarningMissArchJava; guardLicenseEncryptKey = config.guardLicenseEncryptKey; @@ -104,6 +113,7 @@ public LauncherConfig(String address, ECPublicKey publicKey, Map secureCheckSalt = null; secureCheckHash = null; passwordEncryptKey = null; + trustManager = null; } @LauncherAPI @@ -123,6 +133,7 @@ public LauncherConfig(String address, ECPublicKey publicKey, Map secureCheckSalt = null; secureCheckHash = null; passwordEncryptKey = null; + trustManager = null; } @Override diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/SecureAutogenConfig.java b/LauncherAPI/src/main/java/pro/gravit/launcher/SecureAutogenConfig.java new file mode 100644 index 00000000..2d971a4e --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/SecureAutogenConfig.java @@ -0,0 +1,44 @@ +package pro.gravit.launcher; + +public class SecureAutogenConfig { + public byte[][] certificates; + + public SecureAutogenConfig() { + //Пока не реализован SecureLauncherConfigurator + certificates = new byte[][] { + ("-----BEGIN CERTIFICATE-----\n" + + "MIIFyjCCA7KgAwIBAgIRALnsjNjfvOTXfla3fX1fNEUwDQYJKoZIhvcNAQELBQAw\n" + + "WTELMAkGA1UEBhMCUlUxFzAVBgNVBAoTDkdyYXZpdFRydXN0IENBMRAwDgYDVQQL\n" + + "EwdSb290IENBMR8wHQYDVQQDExZHcmF2aXQgQ2VudHJhbCBSb290IENBMCAXDTE5\n" + + "MDYwOTAyNDIwMFoYDzIwNTEwNjA5MDI0MjAwWjBZMQswCQYDVQQGEwJSVTEXMBUG\n" + + "A1UEChMOR3Jhdml0VHJ1c3QgQ0ExEDAOBgNVBAsTB1Jvb3QgQ0ExHzAdBgNVBAMT\n" + + "FkdyYXZpdCBDZW50cmFsIFJvb3QgQ0EwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAw\n" + + "ggIKAoICAQDA3Qm9OH8Xz3YM3bKkZuQI7T/aL3ulMOdY5GFADYgHrOVZXVSJi/4P\n" + + "PruBsut4WXN6TGQdpJtNZ2kyWTYzENGTm/TMzBcIchor1M3JW5Uv/C0r5gSEU1uP\n" + + "DPe7oEpeKtb3FXML/pGoGpLv/sonTKky4AKZnK7B15bZ+oVZNwh7UKANpNrVA8k5\n" + + "0gb4BisFcegLidYL9Y00H1x5WzUxldQAA1IQuwdkL3NP0NPQrSVJ2Ka2EtebE2HP\n" + + "fXHtbftvvnvSWyh4CXAxTfEmJgut0gSPQPm9wVt6pIWWd4O0hHwVmxkKQidgnP6A\n" + + "+d05FnJGsBw0ztMCifIteqNiHF0D8E0GuSz6NtcuV47J3p43qkvKr2vPc8o6WMN8\n" + + "PAb0eVHc/AX8qqOwYQyHlj4M0SDhCltHeeYRWmuZmRFIIelv6VAocaQLlPQrhJNp\n" + + "feIzmXLy60a+84vpe/eQKQx+D8a1elarQkoHMxI7x/9AJvxcnJ4KuXc2rkiu3Zv9\n" + + "KMhixtkLc+pA6jY023U211v+c20RjTqwKIZoMFc7BZipoinAOn1bdsTzXlhOMv1O\n" + + "zj5WoW6DsQQONMZNyLQAkaX6SYZE/kQVJ9YMPhNdaXjxxzfrY05IrWAaWhtPbW8z\n" + + "5nb4/JyO+bJq3v2rav9p03s8P/lQ4k/0af5vOkGkEO0+YKx97ZP8FQIDAQABo4GK\n" + + "MIGHMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFFjMGCvHXAE/vGJih+Lfdo2s\n" + + "YnzsMAsGA1UdDwQEAwIBBjA1BgNVHR8ELjAsMCqgKKAmhiRodHRwOi8vY2EuZ3Jh\n" + + "dml0LnByby9jZW50cmFscm9vdC5jcmwwEQYJYIZIAYb4QgEBBAQDAgAHMA0GCSqG\n" + + "SIb3DQEBCwUAA4ICAQAexCGpThx85skEllva1UskmdlRh3rud9u59AUiwNZF0b0I\n" + + "+7eeyLNaLHarg2Zm30TSCF53ksyPTE5QNdmozs1fl3MddFqunkbUm4G6hwedZMSi\n" + + "4IXIb2QK3z3gZG5ZNdHaDG2u00Jdkc39h3jQFp1rpn4+0DcnYJAe+lw5G+XHURY2\n" + + "j15wcmUFp/Ywgw3pfCWmH5+rxq21e/LG8JiQrxekkFI2GUD+Qw7+Hq3o1Fgg3kfh\n" + + "Lg4B5WEbEICQ1FC+dHYHasEI3q3c96Qpqu2k3pO0l1fr6Cys+AGjoI2WrgXkGlmA\n" + + "F+Wi2ndoZbvspGAwxmrNMtLE3OYNuMXFF410QSPf4o9QqpGDC3a2mccTXb231a18\n" + + "5vDJixeZpuzEm5ECXg8j6aj53X3rtm7C8yfOsg5UTKJJj+pSNz4YTp91IDHm0nTP\n" + + "2KhrgS7jujgKdJn9xv07e/API3kLWkVmMwHBiaSCIaHOfAN0RJMQVV+YgnSp2sIa\n" + + "OATWgSKH0qTkleE/v7k+USs0a+KV8wmC5wwliqH+uLO++yIP/9bjDctyLulQX5Ee\n" + + "+EhD7tb1R/yyWY4uhkzlsr3N2Kl34aQAEBMn8Z1mHsyyu1FcbEaNLU8jcS3pHPVM\n" + + "gQRn3m1iDnQlFciAMxW0pW6mW/4xKYzhXk5BTSolnqMVylxHgWXuBwdDDQQVnQ==\n" + + "-----END CERTIFICATE-----").getBytes() + }; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWIDCheckHelper.java b/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWIDCheckHelper.java index 79052ed7..9bac200f 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWIDCheckHelper.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWIDCheckHelper.java @@ -1,5 +1,7 @@ package pro.gravit.launcher.hwid; +import pro.gravit.utils.helper.LogHelper; + public class HWIDCheckHelper { public static int checkString(String str) { @@ -18,16 +20,15 @@ public static int checkString(String str) if(c == lastChar || Math.abs(c - lastChar) == 1 || ( ( lastChar == '0' || lastChar == '9' ) && ( c == 'A' || c == 'a' ))) //Переход с 0 или 9 на A или a { - lastChar = c; combo++; } else { - if(maxCombo < combo) - maxCombo = combo; - lastChar = c; combo = 1; } + lastChar = c; + if(maxCombo < combo) + maxCombo = combo; int charType = getCharType(c); if(lastCharType == charType) { lastCharTypeCombo++; @@ -56,6 +57,8 @@ public static int checkString(String str) } } //Считаем результат + LogHelper.debug("HWID Checker maxCombo %d", maxCombo); + LogHelper.debug("HWID Checker wtfCharTypeCombo %d", wtfCharTypeCombo); if(maxCombo > 3) result+= maxCombo * 3; if(wtfCharTypeCombo > 1) result+= wtfCharTypeCombo * 2; return result; diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/SecurityHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/SecurityHelper.java index 9f63f46a..23acb73e 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/SecurityHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/SecurityHelper.java @@ -19,9 +19,6 @@ import javax.crypto.NoSuchPaddingException; import javax.crypto.SecretKey; import javax.crypto.spec.SecretKeySpec; - -import org.bouncycastle.jce.provider.BouncyCastleProvider; -import org.bouncycastle.jce.provider.JCEIESCipher; import pro.gravit.launcher.LauncherAPI; public final class SecurityHelper { @@ -187,8 +184,8 @@ private static Cipher newCipher(String algo) { */ private static Cipher newBCCipher(String algo) { try { - return Cipher.getInstance(algo, new BouncyCastleProvider()); - } catch (NoSuchAlgorithmException | NoSuchPaddingException e) { + return Cipher.getInstance(algo, "BC"); + } catch (NoSuchAlgorithmException | NoSuchPaddingException | NoSuchProviderException e) { throw new InternalError(e); } } From d33fe0e6d096ccbe024d0fe8c5883a65477650ab Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Fri, 18 Oct 2019 15:59:11 +0200 Subject: [PATCH 017/192] =?UTF-8?q?[FIX]=20Forge=201.14=20+=20[FEATURE]=20?= =?UTF-8?q?String=20split=20=D0=B4=D0=BB=D1=8F=20asm.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gravit/launchserver/asm/NodeUtils.java | 71 ++++++++++++++++--- .../gravit/launcher/patches/FMLPatcher.java | 2 +- 2 files changed, 63 insertions(+), 10 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/NodeUtils.java b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/NodeUtils.java index 90ed2754..c669f763 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/NodeUtils.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/NodeUtils.java @@ -2,19 +2,13 @@ import java.io.IOException; import java.io.InputStream; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.Type; -import org.objectweb.asm.tree.AbstractInsnNode; -import org.objectweb.asm.tree.AnnotationNode; -import org.objectweb.asm.tree.ClassNode; -import org.objectweb.asm.tree.InvokeDynamicInsnNode; -import org.objectweb.asm.tree.LdcInsnNode; -import org.objectweb.asm.tree.MethodInsnNode; -import org.objectweb.asm.tree.MethodNode; +import org.objectweb.asm.*; +import org.objectweb.asm.tree.*; import pro.gravit.utils.helper.IOHelper; @@ -166,4 +160,63 @@ public static int opcodeEmulation(AbstractInsnNode e) { } return stackSize; } + + public static InsnList getSafeStringInsnList(String string) { + InsnList insnList = new InsnList(); + if (string.length() * 2 < MAX_SAFE_BYTE_COUNT) { + insnList.add(new LdcInsnNode(string)); + return insnList; + } + + insnList.add(new TypeInsnNode(NEW, "java/lang/StringBuilder")); + insnList.add(new InsnNode(DUP)); + insnList.add(new MethodInsnNode(INVOKESPECIAL, "java/lang/StringBuilder", "", "()V", false)); + + String[] chunks = splitUtf8ToChunks(string, MAX_SAFE_BYTE_COUNT); + for (String chunk : chunks) { + insnList.add(new LdcInsnNode(chunk)); + insnList.add(new MethodInsnNode(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false)); + } + insnList.add(new MethodInsnNode(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false)); + + return insnList; + } + + public static final int MAX_SAFE_BYTE_COUNT = 65535-Byte.MAX_VALUE; + + public static String[] splitUtf8ToChunks(String text, int maxBytes) { + List parts = new ArrayList<>(); + + char[] chars = text.toCharArray(); + + int lastCharIndex = 0; + int currentChunkSize = 0; + + for (int i = 0; i < chars.length; i++) { + char c = chars[i]; + int charSize = getUtf8CharSize(c); + if (currentChunkSize + charSize < maxBytes) { + currentChunkSize += charSize; + } else { + parts.add(text.substring(lastCharIndex, i)); + currentChunkSize = 0; + lastCharIndex = i; + } + } + + if (currentChunkSize != 0) { + parts.add(text.substring(lastCharIndex)); + } + + return parts.toArray(new String[0]); + } + + public static int getUtf8CharSize(char c) { + if (c >= 0x0001 && c <= 0x007F) { + return 1; + } else if (c <= 0x07FF) { + return 2; + } + return 3; + } } diff --git a/Launcher/src/main/java/pro/gravit/launcher/patches/FMLPatcher.java b/Launcher/src/main/java/pro/gravit/launcher/patches/FMLPatcher.java index a5a8978d..0e060700 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/patches/FMLPatcher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/patches/FMLPatcher.java @@ -21,7 +21,7 @@ public class FMLPatcher extends ClassLoader implements Opcodes { public static final Vector MHS = new Vector<>(); public static void apply() { - INSTANCE = new FMLPatcher(ClassLoader.getSystemClassLoader()); + INSTANCE = new FMLPatcher(null); // Never cause ClassFormatError (fuck forge 1.14!!!) for (String s : PACKAGES) { String rMethod = randomStr(16); try { From 96d8883ecbc9300c8f4b7306021a7651c600369b Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Fri, 18 Oct 2019 16:16:06 +0200 Subject: [PATCH 018/192] =?UTF-8?q?[FEATURE]=20=D0=9F=D0=B5=D1=80=D0=B5?= =?UTF-8?q?=D0=B4=D0=B5=D0=BB=D1=8B=D0=B2=D0=B0=D1=8E=20=D0=B3=D0=B5=D0=BD?= =?UTF-8?q?=D0=B5=D1=80=D0=B0=D1=82=D0=BE=D1=80=20=D0=BA=D0=BE=D0=BD=D1=84?= =?UTF-8?q?=D0=B8=D0=B3=D0=B0,=20=D1=87=D0=B0=D1=81=D1=82=D1=8C=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launchserver/asm/ConfigGenerator.java | 66 +++++++++++++++++ .../gravit/launchserver/asm/NodeUtils.java | 16 ++++- .../binary/LauncherConfigurator.java | 72 ++----------------- 3 files changed, 86 insertions(+), 68 deletions(-) create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/asm/ConfigGenerator.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ConfigGenerator.java b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ConfigGenerator.java new file mode 100644 index 00000000..20854354 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ConfigGenerator.java @@ -0,0 +1,66 @@ +package pro.gravit.launchserver.asm; + +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.Opcodes; +import org.objectweb.asm.Type; +import org.objectweb.asm.tree.ClassNode; +import org.objectweb.asm.tree.FieldInsnNode; +import org.objectweb.asm.tree.InsnList; +import org.objectweb.asm.tree.InsnNode; +import org.objectweb.asm.tree.LdcInsnNode; +import org.objectweb.asm.tree.MethodInsnNode; +import org.objectweb.asm.tree.MethodNode; +import org.objectweb.asm.tree.VarInsnNode; + +public class ConfigGenerator { + protected static final String stringDesc = Type.getDescriptor(String.class); + protected final ClassNode configclass; + protected final MethodNode constructor; + + public ConfigGenerator(ClassNode configclass) { + this.configclass = configclass; + constructor = this.configclass.methods.stream().filter(e -> "".equals(e.name)).findFirst().get(); + constructor.instructions = new InsnList(); + constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); + constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, Type.getInternalName(Object.class), "", "()V")); + } + + public byte[] getBytecode(ClassMetadataReader reader) { + constructor.instructions.add(new InsnNode(Opcodes.RETURN)); + ClassWriter cw = new SafeClassWriter(reader, ClassWriter.COMPUTE_FRAMES); + configclass.accept(cw); + return cw.toByteArray(); + } + + public String getZipEntryPath() { + return configclass.name.concat(".class"); + } + + public void setStringField(String name, String value) + { + constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); + constructor.instructions.add(NodeUtils.getSafeStringInsnList(value)); + constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, configclass.name, name, stringDesc)); + } + + public void setIntegerField(String name, int value) + { + constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); + constructor.instructions.add(NodeUtils.push(value)); + constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, configclass.name, name, Type.INT_TYPE.getInternalName())); + } + + public void setLongField(String name, long value) + { + constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); + constructor.instructions.add(new LdcInsnNode(value)); + constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, configclass.name, name, Type.INT_TYPE.getInternalName())); + } + + public void setBooleanField(String name, boolean b) + { + constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); + constructor.instructions.add(new InsnNode(b ? Opcodes.ICONST_1 : Opcodes.ICONST_0)); + constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, configclass.name, name, Type.BOOLEAN_TYPE.getInternalName())); + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/NodeUtils.java b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/NodeUtils.java index c669f763..13e80273 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/NodeUtils.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/NodeUtils.java @@ -2,7 +2,6 @@ import java.io.IOException; import java.io.InputStream; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -163,7 +162,7 @@ public static int opcodeEmulation(AbstractInsnNode e) { public static InsnList getSafeStringInsnList(String string) { InsnList insnList = new InsnList(); - if (string.length() * 2 < MAX_SAFE_BYTE_COUNT) { + if ((string.length() * 3) < MAX_SAFE_BYTE_COUNT) { // faster check insnList.add(new LdcInsnNode(string)); return insnList; } @@ -219,4 +218,17 @@ public static int getUtf8CharSize(char c) { } return 3; } + + public static InsnList push(final int value) { + InsnList ret = new InsnList(); + if (value >= -1 && value <= 5) + ret.add(new InsnNode(Opcodes.ICONST_0 + value)); + else if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) + ret.add(new IntInsnNode(Opcodes.BIPUSH, value)); + else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) + ret.add(new IntInsnNode(Opcodes.SIPUSH, value)); + else + ret.add(new LdcInsnNode(value)); + return ret; + } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherConfigurator.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherConfigurator.java index 9494a143..e81b20de 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherConfigurator.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherConfigurator.java @@ -1,42 +1,28 @@ package pro.gravit.launchserver.binary; -import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Opcodes; import org.objectweb.asm.Type; import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.FieldInsnNode; import org.objectweb.asm.tree.InsnList; import org.objectweb.asm.tree.InsnNode; -import org.objectweb.asm.tree.IntInsnNode; -import org.objectweb.asm.tree.LdcInsnNode; import org.objectweb.asm.tree.MethodInsnNode; import org.objectweb.asm.tree.MethodNode; import org.objectweb.asm.tree.TypeInsnNode; -import org.objectweb.asm.tree.VarInsnNode; -import pro.gravit.launcher.AutogenConfig; import pro.gravit.launcher.LauncherConfig; import pro.gravit.launcher.modules.LauncherModule; -import pro.gravit.launchserver.asm.ClassMetadataReader; -import pro.gravit.launchserver.asm.SafeClassWriter; +import pro.gravit.launchserver.asm.ConfigGenerator; -public class LauncherConfigurator { +public class LauncherConfigurator extends ConfigGenerator { private static final String modulesManagerName = "pro/gravit/launcher/modules/LauncherModulesManager"; private static final String launcherName = "pro/gravit/launcher/LauncherEngine"; private static final String modulesManagerDesc = "Lpro/gravit/launcher/client/ClientModuleManager;"; private static final String registerModDesc = Type.getMethodDescriptor(Type.getType(LauncherModule.class), Type.getType(LauncherModule.class)); - private static final String autoGenConfigName = Type.getInternalName(AutogenConfig.class); - private static final String stringDesc = Type.getDescriptor(String.class); - private final ClassNode configclass; - private final MethodNode constructor; private final MethodNode initModuleMethod; public LauncherConfigurator(ClassNode configclass) { - this.configclass = configclass; - constructor = configclass.methods.stream().filter(e -> "".equals(e.name)).findFirst().get(); - constructor.instructions = new InsnList(); - constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); - constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, Type.getInternalName(Object.class), "", "()V")); + super(configclass); initModuleMethod = configclass.methods.stream().filter(e -> "initModules".equals(e.name)).findFirst().get(); initModuleMethod.instructions = new InsnList(); } @@ -49,18 +35,6 @@ public void addModuleClass(String fullName) { initModuleMethod.instructions.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, modulesManagerName, "loadModule", registerModDesc)); } - public byte[] getBytecode(ClassMetadataReader reader) { - constructor.instructions.add(new InsnNode(Opcodes.RETURN)); - initModuleMethod.instructions.add(new InsnNode(Opcodes.RETURN)); - ClassWriter cw = new SafeClassWriter(reader, ClassWriter.COMPUTE_FRAMES); - configclass.accept(cw); - return cw.toByteArray(); - } - - public String getZipEntryPath() { - return configclass.name.concat(".class"); - } - public void setAddress(String address) { setStringField("address", address); } @@ -81,36 +55,17 @@ public void setOemUnlockKey(String key) { setStringField("oemUnlockKey", key); } - private void setStringField(String name, String value) - { - constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); - constructor.instructions.add(new LdcInsnNode(value)); - constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, autoGenConfigName, name, stringDesc)); - } - public void setGuardType(String key) { setStringField("guardType", key); } + public void setSecureCheck(String hash, String salt) { setStringField("secureCheckHash", hash); setStringField("secureCheckSalt", salt); } - - private void push(final int value) { - if (value >= -1 && value <= 5) - constructor.instructions.add(new InsnNode(Opcodes.ICONST_0 + value)); - else if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) - constructor.instructions.add(new IntInsnNode(Opcodes.BIPUSH, value)); - else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) - constructor.instructions.add(new IntInsnNode(Opcodes.SIPUSH, value)); - else - constructor.instructions.add(new LdcInsnNode(value)); - } - + public void setEnv(LauncherConfig.LauncherEnvironment env) { - constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); int i = 2; - switch (env) { case DEV: i = 0; @@ -125,29 +80,14 @@ public void setEnv(LauncherConfig.LauncherEnvironment env) { i = 3; break; } - push(i); - constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, autoGenConfigName, "env", Type.INT_TYPE.getInternalName())); + setIntegerField("env", i); } public void setClientPort(int port) { setIntegerField("clientPort", port); } - public void setIntegerField(String name, int value) - { - constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); - push(value); - constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, autoGenConfigName, name, Type.INT_TYPE.getInternalName())); - } - public void setWarningMissArchJava(boolean b) { setBooleanField("isWarningMissArchJava", b); } - - private void setBooleanField(String name, boolean b) - { - constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); - constructor.instructions.add(new InsnNode(b ? Opcodes.ICONST_1 : Opcodes.ICONST_0)); - constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, autoGenConfigName, name, Type.BOOLEAN_TYPE.getInternalName())); - } } From fd23ba555bf0d91bcb0e700d935d348241208817 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Fri, 18 Oct 2019 16:27:33 +0200 Subject: [PATCH 019/192] =?UTF-8?q?[FEATURE]=20byte[]=20=D0=B2=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=D0=B5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gravit/launchserver/asm/ConfigGenerator.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ConfigGenerator.java b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ConfigGenerator.java index 20854354..fbd3f77e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ConfigGenerator.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ConfigGenerator.java @@ -1,5 +1,7 @@ package pro.gravit.launchserver.asm; +import java.util.Base64; + import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Opcodes; import org.objectweb.asm.Type; @@ -14,6 +16,8 @@ public class ConfigGenerator { protected static final String stringDesc = Type.getDescriptor(String.class); + protected static final String byteArrDesc = Type.getDescriptor(byte[].class); + protected static final String base64DecDesc = "(" + stringDesc + ")" + byteArrDesc; protected final ClassNode configclass; protected final MethodNode constructor; @@ -43,6 +47,15 @@ public void setStringField(String name, String value) constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, configclass.name, name, stringDesc)); } + public void setByteArrayField(String name, byte[] value) + { + constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); + constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/util/Base64", "getDecoder", "()Ljava/util/Base64$Decoder;", false)); + constructor.instructions.add(NodeUtils.getSafeStringInsnList(Base64.getEncoder().encodeToString(value))); + constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/util/Base64$Decoder", "decode", base64DecDesc, false)); + constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, configclass.name, name, stringDesc)); + } + public void setIntegerField(String name, int value) { constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); From 0b316dff563c675f95b3ecebfa14b2deabd251b5 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Fri, 18 Oct 2019 16:36:38 +0200 Subject: [PATCH 020/192] =?UTF-8?q?[ANY]=20=D0=9D=D0=B5=D0=B1=D0=BE=D0=BB?= =?UTF-8?q?=D1=8C=D1=88=D0=BE=D0=B9=20=D1=80=D0=B5=D1=84=D0=B0=D0=BA=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=B8=D0=BD=D0=B3.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/pro/gravit/launchserver/LaunchServer.java | 5 ----- .../java/pro/gravit/launchserver/LaunchServerBuilder.java | 2 -- .../launchserver/command/service/GetModulusCommand.java | 1 - .../modules/impl/LaunchServerModulesManager.java | 1 - .../java/pro/gravit/launchserver/StartLaunchServerTest.java | 2 -- .../src/main/java/pro/gravit/launcher/LauncherEngine.java | 3 --- .../main/java/pro/gravit/launcher/client/ClientLauncher.java | 1 - .../java/pro/gravit/launcher/client/FunctionalBridge.java | 1 - .../src/main/java/pro/gravit/launcher/LauncherConfig.java | 2 -- .../gravit/launcher/modules/impl/SimpleModuleManager.java | 4 ++-- .../main/java/pro/gravit/utils/helper/SecurityHelper.java | 2 +- modules | 2 +- 12 files changed, 4 insertions(+), 22 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java index a1d7de7b..ebe28e43 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java @@ -13,12 +13,8 @@ import java.security.InvalidAlgorithmParameterException; import java.security.KeyPair; import java.security.NoSuchAlgorithmException; -import java.security.cert.CertificateException; import java.security.interfaces.ECPrivateKey; import java.security.interfaces.ECPublicKey; -import java.security.interfaces.RSAPrivateKey; -import java.security.interfaces.RSAPublicKey; -import java.security.spec.InvalidKeySpecException; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -31,7 +27,6 @@ import java.util.Set; import java.util.Timer; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.zip.CRC32; import org.bouncycastle.crypto.util.PrivateKeyFactory; import org.bouncycastle.operator.OperatorCreationException; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerBuilder.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerBuilder.java index 3b21bea1..d3c70de6 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerBuilder.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerBuilder.java @@ -3,8 +3,6 @@ import java.nio.file.Path; import java.security.interfaces.ECPrivateKey; import java.security.interfaces.ECPublicKey; -import java.security.interfaces.RSAPrivateKey; -import java.security.interfaces.RSAPublicKey; import pro.gravit.launchserver.config.LaunchServerConfig; import pro.gravit.launchserver.config.LaunchServerRuntimeConfig; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GetModulusCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GetModulusCommand.java index b7454ecc..dc2c3d82 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GetModulusCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GetModulusCommand.java @@ -2,7 +2,6 @@ import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.command.Command; -import pro.gravit.utils.helper.LogHelper; public class GetModulusCommand extends Command { public GetModulusCommand(LaunchServer server) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerModulesManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerModulesManager.java index 24558e99..aeb68e84 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerModulesManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerModulesManager.java @@ -7,7 +7,6 @@ import pro.gravit.launcher.modules.LauncherModuleInfo; import pro.gravit.launcher.modules.impl.SimpleModuleManager; import pro.gravit.launchserver.LaunchServer; -import pro.gravit.launchserver.manangers.CertificateManager; import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.verify.LauncherTrustManager; diff --git a/LaunchServer/src/test/java/pro/gravit/launchserver/StartLaunchServerTest.java b/LaunchServer/src/test/java/pro/gravit/launchserver/StartLaunchServerTest.java index 31f9d75d..3b04e1b6 100644 --- a/LaunchServer/src/test/java/pro/gravit/launchserver/StartLaunchServerTest.java +++ b/LaunchServer/src/test/java/pro/gravit/launchserver/StartLaunchServerTest.java @@ -6,8 +6,6 @@ import java.security.SecureRandom; import java.security.interfaces.ECPrivateKey; import java.security.interfaces.ECPublicKey; -import java.security.interfaces.RSAPrivateKey; -import java.security.interfaces.RSAPublicKey; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index 17f36147..7de55081 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -9,7 +9,6 @@ import java.util.Objects; import java.util.concurrent.atomic.AtomicBoolean; -import org.bouncycastle.jce.provider.BouncyCastleProvider; import pro.gravit.launcher.client.*; import pro.gravit.launcher.client.events.ClientEngineInitPhase; import pro.gravit.launcher.client.events.ClientPreGuiPhase; @@ -28,8 +27,6 @@ import pro.gravit.launcher.request.websockets.StandartClientWebSocketService; import pro.gravit.utils.helper.*; -import javax.crypto.Cipher; - public class LauncherEngine { public static final AtomicBoolean IS_CLIENT = new AtomicBoolean(false); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index 7bfba319..ea3a684b 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -38,7 +38,6 @@ import pro.gravit.launcher.client.events.ClientLauncherInitPhase; import pro.gravit.launcher.client.events.ClientLauncherPostInitPhase; import pro.gravit.launcher.guard.LauncherGuardManager; -import pro.gravit.launcher.gui.JSRuntimeProvider; import pro.gravit.launcher.hasher.FileNameMatcher; import pro.gravit.launcher.hasher.HashedDir; import pro.gravit.launcher.hwid.HWIDProvider; diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/FunctionalBridge.java b/Launcher/src/main/java/pro/gravit/launcher/client/FunctionalBridge.java index 2cdf51ab..c6f9aefc 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/FunctionalBridge.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/FunctionalBridge.java @@ -1,7 +1,6 @@ package pro.gravit.launcher.client; import java.nio.file.Path; -import java.util.Arrays; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java b/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java index 9dc70fb4..e5d89753 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java @@ -2,9 +2,7 @@ import java.io.IOException; import java.security.cert.CertificateException; -import java.security.interfaces.ECPrivateKey; import java.security.interfaces.ECPublicKey; -import java.security.interfaces.RSAPublicKey; import java.security.spec.InvalidKeySpecException; import java.util.Collections; import java.util.HashMap; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java index 81847cd2..237a6a9e 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java @@ -159,8 +159,8 @@ public LauncherModule loadModule(Path file) throws IOException { return null; } classLoader.addURL(file.toUri().toURL()); - @SuppressWarnings("unchecked cast") - Class clazz = (Class) Class.forName(moduleClass, false, classLoader); + @SuppressWarnings("unchecked") + Class clazz = (Class) Class.forName(moduleClass, false, classLoader); checkModuleClass(clazz, checkMode); LauncherModule module = clazz.newInstance(); loadModule(module); diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/SecurityHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/SecurityHelper.java index 23acb73e..c1e04ab9 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/SecurityHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/SecurityHelper.java @@ -169,7 +169,7 @@ public static boolean isValidToken(CharSequence token) { return token.length() == TOKEN_STRING_LENGTH && token.chars().allMatch(ch -> HEX.indexOf(ch) >= 0); } - private static Cipher newCipher(String algo) { + public static Cipher newCipher(String algo) { try { return Cipher.getInstance(algo); } catch (NoSuchAlgorithmException | NoSuchPaddingException e) { diff --git a/modules b/modules index 3417974a..14389214 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 3417974a1e903115c27b5b2b51bd43c7bbd877d1 +Subproject commit 14389214577f16795ba9844905c2e3886a1ea6d4 From ac55d0694b51d58a1b9d008bc00fb69db8119672 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Fri, 18 Oct 2019 17:04:28 +0200 Subject: [PATCH 021/192] =?UTF-8?q?[FIX]=20=D0=A3=D0=B4=D0=B0=D0=BB=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BF=D0=BE=20=D0=BC=D0=B0=D0=BA=D1=81=D0=B8=D0=BC?= =?UTF-8?q?=D0=BE=D0=BC=D1=83=20=D0=B4=D1=83=D0=BF=D0=BB=D0=B8=D0=BA=D0=B0?= =?UTF-8?q?=D1=82=D1=8B=20=D0=BA=D0=BE=D0=B4=D0=B0=20=D0=B2=20LauncherConf?= =?UTF-8?q?igurator.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../binary/LauncherConfigurator.java | 37 ------------------- .../binary/tasks/MainBuildTask.java | 19 +++++----- 2 files changed, 10 insertions(+), 46 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherConfigurator.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherConfigurator.java index e81b20de..5ab1a00d 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherConfigurator.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherConfigurator.java @@ -35,35 +35,6 @@ public void addModuleClass(String fullName) { initModuleMethod.instructions.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, modulesManagerName, "loadModule", registerModDesc)); } - public void setAddress(String address) { - setStringField("address", address); - } - - public void setPasswordEncryptKey(String pass) { - setStringField("passwordEncryptKey", pass); - } - - public void setProjectName(String name) { - setStringField("projectname", name); - } - - public void setSecretKey(String key) { - setStringField("secretKeyClient", key); - } - - public void setOemUnlockKey(String key) { - setStringField("oemUnlockKey", key); - } - - public void setGuardType(String key) { - setStringField("guardType", key); - } - - public void setSecureCheck(String hash, String salt) { - setStringField("secureCheckHash", hash); - setStringField("secureCheckSalt", salt); - } - public void setEnv(LauncherConfig.LauncherEnvironment env) { int i = 2; switch (env) { @@ -82,12 +53,4 @@ public void setEnv(LauncherConfig.LauncherEnvironment env) { } setIntegerField("env", i); } - - public void setClientPort(int port) { - setIntegerField("clientPort", port); - } - - public void setWarningMissArchJava(boolean b) { - setBooleanField("isWarningMissArchJava", b); - } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java index b111755d..0c3b3b54 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java @@ -123,21 +123,22 @@ public Path process(Path inputJar) throws IOException { LauncherConfigurator launcherConfigurator = new LauncherConfigurator(cn); BuildContext context = new BuildContext(output, launcherConfigurator, this); server.buildHookManager.hook(context); - launcherConfigurator.setAddress(server.config.netty.address); - launcherConfigurator.setProjectName(server.config.projectName); - launcherConfigurator.setSecretKey(SecurityHelper.randomStringAESKey()); - launcherConfigurator.setClientPort(32148 + SecurityHelper.newRandom().nextInt(512)); - launcherConfigurator.setGuardType(server.config.launcher.guardType); - launcherConfigurator.setWarningMissArchJava(server.config.launcher.warningMissArchJava); + launcherConfigurator.setStringField("address", server.config.netty.address); + launcherConfigurator.setStringField("projectname", server.config.projectName); + launcherConfigurator.setStringField("secretKeyClient", SecurityHelper.randomStringAESKey()); + launcherConfigurator.setIntegerField("clientPort", 32148 + SecurityHelper.newRandom().nextInt(512)); + launcherConfigurator.setStringField("guardType", server.config.launcher.guardType); + launcherConfigurator.setBooleanField("isWarningMissArchJava", server.config.launcher.warningMissArchJava); launcherConfigurator.setEnv(server.config.env); - launcherConfigurator.setPasswordEncryptKey(server.runtime.passwordEncryptKey); + launcherConfigurator.setStringField("passwordEncryptKey", server.runtime.passwordEncryptKey); String launcherSalt = SecurityHelper.randomStringToken(); byte[] launcherSecureHash = SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA256, server.runtime.clientCheckSecret.concat(".").concat(launcherSalt)); - launcherConfigurator.setSecureCheck(Base64.getEncoder().encodeToString(launcherSecureHash), launcherSalt); + launcherConfigurator.setStringField("secureCheckHash", Base64.getEncoder().encodeToString(launcherSecureHash)); + launcherConfigurator.setStringField("secureCheckSalt", launcherSalt); //LogHelper.debug("[checkSecure] %s: %s", launcherSalt, Arrays.toString(launcherSecureHash)); if (server.runtime.oemUnlockKey == null) server.runtime.oemUnlockKey = SecurityHelper.randomStringToken(); - launcherConfigurator.setOemUnlockKey(server.runtime.oemUnlockKey); + launcherConfigurator.setStringField("oemUnlockKey", server.runtime.oemUnlockKey); server.buildHookManager.registerAllClientModuleClass(launcherConfigurator); reader.getCp().add(new JarFile(inputJar.toFile())); server.launcherBinary.coreLibs.forEach(e -> { From 386a110eb1bfdeb270ba5a0718f293b42820861a Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Fri, 18 Oct 2019 17:11:08 +0200 Subject: [PATCH 022/192] =?UTF-8?q?[FIX]=20=D0=97=D0=B0=D0=B1=D1=8B=D1=82?= =?UTF-8?q?=D1=8B=D0=B9=20RETURN.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gravit/launchserver/binary/LauncherConfigurator.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherConfigurator.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherConfigurator.java index 5ab1a00d..bde39553 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherConfigurator.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherConfigurator.java @@ -12,6 +12,7 @@ import pro.gravit.launcher.LauncherConfig; import pro.gravit.launcher.modules.LauncherModule; +import pro.gravit.launchserver.asm.ClassMetadataReader; import pro.gravit.launchserver.asm.ConfigGenerator; public class LauncherConfigurator extends ConfigGenerator { @@ -35,6 +36,12 @@ public void addModuleClass(String fullName) { initModuleMethod.instructions.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, modulesManagerName, "loadModule", registerModDesc)); } + @Override + public byte[] getBytecode(ClassMetadataReader reader) { + initModuleMethod.instructions.add(new InsnNode(Opcodes.RETURN)); + return super.getBytecode(reader); + } + public void setEnv(LauncherConfig.LauncherEnvironment env) { int i = 2; switch (env) { From 8ba00d106e334224aa6604e8f6837295978c205a Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Sat, 19 Oct 2019 06:53:13 +0200 Subject: [PATCH 023/192] =?UTF-8?q?[FIX]=20=D0=9F=D0=BE=D0=B4=D0=B4=D0=B5?= =?UTF-8?q?=D1=80=D0=B6=D0=BA=D0=B0=20=D0=B2=20ConfigGenerator=20List?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launchserver/asm/ConfigGenerator.java | 19 +++++++++++++++++++ .../gravit/launcher/SecureAutogenConfig.java | 5 ++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ConfigGenerator.java b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ConfigGenerator.java index fbd3f77e..809f536e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ConfigGenerator.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ConfigGenerator.java @@ -1,6 +1,7 @@ package pro.gravit.launchserver.asm; import java.util.Base64; +import java.util.List; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Opcodes; @@ -12,6 +13,7 @@ import org.objectweb.asm.tree.LdcInsnNode; import org.objectweb.asm.tree.MethodInsnNode; import org.objectweb.asm.tree.MethodNode; +import org.objectweb.asm.tree.TypeInsnNode; import org.objectweb.asm.tree.VarInsnNode; public class ConfigGenerator { @@ -55,6 +57,23 @@ public void setByteArrayField(String name, byte[] value) constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/util/Base64$Decoder", "decode", base64DecDesc, false)); constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, configclass.name, name, stringDesc)); } + + public void setByteArrayListField(String name, List b) + { + constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); + constructor.instructions.add(new TypeInsnNode(Opcodes.NEW, "java/util/ArrayList")); + constructor.instructions.add(new InsnNode(Opcodes.DUP)); + constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/util/ArrayList", "", "()V")); + for (byte[] value : b) { + constructor.instructions.add(new InsnNode(Opcodes.DUP)); + constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/util/Base64", "getDecoder", "()Ljava/util/Base64$Decoder;", false)); + constructor.instructions.add(NodeUtils.getSafeStringInsnList(Base64.getEncoder().encodeToString(value))); + constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/util/Base64$Decoder", "decode", base64DecDesc, false)); + constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", false)); + constructor.instructions.add(new InsnNode(Opcodes.POP)); + } + constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, configclass.name, name, "Ljava/util/List;")); + } public void setIntegerField(String name, int value) { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/SecureAutogenConfig.java b/LauncherAPI/src/main/java/pro/gravit/launcher/SecureAutogenConfig.java index 2d971a4e..b72e5cb9 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/SecureAutogenConfig.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/SecureAutogenConfig.java @@ -1,5 +1,7 @@ package pro.gravit.launcher; +import java.nio.charset.StandardCharsets; + public class SecureAutogenConfig { public byte[][] certificates; @@ -38,7 +40,8 @@ public SecureAutogenConfig() { "OATWgSKH0qTkleE/v7k+USs0a+KV8wmC5wwliqH+uLO++yIP/9bjDctyLulQX5Ee\n" + "+EhD7tb1R/yyWY4uhkzlsr3N2Kl34aQAEBMn8Z1mHsyyu1FcbEaNLU8jcS3pHPVM\n" + "gQRn3m1iDnQlFciAMxW0pW6mW/4xKYzhXk5BTSolnqMVylxHgWXuBwdDDQQVnQ==\n" + - "-----END CERTIFICATE-----").getBytes() + "-----END CERTIFICATE-----").getBytes(StandardCharsets.US_ASCII) + // ? Какая из них, но выбрать надо однозачно }; } } From 9a4b813bb762d54c7cbf65062ed110bc4da6ed4b Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 19 Oct 2019 23:43:25 +0700 Subject: [PATCH 024/192] [ANY] IDEA Inspect Code --- .../pro/gravit/launchserver/LaunchServer.java | 18 ++- .../launchserver/LaunchServerStarter.java | 2 +- .../launchserver/asm/ClassMetadataReader.java | 4 +- .../launchserver/auth/AuthProviderPair.java | 10 +- .../auth/handler/AuthHandler.java | 2 +- .../auth/handler/CachedAuthHandler.java | 4 +- .../auth/handler/HibernateAuthHandler.java | 10 +- .../auth/handler/JsonAuthHandler.java | 24 ++-- .../auth/handler/RequestAuthHandler.java | 4 +- .../launchserver/auth/hwid/HWIDHandler.java | 2 +- .../auth/hwid/JsonFileHWIDHandler.java | 18 ++- .../auth/hwid/JsonHWIDHandler.java | 18 +-- .../auth/hwid/MemoryHWIDHandler.java | 18 ++- .../auth/hwid/MysqlHWIDHandler.java | 10 +- .../permissions/ConfigPermissionsHandler.java | 4 +- .../HibernatePermissionsHandler.java | 2 +- .../JsonFilePermissionsHandler.java | 6 +- .../JsonLongFilePermissionsHandler.java | 8 +- .../auth/permissions/PermissionsHandler.java | 2 +- .../auth/protect/ProtectHandler.java | 2 +- .../auth/protect/StdProtectHandler.java | 2 +- .../auth/provider/AuthProvider.java | 2 +- .../auth/provider/HibernateAuthProvider.java | 2 +- .../auth/provider/JsonAuthProvider.java | 12 +- .../auth/provider/RejectAuthProvider.java | 2 +- .../auth/texture/TextureProvider.java | 2 +- .../binary/EXEL4JLauncherBinary.java | 4 +- .../binary/JARLauncherBinary.java | 6 +- .../binary/SimpleEXELauncherBinary.java | 2 +- .../command/dao/GetAllUsersCommand.java | 2 +- .../command/hash/IndexAssetCommand.java | 6 +- .../command/hash/UnindexAssetCommand.java | 2 +- .../command/install/CheckInstallCommand.java | 2 +- .../command/install/MultiCommand.java | 2 +- .../command/service/ClientsCommand.java | 2 +- .../command/service/GetModulusCommand.java | 2 +- .../service/GivePermissionsCommand.java | 2 +- .../components/AbstractLimiter.java | 12 +- .../components/AuthLimiterComponent.java | 2 +- .../components/CommandRemoverComponent.java | 4 +- .../launchserver/components/Component.java | 2 +- .../components/RegLimiterComponent.java | 2 +- .../config/LaunchServerConfig.java | 19 ++- .../pro/gravit/launchserver/dao/UserHWID.java | 4 +- .../dao/provider/DaoProvider.java | 2 +- .../manangers/CertificateManager.java | 4 +- .../launchserver/manangers/MirrorManager.java | 6 +- .../manangers/ReconfigurableManager.java | 2 +- .../manangers/SessionManager.java | 2 +- .../manangers/hook/AuthHookManager.java | 20 +-- .../impl/LaunchServerModulesManager.java | 2 +- .../gravit/launchserver/socket/Client.java | 2 +- .../launchserver/socket/WebSocketService.java | 8 +- .../handlers/NettyIpForwardHandler.java | 4 +- .../fileserver/FileServerHandler.java | 5 - .../admin/AddLogListenerResponse.java | 2 +- .../socket/response/auth/AuthResponse.java | 16 +-- .../response/auth/SetPasswordResponse.java | 2 +- .../profile/BatchProfileByUsername.java | 2 +- .../launchserver/StartLaunchServerTest.java | 11 +- .../launchserver/console/ExitCommand.java | 2 +- .../console/LogListenerCommand.java | 4 +- .../launcher/ClientLauncherWrapper.java | 2 +- .../gravit/launcher/NewLauncherSettings.java | 8 +- .../launcher/client/ClientLauncher.java | 8 +- .../client/ClientLauncherContext.java | 2 +- .../launcher/client/ClientModuleManager.java | 6 +- .../launcher/client/FunctionalBridge.java | 4 +- .../gravit/launcher/client/ServerPinger.java | 2 +- .../gravit/launcher/client/UserSettings.java | 2 +- .../client/events/ClientPreGuiPhase.java | 2 +- .../launcher/console/FeatureCommand.java | 2 +- .../console/admin/LogListenerCommand.java | 4 +- .../console/store/CopyStoreDirCommand.java | 4 +- .../console/store/LinkStoreDirCommand.java | 2 +- .../console/store/StoreListCommand.java | 2 +- .../gravit/launcher/gui/RuntimeProvider.java | 2 +- .../launcher/managers/ClientHookManager.java | 14 +- .../gravit/launcher/managers/HasherStore.java | 2 +- .../launcher/managers/SettingsManager.java | 2 +- .../gravit/launcher/patches/FMLPatcher.java | 2 +- .../gravit/launcher/utils/NativeJVMHalt.java | 2 +- .../gravit/launcher/ClientPermissions.java | 6 +- .../gravit/launcher/SecureAutogenConfig.java | 2 +- .../launcher/downloader/ListDownloader.java | 9 +- .../gravit/launcher/events/ControlEvent.java | 2 +- .../gravit/launcher/events/SignalEvent.java | 2 +- .../request/ExecCommandRequestEvent.java | 2 +- .../GetAvailabilityAuthRequestEvent.java | 6 +- .../request/GetSecureTokenRequestEvent.java | 2 +- .../request/JoinServerRequestEvent.java | 2 +- .../launcher/events/request/LogEvent.java | 2 +- .../ProfileByUsernameRequestEvent.java | 2 +- .../request/SetProfileRequestEvent.java | 2 +- .../events/request/UpdateRequestEvent.java | 4 +- .../VerifySecureTokenRequestEvent.java | 2 +- .../gravit/launcher/hwid/HWIDProvider.java | 2 +- .../managers/SimpleModulesConfigManager.java | 2 +- .../launcher/modules/LauncherModule.java | 2 +- .../launcher/modules/events/PreGsonPhase.java | 2 +- .../modules/impl/SimpleModuleManager.java | 2 +- .../launcher/profiles/ClientProfile.java | 128 ------------------ .../profiles/optional/OptionalFile.java | 4 +- .../gravit/launcher/request/PingRequest.java | 2 +- .../pro/gravit/launcher/request/Request.java | 2 +- .../request/admin/ExecCommandRequest.java | 2 +- .../launcher/request/auth/AuthRequest.java | 2 +- .../request/auth/RestoreSessionRequest.java | 2 +- .../request/auth/SetProfileRequest.java | 2 +- .../request/update/LauncherRequest.java | 4 +- .../request/update/UpdateRequest.java | 10 +- .../uuid/BatchProfileByUsernameRequest.java | 2 +- .../request/websockets/ClientJSONPoint.java | 12 +- .../websockets/ClientWebSocketService.java | 15 +- .../StandartClientWebSocketService.java | 2 +- .../request/websockets/WaitEventHandler.java | 2 +- .../websockets/WebSocketClientHandler.java | 8 +- .../launcher/managers/GarbageManager.java | 4 +- .../serialize/stream/StreamObject.java | 2 +- .../main/java/pro/gravit/utils/BiHookSet.java | 2 +- .../main/java/pro/gravit/utils/HookSet.java | 2 +- .../main/java/pro/gravit/utils/Version.java | 2 +- .../pro/gravit/utils/command/Command.java | 2 +- .../gravit/utils/command/CommandHandler.java | 8 +- .../utils/command/JLineCommandHandler.java | 6 +- .../utils/command/basic/ClearCommand.java | 2 +- .../utils/command/basic/DebugCommand.java | 2 +- .../gravit/utils/command/basic/GCCommand.java | 2 +- .../utils/command/basic/HelpCommand.java | 6 +- .../pro/gravit/utils/helper/JarHelper.java | 2 +- .../pro/gravit/utils/helper/LogHelper.java | 4 +- .../gravit/utils/helper/SecurityHelper.java | 3 +- .../utils/verify/LauncherTrustManager.java | 5 +- .../gravit/launcher/CommandHandlerTest.java | 4 +- .../pro/gravit/launcher/SerializeTest.java | 4 +- .../gravit/launcher/impl/Test2Command.java | 2 +- .../gravit/launcher/server/ServerAgent.java | 4 +- .../gravit/launcher/server/ServerWrapper.java | 12 +- modules | 2 +- 139 files changed, 319 insertions(+), 454 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java index ebe28e43..8a191169 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java @@ -27,6 +27,7 @@ import java.util.Set; import java.util.Timer; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.stream.Stream; import org.bouncycastle.crypto.util.PrivateKeyFactory; import org.bouncycastle.operator.OperatorCreationException; @@ -153,7 +154,7 @@ public void invoke(String... args) throws Exception { reload(ReloadType.NO_COMPONENTS); break; default: - reload(ReloadType.FULL);; + reload(ReloadType.FULL); break; } } @@ -163,7 +164,7 @@ public void invoke(String... args) throws Exception { } - private final class ProfilesFileVisitor extends SimpleFileVisitor { + private static final class ProfilesFileVisitor extends SimpleFileVisitor { private final Collection result; private ProfilesFileVisitor(Collection result) { @@ -215,7 +216,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO // Server config public LaunchServerConfig config; - public LaunchServerRuntimeConfig runtime; + public final LaunchServerRuntimeConfig runtime; public final ECPublicKey publicKey; @@ -225,7 +226,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO public final JARLauncherBinary launcherBinary; - public Class launcherEXEBinaryClass; + public final Class launcherEXEBinaryClass; public final LauncherBinary launcherEXEBinary; // HWID ban + anti-brutforce @@ -263,7 +264,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO public final Timer taskPool; - public static Class defaultLauncherEXEBinaryClass = null; + public static final Class defaultLauncherEXEBinaryClass = null; public static class LaunchServerDirectories { @@ -402,10 +403,7 @@ public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, La Files.createDirectory(profilesDir); syncProfilesDir(); - if (config.netty != null) - nettyServerSocketHandler = new NettyServerSocketHandler(this); - else - nettyServerSocketHandler = null; + nettyServerSocketHandler = new NettyServerSocketHandler(this); // post init modules modulesManager.invokeEvent(new LaunchServerPostInitPhase(this)); if (config.components != null) { @@ -548,7 +546,7 @@ public void syncUpdatesDir(Collection dirs) throws IOException { // Resolve name and verify is dir String name = IOHelper.getFileName(updateDir); if (!IOHelper.isDir(updateDir)) { - if (!IOHelper.isFile(updateDir) && Arrays.asList(".jar", ".exe", ".hash").stream().noneMatch(e -> updateDir.toString().endsWith(e))) + if (!IOHelper.isFile(updateDir) && Stream.of(".jar", ".exe", ".hash").noneMatch(e -> updateDir.toString().endsWith(e))) LogHelper.warning("Not update dir: '%s'", name); continue; } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java index e9619c7d..64397a3c 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java @@ -43,7 +43,7 @@ import pro.gravit.utils.verify.LauncherTrustManager; public class LaunchServerStarter { - public static boolean allowUnsigned = Boolean.getBoolean("launchserver.allowUnsigned"); + public static final boolean allowUnsigned = Boolean.getBoolean("launchserver.allowUnsigned"); public static void main(String[] args) throws Exception { JVMHelper.checkStackTrace(LaunchServerStarter.class); JVMHelper.verifySystemProperties(LaunchServer.class, true); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ClassMetadataReader.java b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ClassMetadataReader.java index 976bfb6d..52eed8b8 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ClassMetadataReader.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ClassMetadataReader.java @@ -19,7 +19,7 @@ * чего угодно. Работает через поиск class-файлов в classpath. */ public class ClassMetadataReader implements Closeable { - private class CheckSuperClassVisitor extends ClassVisitor { + private static class CheckSuperClassVisitor extends ClassVisitor { String superClassName; @@ -108,7 +108,7 @@ public ArrayList getSuperClasses(String type) { @Override public void close() { - cp.stream().forEach(IOHelper::close); + cp.forEach(IOHelper::close); cp.clear(); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java index d70e022f..7e38da78 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java @@ -8,12 +8,12 @@ import pro.gravit.launchserver.auth.texture.TextureProvider; public class AuthProviderPair { - public AuthProvider provider; - public AuthHandler handler; - public TextureProvider textureProvider; - public String name; + public final AuthProvider provider; + public final AuthHandler handler; + public final TextureProvider textureProvider; + public final String name; public String displayName; - public boolean isDefault = true; + public final boolean isDefault = true; public AuthProviderPair(AuthProvider provider, AuthHandler handler, TextureProvider textureProvider, String name) { this.provider = provider; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/AuthHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/AuthHandler.java index 5845b80f..840d8a3e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/AuthHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/AuthHandler.java @@ -10,7 +10,7 @@ public abstract class AuthHandler implements AutoCloseable { - public static ProviderMap providers = new ProviderMap<>("AuthHandler"); + public static final ProviderMap providers = new ProviderMap<>("AuthHandler"); private static boolean registredHandl = false; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/CachedAuthHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/CachedAuthHandler.java index 1639727a..4197360e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/CachedAuthHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/CachedAuthHandler.java @@ -38,7 +38,7 @@ public Entry(UUID uuid, String username, String accessToken, String serverID) { } } - protected class EntryAndUsername { + protected static class EntryAndUsername { public Map entryCache; public Map usernameCache; } @@ -48,7 +48,7 @@ public Map getCommands() { Map commands = new HashMap<>(); commands.put("clear", new SubCommand() { @Override - public void invoke(String... args) throws Exception { + public void invoke(String... args) { long entryCacheSize = entryCache.size(); long usernamesCacheSize = usernamesCache.size(); entryCache.clear(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/HibernateAuthHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/HibernateAuthHandler.java index 883807e9..c165f78a 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/HibernateAuthHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/HibernateAuthHandler.java @@ -7,21 +7,21 @@ public class HibernateAuthHandler extends CachedAuthHandler { @Override - protected Entry fetchEntry(String username) throws IOException { + protected Entry fetchEntry(String username) { User user = srv.config.dao.userService.findUserByUsername(username); if(user == null) return null; return new Entry(user.uuid, username, user.getAccessToken(), user.serverID); } @Override - protected Entry fetchEntry(UUID uuid) throws IOException { + protected Entry fetchEntry(UUID uuid) { User user = srv.config.dao.userService.findUserByUUID(uuid); if(user == null) return null; return new Entry(user.uuid, user.username, user.getAccessToken(), user.serverID); } @Override - protected boolean updateAuth(UUID uuid, String username, String accessToken) throws IOException { + protected boolean updateAuth(UUID uuid, String username, String accessToken) { User user = srv.config.dao.userService.findUserByUUID(uuid); user.setAccessToken(accessToken); srv.config.dao.userService.updateUser(user); @@ -29,7 +29,7 @@ protected boolean updateAuth(UUID uuid, String username, String accessToken) thr } @Override - protected boolean updateServerID(UUID uuid, String serverID) throws IOException { + protected boolean updateServerID(UUID uuid, String serverID) { User user = srv.config.dao.userService.findUserByUUID(uuid); user.serverID = serverID; srv.config.dao.userService.updateUser(user); @@ -37,7 +37,7 @@ protected boolean updateServerID(UUID uuid, String serverID) throws IOException } @Override - public void close() throws IOException { + public void close() { } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/JsonAuthHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/JsonAuthHandler.java index 51cfc916..9ab78a41 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/JsonAuthHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/JsonAuthHandler.java @@ -12,26 +12,26 @@ public class JsonAuthHandler extends CachedAuthHandler { public URL updateAuthUrl; public URL updateServerIdUrl; - public class EntryRequestByUsername { - public String username; + public static class EntryRequestByUsername { + public final String username; public EntryRequestByUsername(String username) { this.username = username; } } - public class EntryRequestByUUID { - public UUID uuid; + public static class EntryRequestByUUID { + public final UUID uuid; public EntryRequestByUUID(UUID uuid) { this.uuid = uuid; } } - public class UpdateAuthRequest { - public UUID uuid; - public String username; - public String accessToken; + public static class UpdateAuthRequest { + public final UUID uuid; + public final String username; + public final String accessToken; public UpdateAuthRequest(UUID uuid, String username, String accessToken) { this.uuid = uuid; @@ -40,9 +40,9 @@ public UpdateAuthRequest(UUID uuid, String username, String accessToken) { } } - public class UpdateServerIDRequest { - public UUID uuid; - public String serverID; + public static class UpdateServerIDRequest { + public final UUID uuid; + public final String serverID; public UpdateServerIDRequest(UUID uuid, String serverID) { this.uuid = uuid; @@ -50,7 +50,7 @@ public UpdateServerIDRequest(UUID uuid, String serverID) { } } - public class SuccessResponse { + public static class SuccessResponse { public boolean success; } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/RequestAuthHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/RequestAuthHandler.java index 2b7bfa47..c6812693 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/RequestAuthHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/RequestAuthHandler.java @@ -16,8 +16,8 @@ public final class RequestAuthHandler extends CachedAuthHandler { private String updateAuth; private String updateServerID; - private String splitSymbol = ":"; - private String goodResponse = "OK"; + private final String splitSymbol = ":"; + private final String goodResponse = "OK"; @Override public void init(LaunchServer srv) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/HWIDHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/HWIDHandler.java index ae25e41c..b0754c1f 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/HWIDHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/HWIDHandler.java @@ -12,7 +12,7 @@ import pro.gravit.utils.helper.LogHelper; public abstract class HWIDHandler implements AutoCloseable, Reconfigurable { - public static ProviderMap providers = new ProviderMap<>("HWIDHandler"); + public static final ProviderMap providers = new ProviderMap<>("HWIDHandler"); private static boolean registredHandl = false; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/JsonFileHWIDHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/JsonFileHWIDHandler.java index d48868e5..ff831846 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/JsonFileHWIDHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/JsonFileHWIDHandler.java @@ -18,8 +18,8 @@ import pro.gravit.utils.helper.LogHelper; public class JsonFileHWIDHandler extends HWIDHandler { - public class Entry { - public HWID hwid; + public static class Entry { + public final HWID hwid; public String username; public boolean isBanned = false; @@ -41,15 +41,18 @@ public int hashCode() { } } - public String filename = "hwids.json"; + public final String filename = "hwids.json"; public transient LinkedList list = new LinkedList<>(); - public String banMessage = "You banned"; + public final String banMessage = "You banned"; @Override public void ban(List hwid) { for (Entry e : list) { for (HWID banHWID : hwid) { - if (e.hwid.equals(banHWID)) e.isBanned = true; + if (e.hwid.equals(banHWID)) { + e.isBanned = true; + break; + } } } } @@ -101,7 +104,10 @@ public List getHwid(String username) { public void unban(List hwid) { for (Entry e : list) { for (HWID banHWID : hwid) { - if (e.hwid.equals(banHWID)) e.isBanned = false; + if (e.hwid.equals(banHWID)) { + e.isBanned = false; + break; + } } } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/JsonHWIDHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/JsonHWIDHandler.java index 8bbcb277..abba10c6 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/JsonHWIDHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/JsonHWIDHandler.java @@ -23,12 +23,12 @@ public final class JsonHWIDHandler extends HWIDHandler { private URL urlGet; private String apiKey; - public class banRequest { + public static class banRequest { public banRequest(OshiHWID hwid) { this.hwid = hwid; } - OshiHWID hwid; + final OshiHWID hwid; String apiKey; public banRequest(OshiHWID hwid, String apiKey) { @@ -37,14 +37,14 @@ public banRequest(OshiHWID hwid, String apiKey) { } } - public class checkRequest { + public static class checkRequest { public checkRequest(String username, OshiHWID hwid) { this.username = username; this.hwid = hwid; } - String username; - OshiHWID hwid; + final String username; + final OshiHWID hwid; String apiKey; public checkRequest(String username, OshiHWID hwid, String apiKey) { @@ -54,21 +54,21 @@ public checkRequest(String username, OshiHWID hwid, String apiKey) { } } - public class Result { + public static class Result { String error; } - public class BannedResult { + public static class BannedResult { boolean isBanned; String error; } - public class HWIDRequest { + public static class HWIDRequest { public HWIDRequest(String username) { this.username = username; } - String username; + final String username; String apiKey; public HWIDRequest(String username, String apiKey) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/MemoryHWIDHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/MemoryHWIDHandler.java index 21a719b7..16ed445b 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/MemoryHWIDHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/MemoryHWIDHandler.java @@ -7,8 +7,8 @@ import pro.gravit.launcher.hwid.HWID; public class MemoryHWIDHandler extends HWIDHandler { - public class Entry { - public HWID hwid; + public static class Entry { + public final HWID hwid; public String username; public boolean isBanned = false; @@ -30,14 +30,17 @@ public int hashCode() { } } - public transient LinkedList list = new LinkedList<>(); - public String banMessage = "You banned"; + public final transient LinkedList list = new LinkedList<>(); + public final String banMessage = "You banned"; @Override public void ban(List hwid) { for (Entry e : list) { for (HWID banHWID : hwid) { - if (e.hwid.equals(banHWID)) e.isBanned = true; + if (e.hwid.equals(banHWID)) { + e.isBanned = true; + break; + } } } } @@ -79,7 +82,10 @@ public List getHwid(String username) { public void unban(List hwid) { for (Entry e : list) { for (HWID banHWID : hwid) { - if (e.hwid.equals(banHWID)) e.isBanned = false; + if (e.hwid.equals(banHWID)) { + e.isBanned = false; + break; + } } } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java index 7c5d6e06..3b9b63d4 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java @@ -37,10 +37,10 @@ public class MysqlHWIDHandler extends HWIDHandler { private String banMessage; - private boolean compareMode = false; + private final boolean compareMode = false; //Using queryHWID "queryHwids": "SELECT * FROM `users_hwids` WHERE `totalMemory` = ? or `serialNumber` = ? or `HWDiskSerial` = ? or `processorID` = ? or `MACAddr` = ?" - private int compare = 50; //При наборе схожести в 50 очков - private boolean oneCompareMode = false; + private final int compare = 50; //При наборе схожести в 50 очков + private final boolean oneCompareMode = false; /* //Добавить поля hwid в базу с пользователями @@ -151,7 +151,7 @@ public void onCheckInfo(OshiHWID hwid, String username, Connection c) throws HWI db_hwid.serialNumber = set.getString(hwidFieldSerialNumber); db_hwid.processorID = set.getString(hwidFieldProcessorID); db_hwid.HWDiskSerial = set.getString(hwidFieldHWDiskSerial); - db_hwid.totalMemory = Long.valueOf(set.getString(hwidFieldTotalMemory)); + db_hwid.totalMemory = Long.parseLong(set.getString(hwidFieldTotalMemory)); db_hwid.macAddr = set.getString(hwidFieldMAC); if (LogHelper.isDevEnabled()) { LogHelper.dev("Compare HWID: %s vs %s", hwid.toString(), db_hwid.toString()); @@ -238,7 +238,7 @@ public List getHwid(String username) { ResultSet rs = s.executeQuery(); if (rs.next()) { OshiHWID oshiHWID = new OshiHWID(); - oshiHWID.totalMemory = Long.valueOf(rs.getString(hwidFieldTotalMemory)); + oshiHWID.totalMemory = Long.parseLong(rs.getString(hwidFieldTotalMemory)); oshiHWID.serialNumber = rs.getString(hwidFieldSerialNumber); oshiHWID.HWDiskSerial = rs.getString(hwidFieldHWDiskSerial); oshiHWID.processorID = rs.getString(hwidFieldProcessorID); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/ConfigPermissionsHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/ConfigPermissionsHandler.java index 8b892f85..c5b1772e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/ConfigPermissionsHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/ConfigPermissionsHandler.java @@ -3,8 +3,8 @@ import pro.gravit.launcher.ClientPermissions; public class ConfigPermissionsHandler extends PermissionsHandler { - public boolean isAdmin = false; - public boolean isServer = false; + public final boolean isAdmin = false; + public final boolean isServer = false; @Override public ClientPermissions getPermissions(String username) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/HibernatePermissionsHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/HibernatePermissionsHandler.java index 2e1be761..a49d8755 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/HibernatePermissionsHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/HibernatePermissionsHandler.java @@ -21,7 +21,7 @@ public void setPermissions(String username, ClientPermissions permissions) { } @Override - public void close() throws Exception { + public void close() { } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java index fc779fb3..71702349 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java @@ -21,7 +21,7 @@ import pro.gravit.utils.helper.LogHelper; public class JsonFilePermissionsHandler extends PermissionsHandler implements Reconfigurable { - public String filename = "permissions.json"; + public final String filename = "permissions.json"; public static Map map; @@ -47,14 +47,14 @@ public Map getCommands() { Map commands = new HashMap<>(); SubCommand reload = new SubCommand() { @Override - public void invoke(String... args) throws Exception { + public void invoke(String... args) { reload(); } }; commands.put("reload", reload); commands.put("save", new SubCommand() { @Override - public void invoke(String... args) throws Exception { + public void invoke(String... args) { Path path = Paths.get(filename); if (!IOHelper.exists(path)) { try (Writer writer = IOHelper.newWriter(path)) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/JsonLongFilePermissionsHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/JsonLongFilePermissionsHandler.java index 1649303c..c9dbae21 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/JsonLongFilePermissionsHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/JsonLongFilePermissionsHandler.java @@ -21,8 +21,8 @@ import pro.gravit.utils.helper.LogHelper; public class JsonLongFilePermissionsHandler extends PermissionsHandler implements Reconfigurable { - public String filename = "permissions.json"; - public long defaultPerms = 0L; + public final String filename = "permissions.json"; + public final long defaultPerms = 0L; public static Map map; @@ -48,14 +48,14 @@ public Map getCommands() { Map commands = new HashMap<>(); SubCommand reload = new SubCommand() { @Override - public void invoke(String... args) throws Exception { + public void invoke(String... args) { reload(); } }; commands.put("reload", reload); commands.put("save", new SubCommand() { @Override - public void invoke(String... args) throws Exception { + public void invoke(String... args) { Path path = Paths.get(filename); if (!IOHelper.exists(path)) { try (Writer writer = IOHelper.newWriter(path)) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/PermissionsHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/PermissionsHandler.java index 9062da26..73fe7968 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/PermissionsHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/PermissionsHandler.java @@ -5,7 +5,7 @@ import pro.gravit.utils.ProviderMap; public abstract class PermissionsHandler implements AutoCloseable { - public static ProviderMap providers = new ProviderMap<>("PermissionsHandler"); + public static final ProviderMap providers = new ProviderMap<>("PermissionsHandler"); protected transient LaunchServer srv; private static boolean registredHandl = false; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/ProtectHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/ProtectHandler.java index 9cd5a200..5707c281 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/ProtectHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/ProtectHandler.java @@ -4,7 +4,7 @@ import pro.gravit.utils.ProviderMap; public abstract class ProtectHandler { - public static ProviderMap providers = new ProviderMap<>("ProtectHandler"); + public static final ProviderMap providers = new ProviderMap<>("ProtectHandler"); private static boolean registredHandl = false; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/StdProtectHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/StdProtectHandler.java index 1c197296..acee9429 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/StdProtectHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/StdProtectHandler.java @@ -4,7 +4,7 @@ import pro.gravit.utils.helper.SecurityHelper; public class StdProtectHandler extends ProtectHandler { - public boolean checkSecure = true; + public final boolean checkSecure = true; @Override public String generateSecureToken(AuthResponse.AuthContext context) { return SecurityHelper.randomStringToken(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AuthProvider.java index aeb7abf3..b10cef06 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AuthProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AuthProvider.java @@ -8,7 +8,7 @@ import pro.gravit.utils.ProviderMap; public abstract class AuthProvider implements AutoCloseable { - public static ProviderMap providers = new ProviderMap<>("AuthProvider"); + public static final ProviderMap providers = new ProviderMap<>("AuthProvider"); private static boolean registredProv = false; protected transient LaunchServer srv = null; public static AuthProviderResult authError(String message) throws AuthException { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/HibernateAuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/HibernateAuthProvider.java index 7f696a0d..14102dff 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/HibernateAuthProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/HibernateAuthProvider.java @@ -36,7 +36,7 @@ public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface p } @Override - public void close() throws IOException { + public void close() { } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/JsonAuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/JsonAuthProvider.java index cb509465..be1064f5 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/JsonAuthProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/JsonAuthProvider.java @@ -14,17 +14,17 @@ import pro.gravit.utils.helper.SecurityHelper; public final class JsonAuthProvider extends AuthProvider { - private static Gson gson = new Gson(); + private static final Gson gson = new Gson(); private URL url; private String apiKey; - public class authResult { + public static class authResult { String username; String error; long permissions; } - public class authRequest { + public static class authRequest { public authRequest(String username, String password, String ip) { this.username = username; this.password = password; @@ -38,9 +38,9 @@ public authRequest(String username, String password, String ip, String apiKey) { this.apiKey = apiKey; } - String username; - String password; - String ip; + final String username; + final String password; + final String ip; String apiKey; } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/RejectAuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/RejectAuthProvider.java index 1d2874a9..2c9e50e5 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/RejectAuthProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/RejectAuthProvider.java @@ -45,7 +45,7 @@ public Map getCommands() { Map commands = new HashMap<>(); commands.put("message", new SubCommand() { @Override - public void invoke(String... args) throws Exception { + public void invoke(String... args) { message = args[0]; LogHelper.info("New reject message: %s", message); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/TextureProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/TextureProvider.java index 96a20bc1..c0c037a2 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/TextureProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/TextureProvider.java @@ -7,7 +7,7 @@ import pro.gravit.utils.ProviderMap; public abstract class TextureProvider implements AutoCloseable { - public static ProviderMap providers = new ProviderMap<>("TextureProvider"); + public static final ProviderMap providers = new ProviderMap<>("TextureProvider"); private static boolean registredProv = false; public static void registerProviders() { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/EXEL4JLauncherBinary.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/EXEL4JLauncherBinary.java index bba780f3..9570404c 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/EXEL4JLauncherBinary.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/EXEL4JLauncherBinary.java @@ -114,8 +114,8 @@ private void setConfig() { ConfigPersister.getInstance().setAntConfig(config, null); } - private static String VERSION = Version.getVersion().getVersionString(); - private static int BUILD = Version.getVersion().build; + private static final String VERSION = Version.getVersion().getVersionString(); + private static final int BUILD = Version.getVersion().build; public static String formatVars(String mask) { return String.format(mask, VERSION, BUILD); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JARLauncherBinary.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JARLauncherBinary.java index 724bcb16..0c20f5c7 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JARLauncherBinary.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JARLauncherBinary.java @@ -25,9 +25,9 @@ public final class JARLauncherBinary extends LauncherBinary { public final Path runtimeDir; public final Path guardDir; public final Path buildDir; - public List tasks; - public List coreLibs; - public List addonLibs; + public final List tasks; + public final List coreLibs; + public final List addonLibs; public JARLauncherBinary(LaunchServer server) throws IOException { super(server, resolve(server, ".jar")); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/SimpleEXELauncherBinary.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/SimpleEXELauncherBinary.java index 006c9fb0..83a6db4b 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/SimpleEXELauncherBinary.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/SimpleEXELauncherBinary.java @@ -9,7 +9,7 @@ import pro.gravit.utils.helper.LogHelper; public class SimpleEXELauncherBinary extends LauncherBinary { - public Path exeTemplate; + public final Path exeTemplate; public SimpleEXELauncherBinary(LaunchServer server) { super(server, LauncherBinary.resolve(server, ".exe")); exeTemplate = server.dir.resolve("SimpleTemplate.exe"); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/GetAllUsersCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/GetAllUsersCommand.java index c0664aca..6ef93227 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/GetAllUsersCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/GetAllUsersCommand.java @@ -21,7 +21,7 @@ public String getUsageDescription() { } @Override - public void invoke(String... args) throws Exception { + public void invoke(String... args) { int count = 0; for(User user : server.config.dao.userService.findAllUsers()) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/IndexAssetCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/IndexAssetCommand.java index 1e8404ee..40545c66 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/IndexAssetCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/IndexAssetCommand.java @@ -21,17 +21,17 @@ import pro.gravit.utils.helper.SecurityHelper.DigestAlgorithm; public final class IndexAssetCommand extends Command { - private static Gson gson = new Gson(); + private static final Gson gson = new Gson(); public static class IndexObject { - long size; + final long size; public IndexObject(long size, String hash) { this.size = size; this.hash = hash; } - String hash; + final String hash; } private static final class IndexAssetVisitor extends SimpleFileVisitor { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/UnindexAssetCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/UnindexAssetCommand.java index 49839739..89ab3f2d 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/UnindexAssetCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/UnindexAssetCommand.java @@ -17,7 +17,7 @@ import pro.gravit.utils.helper.LogHelper; public final class UnindexAssetCommand extends Command { - private static JsonParser parser = new JsonParser(); + private static final JsonParser parser = new JsonParser(); public UnindexAssetCommand(LaunchServer server) { super(server); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/install/CheckInstallCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/install/CheckInstallCommand.java index 31d7a992..44d085a6 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/install/CheckInstallCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/install/CheckInstallCommand.java @@ -21,7 +21,7 @@ public String getUsageDescription() { } @Override - public void invoke(String... args) throws Exception { + public void invoke(String... args) { LogHelper.info("Check install success"); JVMHelper.RUNTIME.exit(0); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/install/MultiCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/install/MultiCommand.java index c5ddcd48..396cbc8c 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/install/MultiCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/install/MultiCommand.java @@ -19,7 +19,7 @@ public String getUsageDescription() { } @Override - public void invoke(String... args) throws Exception { + public void invoke(String... args) { for (String arg : args) { server.commandHandler.eval(arg, false); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/ClientsCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/ClientsCommand.java index b373e7fd..49c0b5e7 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/ClientsCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/ClientsCommand.java @@ -24,7 +24,7 @@ public String getUsageDescription() { } @Override - public void invoke(String... args) throws Exception { + public void invoke(String... args) { WebSocketService service = server.nettyServerSocketHandler.nettyServer.service; service.channels.forEach((channel -> { WebSocketFrameHandler frameHandler = channel.pipeline().get(WebSocketFrameHandler.class); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GetModulusCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GetModulusCommand.java index dc2c3d82..f5e06ad4 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GetModulusCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GetModulusCommand.java @@ -19,7 +19,7 @@ public String getUsageDescription() { } @Override - public void invoke(String... args) throws Exception { + public void invoke(String... args) { //LogHelper.info("You publickey modulus: %s", server.publicKey.getModulus().toString(16)); } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GivePermissionsCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GivePermissionsCommand.java index ebaa9615..6539617d 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GivePermissionsCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GivePermissionsCommand.java @@ -26,7 +26,7 @@ public void invoke(String... args) throws Exception { String username = args[0]; ClientPermissions permissions = server.config.permissionsHandler.getPermissions(username); String permission = args[1]; - boolean isEnabled = Boolean.valueOf(args[2]); + boolean isEnabled = Boolean.parseBoolean(args[2]); switch (permission) { case "admin": { permissions.canAdmin = isEnabled; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/components/AbstractLimiter.java b/LaunchServer/src/main/java/pro/gravit/launchserver/components/AbstractLimiter.java index 44742e0b..399f9927 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/components/AbstractLimiter.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/components/AbstractLimiter.java @@ -14,14 +14,14 @@ public abstract class AbstractLimiter extends Component implements NeedGarbageCollection, Reconfigurable { public int rateLimit; public int rateLimitMillis; - public List exclude = new ArrayList<>(); + public final List exclude = new ArrayList<>(); @Override public Map getCommands() { Map commands = new HashMap<>(); commands.put("gc", new SubCommand() { @Override - public void invoke(String... args) throws Exception { + public void invoke(String... args) { long size = map.size(); garbageCollection(); LogHelper.info("Cleared %d entity", size); @@ -29,7 +29,7 @@ public void invoke(String... args) throws Exception { }); commands.put("clear", new SubCommand() { @Override - public void invoke(String... args) throws Exception { + public void invoke(String... args) { long size = map.size(); map.clear(); LogHelper.info("Cleared %d entity", size); @@ -51,7 +51,7 @@ public void invoke(String... args) throws Exception { }); commands.put("clearExclude", new SubCommand() { @Override - public void invoke(String... args) throws Exception { + public void invoke(String... args) { exclude.clear(); } }); @@ -67,7 +67,7 @@ public void garbageCollection() { map.entrySet().removeIf((e) -> e.getValue().time + rateLimitMillis < time); } - class LimitEntry + static class LimitEntry { long time; int trys; @@ -82,7 +82,7 @@ public LimitEntry() { trys = 0; } } - protected transient Map map = new HashMap<>(); + protected final transient Map map = new HashMap<>(); public boolean check(T address) { if(exclude.contains(address)) return true; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/components/AuthLimiterComponent.java b/LaunchServer/src/main/java/pro/gravit/launchserver/components/AuthLimiterComponent.java index 5b01de0e..23f78c1b 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/components/AuthLimiterComponent.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/components/AuthLimiterComponent.java @@ -32,7 +32,7 @@ public boolean preAuthHook(AuthResponse.AuthContext context, Client client) { public String message; @Override - public void close() throws Exception { + public void close() { srv.authHookManager.preHook.unregisterHook(this::preAuthHook); } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/components/CommandRemoverComponent.java b/LaunchServer/src/main/java/pro/gravit/launchserver/components/CommandRemoverComponent.java index 3332444e..a2c31bb5 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/components/CommandRemoverComponent.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/components/CommandRemoverComponent.java @@ -7,8 +7,8 @@ import pro.gravit.utils.command.Command; public class CommandRemoverComponent extends Component implements AutoCloseable { - public String[] removeList = new String[]{}; - public transient Map commandsList = new HashMap<>(); + public final String[] removeList = new String[]{}; + public final transient Map commandsList = new HashMap<>(); private transient LaunchServer server = null; @Override diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/components/Component.java b/LaunchServer/src/main/java/pro/gravit/launchserver/components/Component.java index b4789057..e1d61b26 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/components/Component.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/components/Component.java @@ -4,7 +4,7 @@ import pro.gravit.utils.ProviderMap; public abstract class Component { - public static ProviderMap providers = new ProviderMap<>(); + public static final ProviderMap providers = new ProviderMap<>(); private static boolean registredComp = false; public static void registerComponents() { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/components/RegLimiterComponent.java b/LaunchServer/src/main/java/pro/gravit/launchserver/components/RegLimiterComponent.java index 4fbdd053..6840041a 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/components/RegLimiterComponent.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/components/RegLimiterComponent.java @@ -39,7 +39,7 @@ public boolean registerHook(AuthHookManager.RegContext context) } @Override - public void close() throws Exception { + public void close() { launchServer.authHookManager.registraion.unregisterHook(this::registerHook); } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java index 7f7e01f5..85e1be7e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java @@ -44,7 +44,7 @@ public LaunchServerConfig setLaunchServer(LaunchServer server) { public String binaryName; - public boolean copyBinaries = true; + public final boolean copyBinaries = true; public LauncherConfig.LauncherEnvironment env; @@ -75,7 +75,7 @@ public AuthProviderPair getAuthProviderPair() { return pair; } } - return null; + throw new IllegalStateException("Default AuthProviderPair not found"); } public HWIDHandler hwidHandler; @@ -146,16 +146,13 @@ public void init(LaunchServer.ReloadType type) { } if(components != null) { - components.forEach((k,v) -> { - server.registerObject("component.".concat(k), v); - }); + components.forEach((k,v) -> server.registerObject("component.".concat(k), v)); } server.registerObject("permissionsHandler", permissionsHandler); server.registerObject("hwidHandler", hwidHandler); if(!type.equals(LaunchServer.ReloadType.NO_AUTH)) { - for (int i = 0; i < auth.length; ++i) { - AuthProviderPair pair = auth[i]; + for (AuthProviderPair pair : auth) { server.registerObject("auth.".concat(pair.name).concat(".provider"), pair.provider); server.registerObject("auth.".concat(pair.name).concat(".handler"), pair.handler); server.registerObject("auth.".concat(pair.name).concat(".texture"), pair.textureProvider); @@ -258,10 +255,10 @@ public static class NettyConfig { public String downloadURL; public String launcherEXEURL; public String address; - public Map bindings = new HashMap<>(); + public final Map bindings = new HashMap<>(); public NettyPerformanceConfig performance; public NettyBindAddress[] binds; - public LogLevel logLevel = LogLevel.DEBUG; + public final LogLevel logLevel = LogLevel.DEBUG; } public static class NettyPerformanceConfig { @@ -271,8 +268,8 @@ public static class NettyPerformanceConfig { } public static class NettyBindAddress { - public String address; - public int port; + public final String address; + public final int port; public NettyBindAddress(String address, int port) { this.address = address; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserHWID.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserHWID.java index a68298bc..49561182 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserHWID.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserHWID.java @@ -14,7 +14,7 @@ @Entity @Table(name = "users_hwids") public class UserHWID implements HWID { - private transient Supplier oshiSupp = () -> { + private final transient Supplier oshiSupp = () -> { OshiHWID hwid = new OshiHWID(); hwid.HWDiskSerial = this.HWDiskSerial; hwid.macAddr = this.macAddr; @@ -28,7 +28,7 @@ public class UserHWID implements HWID { @GeneratedValue(strategy = GenerationType.IDENTITY) private long id; - public long totalMemory = 0; + public final long totalMemory = 0; public String serialNumber; public String HWDiskSerial; public String processorID; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/provider/DaoProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/provider/DaoProvider.java index ab5586cd..5bd61018 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/provider/DaoProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/provider/DaoProvider.java @@ -6,7 +6,7 @@ import pro.gravit.utils.ProviderMap; public abstract class DaoProvider { - public static ProviderMap providers = new ProviderMap<>("DaoProvider"); + public static final ProviderMap providers = new ProviderMap<>("DaoProvider"); public UserDAO userDAO; public UserService userService; public static void registerProviders() diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/CertificateManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/CertificateManager.java index 69b76a4a..1987163a 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/CertificateManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/CertificateManager.java @@ -57,8 +57,8 @@ public class CertificateManager { public LauncherTrustManager trustManager; - public int validDays = 60; - public int minusHours = 6; + public final int validDays = 60; + public final int minusHours = 6; public String orgName; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/MirrorManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/MirrorManager.java index 592a5fc6..d52684e2 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/MirrorManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/MirrorManager.java @@ -15,7 +15,7 @@ public class MirrorManager { public static class Mirror { - String baseUrl; + final String baseUrl; boolean enabled; Mirror(String url) { @@ -34,7 +34,7 @@ public URL getURL(String mask, Object... args) throws MalformedURLException { } } - protected ArrayList list = new ArrayList<>(); + protected final ArrayList list = new ArrayList<>(); private Mirror defaultMirror; public void addMirror(String mirror) { @@ -44,7 +44,7 @@ public void addMirror(String mirror) { list.add(m); } - public void addMirror(String mirror, boolean enabled) throws MalformedURLException { + public void addMirror(String mirror, boolean enabled) { Mirror m = new Mirror(mirror); m.enabled = enabled; if (defaultMirror == null && enabled) defaultMirror = m; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/ReconfigurableManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/ReconfigurableManager.java index a949847e..f0cbd9fd 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/ReconfigurableManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/ReconfigurableManager.java @@ -10,7 +10,7 @@ import pro.gravit.utils.helper.VerifyHelper; public class ReconfigurableManager { - private class ReconfigurableVirtualCommand extends Command { + private static class ReconfigurableVirtualCommand extends Command { public ReconfigurableVirtualCommand(Map childs) { super(childs); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/SessionManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/SessionManager.java index 8e25b32f..f8d8b395 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/SessionManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/SessionManager.java @@ -14,7 +14,7 @@ public class SessionManager implements NeedGarbageCollection { public static final long SESSION_TIMEOUT = 3 * 60 * 60 * 1000; // 3 часа public static final boolean GARBAGE_SERVER = Boolean.parseBoolean(System.getProperty("launcher.garbageSessionsServer", "false")); - private Map clientSet = new HashMap<>(128); + private final Map clientSet = new HashMap<>(128); public boolean addClient(Client client) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/hook/AuthHookManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/hook/AuthHookManager.java index 739d4eda..65a09dab 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/hook/AuthHookManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/hook/AuthHookManager.java @@ -9,17 +9,17 @@ import pro.gravit.utils.HookSet; public class AuthHookManager { - public BiHookSet preHook = new BiHookSet<>(); - public BiHookSet postHook = new BiHookSet<>(); - public BiHookSet checkServerHook = new BiHookSet<>(); - public BiHookSet joinServerHook = new BiHookSet<>(); - public BiHookSet setProfileHook = new BiHookSet<>(); + public final BiHookSet preHook = new BiHookSet<>(); + public final BiHookSet postHook = new BiHookSet<>(); + public final BiHookSet checkServerHook = new BiHookSet<>(); + public final BiHookSet joinServerHook = new BiHookSet<>(); + public final BiHookSet setProfileHook = new BiHookSet<>(); public static class RegContext { - public String login; - public String password; - public String ip; - public boolean trustContext; + public final String login; + public final String password; + public final String ip; + public final boolean trustContext; public RegContext(String login, String password, String ip, boolean trustContext) { this.login = login; this.password = password; @@ -27,5 +27,5 @@ public RegContext(String login, String password, String ip, boolean trustContext this.trustContext = trustContext; } } - public HookSet registraion = new HookSet<>(); + public final HookSet registraion = new HookSet<>(); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerModulesManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerModulesManager.java index aeb68e84..c63e3b92 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerModulesManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerModulesManager.java @@ -11,7 +11,7 @@ import pro.gravit.utils.verify.LauncherTrustManager; public class LaunchServerModulesManager extends SimpleModuleManager { - public LaunchServerCoreModule coreModule; + public final LaunchServerCoreModule coreModule; public LaunchServerModulesManager(Path modulesDir, Path configDir, LauncherTrustManager trustManager) { super(modulesDir, configDir, trustManager); coreModule = new LaunchServerCoreModule(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/Client.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/Client.java index 13e60a5d..b368953c 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/Client.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/Client.java @@ -10,7 +10,7 @@ public class Client { public long session; public String auth_id; public long timestamp; - public Type type; + public final Type type; public ClientProfile profile; public boolean isAuth; public boolean checkSign; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java index 6749d352..0c4fc268 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java @@ -36,12 +36,12 @@ public class WebSocketService { public final ChannelGroup channels; - public static ProviderMap providers = new ProviderMap<>(); + public static final ProviderMap providers = new ProviderMap<>(); public static class WebSocketRequestContext { - public WebSocketServerResponse response; - public Client client; - public String ip; + public final WebSocketServerResponse response; + public final Client client; + public final String ip; public WebSocketRequestContext(WebSocketServerResponse response, Client client, String ip) { this.response = response; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/NettyIpForwardHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/NettyIpForwardHandler.java index ec74df6b..e1991e64 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/NettyIpForwardHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/NettyIpForwardHandler.java @@ -11,7 +11,7 @@ import pro.gravit.utils.helper.LogHelper; public class NettyIpForwardHandler extends MessageToMessageDecoder { - private NettyConnectContext context; + private final NettyConnectContext context; public NettyIpForwardHandler(NettyConnectContext context) { super(); @@ -19,7 +19,7 @@ public NettyIpForwardHandler(NettyConnectContext context) { } @Override - protected void decode(ChannelHandlerContext ctx, HttpRequest msg, List out) throws Exception { + protected void decode(ChannelHandlerContext ctx, HttpRequest msg, List out) { if (msg instanceof ReferenceCounted) { ((ReferenceCounted) msg).retain(); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/fileserver/FileServerHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/fileserver/FileServerHandler.java index ff3e6b19..fd2f0695 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/fileserver/FileServerHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/fileserver/FileServerHandler.java @@ -88,11 +88,6 @@ public void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) thr return; } - if (path == null) { - sendError(ctx, FORBIDDEN); - return; - } - File file = base.resolve(path).toFile(); if ((file.isHidden() && !showHiddenFiles) || !file.exists()) { sendError(ctx, NOT_FOUND); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/admin/AddLogListenerResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/admin/AddLogListenerResponse.java index 1a7ec741..5a54843c 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/admin/AddLogListenerResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/admin/AddLogListenerResponse.java @@ -7,7 +7,7 @@ import pro.gravit.utils.helper.LogHelper; public class AddLogListenerResponse extends SimpleResponse { - public LogHelper.OutputTypes outputType = LogHelper.OutputTypes.PLAIN; + public final LogHelper.OutputTypes outputType = LogHelper.OutputTypes.PLAIN; @Override public String getType() { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java index 7d03fb55..896a6806 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java @@ -30,7 +30,7 @@ import pro.gravit.utils.helper.VerifyHelper; public class AuthResponse extends SimpleResponse { - public transient static Random random = new SecureRandom(); + public final transient static Random random = new SecureRandom(); public String login; public String client; public String customText; @@ -139,14 +139,14 @@ public AuthContext(Client client, String login, String customText, String profil this.ip = ip; this.authType = authType; } - public String login; + public final String login; @Deprecated public int password_length; //Use AuthProvider for get password - public String profileName; - public HWID hwid; - public String customText; - public String ip; - public ConnectTypes authType; - public Client client; + public final String profileName; + public final HWID hwid; + public final String customText; + public final String ip; + public final ConnectTypes authType; + public final Client client; } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/SetPasswordResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/SetPasswordResponse.java index 93f2fb26..c77758a4 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/SetPasswordResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/SetPasswordResponse.java @@ -16,7 +16,7 @@ public String getType() { } @Override - public void execute(ChannelHandlerContext ctx, Client client) throws Exception { + public void execute(ChannelHandlerContext ctx, Client client) { if(( oldPassword == null && username == null ) || newPassword == null) { sendError("Request invalid"); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/profile/BatchProfileByUsername.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/profile/BatchProfileByUsername.java index 9e8e58a2..ee1c5e8e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/profile/BatchProfileByUsername.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/profile/BatchProfileByUsername.java @@ -10,7 +10,7 @@ import pro.gravit.utils.helper.LogHelper; public class BatchProfileByUsername extends SimpleResponse { - class Entry { + static class Entry { String username; String client; } diff --git a/LaunchServer/src/test/java/pro/gravit/launchserver/StartLaunchServerTest.java b/LaunchServer/src/test/java/pro/gravit/launchserver/StartLaunchServerTest.java index 3b04e1b6..825ce546 100644 --- a/LaunchServer/src/test/java/pro/gravit/launchserver/StartLaunchServerTest.java +++ b/LaunchServer/src/test/java/pro/gravit/launchserver/StartLaunchServerTest.java @@ -49,22 +49,22 @@ public static void prepare() throws Exception .setCertificateManager(new CertificateManager()) .setLaunchServerConfigManager(new LaunchServer.LaunchServerConfigManager() { @Override - public LaunchServerConfig readConfig() throws IOException { + public LaunchServerConfig readConfig() { return null; } @Override - public LaunchServerRuntimeConfig readRuntimeConfig() throws IOException { + public LaunchServerRuntimeConfig readRuntimeConfig() { return null; } @Override - public void writeConfig(LaunchServerConfig config) throws IOException { + public void writeConfig(LaunchServerConfig config) { } @Override - public void writeRuntimeConfig(LaunchServerRuntimeConfig config) throws IOException { + public void writeRuntimeConfig(LaunchServerRuntimeConfig config) { } }) @@ -73,8 +73,7 @@ public void writeRuntimeConfig(LaunchServerRuntimeConfig config) throws IOExcept launchServer = builder.build(); } @Test - public void start() throws Exception - { + public void start() { launchServer.run(); } } diff --git a/LaunchServerConsole/src/main/java/pro/gravit/launchserver/console/ExitCommand.java b/LaunchServerConsole/src/main/java/pro/gravit/launchserver/console/ExitCommand.java index f9c84c04..01be5427 100644 --- a/LaunchServerConsole/src/main/java/pro/gravit/launchserver/console/ExitCommand.java +++ b/LaunchServerConsole/src/main/java/pro/gravit/launchserver/console/ExitCommand.java @@ -17,7 +17,7 @@ public String getUsageDescription() { } @Override - public void invoke(String... args) throws Exception { + public void invoke(String... args) { System.exit(0); } } diff --git a/LaunchServerConsole/src/main/java/pro/gravit/launchserver/console/LogListenerCommand.java b/LaunchServerConsole/src/main/java/pro/gravit/launchserver/console/LogListenerCommand.java index 4de6d4ee..adef0b69 100644 --- a/LaunchServerConsole/src/main/java/pro/gravit/launchserver/console/LogListenerCommand.java +++ b/LaunchServerConsole/src/main/java/pro/gravit/launchserver/console/LogListenerCommand.java @@ -8,9 +8,9 @@ import pro.gravit.utils.helper.LogHelper; public class LogListenerCommand extends Command { - public class LogListenerRequest implements WebSocketRequest { + public static class LogListenerRequest implements WebSocketRequest { @LauncherNetworkAPI - public LogHelper.OutputTypes outputType; + public final LogHelper.OutputTypes outputType; public LogListenerRequest(LogHelper.OutputTypes outputType) { this.outputType = outputType; diff --git a/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java b/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java index aaeba1ec..e5b08c99 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java +++ b/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java @@ -21,7 +21,7 @@ public class ClientLauncherWrapper { public static final String WAIT_PROCESS_PROPERTY = "launcher.waitProcess"; public static final String NO_JAVA9_CHECK_PROPERTY = "launcher.noJava9Check"; public static boolean waitProcess = Boolean.getBoolean(WAIT_PROCESS_PROPERTY); - public static boolean noJava9check = Boolean.getBoolean(NO_JAVA9_CHECK_PROPERTY); + public static final boolean noJava9check = Boolean.getBoolean(NO_JAVA9_CHECK_PROPERTY); public static void main(String[] arguments) throws IOException, InterruptedException { LogHelper.printVersion("Launcher"); diff --git a/Launcher/src/main/java/pro/gravit/launcher/NewLauncherSettings.java b/Launcher/src/main/java/pro/gravit/launcher/NewLauncherSettings.java index f8db286d..4947649d 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/NewLauncherSettings.java +++ b/Launcher/src/main/java/pro/gravit/launcher/NewLauncherSettings.java @@ -48,11 +48,11 @@ public class NewLauncherSettings { public static class HashedStoreEntry { @LauncherAPI - public HashedDir hdir; + public final HashedDir hdir; @LauncherAPI - public String name; + public final String name; @LauncherAPI - public String fullPath; + public final String fullPath; @LauncherAPI public transient boolean needSave = false; @@ -64,7 +64,7 @@ public HashedStoreEntry(HashedDir hdir, String name, String fullPath) { } @LauncherAPI - public transient List lastHDirs = new ArrayList<>(16); + public final transient List lastHDirs = new ArrayList<>(16); @LauncherAPI public void putHDir(String name, Path path, HashedDir dir) { diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index ea3a684b..64cfd348 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -596,12 +596,12 @@ public static void verifyHDir(Path dir, HashedDir hdir, FileNameMatcher matcher, private ClientLauncher() { } - public static interface ParamsAPI { + public interface ParamsAPI { ParamContainer read() throws Exception; - void write(ParamContainer p) throws Exception; + void write(ParamContainer p); } - public static ParamsAPI container = new ParamsAPI() { + public static final ParamsAPI container = new ParamsAPI() { @Override public ParamContainer read() throws Exception { ParamContainer p; @@ -614,7 +614,7 @@ public ParamContainer read() throws Exception { return p; } @Override - public void write(ParamContainer p) throws Exception { + public void write(ParamContainer p) { setWriteParamsThread(CommonHelper.newThread("Client params writter", true, () -> { try { diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherContext.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherContext.java index 9865c312..84a96aa4 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherContext.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherContext.java @@ -9,7 +9,7 @@ public class ClientLauncherContext { public Path javaBin; - public List args = new LinkedList<>(); + public final List args = new LinkedList<>(); public String pathLauncher; public ProcessBuilder builder; public ClientProfile clientProfile; diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientModuleManager.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientModuleManager.java index 1d5ba556..859c3644 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientModuleManager.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientModuleManager.java @@ -16,17 +16,17 @@ public ClientModuleManager() { } @Override - public void autoload() throws IOException { + public void autoload() { throw new UnsupportedOperationException(); } @Override - public void autoload(Path dir) throws IOException { + public void autoload(Path dir) { throw new UnsupportedOperationException(); } @Override - public LauncherModule loadModule(Path file) throws IOException { + public LauncherModule loadModule(Path file) { throw new UnsupportedOperationException(); } diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/FunctionalBridge.java b/Launcher/src/main/java/pro/gravit/launcher/client/FunctionalBridge.java index c6f9aefc..b6c19774 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/FunctionalBridge.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/FunctionalBridge.java @@ -26,11 +26,11 @@ public class FunctionalBridge { @LauncherAPI - public static ScheduledExecutorService threadPool = Executors.newScheduledThreadPool(0); + public static final ScheduledExecutorService threadPool = Executors.newScheduledThreadPool(0); @LauncherAPI public static OshiHWIDProvider hwidProvider; @LauncherAPI - public static AtomicReference hwid = new AtomicReference<>(); + public static final AtomicReference hwid = new AtomicReference<>(); @LauncherAPI public static Thread getHWID = null; diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ServerPinger.java b/Launcher/src/main/java/pro/gravit/launcher/client/ServerPinger.java index 5a64e524..fc8ecd48 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ServerPinger.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ServerPinger.java @@ -22,7 +22,7 @@ import pro.gravit.utils.helper.VerifyHelper; public final class ServerPinger { - private JsonParser parser = new JsonParser(); + private final JsonParser parser = new JsonParser(); public static final class Result { @LauncherAPI diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/UserSettings.java b/Launcher/src/main/java/pro/gravit/launcher/client/UserSettings.java index 6504d459..1f6fb9b5 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/UserSettings.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/UserSettings.java @@ -3,5 +3,5 @@ import pro.gravit.utils.ProviderMap; public class UserSettings { - public static ProviderMap providers = new ProviderMap<>(); + public static final ProviderMap providers = new ProviderMap<>(); } diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientPreGuiPhase.java b/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientPreGuiPhase.java index ebbad380..b7077cdd 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientPreGuiPhase.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientPreGuiPhase.java @@ -4,7 +4,7 @@ import pro.gravit.launcher.modules.LauncherModule; public class ClientPreGuiPhase extends LauncherModule.Event { - public RuntimeProvider runtimeProvider; + public final RuntimeProvider runtimeProvider; public ClientPreGuiPhase(RuntimeProvider runtimeProvider) { this.runtimeProvider = runtimeProvider; diff --git a/Launcher/src/main/java/pro/gravit/launcher/console/FeatureCommand.java b/Launcher/src/main/java/pro/gravit/launcher/console/FeatureCommand.java index 743ca647..78a27999 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/console/FeatureCommand.java +++ b/Launcher/src/main/java/pro/gravit/launcher/console/FeatureCommand.java @@ -18,7 +18,7 @@ public String getUsageDescription() { @Override public void invoke(String... args) throws Exception { verifyArgs(args, 2); - boolean enabled = Boolean.valueOf(args[1]); + boolean enabled = Boolean.parseBoolean(args[1]); switch (args[0]) { case "store": { SettingsManager.settings.featureStore = enabled; diff --git a/Launcher/src/main/java/pro/gravit/launcher/console/admin/LogListenerCommand.java b/Launcher/src/main/java/pro/gravit/launcher/console/admin/LogListenerCommand.java index 8610fa07..8e80354d 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/console/admin/LogListenerCommand.java +++ b/Launcher/src/main/java/pro/gravit/launcher/console/admin/LogListenerCommand.java @@ -8,9 +8,9 @@ import pro.gravit.utils.helper.LogHelper; public class LogListenerCommand extends Command { - public class LogListenerRequest implements WebSocketRequest { + public static class LogListenerRequest implements WebSocketRequest { @LauncherNetworkAPI - public LogHelper.OutputTypes outputType; + public final LogHelper.OutputTypes outputType; public LogListenerRequest(LogHelper.OutputTypes outputType) { this.outputType = outputType; diff --git a/Launcher/src/main/java/pro/gravit/launcher/console/store/CopyStoreDirCommand.java b/Launcher/src/main/java/pro/gravit/launcher/console/store/CopyStoreDirCommand.java index ebdc11a5..2f23c878 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/console/store/CopyStoreDirCommand.java +++ b/Launcher/src/main/java/pro/gravit/launcher/console/store/CopyStoreDirCommand.java @@ -24,8 +24,8 @@ public String getUsageDescription() { public void invoke(String... args) throws Exception { verifyArgs(args, 2); int ind = 1; - int index = Integer.valueOf(args[0]); - boolean overwrite = Boolean.valueOf(args[1]); + int index = Integer.parseInt(args[0]); + boolean overwrite = Boolean.parseBoolean(args[1]); for (NewLauncherSettings.HashedStoreEntry e : SettingsManager.settings.lastHDirs) { if (ind == index) { LogHelper.info("Copy [%d] FullPath: %s name: %s", ind, e.fullPath, e.name); diff --git a/Launcher/src/main/java/pro/gravit/launcher/console/store/LinkStoreDirCommand.java b/Launcher/src/main/java/pro/gravit/launcher/console/store/LinkStoreDirCommand.java index ff915858..b2ab24b7 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/console/store/LinkStoreDirCommand.java +++ b/Launcher/src/main/java/pro/gravit/launcher/console/store/LinkStoreDirCommand.java @@ -25,7 +25,7 @@ public String getUsageDescription() { public void invoke(String... args) throws Exception { verifyArgs(args, 1); int ind = 1; - int index = Integer.valueOf(args[0]); + int index = Integer.parseInt(args[0]); for (NewLauncherSettings.HashedStoreEntry e : SettingsManager.settings.lastHDirs) { if (ind == index) { LogHelper.info("Copy [%d] FullPath: %s name: %s", ind, e.fullPath, e.name); diff --git a/Launcher/src/main/java/pro/gravit/launcher/console/store/StoreListCommand.java b/Launcher/src/main/java/pro/gravit/launcher/console/store/StoreListCommand.java index be1bad46..3ed81fc7 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/console/store/StoreListCommand.java +++ b/Launcher/src/main/java/pro/gravit/launcher/console/store/StoreListCommand.java @@ -17,7 +17,7 @@ public String getUsageDescription() { } @Override - public void invoke(String... args) throws Exception { + public void invoke(String... args) { int ind = 1; for (NewLauncherSettings.HashedStoreEntry e : SettingsManager.settings.lastHDirs) { LogHelper.info("[%d] FullPath: %s name: %s", ind, e.fullPath, e.name); diff --git a/Launcher/src/main/java/pro/gravit/launcher/gui/RuntimeProvider.java b/Launcher/src/main/java/pro/gravit/launcher/gui/RuntimeProvider.java index ab31d734..398b0886 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/gui/RuntimeProvider.java +++ b/Launcher/src/main/java/pro/gravit/launcher/gui/RuntimeProvider.java @@ -5,5 +5,5 @@ public interface RuntimeProvider { void preLoad() throws Exception; - void init(boolean clientInstance) throws Exception; + void init(boolean clientInstance); } diff --git a/Launcher/src/main/java/pro/gravit/launcher/managers/ClientHookManager.java b/Launcher/src/main/java/pro/gravit/launcher/managers/ClientHookManager.java index 3758d281..c273a983 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/managers/ClientHookManager.java +++ b/Launcher/src/main/java/pro/gravit/launcher/managers/ClientHookManager.java @@ -8,13 +8,13 @@ import pro.gravit.utils.HookSet; public class ClientHookManager { - public static HookSet initGuiHook = new HookSet<>(); - public static HookSet paramsInputHook = new HookSet<>(); - public static HookSet paramsOutputHook = new HookSet<>(); + public static final HookSet initGuiHook = new HookSet<>(); + public static final HookSet paramsInputHook = new HookSet<>(); + public static final HookSet paramsOutputHook = new HookSet<>(); - public static HookSet clientLaunchHook = new HookSet<>(); - public static HookSet clientLaunchFinallyHook = new HookSet<>(); + public static final HookSet clientLaunchHook = new HookSet<>(); + public static final HookSet clientLaunchFinallyHook = new HookSet<>(); - public static BiHookSet preStartHook = new BiHookSet<>(); - public static BiHookSet postStartHook = new BiHookSet<>(); + public static final BiHookSet preStartHook = new BiHookSet<>(); + public static final BiHookSet postStartHook = new BiHookSet<>(); } diff --git a/Launcher/src/main/java/pro/gravit/launcher/managers/HasherStore.java b/Launcher/src/main/java/pro/gravit/launcher/managers/HasherStore.java index 348a4ad5..10b6f3e6 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/managers/HasherStore.java +++ b/Launcher/src/main/java/pro/gravit/launcher/managers/HasherStore.java @@ -18,7 +18,7 @@ public class HasherStore { public Map store; - public class HasherStoreEnity { + public static class HasherStoreEnity { @LauncherAPI public HashedDir hdir; @LauncherAPI diff --git a/Launcher/src/main/java/pro/gravit/launcher/managers/SettingsManager.java b/Launcher/src/main/java/pro/gravit/launcher/managers/SettingsManager.java index fcc5a95c..c2525be2 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/managers/SettingsManager.java +++ b/Launcher/src/main/java/pro/gravit/launcher/managers/SettingsManager.java @@ -19,7 +19,7 @@ import pro.gravit.utils.helper.LogHelper; public class SettingsManager extends JsonConfigurable { - public class StoreFileVisitor extends SimpleFileVisitor { + public static class StoreFileVisitor extends SimpleFileVisitor { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { diff --git a/Launcher/src/main/java/pro/gravit/launcher/patches/FMLPatcher.java b/Launcher/src/main/java/pro/gravit/launcher/patches/FMLPatcher.java index 0e060700..3fdf9ff5 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/patches/FMLPatcher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/patches/FMLPatcher.java @@ -33,7 +33,7 @@ public static void apply() { } } - public static void exit(final int code) throws Throwable { + public static void exit(final int code) { for (MethodHandle mh : MHS) try { mh.invoke(code); diff --git a/Launcher/src/main/java/pro/gravit/launcher/utils/NativeJVMHalt.java b/Launcher/src/main/java/pro/gravit/launcher/utils/NativeJVMHalt.java index d2d248a7..ef5a5083 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/utils/NativeJVMHalt.java +++ b/Launcher/src/main/java/pro/gravit/launcher/utils/NativeJVMHalt.java @@ -14,7 +14,7 @@ public NativeJVMHalt(int haltCode) { System.out.println("JVM exit code " + haltCode); } - public int haltCode; + public final int haltCode; public native void aaabbb38C_D(); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/ClientPermissions.java b/LauncherAPI/src/main/java/pro/gravit/launcher/ClientPermissions.java index fc6bbe6e..f9aabbf1 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/ClientPermissions.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/ClientPermissions.java @@ -13,11 +13,11 @@ public class ClientPermissions { @LauncherAPI public boolean canServer; @LauncherAPI - public boolean canUSR1; + public final boolean canUSR1; @LauncherAPI - public boolean canUSR2; + public final boolean canUSR2; @LauncherAPI - public boolean canUSR3; + public final boolean canUSR3; @LauncherAPI public boolean canBot; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/SecureAutogenConfig.java b/LauncherAPI/src/main/java/pro/gravit/launcher/SecureAutogenConfig.java index b72e5cb9..a56ff76d 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/SecureAutogenConfig.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/SecureAutogenConfig.java @@ -3,7 +3,7 @@ import java.nio.charset.StandardCharsets; public class SecureAutogenConfig { - public byte[][] certificates; + public final byte[][] certificates; public SecureAutogenConfig() { //Пока не реализован SecureLauncherConfigurator diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java b/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java index e81c258f..a9eeaa36 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java @@ -9,6 +9,7 @@ import java.net.URL; import java.nio.file.Path; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.CopyOnWriteArrayList; @@ -52,8 +53,8 @@ public interface DownloadTotalCallback { } public static class DownloadTask { - public String apply; - public long size; + public final String apply; + public final long size; public DownloadTask(String apply, long size) { this.apply = apply; @@ -65,7 +66,7 @@ public void download(String base, List applies, Path dstDirFile, D try (CloseableHttpClient httpclient = HttpClients.custom().setUserAgent(IOHelper.USER_AGENT) .setRedirectStrategy(new LaxRedirectStrategy()) .build()) { - applies.sort((a,b) -> Long.compare(a.size, b.size)); + applies.sort(Comparator.comparingLong(a -> a.size)); List> toExec = new ArrayList<>(); URI baseUri = new URI(base); String scheme = baseUri.getScheme(); @@ -106,7 +107,7 @@ public void download(String base, List applies, Path dstDirFile, D } } - public void downloadZip(String base, List applies, Path dstDirFile, DownloadCallback callback, DownloadTotalCallback totalCallback, boolean fullDownload) throws IOException, URISyntaxException { + public void downloadZip(String base, List applies, Path dstDirFile, DownloadCallback callback, DownloadTotalCallback totalCallback, boolean fullDownload) throws IOException { /*try (CloseableHttpClient httpclient = HttpClients.custom() .setRedirectStrategy(new LaxRedirectStrategy()) .build()) { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/ControlEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/ControlEvent.java index 56253752..e83367f9 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/ControlEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/ControlEvent.java @@ -15,5 +15,5 @@ public ControlEvent(ControlCommand signal) { this.signal = signal; } - public ControlCommand signal; + public final ControlCommand signal; } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/SignalEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/SignalEvent.java index e759f3b6..eef9e7fd 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/SignalEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/SignalEvent.java @@ -5,7 +5,7 @@ //Используется, что бы послать короткое сообщение, которое вмещается в int public class SignalEvent { @LauncherNetworkAPI - public int signal; + public final int signal; public SignalEvent(int signal) { this.signal = signal; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ExecCommandRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ExecCommandRequestEvent.java index 988c2d5a..cdcfa4ff 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ExecCommandRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ExecCommandRequestEvent.java @@ -10,7 +10,7 @@ public String getType() { } @LauncherNetworkAPI - public boolean success; + public final boolean success; public ExecCommandRequestEvent(boolean success) { this.success = success; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetAvailabilityAuthRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetAvailabilityAuthRequestEvent.java index 5af4000d..2a69291b 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetAvailabilityAuthRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetAvailabilityAuthRequestEvent.java @@ -8,9 +8,9 @@ public class GetAvailabilityAuthRequestEvent extends RequestEvent { public static class AuthAvailability { @LauncherNetworkAPI - public String name; + public final String name; @LauncherNetworkAPI - public String displayName; + public final String displayName; public AuthAvailability(String name, String displayName) { this.name = name; @@ -19,7 +19,7 @@ public AuthAvailability(String name, String displayName) { } @LauncherNetworkAPI - public List list; + public final List list; public GetAvailabilityAuthRequestEvent(List list) { this.list = list; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetSecureTokenRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetSecureTokenRequestEvent.java index d5741678..e221b76c 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetSecureTokenRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetSecureTokenRequestEvent.java @@ -5,7 +5,7 @@ public class GetSecureTokenRequestEvent extends RequestEvent { @LauncherNetworkAPI - public String secureToken; + public final String secureToken; @Override public String getType() { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/JoinServerRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/JoinServerRequestEvent.java index 59dbbbc9..4f9d15cb 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/JoinServerRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/JoinServerRequestEvent.java @@ -15,7 +15,7 @@ public JoinServerRequestEvent(boolean allow) { } @LauncherNetworkAPI - public boolean allow; + public final boolean allow; @Override public String getType() { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/LogEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/LogEvent.java index db2f6f35..c93bddbc 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/LogEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/LogEvent.java @@ -10,7 +10,7 @@ public String getType() { } @LauncherNetworkAPI - public String string; + public final String string; public LogEvent(String string) { this.string = string; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ProfileByUsernameRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ProfileByUsernameRequestEvent.java index afad9278..84ceb288 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ProfileByUsernameRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ProfileByUsernameRequestEvent.java @@ -13,7 +13,7 @@ public class ProfileByUsernameRequestEvent extends RequestEvent { @LauncherNetworkAPI public String error; @LauncherNetworkAPI - public PlayerProfile playerProfile; + public final PlayerProfile playerProfile; public ProfileByUsernameRequestEvent(PlayerProfile playerProfile) { this.playerProfile = playerProfile; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/SetProfileRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/SetProfileRequestEvent.java index 98d090b1..ed6f8afe 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/SetProfileRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/SetProfileRequestEvent.java @@ -11,7 +11,7 @@ public class SetProfileRequestEvent extends RequestEvent { @SuppressWarnings("unused") private static final UUID uuid = UUID.fromString("08c0de9e-4364-4152-9066-8354a3a48541"); @LauncherNetworkAPI - public ClientProfile newProfile; + public final ClientProfile newProfile; public SetProfileRequestEvent(ClientProfile newProfile) { this.newProfile = newProfile; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/UpdateRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/UpdateRequestEvent.java index 5f997795..ce917b3b 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/UpdateRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/UpdateRequestEvent.java @@ -6,11 +6,11 @@ public class UpdateRequestEvent extends RequestEvent { @LauncherNetworkAPI - public HashedDir hdir; + public final HashedDir hdir; @LauncherNetworkAPI public String url; @LauncherNetworkAPI - public boolean zip; + public final boolean zip; @LauncherNetworkAPI public boolean fullDownload; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/VerifySecureTokenRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/VerifySecureTokenRequestEvent.java index 3f74c2d9..12a6e7bb 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/VerifySecureTokenRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/VerifySecureTokenRequestEvent.java @@ -5,7 +5,7 @@ public class VerifySecureTokenRequestEvent extends RequestEvent { @LauncherAPI - public boolean success; + public final boolean success; @Override public String getType() { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWIDProvider.java b/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWIDProvider.java index 0b924e73..28dd6db2 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWIDProvider.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWIDProvider.java @@ -3,7 +3,7 @@ import pro.gravit.utils.ProviderMap; public class HWIDProvider { - public static ProviderMap hwids = new ProviderMap<>(); + public static final ProviderMap hwids = new ProviderMap<>(); public static void registerHWIDs() { hwids.register("oshi", OshiHWID.class); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/managers/SimpleModulesConfigManager.java b/LauncherAPI/src/main/java/pro/gravit/launcher/managers/SimpleModulesConfigManager.java index a5379675..0bea294b 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/managers/SimpleModulesConfigManager.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/managers/SimpleModulesConfigManager.java @@ -10,7 +10,7 @@ import pro.gravit.utils.helper.LogHelper; public class SimpleModulesConfigManager implements ModulesConfigManager { - public Path configDir; + public final Path configDir; public SimpleModulesConfigManager(Path configDir) { this.configDir = configDir; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModule.java b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModule.java index c6c15472..838cb1dd 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModule.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModule.java @@ -7,7 +7,7 @@ public abstract class LauncherModule { private LauncherModulesContext context; @SuppressWarnings("rawtypes") - private Map, EventHandler> eventMap = new HashMap<>(); + private final Map, EventHandler> eventMap = new HashMap<>(); protected LauncherModulesManager modulesManager; protected final LauncherModuleInfo moduleInfo; protected ModulesConfigManager modulesConfigManager; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/events/PreGsonPhase.java b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/events/PreGsonPhase.java index 6e1acd11..25dcb4cb 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/events/PreGsonPhase.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/events/PreGsonPhase.java @@ -5,7 +5,7 @@ import pro.gravit.launcher.modules.LauncherModule; public class PreGsonPhase extends LauncherModule.Event { - public GsonBuilder gsonBuilder; + public final GsonBuilder gsonBuilder; public PreGsonPhase(GsonBuilder gsonBuilder) { this.gsonBuilder = gsonBuilder; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java index 237a6a9e..fe15f5ac 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java @@ -42,7 +42,7 @@ public class SimpleModuleManager implements LauncherModulesManager { protected LauncherInitContext initContext; protected LauncherTrustManager.CheckMode checkMode = LauncherTrustManager.CheckMode.WARN_IN_NOT_SIGNED; - protected PublicURLClassLoader classLoader = new PublicURLClassLoader(new URL[]{}); + protected final PublicURLClassLoader classLoader = new PublicURLClassLoader(new URL[]{}); protected final class ModulesVisitor extends SimpleFileVisitor { private ModulesVisitor() { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java index 3bb4c443..3e477c69 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java @@ -445,133 +445,5 @@ public void verify() { } } - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((assetDir == null) ? 0 : assetDir.hashCode()); - result = prime * result + ((assetIndex == null) ? 0 : assetIndex.hashCode()); - result = prime * result + ((classPath == null) ? 0 : classPath.hashCode()); - result = prime * result + ((clientArgs == null) ? 0 : clientArgs.hashCode()); - result = prime * result + ((dir == null) ? 0 : dir.hashCode()); - result = prime * result + ((jvmArgs == null) ? 0 : jvmArgs.hashCode()); - result = prime * result + ((mainClass == null) ? 0 : mainClass.hashCode()); - result = prime * result + ((serverAddress == null) ? 0 : serverAddress.hashCode()); - result = prime * result + serverPort; - result = prime * result + sortIndex; - result = prime * result + ((title == null) ? 0 : title.hashCode()); - result = prime * result + ((info == null) ? 0 : info.hashCode()); - result = prime * result + ((update == null) ? 0 : update.hashCode()); - result = prime * result + ((updateExclusions == null) ? 0 : updateExclusions.hashCode()); - result = prime * result + (updateFastCheck ? 1231 : 1237); - result = prime * result + ((updateOptional == null) ? 0 : updateOptional.hashCode()); - result = prime * result + ((updateShared == null) ? 0 : updateShared.hashCode()); - result = prime * result + ((updateVerify == null) ? 0 : updateVerify.hashCode()); - result = prime * result + (useWhitelist ? 1231 : 1237); - result = prime * result + ((version == null) ? 0 : version.hashCode()); - result = prime * result + ((whitelist == null) ? 0 : whitelist.hashCode()); - return result; - } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - ClientProfile other = (ClientProfile) obj; - if (assetDir == null) { - if (other.assetDir != null) - return false; - } else if (!assetDir.equals(other.assetDir)) - return false; - if (assetIndex == null) { - if (other.assetIndex != null) - return false; - } else if (!assetIndex.equals(other.assetIndex)) - return false; - if (classPath == null) { - if (other.classPath != null) - return false; - } else if (!classPath.equals(other.classPath)) - return false; - if (clientArgs == null) { - if (other.clientArgs != null) - return false; - } else if (!clientArgs.equals(other.clientArgs)) - return false; - if (dir == null) { - if (other.dir != null) - return false; - } else if (!dir.equals(other.dir)) - return false; - if (jvmArgs == null) { - if (other.jvmArgs != null) - return false; - } else if (!jvmArgs.equals(other.jvmArgs)) - return false; - if (mainClass == null) { - if (other.mainClass != null) - return false; - } else if (!mainClass.equals(other.mainClass)) - return false; - if (serverAddress == null) { - if (other.serverAddress != null) - return false; - } else if (!serverAddress.equals(other.serverAddress)) - return false; - if (serverPort != other.serverPort) - return false; - if (sortIndex != other.sortIndex) - return false; - if (title == null) { - if (other.title != null) - return false; - } else if (!title.equals(other.title)) - return false; - if (info == null) { - if (other.info != null) - return false; - } else if (!info.equals(other.info)) - return false; - if (update == null) { - if (other.update != null) - return false; - } else if (!update.equals(other.update)) - return false; - if (updateExclusions == null) { - if (other.updateExclusions != null) - return false; - } else if (!updateExclusions.equals(other.updateExclusions)) - return false; - if (updateFastCheck != other.updateFastCheck) - return false; - if (updateOptional == null) { - if (other.updateOptional != null) - return false; - } else if (!updateOptional.equals(other.updateOptional)) - return false; - if (updateShared == null) { - if (other.updateShared != null) - return false; - } else if (!updateShared.equals(other.updateShared)) - return false; - if (updateVerify == null) { - if (other.updateVerify != null) - return false; - } else if (!updateVerify.equals(other.updateVerify)) - return false; - if (useWhitelist != other.useWhitelist) - return false; - if (version == null) { - if (other.version != null) - return false; - } else if (!version.equals(other.version)) - return false; - if (whitelist == null) { - return other.whitelist == null; - } else return whitelist.equals(other.whitelist); - } } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalFile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalFile.java index 8dfffc8c..e949a1a7 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalFile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalFile.java @@ -17,7 +17,7 @@ public class OptionalFile { @LauncherAPI public boolean mark; @LauncherAPI - public boolean visible = true; + public final boolean visible = true; @LauncherAPI public String name; @LauncherAPI @@ -35,7 +35,7 @@ public class OptionalFile { @LauncherAPI public boolean isPreset; @LauncherAPI - public long permissions = 0L; + public final long permissions = 0L; @LauncherAPI public transient Set dependenciesCount; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/PingRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/PingRequest.java index cabe6414..b911b957 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/PingRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/PingRequest.java @@ -5,7 +5,7 @@ public final class PingRequest extends Request { @Override - protected WebSocketEvent requestDo(StandartClientWebSocketService service) throws Exception { + protected WebSocketEvent requestDo(StandartClientWebSocketService service) { return null; } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java index 5c8dd4e9..4b70c0a0 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java @@ -13,7 +13,7 @@ public abstract class Request implements WebSocketRequest { private static long session = SecurityHelper.secureRandom.nextLong(); @LauncherNetworkAPI - public UUID requestUUID = UUID.randomUUID(); + public final UUID requestUUID = UUID.randomUUID(); public static StandartClientWebSocketService service; public static void setSession(long session) { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/admin/ExecCommandRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/admin/ExecCommandRequest.java index c3345f0b..802bd43b 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/admin/ExecCommandRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/admin/ExecCommandRequest.java @@ -7,7 +7,7 @@ public class ExecCommandRequest extends Request implements WebSocketRequest { @LauncherAPI - public String cmd; + public final String cmd; public ExecCommandRequest(String cmd) { this.cmd = cmd; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/AuthRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/AuthRequest.java index 868a39b2..e74c2e57 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/AuthRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/AuthRequest.java @@ -12,7 +12,7 @@ import pro.gravit.utils.helper.VerifyHelper; public final class AuthRequest extends Request implements WebSocketRequest { - public static ProviderMap providers = new ProviderMap<>(); + public static final ProviderMap providers = new ProviderMap<>(); public interface AuthPasswordInterface { boolean check(); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/RestoreSessionRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/RestoreSessionRequest.java index 5e15bfbc..6be0e757 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/RestoreSessionRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/RestoreSessionRequest.java @@ -7,7 +7,7 @@ public class RestoreSessionRequest extends Request implements WebSocketRequest { @LauncherNetworkAPI - public long session; + public final long session; public RestoreSessionRequest(long session) { this.session = session; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/SetProfileRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/SetProfileRequest.java index 0cc7d943..3c72b502 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/SetProfileRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/SetProfileRequest.java @@ -8,7 +8,7 @@ public class SetProfileRequest extends Request implements WebSocketRequest { @LauncherNetworkAPI - public String client; + public final String client; public SetProfileRequest(ClientProfile profile) { this.client = profile.getTitle(); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/LauncherRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/LauncherRequest.java index 16273a2f..52072559 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/LauncherRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/LauncherRequest.java @@ -24,9 +24,9 @@ public final class LauncherRequest extends Request impleme @LauncherNetworkAPI public byte[] digest; @LauncherNetworkAPI - public String secureHash; + public final String secureHash; @LauncherNetworkAPI - public String secureSalt; + public final String secureSalt; @LauncherNetworkAPI public int launcher_type = EXE_BINARY ? 2 : 1; @LauncherAPI diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java index 7a45d41a..164cefdb 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java @@ -28,17 +28,17 @@ public final class UpdateRequest extends Request implements WebSocketRequest { public interface UpdateController { - void preUpdate(UpdateRequest request, UpdateRequestEvent e) throws IOException; + void preUpdate(UpdateRequest request, UpdateRequestEvent e); - void preDiff(UpdateRequest request, UpdateRequestEvent e) throws IOException; + void preDiff(UpdateRequest request, UpdateRequestEvent e); void postDiff(UpdateRequest request, UpdateRequestEvent e, HashedDir.Diff diff) throws IOException; - void preDownload(UpdateRequest request, UpdateRequestEvent e, List adds) throws IOException; + void preDownload(UpdateRequest request, UpdateRequestEvent e, List adds); - void postDownload(UpdateRequest request, UpdateRequestEvent e) throws IOException; + void postDownload(UpdateRequest request, UpdateRequestEvent e); - void postUpdate(UpdateRequest request, UpdateRequestEvent e) throws IOException; + void postUpdate(UpdateRequest request, UpdateRequestEvent e); } private static UpdateController controller; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/BatchProfileByUsernameRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/BatchProfileByUsernameRequest.java index e304e7a9..486ac94a 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/BatchProfileByUsernameRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/BatchProfileByUsernameRequest.java @@ -12,7 +12,7 @@ import pro.gravit.utils.helper.VerifyHelper; public final class BatchProfileByUsernameRequest extends Request implements WebSocketRequest { - class Entry { + static class Entry { @LauncherNetworkAPI String username; @LauncherNetworkAPI diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientJSONPoint.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientJSONPoint.java index f45619d5..06003341 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientJSONPoint.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientJSONPoint.java @@ -31,7 +31,7 @@ public abstract class ClientJSONPoint { protected Channel ch; private static final EventLoopGroup group = new NioEventLoopGroup(); protected WebSocketClientHandler webSocketClientHandler; - protected Bootstrap bootstrap = new Bootstrap(); + protected final Bootstrap bootstrap = new Bootstrap(); protected boolean ssl = false; protected int port; public boolean isClosed; @@ -61,7 +61,7 @@ public ClientJSONPoint(URI uri) throws SSLException { .channel(NioSocketChannel.class) .handler(new ChannelInitializer() { @Override - public void initChannel(SocketChannel ch) throws Exception { + public void initChannel(SocketChannel ch) { ChannelPipeline pipeline = ch.pipeline(); if (sslCtx != null) { pipeline.addLast(sslCtx.newHandler(ch.alloc(), uri.getHost(), port)); @@ -88,11 +88,11 @@ public ChannelFuture send(String text) { return ch.writeAndFlush(new TextWebSocketFrame(text), ch.voidPromise()); } - abstract void onMessage(String message) throws Exception; + abstract void onMessage(String message); - abstract void onDisconnect() throws Exception; + abstract void onDisconnect(); - abstract void onOpen() throws Exception; + abstract void onOpen(); public void close() throws InterruptedException { //System.out.println("WebSocket Client sending close"); @@ -105,7 +105,7 @@ public void close() throws InterruptedException { //group.shutdownGracefully(); } - public void eval(final String text) throws IOException { + public void eval(final String text) { ch.writeAndFlush(new TextWebSocketFrame(text), ch.voidPromise()); } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java index 8b7743d4..3204a344 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java @@ -3,6 +3,7 @@ import java.io.IOException; import java.lang.reflect.Type; import java.net.URI; +import java.net.URISyntaxException; import java.util.HashSet; import javax.net.ssl.SSLException; @@ -26,8 +27,8 @@ public class ClientWebSocketService extends ClientJSONPoint { public OnCloseCallback onCloseCallback; public final Boolean onConnect; public ReconnectCallback reconnectCallback; - public static ProviderMap results = new ProviderMap<>(); - public static ProviderMap requests = new ProviderMap<>(); + public static final ProviderMap results = new ProviderMap<>(); + public static final ProviderMap requests = new ProviderMap<>(); private HashSet handlers; public ClientWebSocketService(String address) throws SSLException { @@ -47,11 +48,9 @@ public static void appendTypeAdapters(GsonBuilder builder) private static URI createURL(String address) { try { - URI u = new URI(address); - return u; - } catch (Throwable e) { - LogHelper.error(e); - return null; + return new URI(address); + } catch (URISyntaxException e) { + throw new RuntimeException(e); } } @@ -70,7 +69,7 @@ void onDisconnect() { } @Override - void onOpen() throws Exception { + void onOpen() { synchronized (onConnect) { onConnect.notifyAll(); } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StandartClientWebSocketService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StandartClientWebSocketService.java index 554eedd3..b8609e73 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StandartClientWebSocketService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StandartClientWebSocketService.java @@ -17,7 +17,7 @@ import pro.gravit.utils.helper.LogHelper; public class StandartClientWebSocketService extends ClientWebSocketService { - public WaitEventHandler waitEventHandler = new WaitEventHandler(); + public final WaitEventHandler waitEventHandler = new WaitEventHandler(); public StandartClientWebSocketService(String address) throws SSLException { super(address); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WaitEventHandler.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WaitEventHandler.java index 860454cd..ed3021bb 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WaitEventHandler.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WaitEventHandler.java @@ -9,7 +9,7 @@ import pro.gravit.utils.helper.LogHelper; public class WaitEventHandler implements ClientWebSocketService.EventHandler { - public Set requests = ConcurrentHashMap.newKeySet(); + public final Set requests = ConcurrentHashMap.newKeySet(); @Override public void process(WebSocketEvent result) { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WebSocketClientHandler.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WebSocketClientHandler.java index 61a58a3c..00aef7c2 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WebSocketClientHandler.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WebSocketClientHandler.java @@ -34,7 +34,7 @@ public ChannelFuture handshakeFuture() { } @Override - public void handlerAdded(final ChannelHandlerContext ctx) throws Exception { + public void handlerAdded(final ChannelHandlerContext ctx) { handshakeFuture = ctx.newPromise(); } @@ -42,9 +42,7 @@ public void handlerAdded(final ChannelHandlerContext ctx) throws Exception { public void channelActive(final ChannelHandlerContext ctx) throws Exception { handshaker.handshake(ctx.channel()); clientJSONPoint.onOpen(); - ctx.executor().scheduleWithFixedDelay(() -> { - ctx.channel().writeAndFlush(new PingWebSocketFrame()); - }, 20L, 20L, TimeUnit.SECONDS); + ctx.executor().scheduleWithFixedDelay(() -> ctx.channel().writeAndFlush(new PingWebSocketFrame()), 20L, 20L, TimeUnit.SECONDS); } @Override @@ -93,7 +91,7 @@ else if (frame instanceof BinaryWebSocketFrame) { } @Override - public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) throws Exception { + public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) { LogHelper.error(cause); if (!handshakeFuture.isDone()) { diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/managers/GarbageManager.java b/LauncherCore/src/main/java/pro/gravit/launcher/managers/GarbageManager.java index 7810f5e4..66ba4e08 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/managers/GarbageManager.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/managers/GarbageManager.java @@ -9,8 +9,8 @@ public class GarbageManager { static class Entry { - NeedGarbageCollection invoke; - long timer; + final NeedGarbageCollection invoke; + final long timer; public Entry(NeedGarbageCollection invoke, long timer) { this.invoke = invoke; diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/stream/StreamObject.java b/LauncherCore/src/main/java/pro/gravit/launcher/serialize/stream/StreamObject.java index dfd6979e..8be1c5fd 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/stream/StreamObject.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/serialize/stream/StreamObject.java @@ -14,7 +14,7 @@ public abstract class StreamObject { @FunctionalInterface public interface Adapter { @LauncherAPI - O convert(HInput input) throws IOException; + O convert(HInput input); } @LauncherAPI diff --git a/LauncherCore/src/main/java/pro/gravit/utils/BiHookSet.java b/LauncherCore/src/main/java/pro/gravit/utils/BiHookSet.java index a636b6e8..4bd24018 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/BiHookSet.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/BiHookSet.java @@ -4,7 +4,7 @@ import java.util.Set; public class BiHookSet { - public Set> list = new HashSet<>(); + public final Set> list = new HashSet<>(); @FunctionalInterface public interface Hook { diff --git a/LauncherCore/src/main/java/pro/gravit/utils/HookSet.java b/LauncherCore/src/main/java/pro/gravit/utils/HookSet.java index 59cbbce2..fe975d64 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/HookSet.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/HookSet.java @@ -4,7 +4,7 @@ import java.util.Set; public class HookSet { - public Set> list = new HashSet<>(); + public final Set> list = new HashSet<>(); @FunctionalInterface public interface Hook { diff --git a/LauncherCore/src/main/java/pro/gravit/utils/Version.java b/LauncherCore/src/main/java/pro/gravit/utils/Version.java index c1d02845..ff26cc93 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/Version.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/Version.java @@ -106,7 +106,7 @@ public enum Type { public static final Map unModTypes = Collections.unmodifiableMap(types); static { - Arrays.asList(values()).stream().forEach(type -> types.put(type.name().substring(0, type.name().length() < 3 ? type.name().length() : 3).toLowerCase(Locale.ENGLISH), type)); + Arrays.asList(values()).forEach(type -> types.put(type.name().substring(0, type.name().length() < 3 ? type.name().length() : 3).toLowerCase(Locale.ENGLISH), type)); } } } diff --git a/LauncherCore/src/main/java/pro/gravit/utils/command/Command.java b/LauncherCore/src/main/java/pro/gravit/utils/command/Command.java index 29cf52d8..ad65920f 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/command/Command.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/command/Command.java @@ -15,7 +15,7 @@ public abstract class Command { /** * List of available subcommands */ - public Map childCommands; + public final Map childCommands; public Command() { childCommands = new HashMap<>(); diff --git a/LauncherCore/src/main/java/pro/gravit/utils/command/CommandHandler.java b/LauncherCore/src/main/java/pro/gravit/utils/command/CommandHandler.java index ca743a9b..65df9c1e 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/command/CommandHandler.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/command/CommandHandler.java @@ -14,8 +14,8 @@ public abstract class CommandHandler implements Runnable { private final CommandCategory baseCategory = new BaseCommandCategory(); public static class Category { - public CommandCategory category; - public String name; + public final CommandCategory category; + public final String name; public String description; public Category(CommandCategory category, String name) { @@ -155,10 +155,8 @@ public List getCategories() { /** * If supported, sends a bell signal to the console - * @throws IOException - * Internal Error */ - public abstract void bell() throws IOException; + public abstract void bell(); /** diff --git a/LauncherCore/src/main/java/pro/gravit/utils/command/JLineCommandHandler.java b/LauncherCore/src/main/java/pro/gravit/utils/command/JLineCommandHandler.java index e7284c9e..ef3151a0 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/command/JLineCommandHandler.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/command/JLineCommandHandler.java @@ -74,18 +74,18 @@ public JLineCommandHandler() throws IOException { } @Override - public void bell() throws IOException { + public void bell() { terminal.puts(InfoCmp.Capability.bell); //reader.beep(); } @Override - public void clear() throws IOException { + public void clear() { terminal.puts(InfoCmp.Capability.clear_screen); } @Override - public String readLine() throws IOException { + public String readLine() { try { return reader.readLine(); } catch (UserInterruptException e) { diff --git a/LauncherCore/src/main/java/pro/gravit/utils/command/basic/ClearCommand.java b/LauncherCore/src/main/java/pro/gravit/utils/command/basic/ClearCommand.java index 840a5f7f..700e955f 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/command/basic/ClearCommand.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/command/basic/ClearCommand.java @@ -5,7 +5,7 @@ import pro.gravit.utils.helper.LogHelper; public final class ClearCommand extends Command { - private CommandHandler handler; + private final CommandHandler handler; public ClearCommand(CommandHandler handler) { this.handler = handler; diff --git a/LauncherCore/src/main/java/pro/gravit/utils/command/basic/DebugCommand.java b/LauncherCore/src/main/java/pro/gravit/utils/command/basic/DebugCommand.java index b8080c52..c192acee 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/command/basic/DebugCommand.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/command/basic/DebugCommand.java @@ -15,7 +15,7 @@ public String getUsageDescription() { } @Override - public void invoke(String... args) throws Exception { + public void invoke(String... args) { boolean newValue, newTraceValue; if (args.length >= 1) { newValue = Boolean.parseBoolean(args[0]); diff --git a/LauncherCore/src/main/java/pro/gravit/utils/command/basic/GCCommand.java b/LauncherCore/src/main/java/pro/gravit/utils/command/basic/GCCommand.java index 1faf7e55..81da6add 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/command/basic/GCCommand.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/command/basic/GCCommand.java @@ -17,7 +17,7 @@ public String getUsageDescription() { } @Override - public void invoke(String... args) throws Exception { + public void invoke(String... args) { LogHelper.subInfo("Performing full GC"); JVMHelper.fullGC(); GarbageManager.gc(); diff --git a/LauncherCore/src/main/java/pro/gravit/utils/command/basic/HelpCommand.java b/LauncherCore/src/main/java/pro/gravit/utils/command/basic/HelpCommand.java index 95f00723..d6b167b0 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/command/basic/HelpCommand.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/command/basic/HelpCommand.java @@ -12,7 +12,7 @@ import pro.gravit.utils.helper.LogHelper; public final class HelpCommand extends Command { - private CommandHandler handler; + private final CommandHandler handler; public static void printCommand(String name, Command command) { String args = command.getArgsDescription(); @@ -34,9 +34,7 @@ public static void printCommand(String name, Command command) { public static void printSubCommandsHelp(String base, Command command) { - command.childCommands.forEach((k, v) -> { - printCommand(base.concat(" ").concat(k), v); - }); + command.childCommands.forEach((k, v) -> printCommand(base.concat(" ").concat(k), v)); } public static void printSubCommandsHelp(String name, String[] args, Command command) throws CommandException diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/JarHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/JarHelper.java index 93f3470e..ece54976 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/JarHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/JarHelper.java @@ -15,7 +15,7 @@ public interface ZipWalkCallback { @FunctionalInterface public interface JarWalkCallback { - void process(ZipInputStream input, ZipEntry e, String fullClassName, String clazz) throws IOException; + void process(ZipInputStream input, ZipEntry e, String fullClassName, String clazz); } public static void zipWalk(ZipInputStream input, ZipWalkCallback callback) throws IOException { diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/LogHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/LogHelper.java index 694c56db..4c9b1d05 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/LogHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/LogHelper.java @@ -43,8 +43,8 @@ public final class LogHelper { private static final AtomicBoolean DEV_ENABLED = new AtomicBoolean(Boolean.getBoolean(DEV_PROPERTY)); public static class OutputEnity { - public Output output; - public OutputTypes type; + public final Output output; + public final OutputTypes type; public OutputEnity(Output output, OutputTypes type) { this.output = output; diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/SecurityHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/SecurityHelper.java index c1e04ab9..194d8094 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/SecurityHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/SecurityHelper.java @@ -451,8 +451,7 @@ private SecurityHelper() { //AES public static byte[] encrypt(String seed, byte[] cleartext) throws Exception { byte[] rawKey = getRawKey(seed.getBytes()); - byte[] result = encrypt(rawKey, cleartext); - return result; + return encrypt(rawKey, cleartext); } public static byte[] encrypt(String seed, String cleartext) throws Exception { diff --git a/LauncherCore/src/main/java/pro/gravit/utils/verify/LauncherTrustManager.java b/LauncherCore/src/main/java/pro/gravit/utils/verify/LauncherTrustManager.java index 3cfe00b5..17fb58f5 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/verify/LauncherTrustManager.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/verify/LauncherTrustManager.java @@ -45,7 +45,7 @@ public enum CheckMode public interface CertificateChecker { - void check(X509Certificate cert, X509Certificate signer) throws CertificateException, SecurityException; + void check(X509Certificate cert, X509Certificate signer) throws SecurityException; } public void checkCertificate(X509Certificate[] certs, CertificateChecker checker) throws CertificateException, NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyException, SignatureException { @@ -56,8 +56,7 @@ public void checkCertificate(X509Certificate[] certs, CertificateChecker checker if(trustCache.contains(cert)) { //Добавляем в кеш все проверенные сертификаты - for(int j=0;j < i;++j) - trustCache.add(certs[j]); + trustCache.addAll(Arrays.asList(certs).subList(0, i)); return; } X509Certificate signer = (i+1 < certs.length) ? certs[i+1] : null; diff --git a/LauncherCore/src/test/java/pro/gravit/launcher/CommandHandlerTest.java b/LauncherCore/src/test/java/pro/gravit/launcher/CommandHandlerTest.java index 539f2eb6..a12b43b9 100644 --- a/LauncherCore/src/test/java/pro/gravit/launcher/CommandHandlerTest.java +++ b/LauncherCore/src/test/java/pro/gravit/launcher/CommandHandlerTest.java @@ -31,7 +31,7 @@ public void failNumberTest() throws Exception { try { cmd.invoke("test1"); Assertions.fail("CommandException not throw"); - } catch (CommandException e) + } catch (CommandException ignored) { } @@ -48,7 +48,7 @@ public void categoryTest() throws Exception try { commandHandler.evalNative("test2", false); Assertions.fail("CommandException not throw"); - } catch (CommandException e) + } catch (CommandException ignored) { } diff --git a/LauncherCore/src/test/java/pro/gravit/launcher/SerializeTest.java b/LauncherCore/src/test/java/pro/gravit/launcher/SerializeTest.java index e0add501..bab3dff3 100644 --- a/LauncherCore/src/test/java/pro/gravit/launcher/SerializeTest.java +++ b/LauncherCore/src/test/java/pro/gravit/launcher/SerializeTest.java @@ -20,7 +20,7 @@ public interface TestInterface } public static class MyTestClass implements TestInterface { - public String a; + public final String a; public MyTestClass(String a) { this.a = a; @@ -33,7 +33,7 @@ public String get() { } public static class MyTestClass2 implements TestInterface { - public String b; + public final String b; public MyTestClass2(String a) { this.b = a; diff --git a/LauncherCore/src/test/java/pro/gravit/launcher/impl/Test2Command.java b/LauncherCore/src/test/java/pro/gravit/launcher/impl/Test2Command.java index 229efac9..e1a6595b 100644 --- a/LauncherCore/src/test/java/pro/gravit/launcher/impl/Test2Command.java +++ b/LauncherCore/src/test/java/pro/gravit/launcher/impl/Test2Command.java @@ -14,7 +14,7 @@ public String getUsageDescription() { } @Override - public void invoke(String... args) throws Exception { + public void invoke(String... args) { } } diff --git a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerAgent.java b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerAgent.java index 8534bcdc..79aac34a 100644 --- a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerAgent.java +++ b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerAgent.java @@ -45,8 +45,8 @@ public static long getObjSize(Object obj) { return inst.getObjectSize(obj); } - public static Boolean isAutoloadLibraries = Boolean.getBoolean(System.getProperty("serverwrapper,agentlibrariesload", "false")); - public static Boolean isAgentProxy = Boolean.getBoolean(System.getProperty("serverwrapper,agentproxy", "false")); + public static final Boolean isAutoloadLibraries = Boolean.getBoolean(System.getProperty("serverwrapper,agentlibrariesload", "false")); + public static final Boolean isAgentProxy = Boolean.getBoolean(System.getProperty("serverwrapper,agentproxy", "false")); public static void premain(String agentArgument, Instrumentation instrumentation) { LogHelper.debug("Server Agent"); diff --git a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java index 42602a1f..e6135e10 100644 --- a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java +++ b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java @@ -39,11 +39,11 @@ public class ServerWrapper extends JsonConfigurable { public ClientPermissions permissions; public static ServerWrapper wrapper; - public static Path modulesDir = Paths.get(System.getProperty("serverwrapper.modulesDir", "modules")); - public static Path modulesConfigDir = Paths.get(System.getProperty("serverwrapper.modulesConfigDir", "modules-config")); - public static Path configFile = Paths.get(System.getProperty("serverwrapper.configFile", "ServerWrapperConfig.json")); - public static Path publicKeyFile = Paths.get(System.getProperty("serverwrapper.publicKeyFile", "public.key")); - public static boolean disableSetup = Boolean.valueOf(System.getProperty("serverwrapper.disableSetup", "false")); + public static final Path modulesDir = Paths.get(System.getProperty("serverwrapper.modulesDir", "modules")); + public static final Path modulesConfigDir = Paths.get(System.getProperty("serverwrapper.modulesConfigDir", "modules-config")); + public static final Path configFile = Paths.get(System.getProperty("serverwrapper.configFile", "ServerWrapperConfig.json")); + public static final Path publicKeyFile = Paths.get(System.getProperty("serverwrapper.publicKeyFile", "public.key")); + public static final boolean disableSetup = Boolean.parseBoolean(System.getProperty("serverwrapper.disableSetup", "false")); public ServerWrapper(Type type, Path configPath) { super(type, configPath); @@ -255,7 +255,7 @@ public static final class Config { public String login; public String[] args; public String password; - public String auth_id = ""; + public final String auth_id = ""; public LauncherConfig.LauncherEnvironment env; } diff --git a/modules b/modules index 14389214..fdadbdfc 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 14389214577f16795ba9844905c2e3886a1ea6d4 +Subproject commit fdadbdfc3c6aae0a90e8c80cc971da47a5db82b0 From 176430e4421bcb9a8af65db13b28c894dbdf1519 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 19 Oct 2019 23:46:04 +0700 Subject: [PATCH 025/192] [ANY] IDEA Reformat Code --- .gitlab-ci.yml | 48 +-- LaunchServer/build.gradle | 2 +- .../pro/gravit/launchserver/LaunchServer.java | 112 +++---- .../launchserver/LaunchServerBuilder.java | 14 +- .../launchserver/LaunchServerStarter.java | 32 +- .../gravit/launchserver/Reconfigurable.java | 5 +- .../pro/gravit/launchserver/StarterAgent.java | 7 +- .../launchserver/asm/ClassMetadataReader.java | 13 +- .../launchserver/asm/ConfigGenerator.java | 58 ++-- .../gravit/launchserver/asm/NodeUtils.java | 281 +++++++++--------- .../launchserver/asm/SafeClassWriter.java | 4 +- .../launchserver/auth/AuthProviderPair.java | 4 +- .../launchserver/auth/MySQLSourceConfig.java | 10 +- .../auth/PostgreSQLSourceConfig.java | 13 +- .../auth/handler/AuthHandler.java | 26 +- .../auth/handler/CachedAuthHandler.java | 20 +- .../auth/handler/HibernateAuthHandler.java | 9 +- .../auth/handler/JsonAuthHandler.java | 6 +- .../auth/handler/MemoryAuthHandler.java | 6 +- .../auth/handler/MySQLAuthHandler.java | 10 +- .../auth/handler/NullAuthHandler.java | 6 +- .../auth/handler/PostgreSQLAuthHandler.java | 7 +- .../auth/handler/RequestAuthHandler.java | 10 +- .../auth/hwid/AcceptHWIDHandler.java | 4 +- .../launchserver/auth/hwid/HWIDHandler.java | 11 +- .../auth/hwid/JsonFileHWIDHandler.java | 13 +- .../auth/hwid/JsonHWIDHandler.java | 15 +- .../auth/hwid/MemoryHWIDHandler.java | 4 +- .../auth/hwid/MysqlHWIDHandler.java | 12 +- .../HibernatePermissionsHandler.java | 4 +- .../JsonFilePermissionsHandler.java | 21 +- .../JsonLongFilePermissionsHandler.java | 21 +- .../auth/permissions/PermissionsHandler.java | 3 +- .../auth/protect/StdProtectHandler.java | 1 + .../auth/provider/AuthProvider.java | 17 +- .../auth/provider/HibernateAuthProvider.java | 20 +- .../auth/provider/JsonAuthProvider.java | 9 +- .../auth/provider/MySQLAuthProvider.java | 14 +- .../auth/provider/NullAuthProvider.java | 6 +- .../auth/provider/PostgreSQLAuthProvider.java | 14 +- .../auth/provider/RejectAuthProvider.java | 8 +- .../auth/provider/RequestAuthProvider.java | 14 +- .../auth/texture/NullTextureProvider.java | 6 +- .../auth/texture/RequestTextureProvider.java | 8 +- .../auth/texture/TextureProvider.java | 6 +- .../auth/texture/VoidTextureProvider.java | 4 +- .../launchserver/binary/BuildContext.java | 6 +- .../binary/EXEL4JLauncherBinary.java | 12 +- .../binary/EXELauncherBinary.java | 6 +- .../binary/JARLauncherBinary.java | 22 +- .../launchserver/binary/LauncherBinary.java | 6 +- .../binary/LauncherConfigurator.java | 13 +- .../launchserver/binary/ProguardConf.java | 15 +- .../binary/SimpleEXELauncherBinary.java | 15 +- .../tasks/AdditionalFixesApplyTask.java | 23 +- .../binary/tasks/AttachJarsTask.java | 8 +- .../binary/tasks/CompressBuildTask.java | 12 +- .../binary/tasks/MainBuildTask.java | 35 ++- .../binary/tasks/PrepareBuildTask.java | 10 +- .../binary/tasks/ProGuardBuildTask.java | 6 +- .../gravit/launchserver/command/Command.java | 4 +- .../command/auth/AuthCommand.java | 4 +- .../command/auth/UUIDToUsernameCommand.java | 6 +- .../command/auth/UsernameToUUIDCommand.java | 6 +- .../command/basic/ProguardCleanCommand.java | 6 +- .../basic/RegenProguardDictCommand.java | 4 +- .../basic/RemoveMappingsProguardCommand.java | 6 +- .../command/basic/TestCommand.java | 16 +- .../command/dao/GetAllUsersCommand.java | 3 +- .../command/dao/GetUserCommand.java | 3 +- .../command/dao/RegisterCommand.java | 4 +- .../command/dao/SetUserPasswordCommand.java | 3 +- .../command/dump/DumpSessionsCommand.java | 19 +- .../command/handler/CommandHandler.java | 25 +- .../command/hash/DownloadAssetCommand.java | 10 +- .../command/hash/DownloadClientCommand.java | 19 +- .../command/hash/IndexAssetCommand.java | 21 +- .../command/hash/SyncBinariesCommand.java | 4 +- .../command/hash/SyncProfilesCommand.java | 4 +- .../command/hash/SyncUpdatesCommand.java | 8 +- .../command/hash/UnindexAssetCommand.java | 19 +- .../command/modules/LoadModuleCommand.java | 6 +- .../command/service/ClientsCommand.java | 7 +- .../command/service/ComponentCommand.java | 6 +- .../components/AbstractLimiter.java | 33 +- .../components/AuthLimiterComponent.java | 12 +- .../components/CommandRemoverComponent.java | 8 +- .../components/RegLimiterComponent.java | 9 +- .../config/LaunchServerConfig.java | 41 ++- .../config/LaunchServerRuntimeConfig.java | 5 +- .../pro/gravit/launchserver/dao/User.java | 32 +- .../pro/gravit/launchserver/dao/UserDAO.java | 11 +- .../pro/gravit/launchserver/dao/UserHWID.java | 17 +- .../gravit/launchserver/dao/UserService.java | 4 +- .../dao/impl/DefaultUserDAOImpl.java | 12 +- .../dao/impl/HibernateUserDAOImpl.java | 60 ++-- .../dao/provider/DaoProvider.java | 5 +- .../dao/provider/HibernateDaoProvider.java | 11 +- .../manangers/CertificateManager.java | 96 +++--- .../manangers/LaunchServerGsonManager.java | 1 - .../launchserver/manangers/MirrorManager.java | 57 ++-- .../manangers/ReconfigurableManager.java | 23 +- .../manangers/SessionManager.java | 6 +- .../manangers/hook/AuthHookManager.java | 6 +- .../manangers/hook/BuildHookManager.java | 10 +- .../modules/impl/LaunchServerCoreModule.java | 3 +- .../impl/LaunchServerModulesManager.java | 18 +- .../socket/LauncherNettyServer.java | 14 +- .../socket/NettyObjectFactory.java | 16 +- .../launchserver/socket/WebSocketService.java | 13 +- .../handlers/NettyIpForwardHandler.java | 4 +- .../handlers/NettyServerSocketHandler.java | 11 +- .../handlers/WebSocketFrameHandler.java | 14 +- .../ClosingChannelFutureListener.java | 4 +- .../fileserver/FileServerHandler.java | 54 +--- .../socket/response/SimpleResponse.java | 4 +- .../socket/response/auth/AuthResponse.java | 27 +- .../auth/GetAvailabilityAuthResponse.java | 6 +- .../response/auth/RegisterResponse.java | 22 +- .../response/auth/SetPasswordResponse.java | 24 +- .../response/auth/SetProfileResponse.java | 4 +- .../profile/BatchProfileByUsername.java | 4 +- .../profile/ProfileByUUIDResponse.java | 9 +- .../response/profile/ProfileByUsername.java | 4 +- .../response/update/LauncherResponse.java | 15 +- .../response/update/UpdateListResponse.java | 6 +- .../launchserver/StartLaunchServerTest.java | 19 +- .../launchserver/console/ConsoleMain.java | 4 +- .../runtime/dialog/overlay/debug/debug.fxml | 18 +- .../dialog/overlay/settings/settings.fxml | 89 +++--- .../runtime/dialog/overlay/update/update.fxml | 50 ++-- .../dialog/scenes/console/console.fxml | 54 ++-- .../runtime/dialog/scenes/login/login.fxml | 122 ++++---- .../dialog/scenes/mainmenu/mainmenu.fxml | 173 ++++++----- .../dialog/scenes/options/options.fxml | 119 ++++---- .../launcher/ClientLauncherWrapper.java | 44 ++- .../pro/gravit/launcher/JSApplication.java | 4 +- .../pro/gravit/launcher/LauncherAgent.java | 29 +- .../pro/gravit/launcher/LauncherEngine.java | 32 +- .../gravit/launcher/NewLauncherSettings.java | 10 +- .../pro/gravit/launcher/api/AuthService.java | 8 +- .../launcher/client/ClientLauncher.java | 195 ++++++------ .../client/ClientLauncherContext.java | 6 +- .../launcher/client/ClientModuleManager.java | 16 +- .../pro/gravit/launcher/client/DirBridge.java | 16 +- .../launcher/client/FunctionalBridge.java | 30 +- .../client/LauncherUpdateController.java | 18 +- .../gravit/launcher/client/ServerPinger.java | 21 +- .../console/store/CopyStoreDirCommand.java | 8 +- .../console/store/LinkStoreDirCommand.java | 8 +- .../guard/LauncherGuardInterface.java | 4 +- .../launcher/guard/LauncherGuardManager.java | 4 +- .../launcher/guard/LauncherJavaGuard.java | 8 +- .../launcher/guard/LauncherNoGuard.java | 8 +- .../launcher/guard/LauncherStdGuard.java | 14 +- .../launcher/guard/LauncherWrapperGuard.java | 12 +- .../launcher/gui/JSRuntimeProvider.java | 44 +-- .../launcher/hwid/OshiHWIDProvider.java | 11 +- .../launcher/managers/ClientGsonManager.java | 1 - .../launcher/managers/ConsoleManager.java | 4 +- .../gravit/launcher/managers/HasherStore.java | 14 +- .../launcher/managers/SettingsManager.java | 12 +- .../gravit/launcher/patches/FMLPatcher.java | 171 ++++++----- .../pro/gravit/launcher/utils/DirWatcher.java | 23 +- .../gravit/launcher/utils/NativeJVMHalt.java | 33 +- .../pro/gravit/launcher/AutogenConfig.java | 2 +- .../gravit/launcher/ClientPermissions.java | 6 +- .../java/pro/gravit/launcher/Launcher.java | 14 +- .../pro/gravit/launcher/LauncherConfig.java | 18 +- .../gravit/launcher/SecureAutogenConfig.java | 2 +- .../launcher/config/JsonConfigurable.java | 4 +- .../config/JsonConfigurableInterface.java | 16 +- .../gravit/launcher/config/SimpleConfig.java | 1 + .../launcher/downloader/ListDownloader.java | 82 +++-- .../gravit/launcher/events/ControlEvent.java | 2 +- .../launcher/events/ExceptionEvent.java | 1 + .../gravit/launcher/events/RequestEvent.java | 4 +- .../request/CheckServerRequestEvent.java | 6 +- .../events/request/ErrorRequestEvent.java | 4 +- .../GetAvailabilityAuthRequestEvent.java | 4 +- .../request/JoinServerRequestEvent.java | 6 +- .../events/request/LauncherRequestEvent.java | 6 +- .../request/ProfileByUUIDRequestEvent.java | 6 +- .../ProfileByUsernameRequestEvent.java | 6 +- .../events/request/ProfilesRequestEvent.java | 8 +- .../request/SetProfileRequestEvent.java | 6 +- .../request/UpdateListRequestEvent.java | 8 +- .../gravit/launcher/hwid/HWIDCheckHelper.java | 53 ++-- .../gravit/launcher/hwid/HWIDProvider.java | 4 +- .../pro/gravit/launcher/hwid/OshiHWID.java | 25 +- .../launcher/managers/ConfigManager.java | 8 +- .../managers/SimpleModulesConfigManager.java | 8 +- .../launcher/modules/LauncherModule.java | 49 ++- .../launcher/modules/LauncherModuleInfo.java | 2 +- .../modules/LauncherModulesContext.java | 1 + .../modules/LauncherModulesManager.java | 23 +- .../modules/ModulesConfigManager.java | 6 +- .../launcher/modules/events/PreGsonPhase.java | 1 - .../modules/impl/SimpleModuleContext.java | 1 + .../modules/impl/SimpleModuleManager.java | 121 ++++---- .../launcher/profiles/ClientProfile.java | 30 +- .../launcher/profiles/PlayerProfile.java | 8 +- .../pro/gravit/launcher/profiles/Texture.java | 12 +- .../profiles/optional/OptionalFile.java | 8 +- .../request/JsonResultSerializeAdapter.java | 8 +- .../pro/gravit/launcher/request/Request.java | 6 +- .../launcher/request/RequestException.java | 4 +- .../gravit/launcher/request/RequestType.java | 4 +- .../launcher/request/auth/AuthRequest.java | 11 +- .../request/auth/password/AuthECPassword.java | 4 +- .../auth/password/AuthPlainPassword.java | 4 +- .../request/update/LauncherRequest.java | 18 +- .../request/update/UpdateRequest.java | 24 +- .../uuid/BatchProfileByUsernameRequest.java | 4 +- .../request/uuid/ProfileByUUIDRequest.java | 6 +- .../request/websockets/ClientJSONPoint.java | 14 +- .../websockets/ClientWebSocketService.java | 19 +- .../StandartClientWebSocketService.java | 13 +- .../request/websockets/WaitEventHandler.java | 8 +- .../websockets/WebSocketClientHandler.java | 18 +- .../java/pro/gravit/launcher/ModulesTest.java | 35 +-- .../launcher/impl/Cyclic2DependModule.java | 2 +- .../launcher/impl/CyclicDependModule.java | 2 +- .../gravit/launcher/impl/Depend1Module.java | 3 +- .../pro/gravit/launcher/impl/MainModule.java | 3 +- .../gravit/launcher/impl/ProvidedModule.java | 2 +- .../pro/gravit/launcher/impl/TestModule.java | 6 +- .../authlib/yggdrasil/CompatBridge.java | 4 +- .../authlib/yggdrasil/CompatProfile.java | 4 +- .../YggdrasilAuthenticationService.java | 5 +- .../YggdrasilGameProfileRepository.java | 7 +- .../YggdrasilMinecraftSessionService.java | 13 +- .../launcher/hasher/FileNameMatcher.java | 4 +- .../pro/gravit/launcher/hasher/HashedDir.java | 22 +- .../gravit/launcher/hasher/HashedEntry.java | 4 +- .../launcher/hasher/HashedEntryAdapter.java | 11 +- .../gravit/launcher/hasher/HashedFile.java | 8 +- .../launcher/managers/GarbageManager.java | 4 +- .../gravit/launcher/managers/GsonManager.java | 1 - .../pro/gravit/launcher/serialize/HInput.java | 6 +- .../gravit/launcher/serialize/HOutput.java | 6 +- .../serialize/signed/DigestBytesHolder.java | 8 +- .../serialize/stream/EnumSerializer.java | 8 +- .../serialize/stream/StreamObject.java | 6 +- .../main/java/pro/gravit/utils/BiHookSet.java | 16 +- .../java/pro/gravit/utils/HTTPRequest.java | 24 +- .../main/java/pro/gravit/utils/HookSet.java | 12 +- .../java/pro/gravit/utils/HttpDownloader.java | 10 +- .../java/pro/gravit/utils/ProviderMap.java | 5 +- .../gravit/utils/PublicURLClassLoader.java | 4 +- .../gravit/utils/UniversalJsonAdapter.java | 15 +- .../main/java/pro/gravit/utils/Version.java | 9 +- .../utils/command/BaseCommandCategory.java | 4 +- .../pro/gravit/utils/command/Command.java | 51 ++-- .../gravit/utils/command/CommandHandler.java | 15 +- .../utils/command/JLineCommandHandler.java | 20 +- .../utils/command/StdCommandHandler.java | 29 +- .../utils/command/basic/HelpCommand.java | 28 +- .../pro/gravit/utils/helper/CommonHelper.java | 51 ++-- .../pro/gravit/utils/helper/FormatHelper.java | 1 - .../pro/gravit/utils/helper/IOHelper.java | 59 +--- .../pro/gravit/utils/helper/JVMHelper.java | 9 +- .../pro/gravit/utils/helper/LogHelper.java | 19 +- .../gravit/utils/helper/SecurityHelper.java | 34 +-- .../pro/gravit/utils/helper/VerifyHelper.java | 4 +- .../utils/verify/LauncherTrustManager.java | 38 +-- .../gravit/launcher/CommandHandlerTest.java | 22 +- .../pro/gravit/launcher/SerializeTest.java | 28 +- .../pro/gravit/launcher/impl/TestCommand.java | 13 +- .../gravit/launcher/server/ServerAgent.java | 6 +- .../gravit/launcher/server/ServerWrapper.java | 24 +- .../server/ServerWrapperGsonManager.java | 1 - .../server/ServerWrapperModulesManager.java | 8 +- .../server/setup/ServerWrapperCommands.java | 4 +- .../server/setup/ServerWrapperSetup.java | 12 +- modules | 2 +- 276 files changed, 2320 insertions(+), 2699 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fc383772..b5149a5b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,47 +1,47 @@ image: docker:latest services: -- docker:dind + - docker:dind variables: DOCKER_DRIVER: overlay2 CI_VERSION: '6.6.$CI_PIPELINE_IID' stages: -- build -- test + - build + - test build: image: frekele/java stage: build before_script: - - apt-get -y update - - apt-get -y install zip git - - export GRADLE_USER_HOME=`pwd`/.gradle - - chmod +x gradlew - - sed -i 's/git@github.com:/https:\/\/github.com\//' .gitmodules - - git submodule sync - - git submodule update --init --recursive + - apt-get -y update + - apt-get -y install zip git + - export GRADLE_USER_HOME=`pwd`/.gradle + - chmod +x gradlew + - sed -i 's/git@github.com:/https:\/\/github.com\//' .gitmodules + - git submodule sync + - git submodule update --init --recursive script: - - ./gradlew assemble + - ./gradlew assemble after_script: - - mkdir -p artifacts/modules - - cd LaunchServer/build/libs/ - - zip -r -9 ../../../artifacts/libraries.zip * -x "LaunchServer.jar" -x "LaunchServer-clean.jar" - - mv LaunchServer.jar ../../../artifacts/LaunchServer.jar - - cd ../../../ServerWrapper/build/libs - - mv ServerWrapper.jar ../../../artifacts/ServerWrapper.jar - - cd ../../../ - - mv modules/*_module/build/libs/*.jar artifacts/modules - - mv modules/*_swmodule/build/libs/*.jar artifacts/modules - - mv modules/*_lmodule/build/libs/*.jar artifacts/modules + - mkdir -p artifacts/modules + - cd LaunchServer/build/libs/ + - zip -r -9 ../../../artifacts/libraries.zip * -x "LaunchServer.jar" -x "LaunchServer-clean.jar" + - mv LaunchServer.jar ../../../artifacts/LaunchServer.jar + - cd ../../../ServerWrapper/build/libs + - mv ServerWrapper.jar ../../../artifacts/ServerWrapper.jar + - cd ../../../ + - mv modules/*_module/build/libs/*.jar artifacts/modules + - mv modules/*_swmodule/build/libs/*.jar artifacts/modules + - mv modules/*_lmodule/build/libs/*.jar artifacts/modules cache: paths: - - .gradle + - .gradle artifacts: expire_in: 6 week paths: - - artifacts - + - artifacts + test: image: frekele/java stage: test diff --git a/LaunchServer/build.gradle b/LaunchServer/build.gradle index 1b0cb5e7..890bb281 100644 --- a/LaunchServer/build.gradle +++ b/LaunchServer/build.gradle @@ -73,7 +73,7 @@ task cleanjar(type: Jar, dependsOn: jar) { pack project(':LauncherAPI') bundle 'org.ow2.asm:asm-commons:7.1' bundle 'mysql:mysql-connector-java:8.0.16' - bundle 'org.postgresql:postgresql:42.2.6' + bundle 'org.postgresql:postgresql:42.2.6' bundle 'org.jline:jline:3.11.0' bundle 'org.jline:jline-reader:3.11.0' bundle 'org.jline:jline-terminal:3.11.0' diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java index 8a191169..c6666495 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java @@ -1,37 +1,7 @@ package pro.gravit.launchserver; -import java.io.BufferedReader; -import java.io.IOException; -import java.lang.ProcessBuilder.Redirect; -import java.lang.reflect.InvocationTargetException; -import java.nio.file.DirectoryStream; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.attribute.BasicFileAttributes; -import java.security.InvalidAlgorithmParameterException; -import java.security.KeyPair; -import java.security.NoSuchAlgorithmException; -import java.security.interfaces.ECPrivateKey; -import java.security.interfaces.ECPublicKey; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.Timer; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.stream.Stream; - import org.bouncycastle.crypto.util.PrivateKeyFactory; import org.bouncycastle.operator.OperatorCreationException; - import pro.gravit.launcher.Launcher; import pro.gravit.launcher.NeedGarbageCollection; import pro.gravit.launcher.hasher.HashedDir; @@ -40,12 +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.binary.EXEL4JLauncherBinary; -import pro.gravit.launchserver.binary.EXELauncherBinary; -import pro.gravit.launchserver.binary.JARLauncherBinary; -import pro.gravit.launchserver.binary.LauncherBinary; -import pro.gravit.launchserver.binary.ProguardConf; -import pro.gravit.launchserver.binary.SimpleEXELauncherBinary; +import pro.gravit.launchserver.binary.*; import pro.gravit.launchserver.config.LaunchServerConfig; import pro.gravit.launchserver.config.LaunchServerRuntimeConfig; import pro.gravit.launchserver.manangers.CertificateManager; @@ -68,41 +33,57 @@ import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.LogHelper; +import java.io.BufferedReader; +import java.io.IOException; +import java.lang.ProcessBuilder.Redirect; +import java.lang.reflect.InvocationTargetException; +import java.nio.file.*; +import java.nio.file.attribute.BasicFileAttributes; +import java.security.InvalidAlgorithmParameterException; +import java.security.KeyPair; +import java.security.NoSuchAlgorithmException; +import java.security.interfaces.ECPrivateKey; +import java.security.interfaces.ECPublicKey; +import java.util.*; +import java.util.Map.Entry; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.stream.Stream; + public final class LaunchServer implements Runnable, AutoCloseable, Reconfigurable { - public enum ReloadType - { + public enum ReloadType { NO_AUTH, NO_COMPONENTS, FULL } - public enum LaunchServerEnv - { + + public enum LaunchServerEnv { TEST, DEV, DEBUG, PRODUCTION } - public interface LaunchServerConfigManager - { + + public interface LaunchServerConfigManager { LaunchServerConfig readConfig() throws IOException; + LaunchServerRuntimeConfig readRuntimeConfig() throws IOException; + void writeConfig(LaunchServerConfig config) throws IOException; + void writeRuntimeConfig(LaunchServerRuntimeConfig config) throws IOException; } public void reload(ReloadType type) throws Exception { config.close(type); AuthProviderPair[] pairs = null; - if(type.equals(ReloadType.NO_AUTH)) - { + if (type.equals(ReloadType.NO_AUTH)) { pairs = config.auth; } LogHelper.info("Reading LaunchServer config file"); config = launchServerConfigManager.readConfig(); config.setLaunchServer(this); - if(type.equals(ReloadType.NO_AUTH)) - { + if (type.equals(ReloadType.NO_AUTH)) { config.auth = pairs; } config.verify(); @@ -137,13 +118,11 @@ public Map getCommands() { SubCommand reload = new SubCommand() { @Override public void invoke(String... args) throws Exception { - if(args.length == 0) - { + if (args.length == 0) { reload(ReloadType.FULL); return; } - switch (args[0]) - { + switch (args[0]) { case "full": reload(ReloadType.FULL); break; @@ -266,17 +245,16 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO public static final Class defaultLauncherEXEBinaryClass = null; - public static class LaunchServerDirectories - { + public static class LaunchServerDirectories { public Path updatesDir; public Path profilesDir; public Path dir; public Path trustStore; - public void collect() - { - if(updatesDir == null) updatesDir = dir.resolve("updates"); - if(profilesDir == null) profilesDir = dir.resolve("profiles"); - if(trustStore == null) trustStore = dir.resolve("truststore"); + + public void collect() { + if (updatesDir == null) updatesDir = dir.resolve("updates"); + if (profilesDir == null) profilesDir = dir.resolve("profiles"); + if (trustStore == null) trustStore = dir.resolve("truststore"); } } @@ -333,15 +311,11 @@ public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, La configManager = new ConfigManager(); //Generate or set new Certificate API certificateManager.orgName = config.projectName; - if(config.certificate != null && config.certificate.enabled) - { - if(IOHelper.isFile(caCertFile) && IOHelper.isFile(caKeyFile)) - { + if (config.certificate != null && config.certificate.enabled) { + if (IOHelper.isFile(caCertFile) && IOHelper.isFile(caKeyFile)) { certificateManager.ca = certificateManager.readCertificate(caCertFile); certificateManager.caKey = certificateManager.readPrivateKey(caKeyFile); - } - else - { + } else { try { certificateManager.generateCA(); certificateManager.writeCertificate(caCertFile, certificateManager.ca); @@ -350,13 +324,10 @@ public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, La LogHelper.error(e); } } - if(IOHelper.isFile(serverCertFile) && IOHelper.isFile(serverKeyFile)) - { + if (IOHelper.isFile(serverCertFile) && IOHelper.isFile(serverKeyFile)) { certificateManager.server = certificateManager.readCertificate(serverCertFile); certificateManager.serverKey = certificateManager.readPrivateKey(serverKeyFile); - } - else - { + } else { try { KeyPair pair = certificateManager.generateKeyPair(); certificateManager.server = certificateManager.generateCertificate(config.projectName.concat(" Server"), pair.getPublic()); @@ -425,8 +396,7 @@ private LauncherBinary binary() { LogHelper.error(e); } } - if(config.launch4j.alternative != null) - { + if (config.launch4j.alternative != null) { switch (config.launch4j.alternative) { case "simple": return new SimpleEXELauncherBinary(this); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerBuilder.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerBuilder.java index d3c70de6..b2d44a24 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerBuilder.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerBuilder.java @@ -1,15 +1,15 @@ package pro.gravit.launchserver; -import java.nio.file.Path; -import java.security.interfaces.ECPrivateKey; -import java.security.interfaces.ECPublicKey; - import pro.gravit.launchserver.config.LaunchServerConfig; import pro.gravit.launchserver.config.LaunchServerRuntimeConfig; import pro.gravit.launchserver.manangers.CertificateManager; import pro.gravit.launchserver.modules.impl.LaunchServerModulesManager; import pro.gravit.utils.command.CommandHandler; +import java.nio.file.Path; +import java.security.interfaces.ECPrivateKey; +import java.security.interfaces.ECPublicKey; + public class LaunchServerBuilder { private LaunchServerConfig config; private LaunchServerRuntimeConfig runtimeConfig; @@ -72,13 +72,11 @@ public LaunchServerBuilder setLaunchServerConfigManager(LaunchServer.LaunchServe return this; } - public LaunchServer build() throws Exception - { + public LaunchServer build() throws Exception { //if(updatesDir == null) updatesDir = dir.resolve("updates"); //if(profilesDir == null) profilesDir = dir.resolve("profiles"); directories.collect(); - if(launchServerConfigManager == null) - { + if (launchServerConfigManager == null) { launchServerConfigManager = new LaunchServer.LaunchServerConfigManager() { @Override public LaunchServerConfig readConfig() { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java index 64397a3c..a91a7a64 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java @@ -1,18 +1,5 @@ package pro.gravit.launchserver; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.IOException; -import java.io.Writer; -import java.nio.file.Files; -import java.nio.file.Path; -import java.security.KeyPair; -import java.security.SecureRandom; -import java.security.Security; -import java.security.cert.CertificateException; -import java.security.interfaces.ECPrivateKey; -import java.security.interfaces.ECPublicKey; - import org.bouncycastle.jce.provider.BouncyCastleProvider; import pro.gravit.launcher.Launcher; import pro.gravit.launcher.hwid.HWIDProvider; @@ -42,8 +29,22 @@ import pro.gravit.utils.helper.SecurityHelper; import pro.gravit.utils.verify.LauncherTrustManager; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.Writer; +import java.nio.file.Files; +import java.nio.file.Path; +import java.security.KeyPair; +import java.security.SecureRandom; +import java.security.Security; +import java.security.cert.CertificateException; +import java.security.interfaces.ECPrivateKey; +import java.security.interfaces.ECPublicKey; + public class LaunchServerStarter { public static final boolean allowUnsigned = Boolean.getBoolean("launchserver.allowUnsigned"); + public static void main(String[] args) throws Exception { JVMHelper.checkStackTrace(LaunchServerStarter.class); JVMHelper.verifySystemProperties(LaunchServer.class, true); @@ -56,7 +57,7 @@ public static void main(String[] args) throws Exception { } Path dir = IOHelper.WORKING_DIR; Path configFile, runtimeConfigFile; - Path publicKeyFile =dir.resolve("public.key"); + Path publicKeyFile = dir.resolve("public.key"); Path privateKeyFile = dir.resolve("private.key"); ECPublicKey publicKey; ECPrivateKey privateKey; @@ -197,8 +198,7 @@ public static void initGson(LaunchServerModulesManager modulesManager) { Launcher.gsonManager.initGson(); } - public static void registerAll() - { + public static void registerAll() { AuthHandler.registerHandlers(); AuthProvider.registerProviders(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/Reconfigurable.java b/LaunchServer/src/main/java/pro/gravit/launchserver/Reconfigurable.java index 181ad476..3b39c5f6 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/Reconfigurable.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/Reconfigurable.java @@ -1,15 +1,16 @@ package pro.gravit.launchserver; -import java.util.Map; - import pro.gravit.utils.command.Command; +import java.util.Map; + /** * Allows calling commands using the config command */ public interface Reconfigurable { /** * Gets a list of commands available for this object. + * * @return Key - Command Name * Value is a command object */ diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/StarterAgent.java b/LaunchServer/src/main/java/pro/gravit/launchserver/StarterAgent.java index 4e17c3e8..c6baacd0 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/StarterAgent.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/StarterAgent.java @@ -2,12 +2,7 @@ import java.io.IOException; import java.lang.instrument.Instrumentation; -import java.nio.file.FileVisitOption; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.SimpleFileVisitor; +import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.PosixFileAttributeView; import java.nio.file.attribute.PosixFilePermission; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ClassMetadataReader.java b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ClassMetadataReader.java index 52eed8b8..84fd4fa9 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ClassMetadataReader.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ClassMetadataReader.java @@ -1,5 +1,10 @@ package pro.gravit.launchserver.asm; +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.ClassVisitor; +import org.objectweb.asm.Opcodes; +import pro.gravit.utils.helper.IOHelper; + import java.io.Closeable; import java.io.IOException; import java.io.InputStream; @@ -8,12 +13,6 @@ import java.util.List; import java.util.jar.JarFile; -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.ClassVisitor; -import org.objectweb.asm.Opcodes; - -import pro.gravit.utils.helper.IOHelper; - /** * Позволяет искать методы внутри незагруженных классов и общие суперклассы для * чего угодно. Работает через поиск class-файлов в classpath. @@ -55,7 +54,7 @@ public void acceptVisitor(byte[] classData, ClassVisitor visitor) { public void acceptVisitor(String className, ClassVisitor visitor) throws IOException { acceptVisitor(getClassData(className), visitor); } - + public void acceptVisitor(byte[] classData, ClassVisitor visitor, int flags) { new ClassReader(classData).accept(visitor, flags); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ConfigGenerator.java b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ConfigGenerator.java index 809f536e..0d1ac656 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ConfigGenerator.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ConfigGenerator.java @@ -1,28 +1,20 @@ package pro.gravit.launchserver.asm; -import java.util.Base64; -import java.util.List; - import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Opcodes; import org.objectweb.asm.Type; -import org.objectweb.asm.tree.ClassNode; -import org.objectweb.asm.tree.FieldInsnNode; -import org.objectweb.asm.tree.InsnList; -import org.objectweb.asm.tree.InsnNode; -import org.objectweb.asm.tree.LdcInsnNode; -import org.objectweb.asm.tree.MethodInsnNode; -import org.objectweb.asm.tree.MethodNode; -import org.objectweb.asm.tree.TypeInsnNode; -import org.objectweb.asm.tree.VarInsnNode; +import org.objectweb.asm.tree.*; + +import java.util.Base64; +import java.util.List; public class ConfigGenerator { - protected static final String stringDesc = Type.getDescriptor(String.class); - protected static final String byteArrDesc = Type.getDescriptor(byte[].class); - protected static final String base64DecDesc = "(" + stringDesc + ")" + byteArrDesc; + protected static final String stringDesc = Type.getDescriptor(String.class); + protected static final String byteArrDesc = Type.getDescriptor(byte[].class); + protected static final String base64DecDesc = "(" + stringDesc + ")" + byteArrDesc; protected final ClassNode configclass; protected final MethodNode constructor; - + public ConfigGenerator(ClassNode configclass) { this.configclass = configclass; constructor = this.configclass.methods.stream().filter(e -> "".equals(e.name)).findFirst().get(); @@ -30,7 +22,7 @@ public ConfigGenerator(ClassNode configclass) { constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, Type.getInternalName(Object.class), "", "()V")); } - + public byte[] getBytecode(ClassMetadataReader reader) { constructor.instructions.add(new InsnNode(Opcodes.RETURN)); ClassWriter cw = new SafeClassWriter(reader, ClassWriter.COMPUTE_FRAMES); @@ -41,56 +33,50 @@ public byte[] getBytecode(ClassMetadataReader reader) { public String getZipEntryPath() { return configclass.name.concat(".class"); } - - public void setStringField(String name, String value) - { + + public void setStringField(String name, String value) { constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); constructor.instructions.add(NodeUtils.getSafeStringInsnList(value)); constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, configclass.name, name, stringDesc)); } - public void setByteArrayField(String name, byte[] value) - { + public void setByteArrayField(String name, byte[] value) { constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/util/Base64", "getDecoder", "()Ljava/util/Base64$Decoder;", false)); constructor.instructions.add(NodeUtils.getSafeStringInsnList(Base64.getEncoder().encodeToString(value))); constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/util/Base64$Decoder", "decode", base64DecDesc, false)); constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, configclass.name, name, stringDesc)); } - - public void setByteArrayListField(String name, List b) - { + + public void setByteArrayListField(String name, List b) { constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); constructor.instructions.add(new TypeInsnNode(Opcodes.NEW, "java/util/ArrayList")); constructor.instructions.add(new InsnNode(Opcodes.DUP)); constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/util/ArrayList", "", "()V")); for (byte[] value : b) { constructor.instructions.add(new InsnNode(Opcodes.DUP)); - constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/util/Base64", "getDecoder", "()Ljava/util/Base64$Decoder;", false)); - constructor.instructions.add(NodeUtils.getSafeStringInsnList(Base64.getEncoder().encodeToString(value))); - constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/util/Base64$Decoder", "decode", base64DecDesc, false)); - constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", false)); - constructor.instructions.add(new InsnNode(Opcodes.POP)); + constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/util/Base64", "getDecoder", "()Ljava/util/Base64$Decoder;", false)); + constructor.instructions.add(NodeUtils.getSafeStringInsnList(Base64.getEncoder().encodeToString(value))); + constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/util/Base64$Decoder", "decode", base64DecDesc, false)); + constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", false)); + constructor.instructions.add(new InsnNode(Opcodes.POP)); } constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, configclass.name, name, "Ljava/util/List;")); } - public void setIntegerField(String name, int value) - { + public void setIntegerField(String name, int value) { constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); constructor.instructions.add(NodeUtils.push(value)); constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, configclass.name, name, Type.INT_TYPE.getInternalName())); } - public void setLongField(String name, long value) - { + public void setLongField(String name, long value) { constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); constructor.instructions.add(new LdcInsnNode(value)); constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, configclass.name, name, Type.INT_TYPE.getInternalName())); } - public void setBooleanField(String name, boolean b) - { + public void setBooleanField(String name, boolean b) { constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); constructor.instructions.add(new InsnNode(b ? Opcodes.ICONST_1 : Opcodes.ICONST_0)); constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, configclass.name, name, Type.BOOLEAN_TYPE.getInternalName())); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/NodeUtils.java b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/NodeUtils.java index 13e80273..56b9e221 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/NodeUtils.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/NodeUtils.java @@ -1,57 +1,60 @@ package pro.gravit.launchserver.asm; +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.Opcodes; +import org.objectweb.asm.Type; +import org.objectweb.asm.tree.*; +import pro.gravit.utils.helper.IOHelper; + import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.objectweb.asm.*; -import org.objectweb.asm.tree.*; - -import pro.gravit.utils.helper.IOHelper; - import static org.objectweb.asm.Opcodes.*; public final class NodeUtils { - private NodeUtils() { } - public static ClassNode forClass(Class cls, int flags) { - try (InputStream in = cls.getClassLoader().getResourceAsStream(cls.getName().replace('.', '/') + ".class")) { - ClassNode ret = new ClassNode(); - new ClassReader(IOHelper.read(in)).accept(ret, flags); - return ret; - } catch (IOException e) { - throw new RuntimeException(e); - } - } + private NodeUtils() { + } - public static ClassNode forClass(String clazz, int flags, ClassMetadataReader r) { - try { - ClassNode ret = new ClassNode(); - r.acceptVisitor(clazz, ret, flags); - return ret; - } catch (IOException e) { - throw new RuntimeException(e); - } - } + public static ClassNode forClass(Class cls, int flags) { + try (InputStream in = cls.getClassLoader().getResourceAsStream(cls.getName().replace('.', '/') + ".class")) { + ClassNode ret = new ClassNode(); + new ClassReader(IOHelper.read(in)).accept(ret, flags); + return ret; + } catch (IOException e) { + throw new RuntimeException(e); + } + } - public static List annots(String clazz, String method, ClassMetadataReader r) { - if (clazz.startsWith("L")) clazz = Type.getType(clazz).getInternalName(); - try { - List ret = new ArrayList<>(); - ClassNode n = forClass(clazz, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG, r); - if (n.visibleAnnotations != null) ret.addAll(n.visibleAnnotations); - if (n.invisibleAnnotations != null) ret.addAll(n.invisibleAnnotations); - for (MethodNode m : n.methods) - if (method.equals(m.name)) { - if (m.visibleAnnotations != null) ret.addAll(m.visibleAnnotations); - if (m.invisibleAnnotations != null) ret.addAll(m.invisibleAnnotations); - } - return ret; - } catch (Throwable e) { - return Collections.emptyList(); - } - } + public static ClassNode forClass(String clazz, int flags, ClassMetadataReader r) { + try { + ClassNode ret = new ClassNode(); + r.acceptVisitor(clazz, ret, flags); + return ret; + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public static List annots(String clazz, String method, ClassMetadataReader r) { + if (clazz.startsWith("L")) clazz = Type.getType(clazz).getInternalName(); + try { + List ret = new ArrayList<>(); + ClassNode n = forClass(clazz, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG, r); + if (n.visibleAnnotations != null) ret.addAll(n.visibleAnnotations); + if (n.invisibleAnnotations != null) ret.addAll(n.invisibleAnnotations); + for (MethodNode m : n.methods) + if (method.equals(m.name)) { + if (m.visibleAnnotations != null) ret.addAll(m.visibleAnnotations); + if (m.invisibleAnnotations != null) ret.addAll(m.invisibleAnnotations); + } + return ret; + } catch (Throwable e) { + return Collections.emptyList(); + } + } private static int doMethodEmulation(String desc) { int result = 0; @@ -64,100 +67,100 @@ private static int doMethodEmulation(String desc) { return result; } - - public static int opcodeEmulation(AbstractInsnNode e) { - int stackSize = 0; - switch (e.getOpcode()) { - case NOP: - case LALOAD: // (index, arrayref) -> (long, long_top) - case DALOAD: // (index, arrayref) -> (double, double_top) - case SWAP: // (value1, value2) -> (value2, value1) - case INEG: - case LNEG: - case FNEG: - case DNEG: - case IINC: - case I2F: - case L2D: - case F2I: - case D2L: - case I2B: - case I2C: - case I2S: - case GOTO: - case RETURN: - case NEWARRAY: - case ANEWARRAY: - case ARRAYLENGTH: - case CHECKCAST: - case INSTANCEOF: - // Does nothing - break; - case ACONST_NULL: - case ICONST_M1: - case ICONST_0: - case ICONST_1: - case ICONST_2: - case ICONST_3: - case ICONST_4: - case ICONST_5: - case FCONST_0: - case FCONST_1: - case FCONST_2: - case BIPUSH: - case SIPUSH: - case ILOAD: - case FLOAD: - case ALOAD: - case DUP: - case DUP_X1: - case DUP_X2: - case I2L: - case I2D: - case F2L: - case F2D: - case NEW: - // Pushes one-word constant to stack - stackSize++; - break; - case LDC: - LdcInsnNode ldc = (LdcInsnNode) e; - if (ldc.cst instanceof Long || ldc.cst instanceof Double) - stackSize++; - stackSize++; - break; - case LCONST_0: - case LCONST_1: - case DCONST_0: - case DCONST_1: - case LLOAD: - case DLOAD: - case DUP2: - case DUP2_X1: - case DUP2_X2: - // Pushes two-word constant or two one-word constants to stack - stackSize++; - stackSize++; - break; - case INVOKEVIRTUAL: - case INVOKESPECIAL: - case INVOKEINTERFACE: - stackSize += doMethodEmulation(((MethodInsnNode) e).desc); - break; - case INVOKESTATIC: - stackSize += doMethodEmulation(((MethodInsnNode) e).desc); - break; - case INVOKEDYNAMIC: - stackSize += doMethodEmulation(((InvokeDynamicInsnNode) e).desc); - break; - case JSR: - case RET: - throw new RuntimeException("Did not expect JSR/RET instructions"); - default: - break; - } - return stackSize; + public static int opcodeEmulation(AbstractInsnNode e) { + int stackSize = 0; + switch (e.getOpcode()) { + case NOP: + case LALOAD: // (index, arrayref) -> (long, long_top) + case DALOAD: // (index, arrayref) -> (double, double_top) + case SWAP: // (value1, value2) -> (value2, value1) + case INEG: + case LNEG: + case FNEG: + case DNEG: + case IINC: + case I2F: + case L2D: + case F2I: + case D2L: + case I2B: + case I2C: + case I2S: + case GOTO: + case RETURN: + case NEWARRAY: + case ANEWARRAY: + case ARRAYLENGTH: + case CHECKCAST: + case INSTANCEOF: + // Does nothing + break; + case ACONST_NULL: + case ICONST_M1: + case ICONST_0: + case ICONST_1: + case ICONST_2: + case ICONST_3: + case ICONST_4: + case ICONST_5: + case FCONST_0: + case FCONST_1: + case FCONST_2: + case BIPUSH: + case SIPUSH: + case ILOAD: + case FLOAD: + case ALOAD: + case DUP: + case DUP_X1: + case DUP_X2: + case I2L: + case I2D: + case F2L: + case F2D: + case NEW: + // Pushes one-word constant to stack + stackSize++; + break; + case LDC: + LdcInsnNode ldc = (LdcInsnNode) e; + if (ldc.cst instanceof Long || ldc.cst instanceof Double) + stackSize++; + + stackSize++; + break; + case LCONST_0: + case LCONST_1: + case DCONST_0: + case DCONST_1: + case LLOAD: + case DLOAD: + case DUP2: + case DUP2_X1: + case DUP2_X2: + // Pushes two-word constant or two one-word constants to stack + stackSize++; + stackSize++; + break; + case INVOKEVIRTUAL: + case INVOKESPECIAL: + case INVOKEINTERFACE: + stackSize += doMethodEmulation(((MethodInsnNode) e).desc); + break; + case INVOKESTATIC: + stackSize += doMethodEmulation(((MethodInsnNode) e).desc); + break; + case INVOKEDYNAMIC: + stackSize += doMethodEmulation(((InvokeDynamicInsnNode) e).desc); + break; + case JSR: + case RET: + throw new RuntimeException("Did not expect JSR/RET instructions"); + default: + break; + } + return stackSize; } public static InsnList getSafeStringInsnList(String string) { @@ -181,7 +184,7 @@ public static InsnList getSafeStringInsnList(String string) { return insnList; } - public static final int MAX_SAFE_BYTE_COUNT = 65535-Byte.MAX_VALUE; + public static final int MAX_SAFE_BYTE_COUNT = 65535 - Byte.MAX_VALUE; public static String[] splitUtf8ToChunks(String text, int maxBytes) { List parts = new ArrayList<>(); @@ -220,15 +223,15 @@ public static int getUtf8CharSize(char c) { } public static InsnList push(final int value) { - InsnList ret = new InsnList(); + InsnList ret = new InsnList(); if (value >= -1 && value <= 5) ret.add(new InsnNode(Opcodes.ICONST_0 + value)); else if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) - ret.add(new IntInsnNode(Opcodes.BIPUSH, value)); + ret.add(new IntInsnNode(Opcodes.BIPUSH, value)); else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) - ret.add(new IntInsnNode(Opcodes.SIPUSH, value)); + ret.add(new IntInsnNode(Opcodes.SIPUSH, value)); else - ret.add(new LdcInsnNode(value)); + ret.add(new LdcInsnNode(value)); return ret; } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/SafeClassWriter.java b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/SafeClassWriter.java index 052a226f..05b340e0 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/SafeClassWriter.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/SafeClassWriter.java @@ -1,10 +1,10 @@ package pro.gravit.launchserver.asm; -import java.util.ArrayList; - import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassWriter; +import java.util.ArrayList; + /** * ClassWriter с другой реализацией метода getCommonSuperClass: при его * использовании не происходит загрузки классов. diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java index 7e38da78..908c2f29 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java @@ -1,12 +1,12 @@ package pro.gravit.launchserver.auth; -import java.io.IOException; - import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.auth.handler.AuthHandler; import pro.gravit.launchserver.auth.provider.AuthProvider; import pro.gravit.launchserver.auth.texture.TextureProvider; +import java.io.IOException; + public class AuthProviderPair { public final AuthProvider provider; public final AuthHandler handler; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/MySQLSourceConfig.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/MySQLSourceConfig.java index ab24b0a0..82dafef4 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/MySQLSourceConfig.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/MySQLSourceConfig.java @@ -1,17 +1,15 @@ package pro.gravit.launchserver.auth; -import java.sql.Connection; -import java.sql.SQLException; - -import javax.sql.DataSource; - import com.mysql.cj.jdbc.MysqlDataSource; import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; - import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.VerifyHelper; +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.SQLException; + public final class MySQLSourceConfig implements AutoCloseable { public static final int TIMEOUT = VerifyHelper.verifyInt( diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/PostgreSQLSourceConfig.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/PostgreSQLSourceConfig.java index 643aaf6a..b6180efb 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/PostgreSQLSourceConfig.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/PostgreSQLSourceConfig.java @@ -1,17 +1,14 @@ package pro.gravit.launchserver.auth; -import java.sql.Connection; -import java.sql.SQLException; - -import javax.sql.DataSource; - -import org.postgresql.ds.PGSimpleDataSource; - import com.zaxxer.hikari.HikariDataSource; - +import org.postgresql.ds.PGSimpleDataSource; import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.VerifyHelper; +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.SQLException; + public final class PostgreSQLSourceConfig implements AutoCloseable { public static final int TIMEOUT = VerifyHelper.verifyInt( Integer.parseUnsignedInt(System.getProperty("launcher.postgresql.idleTimeout", Integer.toString(5000))), diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/AuthHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/AuthHandler.java index 840d8a3e..f1781689 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/AuthHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/AuthHandler.java @@ -1,13 +1,13 @@ package pro.gravit.launchserver.auth.handler; -import java.io.IOException; -import java.util.UUID; - import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.auth.AuthException; import pro.gravit.launchserver.auth.provider.AuthProviderResult; import pro.gravit.utils.ProviderMap; +import java.io.IOException; +import java.util.UUID; + public abstract class AuthHandler implements AutoCloseable { public static final ProviderMap providers = new ProviderMap<>("AuthHandler"); @@ -31,24 +31,24 @@ public static void registerHandlers() { } } - protected transient LaunchServer srv; + protected transient LaunchServer srv; /** * Returns the UUID associated with the account + * * @param authResult {@link pro.gravit.launchserver.auth.provider.AuthProvider} result * @return User UUID - * @throws IOException - * Internal Script Error + * @throws IOException Internal Script Error */ public abstract UUID auth(AuthProviderResult authResult) throws IOException; /** * Validates serverID + * * @param username user name * @param serverID serverID to check * @return user UUID - * @throws IOException - * Internal Script Error + * @throws IOException Internal Script Error */ public abstract UUID checkServer(String username, String serverID) throws IOException; @@ -58,12 +58,12 @@ public static void registerHandlers() { /** * Checks assessToken for validity and saves serverID if successful - * @param username user name + * + * @param username user name * @param accessToken assessToken to check - * @param serverID serverID to save + * @param serverID serverID to save * @return true - allow, false - deny - * @throws IOException - * Internal Script Error + * @throws IOException Internal Script Error */ public abstract boolean joinServer(String username, String accessToken, String serverID) throws IOException; @@ -74,6 +74,6 @@ public static void registerHandlers() { public abstract String uuidToUsername(UUID uuid) throws IOException; public void init(LaunchServer srv) { - this.srv = srv; + this.srv = srv; } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/CachedAuthHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/CachedAuthHandler.java index 4197360e..d6e07d46 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/CachedAuthHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/CachedAuthHandler.java @@ -1,5 +1,13 @@ package pro.gravit.launchserver.auth.handler; +import pro.gravit.launcher.Launcher; +import pro.gravit.launcher.NeedGarbageCollection; +import pro.gravit.launchserver.Reconfigurable; +import pro.gravit.launchserver.auth.provider.AuthProviderResult; +import pro.gravit.utils.command.Command; +import pro.gravit.utils.command.SubCommand; +import pro.gravit.utils.helper.*; + import java.io.IOException; import java.io.Reader; import java.io.Writer; @@ -9,18 +17,6 @@ import java.util.Objects; import java.util.UUID; -import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.NeedGarbageCollection; -import pro.gravit.launchserver.Reconfigurable; -import pro.gravit.launchserver.auth.provider.AuthProviderResult; -import pro.gravit.utils.command.Command; -import pro.gravit.utils.command.SubCommand; -import pro.gravit.utils.helper.CommonHelper; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.LogHelper; -import pro.gravit.utils.helper.SecurityHelper; -import pro.gravit.utils.helper.VerifyHelper; - public abstract class CachedAuthHandler extends AuthHandler implements NeedGarbageCollection, Reconfigurable { public static final class Entry { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/HibernateAuthHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/HibernateAuthHandler.java index c165f78a..6f688c0b 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/HibernateAuthHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/HibernateAuthHandler.java @@ -1,22 +1,21 @@ package pro.gravit.launchserver.auth.handler; -import java.io.IOException; -import java.util.UUID; - import pro.gravit.launchserver.dao.User; +import java.util.UUID; + public class HibernateAuthHandler extends CachedAuthHandler { @Override protected Entry fetchEntry(String username) { User user = srv.config.dao.userService.findUserByUsername(username); - if(user == null) return null; + if (user == null) return null; return new Entry(user.uuid, username, user.getAccessToken(), user.serverID); } @Override protected Entry fetchEntry(UUID uuid) { User user = srv.config.dao.userService.findUserByUUID(uuid); - if(user == null) return null; + if (user == null) return null; return new Entry(user.uuid, user.username, user.getAccessToken(), user.serverID); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/JsonAuthHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/JsonAuthHandler.java index 9ab78a41..41a0bb08 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/JsonAuthHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/JsonAuthHandler.java @@ -1,12 +1,12 @@ package pro.gravit.launchserver.auth.handler; +import pro.gravit.launcher.Launcher; +import pro.gravit.utils.HTTPRequest; + import java.io.IOException; import java.net.URL; import java.util.UUID; -import pro.gravit.launcher.Launcher; -import pro.gravit.utils.HTTPRequest; - public class JsonAuthHandler extends CachedAuthHandler { public URL getUrl; public URL updateAuthUrl; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/MemoryAuthHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/MemoryAuthHandler.java index 12929929..289f2590 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/MemoryAuthHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/MemoryAuthHandler.java @@ -1,12 +1,12 @@ package pro.gravit.launchserver.auth.handler; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.VerifyHelper; + import java.nio.ByteBuffer; import java.util.Arrays; import java.util.UUID; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.VerifyHelper; - public final class MemoryAuthHandler extends CachedAuthHandler { private static String toUsername(UUID uuid) { byte[] bytes = ByteBuffer.allocate(16). diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/MySQLAuthHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/MySQLAuthHandler.java index a0ef56f4..f6368280 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/MySQLAuthHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/MySQLAuthHandler.java @@ -1,5 +1,9 @@ package pro.gravit.launchserver.auth.handler; +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launchserver.auth.MySQLSourceConfig; +import pro.gravit.utils.helper.LogHelper; + import java.io.IOException; import java.sql.Connection; import java.sql.PreparedStatement; @@ -7,10 +11,6 @@ import java.sql.SQLException; import java.util.UUID; -import pro.gravit.launchserver.LaunchServer; -import pro.gravit.launchserver.auth.MySQLSourceConfig; -import pro.gravit.utils.helper.LogHelper; - public final class MySQLAuthHandler extends CachedAuthHandler { private MySQLSourceConfig mySQLHolder; private String uuidColumn; @@ -27,7 +27,7 @@ public final class MySQLAuthHandler extends CachedAuthHandler { @Override public void init(LaunchServer srv) { - super.init(srv); + super.init(srv); //Verify if (mySQLHolder == null) LogHelper.error("[Verify][AuthHandler] mySQLHolder cannot be null"); if (uuidColumn == null) LogHelper.error("[Verify][AuthHandler] uuidColumn cannot be null"); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/NullAuthHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/NullAuthHandler.java index 2357fed8..954998ef 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/NullAuthHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/NullAuthHandler.java @@ -1,12 +1,12 @@ package pro.gravit.launchserver.auth.handler; +import pro.gravit.launchserver.auth.provider.AuthProviderResult; +import pro.gravit.utils.helper.VerifyHelper; + import java.io.IOException; import java.util.Objects; import java.util.UUID; -import pro.gravit.launchserver.auth.provider.AuthProviderResult; -import pro.gravit.utils.helper.VerifyHelper; - public final class NullAuthHandler extends AuthHandler { private volatile AuthHandler handler; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/PostgreSQLAuthHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/PostgreSQLAuthHandler.java index 2d794b1b..ea5c01ff 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/PostgreSQLAuthHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/PostgreSQLAuthHandler.java @@ -1,5 +1,8 @@ package pro.gravit.launchserver.auth.handler; +import org.postgresql.util.PGobject; +import pro.gravit.launchserver.auth.PostgreSQLSourceConfig; + import java.io.IOException; import java.sql.Connection; import java.sql.PreparedStatement; @@ -7,10 +10,6 @@ import java.sql.SQLException; import java.util.UUID; -import org.postgresql.util.PGobject; - -import pro.gravit.launchserver.auth.PostgreSQLSourceConfig; - public final class PostgreSQLAuthHandler extends CachedAuthHandler { private PostgreSQLSourceConfig postgreSQLHolder; private String uuidColumn; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/RequestAuthHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/RequestAuthHandler.java index c6812693..729fe711 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/RequestAuthHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/RequestAuthHandler.java @@ -1,14 +1,14 @@ package pro.gravit.launchserver.auth.handler; -import java.io.IOException; -import java.net.URL; -import java.util.UUID; - import pro.gravit.launchserver.LaunchServer; import pro.gravit.utils.helper.CommonHelper; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; +import java.io.IOException; +import java.net.URL; +import java.util.UUID; + public final class RequestAuthHandler extends CachedAuthHandler { private String usernameFetch; private String uuidFetch; @@ -21,7 +21,7 @@ public final class RequestAuthHandler extends CachedAuthHandler { @Override public void init(LaunchServer srv) { - super.init(srv); + super.init(srv); if (usernameFetch == null) LogHelper.error("[Verify][AuthHandler] usernameFetch cannot be null"); if (uuidFetch == null) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/AcceptHWIDHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/AcceptHWIDHandler.java index 16a36b0d..bed24943 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/AcceptHWIDHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/AcceptHWIDHandler.java @@ -1,10 +1,10 @@ package pro.gravit.launchserver.auth.hwid; +import pro.gravit.launcher.hwid.HWID; + import java.util.ArrayList; import java.util.List; -import pro.gravit.launcher.hwid.HWID; - public class AcceptHWIDHandler extends HWIDHandler { @Override diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/HWIDHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/HWIDHandler.java index b0754c1f..77ba174b 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/HWIDHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/HWIDHandler.java @@ -1,9 +1,5 @@ package pro.gravit.launchserver.auth.hwid; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - import pro.gravit.launcher.hwid.HWID; import pro.gravit.launchserver.Reconfigurable; import pro.gravit.utils.ProviderMap; @@ -11,6 +7,10 @@ import pro.gravit.utils.command.SubCommand; import pro.gravit.utils.helper.LogHelper; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + public abstract class HWIDHandler implements AutoCloseable, Reconfigurable { public static final ProviderMap providers = new ProviderMap<>("HWIDHandler"); private static boolean registredHandl = false; @@ -48,8 +48,7 @@ public void invoke(String... args) throws Exception { @Override public void invoke(String... args) throws Exception { List target = getHwid(args[0]); - for(HWID hwid : target) - { + for (HWID hwid : target) { if (hwid == null) { LogHelper.error("[%s] HWID: null", args[0]); continue; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/JsonFileHWIDHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/JsonFileHWIDHandler.java index ff831846..0c34076c 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/JsonFileHWIDHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/JsonFileHWIDHandler.java @@ -1,5 +1,11 @@ package pro.gravit.launchserver.auth.hwid; +import com.google.gson.reflect.TypeToken; +import pro.gravit.launcher.Launcher; +import pro.gravit.launcher.hwid.HWID; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.LogHelper; + import java.io.IOException; import java.io.Reader; import java.io.Writer; @@ -10,13 +16,6 @@ import java.util.List; import java.util.Objects; -import com.google.gson.reflect.TypeToken; - -import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.hwid.HWID; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.LogHelper; - public class JsonFileHWIDHandler extends HWIDHandler { public static class Entry { public final HWID hwid; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/JsonHWIDHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/JsonHWIDHandler.java index abba10c6..ac2e796f 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/JsonHWIDHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/JsonHWIDHandler.java @@ -1,19 +1,18 @@ package pro.gravit.launchserver.auth.hwid; +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import pro.gravit.launcher.hwid.HWID; +import pro.gravit.launcher.hwid.OshiHWID; +import pro.gravit.utils.HTTPRequest; +import pro.gravit.utils.helper.LogHelper; + import java.io.IOException; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import com.google.gson.Gson; -import com.google.gson.JsonElement; - -import pro.gravit.launcher.hwid.HWID; -import pro.gravit.launcher.hwid.OshiHWID; -import pro.gravit.utils.HTTPRequest; -import pro.gravit.utils.helper.LogHelper; - public final class JsonHWIDHandler extends HWIDHandler { private static final Gson gson = new Gson(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/MemoryHWIDHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/MemoryHWIDHandler.java index 16ed445b..6bcbd194 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/MemoryHWIDHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/MemoryHWIDHandler.java @@ -1,11 +1,11 @@ package pro.gravit.launchserver.auth.hwid; +import pro.gravit.launcher.hwid.HWID; + import java.util.LinkedList; import java.util.List; import java.util.Objects; -import pro.gravit.launcher.hwid.HWID; - public class MemoryHWIDHandler extends HWIDHandler { public static class Entry { public final HWID hwid; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java index 3b9b63d4..a68d210d 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java @@ -1,5 +1,11 @@ package pro.gravit.launchserver.auth.hwid; +import pro.gravit.launcher.hwid.HWID; +import pro.gravit.launcher.hwid.OshiHWID; +import pro.gravit.launchserver.auth.MySQLSourceConfig; +import pro.gravit.utils.helper.CommonHelper; +import pro.gravit.utils.helper.LogHelper; + import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -7,12 +13,6 @@ import java.util.ArrayList; import java.util.List; -import pro.gravit.launcher.hwid.HWID; -import pro.gravit.launcher.hwid.OshiHWID; -import pro.gravit.launchserver.auth.MySQLSourceConfig; -import pro.gravit.utils.helper.CommonHelper; -import pro.gravit.utils.helper.LogHelper; - public class MysqlHWIDHandler extends HWIDHandler { private MySQLSourceConfig mySQLHolder; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/HibernatePermissionsHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/HibernatePermissionsHandler.java index a49d8755..2cb030a2 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/HibernatePermissionsHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/HibernatePermissionsHandler.java @@ -8,14 +8,14 @@ public class HibernatePermissionsHandler extends PermissionsHandler { @Override public ClientPermissions getPermissions(String username) { User user = srv.config.dao.userService.findUserByUsername(username); - if(user == null) return ClientPermissions.DEFAULT; + if (user == null) return ClientPermissions.DEFAULT; return user.getPermissions(); } @Override public void setPermissions(String username, ClientPermissions permissions) { User user = srv.config.dao.userService.findUserByUsername(username); - if(user == null) return; + if (user == null) return; user.setPermissions(permissions); srv.config.dao.userService.updateUser(user); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java index 71702349..1ca4227e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java @@ -1,5 +1,15 @@ package pro.gravit.launchserver.auth.permissions; +import com.google.gson.reflect.TypeToken; +import pro.gravit.launcher.ClientPermissions; +import pro.gravit.launcher.Launcher; +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launchserver.Reconfigurable; +import pro.gravit.utils.command.Command; +import pro.gravit.utils.command.SubCommand; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.LogHelper; + import java.io.IOException; import java.io.Reader; import java.io.Writer; @@ -9,17 +19,6 @@ import java.util.HashMap; import java.util.Map; -import com.google.gson.reflect.TypeToken; - -import pro.gravit.launcher.ClientPermissions; -import pro.gravit.launcher.Launcher; -import pro.gravit.launchserver.LaunchServer; -import pro.gravit.launchserver.Reconfigurable; -import pro.gravit.utils.command.Command; -import pro.gravit.utils.command.SubCommand; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.LogHelper; - public class JsonFilePermissionsHandler extends PermissionsHandler implements Reconfigurable { public final String filename = "permissions.json"; public static Map map; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/JsonLongFilePermissionsHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/JsonLongFilePermissionsHandler.java index c9dbae21..c908777c 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/JsonLongFilePermissionsHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/JsonLongFilePermissionsHandler.java @@ -1,5 +1,15 @@ package pro.gravit.launchserver.auth.permissions; +import com.google.gson.reflect.TypeToken; +import pro.gravit.launcher.ClientPermissions; +import pro.gravit.launcher.Launcher; +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launchserver.Reconfigurable; +import pro.gravit.utils.command.Command; +import pro.gravit.utils.command.SubCommand; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.LogHelper; + import java.io.IOException; import java.io.Reader; import java.io.Writer; @@ -9,17 +19,6 @@ import java.util.HashMap; import java.util.Map; -import com.google.gson.reflect.TypeToken; - -import pro.gravit.launcher.ClientPermissions; -import pro.gravit.launcher.Launcher; -import pro.gravit.launchserver.LaunchServer; -import pro.gravit.launchserver.Reconfigurable; -import pro.gravit.utils.command.Command; -import pro.gravit.utils.command.SubCommand; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.LogHelper; - public class JsonLongFilePermissionsHandler extends PermissionsHandler implements Reconfigurable { public final String filename = "permissions.json"; public final long defaultPerms = 0L; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/PermissionsHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/PermissionsHandler.java index 73fe7968..0ab6c4ae 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/PermissionsHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/PermissionsHandler.java @@ -20,8 +20,7 @@ public static void registerHandlers() { } } - public void init(LaunchServer server) - { + public void init(LaunchServer server) { this.srv = server; } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/StdProtectHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/StdProtectHandler.java index acee9429..1b165ea4 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/StdProtectHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/StdProtectHandler.java @@ -5,6 +5,7 @@ public class StdProtectHandler extends ProtectHandler { public final boolean checkSecure = true; + @Override public String generateSecureToken(AuthResponse.AuthContext context) { return SecurityHelper.randomStringToken(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AuthProvider.java index b10cef06..07b02ae6 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AuthProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AuthProvider.java @@ -1,16 +1,17 @@ package pro.gravit.launchserver.auth.provider; -import java.io.IOException; - import pro.gravit.launcher.request.auth.AuthRequest; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.auth.AuthException; import pro.gravit.utils.ProviderMap; +import java.io.IOException; + public abstract class AuthProvider implements AutoCloseable { public static final ProviderMap providers = new ProviderMap<>("AuthProvider"); private static boolean registredProv = false; protected transient LaunchServer srv = null; + public static AuthProviderResult authError(String message) throws AuthException { throw new AuthException(message); } @@ -32,13 +33,13 @@ public static void registerProviders() { /** * Verifies the username and password - * @param login user login + * + * @param login user login * @param password user password - * @param ip user ip + * @param ip user ip * @return player privileges, effective username and authorization token - * @throws Exception - * Throws an exception {@link AuthException} {@link pro.gravit.utils.HookException} if the verification script returned a meaningful error - * In other cases, throwing an exception indicates a serious error + * @throws Exception Throws an exception {@link AuthException} {@link pro.gravit.utils.HookException} if the verification script returned a meaningful error + * In other cases, throwing an exception indicates a serious error */ public abstract AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface password, String ip) throws Exception; @@ -49,6 +50,6 @@ public void preAuth(String login, AuthRequest.AuthPasswordInterface password, St public abstract void close() throws IOException; public void init(LaunchServer srv) { - this.srv = srv; + this.srv = srv; } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/HibernateAuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/HibernateAuthProvider.java index 14102dff..89587633 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/HibernateAuthProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/HibernateAuthProvider.java @@ -1,7 +1,5 @@ package pro.gravit.launchserver.auth.provider; -import java.io.IOException; - import pro.gravit.launcher.request.auth.AuthRequest; import pro.gravit.launcher.request.auth.password.AuthPlainPassword; import pro.gravit.launchserver.auth.AuthException; @@ -11,25 +9,21 @@ public class HibernateAuthProvider extends AuthProvider { public boolean autoReg; + @Override public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface password, String ip) throws Exception { - if(!(password instanceof AuthPlainPassword)) throw new AuthException("This password type not supported"); + if (!(password instanceof AuthPlainPassword)) throw new AuthException("This password type not supported"); User user = srv.config.dao.userService.findUserByUsername(login); - if(user == null && autoReg) - { + if (user == null && autoReg) { AuthHookManager.RegContext context = new AuthHookManager.RegContext(login, ((AuthPlainPassword) password).password, ip, false); - if(srv.authHookManager.registraion.hook(context)) - { + if (srv.authHookManager.registraion.hook(context)) { user = srv.config.dao.userService.registerNewUser(login, ((AuthPlainPassword) password).password); - } - else - { + } else { throw new AuthException("Registration canceled. Try again later"); } } - if(user == null || !user.verifyPassword(((AuthPlainPassword) password).password)) - { - if(user ==null) throw new AuthException("Username incorrect"); + if (user == null || !user.verifyPassword(((AuthPlainPassword) password).password)) { + if (user == null) throw new AuthException("Username incorrect"); else throw new AuthException("Username or password incorrect"); } return new AuthProviderResult(login, SecurityHelper.randomStringToken(), srv); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/JsonAuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/JsonAuthProvider.java index be1064f5..35e72088 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/JsonAuthProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/JsonAuthProvider.java @@ -1,11 +1,7 @@ package pro.gravit.launchserver.auth.provider; -import java.io.IOException; -import java.net.URL; - import com.google.gson.Gson; import com.google.gson.JsonElement; - import pro.gravit.launcher.ClientPermissions; import pro.gravit.launcher.request.auth.AuthRequest; import pro.gravit.launcher.request.auth.password.AuthPlainPassword; @@ -13,6 +9,9 @@ import pro.gravit.utils.HTTPRequest; import pro.gravit.utils.helper.SecurityHelper; +import java.io.IOException; +import java.net.URL; + public final class JsonAuthProvider extends AuthProvider { private static final Gson gson = new Gson(); private URL url; @@ -46,7 +45,7 @@ public authRequest(String username, String password, String ip, String apiKey) { @Override public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface password, String ip) throws IOException { - if(!(password instanceof AuthPlainPassword)) throw new AuthException("This password type not supported"); + if (!(password instanceof AuthPlainPassword)) throw new AuthException("This password type not supported"); authRequest authRequest = new authRequest(login, ((AuthPlainPassword) password).password, ip, apiKey); JsonElement request = gson.toJsonTree(authRequest); JsonElement content = HTTPRequest.jsonRequest(request, url); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/MySQLAuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/MySQLAuthProvider.java index d0cf2443..a5979f28 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/MySQLAuthProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/MySQLAuthProvider.java @@ -1,10 +1,5 @@ package pro.gravit.launchserver.auth.provider; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; - import pro.gravit.launcher.ClientPermissions; import pro.gravit.launcher.request.auth.AuthRequest; import pro.gravit.launcher.request.auth.password.AuthPlainPassword; @@ -15,6 +10,11 @@ import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.SecurityHelper; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + public final class MySQLAuthProvider extends AuthProvider { private MySQLSourceConfig mySQLHolder; private String query; @@ -24,7 +24,7 @@ public final class MySQLAuthProvider extends AuthProvider { @Override public void init(LaunchServer srv) { - super.init(srv); + super.init(srv); if (query == null) LogHelper.error("[Verify][AuthProvider] query cannot be null"); if (message == null) LogHelper.error("[Verify][AuthProvider] message cannot be null"); if (mySQLHolder == null) LogHelper.error("[Verify][AuthProvider] mySQLHolder cannot be null"); @@ -32,7 +32,7 @@ public void init(LaunchServer srv) { @Override public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface password, String ip) throws SQLException, AuthException { - if(!(password instanceof AuthPlainPassword)) throw new AuthException("This password type not supported"); + if (!(password instanceof AuthPlainPassword)) throw new AuthException("This password type not supported"); try (Connection c = mySQLHolder.getConnection()) { PreparedStatement s = c.prepareStatement(query); String[] replaceParams = {"login", login, "password", ((AuthPlainPassword) password).password, "ip", ip}; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/NullAuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/NullAuthProvider.java index 00e37188..0f7a37e7 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/NullAuthProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/NullAuthProvider.java @@ -1,11 +1,11 @@ package pro.gravit.launchserver.auth.provider; -import java.io.IOException; -import java.util.Objects; - import pro.gravit.launcher.request.auth.AuthRequest; import pro.gravit.utils.helper.VerifyHelper; +import java.io.IOException; +import java.util.Objects; + public final class NullAuthProvider extends AuthProvider { private volatile AuthProvider provider; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/PostgreSQLAuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/PostgreSQLAuthProvider.java index 47c7f6d4..09390a3f 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/PostgreSQLAuthProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/PostgreSQLAuthProvider.java @@ -1,11 +1,6 @@ package pro.gravit.launchserver.auth.provider; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; - import pro.gravit.launcher.ClientPermissions; import pro.gravit.launcher.request.auth.AuthRequest; import pro.gravit.launcher.request.auth.password.AuthPlainPassword; @@ -14,6 +9,11 @@ import pro.gravit.utils.helper.CommonHelper; import pro.gravit.utils.helper.SecurityHelper; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + public final class PostgreSQLAuthProvider extends AuthProvider { private PostgreSQLSourceConfig postgreSQLHolder; private String query; @@ -23,7 +23,7 @@ public final class PostgreSQLAuthProvider extends AuthProvider { @Override public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface password, String ip) throws SQLException, AuthException { - if(!(password instanceof AuthPlainPassword)) throw new AuthException("This password type not supported"); + if (!(password instanceof AuthPlainPassword)) throw new AuthException("This password type not supported"); try (Connection c = postgreSQLHolder.getConnection(); PreparedStatement s = c.prepareStatement(query)) { String[] replaceParams = {"login", login, "password", ((AuthPlainPassword) password).password, "ip", ip}; for (int i = 0; i < queryParams.length; i++) { @@ -40,6 +40,6 @@ public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface p @Override public void close() { - postgreSQLHolder.close(); + postgreSQLHolder.close(); } } \ No newline at end of file diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/RejectAuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/RejectAuthProvider.java index 2c9e50e5..75882753 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/RejectAuthProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/RejectAuthProvider.java @@ -1,9 +1,5 @@ package pro.gravit.launchserver.auth.provider; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; - import pro.gravit.launcher.request.auth.AuthRequest; import pro.gravit.launchserver.Reconfigurable; import pro.gravit.launchserver.auth.AuthException; @@ -12,6 +8,10 @@ import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.SecurityHelper; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + public final class RejectAuthProvider extends AuthProvider implements Reconfigurable { public RejectAuthProvider() { } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/RequestAuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/RequestAuthProvider.java index 1892e5c2..09ce4cbf 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/RequestAuthProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/RequestAuthProvider.java @@ -1,10 +1,5 @@ package pro.gravit.launchserver.auth.provider; -import java.io.IOException; -import java.net.URL; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - import pro.gravit.launcher.ClientPermissions; import pro.gravit.launcher.request.auth.AuthRequest; import pro.gravit.launcher.request.auth.password.AuthPlainPassword; @@ -15,6 +10,11 @@ import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.SecurityHelper; +import java.io.IOException; +import java.net.URL; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + public final class RequestAuthProvider extends AuthProvider { private String url; private transient Pattern pattern; @@ -23,7 +23,7 @@ public final class RequestAuthProvider extends AuthProvider { @Override public void init(LaunchServer srv) { - super.init(srv); + super.init(srv); if (url == null) LogHelper.error("[Verify][AuthProvider] url cannot be null"); if (response == null) LogHelper.error("[Verify][AuthProvider] response cannot be null"); pattern = Pattern.compile(response); @@ -31,7 +31,7 @@ public void init(LaunchServer srv) { @Override public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface password, String ip) throws IOException { - if(!(password instanceof AuthPlainPassword)) throw new AuthException("This password type not supported"); + if (!(password instanceof AuthPlainPassword)) throw new AuthException("This password type not supported"); String currentResponse = IOHelper.request(new URL(getFormattedURL(login, ((AuthPlainPassword) password).password, ip))); // Match username diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/NullTextureProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/NullTextureProvider.java index e715db39..b5f785f1 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/NullTextureProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/NullTextureProvider.java @@ -1,12 +1,12 @@ package pro.gravit.launchserver.auth.texture; +import pro.gravit.launcher.profiles.Texture; +import pro.gravit.utils.helper.VerifyHelper; + import java.io.IOException; import java.util.Objects; import java.util.UUID; -import pro.gravit.launcher.profiles.Texture; -import pro.gravit.utils.helper.VerifyHelper; - public final class NullTextureProvider extends TextureProvider { private volatile TextureProvider provider; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/RequestTextureProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/RequestTextureProvider.java index 3431deeb..a9e83274 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/RequestTextureProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/RequestTextureProvider.java @@ -1,15 +1,15 @@ package pro.gravit.launchserver.auth.texture; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.UUID; - import pro.gravit.launcher.Launcher; import pro.gravit.launcher.profiles.Texture; import pro.gravit.utils.helper.CommonHelper; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.UUID; + public final class RequestTextureProvider extends TextureProvider { public RequestTextureProvider() { } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/TextureProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/TextureProvider.java index c0c037a2..cd98f4c5 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/TextureProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/TextureProvider.java @@ -1,11 +1,11 @@ package pro.gravit.launchserver.auth.texture; -import java.io.IOException; -import java.util.UUID; - import pro.gravit.launcher.profiles.Texture; import pro.gravit.utils.ProviderMap; +import java.io.IOException; +import java.util.UUID; + public abstract class TextureProvider implements AutoCloseable { public static final ProviderMap providers = new ProviderMap<>("TextureProvider"); private static boolean registredProv = false; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/VoidTextureProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/VoidTextureProvider.java index 9d88769a..ad3f3387 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/VoidTextureProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/VoidTextureProvider.java @@ -1,9 +1,9 @@ package pro.gravit.launchserver.auth.texture; -import java.util.UUID; - import pro.gravit.launcher.profiles.Texture; +import java.util.UUID; + public final class VoidTextureProvider extends TextureProvider { @Override diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BuildContext.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BuildContext.java index 0e821bf9..5fa2ca7e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BuildContext.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BuildContext.java @@ -1,5 +1,8 @@ package pro.gravit.launchserver.binary; +import pro.gravit.launchserver.binary.tasks.MainBuildTask; +import pro.gravit.utils.helper.IOHelper; + import java.io.IOException; import java.io.InputStream; import java.util.HashSet; @@ -8,9 +11,6 @@ import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; -import pro.gravit.launchserver.binary.tasks.MainBuildTask; -import pro.gravit.utils.helper.IOHelper; - public class BuildContext { public final ZipOutputStream output; public final LauncherConfigurator config; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/EXEL4JLauncherBinary.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/EXEL4JLauncherBinary.java index 9570404c..75044e82 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/EXEL4JLauncherBinary.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/EXEL4JLauncherBinary.java @@ -1,20 +1,16 @@ package pro.gravit.launchserver.binary; -import java.io.IOException; -import java.nio.file.Path; - import net.sf.launch4j.Builder; import net.sf.launch4j.Log; -import net.sf.launch4j.config.Config; -import net.sf.launch4j.config.ConfigPersister; -import net.sf.launch4j.config.Jre; -import net.sf.launch4j.config.LanguageID; -import net.sf.launch4j.config.VersionInfo; +import net.sf.launch4j.config.*; import pro.gravit.launchserver.LaunchServer; import pro.gravit.utils.Version; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; +import java.io.IOException; +import java.nio.file.Path; + public final class EXEL4JLauncherBinary extends LauncherBinary { private final static class Launch4JLog extends Log { private static final Launch4JLog INSTANCE = new Launch4JLog(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/EXELauncherBinary.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/EXELauncherBinary.java index dc742aee..0e0c9e3f 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/EXELauncherBinary.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/EXELauncherBinary.java @@ -1,12 +1,12 @@ package pro.gravit.launchserver.binary; -import java.io.IOException; -import java.nio.file.Files; - import pro.gravit.launchserver.LaunchServer; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; +import java.io.IOException; +import java.nio.file.Files; + public class EXELauncherBinary extends LauncherBinary { public EXELauncherBinary(LaunchServer server) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JARLauncherBinary.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JARLauncherBinary.java index 0c20f5c7..e28d0f04 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JARLauncherBinary.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JARLauncherBinary.java @@ -1,5 +1,12 @@ package pro.gravit.launchserver.binary; +import pro.gravit.launcher.Launcher; +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launchserver.binary.tasks.*; +import pro.gravit.utils.helper.CommonHelper; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.LogHelper; + import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -7,19 +14,6 @@ import java.util.List; import java.util.concurrent.atomic.AtomicLong; -import pro.gravit.launcher.Launcher; -import pro.gravit.launchserver.LaunchServer; -import pro.gravit.launchserver.binary.tasks.AdditionalFixesApplyTask; -import pro.gravit.launchserver.binary.tasks.AttachJarsTask; -import pro.gravit.launchserver.binary.tasks.CompressBuildTask; -import pro.gravit.launchserver.binary.tasks.LauncherBuildTask; -import pro.gravit.launchserver.binary.tasks.MainBuildTask; -import pro.gravit.launchserver.binary.tasks.PrepareBuildTask; -import pro.gravit.launchserver.binary.tasks.ProGuardBuildTask; -import pro.gravit.utils.helper.CommonHelper; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.LogHelper; - public final class JARLauncherBinary extends LauncherBinary { public final AtomicLong count; public final Path runtimeDir; @@ -52,7 +46,7 @@ public void init() { tasks.add(new ProGuardBuildTask(server)); tasks.add(new AdditionalFixesApplyTask(server)); if (!server.config.launcher.attachLibraryBeforeProGuard) tasks.add(new AttachJarsTask(server)); - if(server.config.launcher.compress) tasks.add(new CompressBuildTask(server)); + if (server.config.launcher.compress) tasks.add(new CompressBuildTask(server)); } @Override diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherBinary.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherBinary.java index a12817f5..62457dbd 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherBinary.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherBinary.java @@ -1,12 +1,12 @@ package pro.gravit.launchserver.binary; -import java.io.IOException; -import java.nio.file.Path; - import pro.gravit.launchserver.LaunchServer; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.SecurityHelper; +import java.io.IOException; +import java.nio.file.Path; + public abstract class LauncherBinary { public final LaunchServer server; public final Path syncBinaryFile; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherConfigurator.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherConfigurator.java index bde39553..c09684a2 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherConfigurator.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherConfigurator.java @@ -2,14 +2,7 @@ import org.objectweb.asm.Opcodes; import org.objectweb.asm.Type; -import org.objectweb.asm.tree.ClassNode; -import org.objectweb.asm.tree.FieldInsnNode; -import org.objectweb.asm.tree.InsnList; -import org.objectweb.asm.tree.InsnNode; -import org.objectweb.asm.tree.MethodInsnNode; -import org.objectweb.asm.tree.MethodNode; -import org.objectweb.asm.tree.TypeInsnNode; - +import org.objectweb.asm.tree.*; import pro.gravit.launcher.LauncherConfig; import pro.gravit.launcher.modules.LauncherModule; import pro.gravit.launchserver.asm.ClassMetadataReader; @@ -23,7 +16,7 @@ public class LauncherConfigurator extends ConfigGenerator { private final MethodNode initModuleMethod; public LauncherConfigurator(ClassNode configclass) { - super(configclass); + super(configclass); initModuleMethod = configclass.methods.stream().filter(e -> "initModules".equals(e.name)).findFirst().get(); initModuleMethod.instructions = new InsnList(); } @@ -38,7 +31,7 @@ public void addModuleClass(String fullName) { @Override public byte[] getBytecode(ClassMetadataReader reader) { - initModuleMethod.instructions.add(new InsnNode(Opcodes.RETURN)); + initModuleMethod.instructions.add(new InsnNode(Opcodes.RETURN)); return super.getBytecode(reader); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/ProguardConf.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/ProguardConf.java index a5286aec..123b8a89 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/ProguardConf.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/ProguardConf.java @@ -1,5 +1,11 @@ package pro.gravit.launchserver.binary; +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.LogHelper; +import pro.gravit.utils.helper.SecurityHelper; +import pro.gravit.utils.helper.UnpackHelper; + import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; @@ -9,12 +15,6 @@ import java.util.ArrayList; import java.util.List; -import pro.gravit.launchserver.LaunchServer; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.LogHelper; -import pro.gravit.utils.helper.SecurityHelper; -import pro.gravit.utils.helper.UnpackHelper; - public class ProguardConf { private static final String chars = "1aAbBcC2dDeEfF3gGhHiI4jJkKl5mMnNoO6pPqQrR7sStT8uUvV9wWxX0yYzZ"; @@ -45,7 +45,8 @@ public ProguardConf(LaunchServer srv) { public String[] buildConfig(Path inputJar, Path outputJar) { List confStrs = new ArrayList<>(); prepare(false); - if (srv.config.launcher.proguardGenMappings) confStrs.add("-printmapping \'" + mappings.toFile().getName() + "\'"); + if (srv.config.launcher.proguardGenMappings) + confStrs.add("-printmapping \'" + mappings.toFile().getName() + "\'"); confStrs.add("-obfuscationdictionary \'" + words.toFile().getName() + "\'"); confStrs.add("-injar \'" + inputJar.toAbsolutePath() + "\'"); confStrs.add("-outjar \'" + outputJar.toAbsolutePath() + "\'"); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/SimpleEXELauncherBinary.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/SimpleEXELauncherBinary.java index 83a6db4b..a9cd8cf5 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/SimpleEXELauncherBinary.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/SimpleEXELauncherBinary.java @@ -1,15 +1,16 @@ package pro.gravit.launchserver.binary; -import java.io.IOException; -import java.io.OutputStream; -import java.nio.file.Path; - import pro.gravit.launchserver.LaunchServer; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; +import java.io.IOException; +import java.io.OutputStream; +import java.nio.file.Path; + public class SimpleEXELauncherBinary extends LauncherBinary { public final Path exeTemplate; + public SimpleEXELauncherBinary(LaunchServer server) { super(server, LauncherBinary.resolve(server, ".exe")); exeTemplate = server.dir.resolve("SimpleTemplate.exe"); @@ -17,13 +18,11 @@ public SimpleEXELauncherBinary(LaunchServer server) { @Override public void build() throws IOException { - if(!IOHelper.isFile(exeTemplate)) - { + if (!IOHelper.isFile(exeTemplate)) { LogHelper.warning("[SimpleEXEBinary] File %s not found. %s not created", exeTemplate.toString(), syncBinaryFile.toString()); return; } - try(OutputStream output = IOHelper.newOutput(syncBinaryFile)) - { + try (OutputStream output = IOHelper.newOutput(syncBinaryFile)) { IOHelper.transfer(exeTemplate, output); IOHelper.transfer(server.launcherBinary.syncBinaryFile, output); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/AdditionalFixesApplyTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/AdditionalFixesApplyTask.java index cc409840..0aded026 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/AdditionalFixesApplyTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/AdditionalFixesApplyTask.java @@ -1,5 +1,14 @@ package pro.gravit.launchserver.binary.tasks; +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.tree.ClassNode; +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launchserver.asm.ClassMetadataReader; +import pro.gravit.launchserver.asm.SafeClassWriter; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.LogHelper; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.file.Path; @@ -11,16 +20,6 @@ import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.ClassWriter; -import org.objectweb.asm.tree.ClassNode; - -import pro.gravit.launchserver.LaunchServer; -import pro.gravit.launchserver.asm.ClassMetadataReader; -import pro.gravit.launchserver.asm.SafeClassWriter; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.LogHelper; - public class AdditionalFixesApplyTask implements LauncherBuildTask { private final LaunchServer server; @@ -75,9 +74,9 @@ public static void apply(Path inputFile, Path addFile, ZipOutputStream output, L bytes = outputStream.toByteArray(); } try { - bytes = classFix(bytes, reader, srv.config.launcher.stripLineNumbers); + bytes = classFix(bytes, reader, srv.config.launcher.stripLineNumbers); } catch (Throwable t) { - LogHelper.error(t); + LogHelper.error(t); } output.write(bytes); } else diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/AttachJarsTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/AttachJarsTask.java index d26735da..3ceae478 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/AttachJarsTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/AttachJarsTask.java @@ -1,5 +1,9 @@ package pro.gravit.launchserver.binary.tasks; +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.LogHelper; + import java.io.IOException; import java.nio.file.Path; import java.util.ArrayList; @@ -8,10 +12,6 @@ import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; -import pro.gravit.launchserver.LaunchServer; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.LogHelper; - public class AttachJarsTask implements LauncherBuildTask { private final LaunchServer srv; private final List jars; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/CompressBuildTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/CompressBuildTask.java index 9766a1b6..a53ee660 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/CompressBuildTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/CompressBuildTask.java @@ -1,5 +1,8 @@ package pro.gravit.launchserver.binary.tasks; +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.utils.helper.IOHelper; + import java.io.IOException; import java.nio.file.Path; import java.util.zip.Deflater; @@ -7,9 +10,6 @@ import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; -import pro.gravit.launchserver.LaunchServer; -import pro.gravit.utils.helper.IOHelper; - public class CompressBuildTask implements LauncherBuildTask { public transient final LaunchServer server; @@ -25,12 +25,10 @@ public String getName() { @Override public Path process(Path inputFile) throws IOException { Path output = server.launcherBinary.nextPath(this); - try(ZipOutputStream outputStream = new ZipOutputStream(IOHelper.newOutput(output))) - { + try (ZipOutputStream outputStream = new ZipOutputStream(IOHelper.newOutput(output))) { outputStream.setMethod(ZipOutputStream.DEFLATED); outputStream.setLevel(Deflater.BEST_COMPRESSION); - try(ZipInputStream input = IOHelper.newZipInput(inputFile)) - { + try (ZipInputStream input = IOHelper.newZipInput(inputFile)) { ZipEntry e = input.getNextEntry(); while (e != null) { if (e.isDirectory()) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java index 0c3b3b54..faf37520 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java @@ -1,6 +1,18 @@ package pro.gravit.launchserver.binary.tasks; -import static pro.gravit.utils.helper.IOHelper.newZipEntry; +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.tree.ClassNode; +import pro.gravit.launcher.AutogenConfig; +import pro.gravit.launcher.Launcher; +import pro.gravit.launcher.LauncherConfig; +import pro.gravit.launcher.serialize.HOutput; +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launchserver.asm.ClassMetadataReader; +import pro.gravit.launchserver.binary.BuildContext; +import pro.gravit.launchserver.binary.LauncherConfigurator; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.LogHelper; +import pro.gravit.utils.helper.SecurityHelper; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -17,20 +29,7 @@ import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.tree.ClassNode; - -import pro.gravit.launcher.AutogenConfig; -import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.LauncherConfig; -import pro.gravit.launcher.serialize.HOutput; -import pro.gravit.launchserver.LaunchServer; -import pro.gravit.launchserver.asm.ClassMetadataReader; -import pro.gravit.launchserver.binary.BuildContext; -import pro.gravit.launchserver.binary.LauncherConfigurator; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.LogHelper; -import pro.gravit.utils.helper.SecurityHelper; +import static pro.gravit.utils.helper.IOHelper.newZipEntry; public class MainBuildTask implements LauncherBuildTask { private final LaunchServer server; @@ -118,9 +117,9 @@ public String getName() { public Path process(Path inputJar) throws IOException { Path outputJar = server.launcherBinary.nextPath("main"); try (ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(outputJar))) { - ClassNode cn = new ClassNode(); - new ClassReader(IOHelper.getResourceBytes(AutogenConfig.class.getName().replace('.', '/').concat(".class"))).accept(cn, 0); - LauncherConfigurator launcherConfigurator = new LauncherConfigurator(cn); + ClassNode cn = new ClassNode(); + new ClassReader(IOHelper.getResourceBytes(AutogenConfig.class.getName().replace('.', '/').concat(".class"))).accept(cn, 0); + LauncherConfigurator launcherConfigurator = new LauncherConfigurator(cn); BuildContext context = new BuildContext(output, launcherConfigurator, this); server.buildHookManager.hook(context); launcherConfigurator.setStringField("address", server.config.netty.address); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/PrepareBuildTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/PrepareBuildTask.java index 4171555c..b412fb5b 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/PrepareBuildTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/PrepareBuildTask.java @@ -1,5 +1,10 @@ package pro.gravit.launchserver.binary.tasks; +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.LogHelper; +import pro.gravit.utils.helper.UnpackHelper; + import java.io.IOException; import java.nio.file.FileVisitResult; import java.nio.file.Files; @@ -8,11 +13,6 @@ import java.nio.file.attribute.BasicFileAttributes; import java.util.List; -import pro.gravit.launchserver.LaunchServer; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.LogHelper; -import pro.gravit.utils.helper.UnpackHelper; - public class PrepareBuildTask implements LauncherBuildTask { private final LaunchServer server; private final Path result; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/ProGuardBuildTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/ProGuardBuildTask.java index 71f2117e..3fc2636c 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/ProGuardBuildTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/ProGuardBuildTask.java @@ -1,8 +1,5 @@ package pro.gravit.launchserver.binary.tasks; -import java.io.IOException; -import java.nio.file.Path; - import pro.gravit.launchserver.LaunchServer; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; @@ -11,6 +8,9 @@ import proguard.ParseException; import proguard.ProGuard; +import java.io.IOException; +import java.nio.file.Path; + public class ProGuardBuildTask implements LauncherBuildTask { private final LaunchServer server; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/Command.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/Command.java index ef48ce08..32ed911e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/Command.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/Command.java @@ -1,9 +1,9 @@ package pro.gravit.launchserver.command; -import java.util.Map; - import pro.gravit.launchserver.LaunchServer; +import java.util.Map; + public abstract class Command extends pro.gravit.utils.command.Command { 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 d7d14289..788a179f 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 @@ -1,7 +1,5 @@ package pro.gravit.launchserver.command.auth; -import java.util.UUID; - import pro.gravit.launcher.request.auth.password.AuthPlainPassword; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.auth.AuthProviderPair; @@ -10,6 +8,8 @@ import pro.gravit.launchserver.command.Command; import pro.gravit.utils.helper.LogHelper; +import java.util.UUID; + public final class AuthCommand extends Command { public AuthCommand(LaunchServer server) { super(server); 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 75c0ffdb..9fc248af 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 @@ -1,14 +1,14 @@ package pro.gravit.launchserver.command.auth; -import java.io.IOException; -import java.util.UUID; - import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.command.Command; import pro.gravit.utils.command.CommandException; import pro.gravit.utils.helper.LogHelper; +import java.io.IOException; +import java.util.UUID; + public final class UUIDToUsernameCommand extends Command { public UUIDToUsernameCommand(LaunchServer server) { super(server); 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 a3947ff5..770b99b2 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 @@ -1,14 +1,14 @@ package pro.gravit.launchserver.command.auth; -import java.io.IOException; -import java.util.UUID; - import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.command.Command; import pro.gravit.utils.command.CommandException; import pro.gravit.utils.helper.LogHelper; +import java.io.IOException; +import java.util.UUID; + public final class UsernameToUUIDCommand extends Command { public UsernameToUUIDCommand(LaunchServer server) { super(server); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/basic/ProguardCleanCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/basic/ProguardCleanCommand.java index 0b62e09e..7ec6460b 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/basic/ProguardCleanCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/basic/ProguardCleanCommand.java @@ -1,11 +1,11 @@ package pro.gravit.launchserver.command.basic; -import java.io.IOException; -import java.nio.file.Files; - import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.command.Command; +import java.io.IOException; +import java.nio.file.Files; + public class ProguardCleanCommand extends Command { public ProguardCleanCommand(LaunchServer server) { super(server); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/basic/RegenProguardDictCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/basic/RegenProguardDictCommand.java index bc6750bd..214ec014 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/basic/RegenProguardDictCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/basic/RegenProguardDictCommand.java @@ -1,10 +1,10 @@ package pro.gravit.launchserver.command.basic; -import java.io.IOException; - import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.command.Command; +import java.io.IOException; + public class RegenProguardDictCommand extends Command { public RegenProguardDictCommand(LaunchServer server) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/basic/RemoveMappingsProguardCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/basic/RemoveMappingsProguardCommand.java index e6b47c31..f16d5374 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/basic/RemoveMappingsProguardCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/basic/RemoveMappingsProguardCommand.java @@ -1,11 +1,11 @@ package pro.gravit.launchserver.command.basic; -import java.io.IOException; -import java.nio.file.Files; - import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.command.Command; +import java.io.IOException; +import java.nio.file.Files; + public class RemoveMappingsProguardCommand extends Command { public RemoveMappingsProguardCommand(LaunchServer server) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/basic/TestCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/basic/TestCommand.java index 4511a8d9..e269c37c 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/basic/TestCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/basic/TestCommand.java @@ -1,10 +1,6 @@ package pro.gravit.launchserver.command.basic; -import java.nio.file.Paths; -import java.security.KeyPair; - import org.bouncycastle.cert.X509CertificateHolder; - import pro.gravit.launcher.hwid.HWIDCheckHelper; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.command.Command; @@ -12,6 +8,9 @@ import pro.gravit.utils.helper.CommonHelper; import pro.gravit.utils.helper.LogHelper; +import java.nio.file.Paths; +import java.security.KeyPair; + public class TestCommand extends Command { public TestCommand(LaunchServer server) { super(server); @@ -40,16 +39,16 @@ public void invoke(String... args) throws Exception { if (args[0].equals("stop")) { handler.close(); } - if(args[0].equals("genCA")) { + if (args[0].equals("genCA")) { server.certificateManager.generateCA(); server.certificateManager.writePrivateKey(Paths.get("ca.key"), server.certificateManager.caKey); server.certificateManager.writeCertificate(Paths.get("ca.crt"), server.certificateManager.ca); } - if(args[0].equals("readCA")) { + if (args[0].equals("readCA")) { server.certificateManager.ca = server.certificateManager.readCertificate(Paths.get("ca.crt")); server.certificateManager.caKey = server.certificateManager.readPrivateKey(Paths.get("ca.key")); } - if(args[0].equals("genCert")) { + if (args[0].equals("genCert")) { verifyArgs(args, 2); String name = args[1]; KeyPair pair = server.certificateManager.generateKeyPair(); @@ -57,8 +56,7 @@ public void invoke(String... args) throws Exception { server.certificateManager.writePrivateKey(Paths.get(name.concat(".key")), pair.getPrivate()); server.certificateManager.writeCertificate(Paths.get(name.concat(".crt")), cert); } - if(args[0].equals("hwidcheck")) - { + if (args[0].equals("hwidcheck")) { LogHelper.info("HWID String %s bad rating %d", args[1], HWIDCheckHelper.checkString(args[1])); } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/GetAllUsersCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/GetAllUsersCommand.java index 6ef93227..bfb6cf59 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/GetAllUsersCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/GetAllUsersCommand.java @@ -23,8 +23,7 @@ public String getUsageDescription() { @Override public void invoke(String... args) { int count = 0; - for(User user : server.config.dao.userService.findAllUsers()) - { + for (User user : server.config.dao.userService.findAllUsers()) { LogHelper.subInfo("[%s] UUID: %s", user.username, user.uuid.toString()); count++; } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/GetUserCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/GetUserCommand.java index 3956f6f1..7b0ae432 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/GetUserCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/GetUserCommand.java @@ -24,8 +24,7 @@ public String getUsageDescription() { public void invoke(String... args) throws Exception { verifyArgs(args, 1); User user = server.config.dao.userService.findUserByUsername(args[0]); - if(user == null) - { + if (user == null) { LogHelper.error("User %s not found", args[0]); return; } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/RegisterCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/RegisterCommand.java index 04b759e3..c970551a 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/RegisterCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/RegisterCommand.java @@ -1,12 +1,12 @@ package pro.gravit.launchserver.command.dao; -import java.util.UUID; - import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.command.Command; import pro.gravit.launchserver.dao.User; import pro.gravit.utils.helper.LogHelper; +import java.util.UUID; + public class RegisterCommand extends Command { public RegisterCommand(LaunchServer server) { super(server); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/SetUserPasswordCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/SetUserPasswordCommand.java index 75ef14ff..8d0a6c47 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/SetUserPasswordCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/SetUserPasswordCommand.java @@ -25,8 +25,7 @@ public String getUsageDescription() { public void invoke(String... args) throws Exception { verifyArgs(args, 2); User user = server.config.dao.userService.findUserByUsername(args[0]); - if(user == null) - { + if (user == null) { LogHelper.error("User %s not found", args[1]); return; } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/dump/DumpSessionsCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dump/DumpSessionsCommand.java index 90b790a7..4eff81ff 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/dump/DumpSessionsCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dump/DumpSessionsCommand.java @@ -1,5 +1,14 @@ package pro.gravit.launchserver.command.dump; +import com.google.gson.reflect.TypeToken; +import pro.gravit.launcher.Launcher; +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launchserver.command.Command; +import pro.gravit.launchserver.socket.Client; +import pro.gravit.utils.command.SubCommand; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.LogHelper; + import java.io.Reader; import java.io.Writer; import java.lang.reflect.Type; @@ -8,16 +17,6 @@ import java.util.HashSet; import java.util.Set; -import com.google.gson.reflect.TypeToken; - -import pro.gravit.launcher.Launcher; -import pro.gravit.launchserver.LaunchServer; -import pro.gravit.launchserver.command.Command; -import pro.gravit.launchserver.socket.Client; -import pro.gravit.utils.command.SubCommand; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.LogHelper; - public class DumpSessionsCommand extends Command { public DumpSessionsCommand(LaunchServer server) { super(server); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java index ec3f0c2d..7f096924 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java @@ -4,37 +4,18 @@ import pro.gravit.launchserver.command.auth.AuthCommand; import pro.gravit.launchserver.command.auth.UUIDToUsernameCommand; import pro.gravit.launchserver.command.auth.UsernameToUUIDCommand; -import pro.gravit.launchserver.command.basic.BuildCommand; -import pro.gravit.launchserver.command.basic.ProguardCleanCommand; -import pro.gravit.launchserver.command.basic.RegenProguardDictCommand; -import pro.gravit.launchserver.command.basic.RemoveMappingsProguardCommand; -import pro.gravit.launchserver.command.basic.RestartCommand; -import pro.gravit.launchserver.command.basic.StopCommand; -import pro.gravit.launchserver.command.basic.TestCommand; -import pro.gravit.launchserver.command.basic.VersionCommand; +import pro.gravit.launchserver.command.basic.*; import pro.gravit.launchserver.command.dao.GetAllUsersCommand; import pro.gravit.launchserver.command.dao.GetUserCommand; import pro.gravit.launchserver.command.dao.RegisterCommand; import pro.gravit.launchserver.command.dao.SetUserPasswordCommand; import pro.gravit.launchserver.command.dump.DumpSessionsCommand; -import pro.gravit.launchserver.command.hash.DownloadAssetCommand; -import pro.gravit.launchserver.command.hash.DownloadClientCommand; -import pro.gravit.launchserver.command.hash.IndexAssetCommand; -import pro.gravit.launchserver.command.hash.SyncBinariesCommand; -import pro.gravit.launchserver.command.hash.SyncProfilesCommand; -import pro.gravit.launchserver.command.hash.SyncUpdatesCommand; -import pro.gravit.launchserver.command.hash.UnindexAssetCommand; +import pro.gravit.launchserver.command.hash.*; import pro.gravit.launchserver.command.install.CheckInstallCommand; import pro.gravit.launchserver.command.install.MultiCommand; import pro.gravit.launchserver.command.modules.LoadModuleCommand; import pro.gravit.launchserver.command.modules.ModulesCommand; -import pro.gravit.launchserver.command.service.ClientsCommand; -import pro.gravit.launchserver.command.service.ComponentCommand; -import pro.gravit.launchserver.command.service.ConfigCommand; -import pro.gravit.launchserver.command.service.GetModulusCommand; -import pro.gravit.launchserver.command.service.GetPermissionsCommand; -import pro.gravit.launchserver.command.service.GivePermissionsCommand; -import pro.gravit.launchserver.command.service.ServerStatusCommand; +import pro.gravit.launchserver.command.service.*; import pro.gravit.utils.command.BaseCommandCategory; import pro.gravit.utils.command.basic.ClearCommand; import pro.gravit.utils.command.basic.DebugCommand; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadAssetCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadAssetCommand.java index 77e60c26..0fd3476a 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadAssetCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadAssetCommand.java @@ -1,14 +1,14 @@ package pro.gravit.launchserver.command.hash; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Collections; - import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.command.Command; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Collections; + public final class DownloadAssetCommand extends Command { public DownloadAssetCommand(LaunchServer server) { @@ -40,7 +40,7 @@ public void invoke(String... args) throws Exception { // Download required asset LogHelper.subInfo("Downloading asset, it may take some time"); //HttpDownloader.downloadZip(server.mirrorManager.getDefaultMirror().getAssetsURL(version.name), assetDir); - server.mirrorManager.downloadZip(assetDir,"assets/%s.zip", versionName); + server.mirrorManager.downloadZip(assetDir, "assets/%s.zip", versionName); // Finished server.syncUpdatesDir(Collections.singleton(dirName)); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadClientCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadClientCommand.java index 99c9da7f..54b3f738 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadClientCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadClientCommand.java @@ -1,12 +1,5 @@ package pro.gravit.launchserver.command.hash; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Collections; - import com.google.gson.JsonElement; import pro.gravit.launcher.Launcher; import pro.gravit.launcher.profiles.ClientProfile; @@ -16,6 +9,13 @@ import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Collections; + public final class DownloadClientCommand extends Command { public DownloadClientCommand(LaunchServer server) { @@ -47,7 +47,7 @@ public void invoke(String... args) throws IOException, CommandException { // Download required client LogHelper.subInfo("Downloading client, it may take some time"); //HttpDownloader.downloadZip(server.mirrorManager.getDefaultMirror().getClientsURL(version.name), clientDir); - server.mirrorManager.downloadZip(clientDir,"clients/%s.zip", versionName); + server.mirrorManager.downloadZip(clientDir, "clients/%s.zip", versionName); // Create profile file LogHelper.subInfo("Creaing profile file: '%s'", dirName); @@ -55,8 +55,7 @@ public void invoke(String... args) throws IOException, CommandException { String profilePath = String.format("pro/gravit/launchserver/defaults/profile%s.cfg", versionName); try (BufferedReader reader = IOHelper.newReader(IOHelper.getResourceURL(profilePath))) { client = Launcher.gsonManager.configGson.fromJson(reader, ClientProfile.class); - } catch (IOException e) - { + } catch (IOException e) { JsonElement clientJson = server.mirrorManager.jsonRequest(null, "GET", "clients/%s.json", versionName); client = Launcher.gsonManager.configGson.fromJson(clientJson, ClientProfile.class); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/IndexAssetCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/IndexAssetCommand.java index 40545c66..ba56a0ae 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/IndexAssetCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/IndexAssetCommand.java @@ -1,5 +1,15 @@ package pro.gravit.launchserver.command.hash; +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launchserver.command.Command; +import pro.gravit.utils.command.CommandException; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.LogHelper; +import pro.gravit.utils.helper.SecurityHelper; +import pro.gravit.utils.helper.SecurityHelper.DigestAlgorithm; + import java.io.BufferedWriter; import java.io.IOException; import java.nio.file.FileVisitResult; @@ -9,17 +19,6 @@ import java.nio.file.attribute.BasicFileAttributes; import java.util.Collections; -import com.google.gson.Gson; -import com.google.gson.JsonObject; - -import pro.gravit.launchserver.LaunchServer; -import pro.gravit.launchserver.command.Command; -import pro.gravit.utils.command.CommandException; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.LogHelper; -import pro.gravit.utils.helper.SecurityHelper; -import pro.gravit.utils.helper.SecurityHelper.DigestAlgorithm; - public final class IndexAssetCommand extends Command { private static final Gson gson = new Gson(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SyncBinariesCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SyncBinariesCommand.java index 6966ad75..ec6b9cc0 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SyncBinariesCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SyncBinariesCommand.java @@ -1,11 +1,11 @@ package pro.gravit.launchserver.command.hash; -import java.io.IOException; - import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.command.Command; import pro.gravit.utils.helper.LogHelper; +import java.io.IOException; + public final class SyncBinariesCommand extends Command { public SyncBinariesCommand(LaunchServer server) { super(server); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SyncProfilesCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SyncProfilesCommand.java index dce5ace0..433fb4ff 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SyncProfilesCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SyncProfilesCommand.java @@ -1,11 +1,11 @@ package pro.gravit.launchserver.command.hash; -import java.io.IOException; - import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.command.Command; import pro.gravit.utils.helper.LogHelper; +import java.io.IOException; + public final class SyncProfilesCommand extends Command { public SyncProfilesCommand(LaunchServer server) { super(server); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SyncUpdatesCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SyncUpdatesCommand.java index eb5d6ee0..8363f848 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SyncUpdatesCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SyncUpdatesCommand.java @@ -1,14 +1,14 @@ package pro.gravit.launchserver.command.hash; +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launchserver.command.Command; +import pro.gravit.utils.helper.LogHelper; + import java.io.IOException; import java.util.Collections; import java.util.HashSet; import java.util.Set; -import pro.gravit.launchserver.LaunchServer; -import pro.gravit.launchserver.command.Command; -import pro.gravit.utils.helper.LogHelper; - public final class SyncUpdatesCommand extends Command { public SyncUpdatesCommand(LaunchServer server) { super(server); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/UnindexAssetCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/UnindexAssetCommand.java index 89ab3f2d..ffe36636 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/UnindexAssetCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/UnindexAssetCommand.java @@ -1,21 +1,20 @@ package pro.gravit.launchserver.command.hash; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launchserver.command.Command; +import pro.gravit.utils.command.CommandException; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.LogHelper; + import java.io.BufferedReader; import java.nio.file.Files; import java.nio.file.Path; import java.util.Collections; import java.util.Map; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; - -import pro.gravit.launchserver.LaunchServer; -import pro.gravit.launchserver.command.Command; -import pro.gravit.utils.command.CommandException; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.LogHelper; - public final class UnindexAssetCommand extends Command { private static final JsonParser parser = new JsonParser(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/modules/LoadModuleCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/modules/LoadModuleCommand.java index 78ce06ea..5a0815b5 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/modules/LoadModuleCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/modules/LoadModuleCommand.java @@ -1,11 +1,11 @@ package pro.gravit.launchserver.command.modules; -import java.nio.file.Path; -import java.nio.file.Paths; - import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.command.Command; +import java.nio.file.Path; +import java.nio.file.Paths; + public class LoadModuleCommand extends Command { public LoadModuleCommand(LaunchServer server) { super(server); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/ClientsCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/ClientsCommand.java index 49c0b5e7..b038aba5 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/ClientsCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/ClientsCommand.java @@ -30,13 +30,12 @@ public void invoke(String... args) { WebSocketFrameHandler frameHandler = channel.pipeline().get(WebSocketFrameHandler.class); Client client = frameHandler.getClient(); String ip = IOHelper.getIP(channel.remoteAddress()); - if(!client.isAuth) + if (!client.isAuth) LogHelper.info("Channel %s | checkSign %s", ip, client.checkSign ? "true" : "false"); - else - { + else { LogHelper.info("Client name %s | ip %s", client.username == null ? "null" : client.username, ip); LogHelper.subInfo("Data: checkSign %s | isSecure %s | auth_id %s", client.checkSign ? "true" : "false", client.isSecure ? "true" : "false", - client.auth_id); + client.auth_id); LogHelper.subInfo("Permissions: %s (long %d)", client.permissions == null ? "null" : client.permissions.toString(), client.permissions == null ? 0 : client.permissions.toLong()); } })); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/ComponentCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/ComponentCommand.java index 9393d6a8..0e5ec89c 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/ComponentCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/ComponentCommand.java @@ -1,8 +1,5 @@ package pro.gravit.launchserver.command.service; -import java.io.Reader; -import java.nio.file.Paths; - import pro.gravit.launcher.Launcher; import pro.gravit.launcher.NeedGarbageCollection; import pro.gravit.launchserver.LaunchServer; @@ -11,6 +8,9 @@ import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; +import java.io.Reader; +import java.nio.file.Paths; + public class ComponentCommand extends Command { public ComponentCommand(LaunchServer server) { super(server); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/components/AbstractLimiter.java b/LaunchServer/src/main/java/pro/gravit/launchserver/components/AbstractLimiter.java index 399f9927..f129e350 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/components/AbstractLimiter.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/components/AbstractLimiter.java @@ -1,16 +1,16 @@ package pro.gravit.launchserver.components; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - import pro.gravit.launcher.NeedGarbageCollection; import pro.gravit.launchserver.Reconfigurable; import pro.gravit.utils.command.Command; import pro.gravit.utils.command.SubCommand; import pro.gravit.utils.helper.LogHelper; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + public abstract class AbstractLimiter extends Component implements NeedGarbageCollection, Reconfigurable { public int rateLimit; public int rateLimitMillis; @@ -67,8 +67,7 @@ public void garbageCollection() { map.entrySet().removeIf((e) -> e.getValue().time + rateLimitMillis < time); } - static class LimitEntry - { + static class LimitEntry { long time; int trys; @@ -82,27 +81,23 @@ public LimitEntry() { trys = 0; } } + protected final transient Map map = new HashMap<>(); - public boolean check(T address) - { - if(exclude.contains(address)) return true; + + public boolean check(T address) { + if (exclude.contains(address)) return true; LimitEntry entry = map.get(address); - if(entry == null) - { + if (entry == null) { map.put(address, new LimitEntry()); return true; - } - else - { + } else { long time = System.currentTimeMillis(); - if(entry.trys < rateLimit) - { + if (entry.trys < rateLimit) { entry.trys++; entry.time = time; return true; } - if(entry.time + rateLimitMillis < time) - { + if (entry.time + rateLimitMillis < time) { entry.trys = 1; entry.time = time; return true; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/components/AuthLimiterComponent.java b/LaunchServer/src/main/java/pro/gravit/launchserver/components/AuthLimiterComponent.java index 23f78c1b..38aa8751 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/components/AuthLimiterComponent.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/components/AuthLimiterComponent.java @@ -7,10 +7,11 @@ import pro.gravit.utils.HookException; public class AuthLimiterComponent extends IPLimiter implements NeedGarbageCollection, AutoCloseable { - private transient LaunchServer srv; + private transient LaunchServer srv; + @Override public void preInit(LaunchServer launchServer) { - srv = launchServer; + srv = launchServer; } @Override @@ -29,10 +30,11 @@ public boolean preAuthHook(AuthResponse.AuthContext context, Client client) { } return false; } + public String message; - @Override - public void close() { + @Override + public void close() { srv.authHookManager.preHook.unregisterHook(this::preAuthHook); - } + } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/components/CommandRemoverComponent.java b/LaunchServer/src/main/java/pro/gravit/launchserver/components/CommandRemoverComponent.java index a2c31bb5..a42b7151 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/components/CommandRemoverComponent.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/components/CommandRemoverComponent.java @@ -1,11 +1,11 @@ package pro.gravit.launchserver.components; -import java.util.HashMap; -import java.util.Map; - import pro.gravit.launchserver.LaunchServer; import pro.gravit.utils.command.Command; +import java.util.HashMap; +import java.util.Map; + public class CommandRemoverComponent extends Component implements AutoCloseable { public final String[] removeList = new String[]{}; public final transient Map commandsList = new HashMap<>(); @@ -13,7 +13,7 @@ public class CommandRemoverComponent extends Component implements AutoCloseable @Override public void preInit(LaunchServer launchServer) { - server = launchServer; + server = launchServer; } @Override diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/components/RegLimiterComponent.java b/LaunchServer/src/main/java/pro/gravit/launchserver/components/RegLimiterComponent.java index 6840041a..426395b3 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/components/RegLimiterComponent.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/components/RegLimiterComponent.java @@ -1,13 +1,13 @@ package pro.gravit.launchserver.components; -import java.util.ArrayList; -import java.util.List; - import pro.gravit.launcher.NeedGarbageCollection; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.manangers.hook.AuthHookManager; import pro.gravit.utils.HookException; +import java.util.ArrayList; +import java.util.List; + public class RegLimiterComponent extends IPLimiter implements NeedGarbageCollection, AutoCloseable { public transient LaunchServer launchServer; @@ -30,8 +30,7 @@ public void postInit(LaunchServer launchServer) { launchServer.authHookManager.registraion.registerHook(this::registerHook); } - public boolean registerHook(AuthHookManager.RegContext context) - { + public boolean registerHook(AuthHookManager.RegContext context) { if (!check(context.ip)) { throw new HookException(message); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java index 85e1be7e..fcc9cec0 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java @@ -1,11 +1,5 @@ package pro.gravit.launchserver.config; -import java.io.File; -import java.io.IOException; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; - import io.netty.channel.epoll.Epoll; import io.netty.handler.logging.LogLevel; import pro.gravit.launcher.Launcher; @@ -30,6 +24,12 @@ import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.LogHelper; +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + public final class LaunchServerConfig { private transient LaunchServer server = null; @@ -139,19 +139,17 @@ public void init(LaunchServer.ReloadType type) { } permissionsHandler.init(server); hwidHandler.init(); - if(dao != null) + if (dao != null) dao.init(server); if (protectHandler != null) { protectHandler.checkLaunchServerLicense(); } - if(components != null) - { - components.forEach((k,v) -> server.registerObject("component.".concat(k), v)); + if (components != null) { + components.forEach((k, v) -> server.registerObject("component.".concat(k), v)); } server.registerObject("permissionsHandler", permissionsHandler); server.registerObject("hwidHandler", hwidHandler); - if(!type.equals(LaunchServer.ReloadType.NO_AUTH)) - { + if (!type.equals(LaunchServer.ReloadType.NO_AUTH)) { for (AuthProviderPair pair : auth) { server.registerObject("auth.".concat(pair.name).concat(".provider"), pair.provider); server.registerObject("auth.".concat(pair.name).concat(".handler"), pair.handler); @@ -167,20 +165,17 @@ public void close(LaunchServer.ReloadType type) { try { server.unregisterObject("permissionsHandler", permissionsHandler); server.unregisterObject("hwidHandler", hwidHandler); - if(!type.equals(LaunchServer.ReloadType.NO_AUTH)) - { + if (!type.equals(LaunchServer.ReloadType.NO_AUTH)) { for (AuthProviderPair pair : auth) { server.unregisterObject("auth.".concat(pair.name).concat(".provider"), pair.provider); server.unregisterObject("auth.".concat(pair.name).concat(".handler"), pair.handler); server.unregisterObject("auth.".concat(pair.name).concat(".texture"), pair.textureProvider); } } - if(type.equals(LaunchServer.ReloadType.FULL)) - { + if (type.equals(LaunchServer.ReloadType.FULL)) { components.forEach((k, component) -> { server.unregisterObject("component.".concat(k), component); - if(component instanceof AutoCloseable) - { + if (component instanceof AutoCloseable) { try { ((AutoCloseable) component).close(); } catch (Exception e) { @@ -226,8 +221,7 @@ public static class ExeConf { public String txtProductVersion; } - public static class CertificateConf - { + public static class CertificateConf { public boolean enabled; } @@ -235,6 +229,7 @@ public static class NettyUpdatesBind { public String url; public boolean zip; } + public static class LauncherConf { public String guardType; public boolean attachLibraryBeforeProGuard; @@ -276,8 +271,8 @@ public NettyBindAddress(String address, int port) { this.port = port; } } - public static LaunchServerConfig getDefault(LaunchServer.LaunchServerEnv env) - { + + public static LaunchServerConfig getDefault(LaunchServer.LaunchServerEnv env) { LaunchServerConfig newConfig = new LaunchServerConfig(); newConfig.mirrors = new String[]{"https://mirror.gravit.pro/"}; newConfig.launch4j = new LaunchServerConfig.ExeConf(); @@ -302,7 +297,7 @@ public static LaunchServerConfig getDefault(LaunchServer.LaunchServerEnv env) , "std")}; newConfig.auth[0].displayName = "Default"; newConfig.protectHandler = new StdProtectHandler(); - if(env.equals(LaunchServer.LaunchServerEnv.TEST)) + if (env.equals(LaunchServer.LaunchServerEnv.TEST)) newConfig.permissionsHandler = new DefaultPermissionsHandler(); else newConfig.permissionsHandler = new JsonFilePermissionsHandler(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerRuntimeConfig.java b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerRuntimeConfig.java index 7e1798f9..c688e10b 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerRuntimeConfig.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerRuntimeConfig.java @@ -11,7 +11,10 @@ public class LaunchServerRuntimeConfig { public void verify() { if (passwordEncryptKey == null) LogHelper.error("[RuntimeConfig] passwordEncryptKey must not be null"); - if (clientCheckSecret == null) { LogHelper.warning("[RuntimeConfig] clientCheckSecret must not be null"); clientCheckSecret = SecurityHelper.randomStringToken(); } + if (clientCheckSecret == null) { + LogHelper.warning("[RuntimeConfig] clientCheckSecret must not be null"); + clientCheckSecret = SecurityHelper.randomStringToken(); + } } public void reset() { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/User.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/User.java index ee09f5b5..28da0d4c 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/User.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/User.java @@ -1,22 +1,16 @@ package pro.gravit.launchserver.dao; +import pro.gravit.launcher.ClientPermissions; +import pro.gravit.utils.helper.LogHelper; +import pro.gravit.utils.helper.SecurityHelper; + +import javax.persistence.*; import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Arrays; import java.util.UUID; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; - -import pro.gravit.launcher.ClientPermissions; -import pro.gravit.utils.helper.LogHelper; -import pro.gravit.utils.helper.SecurityHelper; - @Entity @Table(name = "users") public class User { @@ -34,8 +28,8 @@ public class User { public String serverID; private String password_salt; public long permissions; - public void setPassword(String password) - { + + public void setPassword(String password) { password_salt = SecurityHelper.randomStringAESKey(); MessageDigest digest; try { @@ -46,8 +40,8 @@ public void setPassword(String password) } this.password = digest.digest(password.concat(password_salt).getBytes(StandardCharsets.UTF_8)); } - public boolean verifyPassword(String password) - { + + public boolean verifyPassword(String password) { MessageDigest digest; try { digest = MessageDigest.getInstance("SHA-256"); @@ -58,12 +52,12 @@ public boolean verifyPassword(String password) byte[] enpassword = digest.digest(password.concat(password_salt).getBytes(StandardCharsets.UTF_8)); return Arrays.equals(enpassword, this.password); } - public ClientPermissions getPermissions() - { + + public ClientPermissions getPermissions() { return new ClientPermissions(permissions); } - public void setPermissions(ClientPermissions permissions) - { + + public void setPermissions(ClientPermissions permissions) { this.permissions = permissions.toLong(); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserDAO.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserDAO.java index c70afdbc..7a666c8f 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserDAO.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserDAO.java @@ -1,17 +1,24 @@ package pro.gravit.launchserver.dao; +import pro.gravit.launcher.hwid.OshiHWID; + import java.util.List; import java.util.UUID; -import pro.gravit.launcher.hwid.OshiHWID; - public interface UserDAO { User findById(int id); + User findByUsername(String username); + User findByUUID(UUID uuid); + List findHWID(OshiHWID hwid); + void save(User user); + void update(User user); + void delete(User user); + List findAll(); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserHWID.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserHWID.java index 49561182..2c6fe8e3 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserHWID.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserHWID.java @@ -1,16 +1,11 @@ package pro.gravit.launchserver.dao; -import java.util.function.Supplier; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; - import pro.gravit.launcher.hwid.HWID; import pro.gravit.launcher.hwid.OshiHWID; +import javax.persistence.*; +import java.util.function.Supplier; + @Entity @Table(name = "users_hwids") public class UserHWID implements HWID { @@ -35,9 +30,9 @@ public class UserHWID implements HWID { public String macAddr; public boolean banned; - public OshiHWID toHWID() - { - if(oshi == null) oshi = oshiSupp.get(); + + public OshiHWID toHWID() { + if (oshi == null) oshi = oshiSupp.get(); return oshi; } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserService.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserService.java index 5dd205d3..cdc7fb23 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserService.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserService.java @@ -18,12 +18,12 @@ public User findUser(int id) { public User findUserByUsername(String username) { return usersDao.findByUsername(username); } + public User findUserByUUID(UUID uuid) { return usersDao.findByUUID(uuid); } - public User registerNewUser(String username, String password) - { + public User registerNewUser(String username, String password) { User user = new User(); user.username = username; user.setPassword(password); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/DefaultUserDAOImpl.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/DefaultUserDAOImpl.java index 49a24676..0c2509e0 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/DefaultUserDAOImpl.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/DefaultUserDAOImpl.java @@ -1,17 +1,19 @@ package pro.gravit.launchserver.dao.impl; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - import pro.gravit.launcher.hwid.OshiHWID; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.dao.User; import pro.gravit.launchserver.dao.UserDAO; import pro.gravit.launchserver.dao.UserHWID; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + public class DefaultUserDAOImpl implements UserDAO { - public DefaultUserDAOImpl(LaunchServer srv) { } + public DefaultUserDAOImpl(LaunchServer srv) { + } + @Override public User findById(int id) { return null; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/HibernateUserDAOImpl.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/HibernateUserDAOImpl.java index fc086c57..a31e106e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/HibernateUserDAOImpl.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/HibernateUserDAOImpl.java @@ -1,32 +1,30 @@ package pro.gravit.launchserver.dao.impl; -import java.util.List; -import java.util.UUID; - -import javax.persistence.EntityManager; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; - import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; - import pro.gravit.launcher.hwid.OshiHWID; import pro.gravit.launchserver.dao.User; import pro.gravit.launchserver.dao.UserDAO; import pro.gravit.launchserver.dao.UserHWID; -public class HibernateUserDAOImpl implements UserDAO { - private final SessionFactory factory; +import javax.persistence.EntityManager; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import java.util.List; +import java.util.UUID; - public HibernateUserDAOImpl(SessionFactory factory) { - this.factory = factory; - } +public class HibernateUserDAOImpl implements UserDAO { + private final SessionFactory factory; + + public HibernateUserDAOImpl(SessionFactory factory) { + this.factory = factory; + } public User findById(int id) { - try (Session s = factory.openSession()) { - return s.get(User.class, id); + try (Session s = factory.openSession()) { + return s.get(User.class, id); } } @@ -77,32 +75,32 @@ public List findHWID(OshiHWID hwid) { public void save(User user) { try (Session session = factory.openSession()) { - Transaction tx1 = session.beginTransaction(); - session.save(user); - tx1.commit(); - } + Transaction tx1 = session.beginTransaction(); + session.save(user); + tx1.commit(); + } } public void update(User user) { try (Session session = factory.openSession()) { - Transaction tx1 = session.beginTransaction(); - session.update(user); - tx1.commit(); - } + Transaction tx1 = session.beginTransaction(); + session.update(user); + tx1.commit(); + } } public void delete(User user) { try (Session session = factory.openSession()) { - Transaction tx1 = session.beginTransaction(); - session.delete(user); - tx1.commit(); + Transaction tx1 = session.beginTransaction(); + session.delete(user); + tx1.commit(); } } @SuppressWarnings("unchecked") - public List findAll() { - try (Session s = factory.openSession()) { - return (List) s.createQuery("From User").list(); - } + public List findAll() { + try (Session s = factory.openSession()) { + return (List) s.createQuery("From User").list(); + } } } \ No newline at end of file diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/provider/DaoProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/provider/DaoProvider.java index 5bd61018..f794f720 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/provider/DaoProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/provider/DaoProvider.java @@ -9,9 +9,10 @@ public abstract class DaoProvider { public static final ProviderMap providers = new ProviderMap<>("DaoProvider"); public UserDAO userDAO; public UserService userService; - public static void registerProviders() - { + + public static void registerProviders() { providers.register("hibernate", HibernateDaoProvider.class); } + public abstract void init(LaunchServer server); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/provider/HibernateDaoProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/provider/HibernateDaoProvider.java index c9483916..82d9197f 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/provider/HibernateDaoProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/provider/HibernateDaoProvider.java @@ -1,9 +1,6 @@ package pro.gravit.launchserver.dao.provider; -import java.nio.file.Paths; - import org.hibernate.cfg.Configuration; - import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.dao.User; import pro.gravit.launchserver.dao.UserHWID; @@ -11,6 +8,8 @@ import pro.gravit.launchserver.dao.impl.HibernateUserDAOImpl; import pro.gravit.utils.helper.CommonHelper; +import java.nio.file.Paths; + public class HibernateDaoProvider extends DaoProvider { public String driver; public String url; @@ -32,14 +31,14 @@ public void init(LaunchServer server) { .setProperty("hibernate.connection.username", username) .setProperty("hibernate.connection.password", password) .setProperty("hibernate.connection.pool_size", pool_size); - if(dialect != null) + if (dialect != null) cfg.setProperty("hibernate.dialect", dialect); - if(hibernateConfig != null) + if (hibernateConfig != null) cfg.configure(Paths.get(hibernateConfig).toFile()); userDAO = new HibernateUserDAOImpl(cfg.buildSessionFactory()); userService = new UserService(userDAO); }; - if(parallelHibernateInit) + if (parallelHibernateInit) CommonHelper.newThread("Hibernate Thread", true, init); else init.run(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/CertificateManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/CertificateManager.java index 1987163a..f14c4069 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/CertificateManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/CertificateManager.java @@ -1,6 +1,31 @@ package pro.gravit.launchserver.manangers; +import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; +import org.bouncycastle.asn1.x500.X500Name; +import org.bouncycastle.asn1.x500.X500NameBuilder; +import org.bouncycastle.asn1.x500.style.BCStyle; +import org.bouncycastle.asn1.x509.AlgorithmIdentifier; +import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; +import org.bouncycastle.cert.X509CertificateHolder; +import org.bouncycastle.cert.X509v3CertificateBuilder; +import org.bouncycastle.crypto.params.AsymmetricKeyParameter; +import org.bouncycastle.crypto.util.PrivateKeyFactory; +import org.bouncycastle.crypto.util.PrivateKeyInfoFactory; +import org.bouncycastle.operator.ContentSigner; +import org.bouncycastle.operator.DefaultDigestAlgorithmIdentifierFinder; +import org.bouncycastle.operator.OperatorCreationException; +import org.bouncycastle.operator.bc.BcECContentSignerBuilder; +import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder; +import org.bouncycastle.util.io.pem.PemObject; +import org.bouncycastle.util.io.pem.PemReader; +import org.bouncycastle.util.io.pem.PemWriter; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.JVMHelper; +import pro.gravit.utils.helper.LogHelper; +import pro.gravit.utils.helper.SecurityHelper; +import pro.gravit.utils.verify.LauncherTrustManager; + import java.io.*; import java.math.BigInteger; import java.nio.file.FileVisitResult; @@ -22,32 +47,6 @@ import java.util.Date; import java.util.List; -import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; -import org.bouncycastle.asn1.x500.X500Name; -import org.bouncycastle.asn1.x500.X500NameBuilder; -import org.bouncycastle.asn1.x500.style.BCStyle; -import org.bouncycastle.asn1.x509.AlgorithmIdentifier; -import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; -import org.bouncycastle.cert.X509CertificateHolder; -import org.bouncycastle.cert.X509v3CertificateBuilder; -import org.bouncycastle.crypto.params.AsymmetricKeyParameter; -import org.bouncycastle.crypto.util.PrivateKeyFactory; -import org.bouncycastle.crypto.util.PrivateKeyInfoFactory; -import org.bouncycastle.operator.ContentSigner; -import org.bouncycastle.operator.DefaultDigestAlgorithmIdentifierFinder; -import org.bouncycastle.operator.OperatorCreationException; -import org.bouncycastle.operator.bc.BcECContentSignerBuilder; -import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder; -import org.bouncycastle.util.io.pem.PemObject; -import org.bouncycastle.util.io.pem.PemReader; -import org.bouncycastle.util.io.pem.PemWriter; - -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.JVMHelper; -import pro.gravit.utils.helper.LogHelper; -import pro.gravit.utils.helper.SecurityHelper; -import pro.gravit.utils.verify.LauncherTrustManager; - public class CertificateManager { public X509CertificateHolder ca; public AsymmetricKeyParameter caKey; @@ -82,7 +81,7 @@ public X509CertificateHolder generateCertificate(String subjectName, PublicKey s } public void generateCA() throws NoSuchAlgorithmException, IOException, OperatorCreationException, InvalidAlgorithmParameterException { - ECGenParameterSpec ecGenSpec = new ECGenParameterSpec("secp384r1"); + ECGenParameterSpec ecGenSpec = new ECGenParameterSpec("secp384r1"); KeyPairGenerator generator = KeyPairGenerator.getInstance("EC"); generator.initialize(ecGenSpec, SecurityHelper.newRandom()); KeyPair pair = generator.generateKeyPair(); @@ -92,21 +91,21 @@ public void generateCA() throws NoSuchAlgorithmException, IOException, OperatorC subject.addRDN(BCStyle.CN, orgName.concat(" CA")); subject.addRDN(BCStyle.O, orgName); - X509v3CertificateBuilder builder= new X509v3CertificateBuilder( + X509v3CertificateBuilder builder = new X509v3CertificateBuilder( subject.build(), new BigInteger("0"), Date.from(startDate.atZone(ZoneId.systemDefault()).toInstant()), Date.from(startDate.plusDays(3650).atZone(ZoneId.systemDefault()).toInstant()), new X500Name("CN=ca"), SubjectPublicKeyInfo.getInstance(pair.getPublic().getEncoded())); - JcaContentSignerBuilder csBuilder= new JcaContentSignerBuilder("SHA256WITHECDSA"); + JcaContentSignerBuilder csBuilder = new JcaContentSignerBuilder("SHA256WITHECDSA"); ContentSigner signer = csBuilder.build(pair.getPrivate()); ca = builder.build(signer); caKey = PrivateKeyFactory.createKey(pair.getPrivate().getEncoded()); } public KeyPair generateKeyPair() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException { - ECGenParameterSpec ecGenSpec = new ECGenParameterSpec("secp384r1"); + ECGenParameterSpec ecGenSpec = new ECGenParameterSpec("secp384r1"); KeyPairGenerator generator = KeyPairGenerator.getInstance("EC"); generator.initialize(ecGenSpec, SecurityHelper.newRandom()); return generator.generateKeyPair(); @@ -149,11 +148,9 @@ public AsymmetricKeyParameter readPrivateKey(Path file) throws IOException { public AsymmetricKeyParameter readPrivateKey(Reader reader) throws IOException { AsymmetricKeyParameter ret; - try(PemReader reader1 = new PemReader(reader)) - { + try (PemReader reader1 = new PemReader(reader)) { byte[] bytes = reader1.readPemObject().getContent(); - try(ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes)) - { + try (ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes)) { ret = PrivateKeyFactory.createKey(inputStream); } @@ -167,8 +164,7 @@ public X509CertificateHolder readCertificate(Path file) throws IOException { public X509CertificateHolder readCertificate(Reader reader) throws IOException { X509CertificateHolder ret; - try(PemReader reader1 = new PemReader(reader)) - { + try (PemReader reader1 = new PemReader(reader)) { byte[] bytes = reader1.readPemObject().getContent(); ret = new X509CertificateHolder(bytes); } @@ -176,12 +172,10 @@ public X509CertificateHolder readCertificate(Reader reader) throws IOException { } public void readTrustStore(Path dir) throws IOException, CertificateException { - if(!IOHelper.isDir(dir)) - { + if (!IOHelper.isDir(dir)) { Files.createDirectories(dir); - try(OutputStream outputStream = IOHelper.newOutput(dir.resolve("GravitCentralRootCA.crt")); - InputStream inputStream = IOHelper.newInput(IOHelper.getResourceURL("pro/gravit/launchserver/defaults/GravitCentralRootCA.crt"))) - { + try (OutputStream outputStream = IOHelper.newOutput(dir.resolve("GravitCentralRootCA.crt")); + InputStream inputStream = IOHelper.newInput(IOHelper.getResourceURL("pro/gravit/launchserver/defaults/GravitCentralRootCA.crt"))) { IOHelper.transfer(inputStream, outputStream); } } @@ -190,10 +184,8 @@ public void readTrustStore(Path dir) throws IOException, CertificateException { IOHelper.walk(dir, new SimpleFileVisitor() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { - if(file.toFile().getName().endsWith(".crt")) - { - try(InputStream inputStream = IOHelper.newInput(file)) - { + if (file.toFile().getName().endsWith(".crt")) { + try (InputStream inputStream = IOHelper.newInput(file)) { certificates.add((X509Certificate) certFactory.generateCertificate(inputStream)); } catch (CertificateException e) { throw new IOException(e); @@ -205,20 +197,18 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO trustManager = new LauncherTrustManager(certificates.toArray(new X509Certificate[0])); } - public void checkClass(Class clazz, LauncherTrustManager.CheckMode mode) throws SecurityException - { - if(trustManager == null) return; + public void checkClass(Class clazz, LauncherTrustManager.CheckMode mode) throws SecurityException { + if (trustManager == null) return; X509Certificate[] certificates = JVMHelper.getCertificates(clazz); - if(certificates == null) - { - if(mode == LauncherTrustManager.CheckMode.EXCEPTION_IN_NOT_SIGNED) + if (certificates == null) { + if (mode == LauncherTrustManager.CheckMode.EXCEPTION_IN_NOT_SIGNED) throw new SecurityException(String.format("Class %s not signed", clazz.getName())); - else if(mode == LauncherTrustManager.CheckMode.WARN_IN_NOT_SIGNED) + else if (mode == LauncherTrustManager.CheckMode.WARN_IN_NOT_SIGNED) LogHelper.warning("Class %s not signed", clazz.getName()); return; } try { - trustManager.checkCertificate(certificates, (c,s) -> { + trustManager.checkCertificate(certificates, (c, s) -> { }); } catch (CertificateException | NoSuchProviderException | NoSuchAlgorithmException | InvalidKeyException | SignatureException e) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java index 0a8a7aa6..bf39128f 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java @@ -1,7 +1,6 @@ package pro.gravit.launchserver.manangers; import com.google.gson.GsonBuilder; - import pro.gravit.launcher.hwid.HWID; import pro.gravit.launcher.hwid.HWIDProvider; import pro.gravit.launcher.managers.GsonManager; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/MirrorManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/MirrorManager.java index d52684e2..45a7a92c 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/MirrorManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/MirrorManager.java @@ -1,5 +1,11 @@ package pro.gravit.launchserver.manangers; +import com.google.gson.JsonElement; +import pro.gravit.utils.HTTPRequest; +import pro.gravit.utils.HttpDownloader; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.LogHelper; + import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; @@ -7,12 +13,6 @@ import java.util.ArrayList; import java.util.Arrays; -import com.google.gson.JsonElement; -import pro.gravit.utils.HTTPRequest; -import pro.gravit.utils.HttpDownloader; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.LogHelper; - public class MirrorManager { public static class Mirror { final String baseUrl; @@ -71,58 +71,49 @@ public int size() { return list.size(); } - public boolean downloadZip(Mirror mirror, Path path, String mask, Object... args) throws IOException - { - if(!mirror.enabled) return false; + public boolean downloadZip(Mirror mirror, Path path, String mask, Object... args) throws IOException { + if (!mirror.enabled) return false; URL url = mirror.getURL(mask, args); LogHelper.debug("Try download %s", url.toString()); try { HttpDownloader.downloadZip(url, path); - } catch (IOException e) - { + } catch (IOException e) { LogHelper.error("Download %s failed(%s: %s)", url.toString(), e.getClass().getName(), e.getMessage()); return false; } return true; } - public void downloadZip(Path path, String mask, Object... args) throws IOException - { - if(downloadZip(defaultMirror, path, mask, args)) - { + public void downloadZip(Path path, String mask, Object... args) throws IOException { + if (downloadZip(defaultMirror, path, mask, args)) { return; } - for(Mirror mirror : list) - { - if(mirror != defaultMirror) - { - if(downloadZip(mirror, path, mask, args)) return; + for (Mirror mirror : list) { + if (mirror != defaultMirror) { + if (downloadZip(mirror, path, mask, args)) return; } } throw new IOException(String.format("Error download %s. All mirrors return error", path.toString())); } - public JsonElement jsonRequest(Mirror mirror, JsonElement request, String method, String mask, Object... args) throws IOException - { - if(!mirror.enabled) return null; + + public JsonElement jsonRequest(Mirror mirror, JsonElement request, String method, String mask, Object... args) throws IOException { + if (!mirror.enabled) return null; URL url = mirror.getURL(mask, args); try { return HTTPRequest.jsonRequest(request, method, url); - } catch (IOException e) - { + } catch (IOException e) { LogHelper.error("JsonRequest %s failed(%s: %s)", url.toString(), e.getClass().getName(), e.getMessage()); return null; } } - public JsonElement jsonRequest(JsonElement request, String method, String mask, Object... args) throws IOException - { + + public JsonElement jsonRequest(JsonElement request, String method, String mask, Object... args) throws IOException { JsonElement result = jsonRequest(defaultMirror, request, method, mask, args); - if(result != null) return result; - for(Mirror mirror : list) - { - if(mirror != defaultMirror) - { + if (result != null) return result; + for (Mirror mirror : list) { + if (mirror != defaultMirror) { result = jsonRequest(mirror, request, method, mask, args); - if(result != null) return result; + if (result != null) return result; } } throw new IOException("Error jsonRequest. All mirrors return error"); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/ReconfigurableManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/ReconfigurableManager.java index f0cbd9fd..347923a4 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/ReconfigurableManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/ReconfigurableManager.java @@ -1,14 +1,14 @@ package pro.gravit.launchserver.manangers; -import java.util.HashMap; -import java.util.Map; - import pro.gravit.launchserver.Reconfigurable; import pro.gravit.utils.command.Command; import pro.gravit.utils.command.CommandException; import pro.gravit.utils.command.basic.HelpCommand; import pro.gravit.utils.helper.VerifyHelper; +import java.util.HashMap; +import java.util.Map; + public class ReconfigurableManager { private static class ReconfigurableVirtualCommand extends Command { public ReconfigurableVirtualCommand(Map childs) { @@ -30,6 +30,7 @@ public void invoke(String... args) throws Exception { invokeSubcommands(args); } } + private final HashMap RECONFIGURABLE = new HashMap<>(); public void registerReconfigurable(String name, Reconfigurable reconfigurable) { @@ -41,23 +42,21 @@ public void unregisterReconfigurable(String name) { RECONFIGURABLE.remove(name.toLowerCase()); } - public void call(String name, String action, String[] args) throws Exception - { + public void call(String name, String action, String[] args) throws Exception { Command commands = RECONFIGURABLE.get(name); - if(commands == null) throw new CommandException(String.format("Reconfigurable %s not found", name)); + if (commands == null) throw new CommandException(String.format("Reconfigurable %s not found", name)); Command command = commands.childCommands.get(action); - if(command == null) throw new CommandException(String.format("Action %s.%s not found", name, action)); + if (command == null) throw new CommandException(String.format("Action %s.%s not found", name, action)); command.invoke(args); } - public void printHelp(String name) throws CommandException - { + public void printHelp(String name) throws CommandException { Command commands = RECONFIGURABLE.get(name); - if(commands == null) throw new CommandException(String.format("Reconfigurable %s not found", name)); + if (commands == null) throw new CommandException(String.format("Reconfigurable %s not found", name)); HelpCommand.printSubCommandsHelp(name, commands); } - public Map getCommands() - { + + public Map getCommands() { return RECONFIGURABLE; } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/SessionManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/SessionManager.java index f8d8b395..f4ba8a76 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/SessionManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/SessionManager.java @@ -1,5 +1,8 @@ package pro.gravit.launchserver.manangers; +import pro.gravit.launcher.NeedGarbageCollection; +import pro.gravit.launchserver.socket.Client; + import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -7,9 +10,6 @@ import java.util.function.Function; import java.util.stream.Collectors; -import pro.gravit.launcher.NeedGarbageCollection; -import pro.gravit.launchserver.socket.Client; - public class SessionManager implements NeedGarbageCollection { public static final long SESSION_TIMEOUT = 3 * 60 * 60 * 1000; // 3 часа diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/hook/AuthHookManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/hook/AuthHookManager.java index 65a09dab..8dca9977 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/hook/AuthHookManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/hook/AuthHookManager.java @@ -14,12 +14,13 @@ public class AuthHookManager { public final BiHookSet checkServerHook = new BiHookSet<>(); public final BiHookSet joinServerHook = new BiHookSet<>(); public final BiHookSet setProfileHook = new BiHookSet<>(); - public static class RegContext - { + + public static class RegContext { public final String login; public final String password; public final String ip; public final boolean trustContext; + public RegContext(String login, String password, String ip, boolean trustContext) { this.login = login; this.password = password; @@ -27,5 +28,6 @@ public RegContext(String login, String password, String ip, boolean trustContext this.trustContext = trustContext; } } + public final HookSet registraion = new HookSet<>(); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/hook/BuildHookManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/hook/BuildHookManager.java index 22306726..381b8ee9 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/hook/BuildHookManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/hook/BuildHookManager.java @@ -1,15 +1,15 @@ package pro.gravit.launchserver.manangers.hook; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - import pro.gravit.launcher.AutogenConfig; import pro.gravit.launchserver.binary.BuildContext; import pro.gravit.launchserver.binary.LauncherConfigurator; import pro.gravit.launchserver.binary.tasks.MainBuildTask; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + public class BuildHookManager { @FunctionalInterface diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerCoreModule.java b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerCoreModule.java index 88557e35..9c35208a 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerCoreModule.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerCoreModule.java @@ -16,8 +16,7 @@ public void init(LauncherInitContext initContext) { registerEvent(this::testEvent, InitPhase.class); } - public void testEvent(InitPhase event) - { + public void testEvent(InitPhase event) { //LogHelper.debug("[LaunchServerCore] Event LaunchServerInitPhase passed"); } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerModulesManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerModulesManager.java index c63e3b92..29508783 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerModulesManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerModulesManager.java @@ -1,8 +1,5 @@ package pro.gravit.launchserver.modules.impl; -import java.nio.file.Path; -import java.util.Arrays; - import pro.gravit.launcher.modules.LauncherModule; import pro.gravit.launcher.modules.LauncherModuleInfo; import pro.gravit.launcher.modules.impl.SimpleModuleManager; @@ -10,21 +7,24 @@ import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.verify.LauncherTrustManager; +import java.nio.file.Path; +import java.util.Arrays; + public class LaunchServerModulesManager extends SimpleModuleManager { public final LaunchServerCoreModule coreModule; + public LaunchServerModulesManager(Path modulesDir, Path configDir, LauncherTrustManager trustManager) { super(modulesDir, configDir, trustManager); coreModule = new LaunchServerCoreModule(); modules.add(coreModule); } - public void fullInitializedLaunchServer(LaunchServer server) - { + + public void fullInitializedLaunchServer(LaunchServer server) { initContext = new LaunchServerInitContext(server); } - public void printModulesInfo() - { - for(LauncherModule module : modules) - { + + public void printModulesInfo() { + for (LauncherModule module : modules) { LauncherModuleInfo info = module.getModuleInfo(); LogHelper.info("[MODULE] %s v: %s p: %d deps: %s", info.name, info.version.getVersionString(), info.priority, Arrays.toString(info.dependencies)); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/LauncherNettyServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/LauncherNettyServer.java index 2e9163af..a170fd41 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/LauncherNettyServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/LauncherNettyServer.java @@ -1,7 +1,5 @@ package pro.gravit.launchserver.socket; -import java.net.InetSocketAddress; - import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelInitializer; @@ -24,23 +22,23 @@ import pro.gravit.utils.BiHookSet; import pro.gravit.utils.helper.LogHelper; +import java.net.InetSocketAddress; + public class LauncherNettyServer implements AutoCloseable { public final ServerBootstrap serverBootstrap; public final EventLoopGroup bossGroup; public final EventLoopGroup workerGroup; public final WebSocketService service; - public final BiHookSet pipelineHook = new BiHookSet<>(); + public final BiHookSet pipelineHook = new BiHookSet<>(); private static final String WEBSOCKET_PATH = "/api"; public LauncherNettyServer(LaunchServer server) { LaunchServerConfig.NettyConfig config = server.config.netty; NettyObjectFactory.setUsingEpoll(config.performance.usingEpoll); - if(config.performance.usingEpoll) - { + if (config.performance.usingEpoll) { LogHelper.debug("Netty: Epoll enabled"); } - if(config.performance.usingEpoll && !Epoll.isAvailable()) - { + if (config.performance.usingEpoll && !Epoll.isAvailable()) { LogHelper.error("Epoll is not available: (netty,perfomance.usingEpoll configured wrongly)", Epoll.unavailabilityCause()); } bossGroup = NettyObjectFactory.newEventLoopGroup(config.performance.bossThread); @@ -57,7 +55,7 @@ public void initChannel(SocketChannel ch) { NettyConnectContext context = new NettyConnectContext(); //p.addLast(new LoggingHandler(LogLevel.INFO)); pipeline.addLast("http-codec", new HttpServerCodec()); - pipeline.addLast("http-codec-compressor",new HttpObjectAggregator(65536)); + pipeline.addLast("http-codec-compressor", new HttpObjectAggregator(65536)); if (server.config.netty.ipForwarding) pipeline.addLast("forward-http", new NettyIpForwardHandler(context)); pipeline.addLast("websock-comp", new WebSocketServerCompressionHandler()); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/NettyObjectFactory.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/NettyObjectFactory.java index 119b72c5..1e814b65 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/NettyObjectFactory.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/NettyObjectFactory.java @@ -10,20 +10,20 @@ public class NettyObjectFactory { private static boolean epoll = false; - public static void setUsingEpoll(boolean value) - { + + public static void setUsingEpoll(boolean value) { epoll = value; } - public static EventLoopGroup newEventLoopGroup(int threads) - { - if(epoll) + + public static EventLoopGroup newEventLoopGroup(int threads) { + if (epoll) return new EpollEventLoopGroup(threads); else return new NioEventLoopGroup(threads); } - public static ChannelFactory getServerSocketChannelFactory() - { - if(epoll) + + public static ChannelFactory getServerSocketChannelFactory() { + if (epoll) return EpollServerSocketChannel::new; else return NioServerSocketChannel::new; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java index 0c4fc268..42f820b2 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java @@ -1,9 +1,6 @@ package pro.gravit.launchserver.socket; -import java.lang.reflect.Type; - import com.google.gson.Gson; - import io.netty.channel.Channel; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandlerContext; @@ -34,11 +31,13 @@ import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; +import java.lang.reflect.Type; + public class WebSocketService { public final ChannelGroup channels; public static final ProviderMap providers = new ProviderMap<>(); - public static class WebSocketRequestContext - { + + public static class WebSocketRequestContext { public final WebSocketServerResponse response; public final Client client; public final String ip; @@ -49,6 +48,7 @@ public WebSocketRequestContext(WebSocketServerResponse response, Client client, this.ip = ip; } } + public final BiHookSet hook = new BiHookSet<>(); public WebSocketService(ChannelGroup channels, LaunchServer server) { @@ -71,8 +71,7 @@ public void process(ChannelHandlerContext ctx, TextWebSocketFrame frame, Client void process(ChannelHandlerContext ctx, WebSocketServerResponse response, Client client, String ip) { WebSocketRequestContext context = new WebSocketRequestContext(response, client, ip); - if(hook.hook(context, ctx)) - { + if (hook.hook(context, ctx)) { return; } if (response instanceof SimpleResponse) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/NettyIpForwardHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/NettyIpForwardHandler.java index e1991e64..6eb75bfe 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/NettyIpForwardHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/NettyIpForwardHandler.java @@ -1,7 +1,5 @@ package pro.gravit.launchserver.socket.handlers; -import java.util.List; - import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToMessageDecoder; import io.netty.handler.codec.http.HttpHeaders; @@ -10,6 +8,8 @@ import pro.gravit.launchserver.socket.NettyConnectContext; import pro.gravit.utils.helper.LogHelper; +import java.util.List; + public class NettyIpForwardHandler extends MessageToMessageDecoder { private final NettyConnectContext context; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/NettyServerSocketHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/NettyServerSocketHandler.java index 329b3ca1..bb3c944d 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/NettyServerSocketHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/NettyServerSocketHandler.java @@ -1,14 +1,15 @@ package pro.gravit.launchserver.socket.handlers; -import java.net.InetSocketAddress; -import java.net.Socket; -import java.util.Set; -import javax.net.ssl.SSLServerSocketFactory; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.config.LaunchServerConfig; import pro.gravit.launchserver.socket.LauncherNettyServer; import pro.gravit.utils.helper.LogHelper; +import javax.net.ssl.SSLServerSocketFactory; +import java.net.InetSocketAddress; +import java.net.Socket; +import java.util.Set; + @SuppressWarnings("unused") public final class NettyServerSocketHandler implements Runnable, AutoCloseable { private SSLServerSocketFactory ssf; @@ -20,7 +21,7 @@ public final class NettyServerSocketHandler implements Runnable, AutoCloseable { // API private Set sockets; - private transient final LaunchServer server; + private transient final LaunchServer server; public NettyServerSocketHandler(LaunchServer server) { this.server = server; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/WebSocketFrameHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/WebSocketFrameHandler.java index db0c9836..cb884138 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/WebSocketFrameHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/WebSocketFrameHandler.java @@ -1,15 +1,9 @@ package pro.gravit.launchserver.socket.handlers; -import java.util.concurrent.TimeUnit; - import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; -import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame; -import io.netty.handler.codec.http.websocketx.PingWebSocketFrame; -import io.netty.handler.codec.http.websocketx.PongWebSocketFrame; -import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; -import io.netty.handler.codec.http.websocketx.WebSocketFrame; +import io.netty.handler.codec.http.websocketx.*; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.NettyConnectContext; @@ -17,6 +11,8 @@ import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; +import java.util.concurrent.TimeUnit; + public class WebSocketFrameHandler extends SimpleChannelInboundHandler { public final LaunchServer srv; public final WebSocketService service; @@ -37,7 +33,9 @@ public void setClient(Client client) { this.client = client; } - public Client getClient() { return client; } + public Client getClient() { + return client; + } @Override public void channelActive(ChannelHandlerContext ctx) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/fileserver/ClosingChannelFutureListener.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/fileserver/ClosingChannelFutureListener.java index 987c6a2a..0ed55db0 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/fileserver/ClosingChannelFutureListener.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/fileserver/ClosingChannelFutureListener.java @@ -1,11 +1,11 @@ package pro.gravit.launchserver.socket.handlers.fileserver; -import java.io.Closeable; - import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; import pro.gravit.utils.helper.IOHelper; +import java.io.Closeable; + public class ClosingChannelFutureListener implements ChannelFutureListener { public final Closeable[] close; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/fileserver/FileServerHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/fileserver/FileServerHandler.java index fd2f0695..9b8c6eac 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/fileserver/FileServerHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/fileserver/FileServerHandler.java @@ -1,16 +1,13 @@ package pro.gravit.launchserver.socket.handlers.fileserver; -import static io.netty.handler.codec.http.HttpMethod.GET; -import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST; -import static io.netty.handler.codec.http.HttpResponseStatus.FORBIDDEN; -import static io.netty.handler.codec.http.HttpResponseStatus.FOUND; -import static io.netty.handler.codec.http.HttpResponseStatus.INTERNAL_SERVER_ERROR; -import static io.netty.handler.codec.http.HttpResponseStatus.METHOD_NOT_ALLOWED; -import static io.netty.handler.codec.http.HttpResponseStatus.NOT_FOUND; -import static io.netty.handler.codec.http.HttpResponseStatus.NOT_MODIFIED; -import static io.netty.handler.codec.http.HttpResponseStatus.OK; -import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.channel.*; +import io.netty.handler.codec.http.*; +import io.netty.handler.stream.ChunkedFile; +import io.netty.util.CharsetUtil; +import javax.activation.MimetypesFileTypeMap; import java.io.File; import java.io.FileNotFoundException; import java.io.RandomAccessFile; @@ -19,35 +16,12 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.Locale; -import java.util.TimeZone; +import java.util.*; import java.util.regex.Pattern; -import javax.activation.MimetypesFileTypeMap; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelFutureListener; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.DefaultFileRegion; -import io.netty.channel.SimpleChannelInboundHandler; -import io.netty.handler.codec.http.DefaultFullHttpResponse; -import io.netty.handler.codec.http.DefaultHttpResponse; -import io.netty.handler.codec.http.FullHttpRequest; -import io.netty.handler.codec.http.FullHttpResponse; -import io.netty.handler.codec.http.HttpChunkedInput; -import io.netty.handler.codec.http.HttpHeaderNames; -import io.netty.handler.codec.http.HttpHeaderValues; -import io.netty.handler.codec.http.HttpResponse; -import io.netty.handler.codec.http.HttpResponseStatus; -import io.netty.handler.codec.http.HttpUtil; -import io.netty.handler.codec.http.LastHttpContent; -import io.netty.handler.stream.ChunkedFile; -import io.netty.util.CharsetUtil; +import static io.netty.handler.codec.http.HttpMethod.GET; +import static io.netty.handler.codec.http.HttpResponseStatus.*; +import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1; public class FileServerHandler extends SimpleChannelInboundHandler { @@ -55,7 +29,7 @@ public class FileServerHandler extends SimpleChannelInboundHandler..\r\n"); for (File f : dir.listFiles()) { - if (( f.isHidden() && !showHidden) || !f.canRead()) { + if ((f.isHidden() && !showHidden) || !f.canRead()) { continue; } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/SimpleResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/SimpleResponse.java index 34998f7a..50b7b8ce 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/SimpleResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/SimpleResponse.java @@ -1,13 +1,13 @@ package pro.gravit.launchserver.socket.response; -import java.util.UUID; - import io.netty.channel.ChannelHandlerContext; import pro.gravit.launcher.events.RequestEvent; import pro.gravit.launcher.events.request.ErrorRequestEvent; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.socket.WebSocketService; +import java.util.UUID; + public abstract class SimpleResponse implements WebSocketServerResponse { public UUID requestUUID; public transient LaunchServer server; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java index 896a6806..18c8bb2b 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java @@ -1,20 +1,12 @@ package pro.gravit.launchserver.socket.response.auth; -import java.security.SecureRandom; -import java.util.Collection; -import java.util.Random; -import java.util.UUID; - -import javax.crypto.BadPaddingException; -import javax.crypto.IllegalBlockSizeException; - import io.netty.channel.ChannelHandlerContext; import pro.gravit.launcher.events.request.AuthRequestEvent; import pro.gravit.launcher.hwid.HWID; import pro.gravit.launcher.profiles.ClientProfile; import pro.gravit.launcher.request.auth.AuthRequest; -import pro.gravit.launcher.request.auth.password.AuthPlainPassword; import pro.gravit.launcher.request.auth.password.AuthECPassword; +import pro.gravit.launcher.request.auth.password.AuthPlainPassword; import pro.gravit.launchserver.auth.AuthException; import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.auth.hwid.HWIDException; @@ -29,6 +21,13 @@ import pro.gravit.utils.helper.SecurityHelper; import pro.gravit.utils.helper.VerifyHelper; +import javax.crypto.BadPaddingException; +import javax.crypto.IllegalBlockSizeException; +import java.security.SecureRandom; +import java.util.Collection; +import java.util.Random; +import java.util.UUID; + public class AuthResponse extends SimpleResponse { public final transient static Random random = new SecureRandom(); public String login; @@ -59,11 +58,10 @@ public void execute(ChannelHandlerContext ctx, Client clientData) throws Excepti AuthProvider.authError("Don't skip Launcher Update"); return; } - if(password instanceof AuthECPassword) - { + if (password instanceof AuthECPassword) { try { - password = new AuthPlainPassword(IOHelper.decode(SecurityHelper.decrypt(server.runtime.passwordEncryptKey - , ((AuthECPassword) password).password))); + password = new AuthPlainPassword(IOHelper.decode(SecurityHelper.decrypt(server.runtime.passwordEncryptKey + , ((AuthECPassword) password).password))); } catch (IllegalBlockSizeException | BadPaddingException ignored) { throw new AuthException("Password decryption error"); } @@ -99,7 +97,7 @@ public void execute(ChannelHandlerContext ctx, Client clientData) throws Excepti clientData.permissions = aresult.permissions; clientData.auth_id = auth_id; clientData.updateAuth(server); - if(result.playerProfile != null) + if (result.playerProfile != null) clientData.username = result.playerProfile.username; else clientData.username = login; @@ -139,6 +137,7 @@ public AuthContext(Client client, String login, String customText, String profil this.ip = ip; this.authType = authType; } + public final String login; @Deprecated public int password_length; //Use AuthProvider for get password diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/GetAvailabilityAuthResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/GetAvailabilityAuthResponse.java index ffa5a032..9ed8d242 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/GetAvailabilityAuthResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/GetAvailabilityAuthResponse.java @@ -1,14 +1,14 @@ package pro.gravit.launchserver.socket.response.auth; -import java.util.ArrayList; -import java.util.List; - import io.netty.channel.ChannelHandlerContext; import pro.gravit.launcher.events.request.GetAvailabilityAuthRequestEvent; import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.SimpleResponse; +import java.util.ArrayList; +import java.util.List; + public class GetAvailabilityAuthResponse extends SimpleResponse { @Override public String getType() { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/RegisterResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/RegisterResponse.java index 1db67efd..2a008f48 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/RegisterResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/RegisterResponse.java @@ -1,33 +1,31 @@ package pro.gravit.launchserver.socket.response.auth; +import io.netty.channel.ChannelHandlerContext; +import pro.gravit.launchserver.dao.User; +import pro.gravit.launchserver.socket.Client; +import pro.gravit.launchserver.socket.response.SimpleResponse; + import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Arrays; import java.util.UUID; -import io.netty.channel.ChannelHandlerContext; -import pro.gravit.launchserver.dao.User; -import pro.gravit.launchserver.socket.Client; -import pro.gravit.launchserver.socket.response.SimpleResponse; - public class RegisterResponse extends SimpleResponse { public String login; public String password; public String email; public byte[] verifyHash; + @Override - public void execute(ChannelHandlerContext ctx, Client client) throws Exception - { + public void execute(ChannelHandlerContext ctx, Client client) throws Exception { byte[] normalHash = registerHash(login, server.runtime.registerApiKey); - if(!( client.isAuth && client.permissions.canAdmin ) && !Arrays.equals(normalHash, verifyHash)) - { + if (!(client.isAuth && client.permissions.canAdmin) && !Arrays.equals(normalHash, verifyHash)) { sendError("Hash invalid"); return; } User checkUser = server.config.dao.userService.findUserByUsername(login); - if(checkUser != null) - { + if (checkUser != null) { sendError("User already register"); return; } @@ -38,10 +36,12 @@ public void execute(ChannelHandlerContext ctx, Client client) throws Exception user.uuid = UUID.randomUUID(); server.config.dao.userService.saveUser(user); } + @Override public String getType() { return "register"; } + public static byte[] registerHash(String login, String secret) throws NoSuchAlgorithmException { String text = login.concat("+").concat(secret); MessageDigest digest = MessageDigest.getInstance("SHA-256"); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/SetPasswordResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/SetPasswordResponse.java index c77758a4..e79d5d1f 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/SetPasswordResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/SetPasswordResponse.java @@ -10,6 +10,7 @@ public class SetPasswordResponse extends SimpleResponse { public String oldPassword; public String newPassword; public String username; + @Override public String getType() { return "setPassword"; @@ -17,37 +18,28 @@ public String getType() { @Override public void execute(ChannelHandlerContext ctx, Client client) { - if(( oldPassword == null && username == null ) || newPassword == null) - { + if ((oldPassword == null && username == null) || newPassword == null) { sendError("Request invalid"); return; } - if(!client.isAuth) - { + if (!client.isAuth) { sendError("You not authorized"); return; } - if(username != null && !client.permissions.canAdmin) - { + if (username != null && !client.permissions.canAdmin) { sendError("You not admin"); return; } - if(username != null) - { + if (username != null) { User user = server.config.dao.userService.findUserByUsername(username); user.setPassword(newPassword); sendResult(new SetPasswordRequestEvent()); - } - else - { + } else { User user = server.config.dao.userService.findUserByUsername(client.username); - if(user.verifyPassword(oldPassword)) - { + if (user.verifyPassword(oldPassword)) { user.setPassword(newPassword); sendResult(new SetPasswordRequestEvent()); - } - else - { + } else { sendError("Old password incorrect"); } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/SetProfileResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/SetProfileResponse.java index 9087369f..5f4ce7b3 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/SetProfileResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/SetProfileResponse.java @@ -1,7 +1,5 @@ package pro.gravit.launchserver.socket.response.auth; -import java.util.Collection; - import io.netty.channel.ChannelHandlerContext; import pro.gravit.launcher.events.request.SetProfileRequestEvent; import pro.gravit.launcher.profiles.ClientProfile; @@ -9,6 +7,8 @@ import pro.gravit.launchserver.socket.response.SimpleResponse; import pro.gravit.utils.HookException; +import java.util.Collection; + public class SetProfileResponse extends SimpleResponse { public String client; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/profile/BatchProfileByUsername.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/profile/BatchProfileByUsername.java index ee1c5e8e..0693936e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/profile/BatchProfileByUsername.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/profile/BatchProfileByUsername.java @@ -1,7 +1,5 @@ package pro.gravit.launchserver.socket.response.profile; -import java.util.UUID; - import io.netty.channel.ChannelHandlerContext; import pro.gravit.launcher.events.request.BatchProfileByUsernameRequestEvent; import pro.gravit.launcher.profiles.PlayerProfile; @@ -9,6 +7,8 @@ import pro.gravit.launchserver.socket.response.SimpleResponse; import pro.gravit.utils.helper.LogHelper; +import java.util.UUID; + public class BatchProfileByUsername extends SimpleResponse { static class Entry { String username; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/profile/ProfileByUUIDResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/profile/ProfileByUUIDResponse.java index 754196fb..72365891 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/profile/ProfileByUUIDResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/profile/ProfileByUUIDResponse.java @@ -1,8 +1,5 @@ package pro.gravit.launchserver.socket.response.profile; -import java.io.IOException; -import java.util.UUID; - import io.netty.channel.ChannelHandlerContext; import pro.gravit.launcher.events.request.ProfileByUUIDRequestEvent; import pro.gravit.launcher.profiles.PlayerProfile; @@ -13,6 +10,9 @@ import pro.gravit.launchserver.socket.response.SimpleResponse; import pro.gravit.utils.helper.LogHelper; +import java.io.IOException; +import java.util.UUID; + public class ProfileByUUIDResponse extends SimpleResponse { public UUID uuid; public String client; @@ -55,8 +55,7 @@ public void execute(ChannelHandlerContext ctx, Client client) throws Exception { } else { pair = client.auth; } - if(pair == null) - { + if (pair == null) { sendError("ProfileByUUIDResponse: AuthProviderPair is null"); return; } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/profile/ProfileByUsername.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/profile/ProfileByUsername.java index 3f625e1f..30f44bbd 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/profile/ProfileByUsername.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/profile/ProfileByUsername.java @@ -1,13 +1,13 @@ package pro.gravit.launchserver.socket.response.profile; -import java.util.UUID; - import io.netty.channel.ChannelHandlerContext; import pro.gravit.launcher.events.request.ProfileByUsernameRequestEvent; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.SimpleResponse; import pro.gravit.utils.helper.LogHelper; +import java.util.UUID; + public class ProfileByUsername extends SimpleResponse { String username; String client; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/LauncherResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/LauncherResponse.java index e8bb79e6..63f10afb 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/LauncherResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/LauncherResponse.java @@ -1,8 +1,5 @@ package pro.gravit.launchserver.socket.response.update; -import java.util.Arrays; -import java.util.Base64; - import io.netty.channel.ChannelHandlerContext; import pro.gravit.launcher.events.request.LauncherRequestEvent; import pro.gravit.launchserver.socket.Client; @@ -10,6 +7,9 @@ import pro.gravit.utils.Version; import pro.gravit.utils.helper.SecurityHelper; +import java.util.Arrays; +import java.util.Base64; + public class LauncherResponse extends SimpleResponse { public Version version; public String hash; @@ -34,7 +34,8 @@ public void execute(ChannelHandlerContext ctx, Client client) { if (launcher_type == 1) // JAR { byte[] hash = server.launcherBinary.getDigest(); - if (hash == null) service.sendObjectAndClose(ctx, new LauncherRequestEvent(true, server.config.netty.launcherURL)); + if (hash == null) + service.sendObjectAndClose(ctx, new LauncherRequestEvent(true, server.config.netty.launcherURL)); if (Arrays.equals(bytes, hash)) { client.checkSign = true; client.isSecure = checkSecure(secureHash, secureSalt); @@ -55,9 +56,9 @@ public void execute(ChannelHandlerContext ctx, Client client) { } } else sendError("Request launcher type error"); } - private boolean checkSecure(String hash, String salt) - { - if(hash == null || salt == null) return false; + + private boolean checkSecure(String hash, String salt) { + if (hash == null || salt == null) return false; byte[] normal_hash = SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA256, server.runtime.clientCheckSecret.concat(".").concat(salt)); byte[] launcher_hash = Base64.getDecoder().decode(hash); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/UpdateListResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/UpdateListResponse.java index 2d10cc2b..5c84f9b7 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/UpdateListResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/UpdateListResponse.java @@ -1,14 +1,14 @@ package pro.gravit.launchserver.socket.response.update; -import java.util.HashSet; -import java.util.Map; - import io.netty.channel.ChannelHandlerContext; import pro.gravit.launcher.events.request.UpdateListRequestEvent; import pro.gravit.launcher.hasher.HashedDir; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.SimpleResponse; +import java.util.HashSet; +import java.util.Map; + public class UpdateListResponse extends SimpleResponse { @Override diff --git a/LaunchServer/src/test/java/pro/gravit/launchserver/StartLaunchServerTest.java b/LaunchServer/src/test/java/pro/gravit/launchserver/StartLaunchServerTest.java index 825ce546..a5dcfad1 100644 --- a/LaunchServer/src/test/java/pro/gravit/launchserver/StartLaunchServerTest.java +++ b/LaunchServer/src/test/java/pro/gravit/launchserver/StartLaunchServerTest.java @@ -1,16 +1,8 @@ package pro.gravit.launchserver; -import java.io.IOException; -import java.nio.file.Path; -import java.security.KeyPair; -import java.security.SecureRandom; -import java.security.interfaces.ECPrivateKey; -import java.security.interfaces.ECPublicKey; - import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; - import pro.gravit.launcher.Launcher; import pro.gravit.launchserver.config.LaunchServerConfig; import pro.gravit.launchserver.config.LaunchServerRuntimeConfig; @@ -20,6 +12,12 @@ import pro.gravit.utils.command.StdCommandHandler; import pro.gravit.utils.helper.SecurityHelper; +import java.nio.file.Path; +import java.security.KeyPair; +import java.security.SecureRandom; +import java.security.interfaces.ECPrivateKey; +import java.security.interfaces.ECPublicKey; + public class StartLaunchServerTest { @TempDir public static Path modulesDir; @@ -28,9 +26,9 @@ public class StartLaunchServerTest { @TempDir public static Path dir; public static LaunchServer launchServer; + @BeforeAll - public static void prepare() throws Exception - { + public static void prepare() throws Exception { LaunchServerModulesManager modulesManager = new LaunchServerModulesManager(modulesDir, configDir, null); LaunchServerConfig config = LaunchServerConfig.getDefault(LaunchServer.LaunchServerEnv.TEST); Launcher.gsonManager = new LaunchServerGsonManager(modulesManager); @@ -72,6 +70,7 @@ public void writeRuntimeConfig(LaunchServerRuntimeConfig config) { .setCommandHandler(new StdCommandHandler(false)); launchServer = builder.build(); } + @Test public void start() { launchServer.run(); diff --git a/LaunchServerConsole/src/main/java/pro/gravit/launchserver/console/ConsoleMain.java b/LaunchServerConsole/src/main/java/pro/gravit/launchserver/console/ConsoleMain.java index 50afce45..572a8bed 100644 --- a/LaunchServerConsole/src/main/java/pro/gravit/launchserver/console/ConsoleMain.java +++ b/LaunchServerConsole/src/main/java/pro/gravit/launchserver/console/ConsoleMain.java @@ -1,7 +1,5 @@ package pro.gravit.launchserver.console; -import java.io.IOException; - import pro.gravit.launcher.server.ServerWrapper; import pro.gravit.utils.command.CommandHandler; import pro.gravit.utils.command.JLineCommandHandler; @@ -9,6 +7,8 @@ import pro.gravit.utils.command.basic.HelpCommand; import pro.gravit.utils.helper.LogHelper; +import java.io.IOException; + public class ConsoleMain { public static CommandHandler commandHandler; diff --git a/Launcher/runtime/dialog/overlay/debug/debug.fxml b/Launcher/runtime/dialog/overlay/debug/debug.fxml index 731fba31..dfd6c22f 100644 --- a/Launcher/runtime/dialog/overlay/debug/debug.fxml +++ b/Launcher/runtime/dialog/overlay/debug/debug.fxml @@ -9,20 +9,22 @@ - + - - + + - - - + + - + - + - + - - - - - - - - - + + + + + + + + + + + + + + + + + + diff --git a/Launcher/runtime/dialog/scenes/mainmenu/mainmenu.fxml b/Launcher/runtime/dialog/scenes/mainmenu/mainmenu.fxml index 221c21c7..78fb1cf7 100644 --- a/Launcher/runtime/dialog/scenes/mainmenu/mainmenu.fxml +++ b/Launcher/runtime/dialog/scenes/mainmenu/mainmenu.fxml @@ -13,63 +13,86 @@ - + - + - + - + + + + - + - + - + - + - + - - - - - + - - + + diff --git a/Launcher/runtime/dialog/scenes/options/options.fxml b/Launcher/runtime/dialog/scenes/options/options.fxml index aa3b28a3..e31a5178 100644 --- a/Launcher/runtime/dialog/scenes/options/options.fxml +++ b/Launcher/runtime/dialog/scenes/options/options.fxml @@ -14,59 +14,68 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java b/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java index e5b08c99..e2aeaada 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java +++ b/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java @@ -1,13 +1,5 @@ package pro.gravit.launcher; -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; - import pro.gravit.launcher.client.ClientLauncher; import pro.gravit.launcher.client.ClientModuleManager; import pro.gravit.launcher.client.DirBridge; @@ -16,6 +8,14 @@ import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.LogHelper; +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + public class ClientLauncherWrapper { public static final String MAGIC_ARG = "-Djdk.attach.allowAttachSelf"; public static final String WAIT_PROCESS_PROPERTY = "launcher.waitProcess"; @@ -60,8 +60,7 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep JVMHelper.addSystemPropertyToArgs(args, DirBridge.CUSTOMDIR_PROPERTY); JVMHelper.addSystemPropertyToArgs(args, DirBridge.USE_CUSTOMDIR_PROPERTY); JVMHelper.addSystemPropertyToArgs(args, DirBridge.USE_OPTDIR_PROPERTY); - if (!noJava9check && !System.getProperty("java.version").startsWith("1.8")) - { + if (!noJava9check && !System.getProperty("java.version").startsWith("1.8")) { LogHelper.debug("Found Java 9+ ( %s )", System.getProperty("java.version")); Collections.addAll(args, "--add-modules"); Collections.addAll(args, "javafx.base,javafx.fxml,javafx.controls,jdk.unsupported"); @@ -75,8 +74,7 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep tryAddModule(findPath, "javafx.fxml", builder); tryAddModule(findPath, "javafx.controls", builder); String modulePath = builder.toString(); - if(!modulePath.isEmpty()) - { + if (!modulePath.isEmpty()) { Collections.addAll(args, "--module-path"); Collections.addAll(args, modulePath); } @@ -107,26 +105,24 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep process.waitFor(); } } - public static Path tryFindModule(Path path, String moduleName) - { + + public static Path tryFindModule(Path path, String moduleName) { Path result = path.resolve(moduleName.concat(".jar")); LogHelper.dev("Try resolve %s", result.toString()); - if(!IOHelper.isFile(result)) + if (!IOHelper.isFile(result)) result = path.resolve("lib").resolve(moduleName.concat(".jar")); else return result; - if(!IOHelper.isFile(result)) + if (!IOHelper.isFile(result)) return null; else return result; } - public static boolean tryAddModule(Path[] paths, String moduleName, StringBuilder args) - { - for(Path path : paths) - { - if(path == null) continue; + + public static boolean tryAddModule(Path[] paths, String moduleName, StringBuilder args) { + for (Path path : paths) { + if (path == null) continue; Path result = tryFindModule(path, moduleName); - if(result != null) - { - if(args.length() != 0) args.append(File.pathSeparatorChar); + if (result != null) { + if (args.length() != 0) args.append(File.pathSeparatorChar); args.append(result.toAbsolutePath().toString()); return true; } diff --git a/Launcher/src/main/java/pro/gravit/launcher/JSApplication.java b/Launcher/src/main/java/pro/gravit/launcher/JSApplication.java index c47c73f6..47937e7c 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/JSApplication.java +++ b/Launcher/src/main/java/pro/gravit/launcher/JSApplication.java @@ -1,9 +1,9 @@ package pro.gravit.launcher; -import java.util.concurrent.atomic.AtomicReference; - import javafx.application.Application; +import java.util.concurrent.atomic.AtomicReference; + public abstract class JSApplication extends Application { private static final AtomicReference INSTANCE = new AtomicReference<>(); diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherAgent.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherAgent.java index a86ac483..5309d878 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherAgent.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherAgent.java @@ -1,15 +1,15 @@ package pro.gravit.launcher; +import pro.gravit.launcher.patches.FMLPatcher; +import pro.gravit.launcher.utils.NativeJVMHalt; +import pro.gravit.utils.helper.LogHelper; + import java.io.File; import java.io.IOException; import java.lang.instrument.Instrumentation; import java.nio.file.Path; import java.util.jar.JarFile; -import pro.gravit.launcher.patches.FMLPatcher; -import pro.gravit.launcher.utils.NativeJVMHalt; -import pro.gravit.utils.helper.LogHelper; - @LauncherAPI public final class LauncherAgent { private static boolean isAgentStarted = false; @@ -19,7 +19,7 @@ public static void addJVMClassPath(String path) throws IOException { LogHelper.debug("Launcher Agent addJVMClassPath"); inst.appendToSystemClassLoaderSearch(new JarFile(new File(path))); } - + public static void addJVMClassPath(Path path) throws IOException { LogHelper.debug("Launcher Agent addJVMClassPath"); inst.appendToSystemClassLoaderSearch(new JarFile(path.toFile())); @@ -37,25 +37,22 @@ public static void premain(String agentArgument, Instrumentation instrumentation FMLPatcher.apply(); isAgentStarted = true; } - public static void checkAgentStacktrace() - { + + public static void checkAgentStacktrace() { RuntimeException ex = new SecurityException("Error check agent stacktrace"); boolean isFoundNative = false; boolean foundPreMain = false; - for(StackTraceElement e : ex.getStackTrace()) - { - if(e.isNativeMethod()) - { - if(!isFoundNative) isFoundNative = true; + for (StackTraceElement e : ex.getStackTrace()) { + if (e.isNativeMethod()) { + if (!isFoundNative) isFoundNative = true; else throw ex; } - if(e.getMethodName().equals("premain")) - { - if(!foundPreMain) foundPreMain = true; + if (e.getMethodName().equals("premain")) { + if (!foundPreMain) foundPreMain = true; else throw ex; } } - if(!isFoundNative || !foundPreMain) throw ex; + if (!isFoundNative || !foundPreMain) throw ex; } public static boolean isStarted() { diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index 7de55081..96bff818 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -1,15 +1,9 @@ package pro.gravit.launcher; -import java.io.IOException; -import java.nio.file.Path; -import java.security.*; -import java.security.interfaces.ECPrivateKey; -import java.security.interfaces.ECPublicKey; -import java.security.spec.InvalidKeySpecException; -import java.util.Objects; -import java.util.concurrent.atomic.AtomicBoolean; - -import pro.gravit.launcher.client.*; +import pro.gravit.launcher.client.ClientModuleManager; +import pro.gravit.launcher.client.DirBridge; +import pro.gravit.launcher.client.FunctionalBridge; +import pro.gravit.launcher.client.LauncherUpdateController; import pro.gravit.launcher.client.events.ClientEngineInitPhase; import pro.gravit.launcher.client.events.ClientPreGuiPhase; import pro.gravit.launcher.guard.LauncherGuardManager; @@ -27,8 +21,18 @@ import pro.gravit.launcher.request.websockets.StandartClientWebSocketService; import pro.gravit.utils.helper.*; +import java.io.IOException; +import java.nio.file.Path; +import java.security.KeyPair; +import java.security.SecureRandom; +import java.security.interfaces.ECPrivateKey; +import java.security.interfaces.ECPublicKey; +import java.security.spec.InvalidKeySpecException; +import java.util.Objects; +import java.util.concurrent.atomic.AtomicBoolean; + public class LauncherEngine { - public static final AtomicBoolean IS_CLIENT = new AtomicBoolean(false); + public static final AtomicBoolean IS_CLIENT = new AtomicBoolean(false); public static void main(String... args) throws Throwable { JVMHelper.checkStackTrace(LauncherEngine.class); @@ -70,9 +74,9 @@ public static void initGson(ClientModuleManager modulesManager) { } public void readKeys() throws IOException, InvalidKeySpecException { - if(privateKey != null || publicKey != null) return; + if (privateKey != null || publicKey != null) return; Path dir = DirBridge.dir; - Path publicKeyFile =dir.resolve("public.key"); + Path publicKeyFile = dir.resolve("public.key"); Path privateKeyFile = dir.resolve("private.key"); if (IOHelper.isFile(publicKeyFile) && IOHelper.isFile(privateKeyFile)) { LogHelper.info("Reading EC keypair"); @@ -136,7 +140,7 @@ public void start(String... args) throws Throwable { } }; } - if(UpdateRequest.getController() == null) UpdateRequest.setController(new LauncherUpdateController()); + if (UpdateRequest.getController() == null) UpdateRequest.setController(new LauncherUpdateController()); Objects.requireNonNull(args, "args"); if (started.getAndSet(true)) throw new IllegalStateException("Launcher has been already started"); diff --git a/Launcher/src/main/java/pro/gravit/launcher/NewLauncherSettings.java b/Launcher/src/main/java/pro/gravit/launcher/NewLauncherSettings.java index 4947649d..5c45135d 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/NewLauncherSettings.java +++ b/Launcher/src/main/java/pro/gravit/launcher/NewLauncherSettings.java @@ -1,16 +1,12 @@ package pro.gravit.launcher; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - import pro.gravit.launcher.client.UserSettings; import pro.gravit.launcher.hasher.HashedDir; import pro.gravit.launcher.profiles.ClientProfile; +import java.nio.file.Path; +import java.util.*; + public class NewLauncherSettings { @LauncherAPI public String login; diff --git a/Launcher/src/main/java/pro/gravit/launcher/api/AuthService.java b/Launcher/src/main/java/pro/gravit/launcher/api/AuthService.java index d6d8da59..009b99cf 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/api/AuthService.java +++ b/Launcher/src/main/java/pro/gravit/launcher/api/AuthService.java @@ -8,12 +8,12 @@ public class AuthService { public static String username; public static ClientPermissions permissions = new ClientPermissions(); public static UUID uuid; - public static boolean isAdmin() - { + + public static boolean isAdmin() { return permissions.canAdmin; } - public static boolean isServer() - { + + public static boolean isServer() { return permissions.canServer; } } diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index 64cfd348..30800ff7 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -1,37 +1,6 @@ package pro.gravit.launcher.client; -import java.io.IOException; -import java.lang.ProcessBuilder.Redirect; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; -import java.net.InetSocketAddress; -import java.net.ServerSocket; -import java.net.Socket; -import java.net.URL; -import java.nio.file.FileVisitResult; -import java.nio.file.Path; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.attribute.BasicFileAttributes; -import java.nio.file.attribute.PosixFilePermission; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.EnumSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import javax.swing.JOptionPane; - -import pro.gravit.launcher.ClientLauncherWrapper; -import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.LauncherAPI; -import pro.gravit.launcher.LauncherAgent; -import pro.gravit.launcher.LauncherConfig; -import pro.gravit.launcher.LauncherEngine; +import pro.gravit.launcher.*; import pro.gravit.launcher.api.AuthService; import pro.gravit.launcher.api.ClientService; import pro.gravit.launcher.client.events.ClientLaunchPhase; @@ -56,13 +25,27 @@ import pro.gravit.launcher.utils.NativeJVMHalt; import pro.gravit.utils.PublicURLClassLoader; import pro.gravit.utils.Version; -import pro.gravit.utils.helper.CommonHelper; -import pro.gravit.utils.helper.EnvHelper; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.JVMHelper; +import pro.gravit.utils.helper.*; import pro.gravit.utils.helper.JVMHelper.OS; -import pro.gravit.utils.helper.LogHelper; -import pro.gravit.utils.helper.SecurityHelper; + +import javax.swing.*; +import java.io.IOException; +import java.lang.ProcessBuilder.Redirect; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; +import java.net.InetSocketAddress; +import java.net.ServerSocket; +import java.net.Socket; +import java.net.URL; +import java.nio.file.FileVisitResult; +import java.nio.file.Path; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; +import java.nio.file.attribute.PosixFilePermission; +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; public final class ClientLauncher { private static final class ClassPathFileVisitor extends SimpleFileVisitor { @@ -295,7 +278,7 @@ private static void launch(ClientProfile profile, Params params) throws Throwabl List copy = new ArrayList<>(args); for (int i = 0, l = copy.size(); i < l; i++) { String s = copy.get(i); - if ( i + 1 < l && ("--accessToken".equals(s) || "--session".equals(s))) { + if (i + 1 < l && ("--accessToken".equals(s) || "--session".equals(s))) { copy.set(i + 1, "censored"); } } @@ -306,27 +289,27 @@ private static void launch(ClientProfile profile, Params params) throws Throwabl Launcher.LAUNCHED.set(true); JVMHelper.fullGC(); // Invoke main method - mainMethod.invokeWithArguments((Object)args.toArray(new String[0])); + mainMethod.invokeWithArguments((Object) args.toArray(new String[0])); } private static Process process = null; private static boolean clientStarted = false; private static Thread writeParamsThread; - public static void setWriteParamsThread(Thread writeParamsThread) { - ClientLauncher.writeParamsThread = writeParamsThread; - ClientLauncher.writeParamsThread.start(); - } + public static void setWriteParamsThread(Thread writeParamsThread) { + ClientLauncher.writeParamsThread = writeParamsThread; + ClientLauncher.writeParamsThread.start(); + } - public static Process getProcess() { - return process; - } + public static Process getProcess() { + return process; + } - public static void setClientStarted() { - clientStarted = true; - } + public static void setClientStarted() { + clientStarted = true; + } - public static PlayerProfile playerProfile; + public static PlayerProfile playerProfile; @LauncherAPI public static Process launch( @@ -397,12 +380,12 @@ public static Process launch( ClientHookManager.preStartHook.hook(context, builder); process = builder.start(); if (builder.command() != command) { - LogHelper.error("Something strange cheating..."); + LogHelper.error("Something strange cheating..."); System.exit(100); - clientStarted = false; + clientStarted = false; return null; } - if(ClientHookManager.postStartHook.hook(context, builder)) return process; + if (ClientHookManager.postStartHook.hook(context, builder)) return process; if (!pipeOutput) { for (int i = 0; i < 50; ++i) { if (!process.isAlive()) { @@ -423,8 +406,8 @@ public static Process launch( clientStarted = false; return process; } - public static class ClientLaunchContext - { + + public static class ClientLaunchContext { public final Params params; public final ClientProfile profile; public final HashedDir assetHDir, clientHDir; @@ -441,15 +424,15 @@ public ClientLaunchContext(Params params, ClientProfile profile, HashedDir asset @LauncherAPI public static void main(String... args) throws Throwable { - LauncherEngine.IS_CLIENT.set(true); + LauncherEngine.IS_CLIENT.set(true); LauncherEngine engine = LauncherEngine.clientInstance(); LauncherEngine.modulesManager = new ClientModuleManager(); LauncherConfig.getAutogenConfig().initModules(); //INIT LauncherEngine.modulesManager.initModules(null); initGson(LauncherEngine.modulesManager); if (!LauncherAgent.isStarted()) { - NativeJVMHalt.haltA(100); - return; + NativeJVMHalt.haltA(100); + return; } LauncherEngine.modulesManager.invokeEvent(new PreConfigPhase()); JVMHelper.verifySystemProperties(ClientLauncher.class, true); @@ -597,52 +580,54 @@ private ClientLauncher() { } public interface ParamsAPI { - ParamContainer read() throws Exception; - void write(ParamContainer p); + ParamContainer read() throws Exception; + + void write(ParamContainer p); } - + public static final ParamsAPI container = new ParamsAPI() { - @Override - public ParamContainer read() throws Exception { - ParamContainer p; + @Override + public ParamContainer read() throws Exception { + ParamContainer p; try (Socket socket = IOHelper.newSocket()) { socket.connect(new InetSocketAddress(SOCKET_HOST, SOCKET_PORT)); try (HInput input = new HInput(socket.getInputStream())) { - p = new ParamContainer(input); + p = new ParamContainer(input); } } return p; - } - @Override - public void write(ParamContainer p) { - setWriteParamsThread(CommonHelper.newThread("Client params writter", true, () -> - { - try { - try (ServerSocket socket = new ServerSocket()) { - socket.setReuseAddress(true); - socket.setSoTimeout(30000); - socket.bind(new InetSocketAddress(SOCKET_HOST, SOCKET_PORT)); - Socket client = socket.accept(); - if (process == null) { - LogHelper.error("Process is null"); - return; - } - if (!process.isAlive()) { - LogHelper.error("Process is not alive"); - JOptionPane.showMessageDialog(null, "Client Process crashed", "Launcher", JOptionPane.ERROR_MESSAGE); - return; - } - try (HOutput output = new HOutput(client.getOutputStream())) { - p.write(output); - } - clientStarted = true; - } - } catch (IOException e) { - LogHelper.error(e); - } - })); - } - + } + + @Override + public void write(ParamContainer p) { + setWriteParamsThread(CommonHelper.newThread("Client params writter", true, () -> + { + try { + try (ServerSocket socket = new ServerSocket()) { + socket.setReuseAddress(true); + socket.setSoTimeout(30000); + socket.bind(new InetSocketAddress(SOCKET_HOST, SOCKET_PORT)); + Socket client = socket.accept(); + if (process == null) { + LogHelper.error("Process is null"); + return; + } + if (!process.isAlive()) { + LogHelper.error("Process is not alive"); + JOptionPane.showMessageDialog(null, "Client Process crashed", "Launcher", JOptionPane.ERROR_MESSAGE); + return; + } + try (HOutput output = new HOutput(client.getOutputStream())) { + p.write(output); + } + clientStarted = true; + } + } catch (IOException e) { + LogHelper.error(e); + } + })); + } + }; public static class ParamContainer extends StreamObject { @@ -658,24 +643,24 @@ public ParamContainer(HInput input) throws Exception { public ParamContainer() { } - public ParamContainer(Params params, ClientProfile profile, HashedDir assetHDir, HashedDir clientHDir) { - this.params = params; - this.profile = profile; - this.assetHDir = assetHDir; - this.clientHDir = clientHDir; + public ParamContainer(Params params, ClientProfile profile, HashedDir assetHDir, HashedDir clientHDir) { + this.params = params; + this.profile = profile; + this.assetHDir = assetHDir; + this.clientHDir = clientHDir; } public Params params; public ClientProfile profile; public HashedDir assetHDir, clientHDir; - @Override - public void write(HOutput output) throws IOException { + @Override + public void write(HOutput output) throws IOException { params.write(output); output.writeString(Launcher.gsonManager.gson.toJson(profile), 0); assetHDir.write(output); clientHDir.write(output); ClientHookManager.paramsOutputHook.hook(output); - } + } } } diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherContext.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherContext.java index 84a96aa4..51f78968 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherContext.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherContext.java @@ -1,12 +1,12 @@ package pro.gravit.launcher.client; +import pro.gravit.launcher.profiles.ClientProfile; +import pro.gravit.launcher.profiles.PlayerProfile; + import java.nio.file.Path; import java.util.LinkedList; import java.util.List; -import pro.gravit.launcher.profiles.ClientProfile; -import pro.gravit.launcher.profiles.PlayerProfile; - public class ClientLauncherContext { public Path javaBin; public final List args = new LinkedList<>(); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientModuleManager.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientModuleManager.java index 859c3644..6a6e62d0 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientModuleManager.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientModuleManager.java @@ -1,14 +1,13 @@ package pro.gravit.launcher.client; -import java.io.IOException; -import java.nio.file.Path; -import java.util.Collection; - import pro.gravit.launcher.Launcher; import pro.gravit.launcher.modules.LauncherModule; import pro.gravit.launcher.modules.impl.SimpleModuleManager; import pro.gravit.utils.verify.LauncherTrustManager; +import java.nio.file.Path; +import java.util.Collection; + public class ClientModuleManager extends SimpleModuleManager { public ClientModuleManager() { super(null, null, Launcher.getConfig().trustManager); @@ -36,12 +35,9 @@ public LauncherModule loadModule(LauncherModule module) { return super.loadModule(module); } - public void callWrapper(ProcessBuilder processBuilder, Collection jvmArgs) - { - for(LauncherModule module : modules) - { - if(module instanceof ClientWrapperModule) - { + public void callWrapper(ProcessBuilder processBuilder, Collection jvmArgs) { + for (LauncherModule module : modules) { + if (module instanceof ClientWrapperModule) { ((ClientWrapperModule) module).wrapperPhase(processBuilder, jvmArgs); } } diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/DirBridge.java b/Launcher/src/main/java/pro/gravit/launcher/client/DirBridge.java index 3175bc43..347b764c 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/DirBridge.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/DirBridge.java @@ -1,16 +1,16 @@ package pro.gravit.launcher.client; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; - import pro.gravit.launcher.Launcher; import pro.gravit.launcher.LauncherAPI; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.LogHelper; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + public class DirBridge { public static final String USE_CUSTOMDIR_PROPERTY = "launcher.usecustomdir"; @@ -105,11 +105,11 @@ public static void setUseLegacyDir(boolean b) { String projectName = Launcher.getConfig().projectname; try { DirBridge.dir = getLauncherDir(projectName); - if(!IOHelper.exists(DirBridge.dir)) Files.createDirectories(DirBridge.dir); + if (!IOHelper.exists(DirBridge.dir)) Files.createDirectories(DirBridge.dir); DirBridge.dirStore = getStoreDir(projectName); - if(!IOHelper.exists(DirBridge.dirStore)) Files.createDirectories(DirBridge.dirStore); + if (!IOHelper.exists(DirBridge.dirStore)) Files.createDirectories(DirBridge.dirStore); DirBridge.dirProjectStore = getProjectStoreDir(projectName); - if(!IOHelper.exists(DirBridge.dirProjectStore)) Files.createDirectories(DirBridge.dirProjectStore); + if (!IOHelper.exists(DirBridge.dirProjectStore)) Files.createDirectories(DirBridge.dirProjectStore); } catch (IOException e) { LogHelper.error(e); } diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/FunctionalBridge.java b/Launcher/src/main/java/pro/gravit/launcher/client/FunctionalBridge.java index b6c19774..9b42be65 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/FunctionalBridge.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/FunctionalBridge.java @@ -1,11 +1,5 @@ package pro.gravit.launcher.client; -import java.nio.file.Path; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; - import pro.gravit.launcher.Launcher; import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.api.AuthService; @@ -24,6 +18,12 @@ import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.SecurityHelper; +import java.nio.file.Path; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; + public class FunctionalBridge { @LauncherAPI public static final ScheduledExecutorService threadPool = Executors.newScheduledThreadPool(0); @@ -56,7 +56,7 @@ public static void startTask(Runnable task) { public static HWID getHWID() { HWID hhwid = hwid.get(); if (hhwid == null) { - if(hwidProvider == null) hwidProvider = new OshiHWIDProvider(); + if (hwidProvider == null) hwidProvider = new OshiHWIDProvider(); hwid.set(hwidProvider.getHWID()); } return hhwid; @@ -65,7 +65,7 @@ public static HWID getHWID() { @LauncherAPI public static long getTotalMemory() { if (cachedMemorySize > 0) return cachedMemorySize; - if(hwidProvider == null) hwidProvider = new OshiHWIDProvider(); + if (hwidProvider == null) hwidProvider = new OshiHWIDProvider(); return (cachedMemorySize = hwidProvider.getTotalMemory() >> 20); } @@ -105,8 +105,7 @@ public static void setAuthParams(AuthRequestEvent event) { } LauncherGuardManager.guard.setProtectToken(event.protectToken); AuthService.permissions = event.permissions; - if(event.playerProfile != null) - { + if (event.playerProfile != null) { AuthService.username = event.playerProfile.username; AuthService.uuid = event.playerProfile.uuid; } @@ -126,16 +125,17 @@ public static void evalCommand(String cmd) { public static void addPlainOutput(LogHelper.Output output) { LogHelper.addOutput(output, LogHelper.OutputTypes.PLAIN); } - + @LauncherAPI public static String getLauncherVersion() { return String.format("GravitLauncher v%d.%d.%d build %d", - Version.MAJOR, - Version.MINOR, - Version.PATCH, - Version.BUILD + Version.MAJOR, + Version.MINOR, + Version.PATCH, + Version.BUILD ); } + @LauncherAPI public static byte[] encryptPassword(String string) throws Exception { byte[] encode = IOHelper.encode(string); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java b/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java index 51eb2939..4fbdf4ff 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java @@ -1,14 +1,5 @@ package pro.gravit.launcher.client; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.List; -import java.util.concurrent.atomic.AtomicReference; - import pro.gravit.launcher.NewLauncherSettings; import pro.gravit.launcher.downloader.ListDownloader; import pro.gravit.launcher.events.request.UpdateRequestEvent; @@ -20,6 +11,15 @@ import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; +import java.util.concurrent.atomic.AtomicReference; + public class LauncherUpdateController implements UpdateRequest.UpdateController { @Override public void preUpdate(UpdateRequest request, UpdateRequestEvent e) { diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ServerPinger.java b/Launcher/src/main/java/pro/gravit/launcher/client/ServerPinger.java index fc8ecd48..44ef6ae7 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ServerPinger.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ServerPinger.java @@ -1,5 +1,15 @@ package pro.gravit.launcher.client; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import pro.gravit.launcher.LauncherAPI; +import pro.gravit.launcher.profiles.ClientProfile; +import pro.gravit.launcher.serialize.HInput; +import pro.gravit.launcher.serialize.HOutput; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.LogHelper; +import pro.gravit.utils.helper.VerifyHelper; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.net.InetSocketAddress; @@ -10,17 +20,6 @@ import java.util.Objects; import java.util.regex.Pattern; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; - -import pro.gravit.launcher.LauncherAPI; -import pro.gravit.launcher.profiles.ClientProfile; -import pro.gravit.launcher.serialize.HInput; -import pro.gravit.launcher.serialize.HOutput; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.LogHelper; -import pro.gravit.utils.helper.VerifyHelper; - public final class ServerPinger { private final JsonParser parser = new JsonParser(); diff --git a/Launcher/src/main/java/pro/gravit/launcher/console/store/CopyStoreDirCommand.java b/Launcher/src/main/java/pro/gravit/launcher/console/store/CopyStoreDirCommand.java index 2f23c878..763855ac 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/console/store/CopyStoreDirCommand.java +++ b/Launcher/src/main/java/pro/gravit/launcher/console/store/CopyStoreDirCommand.java @@ -1,14 +1,14 @@ package pro.gravit.launcher.console.store; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; - import pro.gravit.launcher.NewLauncherSettings; import pro.gravit.launcher.managers.SettingsManager; import pro.gravit.utils.command.Command; import pro.gravit.utils.helper.LogHelper; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + public class CopyStoreDirCommand extends Command { @Override public String getArgsDescription() { diff --git a/Launcher/src/main/java/pro/gravit/launcher/console/store/LinkStoreDirCommand.java b/Launcher/src/main/java/pro/gravit/launcher/console/store/LinkStoreDirCommand.java index b2ab24b7..35120f31 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/console/store/LinkStoreDirCommand.java +++ b/Launcher/src/main/java/pro/gravit/launcher/console/store/LinkStoreDirCommand.java @@ -1,14 +1,14 @@ package pro.gravit.launcher.console.store; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; - import pro.gravit.launcher.NewLauncherSettings; import pro.gravit.launcher.managers.SettingsManager; import pro.gravit.utils.command.Command; import pro.gravit.utils.helper.LogHelper; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + public class LinkStoreDirCommand extends Command { @Override diff --git a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherGuardInterface.java b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherGuardInterface.java index ebeb1f3e..e0be7852 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherGuardInterface.java +++ b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherGuardInterface.java @@ -1,9 +1,9 @@ package pro.gravit.launcher.guard; -import java.nio.file.Path; - import pro.gravit.launcher.client.ClientLauncherContext; +import java.nio.file.Path; + public interface LauncherGuardInterface { String getName(); diff --git a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherGuardManager.java b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherGuardManager.java index 6f0ce1d9..14d9a38d 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherGuardManager.java +++ b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherGuardManager.java @@ -1,10 +1,10 @@ package pro.gravit.launcher.guard; -import java.nio.file.Path; - import pro.gravit.launcher.Launcher; import pro.gravit.launcher.LauncherConfig; +import java.nio.file.Path; + public class LauncherGuardManager { public static LauncherGuardInterface guard; diff --git a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherJavaGuard.java b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherJavaGuard.java index 6f4bcc72..8b4a013e 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherJavaGuard.java +++ b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherJavaGuard.java @@ -1,14 +1,14 @@ package pro.gravit.launcher.guard; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Collections; - import pro.gravit.launcher.client.ClientLauncher; import pro.gravit.launcher.client.ClientLauncherContext; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.JVMHelper; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Collections; + public class LauncherJavaGuard implements LauncherGuardInterface { @Override public String getName() { diff --git a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherNoGuard.java b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherNoGuard.java index e55248e7..2ca267a9 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherNoGuard.java +++ b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherNoGuard.java @@ -1,14 +1,14 @@ package pro.gravit.launcher.guard; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Collections; - import pro.gravit.launcher.client.ClientLauncherContext; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.LogHelper; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Collections; + public class LauncherNoGuard implements LauncherGuardInterface { @Override public String getName() { diff --git a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherStdGuard.java b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherStdGuard.java index d93d9baa..b24bcadb 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherStdGuard.java +++ b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherStdGuard.java @@ -1,11 +1,5 @@ package pro.gravit.launcher.guard; -import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Collections; -import java.util.Map; - import pro.gravit.launcher.Launcher; import pro.gravit.launcher.LauncherConfig; import pro.gravit.launcher.client.ClientLauncher; @@ -15,6 +9,12 @@ import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.UnpackHelper; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Collections; +import java.util.Map; + //Стандартный интерфейс для всех AntiInject public class LauncherStdGuard implements LauncherGuardInterface { public String protectToken; @@ -30,7 +30,7 @@ public Path getJavaBinPath() { if (JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) { javaBinPath = ClientLauncher.getJavaBinPath(); String projectName = Launcher.getConfig().projectname; - String wrapperUnpackName = ( javaBinPath == null ? JVMHelper.JVM_BITS : JVMHelper.OS_BITS ) == 64 ? projectName.concat("64.exe") : projectName.concat("32.exe"); + String wrapperUnpackName = (javaBinPath == null ? JVMHelper.JVM_BITS : JVMHelper.OS_BITS) == 64 ? projectName.concat("64.exe") : projectName.concat("32.exe"); return DirBridge.getGuardDir().resolve(wrapperUnpackName); } else return IOHelper.resolveJavaBin(Paths.get(System.getProperty("java.home"))); diff --git a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherWrapperGuard.java b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherWrapperGuard.java index 550a1925..725cb1fc 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherWrapperGuard.java +++ b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherWrapperGuard.java @@ -1,11 +1,5 @@ package pro.gravit.launcher.guard; -import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Collections; -import java.util.Map; - import pro.gravit.launcher.Launcher; import pro.gravit.launcher.LauncherConfig; import pro.gravit.launcher.client.ClientLauncherContext; @@ -14,6 +8,12 @@ import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.UnpackHelper; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Collections; +import java.util.Map; + public class LauncherWrapperGuard implements LauncherGuardInterface { public String protectToken; diff --git a/Launcher/src/main/java/pro/gravit/launcher/gui/JSRuntimeProvider.java b/Launcher/src/main/java/pro/gravit/launcher/gui/JSRuntimeProvider.java index f9ceebbd..d488e6cc 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/gui/JSRuntimeProvider.java +++ b/Launcher/src/main/java/pro/gravit/launcher/gui/JSRuntimeProvider.java @@ -1,27 +1,7 @@ package pro.gravit.launcher.gui; -import java.io.BufferedReader; -import java.io.IOException; -import java.net.URL; -import java.util.Map; - -import javax.script.Bindings; -import javax.script.Invocable; -import javax.script.ScriptContext; -import javax.script.ScriptEngine; -import javax.script.ScriptException; - -import pro.gravit.launcher.JSApplication; -import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.LauncherAPI; -import pro.gravit.launcher.LauncherConfig; -import pro.gravit.launcher.LauncherEngine; -import pro.gravit.launcher.NewLauncherSettings; -import pro.gravit.launcher.client.ClientLauncher; -import pro.gravit.launcher.client.DirBridge; -import pro.gravit.launcher.client.FunctionalBridge; -import pro.gravit.launcher.client.ServerPinger; -import pro.gravit.launcher.client.UserSettings; +import pro.gravit.launcher.*; +import pro.gravit.launcher.client.*; import pro.gravit.launcher.client.events.ClientGuiPhase; import pro.gravit.launcher.hasher.FileNameMatcher; import pro.gravit.launcher.hasher.HashedDir; @@ -39,11 +19,7 @@ import pro.gravit.launcher.request.Request; import pro.gravit.launcher.request.RequestException; import pro.gravit.launcher.request.RequestType; -import pro.gravit.launcher.request.auth.AuthRequest; -import pro.gravit.launcher.request.auth.CheckServerRequest; -import pro.gravit.launcher.request.auth.GetAvailabilityAuthRequest; -import pro.gravit.launcher.request.auth.JoinServerRequest; -import pro.gravit.launcher.request.auth.SetProfileRequest; +import pro.gravit.launcher.request.auth.*; import pro.gravit.launcher.request.update.LauncherRequest; import pro.gravit.launcher.request.update.ProfilesRequest; import pro.gravit.launcher.request.update.UpdateRequest; @@ -55,13 +31,13 @@ import pro.gravit.launcher.serialize.stream.EnumSerializer; import pro.gravit.launcher.serialize.stream.StreamObject; import pro.gravit.utils.HTTPRequest; -import pro.gravit.utils.helper.CommonHelper; -import pro.gravit.utils.helper.EnvHelper; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.JVMHelper; -import pro.gravit.utils.helper.LogHelper; -import pro.gravit.utils.helper.SecurityHelper; -import pro.gravit.utils.helper.VerifyHelper; +import pro.gravit.utils.helper.*; + +import javax.script.*; +import java.io.BufferedReader; +import java.io.IOException; +import java.net.URL; +import java.util.Map; public class JSRuntimeProvider implements RuntimeProvider { diff --git a/Launcher/src/main/java/pro/gravit/launcher/hwid/OshiHWIDProvider.java b/Launcher/src/main/java/pro/gravit/launcher/hwid/OshiHWIDProvider.java index e977bf9b..4ab5cd6d 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/hwid/OshiHWIDProvider.java +++ b/Launcher/src/main/java/pro/gravit/launcher/hwid/OshiHWIDProvider.java @@ -1,16 +1,11 @@ package pro.gravit.launcher.hwid; -import java.net.NetworkInterface; - import oshi.SystemInfo; -import oshi.hardware.CentralProcessor; -import oshi.hardware.ComputerSystem; -import oshi.hardware.HWDiskStore; -import oshi.hardware.HardwareAbstractionLayer; -import oshi.hardware.NetworkIF; -import oshi.hardware.UsbDevice; +import oshi.hardware.*; import pro.gravit.utils.helper.LogHelper; +import java.net.NetworkInterface; + public class OshiHWIDProvider implements LauncherHWIDInterface { public SystemInfo systemInfo; public HardwareAbstractionLayer hardware; diff --git a/Launcher/src/main/java/pro/gravit/launcher/managers/ClientGsonManager.java b/Launcher/src/main/java/pro/gravit/launcher/managers/ClientGsonManager.java index 2a16f9c3..9986b66e 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/managers/ClientGsonManager.java +++ b/Launcher/src/main/java/pro/gravit/launcher/managers/ClientGsonManager.java @@ -1,7 +1,6 @@ package pro.gravit.launcher.managers; import com.google.gson.GsonBuilder; - import pro.gravit.launcher.client.ClientModuleManager; import pro.gravit.launcher.client.UserSettings; import pro.gravit.launcher.hwid.HWID; diff --git a/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java b/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java index fefcb03e..07b41d72 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java +++ b/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java @@ -1,7 +1,5 @@ package pro.gravit.launcher.managers; -import java.io.IOException; - import pro.gravit.launcher.Launcher; import pro.gravit.launcher.console.FeatureCommand; import pro.gravit.launcher.console.UnlockCommand; @@ -21,6 +19,8 @@ import pro.gravit.utils.helper.CommonHelper; import pro.gravit.utils.helper.LogHelper; +import java.io.IOException; + public class ConsoleManager { public static CommandHandler handler; public static Thread thread; diff --git a/Launcher/src/main/java/pro/gravit/launcher/managers/HasherStore.java b/Launcher/src/main/java/pro/gravit/launcher/managers/HasherStore.java index 10b6f3e6..3dab3a92 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/managers/HasherStore.java +++ b/Launcher/src/main/java/pro/gravit/launcher/managers/HasherStore.java @@ -1,12 +1,5 @@ package pro.gravit.launcher.managers; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Collection; -import java.util.LinkedList; -import java.util.Map; - import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.hasher.FileNameMatcher; import pro.gravit.launcher.hasher.HashedDir; @@ -15,6 +8,13 @@ import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Collection; +import java.util.LinkedList; +import java.util.Map; + public class HasherStore { public Map store; diff --git a/Launcher/src/main/java/pro/gravit/launcher/managers/SettingsManager.java b/Launcher/src/main/java/pro/gravit/launcher/managers/SettingsManager.java index c2525be2..55921ab5 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/managers/SettingsManager.java +++ b/Launcher/src/main/java/pro/gravit/launcher/managers/SettingsManager.java @@ -1,13 +1,5 @@ package pro.gravit.launcher.managers; -import java.io.IOException; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.attribute.BasicFileAttributes; - import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.NewLauncherSettings; import pro.gravit.launcher.client.DirBridge; @@ -18,6 +10,10 @@ import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; +import java.io.IOException; +import java.nio.file.*; +import java.nio.file.attribute.BasicFileAttributes; + public class SettingsManager extends JsonConfigurable { public static class StoreFileVisitor extends SimpleFileVisitor { @Override diff --git a/Launcher/src/main/java/pro/gravit/launcher/patches/FMLPatcher.java b/Launcher/src/main/java/pro/gravit/launcher/patches/FMLPatcher.java index 3fdf9ff5..79b7a085 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/patches/FMLPatcher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/patches/FMLPatcher.java @@ -1,5 +1,11 @@ package pro.gravit.launcher.patches; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.Label; +import org.objectweb.asm.MethodVisitor; +import org.objectweb.asm.Opcodes; +import pro.gravit.utils.helper.SecurityHelper; + import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; @@ -7,100 +13,93 @@ import java.util.Random; import java.util.Vector; -import org.objectweb.asm.ClassWriter; -import org.objectweb.asm.Label; -import org.objectweb.asm.MethodVisitor; -import org.objectweb.asm.Opcodes; - -import pro.gravit.utils.helper.SecurityHelper; - public class FMLPatcher extends ClassLoader implements Opcodes { - public static final MethodType EXITMH = MethodType.methodType(void.class, int.class); - public static volatile FMLPatcher INSTANCE = null; - public static final String[] PACKAGES = new String[] { "cpw.mods.fml.", "net.minecraftforge.fml.", "cpw.mods." }; - public static final Vector MHS = new Vector<>(); + public static final MethodType EXITMH = MethodType.methodType(void.class, int.class); + public static volatile FMLPatcher INSTANCE = null; + public static final String[] PACKAGES = new String[]{"cpw.mods.fml.", "net.minecraftforge.fml.", "cpw.mods."}; + public static final Vector MHS = new Vector<>(); - public static void apply() { - INSTANCE = new FMLPatcher(null); // Never cause ClassFormatError (fuck forge 1.14!!!) - for (String s : PACKAGES) { - String rMethod = randomStr(16); - try { - MHS.add(MethodHandles.publicLookup().findStatic(INSTANCE.def(s + randomStr(16), rMethod), rMethod, - EXITMH)); - } catch (NoSuchMethodException | IllegalAccessException e) { - // Simple ignore - other Forge - } - } - } + public static void apply() { + INSTANCE = new FMLPatcher(null); // Never cause ClassFormatError (fuck forge 1.14!!!) + for (String s : PACKAGES) { + String rMethod = randomStr(16); + try { + MHS.add(MethodHandles.publicLookup().findStatic(INSTANCE.def(s + randomStr(16), rMethod), rMethod, + EXITMH)); + } catch (NoSuchMethodException | IllegalAccessException e) { + // Simple ignore - other Forge + } + } + } - public static void exit(final int code) { - for (MethodHandle mh : MHS) - try { - mh.invoke(code); - } catch (Throwable ignored) { - } - } + public static void exit(final int code) { + for (MethodHandle mh : MHS) + try { + mh.invoke(code); + } catch (Throwable ignored) { + } + } - private static byte[] gen(final String name, final String exName) { // "cpw/mods/fml/SafeExitJVMLegacy", "exit" + private static byte[] gen(final String name, final String exName) { // "cpw/mods/fml/SafeExitJVMLegacy", "exit" - final ClassWriter classWriter = new ClassWriter(0); - MethodVisitor methodVisitor; + final ClassWriter classWriter = new ClassWriter(0); + MethodVisitor methodVisitor; - classWriter.visit(V1_8, ACC_PUBLIC | ACC_SUPER, name, null, "java/lang/Object", null); + classWriter.visit(V1_8, ACC_PUBLIC | ACC_SUPER, name, null, "java/lang/Object", null); - { - methodVisitor = classWriter.visitMethod(ACC_PUBLIC, "", "()V", null, null); - methodVisitor.visitCode(); - methodVisitor.visitVarInsn(ALOAD, 0); - methodVisitor.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "", "()V", false); - methodVisitor.visitInsn(RETURN); - methodVisitor.visitMaxs(1, 1); - methodVisitor.visitEnd(); - } - { - methodVisitor = classWriter.visitMethod(ACC_PUBLIC | ACC_STATIC, exName, "(I)V", null, null); - methodVisitor.visitCode(); - final Label label0 = new Label(); - final Label label1 = new Label(); - final Label label2 = new Label(); - methodVisitor.visitTryCatchBlock(label0, label1, label2, "java/lang/Throwable"); - methodVisitor.visitLabel(label0); - methodVisitor.visitMethodInsn(INVOKESTATIC, "java/lang/Runtime", "getRuntime", "()Ljava/lang/Runtime;", - false); - methodVisitor.visitVarInsn(ILOAD, 0); - methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Runtime", "halt", "(I)V", false); - methodVisitor.visitLabel(label1); - final Label label3 = new Label(); - methodVisitor.visitJumpInsn(GOTO, label3); - methodVisitor.visitLabel(label2); - methodVisitor.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/Throwable" }); - methodVisitor.visitVarInsn(ASTORE, 1); - methodVisitor.visitVarInsn(ILOAD, 0); - methodVisitor.visitMethodInsn(INVOKESTATIC, "java/lang/System", "exit", "(I)V", false); - methodVisitor.visitLabel(label3); - methodVisitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null); - methodVisitor.visitInsn(RETURN); - methodVisitor.visitMaxs(2, 2); - methodVisitor.visitEnd(); - } - classWriter.visitEnd(); - return classWriter.toByteArray(); - } + { + methodVisitor = classWriter.visitMethod(ACC_PUBLIC, "", "()V", null, null); + methodVisitor.visitCode(); + methodVisitor.visitVarInsn(ALOAD, 0); + methodVisitor.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "", "()V", false); + methodVisitor.visitInsn(RETURN); + methodVisitor.visitMaxs(1, 1); + methodVisitor.visitEnd(); + } + { + methodVisitor = classWriter.visitMethod(ACC_PUBLIC | ACC_STATIC, exName, "(I)V", null, null); + methodVisitor.visitCode(); + final Label label0 = new Label(); + final Label label1 = new Label(); + final Label label2 = new Label(); + methodVisitor.visitTryCatchBlock(label0, label1, label2, "java/lang/Throwable"); + methodVisitor.visitLabel(label0); + methodVisitor.visitMethodInsn(INVOKESTATIC, "java/lang/Runtime", "getRuntime", "()Ljava/lang/Runtime;", + false); + methodVisitor.visitVarInsn(ILOAD, 0); + methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Runtime", "halt", "(I)V", false); + methodVisitor.visitLabel(label1); + final Label label3 = new Label(); + methodVisitor.visitJumpInsn(GOTO, label3); + methodVisitor.visitLabel(label2); + methodVisitor.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[]{"java/lang/Throwable"}); + methodVisitor.visitVarInsn(ASTORE, 1); + methodVisitor.visitVarInsn(ILOAD, 0); + methodVisitor.visitMethodInsn(INVOKESTATIC, "java/lang/System", "exit", "(I)V", false); + methodVisitor.visitLabel(label3); + methodVisitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null); + methodVisitor.visitInsn(RETURN); + methodVisitor.visitMaxs(2, 2); + methodVisitor.visitEnd(); + } + classWriter.visitEnd(); + return classWriter.toByteArray(); + } - public static String randomStr(final int lenght) { - final String alphabet = "abcdefghijklmnopqrstuvwxyz"; - final StringBuilder sb = new StringBuilder(lenght); - final Random random = SecurityHelper.newRandom(); - for (int i = 0; i < lenght; i++) - sb.append(alphabet.charAt(random.nextInt(26))); - return sb.toString(); - } + public static String randomStr(final int lenght) { + final String alphabet = "abcdefghijklmnopqrstuvwxyz"; + final StringBuilder sb = new StringBuilder(lenght); + final Random random = SecurityHelper.newRandom(); + for (int i = 0; i < lenght; i++) + sb.append(alphabet.charAt(random.nextInt(26))); + return sb.toString(); + } - public FMLPatcher(final ClassLoader cl) { - super(cl); - } + public FMLPatcher(final ClassLoader cl) { + super(cl); + } - public Class def(final String name, final String exName) { - return super.defineClass(name, ByteBuffer.wrap(gen(name.replace('.', '/'), exName)), null); - } + public Class def(final String name, final String exName) { + return super.defineClass(name, ByteBuffer.wrap(gen(name.replace('.', '/'), exName)), null); + } } diff --git a/Launcher/src/main/java/pro/gravit/launcher/utils/DirWatcher.java b/Launcher/src/main/java/pro/gravit/launcher/utils/DirWatcher.java index 213b073f..631ee137 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/utils/DirWatcher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/utils/DirWatcher.java @@ -1,20 +1,5 @@ package pro.gravit.launcher.utils; -import java.io.IOException; -import java.nio.file.ClosedWatchServiceException; -import java.nio.file.FileVisitResult; -import java.nio.file.Path; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.StandardWatchEventKinds; -import java.nio.file.WatchEvent; -import java.nio.file.WatchEvent.Kind; -import java.nio.file.WatchKey; -import java.nio.file.WatchService; -import java.nio.file.attribute.BasicFileAttributes; -import java.util.Deque; -import java.util.LinkedList; -import java.util.Objects; - import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.hasher.FileNameMatcher; import pro.gravit.launcher.hasher.HashedDir; @@ -25,6 +10,14 @@ import pro.gravit.utils.helper.JVMHelper.OS; import pro.gravit.utils.helper.LogHelper; +import java.io.IOException; +import java.nio.file.*; +import java.nio.file.WatchEvent.Kind; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.Deque; +import java.util.LinkedList; +import java.util.Objects; + public final class DirWatcher implements Runnable, AutoCloseable { private final class RegisterFileVisitor extends SimpleFileVisitor { diff --git a/Launcher/src/main/java/pro/gravit/launcher/utils/NativeJVMHalt.java b/Launcher/src/main/java/pro/gravit/launcher/utils/NativeJVMHalt.java index ef5a5083..257808d0 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/utils/NativeJVMHalt.java +++ b/Launcher/src/main/java/pro/gravit/launcher/utils/NativeJVMHalt.java @@ -1,13 +1,11 @@ package pro.gravit.launcher.utils; -import java.awt.event.WindowEvent; - -import javax.swing.JFrame; -import javax.swing.WindowConstants; - import pro.gravit.launcher.patches.FMLPatcher; import pro.gravit.utils.helper.JVMHelper; +import javax.swing.*; +import java.awt.event.WindowEvent; + public final class NativeJVMHalt { public NativeJVMHalt(int haltCode) { this.haltCode = haltCode; @@ -26,21 +24,22 @@ private boolean aaabBooleanC_D() { public static void haltA(int code) { NativeJVMHalt halt = new NativeJVMHalt(code); try { - JVMHelper.RUNTIME.exit(code); + JVMHelper.RUNTIME.exit(code); } catch (Throwable ignored) { try { - new WindowShutdown(); + new WindowShutdown(); } catch (Throwable ignored1) { } } try { - FMLPatcher.exit(code); - } catch (Throwable ignored) { } - + FMLPatcher.exit(code); + } catch (Throwable ignored) { + } + halt.aaabbb38C_D(); boolean a = halt.aaabBooleanC_D(); System.out.println(a); - + } public static boolean initFunc() { @@ -48,12 +47,12 @@ public static boolean initFunc() { } public static class WindowShutdown extends JFrame { - private static final long serialVersionUID = 6321323663070818367L; + private static final long serialVersionUID = 6321323663070818367L; - public WindowShutdown() { - super(); - super.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); - super.processWindowEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING)); - } + public WindowShutdown() { + super(); + super.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + super.processWindowEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING)); + } } } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/AutogenConfig.java b/LauncherAPI/src/main/java/pro/gravit/launcher/AutogenConfig.java index 290a1e38..67f19b48 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/AutogenConfig.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/AutogenConfig.java @@ -24,6 +24,6 @@ public class AutogenConfig { } public void initModules() { - + } } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/ClientPermissions.java b/LauncherAPI/src/main/java/pro/gravit/launcher/ClientPermissions.java index f9aabbf1..7201063c 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/ClientPermissions.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/ClientPermissions.java @@ -1,11 +1,11 @@ package pro.gravit.launcher; -import java.io.IOException; -import java.util.StringJoiner; - import pro.gravit.launcher.serialize.HInput; import pro.gravit.launcher.serialize.HOutput; +import java.io.IOException; +import java.util.StringJoiner; + public class ClientPermissions { public static final ClientPermissions DEFAULT = new ClientPermissions(); @LauncherAPI diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/Launcher.java b/LauncherAPI/src/main/java/pro/gravit/launcher/Launcher.java index b200f191..70dafc79 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/Launcher.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/Launcher.java @@ -1,5 +1,12 @@ package pro.gravit.launcher; +import pro.gravit.launcher.managers.GsonManager; +import pro.gravit.launcher.profiles.ClientProfile; +import pro.gravit.launcher.serialize.HInput; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.LogHelper; +import pro.gravit.utils.helper.SecurityHelper; + import java.io.IOException; import java.net.URL; import java.nio.file.NoSuchFileException; @@ -10,13 +17,6 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.regex.Pattern; -import pro.gravit.launcher.managers.GsonManager; -import pro.gravit.launcher.profiles.ClientProfile; -import pro.gravit.launcher.serialize.HInput; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.LogHelper; -import pro.gravit.utils.helper.SecurityHelper; - public final class Launcher { // Authlib constants diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java b/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java index e5d89753..1d64cf48 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java @@ -1,15 +1,5 @@ package pro.gravit.launcher; -import java.io.IOException; -import java.security.cert.CertificateException; -import java.security.interfaces.ECPublicKey; -import java.security.spec.InvalidKeySpecException; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Set; - import pro.gravit.launcher.serialize.HInput; import pro.gravit.launcher.serialize.HOutput; import pro.gravit.launcher.serialize.stream.StreamObject; @@ -17,6 +7,12 @@ import pro.gravit.utils.helper.VerifyHelper; import pro.gravit.utils.verify.LauncherTrustManager; +import java.io.IOException; +import java.security.cert.CertificateException; +import java.security.interfaces.ECPublicKey; +import java.security.spec.InvalidKeySpecException; +import java.util.*; + public final class LauncherConfig extends StreamObject { private static final AutogenConfig config = new AutogenConfig(); private static final SecureAutogenConfig secureConfig = new SecureAutogenConfig(); @@ -47,7 +43,7 @@ public static AutogenConfig getAutogenConfig() { public final String guardLicenseKey; public final String guardLicenseEncryptKey; public final String guardType; - + public final String secureCheckHash; public final String secureCheckSalt; public final String passwordEncryptKey; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/SecureAutogenConfig.java b/LauncherAPI/src/main/java/pro/gravit/launcher/SecureAutogenConfig.java index a56ff76d..6a0b9443 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/SecureAutogenConfig.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/SecureAutogenConfig.java @@ -7,7 +7,7 @@ public class SecureAutogenConfig { public SecureAutogenConfig() { //Пока не реализован SecureLauncherConfigurator - certificates = new byte[][] { + certificates = new byte[][]{ ("-----BEGIN CERTIFICATE-----\n" + "MIIFyjCCA7KgAwIBAgIRALnsjNjfvOTXfla3fX1fNEUwDQYJKoZIhvcNAQELBQAw\n" + "WTELMAkGA1UEBhMCUlUxFzAVBgNVBAoTDkdyYXZpdFRydXN0IENBMRAwDgYDVQQL\n" + diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/config/JsonConfigurable.java b/LauncherAPI/src/main/java/pro/gravit/launcher/config/JsonConfigurable.java index 90258efc..9d7adec5 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/config/JsonConfigurable.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/config/JsonConfigurable.java @@ -1,10 +1,10 @@ package pro.gravit.launcher.config; +import pro.gravit.launcher.LauncherAPI; + import java.lang.reflect.Type; import java.nio.file.Path; -import pro.gravit.launcher.LauncherAPI; - public abstract class JsonConfigurable implements JsonConfigurableInterface { private transient final Type type; protected transient final Path configPath; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/config/JsonConfigurableInterface.java b/LauncherAPI/src/main/java/pro/gravit/launcher/config/JsonConfigurableInterface.java index 7b80756e..e6d65d08 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/config/JsonConfigurableInterface.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/config/JsonConfigurableInterface.java @@ -17,45 +17,52 @@ public interface JsonConfigurableInterface { default void saveConfig() throws IOException { saveConfig(getPath()); } + @LauncherAPI default void loadConfig() throws IOException { loadConfig(getPath()); } + @LauncherAPI default void saveConfig(Gson gson, Path configPath) throws IOException { try (BufferedWriter writer = IOHelper.newWriter(configPath)) { gson.toJson(getConfig(), getType(), writer); } } + @LauncherAPI default void loadConfig(Gson gson, Path configPath) throws IOException { if (generateConfigIfNotExists(configPath)) return; try (BufferedReader reader = IOHelper.newReader(configPath)) { setConfig(gson.fromJson(reader, getType())); - } catch (Exception e) - { + } catch (Exception e) { LogHelper.error(e); resetConfig(configPath); } } + @LauncherAPI default void saveConfig(Path configPath) throws IOException { saveConfig(Launcher.gsonManager.configGson, configPath); } + @LauncherAPI default void loadConfig(Path configPath) throws IOException { loadConfig(Launcher.gsonManager.configGson, configPath); } + @LauncherAPI default void resetConfig() throws IOException { setConfig(getDefaultConfig()); saveConfig(); } + @LauncherAPI default void resetConfig(Path newPath) throws IOException { setConfig(getDefaultConfig()); saveConfig(newPath); } + @LauncherAPI default boolean generateConfigIfNotExists(Path path) throws IOException { if (IOHelper.isFile(path)) @@ -63,6 +70,7 @@ default boolean generateConfigIfNotExists(Path path) throws IOException { resetConfig(path); return true; } + @LauncherAPI default boolean generateConfigIfNotExists() throws IOException { if (IOHelper.isFile(getPath())) @@ -70,12 +78,16 @@ default boolean generateConfigIfNotExists() throws IOException { resetConfig(); return true; } + @LauncherAPI T getConfig(); + @LauncherAPI T getDefaultConfig(); + @LauncherAPI void setConfig(T config); + @LauncherAPI Path getPath(); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfig.java b/LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfig.java index 764cab2b..507376d0 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfig.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfig.java @@ -11,6 +11,7 @@ protected SimpleConfig(Class type, Path configPath) { this.type = type; this.configPath = configPath; } + @SuppressWarnings("unchecked") @Override public T getConfig() { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java b/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java index a9eeaa36..643e50e3 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java @@ -1,5 +1,16 @@ package pro.gravit.launcher.downloader; +import org.apache.http.HttpResponse; +import org.apache.http.client.ResponseHandler; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.impl.client.LaxRedirectStrategy; +import pro.gravit.utils.helper.CommonHelper; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.LogHelper; +import pro.gravit.utils.helper.VerifyHelper; + import java.io.EOFException; import java.io.IOException; import java.io.InputStream; @@ -11,37 +22,19 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.List; -import java.util.concurrent.Callable; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; +import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicInteger; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; -import org.apache.http.HttpResponse; -import org.apache.http.client.ResponseHandler; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.impl.client.LaxRedirectStrategy; - -import pro.gravit.utils.helper.CommonHelper; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.LogHelper; -import pro.gravit.utils.helper.VerifyHelper; - public class ListDownloader { private static final AtomicInteger COUNTER_THR = new AtomicInteger(0); - private static final ThreadFactory FACTORY = r -> CommonHelper.newThread("Downloader Thread #" + COUNTER_THR.incrementAndGet(), true, r); + private static final ThreadFactory FACTORY = r -> CommonHelper.newThread("Downloader Thread #" + COUNTER_THR.incrementAndGet(), true, r); + + private static ExecutorService newExecutor() { + return new ThreadPoolExecutor(0, VerifyHelper.verifyInt(Integer.parseInt(System.getProperty("launcher.downloadThreads", "3")), VerifyHelper.POSITIVE, "Thread max count must be positive."), 5, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), FACTORY); + } - private static ExecutorService newExecutor() { - return new ThreadPoolExecutor(0, VerifyHelper.verifyInt(Integer.parseInt(System.getProperty("launcher.downloadThreads", "3")), VerifyHelper.POSITIVE, "Thread max count must be positive."), 5, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), FACTORY); - } - @FunctionalInterface public interface DownloadCallback { void stateChanged(String filename, long downloadedSize, long size); @@ -66,8 +59,8 @@ public void download(String base, List applies, Path dstDirFile, D try (CloseableHttpClient httpclient = HttpClients.custom().setUserAgent(IOHelper.USER_AGENT) .setRedirectStrategy(new LaxRedirectStrategy()) .build()) { - applies.sort(Comparator.comparingLong(a -> a.size)); - List> toExec = new ArrayList<>(); + applies.sort(Comparator.comparingLong(a -> a.size)); + List> toExec = new ArrayList<>(); URI baseUri = new URI(base); String scheme = baseUri.getScheme(); String host = baseUri.getHost(); @@ -81,28 +74,28 @@ public void download(String base, List applies, Path dstDirFile, D callback.stateChanged(apply.apply, 0L, apply.size); Path targetPath = dstDirFile.resolve(apply.apply); toExec.add(() -> { - if (LogHelper.isDebugEnabled()) + if (LogHelper.isDebugEnabled()) LogHelper.debug("Download URL: %s to file %s dir: %s", u.toString(), targetPath.toAbsolutePath().toString(), dstDirFile.toAbsolutePath().toString()); - try { - httpclient.execute(new HttpGet(u), new FileDownloadResponseHandler(targetPath, apply, callback, totalCallback, false)); - } catch (IOException e) { - excs.add(e); - } - return null; + try { + httpclient.execute(new HttpGet(u), new FileDownloadResponseHandler(targetPath, apply, callback, totalCallback, false)); + } catch (IOException e) { + excs.add(e); + } + return null; }); } try { ExecutorService e = newExecutor(); e.invokeAll(toExec); e.shutdown(); - e.awaitTermination(4, TimeUnit.HOURS); - } catch (InterruptedException t) { - LogHelper.error(t); - } + e.awaitTermination(4, TimeUnit.HOURS); + } catch (InterruptedException t) { + LogHelper.error(t); + } if (!excs.isEmpty()) { - IOException toThrow = excs.remove(0); - excs.forEach(toThrow::addSuppressed); - throw toThrow; + IOException toThrow = excs.remove(0); + excs.forEach(toThrow::addSuppressed); + throw toThrow; } } } @@ -125,8 +118,7 @@ public void downloadZip(String base, List applies, Path dstDirFile String name = entry.getName(); callback.stateChanged(name, 0L, entry.getSize()); LogHelper.subInfo("Downloading file: '%s'", name); - if(fullDownload || applies.stream().anyMatch((t) -> t.apply.equals(name))) - { + if (fullDownload || applies.stream().anyMatch((t) -> t.apply.equals(name))) { Path fileName = IOHelper.toPath(name); transfer(input, dstDirFile.resolve(fileName), fileName.toString(), entry.getSize(), callback, totalCallback); } @@ -184,13 +176,11 @@ public FileDownloadResponseHandler(Path target, DownloadCallback callback, Downl public Path handleResponse(HttpResponse response) throws IOException { InputStream source = response.getEntity().getContent(); int returnCode = response.getStatusLine().getStatusCode(); - if(returnCode != 200) - { + if (returnCode != 200) { throw new IllegalStateException(String.format("Request download file %s return code %d", target.toString(), returnCode)); } long contentLength = response.getEntity().getContentLength(); - if (task != null && contentLength != task.size) - { + if (task != null && contentLength != task.size) { LogHelper.warning("Missing content length: expected %d | found %d", task.size, contentLength); } if (zip) { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/ControlEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/ControlEvent.java index e83367f9..399dd4dc 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/ControlEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/ControlEvent.java @@ -5,7 +5,7 @@ //Набор стандартных событий public class ControlEvent { @SuppressWarnings("unused") - private static final UUID uuid = UUID.fromString("f1051a64-0cd0-4ed8-8430-d856a196e91f"); + private static final UUID uuid = UUID.fromString("f1051a64-0cd0-4ed8-8430-d856a196e91f"); public enum ControlCommand { STOP, START, PAUSE, CONTINUE, CRASH diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/ExceptionEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/ExceptionEvent.java index e67892b8..c44bd9d9 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/ExceptionEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/ExceptionEvent.java @@ -7,6 +7,7 @@ public ExceptionEvent(Exception e) { this.message = e.getMessage(); this.clazz = e.getClass().getName(); } + @LauncherNetworkAPI public final String message; @LauncherNetworkAPI diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/RequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/RequestEvent.java index a833c872..f2d47803 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/RequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/RequestEvent.java @@ -1,10 +1,10 @@ package pro.gravit.launcher.events; -import java.util.UUID; - import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.request.WebSocketEvent; +import java.util.UUID; + /** * The class of all request events sent by the server to the client */ diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/CheckServerRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/CheckServerRequestEvent.java index f28a2a33..d4fc571a 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/CheckServerRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/CheckServerRequestEvent.java @@ -1,15 +1,15 @@ package pro.gravit.launcher.events.request; -import java.util.UUID; - import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.RequestEvent; import pro.gravit.launcher.profiles.PlayerProfile; +import java.util.UUID; + public class CheckServerRequestEvent extends RequestEvent { @SuppressWarnings("unused") - private static final UUID _uuid = UUID.fromString("8801d07c-51ba-4059-b61d-fe1f1510b28a"); + private static final UUID _uuid = UUID.fromString("8801d07c-51ba-4059-b61d-fe1f1510b28a"); @LauncherNetworkAPI public UUID uuid; @LauncherNetworkAPI diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ErrorRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ErrorRequestEvent.java index b97e3c28..07b0107c 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ErrorRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ErrorRequestEvent.java @@ -1,10 +1,10 @@ package pro.gravit.launcher.events.request; -import java.util.UUID; - import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.RequestEvent; +import java.util.UUID; + public class ErrorRequestEvent extends RequestEvent { public static UUID uuid = UUID.fromString("0af22bc7-aa01-4881-bdbb-dc62b3cdac96"); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetAvailabilityAuthRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetAvailabilityAuthRequestEvent.java index 2a69291b..28df28df 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetAvailabilityAuthRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetAvailabilityAuthRequestEvent.java @@ -1,10 +1,10 @@ package pro.gravit.launcher.events.request; -import java.util.List; - import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.RequestEvent; +import java.util.List; + public class GetAvailabilityAuthRequestEvent extends RequestEvent { public static class AuthAvailability { @LauncherNetworkAPI diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/JoinServerRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/JoinServerRequestEvent.java index 4f9d15cb..4ef71764 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/JoinServerRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/JoinServerRequestEvent.java @@ -1,14 +1,14 @@ package pro.gravit.launcher.events.request; -import java.util.UUID; - import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.RequestEvent; +import java.util.UUID; + public class JoinServerRequestEvent extends RequestEvent { @SuppressWarnings("unused") - private static final UUID uuid = UUID.fromString("2a12e7b5-3f4a-4891-a2f9-ea141c8e1995"); + private static final UUID uuid = UUID.fromString("2a12e7b5-3f4a-4891-a2f9-ea141c8e1995"); public JoinServerRequestEvent(boolean allow) { this.allow = allow; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/LauncherRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/LauncherRequestEvent.java index 660fef06..0a160368 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/LauncherRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/LauncherRequestEvent.java @@ -1,14 +1,14 @@ package pro.gravit.launcher.events.request; -import java.util.UUID; - import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.RequestEvent; +import java.util.UUID; + public class LauncherRequestEvent extends RequestEvent { @SuppressWarnings("unused") - private static final UUID uuid = UUID.fromString("d54cc12a-4f59-4f23-9b10-f527fdd2e38f"); + private static final UUID uuid = UUID.fromString("d54cc12a-4f59-4f23-9b10-f527fdd2e38f"); @LauncherNetworkAPI public String url; @LauncherNetworkAPI diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ProfileByUUIDRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ProfileByUUIDRequestEvent.java index a08c126e..b2bad307 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ProfileByUUIDRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ProfileByUUIDRequestEvent.java @@ -1,15 +1,15 @@ package pro.gravit.launcher.events.request; -import java.util.UUID; - import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.RequestEvent; import pro.gravit.launcher.profiles.PlayerProfile; +import java.util.UUID; + public class ProfileByUUIDRequestEvent extends RequestEvent { @SuppressWarnings("unused") - private static final UUID uuid = UUID.fromString("b9014cf3-4b95-4d38-8c5f-867f190a18a0"); + private static final UUID uuid = UUID.fromString("b9014cf3-4b95-4d38-8c5f-867f190a18a0"); @LauncherNetworkAPI public String error; @LauncherNetworkAPI diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ProfileByUsernameRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ProfileByUsernameRequestEvent.java index 84ceb288..2fe5feb4 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ProfileByUsernameRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ProfileByUsernameRequestEvent.java @@ -1,15 +1,15 @@ package pro.gravit.launcher.events.request; -import java.util.UUID; - import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.RequestEvent; import pro.gravit.launcher.profiles.PlayerProfile; +import java.util.UUID; + public class ProfileByUsernameRequestEvent extends RequestEvent { @SuppressWarnings("unused") - private static final UUID uuid = UUID.fromString("06204302-ff6b-4779-b97d-541e3bc39aa1"); + private static final UUID uuid = UUID.fromString("06204302-ff6b-4779-b97d-541e3bc39aa1"); @LauncherNetworkAPI public String error; @LauncherNetworkAPI diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ProfilesRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ProfilesRequestEvent.java index c1611d62..383becab 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ProfilesRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ProfilesRequestEvent.java @@ -1,16 +1,16 @@ package pro.gravit.launcher.events.request; -import java.util.List; -import java.util.UUID; - import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.RequestEvent; import pro.gravit.launcher.profiles.ClientProfile; +import java.util.List; +import java.util.UUID; + public class ProfilesRequestEvent extends RequestEvent { @SuppressWarnings("unused") - private static final UUID uuid = UUID.fromString("2f26fbdf-598a-46dd-92fc-1699c0e173b1"); + private static final UUID uuid = UUID.fromString("2f26fbdf-598a-46dd-92fc-1699c0e173b1"); @LauncherNetworkAPI public List profiles; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/SetProfileRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/SetProfileRequestEvent.java index ed6f8afe..6596ac9a 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/SetProfileRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/SetProfileRequestEvent.java @@ -1,15 +1,15 @@ package pro.gravit.launcher.events.request; -import java.util.UUID; - import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.RequestEvent; import pro.gravit.launcher.profiles.ClientProfile; +import java.util.UUID; + public class SetProfileRequestEvent extends RequestEvent { @SuppressWarnings("unused") - private static final UUID uuid = UUID.fromString("08c0de9e-4364-4152-9066-8354a3a48541"); + private static final UUID uuid = UUID.fromString("08c0de9e-4364-4152-9066-8354a3a48541"); @LauncherNetworkAPI public final ClientProfile newProfile; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/UpdateListRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/UpdateListRequestEvent.java index 1051d790..5f54432c 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/UpdateListRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/UpdateListRequestEvent.java @@ -1,15 +1,15 @@ package pro.gravit.launcher.events.request; -import java.util.HashSet; -import java.util.UUID; - import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.RequestEvent; +import java.util.HashSet; +import java.util.UUID; + public class UpdateListRequestEvent extends RequestEvent { @SuppressWarnings("unused") - private static final UUID uuid = UUID.fromString("5fa836ae-6b61-401c-96ac-d8396f07ec6b"); + private static final UUID uuid = UUID.fromString("5fa836ae-6b61-401c-96ac-d8396f07ec6b"); @LauncherNetworkAPI public final HashSet dirs; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWIDCheckHelper.java b/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWIDCheckHelper.java index 9bac200f..39249b2a 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWIDCheckHelper.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWIDCheckHelper.java @@ -3,8 +3,7 @@ import pro.gravit.utils.helper.LogHelper; public class HWIDCheckHelper { - public static int checkString(String str) - { + public static int checkString(String str) { int result = 0; //Считаем символы char lastChar = '\0'; @@ -15,42 +14,32 @@ public static int checkString(String str) int lastCharTypeCombo = 0; int wtfCharTypeCombo = 0; boolean skipLastCharType = true; - for(char c : str.toCharArray()) - { - if(c == lastChar || Math.abs(c - lastChar) == 1 || - ( ( lastChar == '0' || lastChar == '9' ) && ( c == 'A' || c == 'a' ))) //Переход с 0 или 9 на A или a + for (char c : str.toCharArray()) { + if (c == lastChar || Math.abs(c - lastChar) == 1 || + ((lastChar == '0' || lastChar == '9') && (c == 'A' || c == 'a'))) //Переход с 0 или 9 на A или a { combo++; - } - else - { + } else { combo = 1; } lastChar = c; - if(maxCombo < combo) + if (maxCombo < combo) maxCombo = combo; int charType = getCharType(c); - if(lastCharType == charType) { + if (lastCharType == charType) { lastCharTypeCombo++; //Нам подсунули серию из идущих подряд спец символов. Что за? - if((charType == -1 || charType == 3) && lastCharTypeCombo > 2) - { - wtfCharTypeCombo+=3; + if ((charType == -1 || charType == 3) && lastCharTypeCombo > 2) { + wtfCharTypeCombo += 3; } //Нам подсунули серию из слишком большого числа идущих подряд чисел. Что за? - if((charType == 0) && lastCharTypeCombo > 4) - { + if ((charType == 0) && lastCharTypeCombo > 4) { wtfCharTypeCombo++; } - } - else - { - if(skipLastCharType && ( charType == -1 || charType == 3 )) - { + } else { + if (skipLastCharType && (charType == -1 || charType == 3)) { skipLastCharType = false; - } - else - { + } else { skipLastCharType = true; lastCharType = charType; } @@ -59,16 +48,16 @@ public static int checkString(String str) //Считаем результат LogHelper.debug("HWID Checker maxCombo %d", maxCombo); LogHelper.debug("HWID Checker wtfCharTypeCombo %d", wtfCharTypeCombo); - if(maxCombo > 3) result+= maxCombo * 3; - if(wtfCharTypeCombo > 1) result+= wtfCharTypeCombo * 2; + if (maxCombo > 3) result += maxCombo * 3; + if (wtfCharTypeCombo > 1) result += wtfCharTypeCombo * 2; return result; } - public static int getCharType(char c) - { - if(c >= '0' && c <= '9') return 0; - if(c >= 'A' && c <= 'Z') return 1; - if(c >= 'a' && c <= 'z') return 2; - if(c == ' ' || c == '-' || c == '_') return 3; + + public static int getCharType(char c) { + if (c >= '0' && c <= '9') return 0; + if (c >= 'A' && c <= 'Z') return 1; + if (c >= 'a' && c <= 'z') return 2; + if (c == ' ' || c == '-' || c == '_') return 3; return -1; } } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWIDProvider.java b/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWIDProvider.java index 28dd6db2..ae82c808 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWIDProvider.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWIDProvider.java @@ -4,8 +4,8 @@ public class HWIDProvider { public static final ProviderMap hwids = new ProviderMap<>(); - public static void registerHWIDs() - { + + public static void registerHWIDs() { hwids.register("oshi", OshiHWID.class); hwids.register("no", NoHWID.class); } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/OshiHWID.java b/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/OshiHWID.java index efced953..405a2f9c 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/OshiHWID.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/OshiHWID.java @@ -1,12 +1,11 @@ package pro.gravit.launcher.hwid; +import com.google.gson.Gson; +import pro.gravit.launcher.LauncherAPI; + import java.util.Objects; import java.util.StringJoiner; -import com.google.gson.Gson; - -import pro.gravit.launcher.LauncherAPI; - public class OshiHWID implements HWID { public static Gson gson = new Gson(); @LauncherAPI @@ -28,7 +27,7 @@ public int getLevel() //Уровень доверия, насколько уни if (serialNumber != null) result += isRealSerialNumber() ? 20 : 3; if (HWDiskSerial != null && !HWDiskSerial.isEmpty()) result += 38; if (processorID != null && !processorID.isEmpty()) result += 15; - if (macAddr != null && !macAddr.isEmpty()) result += 25; + if (macAddr != null && !macAddr.isEmpty()) result += 25; return result; } @@ -65,14 +64,14 @@ public void normalize() { processorID = processorID.trim(); macAddr = macAddr.trim(); } - public boolean isRealSerialNumber() - { - if(serialNumber.isEmpty()) return false; - if(serialNumber.equals("System Serial Number")) return false; - if(serialNumber.equals("To be filled by O.E.M.")) return false; - if(serialNumber.equals("unknown")) return false; - if(serialNumber.equals("None")) return false; - if(serialNumber.equals("Default string")) return false; + + public boolean isRealSerialNumber() { + if (serialNumber.isEmpty()) return false; + if (serialNumber.equals("System Serial Number")) return false; + if (serialNumber.equals("To be filled by O.E.M.")) return false; + if (serialNumber.equals("unknown")) return false; + if (serialNumber.equals("None")) return false; + if (serialNumber.equals("Default string")) return false; return true; } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/managers/ConfigManager.java b/LauncherAPI/src/main/java/pro/gravit/launcher/managers/ConfigManager.java index eaa9ec79..cda96970 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/managers/ConfigManager.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/managers/ConfigManager.java @@ -1,14 +1,14 @@ package pro.gravit.launcher.managers; +import pro.gravit.launcher.config.JsonConfigurable; +import pro.gravit.utils.helper.LogHelper; +import pro.gravit.utils.helper.VerifyHelper; + import java.io.IOException; import java.nio.file.Path; import java.util.HashMap; import java.util.Objects; -import pro.gravit.launcher.config.JsonConfigurable; -import pro.gravit.utils.helper.LogHelper; -import pro.gravit.utils.helper.VerifyHelper; - @SuppressWarnings("rawtypes") public class ConfigManager { private final HashMap CONFIGURABLE = new HashMap<>(); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/managers/SimpleModulesConfigManager.java b/LauncherAPI/src/main/java/pro/gravit/launcher/managers/SimpleModulesConfigManager.java index 0bea294b..8c185f16 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/managers/SimpleModulesConfigManager.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/managers/SimpleModulesConfigManager.java @@ -1,14 +1,14 @@ package pro.gravit.launcher.managers; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; - import pro.gravit.launcher.config.SimpleConfigurable; import pro.gravit.launcher.modules.ModulesConfigManager; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + public class SimpleModulesConfigManager implements ModulesConfigManager { public final Path configDir; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModule.java b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModule.java index 838cb1dd..11501b42 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModule.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModule.java @@ -7,7 +7,7 @@ public abstract class LauncherModule { private LauncherModulesContext context; @SuppressWarnings("rawtypes") - private final Map, EventHandler> eventMap = new HashMap<>(); + private final Map, EventHandler> eventMap = new HashMap<>(); protected LauncherModulesManager modulesManager; protected final LauncherModuleInfo moduleInfo; protected ModulesConfigManager modulesConfigManager; @@ -29,8 +29,7 @@ public LauncherModuleInfo getModuleInfo() { /** * Module initialization status at the current time */ - public enum InitStatus - { + public enum InitStatus { /** * When creating an object */ @@ -63,13 +62,13 @@ public boolean isAvailable() { private final boolean isAvailable; } + @FunctionalInterface - public interface EventHandler - { + public interface EventHandler { void event(T e); } - public static class Event - { + + public static class Event { public boolean isCancel() { return cancel; } @@ -94,11 +93,11 @@ public LauncherModule setInitStatus(InitStatus initStatus) { /** * The internal method used by the ModuleManager * DO NOT TOUCH + * * @param context Private context */ - public void setContext(LauncherModulesContext context) - { - if(this.context != null) throw new IllegalStateException("Module already set context"); + public void setContext(LauncherModulesContext context) { + if (this.context != null) throw new IllegalStateException("Module already set context"); this.context = context; this.modulesManager = context.getModulesManager(); this.modulesConfigManager = context.getModulesConfigManager(); @@ -119,9 +118,10 @@ public void setContext(LauncherModulesContext context) public void preInitAction() { //NOP } - public LauncherModule preInit() - { - if(!initStatus.equals(InitStatus.PRE_INIT_WAIT)) throw new IllegalStateException("PreInit not allowed in current state"); + + public LauncherModule preInit() { + if (!initStatus.equals(InitStatus.PRE_INIT_WAIT)) + throw new IllegalStateException("PreInit not allowed in current state"); initStatus = InitStatus.PRE_INIT; preInitAction(); initStatus = InitStatus.INIT_WAIT; @@ -139,41 +139,40 @@ public LauncherModule preInit() * - Modify module description, dependencies * - Add modules * - Read configuration + * * @param initContext null on module initialization during boot or startup - * Not null during module initialization while running + * Not null during module initialization while running */ public abstract void init(LauncherInitContext initContext); /** * Registers an event handler for the current module + * * @param handle your event handler * @param tClass event class - * @param event type + * @param event type * @return true if adding a handler was successful */ - protected boolean registerEvent(EventHandler handle, Class tClass) - { + protected boolean registerEvent(EventHandler handle, Class tClass) { eventMap.put(tClass, handle); return true; } /** * Call the handler of the current module + * * @param event event handled - * @param event type + * @param event type */ @SuppressWarnings("unchecked") - public final void callEvent(T event) - { + public final void callEvent(T event) { Class tClass = event.getClass(); - for(@SuppressWarnings("rawtypes") Map.Entry, EventHandler> e : eventMap.entrySet()) - { + for (@SuppressWarnings("rawtypes") Map.Entry, EventHandler> e : eventMap.entrySet()) { - if(e.getKey().isAssignableFrom(tClass)) - { + if (e.getKey().isAssignableFrom(tClass)) { e.getValue().event(event); - if(event.isCancel()) return; + if (event.isCancel()) return; } } } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModuleInfo.java b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModuleInfo.java index 996618a5..0237a9ee 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModuleInfo.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModuleInfo.java @@ -22,7 +22,7 @@ public LauncherModuleInfo(String name, Version version) { public LauncherModuleInfo(String name) { this.name = name; - this.version = new Version(1,0,0); + this.version = new Version(1, 0, 0); this.priority = 0; this.dependencies = new String[0]; providers = new String[0]; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModulesContext.java b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModulesContext.java index 77de956d..317e2d31 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModulesContext.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModulesContext.java @@ -2,5 +2,6 @@ public interface LauncherModulesContext { LauncherModulesManager getModulesManager(); + ModulesConfigManager getModulesConfigManager(); } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModulesManager.java b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModulesManager.java index 94f3a6e5..d7fdb7bf 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModulesManager.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModulesManager.java @@ -1,39 +1,48 @@ package pro.gravit.launcher.modules; +import pro.gravit.utils.Version; + import java.io.IOException; import java.nio.file.Path; import java.util.List; import java.util.function.Predicate; -import pro.gravit.utils.Version; - public interface LauncherModulesManager { LauncherModule loadModule(LauncherModule module); + LauncherModule loadModule(Path file) throws IOException; + LauncherModule getModule(String name); + LauncherModule getCoreModule(); - default boolean containsModule(String name) - { + + default boolean containsModule(String name) { return getModule(name) != null; } - default boolean containsModule(Class clazz) - { + default boolean containsModule(Class clazz) { return getModule(clazz) != null; } + ClassLoader getModuleClassLoader(); + ModulesConfigManager getConfigManager(); + T getModule(Class clazz); + T getModuleByInterface(Class clazz); + List getModulesByInterface(Class clazz); + T findModule(Class clazz, Predicate versionPredicate); /** * Invoke event processing for all modules. * Event processing is carried out in the order of the modules in the list (sorted by priority) + * * @param event event handled - * @param event type + * @param event type */ void invokeEvent(T event); } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/ModulesConfigManager.java b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/ModulesConfigManager.java index 1016ac14..570059a7 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/ModulesConfigManager.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/ModulesConfigManager.java @@ -13,13 +13,11 @@ public interface ModulesConfigManager { SimpleConfigurable getConfigurable(Class tClass, Path configPath); - default SimpleConfigurable getConfigurable(Class tClass, String moduleName) - { + default SimpleConfigurable getConfigurable(Class tClass, String moduleName) { return getConfigurable(tClass, getModuleConfig(moduleName)); } - default SimpleConfigurable getConfigurable(Class tClass, String moduleName, String configName) - { + default SimpleConfigurable getConfigurable(Class tClass, String moduleName, String configName) { return getConfigurable(tClass, getModuleConfig(moduleName, configName)); } } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/events/PreGsonPhase.java b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/events/PreGsonPhase.java index 25dcb4cb..b47f2a6b 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/events/PreGsonPhase.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/events/PreGsonPhase.java @@ -1,7 +1,6 @@ package pro.gravit.launcher.modules.events; import com.google.gson.GsonBuilder; - import pro.gravit.launcher.modules.LauncherModule; public class PreGsonPhase extends LauncherModule.Event { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleContext.java b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleContext.java index c7f87e45..b412423e 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleContext.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleContext.java @@ -7,6 +7,7 @@ public class SimpleModuleContext implements LauncherModulesContext { public final LauncherModulesManager modulesManager; public final ModulesConfigManager configManager; + @Override public LauncherModulesManager getModulesManager() { return modulesManager; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java index fe15f5ac..740fe8b4 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java @@ -1,5 +1,14 @@ package pro.gravit.launcher.modules.impl; +import pro.gravit.launcher.managers.SimpleModulesConfigManager; +import pro.gravit.launcher.modules.*; +import pro.gravit.utils.PublicURLClassLoader; +import pro.gravit.utils.Version; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.JVMHelper; +import pro.gravit.utils.helper.LogHelper; +import pro.gravit.utils.verify.LauncherTrustManager; + import java.io.IOException; import java.net.URL; import java.nio.file.FileVisitResult; @@ -19,19 +28,6 @@ import java.util.function.Predicate; import java.util.jar.JarFile; -import pro.gravit.launcher.managers.SimpleModulesConfigManager; -import pro.gravit.launcher.modules.LauncherInitContext; -import pro.gravit.launcher.modules.LauncherModule; -import pro.gravit.launcher.modules.LauncherModuleInfo; -import pro.gravit.launcher.modules.LauncherModulesManager; -import pro.gravit.launcher.modules.ModulesConfigManager; -import pro.gravit.utils.PublicURLClassLoader; -import pro.gravit.utils.Version; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.JVMHelper; -import pro.gravit.utils.helper.LogHelper; -import pro.gravit.utils.verify.LauncherTrustManager; - public class SimpleModuleManager implements LauncherModulesManager { protected final List modules = new ArrayList<>(); protected final List moduleNames = new ArrayList<>(); @@ -74,14 +70,11 @@ public void initModules(LauncherInitContext initContext) { int priority2 = m2.getModuleInfo().priority; return Integer.compare(priority1, priority2); }); - while(isAnyModuleLoad) - { + while (isAnyModuleLoad) { isAnyModuleLoad = false; - for(LauncherModule module : modules) - { - if(!module.getInitStatus().equals(LauncherModule.InitStatus.INIT_WAIT)) continue; - if(checkDepend(module)) - { + for (LauncherModule module : modules) { + if (!module.getInitStatus().equals(LauncherModule.InitStatus.INIT_WAIT)) continue; + if (checkDepend(module)) { isAnyModuleLoad = true; module.setInitStatus(LauncherModule.InitStatus.INIT); module.init(initContext); @@ -89,32 +82,27 @@ public void initModules(LauncherInitContext initContext) { } } } - for(LauncherModule module : modules) - { - if(module.getInitStatus().equals(LauncherModule.InitStatus.INIT_WAIT)) - { + for (LauncherModule module : modules) { + if (module.getInitStatus().equals(LauncherModule.InitStatus.INIT_WAIT)) { LauncherModuleInfo info = module.getModuleInfo(); LogHelper.warning("Module %s required %s. Cyclic dependencies?", info.name, Arrays.toString(info.dependencies)); module.setInitStatus(LauncherModule.InitStatus.INIT); module.init(initContext); module.setInitStatus(LauncherModule.InitStatus.FINISH); - } - else if(module.getInitStatus().equals(LauncherModule.InitStatus.PRE_INIT_WAIT)) - { + } else if (module.getInitStatus().equals(LauncherModule.InitStatus.PRE_INIT_WAIT)) { LauncherModuleInfo info = module.getModuleInfo(); LogHelper.error("Module %s skip pre-init phase. This module NOT finish loading", info.name, Arrays.toString(info.dependencies)); } } } - private boolean checkDepend(LauncherModule module) - { + private boolean checkDepend(LauncherModule module) { LauncherModuleInfo info = module.getModuleInfo(); - for(String dep : info.dependencies) - { + for (String dep : info.dependencies) { LauncherModule depModule = getModule(dep); - if(depModule == null) throw new RuntimeException(String.format("Module %s required %s. %s not found", info.name, dep, dep)); - if(!depModule.getInitStatus().equals(LauncherModule.InitStatus.FINISH)) return false; + if (depModule == null) + throw new RuntimeException(String.format("Module %s required %s. %s not found", info.name, dep, dep)); + if (!depModule.getInitStatus().equals(LauncherModule.InitStatus.FINISH)) return false; } return true; } @@ -125,6 +113,7 @@ public SimpleModuleManager(Path modulesDir, Path configDir) { this.modulesDir = modulesDir; this.trustManager = null; } + public SimpleModuleManager(Path modulesDir, Path configDir, LauncherTrustManager trustManager) { modulesConfigManager = new SimpleModulesConfigManager(configDir); context = new SimpleModuleContext(this, modulesConfigManager); @@ -134,14 +123,13 @@ public SimpleModuleManager(Path modulesDir, Path configDir, LauncherTrustManager @Override public LauncherModule loadModule(LauncherModule module) { - if(modules.contains(module)) return module; + if (modules.contains(module)) return module; modules.add(module); LauncherModuleInfo info = module.getModuleInfo(); moduleNames.add(info.name); module.setContext(context); module.preInit(); - if(initContext != null) - { + if (initContext != null) { module.setInitStatus(LauncherModule.InitStatus.INIT); module.init(initContext); module.setInitStatus(LauncherModule.InitStatus.FINISH); @@ -153,14 +141,13 @@ public LauncherModule loadModule(LauncherModule module) { public LauncherModule loadModule(Path file) throws IOException { try (JarFile f = new JarFile(file.toFile())) { String moduleClass = f.getManifest().getMainAttributes().getValue("Module-Main-Class"); - if(moduleClass == null) - { + if (moduleClass == null) { LogHelper.error("In module %s Module-Main-Class not found", file.toString()); return null; } classLoader.addURL(file.toUri().toURL()); @SuppressWarnings("unchecked") - Class clazz = (Class) Class.forName(moduleClass, false, classLoader); + Class clazz = (Class) Class.forName(moduleClass, false, classLoader); checkModuleClass(clazz, checkMode); LauncherModule module = clazz.newInstance(); loadModule(module); @@ -173,21 +160,18 @@ public LauncherModule loadModule(Path file) throws IOException { } - - public void checkModuleClass(Class clazz, LauncherTrustManager.CheckMode mode) throws SecurityException - { - if(trustManager == null) return; + public void checkModuleClass(Class clazz, LauncherTrustManager.CheckMode mode) throws SecurityException { + if (trustManager == null) return; X509Certificate[] certificates = JVMHelper.getCertificates(clazz); - if(certificates == null) - { - if(mode == LauncherTrustManager.CheckMode.EXCEPTION_IN_NOT_SIGNED) + if (certificates == null) { + if (mode == LauncherTrustManager.CheckMode.EXCEPTION_IN_NOT_SIGNED) throw new SecurityException(String.format("Class %s not signed", clazz.getName())); - else if(mode == LauncherTrustManager.CheckMode.WARN_IN_NOT_SIGNED) + else if (mode == LauncherTrustManager.CheckMode.WARN_IN_NOT_SIGNED) LogHelper.warning("Class %s not signed", clazz.getName()); return; } try { - trustManager.checkCertificate(certificates, (c,s) -> { + trustManager.checkCertificate(certificates, (c, s) -> { }); } catch (CertificateException | NoSuchProviderException | NoSuchAlgorithmException | InvalidKeyException | SignatureException e) { @@ -197,10 +181,10 @@ else if(mode == LauncherTrustManager.CheckMode.WARN_IN_NOT_SIGNED) @Override public LauncherModule getModule(String name) { - for(LauncherModule module : modules) - { + for (LauncherModule module : modules) { LauncherModuleInfo info = module.getModuleInfo(); - if(info.name.equals(name) || ( info.providers.length > 0 && Arrays.asList(info.providers).contains(name))) return module; + if (info.name.equals(name) || (info.providers.length > 0 && Arrays.asList(info.providers).contains(name))) + return module; } return null; } @@ -218,9 +202,8 @@ public ClassLoader getModuleClassLoader() { @Override @SuppressWarnings("unchecked") public T getModule(Class clazz) { - for(LauncherModule module : modules) - { - if(clazz.isAssignableFrom(module.getClass())) return (T) module; + for (LauncherModule module : modules) { + if (clazz.isAssignableFrom(module.getClass())) return (T) module; } return null; } @@ -228,9 +211,8 @@ public T getModule(Class clazz) { @Override @SuppressWarnings("unchecked") public T getModuleByInterface(Class clazz) { - for(LauncherModule module : modules) - { - if(clazz.isAssignableFrom(module.getClass())) return (T) module; + for (LauncherModule module : modules) { + if (clazz.isAssignableFrom(module.getClass())) return (T) module; } return null; } @@ -239,9 +221,8 @@ public T getModuleByInterface(Class clazz) { @SuppressWarnings("unchecked") public List getModulesByInterface(Class clazz) { List list = new ArrayList<>(); - for(LauncherModule module : modules) - { - if(clazz.isAssignableFrom(module.getClass())) list.add((T) module); + for (LauncherModule module : modules) { + if (clazz.isAssignableFrom(module.getClass())) list.add((T) module); } return list; } @@ -249,26 +230,24 @@ public List getModulesByInterface(Class clazz) { @Override @SuppressWarnings("unchecked") public T findModule(Class clazz, Predicate versionPredicate) { - for(LauncherModule module : modules) - { + for (LauncherModule module : modules) { LauncherModuleInfo info = module.getModuleInfo(); - if(!versionPredicate.test(info.version)) continue; - if(clazz.isAssignableFrom(module.getClass())) return (T) module; + if (!versionPredicate.test(info.version)) continue; + if (clazz.isAssignableFrom(module.getClass())) return (T) module; } return null; } @Override public void invokeEvent(T event) { - for(LauncherModule module : modules) - { + for (LauncherModule module : modules) { module.callEvent(event); - if(event.isCancel()) return; + if (event.isCancel()) return; } } - @Override - public ModulesConfigManager getConfigManager() { - return modulesConfigManager; - } + @Override + public ModulesConfigManager getConfigManager() { + return modulesConfigManager; + } } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java index 3e477c69..8ef8ea5f 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java @@ -1,16 +1,5 @@ package pro.gravit.launcher.profiles; -import java.io.IOException; -import java.net.InetSocketAddress; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.hasher.FileNameMatcher; import pro.gravit.launcher.hasher.HashedDir; @@ -20,10 +9,14 @@ import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.VerifyHelper; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.util.*; + public final class ClientProfile implements Comparable { @LauncherAPI public enum Version { - MC125("1.2.5", 29), + MC125("1.2.5", 29), MC147("1.4.7", 51), MC152("1.5.2", 61), MC164("1.6.4", 78), @@ -434,13 +427,16 @@ public void verify() { if (f.name == null) throw new IllegalArgumentException("Optional: name must not be null"); if (f.list == null) throw new IllegalArgumentException("Optional: list must not be null"); for (String s : f.list) { - if (s == null) throw new IllegalArgumentException(String.format("Found null entry in updateOptional.%s.list", f.name)); + if (s == null) + throw new IllegalArgumentException(String.format("Found null entry in updateOptional.%s.list", f.name)); } - if(f.conflictFile != null) for (OptionalDepend s : f.conflictFile) { - if (s == null) throw new IllegalArgumentException(String.format("Found null entry in updateOptional.%s.conflictFile", f.name)); + if (f.conflictFile != null) for (OptionalDepend s : f.conflictFile) { + if (s == null) + throw new IllegalArgumentException(String.format("Found null entry in updateOptional.%s.conflictFile", f.name)); } - if(f.dependenciesFile != null) for (OptionalDepend s : f.dependenciesFile) { - if (s == null) throw new IllegalArgumentException(String.format("Found null entry in updateOptional.%s.dependenciesFile", f.name)); + if (f.dependenciesFile != null) for (OptionalDepend s : f.dependenciesFile) { + if (s == null) + throw new IllegalArgumentException(String.format("Found null entry in updateOptional.%s.dependenciesFile", f.name)); } } } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/PlayerProfile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/PlayerProfile.java index e4178bb2..94f419af 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/PlayerProfile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/PlayerProfile.java @@ -1,9 +1,5 @@ package pro.gravit.launcher.profiles; -import java.io.IOException; -import java.util.Objects; -import java.util.UUID; - import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.serialize.HInput; import pro.gravit.launcher.serialize.HOutput; @@ -11,6 +7,10 @@ import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.VerifyHelper; +import java.io.IOException; +import java.util.Objects; +import java.util.UUID; + public final class PlayerProfile extends StreamObject { @LauncherAPI public static PlayerProfile newOfflineProfile(String username) { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/Texture.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/Texture.java index 8a1beb28..84869e1d 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/Texture.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/Texture.java @@ -1,11 +1,5 @@ package pro.gravit.launcher.profiles; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.Objects; - import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.serialize.HInput; import pro.gravit.launcher.serialize.HOutput; @@ -13,6 +7,12 @@ import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.SecurityHelper; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.Objects; + public final class Texture extends StreamObject { private static final SecurityHelper.DigestAlgorithm DIGEST_ALGO = SecurityHelper.DigestAlgorithm.SHA256; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalFile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalFile.java index e949a1a7..e4061f82 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalFile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalFile.java @@ -1,14 +1,14 @@ package pro.gravit.launcher.profiles.optional; -import java.io.IOException; -import java.util.Objects; -import java.util.Set; - import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.serialize.HInput; import pro.gravit.launcher.serialize.HOutput; import pro.gravit.utils.helper.LogHelper; +import java.io.IOException; +import java.util.Objects; +import java.util.Set; + public class OptionalFile { @LauncherAPI public String[] list; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/JsonResultSerializeAdapter.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/JsonResultSerializeAdapter.java index 5ca49743..3a46e1d3 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/JsonResultSerializeAdapter.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/JsonResultSerializeAdapter.java @@ -1,12 +1,8 @@ package pro.gravit.launcher.request; -import java.lang.reflect.Type; +import com.google.gson.*; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; +import java.lang.reflect.Type; public class JsonResultSerializeAdapter implements JsonSerializer { private static final String PROP_NAME = "type"; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java index 4b70c0a0..b0d11608 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java @@ -1,8 +1,5 @@ package pro.gravit.launcher.request; -import java.util.UUID; -import java.util.concurrent.atomic.AtomicBoolean; - import pro.gravit.launcher.Launcher; import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.LauncherNetworkAPI; @@ -10,6 +7,9 @@ import pro.gravit.launcher.request.websockets.WebSocketRequest; import pro.gravit.utils.helper.SecurityHelper; +import java.util.UUID; +import java.util.concurrent.atomic.AtomicBoolean; + public abstract class Request implements WebSocketRequest { private static long session = SecurityHelper.secureRandom.nextLong(); @LauncherNetworkAPI diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/RequestException.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/RequestException.java index 765f991e..5b2fe42f 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/RequestException.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/RequestException.java @@ -1,9 +1,9 @@ package pro.gravit.launcher.request; -import java.io.IOException; - import pro.gravit.launcher.LauncherAPI; +import java.io.IOException; + public final class RequestException extends IOException { private static final long serialVersionUID = 7558237657082664821L; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/RequestType.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/RequestType.java index 8362ebb9..8c9ed549 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/RequestType.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/RequestType.java @@ -1,11 +1,11 @@ package pro.gravit.launcher.request; -import java.io.IOException; - import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.serialize.HInput; import pro.gravit.launcher.serialize.stream.EnumSerializer; +import java.io.IOException; + public enum RequestType implements EnumSerializer.Itf { PING(0), // Ping request LEGACYLAUNCHER(1), UPDATE(2), UPDATE_LIST(3), // Update requests diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/AuthRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/AuthRequest.java index e74c2e57..327a71d2 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/AuthRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/AuthRequest.java @@ -5,18 +5,19 @@ import pro.gravit.launcher.events.request.AuthRequestEvent; import pro.gravit.launcher.hwid.HWID; import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.auth.password.AuthPlainPassword; import pro.gravit.launcher.request.auth.password.AuthECPassword; +import pro.gravit.launcher.request.auth.password.AuthPlainPassword; import pro.gravit.launcher.request.websockets.WebSocketRequest; import pro.gravit.utils.ProviderMap; import pro.gravit.utils.helper.VerifyHelper; public final class AuthRequest extends Request implements WebSocketRequest { public static final ProviderMap providers = new ProviderMap<>(); - public interface AuthPasswordInterface - { + + public interface AuthPasswordInterface { boolean check(); } + @LauncherNetworkAPI private final String login; @LauncherNetworkAPI @@ -102,9 +103,11 @@ public AuthRequest(String login, String password, String auth_id, ConnectTypes a public String getType() { return "auth"; } + private static boolean registerProviders = false; + public static void registerProviders() { - if(!registerProviders) { + if (!registerProviders) { providers.register("plain", AuthPlainPassword.class); providers.register("rsa", AuthECPassword.class); registerProviders = true; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/password/AuthECPassword.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/password/AuthECPassword.java index 2e8854b7..b4e19f93 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/password/AuthECPassword.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/password/AuthECPassword.java @@ -4,8 +4,8 @@ import pro.gravit.launcher.request.auth.AuthRequest; public class AuthECPassword implements AuthRequest.AuthPasswordInterface { - @LauncherNetworkAPI - public final byte[] password; + @LauncherNetworkAPI + public final byte[] password; public AuthECPassword(byte[] password) { this.password = password; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/password/AuthPlainPassword.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/password/AuthPlainPassword.java index 68eb760f..9e83e6a2 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/password/AuthPlainPassword.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/password/AuthPlainPassword.java @@ -4,8 +4,8 @@ import pro.gravit.launcher.request.auth.AuthRequest; public class AuthPlainPassword implements AuthRequest.AuthPasswordInterface { - @LauncherNetworkAPI - public final String password; + @LauncherNetworkAPI + public final String password; public AuthPlainPassword(String password) { this.password = password; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/LauncherRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/LauncherRequest.java index 52072559..8f3615f4 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/LauncherRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/LauncherRequest.java @@ -1,12 +1,5 @@ package pro.gravit.launcher.request.update; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.List; - import pro.gravit.launcher.Launcher; import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.LauncherNetworkAPI; @@ -20,6 +13,13 @@ import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.SecurityHelper; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; + public final class LauncherRequest extends Request implements WebSocketRequest { @LauncherNetworkAPI public byte[] digest; @@ -31,7 +31,7 @@ public final class LauncherRequest extends Request impleme public int launcher_type = EXE_BINARY ? 2 : 1; @LauncherAPI public static final Path BINARY_PATH = IOHelper.getCodeSource(Launcher.class); - + @LauncherAPI public static final Path C_BINARY_PATH = BINARY_PATH.getParent().resolve(IOHelper.getFileName(BINARY_PATH) + ".tmp"); @@ -64,7 +64,7 @@ public static void update(LauncherRequestEvent result) throws IOException { Files.deleteIfExists(C_BINARY_PATH); downloader.downloadOne(result.url, C_BINARY_PATH); try (InputStream in = IOHelper.newInput(C_BINARY_PATH)) { - IOHelper.transfer(in, BINARY_PATH); + IOHelper.transfer(in, BINARY_PATH); } Files.deleteIfExists(C_BINARY_PATH); } catch (Throwable e) { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java index 164cefdb..ac6eface 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java @@ -1,15 +1,5 @@ package pro.gravit.launcher.request.update; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.time.Duration; -import java.time.Instant; -import java.util.ArrayList; -import java.util.List; -import java.util.Map.Entry; -import java.util.Objects; - import pro.gravit.launcher.Launcher; import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.LauncherNetworkAPI; @@ -26,6 +16,16 @@ import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.time.Duration; +import java.time.Instant; +import java.util.ArrayList; +import java.util.List; +import java.util.Map.Entry; +import java.util.Objects; + public final class UpdateRequest extends Request implements WebSocketRequest { public interface UpdateController { void preUpdate(UpdateRequest request, UpdateRequestEvent e); @@ -46,8 +46,8 @@ public interface UpdateController { public static void setController(UpdateController controller) { UpdateRequest.controller = controller; } - public static UpdateController getController() - { + + public static UpdateController getController() { return controller; } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/BatchProfileByUsernameRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/BatchProfileByUsernameRequest.java index 486ac94a..cb46318f 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/BatchProfileByUsernameRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/BatchProfileByUsernameRequest.java @@ -1,7 +1,5 @@ package pro.gravit.launcher.request.uuid; -import java.io.IOException; - import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.request.BatchProfileByUsernameRequestEvent; @@ -11,6 +9,8 @@ import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.VerifyHelper; +import java.io.IOException; + public final class BatchProfileByUsernameRequest extends Request implements WebSocketRequest { static class Entry { @LauncherNetworkAPI diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/ProfileByUUIDRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/ProfileByUUIDRequest.java index 171b1116..a5190965 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/ProfileByUUIDRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/ProfileByUUIDRequest.java @@ -1,14 +1,14 @@ package pro.gravit.launcher.request.uuid; -import java.util.Objects; -import java.util.UUID; - import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.request.ProfileByUUIDRequestEvent; import pro.gravit.launcher.request.Request; import pro.gravit.launcher.request.websockets.WebSocketRequest; +import java.util.Objects; +import java.util.UUID; + public final class ProfileByUUIDRequest extends Request implements WebSocketRequest { @LauncherNetworkAPI private final UUID uuid; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientJSONPoint.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientJSONPoint.java index 06003341..c646a6a4 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientJSONPoint.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientJSONPoint.java @@ -1,16 +1,7 @@ package pro.gravit.launcher.request.websockets; -import java.io.IOException; -import java.net.URI; - -import javax.net.ssl.SSLException; - import io.netty.bootstrap.Bootstrap; -import io.netty.channel.Channel; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelInitializer; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.EventLoopGroup; +import io.netty.channel.*; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; @@ -25,6 +16,9 @@ import io.netty.handler.ssl.SslContextBuilder; import pro.gravit.utils.helper.LogHelper; +import javax.net.ssl.SSLException; +import java.net.URI; + public abstract class ClientJSONPoint { private final URI uri; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java index 3204a344..8aa7efe4 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java @@ -1,16 +1,7 @@ package pro.gravit.launcher.request.websockets; -import java.io.IOException; -import java.lang.reflect.Type; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.HashSet; - -import javax.net.ssl.SSLException; - import com.google.gson.Gson; import com.google.gson.GsonBuilder; - import pro.gravit.launcher.Launcher; import pro.gravit.launcher.events.ExceptionEvent; import pro.gravit.launcher.events.request.*; @@ -22,6 +13,13 @@ import pro.gravit.utils.UniversalJsonAdapter; import pro.gravit.utils.helper.LogHelper; +import javax.net.ssl.SSLException; +import java.io.IOException; +import java.lang.reflect.Type; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.HashSet; + public class ClientWebSocketService extends ClientJSONPoint { public final Gson gson; public OnCloseCallback onCloseCallback; @@ -38,8 +36,7 @@ public ClientWebSocketService(String address) throws SSLException { this.onConnect = true; } - public static void appendTypeAdapters(GsonBuilder builder) - { + public static void appendTypeAdapters(GsonBuilder builder) { builder.registerTypeAdapter(HashedEntry.class, new HashedEntryAdapter()); builder.registerTypeAdapter(WebSocketEvent.class, new UniversalJsonAdapter<>(ClientWebSocketService.results)); builder.registerTypeAdapter(WebSocketRequest.class, new UniversalJsonAdapter<>(ClientWebSocketService.requests)); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StandartClientWebSocketService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StandartClientWebSocketService.java index b8609e73..728ec40b 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StandartClientWebSocketService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StandartClientWebSocketService.java @@ -1,12 +1,5 @@ package pro.gravit.launcher.request.websockets; -import java.io.IOException; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; - -import javax.net.ssl.SSLException; - import pro.gravit.launcher.events.ExceptionEvent; import pro.gravit.launcher.events.request.ErrorRequestEvent; import pro.gravit.launcher.request.Request; @@ -16,6 +9,12 @@ import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.LogHelper; +import javax.net.ssl.SSLException; +import java.io.IOException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; + public class StandartClientWebSocketService extends ClientWebSocketService { public final WaitEventHandler waitEventHandler = new WaitEventHandler(); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WaitEventHandler.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WaitEventHandler.java index ed3021bb..ff9281fb 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WaitEventHandler.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WaitEventHandler.java @@ -1,13 +1,13 @@ package pro.gravit.launcher.request.websockets; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; - import pro.gravit.launcher.events.RequestEvent; import pro.gravit.launcher.request.WebSocketEvent; import pro.gravit.utils.helper.LogHelper; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; + public class WaitEventHandler implements ClientWebSocketService.EventHandler { public final Set requests = ConcurrentHashMap.newKeySet(); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WebSocketClientHandler.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WebSocketClientHandler.java index 00aef7c2..df633e6f 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WebSocketClientHandler.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WebSocketClientHandler.java @@ -1,23 +1,13 @@ package pro.gravit.launcher.request.websockets; -import java.util.concurrent.TimeUnit; - -import io.netty.channel.Channel; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelPromise; -import io.netty.channel.SimpleChannelInboundHandler; +import io.netty.channel.*; import io.netty.handler.codec.http.FullHttpResponse; -import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; -import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame; -import io.netty.handler.codec.http.websocketx.PingWebSocketFrame; -import io.netty.handler.codec.http.websocketx.PongWebSocketFrame; -import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; -import io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker; -import io.netty.handler.codec.http.websocketx.WebSocketFrame; +import io.netty.handler.codec.http.websocketx.*; import io.netty.util.CharsetUtil; import pro.gravit.utils.helper.LogHelper; +import java.util.concurrent.TimeUnit; + public class WebSocketClientHandler extends SimpleChannelInboundHandler { private final WebSocketClientHandshaker handshaker; diff --git a/LauncherAPI/src/test/java/pro/gravit/launcher/ModulesTest.java b/LauncherAPI/src/test/java/pro/gravit/launcher/ModulesTest.java index 87325775..c228df09 100644 --- a/LauncherAPI/src/test/java/pro/gravit/launcher/ModulesTest.java +++ b/LauncherAPI/src/test/java/pro/gravit/launcher/ModulesTest.java @@ -1,24 +1,17 @@ package pro.gravit.launcher; -import java.nio.file.Path; - import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; - -import pro.gravit.launcher.impl.Cyclic2DependModule; -import pro.gravit.launcher.impl.CyclicDependModule; -import pro.gravit.launcher.impl.Depend1Module; -import pro.gravit.launcher.impl.Depend2Module; -import pro.gravit.launcher.impl.Depend3Module; -import pro.gravit.launcher.impl.MainModule; -import pro.gravit.launcher.impl.TestModule; +import pro.gravit.launcher.impl.*; import pro.gravit.launcher.impl.event.CancelEvent; import pro.gravit.launcher.impl.event.NormalEvent; import pro.gravit.launcher.modules.LauncherModule; import pro.gravit.launcher.modules.impl.SimpleModuleManager; +import java.nio.file.Path; + public class ModulesTest { @TempDir public static Path configDir; @@ -26,19 +19,19 @@ public class ModulesTest { public static Path modulesDir; public static SimpleModuleManager moduleManager; public static int dependInt = 0; - public static void add(int a) - { - if(dependInt != a) throw new IllegalStateException(String.valueOf(a)); + + public static void add(int a) { + if (dependInt != a) throw new IllegalStateException(String.valueOf(a)); dependInt++; } + @BeforeAll - public static void prepare() - { + public static void prepare() { moduleManager = new SimpleModuleManager(modulesDir, configDir); } + @Test - public void baseModule() - { + public void baseModule() { moduleManager.loadModule(new TestModule()); moduleManager.initModules(null); NormalEvent e = new NormalEvent(); @@ -48,9 +41,9 @@ public void baseModule() moduleManager.invokeEvent(e1); Assertions.assertTrue(e1.isCancel()); } + @Test - public void dependenciesTest() - { + public void dependenciesTest() { moduleManager.loadModule(new Depend1Module()); moduleManager.loadModule(new Depend2Module()); moduleManager.loadModule(new Depend3Module()); @@ -63,9 +56,9 @@ public void dependenciesTest() Assertions.assertEquals(moduleManager.getModule("virtual").getInitStatus(), LauncherModule.InitStatus.FINISH); Assertions.assertEquals(moduleManager.getModule("main").getInitStatus(), LauncherModule.InitStatus.FINISH); } + @Test - public void cyclicTest() - { + public void cyclicTest() { moduleManager.loadModule(new CyclicDependModule()); moduleManager.loadModule(new Cyclic2DependModule()); moduleManager.initModules(null); diff --git a/LauncherAPI/src/test/java/pro/gravit/launcher/impl/Cyclic2DependModule.java b/LauncherAPI/src/test/java/pro/gravit/launcher/impl/Cyclic2DependModule.java index 99b1b7c2..fa321bce 100644 --- a/LauncherAPI/src/test/java/pro/gravit/launcher/impl/Cyclic2DependModule.java +++ b/LauncherAPI/src/test/java/pro/gravit/launcher/impl/Cyclic2DependModule.java @@ -8,7 +8,7 @@ public class Cyclic2DependModule extends LauncherModule { public Cyclic2DependModule() { super(new LauncherModuleInfo("cyclic2", - new Version(1,0,0), + new Version(1, 0, 0), 2, new String[]{"cyclic1"})); } diff --git a/LauncherAPI/src/test/java/pro/gravit/launcher/impl/CyclicDependModule.java b/LauncherAPI/src/test/java/pro/gravit/launcher/impl/CyclicDependModule.java index 3fcee538..c13d8b58 100644 --- a/LauncherAPI/src/test/java/pro/gravit/launcher/impl/CyclicDependModule.java +++ b/LauncherAPI/src/test/java/pro/gravit/launcher/impl/CyclicDependModule.java @@ -8,7 +8,7 @@ public class CyclicDependModule extends LauncherModule { public CyclicDependModule() { super(new LauncherModuleInfo("cyclic1", - new Version(1,0,0), + new Version(1, 0, 0), 2, new String[]{"cyclic2"})); } diff --git a/LauncherAPI/src/test/java/pro/gravit/launcher/impl/Depend1Module.java b/LauncherAPI/src/test/java/pro/gravit/launcher/impl/Depend1Module.java index d5156125..a3f046b7 100644 --- a/LauncherAPI/src/test/java/pro/gravit/launcher/impl/Depend1Module.java +++ b/LauncherAPI/src/test/java/pro/gravit/launcher/impl/Depend1Module.java @@ -1,7 +1,6 @@ package pro.gravit.launcher.impl; import org.junit.jupiter.api.Assertions; - import pro.gravit.launcher.modules.LauncherInitContext; import pro.gravit.launcher.modules.LauncherModule; import pro.gravit.launcher.modules.LauncherModuleInfo; @@ -9,7 +8,7 @@ public class Depend1Module extends LauncherModule { public Depend1Module() { - super(new LauncherModuleInfo("depend1", new Version(1,0,0), + super(new LauncherModuleInfo("depend1", new Version(1, 0, 0), 0, new String[]{"depend3", "internal", "virtual"})); } diff --git a/LauncherAPI/src/test/java/pro/gravit/launcher/impl/MainModule.java b/LauncherAPI/src/test/java/pro/gravit/launcher/impl/MainModule.java index 3fdf52a4..22248da6 100644 --- a/LauncherAPI/src/test/java/pro/gravit/launcher/impl/MainModule.java +++ b/LauncherAPI/src/test/java/pro/gravit/launcher/impl/MainModule.java @@ -1,7 +1,6 @@ package pro.gravit.launcher.impl; import org.junit.jupiter.api.Assertions; - import pro.gravit.launcher.modules.LauncherInitContext; import pro.gravit.launcher.modules.LauncherModule; import pro.gravit.launcher.modules.LauncherModuleInfo; @@ -11,7 +10,7 @@ public class MainModule extends LauncherModule { public MainModule() { super(new LauncherModuleInfo("main", - new Version(1,0,0), + new Version(1, 0, 0), 0, new String[]{"depend1", "depend2"})); } diff --git a/LauncherAPI/src/test/java/pro/gravit/launcher/impl/ProvidedModule.java b/LauncherAPI/src/test/java/pro/gravit/launcher/impl/ProvidedModule.java index 826d768d..dd201374 100644 --- a/LauncherAPI/src/test/java/pro/gravit/launcher/impl/ProvidedModule.java +++ b/LauncherAPI/src/test/java/pro/gravit/launcher/impl/ProvidedModule.java @@ -7,7 +7,7 @@ public class ProvidedModule extends LauncherModule implements VirtualInterface { public ProvidedModule() { - super(new LauncherModuleInfo("provided", new Version(1,0,0), + super(new LauncherModuleInfo("provided", new Version(1, 0, 0), 0, new String[]{}, new String[]{"virtual"})); } diff --git a/LauncherAPI/src/test/java/pro/gravit/launcher/impl/TestModule.java b/LauncherAPI/src/test/java/pro/gravit/launcher/impl/TestModule.java index bdd1f617..9f247324 100644 --- a/LauncherAPI/src/test/java/pro/gravit/launcher/impl/TestModule.java +++ b/LauncherAPI/src/test/java/pro/gravit/launcher/impl/TestModule.java @@ -18,13 +18,11 @@ public void init(LauncherInitContext initContext) { registerEvent(this::testevent2, CancelEvent.class); } - public void testevent(NormalEvent event) - { + public void testevent(NormalEvent event) { event.passed = true; } - public void testevent2(CancelEvent cancelEvent) - { + public void testevent2(CancelEvent cancelEvent) { cancelEvent.cancel(); } } diff --git a/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/CompatBridge.java b/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/CompatBridge.java index 67a77fb5..bc11fa25 100644 --- a/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/CompatBridge.java +++ b/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/CompatBridge.java @@ -1,7 +1,5 @@ package com.mojang.authlib.yggdrasil; -import java.util.UUID; - import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.profiles.PlayerProfile; import pro.gravit.launcher.request.auth.CheckServerRequest; @@ -12,6 +10,8 @@ import pro.gravit.launcher.serialize.SerializeLimits; import pro.gravit.utils.helper.LogHelper; +import java.util.UUID; + // Used to bypass Launcher's class name obfuscation and access API @LauncherAPI public class CompatBridge { diff --git a/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/CompatProfile.java b/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/CompatProfile.java index 56fb51e2..a90421ce 100644 --- a/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/CompatProfile.java +++ b/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/CompatProfile.java @@ -1,12 +1,12 @@ package com.mojang.authlib.yggdrasil; -import java.util.UUID; - import pro.gravit.launcher.Launcher; import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.profiles.PlayerProfile; import pro.gravit.utils.helper.SecurityHelper; +import java.util.UUID; + @LauncherAPI public class CompatProfile { public static final String SKIN_URL_PROPERTY = Launcher.SKIN_URL_PROPERTY; diff --git a/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilAuthenticationService.java b/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilAuthenticationService.java index 227952e2..cf75f1f7 100644 --- a/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilAuthenticationService.java +++ b/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilAuthenticationService.java @@ -1,15 +1,14 @@ package com.mojang.authlib.yggdrasil; -import java.net.Proxy; - import com.mojang.authlib.Agent; import com.mojang.authlib.AuthenticationService; import com.mojang.authlib.GameProfileRepository; import com.mojang.authlib.UserAuthentication; import com.mojang.authlib.minecraft.MinecraftSessionService; - import pro.gravit.utils.helper.LogHelper; +import java.net.Proxy; + public class YggdrasilAuthenticationService implements AuthenticationService { public YggdrasilAuthenticationService(Proxy proxy, String clientToken) { LogHelper.debug("Patched AuthenticationService created: '%s'", clientToken); diff --git a/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilGameProfileRepository.java b/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilGameProfileRepository.java index 97fd927a..9ccad1b2 100644 --- a/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilGameProfileRepository.java +++ b/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilGameProfileRepository.java @@ -1,19 +1,18 @@ package com.mojang.authlib.yggdrasil; -import java.util.Arrays; -import java.util.UUID; - import com.mojang.authlib.Agent; import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfileRepository; import com.mojang.authlib.ProfileLookupCallback; - import pro.gravit.launcher.profiles.PlayerProfile; import pro.gravit.launcher.request.uuid.BatchProfileByUsernameRequest; import pro.gravit.launcher.serialize.SerializeLimits; import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.VerifyHelper; +import java.util.Arrays; +import java.util.UUID; + public class YggdrasilGameProfileRepository implements GameProfileRepository { private static final long BUSY_WAIT_MS = VerifyHelper.verifyLong( Long.parseLong(System.getProperty("launcher.com.mojang.authlib.busyWait", Long.toString(100L))), diff --git a/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilMinecraftSessionService.java b/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilMinecraftSessionService.java index dfbad307..0ceed8a5 100644 --- a/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilMinecraftSessionService.java +++ b/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilMinecraftSessionService.java @@ -1,11 +1,5 @@ package com.mojang.authlib.yggdrasil; -import java.net.InetAddress; -import java.util.Base64; -import java.util.EnumMap; -import java.util.Map; -import java.util.UUID; - import com.google.common.collect.Iterables; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -18,7 +12,6 @@ import com.mojang.authlib.minecraft.MinecraftProfileTexture; import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; - import pro.gravit.launcher.Launcher; import pro.gravit.launcher.profiles.PlayerProfile; import pro.gravit.launcher.request.auth.CheckServerRequest; @@ -28,6 +21,12 @@ import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.SecurityHelper; +import java.net.InetAddress; +import java.util.Base64; +import java.util.EnumMap; +import java.util.Map; +import java.util.UUID; + public class YggdrasilMinecraftSessionService extends BaseMinecraftSessionService { public static final JsonParser JSON_PARSER = new JsonParser(); public static final boolean NO_TEXTURES = Boolean.parseBoolean("launcher.com.mojang.authlib.noTextures"); diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/hasher/FileNameMatcher.java b/LauncherCore/src/main/java/pro/gravit/launcher/hasher/FileNameMatcher.java index c468d03d..1991c56a 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/hasher/FileNameMatcher.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/hasher/FileNameMatcher.java @@ -1,9 +1,9 @@ package pro.gravit.launcher.hasher; -import java.util.Collection; - import pro.gravit.launcher.LauncherAPI; +import java.util.Collection; + public final class FileNameMatcher { private static final String[] NO_ENTRIES = new String[0]; diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedDir.java b/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedDir.java index 9e6a5309..1be50e9f 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedDir.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedDir.java @@ -1,19 +1,5 @@ package pro.gravit.launcher.hasher; -import java.io.IOException; -import java.nio.file.FileVisitResult; -import java.nio.file.Path; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.attribute.BasicFileAttributes; -import java.util.Collections; -import java.util.Deque; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.StringTokenizer; - import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.serialize.HInput; @@ -23,6 +9,14 @@ import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.VerifyHelper; +import java.io.IOException; +import java.nio.file.FileVisitResult; +import java.nio.file.Path; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.*; +import java.util.Map.Entry; + public final class HashedDir extends HashedEntry { public static final class Diff { @LauncherAPI diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedEntry.java b/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedEntry.java index 8da8d6f5..8ae689c1 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedEntry.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedEntry.java @@ -1,12 +1,12 @@ package pro.gravit.launcher.hasher; -import java.io.IOException; - import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.serialize.HInput; import pro.gravit.launcher.serialize.stream.EnumSerializer; import pro.gravit.launcher.serialize.stream.StreamObject; +import java.io.IOException; + public abstract class HashedEntry extends StreamObject { @LauncherAPI public enum Type implements EnumSerializer.Itf { diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedEntryAdapter.java b/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedEntryAdapter.java index 625d24fe..67be19cc 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedEntryAdapter.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedEntryAdapter.java @@ -1,15 +1,8 @@ package pro.gravit.launcher.hasher; -import java.lang.reflect.Type; +import com.google.gson.*; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; +import java.lang.reflect.Type; public class HashedEntryAdapter implements JsonSerializer, JsonDeserializer { diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedFile.java b/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedFile.java index d5118338..d18b3405 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedFile.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedFile.java @@ -1,9 +1,5 @@ package pro.gravit.launcher.hasher; -import java.io.IOException; -import java.nio.file.Path; -import java.util.Arrays; - import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.serialize.HInput; @@ -13,6 +9,10 @@ import pro.gravit.utils.helper.SecurityHelper.DigestAlgorithm; import pro.gravit.utils.helper.VerifyHelper; +import java.io.IOException; +import java.nio.file.Path; +import java.util.Arrays; + public final class HashedFile extends HashedEntry { public static final DigestAlgorithm DIGEST_ALGO = DigestAlgorithm.MD5; diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/managers/GarbageManager.java b/LauncherCore/src/main/java/pro/gravit/launcher/managers/GarbageManager.java index 66ba4e08..285b551c 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/managers/GarbageManager.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/managers/GarbageManager.java @@ -1,12 +1,12 @@ package pro.gravit.launcher.managers; +import pro.gravit.launcher.NeedGarbageCollection; + import java.util.HashSet; import java.util.Set; import java.util.Timer; import java.util.TimerTask; -import pro.gravit.launcher.NeedGarbageCollection; - public class GarbageManager { static class Entry { final NeedGarbageCollection invoke; diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/managers/GsonManager.java b/LauncherCore/src/main/java/pro/gravit/launcher/managers/GsonManager.java index 52a43b2f..655f21c2 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/managers/GsonManager.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/managers/GsonManager.java @@ -2,7 +2,6 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; - import pro.gravit.launcher.hasher.HashedEntry; import pro.gravit.launcher.hasher.HashedEntryAdapter; import pro.gravit.utils.helper.CommonHelper; diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/HInput.java b/LauncherCore/src/main/java/pro/gravit/launcher/serialize/HInput.java index 3d28fc28..56367213 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/HInput.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/serialize/HInput.java @@ -1,5 +1,8 @@ package pro.gravit.launcher.serialize; +import pro.gravit.launcher.LauncherAPI; +import pro.gravit.utils.helper.IOHelper; + import java.io.ByteArrayInputStream; import java.io.EOFException; import java.io.IOException; @@ -8,9 +11,6 @@ import java.util.Objects; import java.util.UUID; -import pro.gravit.launcher.LauncherAPI; -import pro.gravit.utils.helper.IOHelper; - public final class HInput implements AutoCloseable { @LauncherAPI public final InputStream stream; diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/HOutput.java b/LauncherCore/src/main/java/pro/gravit/launcher/serialize/HOutput.java index 08ff3845..23669ce3 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/HOutput.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/serialize/HOutput.java @@ -1,5 +1,8 @@ package pro.gravit.launcher.serialize; +import pro.gravit.launcher.LauncherAPI; +import pro.gravit.utils.helper.IOHelper; + import java.io.Flushable; import java.io.IOException; import java.io.OutputStream; @@ -7,9 +10,6 @@ import java.util.Objects; import java.util.UUID; -import pro.gravit.launcher.LauncherAPI; -import pro.gravit.utils.helper.IOHelper; - public final class HOutput implements AutoCloseable, Flushable { @LauncherAPI public final OutputStream stream; diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/signed/DigestBytesHolder.java b/LauncherCore/src/main/java/pro/gravit/launcher/serialize/signed/DigestBytesHolder.java index e0fedc2a..e7af277d 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/signed/DigestBytesHolder.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/serialize/signed/DigestBytesHolder.java @@ -1,15 +1,15 @@ package pro.gravit.launcher.serialize.signed; -import java.io.IOException; -import java.security.SignatureException; -import java.util.Arrays; - import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.serialize.HInput; import pro.gravit.launcher.serialize.HOutput; import pro.gravit.launcher.serialize.stream.StreamObject; import pro.gravit.utils.helper.SecurityHelper; +import java.io.IOException; +import java.security.SignatureException; +import java.util.Arrays; + public class DigestBytesHolder extends StreamObject { protected final byte[] bytes; private final byte[] digest; diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/stream/EnumSerializer.java b/LauncherCore/src/main/java/pro/gravit/launcher/serialize/stream/EnumSerializer.java index bf06e9eb..ac6c283f 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/stream/EnumSerializer.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/serialize/stream/EnumSerializer.java @@ -1,15 +1,15 @@ package pro.gravit.launcher.serialize.stream; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.serialize.HInput; import pro.gravit.launcher.serialize.HOutput; import pro.gravit.launcher.serialize.stream.EnumSerializer.Itf; import pro.gravit.utils.helper.VerifyHelper; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + public final class EnumSerializer & Itf> { @FunctionalInterface public interface Itf { diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/stream/StreamObject.java b/LauncherCore/src/main/java/pro/gravit/launcher/serialize/stream/StreamObject.java index 8be1c5fd..561d899f 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/stream/StreamObject.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/serialize/stream/StreamObject.java @@ -1,13 +1,13 @@ package pro.gravit.launcher.serialize.stream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; - import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.serialize.HInput; import pro.gravit.launcher.serialize.HOutput; import pro.gravit.utils.helper.IOHelper; +import java.io.ByteArrayOutputStream; +import java.io.IOException; + public abstract class StreamObject { /* public StreamObject(HInput input) */ diff --git a/LauncherCore/src/main/java/pro/gravit/utils/BiHookSet.java b/LauncherCore/src/main/java/pro/gravit/utils/BiHookSet.java index 4bd24018..e7af55fc 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/BiHookSet.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/BiHookSet.java @@ -10,12 +10,10 @@ public class BiHookSet { public interface Hook { /** * @param context custom param - * @param object custom param - * @return - * True if you need to interrupt hook processing + * @param object custom param + * @return True if you need to interrupt hook processing * False to continue processing hook - * @throws HookException - * The hook may return the error text throwing this exception + * @throws HookException The hook may return the error text throwing this exception */ boolean hook(V object, R context) throws HookException; } @@ -30,12 +28,10 @@ public boolean unregisterHook(Hook hook) { /** * @param context custom param - * @param object custom param - * @return - * True if hook to interrupt processing + * @param object custom param + * @return True if hook to interrupt processing * False to continue - * @throws HookException - * The hook may return the error text throwing this exception + * @throws HookException The hook may return the error text throwing this exception */ public boolean hook(V context, R object) throws HookException { for (Hook hook : list) { diff --git a/LauncherCore/src/main/java/pro/gravit/utils/HTTPRequest.java b/LauncherCore/src/main/java/pro/gravit/utils/HTTPRequest.java index 97a33fe8..051601de 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/HTTPRequest.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/HTTPRequest.java @@ -1,5 +1,10 @@ package pro.gravit.utils; +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.LogHelper; + import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; @@ -8,12 +13,6 @@ import java.net.URL; import java.nio.charset.StandardCharsets; -import com.google.gson.JsonElement; -import com.google.gson.JsonParser; - -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.LogHelper; - public final class HTTPRequest { private static final int TIMEOUT = 10000; private static final JsonParser parser = new JsonParser(); @@ -44,16 +43,17 @@ public static JsonElement jsonRequest(JsonElement request, URL url) throws IOExc public static JsonElement jsonRequest(JsonElement request, String method, URL url) throws IOException { HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoInput(true); - if(request != null) connection.setDoOutput(true); + if (request != null) connection.setDoOutput(true); connection.setRequestMethod(method); - if(request != null) connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); + if (request != null) connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); connection.setRequestProperty("Accept", "application/json"); if (TIMEOUT > 0) connection.setConnectTimeout(TIMEOUT); - if(request != null) try (OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream(), StandardCharsets.UTF_8)) { - writer.write(request.toString()); - writer.flush(); - } + if (request != null) + try (OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream(), StandardCharsets.UTF_8)) { + writer.write(request.toString()); + writer.flush(); + } InputStreamReader reader; int statusCode = connection.getResponseCode(); diff --git a/LauncherCore/src/main/java/pro/gravit/utils/HookSet.java b/LauncherCore/src/main/java/pro/gravit/utils/HookSet.java index fe975d64..56c4dedf 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/HookSet.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/HookSet.java @@ -10,11 +10,9 @@ public class HookSet { public interface Hook { /** * @param context custom param - * @return - * True if you need to interrupt hook processing + * @return True if you need to interrupt hook processing * False to continue processing hook - * @throws HookException - * The hook may return the error text throwing this exception + * @throws HookException The hook may return the error text throwing this exception */ boolean hook(R context) throws HookException; } @@ -29,11 +27,9 @@ public boolean unregisterHook(Hook hook) { /** * @param context custom param - * @return - * True if hook to interrupt processing + * @return True if hook to interrupt processing * False to continue - * @throws HookException - * The hook may return the error text throwing this exception + * @throws HookException The hook may return the error text throwing this exception */ public boolean hook(R context) throws HookException { for (Hook hook : list) { diff --git a/LauncherCore/src/main/java/pro/gravit/utils/HttpDownloader.java b/LauncherCore/src/main/java/pro/gravit/utils/HttpDownloader.java index 58b7d7fd..aeb2cf66 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/HttpDownloader.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/HttpDownloader.java @@ -1,5 +1,8 @@ package pro.gravit.utils; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.LogHelper; + import java.io.BufferedInputStream; import java.io.IOException; import java.io.OutputStream; @@ -10,9 +13,6 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.LogHelper; - public final class HttpDownloader { public static final int INTERVAL = 500; public final AtomicInteger writed; @@ -20,7 +20,7 @@ public final class HttpDownloader { public final Thread thread; public HttpDownloader(URL url, Path file) { - writed = new AtomicInteger(0); + writed = new AtomicInteger(0); filename = null; thread = new Thread(() -> { try { @@ -49,7 +49,7 @@ public static void downloadFile(URL url, Path file, Consumer chanheTrac fout.write(data, 0, count); writed_local += count; if (System.currentTimeMillis() - timestamp > INTERVAL) { - chanheTrack.accept(writed_local); + chanheTrack.accept(writed_local); LogHelper.debug("Downloaded %d", writed_local); } } diff --git a/LauncherCore/src/main/java/pro/gravit/utils/ProviderMap.java b/LauncherCore/src/main/java/pro/gravit/utils/ProviderMap.java index 56a5e4a5..9be18942 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/ProviderMap.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/ProviderMap.java @@ -1,13 +1,14 @@ package pro.gravit.utils; +import pro.gravit.utils.helper.VerifyHelper; + import java.util.Map; import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; -import pro.gravit.utils.helper.VerifyHelper; - /** * The relationship between classes of an interface or abstract class and names when they are serialized + * * @param Class or interface type */ public class ProviderMap { diff --git a/LauncherCore/src/main/java/pro/gravit/utils/PublicURLClassLoader.java b/LauncherCore/src/main/java/pro/gravit/utils/PublicURLClassLoader.java index a6f8b967..6ea17422 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/PublicURLClassLoader.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/PublicURLClassLoader.java @@ -1,10 +1,10 @@ package pro.gravit.utils; +import pro.gravit.launcher.LauncherAPI; + import java.net.URL; import java.net.URLClassLoader; -import pro.gravit.launcher.LauncherAPI; - public class PublicURLClassLoader extends URLClassLoader { @LauncherAPI public static ClassLoader systemclassloader = ClassLoader.getSystemClassLoader(); diff --git a/LauncherCore/src/main/java/pro/gravit/utils/UniversalJsonAdapter.java b/LauncherCore/src/main/java/pro/gravit/utils/UniversalJsonAdapter.java index 06d8e3d0..093c271a 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/UniversalJsonAdapter.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/UniversalJsonAdapter.java @@ -1,20 +1,13 @@ package pro.gravit.utils; +import com.google.gson.*; +import pro.gravit.utils.helper.LogHelper; + import java.lang.reflect.Type; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; - -import pro.gravit.utils.helper.LogHelper; - /** * An adapter that uses {@link ProviderMap} to serialize and deserialize a group of similar objects + * * @param Class or interface type * @see ProviderMap */ diff --git a/LauncherCore/src/main/java/pro/gravit/utils/Version.java b/LauncherCore/src/main/java/pro/gravit/utils/Version.java index ff26cc93..deebee2b 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/Version.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/Version.java @@ -1,14 +1,9 @@ package pro.gravit.utils; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; -import java.util.Objects; - import pro.gravit.launcher.LauncherAPI; +import java.util.*; + public final class Version { @LauncherAPI public final int major; diff --git a/LauncherCore/src/main/java/pro/gravit/utils/command/BaseCommandCategory.java b/LauncherCore/src/main/java/pro/gravit/utils/command/BaseCommandCategory.java index 85c871e0..2d64cb5e 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/command/BaseCommandCategory.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/command/BaseCommandCategory.java @@ -1,11 +1,11 @@ package pro.gravit.utils.command; +import pro.gravit.utils.helper.VerifyHelper; + import java.util.Map; import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; -import pro.gravit.utils.helper.VerifyHelper; - public class BaseCommandCategory implements CommandCategory { private final Map commands = new ConcurrentHashMap<>(32); diff --git a/LauncherCore/src/main/java/pro/gravit/utils/command/Command.java b/LauncherCore/src/main/java/pro/gravit/utils/command/Command.java index ad65920f..85f79d61 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/command/Command.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/command/Command.java @@ -1,16 +1,10 @@ package pro.gravit.utils.command; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - import org.jline.reader.Candidate; - import pro.gravit.utils.helper.VerifyHelper; +import java.util.*; + public abstract class Command { /** * List of available subcommands @@ -49,63 +43,58 @@ protected static UUID parseUUID(String s) throws CommandException { /** * Creates a JLine candidate that appears in the list of available options when you press TAB - * @param category this command category + * + * @param category this command category * @param commandName this command name * @return JLine Candidate */ - public Candidate buildCandidate(CommandHandler.Category category, String commandName) - { + public Candidate buildCandidate(CommandHandler.Category category, String commandName) { return new Candidate(commandName); } /** * Returns a list of available options for the next word for the current command. - * @param words list all user words + * + * @param words list all user words * @param wordIndex current word index - * @param word current word + * @param word current word * @return list of available Candidate */ - public List complete(List words, int wordIndex, String word) - { - if(wordIndex == 0) - { + public List complete(List words, int wordIndex, String word) { + if (wordIndex == 0) { List candidates = new ArrayList<>(); - childCommands.forEach((k,v) -> { - if(k.startsWith(word)) - { + childCommands.forEach((k, v) -> { + if (k.startsWith(word)) { candidates.add(new Candidate(k)); } }); return candidates; - } - else - { + } else { Command cmd = childCommands.get(words.get(0)); - if(cmd == null) return new ArrayList<>(); + if (cmd == null) return new ArrayList<>(); return cmd.complete(words.subList(1, words.size()), wordIndex - 1, word); } } /** * Transfer control to subcommands + * * @param args command arguments(includes subcommand name) - * @throws Exception - * Error executing command + * @throws Exception Error executing command */ - public void invokeSubcommands(String... args) throws Exception - { + public void invokeSubcommands(String... args) throws Exception { verifyArgs(args, 1); Command command = childCommands.get(args[0]); - if(command == null) throw new CommandException(String.format("Unknown sub command: '%s'", args[0])); + if (command == null) throw new CommandException(String.format("Unknown sub command: '%s'", args[0])); command.invoke(Arrays.copyOfRange(args, 1, args.length)); } /** * Run current command + * * @param args command arguments - * @throws Exception - * Error executing command + * @throws Exception Error executing command */ public abstract void invoke(String... args) throws Exception; diff --git a/LauncherCore/src/main/java/pro/gravit/utils/command/CommandHandler.java b/LauncherCore/src/main/java/pro/gravit/utils/command/CommandHandler.java index 65df9c1e..81b94904 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/command/CommandHandler.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/command/CommandHandler.java @@ -1,14 +1,14 @@ package pro.gravit.utils.command; +import pro.gravit.utils.helper.CommonHelper; +import pro.gravit.utils.helper.LogHelper; + import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; -import pro.gravit.utils.helper.CommonHelper; -import pro.gravit.utils.helper.LogHelper; - public abstract class CommandHandler implements Runnable { private final List categories = new ArrayList<>(); private final CommandCategory baseCategory = new BaseCommandCategory(); @@ -83,9 +83,9 @@ public Command findCommand(String name) { /** * Reads a line from the console + * * @return command line - * @throws IOException - * Internal Error + * @throws IOException Internal Error */ public abstract String readLine() throws IOException; @@ -134,6 +134,7 @@ public interface CommandWalk { * Walk all categories * Categories are sorted in the order they are added. * The base category is walked last + * * @param callback your callback */ public void walk(CommandWalk callback) { @@ -161,8 +162,8 @@ public List getCategories() { /** * Cleans the console - * @throws IOException - * Internal Error + * + * @throws IOException Internal Error */ public abstract void clear() throws IOException; } diff --git a/LauncherCore/src/main/java/pro/gravit/utils/command/JLineCommandHandler.java b/LauncherCore/src/main/java/pro/gravit/utils/command/JLineCommandHandler.java index ef3151a0..c05297e9 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/command/JLineCommandHandler.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/command/JLineCommandHandler.java @@ -1,18 +1,13 @@ package pro.gravit.utils.command; -import java.io.IOException; -import java.util.List; - -import org.jline.reader.Candidate; -import org.jline.reader.Completer; -import org.jline.reader.LineReader; -import org.jline.reader.LineReaderBuilder; -import org.jline.reader.ParsedLine; -import org.jline.reader.UserInterruptException; +import org.jline.reader.*; import org.jline.terminal.Terminal; import org.jline.terminal.TerminalBuilder; import org.jline.utils.InfoCmp; +import java.io.IOException; +import java.util.List; + public class JLineCommandHandler extends CommandHandler { /*private final class JLineOutput implements Output { @Override @@ -36,16 +31,13 @@ public class JLineConsoleCompleter implements Completer { @Override public void complete(LineReader reader, ParsedLine line, List candidates) { String completeWord = line.word(); - if (line.wordIndex() == 0) - { + if (line.wordIndex() == 0) { walk((category, name, command) -> { if (name.startsWith(completeWord)) { candidates.add(command.buildCandidate(category, name)); } }); - } - else - { + } else { Command target = findCommand(line.words().get(0)); List words = line.words(); List candidates1 = target.complete(words.subList(1, words.size()), line.wordIndex() - 1, completeWord); diff --git a/LauncherCore/src/main/java/pro/gravit/utils/command/StdCommandHandler.java b/LauncherCore/src/main/java/pro/gravit/utils/command/StdCommandHandler.java index 7c0a8930..5bb297aa 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/command/StdCommandHandler.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/command/StdCommandHandler.java @@ -1,11 +1,11 @@ package pro.gravit.utils.command; -import java.io.BufferedReader; -import java.io.IOException; - import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.JVMHelper; +import java.io.BufferedReader; +import java.io.IOException; + public class StdCommandHandler extends CommandHandler { private final BufferedReader reader; @@ -20,19 +20,16 @@ public void bell() { @Override public void clear() throws IOException { - System.out.flush(); - if (JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) - { - try { - new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor(); - } catch (InterruptedException ex) { - throw new IOException(ex); - } - } - else - { - System.out.print("\033[H\033[2J"); - System.out.flush(); + System.out.flush(); + if (JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) { + try { + new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor(); + } catch (InterruptedException ex) { + throw new IOException(ex); + } + } else { + System.out.print("\033[H\033[2J"); + System.out.flush(); } } diff --git a/LauncherCore/src/main/java/pro/gravit/utils/command/basic/HelpCommand.java b/LauncherCore/src/main/java/pro/gravit/utils/command/basic/HelpCommand.java index d6b167b0..f051196a 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/command/basic/HelpCommand.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/command/basic/HelpCommand.java @@ -1,16 +1,15 @@ package pro.gravit.utils.command.basic; -import java.util.Arrays; -import java.util.Map.Entry; - import org.fusesource.jansi.Ansi; - import pro.gravit.utils.command.Command; import pro.gravit.utils.command.CommandException; import pro.gravit.utils.command.CommandHandler; import pro.gravit.utils.helper.FormatHelper; import pro.gravit.utils.helper.LogHelper; +import java.util.Arrays; +import java.util.Map.Entry; + public final class HelpCommand extends Command { private final CommandHandler handler; @@ -32,22 +31,17 @@ public static void printCommand(String name, Command command) { }, () -> LogHelper.htmlFormatLog(LogHelper.Level.INFO, LogHelper.getDataTime(), String.format("%s %s - %s", name, args == null ? "[nothing]" : args, command.getUsageDescription()), true)); } - public static void printSubCommandsHelp(String base, Command command) - { + public static void printSubCommandsHelp(String base, Command command) { command.childCommands.forEach((k, v) -> printCommand(base.concat(" ").concat(k), v)); } - public static void printSubCommandsHelp(String name, String[] args, Command command) throws CommandException - { - if(args.length == 0) - { + public static void printSubCommandsHelp(String name, String[] args, Command command) throws CommandException { + if (args.length == 0) { printSubCommandsHelp(name, command); - } - else - { + } else { Command child = command.childCommands.get(args[0]); - if(child == null) throw new CommandException(String.format("Unknown sub command: '%s'", args[0])); - printSubCommandsHelp(name.concat(" ").concat(args[0]), Arrays.copyOfRange(args,1 , args.length), child); + if (child == null) throw new CommandException(String.format("Unknown sub command: '%s'", args[0])); + printSubCommandsHelp(name.concat(" ").concat(args[0]), Arrays.copyOfRange(args, 1, args.length), child); } } @@ -78,9 +72,9 @@ public void invoke(String... args) throws CommandException { } // Print command help - if(args.length == 1) + if (args.length == 1) printCommand(args[0]); - printSubCommandsHelp(args[0], Arrays.copyOfRange(args, 1 , args.length), handler.lookup(args[0])); + printSubCommandsHelp(args[0], Arrays.copyOfRange(args, 1, args.length), handler.lookup(args[0])); } private void printCommand(String name) throws CommandException { diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/CommonHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/CommonHelper.java index a7dc68a1..177aaabc 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/CommonHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/CommonHelper.java @@ -1,5 +1,12 @@ package pro.gravit.utils.helper; +import com.google.gson.*; +import pro.gravit.launcher.LauncherAPI; +import pro.gravit.utils.command.CommandException; + +import javax.script.ScriptEngine; +import javax.script.ScriptEngineFactory; +import javax.script.ScriptEngineManager; import java.lang.reflect.Type; import java.util.Base64; import java.util.Collection; @@ -8,23 +15,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import javax.script.ScriptEngine; -import javax.script.ScriptEngineFactory; -import javax.script.ScriptEngineManager; - -import com.google.gson.GsonBuilder; -import com.google.gson.JsonArray; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonParseException; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; - -import pro.gravit.launcher.LauncherAPI; -import pro.gravit.utils.command.CommandException; - public final class CommonHelper { @LauncherAPI public static final ScriptEngineManager scriptManager = new ScriptEngineManager(); @@ -136,23 +126,24 @@ public static String[] parseCommand(CharSequence line) throws CommandException { @LauncherAPI public static GsonBuilder newBuilder() { - return new GsonBuilder().registerTypeHierarchyAdapter(byte[].class, + return new GsonBuilder().registerTypeHierarchyAdapter(byte[].class, ByteArrayToBase64TypeAdapter.INSTANCE); } private static class ByteArrayToBase64TypeAdapter implements JsonSerializer, JsonDeserializer { - private static final ByteArrayToBase64TypeAdapter INSTANCE = new ByteArrayToBase64TypeAdapter(); - private final Base64.Decoder decoder = Base64.getUrlDecoder(); - private final Base64.Encoder encoder = Base64.getUrlEncoder(); - public byte[] deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { - if (json.isJsonArray()) { - JsonArray byteArr = json.getAsJsonArray(); - byte[] arr = new byte[byteArr.size()]; - for (int i = 0; i < arr.length; i++) { - arr[i] = byteArr.get(i).getAsByte(); - } - return arr; - } + private static final ByteArrayToBase64TypeAdapter INSTANCE = new ByteArrayToBase64TypeAdapter(); + private final Base64.Decoder decoder = Base64.getUrlDecoder(); + private final Base64.Encoder encoder = Base64.getUrlEncoder(); + + public byte[] deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + if (json.isJsonArray()) { + JsonArray byteArr = json.getAsJsonArray(); + byte[] arr = new byte[byteArr.size()]; + for (int i = 0; i < arr.length; i++) { + arr[i] = byteArr.get(i).getAsByte(); + } + return arr; + } return decoder.decode(json.getAsString()); } diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/FormatHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/FormatHelper.java index 3ae5bb7c..f4c46571 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/FormatHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/FormatHelper.java @@ -1,7 +1,6 @@ package pro.gravit.utils.helper; import org.fusesource.jansi.Ansi; - import pro.gravit.utils.Version; /* diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java index e8929abe..c75bfe0d 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java @@ -1,51 +1,16 @@ package pro.gravit.utils.helper; +import pro.gravit.launcher.LauncherAPI; + +import javax.imageio.ImageIO; +import javax.imageio.ImageReader; import java.awt.image.BufferedImage; -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.ByteArrayOutputStream; -import java.io.EOFException; -import java.io.FileDescriptor; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.UnsupportedEncodingException; -import java.net.HttpURLConnection; -import java.net.InetSocketAddress; -import java.net.MalformedURLException; -import java.net.Socket; -import java.net.SocketAddress; -import java.net.SocketException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.net.URLConnection; -import java.net.URLDecoder; -import java.net.URLEncoder; +import java.io.*; +import java.net.*; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -import java.nio.file.CopyOption; -import java.nio.file.DirectoryStream; import java.nio.file.FileSystem; -import java.nio.file.FileSystems; -import java.nio.file.FileVisitOption; -import java.nio.file.FileVisitResult; -import java.nio.file.FileVisitor; -import java.nio.file.Files; -import java.nio.file.InvalidPathException; -import java.nio.file.LinkOption; -import java.nio.file.NoSuchFileException; -import java.nio.file.OpenOption; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.StandardCopyOption; -import java.nio.file.StandardOpenOption; +import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; import java.util.Collections; import java.util.Set; @@ -56,13 +21,9 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; -import javax.imageio.ImageIO; -import javax.imageio.ImageReader; - -import pro.gravit.launcher.LauncherAPI; - public final class IOHelper { - public static final long MB32 = 1 << 25; + public static final long MB32 = 1 << 25; + private static final class DeleteDirVisitor extends SimpleFileVisitor { private final Path dir; private final boolean self; @@ -168,7 +129,7 @@ public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOExce private static final Pattern CROSS_SEPARATOR_PATTERN = Pattern.compile(CROSS_SEPARATOR, Pattern.LITERAL); private static final Pattern PLATFORM_SEPARATOR_PATTERN = Pattern.compile(PLATFORM_SEPARATOR, Pattern.LITERAL); - public static final String USER_AGENT = System.getProperty("launcher.userAgentDefault", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); + public static final String USER_AGENT = System.getProperty("launcher.userAgentDefault", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); @LauncherAPI public static void close(AutoCloseable closeable) { diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java index 934e8518..d5a140cc 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java @@ -1,5 +1,7 @@ package pro.gravit.utils.helper; +import pro.gravit.launcher.LauncherAPI; + import java.io.File; import java.lang.invoke.MethodHandles; import java.lang.management.ManagementFactory; @@ -13,8 +15,6 @@ import java.util.Locale; import java.util.Map; -import pro.gravit.launcher.LauncherAPI; - public final class JVMHelper { @LauncherAPI public enum OS { @@ -111,10 +111,9 @@ public static URL[] getClassPathURL() { return list; } - public static X509Certificate[] getCertificates(Class clazz) - { + public static X509Certificate[] getCertificates(Class clazz) { Object[] signers = clazz.getSigners(); - if(signers == null) return null; + if (signers == null) return null; return Arrays.stream(signers).filter((c) -> c instanceof X509Certificate).map((c) -> (X509Certificate) c).toArray(X509Certificate[]::new); } diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/LogHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/LogHelper.java index 4c9b1d05..9767dafc 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/LogHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/LogHelper.java @@ -1,10 +1,12 @@ package pro.gravit.utils.helper; -import java.io.IOException; -import java.io.OutputStream; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.io.Writer; +import org.fusesource.jansi.Ansi; +import org.fusesource.jansi.AnsiConsole; +import org.fusesource.jansi.AnsiOutputStream; +import pro.gravit.launcher.LauncherAPI; +import pro.gravit.launcher.LauncherNetworkAPI; + +import java.io.*; import java.nio.file.Path; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -17,13 +19,6 @@ import java.util.function.Consumer; import java.util.function.Supplier; -import org.fusesource.jansi.Ansi; -import org.fusesource.jansi.AnsiConsole; -import org.fusesource.jansi.AnsiOutputStream; - -import pro.gravit.launcher.LauncherAPI; -import pro.gravit.launcher.LauncherNetworkAPI; - public final class LogHelper { @LauncherAPI public static final String DEBUG_PROPERTY = "launcher.debug"; diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/SecurityHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/SecurityHelper.java index 194d8094..6bd343ae 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/SecurityHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/SecurityHelper.java @@ -1,11 +1,20 @@ package pro.gravit.utils.helper; +import pro.gravit.launcher.LauncherAPI; + +import javax.crypto.Cipher; +import javax.crypto.KeyGenerator; +import javax.crypto.NoSuchPaddingException; +import javax.crypto.SecretKey; +import javax.crypto.spec.SecretKeySpec; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.nio.file.Path; import java.security.*; -import java.security.interfaces.*; +import java.security.interfaces.ECKey; +import java.security.interfaces.ECPrivateKey; +import java.security.interfaces.ECPublicKey; import java.security.spec.ECGenParameterSpec; import java.security.spec.InvalidKeySpecException; import java.security.spec.PKCS8EncodedKeySpec; @@ -14,13 +23,6 @@ import java.util.Map; import java.util.Random; -import javax.crypto.Cipher; -import javax.crypto.KeyGenerator; -import javax.crypto.NoSuchPaddingException; -import javax.crypto.SecretKey; -import javax.crypto.spec.SecretKeySpec; -import pro.gravit.launcher.LauncherAPI; - public final class SecurityHelper { public enum DigestAlgorithm { @@ -426,21 +428,18 @@ public static String verifyToken(String token) { return VerifyHelper.verify(token, SecurityHelper::isValidToken, String.format("Invalid token: '%s'", token)); } - public static Cipher newECDecryptCipher(ECPrivateKey privateKey) - { + public static Cipher newECDecryptCipher(ECPrivateKey privateKey) { try { return newECCipher(Cipher.DECRYPT_MODE, privateKey); - } catch (SecurityException e) - { + } catch (SecurityException e) { throw new InternalError(e); } } - public static Cipher newECEncryptCipher(ECPublicKey publicKey) - { + + public static Cipher newECEncryptCipher(ECPublicKey publicKey) { try { return newECCipher(Cipher.ENCRYPT_MODE, publicKey); - } catch (SecurityException e) - { + } catch (SecurityException e) { throw new InternalError(e); } } @@ -481,8 +480,9 @@ public static byte[] decrypt(byte[] raw, byte[] encrypted) throws Exception { cipher.init(Cipher.DECRYPT_MODE, sKeySpec); return cipher.doFinal(encrypted); } + public static byte[] decrypt(String seed, byte[] encrypted) throws Exception { - return decrypt( getRawKey(seed.getBytes()), encrypted); + return decrypt(getRawKey(seed.getBytes()), encrypted); } public static byte[] HexToByte(String hexString) { diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/VerifyHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/VerifyHelper.java index 310049d3..4db1741b 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/VerifyHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/VerifyHelper.java @@ -1,5 +1,7 @@ package pro.gravit.utils.helper; +import pro.gravit.launcher.LauncherAPI; + import java.util.Map; import java.util.Objects; import java.util.function.DoublePredicate; @@ -8,8 +10,6 @@ import java.util.function.Predicate; import java.util.regex.Pattern; -import pro.gravit.launcher.LauncherAPI; - public final class VerifyHelper { @LauncherAPI public static final IntPredicate POSITIVE = i -> i > 0; diff --git a/LauncherCore/src/main/java/pro/gravit/utils/verify/LauncherTrustManager.java b/LauncherCore/src/main/java/pro/gravit/utils/verify/LauncherTrustManager.java index 17fb58f5..1171c947 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/verify/LauncherTrustManager.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/verify/LauncherTrustManager.java @@ -25,11 +25,11 @@ public class LauncherTrustManager { public LauncherTrustManager(X509Certificate[] trustSigners) { this.trustSigners = trustSigners; } + public LauncherTrustManager(byte[][] encodedCertificate) throws CertificateException { CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); trustSigners = Arrays.stream(encodedCertificate).map((cert) -> { - try(InputStream input = new ByteArrayInputStream(cert)) - { + try (InputStream input = new ByteArrayInputStream(cert)) { return (X509Certificate) certFactory.generateCertificate(input); } catch (IOException | CertificateException e) { LogHelper.error(e); @@ -38,37 +38,29 @@ public LauncherTrustManager(byte[][] encodedCertificate) throws CertificateExcep }).toArray(X509Certificate[]::new); } - public enum CheckMode - { + public enum CheckMode { EXCEPTION_IN_NOT_SIGNED, WARN_IN_NOT_SIGNED, NONE_IN_NOT_SIGNED } - public interface CertificateChecker - { + public interface CertificateChecker { void check(X509Certificate cert, X509Certificate signer) throws SecurityException; } public void checkCertificate(X509Certificate[] certs, CertificateChecker checker) throws CertificateException, NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyException, SignatureException { - if(certs == null) throw new SecurityException("Object not signed"); - for(int i=0;i< certs.length;++i) - { + if (certs == null) throw new SecurityException("Object not signed"); + for (int i = 0; i < certs.length; ++i) { X509Certificate cert = certs[i]; - if(trustCache.contains(cert)) - { + if (trustCache.contains(cert)) { //Добавляем в кеш все проверенные сертификаты trustCache.addAll(Arrays.asList(certs).subList(0, i)); return; } - X509Certificate signer = (i+1 < certs.length) ? certs[i+1] : null; + X509Certificate signer = (i + 1 < certs.length) ? certs[i + 1] : null; cert.checkValidity(); - if(signer != null) - { + if (signer != null) { cert.verify(signer.getPublicKey()); - } - else - { - if(!isTrusted(cert)) - { + } else { + if (!isTrusted(cert)) { throw new CertificateException(String.format("Certificate %s is not signed by a trusted signer", cert.getSubjectDN().getName())); } } @@ -76,14 +68,14 @@ public void checkCertificate(X509Certificate[] certs, CertificateChecker checker } Collections.addAll(trustCache, certs); } + public boolean isTrusted(X509Certificate certificate) throws CertificateEncodingException { //Java API не дает возможности вызвать getFingerprint //Oracle использует хак с кастом к sun.security.x509.X509CertImpl для проверки равенства сертификатов //Мы пойдем более медленным путем - for(X509Certificate cert : trustSigners) - { - if(cert.getSerialNumber().equals(certificate.getSerialNumber()) //Проверка serialNumber (быстро) - && Arrays.equals(cert.getEncoded(), certificate.getEncoded())) //Полная проверка (медленно) + for (X509Certificate cert : trustSigners) { + if (cert.getSerialNumber().equals(certificate.getSerialNumber()) //Проверка serialNumber (быстро) + && Arrays.equals(cert.getEncoded(), certificate.getEncoded())) //Полная проверка (медленно) { return true; } diff --git a/LauncherCore/src/test/java/pro/gravit/launcher/CommandHandlerTest.java b/LauncherCore/src/test/java/pro/gravit/launcher/CommandHandlerTest.java index a12b43b9..87a4e73b 100644 --- a/LauncherCore/src/test/java/pro/gravit/launcher/CommandHandlerTest.java +++ b/LauncherCore/src/test/java/pro/gravit/launcher/CommandHandlerTest.java @@ -3,53 +3,49 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; - import pro.gravit.launcher.impl.Test2Command; import pro.gravit.launcher.impl.TestCommand; -import pro.gravit.utils.command.BaseCommandCategory; -import pro.gravit.utils.command.Command; -import pro.gravit.utils.command.CommandException; -import pro.gravit.utils.command.CommandHandler; -import pro.gravit.utils.command.StdCommandHandler; +import pro.gravit.utils.command.*; public class CommandHandlerTest { public static CommandHandler commandHandler; + @BeforeAll public static void prepare() { commandHandler = new StdCommandHandler(false); commandHandler.registerCommand("test", new TestCommand()); } + @Test public void baseTest() throws Exception { commandHandler.evalNative("test test1 \"test 2\" \"test\\\" 3\" \"test\\\\ 4\"", false); Assertions.assertTrue(((TestCommand) commandHandler.findCommand("test")).ok); } + @Test public void failNumberTest() throws Exception { Command cmd = commandHandler.findCommand("test"); try { cmd.invoke("test1"); Assertions.fail("CommandException not throw"); - } catch (CommandException ignored) - { + } catch (CommandException ignored) { } } + @Test - public void categoryTest() throws Exception - { + public void categoryTest() throws Exception { BaseCommandCategory category = new BaseCommandCategory(); category.registerCommand("test2", new Test2Command()); - CommandHandler.Category category1 = new CommandHandler.Category(category,"testCat"); + CommandHandler.Category category1 = new CommandHandler.Category(category, "testCat"); commandHandler.registerCategory(category1); commandHandler.evalNative("test2", false); commandHandler.unregisterCategory(category1); try { commandHandler.evalNative("test2", false); Assertions.fail("CommandException not throw"); - } catch (CommandException ignored) - { + } catch (CommandException ignored) { } } diff --git a/LauncherCore/src/test/java/pro/gravit/launcher/SerializeTest.java b/LauncherCore/src/test/java/pro/gravit/launcher/SerializeTest.java index bab3dff3..3e495855 100644 --- a/LauncherCore/src/test/java/pro/gravit/launcher/SerializeTest.java +++ b/LauncherCore/src/test/java/pro/gravit/launcher/SerializeTest.java @@ -1,12 +1,10 @@ package pro.gravit.launcher; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - import com.google.gson.Gson; import com.google.gson.GsonBuilder; - +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import pro.gravit.utils.ProviderMap; import pro.gravit.utils.UniversalJsonAdapter; @@ -14,12 +12,12 @@ public class SerializeTest { public static GsonBuilder builder; public static Gson gson; public static ProviderMap map; - public interface TestInterface - { + + public interface TestInterface { String get(); } - public static class MyTestClass implements TestInterface - { + + public static class MyTestClass implements TestInterface { public final String a; public MyTestClass(String a) { @@ -31,8 +29,8 @@ public String get() { return a; } } - public static class MyTestClass2 implements TestInterface - { + + public static class MyTestClass2 implements TestInterface { public final String b; public MyTestClass2(String a) { @@ -44,9 +42,9 @@ public String get() { return b; } } + @BeforeAll - public static void prepare() - { + public static void prepare() { builder = new GsonBuilder(); map = new ProviderMap<>(); map.register("test", MyTestClass.class); @@ -54,9 +52,9 @@ public static void prepare() builder.registerTypeAdapter(TestInterface.class, new UniversalJsonAdapter<>(map)); gson = builder.create(); } + @Test - public void main() - { + public void main() { Assertions.assertNotNull(gson); String json = gson.toJson(new MyTestClass("AAAA"), TestInterface.class); String json2 = gson.toJson(new MyTestClass2("BBBB"), TestInterface.class); diff --git a/LauncherCore/src/test/java/pro/gravit/launcher/impl/TestCommand.java b/LauncherCore/src/test/java/pro/gravit/launcher/impl/TestCommand.java index e8eb16ba..09fc9861 100644 --- a/LauncherCore/src/test/java/pro/gravit/launcher/impl/TestCommand.java +++ b/LauncherCore/src/test/java/pro/gravit/launcher/impl/TestCommand.java @@ -4,6 +4,7 @@ public class TestCommand extends Command { public boolean ok = true; + @Override public String getArgsDescription() { return "TEST ARGS"; @@ -17,20 +18,16 @@ public String getUsageDescription() { @Override public void invoke(String... args) throws Exception { verifyArgs(args, 4); - if(!args[0].equals("test1")) - { + if (!args[0].equals("test1")) { throw new IllegalArgumentException(args[0]); } - if(!args[1].equals("test 2")) - { + if (!args[1].equals("test 2")) { throw new IllegalArgumentException(args[1]); } - if(!args[2].equals("test\" 3")) - { + if (!args[2].equals("test\" 3")) { throw new IllegalArgumentException(args[2]); } - if(!args[3].equals("test\\ 4")) - { + if (!args[3].equals("test\\ 4")) { throw new IllegalArgumentException(args[3]); } ok = true; diff --git a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerAgent.java b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerAgent.java index 79aac34a..4f75ce4d 100644 --- a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerAgent.java +++ b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerAgent.java @@ -1,5 +1,8 @@ package pro.gravit.launcher.server; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.LogHelper; + import java.io.IOException; import java.lang.instrument.Instrumentation; import java.lang.invoke.MethodHandle; @@ -12,9 +15,6 @@ import java.nio.file.attribute.BasicFileAttributes; import java.util.jar.JarFile; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.LogHelper; - public class ServerAgent { private static boolean isAgentStarted = false; public static Instrumentation inst = null; diff --git a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java index e6135e10..c5959b90 100644 --- a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java +++ b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java @@ -1,17 +1,5 @@ package pro.gravit.launcher.server; -import java.io.IOException; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; -import java.lang.reflect.Type; -import java.net.URL; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.security.spec.InvalidKeySpecException; -import java.util.Arrays; -import java.util.HashMap; - import pro.gravit.launcher.ClientPermissions; import pro.gravit.launcher.Launcher; import pro.gravit.launcher.LauncherConfig; @@ -31,6 +19,18 @@ import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.SecurityHelper; +import java.io.IOException; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; +import java.lang.reflect.Type; +import java.net.URL; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.security.spec.InvalidKeySpecException; +import java.util.Arrays; +import java.util.HashMap; + public class ServerWrapper extends JsonConfigurable { public static ServerWrapperModulesManager modulesManager; public Config config; diff --git a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapperGsonManager.java b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapperGsonManager.java index a40c0aa1..77e2e4d8 100644 --- a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapperGsonManager.java +++ b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapperGsonManager.java @@ -1,7 +1,6 @@ package pro.gravit.launcher.server; import com.google.gson.GsonBuilder; - import pro.gravit.launcher.managers.GsonManager; import pro.gravit.launcher.modules.events.PreGsonPhase; import pro.gravit.launcher.request.websockets.ClientWebSocketService; diff --git a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapperModulesManager.java b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapperModulesManager.java index b8c11eb7..7d91dc90 100644 --- a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapperModulesManager.java +++ b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapperModulesManager.java @@ -1,15 +1,15 @@ package pro.gravit.launcher.server; -import java.nio.file.Path; - import pro.gravit.launcher.modules.impl.SimpleModuleManager; +import java.nio.file.Path; + public class ServerWrapperModulesManager extends SimpleModuleManager { public ServerWrapperModulesManager(Path modulesDir, Path configDir) { super(modulesDir, configDir); } - public void fullInitializeServerWrapper(ServerWrapper serverWrapper) - { + + public void fullInitializeServerWrapper(ServerWrapper serverWrapper) { initContext = new ServerWrapperInitContext(serverWrapper); } } diff --git a/ServerWrapper/src/main/java/pro/gravit/launcher/server/setup/ServerWrapperCommands.java b/ServerWrapper/src/main/java/pro/gravit/launcher/server/setup/ServerWrapperCommands.java index 8c6bd417..5d3477e2 100644 --- a/ServerWrapper/src/main/java/pro/gravit/launcher/server/setup/ServerWrapperCommands.java +++ b/ServerWrapper/src/main/java/pro/gravit/launcher/server/setup/ServerWrapperCommands.java @@ -1,12 +1,12 @@ package pro.gravit.launcher.server.setup; -import java.io.IOException; - import pro.gravit.utils.command.CommandHandler; import pro.gravit.utils.command.JLineCommandHandler; import pro.gravit.utils.command.StdCommandHandler; import pro.gravit.utils.helper.LogHelper; +import java.io.IOException; + public class ServerWrapperCommands { public final CommandHandler commandHandler; diff --git a/ServerWrapper/src/main/java/pro/gravit/launcher/server/setup/ServerWrapperSetup.java b/ServerWrapper/src/main/java/pro/gravit/launcher/server/setup/ServerWrapperSetup.java index 9d79ce68..12cbf82e 100644 --- a/ServerWrapper/src/main/java/pro/gravit/launcher/server/setup/ServerWrapperSetup.java +++ b/ServerWrapper/src/main/java/pro/gravit/launcher/server/setup/ServerWrapperSetup.java @@ -1,5 +1,11 @@ package pro.gravit.launcher.server.setup; +import pro.gravit.launcher.server.ServerWrapper; +import pro.gravit.utils.PublicURLClassLoader; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.JVMHelper; +import pro.gravit.utils.helper.LogHelper; + import java.io.IOException; import java.io.Writer; import java.net.URL; @@ -8,12 +14,6 @@ import java.nio.file.Paths; import java.util.jar.JarFile; -import pro.gravit.launcher.server.ServerWrapper; -import pro.gravit.utils.PublicURLClassLoader; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.JVMHelper; -import pro.gravit.utils.helper.LogHelper; - public class ServerWrapperSetup { public ServerWrapperCommands commands; public PublicURLClassLoader urlClassLoader; diff --git a/modules b/modules index fdadbdfc..20f48bfc 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit fdadbdfc3c6aae0a90e8c80cc971da47a5db82b0 +Subproject commit 20f48bfce37dc77d2d7025e7e997251c2b2e100d From b9761637db4ce8f6d6d463db929ca8f1eee1bc59 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 19 Oct 2019 23:52:57 +0700 Subject: [PATCH 026/192] =?UTF-8?q?[ANY]=20=D0=A7=D0=B8=D1=81=D1=82=D0=BA?= =?UTF-8?q?=D0=B0=20LauncherConfig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../binary/tasks/MainBuildTask.java | 2 +- .../launcher/ClientLauncherWrapper.java | 2 +- .../pro/gravit/launcher/client/DirBridge.java | 2 +- .../launcher/guard/LauncherStdGuard.java | 11 ++---- .../launcher/guard/LauncherWrapperGuard.java | 11 ++---- .../pro/gravit/launcher/AutogenConfig.java | 3 -- .../pro/gravit/launcher/LauncherConfig.java | 37 ++----------------- 7 files changed, 13 insertions(+), 55 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java index faf37520..60b17d06 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java @@ -195,7 +195,7 @@ public Path process(Path inputJar) throws IOException { byte[] launcherConfigBytes; try (ByteArrayOutputStream configArray = IOHelper.newByteArrayOutput()) { try (HOutput configOutput = new HOutput(configArray)) { - new LauncherConfig(server.config.netty.address, server.publicKey, runtime) + new LauncherConfig(server.config.netty.address, server.publicKey, runtime, server.config.projectName) .write(configOutput); } launcherConfigBytes = configArray.toByteArray(); diff --git a/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java b/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java index e2aeaada..9838ffe5 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java +++ b/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java @@ -33,7 +33,7 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep LauncherEngine.modulesManager = new ClientModuleManager(); LauncherConfig.getAutogenConfig().initModules(); - LogHelper.info("Launcher for project %s", config.projectname); + LogHelper.info("Launcher for project %s", config.projectName); if (config.environment.equals(LauncherConfig.LauncherEnvironment.PROD)) { if (System.getProperty(LogHelper.DEBUG_PROPERTY) != null) { LogHelper.warning("Found -Dlauncher.debug=true"); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/DirBridge.java b/Launcher/src/main/java/pro/gravit/launcher/client/DirBridge.java index 347b764c..6e4ff2dd 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/DirBridge.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/DirBridge.java @@ -102,7 +102,7 @@ public static void setUseLegacyDir(boolean b) { } static { - String projectName = Launcher.getConfig().projectname; + String projectName = Launcher.getConfig().projectName; try { DirBridge.dir = getLauncherDir(projectName); if (!IOHelper.exists(DirBridge.dir)) Files.createDirectories(DirBridge.dir); diff --git a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherStdGuard.java b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherStdGuard.java index b24bcadb..96d17677 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherStdGuard.java +++ b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherStdGuard.java @@ -29,7 +29,7 @@ public String getName() { public Path getJavaBinPath() { if (JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) { javaBinPath = ClientLauncher.getJavaBinPath(); - String projectName = Launcher.getConfig().projectname; + String projectName = Launcher.getConfig().projectName; String wrapperUnpackName = (javaBinPath == null ? JVMHelper.JVM_BITS : JVMHelper.OS_BITS) == 64 ? projectName.concat("64.exe") : projectName.concat("32.exe"); return DirBridge.getGuardDir().resolve(wrapperUnpackName); } else @@ -48,7 +48,7 @@ public int getClientJVMBits() { @Override public void init(boolean clientInstance) { try { - String projectName = Launcher.getConfig().projectname; + String projectName = Launcher.getConfig().projectName; UnpackHelper.unpack(Launcher.getResourceURL("wrapper64.exe", "guard"), DirBridge.getGuardDir().resolve(projectName.concat("64.exe"))); UnpackHelper.unpack(Launcher.getResourceURL("AntiInject64.dll", "guard"), DirBridge.getGuardDir().resolve("AntiInject64.dll")); @@ -73,14 +73,9 @@ public void addCustomEnv(ClientLauncherContext context) { env.put("JAVA_HOME", javaBinPath.toAbsolutePath().toString()); LauncherConfig config = Launcher.getConfig(); env.put("GUARD_USERNAME", context.playerProfile.username); - env.put("GUARD_PROJECTNAME", config.projectname); + env.put("GUARD_PROJECTNAME", config.projectName); if (protectToken != null) env.put("GUARD_TOKEN", protectToken); - if (config.guardLicenseName != null) - env.put("GUARD_LICENSE_NAME", config.guardLicenseName); - if (config.guardLicenseKey != null) { - env.put("GUARD_LICENSE_KEY", config.guardLicenseKey); - } } @Override diff --git a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherWrapperGuard.java b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherWrapperGuard.java index 725cb1fc..fe841e79 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherWrapperGuard.java +++ b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherWrapperGuard.java @@ -26,7 +26,7 @@ public String getName() { @Override public Path getJavaBinPath() { if (JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) { - String projectName = Launcher.getConfig().projectname; + String projectName = Launcher.getConfig().projectName; String wrapperUnpackName = JVMHelper.JVM_BITS == 64 ? projectName.concat("64.exe") : projectName.concat("32.exe"); return DirBridge.getGuardDir().resolve(wrapperUnpackName); } else @@ -42,7 +42,7 @@ public int getClientJVMBits() { public void init(boolean clientInstance) { try { String wrapperName = JVMHelper.JVM_BITS == 64 ? "wrapper64.exe" : "wrapper32.exe"; - String projectName = Launcher.getConfig().projectname; + String projectName = Launcher.getConfig().projectName; String wrapperUnpackName = JVMHelper.JVM_BITS == 64 ? projectName.concat("64.exe") : projectName.concat("32.exe"); String antiInjectName = JVMHelper.JVM_BITS == 64 ? "AntiInject64.dll" : "AntiInject32.dll"; UnpackHelper.unpack(Launcher.getResourceURL(wrapperName, "guard"), DirBridge.getGuardDir().resolve(wrapperUnpackName)); @@ -63,14 +63,9 @@ public void addCustomEnv(ClientLauncherContext context) { env.put("JAVA_HOME", System.getProperty("java.home")); LauncherConfig config = Launcher.getConfig(); env.put("GUARD_USERNAME", context.playerProfile.username); - env.put("GUARD_PROJECTNAME", config.projectname); + env.put("GUARD_PROJECTNAME", config.projectName); if (protectToken != null) env.put("GUARD_TOKEN", protectToken); - if (config.guardLicenseName != null) - env.put("GUARD_LICENSE_NAME", config.guardLicenseName); - if (config.guardLicenseKey != null) { - env.put("GUARD_LICENSE_KEY", config.guardLicenseKey); - } } @Override diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/AutogenConfig.java b/LauncherAPI/src/main/java/pro/gravit/launcher/AutogenConfig.java index 67f19b48..da1d710c 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/AutogenConfig.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/AutogenConfig.java @@ -7,9 +7,6 @@ public class AutogenConfig { public String guardType; public String secretKeyClient; public String oemUnlockKey; - public String guardLicenseName; - public String guardLicenseKey; - public String guardLicenseEncryptKey; public String secureCheckHash; public String secureCheckSalt; public String passwordEncryptKey; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java b/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java index 1d64cf48..c916c8b7 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java @@ -25,7 +25,7 @@ public static AutogenConfig getAutogenConfig() { // Instance public String address; @LauncherAPI - public final String projectname; + public final String projectName; public final int clientPort; public String secretKeyClient; public String oemUnlockKey; @@ -39,9 +39,6 @@ public static AutogenConfig getAutogenConfig() { public boolean isNettyEnabled; public LauncherEnvironment environment; - public final String guardLicenseName; - public final String guardLicenseKey; - public final String guardLicenseEncryptKey; public final String guardType; public final String secureCheckHash; @@ -54,7 +51,7 @@ public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException secureCheckHash = config.secureCheckHash; secureCheckSalt = config.secureCheckSalt; passwordEncryptKey = config.passwordEncryptKey; - projectname = config.projectname; + projectName = config.projectname; clientPort = config.clientPort; secretKeyClient = config.secretKeyClient; oemUnlockKey = config.oemUnlockKey; @@ -65,10 +62,7 @@ public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException } isWarningMissArchJava = config.isWarningMissArchJava; - guardLicenseEncryptKey = config.guardLicenseEncryptKey; - guardLicenseKey = config.guardLicenseKey; guardType = config.guardType; - guardLicenseName = config.guardLicenseName; address = config.address; LauncherEnvironment env; if (config.env == 0) env = LauncherEnvironment.DEV; @@ -91,34 +85,11 @@ public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException } @LauncherAPI - public LauncherConfig(String address, ECPublicKey publicKey, Map runtime, String projectname) { + public LauncherConfig(String address, ECPublicKey publicKey, Map runtime, String projectName) { this.address = address; this.publicKey = Objects.requireNonNull(publicKey, "publicKey"); this.runtime = Collections.unmodifiableMap(new HashMap<>(runtime)); - this.projectname = projectname; - this.clientPort = 32148; - this.guardLicenseName = "FREE"; - this.guardLicenseKey = "AAAA-BBBB-CCCC-DDDD"; - this.guardLicenseEncryptKey = "12345"; - guardType = "no"; - isWarningMissArchJava = true; - isNettyEnabled = false; - environment = LauncherEnvironment.STD; - secureCheckSalt = null; - secureCheckHash = null; - passwordEncryptKey = null; - trustManager = null; - } - - @LauncherAPI - public LauncherConfig(String address, ECPublicKey publicKey, Map runtime) { - this.address = address; - this.publicKey = Objects.requireNonNull(publicKey, "publicKey"); - this.runtime = Collections.unmodifiableMap(new HashMap<>(runtime)); - this.projectname = "Minecraft"; - this.guardLicenseName = "FREE"; - this.guardLicenseKey = "AAAA-BBBB-CCCC-DDDD"; - this.guardLicenseEncryptKey = "12345"; + this.projectName = projectName; this.clientPort = 32148; guardType = "no"; isWarningMissArchJava = true; From 0cab4f254e85be33799b098fcb1eb4213863261f Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 19 Oct 2019 23:57:23 +0700 Subject: [PATCH 027/192] =?UTF-8?q?[FIX]=20=D0=94=D0=BE=D1=81=D1=82=D1=83?= =?UTF-8?q?=D0=BF=20=D0=B8=D0=B7=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D1=8F=20?= =?UTF-8?q?=D0=BA=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D1=8E=20?= =?UTF-8?q?=D1=81=D0=B2=D0=BE=D0=B8=D1=85=20=D0=B7=D0=B0=D1=89=D0=B8=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launcher/guard/LauncherGuardManager.java | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherGuardManager.java b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherGuardManager.java index 14d9a38d..6b4e763b 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherGuardManager.java +++ b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherGuardManager.java @@ -9,22 +9,25 @@ public class LauncherGuardManager { public static LauncherGuardInterface guard; public static void initGuard(boolean clientInstance) { - LauncherConfig config = Launcher.getConfig(); - switch (config.guardType) { - case "gravitguard": { - guard = new LauncherStdGuard(); - break; - } - case "wrapper": { - guard = new LauncherWrapperGuard(); - break; - } - case "java": { - guard = new LauncherJavaGuard(); - break; - } - default: { - guard = new LauncherNoGuard(); + if(guard == null) + { + LauncherConfig config = Launcher.getConfig(); + switch (config.guardType) { + case "stdguard": { + guard = new LauncherStdGuard(); + break; + } + case "wrapper": { + guard = new LauncherWrapperGuard(); + break; + } + case "java": { + guard = new LauncherJavaGuard(); + break; + } + default: { + guard = new LauncherNoGuard(); + } } } guard.init(clientInstance); From d9e5e3d3508ec65e4b76ea4a4fa10a7469fa6d58 Mon Sep 17 00:00:00 2001 From: zaxar163 Date: Sat, 19 Oct 2019 20:38:24 +0300 Subject: [PATCH 028/192] =?UTF-8?q?[FEATURE][EXP]=20=D0=90=D0=B2=D1=82?= =?UTF-8?q?=D0=BE=D0=B3=D0=B5=D0=BD=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=D0=B0,=20=D0=BD=D1=83?= =?UTF-8?q?=D0=B6=D0=B5=D0=BD=20=D1=82=D0=B5=D1=81=D1=82!!!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../binary/tasks/MainBuildTask.java | 19 ++++++++++++++++++- .../gravit/launcher/SecureAutogenConfig.java | 12 +++++++----- .../utils/verify/LauncherTrustManager.java | 9 +++++++-- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java index 60b17d06..22be4c3e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java @@ -5,9 +5,11 @@ import pro.gravit.launcher.AutogenConfig; import pro.gravit.launcher.Launcher; import pro.gravit.launcher.LauncherConfig; +import pro.gravit.launcher.SecureAutogenConfig; import pro.gravit.launcher.serialize.HOutput; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.asm.ClassMetadataReader; +import pro.gravit.launchserver.asm.ConfigGenerator; import pro.gravit.launchserver.binary.BuildContext; import pro.gravit.launchserver.binary.LauncherConfigurator; import pro.gravit.utils.helper.IOHelper; @@ -20,10 +22,13 @@ import java.nio.file.Path; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; +import java.security.cert.CertificateEncodingException; +import java.util.Arrays; import java.util.Base64; import java.util.HashMap; import java.util.Map; import java.util.jar.JarFile; +import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipException; import java.util.zip.ZipInputStream; @@ -120,6 +125,9 @@ public Path process(Path inputJar) throws IOException { ClassNode cn = new ClassNode(); new ClassReader(IOHelper.getResourceBytes(AutogenConfig.class.getName().replace('.', '/').concat(".class"))).accept(cn, 0); LauncherConfigurator launcherConfigurator = new LauncherConfigurator(cn); + ClassNode cn1 = new ClassNode(); + new ClassReader(IOHelper.getResourceBytes(SecureAutogenConfig.class.getName().replace('.', '/').concat(".class"))).accept(cn, 0); + ConfigGenerator secureConfigurator = new ConfigGenerator(cn1); BuildContext context = new BuildContext(output, launcherConfigurator, this); server.buildHookManager.hook(context); launcherConfigurator.setStringField("address", server.config.netty.address); @@ -130,6 +138,14 @@ public Path process(Path inputJar) throws IOException { launcherConfigurator.setBooleanField("isWarningMissArchJava", server.config.launcher.warningMissArchJava); launcherConfigurator.setEnv(server.config.env); launcherConfigurator.setStringField("passwordEncryptKey", server.runtime.passwordEncryptKey); + secureConfigurator.setByteArrayListField("certificates", Arrays.stream(server.certificateManager.trustManager.getTrusted()).map(e -> { + try { + return e.getEncoded(); + } catch (CertificateEncodingException e2) { + LogHelper.error(e2); + return new byte[0]; + } + }).collect(Collectors.toList())); String launcherSalt = SecurityHelper.randomStringToken(); byte[] launcherSecureHash = SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA256, server.runtime.clientCheckSecret.concat(".").concat(launcherSalt)); @@ -148,11 +164,12 @@ public Path process(Path inputJar) throws IOException { } }); String zPath = launcherConfigurator.getZipEntryPath(); + String sPath = secureConfigurator.getZipEntryPath(); try (ZipInputStream input = new ZipInputStream(IOHelper.newInput(inputJar))) { ZipEntry e = input.getNextEntry(); while (e != null) { String filename = e.getName(); - if (server.buildHookManager.isContainsBlacklist(filename) || e.isDirectory() || zPath.equals(filename)) { + if (server.buildHookManager.isContainsBlacklist(filename) || e.isDirectory() || zPath.equals(filename) || sPath.equals(filename)) { e = input.getNextEntry(); continue; } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/SecureAutogenConfig.java b/LauncherAPI/src/main/java/pro/gravit/launcher/SecureAutogenConfig.java index 6a0b9443..15c94a06 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/SecureAutogenConfig.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/SecureAutogenConfig.java @@ -1,13 +1,17 @@ package pro.gravit.launcher; +import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.List; public class SecureAutogenConfig { - public final byte[][] certificates; + public static final Charset KEY_CHARSET = StandardCharsets.US_ASCII; // ? Какая из них, но выбрать надо однозачно проверить методом тыка!!! + public final List certificates; public SecureAutogenConfig() { //Пока не реализован SecureLauncherConfigurator - certificates = new byte[][]{ + certificates = Arrays.asList( ("-----BEGIN CERTIFICATE-----\n" + "MIIFyjCCA7KgAwIBAgIRALnsjNjfvOTXfla3fX1fNEUwDQYJKoZIhvcNAQELBQAw\n" + "WTELMAkGA1UEBhMCUlUxFzAVBgNVBAoTDkdyYXZpdFRydXN0IENBMRAwDgYDVQQL\n" + @@ -40,8 +44,6 @@ public SecureAutogenConfig() { "OATWgSKH0qTkleE/v7k+USs0a+KV8wmC5wwliqH+uLO++yIP/9bjDctyLulQX5Ee\n" + "+EhD7tb1R/yyWY4uhkzlsr3N2Kl34aQAEBMn8Z1mHsyyu1FcbEaNLU8jcS3pHPVM\n" + "gQRn3m1iDnQlFciAMxW0pW6mW/4xKYzhXk5BTSolnqMVylxHgWXuBwdDDQQVnQ==\n" + - "-----END CERTIFICATE-----").getBytes(StandardCharsets.US_ASCII) - // ? Какая из них, но выбрать надо однозачно - }; + "-----END CERTIFICATE-----").getBytes(KEY_CHARSET)); } } diff --git a/LauncherCore/src/main/java/pro/gravit/utils/verify/LauncherTrustManager.java b/LauncherCore/src/main/java/pro/gravit/utils/verify/LauncherTrustManager.java index 1171c947..8e4de504 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/verify/LauncherTrustManager.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/verify/LauncherTrustManager.java @@ -26,9 +26,9 @@ public LauncherTrustManager(X509Certificate[] trustSigners) { this.trustSigners = trustSigners; } - public LauncherTrustManager(byte[][] encodedCertificate) throws CertificateException { + public LauncherTrustManager(List encodedCertificate) throws CertificateException { CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); - trustSigners = Arrays.stream(encodedCertificate).map((cert) -> { + trustSigners = encodedCertificate.stream().map((cert) -> { try (InputStream input = new ByteArrayInputStream(cert)) { return (X509Certificate) certFactory.generateCertificate(input); } catch (IOException | CertificateException e) { @@ -82,4 +82,9 @@ public boolean isTrusted(X509Certificate certificate) throws CertificateEncoding } return false; } + + + public X509Certificate[] getTrusted() { + return Arrays.copyOf(trustSigners, trustSigners.length); // AntiModify orig array!!! + } } From 908bd1cb76fa91bd00ae14a38dec828ca68db72d Mon Sep 17 00:00:00 2001 From: zaxar163 Date: Sat, 19 Oct 2019 20:41:08 +0300 Subject: [PATCH 029/192] =?UTF-8?q?[FIX]=20=D0=97=D0=B0=D0=B1=D1=8B=D1=82?= =?UTF-8?q?=D0=B0=D1=8F=20=D0=B7=D0=B0=D0=BF=D0=B8=D1=81=D1=8C=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=D0=B0=20=D0=B2=20jar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launchserver/binary/tasks/MainBuildTask.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java index 22be4c3e..f1d7f0bc 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java @@ -224,6 +224,10 @@ public Path process(Path inputJar) throws IOException { ZipEntry e = newZipEntry(zPath); output.putNextEntry(e); output.write(launcherConfigurator.getBytecode(reader)); + + e = newZipEntry(sPath); + output.putNextEntry(e); + output.write(secureConfigurator.getBytecode(reader)); } reader.close(); return outputJar; From 8d098108d0056a235393202dac9dababc85f34be Mon Sep 17 00:00:00 2001 From: zaxar163 Date: Sat, 19 Oct 2019 20:45:05 +0300 Subject: [PATCH 030/192] [FIX] Copy-paste shit --- .../pro/gravit/launchserver/binary/tasks/MainBuildTask.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java index f1d7f0bc..5742cdfb 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java @@ -126,7 +126,7 @@ public Path process(Path inputJar) throws IOException { new ClassReader(IOHelper.getResourceBytes(AutogenConfig.class.getName().replace('.', '/').concat(".class"))).accept(cn, 0); LauncherConfigurator launcherConfigurator = new LauncherConfigurator(cn); ClassNode cn1 = new ClassNode(); - new ClassReader(IOHelper.getResourceBytes(SecureAutogenConfig.class.getName().replace('.', '/').concat(".class"))).accept(cn, 0); + new ClassReader(IOHelper.getResourceBytes(SecureAutogenConfig.class.getName().replace('.', '/').concat(".class"))).accept(cn1, 0); ConfigGenerator secureConfigurator = new ConfigGenerator(cn1); BuildContext context = new BuildContext(output, launcherConfigurator, this); server.buildHookManager.hook(context); From 898dcb3ea05a4cb7d1ff182ef54e554cce314f9f Mon Sep 17 00:00:00 2001 From: zaxar163 Date: Sat, 19 Oct 2019 20:50:51 +0300 Subject: [PATCH 031/192] [FIX] Invalid bytecode(1) --- .../main/java/pro/gravit/launcher/SecureAutogenConfig.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/SecureAutogenConfig.java b/LauncherAPI/src/main/java/pro/gravit/launcher/SecureAutogenConfig.java index 15c94a06..fd73d18e 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/SecureAutogenConfig.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/SecureAutogenConfig.java @@ -11,7 +11,7 @@ public class SecureAutogenConfig { public SecureAutogenConfig() { //Пока не реализован SecureLauncherConfigurator - certificates = Arrays.asList( + certificates = null/*Arrays.asList( ("-----BEGIN CERTIFICATE-----\n" + "MIIFyjCCA7KgAwIBAgIRALnsjNjfvOTXfla3fX1fNEUwDQYJKoZIhvcNAQELBQAw\n" + "WTELMAkGA1UEBhMCUlUxFzAVBgNVBAoTDkdyYXZpdFRydXN0IENBMRAwDgYDVQQL\n" + @@ -44,6 +44,6 @@ public SecureAutogenConfig() { "OATWgSKH0qTkleE/v7k+USs0a+KV8wmC5wwliqH+uLO++yIP/9bjDctyLulQX5Ee\n" + "+EhD7tb1R/yyWY4uhkzlsr3N2Kl34aQAEBMn8Z1mHsyyu1FcbEaNLU8jcS3pHPVM\n" + "gQRn3m1iDnQlFciAMxW0pW6mW/4xKYzhXk5BTSolnqMVylxHgWXuBwdDDQQVnQ==\n" + - "-----END CERTIFICATE-----").getBytes(KEY_CHARSET)); + "-----END CERTIFICATE-----").getBytes(KEY_CHARSET));*/ } } From f5fe5afe81815f121ed9b0f9d62232963f02f2d4 Mon Sep 17 00:00:00 2001 From: zaxar163 Date: Sat, 19 Oct 2019 20:51:50 +0300 Subject: [PATCH 032/192] =?UTF-8?q?[FIX]=20=D0=9E=D1=88=D0=B8=D0=B1=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=B8=D0=BB=D1=8F=D1=86=D0=B8?= =?UTF-8?q?=D0=B8=20+=20[FIX]=20=D0=9E=D0=BF=D0=BA=D0=BE=D0=B4=D1=8B=20sta?= =?UTF-8?q?tic/virtual=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BF=D1=83=D1=82=D0=B0?= =?UTF-8?q?=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/pro/gravit/launchserver/asm/ConfigGenerator.java | 4 ++-- .../main/java/pro/gravit/launcher/SecureAutogenConfig.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ConfigGenerator.java b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ConfigGenerator.java index 0d1ac656..c39ecc2a 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ConfigGenerator.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ConfigGenerator.java @@ -44,7 +44,7 @@ public void setByteArrayField(String name, byte[] value) { constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/util/Base64", "getDecoder", "()Ljava/util/Base64$Decoder;", false)); constructor.instructions.add(NodeUtils.getSafeStringInsnList(Base64.getEncoder().encodeToString(value))); - constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/util/Base64$Decoder", "decode", base64DecDesc, false)); + constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/util/Base64$Decoder", "decode", base64DecDesc, false)); constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, configclass.name, name, stringDesc)); } @@ -57,7 +57,7 @@ public void setByteArrayListField(String name, List b) { constructor.instructions.add(new InsnNode(Opcodes.DUP)); constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/util/Base64", "getDecoder", "()Ljava/util/Base64$Decoder;", false)); constructor.instructions.add(NodeUtils.getSafeStringInsnList(Base64.getEncoder().encodeToString(value))); - constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/util/Base64$Decoder", "decode", base64DecDesc, false)); + constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/util/Base64$Decoder", "decode", base64DecDesc, false)); constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", false)); constructor.instructions.add(new InsnNode(Opcodes.POP)); } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/SecureAutogenConfig.java b/LauncherAPI/src/main/java/pro/gravit/launcher/SecureAutogenConfig.java index fd73d18e..76519415 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/SecureAutogenConfig.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/SecureAutogenConfig.java @@ -11,7 +11,7 @@ public class SecureAutogenConfig { public SecureAutogenConfig() { //Пока не реализован SecureLauncherConfigurator - certificates = null/*Arrays.asList( + certificates = null;/*Arrays.asList( ("-----BEGIN CERTIFICATE-----\n" + "MIIFyjCCA7KgAwIBAgIRALnsjNjfvOTXfla3fX1fNEUwDQYJKoZIhvcNAQELBQAw\n" + "WTELMAkGA1UEBhMCUlUxFzAVBgNVBAoTDkdyYXZpdFRydXN0IENBMRAwDgYDVQQL\n" + From 5ed233613fe8f4b8695f182136657ba3ffdfb283 Mon Sep 17 00:00:00 2001 From: zaxar163 Date: Sat, 19 Oct 2019 21:08:18 +0300 Subject: [PATCH 033/192] =?UTF-8?q?[FIX]=20=D0=97=D0=B0=D0=B1=D1=8B=D1=82?= =?UTF-8?q?=D1=8B=D0=B9=20POP...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/pro/gravit/launchserver/asm/ConfigGenerator.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ConfigGenerator.java b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ConfigGenerator.java index c39ecc2a..cb6d9ee2 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ConfigGenerator.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ConfigGenerator.java @@ -54,13 +54,14 @@ public void setByteArrayListField(String name, List b) { constructor.instructions.add(new InsnNode(Opcodes.DUP)); constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/util/ArrayList", "", "()V")); for (byte[] value : b) { - constructor.instructions.add(new InsnNode(Opcodes.DUP)); + constructor.instructions.add(new InsnNode(Opcodes.DUP)); // +1-1 constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/util/Base64", "getDecoder", "()Ljava/util/Base64$Decoder;", false)); constructor.instructions.add(NodeUtils.getSafeStringInsnList(Base64.getEncoder().encodeToString(value))); constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/util/Base64$Decoder", "decode", base64DecDesc, false)); - constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", false)); + constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", true)); constructor.instructions.add(new InsnNode(Opcodes.POP)); } + constructor.instructions.add(new InsnNode(Opcodes.POP)); // needs -1 constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, configclass.name, name, "Ljava/util/List;")); } From cfc63b535e02695d0eb7de0c2d00fe7d4fbc4b5c Mon Sep 17 00:00:00 2001 From: zaxar163 Date: Sat, 19 Oct 2019 21:17:51 +0300 Subject: [PATCH 034/192] =?UTF-8?q?[FIX]=20=D0=9E=D0=BA=D0=BE=D0=BD=D1=87?= =?UTF-8?q?=D0=B0=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20=D1=84=D0=B8?= =?UTF-8?q?=D0=BA=D1=81...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/pro/gravit/launchserver/asm/ConfigGenerator.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ConfigGenerator.java b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ConfigGenerator.java index cb6d9ee2..ab66442c 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ConfigGenerator.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ConfigGenerator.java @@ -51,7 +51,7 @@ public void setByteArrayField(String name, byte[] value) { public void setByteArrayListField(String name, List b) { constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); constructor.instructions.add(new TypeInsnNode(Opcodes.NEW, "java/util/ArrayList")); - constructor.instructions.add(new InsnNode(Opcodes.DUP)); + constructor.instructions.add(new InsnNode(Opcodes.DUP)); // +1 constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/util/ArrayList", "", "()V")); for (byte[] value : b) { constructor.instructions.add(new InsnNode(Opcodes.DUP)); // +1-1 @@ -61,7 +61,6 @@ public void setByteArrayListField(String name, List b) { constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", true)); constructor.instructions.add(new InsnNode(Opcodes.POP)); } - constructor.instructions.add(new InsnNode(Opcodes.POP)); // needs -1 constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, configclass.name, name, "Ljava/util/List;")); } From 12f5c7ef65b25ba5dcfd240eba0c99c33368d2f8 Mon Sep 17 00:00:00 2001 From: zaxar163 Date: Sat, 19 Oct 2019 21:21:48 +0300 Subject: [PATCH 035/192] [ANY] Oraganize imports. --- .../src/main/java/pro/gravit/launcher/SecureAutogenConfig.java | 1 - 1 file changed, 1 deletion(-) diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/SecureAutogenConfig.java b/LauncherAPI/src/main/java/pro/gravit/launcher/SecureAutogenConfig.java index 76519415..fc34057b 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/SecureAutogenConfig.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/SecureAutogenConfig.java @@ -2,7 +2,6 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -import java.util.Arrays; import java.util.List; public class SecureAutogenConfig { From d8536482ff57e96df24d3fab37bf488b086b5cca Mon Sep 17 00:00:00 2001 From: Gravit Date: Sun, 20 Oct 2019 02:58:05 +0700 Subject: [PATCH 036/192] =?UTF-8?q?[FIX]=20=D0=9E=D0=B1=D1=8F=D0=B7=D0=B0?= =?UTF-8?q?=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D0=B0=D1=8F=20=D0=BF=D0=BE=D0=B4?= =?UTF-8?q?=D0=BF=D0=B8=D1=81=D1=8C=20=D0=BB=D0=B0=D1=83=D0=BD=D1=87=D0=B5?= =?UTF-8?q?=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launcher/LauncherEngine.java | 32 +++++++++++++++---- .../launcher/client/ClientLauncher.java | 3 ++ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index 96bff818..5f67a456 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -1,9 +1,6 @@ package pro.gravit.launcher; -import pro.gravit.launcher.client.ClientModuleManager; -import pro.gravit.launcher.client.DirBridge; -import pro.gravit.launcher.client.FunctionalBridge; -import pro.gravit.launcher.client.LauncherUpdateController; +import pro.gravit.launcher.client.*; import pro.gravit.launcher.client.events.ClientEngineInitPhase; import pro.gravit.launcher.client.events.ClientPreGuiPhase; import pro.gravit.launcher.guard.LauncherGuardManager; @@ -13,6 +10,7 @@ import pro.gravit.launcher.managers.ClientGsonManager; import pro.gravit.launcher.managers.ClientHookManager; import pro.gravit.launcher.managers.ConsoleManager; +import pro.gravit.launcher.modules.LauncherModule; import pro.gravit.launcher.modules.events.PreConfigPhase; import pro.gravit.launcher.request.Request; import pro.gravit.launcher.request.RequestException; @@ -20,11 +18,13 @@ import pro.gravit.launcher.request.update.UpdateRequest; import pro.gravit.launcher.request.websockets.StandartClientWebSocketService; import pro.gravit.utils.helper.*; +import pro.gravit.utils.verify.LauncherTrustManager; import java.io.IOException; import java.nio.file.Path; -import java.security.KeyPair; -import java.security.SecureRandom; +import java.security.*; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; import java.security.interfaces.ECPrivateKey; import java.security.interfaces.ECPublicKey; import java.security.spec.InvalidKeySpecException; @@ -34,6 +34,22 @@ public class LauncherEngine { public static final AtomicBoolean IS_CLIENT = new AtomicBoolean(false); + public static void checkClass(Class clazz) throws SecurityException { + LauncherTrustManager trustManager = Launcher.getConfig().trustManager; + if (trustManager == null) return; + X509Certificate[] certificates = JVMHelper.getCertificates(clazz); + if (certificates == null) { + throw new SecurityException(String.format("Class %s not signed", clazz.getName())); + } + try { + trustManager.checkCertificate(certificates, (c, s) -> { + + }); + } catch (CertificateException | NoSuchProviderException | NoSuchAlgorithmException | InvalidKeyException | SignatureException e) { + throw new SecurityException(e); + } + } + public static void main(String... args) throws Throwable { JVMHelper.checkStackTrace(LauncherEngine.class); JVMHelper.verifySystemProperties(Launcher.class, true); @@ -41,7 +57,9 @@ public static void main(String... args) throws Throwable { //if(!LauncherAgent.isStarted()) throw new SecurityException("JavaAgent not set"); LogHelper.printVersion("Launcher"); LogHelper.printLicense("Launcher"); - + LauncherEngine.checkClass(LauncherEngine.class); + LauncherEngine.checkClass(LauncherAgent.class); + LauncherEngine.checkClass(ClientLauncher.class); LauncherEngine.modulesManager = new ClientModuleManager(); LauncherConfig.getAutogenConfig().initModules(); LauncherEngine.modulesManager.initModules(null); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index 30800ff7..79959151 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -426,6 +426,9 @@ public ClientLaunchContext(Params params, ClientProfile profile, HashedDir asset public static void main(String... args) throws Throwable { LauncherEngine.IS_CLIENT.set(true); LauncherEngine engine = LauncherEngine.clientInstance(); + LauncherEngine.checkClass(LauncherEngine.class); + LauncherEngine.checkClass(LauncherAgent.class); + LauncherEngine.checkClass(ClientLauncher.class); LauncherEngine.modulesManager = new ClientModuleManager(); LauncherConfig.getAutogenConfig().initModules(); //INIT LauncherEngine.modulesManager.initModules(null); From 21a90f05400469e31560a7beac1e7a6a846a8e5d Mon Sep 17 00:00:00 2001 From: Gravit Date: Sun, 20 Oct 2019 04:13:24 +0700 Subject: [PATCH 037/192] =?UTF-8?q?[ANY]=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index 20f48bfc..2e245f2f 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 20f48bfce37dc77d2d7025e7e997251c2b2e100d +Subproject commit 2e245f2fb44c705cba08328acc68187b78d607c7 From 2b87d67e92e0f81f11188a4e18cbdd3c717d2446 Mon Sep 17 00:00:00 2001 From: zaxar163 Date: Sun, 20 Oct 2019 09:27:40 +0300 Subject: [PATCH 038/192] =?UTF-8?q?[ANY]=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B8?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index 2e245f2f..83438df1 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 2e245f2fb44c705cba08328acc68187b78d607c7 +Subproject commit 83438df1eaf2089d7abb23137a57b96c708cfbfe From f1dcae53b562e5422007d14c3071a69be3919a99 Mon Sep 17 00:00:00 2001 From: zaxar163 Date: Sun, 20 Oct 2019 12:31:18 +0300 Subject: [PATCH 039/192] =?UTF-8?q?[ANY]=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index 83438df1..bcaa597a 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 83438df1eaf2089d7abb23137a57b96c708cfbfe +Subproject commit bcaa597a85e3ff749144fabc182e47b26f4f14ef From d84b13c319432391c3aca67e8c235548f994126e Mon Sep 17 00:00:00 2001 From: Gravit Date: Sun, 20 Oct 2019 20:40:11 +0700 Subject: [PATCH 040/192] =?UTF-8?q?[FEATURE]=20JarSigner=20=D0=BF=D0=B5?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=B5=D1=81=D0=B5=D0=BD=20=D0=B2=20=D0=BE?= =?UTF-8?q?=D1=81=D0=BD=D0=BE=D0=B2=D0=BD=D1=83=D1=8E=20=D0=B2=D0=B5=D1=82?= =?UTF-8?q?=D0=BA=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../binary/JARLauncherBinary.java | 1 + .../gravit/launchserver/binary/SignerJar.java | 287 ++++++++++++++++++ .../binary/tasks/SignJarTask.java | 78 +++++ .../config/LaunchServerConfig.java | 12 + .../launchserver/helper/SignHelper.java | 158 ++++++++++ modules | 2 +- 6 files changed, 537 insertions(+), 1 deletion(-) create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/binary/SignerJar.java create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/helper/SignHelper.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JARLauncherBinary.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JARLauncherBinary.java index e28d0f04..b8082682 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JARLauncherBinary.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JARLauncherBinary.java @@ -47,6 +47,7 @@ public void init() { tasks.add(new AdditionalFixesApplyTask(server)); if (!server.config.launcher.attachLibraryBeforeProGuard) tasks.add(new AttachJarsTask(server)); if (server.config.launcher.compress) tasks.add(new CompressBuildTask(server)); + if(server.config.sign.enabled) tasks.add(new SignJarTask(server.config.sign, server)); } @Override diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/SignerJar.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/SignerJar.java new file mode 100644 index 00000000..b0d525cb --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/SignerJar.java @@ -0,0 +1,287 @@ +package pro.gravit.launchserver.binary; + +import org.bouncycastle.cms.CMSProcessableByteArray; +import org.bouncycastle.cms.CMSSignedData; +import org.bouncycastle.cms.CMSSignedDataGenerator; +import org.bouncycastle.cms.CMSTypedData; +import pro.gravit.launchserver.helper.SignHelper; +import pro.gravit.utils.helper.IOHelper; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Arrays; +import java.util.Base64; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.function.Supplier; +import java.util.jar.Attributes; +import java.util.jar.Manifest; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + + +/** + * Generator of signed Jars. It stores some data in memory therefore it is not suited for creation of large files. The + * usage: + *
+ * KeyStore keystore = KeyStore.getInstance("JKS");
+ * keyStore.load(keystoreStream, "keystorePassword");
+ * SignerJar jar = new SignerJar(out, keyStore, "keyAlias", "keyPassword");
+ * signedJar.addManifestAttribute("Main-Class", "com.example.MainClass");
+ * signedJar.addManifestAttribute("Application-Name", "Example");
+ * signedJar.addManifestAttribute("Permissions", "all-permissions");
+ * signedJar.addManifestAttribute("Codebase", "*");
+ * signedJar.addFileContents("com/example/MainClass.class", clsData);
+ * signedJar.addFileContents("JNLP-INF/APPLICATION.JNLP", generateJnlpContents());
+ * signedJar.close();
+ * 
+ */ +public class SignerJar implements AutoCloseable { + + private static final String MANIFEST_FN = "META-INF/MANIFEST.MF"; + private static final String SIG_FN = "META-INF/SIGNUMO.SF"; + private static final String SIG_RSA_FN = "META-INF/SIGNUMO.RSA"; + private static final String DIGEST_HASH = SignHelper.hashFunctionName + "-Digest"; + + private final ZipOutputStream zos; + + private final Map manifestAttributes; + private String manifestHash; + private String manifestMainHash; + + private final Map fileDigests; + + private final Map sectionDigests; + private final Supplier gen; + + public SignerJar(ZipOutputStream out, Supplier gen) { + zos = out; + this.gen = gen; + manifestAttributes = new LinkedHashMap<>(); + fileDigests = new LinkedHashMap<>(); + sectionDigests = new LinkedHashMap<>(); + } + + /** + * Adds a file to the JAR. The file is immediately added to the zipped output stream. This method cannot be called once + * the stream is closed. + * + * @param filename name of the file to add (use forward slash as a path separator) + * @param contents contents of the file + * @throws IOException + * @throws NullPointerException if any of the arguments is {@code null} + */ + public void addFileContents(String filename, byte[] contents) throws IOException { + addFileContents(filename, new ByteArrayInputStream(contents)); + } + + /** + * Adds a file to the JAR. The file is immediately added to the zipped output stream. This method cannot be called once + * the stream is closed. + * + * @param filename name of the file to add (use forward slash as a path separator) + * @param contents contents of the file + * @throws IOException + * @throws NullPointerException if any of the arguments is {@code null} + */ + public void addFileContents(String filename, InputStream contents) throws IOException { + addFileContents(IOHelper.newZipEntry(filename), contents); + } + + /** + * Adds a file to the JAR. The file is immediately added to the zipped output stream. This method cannot be called once + * the stream is closed. + * + * @param entry name of the file to add (use forward slash as a path separator) + * @param contents contents of the file + * @throws IOException + * @throws NullPointerException if any of the arguments is {@code null} + */ + public void addFileContents(ZipEntry entry, byte[] contents) throws IOException { + addFileContents(entry, new ByteArrayInputStream(contents)); + } + + /** + * Adds a file to the JAR. The file is immediately added to the zipped output stream. This method cannot be called once + * the stream is closed. + * + * @param entry name of the file to add (use forward slash as a path separator) + * @param contents contents of the file + * @throws IOException + * @throws NullPointerException if any of the arguments is {@code null} + */ + public void addFileContents(ZipEntry entry, InputStream contents) throws IOException { + zos.putNextEntry(entry); + SignHelper.HashingOutputStream out = new SignHelper.HashingNonClosingOutputStream(zos, SignHelper.hasher()); + IOHelper.transfer(contents, out); + zos.closeEntry(); + fileDigests.put(entry.getName(), Base64.getEncoder().encodeToString(out.digest())); + } + + /** + * Adds a header to the manifest of the JAR. + * + * @param name name of the attribute, it is placed into the main section of the manifest file + * @param value value of the attribute + */ + public void addManifestAttribute(String name, String value) { + manifestAttributes.put(name, value); + } + + + /** + * Closes the JAR file by writing the manifest and signature data to it and finishing the ZIP entries. It closes the + * underlying stream. + * + * @throws IOException + * @throws RuntimeException if the signing goes wrong + */ + @Override + public void close() throws IOException { + finish(); + zos.close(); + } + + + /** + * Finishes the JAR file by writing the manifest and signature data to it and finishing the ZIP entries. It leaves the + * underlying stream open. + * + * @throws IOException + * @throws RuntimeException if the signing goes wrong + */ + public void finish() throws IOException { + writeManifest(); + byte[] sig = writeSigFile(); + writeSignature(sig); + zos.finish(); + } + + public ZipOutputStream getZos() { + return zos; + } + + /** + * Helper for {@link #writeManifest()} that creates the digest of one entry. + */ + private String hashEntrySection(String name, Attributes attributes) throws IOException { + Manifest manifest = new Manifest(); + manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); + ByteArrayOutputStream o = new ByteArrayOutputStream(); + manifest.write(o); + int emptyLen = o.toByteArray().length; + + manifest.getEntries().put(name, attributes); + + manifest.write(o); + byte[] ob = o.toByteArray(); + ob = Arrays.copyOfRange(ob, emptyLen, ob.length); + return Base64.getEncoder().encodeToString(SignHelper.hasher().digest(ob)); + } + + /** + * Helper for {@link #writeManifest()} that creates the digest of the main section. + */ + private String hashMainSection(Attributes attributes) throws IOException { + Manifest manifest = new Manifest(); + manifest.getMainAttributes().putAll(attributes); + SignHelper.HashingOutputStream o = new SignHelper.HashingNonClosingOutputStream(SignHelper.NULL, SignHelper.hasher()); + manifest.write(o); + return Base64.getEncoder().encodeToString(o.digest()); + } + + /** + * Returns the CMS signed data. + */ + private byte[] signSigFile(byte[] sigContents) throws Exception { + CMSSignedDataGenerator gen = this.gen.get(); + CMSTypedData cmsData = new CMSProcessableByteArray(sigContents); + CMSSignedData signedData = gen.generate(cmsData, true); + return signedData.getEncoded(); + } + + /** + * Writes the manifest to the JAR. It also calculates the digests that are required to be placed in the the signature + * file. + * + * @throws IOException + */ + private void writeManifest() throws IOException { + zos.putNextEntry(IOHelper.newZipEntry(MANIFEST_FN)); + Manifest man = new Manifest(); + + // main section + Attributes mainAttributes = man.getMainAttributes(); + mainAttributes.put(Attributes.Name.MANIFEST_VERSION, "1.0"); + + for (Map.Entry entry : manifestAttributes.entrySet()) + mainAttributes.put(new Attributes.Name(entry.getKey()), entry.getValue()); + + // individual files sections + Attributes.Name digestAttr = new Attributes.Name(DIGEST_HASH); + for (Map.Entry entry : fileDigests.entrySet()) { + Attributes attributes = new Attributes(); + man.getEntries().put(entry.getKey(), attributes); + attributes.put(digestAttr, entry.getValue()); + sectionDigests.put(entry.getKey(), hashEntrySection(entry.getKey(), attributes)); + } + + SignHelper.HashingOutputStream out = new SignHelper.HashingNonClosingOutputStream(zos, SignHelper.hasher()); + man.write(out); + zos.closeEntry(); + + manifestHash = Base64.getEncoder().encodeToString(out.digest()); + manifestMainHash = hashMainSection(man.getMainAttributes()); + } + + /** + * Writes the .SIG file to the JAR. + * + * @return the contents of the file as bytes + */ + private byte[] writeSigFile() throws IOException { + zos.putNextEntry(IOHelper.newZipEntry(SIG_FN)); + Manifest man = new Manifest(); + // main section + Attributes mainAttributes = man.getMainAttributes(); + mainAttributes.put(Attributes.Name.SIGNATURE_VERSION, "1.0"); + mainAttributes.put(new Attributes.Name(DIGEST_HASH + "-Manifest"), manifestHash); + mainAttributes.put(new Attributes.Name(DIGEST_HASH + "-Manifest-Main-Attributes"), manifestMainHash); + + // individual files sections + Attributes.Name digestAttr = new Attributes.Name(DIGEST_HASH); + for (Map.Entry entry : sectionDigests.entrySet()) { + Attributes attributes = new Attributes(); + man.getEntries().put(entry.getKey(), attributes); + attributes.put(digestAttr, entry.getValue()); + } + + man.write(zos); + zos.closeEntry(); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + man.write(baos); + return baos.toByteArray(); + } + + /** + * Signs the .SIG file and writes the signature (.RSA file) to the JAR. + * + * @throws IOException + * @throws RuntimeException if the signing failed + */ + private void writeSignature(byte[] sigFile) throws IOException { + zos.putNextEntry(IOHelper.newZipEntry(SIG_RSA_FN)); + try { + byte[] signature = signSigFile(sigFile); + zos.write(signature); + } catch (IOException e) { + throw e; + } catch (Exception e) { + throw new RuntimeException("Signing failed.", e); + } + zos.closeEntry(); + } +} \ No newline at end of file diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java new file mode 100644 index 00000000..8746b342 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java @@ -0,0 +1,78 @@ +package pro.gravit.launchserver.binary.tasks; + +import org.bouncycastle.cms.CMSException; +import org.bouncycastle.cms.CMSSignedDataGenerator; +import org.bouncycastle.operator.OperatorCreationException; +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launchserver.binary.SignerJar; +import pro.gravit.launchserver.config.LaunchServerConfig; +import pro.gravit.launchserver.helper.SignHelper; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.LogHelper; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.UnrecoverableKeyException; +import java.security.cert.CertificateEncodingException; +import java.util.jar.Manifest; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; +import java.util.zip.ZipOutputStream; + +public class SignJarTask implements LauncherBuildTask { + + private final LaunchServerConfig.JarSignerConf config; + private final LaunchServer srv; + + public SignJarTask(LaunchServerConfig.JarSignerConf config, LaunchServer srv) { + this.config = config; + this.srv = srv; + } + + @Override + public String getName() { + return "SignJar"; + } + + @Override + public Path process(Path inputFile) throws IOException { + Path toRet = srv.launcherBinary.nextPath("signed"); + KeyStore c = SignHelper.getStore(new File(config.keyStore).toPath(), config.keyStorePass, config.keyStoreType); + try (SignerJar output = new SignerJar(new ZipOutputStream(IOHelper.newOutput(toRet)), () -> this.gen(c)); + ZipInputStream input = new ZipInputStream(IOHelper.newInput(inputFile))) { + //input.getManifest().getMainAttributes().forEach((a, b) -> output.addManifestAttribute(a.toString(), b.toString())); // may not work such as after Radon. + ZipEntry e = input.getNextEntry(); + while (e != null) { + if ("META-INF/MANIFEST.MF".equals(e.getName()) || "/META-INF/MANIFEST.MF".equals(e.getName())) { + Manifest m = new Manifest(input); + m.getMainAttributes().forEach((a, b) -> output.addManifestAttribute(a.toString(), b.toString())); + e = input.getNextEntry(); + continue; + } + output.addFileContents(IOHelper.newZipEntry(e), input); + e = input.getNextEntry(); + } + } + return toRet; + } + + @Override + public boolean allowDelete() { + return true; + } + + public CMSSignedDataGenerator gen(KeyStore c) { + try { + return SignHelper.createSignedDataGenerator(c, + config.keyAlias, config.signAlgo, config.keyStorePass); + } catch (CertificateEncodingException | UnrecoverableKeyException | KeyStoreException + | OperatorCreationException | NoSuchAlgorithmException | CMSException e) { + LogHelper.error(e); + return null; + } + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java index fcc9cec0..27b010dd 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java @@ -88,6 +88,7 @@ public AuthProviderPair getAuthProviderPair() { public String whitelistRejectString; public LauncherConf launcher; public CertificateConf certificate; + public JarSignerConf sign; public String startScript; @@ -225,6 +226,16 @@ public static class CertificateConf { public boolean enabled; } + public static class JarSignerConf { + public boolean enabled = true; + public String keyStore = "pathToKey"; + public String keyStoreType = "JKS"; + public String keyStorePass = "mypass"; + public String keyAlias = "myname"; + public String keyPass = "mypass"; + public String signAlgo = "SHA256WITHRSA"; + } + public static class NettyUpdatesBind { public String url; public boolean zip; @@ -324,6 +335,7 @@ public static LaunchServerConfig getDefault(LaunchServer.LaunchServerEnv env) { newConfig.certificate = new LaunchServerConfig.CertificateConf(); newConfig.certificate.enabled = false; + newConfig.sign = new JarSignerConf(); newConfig.components = new HashMap<>(); AuthLimiterComponent authLimiterComponent = new AuthLimiterComponent(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/helper/SignHelper.java b/LaunchServer/src/main/java/pro/gravit/launchserver/helper/SignHelper.java new file mode 100644 index 00000000..86e3a165 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/helper/SignHelper.java @@ -0,0 +1,158 @@ +package pro.gravit.launchserver.helper; + +import org.bouncycastle.cert.jcajce.JcaCertStore; +import org.bouncycastle.cms.CMSException; +import org.bouncycastle.cms.CMSSignedDataGenerator; +import org.bouncycastle.cms.SignerInfoGenerator; +import org.bouncycastle.cms.jcajce.JcaSignerInfoGeneratorBuilder; +import org.bouncycastle.jce.provider.BouncyCastleProvider; +import org.bouncycastle.operator.ContentSigner; +import org.bouncycastle.operator.DigestCalculatorProvider; +import org.bouncycastle.operator.OperatorCreationException; +import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder; +import org.bouncycastle.operator.jcajce.JcaDigestCalculatorProviderBuilder; +import org.bouncycastle.util.Store; +import pro.gravit.utils.helper.IOHelper; + +import java.io.IOException; +import java.io.OutputStream; +import java.nio.file.Path; +import java.security.*; +import java.security.cert.Certificate; +import java.security.cert.CertificateEncodingException; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class SignHelper { + + /** + * Helper output stream that also sends the data to the given. + */ + public static class HashingOutputStream extends OutputStream { + public final OutputStream out; + public final MessageDigest hasher; + + public HashingOutputStream(OutputStream out, MessageDigest hasher) { + this.out = out; + this.hasher = hasher; + } + + @Override + public void close() throws IOException { + out.close(); + } + + @Override + public void flush() throws IOException { + out.flush(); + } + + @Override + public void write(byte[] b) throws IOException { + out.write(b); + hasher.update(b); + } + + @Override + public void write(byte[] b, int off, int len) throws IOException { + out.write(b, off, len); + hasher.update(b, off, len); + } + + @Override + public void write(int b) throws IOException { + out.write(b); + hasher.update((byte) b); + } + + public byte[] digest() { + return hasher.digest(); + } + } + /** + * Helper output stream that also sends the data to the given. + */ + public static class HashingNonClosingOutputStream extends HashingOutputStream { + public HashingNonClosingOutputStream(OutputStream out, MessageDigest hasher) { + super(out, hasher); + } + + @Override + public void close() throws IOException { + // Do nothing + } + } + + public static final OutputStream NULL = new OutputStream() { + @Override + public String toString() { + return "NullOutputStream"; + } + + /** Discards the specified byte array. */ + @Override + public void write(byte[] b) { + } + + /** Discards the specified byte array. */ + @Override + public void write(byte[] b, int off, int len) { + } + + /** Discards the specified byte. */ + @Override + public void write(int b) { + } + + /** Never closes */ + @Override + public void close() { + } + }; + private SignHelper() { + } + + /** + * Creates the KeyStore with given algo. + */ + public static KeyStore getStore(Path file, String storepass, String algo) throws IOException { + try { + KeyStore st = KeyStore.getInstance(algo); + st.load(IOHelper.newInput(file), storepass != null ? storepass.toCharArray() : null); + return st; + } catch (NoSuchAlgorithmException | CertificateException | KeyStoreException e) { + throw new IOException(e); + } + } + + /** + * Creates the beast that can actually sign the data (for JKS, for other make it). + */ + public static CMSSignedDataGenerator createSignedDataGenerator(KeyStore keyStore, String keyAlias, String signAlgo, String keyPassword) throws KeyStoreException, OperatorCreationException, CertificateEncodingException, UnrecoverableKeyException, NoSuchAlgorithmException, CMSException { + List certChain = new ArrayList<>(Arrays.asList(keyStore.getCertificateChain(keyAlias))); + @SuppressWarnings("rawtypes") + Store certStore = new JcaCertStore(certChain); + Certificate cert = keyStore.getCertificate(keyAlias); + PrivateKey privateKey = (PrivateKey) keyStore.getKey(keyAlias, keyPassword != null ? keyPassword.toCharArray() : null); + ContentSigner signer = new JcaContentSignerBuilder(signAlgo).setProvider("BC").build(privateKey); + CMSSignedDataGenerator generator = new CMSSignedDataGenerator(); + DigestCalculatorProvider dcp = new JcaDigestCalculatorProviderBuilder().setProvider("BC").build(); + SignerInfoGenerator sig = new JcaSignerInfoGeneratorBuilder(dcp).build(signer, (X509Certificate) cert); + generator.addSignerInfoGenerator(sig); + generator.addCertificates(certStore); + return generator; + } + + public static final String hashFunctionName = "SHA-256"; + + public static MessageDigest hasher() { + try { + return MessageDigest.getInstance(hashFunctionName); + } catch (NoSuchAlgorithmException e) { + return null; + } + } +} diff --git a/modules b/modules index bcaa597a..6f008f59 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit bcaa597a85e3ff749144fabc182e47b26f4f14ef +Subproject commit 6f008f595975887b6a1366cb444b82b339e3afad From 087e2b5a8cc0f32c433de8acceea8ea1b3b08cee Mon Sep 17 00:00:00 2001 From: zaxar163 Date: Sun, 20 Oct 2019 18:19:27 +0300 Subject: [PATCH 041/192] [FEATURE] CryptoHelper --- .../pro/gravit/utils/helper/CryptoHelper.java | 54 +++++++++++++++++++ .../gravit/utils/helper/SecurityHelper.java | 2 +- 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 LauncherCore/src/main/java/pro/gravit/utils/helper/CryptoHelper.java diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/CryptoHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/CryptoHelper.java new file mode 100644 index 00000000..727243a5 --- /dev/null +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/CryptoHelper.java @@ -0,0 +1,54 @@ +package pro.gravit.utils.helper; + +import java.util.Objects; +import java.util.function.LongSupplier; + +public final class CryptoHelper { + public static byte[] encode(byte[] txt, String pKey) { + Objects.requireNonNull(txt); + Objects.requireNonNull(pKey); + byte[] key = SecurityHelper.fromHex(pKey); + byte[] res = new byte[txt.length]; + for (int i = 0; i < txt.length; i++) + res[i] = (byte) (txt[i] ^ key[i % key.length]); + return res; + } + + public static byte[] decode(byte[] pText, String pKey) { + Objects.requireNonNull(pText); + Objects.requireNonNull(pKey); + byte[] res = new byte[pText.length]; + byte[] key = SecurityHelper.fromHex(pKey); + for (int i = 0; i < pText.length; i++) + res[i] = (byte) (pText[i] ^ key[i % key.length]); + return res; + } + + public static String randomToken(int depth) { + VerifyHelper.verifyInt(depth, VerifyHelper.POSITIVE, "Depth must be positive"); + StringBuilder sb = new StringBuilder(SecurityHelper.TOKEN_STRING_LENGTH*depth); + for (int i = 0; i < depth; i++) + sb.append(SecurityHelper.randomStringToken()); + return sb.toString(); + } + + private CryptoHelper() { + } + + public static class StaticRandom implements LongSupplier { + private volatile long rnd; + + public StaticRandom(long rnd) { + this.rnd = rnd; + } + + @Override + public long getAsLong() { + this.rnd ^= (this.rnd << 21); + this.rnd ^= (this.rnd >>> 35); + this.rnd ^= (this.rnd << 4); + return this.rnd; + } + } + +} diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/SecurityHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/SecurityHelper.java index 6bd343ae..29d4a1f2 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/SecurityHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/SecurityHelper.java @@ -485,7 +485,7 @@ public static byte[] decrypt(String seed, byte[] encrypted) throws Exception { return decrypt(getRawKey(seed.getBytes()), encrypted); } - public static byte[] HexToByte(String hexString) { + public static byte[] fromHex(String hexString) { int len = hexString.length() / 2; byte[] result = new byte[len]; for (int i = 0; i < len; i++) { From 72f938333ae21438850ef087a542f05c36be8b63 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sun, 20 Oct 2019 22:21:58 +0700 Subject: [PATCH 042/192] =?UTF-8?q?[FEATURE]=20=D0=9D=D0=B0=D1=81=D1=82?= =?UTF-8?q?=D1=80=D0=B0=D0=B8=D0=B2=D0=B0=D0=B5=D0=BC=D1=8B=D0=B9=20=D0=B0?= =?UTF-8?q?=D0=BB=D0=BB=D0=B8=D0=B0=D1=81=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B0?= =?UTF-8?q?=20=D0=B2=20=D0=BC=D0=B0=D0=BD=D0=B8=D1=84=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/pro/gravit/launchserver/binary/SignerJar.java | 10 ++++++---- .../gravit/launchserver/binary/tasks/SignJarTask.java | 3 ++- .../gravit/launchserver/config/LaunchServerConfig.java | 2 ++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/SignerJar.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/SignerJar.java index b0d525cb..5da3d5e0 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/SignerJar.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/SignerJar.java @@ -41,8 +41,8 @@ public class SignerJar implements AutoCloseable { private static final String MANIFEST_FN = "META-INF/MANIFEST.MF"; - private static final String SIG_FN = "META-INF/SIGNUMO.SF"; - private static final String SIG_RSA_FN = "META-INF/SIGNUMO.RSA"; + private final String SIG_FN; + private final String SIG_KEY_FN; private static final String DIGEST_HASH = SignHelper.hashFunctionName + "-Digest"; private final ZipOutputStream zos; @@ -56,12 +56,14 @@ public class SignerJar implements AutoCloseable { private final Map sectionDigests; private final Supplier gen; - public SignerJar(ZipOutputStream out, Supplier gen) { + public SignerJar(ZipOutputStream out, Supplier gen, String sig_fn, String sig_key_fn) { zos = out; this.gen = gen; manifestAttributes = new LinkedHashMap<>(); fileDigests = new LinkedHashMap<>(); sectionDigests = new LinkedHashMap<>(); + SIG_FN = "META-INF/".concat(sig_fn); + SIG_KEY_FN = "META-INF/".concat(sig_key_fn); } /** @@ -273,7 +275,7 @@ private byte[] writeSigFile() throws IOException { * @throws RuntimeException if the signing failed */ private void writeSignature(byte[] sigFile) throws IOException { - zos.putNextEntry(IOHelper.newZipEntry(SIG_RSA_FN)); + zos.putNextEntry(IOHelper.newZipEntry(SIG_KEY_FN)); try { byte[] signature = signSigFile(sigFile); zos.write(signature); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java index 8746b342..f1091cc7 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java @@ -42,7 +42,8 @@ public String getName() { public Path process(Path inputFile) throws IOException { Path toRet = srv.launcherBinary.nextPath("signed"); KeyStore c = SignHelper.getStore(new File(config.keyStore).toPath(), config.keyStorePass, config.keyStoreType); - try (SignerJar output = new SignerJar(new ZipOutputStream(IOHelper.newOutput(toRet)), () -> this.gen(c)); + try (SignerJar output = new SignerJar(new ZipOutputStream(IOHelper.newOutput(toRet)), () -> this.gen(c), + config.manifestFileSfName, config.manifestFileSfName); ZipInputStream input = new ZipInputStream(IOHelper.newInput(inputFile))) { //input.getManifest().getMainAttributes().forEach((a, b) -> output.addManifestAttribute(a.toString(), b.toString())); // may not work such as after Radon. ZipEntry e = input.getNextEntry(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java index 27b010dd..a4f29d46 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java @@ -233,6 +233,8 @@ public static class JarSignerConf { public String keyStorePass = "mypass"; public String keyAlias = "myname"; public String keyPass = "mypass"; + public String manifestFileName = "SIGNUMO.RSA"; + public String manifestFileSfName = "SIGNUMO.SF"; public String signAlgo = "SHA256WITHRSA"; } From e1c6775e34b01b0694fbf42d3e2ddba2804635de Mon Sep 17 00:00:00 2001 From: Gravit Date: Sun, 20 Oct 2019 22:55:36 +0700 Subject: [PATCH 043/192] =?UTF-8?q?[FIX]=20=D0=9E=D1=88=D0=B8=D0=B1=D0=BA?= =?UTF-8?q?=D0=B8=20SignJarTask=20=D0=B8=20=D0=BE=D1=82=D0=BA=D0=BB=D1=8E?= =?UTF-8?q?=D1=87=D0=B5=D0=BD=D0=B8=D0=B5=20STRIP=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D0=B1=D0=B8=D0=B1=D0=BB=D0=B8=D0=BE=D1=82=D0=B5=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launchserver/binary/tasks/AdditionalFixesApplyTask.java | 6 +++--- .../gravit/launchserver/binary/tasks/AttachJarsTask.java | 2 +- .../pro/gravit/launchserver/binary/tasks/SignJarTask.java | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/AdditionalFixesApplyTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/AdditionalFixesApplyTask.java index 0aded026..f486e965 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/AdditionalFixesApplyTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/AdditionalFixesApplyTask.java @@ -36,12 +36,12 @@ public String getName() { public Path process(Path inputFile) throws IOException { Path out = server.launcherBinary.nextPath("post-fixed"); try (ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(out))) { - apply(inputFile, inputFile, output, server, (e) -> false); + apply(inputFile, inputFile, output, server, (e) -> false, true); } return out; } - public static void apply(Path inputFile, Path addFile, ZipOutputStream output, LaunchServer srv, Predicate excluder) throws IOException { + public static void apply(Path inputFile, Path addFile, ZipOutputStream output, LaunchServer srv, Predicate excluder, boolean needFixes) throws IOException { try (ClassMetadataReader reader = new ClassMetadataReader()) { reader.getCp().add(new JarFile(inputFile.toFile())); List libs = srv.launcherBinary.coreLibs.stream().map(e -> { @@ -74,7 +74,7 @@ public static void apply(Path inputFile, Path addFile, ZipOutputStream output, L bytes = outputStream.toByteArray(); } try { - bytes = classFix(bytes, reader, srv.config.launcher.stripLineNumbers); + if(needFixes) bytes = classFix(bytes, reader, srv.config.launcher.stripLineNumbers); } catch (Throwable t) { LogHelper.error(t); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/AttachJarsTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/AttachJarsTask.java index 3ceae478..98731a6d 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/AttachJarsTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/AttachJarsTask.java @@ -56,7 +56,7 @@ public Path process(Path inputFile) throws IOException { private void attach(ZipOutputStream output, Path inputFile, List lst) throws IOException { for (Path p : lst) { LogHelper.debug("Attaching: " + p); - AdditionalFixesApplyTask.apply(inputFile, p, output, srv, (e) -> exclusions.stream().anyMatch(e.getName()::startsWith)); + AdditionalFixesApplyTask.apply(inputFile, p, output, srv, (e) -> exclusions.stream().anyMatch(e.getName()::startsWith), false); } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java index f1091cc7..25cc1d5d 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java @@ -43,7 +43,7 @@ public Path process(Path inputFile) throws IOException { Path toRet = srv.launcherBinary.nextPath("signed"); KeyStore c = SignHelper.getStore(new File(config.keyStore).toPath(), config.keyStorePass, config.keyStoreType); try (SignerJar output = new SignerJar(new ZipOutputStream(IOHelper.newOutput(toRet)), () -> this.gen(c), - config.manifestFileSfName, config.manifestFileSfName); + config.manifestFileSfName, config.manifestFileName); ZipInputStream input = new ZipInputStream(IOHelper.newInput(inputFile))) { //input.getManifest().getMainAttributes().forEach((a, b) -> output.addManifestAttribute(a.toString(), b.toString())); // may not work such as after Radon. ZipEntry e = input.getNextEntry(); @@ -69,7 +69,7 @@ public boolean allowDelete() { public CMSSignedDataGenerator gen(KeyStore c) { try { return SignHelper.createSignedDataGenerator(c, - config.keyAlias, config.signAlgo, config.keyStorePass); + config.keyAlias, config.signAlgo, config.keyPass); } catch (CertificateEncodingException | UnrecoverableKeyException | KeyStoreException | OperatorCreationException | NoSuchAlgorithmException | CMSException e) { LogHelper.error(e); From 68cb755212cb24df9211d84e44e4a5a5ae86000f Mon Sep 17 00:00:00 2001 From: Gravit Date: Sun, 20 Oct 2019 23:10:41 +0700 Subject: [PATCH 044/192] =?UTF-8?q?[FIX]=20=D0=91=D0=BE=D0=BB=D0=B5=D0=B5?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=BD=D1=8F=D1=82=D0=BD=D1=8B=D0=B5=20=D0=B8?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launchserver/binary/tasks/SignJarTask.java | 2 +- .../pro/gravit/launchserver/config/LaunchServerConfig.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java index 25cc1d5d..9dd608c8 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java @@ -43,7 +43,7 @@ public Path process(Path inputFile) throws IOException { Path toRet = srv.launcherBinary.nextPath("signed"); KeyStore c = SignHelper.getStore(new File(config.keyStore).toPath(), config.keyStorePass, config.keyStoreType); try (SignerJar output = new SignerJar(new ZipOutputStream(IOHelper.newOutput(toRet)), () -> this.gen(c), - config.manifestFileSfName, config.manifestFileName); + config.metaInfSfName, config.metaInfKeyName); ZipInputStream input = new ZipInputStream(IOHelper.newInput(inputFile))) { //input.getManifest().getMainAttributes().forEach((a, b) -> output.addManifestAttribute(a.toString(), b.toString())); // may not work such as after Radon. ZipEntry e = input.getNextEntry(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java index a4f29d46..5f42a71b 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java @@ -233,8 +233,8 @@ public static class JarSignerConf { public String keyStorePass = "mypass"; public String keyAlias = "myname"; public String keyPass = "mypass"; - public String manifestFileName = "SIGNUMO.RSA"; - public String manifestFileSfName = "SIGNUMO.SF"; + public String metaInfKeyName = "SIGNUMO.RSA"; + public String metaInfSfName = "SIGNUMO.SF"; public String signAlgo = "SHA256WITHRSA"; } From ff30ba267070dd46a7c3eabb6f0a2a550b343bb3 Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 21 Oct 2019 22:34:08 +0700 Subject: [PATCH 045/192] =?UTF-8?q?[FIX]=20=D0=A4=D0=B8=D0=BA=D1=81=20?= =?UTF-8?q?=D0=BD=D0=B5=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BE=D1=81=D0=BF?= =?UTF-8?q?=D0=BE=D1=81=D0=BE=D0=B1=D0=BD=D0=BE=D1=81=D1=82=D0=B8=20Mojang?= =?UTF-8?q?=20=D0=B0=D0=B2=D1=82=D0=BE=D1=80=D0=B8=D0=B7=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launcher/request/auth/JoinServerRequest.java | 2 +- .../authlib/yggdrasil/YggdrasilMinecraftSessionService.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/JoinServerRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/JoinServerRequest.java index 6e2ca2f4..b50ada1a 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/JoinServerRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/JoinServerRequest.java @@ -21,7 +21,7 @@ public final class JoinServerRequest extends Request imp @LauncherAPI public JoinServerRequest(String username, String accessToken, String serverID) { this.username = VerifyHelper.verifyUsername(username); - this.accessToken = SecurityHelper.verifyToken(accessToken); + this.accessToken = accessToken; this.serverID = VerifyHelper.verifyServerID(serverID); } diff --git a/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilMinecraftSessionService.java b/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilMinecraftSessionService.java index 0ceed8a5..b75e9014 100644 --- a/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilMinecraftSessionService.java +++ b/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilMinecraftSessionService.java @@ -208,6 +208,7 @@ public void joinServer(GameProfile profile, String accessToken, String serverID) try { success = new JoinServerRequest(username, accessToken, serverID).request().allow; } catch (Exception e) { + LogHelper.error(e); throw new AuthenticationUnavailableException(e); } From fb21aeb888ed5efa179727001ab89cae5f3241c0 Mon Sep 17 00:00:00 2001 From: Gravit Date: Tue, 22 Oct 2019 00:12:38 +0700 Subject: [PATCH 046/192] =?UTF-8?q?[FEATURE]=20=D0=9F=D0=BE=D0=B4=D0=BF?= =?UTF-8?q?=D0=B8=D1=81=D1=8B=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BB=D1=8E?= =?UTF-8?q?=D0=B1=D0=BE=D0=B3=D0=BE=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B0=20?= =?UTF-8?q?=D0=B8=20=D0=BB=D1=8E=D0=B1=D0=BE=D0=B9=20=D0=B4=D0=B8=D1=80?= =?UTF-8?q?=D0=B5=D1=82=D0=BE=D1=80=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../binary/tasks/SignJarTask.java | 22 ++++---- .../command/handler/CommandHandler.java | 2 + .../command/service/SignDirCommand.java | 52 +++++++++++++++++++ .../command/service/SignJarCommand.java | 47 +++++++++++++++++ 4 files changed, 114 insertions(+), 9 deletions(-) create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignDirCommand.java create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignJarCommand.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java index 9dd608c8..c06ee91c 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java @@ -41,24 +41,28 @@ public String getName() { @Override public Path process(Path inputFile) throws IOException { Path toRet = srv.launcherBinary.nextPath("signed"); + sign(config, inputFile, toRet); + return toRet; + } + + public static void sign(LaunchServerConfig.JarSignerConf config, Path inputFile, Path signedFile) throws IOException { KeyStore c = SignHelper.getStore(new File(config.keyStore).toPath(), config.keyStorePass, config.keyStoreType); - try (SignerJar output = new SignerJar(new ZipOutputStream(IOHelper.newOutput(toRet)), () -> this.gen(c), + try (SignerJar output = new SignerJar(new ZipOutputStream(IOHelper.newOutput(signedFile)), () -> SignJarTask.gen(config, c), config.metaInfSfName, config.metaInfKeyName); ZipInputStream input = new ZipInputStream(IOHelper.newInput(inputFile))) { //input.getManifest().getMainAttributes().forEach((a, b) -> output.addManifestAttribute(a.toString(), b.toString())); // may not work such as after Radon. ZipEntry e = input.getNextEntry(); while (e != null) { - if ("META-INF/MANIFEST.MF".equals(e.getName()) || "/META-INF/MANIFEST.MF".equals(e.getName())) { - Manifest m = new Manifest(input); - m.getMainAttributes().forEach((a, b) -> output.addManifestAttribute(a.toString(), b.toString())); - e = input.getNextEntry(); - continue; - } + if ("META-INF/MANIFEST.MF".equals(e.getName()) || "/META-INF/MANIFEST.MF".equals(e.getName())) { + Manifest m = new Manifest(input); + m.getMainAttributes().forEach((a, b) -> output.addManifestAttribute(a.toString(), b.toString())); + e = input.getNextEntry(); + continue; + } output.addFileContents(IOHelper.newZipEntry(e), input); e = input.getNextEntry(); } } - return toRet; } @Override @@ -66,7 +70,7 @@ public boolean allowDelete() { return true; } - public CMSSignedDataGenerator gen(KeyStore c) { + public static CMSSignedDataGenerator gen(LaunchServerConfig.JarSignerConf config, KeyStore c) { try { return SignHelper.createSignedDataGenerator(c, config.keyAlias, config.signAlgo, config.keyPass); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java index 7f096924..8402b32b 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java @@ -89,6 +89,8 @@ public static void registerCommands(pro.gravit.utils.command.CommandHandler hand service.registerCommand("givePermission", new GivePermissionsCommand(server)); service.registerCommand("getPermissions", new GetPermissionsCommand(server)); service.registerCommand("clients", new ClientsCommand(server)); + service.registerCommand("signJar", new SignJarCommand(server)); + service.registerCommand("signDir", new SignDirCommand(server)); Category serviceCategory = new Category(service, "service", "Managing LaunchServer Components"); handler.registerCategory(serviceCategory); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignDirCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignDirCommand.java new file mode 100644 index 00000000..87ef1c9e --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignDirCommand.java @@ -0,0 +1,52 @@ +package pro.gravit.launchserver.command.service; + +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launchserver.binary.tasks.SignJarTask; +import pro.gravit.launchserver.command.Command; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.LogHelper; + +import java.io.IOException; +import java.nio.file.*; +import java.nio.file.attribute.BasicFileAttributes; + +public class SignDirCommand extends Command { + private class SignJarVisitor extends SimpleFileVisitor + { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + if (file.toFile().getName().endsWith(".jar")) + { + Path tmpSign = server.dir.resolve("build").resolve(file.toFile().getName()); + LogHelper.info("Signing jar %s", file.toString()); + SignJarTask.sign(server.config.sign, file, tmpSign); + Files.deleteIfExists(file); + Files.move(tmpSign, file); + } + return super.visitFile(file, attrs); + } + } + public SignDirCommand(LaunchServer server) { + super(server); + } + + @Override + public String getArgsDescription() { + return "[path to dir]"; + } + + @Override + public String getUsageDescription() { + return "sign all jar files into dir"; + } + + @Override + public void invoke(String... args) throws Exception { + verifyArgs(args, 1); + Path targetDir = Paths.get(args[0]); + if(!IOHelper.isDir(targetDir)) + throw new IllegalArgumentException(String.format("%s not directory", targetDir.toString())); + IOHelper.walk(targetDir, new SignJarVisitor(), true); + LogHelper.info("Success signed"); + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignJarCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignJarCommand.java new file mode 100644 index 00000000..6056597c --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignJarCommand.java @@ -0,0 +1,47 @@ +package pro.gravit.launchserver.command.service; + +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launchserver.binary.tasks.SignJarTask; +import pro.gravit.launchserver.command.Command; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.LogHelper; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +public class SignJarCommand extends Command { + public SignJarCommand(LaunchServer server) { + super(server); + } + + @Override + public String getArgsDescription() { + return "[path to file] (path to signed file)"; + } + + @Override + public String getUsageDescription() { + return "sign custom jar"; + } + + @Override + public void invoke(String... args) throws Exception { + verifyArgs(args, 1); + Path target = Paths.get(args[0]); + Path tmpSign; + if(args.length > 1) + tmpSign = Paths.get(args[1]); + else + tmpSign = server.dir.resolve("build").resolve(target.toFile().getName()); + LogHelper.info("Signing jar %s to %s", target.toString(), tmpSign.toString()); + SignJarTask.sign(server.config.sign, target, tmpSign); + if(args.length <= 1) + { + LogHelper.info("Move temp jar %s to %s", tmpSign.toString(), target.toString()); + Files.deleteIfExists(target); + Files.move(tmpSign, target); + } + LogHelper.info("Success signed"); + } +} From e002d1a7e9f67f0c104ee7056df228ee6685db0e Mon Sep 17 00:00:00 2001 From: Gravit Date: Tue, 22 Oct 2019 01:12:08 +0700 Subject: [PATCH 047/192] =?UTF-8?q?[FEATURE]=20=D0=A2=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D0=BE=D0=B2=D1=8B=D0=B9=20SecurityManager=20=D0=B4=D0=BB=D1=8F?= =?UTF-8?q?=20=D0=BB=D0=BE=D0=B2=D0=BB=D0=B8=20System.exit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launcher/client/ClientLauncher.java | 1 + .../client/ClientSecurityManager.java | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 Launcher/src/main/java/pro/gravit/launcher/client/ClientSecurityManager.java diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index 79959151..dee3cd85 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -442,6 +442,7 @@ public static void main(String... args) throws Throwable { EnvHelper.checkDangerousParams(); JVMHelper.checkStackTrace(ClientLauncher.class); LogHelper.printVersion("Client Launcher"); + System.setSecurityManager(new ClientSecurityManager()); engine.readKeys(); HWIDProvider.registerHWIDs(); LauncherGuardManager.initGuard(true); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientSecurityManager.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientSecurityManager.java new file mode 100644 index 00000000..28b4ab01 --- /dev/null +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientSecurityManager.java @@ -0,0 +1,29 @@ +package pro.gravit.launcher.client; + +import java.security.Permission; + +public class ClientSecurityManager extends SecurityManager { + @Override + public void checkPermission(Permission perm) + { + String permName = perm.getName(); + if(permName == null) return; + if (permName.startsWith("exitVM")) + { + Class[] classContexts = getClassContext(); + String callingClass = classContexts.length > 3 ? classContexts[4].getName() : "none"; + if (!(callingClass.startsWith("pro.gravit."))) + { + throw new ExitTrappedException(); + } + } + } + + @Override + public void checkPermission(Permission perm, Object context) { + } + + public static class ExitTrappedException extends SecurityException { + + } +} From 89c412cda16bbaf370699f747ad167f3a5fd9fec Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 23 Oct 2019 03:09:47 +0700 Subject: [PATCH 048/192] =?UTF-8?q?[FIX]=20=D0=9D=D0=B5=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=B7=D0=B2=D0=BE=D0=BB=D1=8F=D0=B5=D0=BC=20=D0=BB=D0=B0=D1=83?= =?UTF-8?q?=D0=BD=D1=87=D0=B5=D1=80=D1=83=20=D1=80=D0=B0=D0=B7=D0=B6=D0=B8?= =?UTF-8?q?=D1=80=D0=B0=D1=82=D1=8C=D1=81=D1=8F=20=D1=81=D0=BB=D0=B8=D1=88?= =?UTF-8?q?=D0=BA=D0=BE=D0=BC=20=D1=81=D0=B8=D0=BB=D1=8C=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launchserver/asm/SafeClassWriter.java | 1 + .../tasks/AdditionalFixesApplyTask.java | 19 ++++++++----------- .../launcher/ClientLauncherWrapper.java | 1 + 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/SafeClassWriter.java b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/SafeClassWriter.java index 05b340e0..54fe3e4c 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/SafeClassWriter.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/SafeClassWriter.java @@ -18,6 +18,7 @@ public SafeClassWriter(ClassMetadataReader classMetadataReader, int flags) { this.classMetadataReader = classMetadataReader; } + public SafeClassWriter(ClassReader classReader, ClassMetadataReader classMetadataReader, int flags) { super(classReader, flags); this.classMetadataReader = classMetadataReader; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/AdditionalFixesApplyTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/AdditionalFixesApplyTask.java index f486e965..57f2c311 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/AdditionalFixesApplyTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/AdditionalFixesApplyTask.java @@ -11,6 +11,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.io.InputStream; import java.nio.file.Path; import java.util.List; import java.util.function.Predicate; @@ -69,16 +70,12 @@ public static void apply(Path inputFile, Path addFile, ZipOutputStream output, L output.putNextEntry(IOHelper.newZipEntry(e)); if (filename.endsWith(".class")) { byte[] bytes; - try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(2048)) { - IOHelper.transfer(input, outputStream); - bytes = outputStream.toByteArray(); + if(needFixes) { + bytes = classFix(input, reader, srv.config.launcher.stripLineNumbers); + output.write(bytes); } - try { - if(needFixes) bytes = classFix(bytes, reader, srv.config.launcher.stripLineNumbers); - } catch (Throwable t) { - LogHelper.error(t); - } - output.write(bytes); + else + IOHelper.transfer(input, output); } else IOHelper.transfer(input, output); e = input.getNextEntry(); @@ -87,8 +84,8 @@ public static void apply(Path inputFile, Path addFile, ZipOutputStream output, L } } - private static byte[] classFix(byte[] bytes, ClassMetadataReader reader, boolean stripNumbers) { - ClassReader cr = new ClassReader(bytes); + private static byte[] classFix(InputStream input, ClassMetadataReader reader, boolean stripNumbers) throws IOException { + ClassReader cr = new ClassReader(input); ClassNode cn = new ClassNode(); cr.accept(cn, stripNumbers ? (ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES) : ClassReader.SKIP_FRAMES); ClassWriter cw = new SafeClassWriter(reader, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); diff --git a/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java b/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java index 9838ffe5..a7aafb6a 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java +++ b/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java @@ -81,6 +81,7 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep } Collections.addAll(args, MAGIC_ARG); Collections.addAll(args, "-XX:+DisableAttachMechanism"); + Collections.addAll(args, "-Xmx256M"); Collections.addAll(args, "-javaagent:".concat(pathLauncher)); Collections.addAll(args, "-cp"); Collections.addAll(args, pathLauncher); From 600c65d2f2470f633b77e8e1ad5aa25e1992c10f Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Wed, 23 Oct 2019 15:23:50 +0200 Subject: [PATCH 049/192] =?UTF-8?q?[FIX]=20=D0=9E=D1=88=D0=B8=D0=B1=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BD=D0=B0=20MAC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/pro/gravit/launcher/client/ClientLauncher.java | 2 +- modules | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index dee3cd85..e23fb046 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -537,7 +537,7 @@ private static LinkedList resolveClassPathList(Path clientDir, String... c private static Stream resolveClassPathStream(Path clientDir, String... classPath) throws IOException { Stream.Builder builder = Stream.builder(); for (String classPathEntry : classPath) { - Path path = clientDir.resolve(IOHelper.toPath(classPathEntry)); + Path path = clientDir.resolve(IOHelper.toPath(classPathEntry.replace(IOHelper.CROSS_SEPARATOR, IOHelper.PLATFORM_SEPARATOR))); if (IOHelper.isDir(path)) { // Recursive walking and adding IOHelper.walk(path, new ClassPathFileVisitor(builder), false); continue; diff --git a/modules b/modules index 6f008f59..8bd7ee83 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 6f008f595975887b6a1366cb444b82b339e3afad +Subproject commit 8bd7ee839ad17cc75ff26653189f6cb995260989 From becb12887da36c53a5dac182792029f919310c89 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Wed, 23 Oct 2019 17:45:25 +0200 Subject: [PATCH 050/192] =?UTF-8?q?[ANY]=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B8?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index 8bd7ee83..52818e6e 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 8bd7ee839ad17cc75ff26653189f6cb995260989 +Subproject commit 52818e6ef05d90ad678d02e83f9bd4140d8eda34 From a681f43312e23f5a9babeca1e8860181f7ee672c Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Thu, 24 Oct 2019 15:18:01 +0200 Subject: [PATCH 051/192] =?UTF-8?q?[FIX]=20=D0=9B=D0=B8=D1=88=D0=BD=D0=B8?= =?UTF-8?q?=D0=B9=20final?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/pro/gravit/launcher/client/ClientLauncher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index e23fb046..008afe03 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -589,7 +589,7 @@ public interface ParamsAPI { void write(ParamContainer p); } - public static final ParamsAPI container = new ParamsAPI() { + public static ParamsAPI container = new ParamsAPI() { @Override public ParamContainer read() throws Exception { ParamContainer p; From 5e294d1517724e7199e9fec86ed15f1c19980fa8 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Thu, 24 Oct 2019 15:19:55 +0200 Subject: [PATCH 052/192] =?UTF-8?q?[FIX]=20=D0=90=20=D0=B5=D1=89=D1=91=20?= =?UTF-8?q?=D0=B8=D0=B4=D0=B5=D1=8F=20=D0=B2=20=D0=BD=D0=B5=D0=BA=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D1=8B=D1=85=20=D0=BC=D0=B5=D1=81=D1=82=D0=B0?= =?UTF-8?q?=D1=85=20=D0=B8=D1=81=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=B2=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5?= =?UTF-8?q?=D0=B9=D1=81=D0=B0=D1=85=20=D0=BF=D0=BE=D0=B5=D0=BB=D0=B0...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/pro/gravit/launcher/client/ClientLauncher.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index 008afe03..9e523ce7 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -586,7 +586,7 @@ private ClientLauncher() { public interface ParamsAPI { ParamContainer read() throws Exception; - void write(ParamContainer p); + void write(ParamContainer p) throws Exception; } public static ParamsAPI container = new ParamsAPI() { @@ -603,7 +603,7 @@ public ParamContainer read() throws Exception { } @Override - public void write(ParamContainer p) { + public void write(ParamContainer p) throws Exception { setWriteParamsThread(CommonHelper.newThread("Client params writter", true, () -> { try { From e55f266b915b15eadd6796e5e10cfe9ef333eb08 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Thu, 24 Oct 2019 15:22:17 +0200 Subject: [PATCH 053/192] =?UTF-8?q?[ANY]=20=D0=A0=D0=B5=D1=84=D0=B0=D0=BA?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=B8=D0=BD=D0=B3.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launchserver/binary/tasks/AdditionalFixesApplyTask.java | 2 -- .../pro/gravit/launchserver/command/service/SignJarCommand.java | 1 - .../main/java/pro/gravit/launchserver/helper/SignHelper.java | 1 - Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java | 1 - .../java/pro/gravit/launcher/client/ClientSecurityManager.java | 2 +- .../pro/gravit/launcher/request/auth/JoinServerRequest.java | 1 - 6 files changed, 1 insertion(+), 7 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/AdditionalFixesApplyTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/AdditionalFixesApplyTask.java index 57f2c311..b24262e0 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/AdditionalFixesApplyTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/AdditionalFixesApplyTask.java @@ -7,9 +7,7 @@ import pro.gravit.launchserver.asm.ClassMetadataReader; import pro.gravit.launchserver.asm.SafeClassWriter; import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.LogHelper; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.nio.file.Path; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignJarCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignJarCommand.java index 6056597c..57c202e6 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignJarCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignJarCommand.java @@ -3,7 +3,6 @@ import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.binary.tasks.SignJarTask; import pro.gravit.launchserver.command.Command; -import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; import java.nio.file.Files; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/helper/SignHelper.java b/LaunchServer/src/main/java/pro/gravit/launchserver/helper/SignHelper.java index 86e3a165..896d6f2c 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/helper/SignHelper.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/helper/SignHelper.java @@ -5,7 +5,6 @@ import org.bouncycastle.cms.CMSSignedDataGenerator; import org.bouncycastle.cms.SignerInfoGenerator; import org.bouncycastle.cms.jcajce.JcaSignerInfoGeneratorBuilder; -import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.bouncycastle.operator.ContentSigner; import org.bouncycastle.operator.DigestCalculatorProvider; import org.bouncycastle.operator.OperatorCreationException; diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index 5f67a456..5b4fbb9b 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -10,7 +10,6 @@ import pro.gravit.launcher.managers.ClientGsonManager; import pro.gravit.launcher.managers.ClientHookManager; import pro.gravit.launcher.managers.ConsoleManager; -import pro.gravit.launcher.modules.LauncherModule; import pro.gravit.launcher.modules.events.PreConfigPhase; import pro.gravit.launcher.request.Request; import pro.gravit.launcher.request.RequestException; diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientSecurityManager.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientSecurityManager.java index 28b4ab01..86fea872 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientSecurityManager.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientSecurityManager.java @@ -24,6 +24,6 @@ public void checkPermission(Permission perm, Object context) { } public static class ExitTrappedException extends SecurityException { - + private static final long serialVersionUID = 6929785890434102330L; } } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/JoinServerRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/JoinServerRequest.java index b50ada1a..f4ee91cf 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/JoinServerRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/JoinServerRequest.java @@ -5,7 +5,6 @@ import pro.gravit.launcher.events.request.JoinServerRequestEvent; import pro.gravit.launcher.request.Request; import pro.gravit.launcher.request.websockets.WebSocketRequest; -import pro.gravit.utils.helper.SecurityHelper; import pro.gravit.utils.helper.VerifyHelper; public final class JoinServerRequest extends Request implements WebSocketRequest { From 5018e6f35afa340e19dac89f6fb1f84f9af7191a Mon Sep 17 00:00:00 2001 From: LoomeL <44950511+LoomeL@users.noreply.github.com> Date: Thu, 24 Oct 2019 22:46:11 +0600 Subject: [PATCH 054/192] =?UTF-8?q?[ANY]=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B6=D0=B0=D0=B1=D1=8B=20(#3?= =?UTF-8?q?46)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Launcher/runtime/config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Launcher/runtime/config.js b/Launcher/runtime/config.js index 1f1f81b4..d17f8b80 100644 --- a/Launcher/runtime/config.js +++ b/Launcher/runtime/config.js @@ -29,8 +29,8 @@ var config = { /* LaunchServer: guardtype = java */ jvm: { enable: false, // Включение загрузки своей JVM - jvmMustdie32Dir: "jre-8u211-win32", // Название папки JVM для Windows x32 - jvmMustdie64Dir: "jre-8u211-win64", // Название папки JVM для Windows x64 + jvmMustdie32Dir: "jre-8u231-win32", // Название папки JVM для Windows x32 + jvmMustdie64Dir: "jre-8u231-win64", // Название папки JVM для Windows x64 }, settingsMagic: 0xC0DE5, // Магия вне хогвартса From 02cb32cd65002518af77979353369908d0294245 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 26 Oct 2019 07:12:08 +0700 Subject: [PATCH 055/192] =?UTF-8?q?[FIX]=20=D0=9E=D1=88=D0=B8=D0=B1=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BF=D1=80=D0=B8=20=D0=B7=D0=B0=D0=BF=D1=83=D1=81?= =?UTF-8?q?=D0=BA=D0=B5=20ServerWrapper(ECCryptCipher)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/pro/gravit/launcher/server/ServerWrapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java index c5959b90..a6ea4409 100644 --- a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java +++ b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java @@ -52,7 +52,7 @@ public ServerWrapper(Type type, Path configPath) { public boolean auth() { try { LauncherConfig cfg = Launcher.getConfig(); - AuthRequest request = new AuthRequest(config.login, SecurityHelper.newECEncryptCipher(cfg.publicKey).doFinal(IOHelper.encode(config.password)), config.auth_id, AuthRequest.ConnectTypes.SERVER); + AuthRequest request = new AuthRequest(config.login, config.password, config.auth_id, AuthRequest.ConnectTypes.SERVER); permissions = request.request().permissions; ProfilesRequestEvent result = new ProfilesRequest().request(); for (ClientProfile p : result.profiles) { From 585fb0615129cc269484662b9481068478b92b77 Mon Sep 17 00:00:00 2001 From: zaxar163 Date: Sat, 26 Oct 2019 20:00:08 +0300 Subject: [PATCH 056/192] =?UTF-8?q?[FIX]=20XOR=20=D0=B8=D0=B7=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D1=8F=D1=8E=D1=89=D0=B8=D0=B9=20=D0=BE=D1=80=D0=B8=D0=B3?= =?UTF-8?q?=D0=B8=D0=BD=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20=D0=BC=D0=B0?= =?UTF-8?q?=D1=81=D1=81=D0=B8=D0=B2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/utils/helper/CryptoHelper.java | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/CryptoHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/CryptoHelper.java index 727243a5..7106fca5 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/CryptoHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/CryptoHelper.java @@ -1,5 +1,6 @@ package pro.gravit.utils.helper; +import java.io.OutputStream; import java.util.Objects; import java.util.function.LongSupplier; @@ -24,12 +25,26 @@ public static byte[] decode(byte[] pText, String pKey) { return res; } + public static void encodeOrig(byte[] txt, String pKey) { + Objects.requireNonNull(txt); + Objects.requireNonNull(pKey); + byte[] key = SecurityHelper.fromHex(pKey); + for (int i = 0; i < txt.length; i++) + txt[i] = (byte) (txt[i] ^ key[i % key.length]); + } + + public static void decodeOrig(byte[] pText, String pKey) { + Objects.requireNonNull(pText); + Objects.requireNonNull(pKey); + byte[] key = SecurityHelper.fromHex(pKey); + for (int i = 0; i < pText.length; i++) + pText[i] = (byte) (pText[i] ^ key[i % key.length]); + } + + public static String randomToken(int depth) { VerifyHelper.verifyInt(depth, VerifyHelper.POSITIVE, "Depth must be positive"); - StringBuilder sb = new StringBuilder(SecurityHelper.TOKEN_STRING_LENGTH*depth); - for (int i = 0; i < depth; i++) - sb.append(SecurityHelper.randomStringToken()); - return sb.toString(); + return SecurityHelper.toHex(SecurityHelper.randomBytes(SecurityHelper.TOKEN_LENGTH*depth)); } private CryptoHelper() { @@ -50,5 +65,4 @@ public long getAsLong() { return this.rnd; } } - } From 625fb75f825ee3880a522ae864c5a83aa6b68d0f Mon Sep 17 00:00:00 2001 From: Gravit Date: Sun, 27 Oct 2019 21:47:55 +0700 Subject: [PATCH 057/192] =?UTF-8?q?[FEATURE]=20=D0=90=D0=B2=D1=82=D0=BE?= =?UTF-8?q?=D0=B3=D0=B5=D0=BD=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D1=8F=20=D1=81?= =?UTF-8?q?=D0=B5=D1=80=D1=82=D0=B8=D1=84=D0=B8=D0=BA=D0=B0=D1=82=D0=B0=20?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BB=D0=B5=D1=82=D1=83=20=D0=BF=D1=80=D0=B8=20?= =?UTF-8?q?=D0=B5=D0=B3=D0=BE=20=D0=BE=D1=82=D1=81=D1=83=D1=82=D1=81=D1=82?= =?UTF-8?q?=D0=B2=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../binary/JARLauncherBinary.java | 2 +- .../binary/tasks/SignJarTask.java | 73 ++++++++++++++++++- .../command/service/SignDirCommand.java | 11 ++- .../command/service/SignJarCommand.java | 4 +- .../config/LaunchServerConfig.java | 2 +- .../launchserver/helper/SignHelper.java | 11 +++ .../manangers/CertificateManager.java | 4 +- 7 files changed, 99 insertions(+), 8 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JARLauncherBinary.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JARLauncherBinary.java index b8082682..23547d02 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JARLauncherBinary.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JARLauncherBinary.java @@ -47,7 +47,7 @@ public void init() { tasks.add(new AdditionalFixesApplyTask(server)); if (!server.config.launcher.attachLibraryBeforeProGuard) tasks.add(new AttachJarsTask(server)); if (server.config.launcher.compress) tasks.add(new CompressBuildTask(server)); - if(server.config.sign.enabled) tasks.add(new SignJarTask(server.config.sign, server)); + tasks.add(new SignJarTask(server.config.sign, server)); } @Override diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java index c06ee91c..4711dcc2 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java @@ -1,8 +1,17 @@ package pro.gravit.launchserver.binary.tasks; +import org.bouncycastle.asn1.x500.X500Name; +import org.bouncycastle.asn1.x500.X500NameBuilder; +import org.bouncycastle.asn1.x500.style.BCStyle; +import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; +import org.bouncycastle.cert.X509CertificateHolder; +import org.bouncycastle.cert.X509v3CertificateBuilder; +import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter; import org.bouncycastle.cms.CMSException; import org.bouncycastle.cms.CMSSignedDataGenerator; +import org.bouncycastle.operator.ContentSigner; import org.bouncycastle.operator.OperatorCreationException; +import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.binary.SignerJar; import pro.gravit.launchserver.config.LaunchServerConfig; @@ -12,12 +21,23 @@ import java.io.File; import java.io.IOException; +import java.math.BigInteger; import java.nio.file.Path; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.UnrecoverableKeyException; +import java.security.cert.Certificate; import java.security.cert.CertificateEncodingException; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; +import java.security.interfaces.ECPrivateKey; +import java.security.interfaces.ECPublicKey; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.ArrayList; +import java.util.Date; import java.util.jar.Manifest; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -45,7 +65,12 @@ public Path process(Path inputFile) throws IOException { return toRet; } - public static void sign(LaunchServerConfig.JarSignerConf config, Path inputFile, Path signedFile) throws IOException { + public void sign(LaunchServerConfig.JarSignerConf config, Path inputFile, Path signedFile) throws IOException { + if(config.enabled) stdSign(config, inputFile, signedFile); + else autoSign(inputFile, signedFile); + } + + private void stdSign(LaunchServerConfig.JarSignerConf config, Path inputFile, Path signedFile) throws IOException { KeyStore c = SignHelper.getStore(new File(config.keyStore).toPath(), config.keyStorePass, config.keyStoreType); try (SignerJar output = new SignerJar(new ZipOutputStream(IOHelper.newOutput(signedFile)), () -> SignJarTask.gen(config, c), config.metaInfSfName, config.metaInfKeyName); @@ -64,6 +89,30 @@ public static void sign(LaunchServerConfig.JarSignerConf config, Path inputFile, } } } + private void autoSign(Path inputFile, Path signedFile) throws IOException { + try (SignerJar output = new SignerJar(new ZipOutputStream(IOHelper.newOutput(signedFile)), () -> { + try { + return genCertificate(srv.config.projectName, srv.publicKey, srv.privateKey); + } catch (OperatorCreationException | CertificateException | CMSException e) { + throw new InternalError(e); + } + }, + "AUTOGEN.SF", "AUTOGEN.EC"); + ZipInputStream input = new ZipInputStream(IOHelper.newInput(inputFile))) { + //input.getManifest().getMainAttributes().forEach((a, b) -> output.addManifestAttribute(a.toString(), b.toString())); // may not work such as after Radon. + ZipEntry e = input.getNextEntry(); + while (e != null) { + if ("META-INF/MANIFEST.MF".equals(e.getName()) || "/META-INF/MANIFEST.MF".equals(e.getName())) { + Manifest m = new Manifest(input); + m.getMainAttributes().forEach((a, b) -> output.addManifestAttribute(a.toString(), b.toString())); + e = input.getNextEntry(); + continue; + } + output.addFileContents(IOHelper.newZipEntry(e), input); + e = input.getNextEntry(); + } + } + } @Override public boolean allowDelete() { @@ -80,4 +129,26 @@ public static CMSSignedDataGenerator gen(LaunchServerConfig.JarSignerConf config return null; } } + public static CMSSignedDataGenerator genCertificate(String projectName, ECPublicKey publicKey, ECPrivateKey privateKey) throws OperatorCreationException, CertificateException, CMSException { + + X500NameBuilder subject = new X500NameBuilder(); + subject.addRDN(BCStyle.CN, projectName.concat(" Autogenerated")); + subject.addRDN(BCStyle.O, projectName); + LocalDateTime startDate = LocalDate.now().atStartOfDay(); + X509v3CertificateBuilder builder = new X509v3CertificateBuilder( + subject.build(), + new BigInteger("0"), + Date.from(startDate.atZone(ZoneId.systemDefault()).toInstant()), + Date.from(startDate.plusDays(3650).atZone(ZoneId.systemDefault()).toInstant()), + new X500Name("CN=ca"), + SubjectPublicKeyInfo.getInstance(publicKey.getEncoded())); + JcaContentSignerBuilder csBuilder = new JcaContentSignerBuilder("SHA256WITHECDSA"); + ContentSigner signer = csBuilder.build(privateKey); + X509CertificateHolder certificate = builder.build(signer); + X509Certificate x509Certificate = new JcaX509CertificateConverter().setProvider( "BC" ) + .getCertificate( certificate ); + ArrayList chain = new ArrayList<>(); + chain.add(x509Certificate); + return SignHelper.createSignedDataGenerator(privateKey, x509Certificate, chain, "SHA256WITHECDSA"); + } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignDirCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignDirCommand.java index 87ef1c9e..84abd7cf 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignDirCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignDirCommand.java @@ -2,6 +2,7 @@ import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.binary.tasks.SignJarTask; +import pro.gravit.launchserver.binary.tasks.TaskUtil; import pro.gravit.launchserver.command.Command; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; @@ -13,13 +14,18 @@ public class SignDirCommand extends Command { private class SignJarVisitor extends SimpleFileVisitor { + private SignJarTask task; + public SignJarVisitor(SignJarTask task) { + this.task = task; + } + @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (file.toFile().getName().endsWith(".jar")) { Path tmpSign = server.dir.resolve("build").resolve(file.toFile().getName()); LogHelper.info("Signing jar %s", file.toString()); - SignJarTask.sign(server.config.sign, file, tmpSign); + task.sign(server.config.sign, file, tmpSign); Files.deleteIfExists(file); Files.move(tmpSign, file); } @@ -46,7 +52,8 @@ public void invoke(String... args) throws Exception { Path targetDir = Paths.get(args[0]); if(!IOHelper.isDir(targetDir)) throw new IllegalArgumentException(String.format("%s not directory", targetDir.toString())); - IOHelper.walk(targetDir, new SignJarVisitor(), true); + SignJarTask task = (SignJarTask) TaskUtil.getTaskByClass(server.launcherBinary.tasks, SignJarTask.class); + IOHelper.walk(targetDir, new SignJarVisitor(task), true); LogHelper.info("Success signed"); } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignJarCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignJarCommand.java index 57c202e6..62162f60 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignJarCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignJarCommand.java @@ -2,6 +2,7 @@ import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.binary.tasks.SignJarTask; +import pro.gravit.launchserver.binary.tasks.TaskUtil; import pro.gravit.launchserver.command.Command; import pro.gravit.utils.helper.LogHelper; @@ -34,7 +35,8 @@ public void invoke(String... args) throws Exception { else tmpSign = server.dir.resolve("build").resolve(target.toFile().getName()); LogHelper.info("Signing jar %s to %s", target.toString(), tmpSign.toString()); - SignJarTask.sign(server.config.sign, target, tmpSign); + SignJarTask task = (SignJarTask) TaskUtil.getTaskByClass(server.launcherBinary.tasks, SignJarTask.class); + task.sign(server.config.sign, target, tmpSign); if(args.length <= 1) { LogHelper.info("Move temp jar %s to %s", tmpSign.toString(), target.toString()); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java index 5f42a71b..ecb3ffaf 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java @@ -227,7 +227,7 @@ public static class CertificateConf { } public static class JarSignerConf { - public boolean enabled = true; + public boolean enabled = false; public String keyStore = "pathToKey"; public String keyStoreType = "JKS"; public String keyStorePass = "mypass"; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/helper/SignHelper.java b/LaunchServer/src/main/java/pro/gravit/launchserver/helper/SignHelper.java index 896d6f2c..a66f588e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/helper/SignHelper.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/helper/SignHelper.java @@ -144,6 +144,17 @@ public static CMSSignedDataGenerator createSignedDataGenerator(KeyStore keyStore generator.addCertificates(certStore); return generator; } + public static CMSSignedDataGenerator createSignedDataGenerator(PrivateKey privateKey, Certificate cert, List certChain, String signAlgo) throws OperatorCreationException, CertificateEncodingException, CMSException { + @SuppressWarnings("rawtypes") + Store certStore = new JcaCertStore(certChain); + ContentSigner signer = new JcaContentSignerBuilder(signAlgo).setProvider("BC").build(privateKey); + CMSSignedDataGenerator generator = new CMSSignedDataGenerator(); + DigestCalculatorProvider dcp = new JcaDigestCalculatorProviderBuilder().setProvider("BC").build(); + SignerInfoGenerator sig = new JcaSignerInfoGeneratorBuilder(dcp).build(signer, (X509Certificate) cert); + generator.addSignerInfoGenerator(sig); + generator.addCertificates(certStore); + return generator; + } public static final String hashFunctionName = "SHA-256"; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/CertificateManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/CertificateManager.java index f14c4069..71fad349 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/CertificateManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/CertificateManager.java @@ -81,7 +81,7 @@ public X509CertificateHolder generateCertificate(String subjectName, PublicKey s } public void generateCA() throws NoSuchAlgorithmException, IOException, OperatorCreationException, InvalidAlgorithmParameterException { - ECGenParameterSpec ecGenSpec = new ECGenParameterSpec("secp384r1"); + ECGenParameterSpec ecGenSpec = new ECGenParameterSpec("secp384k1"); KeyPairGenerator generator = KeyPairGenerator.getInstance("EC"); generator.initialize(ecGenSpec, SecurityHelper.newRandom()); KeyPair pair = generator.generateKeyPair(); @@ -105,7 +105,7 @@ public void generateCA() throws NoSuchAlgorithmException, IOException, OperatorC } public KeyPair generateKeyPair() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException { - ECGenParameterSpec ecGenSpec = new ECGenParameterSpec("secp384r1"); + ECGenParameterSpec ecGenSpec = new ECGenParameterSpec("secp384k1"); KeyPairGenerator generator = KeyPairGenerator.getInstance("EC"); generator.initialize(ecGenSpec, SecurityHelper.newRandom()); return generator.generateKeyPair(); From f7cfaaa543fc609b229c956abbc7e8777824365f Mon Sep 17 00:00:00 2001 From: Gravit Date: Sun, 27 Oct 2019 22:33:52 +0700 Subject: [PATCH 058/192] =?UTF-8?q?[FIX]=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=81=D0=B3=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D1=80=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=BD=D0=BE=D0=B3?= =?UTF-8?q?=D0=BE=20=D1=81=D0=B5=D1=80=D1=82=D0=B8=D1=84=D0=B8=D0=BA=D0=B0?= =?UTF-8?q?=D1=82=D0=B0=20=D0=B2=20trustStore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../binary/JARLauncherBinary.java | 1 + .../binary/tasks/CertificateAutogenTask.java | 80 +++++++++++++++++++ .../binary/tasks/MainBuildTask.java | 32 +++++--- .../binary/tasks/SignJarTask.java | 29 +------ 4 files changed, 103 insertions(+), 39 deletions(-) create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/CertificateAutogenTask.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JARLauncherBinary.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JARLauncherBinary.java index 23547d02..79211cff 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JARLauncherBinary.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JARLauncherBinary.java @@ -41,6 +41,7 @@ public JARLauncherBinary(LaunchServer server) throws IOException { @Override public void init() { tasks.add(new PrepareBuildTask(server)); + if(!server.config.sign.enabled) tasks.add(new CertificateAutogenTask(server)); tasks.add(new MainBuildTask(server)); if (server.config.launcher.attachLibraryBeforeProGuard) tasks.add(new AttachJarsTask(server)); tasks.add(new ProGuardBuildTask(server)); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/CertificateAutogenTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/CertificateAutogenTask.java new file mode 100644 index 00000000..c597034f --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/CertificateAutogenTask.java @@ -0,0 +1,80 @@ +package pro.gravit.launchserver.binary.tasks; + +import org.bouncycastle.asn1.x500.X500Name; +import org.bouncycastle.asn1.x500.X500NameBuilder; +import org.bouncycastle.asn1.x500.style.BCStyle; +import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; +import org.bouncycastle.cert.X509CertificateHolder; +import org.bouncycastle.cert.X509v3CertificateBuilder; +import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter; +import org.bouncycastle.cms.CMSException; +import org.bouncycastle.cms.CMSSignedDataGenerator; +import org.bouncycastle.operator.ContentSigner; +import org.bouncycastle.operator.OperatorCreationException; +import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder; +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launchserver.helper.SignHelper; +import pro.gravit.utils.helper.LogHelper; + +import java.io.IOException; +import java.math.BigInteger; +import java.nio.file.Path; +import java.security.cert.Certificate; +import java.security.cert.CertificateEncodingException; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.ArrayList; +import java.util.Date; + +public class CertificateAutogenTask implements LauncherBuildTask { + private LaunchServer server; + + public CertificateAutogenTask(LaunchServer server) { + this.server = server; + } + + @Override + public String getName() { + return "CertificateAutogen"; + } + public X509Certificate certificate; + public X509CertificateHolder bcCertificate; + public CMSSignedDataGenerator signedDataGenerator; + + @Override + public Path process(Path inputFile) throws IOException { + if(signedDataGenerator != null) return inputFile; + try { + X500NameBuilder subject = new X500NameBuilder(); + subject.addRDN(BCStyle.CN, server.config.projectName.concat(" Autogenerated")); + subject.addRDN(BCStyle.O, server.config.projectName); + LocalDateTime startDate = LocalDate.now().atStartOfDay(); + X509v3CertificateBuilder builder = new X509v3CertificateBuilder( + subject.build(), + new BigInteger("0"), + Date.from(startDate.atZone(ZoneId.systemDefault()).toInstant()), + Date.from(startDate.plusDays(3650).atZone(ZoneId.systemDefault()).toInstant()), + new X500Name("CN=ca"), + SubjectPublicKeyInfo.getInstance(server.publicKey.getEncoded())); + JcaContentSignerBuilder csBuilder = new JcaContentSignerBuilder("SHA256WITHECDSA"); + ContentSigner signer = csBuilder.build(server.privateKey); + bcCertificate = builder.build(signer); + certificate = new JcaX509CertificateConverter().setProvider( "BC" ) + .getCertificate( bcCertificate ); + ArrayList chain = new ArrayList<>(); + chain.add(certificate); + signedDataGenerator = SignHelper.createSignedDataGenerator(server.privateKey, certificate, chain, "SHA256WITHECDSA"); + } catch (OperatorCreationException | CMSException | CertificateException e) { + LogHelper.error(e); + } + return inputFile; + } + + @Override + public boolean allowDelete() { + return false; + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java index 5742cdfb..c483fae6 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java @@ -23,10 +23,8 @@ import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import java.security.cert.CertificateEncodingException; -import java.util.Arrays; -import java.util.Base64; -import java.util.HashMap; -import java.util.Map; +import java.security.cert.X509Certificate; +import java.util.*; import java.util.jar.JarFile; import java.util.stream.Collectors; import java.util.zip.ZipEntry; @@ -138,14 +136,24 @@ public Path process(Path inputJar) throws IOException { launcherConfigurator.setBooleanField("isWarningMissArchJava", server.config.launcher.warningMissArchJava); launcherConfigurator.setEnv(server.config.env); launcherConfigurator.setStringField("passwordEncryptKey", server.runtime.passwordEncryptKey); - secureConfigurator.setByteArrayListField("certificates", Arrays.stream(server.certificateManager.trustManager.getTrusted()).map(e -> { - try { - return e.getEncoded(); - } catch (CertificateEncodingException e2) { - LogHelper.error(e2); - return new byte[0]; - } - }).collect(Collectors.toList())); + List certificates = Arrays.stream(server.certificateManager.trustManager.getTrusted()).map(e -> { + try { + return e.getEncoded(); + } catch (CertificateEncodingException e2) { + LogHelper.error(e2); + return new byte[0]; + } + }).collect(Collectors.toList()); + if(!server.config.sign.enabled) + { + CertificateAutogenTask task = TaskUtil.getTaskByClass(server.launcherBinary.tasks, CertificateAutogenTask.class).get(0); + try { + certificates.add(task.certificate.getEncoded()); + } catch (CertificateEncodingException e) { + throw new InternalError(e); + } + } + secureConfigurator.setByteArrayListField("certificates", certificates); String launcherSalt = SecurityHelper.randomStringToken(); byte[] launcherSecureHash = SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA256, server.runtime.clientCheckSecret.concat(".").concat(launcherSalt)); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java index 4711dcc2..32e42e66 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java @@ -91,11 +91,8 @@ private void stdSign(LaunchServerConfig.JarSignerConf config, Path inputFile, Pa } private void autoSign(Path inputFile, Path signedFile) throws IOException { try (SignerJar output = new SignerJar(new ZipOutputStream(IOHelper.newOutput(signedFile)), () -> { - try { - return genCertificate(srv.config.projectName, srv.publicKey, srv.privateKey); - } catch (OperatorCreationException | CertificateException | CMSException e) { - throw new InternalError(e); - } + CertificateAutogenTask task = TaskUtil.getTaskByClass(srv.launcherBinary.tasks, CertificateAutogenTask.class).get(0); + return task.signedDataGenerator; }, "AUTOGEN.SF", "AUTOGEN.EC"); ZipInputStream input = new ZipInputStream(IOHelper.newInput(inputFile))) { @@ -129,26 +126,4 @@ public static CMSSignedDataGenerator gen(LaunchServerConfig.JarSignerConf config return null; } } - public static CMSSignedDataGenerator genCertificate(String projectName, ECPublicKey publicKey, ECPrivateKey privateKey) throws OperatorCreationException, CertificateException, CMSException { - - X500NameBuilder subject = new X500NameBuilder(); - subject.addRDN(BCStyle.CN, projectName.concat(" Autogenerated")); - subject.addRDN(BCStyle.O, projectName); - LocalDateTime startDate = LocalDate.now().atStartOfDay(); - X509v3CertificateBuilder builder = new X509v3CertificateBuilder( - subject.build(), - new BigInteger("0"), - Date.from(startDate.atZone(ZoneId.systemDefault()).toInstant()), - Date.from(startDate.plusDays(3650).atZone(ZoneId.systemDefault()).toInstant()), - new X500Name("CN=ca"), - SubjectPublicKeyInfo.getInstance(publicKey.getEncoded())); - JcaContentSignerBuilder csBuilder = new JcaContentSignerBuilder("SHA256WITHECDSA"); - ContentSigner signer = csBuilder.build(privateKey); - X509CertificateHolder certificate = builder.build(signer); - X509Certificate x509Certificate = new JcaX509CertificateConverter().setProvider( "BC" ) - .getCertificate( certificate ); - ArrayList chain = new ArrayList<>(); - chain.add(x509Certificate); - return SignHelper.createSignedDataGenerator(privateKey, x509Certificate, chain, "SHA256WITHECDSA"); - } } From f3c7f57e50c49a75f3347aa47c040492d7d5a88e Mon Sep 17 00:00:00 2001 From: Gravit Date: Sun, 27 Oct 2019 22:39:08 +0700 Subject: [PATCH 059/192] =?UTF-8?q?[FIX]=20=D0=9A=D1=80=D0=B8=D0=B2=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=BF=D0=BE=D0=B4=D0=BF=D0=B8=D1=81=D1=8C,=20=D0=B8?= =?UTF-8?q?=D1=81=D0=BF=D1=80=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BC=D0=BE=D0=B7=D0=BE=D0=B2=20=D0=BF=D1=80=D0=B8?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=B4=D0=BF=D0=B8=D1=81=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/pro/gravit/launchserver/binary/SignerJar.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/SignerJar.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/SignerJar.java index 5da3d5e0..29f7bbb2 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/SignerJar.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/SignerJar.java @@ -200,7 +200,7 @@ private String hashMainSection(Attributes attributes) throws IOException { private byte[] signSigFile(byte[] sigContents) throws Exception { CMSSignedDataGenerator gen = this.gen.get(); CMSTypedData cmsData = new CMSProcessableByteArray(sigContents); - CMSSignedData signedData = gen.generate(cmsData, true); + CMSSignedData signedData = gen.generate(cmsData, false); return signedData.getEncoded(); } From 5446142e6a2f7bc669e80915f071eab7a589c7ab Mon Sep 17 00:00:00 2001 From: Gravit Date: Sun, 27 Oct 2019 23:51:48 +0700 Subject: [PATCH 060/192] =?UTF-8?q?[FEATURE]=20=D0=A0=D0=B0=D1=88=D0=B8?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=B8=D0=B5=20pipeline=20=D0=BD=D0=B0=20EXE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launchserver/LaunchServer.java | 12 -- .../launchserver/binary/BinaryPipeline.java | 112 +++++++++++++++ .../binary/EXEL4JLauncherBinary.java | 110 +------------- .../binary/EXELauncherBinary.java | 2 +- .../binary/JARLauncherBinary.java | 45 +----- .../launchserver/binary/LauncherBinary.java | 10 +- .../binary/SimpleEXELauncherBinary.java | 30 ---- .../binary/tasks/exe/Launch4JTask.java | 134 ++++++++++++++++++ .../config/LaunchServerConfig.java | 2 - 9 files changed, 259 insertions(+), 198 deletions(-) create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/binary/BinaryPipeline.java delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/binary/SimpleEXELauncherBinary.java create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/exe/Launch4JTask.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java index c6666495..0b60e7f8 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java @@ -396,18 +396,6 @@ private LauncherBinary binary() { LogHelper.error(e); } } - if (config.launch4j.alternative != null) { - switch (config.launch4j.alternative) { - case "simple": - return new SimpleEXELauncherBinary(this); - case "no": - //None - break; - default: - LogHelper.warning("Alternative %s not found", config.launch4j.alternative); - break; - } - } try { Class.forName("net.sf.launch4j.Builder"); if (config.launch4j.enabled) return new EXEL4JLauncherBinary(this); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BinaryPipeline.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BinaryPipeline.java new file mode 100644 index 00000000..fd1270f6 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BinaryPipeline.java @@ -0,0 +1,112 @@ +package pro.gravit.launchserver.binary; + +import pro.gravit.launchserver.binary.tasks.LauncherBuildTask; +import pro.gravit.utils.helper.CommonHelper; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.LogHelper; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicLong; +import java.util.function.Predicate; +import java.util.stream.Collectors; + +public class BinaryPipeline { + public final List tasks = new ArrayList<>(); + public final AtomicLong count = new AtomicLong(0); + public final Path buildDir; + public final String nameFormat; + + public BinaryPipeline(Path buildDir, String nameFormat) { + this.buildDir = buildDir; + this.nameFormat = nameFormat; + } + + public void addCounted(int count, Predicate pred, LauncherBuildTask taskAdd) { + List indexes = new ArrayList<>(); + tasks.stream().filter(pred).forEach(indexes::add); + indexes.forEach(e -> tasks.add(tasks.indexOf(e) + count, taskAdd)); + } + + public void replaceCounted(int count, Predicate pred, LauncherBuildTask taskRep) { + List indexes = new ArrayList<>(); + tasks.stream().filter(pred).forEach(indexes::add); + indexes.forEach(e -> tasks.set(tasks.indexOf(e) + count, taskRep)); + } + + public void addPre(Predicate pred, LauncherBuildTask taskAdd) { + addCounted(-1, pred, taskAdd); + } + + public void add(Predicate pred, LauncherBuildTask taskAdd) { + addCounted(0, pred, taskAdd); + } + + public void addAfter(Predicate pred, LauncherBuildTask taskAdd) { + addCounted(1, pred, taskAdd); + } + + public void replacePre(Predicate pred, LauncherBuildTask taskRep) { + replaceCounted(-1, pred, taskRep); + } + + public void replace(Predicate pred, LauncherBuildTask taskRep) { + replaceCounted( 0, pred, taskRep); + } + + public void replaceAfter(Predicate pred, LauncherBuildTask taskRep) { + replaceCounted(1, pred, taskRep); + } + + public List getTasksByClass(Class taskClass) { + return tasks.stream().filter(taskClass::isInstance).map(taskClass::cast).collect(Collectors.toList()); + } + + public Optional getTaskByClass(Class taskClass) { + return tasks.stream().filter(taskClass::isInstance).map(taskClass::cast).findFirst(); + } + + public void build(Path target, boolean deleteTempFiles) throws IOException { + LogHelper.info("Building launcher binary file"); + count.set(0); // set jar number + Path thisPath = null; + boolean isNeedDelete = false; + long time_start = System.currentTimeMillis(); + long time_this = time_start; + for (LauncherBuildTask task : tasks) { + LogHelper.subInfo("Task %s", task.getName()); + Path oldPath = thisPath; + thisPath = task.process(oldPath); + long time_task_end = System.currentTimeMillis(); + long time_task = time_task_end - time_this; + time_this = time_task_end; + if (isNeedDelete && deleteTempFiles) Files.deleteIfExists(oldPath); + isNeedDelete = task.allowDelete(); + LogHelper.subInfo("Task %s processed from %d millis", task.getName(), time_task); + } + long time_end = System.currentTimeMillis(); + if (isNeedDelete && deleteTempFiles) IOHelper.move(thisPath, target); + else IOHelper.copy(thisPath, target); + LogHelper.info("Build successful from %d millis", time_end - time_start); + } + + public String nextName(String taskName) { + return String.format(nameFormat, taskName, count.getAndIncrement()); + } + + public Path nextPath(String taskName) { + return buildDir.resolve(nextName(taskName)); + } + + public Path nextPath(LauncherBuildTask task) { + return nextPath(task.getName()); + } + + public Path nextLowerPath(LauncherBuildTask task) { + return nextPath(CommonHelper.low(task.getName())); + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/EXEL4JLauncherBinary.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/EXEL4JLauncherBinary.java index 75044e82..c9a0a3e2 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/EXEL4JLauncherBinary.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/EXEL4JLauncherBinary.java @@ -1,119 +1,17 @@ package pro.gravit.launchserver.binary; -import net.sf.launch4j.Builder; -import net.sf.launch4j.Log; -import net.sf.launch4j.config.*; import pro.gravit.launchserver.LaunchServer; -import pro.gravit.utils.Version; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.LogHelper; - -import java.io.IOException; -import java.nio.file.Path; +import pro.gravit.launchserver.binary.tasks.exe.Launch4JTask; public final class EXEL4JLauncherBinary extends LauncherBinary { - private final static class Launch4JLog extends Log { - private static final Launch4JLog INSTANCE = new Launch4JLog(); - - @Override - public void append(String s) { - LogHelper.subInfo(s); - } - - @Override - public void clear() { - // Do nothing - } - } - - // URL constants - private static final String DOWNLOAD_URL = "http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html"; // Oracle - // JRE 8 - - // File constants - private final Path faviconFile; public EXEL4JLauncherBinary(LaunchServer server) { - super(server, LauncherBinary.resolve(server, ".exe")); - faviconFile = server.dir.resolve("favicon.ico"); + super(server, LauncherBinary.resolve(server, ".exe"), "Launcher-%s-%d.exe"); } @Override - public void build() throws IOException { - LogHelper.info("Building launcher EXE binary file (Using Launch4J)"); - setConfig(); - - // Set favicon path - Config config = ConfigPersister.getInstance().getConfig(); - if (IOHelper.isFile(faviconFile)) - config.setIcon(faviconFile.toFile()); - else { - config.setIcon(null); - LogHelper.warning("Missing favicon.ico file"); - } - - // Start building - Builder builder = new Builder(Launch4JLog.INSTANCE); - try { - builder.build(); - } catch (Throwable e) { - throw new IOException(e); - } - } - - private void setConfig() { - Config config = new Config(); - // Set file options - config.setChdir("."); - config.setErrTitle("JVM Error"); - config.setDownloadUrl(DOWNLOAD_URL); - - // Set boolean options - config.setPriorityIndex(0); - config.setHeaderType(Config.GUI_HEADER); - config.setStayAlive(false); - config.setRestartOnCrash(false); - - // Prepare JRE - Jre jre = new Jre(); - jre.setMinVersion("1.8.0"); - if (server.config.launch4j.setMaxVersion) - jre.setMaxVersion(server.config.launch4j.maxVersion); - jre.setRuntimeBits(Jre.RUNTIME_BITS_64_AND_32); - jre.setJdkPreference(Jre.JDK_PREFERENCE_PREFER_JRE); - config.setJre(jre); - - // Prepare version info (product) - VersionInfo info = new VersionInfo(); - info.setProductName(server.config.launch4j.productName); - info.setProductVersion(formatVars(server.config.launch4j.productVer)); - info.setFileDescription(server.config.launch4j.fileDesc); - info.setFileVersion(formatVars(server.config.launch4j.fileVer)); - info.setCopyright(server.config.launch4j.copyright); - info.setTrademarks(server.config.launch4j.trademarks); - info.setInternalName(formatVars(server.config.launch4j.internalName)); - // Prepare version info (file) - info.setTxtFileVersion(formatVars(server.config.launch4j.txtFileVersion)); - info.setTxtProductVersion(formatVars(server.config.launch4j.txtProductVersion)); - // Prepare version info (misc) - info.setOriginalFilename(syncBinaryFile.getFileName().toString()); - info.setLanguage(LanguageID.RUSSIAN); - config.setVersionInfo(info); - - // Set JAR wrapping options - config.setDontWrapJar(false); - config.setJar(server.launcherBinary.syncBinaryFile.toFile()); - config.setOutfile(syncBinaryFile.toFile()); - - // Return prepared config - ConfigPersister.getInstance().setAntConfig(config, null); - } - - private static final String VERSION = Version.getVersion().getVersionString(); - private static final int BUILD = Version.getVersion().build; - - public static String formatVars(String mask) { - return String.format(mask, VERSION, BUILD); + public void init() { + tasks.add(new Launch4JTask(server)); } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/EXELauncherBinary.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/EXELauncherBinary.java index 0e0c9e3f..3a7b89a6 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/EXELauncherBinary.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/EXELauncherBinary.java @@ -10,7 +10,7 @@ public class EXELauncherBinary extends LauncherBinary { public EXELauncherBinary(LaunchServer server) { - super(server, LauncherBinary.resolve(server, ".exe")); + super(server, LauncherBinary.resolve(server, ".exe"), "Launcher-%s-%d.exe"); } @Override diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JARLauncherBinary.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JARLauncherBinary.java index 79211cff..5bd5ea78 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JARLauncherBinary.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JARLauncherBinary.java @@ -19,17 +19,15 @@ public final class JARLauncherBinary extends LauncherBinary { public final Path runtimeDir; public final Path guardDir; public final Path buildDir; - public final List tasks; public final List coreLibs; public final List addonLibs; public JARLauncherBinary(LaunchServer server) throws IOException { - super(server, resolve(server, ".jar")); + super(server, resolve(server, ".jar"), "Launcher-%s-%d.jar"); count = new AtomicLong(0); runtimeDir = server.dir.resolve(Launcher.RUNTIME_DIR); guardDir = server.dir.resolve(Launcher.GUARD_DIR); buildDir = server.dir.resolve("build"); - tasks = new ArrayList<>(); coreLibs = new ArrayList<>(); addonLibs = new ArrayList<>(); if (!Files.isDirectory(buildDir)) { @@ -50,45 +48,4 @@ public void init() { if (server.config.launcher.compress) tasks.add(new CompressBuildTask(server)); tasks.add(new SignJarTask(server.config.sign, server)); } - - @Override - public void build() throws IOException { - LogHelper.info("Building launcher binary file"); - count.set(0); // set jar number - Path thisPath = null; - boolean isNeedDelete = false; - long time_start = System.currentTimeMillis(); - long time_this = time_start; - for (LauncherBuildTask task : tasks) { - LogHelper.subInfo("Task %s", task.getName()); - Path oldPath = thisPath; - thisPath = task.process(oldPath); - long time_task_end = System.currentTimeMillis(); - long time_task = time_task_end - time_this; - time_this = time_task_end; - if (isNeedDelete && server.config.launcher.deleteTempFiles) Files.deleteIfExists(oldPath); - isNeedDelete = task.allowDelete(); - LogHelper.subInfo("Task %s processed from %d millis", task.getName(), time_task); - } - long time_end = System.currentTimeMillis(); - if (isNeedDelete && server.config.launcher.deleteTempFiles) IOHelper.move(thisPath, syncBinaryFile); - else IOHelper.copy(thisPath, syncBinaryFile); - LogHelper.info("Build successful from %d millis", time_end - time_start); - } - - public String nextName(String taskName) { - return String.format("Launcher-%s-%d.jar", taskName, count.getAndIncrement()); - } - - public Path nextPath(String taskName) { - return buildDir.resolve(nextName(taskName)); - } - - public Path nextPath(LauncherBuildTask task) { - return nextPath(task.getName()); - } - - public Path nextLowerPath(LauncherBuildTask task) { - return nextPath(CommonHelper.low(task.getName())); - } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherBinary.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherBinary.java index 62457dbd..e2131dd9 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherBinary.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherBinary.java @@ -7,18 +7,22 @@ import java.io.IOException; import java.nio.file.Path; -public abstract class LauncherBinary { +public abstract class LauncherBinary extends BinaryPipeline { public final LaunchServer server; public final Path syncBinaryFile; private volatile byte[] digest; private volatile byte[] sign; - protected LauncherBinary(LaunchServer server, Path binaryFile) { + protected LauncherBinary(LaunchServer server, Path binaryFile, String nameFormat) { + super(server.dir.resolve("build"), nameFormat); this.server = server; syncBinaryFile = binaryFile; } - public abstract void build() throws IOException; + public void build() throws IOException + { + build(syncBinaryFile, server.config.launcher.deleteTempFiles); + } public final boolean exists() { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/SimpleEXELauncherBinary.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/SimpleEXELauncherBinary.java deleted file mode 100644 index a9cd8cf5..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/SimpleEXELauncherBinary.java +++ /dev/null @@ -1,30 +0,0 @@ -package pro.gravit.launchserver.binary; - -import pro.gravit.launchserver.LaunchServer; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.LogHelper; - -import java.io.IOException; -import java.io.OutputStream; -import java.nio.file.Path; - -public class SimpleEXELauncherBinary extends LauncherBinary { - public final Path exeTemplate; - - public SimpleEXELauncherBinary(LaunchServer server) { - super(server, LauncherBinary.resolve(server, ".exe")); - exeTemplate = server.dir.resolve("SimpleTemplate.exe"); - } - - @Override - public void build() throws IOException { - if (!IOHelper.isFile(exeTemplate)) { - LogHelper.warning("[SimpleEXEBinary] File %s not found. %s not created", exeTemplate.toString(), syncBinaryFile.toString()); - return; - } - try (OutputStream output = IOHelper.newOutput(syncBinaryFile)) { - IOHelper.transfer(exeTemplate, output); - IOHelper.transfer(server.launcherBinary.syncBinaryFile, output); - } - } -} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/exe/Launch4JTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/exe/Launch4JTask.java new file mode 100644 index 00000000..11ab9927 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/exe/Launch4JTask.java @@ -0,0 +1,134 @@ +package pro.gravit.launchserver.binary.tasks.exe; + +import net.sf.launch4j.Builder; +import net.sf.launch4j.Log; +import net.sf.launch4j.config.*; +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launchserver.binary.EXEL4JLauncherBinary; +import pro.gravit.launchserver.binary.tasks.LauncherBuildTask; +import pro.gravit.utils.Version; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.LogHelper; + +import java.io.IOException; +import java.nio.file.Path; + +public class Launch4JTask implements LauncherBuildTask { + private final static class Launch4JLog extends Log { + private static final Launch4JLog INSTANCE = new Launch4JLog(); + + @Override + public void append(String s) { + LogHelper.subInfo(s); + } + + @Override + public void clear() { + // Do nothing + } + } + + // URL constants + private static final String DOWNLOAD_URL = "http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html"; // Oracle + // JRE 8 + // File constants + private final Path faviconFile; + + // File constants + private final LaunchServer server; + + public Launch4JTask(LaunchServer launchServer) { + this.server = launchServer; + faviconFile = launchServer.dir.resolve("favicon.ico"); + } + + @Override + public String getName() { + return "launch4j"; + } + + @Override + public Path process(Path inputFile) throws IOException { + LogHelper.info("Building launcher EXE binary file (Using Launch4J)"); + Path output = setConfig(); + + // Set favicon path + Config config = ConfigPersister.getInstance().getConfig(); + if (IOHelper.isFile(faviconFile)) + config.setIcon(faviconFile.toFile()); + else { + config.setIcon(null); + LogHelper.warning("Missing favicon.ico file"); + } + + // Start building + Builder builder = new Builder(Launch4JLog.INSTANCE); + try { + builder.build(); + } catch (Throwable e) { + throw new IOException(e); + } + return output; + } + + @Override + public boolean allowDelete() { + return true; + } + private Path setConfig() { + Path path = server.launcherEXEBinary.nextPath(getName()); + Config config = new Config(); + // Set file options + config.setChdir("."); + config.setErrTitle("JVM Error"); + config.setDownloadUrl(DOWNLOAD_URL); + + // Set boolean options + config.setPriorityIndex(0); + config.setHeaderType(Config.GUI_HEADER); + config.setStayAlive(false); + config.setRestartOnCrash(false); + + // Prepare JRE + Jre jre = new Jre(); + jre.setMinVersion("1.8.0"); + if (server.config.launch4j.setMaxVersion) + jre.setMaxVersion(server.config.launch4j.maxVersion); + jre.setRuntimeBits(Jre.RUNTIME_BITS_64_AND_32); + jre.setJdkPreference(Jre.JDK_PREFERENCE_PREFER_JRE); + config.setJre(jre); + + // Prepare version info (product) + VersionInfo info = new VersionInfo(); + info.setProductName(server.config.launch4j.productName); + info.setProductVersion(formatVars(server.config.launch4j.productVer)); + info.setFileDescription(server.config.launch4j.fileDesc); + info.setFileVersion(formatVars(server.config.launch4j.fileVer)); + info.setCopyright(server.config.launch4j.copyright); + info.setTrademarks(server.config.launch4j.trademarks); + info.setInternalName(formatVars(server.config.launch4j.internalName)); + // Prepare version info (file) + info.setTxtFileVersion(formatVars(server.config.launch4j.txtFileVersion)); + info.setTxtProductVersion(formatVars(server.config.launch4j.txtProductVersion)); + // Prepare version info (misc) + info.setOriginalFilename(path.getFileName().toString()); + info.setLanguage(LanguageID.RUSSIAN); + config.setVersionInfo(info); + + // Set JAR wrapping options + config.setDontWrapJar(false); + config.setJar(server.launcherBinary.syncBinaryFile.toFile()); + config.setOutfile(path.toFile()); + + // Return prepared config + ConfigPersister.getInstance().setAntConfig(config, null); + return path; + } + + private static final String VERSION = Version.getVersion().getVersionString(); + private static final int BUILD = Version.getVersion().build; + + public static String formatVars(String mask) { + return String.format(mask, VERSION, BUILD); + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java index ecb3ffaf..d37031be 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java @@ -207,7 +207,6 @@ public void close(LaunchServer.ReloadType type) { public static class ExeConf { public boolean enabled; - public String alternative; public boolean setMaxVersion; public String maxVersion; public String productName; @@ -291,7 +290,6 @@ public static LaunchServerConfig getDefault(LaunchServer.LaunchServerEnv env) { newConfig.launch4j = new LaunchServerConfig.ExeConf(); newConfig.launch4j.enabled = true; newConfig.launch4j.copyright = "© GravitLauncher Team"; - newConfig.launch4j.alternative = "no"; newConfig.launch4j.fileDesc = "GravitLauncher ".concat(Version.getVersion().getVersionString()); newConfig.launch4j.fileVer = Version.getVersion().getVersionString().concat(".").concat(String.valueOf(Version.getVersion().patch)); newConfig.launch4j.internalName = "Launcher"; From 085924c8315eda8a5beec8e62a413ea40ae57e20 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sun, 27 Oct 2019 23:58:44 +0700 Subject: [PATCH 061/192] =?UTF-8?q?[FEATURE]=20=D0=A3=D0=B4=D0=B0=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=83=D1=81=D1=82=D0=B0=D1=80=D0=B5?= =?UTF-8?q?=D0=B2=D1=88=D0=B5=D0=B3=D0=BE=20TaskUtil?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../binary/tasks/MainBuildTask.java | 2 +- .../binary/tasks/SignJarTask.java | 2 +- .../launchserver/binary/tasks/TaskUtil.java | 51 ------------------- .../command/service/SignDirCommand.java | 7 +-- .../command/service/SignJarCommand.java | 7 +-- 5 files changed, 10 insertions(+), 59 deletions(-) delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/TaskUtil.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java index c483fae6..83946c33 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java @@ -146,7 +146,7 @@ public Path process(Path inputJar) throws IOException { }).collect(Collectors.toList()); if(!server.config.sign.enabled) { - CertificateAutogenTask task = TaskUtil.getTaskByClass(server.launcherBinary.tasks, CertificateAutogenTask.class).get(0); + CertificateAutogenTask task = server.launcherBinary.getTaskByClass(CertificateAutogenTask.class).get(); try { certificates.add(task.certificate.getEncoded()); } catch (CertificateEncodingException e) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java index 32e42e66..44eadd98 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java @@ -91,7 +91,7 @@ private void stdSign(LaunchServerConfig.JarSignerConf config, Path inputFile, Pa } private void autoSign(Path inputFile, Path signedFile) throws IOException { try (SignerJar output = new SignerJar(new ZipOutputStream(IOHelper.newOutput(signedFile)), () -> { - CertificateAutogenTask task = TaskUtil.getTaskByClass(srv.launcherBinary.tasks, CertificateAutogenTask.class).get(0); + CertificateAutogenTask task = srv.launcherBinary.getTaskByClass(CertificateAutogenTask.class).get(); return task.signedDataGenerator; }, "AUTOGEN.SF", "AUTOGEN.EC"); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/TaskUtil.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/TaskUtil.java deleted file mode 100644 index 9449952e..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/TaskUtil.java +++ /dev/null @@ -1,51 +0,0 @@ -package pro.gravit.launchserver.binary.tasks; - -import java.util.ArrayList; -import java.util.List; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -public final class TaskUtil { - public static void addCounted(List tasks, int count, Predicate pred, LauncherBuildTask taskAdd) { - List indexes = new ArrayList<>(); - tasks.stream().filter(pred).forEach(indexes::add); - indexes.forEach(e -> tasks.add(tasks.indexOf(e) + count, taskAdd)); - } - - public static void replaceCounted(List tasks, int count, Predicate pred, LauncherBuildTask taskRep) { - List indexes = new ArrayList<>(); - tasks.stream().filter(pred).forEach(indexes::add); - indexes.forEach(e -> tasks.set(tasks.indexOf(e) + count, taskRep)); - } - - public static void addPre(List tasks, Predicate pred, LauncherBuildTask taskAdd) { - addCounted(tasks, -1, pred, taskAdd); - } - - public static void add(List tasks, Predicate pred, LauncherBuildTask taskAdd) { - addCounted(tasks, 0, pred, taskAdd); - } - - public static void addAfter(List tasks, Predicate pred, LauncherBuildTask taskAdd) { - addCounted(tasks, 1, pred, taskAdd); - } - - public static void replacePre(List tasks, Predicate pred, LauncherBuildTask taskRep) { - replaceCounted(tasks, -1, pred, taskRep); - } - - public static void replace(List tasks, Predicate pred, LauncherBuildTask taskRep) { - replaceCounted(tasks, 0, pred, taskRep); - } - - public static void replaceAfter(List tasks, Predicate pred, LauncherBuildTask taskRep) { - replaceCounted(tasks, 1, pred, taskRep); - } - - public static List getTaskByClass(List tasks, Class taskClass) { - return tasks.stream().filter(taskClass::isInstance).map(taskClass::cast).collect(Collectors.toList()); - } - - private TaskUtil() { - } -} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignDirCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignDirCommand.java index 84abd7cf..3cea5b76 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignDirCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignDirCommand.java @@ -2,7 +2,6 @@ import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.binary.tasks.SignJarTask; -import pro.gravit.launchserver.binary.tasks.TaskUtil; import pro.gravit.launchserver.command.Command; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; @@ -10,6 +9,7 @@ import java.io.IOException; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; +import java.util.Optional; public class SignDirCommand extends Command { private class SignJarVisitor extends SimpleFileVisitor @@ -52,8 +52,9 @@ public void invoke(String... args) throws Exception { Path targetDir = Paths.get(args[0]); if(!IOHelper.isDir(targetDir)) throw new IllegalArgumentException(String.format("%s not directory", targetDir.toString())); - SignJarTask task = (SignJarTask) TaskUtil.getTaskByClass(server.launcherBinary.tasks, SignJarTask.class); - IOHelper.walk(targetDir, new SignJarVisitor(task), true); + Optional task = server.launcherBinary.getTaskByClass(SignJarTask.class); + if(!task.isPresent()) throw new IllegalStateException("SignJarTask not found"); + IOHelper.walk(targetDir, new SignJarVisitor(task.get()), true); LogHelper.info("Success signed"); } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignJarCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignJarCommand.java index 62162f60..ce71f751 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignJarCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignJarCommand.java @@ -2,13 +2,13 @@ import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.binary.tasks.SignJarTask; -import pro.gravit.launchserver.binary.tasks.TaskUtil; import pro.gravit.launchserver.command.Command; import pro.gravit.utils.helper.LogHelper; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Optional; public class SignJarCommand extends Command { public SignJarCommand(LaunchServer server) { @@ -35,8 +35,9 @@ public void invoke(String... args) throws Exception { else tmpSign = server.dir.resolve("build").resolve(target.toFile().getName()); LogHelper.info("Signing jar %s to %s", target.toString(), tmpSign.toString()); - SignJarTask task = (SignJarTask) TaskUtil.getTaskByClass(server.launcherBinary.tasks, SignJarTask.class); - task.sign(server.config.sign, target, tmpSign); + Optional task = server.launcherBinary.getTaskByClass(SignJarTask.class); + if(!task.isPresent()) throw new IllegalStateException("SignJarTask not found"); + task.get().sign(server.config.sign, target, tmpSign); if(args.length <= 1) { LogHelper.info("Move temp jar %s to %s", tmpSign.toString(), target.toString()); From c0b476a49428cb02cbec6afee7f776c7abd6786f Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 28 Oct 2019 01:24:09 +0700 Subject: [PATCH 062/192] =?UTF-8?q?[FIX]=20public.key=20=D0=B1=D0=BE=D0=BB?= =?UTF-8?q?=D1=8C=D1=88=D0=B5=20=D0=BD=D0=B5=20=D1=82=D1=80=D0=B5=D0=B1?= =?UTF-8?q?=D1=83=D0=B5=D1=82=D1=81=D1=8F=20=D0=B4=D0=BB=D1=8F=20ServerWra?= =?UTF-8?q?pper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/pro/gravit/launcher/LauncherConfig.java | 2 +- .../java/pro/gravit/launcher/server/ServerWrapper.java | 6 +++++- .../launcher/server/setup/ServerWrapperSetup.java | 10 ---------- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java b/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java index c916c8b7..037c541f 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java @@ -87,7 +87,7 @@ public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException @LauncherAPI public LauncherConfig(String address, ECPublicKey publicKey, Map runtime, String projectName) { this.address = address; - this.publicKey = Objects.requireNonNull(publicKey, "publicKey"); + this.publicKey = publicKey; this.runtime = Collections.unmodifiableMap(new HashMap<>(runtime)); this.projectName = projectName; this.clientPort = 32148; diff --git a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java index a6ea4409..365f6eeb 100644 --- a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java +++ b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java @@ -27,6 +27,7 @@ import java.net.URL; import java.nio.file.Path; import java.nio.file.Paths; +import java.security.interfaces.ECPublicKey; import java.security.spec.InvalidKeySpecException; import java.util.Arrays; import java.util.HashMap; @@ -190,7 +191,10 @@ public void updateLauncherConfig() { LauncherConfig cfg = null; try { - cfg = new LauncherConfig(config.address, SecurityHelper.toPublicECKey(IOHelper.read(publicKeyFile)), new HashMap<>(), config.projectname); + ECPublicKey publicKey = null; + if(IOHelper.isFile(publicKeyFile)) + publicKey = SecurityHelper.toPublicECKey(IOHelper.read(publicKeyFile)); + cfg = new LauncherConfig(config.address, publicKey, new HashMap<>(), config.projectname); cfg.isNettyEnabled = true; cfg.address = config.address; } catch (InvalidKeySpecException | IOException e) { diff --git a/ServerWrapper/src/main/java/pro/gravit/launcher/server/setup/ServerWrapperSetup.java b/ServerWrapper/src/main/java/pro/gravit/launcher/server/setup/ServerWrapperSetup.java index 12cbf82e..79c940b7 100644 --- a/ServerWrapper/src/main/java/pro/gravit/launcher/server/setup/ServerWrapperSetup.java +++ b/ServerWrapper/src/main/java/pro/gravit/launcher/server/setup/ServerWrapperSetup.java @@ -46,16 +46,6 @@ public void run() throws IOException { String address = commands.commandHandler.readLine(); wrapper.config.mainclass = mainClassName; wrapper.config.address = address; - if (!Files.exists(ServerWrapper.publicKeyFile)) { - LogHelper.error("public.key not found"); - for (int i = 0; i < 10; ++i) { - System.out.println("Print F to continue:"); - String printF = commands.commandHandler.readLine(); - if (printF.equals("stop")) return; - if (Files.exists(ServerWrapper.publicKeyFile)) break; - else LogHelper.error("public.key not found"); - } - } boolean stopOnError = wrapper.config.stopOnError; for (int i = 0; i < 10; ++i) { System.out.println("Print server account login:"); From 888a3a92d99ce068accaf444fef6a17144ef06bb Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 28 Oct 2019 01:31:04 +0700 Subject: [PATCH 063/192] [ANY] 5.1.0-dev --- LauncherCore/src/main/java/pro/gravit/utils/Version.java | 6 +++--- build.gradle | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/LauncherCore/src/main/java/pro/gravit/utils/Version.java b/LauncherCore/src/main/java/pro/gravit/utils/Version.java index a8ae29b4..78bc7b37 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/Version.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/Version.java @@ -16,10 +16,10 @@ public final class Version { @LauncherAPI public final Type release; public static final int MAJOR = 5; - public static final int MINOR = 0; - public static final int PATCH = 10; + public static final int MINOR = 1; + public static final int PATCH = 0; public static final int BUILD = 1; - public static final Version.Type RELEASE = Type.STABLE; + public static final Version.Type RELEASE = Type.DEV; @LauncherAPI public Version(int major, int minor, int patch) { diff --git a/build.gradle b/build.gradle index 4747dbb5..d40d113b 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ id 'signing' } group = 'pro.gravit.launcher' -version = '5.0.10' +version = '5.1.0-SNAPSHOT' configure(subprojects.findAll { it.name != 'modules' }) { apply plugin: 'idea' From 35f71f679737c71178fb817acd41f52d1ddc2c13 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 9 Nov 2019 11:53:15 +0700 Subject: [PATCH 064/192] =?UTF-8?q?[FIX]=20=D0=A4=D0=B8=D0=BA=D1=81=20Cast?= =?UTF-8?q?Exception?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../request/websockets/StandartClientWebSocketService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StandartClientWebSocketService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StandartClientWebSocketService.java index 728ec40b..8af049ab 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StandartClientWebSocketService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StandartClientWebSocketService.java @@ -65,7 +65,7 @@ public WebSocketEvent get() throws InterruptedException, ExecutionException { } WebSocketEvent result = event.result; waitEventHandler.requests.remove(event); - if (event.result.getType().equals("error") || event.result.getType().equals("exception")) { + if (event.result.getType().equals("error")) { ErrorRequestEvent errorRequestEvent = (ErrorRequestEvent) event.result; throw new ExecutionException(new RequestException(errorRequestEvent.error)); } From 0224ce8cd605c3553a3e606d124b761735f64fbe Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 9 Nov 2019 16:40:08 +0700 Subject: [PATCH 065/192] =?UTF-8?q?[FIX]=20=D0=A4=D0=B8=D0=BA=D1=81=20fina?= =?UTF-8?q?l=20=D0=B8=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D1=81=D0=B2=D0=BE=D0=B5=D0=B3=D0=BE=20runtime?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launcher/client/events/ClientPreGuiPhase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientPreGuiPhase.java b/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientPreGuiPhase.java index b7077cdd..ebbad380 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientPreGuiPhase.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientPreGuiPhase.java @@ -4,7 +4,7 @@ import pro.gravit.launcher.modules.LauncherModule; public class ClientPreGuiPhase extends LauncherModule.Event { - public final RuntimeProvider runtimeProvider; + public RuntimeProvider runtimeProvider; public ClientPreGuiPhase(RuntimeProvider runtimeProvider) { this.runtimeProvider = runtimeProvider; From 3291d2de6bb4b925355f878a2ab9471c97bb095c Mon Sep 17 00:00:00 2001 From: Gravit Date: Sun, 10 Nov 2019 07:00:22 +0700 Subject: [PATCH 066/192] =?UTF-8?q?[FIX]=20=D0=A3=D1=81=D0=BA=D0=BE=D1=80?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B7=D0=B0=D0=BF=D1=83=D1=81=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BF=D1=83=D1=82=D0=B5=D0=BC=20=D0=B2=D1=8B=D0=BA?= =?UTF-8?q?=D0=BB=D1=8E=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=20javaagent=20=D0=BD?= =?UTF-8?q?=D0=B0=20=D1=81=D1=82=D0=BE=D1=80=D0=BE=D0=BD=D0=B5=20=D0=BB?= =?UTF-8?q?=D0=B0=D1=83=D0=BD=D1=87=D0=B5=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/pro/gravit/launcher/ClientLauncherWrapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java b/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java index a7aafb6a..6c97efcf 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java +++ b/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java @@ -82,7 +82,7 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep Collections.addAll(args, MAGIC_ARG); Collections.addAll(args, "-XX:+DisableAttachMechanism"); Collections.addAll(args, "-Xmx256M"); - Collections.addAll(args, "-javaagent:".concat(pathLauncher)); + //Collections.addAll(args, "-javaagent:".concat(pathLauncher)); Collections.addAll(args, "-cp"); Collections.addAll(args, pathLauncher); Collections.addAll(args, LauncherEngine.class.getName()); From b23b033d1902911cf473d8ca5fa7f11bd8e54125 Mon Sep 17 00:00:00 2001 From: zaxar163 Date: Sun, 10 Nov 2019 10:21:44 +0300 Subject: [PATCH 067/192] =?UTF-8?q?[FIX]=20=D0=9E=D1=81=D1=82=D0=B0=D1=82?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=20=D1=83=D0=B4?= =?UTF-8?q?=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B0=D0=B3=D0=B5=D0=BD?= =?UTF-8?q?=D1=82=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/pro/gravit/launcher/LauncherEngine.java | 1 + .../src/main/java/pro/gravit/utils/helper/JVMHelper.java | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index 5b4fbb9b..f0339e74 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -54,6 +54,7 @@ public static void main(String... args) throws Throwable { JVMHelper.verifySystemProperties(Launcher.class, true); EnvHelper.checkDangerousParams(); //if(!LauncherAgent.isStarted()) throw new SecurityException("JavaAgent not set"); + JVMHelper.verifyNoAgent(); LogHelper.printVersion("Launcher"); LogHelper.printLicense("Launcher"); LauncherEngine.checkClass(LauncherEngine.class); diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java index d5a140cc..fef77d80 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java @@ -180,4 +180,8 @@ public static void verifySystemProperties(Class mainClass, boolean requireSys private JVMHelper() { } + + public static void verifyNoAgent() { + if (RUNTIME_MXBEAN.getInputArguments().stream().filter(e -> e != null && !e.isEmpty()).anyMatch(e -> e.contains("javaagent"))) throw new SecurityException("JavaAgent found"); + } } From 6b85de280657f4cf429c17893d2bc17e0902a317 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Fri, 15 Nov 2019 14:37:43 +0100 Subject: [PATCH 068/192] =?UTF-8?q?[FIX]=20=D0=92=202=20=D0=BC=D0=B5=D1=81?= =?UTF-8?q?=D1=82=D0=B0=D1=85=20=D1=83=D0=B1=D1=80=D0=B0=D0=BB=20=D1=80?= =?UTF-8?q?=D0=B5=D1=84=D0=BB=D0=B5=D0=BA=D1=81=D0=B8=D1=8E.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/pro/gravit/launchserver/LaunchServer.java | 8 ++++---- .../launchserver/config/LaunchServerConfig.java | 7 ++++++- .../launcher/modules/impl/SimpleModuleManager.java | 14 ++++++++++++-- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java index 0b60e7f8..67fae76b 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java @@ -36,7 +36,8 @@ import java.io.BufferedReader; import java.io.IOException; import java.lang.ProcessBuilder.Redirect; -import java.lang.reflect.InvocationTargetException; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; import java.security.InvalidAlgorithmParameterException; @@ -390,9 +391,8 @@ public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, La private LauncherBinary binary() { if (launcherEXEBinaryClass != null) { try { - return launcherEXEBinaryClass.getConstructor(LaunchServer.class).newInstance(this); - } catch (InstantiationException | IllegalAccessException | IllegalArgumentException - | InvocationTargetException | NoSuchMethodException | SecurityException e) { + return (LauncherBinary) MethodHandles.publicLookup().findConstructor(launcherEXEBinaryClass, MethodType.methodType(void.class, LaunchServer.class)).invoke(this); + } catch (Throwable e) { LogHelper.error(e); } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java index d37031be..e2f20159 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java @@ -319,7 +319,12 @@ public static LaunchServerConfig getDefault(LaunchServer.LaunchServerEnv env) { newConfig.netty.fileServerEnabled = true; newConfig.netty.binds = new NettyBindAddress[]{new NettyBindAddress("0.0.0.0", 9274)}; newConfig.netty.performance = new NettyPerformanceConfig(); - newConfig.netty.performance.usingEpoll = Epoll.isAvailable(); + try { + newConfig.netty.performance.usingEpoll = Epoll.isAvailable(); + } catch (Throwable e) { + // Epoll class line 51+ catch (Exception) but Error will be thrown by System.load + newConfig.netty.performance.usingEpoll = false; + } // such as on ARM newConfig.netty.performance.bossThread = 2; newConfig.netty.performance.workerThread = 8; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java index 740fe8b4..16737cd1 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java @@ -10,6 +10,8 @@ import pro.gravit.utils.verify.LauncherTrustManager; import java.io.IOException; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; import java.net.URL; import java.nio.file.FileVisitResult; import java.nio.file.Files; @@ -29,6 +31,7 @@ import java.util.jar.JarFile; public class SimpleModuleManager implements LauncherModulesManager { + private static final MethodType VOID_TYPE = MethodType.methodType(void.class); protected final List modules = new ArrayList<>(); protected final List moduleNames = new ArrayList<>(); protected final SimpleModuleContext context; @@ -149,10 +152,17 @@ public LauncherModule loadModule(Path file) throws IOException { @SuppressWarnings("unchecked") Class clazz = (Class) Class.forName(moduleClass, false, classLoader); checkModuleClass(clazz, checkMode); - LauncherModule module = clazz.newInstance(); + if (!LauncherModule.class.isAssignableFrom(clazz)) + throw new ClassNotFoundException("Invalid module class... Not contains LauncherModule in hierarchy."); + LauncherModule module; + try { + module = (LauncherModule) MethodHandles.publicLookup().findConstructor(clazz, VOID_TYPE).invoke(); + } catch (Throwable e) { + throw (InstantiationException) new InstantiationException("Error on instancing...").initCause(e); + } loadModule(module); return module; - } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) { + } catch (ClassNotFoundException | InstantiationException e) { LogHelper.error(e); LogHelper.error("In module %s Module-Main-Class incorrect", file.toString()); return null; From 31c32aa2c2ca04a6f2f27e8a4c596cc2a0eeb8be Mon Sep 17 00:00:00 2001 From: zaxar163 Date: Sat, 16 Nov 2019 20:38:59 +0300 Subject: [PATCH 069/192] =?UTF-8?q?[FIX]=20=D0=A0=D0=B0=D0=B7=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20url=20=D0=B8=20=D0=BF=D1=83?= =?UTF-8?q?=D1=82=D0=B8=20=D0=B2=20ListDownloader.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launcher/downloader/ListDownloader.java | 16 +++++++++++++--- modules | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java b/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java index 643e50e3..741cdf3f 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java @@ -47,10 +47,18 @@ public interface DownloadTotalCallback { public static class DownloadTask { public final String apply; - public final long size; + public long size; + public final String urlApply; public DownloadTask(String apply, long size) { this.apply = apply; + urlApply = apply; + this.size = size; + } + + public DownloadTask(String urlApply, String apply, long size) { + this.apply = apply; + this.urlApply = urlApply; this.size = size; } } @@ -70,7 +78,7 @@ public void download(String base, List applies, Path dstDirFile, D String path = baseUri.getPath(); List excs = new CopyOnWriteArrayList<>(); for (DownloadTask apply : applies) { - URI u = new URI(scheme, host, path + apply.apply, "", ""); + URI u = new URI(scheme, host, path + apply.urlApply, "", ""); callback.stateChanged(apply.apply, 0L, apply.size); Path targetPath = dstDirFile.resolve(apply.apply); toExec.add(() -> { @@ -181,7 +189,9 @@ public Path handleResponse(HttpResponse response) throws IOException { } long contentLength = response.getEntity().getContentLength(); if (task != null && contentLength != task.size) { - LogHelper.warning("Missing content length: expected %d | found %d", task.size, contentLength); + if (task.size > 0) + LogHelper.warning("Missing content length: expected %d | found %d", task.size, contentLength); + else task.size = contentLength; } if (zip) { try (ZipInputStream input = IOHelper.newZipInput(source)) { diff --git a/modules b/modules index 52818e6e..e098678d 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 52818e6ef05d90ad678d02e83f9bd4140d8eda34 +Subproject commit e098678d7ea2c5e6a926f457dcbc820c4e9fba66 From a841746ac868c20447b12327fd99adf19b4abd40 Mon Sep 17 00:00:00 2001 From: zaxar163 Date: Sat, 16 Nov 2019 21:14:28 +0300 Subject: [PATCH 070/192] =?UTF-8?q?[FIX]=20=D0=97=D0=B0=D0=B1=D1=8B=D1=82?= =?UTF-8?q?=D1=8B=D0=B5=20=D0=B7=D0=B0=D0=B2=D0=B8=D1=81=D0=B8=D0=BC=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LaunchServer/build.gradle | 1 + ServerWrapper/build.gradle | 1 + modules | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/LaunchServer/build.gradle b/LaunchServer/build.gradle index 890bb281..77e444c7 100644 --- a/LaunchServer/build.gradle +++ b/LaunchServer/build.gradle @@ -81,6 +81,7 @@ pack project(':LauncherAPI') bundle 'org.fusesource.jansi:jansi:1.18' bundle 'commons-io:commons-io:2.6' bundle 'commons-codec:commons-codec:1.12' + bundle 'org.apache.httpcomponents:httpclient:4.5.7' bundle 'org.javassist:javassist:3.25.0-GA' bundle 'io.netty:netty-all:4.1.36.Final' bundle 'org.hibernate:hibernate-core:5.4.4.Final' diff --git a/ServerWrapper/build.gradle b/ServerWrapper/build.gradle index 72d24cec..e4d95236 100644 --- a/ServerWrapper/build.gradle +++ b/ServerWrapper/build.gradle @@ -38,6 +38,7 @@ task javadocJar(type: Jar) { dependencies { pack project(':LauncherAuthlib') + pack 'org.bouncycastle:bcprov-jdk15:1.46' pack 'org.apache.httpcomponents:httpclient:4.5.7' pack 'io.netty:netty-codec-http:4.1.36.Final' } diff --git a/modules b/modules index e098678d..bac8af98 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit e098678d7ea2c5e6a926f457dcbc820c4e9fba66 +Subproject commit bac8af98b5cac38e634a7776b947d01eb30ff873 From 8c1a8235a86ca8c83792036772fdf203939dc5e7 Mon Sep 17 00:00:00 2001 From: zaxar163 Date: Sat, 16 Nov 2019 21:17:45 +0300 Subject: [PATCH 071/192] =?UTF-8?q?[ANY]=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B8?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index bac8af98..cec48e15 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit bac8af98b5cac38e634a7776b947d01eb30ff873 +Subproject commit cec48e154a44b3ee51aadda8e2886739445939ec From ee955d002c4913244cdafcfbe63acef49fae1066 Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 20 Nov 2019 20:00:23 +0700 Subject: [PATCH 072/192] [FEATURE] New ClientProcessBuilder API --- .../client/ClientLauncherContext.java | 2 + .../launcher/client/ClientProcessBuilder.java | 152 ++++++++++++++++++ 2 files changed, 154 insertions(+) create mode 100644 Launcher/src/main/java/pro/gravit/launcher/client/ClientProcessBuilder.java diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherContext.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherContext.java index 51f78968..a618e529 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherContext.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherContext.java @@ -12,6 +12,8 @@ public class ClientLauncherContext { public final List args = new LinkedList<>(); public String pathLauncher; public ProcessBuilder builder; + public Process process; public ClientProfile clientProfile; public PlayerProfile playerProfile; + public ClientLauncher.Params params; } diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientProcessBuilder.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientProcessBuilder.java new file mode 100644 index 00000000..cd4d9382 --- /dev/null +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientProcessBuilder.java @@ -0,0 +1,152 @@ +package pro.gravit.launcher.client; + +import pro.gravit.launcher.ClientLauncherWrapper; +import pro.gravit.launcher.Launcher; +import pro.gravit.launcher.guard.LauncherGuardManager; +import pro.gravit.launcher.hasher.HashedDir; +import pro.gravit.launcher.managers.ClientHookManager; +import pro.gravit.launcher.profiles.ClientProfile; +import pro.gravit.utils.helper.EnvHelper; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.JVMHelper; +import pro.gravit.utils.helper.LogHelper; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.Collections; +import java.util.List; + +import static pro.gravit.launcher.client.ClientLauncher.checkJVMBitsAndVersion; + +public class ClientProcessBuilder { + private HashedDir assetHDir; + private HashedDir clientHDir; + private ClientProfile profile; + private ClientLauncher.Params params; + private Path nativesDir = IOHelper.toPath("natives"); + private Path resourcepacksDir = IOHelper.toPath("resourcepacks"); + private boolean pipeOutput = false; + private boolean clientLaunchStarting = false; + public interface ParamsWriter + { + void write(ClientLauncherContext context); + } + private ParamsWriter paramsWriter; + + private static final String MAGICAL_INTEL_OPTION = "-XX:HeapDumpPath=ThisTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump"; + + public ClientProcessBuilder setAssetHDir(HashedDir assetHDir) { + this.assetHDir = assetHDir; + return this; + } + + public ClientProcessBuilder setClientHDir(HashedDir clientHDir) { + this.clientHDir = clientHDir; + return this; + } + + public ClientProcessBuilder setProfile(ClientProfile profile) { + this.profile = profile; + return this; + } + + public ClientProcessBuilder setParams(ClientLauncher.Params params) { + this.params = params; + return this; + } + + public ClientProcessBuilder setNativesDir(Path nativesDir) { + this.nativesDir = nativesDir; + return this; + } + + public ClientProcessBuilder setResourcepacksDir(Path resourcepacksDir) { + this.resourcepacksDir = resourcepacksDir; + return this; + } + + public ClientProcessBuilder setPipeOutput(boolean pipeOutput) { + this.pipeOutput = pipeOutput; + return this; + } + + public ClientProcessBuilder setParamsWriter(ParamsWriter paramsWriter) { + this.paramsWriter = paramsWriter; + return this; + } + + public ClientLauncherContext build() throws IOException { + LogHelper.debug("Writing ClientLauncher params"); + ClientLauncherContext context = new ClientLauncherContext(); + clientLaunchStarting = true; + checkJVMBitsAndVersion(); + LogHelper.debug("Resolving JVM binary"); + Path javaBin = LauncherGuardManager.getGuardJavaBinPath(); + context.javaBin = javaBin; + context.clientProfile = profile; + context.playerProfile = params.pp; + context.args.add(javaBin.toString()); + context.args.add(MAGICAL_INTEL_OPTION); + context.params = params; + if(paramsWriter != null) paramsWriter.write(context); + if (params.ram > 0 && params.ram <= FunctionalBridge.getJVMTotalMemory()) { + context.args.add("-Xms" + params.ram + 'M'); + context.args.add("-Xmx" + params.ram + 'M'); + } + context.args.add(JVMHelper.jvmProperty(LogHelper.DEBUG_PROPERTY, Boolean.toString(LogHelper.isDebugEnabled()))); + context.args.add(JVMHelper.jvmProperty(LogHelper.STACKTRACE_PROPERTY, Boolean.toString(LogHelper.isStacktraceEnabled()))); + context.args.add(JVMHelper.jvmProperty(LogHelper.DEV_PROPERTY, Boolean.toString(LogHelper.isDevEnabled()))); + context.args.add(JVMHelper.jvmProperty(LogHelper.NO_JANSI_PROPERTY, "true")); // Отключаем JAnsi для нормального вывода в DEBUG окно + JVMHelper.addSystemPropertyToArgs(context.args, DirBridge.CUSTOMDIR_PROPERTY); + JVMHelper.addSystemPropertyToArgs(context.args, DirBridge.USE_CUSTOMDIR_PROPERTY); + JVMHelper.addSystemPropertyToArgs(context.args, DirBridge.USE_OPTDIR_PROPERTY); + if (JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) { + if (JVMHelper.OS_VERSION.startsWith("10.")) { + LogHelper.debug("MustDie 10 fix is applied"); + context.args.add(JVMHelper.jvmProperty("os.name", "Windows 10")); + context.args.add(JVMHelper.jvmProperty("os.version", "10.0")); + } + } + // Add classpath and main class + String pathLauncher = IOHelper.getCodeSource(ClientLauncher.class).toString(); + context.pathLauncher = pathLauncher; + Collections.addAll(context.args, ClientLauncherWrapper.MAGIC_ARG); + Collections.addAll(context.args, profile.getJvmArgs()); + profile.pushOptionalJvmArgs(context.args); + Collections.addAll(context.args, "-Djava.library.path=".concat(params.clientDir.resolve(nativesDir).toString())); // Add Native Path + Collections.addAll(context.args, "-javaagent:".concat(pathLauncher)); + ClientHookManager.clientLaunchHook.hook(context); + LauncherGuardManager.guard.addCustomParams(context); + Collections.addAll(context.args, ClientLauncher.class.getName()); + ClientHookManager.clientLaunchFinallyHook.hook(context); + + // Print commandline debug message + LogHelper.debug("Commandline: " + context.args); + + // Build client process + LogHelper.debug("Launching client instance"); + ProcessBuilder builder = new ProcessBuilder(context.args); + context.builder = builder; + LauncherGuardManager.guard.addCustomEnv(context); + //else + //builder.environment().put("CLASSPATH", classPathString.toString()); + EnvHelper.addEnv(builder); + builder.directory(params.clientDir.toFile()); + builder.inheritIO(); + if (pipeOutput) { + builder.redirectErrorStream(true); + builder.redirectOutput(ProcessBuilder.Redirect.PIPE); + } + List command = builder.command(); + // Let's rock! + ClientHookManager.preStartHook.hook(context, builder); + context.process = builder.start(); + if (builder.command() != command) { + LogHelper.error("Something strange cheating..."); + System.exit(100); + return null; + } + ClientHookManager.postStartHook.hook(context, builder); + return context; + } +} From 8730ecb7497251c9ce5767f88d2ea90adadf7e55 Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 20 Nov 2019 20:04:41 +0700 Subject: [PATCH 073/192] =?UTF-8?q?[ANY]=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index cec48e15..4a0419a5 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit cec48e154a44b3ee51aadda8e2886739445939ec +Subproject commit 4a0419a5bfeb391fd694dd4a39483668a88262c3 From 641001f0419bcba224a05b1b1680ac71e70c8bab Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 20 Nov 2019 20:07:26 +0700 Subject: [PATCH 074/192] =?UTF-8?q?[FIX]=20=D0=9E=D1=82=D0=BA=D0=BB=D1=8E?= =?UTF-8?q?=D1=87=D0=B5=D0=BD=20=D1=82=D0=B5=D1=81=D1=82=D0=BE=D0=B2=D1=8B?= =?UTF-8?q?=D0=B9=20SecurityManager?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/pro/gravit/launcher/client/ClientLauncher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index 9e523ce7..f39a5af1 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -442,7 +442,7 @@ public static void main(String... args) throws Throwable { EnvHelper.checkDangerousParams(); JVMHelper.checkStackTrace(ClientLauncher.class); LogHelper.printVersion("Client Launcher"); - System.setSecurityManager(new ClientSecurityManager()); + //System.setSecurityManager(new ClientSecurityManager()); engine.readKeys(); HWIDProvider.registerHWIDs(); LauncherGuardManager.initGuard(true); From 490ba360e710a3ba09d0b2b38b5fa1094e5809ae Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 20 Nov 2019 20:42:43 +0700 Subject: [PATCH 075/192] =?UTF-8?q?[FEATURE]=20=D0=A1=D0=B8=D1=81=D1=82?= =?UTF-8?q?=D0=B5=D0=BC=D0=B0=20=D1=83=D0=B2=D0=B5=D0=B4=D0=BE=D0=BC=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../command/handler/CommandHandler.java | 2 +- .../command/service/GetModulusCommand.java | 25 --------------- .../command/service/NotifyCommand.java | 31 +++++++++++++++++++ .../launcher/events/NotificationEvent.java | 18 +++++++++++ .../websockets/ClientWebSocketService.java | 2 ++ 5 files changed, 52 insertions(+), 26 deletions(-) delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GetModulusCommand.java create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/command/service/NotifyCommand.java create mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/events/NotificationEvent.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java index 8402b32b..ab917f10 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java @@ -84,7 +84,7 @@ public static void registerCommands(pro.gravit.utils.command.CommandHandler hand service.registerCommand("serverStatus", new ServerStatusCommand(server)); service.registerCommand("checkInstall", new CheckInstallCommand(server)); service.registerCommand("multi", new MultiCommand(server)); - service.registerCommand("getModulus", new GetModulusCommand(server)); + service.registerCommand("notify", new NotifyCommand(server)); service.registerCommand("component", new ComponentCommand(server)); service.registerCommand("givePermission", new GivePermissionsCommand(server)); service.registerCommand("getPermissions", new GetPermissionsCommand(server)); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GetModulusCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GetModulusCommand.java deleted file mode 100644 index f5e06ad4..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GetModulusCommand.java +++ /dev/null @@ -1,25 +0,0 @@ -package pro.gravit.launchserver.command.service; - -import pro.gravit.launchserver.LaunchServer; -import pro.gravit.launchserver.command.Command; - -public class GetModulusCommand extends Command { - public GetModulusCommand(LaunchServer server) { - super(server); - } - - @Override - public String getArgsDescription() { - return null; - } - - @Override - public String getUsageDescription() { - return null; - } - - @Override - public void invoke(String... args) { - //LogHelper.info("You publickey modulus: %s", server.publicKey.getModulus().toString(16)); - } -} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/NotifyCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/NotifyCommand.java new file mode 100644 index 00000000..bf14beeb --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/NotifyCommand.java @@ -0,0 +1,31 @@ +package pro.gravit.launchserver.command.service; + +import pro.gravit.launcher.events.NotificationEvent; +import pro.gravit.launcher.request.WebSocketEvent; +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launchserver.command.Command; +import pro.gravit.launchserver.socket.WebSocketService; + +public class NotifyCommand extends Command { + public NotifyCommand(LaunchServer server) { + super(server); + } + + @Override + public String getArgsDescription() { + return "[head] [message]"; + } + + @Override + public String getUsageDescription() { + return "send notification to all connected client"; + } + + @Override + public void invoke(String... args) throws Exception { + verifyArgs(args, 2); + NotificationEvent event = new NotificationEvent(args[0], args[1]); + WebSocketService service = server.nettyServerSocketHandler.nettyServer.service; + service.sendObjectAll(event, WebSocketEvent.class); + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/NotificationEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/NotificationEvent.java new file mode 100644 index 00000000..528b7eb1 --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/NotificationEvent.java @@ -0,0 +1,18 @@ +package pro.gravit.launcher.events; + +import pro.gravit.launcher.request.WebSocketEvent; + +public class NotificationEvent implements WebSocketEvent { + public final String head; + public final String message; + + public NotificationEvent(String head, String message) { + this.head = head; + this.message = message; + } + + @Override + public String getType() { + return "notification"; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java index 8aa7efe4..3b4afcbd 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java @@ -4,6 +4,7 @@ import com.google.gson.GsonBuilder; import pro.gravit.launcher.Launcher; import pro.gravit.launcher.events.ExceptionEvent; +import pro.gravit.launcher.events.NotificationEvent; import pro.gravit.launcher.events.request.*; import pro.gravit.launcher.hasher.HashedEntry; import pro.gravit.launcher.hasher.HashedEntryAdapter; @@ -107,6 +108,7 @@ public void registerResults() { results.register("exception", ExceptionEvent.class); results.register("register", RegisterRequestEvent.class); results.register("setpassword", SetPasswordRequestEvent.class); + results.register("notification", NotificationEvent.class); } public void registerHandler(EventHandler eventHandler) { From 17106886bbd8da236193269f7f376e6c3fc820e0 Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 20 Nov 2019 20:49:35 +0700 Subject: [PATCH 076/192] [FIX] NotificationEvent proguard support --- .../gravit/launcher/events/ControlEvent.java | 19 ------------------- .../launcher/events/NotificationEvent.java | 3 +++ .../gravit/launcher/events/SignalEvent.java | 8 +++++++- .../websockets/ClientWebSocketService.java | 2 ++ 4 files changed, 12 insertions(+), 20 deletions(-) delete mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/events/ControlEvent.java diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/ControlEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/ControlEvent.java deleted file mode 100644 index 399dd4dc..00000000 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/ControlEvent.java +++ /dev/null @@ -1,19 +0,0 @@ -package pro.gravit.launcher.events; - -import java.util.UUID; - -//Набор стандартных событий -public class ControlEvent { - @SuppressWarnings("unused") - private static final UUID uuid = UUID.fromString("f1051a64-0cd0-4ed8-8430-d856a196e91f"); - - public enum ControlCommand { - STOP, START, PAUSE, CONTINUE, CRASH - } - - public ControlEvent(ControlCommand signal) { - this.signal = signal; - } - - public final ControlCommand signal; -} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/NotificationEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/NotificationEvent.java index 528b7eb1..cdf124cb 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/NotificationEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/NotificationEvent.java @@ -1,9 +1,12 @@ package pro.gravit.launcher.events; +import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.request.WebSocketEvent; public class NotificationEvent implements WebSocketEvent { + @LauncherNetworkAPI public final String head; + @LauncherNetworkAPI public final String message; public NotificationEvent(String head, String message) { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/SignalEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/SignalEvent.java index eef9e7fd..c4ff91f6 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/SignalEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/SignalEvent.java @@ -1,13 +1,19 @@ package pro.gravit.launcher.events; import pro.gravit.launcher.LauncherNetworkAPI; +import pro.gravit.launcher.request.WebSocketEvent; //Используется, что бы послать короткое сообщение, которое вмещается в int -public class SignalEvent { +public class SignalEvent implements WebSocketEvent { @LauncherNetworkAPI public final int signal; public SignalEvent(int signal) { this.signal = signal; } + + @Override + public String getType() { + return "signal"; + } } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java index 3b4afcbd..3ec44934 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java @@ -5,6 +5,7 @@ import pro.gravit.launcher.Launcher; import pro.gravit.launcher.events.ExceptionEvent; import pro.gravit.launcher.events.NotificationEvent; +import pro.gravit.launcher.events.SignalEvent; import pro.gravit.launcher.events.request.*; import pro.gravit.launcher.hasher.HashedEntry; import pro.gravit.launcher.hasher.HashedEntryAdapter; @@ -109,6 +110,7 @@ public void registerResults() { results.register("register", RegisterRequestEvent.class); results.register("setpassword", SetPasswordRequestEvent.class); results.register("notification", NotificationEvent.class); + results.register("signal", SignalEvent.class); } public void registerHandler(EventHandler eventHandler) { From 5c39b1d4d2991b965f4032d4601b99e4b247f237 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sun, 24 Nov 2019 19:55:33 +0700 Subject: [PATCH 077/192] =?UTF-8?q?[FIX]=20=D0=94=D0=BE=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D0=BD=D0=B8=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=B5=20=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B8=20=D0=B2=20Auth=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=B7=D0=B0=D1=89=D0=B8=D1=82=D1=8B=20?= =?UTF-8?q?=D0=BE=D1=82=20=D0=B4=D1=83=D1=80=D0=B0=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launchserver/auth/provider/AuthProvider.java | 2 +- .../socket/response/auth/AuthResponse.java | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AuthProvider.java index 07b02ae6..03cd0462 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AuthProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AuthProvider.java @@ -43,7 +43,7 @@ public static void registerProviders() { */ public abstract AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface password, String ip) throws Exception; - public void preAuth(String login, AuthRequest.AuthPasswordInterface password, String customText, String ip) { + public void preAuth(String login, AuthRequest.AuthPasswordInterface password, String ip) { } @Override diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java index 18c8bb2b..f067795d 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java @@ -3,6 +3,7 @@ import io.netty.channel.ChannelHandlerContext; import pro.gravit.launcher.events.request.AuthRequestEvent; import pro.gravit.launcher.hwid.HWID; +import pro.gravit.launcher.hwid.NoHWID; import pro.gravit.launcher.profiles.ClientProfile; import pro.gravit.launcher.request.auth.AuthRequest; import pro.gravit.launcher.request.auth.password.AuthECPassword; @@ -32,7 +33,6 @@ public class AuthResponse extends SimpleResponse { public final transient static Random random = new SecureRandom(); public String login; public String client; - public String customText; public boolean getSession; public AuthRequest.AuthPasswordInterface password; @@ -66,13 +66,19 @@ public void execute(ChannelHandlerContext ctx, Client clientData) throws Excepti throw new AuthException("Password decryption error"); } } + if(hwid == null) hwid = new NoHWID(); AuthProviderPair pair; if (auth_id.isEmpty()) pair = server.config.getAuthProviderPair(); else pair = server.config.getAuthProviderPair(auth_id); - AuthContext context = new AuthContext(clientData, login, customText, client, hwid, ip, authType); + if(pair == null) + { + sendError("auth_id incorrect"); + return; + } + AuthContext context = new AuthContext(clientData, login, client, hwid, ip, authType); AuthProvider provider = pair.provider; server.authHookManager.preHook.hook(context, clientData); - provider.preAuth(login, password, customText, ip); + provider.preAuth(login, password, ip); AuthProviderResult aresult = provider.auth(login, password, ip); if (!VerifyHelper.isValidUsername(aresult.username)) { AuthProvider.authError(String.format("Illegal result: '%s'", aresult.username)); @@ -128,10 +134,9 @@ public void execute(ChannelHandlerContext ctx, Client clientData) throws Excepti } public static class AuthContext { - public AuthContext(Client client, String login, String customText, String profileName, HWID hwid, String ip, ConnectTypes authType) { + public AuthContext(Client client, String login, String profileName, HWID hwid, String ip, ConnectTypes authType) { this.client = client; this.login = login; - this.customText = customText; this.profileName = profileName; this.hwid = hwid; this.ip = ip; @@ -143,7 +148,6 @@ public AuthContext(Client client, String login, String customText, String profil public int password_length; //Use AuthProvider for get password public final String profileName; public final HWID hwid; - public final String customText; public final String ip; public final ConnectTypes authType; public final Client client; From 178fab6ff79d394b8a83f76cea2e3a6bf3b00724 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sun, 24 Nov 2019 22:32:39 +0700 Subject: [PATCH 078/192] =?UTF-8?q?[FIX]=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B1=D0=B8=D0=B1=D0=BB=D0=B8?= =?UTF-8?q?=D0=BE=D1=82=D0=B5=D0=BA=20=D0=B4=D0=BE=20=D0=B0=D0=BA=D1=82?= =?UTF-8?q?=D1=83=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B=D1=85=20=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D1=81=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LaunchServer/build.gradle | 17 ++++++++--------- Launcher/build.gradle | 5 ++--- LauncherAPI/build.gradle | 4 ++-- ServerWrapper/build.gradle | 5 ++--- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/LaunchServer/build.gradle b/LaunchServer/build.gradle index 77e444c7..5e6747a8 100644 --- a/LaunchServer/build.gradle +++ b/LaunchServer/build.gradle @@ -74,24 +74,23 @@ pack project(':LauncherAPI') bundle 'org.ow2.asm:asm-commons:7.1' bundle 'mysql:mysql-connector-java:8.0.16' bundle 'org.postgresql:postgresql:42.2.6' - bundle 'org.jline:jline:3.11.0' - bundle 'org.jline:jline-reader:3.11.0' - bundle 'org.jline:jline-terminal:3.11.0' - bundle 'net.sf.proguard:proguard-base:6.1.0' + bundle 'org.jline:jline:3.13.1' + bundle 'org.jline:jline-reader:3.13.1' + bundle 'org.jline:jline-terminal:3.13.1' + bundle 'net.sf.proguard:proguard-base:6.2.0' bundle 'org.fusesource.jansi:jansi:1.18' bundle 'commons-io:commons-io:2.6' bundle 'commons-codec:commons-codec:1.12' - bundle 'org.apache.httpcomponents:httpclient:4.5.7' - bundle 'org.javassist:javassist:3.25.0-GA' - bundle 'io.netty:netty-all:4.1.36.Final' - bundle 'org.hibernate:hibernate-core:5.4.4.Final' + bundle 'org.apache.httpcomponents:httpclient:4.5.10' + bundle 'io.netty:netty-all:4.1.43.Final' + bundle 'org.hibernate:hibernate-core:5.4.9.Final' bundle 'org.bouncycastle:bcpkix-jdk15on:1.61' bundle 'org.slf4j:slf4j-simple:1.7.25' bundle 'org.slf4j:slf4j-api:1.7.25' hikari 'io.micrometer:micrometer-core:1.0.6' - hikari('com.zaxxer:HikariCP:3.2.0') { + hikari('com.zaxxer:HikariCP:3.4.1') { exclude group: 'javassist' exclude group: 'io.micrometer' exclude group: 'org.slf4j' diff --git a/Launcher/build.gradle b/Launcher/build.gradle index a989aea5..36353d18 100644 --- a/Launcher/build.gradle +++ b/Launcher/build.gradle @@ -49,9 +49,8 @@ task javadocJar(type: Jar) { dependencies { pack project(':LauncherAuthlib') bundle 'com.github.oshi:oshi-core:3.13.0' - bundle 'org.apache.httpcomponents:httpclient:4.5.7' - bundle 'org.bouncycastle:bcprov-jdk15:1.46' - pack 'io.netty:netty-codec-http:4.1.36.Final' + bundle 'org.apache.httpcomponents:httpclient:4.5.10' + pack 'io.netty:netty-codec-http:4.1.43.Final' pack 'org.ow2.asm:asm-tree:7.1' } diff --git a/LauncherAPI/build.gradle b/LauncherAPI/build.gradle index fccaad8b..820aa7f6 100644 --- a/LauncherAPI/build.gradle +++ b/LauncherAPI/build.gradle @@ -3,8 +3,8 @@ dependencies { compile project(':LauncherCore') - compileOnly 'org.apache.httpcomponents:httpclient:4.5.7' - compileOnly 'io.netty:netty-codec-http:4.1.36.Final' + compileOnly 'org.apache.httpcomponents:httpclient:4.5.10' + compileOnly 'io.netty:netty-codec-http:4.1.43.Final' testCompile 'org.junit.jupiter:junit-jupiter:5.4.1' } diff --git a/ServerWrapper/build.gradle b/ServerWrapper/build.gradle index e4d95236..d32120f4 100644 --- a/ServerWrapper/build.gradle +++ b/ServerWrapper/build.gradle @@ -38,9 +38,8 @@ task javadocJar(type: Jar) { dependencies { pack project(':LauncherAuthlib') - pack 'org.bouncycastle:bcprov-jdk15:1.46' - pack 'org.apache.httpcomponents:httpclient:4.5.7' - pack 'io.netty:netty-codec-http:4.1.36.Final' + pack 'org.apache.httpcomponents:httpclient:4.5.10' + pack 'io.netty:netty-codec-http:4.1.43.Final' } shadowJar { From e9db1b307b5252340553a00ea6e776082bf33e5d Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 25 Nov 2019 00:33:18 +0700 Subject: [PATCH 079/192] =?UTF-8?q?[FEATURE]=20Multi-Release=20JAR=20?= =?UTF-8?q?=D0=B8=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=B8=D0=BB=D1=8F=D1=86=D0=B8?= =?UTF-8?q?=D1=8F=20=D1=82=D0=BE=D0=BB=D1=8C=D0=BA=D0=BE=20=D0=BD=D0=B0=20?= =?UTF-8?q?Java=2011+?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitlab-ci.yml | 4 ++-- Launcher/build.gradle | 8 +++++++- LauncherCore/build.gradle | 19 ++++++++++++++++++- .../pro/gravit/utils/helper/JVMHelper.java | 11 +++++++++++ 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b5149a5b..713955e1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,7 +11,7 @@ stages: - test build: - image: frekele/java + image: java:11 stage: build before_script: - apt-get -y update @@ -43,7 +43,7 @@ build: - artifacts test: - image: frekele/java + image: java:11 stage: test script: - ./gradlew check \ No newline at end of file diff --git a/Launcher/build.gradle b/Launcher/build.gradle index 36353d18..0836fc7f 100644 --- a/Launcher/build.gradle +++ b/Launcher/build.gradle @@ -1,3 +1,6 @@ +plugins { + id 'org.openjfx.javafxplugin' version '0.0.5' +} apply plugin: 'com.github.johnrengelman.shadow' String mainClassName = "pro.gravit.launcher.ClientLauncherWrapper" @@ -8,7 +11,10 @@ url "http://repo.spring.io/plugins-release/" } } - +javafx { + version = "12" + modules = [ 'javafx.controls', 'javafx.fxml' ] +} sourceCompatibility = '1.8' targetCompatibility = '1.8' diff --git a/LauncherCore/build.gradle b/LauncherCore/build.gradle index 7d26a1a1..c4783f31 100644 --- a/LauncherCore/build.gradle +++ b/LauncherCore/build.gradle @@ -1,3 +1,4 @@ +apply plugin: 'java-library' sourceCompatibility = '1.8' targetCompatibility = '1.8' @@ -17,10 +18,26 @@ events "passed", "skipped", "failed" } } - +sourceSets { + java9 { + java { + srcDirs = ['src/main/java9'] + } + dependencies { + java9Implementation files(sourceSets.main.output.classesDirs) { builtBy compileJava } + } + } +} jar { + into('META-INF/versions/9') { + from sourceSets.java9.output + } classifier = 'clean' } +compileJava9Java { + sourceCompatibility = 9 + targetCompatibility = 9 +} task sourcesJar(type: Jar) { from sourceSets.main.allJava diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java index fef77d80..2c40fa0d 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java @@ -59,6 +59,17 @@ public static OS byName(String name) { public static final ClassLoader LOADER = ClassLoader.getSystemClassLoader(); + public static final int JVM_VERSION = getVersion(); + public static int getVersion() { + String version = System.getProperty("java.version"); + if(version.startsWith("1.")) { + version = version.substring(2, 3); + } else { + int dot = version.indexOf("."); + if(dot != -1) { version = version.substring(0, dot); } + } return Integer.parseInt(version); + } + static { try { MethodHandles.publicLookup(); // Just to initialize class From fc9ac07bc08d3995a518d71ec5a1f02606d0ce95 Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 25 Nov 2019 00:38:59 +0700 Subject: [PATCH 080/192] =?UTF-8?q?[FEATURE]=20=D0=98=D1=81=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20GitLab=20CI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 713955e1..49de251e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,7 +11,7 @@ stages: - test build: - image: java:11 + image: gradle:jdk11 stage: build before_script: - apt-get -y update @@ -43,7 +43,7 @@ build: - artifacts test: - image: java:11 + image: gradle:jdk11 stage: test script: - ./gradlew check \ No newline at end of file From 05093d8865eddabb7065c22961b360d44c119173 Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 25 Nov 2019 00:53:31 +0700 Subject: [PATCH 081/192] =?UTF-8?q?[FIX]=20=D0=98=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20Travis=20CI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index b195f4ae..5822178d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,7 @@ language: java dist: trusty +jdk: + - openjdk11 # Use https (public access) instead of git for git-submodules. This modifies only Travis-CI behavior! # disable the default submodule logic git: From aa4d4881c8af2bb80af4016aeffc488a16701c43 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Mon, 25 Nov 2019 16:54:27 +0100 Subject: [PATCH 082/192] =?UTF-8?q?[FIX]=20=D0=A1=D1=82=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=BD=D0=B0=D1=8F=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B0=20?= =?UTF-8?q?=D1=81=20MH.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launcher/modules/impl/SimpleModuleManager.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java index 16737cd1..72d701fc 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java @@ -26,6 +26,7 @@ import java.security.cert.X509Certificate; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.function.Predicate; import java.util.jar.JarFile; @@ -156,7 +157,7 @@ public LauncherModule loadModule(Path file) throws IOException { throw new ClassNotFoundException("Invalid module class... Not contains LauncherModule in hierarchy."); LauncherModule module; try { - module = (LauncherModule) MethodHandles.publicLookup().findConstructor(clazz, VOID_TYPE).invoke(); + module = (LauncherModule) MethodHandles.publicLookup().findConstructor(clazz, VOID_TYPE).invokeWithArguments(Collections.emptyList()); } catch (Throwable e) { throw (InstantiationException) new InstantiationException("Error on instancing...").initCause(e); } From 37e3991a9a3a3376dab795698755ce0cbf5e6c23 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Thu, 28 Nov 2019 17:14:06 +0100 Subject: [PATCH 083/192] =?UTF-8?q?[FEATURE]=20=D0=90=D0=B4=D0=B5=D0=BA?= =?UTF-8?q?=D0=B2=D0=B0=D1=82=D0=BD=D0=B0=D1=8F=20=D0=BF=D0=BE=D0=B4=D0=B4?= =?UTF-8?q?=D0=B5=D1=80=D0=B6=D0=BA=D0=B0=20Docker.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launchserver/LaunchServer.java | 17 ++++++++++++----- .../launchserver/LaunchServerStarter.java | 11 +++++++++-- .../pro/gravit/launchserver/StarterAgent.java | 3 ++- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java index 67fae76b..d3967ea3 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java @@ -247,15 +247,22 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO public static final Class defaultLauncherEXEBinaryClass = null; public static class LaunchServerDirectories { + public static final String UPDATES_NAME = "updates", PROFILES_NAME = "profiles", + TRUSTSTORE_NAME = "truststore", LAUNCHERLIBRARIES_NAME = "launcher-libraries", + LAUNCHERLIBRARIESCOMPILE_NAME = "launcher-libraries-compile"; public Path updatesDir; public Path profilesDir; + public Path launcherLibrariesDir; + public Path launcherLibrariesCompileDir; public Path dir; public Path trustStore; public void collect() { - if (updatesDir == null) updatesDir = dir.resolve("updates"); - if (profilesDir == null) profilesDir = dir.resolve("profiles"); - if (trustStore == null) trustStore = dir.resolve("truststore"); + if (updatesDir == null) updatesDir = dir.resolve(UPDATES_NAME); + if (profilesDir == null) profilesDir = dir.resolve(PROFILES_NAME); + if (trustStore == null) trustStore = dir.resolve(TRUSTSTORE_NAME); + if (launcherLibrariesDir == null) launcherLibrariesDir = dir.resolve(LAUNCHERLIBRARIES_NAME); + if (launcherLibrariesCompileDir == null) launcherLibrariesCompileDir = dir.resolve(LAUNCHERLIBRARIESCOMPILE_NAME); } } @@ -273,8 +280,8 @@ public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, La this.runtime = runtimeConfig; this.certificateManager = certificateManager; taskPool = new Timer("Timered task worker thread", true); - launcherLibraries = dir.resolve("launcher-libraries"); - launcherLibrariesCompile = dir.resolve("launcher-libraries-compile"); + launcherLibraries = directories.launcherLibrariesDir; + launcherLibrariesCompile = directories.launcherLibrariesCompileDir; config.setLaunchServer(this); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java index a91a7a64..ff31bb65 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java @@ -44,6 +44,7 @@ public class LaunchServerStarter { public static final boolean allowUnsigned = Boolean.getBoolean("launchserver.allowUnsigned"); + public static final boolean inDocker = Boolean.getBoolean("launchserver.dockered"); public static void main(String[] args) throws Exception { JVMHelper.checkStackTrace(LaunchServerStarter.class); @@ -177,9 +178,15 @@ public void writeRuntimeConfig(LaunchServerRuntimeConfig config) throws IOExcept } } }; - + LaunchServer.LaunchServerDirectories directories = new LaunchServer.LaunchServerDirectories(); + directories.dir = dir; + if (inDocker) { + Path parentLibraries = StarterAgent.libraries.toAbsolutePath().normalize().getParent(); + directories.launcherLibrariesCompileDir = parentLibraries.resolve(LaunchServer.LaunchServerDirectories.LAUNCHERLIBRARIESCOMPILE_NAME); + directories.launcherLibrariesDir = parentLibraries.resolve(LaunchServer.LaunchServerDirectories.LAUNCHERLIBRARIES_NAME); + } LaunchServer server = new LaunchServerBuilder() - .setDir(dir) + .setDirectories(directories) .setEnv(env) .setCommandHandler(localCommandHandler) .setPrivateKey(privateKey) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/StarterAgent.java b/LaunchServer/src/main/java/pro/gravit/launchserver/StarterAgent.java index c6baacd0..ba309020 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/StarterAgent.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/StarterAgent.java @@ -9,6 +9,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashSet; +import java.util.Optional; import java.util.Set; import java.util.jar.JarFile; @@ -59,7 +60,7 @@ public static boolean isAgentStarted() { public static void premain(String agentArgument, Instrumentation inst) { StarterAgent.inst = inst; - libraries = Paths.get("libraries"); + libraries = Paths.get(Optional.ofNullable(agentArgument).map(e -> e.trim()).filter(e -> !e.isEmpty()).orElse("libraries")); isStarted = true; try { Files.walkFileTree(libraries, Collections.singleton(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new StarterVisitor()); From fccc9fe8c05f29f29c4b6743f48f60d5bf0968cb Mon Sep 17 00:00:00 2001 From: Gravit Date: Thu, 28 Nov 2019 23:15:28 +0700 Subject: [PATCH 084/192] =?UTF-8?q?[FIX](=D0=97=D0=B0=D0=B1=D1=8B=D1=82?= =?UTF-8?q?=D1=8B=D0=B9=20=D0=BA=D0=BE=D0=BC=D0=BC=D0=B8=D1=82)=20=D0=9D?= =?UTF-8?q?=D0=B5=20=D1=83=D0=BA=D0=B0=D0=B7=D1=8B=D0=B2=D0=B0=D0=BB=D1=81?= =?UTF-8?q?=D1=8F=20requestUUID=20=D0=B2=20UpdateResponse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launchserver/socket/response/update/UpdateResponse.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/UpdateResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/UpdateResponse.java index bb3156d8..3765dfa3 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/UpdateResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/UpdateResponse.java @@ -28,14 +28,14 @@ public void execute(ChannelHandlerContext ctx, Client client) { for (ClientProfile p : server.getProfiles()) { if (!client.profile.getTitle().equals(p.getTitle())) continue; if (!p.isWhitelistContains(client.username)) { - service.sendObject(ctx, new ErrorRequestEvent("You don't download this folder")); + sendError("You don't download this folder"); return; } } } HashedDir dir = server.updatesDirMap.get(dirName); if (dir == null) { - service.sendObject(ctx, new ErrorRequestEvent(String.format("Directory %s not found", dirName))); + sendError(String.format("Directory %s not found", dirName)); return; } String url = server.config.netty.downloadURL.replace("%dirname%", IOHelper.urlEncode(dirName)); @@ -45,6 +45,6 @@ public void execute(ChannelHandlerContext ctx, Client client) { url = bind.url; zip = bind.zip; } - service.sendObject(ctx, new UpdateRequestEvent(dir, url, zip)); + sendResult(new UpdateRequestEvent(dir, url, zip)); } } From 90d2123f762e2e2b4cabf66f4feb0dc8bcd7df5b Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Thu, 28 Nov 2019 17:29:36 +0100 Subject: [PATCH 085/192] =?UTF-8?q?[FIX]=20=D0=90=D0=B2=D1=82=D0=BE=D0=B2?= =?UTF-8?q?=D1=8B=D0=B1=D0=BE=D1=80=20=D0=BE=D0=BF=D1=86=D0=B8=D0=B9=20Pro?= =?UTF-8?q?Guard=20=D0=B4=D0=BB=D1=8F=20Java9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/pro/gravit/launchserver/asm/NodeUtils.java | 11 +++++++++++ .../gravit/launchserver/binary/ProguardConf.java | 13 +++++++++++++ .../pro/gravit/launchserver/defaults/proguard.cfg | 4 ---- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/NodeUtils.java b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/NodeUtils.java index 56b9e221..9919cde7 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/NodeUtils.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/NodeUtils.java @@ -15,6 +15,17 @@ import static org.objectweb.asm.Opcodes.*; public final class NodeUtils { + public static final boolean JAVA9; + + static { + boolean java9 = false; + try { + Class.forName("java.lang.StackWalker"); + java9 = true; + } catch (final Throwable e) { + } + JAVA9 = java9; + } private NodeUtils() { } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/ProguardConf.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/ProguardConf.java index 123b8a89..ff9e3277 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/ProguardConf.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/ProguardConf.java @@ -1,6 +1,7 @@ package pro.gravit.launchserver.binary; import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launchserver.asm.NodeUtils; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.SecurityHelper; @@ -13,11 +14,21 @@ import java.nio.file.Path; import java.security.SecureRandom; import java.util.ArrayList; +import java.util.Collections; import java.util.List; public class ProguardConf { private static final String chars = "1aAbBcC2dDeEfF3gGhHiI4jJkKl5mMnNoO6pPqQrR7sStT8uUvV9wWxX0yYzZ"; + public static final String[] JAVA9_OPTS = new String[] { + "-libraryjars '/jmods/'" + }; + public static final String[] JAVA8_OPTS = new String[] { + "-libraryjars '/lib/rt.jar'", + "-libraryjars '/lib/jce.jar'", + "-libraryjars '/lib/ext/nashorn.jar'", + "-libraryjars '/lib/ext/jfxrt.jar'" + }; private static String generateString(SecureRandom rand, String lowString, String upString, int il) { StringBuilder sb = new StringBuilder(Math.max(il, lowString.length())); for (int i = 0; i < lowString.length(); ++i) { @@ -50,9 +61,11 @@ public String[] buildConfig(Path inputJar, Path outputJar) { confStrs.add("-obfuscationdictionary \'" + words.toFile().getName() + "\'"); confStrs.add("-injar \'" + inputJar.toAbsolutePath() + "\'"); confStrs.add("-outjar \'" + outputJar.toAbsolutePath() + "\'"); + Collections.addAll(confStrs, NodeUtils.JAVA9 ? JAVA9_OPTS : JAVA8_OPTS); srv.launcherBinary.coreLibs.stream() .map(e -> "-libraryjars \'" + e.toAbsolutePath().toString() + "\'") .forEach(confStrs::add); + srv.launcherBinary.addonLibs.stream() .map(e -> "-libraryjars \'" + e.toAbsolutePath().toString() + "\'") .forEach(confStrs::add); diff --git a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/proguard.cfg b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/proguard.cfg index 5a4eb1ef..08b511c1 100644 --- a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/proguard.cfg +++ b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/proguard.cfg @@ -1,7 +1,3 @@ --libraryjars '/lib/rt.jar' --libraryjars '/lib/jce.jar' --libraryjars '/lib/ext/nashorn.jar' --libraryjars '/lib/ext/jfxrt.jar' -keepattributes SourceFile,LineNumberTable -renamesourcefileattribute Source From af88a02a526b555b0b649d5100e6220afb0efcbc Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Thu, 28 Nov 2019 17:42:45 +0100 Subject: [PATCH 086/192] =?UTF-8?q?[FIX]=20=D0=9D=D0=B5=D0=BC=D0=BD=D0=BE?= =?UTF-8?q?=D0=B6=D0=BA=D0=BE=20=D0=BE=D0=BF=D1=82=D0=B8=D0=BC=D0=B8=D0=B7?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=20=D0=B0=D0=BB=D0=B3=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D1=82=D0=BC=20=D0=B3=D0=B5=D0=BD=D0=B5=D1=80=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D0=B8=20dictonary.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/pro/gravit/launchserver/binary/ProguardConf.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/ProguardConf.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/ProguardConf.java index ff9e3277..d9eb81ee 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/ProguardConf.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/ProguardConf.java @@ -18,7 +18,7 @@ import java.util.List; public class ProguardConf { - private static final String chars = "1aAbBcC2dDeEfF3gGhHiI4jJkKl5mMnNoO6pPqQrR7sStT8uUvV9wWxX0yYzZ"; + private static final char[] chars = "1aAbBcC2dDeEfF3gGhHiI4jJkKl5mMnNoO6pPqQrR7sStT8uUvV9wWxX0yYzZ".toCharArray(); public static final String[] JAVA9_OPTS = new String[] { "-libraryjars '/jmods/'" @@ -35,7 +35,7 @@ private static String generateString(SecureRandom rand, String lowString, String sb.append(rand.nextBoolean() ? lowString.charAt(i) : upString.charAt(i)); } int toI = il - lowString.length(); - for (int i = 0; i < toI; i++) sb.append(chars.charAt(rand.nextInt(chars.length()))); + for (int i = 0; i < toI; i++) sb.append(chars[rand.nextInt(chars.length)]); return sb.toString(); } From 97b30aa2349caf650f043ca539b862126a7602da Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Thu, 28 Nov 2019 18:01:04 +0100 Subject: [PATCH 087/192] =?UTF-8?q?[ANY]=20=D0=A0=D0=B5=D1=84=D0=B0=D0=BA?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=B8=D0=BD=D0=B3.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../binary/JARLauncherBinary.java | 3 --- .../launchserver/binary/ProguardConf.java | 6 +----- .../binary/tasks/CertificateAutogenTask.java | 1 - .../binary/tasks/MainBuildTask.java | 1 - .../binary/tasks/SignJarTask.java | 20 ------------------- .../binary/tasks/exe/Launch4JTask.java | 1 - .../response/update/UpdateResponse.java | 1 - .../launcher/client/ClientProcessBuilder.java | 1 - .../pro/gravit/utils/helper/CryptoHelper.java | 1 - .../gravit/launcher/server/ServerWrapper.java | 2 +- 10 files changed, 2 insertions(+), 35 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JARLauncherBinary.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JARLauncherBinary.java index 5bd5ea78..aec99498 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JARLauncherBinary.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JARLauncherBinary.java @@ -3,9 +3,6 @@ import pro.gravit.launcher.Launcher; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.binary.tasks.*; -import pro.gravit.utils.helper.CommonHelper; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.LogHelper; import java.io.IOException; import java.nio.file.Files; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/ProguardConf.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/ProguardConf.java index d9eb81ee..9201cad4 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/ProguardConf.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/ProguardConf.java @@ -70,7 +70,7 @@ public String[] buildConfig(Path inputJar, Path outputJar) { .map(e -> "-libraryjars \'" + e.toAbsolutePath().toString() + "\'") .forEach(confStrs::add); confStrs.add("-classobfuscationdictionary \'" + words.toFile().getName() + "\'"); - confStrs.add(readConf()); + confStrs.add("@".concat(config.toFile().getName())); return confStrs.toArray(new String[0]); } @@ -102,8 +102,4 @@ public void prepare(boolean force) { LogHelper.error(e); } } - - private String readConf() { - return "@".concat(config.toFile().getName()); - } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/CertificateAutogenTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/CertificateAutogenTask.java index c597034f..feaddff3 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/CertificateAutogenTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/CertificateAutogenTask.java @@ -20,7 +20,6 @@ import java.math.BigInteger; import java.nio.file.Path; import java.security.cert.Certificate; -import java.security.cert.CertificateEncodingException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.time.LocalDate; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java index 83946c33..807e6993 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java @@ -23,7 +23,6 @@ import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import java.security.cert.CertificateEncodingException; -import java.security.cert.X509Certificate; import java.util.*; import java.util.jar.JarFile; import java.util.stream.Collectors; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java index 44eadd98..d327150d 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/SignJarTask.java @@ -1,17 +1,8 @@ package pro.gravit.launchserver.binary.tasks; -import org.bouncycastle.asn1.x500.X500Name; -import org.bouncycastle.asn1.x500.X500NameBuilder; -import org.bouncycastle.asn1.x500.style.BCStyle; -import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; -import org.bouncycastle.cert.X509CertificateHolder; -import org.bouncycastle.cert.X509v3CertificateBuilder; -import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter; import org.bouncycastle.cms.CMSException; import org.bouncycastle.cms.CMSSignedDataGenerator; -import org.bouncycastle.operator.ContentSigner; import org.bouncycastle.operator.OperatorCreationException; -import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.binary.SignerJar; import pro.gravit.launchserver.config.LaunchServerConfig; @@ -21,23 +12,12 @@ import java.io.File; import java.io.IOException; -import java.math.BigInteger; import java.nio.file.Path; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.UnrecoverableKeyException; -import java.security.cert.Certificate; import java.security.cert.CertificateEncodingException; -import java.security.cert.CertificateException; -import java.security.cert.X509Certificate; -import java.security.interfaces.ECPrivateKey; -import java.security.interfaces.ECPublicKey; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.ZoneId; -import java.util.ArrayList; -import java.util.Date; import java.util.jar.Manifest; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/exe/Launch4JTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/exe/Launch4JTask.java index 11ab9927..08d743fb 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/exe/Launch4JTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/exe/Launch4JTask.java @@ -4,7 +4,6 @@ import net.sf.launch4j.Log; import net.sf.launch4j.config.*; import pro.gravit.launchserver.LaunchServer; -import pro.gravit.launchserver.binary.EXEL4JLauncherBinary; import pro.gravit.launchserver.binary.tasks.LauncherBuildTask; import pro.gravit.utils.Version; import pro.gravit.utils.helper.IOHelper; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/UpdateResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/UpdateResponse.java index 3765dfa3..4eef9f11 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/UpdateResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/UpdateResponse.java @@ -1,7 +1,6 @@ package pro.gravit.launchserver.socket.response.update; import io.netty.channel.ChannelHandlerContext; -import pro.gravit.launcher.events.request.ErrorRequestEvent; import pro.gravit.launcher.events.request.UpdateRequestEvent; import pro.gravit.launcher.hasher.HashedDir; import pro.gravit.launcher.profiles.ClientProfile; diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientProcessBuilder.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientProcessBuilder.java index cd4d9382..4259700d 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientProcessBuilder.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientProcessBuilder.java @@ -1,7 +1,6 @@ package pro.gravit.launcher.client; import pro.gravit.launcher.ClientLauncherWrapper; -import pro.gravit.launcher.Launcher; import pro.gravit.launcher.guard.LauncherGuardManager; import pro.gravit.launcher.hasher.HashedDir; import pro.gravit.launcher.managers.ClientHookManager; diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/CryptoHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/CryptoHelper.java index 7106fca5..3a843df7 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/CryptoHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/CryptoHelper.java @@ -1,6 +1,5 @@ package pro.gravit.utils.helper; -import java.io.OutputStream; import java.util.Objects; import java.util.function.LongSupplier; diff --git a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java index 365f6eeb..3df2bc50 100644 --- a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java +++ b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java @@ -52,7 +52,7 @@ public ServerWrapper(Type type, Path configPath) { public boolean auth() { try { - LauncherConfig cfg = Launcher.getConfig(); + Launcher.getConfig(); AuthRequest request = new AuthRequest(config.login, config.password, config.auth_id, AuthRequest.ConnectTypes.SERVER); permissions = request.request().permissions; ProfilesRequestEvent result = new ProfilesRequest().request(); From 358e92ad9e2cffc7b245f2640d29b8fd08329225 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Thu, 28 Nov 2019 18:12:40 +0100 Subject: [PATCH 088/192] =?UTF-8?q?[FIX]=20=D0=9F=D0=B5=D1=80=D0=B5=D0=BF?= =?UTF-8?q?=D0=B8=D1=81=D0=B0=D0=BB=20=D0=BA=D0=BE=D0=B4=20=D0=B8=D1=81?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D1=83=D1=8E=D1=89=D0=B8=D0=B9=20?= =?UTF-8?q?ProccessBuilder.=20=D0=90=D0=BA=D1=82=D0=B8=D0=B2=D0=BD=D1=8B?= =?UTF-8?q?=D0=B5=20=D1=83=D1=87=D0=B0=D1=81=D1=82=D0=BD=D0=B8=D0=BA=D0=B8?= =?UTF-8?q?=20=D0=BF=D1=80=D0=BE=D1=88=D1=83=20=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D1=81=D0=BF=D0=BE=D1=81=D0=BE=D0=B1=D0=BD=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D1=8C=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=20=D1=8D?= =?UTF-8?q?=D1=82=D0=BE=D0=B3=D0=BE=20=D0=BA=D0=BE=D0=BC=D0=BC=D0=B8=D1=82?= =?UTF-8?q?=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launcher/ClientLauncherWrapper.java | 21 +++++++++---------- .../launcher/client/ClientProcessBuilder.java | 8 +++---- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java b/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java index 6c97efcf..6ea83190 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java +++ b/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java @@ -12,7 +12,6 @@ import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Collections; import java.util.LinkedList; import java.util.List; @@ -62,8 +61,8 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep JVMHelper.addSystemPropertyToArgs(args, DirBridge.USE_OPTDIR_PROPERTY); if (!noJava9check && !System.getProperty("java.version").startsWith("1.8")) { LogHelper.debug("Found Java 9+ ( %s )", System.getProperty("java.version")); - Collections.addAll(args, "--add-modules"); - Collections.addAll(args, "javafx.base,javafx.fxml,javafx.controls,jdk.unsupported"); + args.add("--add-modules"); + args.add("javafx.base,javafx.fxml,javafx.controls,jdk.unsupported"); Path jvmDir = Paths.get(System.getProperty("java.home")); String pathToFx = System.getenv("PATH_TO_FX"); Path fxPath = pathToFx == null ? null : Paths.get(pathToFx); @@ -75,17 +74,17 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep tryAddModule(findPath, "javafx.controls", builder); String modulePath = builder.toString(); if (!modulePath.isEmpty()) { - Collections.addAll(args, "--module-path"); - Collections.addAll(args, modulePath); + args.add("--module-path"); + args.add(modulePath); } } - Collections.addAll(args, MAGIC_ARG); - Collections.addAll(args, "-XX:+DisableAttachMechanism"); - Collections.addAll(args, "-Xmx256M"); + args.add(MAGIC_ARG); + args.add("-XX:+DisableAttachMechanism"); + args.add("-Xmx256M"); //Collections.addAll(args, "-javaagent:".concat(pathLauncher)); - Collections.addAll(args, "-cp"); - Collections.addAll(args, pathLauncher); - Collections.addAll(args, LauncherEngine.class.getName()); + args.add("-cp"); + args.add(pathLauncher); + args.add(LauncherEngine.class.getName()); LauncherEngine.modulesManager.callWrapper(processBuilder, args); EnvHelper.addEnv(processBuilder); LogHelper.debug("Commandline: " + args); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientProcessBuilder.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientProcessBuilder.java index 4259700d..f658b4fb 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientProcessBuilder.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientProcessBuilder.java @@ -109,14 +109,14 @@ public ClientLauncherContext build() throws IOException { // Add classpath and main class String pathLauncher = IOHelper.getCodeSource(ClientLauncher.class).toString(); context.pathLauncher = pathLauncher; - Collections.addAll(context.args, ClientLauncherWrapper.MAGIC_ARG); + context.args.add(ClientLauncherWrapper.MAGIC_ARG); Collections.addAll(context.args, profile.getJvmArgs()); profile.pushOptionalJvmArgs(context.args); - Collections.addAll(context.args, "-Djava.library.path=".concat(params.clientDir.resolve(nativesDir).toString())); // Add Native Path - Collections.addAll(context.args, "-javaagent:".concat(pathLauncher)); + context.args.add("-Djava.library.path=".concat(params.clientDir.resolve(nativesDir).toString())); // Add Native Path + context.args.add("-javaagent:".concat(pathLauncher)); ClientHookManager.clientLaunchHook.hook(context); LauncherGuardManager.guard.addCustomParams(context); - Collections.addAll(context.args, ClientLauncher.class.getName()); + context.args.add(ClientLauncher.class.getName()); ClientHookManager.clientLaunchFinallyHook.hook(context); // Print commandline debug message From 9456c45a3d7797e3dd10cef981f2292a94074f98 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Fri, 29 Nov 2019 18:20:02 +0100 Subject: [PATCH 089/192] =?UTF-8?q?[FIX]=20=D0=9D=D0=B5=D0=B1=D0=BE=D0=BB?= =?UTF-8?q?=D1=8C=D1=88=D0=B0=D1=8F=20=D1=87=D0=B8=D1=81=D1=82=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=BA=D0=BE=D0=B4=D0=B0=20ClientLauncher.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/pro/gravit/launcher/client/ClientLauncher.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index f39a5af1..4171e7ca 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -348,14 +348,14 @@ public static Process launch( // Add classpath and main class String pathLauncher = IOHelper.getCodeSource(ClientLauncher.class).toString(); context.pathLauncher = pathLauncher; - Collections.addAll(context.args, ClientLauncherWrapper.MAGIC_ARG); + context.args.add(ClientLauncherWrapper.MAGIC_ARG); Collections.addAll(context.args, profile.getJvmArgs()); profile.pushOptionalJvmArgs(context.args); - Collections.addAll(context.args, "-Djava.library.path=".concat(params.clientDir.resolve(NATIVES_DIR).toString())); // Add Native Path - Collections.addAll(context.args, "-javaagent:".concat(pathLauncher)); + context.args.add("-Djava.library.path=".concat(params.clientDir.resolve(NATIVES_DIR).toString())); // Add Native Path + context.args.add("-javaagent:".concat(pathLauncher)); ClientHookManager.clientLaunchHook.hook(context); LauncherGuardManager.guard.addCustomParams(context); - Collections.addAll(context.args, ClientLauncher.class.getName()); + context.args.add(ClientLauncher.class.getName()); ClientHookManager.clientLaunchFinallyHook.hook(context); // Print commandline debug message From fe0b4ccf040db1b535084370d28d2571c663b0dc Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Fri, 29 Nov 2019 18:31:36 +0100 Subject: [PATCH 090/192] =?UTF-8?q?[FIX]=20=D0=9A=D0=BE=D0=B3=D0=B4=D0=B0?= =?UTF-8?q?=20=D0=BF=D0=BE=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B5=20=D0=B2?= =?UTF-8?q?=20=D0=BF=D0=B0=D0=BF=D0=BA=D0=B5=20=D0=BC=D0=BE=D0=B4=D1=83?= =?UTF-8?q?=D0=BB=D0=B5=D0=B9=20=D0=BE=D0=BA=D0=B0=D0=B7=D1=8B=D0=B2=D0=B0?= =?UTF-8?q?=D0=B5=D1=82=D1=81=D1=8F=20=D0=B1=D0=B8=D0=B1=D0=BB=D0=B8=D0=BE?= =?UTF-8?q?=D1=82=D0=B5=D0=BA=D0=B0,=20=D0=BD=D0=B5=20=D0=B7=D0=B0=D1=81?= =?UTF-8?q?=D1=8B=D0=BF=D0=B0=D0=B5=D0=BC=20=D0=BA=D0=BE=D0=BD=D1=81=D0=BE?= =?UTF-8?q?=D0=BB=D1=8C=20NPE.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launcher/modules/impl/SimpleModuleManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java index 72d701fc..50766c4d 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java @@ -144,7 +144,7 @@ public LauncherModule loadModule(LauncherModule module) { @Override public LauncherModule loadModule(Path file) throws IOException { try (JarFile f = new JarFile(file.toFile())) { - String moduleClass = f.getManifest().getMainAttributes().getValue("Module-Main-Class"); + String moduleClass = f.getManifest() != null ? f.getManifest().getMainAttributes().getValue("Module-Main-Class") : null; if (moduleClass == null) { LogHelper.error("In module %s Module-Main-Class not found", file.toString()); return null; From ede1749f58172cb7bdbf73c2e4fe407ea9ce53e5 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Fri, 29 Nov 2019 18:38:45 +0100 Subject: [PATCH 091/192] =?UTF-8?q?[ANY]=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B8?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index 4a0419a5..143a6ca1 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 4a0419a5bfeb391fd694dd4a39483668a88262c3 +Subproject commit 143a6ca115cada25a942b0dacc83d59c76595421 From e081bf5a7688b1af86ce2de856af87ecb6421ec6 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 30 Nov 2019 02:41:27 +0700 Subject: [PATCH 092/192] =?UTF-8?q?[FEATURE]=20=D0=9F=D0=BE=D0=B4=D0=B4?= =?UTF-8?q?=D0=B5=D1=80=D0=B6=D0=BA=D0=B0=202FA=20=D0=B8=20=D0=BD=D0=B5?= =?UTF-8?q?=D0=BE=D0=B1=D1=8B=D1=87=D0=BD=D1=8B=D1=85=20=D1=81=D0=BF=D0=BE?= =?UTF-8?q?=D1=81=D0=BE=D0=B1=D0=B0=D1=85=20=D0=B0=D0=B2=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/provider/AuthProvider.java | 8 ++++++ .../auth/GetAvailabilityAuthResponse.java | 2 +- .../GetAvailabilityAuthRequestEvent.java | 25 ++++++++++++++++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AuthProvider.java index 03cd0462..019a1d75 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AuthProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AuthProvider.java @@ -1,5 +1,6 @@ package pro.gravit.launchserver.auth.provider; +import pro.gravit.launcher.events.request.GetAvailabilityAuthRequestEvent; import pro.gravit.launcher.request.auth.AuthRequest; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.auth.AuthException; @@ -12,6 +13,13 @@ public abstract class AuthProvider implements AutoCloseable { private static boolean registredProv = false; protected transient LaunchServer srv = null; + public GetAvailabilityAuthRequestEvent.AuthAvailability.AuthType getFirstAuthType() { + return GetAvailabilityAuthRequestEvent.AuthAvailability.AuthType.PASSWORD; + } + public GetAvailabilityAuthRequestEvent.AuthAvailability.AuthType getSecondAuthType() { + return GetAvailabilityAuthRequestEvent.AuthAvailability.AuthType.NONE; + } + public static AuthProviderResult authError(String message) throws AuthException { throw new AuthException(message); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/GetAvailabilityAuthResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/GetAvailabilityAuthResponse.java index 9ed8d242..79e63047 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/GetAvailabilityAuthResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/GetAvailabilityAuthResponse.java @@ -19,7 +19,7 @@ public String getType() { public void execute(ChannelHandlerContext ctx, Client client) { List list = new ArrayList<>(); for (AuthProviderPair pair : server.config.auth) { - list.add(new GetAvailabilityAuthRequestEvent.AuthAvailability(pair.name, pair.displayName)); + list.add(new GetAvailabilityAuthRequestEvent.AuthAvailability(pair.name, pair.displayName, pair.provider.getFirstAuthType(), pair.provider.getSecondAuthType())); } sendResult(new GetAvailabilityAuthRequestEvent(list)); } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetAvailabilityAuthRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetAvailabilityAuthRequestEvent.java index 28df28df..684d0485 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetAvailabilityAuthRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetAvailabilityAuthRequestEvent.java @@ -11,10 +11,33 @@ public static class AuthAvailability { public final String name; @LauncherNetworkAPI public final String displayName; + @LauncherNetworkAPI + public final AuthType firstType; + @LauncherNetworkAPI + public final AuthType secondType; - public AuthAvailability(String name, String displayName) { + public AuthAvailability(String name, String displayName, AuthType firstType, AuthType secondType) { this.name = name; this.displayName = displayName; + this.firstType = firstType; + this.secondType = secondType; + } + + + public enum AuthType + { + @LauncherNetworkAPI + PASSWORD, + @LauncherNetworkAPI + KEY, + @LauncherNetworkAPI + TOTP, + @LauncherNetworkAPI + OAUTH, + @LauncherNetworkAPI + NONE, + @LauncherNetworkAPI + OTHER } } From 977f8dfaecd66caeba8d7b24d058fdf94aab2c39 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 30 Nov 2019 02:50:26 +0700 Subject: [PATCH 093/192] =?UTF-8?q?[FEATURE]=20=D0=9C=D0=B0=D0=B3=D0=B8?= =?UTF-8?q?=D1=87=D0=B5=D1=81=D0=BA=D0=B8=D0=B9=20UUID=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=BE=D1=82=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20Req?= =?UTF-8?q?uestEvent=20=D0=B1=D0=B5=D0=B7=20=D0=B7=D0=B0=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D1=81=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/pro/gravit/launcher/events/RequestEvent.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/RequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/RequestEvent.java index f2d47803..e153a2a9 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/RequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/RequestEvent.java @@ -14,4 +14,6 @@ public abstract class RequestEvent implements WebSocketEvent { */ @LauncherNetworkAPI public UUID requestUUID; + + public static final UUID eventUUID = UUID.fromString("fac0e2bd-9820-4449-b191-1d7c9bf781be"); } From b93848055bed9629bfa318365adce95a51600534 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 30 Nov 2019 03:12:00 +0700 Subject: [PATCH 094/192] [FEATURE] connectUUID --- .../gravit/launchserver/command/service/ClientsCommand.java | 4 ++-- .../launchserver/socket/handlers/WebSocketFrameHandler.java | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/ClientsCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/ClientsCommand.java index b038aba5..80ed2ef3 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/ClientsCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/ClientsCommand.java @@ -31,9 +31,9 @@ public void invoke(String... args) { Client client = frameHandler.getClient(); String ip = IOHelper.getIP(channel.remoteAddress()); if (!client.isAuth) - LogHelper.info("Channel %s | checkSign %s", ip, client.checkSign ? "true" : "false"); + LogHelper.info("Channel %s | connectUUID %s | checkSign %s", ip, frameHandler.getConnectUUID(), client.checkSign ? "true" : "false"); else { - LogHelper.info("Client name %s | ip %s", client.username == null ? "null" : client.username, ip); + LogHelper.info("Client name %s | ip %s | connectUUID %s", client.username == null ? "null" : client.username, ip, frameHandler.getConnectUUID()); LogHelper.subInfo("Data: checkSign %s | isSecure %s | auth_id %s", client.checkSign ? "true" : "false", client.isSecure ? "true" : "false", client.auth_id); LogHelper.subInfo("Permissions: %s (long %d)", client.permissions == null ? "null" : client.permissions.toString(), client.permissions == null ? 0 : client.permissions.toLong()); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/WebSocketFrameHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/WebSocketFrameHandler.java index cb884138..be6f08df 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/WebSocketFrameHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/WebSocketFrameHandler.java @@ -11,6 +11,7 @@ import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; +import java.util.UUID; import java.util.concurrent.TimeUnit; public class WebSocketFrameHandler extends SimpleChannelInboundHandler { @@ -25,6 +26,7 @@ public WebSocketFrameHandler(NettyConnectContext context, LaunchServer srv, WebS } private Client client; + private final UUID connectUUID = UUID.randomUUID(); static { } @@ -37,6 +39,10 @@ public Client getClient() { return client; } + public final UUID getConnectUUID() { + return connectUUID; + } + @Override public void channelActive(ChannelHandlerContext ctx) { if (LogHelper.isDevEnabled()) { From 8c62cfff11e606fb341a48aaac9c24f091d6ea3e Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 30 Nov 2019 03:25:56 +0700 Subject: [PATCH 095/192] =?UTF-8?q?[FIX]=20=D0=94=D1=83=D0=B1=D0=BB=D0=B8?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D1=84=D1=83=D0=BD?= =?UTF-8?q?=D0=BA=D1=86=D0=B8=D0=B9=20Client.Type=20=D0=B8=20ConnectTypes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launchserver/manangers/SessionManager.java | 3 ++- .../src/main/java/pro/gravit/launchserver/socket/Client.java | 5 +++-- .../launchserver/socket/response/auth/AuthResponse.java | 1 + .../launchserver/socket/response/update/UpdateResponse.java | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/SessionManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/SessionManager.java index f4ba8a76..55b860f1 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/SessionManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/SessionManager.java @@ -2,6 +2,7 @@ import pro.gravit.launcher.NeedGarbageCollection; import pro.gravit.launchserver.socket.Client; +import pro.gravit.launchserver.socket.response.auth.AuthResponse; import java.util.HashMap; import java.util.HashSet; @@ -27,7 +28,7 @@ public void garbageCollection() { long time = System.currentTimeMillis(); clientSet.entrySet().removeIf(entry -> { Client c = entry.getValue(); - return (c.timestamp + SESSION_TIMEOUT < time) && ((c.type == Client.Type.USER) || ((c.type == Client.Type.SERVER) && GARBAGE_SERVER)); + return (c.timestamp + SESSION_TIMEOUT < time) && ((c.type == AuthResponse.ConnectTypes.CLIENT) || ((c.type == AuthResponse.ConnectTypes.SERVER) && GARBAGE_SERVER)); }); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/Client.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/Client.java index b368953c..a6ee1cd8 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/Client.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/Client.java @@ -4,13 +4,14 @@ import pro.gravit.launcher.profiles.ClientProfile; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.auth.AuthProviderPair; +import pro.gravit.launchserver.socket.response.auth.AuthResponse; import pro.gravit.utils.helper.LogHelper; public class Client { public long session; public String auth_id; public long timestamp; - public final Type type; + public AuthResponse.ConnectTypes type; public ClientProfile profile; public boolean isAuth; public boolean checkSign; @@ -25,7 +26,7 @@ public class Client { public Client(long session) { this.session = session; timestamp = System.currentTimeMillis(); - type = Type.USER; + type = null; isAuth = false; permissions = ClientPermissions.DEFAULT; username = ""; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java index f067795d..f50fc1fc 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java @@ -127,6 +127,7 @@ public void execute(ChannelHandlerContext ctx, Client clientData) throws Excepti LogHelper.debug("Auth: %s accessToken %s uuid: %s", login, result.accessToken, uuid.toString()); } } + clientData.type = authType; sendResult(result); } catch (AuthException | HWIDException | HookException e) { sendError(e.getMessage()); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/UpdateResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/UpdateResponse.java index 4eef9f11..9904f1d0 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/UpdateResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/UpdateResponse.java @@ -7,6 +7,7 @@ import pro.gravit.launchserver.config.LaunchServerConfig; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.SimpleResponse; +import pro.gravit.launchserver.socket.response.auth.AuthResponse; import pro.gravit.utils.helper.IOHelper; public class UpdateResponse extends SimpleResponse { @@ -19,7 +20,7 @@ public String getType() { @Override public void execute(ChannelHandlerContext ctx, Client client) { - if (!client.isAuth || client.type != Client.Type.USER || client.profile == null) { + if (!client.isAuth || client.type != AuthResponse.ConnectTypes.CLIENT || client.profile == null) { sendError("Access denied"); return; } From 773981c32fbee59039cde27e5ce269e112944020 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 30 Nov 2019 03:47:40 +0700 Subject: [PATCH 096/192] =?UTF-8?q?[FIX]=20=D0=92=D0=BE=D0=B7=D0=BC=D0=BE?= =?UTF-8?q?=D0=B6=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20=D0=BE=D1=82=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BA=D0=B8=20=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B9=20=D0=BF=D0=BE=20Channel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launchserver/socket/WebSocketService.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java index 42f820b2..e717dcb0 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java @@ -133,6 +133,14 @@ public void sendObject(ChannelHandlerContext ctx, Object obj, Type type) { ctx.writeAndFlush(new TextWebSocketFrame(gson.toJson(obj, type)), ctx.voidPromise()); } + public void sendObject(Channel channel, Object obj) { + channel.writeAndFlush(new TextWebSocketFrame(gson.toJson(obj, WebSocketEvent.class)), channel.voidPromise()); + } + + public void sendObject(Channel channel, Object obj, Type type) { + channel.writeAndFlush(new TextWebSocketFrame(gson.toJson(obj, type)), channel.voidPromise()); + } + public void sendObjectAll(Object obj) { for (Channel ch : channels) { ch.writeAndFlush(new TextWebSocketFrame(gson.toJson(obj, WebSocketEvent.class)), ch.voidPromise()); From cf63e96c1e6f43fbce3e22e84aacb7318bbd771c Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 30 Nov 2019 04:41:47 +0700 Subject: [PATCH 097/192] =?UTF-8?q?[ANY]=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index 143a6ca1..2b97b396 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 143a6ca115cada25a942b0dacc83d59c76595421 +Subproject commit 2b97b3967750625a89d28a243723a26af1114481 From 40bd92229a5f7769e4a54fdf99fd447aa4ef60ef Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 4 Dec 2019 22:25:17 +0700 Subject: [PATCH 098/192] =?UTF-8?q?[FEATURE][EXPERIMENTAL]=20=D0=9F=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B0=20CodeSign=20=D1=81=D0=B5?= =?UTF-8?q?=D1=80=D1=82=D0=B8=D1=84=D0=B8=D0=BA=D0=B0=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../utils/verify/LauncherTrustManager.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/LauncherCore/src/main/java/pro/gravit/utils/verify/LauncherTrustManager.java b/LauncherCore/src/main/java/pro/gravit/utils/verify/LauncherTrustManager.java index 8e4de504..b35fb07e 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/verify/LauncherTrustManager.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/verify/LauncherTrustManager.java @@ -9,10 +9,7 @@ import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; import java.security.SignatureException; -import java.security.cert.CertificateEncodingException; -import java.security.cert.CertificateException; -import java.security.cert.CertificateFactory; -import java.security.cert.X509Certificate; +import java.security.cert.*; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -87,4 +84,15 @@ public boolean isTrusted(X509Certificate certificate) throws CertificateEncoding public X509Certificate[] getTrusted() { return Arrays.copyOf(trustSigners, trustSigners.length); // AntiModify orig array!!! } + + public void isCertificateCodeSign(X509Certificate certificate) + { + if(!certificate.getKeyUsage()[0]) throw new SecurityException("Certificate keyUsage \"digitalSignature\" check failed"); + List extended; + try { + extended = certificate.getExtendedKeyUsage(); + } catch (CertificateParsingException e) { + throw new SecurityException(e); + } + } } From 94c19c9c5640994ee6777929304debeb692bf20b Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 4 Dec 2019 22:37:29 +0700 Subject: [PATCH 099/192] =?UTF-8?q?[FEATURE]=20=D0=A3=D0=B4=D0=B0=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=81=D1=82=D0=B0=D1=80=D0=BE=D0=B3?= =?UTF-8?q?=D0=BE=20runtime?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Launcher/runtime/README.txt | 2 + Launcher/runtime/config.js | 42 -- Launcher/runtime/dialog/dialog.js | 553 ------------------ Launcher/runtime/dialog/images/background.jpg | Bin 9847 -> 0 bytes .../dialog/images/downloader/blured.jpg | Bin 7155 -> 0 bytes .../runtime/dialog/images/downloader/line.png | Bin 1839 -> 0 bytes Launcher/runtime/dialog/images/icons/back.png | Bin 2130 -> 0 bytes .../runtime/dialog/images/icons/close.png | Bin 2181 -> 0 bytes .../runtime/dialog/images/icons/console.png | Bin 2247 -> 0 bytes .../runtime/dialog/images/icons/discord.png | Bin 2482 -> 0 bytes Launcher/runtime/dialog/images/icons/hide.png | Bin 2009 -> 0 bytes Launcher/runtime/dialog/images/icons/list.png | Bin 2417 -> 0 bytes Launcher/runtime/dialog/images/icons/logo.png | Bin 1481 -> 0 bytes .../runtime/dialog/images/icons/settings.png | Bin 2586 -> 0 bytes .../runtime/dialog/images/servers/example.png | Bin 29140 -> 0 bytes .../runtime/dialog/overlay/debug/debug.css | 57 -- .../runtime/dialog/overlay/debug/debug.fxml | 30 - .../runtime/dialog/overlay/debug/debug.js | 102 ---- .../dialog/overlay/processing/processing.css | 12 - .../dialog/overlay/processing/processing.fxml | 21 - .../dialog/overlay/processing/processing.js | 137 ----- .../dialog/overlay/settings/settings.css | 100 ---- .../dialog/overlay/settings/settings.fxml | 90 --- .../dialog/overlay/settings/settings.js | 255 -------- .../runtime/dialog/overlay/update/update.css | 54 -- .../runtime/dialog/overlay/update/update.fxml | 38 -- .../runtime/dialog/overlay/update/update.js | 98 ---- .../dialog/scenes/console/console.fxml | 63 -- .../runtime/dialog/scenes/console/console.js | 3 - .../runtime/dialog/scenes/login/login.fxml | 84 --- .../dialog/scenes/mainmenu/mainmenu.fxml | 162 ----- .../dialog/scenes/options/options.fxml | 81 --- .../runtime/dialog/scenes/options/options.js | 150 ----- Launcher/runtime/dialog/servers.css | 29 - Launcher/runtime/dialog/styles.css | 435 -------------- Launcher/runtime/engine/api.js | 92 --- Launcher/runtime/engine/settings.js | 22 - Launcher/runtime/favicon.ico | Bin 41661 -> 0 bytes Launcher/runtime/favicon.png | Bin 4829 -> 0 bytes Launcher/runtime/init.js | 103 ---- .../pro/gravit/launcher/LauncherEngine.java | 4 +- .../launcher/gui/JSRuntimeProvider.java | 163 ------ .../launcher/gui/NoRuntimeProvider.java | 20 + 43 files changed, 24 insertions(+), 2978 deletions(-) create mode 100644 Launcher/runtime/README.txt delete mode 100644 Launcher/runtime/config.js delete mode 100644 Launcher/runtime/dialog/dialog.js delete mode 100644 Launcher/runtime/dialog/images/background.jpg delete mode 100644 Launcher/runtime/dialog/images/downloader/blured.jpg delete mode 100644 Launcher/runtime/dialog/images/downloader/line.png delete mode 100644 Launcher/runtime/dialog/images/icons/back.png delete mode 100644 Launcher/runtime/dialog/images/icons/close.png delete mode 100644 Launcher/runtime/dialog/images/icons/console.png delete mode 100644 Launcher/runtime/dialog/images/icons/discord.png delete mode 100644 Launcher/runtime/dialog/images/icons/hide.png delete mode 100644 Launcher/runtime/dialog/images/icons/list.png delete mode 100644 Launcher/runtime/dialog/images/icons/logo.png delete mode 100644 Launcher/runtime/dialog/images/icons/settings.png delete mode 100644 Launcher/runtime/dialog/images/servers/example.png delete mode 100644 Launcher/runtime/dialog/overlay/debug/debug.css delete mode 100644 Launcher/runtime/dialog/overlay/debug/debug.fxml delete mode 100644 Launcher/runtime/dialog/overlay/debug/debug.js delete mode 100644 Launcher/runtime/dialog/overlay/processing/processing.css delete mode 100644 Launcher/runtime/dialog/overlay/processing/processing.fxml delete mode 100644 Launcher/runtime/dialog/overlay/processing/processing.js delete mode 100644 Launcher/runtime/dialog/overlay/settings/settings.css delete mode 100644 Launcher/runtime/dialog/overlay/settings/settings.fxml delete mode 100644 Launcher/runtime/dialog/overlay/settings/settings.js delete mode 100644 Launcher/runtime/dialog/overlay/update/update.css delete mode 100644 Launcher/runtime/dialog/overlay/update/update.fxml delete mode 100644 Launcher/runtime/dialog/overlay/update/update.js delete mode 100644 Launcher/runtime/dialog/scenes/console/console.fxml delete mode 100644 Launcher/runtime/dialog/scenes/console/console.js delete mode 100644 Launcher/runtime/dialog/scenes/login/login.fxml delete mode 100644 Launcher/runtime/dialog/scenes/mainmenu/mainmenu.fxml delete mode 100644 Launcher/runtime/dialog/scenes/options/options.fxml delete mode 100644 Launcher/runtime/dialog/scenes/options/options.js delete mode 100644 Launcher/runtime/dialog/servers.css delete mode 100644 Launcher/runtime/dialog/styles.css delete mode 100644 Launcher/runtime/engine/api.js delete mode 100644 Launcher/runtime/engine/settings.js delete mode 100644 Launcher/runtime/favicon.ico delete mode 100644 Launcher/runtime/favicon.png delete mode 100644 Launcher/runtime/init.js delete mode 100644 Launcher/src/main/java/pro/gravit/launcher/gui/JSRuntimeProvider.java create mode 100644 Launcher/src/main/java/pro/gravit/launcher/gui/NoRuntimeProvider.java diff --git a/Launcher/runtime/README.txt b/Launcher/runtime/README.txt new file mode 100644 index 00000000..735e7607 --- /dev/null +++ b/Launcher/runtime/README.txt @@ -0,0 +1,2 @@ +Скопируйте в эту папку файлы в соответствии с инструкцией по установке вашего модуля GUI +Старый рантайм на JavaScript больше не поддерживается \ No newline at end of file diff --git a/Launcher/runtime/config.js b/Launcher/runtime/config.js deleted file mode 100644 index 24865fa0..00000000 --- a/Launcher/runtime/config.js +++ /dev/null @@ -1,42 +0,0 @@ -var config = { - //*** Настройки лаунчера ***// - // Название папки лаунчера настраивается в LaunchServer.conf(строка projectName) - title: "GravitLauncher", // Заголовок окна - icons: ["favicon.png"], // Путь/Пути до иконки окна - - links: [ - //*** Ссылки ***// - { - id: "link", - text: "GravitLauncher", - url: "https://gravit.pro", - }, - - { - id: "discord", - text: "", - url: "https://discord.gg/aJK6nMN", - } - ], - - //*** Стандартные настройки клиента ***// - autoEnterDefault: false, // Автоматический вход на выбранный сервер - fullScreenDefault: false, // Клиент в полный экран - featureStoreDefault: true, // Поиск файлов в других клиентах (Используется для экономии трафика и ускорения загрузки) - ramDefault: 1024, // Количество оперативной памяти выделенной по умолчанию (0 - Автоматически) - - //*** Настройка загрузки JVM ***// - /* LaunchServer: guardtype = java */ - jvm: { - enable: false, // Включение загрузки своей JVM - jvmMustdie32Dir: "jre-8u231-win32", // Название папки JVM для Windows x32 - jvmMustdie64Dir: "jre-8u231-win64", // Название папки JVM для Windows x64 - }, - - settingsMagic: 0xC0DE5, // Магия вне хогвартса -}; - -DirBridge.defaultUpdatesDir = DirBridge.dir.resolve("updates"); -if (!IOHelper.isDir(DirBridge.defaultUpdatesDir)) { - java.nio.file.Files.createDirectory(DirBridge.defaultUpdatesDir); -} \ No newline at end of file diff --git a/Launcher/runtime/dialog/dialog.js b/Launcher/runtime/dialog/dialog.js deleted file mode 100644 index cb99d0a0..00000000 --- a/Launcher/runtime/dialog/dialog.js +++ /dev/null @@ -1,553 +0,0 @@ -var authPane, dimPane, serverPane, bar, consoleBar, optionsPane, consolePane, loginPaneLayout, serverPaneLayout; -var loginField, passwordField, savePasswordBox, authOptions; -var serverList, serverInfo, serverDescription, serverEntrance, serverLabel, serverStatus; -var profilesList = []; -var movePoint = null; -var pingers = {}; -var loginData; -var authTypes = {}; - -function initLauncher() { - initLoginScene(); - initMenuScene(); - initConsoleScene(); - initOptionsScene(); - - /* ======== init Overlays ======== */ - debug.initOverlay(); - processing.initOverlay(); - settingsOverlay.initOverlay(); - update.initOverlay(); - - verifyLauncher(); -} - -/* ======== init Login window======== */ -function initLoginScene() { - loginPane.setOnMousePressed(function(event) { movePoint = new javafx.geometry.Point2D(event.getSceneX(), event.getSceneY()) }); - loginPane.setOnMouseDragged(function(event) { - if (movePoint === null) { - return; - } - stage.setX(event.getScreenX() - movePoint.getX()); - stage.setY(event.getScreenY() - movePoint.getY()); - }); - - var pane = loginPane.lookup("#bar"); - bar = pane; - loginPane.lookup("#close").setOnAction(function(event) { javafx.application.Platform.exit() }); - loginPane.lookup("#hide").setOnAction(function(event) { stage.setIconified(true) }); - - var pane = loginPane.lookup("#authPane"); - authPane = pane; - - var loginLayout = loginPane.lookup("#layout"); - loginPaneLayout = loginLayout; - - loginField = pane.lookup("#login"); - loginField.setOnMouseMoved(function(event) { rootPane.fireEvent(event) }); - loginField.setOnAction(goAuth); - if (settings.login !== null) { - loginField.setText(settings.login); - } - - passwordField = pane.lookup("#password"); - passwordField.setOnMouseMoved(function(event) { rootPane.fireEvent(event) }); - passwordField.setOnAction(goAuth); - if (settings.rsaPassword !== null) { - passwordField.getStyleClass().add("hasSaved"); - passwordField.setPromptText("*** Сохранённый ***"); - } - - savePasswordBox = pane.lookup("#rememberchb"); - savePasswordBox.setSelected(settings.login === null || settings.rsaPassword !== null); - - authOptions = pane.lookup("#authOptions"); - - pane.lookup("#goAuth").setOnAction(goAuth); - - var pane = loginPane; - config.links.forEach(function(link) { - var el = pane.lookup("#link_" + link.id); - if (el === null) return; - - el.setOnAction(function() { - openURL(new java.net.URL(link.url)); - }); - - if (link.text === "") return; - - el.setText(link.text); - }); -} - -/* ======== init Menu window======== */ -function initMenuScene() { - menuPane.setOnMousePressed(function(event) { movePoint = new javafx.geometry.Point2D(event.getSceneX(), event.getSceneY()) }); - menuPane.setOnMouseDragged(function(event) { - if (movePoint === null) { - return; - } - - stage.setX(event.getScreenX() - movePoint.getX()); - stage.setY(event.getScreenY() - movePoint.getY()); - }); - - var pane = menuPane.lookup("#bar"); - bar = pane; - pane.lookup("#close").setOnAction(function(event) { javafx.application.Platform.exit() }); - pane.lookup("#hide").setOnAction(function(event) { stage.setIconified(true) }); - pane.lookup("#settings").setOnAction(goSettings); - pane.lookup("#goConsole").setOnAction(goConsole); - - var pane = menuPane.lookup("#serverPane"); - serverPane = pane; - - var menuLayout = menuPane.lookup("#layout"); - serverPaneLayout = menuLayout; - - pane.lookup("#clientSettings").setOnAction(goOptions); - serverList = pane.lookup("#serverlist").getContent(); - serverInfo = pane.lookup("#serverinfo").getContent(); - serverDescription = serverInfo.lookup("#serverDescription"); - serverEntrance = pane.lookup("#serverentrance"); - serverStatus = serverEntrance.lookup("#serverStatus"); - serverLabel = serverEntrance.lookup("#serverLabel"); - serverEntrance.lookup("#clientLaunch").setOnAction(function() { - doUpdate(profilesList[serverHolder.old], loginData.pp, loginData.accessToken); - }); - pane.lookup("#logout").setOnAction(function() { - setCurrentScene(loginScene); - }); - - var pane = menuPane; - config.links.forEach(function(link) { - var el = pane.lookup("#link_" + link.id); - if (el === null) return; - - el.setOnAction(function() { - openURL(new java.net.URL(link.url)); - }); - - if (link.text === "") return; - - el.setText(link.text); - }); -} - -/* ======== init Console window======== */ -function initConsoleScene() { - consoleMenu.setOnMousePressed(function(event) { movePoint = new javafx.geometry.Point2D(event.getSceneX(), event.getSceneY()) }); - consoleMenu.setOnMouseDragged(function(event) { - if (movePoint === null) { - return; - } - - consoleStage.setX(event.getScreenX() - movePoint.getX()); - consoleStage.setY(event.getScreenY() - movePoint.getY()); - }); - - var pane = consoleMenu.lookup("#bar"); - consoleBar = pane; - pane.lookup("#close").setOnAction(function() { - consoleStage.hide(); - }); - var text = consoleMenu.lookup("#textField"); - var output = consoleMenu.lookup("#output"); - var appendFunction = function(line) javafx.application.Platform.runLater(function() output.appendText(line)); - consoleMenu.lookup("#send").setOnAction(function() { - execCommand(text.getText()); - if (text.getText() == "clear") { - output.setText(""); - } - text.setText(""); - }); - FunctionalBridge.addPlainOutput(function(string) { - appendFunction(string + "\n"); - }) - pane.lookup("#hide").setOnAction(function(event) { consoleStage.setIconified(true) }); - - var pane = consoleMenu.lookup("#consolePane"); - consolePane = pane; - -} - -/* ======== init Options window======== */ -function initOptionsScene() { - optionsMenu.setOnMousePressed(function(event) { movePoint = new javafx.geometry.Point2D(event.getSceneX(), event.getSceneY()) }); - optionsMenu.setOnMouseDragged(function(event) { - if (movePoint === null) { - return; - } - - stage.setX(event.getScreenX() - movePoint.getX()); - stage.setY(event.getScreenY() - movePoint.getY()); - }); - - var pane = optionsMenu.lookup("#bar"); - bar = pane; - pane.lookup("#close").setOnAction(function(event) { javafx.application.Platform.exit() }); - pane.lookup("#hide").setOnAction(function(event) { stage.setIconified(true) }); - pane.lookup("#back").setOnAction(function() { - setCurrentScene(menuScene); - }); -} - -/* ======== init Offline ======== */ -function initOffline() { - stage.setTitle(config.title + " [Offline]"); - - loginField.setPromptText("Имя пользователя"); - if (!VerifyHelper.isValidUsername(settings.login)) { - loginField.setText(""); // Reset if not valid - } - - passwordField.setDisable(true); - passwordField.setPromptText("Недоступно"); - passwordField.setText(""); -} - -/* ======== Auth ======== */ -function goAuth(event) { - if (overlay.current !== null) { - return; - } - - var login = loginField.getText(); - if (login.isEmpty()) { - return; - } - - var auth = authOptions.getSelectionModel().getSelectedItem(); - if (auth === null) { - return; // No auth selected - } - - var rsaPassword = null; - var auth = authOptions.getSelectionModel().getSelectedItem(); - if (auth === null) { - return; - } - if (!passwordField.isDisable()) { - var password = passwordField.getText(); - if (password !== null && !password.isEmpty()) { - rsaPassword = settingsOverlay.setPassword(password); - } else if (settings.rsaPassword !== null) { - rsaPassword = settings.rsaPassword; - } else { - return; - } - - settings.rsaPassword = savePasswordBox.isSelected() ? rsaPassword : null; - } - - settings.login = login; - doAuth(login, rsaPassword, authTypes[auth]); -} - -/* ======== Console ======== */ -function goConsole(event) { - setConsoleCurrentScene(consoleScene); -} - -/* ======== Settings ======== */ -function goSettings(event) { - if (overlay.current !== null) { - return; - } - - overlay.show(settingsOverlay.overlay, null); -} - -/* ======== Options ======== */ -function goOptions(event) { - setCurrentScene(optionsScene); - - options.update(); -} - -/* ======== Processing functions ======== */ -function verifyLauncher(e) { - processing.resetOverlay(); - overlay.show(processing.overlay, function(event) makeLauncherRequest(function(result) { - settings.lastDigest = result.digest; - processing.resetOverlay(); - if (settings.offline) { - initOffline(); - } - overlay.swap(0, processing.overlay, function(event) makeAuthAvailabilityRequest(function(result) { - var iter = 0; - authTypes = {}; - result.list.forEach(function(auth_type, i, arr) { - var serverAuth = new javafx.scene.control.ComboBox(); - serverAuth.getStyleClass().add("authOptions"); - authOptions.getItems().add(auth_type.displayName); - authTypes[auth_type.displayName] = auth_type.name; - iter++; - }); - authOptions.getSelectionModel().select(0); - var sm = authOptions.getSelectionModel().selectedIndexProperty(); - sm.addListener(new javafx.beans.value.ChangeListener({ - changed: function(observableValue, oldSelection, newSelection) { - settings.auth = authTypes[authOptions.getSelectionModel().getSelectedItem()]; - } - })); - overlay.swap(0, processing.overlay, function(event) makeProfilesRequest(function(result) { - settings.lastProfiles = result.profiles; - updateProfilesList(result.profiles); - options.load(); - overlay.hide(0, function() { - if (cliParams.autoLogin) { - goAuth(null); - } - }); - })); - })); - })); -} - -function doAuth(login, rsaPassword, auth_type) { - processing.resetOverlay(); - overlay.show(processing.overlay, function(event) { - FunctionalBridge.getHWID.join(); - makeAuthRequest(login, rsaPassword, auth_type, function(result) { - FunctionalBridge.setAuthParams(result); - loginData = { - pp: result.playerProfile, - accessToken: result.accessToken, - permissions: result.permissions, - auth_type: settings.auth - }; - - overlay.hide(0, function() { - setCurrentScene(menuScene); - }); - return result; - }) - }); -} - -function doUpdate(profile, pp, accessToken) { - var digest = profile.isUpdateFastCheck(); - overlay.swap(0, update.overlay, function(event) { - if (config.jvm.enable) { - makeSetProfileRequest(profile, function() { - ClientLauncher.setProfile(profile); - var jvmDir = settings.updatesDir.resolve(jvmDirName); - update.resetOverlay("Обновление файлов JVM"); - makeUpdateRequest(jvmDirName, jvmDir, null, digest, function(jvmHDir) { - ClientLauncher.setJavaBinPath(jvmDir); - update.resetOverlay("Обновление файлов ресурсов"); - var assetDirName = profile.getAssetDir(); - var assetDir = settings.updatesDir.resolve(assetDirName); - var assetMatcher = profile.getAssetUpdateMatcher(); - makeUpdateRequest(assetDirName, assetDir, assetMatcher, digest, function(assetHDir) { - settings.putHDir(assetDirName, assetDir, assetHDir.hdir); - update.resetOverlay("Обновление файлов клиента"); - var clientDirName = profile.getDir(); - var clientDir = settings.updatesDir.resolve(clientDirName); - var clientMatcher = profile.getClientUpdateMatcher(); - makeUpdateRequest(clientDirName, clientDir, clientMatcher, digest, function(clientHDir) { - settings.putHDir(clientDirName, clientDir, clientHDir.hdir); - doLaunchClient(assetDir, assetHDir.hdir, clientDir, clientHDir.hdir, profile, pp, accessToken); - }); - }); - }); - }); - } else { - update.resetOverlay("Обновление файлов ресурсов"); - var assetDirName = profile.getAssetDir(); - var assetDir = settings.updatesDir.resolve(assetDirName); - var assetMatcher = profile.getAssetUpdateMatcher(); - makeSetProfileRequest(profile, function() { - ClientLauncher.setProfile(profile); - makeUpdateRequest(assetDirName, assetDir, assetMatcher, digest, function(assetHDir) { - settings.putHDir(assetDirName, assetDir, assetHDir.hdir); - - update.resetOverlay("Обновление файлов клиента"); - var clientDirName = profile.getDir(); - var clientDir = settings.updatesDir.resolve(clientDirName); - var clientMatcher = profile.getClientUpdateMatcher(); - makeUpdateRequest(clientDirName, clientDir, clientMatcher, digest, function(clientHDir) { - settings.putHDir(clientDirName, clientDir, clientHDir.hdir); - doLaunchClient(assetDir, assetHDir.hdir, clientDir, clientHDir.hdir, profile, pp, accessToken); - }); - }); - }); - } - }); -} - -function doLaunchClient(assetDir, assetHDir, clientDir, clientHDir, profile, pp, accessToken) { - processing.resetOverlay(); - overlay.swap(0, processing.overlay, function(event) launchClient(assetHDir, clientHDir, profile, new ClientLauncherParams(settings.lastDigest, - assetDir, clientDir, pp, accessToken, settings.autoEnter, settings.fullScreen, settings.ram, 0, 0), doDebugClient)); -} - -function doDebugClient(process) { - if (!settings.debug) { - javafx.application.Platform.exit(); - return; - } - - debug.resetOverlay(); - overlay.swap(0, debug.overlay, function(event) debugProcess(process)); -} - -/* ======== Server handler functions ======== */ -function updateProfilesList(profiles) { - profilesList = []; - serverList.getChildren().clear(); - var index = 0; - profiles.forEach(function(profile, i, arr) { - pingers[profile] = new ServerPinger(profile); - - var serverBtn = new javafx.scene.control.ToggleButton(profile); - - serverBtn.getStyleClass().add("server-button"); - serverBtn.getStyleClass().add("server-button-" + profile); - - (function() { - profilesList[serverBtn] = profile; - var hold = serverBtn; - var hIndex = index; - serverBtn.setOnAction(function(event) { - serverHolder.set(hold); - settings.profile = hIndex; - }); - })(); - - serverList.getChildren().add(serverBtn); - if (profile.getOptional() != null) profile.updateOptionalGraph(); - index++; - }); - LogHelper.debug("Load selected %d profile", settings.profile); - if (profiles.length > 0) { - if (settings.profile >= profiles.length) - settings.profile = profiles.length - 1; - serverHolder.set(serverList.getChildren().get(settings.profile)); - } -} - -function pingServer(btn) { - var profile = profilesList[btn]; - setServerStatus("..."); - var task = newTask(function() pingers[profile].ping()); - task.setOnSucceeded(function(event) { - var result = task.getValue(); - if (btn == serverHolder.old) { - setServerStatus(java.lang.String.format("%d из %d", result.onlinePlayers, result.maxPlayers)); - } - }); - task.setOnFailed(function(event) { if (btn == serverHolder.old) { setServerStatus("Недоступен") } }); - startTask(task); -} - -function setServerStatus(description) { - serverStatus.setText(description); -} - -/* ======== Overlay helper functions ======== */ -function fade(region, delay, from, to, onFinished) { - var transition = new javafx.animation.FadeTransition(javafx.util.Duration.millis(100), region); - if (onFinished !== null) { - transition.setOnFinished(onFinished); - } - - transition.setDelay(javafx.util.Duration.millis(delay)); - transition.setFromValue(from); - transition.setToValue(to); - transition.play(); -} - -var overlay = { - current: null, - - show: function(newOverlay, onFinished) { - authPane.setDisable(true); - overlay.current = newOverlay; - - dimPane.setVisible(true); - dimPane.toFront(); - loginPaneLayout.setEffect(new javafx.scene.effect.GaussianBlur(10)); - serverPaneLayout.setEffect(new javafx.scene.effect.GaussianBlur(10)); - fade(dimPane, 0.0, 0.0, 1.0, function(event) { - dimPane.requestFocus(); - dimPane.getChildren().add(newOverlay); - - newOverlay.setLayoutX((dimPane.getPrefWidth() - newOverlay.getPrefWidth()) / 2.0); - newOverlay.setLayoutY((dimPane.getPrefHeight() - newOverlay.getPrefHeight()) / 2.0); - - fade(newOverlay, 0.0, 0.0, 1.0, onFinished); - }); - }, - - hide: function(delay, onFinished) { - fade(overlay.current, delay, 1.0, 0.0, function(event) { - dimPane.getChildren().remove(overlay.current); - fade(dimPane, 0.0, 1.0, 0.0, function(event) { - dimPane.setVisible(false); - - authPane.setDisable(false); - rootPane.requestFocus(); - loginPaneLayout.setEffect(new javafx.scene.effect.GaussianBlur(0)); - serverPaneLayout.setEffect(new javafx.scene.effect.GaussianBlur(0)); - overlay.current = null; - if (onFinished !== null) { - onFinished(); - } - }); - }); - }, - - swap: function(delay, newOverlay, onFinished) { - dimPane.toFront(); - fade(overlay.current, delay, 1.0, 0.0, function(event) { - dimPane.requestFocus(); - - if (overlay.current == null) { - overlay.show(newOverlay, onFinished); - return; - } - - if (overlay.current !== newOverlay) { - var child = dimPane.getChildren(); - child.set(child.indexOf(overlay.current), newOverlay); - } - - newOverlay.setLayoutX((dimPane.getPrefWidth() - newOverlay.getPrefWidth()) / 2.0); - newOverlay.setLayoutY((dimPane.getPrefHeight() - newOverlay.getPrefHeight()) / 2.0); - - overlay.current = newOverlay; - fade(newOverlay, 0.0, 0.0, 1.0, onFinished); - }); - } -}; - -var serverHolder = { - old: null, - - set: function(btn) { - pingServer(btn); - serverLabel.setText(profilesList[btn]); - serverDescription.setText(profilesList[btn].info); - btn.setSelected(true); - btn.setDisable(true); - if (serverHolder.old != null) { - serverHolder.old.setSelected(false); - serverHolder.old.setDisable(false); - } - serverHolder.old = btn; - } -}; - -/* ======== Overlays scripts ======== */ -launcher.loadScript("engine/settings.js"); -launcher.loadScript("dialog/overlay/debug/debug.js"); -launcher.loadScript("dialog/overlay/processing/processing.js"); -launcher.loadScript("dialog/overlay/settings/settings.js"); -launcher.loadScript("dialog/overlay/update/update.js"); - -/* ======== Scenes scripts ======== */ -launcher.loadScript("dialog/scenes/options/options.js"); -launcher.loadScript("dialog/scenes/console/console.js"); \ No newline at end of file diff --git a/Launcher/runtime/dialog/images/background.jpg b/Launcher/runtime/dialog/images/background.jpg deleted file mode 100644 index bbd3866c0464bc9625020d97dfc9fbf688c94b33..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 9847 zcmbVyc_38n`}di#D?~$tr9q5EI5$dQy}n zq(YQ1hNs0+ma(-wg+$8lK7)FG-}n2+`@W;woVo9Fu5*2^>vMhXGnW=#F1&?S*$}OX z5CVaKT)_{t@D8FAPSLy}$le~>06~x_B!W#J)jqfHFWOt%^uUvtr_MYvdIaHMO+Sm5FPn%mfo!qYOzhAz3{cd1zXqY!LIyV0K%jDGb*O_m#b1*Ih zB(MnU7qb7rB@J*P1qB5JMPOVAWH1;4(t<+k^o3uhQ>$se+TUB{}-}fz<%R;4XqSFfaD2CL*~%?LUvBt6LwB&qzs*c zhH~f>$Oc1YA?X+zluYixixD=V{@X!vnIn>9OV9&X+3>Fr%wy-kHf#hnQDsgD3@{>? zlbXbzf^2MpH1%YXQt5)4nwwA$;g66eiUeEN)L*;>Y>@0!go#Wha~#!{jG+gMIyisTVop)~I9=2r;dgp&D` z1{Pop65!-C{xqC%IQnqLt?}oUDg7^x38+PY7W_yrvKr<%1&%fV2}sKi5S0Xo;08w% z=HdTI2$&R$ga$54$Z!KMI6nB-N@rp0CpPAGm7-z2gpD0XDNPg zrT+E=*k96tWyf?*fBMJ0JPGwm_I4 z!Z}*?Z}J05EGyR%@1oWeQFHE~VGm&z$}Oju{|>mqk1rhKrLk;HV41Vxure&l$|4#5 zlf26=0SWu>?k+KLNs0eeugmP`3p$#$f=eQJ>Qey#4E0~iL|G)I1;5My6SUAvlK;Oc z3MjrzdVWGRA%1nk$%2UhVA#NMUe+|2&r4guZ!#<;JnvTpU?P{}0VEbo(}_W(RM+k0 zt9y6lemXpgIp17Z9D62un{&1e=F6Rs#8RNTm)&fwZI?C%ut6-Tgc{5ffGcfz0&sCr zh46d{1AeYtF1f|BgA@7Naac3{O^`+LApP137dHr)sc?RPE-n`y~lZHlvFwBJ~ z=c2d+*OSJvP;_-xmko`wxB2Z!S!p95Enlzvnxpf@`kx$Yp5K!EBl@NDf&A%W>s3Py zJ=Q}!1{0lcpmC`6lkOakmxIw*IVi$g~mJQg=8$)Q*?YS7y_A?B2S(30td>e5(sdnKVq2mV~BB zG+shLn~CWyWF2+@nR6+?FV{lZvgVW}mx;nYQz$kR*MBRKCW;KBBJ;}*oFNQ2m%J#n z{HGXLjzHEHNwla6((Z$w-5@*IcES?z4)6dKHC(IGp|YFlf%yG%?65p&6|qmK^nX#+8*+mR$9nkC6h zO``KmmZ3mw*l`#in1(2rMUX()Gy$%3{#L?=?ncmDmN~GZiAqO7Wn>u)P8J7^?|0+OA3nL}F$h9g|q>Wq9pEoxMR~o++kIKNl z*I|@5|NO9{bE}}Qaba^lV~@Kp=4hvNUY=IEn!Tn%UcTCd6%7bI*^!31L@`&~4Qe(* z+y>2y60^0Uj`XD=c;IHRA|p5-QJ&5R*sX!eg6Syl+*YMRq)P`gK1hKjW=N!^=VB3B z)K<%?tJuhJYO5jEJ5rTtXy2;967jx@ecr)zHOD5Wvr$k5mi#pjD+(^j<9J8Kw`$QU zbFt9-4yG^7&`N|C(`iT?hy1ZU9Jzd6q;eG_2+Q=PB4+b??X(!!hvDNm=a8A)?NbP? zNy~J4409(PN^WM_&vP{f7(sH#m&XZ84f~v$gs)YlHQ%S>#4iQ`KaUMCP89}|sv@=e z(0v=$a(r20_vt&;RLUi(T31AqTg)Vkh6jfyNW6qEn8>*Iy@Xx%rk{J9q`2WHo-{HV z^hP*Y;WZMR{ESL7lZl`strnz5@R$C}|82nJsO^06h z+E!ifCyw(>ZrWGHc1eyO!Pf* zPts)&kL$g}aoue);37g5BWw*Y!7ATb%luM&%N~4CXmlvYwaK>`WgQkM%ERdlA8URQ zxc@tG+nR6=;)C6hJKMr^jCdm@de2fOY_FYCR+4ynVzM;$KAbOwO@w(z8Vhd$~>{UzFq8 zB5IT-7-4@BPcT}0Zx36j)Rv!Ya%BFIqhjBpS7f&rH`7s7_^M6gUTL!~ zPOnYnTAfXH$ds&`dl)yPSb2oQ2$^E-)$X;fW?qaaR~kEi`Mx9NdjE7@|1@i(En{Mi z>^b){MP&gB-SKUV>3(}M!Psa;QYiD}+ub3mu|{pmVsna~WklM8&V!MvL6I|s&r^08 z996Vayx5xCTHtPdo2KWpc}x73G?}*@(WH>FkTQg>guKz3bjx)7<&c8trWy+#i6=#Y zva#N*Ns*GxY3SRly<@oBy;QuATCG|>n+;;89$v*d|1rvv*wi;wT{B*n7DhYs_=C&E zpvyC-IUi?=zqhg2ePQSot3S@<2G{I-@ICy5-}cS4#W8U*{7ya*Dr+9|EinVy_XlY zzx^Wfb~!~dg+|MfFY7LFq7){THOcNTZL`S=bbeJi;YhuV%eDdkt_0U8py;LAX*AQv zq*N8)!^YaW6205JYk2j5kIHwQ^QxY@I(*}6PneJT z<{D?(?$FLNE!LvUQcli1ZpKVobo z9Uwu*TXCGuJZE0cz&_$~kj-8?eN0dJMh7F|pP2K-@7G(N$--0~Jz=EaOM7$oZ_X9b zle|~={kFb1-Pui4J(YF3D`3QoR_oSi5MgqL74)@=ofxYwIaVg5;yN|6cF$ksZ-OQV z7oggSOV$o{@h!+OjcUJ(#6Gii@}1H!BKU_a#HARXZ(g!}*dgJ*i>| z&VkI*2Xpj0M;&;I4%j(oq)W`%ywi$@^yb7}ZM<56M}-eM0dsDeHYZptK#G@qMRLMI z$?3-VAEzMIKkfCg64iyy+BLg&)kc4jRXeHr$lSzIsZwVFicj1PtNnN4{b?XW7;3OAv=SB#0C6JKGT=7CM}HG*WYLKBvh~;$ClroU9z)c0Xo&e z_%VoIJve5mlEYenqDavb_-9IypDfeL4`oyS45J~;nYGCwH%5IV!-@jJ3Xu^;VPj{y zri~8ye+5N=ftT~+v8TC8qy2a}(|!*JYlF}|hYYT*%{Efoa_j}+k3Un0U0;L_IyE@k z?H@mKqQFU&?IcYctC=uM8!0(hZIs#C>U~7|6*fJ8i0nU3OWwAf>-!b;T_zy&Iz6?Sn{r3PbiyspxnB%KJk(aWS(NmCw!zII!nb|K()~m7-278Xn$*?4?L8~ozwGia6&8IF!M4V%p_&E?m#(&U#uMfQoNo zTMj2-F74hO6c0Rc88cWLsjRu0GS4&sCe7xsgB2I%ymHNT9;MUlw<} zvywwOSl*U)=2~%qc+Nh{)a8@~uz6gG)xNI#!QYuaIZ$D##LR zHE=(0vPi)!BY_r|Q29)v=|_%F=Dqj(XK78}xg8r*p4@1B8sAC3^$7p+b%a2oyGU4GDF zTJQJ~>)9^&({-BNC&k{^oHx?$D0FS`HNAu}M$lJYlWAUUI}&l%PACi$P@B>iDlp&g zgBvNw#oHKuz)Lk_1MOOM?bpT6*3k6&%6iHb{3y`Lzo*$R`}^{}>S`>vmqms*{+w2l znklMtBJS&sRK5))>Z;#&=hkNvR{KMl5Ca@fy{qa97)bHtB`Dpqe^`Qgp|igJa-+^3 z`N70pcAmC&;mOrC#R}|4U0bZPPkn3kHZ3sn{u*xYT{h2Er!r>CLUL||JYuxU?nRgL zq-;#Pifes3c$?&q^@&!6hkpD~Y*U{GiH)GL+&g#$Y&q%V6O~p2go(b)6F2{0RHTQA z*xcDOxz4b(cgDZ5-zPL>3lF2DcB^M5=gF(JlgN?_Z{y0&oni6*x|d4Xab~#wYyOrb z%ic8A!UFe=Ep97x_c6wPhNqadCMPtEAQcQObUH#B_Q%^jJlL6FX};Mbt4r?sia&}r zyl*dU7M!_0x=mJ{A!IQTZ+HByUn# zc50dn=Z{MLvjSn3TFL!-KV_%px)3JQ>IF60S(!3Y6~b56^^|Mm>N9v=ZH||A>+&lRQgoutI$h(~OQTk@NEeK; z-_`c%BJvK&JyF|pOAxHO!^e9pwTH=~{Y7yOPkC8a?=(W@#xq3{3y`t2z&CFBkdgZl zo%Ca!)N?7?+5wqAgV;jv1Hwj?%~y7B$|NJqF z^p~!;)q5@SHwlj@2NK^0=Xr1Hs$*kgG8q=?Guadz)7xycsYXv@(rmP_kY%~Eu8+|= zQy5Kmd{h}X;9wGO+8Itcl$y{K#^TJ5aMHhUhN+0YK=SNgb}e%pKT=loVWHLr_GK&L#3xl;64zu1fWwP5!} z|KefA5_R_-j~GFgWt^ki%N{b0=N>P-r%KtvbhS>I&U-pt_z$%KsrfW-Ah$m6br==t zLdQu_t{e&F9P@E?NSQA5-C4GaFr4l9HX&kzZ>M$i1R=8iL7dgdOuKOWw382&hW z2QPGL@bBr8ZKu>vJFBftZgi*+m=#B?XV<20{QRk}DC@Z-&7;#6`jc#6HS4h{MrHcu z%@)>SV`clzX_fpbr{Q+b91 z+9|fC<@Q^$%PR+}?E(ZDOG+Ak+f$+b;7z%FLuoT~5&9`Vwl7FYKS+%6+;uc_!<6<| z_t}!`ZL@b&ZaQ?wZ?XI5!#BnDW9uzYUWWqf{`sJWh(GkXi9+D`;v!Fe805*1O|dcz zl8<29%5l}IHvXwr8J>j(HJ5m0N|p(b+;O7AQIGbnBe4bpT95up)6XmsxVuyCgzvYx z&igmkek4sBk#d3@pU0r4z_UYUyAD&u{X^qFVR4vzg8bvnD$`cT-P^d2I71Q7#4P8b z_HC);(I>Cs?DM`H_jw*#y&?9^p^5rJM;|IA`s8$>QGxG)gphwk+wcJpfRVN`eoy&P zkz*G}t=JV+<;;y6J8)+5nc*p}jk(_4qn)&vr!>p-O2-Wg zP%vYToAmU8UE~_GyL#;GOQMy|OYp9P_y~dJnEMWj3ci zFt_tova4^yu_pf}m%lY#-`-Xbm^dg~`yn^sh)C{wtEw3{g4dz(jffR{hqe9Iml_Ex zn37JHYLJ;jcV&Dwo8$yC?3zoGup2{i;`J0us$#kOb@%swB7z5tzZgV&xfP7rv+;U+ z0_?Tyw}}tO8_`zg+!*3`UpqVWlbUBBMLByFwSS-Hq}iBhOS~KV6<%_4f&~=)y7&iE zb*qWZ@H_Rnz<;-zIBWphr_`zeof1)nAC^i}_Re!A%06a90733|fdi3I)S$LI>l zJ~PmT^Gmf1wa-tJ>b1`H@x|!lFY;otDTlG1bB+SD)49UwRmnzr%F&isUu^X#BveBS zpyBBD6L=}XIda@-=hICkND%o>zi;z6J5#`ukZ7LSSQyy{~0oc3K`^F zJAWM`VZZIX;fq6*L)eJW$TiyCu}$6adZ!ibpN-iOi8oeUoQ&(u8;mQMI56Z-nXA&V zc;LCpvV9tS<7@t@ctOkFYb4}x^QL;CNVB^=!6ozEvQfxU4L)AcoP1??4hY{ zhwtNbe|ZIk?OexouRvVhi|gsA`&Y+m*_+diS;C$jt>(xWM}e*E`T|!{gMbp>$f@QOr#DfeNBztU6p*c6aGL5DwFP)w&9+=!uE3Z+2Lygv5$&BZZE5jm0OVt z8jI0kV9Q&h*@y1gu!);dxPn27a`el6jumSDmcyEqP-@*K1imZg^=(k*`m*+E^%LhV zV$)f=4i#kILIY|K?WL|mEhEgLg5#U>sPgb}u%{J&FYLv;q-BTNPs@$la~lH4j~MFR zxjh&|{KcWUjtBI3Y;{rOC(wiGq1y;<^UrGrJ$umnL=Qx+!Fngr-TA+vU~Hf@(-6Oc zL8ReGOvvSXXS6ECm$23mvHoWB9gCEkv+orS=}VVojmVcsHO6p!-deccA>O*9=Hej; ziGj3MR?Klv*A(_(qO>M$d6EOUPuVPyPm~oHdDHk%FD*=Dtl#Prf?*Q4_cwkFI`FP) zMIBhB6uk3X!r@M1tn=*F7iiXARk-J9uV9p3-W*J-&1prQ9m?|3PPfZNK|gqmARNk3 zV3J5HV<`&jQd{N0Ea=?!p`WruI_yAKNPMRTsnz8?;)64XAYAhJ#Ff|i`;dq4lTG$) zb$jhI^JcKgro^np+~!h`_%8RPtQTVWLwi}8nz}SYI}1y!_to{0tC^TU&_LBE!f#N6 zd>-gABm4%~S30kB9=RH}0J{6TY2eyb z=~(ZWc7on&tS4s`Z7WN}v!kLjfCf_Xk=?Vw1dX)kf(EuizQCk4XfC%Rl`FtHl_dfi zp$2hO#P`BhLnZ~}q;h>a)1_VDen)MFZG)cj1M-ELd{?r2q-Gy2m}}a>z`JChV)vN& z)Q%hCUG64M5cam!poE%BVE{)A9UF8pI8s%@3c4Pqy08z8m?tHYKILC!>Dq#}_AUxT zE3#5|4)BKBiU`;-b$%=z{0D~bW4KPxga1Bu<}r!v9a)KEhJjYt1PS0-qd6&|;#PQ< zNR@4V(1PP`&BaO%y&3Iy^p53<5B>DooW5t0NWJY+$|HxQ2veH@Z)+J5H9HwZ>WZX~ z;5ivI;vWspa6T1I5|A2z+i`S=0lLSg9ZV>k+G_{*>OZmjNgZ}#!5vk({DyvWzAw8M zF9~Axk=+UbJ?LQK9M|bl8@2^0pr9V|z*Urcq|&_@r$UzSK#XDp%HK|y+*tv*kxT-A qApr-;=`0cV7^gtc)psEg$8nAbBFzw_w{BN5FMj8defHV= zU;p~o+G`)5-+BHW=9b9eaxfB!gl&R<*z@l(1$(b72gCS$Y$=9ev#^;YU(6BiNN{A5 z{HE^ZBnIX{w3FdsI0k3T4UU}xH=-{LiD3eFj6(E5_Z~0q;V1gr1PAIyTz71i^8@Bj)%LO=X{3md~fgh;frYt87m`K$GjG~BAS(u zv4OQNjUBxrd7B{Z?aX(i@2ug!Td*U0Z^o8)vd|zTcMp&GUh|jv`Yy|gTM?J_fBt*k zg}KinRglviNC6nxo#fz7dftP*3fLWiIYgfQk3@E$IL??k%gNaVI<&iCWRimend0E+ zNC6s1MerP>xI23IhsVzF6l|Uu@Gdo?dAPgK{a)b*MMZKF=#biTE%{j&=fJ370s_Vix6{^gCEMw8hx@aH>U-~ImnUmpB* z_`gOTT7UX^Y<%LECx8F-DYA=%IoQmavg}{%atFJ}6p907CbEk}-UEk&JH^pIe1=D? zVCLp`Jp&?2W>Mpgooe~QX>p|RZ(f-@`<=Z5@$YFrA=3!U{&$9z{=Y1nGVFz2cd^+H zBygUCJGK`4VMMLSa%M{F$O=Xs`M83CsTC58p;oY{0yg%a4jQ#BnJh@+^2n9P6<8uu z#vm~o)Wsg~i$bFccog;V%3|k434_FhVJVshb+s!rl{m3OXki`-Nh0wMhT6;ERO|s0 zqj#zuX(3chDKsW8QY+Ayn!3pun8gA%bygoB>oLQ?fK`HUGBE)=1Vea8Z0dhJ04JO1 zK!yQe?0%LLcY{WY;IjY^6}t-%Pi3fF&kMn8ivZ7>U}^Ll)o%OBw2FWCIy& zu-gU@iqZ43DU*RXFi%n;@W{)k8R}vj{MUjz!<|hCOex{f z$p&x^VU%W)O_9yv$d$GM!QlicHtS^!!nrR2oJJ<{fK3)oHuDHq(83Y7Q@-j#x^hF@ zqD~~jR-3jISRdf&IR_fS5HN=Nc(I2~x1a~RyQlPEd(kFX)}+8h2p>XhlcL=kP@$$# z_<~6!Of6X`(lgwq)Igb3=9FM(*#p2P)=l6(B{YHV3498ML!5%qe8l-B(E>;!un6mr z1KR{FN2*}D8m4S+Q(|@&5bHo3;S2}@5<&KKtrEHjv&ErJ7uG}q5D`>}LkK@cT^vCY z(LrdOqJlwc12{*<+XNfEsRSOOk;IgOBp400+<@}K|8Uqqfqn>1r$mOdXLH@Z$@E`C z4FzNwN&F9v6NnUN%M<>SK~Lm5TS!ksN?s;ldmW2Sf|wQ>g?&@f zWK-KvVwg2ezz8LR3wA&@odMaD(1l$aM05~xuxBgi_reO$p)J~{F)lzJpPq0LySDr_ zh1s6E(7XMtc`_MutN(uLzr)0UZZgt>&DVs&ZAtM3iJ3&6Lw4HZ)}D0;f`#D&Wb;V;|J-9eW{3VfIcB)eUz9;;9LNY&lL%cW{X zPYayT+C?OVNm<0&hzEy`5W>Xk!Ov`VUwr`fmhnruS8;`M0?hMNd?o_zo}3} z{M*d1<*~9p5`PJ`{EqIe#LSDo{6Wm8t@~LVJRx&?u)%2F77`~>@ly`%q(z95%mo^Q zx7YPiT*T1Mgy{6TxeK|RIP5D1xgV4QGf1%psAi^V2n84yWi}cS2S_`ci5B|+wj68o z2`tU_g_V#Eu|@-1ptCk*mpy82ffCD2N|0h2dc|i;mltk|Y3JM)w0-Ep6(0+!jQP;v za+Io`t`G2=A(!C-aROvVZbHP{h@P$rdU^Bz^`2`==P z%L=h~@oVy|)$4AHD{2>vCSNjbY>JRq`k%{E$?A+L9zYL@eGN+DTwWZEGPT$^G^#6) zcf4ObNu1P9zN4A|O(;iQ;=-m;u{NQAMclyqvl;5jVsAwvVw=}THVRa5?&lkP>ShYi z*->4E=Rk*CsR1mmX)s_wZ+Tz1jA5W*AvCH8QiT9AD1!lyOHdOxLQ<2DwxbeOj}qc5(Oj~_>Kjf zB;#bG!A1N=$MbKP{qmi z>l<`rzPYw3V%#{M;j~AXtGi&_uKq5m^QdLc(`XZUn>kmv$2hOf=|caN(>08-)g$CS z`J0w>?uH>=_A}jJ@@Rb#hI)Hj`DRk6HCp_JZjj{xFxj0|`DEH4KZG~Pr&l{01g*(@ z+~ny7dKB^Kx?@h-s#v^Rb|}M`Q-#-PgWfmLWgYeStbFRX#^GugE(c7b3RJKFLSA*% zG-j5I-0m{(XnJ8ayr?c-enI$Hw@1*~@&0K~m@OWNB4rY2g^xAf^g)jGV1B5T+;d64 zN4yFkrPt>BHHDaS>w=S@YkcQXb7{{v`grjweY{{t%L@D_0aKq^6P)kgpluI#rB_Q1 zM!Cx?4@V0+)q~v5Bk%WI(hUl7HOtuDFl2)@V8Zh&1%LnHTgs~;qJn=~=_l{C?p%08 zyS;Gp$$PrC-zI!c-a8SN-aq!whuXi~Yvuhme(mCu##`R_Z^qTqX9*L{c{_?^+6PZf z!!CaG2Zbhn-$ZlPt|Hli5u%ARQrQ2?sYmHK51tx}bWcqen|HbFS}p5-Q26JV&@V?f z%xfI@xNC&{w@%KL~Cym}~Ww zAU8p7eNngv2y@lQ5R0Ju%F*#zCxPHkube2tUROmX7bpvq=}u!@)sZ5<5%*B3fel@{ zPT=AWC0MS66jM0#MQ%KY@`!$YO<$&upos-_&isu7E+@3E|eSZ&CWk7%bhhUbZLDgUiI;!&tGYq z=$v^uZ|m+N`QFF3&&>1b5B}~+qtn4NnY5wHybEuQXY7vZQC@oVT4>}wjpqlF%+OKI zPzvQQ10T_5UJeU>tO-dzSf3xBUVvXskW{ELrSW|FNBl5TM~vE&9}@3duF}NEA2I#m zX1Qu})VenQu<+Lp)7ztqD98VCGv=;-STHOi57n%%O^LY~bCZ%W#u!`LShK!{<^7Ml zF*niUWXIbP3b^5MhOKW}=2)ZC+((eV+29t^a)@peN;fVTM|BVw6`rFFLn%*$kL#SC z7)P6)>Gv4PMc}aL{?6jy8T$HMd3B+RK3q}L;B;DM)OA_%=Xxa=KF|#{aPO+C8kTc~ zS>nNt(~+u%#d$($aXZ~w4u?zNATQ^BZD)lFE6v+zTHxDv;+S}egzs^)e7t)+VUC<` z2=Z8atGw=D_XJI+b0V*2}bKK$7jvZ`f>_$ty0G*AAKY*swr@@ zrU9>Rax*2!`EC297Qyhmb(Oy%kzue_Ad zckgMQy?r_Ra6;Y9BAH_N{NUI?^ZL9`CQ8q%TB+9uKD@R)@as|G!RCuwPH&~NCFFsp z(PF=cdr}||#>rQkbG76uKJLksPSHS z<>-VDK4|XY!wpcLOnEkfVk93+A7ZBsvcng8gDd6AN2}) zr-rx+$r=5sBl&(hxOUb<;wq-Qiq?H=VNC?{4gS8r{Am32+TP|%IS(b_uP`{mCAYn1 zH!3PVS=x5Hgx?a-a5cs0Rn;fM8`@7U9!uz-yNvVn>|0eutGv^PI8V#|BzwVJLIEj<3V6Weob}!ic9)Fc*W}PVZ{+VA>X6sAhV>8Kr z*VZsA7x(YV`GnOTjWd&!js(gmLtcrVy+I8NywEJ{{^3sS) zl_$419+C)YjiY}rdpJ3}Ze|tVzT0C)aui+ z=*!toEy9rNm&3ok<2hHdS6Mi)qT@;9k&}h8{f5np8iqD*%^MY-xqdl0qi>KSSN&;j zVMUTElTKIX#a1awWh+j#xbC4E?w{r^!@pP-b#l2{+R<4mKY!!(p*QF`*Q@ySs(f6f zW)qi0$|~f;8ZD((ryFCFS1ugijsm0O{rg352Z^iV21EulT`67y6z(hXdzkL@r2k4C z{0OEzd$`8}{nS^{vx7x`x^tcf^xx;oE99*XdEAmu<%Ovqtyg^2zB*{b;$E)uaQaW; zv#(;7#+cN6(+-&vH8lHyW#)VG-yay(w+!nSuVc#jW}_@p9R5rnEsEr-u&N@uHAfc7 zn>k#e%9Ta3_6Jmvp>C-rkx%nJPbrm0KM-v8$!m-f9E@tj3!1ji!<*yTn<9mpY}3FR zxmh4O*Bp1w^!W$!i#p~vj;p+~Ui-e6HNuvEzR6M$pzdz@cppoYS{`F;#+`fL^}$CO zmbL>8Kd)~HYxyV(Hy&u?t+DvU|Hw-J(^9E(UYhS*dFpEu7`2 z6Zjb$Lp&83qSOX~gdXJnWBsHV##P8T0-jPS*?s}zRLsx!Qwe;Q~#oBb%xgUuaMH5-zG#*)3yc;JDs@<9me?>K>! z)bInMgD71ZH+#ThEqJUkgatxq*F&Ki|3v7?H-uo}*W@!kh{~x|WCk7jn|w=#s3l23 z?qcR~xjaYwT82r_aDU|sR_yEbI7U+J&<>x#yE2^P)a6hW%3{|aXMSCuPsZv*pDA*! z(S76}sK2Au!bYY6@%+`~iZA z?~m8ivDnlab&2P2xlx$Pxepg8)K!sC0Fv@JvPh0}{tx{ssKgh|n=EvFw8Q0n4r7UD z6d&LYta+IyW_)@zuVkP_X&!kX#%Fxd`Q@XOB_~%~^%eKk1+Fx=g@H9uKJufg+Rn3G zL}hCQ=oym*VJIqakb9w!t|#cWT{k7!+R1?iI?CpCP7qT$Q08_&sL?=W4&`k}sFjC` zbyfzHu&73_KD!pr)j<_R;X+OPiu8r2oS^*D!XCo^nQoAWHX1NvB%V`!&~`0;71V=@ zbmZ$8;z}`r?WD@t<{4|`H#A)hn-(7pPfaTklqh!KP*`>7T9Z`Rdom{=!-V1RxyHXu zq^k>FYa8H}xhfx`A811(-(-+bQjpeV!Askyn2k|v6=IZ!sB~T5sf_Zk3Q3Pm@v`o! z5TBz5^~T*lIb1G&eGy*a-X3Ob73HOpQLPS`bIMJ5fbHvg{99sQLHI)lyNg;K2{s#0 zHtO8a?gV&7oov62Xq&=|Z{;Fq+NO>KM>D}nw;XUf&k=S2j5&o?_D~*dYun zCia71rUbA69KWETZMPPPZR0a2E%$7h}f;c26Sa*<#G5dsYd^!VEcIL x#9_*$q;L*X+6y1NGT=)pd~JgdYw#gRqlV2ZlR=WfcN|C9vHMG*W$p8?{~M=PG~)mO diff --git a/Launcher/runtime/dialog/images/downloader/line.png b/Launcher/runtime/dialog/images/downloader/line.png deleted file mode 100644 index 8ff252533541c884d38897edf97f6fa37c471dd5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1839 zcmb_dYfKzf6ut|nl(w)~BM1`4!3d4rotb^GJ0mOI?owFNg$34jsn#+(bAgfFnd!{H zE~E{lY9Cr#i)pN;4Q-4jNacq~Z7NY9*h;LaTBQVILgNojG?rBCAM5MRzG6((+PKNy zoO|zgzjM!b&ONg~&{V%VuOtruu-ez)Z3Q6bNo1GgW}(q=qF@@04#DFIxOpiIvDW$x zSQSOn&b0tk9X@hsvT-JG&)&(>x^pKt=YD-fu51ZJ=B5w$9)AuCjd_OO@_CMg?-s`g ze>NTz%bxgZS5{^HwENnMo!RF`pY}Yn>W=3Ze>%QM-+$5YT6q5Wo|Zk!p|QTt508I) zVWFt=Xx32E(bxONdV#TW#|OoWOSwby{)wx$^EU=9}*S9DC2!Uy){eL8t*^iC@0 z;}auK84HF+o4&Lgo7a!Ne4{jwr~D2YKf1otxP53rb(J5Wr&cN34V%ig^$cwt&i|r) zDR|*c*na8iL+%F;-Sx`Bi`KK{d-pf4nft7zXm%;PgDQ_W%Fb>+ed@jIgTJ{7=a->4 zQlGniovWzb9Y1Lve60A9m%a~wDBqXA#0~`c35R^fu<}gZJ6oUq@!p#JK`?c``Pb#P z+F7LJ3b~XmI4Npob$!k8sEp76)YQghmg|8U7KUAd z=)#vKCUH#QUHBHepY+Qf*ex^+D6nmyDaZ}S_q59gb*gRU)0#RNmMJ+ z3|^>miXdx(Bw{)v8FteZXh)kvrwRdBe>oQb?Eip$ Zm-X(j;hTLPuL8%CW{G(Q?L{io7#us~DMOa@6J%}L6dnoKCs8B5dNgX3}U%Z8t7eAB*i^vLyBZ|%5BKi{U=A|G54}5E^kKT*1HM$TKNHz^ZD&%af@m$DYi))=$6s)BF(JCg=IDKw!~g6=`A|< zJ}Bwvc{%OHO;2yHYcm|3w0dpMn9d8cgodoB z8B=ZXC27Iky6RWQPkZaSt5up1+sjrJ@l6)#h$i|-=HYp(ZjPHCTaC1w&ikvcF!c;OUtQ2IK{SF)PYp^eR|Ztn1xmew z4eM=c#!xSB!{(Ztq*Jm3k2kwY28C6*MO;-GNApXQM)Ju)TA@x9A(s_7FtJ{Nm_55it0(qLXZ}MGTg} zqu~RC(PZAu6lBZ{$AWh@%%iFjLlA*LKo>CRM7flJ%|a8Tp3v)Yh`^OfL1lxupd<}4 zWB`Sey^`t`1vJFSy2NtThC!tRDfp!bt)PU<1Pew4S&5)@WGJOUpwszesNWw!D{5v1 zj1t!SNMfa^QUXK)P{eYX1DO>-P?H9O@myrDR4)7aGvzq~_<$e66ex^}gpxd>Dk>iF zF?mE@N3xL^y9`)Wl#4{sH)vG;APZ`@qm$=)1zrp&Q$l*eaFD^Oz=lE3Xq>d-l(C31 zGZe)bjVaJMk{p0KVHfbM$_@=I@?Ll4P@qmH;}8^;6*%C?uwhV?&gemJLXNX*RsCc3M15L||9OQ`9hcN>Zuz;m;)?lD< zGcW?&YBlh<#Y6)WY2qzz+B(RVCwt*{!}=a(4XNTGBWE;G2A7e>X)|lVEqbFBX8}dw zyg^U8fI)92triUBImRu@ein9#*Uy#$LJ~?b^dB{L(I?7Ik%u)mgnAjW!z{AB3N)@V z{B;z9rQwy&i}tr1!*Zccw_#k!V!&hJ$KFR&Z)iFPXagPqNuOZ;08A0xYJinNS}Cmb zf3z0yIOz&o@nqpcv;BV)9xf^8VTDovM<#)VQXxXaWxx>P-(K~Do#QG7Yik zBsf|-vv=NUtN$VHhPo$p)V0p}`!v>JU*~?c6`8Z!-M80q(;@dAn4h_B&hZ~TBd@Gz ztNo^ZyOhF23t6QtO}h-;3)}g7=l+QLHZ^rrUh{+2gB>vqCGJzD@t1#F*X22$(mn2& zR@a*HUBR)5_hXvtZZUPqGm+J2FDJI(7nf|iqu!j-I%eZX_j4v_-q9?0H&Y1C`{mbm gD6mipXnWeC!J@MbpI%QtANtF3WaefZN?*L;M1& diff --git a/Launcher/runtime/dialog/images/icons/close.png b/Launcher/runtime/dialog/images/icons/close.png deleted file mode 100644 index b3ddaa563ceaad9e47d8b7a3265ecd3b589c86c5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2181 zcmcIlX;9Q=7!II-h=^@1Dkveeibpod9_%K%D(+GaT|}S?S_iT@*vRfCZUVb7TEMd& z)d8zTr`D@=ig^7|%TNTouW`hpRHv<1ZJj#GSaimzR{AY0Tc@LzKi!#Zz9i50ywCf* zZ{DoR%t#p&HX;myph0P=<}7elfddT<2LG*S-ew32&;nj4R|-XLQx2JEu7Z(T8KMQ3hZ$@f+Je>;CIimwT* z$f)_cq^=l>9JBDmup1qr744RWhuTxm%GI&E(}Us*8lt(lPr@!WU9Jr#`d!$*Z9(MV zirS3py2zPRYd?P$of+opg3`}DSrnOHaZNVHt|gnpUHJhsM$Rv)m|Gpume-MUeh-&- z`QhlK_tuAOUUyMbAG>l@`rB7pXGNXq2r3|A?fQ}Rvk&cUd{X|xIHbLkb8brsojSo7 zm6zn%p(_7y*u)L@t*52o5gl|{4%?uYjsy%ml6-jX@;~046j2T}pPKnsXZDmcz{vqp zYMu;15huJyz{c?r(Gb-Cn2?jJjOb9&UVl{{hXl|NG---QqM0I2fvsGj;4~r~ z4NV9vutsE#&VpMc6K4}r%UoP`Sw;?1R>Y7jGG#J6$wL7G2dB`m$6#&cK;=@WLVHlB9N)`e z=48etNQxjjVJ{ZPT6M@Fbwn15=N+SZ%VyDi{;Hwhr^GSmE;l- z#i#d`#Bxrl#9>*SEEc;MF1dtrD)GI+SjN9sDt6hsGi4c!vvUprlYub8A4;-`iYVK} z*W}@U?9WD`OfHUAL|2X|+ItI?*~QX@%|^SY!phv@cMLg-UbE3hiXLG_w%_qEv#wQj8jBST)O{ zIB(!ltwzhBB*)^Y!AcVbn&nAcr|H%O_M1hf*lV75e^1l0A_F-5{!lE-8)&PRL=*LT z24!ij9<{Qp8fB~+T1Vov&S22@vdwe};Ju;kFSB}8v49cBd3_?0s7HC8HK07MHJ}ET zXHm65OIvXr&RaLJpIhg$VqQ8k1-jT^5lAo@>0l4A?;yse%j& zSL%B^vblx6m0f_lTaKa`Z>Jj(##>^JMSQn~SGdJE$nsDWxC|e!uwYC|4q2hQpQF*3pp?{F~pk+<{d6Q1;PGZtL|qn4WeE+m~P&s zf2@KF|6t~vfZ7Gd?w#wEPrz4lbecIS$5#2Ey~S}H4_|&Oe{0-nTR*HdZi9oGh7FHv ze1GD1qxNiHeQWfl69*&rh71d~*F29noZLU{am|sg;5NRwQFHU>;ZjHVx9-G{!Be&O zVzc+%Zfg#bpvjfByM=R~Er|K1W%@XB$yd8RmaDWwufj(8?C&wz53cCaqfg}>AMre9 zaov#o0p)F;K}YXi<2`6|_)me@@|vCVZWSf{Y8&`e^TYH@)uGjAzmx+fSIjSYu;pTB zQAcy_p&dhGHa#l6aH(Ko-4{ow&L`=iDe z5&C+lxc(P6$rh7WOB$-~mE7NSXI@vhei1Qu&$fu5gCQ3`J)hd|XoYpzUFF^uf-NoV d%}g2C6inJ7)~i*DNtKQKnv3tlu}AI$!_+@!U}b_lvcKsvcQ&O+HCS|H+DA(NxHiQ zw1)>*#Q~-jhCyIF#!_Is%3()Zgdze1Qso9)@j%Csj^e=xf?s;9j-$vQcP5)J$@4w$ z^FHsJH!BMAbA~29l!ze6(A;URLU=a715X$T|4-sY8xSPUDma}5S-j)}XkpId=s1dD zY#9hLZcW{bEqMnDhAnGJ&2HN|C*g9ZoIbN4cxr!b?);Ugx6!$FN3OHZcb~Yk^0(yG z;^+kzpX!&Mvp?&HK}+M?8lG`JJ7mDBj-NJlFr$vgz2ZBw>G_$@U-LGGKUuT$%F%Np z{OkKw<*$D&+*pnzr!P7WsVjDt+iir7`XGy!bIC&8gtw<%u7+v^NZ-`XAe} z`N`yas~Ympo0DfuX?W>IYC)oM8_7HJ^U~zvs&lF%t(IvWq7=tXAHA@wYTnwUPm8)d zN4J5Z_N!yF9(nPe4Xclv_NFack$3;8lQTyg?usv=(t_5}d*?K5fB)yoTaJ`7*MPV= zCt=D2$B3e==vG7J?2!}Kedqg7elV$vUF_kTt@7@;!Mn3}&3o?0;ggaok=8>qe!n(r z@?q%YAbDDmiXce`^&_q>Gbt5827DlRyqecN-OfoN1FQRMh=yc{MvzI9qcY2t0S)zm zQbBZJUCk{RD)0_$uGvkxWhV#-(-tdW*5Z5*x44XBcx>`x=%lC}5`=)pqR~)LRP9j* z*3D~&YyCEXq1_Oz%z^b3)ax!lost4jv%!LM6m3MUjDfO{jFFyz8cE7ZkXC{+;Ur}z zEp`)w_Wm#!P2v6aLf6#ZSn$e$1vE{z6GS8uF+@xTNhu{@voHi{B#cHJB5<`r)YvF4 zs$=>XTtMX%LDmFGM0G~iCzWds3@YtOAtc9WMYY!^Xc!S?Wr8x0dP;pjxBJe}P$-60 zwd^pA(yR9$iB(U942VLYO63X%vco{s#`Fc_x!7L0TnTn(%5ww=f)IqMP#6^pB?lx; zQUlVz>y*seP3;v3`fx6xHTv63nkpsCd2L?qM1cA5vEhg5? zn*eU}8GX2kr+qj}TR5DdEk+Y%vXDO7)~yTfcS&5iZl1osr)hbKgB&q`>FKWG#NPm4RA}MjAJoX(P_q zC@an|J}a=<{E!D=D9_pbk`iKJmk1%Y6cDmlilKk1aY{i+aZ5b(+@$w1WQSQy6I58Z zir%+l7Fg7~3JPd<%h_2@?{o*o=_LkGZ_jPvAKbe;ojv;_0RTzwQ2ZX4D*3ettAMOh z==6WI7V&S=RW^KQ;dfW||4n$WrCfj&O93321g57#=)>tE|@^sVdIvgL)krjmxb z=We&%-uhZ#)A$!^>Q9G#nXatlRqvdgnDF$a>0gJBKYC-^L^1NqCGwczLdMFPVc+h; zNxbOd#tB#5!+#ySYKbX*)b6BFaf4G9BA->8I^PmYa`t>x9DiYIMuxRD{}L)RY(Kxi zv;6eh`nc#!Ufz-N_RYe5%}3^!-K?+wa^pAScN{(uoY?;?#_uWK zH@7LR>43Lw{+fXsqqC1*Z7;b{^>X#xn(H&#pX%H<_RyfuublE8OsiVhIn4I;lGmGC zr@DvyK>daV=}*M0xR`PvilH&P~TJL`M*vZJ$* zNl$DqtXTOZ)i$qvNgYo-du#MZ;krH-)@{F@zN~9XJzaa{w*H;W&CYl2e7vOQ4?FN3 Ag#Z8m diff --git a/Launcher/runtime/dialog/images/icons/discord.png b/Launcher/runtime/dialog/images/icons/discord.png deleted file mode 100644 index f55666a506e63f6c0446ad17c8431f4794725f14..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2482 zcmcImdsGv579OxDic(||bP*kf7USwDwM2sG@;R5i-Ayy` z$2t!*JRkCSX;a!4l92SLnreTD%$VbN0Hs{`c2h`hX)mi>S}8v>*OBX&8nv;Ybi$P;k5N^s8AB90@@Itroq(Y0#xANZQ6HeD&pfYz&8npoG;Ph9C=o z6E=c;i(QEfwRjQOLMf5;5}iQDsDRm$T z5h}nH0;xhIhbIq&i{_wAigoIzCu4DUO2q7RG71cHyWM=Zh)+B6F|JwUm_UdLg(!zW z*&@4>@St`!W{N=#Skhr(oEF*+`xpr$?Q$v+PU%DnHfEaE&Q6wzD;VY>7!2nNd?`%< zb-IT`ZMJDN>(mr-Q6}~NBr&TmVgR-du(ZoT0!<;XJ7cDTQRMVq#^tb%XG)P6umT$g zV>w~?bSTD5J89NT|4bg!ucxzN6ec^QpgNsGYiFH=odjC7 z65&MgEfz{4mlz4Tl%h~z5*bk-77I|hoRXo035did90&j<8P~<_SJR}+S3KYTiKeA! zlH-`Jk3u4r;wDNAPzfQSP@_<6M2$vZLQRA~LWra$lN=|e*wP&q?zOGpy z30k)qaHJ10e*(tRCa0TlfW&;R(*L8iu%DC85`_;J{%E%U--J(=lr$6ee87!N4DqFc z`G(7cA=rO=HU92LgJ=rQO*h|idaQCc(}Nk&LSHLgUTNs@bUhuiBIvm*ytj^APFi{F$g%gzx4?CZt>t-*Ji}X|=zutI zXARGMkoT+Tt;6(|SQ3vsm2?00fSo^cFsSYJJo?^P;oxc6&~daZPtyHSxBt%W(CgL> zt@XOKo}=0I=G-5M+(MXPd_$reXOV| ztIYj&fj0KUu4n4^p?$8-+S@fJ4mAChiQas3L!md#nWqmswcy5ZcvjrOEt{H>zKhK4 z3{N=M5in59Krbz9Zxp6Ahindb9E}PdI@(n|@}(;LkhStbyUl_pRLvh2tVqr7``0(` z-uxmSEUsN}|3Kf1^Om(gw!cwS-z@35j`jb^TDj}9jqbih(w$y)uCyd*`*2YF=q=4} z$k1CAar~qGCEuJR_)q@1q+&r+2q+xg%iFvSANcefb8Qq~d^U@X_qvT0`%)M6^}DVr z|FMAl=>4~sbW{zTjHqwl4lhaF%8NM_JNVUmhK3fr?2jH~iF$8O?BLh@gw{{2W2^9c z74wtM$IoodIiw0)uL^uoRDX1&r&I7+@4(#XoVn4douug1_36FubZ^V*tvhp4V@>am zlh)qd@%5W4dtPlj6xwy{`{BRsMMhPcRj(LaDZ7zT{;FCRFZS+%p75~PC*|IoFu#13 zcG2%gaR2}S diff --git a/Launcher/runtime/dialog/images/icons/hide.png b/Launcher/runtime/dialog/images/icons/hide.png deleted file mode 100644 index 4cccaf233339a1ce8751c5860341c10b36739e50..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2009 zcmcIleQeZZ81KNrHegOMf=;s988$w8{ko5~a>BTq+fD9vi~}~NfnNLGuI#QYZMVBE zm<{rA0h&piT@a5WI-SrQS|NZLt+5;k4@Tp+y36) z^Lw7()92O)16AV+o-9BRWSpK)aTL;=8QR5`Qf6~zdSypumd@KqV~@l z^JboemCV;~JZ7Ca+ou&4BS`L1IaF`f`{(eY8n+2neQn9O2GIyIV`fql#AaZk zVbCNiZfvlxA46ryjV*NeNx$X+QMtNZ2lLtkA+fz#QQxoI&4l{r0g{6;%tvn&bSc8ud7n?mf_H8#YML5P5Q#*>mSAkE-bBD=;Ruo@Xc~tI+-OrwA&DzS zX@v>|lmYtv4~E9$S+rqR zw!$cBz4s(GLTwr#>VToP=pv|W1&Udk2_}izy;_SN8_HA?2@nHu2s5BCDjQ0Rs-|j0 z)%)a;eVxrl<2^bMOjQr5YAj<^FvEg+JZSksS&`I)F~!o8h6Ar)0yhRd<8YG2DSL== z@)X58*lEx?l1xGUunQ!?6ov;@B{|YI9H`&V`xL_z6cPBmZVZaD$+E=Lv_LZ~>%_y1 z-HAt7JAf;S#sMuxBq}UA1PTo4g8RLy*kTpW+MjA#NfjYSwm!T=w1bEg4&xllaX3ZV zT{y=`3=XJ>7~yDvWf?KUR;$bKyAfh{vs$Vo$SAOsQ*eZxI43$CIK$W(oC6GlQ-F*x z4riDpfeS+=k&mc)T!397$Au<9Xi5`?{-egD##G&}O0edP)yt3_W>GC0(73kr*D(() zORr)wI@EH!AX=U7#zf0vAYtjp@;$0IJe?`pL=-^M2biCN8EV8#2s)@}f|dS{)*|jF z-4I$IEPQyj|8K(6B^9HB(gfhhBrq!#!Wu3qLx_KSHT3STL6m{R>1HjnV-?DAn?nEhL*G0Ya*iiLknEoJtK zR|Y!Y&)+vbP_`?;c4_=o^XQMO&gbvDvfH`jgi0zn_pdv~3mZ{F;xY5cAH qPS5lM*QYMuc{xyd_l^|Bw_`Ti_MaiD7dxzf4qs)!+dF&7D}Mv(v8X8k diff --git a/Launcher/runtime/dialog/images/icons/list.png b/Launcher/runtime/dialog/images/icons/list.png deleted file mode 100644 index be11c6fb27d568dc10a9668e9d202331a2b3a6ed..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2417 zcmcIlZB!K386Kc0P(`91-4re3$SD}IJ2U&e6E}#v6c)3%;8qZm$n4DBWo36}+!>aS zW6MWd4OXSWC>lf5LhA>WT91Y*RUj&))kuOS7}FCrvDVN;i2+-xmG&+l+nk=n`lox& z+_`t=xzByx_j%{tT3dF;%$V=QAP6$kl4;I`_oeVsMNNa_#UsTB5hP6KHkoW`Ebjnl zZpLynnKT&mOAsXa<(+jMS?6qXH+RIRUpTNj>XU$wlw2LE@4&oR%yK}_(E}2 zL4EAiHAD7`N5GoCJKsx7ted`P`(@Rsgw3^CbKZM5XZ~A55rt%eN4N0Q>XW}dbFXsD z_(cCO;Pz!iEqmHHe@$B10Y&8xWY6sQ%+Vt}89PK**x7cS&=&UXw)8g&e){FSrLmPr zXZOm7!>dx?f|-mKGS`R*5_>*)h3!mswh<{c%KW0#bUq-C9YJ; zAwn*ea}r%9=fuTR3}zrQKDQvbc@7OS(hj~vGGb8aL*X4iS|c}TRCI7KXjzAfB-He{F1X*!GbO>~1@})BEz2{I zBa|OX=U`PThfXI~5`+p4YQ5Z{a}si`lF&M|4ucjrHB)RWeQx;O(4Mcd234_;kx(mD zDz#QE*J&AzoYbosIjz@f)@W-?L|0aAgrA!gcxd3dLI2H^A4>p$x zL-7ChYW&?-8qpLScDLX()K=jl)R+MWseQ2RwvNQ-AxQXai#g3+RDFB5b%i}g)>GNE zNR}MEKE0+Ukn-f!q^RqWM+;8ODY!OWxN&?nx4!9_yjF9~JnjL4Mf71YU0Z5jlpUJ) z#PV0}mu{%LblbnDL5vl9Zv3MQyl&_{(_20!?i*GfOspL?=e-+!VsElu`bFTK+8R?* zOl;%C;#6Q!_e%%$ZwpZy{n55BzxeyH@U5q(x$EmXcdw|*@0<7e&wqc@Z!4J@Xlm}A zd#km%X?%ZA&+(DCPx+6>+Bz>%V_}6KU0YXuYghTr#ecYW#CNF?aS}a{83`c7R4aBKk3Tf=E|lyt2YF!-Klr3HVs+2J~_SP)#ev1Pl127 z<&KrsS6sf|d`|}&sy~-~7`c6$JW#j7)rgKJgWj8?u0uD=GnFkLt`ZC@_ny?gUEi#@ zkx+kP$K4KL@Jdg1@toiF1zvyZ3-sW_=_fU#uYkg8cGubH=P!*`uKjcVxpQle93pp8 zy?7Q?KXUr=a7W^q1_>Q}b;a36VpCpqOJ_;o*<%fNc|@1Ft0}r($8W3KmZ9o7adg3N zK8ko_>%)bz!Ox1?vATbCEs{2RHefb;+W diff --git a/Launcher/runtime/dialog/images/icons/logo.png b/Launcher/runtime/dialog/images/icons/logo.png deleted file mode 100644 index 7a4e2540c6ec8f9c2ac1db86d438098203a4e254..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1481 zcmV;)1vdJLP)N2bZe?^J zG%hhNGmRwuX8-^NM@d9MRA@u(n%$ArI242@1TugSc%KKzV95Y7fD9l5$bij&5D0+~ z2!RlGzxGNl`Ka~h%lPuJUDb8%^CR189ZB}g!z>;jA78_d@GJbD_$}F9r?4py|57;< ze3?>y8))-cxQ6&5xp!cjikk(w@tL=0<5$;tQF2QF9GCI8@>y!uLjmv;{009R@F)BX zhaEzU28wH=Ma92O={F&@72E%s+&i%8*<;-2*Cbpfqw0;ubtLjWw-BAp2dP7QVyzZ~$+Q4~FY}Y55acNMWy10$0 z$^U?%HS(uBl~~<)S7-r$6ua6WmB6oibAnG*H*qds_YiFdAp~rvH)_NwH_i-)XXU&p zb`K_Re#RkK)m0{o)kq(KoS^{3EQu`;b9((GPP0SI{R_Siw#}Z>c3_M5Yp47OV%&8P zGbHENicO%a>Y)H3peD&3f?-DUsrimr(rua(1?lmTM3Enafw|tS*m0?u5!+UE2IsTYJvAsY z@VO~!4SDB+))ezCck?eM9V^QDa%zG_35 zTnAvkPHckQL)h0W>~2b2;kK#acUf#=^hK}C5v$Eq3H)x;>8i_3xs{OE;(gnV8n*7c zbqVa3itQe>CHBm_YLDCd9=}Us<9CCs+bQ^$Hl6r}LUKMkQ&jKP(C*%`-@USJ#bA$9 z(<+CR&9Ow1xT4m*7@OIBEyV8zX759f6ViQTnOWasOmC1~C$>Ofyt&qztqaVus+81> z+UbcsGkg3<;THIpsyc(1nd;WFl`-PJQRCRnLcOn#vAri3J3i!GVh6o8jjt4YG<)dN zt(_7x@VgCHv%@op8BWujcQXQl}&xo zBQ6dYZy}qgMj|MUeA%XrpR}^X4?3fz91d zw@L(J+&~#|-;i>w!5a54RY$rQ7_U7PfS9|8?H*Fp8rdD4f?{A4QB(&U@;RRoyEQ}f zzFMtTb>^X?IG?F*7ZYjUtxFJdz1RW?Z$bklHN{r{0EkUfTJQhV-lWhS*oI;Y*xhv5 z+==6h?P{=;>vNCgGUJxDI3Qe1hAP>7rV_;6Pi%q2v;S#ZyRX;+$*nbbMCEilImMJY-73KEzKib<$MLC;C?n8DyiX0X_>sjG#gt$IvG*4{ zgGOFKH%uGmxWMXC@frSFr6;Tuk zMMUXZ#nweA+qEs&Vg(hU2P_H{DOH4mr*79pq*PIx3rMJ-P|O4>u{b&q!Q?14Hgpr!lLdl4 zUKEOFNm+4I_?76T1x>EOS5LlWGd!eS9}}I{d#Om0w4WMZBQ|~{5tqrAXzFsGIUdri z+Il<3e0}Jpz;WAbi>uY|i1#eCIxzV2dxPN0PO~a`-+Oyw_D;mtWb~BO-RtOgQ5-eT zi#+;4Mol`!as95AWrJfjd41Bx2i(@FT(;YX;TCI>8(mTNeRemRx~mtkEU&$PVyENc zyz0pBc#cs4)#X#J(RR9*l<@XP*^WE%`f-t45!k#?x5F%A)wa~UM5Dtu31hO3vuHy1 zgLQ#xi>)gTb#gv;D<}+i>g|eg`D)A}ndO!ySoQf^pVfZ(DEEcvjlKy~b0X9xV57(- zA<%G=p1XP3o2B>VZQA7yV^Ee1X%uK1%l6R{le4cwE~U9O>iI;R|5s!sZM9(u zIECWSVmi&rHaNIaC{~wMvUnn18X<%+H61e5mu^sNNi>Dx>u=CPa4JertIYLtMe26dVS7aBygXKYfN@)%#mA)FP zR?nkxA~=JLGOPDDiE&w`7G=buIF_!1(clbJL#&w#hQRZCwduOF=}Zxrfu^Bq5{8q) zSo5K@N{qm8CH6ac%)g$`Mk^HSP>8^EG7L+bGb(zHg(?(*XO35xjAOd)PCyzMl>~`s zq$s*dg$Q|E7MCd(Fad!80Rb+PD*)ttm;)djF6hGnVL1$Qrgf3~gD^PVR6NuEnWjZB znBvP)EICZ?C4`{b~@+!O7`nTF#GE@@9T8qZ*Q0M~+=fnz>itebKQeW4PgJ<2xzaIb&b<-tWkNdO3fp6CA4?y8uq!!Li6CU+;ro9&diTi}n{@ zV#_BX2MjlriNosrkpc77X3ql}d!CzLG{2r7``4h8g@e|sZ{FBpU2hxa>!R(zEG}By zyFGEJ%c7Q2Ui2csCSjzwf6bRREA{98LF6=-Ciky>+WrSgoUtzapYOg~&aK(Gv?$kI zalC}Pv0B`H__VD{&w&EQkDnOZ!&?mpCtKt0cr|`o5Rxr)e_DUKWRE_yGD;LNr5&%R zY{;L~{9-FK)I^-ry1P=0nPPTLOG(uI=tG$X~qZ@8eI(@E`6MWxj}$uoc6d zyl301F8#@4^q8fE*9%bMQh7Hv+Zy)hxn*-Er2L9g^V!U|j|?SQwl^(ER_r#{Av87wwO{SThSp& zs`A^Kt?$g_JUGzbX(7^Fu-uBDyGw{V+b*{n?ulE zq0&>qj~rw)H$^g8yqzCPGD_0xSR2c5@j$6f64`~mNQ-9MQAdPssJgX%UV@BTND CZO{b( diff --git a/Launcher/runtime/dialog/images/servers/example.png b/Launcher/runtime/dialog/images/servers/example.png deleted file mode 100644 index a233b8390a3303986db8759bb3c36f03a54b7a49..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 29140 zcmX7vdpwi>|NpPq%xR>YwvkeAjKplSB!?mElN>gOqNri!w4|uykRd8j-kI2tv78lA zIYf=JkmVdI5;+$k$5g-T{r&ynu-({o?X}nIdAL6w&zls7BeK$HX#fCZkN)ql697Qa z;P1yI;o$cQ<^OqrKVW{A_Lczf_>Rn$mpJ%XD&&9ep#UJ){NEQu31iCwpG1b)xP>{N zV}xDyy5I|hcm)K9=?D9U?I!3O>f=-X`RxY)=berowsZ+U-Ji2D@FK|l{meH16>AGg zh8M>-=xJaAMv6%%YkA4w7)jQcv3nPY?N*9D@`|zcw-37Braib}ZG3C*JMKNLBxhDk z(@I#>?QzpbzpjofJo4bYZFHae+VJRCUGA^wwaW_&emkempB}jQd9F%-?WKqQt|$5# z+q4{`Zj8lleuJo2aL(v&d*N|!>_XNfv%{QqO3SP4feEjOcYASX+UAxpo{@;W4Zgyy zjq&%sX2+M`%-(;48(3f5{3g|=vUGi}dh%nsMe}2QN9xt8vAs&kxh9K0r5;(>FCtp- zE1~!8->=;-*`l`Jd^@pgZtCijrO=Mt|rn%V9ZNQJ#MleaGZdl#-*rJ74USQOqq}lu`WaG9FXdY3{r@!`*kreDCAd z+>)u7d$`3;rQBoFhyGeMttTYK|+NRtzI3Cs3@$#o)#ijDLjJH8bmuH_>^ydD`ssD3s=Zi}l z(w;GmODASOWbBJcUpf(SwJs`UN=kSpGU;5`nqvFhQcC;Z(~G-So^M@8#Z<>F#{4t4 zc|a%T*4Qbf&qU6KD&x=22)XgU4o6(3ltqZCt~jIr`Qf_0sO|H^t;Y7x zWed@FaEoWczW>TL$f(i1O3K}S&UGtw(xUkDZwYn`eeAlDMd|utn?+$K>hHBb4Ocxr zZ|ImU6s5;F4cy2*zV+>E?%Qxf?Gf{VtJHz3r#Dm-Uz#qKDeU~4H1=|K=w;se#Wxd6 zpOs$bE&Ms)8@KT{GyM8;{nl;V;>XRLk%Qx(``6c6H}yAixPSi@zN}c><-aA-9#dTR z==|>`i-m%}3U10F5M5cp(l#Z5&13ZkTeRPl$;4ag@DTOc4IC4hw(Ajq`+7T8#Al0V ziHDf$`B)|{;^;_KTz$sYYbl|lld1cf=9%{>eNq7p)ukuOXv+74sE)bU!)f;m0MpkN zP5@eL8bAqmRYY1G*Wh`u4RU#%tab}(RQ`+3l_?$bfGTeYIw5b*sIj@tXFNS@=d}Fa zFtOTHi?d_BD;~hBmCpC;)#vxu>#^)jky@ z=Ymv-dn-kFn|l7e2kX2faZX8Euyi5%k8boITM3^xy8f*d-DlVXm>AA{bPn!(k+5Rm zG9U+`v*c(xE-y|FK;E5*j1o+I&Jn&In7Q9P`FWo-YAlPOLVtfi`^<}@7AiafAWPf0 zG!>gH){3b(F!M)DqISzq^zzt1tSD=xQ=E>Bxnu6Pr94qHtv<<``gO6Qx$^vbKhlv@ zs@^N{>C_mzTq)yQTjQJG&emTF(t}K0*x*R*wubA;^6ob1za)gxUaew70eV?Kz#l_vV$D@6QGN$!h;=z5Mz8%3kFV!w|{cP!D7-u(wtZI_X)z zYSG4m+wk4!yW^|2)0HU@V+AK1M08eq_ukR+>$4|aWq;H`GFK!$ty@BJJZeo({#~LF zb`^F~4LlB&al{h0zDNVs&+@x3v*gAh@5FG9y-)EWFy(znh_4bcL55=49bS&15r{OF zj4iytr>nyQ*b#Ei3reRPXir3hl9r>)e#wcqYqm4aUR)MSDe#76`qpmYCz>aES9S_9 z$lc@RL9Vz2SzYq-ij|F*g3aF1X>%HsCduwlnf_4Bas9yygmG5R{Y3e=$o{xeci-zG z|6qt^3rufr&omNyCcl!~J$0tgPSH3yR#c3>(*`6aCuuxjs<9Hbj3Qp}s$Y;h_2};w zS2p!3rQCqqY>`zX_V2dMtFE%`35zw;cnJB&!M+aFi=S1~U-}6D1{~=-25pV1c~QX> zG`O!};ke?=*jwqcr!EQXSC zab_I6R^G|z>&mVAT`O^SrNYG0G2B~C@%a$!>zIMsz(hm{AWef1Fqyh)yO$5uC&odr zEUoR801D#wJJ0;DwP#uBl{F0d6xKn8QUiuy9wUzyph%V#z&UgLiAx}P82iUaTo=xB>8`!jGgXW(K}xj4M*$U* z_0=Ntb0}X|ek278NC@msEBq->DlF)ofUbNIOaLi=Ae<9Jrj#>QqECgpGWA-g(MfRL zldy>5M`l)Q@^|{S{#BPCLRBL1tAXs;W3IBPSMn!GiGXp<+%FdVT%zG9gb+@Is!r*0 z1X@?^NY-`qA9}dhDwM0wXlkt7Y=OD#{p2q=h)22qPqX~MLP0N5($mR!^tMQsvrd5Ank?&r=#mnhW;D^ylY1`1 zvN7nCQ@A=NcLRgA#aN10!t{%?!*PoY3a+C6GLS61b&#Ut&qAOovB4X3SN;M-S<(J& zNk#8dDmF+_bWk}}V|DM`IJ!Z|i@bAJXFP(y zN(2b_%QG+v1t&-ByxiL5POew)w`#p<3Nq6!qz>Wt)0sSA_&; z{NSwc@k!i6oh>~7OP;H}IJ(RS2?j2TB_!kBLdfT*nF?u(YcGWFZ5MPf{2)8Y?9^!d}%ix+UJU8IS zDkxA`Ui5w6>DO@8at*Sx3@L)V)8{C<8tu;wi*{`r^^&uf?Xi5?B07nLijT zyX9Rvr&^|mSW})b9t68Tx71%!umlYM+->!DbU!D!Hy(IH6=uF15vpaDcor+8rNZ=>HRivgy5h(=bWcPR@P#zwWy;u&lHr3YAg+&O-^AO$N?D z=Hxy5ud%m8UR$UH5eGGr>c;$rPh90cJ1tQ~KQsuNy6qL3>bF04}@)hk0baL#qD zKvD$x7i^bf5d~?DNZQ_7KuxvzbLlUpWRTtKqJxoy1krZ3?Q0g}OJ^VWb}akt){e$< zEr)@en%Rih-eBjHQSxquE?)4oNuK{zD@$_sXv-G+ery~>uS15Ti^_12?iju2$dVBF zH&E~}TZRkxp;@MF=x5D#cKJ3-7QX813D{i?9E*+T256ns?Jq-hN#dOF5$_|J@E}T8 zDxV?7$rKzX$Yt2opBWl}+;%~<3$KD()r4)EVCU`LFaPA3P8vm@P5o{R$+~BEXW+MP z-g|{~8CAg9H$K14v-4n|h-x1F;6*5y{YtoXv&J*O1YdpFiwsF2qytC);qO5HVZu(a z4Ba?9?D*u@&o(qvm4_=}TjEoj=LL4qZbb{E>Vn6AndY2{z@sC}eR0)d+sad>>O?_S5X`0mHFRm;v}_t^}i)Q#e=AlQ3_4SxtqV;EJZ^J+&tf$rIx*%4%BI-2C5E zTZnrxiZ$MIH0Cj+qmC)2w?Btsz;=M&nqTwi?1~aM4vLp>g}P|Dm=`c@r4mYSRy7q_ z4rRA%UB1tfHJ7!8*H+$RAiT0H50RRe+`J_+;a2D0bhLi{D@Z9; z?jWn=NPNC!Tgbx~$zFT_ci??jc{98#>iN}2f~t4zLKe01s&FnKY#RgHo)DzZ(K68w zQ(R@B1(PsTy5n0Pk~NsjpGlPidgro|A*M-;NF!Fl6~L#MiFXTR^dkzRs!-*-6$E6j zRtm0w*}jPq6X&~qH-{iy5S5m7sSsJ+>o+u_UN6kNr1l|n$$>(1*)Gd&9$gw$mK8ap zV$%&MwRnFSfgmFZ;{(hJA;e>v2vJqEJ7h2WVI;0yjKFq5zGT__a9{Ne6M1T-#CGU& z!gf|ZVJ0~$C|M8nAt;LN*CQZUSb;*Q@~mr{d{_?aR?6ttf`(e*CVGoACC`QKQgrZg z?t1Vv8ju)tYx_r8Gfjj4>B7tpKkq;9tQuuecP`p5i@TUx`zXr#;8OFJ2?c48!%`QC z@ol68JCrybKo|yUytd_(^**;a}^ z1R2Z73uGM|=t{l0jOKEi#O&U8(V4XrDjClcO)AY25}3gJmStYe12T_O2<%G@~mtonw7k{lQvZI^#^AACL$}>til>~ zT`@}NI53qgCBWrq9U+C%N3CYUh>2x^a9pCy`QwCK-skO6Yzfx!41 zjPi0Z%GwWt7M`hygxGpPqbLUMwFd&pYe-_dtI_B3$0C|p&>mg#Uk|aAj~`gR_4bCb zD?4}hrZ>UJ*aAhL-FRPx!pf8{ivb=uFmxaLZVK7C+h?y^T@qYL;SL-c{=KSX&i|wd zmH7B1vWw@B$zUNWHx8N=B^92Q<>`d8WRe(5`gxe#d}h^s_(h*wa%bqqgJiDd5CJ>~ zTnyKy?MXRPu{h)Nz-0OLWp<%PV01AlzZ^7n!i&3i0FkYT0 zdetAy=MapzOljhI$a43l9LmPIRbJp5g|0x}uWHj&6hMe{AhbA>ZI^SRN!}=ak*X_)s2 z?xr1}#+FqVW#|AMq@o}0VC`J2H+T%LU#v>A&XDR#KHy`6A3-EBq;Nq9+LTU)^63=e ztt-higOTckUueLOpVDc1?Nb3(xuzFae#VAy1WZV}T5Cg^a-nwcB- z>;(m0739wq`Cg0aL%QUF^o({b==C6$4R7%Shkfj${4?&AJM$00x_IC^D{-ABGK@<% zt0;w##5$~olQkM3)~FV-M$U73Gry$X%d|96`SLT3Y1AUaRM|tClg6cXosGCV-;xV4 zDOO>Du;NKotn6@+m6k3;M*)-JyE4{tCC%Anee|Sgur?X-NB5S3?Fiuw4R_lEi zz@D0ooLbV+bV>dkI>_(7+zJ%Be=&1_EeBf`qx6dP`VeF+>!_5HfKckqO3~n_#VWI!MsBbJ^6t|p19kOIQw1DBJG#e zY#7J){}C`YKratEeW15TO8nJUs}85spY2NadOqkWigBera_bF9T3<5OrQWBsoqeOj@-fm-_53^+{t&lGmS)o9Cu>)@#rCJDKNs z10aN0nn7ee;sE3dS51y7ElLOd!X$kb*c1XV+fk1MP)5 z+O`FoMjbjUj+)tS-59OLQMIR4ybCrXXP07Pck61>2*MW$?UPir<0%z`WrHfT>!m zB6I_Gt>G#eLMOM>dYJ4(o%~SF*BBoHR0MoxMIwSp?hd~gk}~RPVqbXp?p^obb3yl? z5+JfND=dfTtWp%v`(1)*CXg?rmvT{qOkeA|*Ad)-xfh19h6y_bniI~K&f_JpMu`wR zSJ{a)!Ik{vJ;V0PC z(-sPM7^=<3u>yE&c6!IQ*+^2MredmPzohX{quGG8Y6B;Z5$E}F-`VfQ$Y%2tvEmN+ zu~_Z<2u+tm4n~Po0?GHdlnlXrKX~eVYzwRNz0N84C@gExj!B0x0KM(T$ zLQoyFn(7>=8br7g6HngWm2APcfbp6$opefte>zI@11PwQonXvt4WYkYC&-yNupPp3 zCHp#da*y=W8|{F!Xh*SR7dt!JXw?B%UB{UR za(u*2ed!ofPq{A<#j;&H1W6AaBAAQhG8{J5rYmo$*4oW{eJI8EX5ETL3$@P(0}FW? z(2R$HrWU*Lfs7+A_JTdFVZUO1Y&El9V$>{!U0#~lvUn7q{=*jpT*!qnxISz^Mmb8= zj&@zRPPl#|lr{OS)1P_Kd2goY$Kg7AW(9e1E`p&bdR($Y&~<)k6EzV|;DFrz60%uZ zR2_@EVvF%R4tpNfvtm)$n4%5!z+OXrlzhJuo1$SYsV`G`xFv+}`f+HMTB}D*9Tk`4 zdI#Qx73MxJr3#BSoORK^h%mwVtW%vzZmW;Jm#X5n+bH}PlvfTb4VG+bk>`R*SSd0W zK!6lFEX#=~Mc8ccRg_K)0&&!=cm#3(cb}nmE2B{;lR_-o(f<7` z59%>(B4r{|D^C)Sne-!=>u}P~O6g?OCf?Pdq1W+90sNNOgqT0@_Tb?7*JsbXqtME8 z`;SYm6-%~j#lE?7ImxDV$J4UxKHDHLeo2$;~%y?NA=$2gCg6X9$*k^f;dTQSo@8hnU`Ye|Xbr4Qn1l67uG{ zrxXUvYhX=6ul(tOroGAr^nk>c$lM|Tn*i2W4<#{KrJ1oQU&JVwbm<&jlx+c?)(TRF z1}Dj(1$sk2 zZz8SpLHEUkHDg1#9t%Foqbo9xR^~VDhGTssPqfr7e@$;rI(VI7O%APj_VN7E2EKj@ z!?|=?jdfALfN+_XUB5}<(@&VXOgOgP9rejcYFS0Icf-A{@_!XcLNE>qC{|zI_R0V0 z=S1#{6ABW=BiHc)c;!z(kBtzNpzI{|&F{c#0k(RSO;FZ_o99`fWn3@0@R0%wi)XtV zA{Fg-^UuF6LN|+xperat-(LL;1j=)YZq|}r>gPP@L$kj6(-ShLwicP&S({X}RdB8` z=~v^L-$J;c@o&HDr~YO1ruBIV+n1f0FN=|vvz~FOfRflm++8obHpO$3@4+yPCiRkr zM>_#EoNZx_mP0?@pD~ZK^&#PB84i6u1D8I09CmYeHWpBCKCpX|GyF)w$HW0C=)EFF zgv*%A3M)>1;Pys;C?yZDl7VsJfmDbt3*KrM`EeFLs-|uaSo3HU99ZS_G~eO$+!T*I z{p5(EN$>m9VzSR`L=pwDjvAgiR#lm)h7EJ?+$`65<0un}0e~O`iOnHp58-j%Zh;H2M+0ANzfI&62 z_;~Zc8~QObON&D9Q}sP}q$_jBYz9F>pY4d@KB+M%DAFy&b(qItl!6{qzlO!R2EfUKE@OZ`&0 zFTZldysCHQ?#P@+x*FMXOj&(bcTI70&WULRpbQ> z%&;8TvazLY-igKY;n!oT7>V+YrV}@6Dew242=K22!V#%EDz^Dr6$^$6`elT;h zXI1M>(a|-X%C@-1G!5o-_A!hAujw3xdSm`GX~XJEwxzS6qn-B4Nbi01U1|f_C*AS+ zvdbVZn1U03R~N?pF=i@=yUXcm(*@6wel7uyEmpnI$g$GabOu|=!YCYwM+>7a02#r> zdQ41iX$XvyP?Z-oCfRwCs`AAF`^$fD3zJcvOtWN9U7g+he~Z>>-a zbaF22?CQ&a;9$07-uXH$#~mbBTJjMz$|1JxNS#?-X<>U}OGLO4YYLO) zy|u%Y02@K@H2AcJ#Kgz9ScmvA2~{ z?k|$XbraK@>56u)_F}EC(;!6F^(vjyA}aAID2W-y-`Trowm(%yMNoA@vh(RZdso9L z=T(Z~IvyfAuWtXgFoK|;7q$yLAF3s)2A`lmDd*yl0!KSmtueVZ?O6qSO;g|o#QVp&<`WTHH5j_4X zM!!S0x(#7U0|5k8317FI1EJ8;S|WfOq<#P?rU};7&?C93xOP{Z(e>UjIhvc)H_uP) z2K@^%ZrJ#us4DHW9qmbs$NVfO-C?a~YTtf4WD1CJRDC|fTTJ_zW7?9=S*D_#E!?*^ zz5?7wA$fB!59CLF_Zr2><5qr~<%#k<4LR2|MG)Nes+$^mO4SI}iBhxxmn7_h z=q1O3Oqa!gs6K)qX|MJ)vK@6eEL%ugwI9*t9?fUGCRKyapkVod4Z}dIqRH@8`P|9D zsh^jA>pywAlRHob(Lep5sIrP$m_3`=9uA79DLQ$I#|@{dqz3JtS@c#(wLXd3;nq-7 zl4{u`f6(24f%VBnF*U8#k#KgAHj(;Eopy+Cp=peM%Lb5Zuq*ZVNv(~O3j()wX^CEHHC0WH!;EM&T{j&1DQ&WiSOTH2V5o@g9xl>;7&4CAWE=VUC+vIRhm-UY7_ zmU9~??K>WvW^O=_0F-?oEd>hFg%YCeg?ir=o>uVZ8(0buT#fF>6q&1zBK6L_zt~=|@c!axb5tZA zEkTHtK97sj$wJ&?A2W=HW{%&GoOHI@kd@TQ@)j!!Ywwm9lRH$`_`eE)7a~Ncc)ukA z6bw4lBGT>e(Rcd@rl%;xD~~=uE>O6&(ux$g9sm`?eX7x9p0|@p3sQ@60E86onF0*z zT=74SGfyzN-ms~D-MBkSx8uGURtEeONnp4i3CbRBhsJj#&E2WpP}vHGp>6-!9bXF3 zcQs;(cZF3b$gGl^kjDG7&`t#6wIjo|!=51GzIo8sSy7}mUJ@hasvmbJFaO}M*5zzK zCbg+Lpy(ztX0nv-)G-qQNjc;w?PB+~2y!bg^f-a8Xurh)rAu8`d@|M0%mP_!x7NlQ z8rBjA**)AAY#85h3`DZrO~MKY7B0T4tt`1qU7d+2MuL!Xo^1OH6zX`3^Jm3g*H>4X*wn+%?Ta3zsmu(U z3e(IS;$+B`A3u$Y){7-=wJ&EYE(VN=4vT2;=N>qwWX;ob2;wTD5~5eVaFcH;4g!aR z-$&kM$)6}H;fb$`8P#>2_14NiS+bkNPccLKhaDM{)TvBhO` zigh_wLLbjNNm3z{gY%|3&zbfAx4c|Phpekl=wN~Ko>bJtn0OTT*XTaMtEZVw?t&@e zTE{|{8*A~@wv*=P$yi<<)TYCokZ9MRY@G|?ya;ZYxa;kb4C!56)z1kV_Ei{f!ys`X zU=fW$Ax1Cp2!+h{?b|oEUF3~FBeFo+WIphIBYj`&u_#o++94|LsHm0>k}V0}SI8Bo zR^VQ>j_LK&8=pp>)IgC!ak;vQy9bd(6KkZcTOKfHYa!5 z7T#J#f^mN1>nNsEC#RedHV!Z{97k^R3_yb+Ubvv2Ls%O#BlQ9Vw&S*!|9|W5iYi#g z{C+D=49m*AEGuH$uli!Ls${rzh;>j9j6v*MUr455+$o~{l#cdy!@@bm$|oM^ zRt$jP9gMf}P5a_K?T_&AFqt_B2n+6dlg7(`ywD8JGo~keD-GUDAk3J z*ObEVzy&;dIYW`{-~<2V=_n?5RTLZwy%%8=ecnUKKE(^dc=@s94`MdR_Gq)0k>yD)GqWk>^G$b)#`TERY`4{>l?ENQDc{qDVc>RoyjDF;P5wcm8h{?Q12`Bg& zrB&%1dKUX`@3}wXFQ2o>e}l3j?Y^7^ob@4S6Nmk|EZI__dI}CiGd%Cv{@S?*oe{~} zsd-^bVvTjgBq8toty7kqYe_c`e%hgX#OAf+?IXQQ0g9rTXa{i7>401vZRQ~86j?Q) zS{W9F>G}huln$y4Er?5k-~@$&$9KCsW&JO>)ukuD zS_pHhQ%oOEZ`w2yQ%OmeQHisOFkiR*3?Z!e0&m%lS7n+7g=KLM11Sb{vC7e2mmzt! zo%ptmN9DA>PxT5@B9ILR71K>ZxY(jpcqOu_NeJS(epsI)j zm1WJ)lf_fYmruYzA4A9Ui=WvJZy%nGCm(<)IZg2WSJ_4J;VLrSE=E(mcQPbXP#z?csht8&2~K7no?qh!MvarAM? zP7`i%=DEI3r`rek3rd8fD>7Clb}N3;=(v^$(CbyKI%=h^x@W zL?pp$UHbhSF0`iGYX5%0b_~mA$%MMtMqa2!!Z2 z3ZUDyK~qJ?>7s_f2?{}Kl6`a?&jL+)Iyvv&*rZl~JYBlgZmMm(n48`sRXp08y2#)z z`UA&Kesb2=VI?2a^6aE;cfz4_KYW~1#;*rMx$3MI137qvyPofC>yjbd~-!TFtKOGIJrTy z5Af@rpWnVcv$+^K37YJz;W*H$S?{GcSR1A576^l?h*U;I>-gjNoih6RB~gTHlQX1( zYhwDu1fwI3NMeLsdqGm+3k0afX~1!+#)j9b#ba|mEzh6LI4Wyfpw4m~1-R}OX^-Qc z;+fWfDXSn!%hy>>u*1!RxMH-AbiLaDB=KKQoRnB%N*vRbA4J7LQQ~C@RKlr#4B$xX zy?06FyEtLWNjd=}zpoN@%(n9(daHgvBQG_nOD7tFwh5oE>HBPlBSZfb*S>{;K{BCI zr^D^DWy=GmZPuxf#d>Zrx0v(oVh`&cabic&H=FK%oQYKPq1;h;uMUC2iq{Vv zp)Q}^JA8Zfs8v7f=fO${HceJdQ8x8)Qny(chk~Cc2HXZ2Up@nd^3?uM9uy-u>-!FO zTqBKV{HmFQxlxSS)MRK*Y|4FA*HBP)rGeV(a7ebcuL3J?+$90(zj-%iw{;yXY_L(3 z-&l&Qw_`i7o!G~c8t=i2c_B-3^ZTsBX$rM&{izqvJa;&bm)-)^6{puQ^V3U?0NTWn zRUimpoKvu6D9@mDF({fdK9lB(t+ed_WO_%aZttBJ`03qyKMeXM$zen7N!>6A`%TKw zyPXA!ddKmbD!Kx_c=9$l(J+4Cp=V*FwExdeh=(NU)#Lk6^$bT6{0E?Ndj&=`Ywu0% z{#~rHySM7-tZxNEO9ixj%)aG?fMV=DtHQ((`!50KDzX+rchFeL+v?iqTp4%L9;I0L zw5C$A0&&;)e2v1Ev&#d%X_J{v2`SbCxcdWNWj|2u%f0GBAv5ltv2dhUfx78J9|3ce_C)j4UfUYAsya zgO@O7+ZS_n@}7axumULW!Bn!E%JTx+UK{-)pihXf!9iKPTL z7WU6-{o;Iz?s*zI^q^H$KFo2X@u5WLDS73}$EDqBUA19Ol?zhS@&ZkP6rFHpjb`Jc ziO(r|7zkDogMbQ@F*Sc)+5>J9v}*djXGTs`#ze3B{`A||71A(ej$cQha&5pA%?K3Z z(+jV0Yc&4Xh~d*ug4t3L5h_ef`7@z{o5K1l9yi|1e!p4{gA-0v9<3?)_kg-Q+fi?D z?vy+QpCF6X@qnq;)I_rV-oJamv=ULs6DztSb)r9o3E-}VWl!XMME8!svC;d)gq5Um z{$4=N_Dv}{H%%w2JmlxHPFCg#5$2b?UONVCG58EQai~9VO9+?Y1$;HyN4ze6uRMzy z_C=lXqbgq`Oq8RYQjwOaz#2|4x=u9&Gi0-|pe@^DFyx=Z zdGT>Kw`YUt$}43hdlL^N_O61KySZznoCCXSU3So-)MZN(m!t$(i$>)&tBo*|?5HS? zGr+a-GvziG77lBIi?%7lZSy41y?{4QiAIf;GZ3oL3?=^V+&55g(1K#5cF9+h zZ#dPX2v${Wdp`Xq=kob|!nC0y5n`E_vL-VnM;4wa$qF7aOe@jnnX` zR5V%fYe*#jo8Avo~t3Pv~PvM}!v-_wf7h+4fBi&e<`@|q74+L;!#FC!p{O?mF%WC%yZ=7Rw_19bYudF>Ygj6QpfwD4BZOTikl>ziw{ z9NW%S#CA-|R!TVfCU+ym-|MX!sR_-$lcfmO+qHB%i7M;gV7&%ep71EXP6 z%PDyl;*HG%`Uk%rW2oA0J~rgTdGz$*ZadIhCQPMW;p$b_s-F#ii&aw&Q95Le0iilzzmycJvKQKlt1)GlvdT_01h! z6esr?%t>>U$$yb}OXhFtTJ(zRr)w=fBfor4oPT5eVpcae!hEXs^O=qEop)X=fbpa6 z<>KsrZT4)8`?0;6{1~BC;m#tRtOnYhr4n66d+|emmVL?>Hbo~5!v~euFC}&`6CM7h zi3cw(X{Ia$B8!>^((l{9+76nc0mg^nw|?-sWo{Fw&Mf*zn7;ln=T9+;Yxh2<5E78} z3z7A##?|Udnx^*bQ?M&UsCu5LoiKas*l*p^_3oW|QTPFmH@BMP)z2|rO=9?~r?nR@ zTeTb(9d3J#kn{i6J$*14n%;K-;z&@mSsIQ;CF(mlu0p~w6{3?&FWAtgur$p z#wzXSoFvwTIVlnj?+*QXxB(5)zZ3Tx9jG|swTqrScfC*h{D1gi$Av3~d?xNTJY^&@*VeKG;GqJxI>^dRj0%0q7)nA@E2`g!lp zS@;8)y~Jy0Vf*;OPUbVq#aZnC0sew9OgPw&jXaW{ym8~61Ixz88nox_qKw>a(eHp=v5$vX|o=A(Ym|fJcz{(v9!2(mym51YqmC zwlh#G6+#Tl{`PiyO7nSRj%<375#cxvqhiWg#~<|UR8P6kkN5$>omPrkHuzyCK`<}Q zey31~Jybh41fX5)!FIG)5!WtL0T(>E7T9+9nIpebMw!%m+2nCZ1z2#TMgq#Ic~N4< zNt%P}niq;(n@?yuCy%~XV?A9uUF0rXex(tWL5a9+$-kjtTB`ML@2VmxVMnQN8icSs zKN7srXPN{~L)AO4L3i#`O*y4&FEwFA0Gkd|fwPVE(6s~BBfRs6hj^#ivYa@O_4o(h zbJ(9n?hp60-_s6C>+GBBhEyYTWC50^F_;9{6JI2x!%XOg`V1GuV%^TgN6uazdMuLo?QEI&T@K_!)+oZ927t> zf`aEyIW^;biw~ba{kvKAXw2u&d(}r{|E^sbay9)qVz6N$yncV|>ca1XCl)o%bN!FlOkHGgwWZsrliH7@Y zz0WS6x={K;w4igMEks#Vton->^Wbw!;*Zlu_{I6#-5L@L$swe))o1AG8;}N6Rx!&VFF$8+^IPW<6Ll`0ief>@4=9$c|$tFn@MbU zSIYL$xS^8{&Jn1JjRGiKDd@|Gp;EqgVxY+D!f?EJ$M(|}-~eC94J&wY*nZihLV*-B z;+mg}y~;Pk7qehNl0h*FH*_V$c648C1`#dw0M)qn!$@i3qJG}bDS+lgENDrIfS7(K z8X7QJ@-jaezaSxtr8MDx1EJC&Y@J`A-tS01m>~?c)h6w&{kg?yv|5i`SwL0@pFdS{ zC6E%nb*<>+mV1{6Yq=1wRBN*GuHiy{9(vl6u-<5GjoS)IVt@o)arR~s-%mEMsI_bbR-b~Yp-it{P zkK9E64Vc@kDEv|K-6lmiF`QujU~BTsXr#PCzs5`6S^ z#?Y1aLheh$#E1S48!q}NTt_SdT7>OjrqbrCgy*P-gVt_r6Ao zL%|+ue?e)mV$db#g1+L!-D5hUGX;NJdwS%;z=_kQuPKrNKKQ9=NtS|%ZZq%q`}KM~ANR-oo&R?w zcm5=aaB>Qyi#mndzXYN;(o?FW=6c^pHt^$9ezP|GUB;x-g7DY6m=0~Ccz1F;kLRAgi2x{{UH8xE2f7FTy=M-w7#<3B5e;4m@tpim*l?V z<4Ypw8T5sm)q1ai?7I%nR5S!{H-&x_y6Q8XcY+MhnF`~b9o5TZN-okFH@5!we%TEN zMG10_HBn@|cA?B$#QMhY-)qg}++8yQM8RAs;19XB+r#1l!v@;fGcpqC$I!9=(fwB) zVi@AGSx)MSPeVlHY@e53`*zAU4kB~V3mU|yc7c38{%|oM*O1x4432p#+=dd(lc zh-%jAu86u^xb?MC)1PQS2Ej?L`kzcz|EfTlvv1*6=SET5Qb%ADv8xg$w2-zB&%Glf7#~Qch2pf*VD{%Fcp72u$rtkan<9q7NIa>}6RYiLUzTerc_}OH zVkYSHlEKPT?dtgO#WXgUE~z>wW}?ZZzwE2kbX=Oa9Qpe5yYo15P3=$&6c6Y8O#VIH z5C#|+E8PuKDZyI?ImK=lhE4-t@`y*fPM-Qn%a6hrvknb%eQd^#PT!$vMf%`Y1IZAl zvFfaj>$?;0>&NhZa8f^*#FEcGwci~{9G*C51u_3*rU^QSzG)X54i|1ejae1)%I8u~ z>KM5iS&7I!JGB>8=k;J({Y4lL5!Pxo@R{jMPtUyRfzADud`0l~a}aaS!LM;I9Q|xj zhTkpMUw@i^2SZ*Z_Z5}bH$(TB^3`X0=^amcpRd_GX18qy4R>VKLiNO#>dtp8%5d89 z(6KR|Mo!h6mKsdSY)#sy(cP(6B0BoXL^JQcl@`Xmv*55J(a`XIj1%%EC!_ne06V-0jo#KLRdNjmVL~m8kZVXbW*f!3I!cmrtv^zoEpwfq7-`oG@M74g9 zI+wZ;=v8SPAfuaIS6g!?=CkhCXPr z=^&8qpcVa$C_i5eae9o-x^C43VX>b+j|hJsk5O2nJT-Ur=G5eR=_iT_D<3zd-ZEQUE@^4t`sL zA=H=Xbg4-YLM{?+Y8I}IT&nxs3fhHSYKRD2an#8V?n+0d>-k?`Z<~`-qM|;V2Fq@J@bG+7Bv|8 zRgQj_FHUw>*DQa3=MeB9+zHx(HGMav2+kJUA9+v>dfyMEeJ=4;VtUl9z~!);o7DTq z%7C0;ZiMDvW-TLQ(ityBk>^-HB+d8wYV=g383V#qPY6VcR#$h!{Uv6%8aI zj=#UYF){4uO@w#Nu4xm)9dc`Yt!X;Twef#{tj9Wv8T4S3Ai1{HmoTP+Ri2|QxXWf< z+|MqZ5 zE}yuM`C;M`AXtb#9@F+>4r)LzyI3qF|DXhV$isj_VyJQ}bb&wy-Puy(;BUtj2c>^y zX;AffncO>b*{WNJta#csx9gO2h{$Yh)e?A8`|j)sf*`D*228i$@IOL$)8z>UOvkT4 z7_-1D`(vLhqtXnT4V?d;;@f zXz*3hK7OZdBNLcos$6m>L~lwSGD;%q^i65`3u*hqPV`k9fD;%UG&4OV8c481R%!0R zIMQpbv`_0V2=)C5N=krSnTaHq^bsa0Sg(Nxnm$Iv!Fr#y z{7X88t|k~%k9yU7pR0~{_ev98q#E)E2@zFMQ0L$;6L<0r6bY^srZc7LAuS~I2Y_~A z#+`eqyN_OCw3S-X2Z#aBS~&n^Uigl!)B4&Pa}iotk-unAwl~ zzY8s11=4wB)q#izB|-Ab8Im{l>qbaz7IhT-Xk?L?@MafZB#?%v$hF1kz9KeK+(Bt^ zeWCVv@rB);(ig}eSOKksj^87&X`3h>N^DqFoRcQ+Xh%W&nwWp8+#P@paG8H3e%Afj z*BC4{`-T~xwfytGvCoUs77t2h>vS0l9*qO;Vg~UwPdlcMuGSu}al#0@ijynBCGnFl z$0V35jxq+yYozhrqraR5JpPhYpPPY|I>-9O^W5NZaS!6$_8ki=nS&ac;`_)T z^OlOd=1_MbT*e&-=5vdW9zlVS!b#n(BpGb5EpObaKsUwjGsOc*hFU(~T`K}DRN*h~H+YU9??m5p>u0*Y(<*q9AUrrX z;`--UIq+!=^gL8-gOtx8*3`69h?XTG;MP2?KHAH45h2Kd%=cNziOq0&?}PWI6(Gos z$?Q#c)J7%FY<15tIy{YfJaG)Ung_}s_SUD^42Nf`UWvPpz;BmVO^%Ee4J~3Sp~@4OIt}Jd^!`)vWUS>KniOGyT2WB~Lv>M-K zA+-^~ivq1~dV0>?^o^-)3owgRkMwh9lPE)dDxUy=Y9ToPls1_!RUL@TI-)(ea^ZQdDncpXXFjwq z9ib+BeMbUi01ONNQv&^`3MDJsEWW8tb`*;=0Is5&m;$(gw?pm@j@~A=<89c3K||n? z?zsJGq+g12ut@cmOBw8%X8kZ8&8*?kX5g(cM)I)u)AXFxcVpS7aV2NL60ts7+nwzO zK~v$aw=O2yK|6-+DC_=dJC9jCYrihz!pgOI>Z9P0bwS5DMtH_TtbXe9@ z$*g@M>IFd*A;PJLr!}GkI7Px;cj3^)ebjw*#mM!h|VE_U?GKkY(ViM(vjSo(W2PJ&H>7*g-NIml*DNljTpFHXX#VqdNEvKL>DJvsI;L0CL+hJG&6rL< z{uU!4Ijc4nqlj@HEt*F;+xrTx)ZY9rK|+4z;r&FN!i_+fQnd5yd$lD;LprZn_09D` zn$S2=A25s`s3T!aCvL0HXuX>=Ut;A#4Z{V z>F=n~dnU<_(=GX1vVgey?%J;+eMdgcYUt)QmX4UoG*p)C&+eXBLp7EVvWRi2_tX7F;EVAoq*LU|KA zj9LMNcihvv!z!6N5GBaS1ykt$3xyy?edCFX3|@WSYKhcW-_R*!C-wTv-Z=RFN$2XB zE&ngA8vnm1ybfoTYeB#=Wgv{lDq-$Xd8zwc-=u9x_&rjUHMG#qH_3BZHF!}_jc-5^})n21n$)RPaDho!%RE!oH+~skgC&{7I%Bjvl^%$DDkj(ZT zVKsOdL^1|FrKQU2r9WL0NoekKWxeE~dYg&L> z5n@>_yNI%1E*_L~85_97F4C^>nkNk%?Ng3yyCEHROW~s?Oj%PgQ<8~cF^?G~cNRy1 zR*Q|i&z*?cMZtcJ)1oF?1>f0n&tA}nmg!|{A{&P8X2J%*N#J4cJ;aHSP&heN-(=)# zdixD$bv0pXuLw>kriZ6ls9cf1YOa5NcNHKmXlsW79m-H zR2EEj9$jhK2~_TEI{|v+SwJ|EU_HrT0}$dvT0)BtOfPkm@tEaiaJ`SYL)|WX7kUFo zb9N#7I{Lq(!z>^s`GN{G!!O|J${!O9=|hba0&;Pm+XUqbF)JfKT2teLCN7M2ADmI4 z27u>GUji+u_|V0nSeVK4i%Y4GU$)K_Z*@!Ve&}1tgK8y?WjJXBXrclE6IlN&l@GeN znK$bniW>H{r0ydl&^;Pk|L(DaQ|OXyts&s}j^L5lIoaXBosM6=9+H||x zK$S^&P(55QXIJFOkd=LitCR^~j6tnm7|wr$8-(iBH%Z=R5`G-MSy|S$7Z-_8NX&~~ z)7W0Wa~fEzIup+0?H}TOtVK5Pr>52;742fK8*`iF@UyFih2@oqS20~+-^uuNS6|s9 zSNIY%bH4pY!>_FJTdtNWHvb}+&hCbFcMYi3%-*dv@*`CmlHkO{u#{KDNtj|trtO}; zdeqNZRF^{48JaiMM9SaOIi5HkDCcISKnWB8TG0uy0d;ssN@^buo!gD zM0A*7JK&o+R|^4gA0!Z}y#Cr#C3fVYVW)5THJExv$3hiXwY4N#HdA5K@8_c*??!f* z!uj_@BA!5@8xW<}Zx-OL*PR%_CcXS{p~vaB9Av4I+QoFO6sgK_ zn-GdXkBL#XiZteIB9TTZwW=X78GoVmyq`DtQIo0S40g>KZpD$2t!wVxi@Bd9DQi;< z7w(25`Bzv69G!>vk?}(0Rh6l_8tAZ4+CSNHi?HRXFU!wyLa!&G1C|?WJ;lH!dePPB z+^Y+vRH+pNMOhhb-9!T^<959TL}ud7d$1HRnxTdwQc;gD{>X=;Ux2zzfJ~X}dn%nk z=T=@sE%ZSO+pp$zK$UvbKwr)kHJ~r8Q;0wZj9#yueVB+#=LQWYmXb=r#Q;%aN``<_ zB$|}jqrN_~(=&%*Z&GEG@PI}#_Dr}foS^vQCzRiI_VV1zQZWpQ-IVt@$BV5SXMm* z+*@Dv4aUV*6a4y%k88?(8Q!|~DTkbl{;&W_N}2_*{SOM=s#NhfAKJ8THu2FBuGPG( z9$;_wNvOfer6EE}iJjGMDmOarr9xk}ezPK*`nDvqp_YePdRHZtMiG&#I-eBVXhmf>M8e^v>5}*Ifsnmo(&Uwk7k_4ty)@B`#9TY7`oB?k*MGpiyY5a1@6uXJ1CoUW1UtN9uZ8y> zY$G2;?NhXVof26HFT~z2?V#F%I{-Zd9sa_=px_Qr+Yvv$D#Axrr$ofWyV2odLA3Y; z8FHeVjL1zQ^pr!=bAo%y3->qAwlo>3Pxy4-60(Zf0sQsHh`H#+q5tWU;bi4zm+UA= z9<+b48_>J52227)v)~INah=6>0r&o3)LCbzi;m?G2fx9UBP$iC8}CQHLJoCM%$%)+ z(^5j9X8P%&kiZ8r`kc+8@+TwW!Ur4U)FR~wzgVqb|1~*+I_R~*`b5mS3eho26K_Qe za{7s{r#t|SY6RFwm>QhKPLgzV;J?^ku}N+9Z&}P8W0a=rkyV%T#r~N0R?F34R=Mev zP}I*~EV$X`iA^XPV}N8}*h1uGY9jhq%gWa~L9Jc`e0#SWynnWUh;kY13=A){v`p>o zpORiNdr12e;yCq27%#t0C^+?$=!5|(Klsg_ zQ3B-zVbJ3b4lSpx6-c}4^umkohrRliFLw2biw;SGtyzeWD`=AdnnFxoeqC0&X(S-2 z$)BBn#ovCZ7A*%FpKoecEt(au6WOX>m7-xP$MjwqNvS;mip7HhhIHi*3Hj1O4Z&7q zVtO?CLC2gburEwzbHiktpQ??>$TIOR?jk01z@AVc_?PN^3M{J^&k@dOyUBNzpY3XrI~}0t?&^7S!8S;}J4R#>9}#DpKH%qEu6eqgc|1)DN)yquEJ#o3Cfdj6mYu0H zD9e>Y0tJEqPZ*OVw624*t0XVdNxc@zo%PV7 zUSO|{iD4$wIRnr=0N1395^O=uDEb=^=^6*BJNzy+?L{j7GJn+vQG&^!1e~*7Oef6kFk2I59~xJo2zizt zcFukle#jfG?B7^jve=iObJsC_OaS&5_|y&^me(DHmFEXkx=>apPM1$U{%F+%T2BR- zn}{Nx1~$~D62=R&>Api+>;L%G5W|9XmgPJF?J~<)pDXG3>wj^?!-^`_k1YZiaTL$& zJzVX5m_?UpYqUhhJObmm9qLJYs4_SlBT&=CgI_N-tN5vL_eSpA^V|pp(3G7&I1~rd z7mznaGOK`0?$XnkQwzywwK?K`kLc5A@(Y!loBlkCVI5?z5T2<{ZwF<3y-)^ z;EMGyWfDAeVZH6SnnC@RNG*|oT;fiZBSw^CJ;Y#7qPva`x!TWn|1T(hyclf@T(NMI z=k*U0F{X>|oLni{ArFC@-ni)L_{va*ILG};y3bASaQD5GmYRLl%Jz{bCoOaBuYBtk zlvT4HJ@P=5Y-#F#xj<2ZY4I|6+R68WwhuXC=-}%GdS$`NeY)E3p;zRlI9aD0F? zRv*UR7joe?-Psy|kdxbwoi~GD`MRX=gR4E45NLBHgU`XC4KE&>AYN9x-S$AzRjF+% zr}n<8$+BMn(uCWA9iI9|Dcqoa;lZbdR`OJ_yW$rqc1{{};*k#j>CdQNFF!oA;mv{B z8~1n>A8OE(Jm86aubJ@bF0I*|0Ces7cnB&m5vP{hcZN&^EBv82L*ONqMFJZfPX### zJjW(edta^ZRg>``-r(`od#DW!%VGoG`zuj`MoGISp&&6}niQ?x%cb1D#?RMcb;N24 zlWOK!q zbAD3i=dxAHSFA?1m<8HRJ{~8L*YF!kQ8Z#@j(xN z+qhQ)cYKBeDS~}iud*D2%Sh>SOSRyyU17=4is_Qz|Gcvf%`4Zw9eY1JKHV}@1V;xQ z?Awp(|5FiMEc)H>c)pY z$m}ek29U~2Y512KW(4*{J3YGf(<;QuF&b`osghPyw8 zCqCu#TtU?TV>r=Kl)pYxWekd@j2tMgcRF$SGlT#Xr9rI2bG-rwT%BQ*+#@t?(o=MiruHl!EO2f|j3Lwf= z;s)ARbAg4ROXPYL{MM@FOK~%)GnE{EJRyEXM65sUZG#`qfO)NZbbg%`=9Qr>w zllFQc9W4!5-^8dlrfV+|lu8QqpxXRr@c3`ypo=?{4(rnkj2zUv|*xI?n(8+`jH!3}b=PWASy^Ej^rWM&7Huw(iqPR!QcA3{vShIC|u z2}wnB)bia7-f4BPZ?yyF4t_^=RFD*<>r3!SoLwIUI(zV@uwp}VQV(}~+F_MVKdS}= zl#R#w4nakZbbx*XLQCX}jnh=MpLvs7E;I84MABp@1pItIwb%l6?KC%Cfjy_@3@~@@ za?hR>3rtyz*^Y1cQ)mW$sUO*8A_#)6%1c-dID}`)(wYx0$(*n&RIr?r! zdKJ+cPWF0!!PD?75YSK~{c?3k2y#~XUaxJ7QOQU@4P&izuDQby$}n((Lyhw<>rrp0 z?`FC(B=eP}hZMSm5BWIEyW&>AE6<|?WUwY+IqBfI@yf!DxTg0btQHzFUFgLhSfSGz^nG1%HNI!I*0;clY)bcIxY(Ks)9463l|BNd!+t(8 z`Q#hKq!>>FT#8W^6zr%Ey)JlY=!rdCETRLuK0fqZ>=mk*>Zq1?oMb(&r1QIjNKYkrtoTg%cvt5=TJHlmlVlF58{z@{S5Uv zZ_mT0t55iUJ-Czrn6eU~{nOy(9_8<2puhm)%6jaaB*B9BxasslrO1BfAsvguliY7Y zzv3C+3dZlR{G}YNHqra?7u2!Y1tNTNB$Vm!(afW5`{$gZz*PP1-w^eCN%und;Qbsv z`E{Nmi|xuci7wzF@pwPc3k)RO|3sT*+;V<*+hJk&E@#MuPksH`a$8G<;M?>zXVsqO zQJsjk>zxB5B=rCiObuB0fitBap%b+9QS^kUudq4l*(6!qHQ}|&!Yx-#F5rlaU#bWG zitjb=w8aDEJIA*)qB-V=t6|`cbRR5gPI*C}ep8s;x^ZSfvp|{YR4Jj(B?CQ*dz>T2 zR#XniLCnfzI3+KID6&M${qw`ep*}zf6b{~Ska;5mVgjJt$oW3zS8PQ10P0)^-`*b# z(AjSKeYAX7o1XBF_@<8znB!*&ll3|` zMt|)DQs3m9Jg>83ndcacRrm@#-fxlpfR>PnLD|-C6en-eBQOL0$8{ z#xj`&p535Zr{wYyR$W9KV`X;Qq!!hJC|TO z6`;%|r1<)^&#Xwb?SK$?y#)f@acJ~(Gjj})#IDh=L{Pdah2(>%Pl;yE^zuQ!HkCn5@3z`mWTE5$yMN$5MUD+OEj{TiiF)#k%p50R>9BUc2@_r9R|4izeoq5)Utm$j#DxuE z8h>cw@F(bvc{thC(Dw-UB2;pL>72x<`WCA#6u< z$eR`Df~OzN3oY2ttf|*^CDGGq{K-Wbzb=fw5L^*I|Ky^QOdRe+DFvaxagQDO#&iW2 zUw~e~s3r3@!V3jDfWaY<6Mdv1SA+SNgZ=6o!LMVrBAc!Dc)-bkS5jdjG(MJ`T^qvR zrKk~Q@;?#%QgWbRLzG@^d}6IgOVLp?iQ4Sk`HwWr$+xcb;=Ld*afa~-5Id!tvL0f& z)Z3b6D4=gZ3{nmO-Dg!qQSoS<%;SwtY1^H930EdJ-aw@ViiG$eTLK3zP7Ag-c@H z;Lo#f62^L=N;B)D#w2yR^B6J`YW6PIm>YjScED5UZeIPv0eXp~FbO!8A2lW+CDgT( zSnG8uNYtGF1N(sp@fV8hTh1~fQkKZTi@*pP~ ztX_|;t`2L8{?m|ZGbDScw;NN)2mH_pF}NZp#f2!?%V@crj&HbIs4f5!V1g>Q7hq}? zeAbx2vPWi6?+7qp4%{XCS@P32PAUR5p6}X-n2rb_s{=}W%9(t zh{Y;uUn*63LTF_PM>c;HfU2@pCF+^N(-2`hfWkUzaE7Z!m@aWRodT09ynx)loZ0{C zb5?mhx15+RM#&Ap+%)bG-%+3$WWwczfGUk3jl+Op^4qwSTjN83+)^LE)e(Au&8JpU zwy)B2?t*PB#Zj~8j(+NX4=lyT3TiOp$}%$S{Hx(!>Q? z#b?gux3AiG4+Z(I%#CkTEa)R!;zq#zAUiVCKehLJ^1pCB47&pD$m>{M9gr9V9LxR# zwj4keKoJX{O$`OSCtx?X>}JTgA3=M%H1n{}Q)sIK)Rqql;*iLXVbROwStGYA6%L}h z@VKBA1E^BRCHd-V1C&RuT>Gk}T{q-b0v3Y;@EIN7;+jMlCUC zm^!9se!8b?EAIoeR}=^^cn#LmLOR9m7Sa;HtBB&q2RT$%BU*vfV6VO7bS{B8CA7mv z&+VK0A9#HiXkymov>~V;a(9@fDzHKDQXooCIjAhDFXq--!VQ$&vl4(3PK+LXSxrX( z)j_pEc&E!{f;?xF4-8Ub7UK-k7|3}(Yl`L)ZIzM$1(jRw0+XS!@aR#Ib$M`)db5iT z*PuUy+*8g6V;6bt6#e8QKJ%Y)|6G*$hAGgacUzTJLk$JX-rq%!cGoYYiX%uOI41r_ zFS-2*wqD2nQhSJhIVTf0y9ep?#output, -#background>#output { - -fx-background-color: white; - -fx-background-radius: 0; - -fx-font-family: monospace; - -fx-font-size: 8pt; -} - -#overlay>#output .content, -#background>#output .content { - -fx-background-color: white; - -fx-background-radius: 0; -} - -/* Close button */ -#overlay>#copy, -#overlay>#action.close { - -fx-background-radius: 0; - -fx-text-fill: white; - -fx-background-position: center; - -fx-background-color: #2d83ce; - -fx-pref-width: 150px; - -fx-pref-height: 25px; -} - -#overlay>#copy:hover, -#overlay>#copy:focused, -#overlay>#action.close:hover, -#overlay>#action.close:focused, -#overlay>#copy:pressed, -#overlay>#action.close:pressed { - -fx-background-color: #1568ce; -} - -/* Kill button */ -#overlay>#action.kill { - -fx-background-radius: 0; - -fx-text-fill: white; - -fx-background-position: center; - -fx-background-color: #CE5757; - -fx-pref-width: 150px; - -fx-pref-height: 25px; -} - -#overlay>#action.kill:hover, -#overlay>#action.kill:focused, -#overlay>#action.kill:pressed { - -fx-background-color: #DB5252; -} - -/*-- DrLeonardo Design --*/ \ No newline at end of file diff --git a/Launcher/runtime/dialog/overlay/debug/debug.fxml b/Launcher/runtime/dialog/overlay/debug/debug.fxml deleted file mode 100644 index dfd6c22f..00000000 --- a/Launcher/runtime/dialog/overlay/debug/debug.fxml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Launcher/runtime/dialog/scenes/mainmenu/mainmenu.fxml b/Launcher/runtime/dialog/scenes/mainmenu/mainmenu.fxml deleted file mode 100644 index 78fb1cf7..00000000 --- a/Launcher/runtime/dialog/scenes/mainmenu/mainmenu.fxml +++ /dev/null @@ -1,162 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Launcher/runtime/dialog/scenes/options/options.fxml b/Launcher/runtime/dialog/scenes/options/options.fxml deleted file mode 100644 index e31a5178..00000000 --- a/Launcher/runtime/dialog/scenes/options/options.fxml +++ /dev/null @@ -1,81 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Launcher/runtime/dialog/scenes/options/options.js b/Launcher/runtime/dialog/scenes/options/options.js deleted file mode 100644 index ed573704..00000000 --- a/Launcher/runtime/dialog/scenes/options/options.js +++ /dev/null @@ -1,150 +0,0 @@ -var options = { - file: DirBridge.dir.resolve("options.bin"), - - load: function(profiles) { - LogHelper.debug("Loading options file"); - try { - tryWithResources(new HInput(IOHelper.newInput(options.file)), options.read); - } catch (e) { - LogHelper.error(e); - } - }, - - save: function() { - LogHelper.debug("Saving options file"); - try { - tryWithResources(new HOutput(IOHelper.newOutput(options.file)), options.write); - } catch (e) { - LogHelper.error(e); - } - }, - - read: function(input) { - var magic = input.readInt(); - if (magic != config.settingsMagic) { - throw new java.io.IOException("options magic mismatch: " + java.lang.Integer.toString(magic, 16)); - } - var profilesCount = input.readInt(); - LogHelper.debug("Load options. ProfilesCount %d", profilesCount); - for (var i = 0; i < profilesCount; i++) { - var listSize = input.readInt(); - var sortIndex = input.readInt(); - var profile = null; - settings.lastProfiles.forEach(function(hprofile, i, arr) { - if (hprofile.getSortIndex() == sortIndex) { - profile = hprofile; - } - }); - for (var j = 0; j < listSize; j++) { - var mark = input.readBoolean(); - var modType = OptionalFile.readType(input); - var modFile = input.readString(0); - if (mark) { - profile.markOptional(modFile, modType); - LogHelper.debug("Load options %s marked", modFile); - } else { - profile.unmarkOptional(modFile, modType); - LogHelper.debug("Load options %s unmarked", modFile); - } - } - } - }, - - write: function(output) { - output.writeInt(config.settingsMagic); - output.writeInt(settings.lastProfiles.length); - settings.lastProfiles.forEach(function(hprofile, i, arr) { - var profile = hprofile; - LogHelper.debug("Save options %s", profile.getTitle()); - var list = profile.getOptional(); - output.writeInt(list.size()); - output.writeInt(profile.getSortIndex()); - list.forEach(function(modFile, j, arr2) { - output.writeBoolean(modFile.mark); - modFile.writeType(output); - output.writeString(modFile.name, 0); - }); - }); - }, - - count: 0, - - update: function() { - var pane = optionsMenu.lookup("#optionsPane"); - optionsPane = pane; - - var modlist = pane.lookup("#modlist").getContent(); - var nodelist = new java.util.ArrayList; - - modlist.getChildren().forEach(function(node, i, arr) { - if (node instanceof javafx.scene.control.CheckBox) - nodelist.add(node); - }); - nodelist.forEach(function(node, i, arr) { - modlist.getChildren().remove(node); - }); - var profile = profilesList[serverHolder.old]; - var list = profile.getOptional(); - var checkBoxList = new java.util.ArrayList; - list.forEach(function(modFile) { - var modName = modFile.name, - modDescription = "", - subLevel = 1; - if (!modFile.visible) { - LogHelper.debug("optionalMod %s hidden", modFile.name); - return; - } - - if (modFile.permissions != 0 && ((loginData.permissions.toLong() & modFile.permissions) == 0)) { - LogHelper.debug("optionalMod %s permissions deny", modFile.name); - return; - } - if (modFile.info != null) - modDescription = modFile.info; - if (modFile.subTreeLevel != null && modFile.subTreeLevel > 1) - subLevel = modFile.subTreeLevel; - var testMod = new javafx.scene.control.CheckBox(modName); - testMod.getStyleClass().add("checkboxOpt"); - - if (subLevel > 1) - for (var i = 1; i < subLevel; i++) - testMod.setTranslateX(25 * i); - - testMod.setSelected(modFile.mark); - testMod.setOnAction(function(event) { - var isSelected = event.getSource().isSelected(); - if (isSelected) { - profile.markOptional(modFile); - LogHelper.debug("Selected mod %s", modFile.name); - } else { - profile.unmarkOptional(modFile); - LogHelper.debug("Unselected mod %s", modFile.name); - } - options.update(); - }); - testMod.setFocusTraversable(false); - checkBoxList.add(testMod); - testMod.getStyleClass().add("modname"); - if (modDescription != "") { - textDescr = new javafx.scene.text.Text(modDescription); - if (subLevel > 1) { - for (var i = 1; i < subLevel; i++) { - textDescr.setWrappingWidth(620 - (25 * i)); - textDescr.setTranslateX(25 + (25 * i)); - } - } else { - textDescr.setWrappingWidth(620); - textDescr.setTranslateX(25); - } - textDescr.setTextAlignment(javafx.scene.text.TextAlignment.JUSTIFY); - textDescr.getStyleClass().add("description-text"); - checkBoxList.add(textDescr); - } - sep = new javafx.scene.control.Separator(); - sep.getStyleClass().add("separator"); - checkBoxList.add(sep); - }); - modlist.getChildren().clear(); - modlist.getChildren().addAll(checkBoxList); - } -}; \ No newline at end of file diff --git a/Launcher/runtime/dialog/servers.css b/Launcher/runtime/dialog/servers.css deleted file mode 100644 index b0852e67..00000000 --- a/Launcher/runtime/dialog/servers.css +++ /dev/null @@ -1,29 +0,0 @@ -/*-- DrLeonardo Design --*/ -/* Server buttons */ - -.server-button { - -fx-font-weight: bold; - -fx-font-size: 16pt; - -fx-background-color: transparent; - -fx-background-size: cover; - -fx-background-radius: 0; - -fx-alignment: CENTER-LEFT; - -fx-padding: 0 0 0 75; - -fx-font-family: "Segoe UI"; - -fx-text-fill: #323232; - -fx-pref-width: 282px; - -fx-pref-height: 75px; -} - -.server-button:selected { - -fx-effect: dropshadow(gaussian, rgba(23, 25, 29, 0.3), 15, 0, 0, 3); -} - - -/** server-button- **/ - -.server-button-Example { - -fx-background-image: url('images/servers/example.png'); -} - -/*-- DrLeonardo Design --*/ \ No newline at end of file diff --git a/Launcher/runtime/dialog/styles.css b/Launcher/runtime/dialog/styles.css deleted file mode 100644 index c80e9a77..00000000 --- a/Launcher/runtime/dialog/styles.css +++ /dev/null @@ -1,435 +0,0 @@ -/*-- Without jfoenix --*/ -Button { - -fx-background-color: TRANSPARENT, TRANSPARENT, TRANSPARENT, TRANSPARENT; - -fx-background-radius: 3px; - -fx-background-insets: 0px; -} - -CheckBox .box-container { - -fx-shape: "M 400 100 L 400 100 A 50 50 0 1 1 400 250 A 50 50 0 1 1 400 100 "; - -fx-padding: 10; -} - -CheckBox .box, -CheckBox:indeterminate .box, -CheckBox:indeterminate:selected .box { - -fx-pref-width: 18; - -fx-pref-height: 18; - - -fx-background-color: TRANSPARENT; - -fx-background-radius: 2; - - -fx-border-color: #909090; - -fx-border-style: solid; - -fx-border-radius: 2; - -fx-border-width: 2; -} - -CheckBox:selected .box { - -fx-border-color: #5fd97a; - -fx-background-color: #5fd97a; -} - -CheckBox .mark { - -fx-background-color: TRANSPARENT; -} - -CheckBox:selected .mark { - -fx-shape: "M384 690l452-452 60 60-512 512-238-238 60-60z"; - -fx-max-width: 15; - -fx-max-height: 12; - - -fx-background-color: WHITE; - - -fx-border-color: WHITE; - -fx-border-width: 2; - -fx-border-radius: 2; -} - -CheckBox .indeterminate-mark { - -fx-background-color: #5fd97a; - -fx-background-radius: 2; - -fx-border-width: 0; - -fx-max-width: 10; - -fx-max-height: 10; -} - - -/*-- DrLeonardo Design --*/ -Button, -CheckBox, -ComboBox, -RadioButton { - -fx-cursor: hand; -} - - -/* Backgrounds */ -#layout { - -fx-background-color: transparent; - -fx-background-size: cover; - -fx-pref-width: 738px; - -fx-pref-height: 450px; - -fx-background-image: url('images/background.jpg'); -} - -#background { - -fx-background-color: #fff; -} - -/** Labels **/ -#background>#settingsTitle { - -fx-font-size: 14pt; - -fx-alignment: baseline-center; -} - -#serverLabel { - -fx-text-fill: #323232; -} - -#serverStatus { - -fx-text-fill: #323232; - -fx-pref-width: 120px; - -fx-pref-height: 25px; -} - -/* Mask */ -#mask { - -fx-effect: DropShadow(gaussian, rgba(255, 255, 255, 0.5), 0, 0, 0, 1); -} - -/** Errors **/ -#errormessage { - -fx-background-color: transparent; - -fx-text-alignment: center; - -fx-text-fill: #CE5757; -} - -.error { - -fx-text-fill: #CE5757; -} - -/* bars */ -#bar { - -fx-background-color: #323232; - -fx-pref-width: 46px; - -fx-pref-height: 450px; -} - -/** buttons in bar **/ -#close { - -fx-background-position: center; - -fx-background-radius: 0; - -fx-background-color: #CE5757; - -fx-pref-width: 46px; - -fx-pref-height: 45px; -} - -#hide, -#back, -#goConsole, -#settings, -#link_discord { - -fx-background-position: center; - -fx-background-radius: 0; - -fx-pref-width: 46px; - -fx-pref-height: 45px; -} - -#logout { - -fx-text-fill: #323232; - -fx-font-size: 12; - -fx-font-weight: normal; - -fx-border-color: #CE5757; - -fx-border-width: 1; - -fx-background-color: transparent; - -fx-padding: 0; -} - -#logout:hover, -#logout:focus { - -fx-text-fill: #ff6a5e; -} - -#logout:pressed { - -fx-border-color: #cb4d43; -} - -#send { - -fx-background-radius: 0; - -fx-text-fill: black; - -fx-background-position: center; - -fx-background-color: #ffffff; - -fx-pref-width: 150px; - -fx-pref-height: 30px; -} - -#send:pressed { - -fx-background-color: #d8d8d8; -} - -/* LoginMenu */ -#authPane { - -fx-background-color: rgba(255, 255, 255, 0.71); - -fx-pref-width: 270px; - -fx-pref-height: 450px; -} - -#logo { - -fx-background-image: url('images/icons/logo.png'); - -fx-background-repeat: no-repeat; - -fx-pref-width: 125px; - -fx-pref-height: 32px; -} - -/** Buttons & textarea**/ -.auth { - -fx-font-weight: bold; - -fx-font-size: 13pt; - -fx-background-radius: 0; - -fx-background-color: #5fd97a; - -fx-text-fill: #ffffff; - -fx-pref-width: 200px; - -fx-pref-height: 45px; - -fx-effect: dropshadow(gaussian, rgba(23, 25, 29, 0.3), 15, 0, 0, 3); -} - -.auth:hover, -.auth:pressed { - -fx-background-color: #75e18c; -} - -#password, -#login { - -fx-background-radius: 0; - -fx-pref-width: 200px; - -fx-pref-height: 30px; -} - -.text-input { - -fx-focus-color: transparent; - -fx-background-repeat: no-repeat; - -fx-text-fill: #909090; - -fx-prompt-text-fill: #909090; - -fx-background-color: transparent; - -fx-font-family: "Segoe UI"; - -fx-font-size: 13px; - -fx-font-weight: bold; -} - -/** Hyperlink **/ -#link_link { - -fx-font-weight: bold; - -fx-font-size: 7pt; - -fx-opacity: 0.5; - -fx-text-fill: #323232; - -fx-pref-width: 80px; - -fx-pref-height: 17px; -} - -#link_link:hover, -#link_link:pressed { - -fx-opacity: 0.8; -} - -/** CheckBox & ComboBox**/ -#rememberchb { - -fx-font-size: 13; - -fx-text-fill: #909090; - -fx-pref-width: 145px; - -fx-pref-height: 30px; -} - -#combologin { - -fx-text-fill: #909090; - -fx-prompt-text-fill: #909090; - -fx-pref-width: 200px; - -fx-pref-height: 30px; -} - -.combologin, -.combologin { - -fx-font-size: 13px; - -fx-prompt-text-fill: #909090; - -fx-text-fill: #909090; - -fx-background-color: transparent; -} - -.combologin .list-cell { - -fx-background: white; - -fx-background-color: transparent; - -fx-text-fill: -fx-text-base-color; -} - -.combologin-popup .list-view { - -fx-background-color: white, white; - -fx-background-insets: 0, 1; - -fx-effect: dropshadow(three-pass-box, rgba(0, 0, 0, 0.6), 8, 0.0, 0, 0); -} - -.combologin .list-cell:filled:selected .text, -.combologin .list-cell:filled:selected .text { - -fx-fill: #323232; -} - -.combologin .arrow, -.combologin .arrow { - -fx-background-color: #5fd97a; -} - -.combologin-popup .list-view .list-cell { - -fx-background-color: white; -} - -.combologin-popup .list-view .list-cell:filled:selected, -.combologin-popup .list-view .list-cell:filled:selected:hover { - -fx-background: -fx-accent; - -fx-background-color: -fx-selection-bar; - -fx-text-fill: #909090; -} - -.combologin-popup .list-view .list-cell:filled:hover { - -fx-background-color: white; - -fx-text-fill: #909090; -} - -/** web**/ -#news { - -fx-background-color: transparent; - -fx-pref-width: 423px; - -fx-pref-height: 450px; -} - -/* MenuPane */ -.serverentrance { - -fx-background-color: rgba(255, 255, 255, 0.71); - -fx-pref-width: 386px; - -fx-pref-height: 450px; -} - -/** buttons **/ -.clientLaunch { - -fx-font-weight: bold; - -fx-font-size: 16pt; - -fx-background-radius: 0; - -fx-background-color: #5fd97a; - -fx-text-fill: #ffffff; -} - -.clientSettings { - -fx-background-position: center; - -fx-background-color: #5fd97a; - -fx-background-radius: 0; -} - -.clientLaunch:hover, -.clientLaunch:pressed { - -fx-background-color: #75e18c; -} - -/* Scrolls */ -.scroll-pane { - -fx-background-color: transparent; -} - -.scroll-bar:horizontal, -.scroll-bar:vertical { - -fx-background-color: transparent; -} - -.increment-button, -.decrement-button, -.increment-arrow, -.decrement-arrow { - -fx-background-color: transparent; - -fx-border-color: transparent; -} - -.scroll-bar:horizontal .track, -.scroll-bar:vertical .track { - -fx-background-color: transparent; - -fx-border-color: transparent; -} - -.scroll-bar:horizontal .thumb, -.scroll-bar:vertical .thumb { - -fx-background-color: rgba(0, 0, 0, 0.19); - -fx-background-radius: 0; -} - -.scroll-bar { - -fx-font-size: 6px; -} - -.scroll-pane>.corner { - -fx-background-color: rgba(0, 0, 0, 0.19); -} - -/* OptionsPane */ -#optionsPane>#modlist { - -fx-background-color: transparent; -} - -#optionsPane>#modlist>.viewport { - -fx-background-color: transparent; -} - -.description-text { - -fx-font-smoothing-type: lcd; - -fx-fill: #8c8c8c; - -fx-font-size: 12px; -} - -.modname { - -fx-text-fill: #323232; -} - -.lineHead { - -fx-stroke: #d8d8d8; - -fx-stroke-width: 1; -} - -.separator *.line { - -fx-border-color: transparent; - -fx-border-width: 0 0 10 0; -} - -#serverlist { - -fx-background-color: transparent; -} - -#serverlist>.viewport { - -fx-background-color: transparent; -} - -#serverdesc { - -fx-background-color: transparent; -} - -#serverdesc>.viewport { - -fx-background-color: transparent; -} - -#serverinfo { - -fx-background-color: transparent; -} - -#serverinfo>.viewport { - -fx-background-color: transparent; -} - -#servercontainer { - -fx-background-color: transparent; - -fx-pref-width: 282px; - -fx-pref-height: 75px; -} - -.toggle-button:disabled { - -fx-opacity: 1.0; -} - -.heading { - -fx-text-fill: #555555; -} - -/*-- DrLeonardo Design --*/ \ No newline at end of file diff --git a/Launcher/runtime/engine/api.js b/Launcher/runtime/engine/api.js deleted file mode 100644 index 3374a51d..00000000 --- a/Launcher/runtime/engine/api.js +++ /dev/null @@ -1,92 +0,0 @@ -var Launcher = LauncherClass.static; -var LauncherConfig = LauncherConfigClass.static; -var HTTPRequest = HTTPRequestClass.static; -var DirBridge = DirBridgeClass.static; -var FunctionalBridge = FunctionalBridgeClass.static; - -// Hasher class API imports -var PlayerProfile = PlayerProfileClass.static; -var PlayerProfileTexture = PlayerProfileTextureClass.static; -var ClientProfile = ClientProfileClass.static; -var ClientProfileVersion = ClientProfileVersionClass.static; -var ClientLauncher = ClientLauncherClass.static; -var ClientLauncherParams = ClientLauncherParamsClass.static; -var ServerPinger = ServerPingerClass.static; - -// Request class API imports -var Request = RequestClass.static; -var RequestType = RequestTypeClass.static; -var RequestException = RequestExceptionClass.static; -//var PingRequest = PingRequestClass.static; -var AuthRequest = AuthRequestClass.static; -var JoinServerRequest = JoinServerRequestClass.static; -var CheckServerRequest = CheckServerRequestClass.static; -var UpdateRequest = UpdateRequestClass.static; -var LauncherRequest = LauncherRequestClass.static; -var ProfilesRequest = ProfilesRequestClass.static; -var SetProfileRequest = SetProfileRequestClass.static; -var ProfileByUsernameRequest = ProfileByUsernameRequestClass.static; -var ProfileByUUIDRequest = ProfileByUUIDRequestClass.static; -var BatchProfileByUsernameRequest = BatchProfileByUsernameRequestClass.static; -var GetAvailabilityAuthRequest = GetAvailabilityAuthRequestClass.static; - -// Hasher class API imports -var FileNameMatcher = FileNameMatcherClass.static; -var HashedDir = HashedDirClass.static; -var HashedFile = HashedFileClass.static; -var HashedEntryType = HashedEntryTypeClass.static; - -// Serialization class API imports -var HInput = HInputClass.static; -var HOutput = HOutputClass.static; -var StreamObject = StreamObjectClass.static; -var StreamObjectAdapter = StreamObjectAdapterClass.static; -var EnumSerializer = EnumSerializerClass.static; -var OptionalFile = OptionalFileClass.static; - -// Helper class API imports -var CommonHelper = CommonHelperClass.static; -var IOHelper = IOHelperClass.static; -var JVMHelper = JVMHelperClass.static; -var JVMHelperOS = JVMHelperOSClass.static; -var LogHelper = LogHelperClass.static; -var EnvHelper = EnvHelperClass.static; -var SecurityHelper = SecurityHelperClass.static; -var DigestAlgorithm = DigestAlgorithmClass.static; -var VerifyHelper = VerifyHelperClass.static; -var NewLauncherSettings = NewLauncherSettingsClass.static; -var SettingsManager = SettingsManagerClass.static; - -var NoHWID = NoHWIDClass.static; -var OshiHWID = OshiHWIDClass.static; - -// Helper JS class API imports -var JSApplication = null; -if (typeof JSApplicationClass !== 'undefined') { - JSApplication = JSApplicationClass.static; -} - -// API wrapper -function tryWithResources(closeable, f) { - try { - f(closeable); - } finally { - IOHelper.close(closeable); - } -} - -function newTask(r) { - return new javafx.concurrent.Task() { call: r }; -} - -function newRequestTask(request) { - return newTask(function() request.request()); -} - -function startTask(task) { - FunctionalBridge.startTask(task); -} - -function openURL(url) { - app.getHostServices().showDocument(url.toURI()); -} \ No newline at end of file diff --git a/Launcher/runtime/engine/settings.js b/Launcher/runtime/engine/settings.js deleted file mode 100644 index d37463cf..00000000 --- a/Launcher/runtime/engine/settings.js +++ /dev/null @@ -1,22 +0,0 @@ -var settingsManagerClass = Java.extend(SettingsManagerClass.static, { - getDefaultConfig: function() { - var new_settings = new NewLauncherSettings; - new_settings.login = null; - new_settings.rsaPassword = null; - new_settings.profile = 0; - - new_settings.updatesDir = DirBridge.defaultUpdatesDir; - new_settings.autoEnter = config.autoEnterDefault; - new_settings.fullScreen = config.fullScreenDefault; - new_settings.ram = config.ramDefault; - - new_settings.featureStore = config.featureStoreDefault; - new_settings.lastDigest = null; - new_settings.lastProfiles.clear(); - new_settings.lastHDirs.clear(); - return new_settings; - }, -}); - -var settingsManager = new settingsManagerClass; -var settings = SettingsManager.settings; \ No newline at end of file diff --git a/Launcher/runtime/favicon.ico b/Launcher/runtime/favicon.ico deleted file mode 100644 index 93e20afb810e68c058b37897dfb14ce362cf3e0e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 41661 zcmeI4TX0=f8OKlVY1$-BLYk&c$(>xtvt9NzUHMxuvsL z=F8e^@3q$c*7yIuZ(YxhMDq0azylHeZ;HI~QY5k}5{Yz*bSv^(5%&qB--$%3md}v6 zp?}w|T?;9cL8t?v4um=o>OiOip$>#P5b8jv1ECJ&oDR4-OBe@}K)U95!MI3k?mSyN zF_dp(m$r{{Bf1Xpa568Dgo_3S28uj!v96&K8*^=*D=rjK#^I&Q%!eh8htqLnh%AfS z+S-tHsi;h}qPn`e!jaOIqLsu|RaIP9SSnY%LR8k+*hpE2TgLHOqIftPK&O!%GSq6D zkuUPD5!EhVzPwKHYS9|eT2TYEY}qms+j~4)P2LqNR@Ca6veW@q)Cs=WP)4v>N_dD@ zhXe8{sjI77j_&KaTJmIRv|hAM)F^5xE-t=FafjkA#Zb4UF5Tmrd!3>VQM;%`)Ff&s zD=VWe@Tsn;slk4hiNGEmNSjYvB6vh`z@OCC*5X^xVK6|y8%s(`+7u(#^`ecUUQxej zK(x8AuyC{Dn?1CJ`%qC)5qbJVy}G9Cdf`P~ts=1H9XH_P(1Gsm?&1Rn4qz|vmC~>T z@W>w-89^uU8{kkS!Vh5w=reNLAlf7vklc~;Euvd>J*aq_r6I+`x(9LXCGwE>R?$`w zb$}6=f^UcLZdQ!X!)EAvmfOCnU}9nddr3*iRXp%bRtNDBWw!rC7WjVj7GKjNLT*O> zink$e#n6aoJMr4JYwz5?efyE!yLUh4rA?bQeYU5k=N^?Iugec!4ny#9*ld)|;M>pv zV=wqI+y56@Ocre~xrhgCvo?Xx#&_4K4@L&aqEkKvTfoiYdf`>ArpY&hrkv56lNWxZooh1KcR8wc`rLdH7b^upnE>B|Ovy{BSXSW_fve zjjrpZhu8#Tp*|}M^mQ0t^T;EQyctBs3(X5Q*j#UK?*YA=eg}JDY(W2l-)s_LD=Qls z8n9{fX{qCZt~ZHGx9TynrZ;1?|1_~{1xlhX8^=pX&*P_}W1$5Hn3g8bNS*$H}rt)MsfuLf(| zUQBe`U&sMGjE@qxjAgx8FdsnwhVH%h-Y?SM#>*tzX?WVTYu8Efhz|u5#u@Z;*mezm zSFy7bT_z7%#=~K;-1;c&0)K3Kl=LmKEs&9j>qv`Yi)l*A73C@C+$nJhzB}@ z?o_ECT&uW4?dVr~w(j4*|Llbe7e1V;?YVj%Of+vAS6k@wTz|s6X{Cs-{8q?fv6td}YJ$sHk%KL%hq-!gF^MHx^lYMF%Yb^AO>%4u5(g{O`@xWIx z&v1U~CiNM8{r&xSGY9tD*7@>*f!4oHiI}?t3M$j2@{_86YQA^)eMWzxG0T{kz!y8e z#d;j`UVQe)LI&{w3v2_MtrazkHng;~eB!C6o_fb`8|TU=IlhSAtIm`JVKb_CEgBcv zCWh!sn8P!kXB}wST>B>(!~=bBwqeFoN)J5z@WZdnC1XGLv4>RRAf94EDsVY=?AW(e zDdYHd?K`fv`;En_`(rkeK|HVx=HSLQ3Dwpq-m>I?A5-3u@POD+xc*eK4kz8-iIEb5BSbT(Z+`!dgxnz+7X`z z|8(inrDoNUl^{E55f2N(WPE&lLU=HqWL#M#Vh$GLvoeGSYif)u*du6fZf+iCJQy!) zAL%PkKmBxz>WI-Pr861w;6c0w#zZ##z8E!QE!OMsS#}>Z%741?Q2oe`ew;M});+sq z8{hOH`+dUq97P=bsS?R{Z+9TsC)^OUi z$NG(+Z4ee;Rasx_qskW_(7jZVx9&XJrm^2wV?uJ1-bLoDnK6wFU0X=?#Jbg=3yOhjxxnM zkJ2qWc`rztB!joT<1Fg7em!l!8__!m$jI~^8s|1>PI@>9-{h5jKcG7BdCBll7LyOz zF>Wbif6lI3q7T?8V+t>M&sv-N)~9>(#N78hudvru+EaflXuF1nhCV4?m>0tvJe&5V z**@@#$fjDtomyK9co(N7yLj()IS7F6lLP zZdC7Ln=dB6E${9TH>fXY6t8~|(zYWB}{?V@}?Jod)6g%$YOC zRSp>^vkiBa5$tK-YGkCiReqsEv7=5;x>NTdp3ND@<#%~qS>i6{-SS&%n*a4-oz;6= zWt&9kD&rmWDXsp>_T}hnZC6)UUl4xfldtaCvj_d7uS<%D&BwcHtll9j#`=trp#jN_ zvpLb2YY&+`F0Fk^&RM&1G0)=a*{m`*Z`rbCEJ*v9e=*)vSu+n&Yr&Rr)Vd8T&$~dc5R#D7}C8#KlhYp$mO$TV#?_r z&!J(?GX`nn*x1;oRgOJ5*G|r7ro~3|4g#{IKU{tC+-vME-$frMm?Ni z4AREq$B&<}zZqhzVf;Xv@i6_Xe%c~;`J*7L9y)ZW*B-q@?UM#O%q`LM=FTAR$!6YD zr%t_~hSk|2py?(v00+aldUfSL^V@d0)_j4{@xSuE+1YvY8K=h;N2~ znKBROuIhsf2Q}sRqj&@l+^R48kY3SU6`*T+*RQfEXTR^(vgB{Xv$Ky(xht?=EgAjI zFQ4*lud0k0cKGc+93J>Ml|SqEUD?csOz1xBvC=}?kVb!HhFA7ob@Cy;mk^~l;K7u| zw|yutfp?b3FE5EcM1J`_e%^wNoZh7y54$b7Du^E1evV-vLuF&fiv0xepkFN4`*OYy z0T1z7gH7A?bP6mL^Ld36Ejuexd*#w5wQSf-|X-Te|9z51$sV z$S3Lp(&(@B8Y7!h#Z^J@V3|v0nnX;s;n&v~OZi+VP#^TEbjdMQ^~yeeVVC&PA#^D% zQ*$u3b?4cwgG%Y^ul=?|viyt6w~N?rXL=vq9?*5NK)cNHqVzBDcB)?ny(nJu zB`<>o4NJ3q@E&Y&g_ffN{j8?Fy`3Zb4WcTqe^uIV$dk+#eY`Lga-XXX;qkm06UBmt zr5O)ifv+jk()pL?;w#a8Ewvp{xfT)QUN?W$rT?HY%c$y}$W?;B_|{|qk96zI;Q_nwUmDbBX>RzA%CYU*BWe|K6eQD_Aa};?9Lrf| z*W^m=+$uV^*0V*24B|nXiZteac|Lnc^h{%c=e11@CL2W#lPW70*0-oT9RXiU-3ABu zX+Wjfo56Ro*T(uo$}q_k9@f?iv}N3pNapk1lTEpwMs8Ny!K6+72}jA032VT}3;T1Q zYtrSSg2SQE+5qoh%*}cMKRIi%@oN1RRq}mlKKUnl#?M)FbYP#V zalY#&U9;xMe9`G?k=;i?p3p)9<-iuZE3-DiJD3NxiMrLFp%dMr77_jvtWwgaWfBkZ zY}%^1dV3<7C%Z>qqP>Ehs%MMs<2hp0Y>yaXE9LAZc>FrPCK)#Fd4XNqD^VHt!NAyk zmaa+1;>>X_{HAD&C~B+9XE1S}?o*mN7Zfs#hp`bcTDTA!0WS|Gx2T?etE=sHj)FhI zw{u(+AA?+xFa8XD$InCVy2xTzV*4W2WhhG>$e1IJ*x?3|`ILv^Z93llU2Cgg(xYQ- zZB{3|zH32!TBh+3|Ac(|bC#H&+$6IP_Z&>@C&4)C#=0YO6l8|%nrz>~xeersFG0rT z_FN4zcZ3b73oxG$BQIsv@;L?B19hzz^^17NAV;~hH*Y@4==8$biOMj}Kp%KlsmE_B z=|5xx54{t6&exvE=bem$#_CVZr>7*3AkA4MQ@avrJ4q!gSaW~%Sz&4T%Jj5r#>`|zF zfq#bQm5F}(_Nx8dBu6%#z2HasB-c%f(Q!UUjsNcuq4&t0G{>vKZUY#Iz<{#&!aEo@RV{c`xhOR4`5yR!lRB}~4uP+9mXhy9@U5Z8Xn1kIy*|Dex! z(Wfuy=chT~uVz7+8FPIvs0?x~zt(@p)hPT_AYX+batRM?1fJBtPv)A8{qh6vc0Hb^ z1P-}`hhrXG)c%zACw}F*n0)fLr`3kQHsRV$oQrrk{w`j;c$?&t(`TqGeph4@z2bXO zSmZh$@TYb*sm)W1(c3hay$p}=nu?Ii_Tg=x+B~+{d1ESZ5ieIJCnpbkc}&IiQo)0^ z3X_$#ug|6ry8;jNajB4hd>u;(568R1C6o5z>>-uD$+gEDFGW1O{7XKg@3!CTA<%RYYD*Jnty{x*%sMFP-srY)qBVJy}Qq*fP;!O2( z$T^O<$ET~!XREUz|9HOBg-2L#dOmv*$~Ba0r~{!6ggOxFK&S(u4um=o>OiOip$>#P z5b8jv1ECItIuPo>64C*&IuovHVbWa_XD$8T62nIH{gaVKFF(4^Z`h*zO^NRjPnz}B z%GvZsq^Z%?_aD+!VAIp2BNNf|lu3_7(xi#=NZ6~rzgz&rXvNmzM1sZ z6sJ{x41Y9ahF|wSmyYrulmDvnPniPlc|^igu=1k))1+tRZ8ADMBs=6wFzro{ZZuD4 zpMxL4kC)*i%Kr8pk326Y+xXe^^vv_9y~L+gHzE4mYD2U>i*__^r9GP-HRYrHSq7r~8@9amZeAFbhp~kj tna%J&^C2x{>e5qsfvSt9RRP7LX>llSX4BWEk)|h2Lc!HHlUkbT{{ttI`6U1V diff --git a/Launcher/runtime/favicon.png b/Launcher/runtime/favicon.png deleted file mode 100644 index 683659f9652071d3af890ef85eebb4b998d5b666..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4829 zcmai2XEElpLUi{9?Pc9Zzx z>Aslq=%QnXY8vSR0RG$nz{@ZI0DpebuLA%^Hv!k^%>V#M8US$HZQO$G^~G3HcTICI z0Dv6$U%M7!_iy6GM@G1s8Qj>-9`0-72?My>I6a38J%_>BC4@wU#N)XL4gkO{MJ-jO zM}F2j*^>#NaqlR3&|qJVN({)uu@d_HRxguLvW|!J0p~+B*r^;L%0G4d!FR830!%!YB8D-*3 zNe#vsc4~g;lYUbxZZ|BaPO(O_+8|@r00N~Rlb+s;iH1F-Hr_B4&X0b5?M%q+HP2#& z|9$ACaT@Z=Cx=^XhM`$J{A3?F-ff$vzMG9RuRjn;VI2Wl&6g-!57A>ba0d8nwBo&Y z%R6S_7beB5V+_(KJhCF5`}BM&fLZf>rQ^EX7)uAsweO!tlR?s6s~}4SA5{+HY%je` zrned?d42xMq}89p;r#5^%9nG>!1}=qA?>3)BuK_HDrQtKV@|+o=S`iBSK)zuiSY=n?pNgMsK$S z=MBUG-73v%SCh2Gr5^;E5x3}LgKXWdhf!)AH)*VG(`R=y_8O8D$sR8!>7O~>L%!JS zx*bycd={gEdH(5m;SKl0)Qt)7DpG~(Srj$f^T(lcy|=3=oSo;8$hWCW;ma@ckw~N! zWS3?dA}ial`B5!UlY*?pEhRV$>ANwLW2>3h_}eCd)J-=3ru@2v%{ev}B=?4R&eRWw`EYkr=7c-8{ zJZF7pXGQk2#~^WNVf}Xyix&CX;xds$7~U~@@Hjje8|}Lhe8;;;#z++pKU~Gg%`qxf(q4Dyz z#P>TzYH(bWM*;z}Mq9eXOHD*XM6K>HQ{l4S?;&xt$#dc@NY8?}gzop~U~tmDfdwKBqa%REe=Dhpa>!lD%{9BN9d?( zr+bx^XP>+(EQX@S-2EK3Ik6%2(G5o+yNcv$)suQ04tG~AYU;;%Ox>H7SNC%>Kbe-( zF;YX}c9}7y%-qr%3)yokU(%B9AHA*ZKAwg?5-TVex;aR5SFB{4;wr{8tc%ERjM+Vl zh5h7QZuJ${RYj%LNvfm9soNfgK61$?|tKu7T<4? zV;6B9Y0yeFAkzY6YDVns?MXTE!{rCx?o-r>)t?$?0>}A!MWu^*)yY#{DnvqK`Z3Z( zHLe>r{PGm}#J*+q=UFf~^$Dd_T4w2T9OhdeGnZ=YO=L8EzU;{3v3t~4q@vg39u7dChd}H9`mQbls%va;^*ZbUCuD#1o?Ze$Z#aoan4J80=)nF$ zmf^xqF=aDf6m;%6)2s^aAP;){4PAHinBsaFP^W8B9?vVISb-YSO}TE*ZOFRT=8|(~@5h;V1QW zpDiv9&k!{>x(j<;WliuEFlNZ4I8z?4mTT*Yks%qdW^zh1R(xJOtK&F|Kk`tj9hS1V zbi`1Ei+D$1>Gl5F(7C~QwR;a&wYXlVGmxySF(;;n+;nOnoO79F?>m(ZX5FJ!>IfJ83dVdKs#9|sL zmm6}1mugh6?z6Cu4&QfQ;4I!(#KW^FWtJQIT-b)(Z3SAL>zwq-jW?7QZO`7Dl!I-aoGvgXL4< z^SmjCK+Z^-S#jy`cnZw8qS?m%JI$mR=ogwtBypr9@r=zZn*41#} zEclDeu*rRwvRf&crxyq(gjPcR^7>?If$d51EFUNPo=w+NnrHla%jS20(|BQbM~pv) zOC~Si(A(Fy7Rcq?UKjD>~8Cd?bMigIlwX7aBZd^kS)>xmGHPy0-*+kA^?8Hjb0 zcYbGcvtThCSA=|oVsb-&)Jm}5?7w>-tqy|?F11IHzk^#jK2b{y?^0#S*h9~tAqudW z(aFhP;;rjhWdeENjoKIeIeAF)3GyarV4$UW{TG{j1<8u>2<)(Jx5MU5sW#0SIH7h( z;S?s|#md}rraE4eBw|kW?4g2ETg4j>29c~_JwjmInpjEGv zTsVltJvhTg9;6ujM?21r-=H||>a6G}x&~5zE$i1Eqf#0!5 zZx&FH#FT1%b6t~-oOCRbB|vL@-w(1~1f1a0oI|Qz1V>yr(&|9;{lo{Skux#!cv6`a zzvwm2+6%peRILAHp*o{m3;xaKI`^?S;lpJPc(X1pDR2OO<*+=hm#0855vWx|{rqff z!x+5k;tVdjclI510A4KANN6e8Vyc*BI%Usn(a!kgBiR1P-!420x9aIN)!#;W=YE_B zRfCvi#GOA{5+##-q#=(?thLXj#MCt=T)I_cSJ`T`s{Rr+FixYEp6A&seA{fyn=12+ z%1F+YZkMX&?(p{<1@=iHl=>S9?>A*DOU2hhxaD#OcO}dI&ZNyA?p^AW?w&^n6HW}z z!lAGx<{JD7T=NBk+R@66s<9_A%;eUm+QKsF_n)|@?mh8O*QQn(c8oPYB_4S0tMGdQ z%3IMt9+TO;rR`#xDXiALZ_4Tn`!Uy?AXfO;Xp2GEx=F6q(lhodT}0Ak!gu=%GH7r$ zJGgCvaQQ!@WV-2*xeYsj^0Xe{c5wE$$WIp%E!aw{CRR~ZW3#`)u<(*SZEi|t@Yx(n zsYZWvS?Z2w8&lnoGF9qh#|GBsB1@ydFVS~pOmm{CA~BOBZVhS;SDNT1lcr(2#n&jh zZk3LXj=WUStzSN@oRO<)KY8Y zvT(k9f?Zo8j<^shzo|cH7LiFMt$}4DowE+o370Zc`NL}6)Gq^RsGQbI@i{5v_u@5; z7+;+WwT-#l-;iBZOT+SD={vb}a=e>3X;7s7T+>{_XQPFL1Y45U=a?PPs&Z* zM;=gvcv}CDDEWM6yVJHfdN93~N=bQN4TZJ%RwXL8Psfv>0#Anw%f(e2yW85@nu0p` z|M_%F9Qkyg#Zc+`$eQTT(;L1{GiMeMu{T%HH3nK?)kVpaLs77Y`19+!W@`aeGhmB} zPKLSdk|jiDy#BA>UoX_d_#vCIbZ8Eu=_oB=J-BHH9#T%%-;&Wktcq)@jFWxLI8{Ow zxGT#=TK0BNi@7eoF7LozssQE!G98Ya9ON_#F$@n>L8b2F2fB{YFtMLuMx_PJ*^DbpzZk zCA}qLQdn0F!5CWOC+>t`X5nChKa%`oOhU~nhpa^x#g9mfc_|<%PknAUiJ=x)eFe0c z91ZTGKmum!`c;R8w>G5j{jYA^S+WV%7CH6u*iVOCNGLnFC$dQ^w5N8y}e&4YJ zBgEQSdVrEJ1UQXba)AG-&-7Xn3aaF$9M;Z}q<@J>7uDdpDgf-YMD#rM7y+F=EF_|? z*6H_+v6=-t*olXW?AKUmu1SP7*CciKiU{cSTrmXhK`#V_4u!BL<$GA1fP!zUPM6EF z3twedS}idl>~i^m4B?x^72-eGIbXi~zgIAet0ZUCjHd%K_?+T_i|ZzUmYSYwrSj8P F{{x0ER bindings) { - bindings.put("LauncherClass", Launcher.class); - bindings.put("LauncherConfigClass", LauncherConfig.class); - bindings.put("HTTPRequestClass", HTTPRequest.class); - bindings.put("SettingsManagerClass", SettingsManager.class); - bindings.put("NewLauncherSettingsClass", NewLauncherSettings.class); - - // Set client class bindings - bindings.put("PlayerProfileClass", PlayerProfile.class); - bindings.put("PlayerProfileTextureClass", Texture.class); - bindings.put("ClientProfileClass", ClientProfile.class); - bindings.put("ClientProfileVersionClass", ClientProfile.Version.class); - bindings.put("ClientLauncherClass", ClientLauncher.class); - bindings.put("ClientLauncherParamsClass", ClientLauncher.Params.class); - bindings.put("ServerPingerClass", ServerPinger.class); - - // Set request class bindings - bindings.put("RequestClass", Request.class); - bindings.put("RequestTypeClass", RequestType.class); - bindings.put("RequestExceptionClass", RequestException.class); - bindings.put("PingRequestClass", PingRequest.class); - bindings.put("AuthRequestClass", AuthRequest.class); - bindings.put("JoinServerRequestClass", JoinServerRequest.class); - bindings.put("CheckServerRequestClass", CheckServerRequest.class); - bindings.put("UpdateRequestClass", UpdateRequest.class); - bindings.put("LauncherRequestClass", LauncherRequest.class); - bindings.put("SetProfileRequestClass", SetProfileRequest.class); - bindings.put("ProfilesRequestClass", ProfilesRequest.class); - bindings.put("ProfileByUsernameRequestClass", ProfileByUsernameRequest.class); - bindings.put("ProfileByUUIDRequestClass", ProfileByUUIDRequest.class); - bindings.put("BatchProfileByUsernameRequestClass", BatchProfileByUsernameRequest.class); - bindings.put("GetAvailabilityAuthRequestClass", GetAvailabilityAuthRequest.class); - - // Set hasher class bindings - bindings.put("FileNameMatcherClass", FileNameMatcher.class); - bindings.put("HashedDirClass", HashedDir.class); - bindings.put("HashedFileClass", HashedFile.class); - bindings.put("HashedEntryTypeClass", HashedEntry.Type.class); - - // Set serialization class bindings - bindings.put("HInputClass", HInput.class); - bindings.put("HOutputClass", HOutput.class); - bindings.put("StreamObjectClass", StreamObject.class); - bindings.put("StreamObjectAdapterClass", StreamObject.Adapter.class); - bindings.put("EnumSerializerClass", EnumSerializer.class); - bindings.put("OptionalFileClass", OptionalFile.class); - bindings.put("UserSettingsClass", UserSettings.class); - - // Set helper class bindings - bindings.put("CommonHelperClass", CommonHelper.class); - bindings.put("IOHelperClass", IOHelper.class); - bindings.put("EnvHelperClass", EnvHelper.class); - bindings.put("JVMHelperClass", JVMHelper.class); - bindings.put("JVMHelperOSClass", JVMHelper.OS.class); - bindings.put("LogHelperClass", LogHelper.class); - bindings.put("LogHelperOutputClass", LogHelper.Output.class); - bindings.put("SecurityHelperClass", SecurityHelper.class); - bindings.put("DigestAlgorithmClass", SecurityHelper.DigestAlgorithm.class); - bindings.put("VerifyHelperClass", VerifyHelper.class); - bindings.put("DirBridgeClass", DirBridge.class); - bindings.put("FunctionalBridgeClass", FunctionalBridge.class); - - bindings.put("NoHWIDClass", NoHWID.class); - bindings.put("OshiHWIDClass", OshiHWID.class); - - // Load JS API if available - try { - Class.forName("javafx.application.Application"); - bindings.put("JSApplicationClass", JSApplication.class); - } catch (ClassNotFoundException ignored) { - LogHelper.warning("JavaFX API isn't available"); - } - } - - @LauncherAPI - public Object loadScript(String path) throws IOException, ScriptException { - URL url = Launcher.getResourceURL(path); - LogHelper.debug("Loading script: '%s'", url); - try (BufferedReader reader = IOHelper.newReader(url)) { - return engine.eval(reader, engine.getBindings(ScriptContext.ENGINE_SCOPE)); - } - } - - private void setScriptBindings() { - LogHelper.info("Setting up script engine bindings"); - Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE); - bindings.put("launcher", this); - - // Add launcher class bindings - JSRuntimeProvider.addLauncherClassBindings(bindings); - } - - @Override - public void run(String[] args) throws ScriptException, NoSuchMethodException, IOException { - preLoad(); - loadScript(Launcher.INIT_SCRIPT_FILE); - LogHelper.info("Invoking start() function"); - LauncherEngine.modulesManager.invokeEvent(new ClientGuiPhase(this)); - ((Invocable) engine).invokeFunction("start", (Object) args); - LauncherEngine.modulesManager.invokeEvent(new ClosePhase()); - } - - @Override - public void preLoad() throws IOException, ScriptException { - if (!isPreLoaded) { - loadScript(Launcher.API_SCRIPT_FILE); - loadScript(Launcher.CONFIG_SCRIPT_FILE); - isPreLoaded = true; - } - } - - @Override - public void init(boolean clientInstance) { - setScriptBindings(); - } -} diff --git a/Launcher/src/main/java/pro/gravit/launcher/gui/NoRuntimeProvider.java b/Launcher/src/main/java/pro/gravit/launcher/gui/NoRuntimeProvider.java new file mode 100644 index 00000000..9f3b6af8 --- /dev/null +++ b/Launcher/src/main/java/pro/gravit/launcher/gui/NoRuntimeProvider.java @@ -0,0 +1,20 @@ +package pro.gravit.launcher.gui; + +import javax.swing.*; + +public class NoRuntimeProvider implements RuntimeProvider { + @Override + public void run(String[] args) throws Exception { + JOptionPane.showMessageDialog(null, "GUI часть лаунчера не найдена.\nС 5.1.0 вам необходимо самостоятельно установить модуль, отвечающий за GUI. Рантайм на JS более не поддерживается"); + } + + @Override + public void preLoad() throws Exception { + + } + + @Override + public void init(boolean clientInstance) { + + } +} From fd54f4739fa3571c14ec230d7c84a210af3f6ac1 Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 4 Dec 2019 22:45:24 +0700 Subject: [PATCH 100/192] =?UTF-8?q?[FEATURE]=20=D0=A3=D0=B4=D0=B0=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BB=D0=B8=D1=88=D0=BD=D0=B5=D0=B3?= =?UTF-8?q?=D0=BE=20=D0=BA=D0=BE=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launcher/LauncherEngine.java | 2 - .../launcher/client/ClientLauncher.java | 9 +- .../launcher/client/ClientProcessBuilder.java | 2 +- .../pro/gravit/launcher/client/DirBridge.java | 2 + .../launcher/client/FunctionalBridge.java | 144 ------------------ 5 files changed, 11 insertions(+), 148 deletions(-) delete mode 100644 Launcher/src/main/java/pro/gravit/launcher/client/FunctionalBridge.java diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index 87c67a80..0f9d5895 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -166,8 +166,6 @@ public void start(String... args) throws Throwable { LauncherEngine.modulesManager.invokeEvent(new ClientEngineInitPhase(this)); runtimeProvider.preLoad(); LauncherGuardManager.initGuard(false); - FunctionalBridge.getHWID = CommonHelper.newThread("GetHWID Thread", true, FunctionalBridge::getHWID); - FunctionalBridge.getHWID.start(); LogHelper.debug("Dir: %s", DirBridge.dir); runtimeProvider.run(args); } diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index 4171e7ca..c0ce62b8 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -10,6 +10,7 @@ import pro.gravit.launcher.hasher.FileNameMatcher; import pro.gravit.launcher.hasher.HashedDir; import pro.gravit.launcher.hwid.HWIDProvider; +import pro.gravit.launcher.hwid.OshiHWIDProvider; import pro.gravit.launcher.managers.ClientGsonManager; import pro.gravit.launcher.managers.ClientHookManager; import pro.gravit.launcher.modules.events.PreConfigPhase; @@ -48,6 +49,12 @@ import java.util.stream.Stream; public final class ClientLauncher { + + @LauncherAPI + public static int getClientJVMBits() { + return LauncherGuardManager.guard.getClientJVMBits(); + } + private static final class ClassPathFileVisitor extends SimpleFileVisitor { private final Stream.Builder result; @@ -327,7 +334,7 @@ public static Process launch( context.playerProfile = params.pp; context.args.add(javaBin.toString()); context.args.add(MAGICAL_INTEL_OPTION); - if (params.ram > 0 && params.ram <= FunctionalBridge.getJVMTotalMemory()) { + if (params.ram > 0) { context.args.add("-Xms" + params.ram + 'M'); context.args.add("-Xmx" + params.ram + 'M'); } diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientProcessBuilder.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientProcessBuilder.java index f658b4fb..c51b3938 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientProcessBuilder.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientProcessBuilder.java @@ -88,7 +88,7 @@ public ClientLauncherContext build() throws IOException { context.args.add(MAGICAL_INTEL_OPTION); context.params = params; if(paramsWriter != null) paramsWriter.write(context); - if (params.ram > 0 && params.ram <= FunctionalBridge.getJVMTotalMemory()) { + if (params.ram > 0) { context.args.add("-Xms" + params.ram + 'M'); context.args.add("-Xmx" + params.ram + 'M'); } diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/DirBridge.java b/Launcher/src/main/java/pro/gravit/launcher/client/DirBridge.java index 6e4ff2dd..f33fe32e 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/DirBridge.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/DirBridge.java @@ -106,6 +106,8 @@ public static void setUseLegacyDir(boolean b) { try { DirBridge.dir = getLauncherDir(projectName); if (!IOHelper.exists(DirBridge.dir)) Files.createDirectories(DirBridge.dir); + DirBridge.defaultUpdatesDir = DirBridge.dir.resolve("updates"); + if (!IOHelper.exists(DirBridge.defaultUpdatesDir)) Files.createDirectories(DirBridge.defaultUpdatesDir); DirBridge.dirStore = getStoreDir(projectName); if (!IOHelper.exists(DirBridge.dirStore)) Files.createDirectories(DirBridge.dirStore); DirBridge.dirProjectStore = getProjectStoreDir(projectName); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/FunctionalBridge.java b/Launcher/src/main/java/pro/gravit/launcher/client/FunctionalBridge.java deleted file mode 100644 index 9b42be65..00000000 --- a/Launcher/src/main/java/pro/gravit/launcher/client/FunctionalBridge.java +++ /dev/null @@ -1,144 +0,0 @@ -package pro.gravit.launcher.client; - -import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.LauncherAPI; -import pro.gravit.launcher.api.AuthService; -import pro.gravit.launcher.events.request.AuthRequestEvent; -import pro.gravit.launcher.guard.LauncherGuardManager; -import pro.gravit.launcher.hasher.FileNameMatcher; -import pro.gravit.launcher.hasher.HashedDir; -import pro.gravit.launcher.hwid.HWID; -import pro.gravit.launcher.hwid.OshiHWIDProvider; -import pro.gravit.launcher.managers.ConsoleManager; -import pro.gravit.launcher.managers.HasherManager; -import pro.gravit.launcher.managers.HasherStore; -import pro.gravit.launcher.request.Request; -import pro.gravit.utils.Version; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.LogHelper; -import pro.gravit.utils.helper.SecurityHelper; - -import java.nio.file.Path; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; - -public class FunctionalBridge { - @LauncherAPI - public static final ScheduledExecutorService threadPool = Executors.newScheduledThreadPool(0); - @LauncherAPI - public static OshiHWIDProvider hwidProvider; - @LauncherAPI - public static final AtomicReference hwid = new AtomicReference<>(); - @LauncherAPI - public static Thread getHWID = null; - - private static long cachedMemorySize = -1; - - @LauncherAPI - public static HashedDirRunnable offlineUpdateRequest(String dirName, Path dir, HashedDir hdir, FileNameMatcher matcher, boolean digest) { - return () -> { - if (hdir == null) { - Request.requestError(java.lang.String.format("Директории '%s' нет в кэше", dirName)); - } - ClientLauncher.verifyHDir(dir, hdir, matcher, digest); - return hdir; - }; - } - - @LauncherAPI - public static void startTask(Runnable task) { - threadPool.execute(task); - } - - @LauncherAPI - public static HWID getHWID() { - HWID hhwid = hwid.get(); - if (hhwid == null) { - if (hwidProvider == null) hwidProvider = new OshiHWIDProvider(); - hwid.set(hwidProvider.getHWID()); - } - return hhwid; - } - - @LauncherAPI - public static long getTotalMemory() { - if (cachedMemorySize > 0) return cachedMemorySize; - if (hwidProvider == null) hwidProvider = new OshiHWIDProvider(); - return (cachedMemorySize = hwidProvider.getTotalMemory() >> 20); - } - - @LauncherAPI - public static int getClientJVMBits() { - return LauncherGuardManager.guard.getClientJVMBits(); - } - - @LauncherAPI - public static long getJVMTotalMemory() { - if (getClientJVMBits() == 32) { - return Math.min(getTotalMemory(), 1536); - } else { - return getTotalMemory(); - } - } - - @LauncherAPI - public static HasherStore getDefaultHasherStore() { - return HasherManager.getDefaultStore(); - } - - @LauncherAPI - public static void registerUserSettings(String typename, Class clazz) { - UserSettings.providers.register(typename, clazz); - } - - @LauncherAPI - public static void close() throws Exception { - threadPool.awaitTermination(2, TimeUnit.SECONDS); - } - - @LauncherAPI - public static void setAuthParams(AuthRequestEvent event) { - if (event.session != 0) { - Request.setSession(event.session); - } - LauncherGuardManager.guard.setProtectToken(event.protectToken); - AuthService.permissions = event.permissions; - if (event.playerProfile != null) { - AuthService.username = event.playerProfile.username; - AuthService.uuid = event.playerProfile.uuid; - } - } - - @FunctionalInterface - public interface HashedDirRunnable { - HashedDir run() throws Exception; - } - - @LauncherAPI - public static void evalCommand(String cmd) { - ConsoleManager.handler.eval(cmd, false); - } - - @LauncherAPI - public static void addPlainOutput(LogHelper.Output output) { - LogHelper.addOutput(output, LogHelper.OutputTypes.PLAIN); - } - - @LauncherAPI - public static String getLauncherVersion() { - return String.format("GravitLauncher v%d.%d.%d build %d", - Version.MAJOR, - Version.MINOR, - Version.PATCH, - Version.BUILD - ); - } - - @LauncherAPI - public static byte[] encryptPassword(String string) throws Exception { - byte[] encode = IOHelper.encode(string); - return SecurityHelper.encrypt(Launcher.getConfig().passwordEncryptKey, encode); - } -} From 1086153945352cfbbba5e756eae16ac5a1b6f0ae Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Wed, 4 Dec 2019 16:58:03 +0100 Subject: [PATCH 101/192] =?UTF-8?q?[ANY]=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B8?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index 2b97b396..3cf0cb41 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 2b97b3967750625a89d28a243723a26af1114481 +Subproject commit 3cf0cb41a64b1f05d76bdc67f83d67d80ebe41f1 From 03471e8bbf80fb46f4c0b305161773f69eafe850 Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 4 Dec 2019 23:08:36 +0700 Subject: [PATCH 102/192] =?UTF-8?q?[FEATURE]=20=D0=A3=D0=B4=D0=B0=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20ListDownloader?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launcher/LauncherEngine.java | 1 - .../client/LauncherUpdateController.java | 31 +- .../launcher/downloader/ListDownloader.java | 252 ---------------- .../request/update/LauncherRequest.java | 11 +- .../request/update/UpdateRequest.java | 277 +----------------- modules | 2 +- 6 files changed, 13 insertions(+), 561 deletions(-) delete mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index 0f9d5895..ae9c10f8 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -158,7 +158,6 @@ public void start(String... args) throws Throwable { } }; } - if (UpdateRequest.getController() == null) UpdateRequest.setController(new LauncherUpdateController()); Objects.requireNonNull(args, "args"); if (started.getAndSet(true)) throw new IllegalStateException("Launcher has been already started"); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java b/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java index 4fbdf4ff..62c1e1e5 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java @@ -1,7 +1,6 @@ package pro.gravit.launcher.client; import pro.gravit.launcher.NewLauncherSettings; -import pro.gravit.launcher.downloader.ListDownloader; import pro.gravit.launcher.events.request.UpdateRequestEvent; import pro.gravit.launcher.hasher.HashedDir; import pro.gravit.launcher.hasher.HashedEntry; @@ -17,21 +16,10 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.List; import java.util.concurrent.atomic.AtomicReference; +@Deprecated +public class LauncherUpdateController { -public class LauncherUpdateController implements UpdateRequest.UpdateController { - @Override - public void preUpdate(UpdateRequest request, UpdateRequestEvent e) { - - } - - @Override - public void preDiff(UpdateRequest request, UpdateRequestEvent e) { - - } - - @Override public void postDiff(UpdateRequest request, UpdateRequestEvent e, HashedDir.Diff diff) throws IOException { if (e.zip && e.fullDownload) return; if (SettingsManager.settings.featureStore) { @@ -116,19 +104,4 @@ public Path tryFind(NewLauncherSettings.HashedStoreEntry en, HashedFile file) th }); return ret.get(); } - - @Override - public void preDownload(UpdateRequest request, UpdateRequestEvent e, List adds) { - - } - - @Override - public void postDownload(UpdateRequest request, UpdateRequestEvent e) { - - } - - @Override - public void postUpdate(UpdateRequest request, UpdateRequestEvent e) { - - } } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java b/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java deleted file mode 100644 index 741cdf3f..00000000 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java +++ /dev/null @@ -1,252 +0,0 @@ -package pro.gravit.launcher.downloader; - -import org.apache.http.HttpResponse; -import org.apache.http.client.ResponseHandler; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.impl.client.LaxRedirectStrategy; -import pro.gravit.utils.helper.CommonHelper; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.LogHelper; -import pro.gravit.utils.helper.VerifyHelper; - -import java.io.EOFException; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.concurrent.*; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; - -public class ListDownloader { - private static final AtomicInteger COUNTER_THR = new AtomicInteger(0); - private static final ThreadFactory FACTORY = r -> CommonHelper.newThread("Downloader Thread #" + COUNTER_THR.incrementAndGet(), true, r); - - private static ExecutorService newExecutor() { - return new ThreadPoolExecutor(0, VerifyHelper.verifyInt(Integer.parseInt(System.getProperty("launcher.downloadThreads", "3")), VerifyHelper.POSITIVE, "Thread max count must be positive."), 5, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), FACTORY); - } - - @FunctionalInterface - public interface DownloadCallback { - void stateChanged(String filename, long downloadedSize, long size); - } - - @FunctionalInterface - public interface DownloadTotalCallback { - void addTotal(long size); - } - - public static class DownloadTask { - public final String apply; - public long size; - public final String urlApply; - - public DownloadTask(String apply, long size) { - this.apply = apply; - urlApply = apply; - this.size = size; - } - - public DownloadTask(String urlApply, String apply, long size) { - this.apply = apply; - this.urlApply = urlApply; - this.size = size; - } - } - - public void download(String base, List applies, Path dstDirFile, DownloadCallback callback, DownloadTotalCallback totalCallback) throws IOException, URISyntaxException { - try (CloseableHttpClient httpclient = HttpClients.custom().setUserAgent(IOHelper.USER_AGENT) - .setRedirectStrategy(new LaxRedirectStrategy()) - .build()) { - applies.sort(Comparator.comparingLong(a -> a.size)); - List> toExec = new ArrayList<>(); - URI baseUri = new URI(base); - String scheme = baseUri.getScheme(); - String host = baseUri.getHost(); - int port = baseUri.getPort(); - if (port != -1) - host = host + ":" + port; - String path = baseUri.getPath(); - List excs = new CopyOnWriteArrayList<>(); - for (DownloadTask apply : applies) { - URI u = new URI(scheme, host, path + apply.urlApply, "", ""); - callback.stateChanged(apply.apply, 0L, apply.size); - Path targetPath = dstDirFile.resolve(apply.apply); - toExec.add(() -> { - if (LogHelper.isDebugEnabled()) - LogHelper.debug("Download URL: %s to file %s dir: %s", u.toString(), targetPath.toAbsolutePath().toString(), dstDirFile.toAbsolutePath().toString()); - try { - httpclient.execute(new HttpGet(u), new FileDownloadResponseHandler(targetPath, apply, callback, totalCallback, false)); - } catch (IOException e) { - excs.add(e); - } - return null; - }); - } - try { - ExecutorService e = newExecutor(); - e.invokeAll(toExec); - e.shutdown(); - e.awaitTermination(4, TimeUnit.HOURS); - } catch (InterruptedException t) { - LogHelper.error(t); - } - if (!excs.isEmpty()) { - IOException toThrow = excs.remove(0); - excs.forEach(toThrow::addSuppressed); - throw toThrow; - } - } - } - - public void downloadZip(String base, List applies, Path dstDirFile, DownloadCallback callback, DownloadTotalCallback totalCallback, boolean fullDownload) throws IOException { - /*try (CloseableHttpClient httpclient = HttpClients.custom() - .setRedirectStrategy(new LaxRedirectStrategy()) - .build()) { - HttpGet get; - URI u = new URL(base).toURI(); - LogHelper.debug("Download ZIP URL: %s", u.toString()); - get = new HttpGet(u); - httpclient.execute(get, new FileDownloadResponseHandler(dstDirFile, callback, totalCallback, true)); - }*/ - try (ZipInputStream input = IOHelper.newZipInput(new URL(base))) { - for (ZipEntry entry = input.getNextEntry(); entry != null; entry = input.getNextEntry()) { - if (entry.isDirectory()) - continue; // Skip directories - // Unpack entry - String name = entry.getName(); - callback.stateChanged(name, 0L, entry.getSize()); - LogHelper.subInfo("Downloading file: '%s'", name); - if (fullDownload || applies.stream().anyMatch((t) -> t.apply.equals(name))) { - Path fileName = IOHelper.toPath(name); - transfer(input, dstDirFile.resolve(fileName), fileName.toString(), entry.getSize(), callback, totalCallback); - } - } - } - } - - public void downloadOne(String url, Path target) throws IOException, URISyntaxException { - try (CloseableHttpClient httpclient = HttpClients.custom() - .setRedirectStrategy(new LaxRedirectStrategy()) - .build()) { - - HttpGet get; - URI u = new URL(url).toURI(); - if (LogHelper.isDebugEnabled()) { - LogHelper.debug("Download URL: %s", u.toString()); - } - get = new HttpGet(u); - httpclient.execute(get, new FileDownloadResponseHandler(target.toAbsolutePath())); - } - } - - static class FileDownloadResponseHandler implements ResponseHandler { - private final Path target; - private final DownloadTask task; - private final DownloadCallback callback; - private final DownloadTotalCallback totalCallback; - private final boolean zip; - - public FileDownloadResponseHandler(Path target) { - this.target = target; - this.task = null; - this.zip = false; - callback = null; - totalCallback = null; - } - - public FileDownloadResponseHandler(Path target, DownloadTask task, DownloadCallback callback, DownloadTotalCallback totalCallback, boolean zip) { - this.target = target; - this.task = task; - this.callback = callback; - this.totalCallback = totalCallback; - this.zip = zip; - } - - public FileDownloadResponseHandler(Path target, DownloadCallback callback, DownloadTotalCallback totalCallback, boolean zip) { - this.target = target; - this.task = null; - this.callback = callback; - this.totalCallback = totalCallback; - this.zip = zip; - } - - @Override - public Path handleResponse(HttpResponse response) throws IOException { - InputStream source = response.getEntity().getContent(); - int returnCode = response.getStatusLine().getStatusCode(); - if (returnCode != 200) { - throw new IllegalStateException(String.format("Request download file %s return code %d", target.toString(), returnCode)); - } - long contentLength = response.getEntity().getContentLength(); - if (task != null && contentLength != task.size) { - if (task.size > 0) - LogHelper.warning("Missing content length: expected %d | found %d", task.size, contentLength); - else task.size = contentLength; - } - if (zip) { - try (ZipInputStream input = IOHelper.newZipInput(source)) { - ZipEntry entry = input.getNextEntry(); - while (entry != null) { - if (entry.isDirectory()) { - entry = input.getNextEntry(); - continue; - } - long size = entry.getSize(); - String filename = entry.getName(); - Path target = this.target.resolve(filename); - if (callback != null) { - callback.stateChanged(entry.getName(), 0, entry.getSize()); - } - if (LogHelper.isDevEnabled()) { - LogHelper.dev("Resolved filename %s to %s", filename, target.toAbsolutePath().toString()); - } - transfer(source, target, filename, size, callback, totalCallback); - entry = input.getNextEntry(); - } - - } - return null; - } - if (callback != null && task != null) { - callback.stateChanged(task.apply, 0, task.size); - transfer(source, this.target, task.apply, task.size, callback, totalCallback); - } else - IOHelper.transfer(source, this.target); - return this.target; - } - } - - public static void transfer(InputStream input, Path file, String filename, long size, DownloadCallback callback, DownloadTotalCallback totalCallback) throws IOException { - try (OutputStream fileOutput = IOHelper.newOutput(file)) { - long downloaded = 0L; - - // Download with digest update - byte[] bytes = IOHelper.newBuffer(); - while (downloaded < size) { - int remaining = (int) Math.min(size - downloaded, bytes.length); - int length = input.read(bytes, 0, remaining); - if (length < 0) - throw new EOFException(String.format("%d bytes remaining", size - downloaded)); - - // Update file - fileOutput.write(bytes, 0, length); - - // Update state - downloaded += length; - //totalDownloaded += length; - totalCallback.addTotal(length); - callback.stateChanged(filename, downloaded, size); - } - } - } -} \ No newline at end of file diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/LauncherRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/LauncherRequest.java index 8f3615f4..91109b14 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/LauncherRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/LauncherRequest.java @@ -3,7 +3,6 @@ import pro.gravit.launcher.Launcher; import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.downloader.ListDownloader; import pro.gravit.launcher.events.request.LauncherRequestEvent; import pro.gravit.launcher.request.Request; import pro.gravit.launcher.request.websockets.StandartClientWebSocketService; @@ -15,6 +14,8 @@ import java.io.IOException; import java.io.InputStream; +import java.net.URL; +import java.net.URLConnection; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; @@ -60,9 +61,13 @@ public static void update(LauncherRequestEvent result) throws IOException { IOHelper.transfer(BINARY_PATH, stream); }*/ try { - ListDownloader downloader = new ListDownloader(); Files.deleteIfExists(C_BINARY_PATH); - downloader.downloadOne(result.url, C_BINARY_PATH); + URL url = new URL(result.url); + URLConnection connection = url.openConnection(); + try(InputStream in = connection.getInputStream()) + { + IOHelper.transfer(in, C_BINARY_PATH); + } try (InputStream in = IOHelper.newInput(C_BINARY_PATH)) { IOHelper.transfer(in, BINARY_PATH); } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java index ac6eface..29e25f15 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java @@ -1,313 +1,40 @@ package pro.gravit.launcher.request.update; -import pro.gravit.launcher.Launcher; import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.downloader.ListDownloader; import pro.gravit.launcher.events.request.UpdateRequestEvent; -import pro.gravit.launcher.hasher.FileNameMatcher; -import pro.gravit.launcher.hasher.HashedDir; -import pro.gravit.launcher.hasher.HashedEntry; -import pro.gravit.launcher.hasher.HashedFile; import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.update.UpdateRequest.State.Callback; import pro.gravit.launcher.request.websockets.StandartClientWebSocketService; import pro.gravit.launcher.request.websockets.WebSocketRequest; -import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; - -import java.io.IOException; -import java.nio.file.Files; import java.nio.file.Path; -import java.time.Duration; -import java.time.Instant; -import java.util.ArrayList; -import java.util.List; -import java.util.Map.Entry; import java.util.Objects; public final class UpdateRequest extends Request implements WebSocketRequest { - public interface UpdateController { - void preUpdate(UpdateRequest request, UpdateRequestEvent e); - - void preDiff(UpdateRequest request, UpdateRequestEvent e); - - void postDiff(UpdateRequest request, UpdateRequestEvent e, HashedDir.Diff diff) throws IOException; - - void preDownload(UpdateRequest request, UpdateRequestEvent e, List adds); - - void postDownload(UpdateRequest request, UpdateRequestEvent e); - - void postUpdate(UpdateRequest request, UpdateRequestEvent e); - } - - private static UpdateController controller; - - public static void setController(UpdateController controller) { - UpdateRequest.controller = controller; - } - - public static UpdateController getController() { - return controller; - } @Override public String getType() { return "update"; } - public static final class State { - @FunctionalInterface - public interface Callback { - @LauncherAPI - void call(State state); - } - @LauncherAPI - public final long fileDownloaded; - @LauncherAPI - public final long fileSize; - @LauncherAPI - public final long totalDownloaded; - @LauncherAPI - public final long totalSize; - @LauncherAPI - public final String filePath; - - @LauncherAPI - public final Duration duration; - - public State(String filePath, long fileDownloaded, long fileSize, long totalDownloaded, long totalSize, Duration duration) { - this.filePath = filePath; - this.fileDownloaded = fileDownloaded; - this.fileSize = fileSize; - this.totalDownloaded = totalDownloaded; - this.totalSize = totalSize; - - // Also store time of creation - this.duration = duration; - } - - @LauncherAPI - public double getBps() { - long seconds = duration.getSeconds(); - if (seconds == 0) - return -1.0D; // Otherwise will throw /0 exception - return totalDownloaded / (double) seconds; - } - - @LauncherAPI - public Duration getEstimatedTime() { - double bps = getBps(); - if (bps <= 0.0D) - return null; // Otherwise will throw /0 exception - return Duration.ofSeconds((long) (getTotalRemaining() / bps)); - } - - @LauncherAPI - public double getFileDownloadedKiB() { - return fileDownloaded / 1024.0D; - } - - @LauncherAPI - public double getFileDownloadedMiB() { - return getFileDownloadedKiB() / 1024.0D; - } - - @LauncherAPI - public double getFileDownloadedPart() { - if (fileSize == 0) - return 0.0D; - return (double) fileDownloaded / fileSize; - } - - @LauncherAPI - public long getFileRemaining() { - return fileSize - fileDownloaded; - } - - @LauncherAPI - public double getFileRemainingKiB() { - return getFileRemaining() / 1024.0D; - } - - @LauncherAPI - public double getFileRemainingMiB() { - return getFileRemainingKiB() / 1024.0D; - } - - @LauncherAPI - public double getFileSizeKiB() { - return fileSize / 1024.0D; - } - - @LauncherAPI - public double getFileSizeMiB() { - return getFileSizeKiB() / 1024.0D; - } - - @LauncherAPI - public double getTotalDownloadedKiB() { - return totalDownloaded / 1024.0D; - } - - @LauncherAPI - public double getTotalDownloadedMiB() { - return getTotalDownloadedKiB() / 1024.0D; - } - - @LauncherAPI - public double getTotalDownloadedPart() { - if (totalSize == 0) - return 0.0D; - return (double) totalDownloaded / totalSize; - } - - @LauncherAPI - public long getTotalRemaining() { - return totalSize - totalDownloaded; - } - - @LauncherAPI - public double getTotalRemainingKiB() { - return getTotalRemaining() / 1024.0D; - } - - @LauncherAPI - public double getTotalRemainingMiB() { - return getTotalRemainingKiB() / 1024.0D; - } - - @LauncherAPI - public double getTotalSizeKiB() { - return totalSize / 1024.0D; - } - - @LauncherAPI - public double getTotalSizeMiB() { - return getTotalSizeKiB() / 1024.0D; - } - } @Override public UpdateRequestEvent requestDo(StandartClientWebSocketService service) throws Exception { LogHelper.debug("Start update request"); - UpdateRequestEvent e = (UpdateRequestEvent) service.sendRequest(this); - if (controller != null) controller.preUpdate(this, e); - LogHelper.debug("Start update"); - Launcher.profile.pushOptionalFile(e.hdir, !Launcher.profile.isUpdateFastCheck()); - if (controller != null) controller.preDiff(this, e); - HashedDir.Diff diff = e.hdir.diff(localDir, matcher); - if (controller != null) controller.postDiff(this, e, diff); - final List adds = new ArrayList<>(); - if (controller != null) controller.preDownload(this, e, adds); - diff.mismatch.walk(IOHelper.CROSS_SEPARATOR, (path, name, entry) -> { - if (entry.getType().equals(HashedEntry.Type.FILE)) { - if (!entry.flag) { - HashedFile file = (HashedFile) entry; - totalSize += file.size; - adds.add(new ListDownloader.DownloadTask(path, file.size)); - } - } else if (entry.getType().equals(HashedEntry.Type.DIR)) { - try { - Files.createDirectories(dir.resolve(path)); - } catch (IOException ex) { - LogHelper.error(ex); - } - } - return HashedDir.WalkAction.CONTINUE; - }); - totalSize = diff.mismatch.size(); - startTime = Instant.now(); - updateState("UnknownFile", 0L, 100); - ListDownloader listDownloader = new ListDownloader(); - LogHelper.info("Download %s to %s", dirName, dir.toAbsolutePath().toString()); - if (e.zip && !adds.isEmpty()) { - listDownloader.downloadZip(e.url, adds, dir, this::updateState, (add) -> totalDownloaded += add, e.fullDownload); - } else { - listDownloader.download(e.url, adds, dir, this::updateState, (add) -> totalDownloaded += add); - } - if (controller != null) controller.postDownload(this, e); - deleteExtraDir(dir, diff.extra, diff.extra.flag); - if (controller != null) controller.postUpdate(this, e); - LogHelper.debug("Update success"); - return e; + return (UpdateRequestEvent) service.sendRequest(this); } // Instance @LauncherNetworkAPI - private final String dirName; private transient final Path dir; public Path getDir() { return dir; } - private transient final FileNameMatcher matcher; - - private transient final boolean digest; - private transient volatile Callback stateCallback; - // State - private transient HashedDir localDir; - private transient long totalDownloaded; - - private transient long totalSize; - - private transient Instant startTime; - @LauncherAPI - public UpdateRequest(String dirName, Path dir, FileNameMatcher matcher, boolean digest) { - this.dirName = IOHelper.verifyFileName(dirName); + public UpdateRequest(Path dir) { this.dir = Objects.requireNonNull(dir, "dir"); - this.matcher = matcher; - this.digest = digest; - } - - private void deleteExtraDir(Path subDir, HashedDir subHDir, boolean flag) throws IOException { - for (Entry mapEntry : subHDir.map().entrySet()) { - String name = mapEntry.getKey(); - Path path = subDir.resolve(name); - - // Delete list and dirs based on type - HashedEntry entry = mapEntry.getValue(); - HashedEntry.Type entryType = entry.getType(); - switch (entryType) { - case FILE: - updateState(IOHelper.toString(path), 0, 0); - Files.delete(path); - break; - case DIR: - deleteExtraDir(path, (HashedDir) entry, flag || entry.flag); - break; - default: - throw new AssertionError("Unsupported hashed entry type: " + entryType.name()); - } - } - - // Delete! - if (flag) { - updateState(IOHelper.toString(subDir), 0, 0); - Files.delete(subDir); - } - } - - @Override - public UpdateRequestEvent request() throws Exception { - Files.createDirectories(dir); - localDir = new HashedDir(dir, matcher, false, digest); - - // Start request - return super.request(); - } - - @LauncherAPI - public void setStateCallback(Callback callback) { - stateCallback = callback; - } - - private void updateState(String filePath, long fileDownloaded, long fileSize) { - if (stateCallback != null) - stateCallback.call(new State(filePath, fileDownloaded, fileSize, - totalDownloaded, totalSize, Duration.between(startTime, Instant.now()))); } } diff --git a/modules b/modules index 3cf0cb41..5069ebac 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 3cf0cb41a64b1f05d76bdc67f83d67d80ebe41f1 +Subproject commit 5069ebacddc00b261dd03036fc637a8aa803e2d5 From 4eb9c7fe7c1f2a42b21de599b6e2838fd21c3616 Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 4 Dec 2019 23:42:41 +0700 Subject: [PATCH 103/192] =?UTF-8?q?[FEATURE]=20=D0=A3=D0=B4=D0=B0=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20apache=20http=20client=20=D0=B8?= =?UTF-8?q?=D0=B7=20=D0=BE=D0=B1=D1=8F=D0=B7=D0=B0=D1=82=D0=B5=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D1=8B=D1=85=20=D0=B1=D0=B8=D0=B1=D0=BB=D0=B8=D0=BE=D1=82?= =?UTF-8?q?=D0=B5=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Launcher/build.gradle | 1 - LauncherAPI/build.gradle | 1 - 2 files changed, 2 deletions(-) diff --git a/Launcher/build.gradle b/Launcher/build.gradle index 0836fc7f..3db21f40 100644 --- a/Launcher/build.gradle +++ b/Launcher/build.gradle @@ -55,7 +55,6 @@ task javadocJar(type: Jar) { dependencies { pack project(':LauncherAuthlib') bundle 'com.github.oshi:oshi-core:3.13.0' - bundle 'org.apache.httpcomponents:httpclient:4.5.10' pack 'io.netty:netty-codec-http:4.1.43.Final' pack 'org.ow2.asm:asm-tree:7.1' } diff --git a/LauncherAPI/build.gradle b/LauncherAPI/build.gradle index 820aa7f6..c6382a08 100644 --- a/LauncherAPI/build.gradle +++ b/LauncherAPI/build.gradle @@ -3,7 +3,6 @@ dependencies { compile project(':LauncherCore') - compileOnly 'org.apache.httpcomponents:httpclient:4.5.10' compileOnly 'io.netty:netty-codec-http:4.1.43.Final' testCompile 'org.junit.jupiter:junit-jupiter:5.4.1' } From f839691c87b27a23a3092566694b1f0f20a3a772 Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 4 Dec 2019 23:49:52 +0700 Subject: [PATCH 104/192] =?UTF-8?q?[ANY]=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index 5069ebac..f986d6b7 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 5069ebacddc00b261dd03036fc637a8aa803e2d5 +Subproject commit f986d6b73705742b60a0db7feef2d8daacc43a5a From 4136f4a6e8c3f29cb10128f18d878de573010075 Mon Sep 17 00:00:00 2001 From: Gravit Date: Thu, 5 Dec 2019 01:22:07 +0700 Subject: [PATCH 105/192] =?UTF-8?q?[FEATURE]=20=D0=A3=D0=B4=D0=B0=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D0=B1=D0=BE=D0=BB=D1=8C=D1=88=D0=B8=D0=BD?= =?UTF-8?q?=D1=81=D1=82=D0=B2=D0=BE=20=D0=BD=D0=B0=D1=81=D1=82=D1=80=D0=BE?= =?UTF-8?q?=D0=B5=D0=BA,=20=D0=BE=D1=82=D0=BD=D0=BE=D1=81=D0=B2=D1=89?= =?UTF-8?q?=D0=B8=D1=85=D1=81=D1=8F=20=D0=BA=20=D1=80=D0=B0=D0=BD=D1=82?= =?UTF-8?q?=D0=B0=D0=B9=D0=BC=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gravit/launcher/NewLauncherSettings.java | 29 +---- .../client/LauncherUpdateController.java | 104 +++++++++--------- .../launcher/console/FeatureCommand.java | 34 ------ .../console/store/CopyStoreDirCommand.java | 47 -------- .../console/store/LinkStoreDirCommand.java | 47 -------- .../console/store/StoreListCommand.java | 27 ----- .../launcher/managers/ConsoleManager.java | 10 -- .../launcher/managers/SettingsManager.java | 4 - 8 files changed, 52 insertions(+), 250 deletions(-) delete mode 100644 Launcher/src/main/java/pro/gravit/launcher/console/FeatureCommand.java delete mode 100644 Launcher/src/main/java/pro/gravit/launcher/console/store/CopyStoreDirCommand.java delete mode 100644 Launcher/src/main/java/pro/gravit/launcher/console/store/LinkStoreDirCommand.java delete mode 100644 Launcher/src/main/java/pro/gravit/launcher/console/store/StoreListCommand.java diff --git a/Launcher/src/main/java/pro/gravit/launcher/NewLauncherSettings.java b/Launcher/src/main/java/pro/gravit/launcher/NewLauncherSettings.java index 5c45135d..b812b3c5 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/NewLauncherSettings.java +++ b/Launcher/src/main/java/pro/gravit/launcher/NewLauncherSettings.java @@ -8,37 +8,10 @@ import java.util.*; public class NewLauncherSettings { - @LauncherAPI - public String login; - @LauncherAPI - public String auth; - @LauncherAPI - public byte[] rsaPassword; - @LauncherAPI - public int profile; - @LauncherAPI - public transient Path updatesDir; - @LauncherAPI - public String updatesDirPath; - @LauncherAPI - public boolean autoEnter; - @LauncherAPI - public boolean debug; - @LauncherAPI - public boolean fullScreen; - @LauncherAPI - public boolean offline; - @LauncherAPI - public int ram; - - @LauncherAPI - public byte[] lastDigest; - @LauncherAPI - public List lastProfiles = new LinkedList<>(); @LauncherAPI public Map userSettings = new HashMap<>(); @LauncherAPI - public boolean featureStore; + public List features = new ArrayList<>(); @LauncherAPI public String consoleUnlockKey; diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java b/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java index 62c1e1e5..c66a7ee1 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java @@ -22,60 +22,58 @@ public class LauncherUpdateController { public void postDiff(UpdateRequest request, UpdateRequestEvent e, HashedDir.Diff diff) throws IOException { if (e.zip && e.fullDownload) return; - if (SettingsManager.settings.featureStore) { - LogHelper.info("Enabled HStore feature. Find"); - AtomicReference lastEn = new AtomicReference<>(null); - //ArrayList removed = new ArrayList<>(); - diff.mismatch.walk(File.separator, (path, name, entry) -> { - if (entry.getType() == HashedEntry.Type.DIR) { - Files.createDirectories(request.getDir().resolve(path)); - return HashedDir.WalkAction.CONTINUE; - } - HashedFile file = (HashedFile) entry; - //Первый экспериментальный способ - честно обходим все возможные Store - Path ret = null; - if (lastEn.get() == null) { - for (NewLauncherSettings.HashedStoreEntry en : SettingsManager.settings.lastHDirs) { - ret = tryFind(en, file); - if (ret != null) { - lastEn.set(en); - break; - } - } - } else { - ret = tryFind(lastEn.get(), file); - } - if (ret == null) { - for (NewLauncherSettings.HashedStoreEntry en : SettingsManager.settings.lastHDirs) { - ret = tryFind(en, file); - if (ret != null) { - lastEn.set(en); - break; - } - } - } - if (ret != null) { - //Еще раз проверим корректность хеша - //Возможно эта проверка избыточна - //if(file.isSame(ret, true)) - { - Path source = request.getDir().resolve(path); - if (LogHelper.isDebugEnabled()) { - LogHelper.debug("Copy file %s to %s", ret.toAbsolutePath().toString(), source.toAbsolutePath().toString()); - } - //Let's go! - Files.deleteIfExists(source); - Files.copy(ret, source); - try (InputStream input = IOHelper.newInput(ret)) { - IOHelper.transfer(input, source); - } - entry.flag = true; - //removed.add(path.replace('\\', '/')); - } - } + LogHelper.info("Enabled HStore feature. Find"); + AtomicReference lastEn = new AtomicReference<>(null); + //ArrayList removed = new ArrayList<>(); + diff.mismatch.walk(File.separator, (path, name, entry) -> { + if (entry.getType() == HashedEntry.Type.DIR) { + Files.createDirectories(request.getDir().resolve(path)); return HashedDir.WalkAction.CONTINUE; - }); - } + } + HashedFile file = (HashedFile) entry; + //Первый экспериментальный способ - честно обходим все возможные Store + Path ret = null; + if (lastEn.get() == null) { + for (NewLauncherSettings.HashedStoreEntry en : SettingsManager.settings.lastHDirs) { + ret = tryFind(en, file); + if (ret != null) { + lastEn.set(en); + break; + } + } + } else { + ret = tryFind(lastEn.get(), file); + } + if (ret == null) { + for (NewLauncherSettings.HashedStoreEntry en : SettingsManager.settings.lastHDirs) { + ret = tryFind(en, file); + if (ret != null) { + lastEn.set(en); + break; + } + } + } + if (ret != null) { + //Еще раз проверим корректность хеша + //Возможно эта проверка избыточна + //if(file.isSame(ret, true)) + { + Path source = request.getDir().resolve(path); + if (LogHelper.isDebugEnabled()) { + LogHelper.debug("Copy file %s to %s", ret.toAbsolutePath().toString(), source.toAbsolutePath().toString()); + } + //Let's go! + Files.deleteIfExists(source); + Files.copy(ret, source); + try (InputStream input = IOHelper.newInput(ret)) { + IOHelper.transfer(input, source); + } + entry.flag = true; + //removed.add(path.replace('\\', '/')); + } + } + return HashedDir.WalkAction.CONTINUE; + }); } public Path tryFind(NewLauncherSettings.HashedStoreEntry en, HashedFile file) throws IOException { diff --git a/Launcher/src/main/java/pro/gravit/launcher/console/FeatureCommand.java b/Launcher/src/main/java/pro/gravit/launcher/console/FeatureCommand.java deleted file mode 100644 index 78a27999..00000000 --- a/Launcher/src/main/java/pro/gravit/launcher/console/FeatureCommand.java +++ /dev/null @@ -1,34 +0,0 @@ -package pro.gravit.launcher.console; - -import pro.gravit.launcher.managers.SettingsManager; -import pro.gravit.utils.command.Command; -import pro.gravit.utils.helper.LogHelper; - -public class FeatureCommand extends Command { - @Override - public String getArgsDescription() { - return "[feature] [true/false]"; - } - - @Override - public String getUsageDescription() { - return "Enable or disable feature"; - } - - @Override - public void invoke(String... args) throws Exception { - verifyArgs(args, 2); - boolean enabled = Boolean.parseBoolean(args[1]); - switch (args[0]) { - case "store": { - SettingsManager.settings.featureStore = enabled; - break; - } - default: { - LogHelper.info("Features: [store]"); - return; - } - } - LogHelper.info("Feature %s %s", args[0], enabled ? "enabled" : "disabled"); - } -} diff --git a/Launcher/src/main/java/pro/gravit/launcher/console/store/CopyStoreDirCommand.java b/Launcher/src/main/java/pro/gravit/launcher/console/store/CopyStoreDirCommand.java deleted file mode 100644 index 763855ac..00000000 --- a/Launcher/src/main/java/pro/gravit/launcher/console/store/CopyStoreDirCommand.java +++ /dev/null @@ -1,47 +0,0 @@ -package pro.gravit.launcher.console.store; - -import pro.gravit.launcher.NewLauncherSettings; -import pro.gravit.launcher.managers.SettingsManager; -import pro.gravit.utils.command.Command; -import pro.gravit.utils.helper.LogHelper; - -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; - -public class CopyStoreDirCommand extends Command { - @Override - public String getArgsDescription() { - return "[index] [overwrite(true/false)]"; - } - - @Override - public String getUsageDescription() { - return "Copy dir in GravitLauncherStore"; - } - - @Override - public void invoke(String... args) throws Exception { - verifyArgs(args, 2); - int ind = 1; - int index = Integer.parseInt(args[0]); - boolean overwrite = Boolean.parseBoolean(args[1]); - for (NewLauncherSettings.HashedStoreEntry e : SettingsManager.settings.lastHDirs) { - if (ind == index) { - LogHelper.info("Copy [%d] FullPath: %s name: %s", ind, e.fullPath, e.name); - Path path = Paths.get(e.fullPath); - if (!Files.isDirectory(path)) { - LogHelper.error("Directory %s not found", path.toAbsolutePath().toString()); - return; - } - Path target = Paths.get(SettingsManager.settings.updatesDirPath).resolve(e.name); - if (Files.exists(target) && !overwrite) { - LogHelper.error("Directory %s found, flag overwrite not found", target.toAbsolutePath().toString()); - return; - } - Files.copy(path, target); - } - ind++; - } - } -} diff --git a/Launcher/src/main/java/pro/gravit/launcher/console/store/LinkStoreDirCommand.java b/Launcher/src/main/java/pro/gravit/launcher/console/store/LinkStoreDirCommand.java deleted file mode 100644 index 35120f31..00000000 --- a/Launcher/src/main/java/pro/gravit/launcher/console/store/LinkStoreDirCommand.java +++ /dev/null @@ -1,47 +0,0 @@ -package pro.gravit.launcher.console.store; - -import pro.gravit.launcher.NewLauncherSettings; -import pro.gravit.launcher.managers.SettingsManager; -import pro.gravit.utils.command.Command; -import pro.gravit.utils.helper.LogHelper; - -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; - -public class LinkStoreDirCommand extends Command { - - @Override - public String getArgsDescription() { - return "[index]"; - } - - @Override - public String getUsageDescription() { - return "Create symlink to GravitLauncherStore directory"; - } - - @Override - public void invoke(String... args) throws Exception { - verifyArgs(args, 1); - int ind = 1; - int index = Integer.parseInt(args[0]); - for (NewLauncherSettings.HashedStoreEntry e : SettingsManager.settings.lastHDirs) { - if (ind == index) { - LogHelper.info("Copy [%d] FullPath: %s name: %s", ind, e.fullPath, e.name); - Path path = Paths.get(e.fullPath); - if (!Files.isDirectory(path)) { - LogHelper.error("Directory %s not found", path.toAbsolutePath().toString()); - return; - } - Path target = Paths.get(SettingsManager.settings.updatesDirPath).resolve(e.name); - if (Files.exists(target)) { - LogHelper.error("Directory %s already exists", target.toAbsolutePath().toString()); - return; - } - Files.createSymbolicLink(path, target); - } - ind++; - } - } -} diff --git a/Launcher/src/main/java/pro/gravit/launcher/console/store/StoreListCommand.java b/Launcher/src/main/java/pro/gravit/launcher/console/store/StoreListCommand.java deleted file mode 100644 index 3ed81fc7..00000000 --- a/Launcher/src/main/java/pro/gravit/launcher/console/store/StoreListCommand.java +++ /dev/null @@ -1,27 +0,0 @@ -package pro.gravit.launcher.console.store; - -import pro.gravit.launcher.NewLauncherSettings; -import pro.gravit.launcher.managers.SettingsManager; -import pro.gravit.utils.command.Command; -import pro.gravit.utils.helper.LogHelper; - -public class StoreListCommand extends Command { - @Override - public String getArgsDescription() { - return null; - } - - @Override - public String getUsageDescription() { - return "List GravitLauncherStore"; - } - - @Override - public void invoke(String... args) { - int ind = 1; - for (NewLauncherSettings.HashedStoreEntry e : SettingsManager.settings.lastHDirs) { - LogHelper.info("[%d] FullPath: %s name: %s", ind, e.fullPath, e.name); - ind++; - } - } -} diff --git a/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java b/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java index 07b41d72..19098f36 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java +++ b/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java @@ -1,13 +1,9 @@ package pro.gravit.launcher.managers; import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.console.FeatureCommand; import pro.gravit.launcher.console.UnlockCommand; import pro.gravit.launcher.console.admin.ExecCommand; import pro.gravit.launcher.console.admin.LogListenerCommand; -import pro.gravit.launcher.console.store.CopyStoreDirCommand; -import pro.gravit.launcher.console.store.LinkStoreDirCommand; -import pro.gravit.launcher.console.store.StoreListCommand; import pro.gravit.utils.command.BaseCommandCategory; import pro.gravit.utils.command.CommandHandler; import pro.gravit.utils.command.JLineCommandHandler; @@ -57,16 +53,10 @@ public static boolean checkUnlockKey(String key) { public static void unlock() { handler.registerCommand("debug", new DebugCommand()); - handler.registerCommand("feature", new FeatureCommand()); BaseCommandCategory admin = new BaseCommandCategory(); admin.registerCommand("exec", new ExecCommand()); admin.registerCommand("logListen", new LogListenerCommand()); handler.registerCategory(new CommandHandler.Category(admin, "admin", "Server admin commands")); - BaseCommandCategory store = new BaseCommandCategory(); - store.registerCommand("storeList", new StoreListCommand()); - store.registerCommand("copyStoreDir", new CopyStoreDirCommand()); - store.registerCommand("linkStoreDir", new LinkStoreDirCommand()); - handler.registerCategory(new CommandHandler.Category(admin, "store", "Store admin commands")); isConsoleUnlock = true; } } diff --git a/Launcher/src/main/java/pro/gravit/launcher/managers/SettingsManager.java b/Launcher/src/main/java/pro/gravit/launcher/managers/SettingsManager.java index 55921ab5..edf1dfe6 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/managers/SettingsManager.java +++ b/Launcher/src/main/java/pro/gravit/launcher/managers/SettingsManager.java @@ -42,8 +42,6 @@ public SettingsManager() { @LauncherAPI @Override public NewLauncherSettings getConfig() { - if (settings.updatesDir != null) - settings.updatesDirPath = settings.updatesDir.toString(); return settings; } @@ -57,8 +55,6 @@ public NewLauncherSettings getDefaultConfig() { @Override public void setConfig(NewLauncherSettings config) { settings = config; - if (settings.updatesDirPath != null) - settings.updatesDir = Paths.get(settings.updatesDirPath); if (settings.consoleUnlockKey != null && !ConsoleManager.isConsoleUnlock) { if (ConsoleManager.checkUnlockKey(settings.consoleUnlockKey)) { ConsoleManager.unlock(); From 71018a0cdfc367bb5a01ff6afcf506276c137d4b Mon Sep 17 00:00:00 2001 From: Gravit Date: Thu, 5 Dec 2019 01:35:36 +0700 Subject: [PATCH 106/192] =?UTF-8?q?[FEATURE]=20UUID=20=D0=B2=20ClientProfi?= =?UTF-8?q?le?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../command/hash/DownloadClientCommand.java | 2 ++ .../pro/gravit/launcher/profiles/ClientProfile.java | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadClientCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadClientCommand.java index 54b3f738..ef403ecc 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadClientCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadClientCommand.java @@ -15,6 +15,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Collections; +import java.util.UUID; public final class DownloadClientCommand extends Command { @@ -61,6 +62,7 @@ public void invoke(String... args) throws IOException, CommandException { } client.setTitle(dirName); client.setDir(dirName); + client.setUUID(UUID.randomUUID()); try (BufferedWriter writer = IOHelper.newWriter(IOHelper.resolveIncremental(server.profilesDir, dirName, "json"))) { Launcher.gsonManager.configGson.toJson(client, writer); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java index 8ef8ea5f..3530d993 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java @@ -86,6 +86,8 @@ public String toString() { @LauncherAPI private int sortIndex; @LauncherAPI + private UUID uuid; + @LauncherAPI private String title; @LauncherAPI private String info; @@ -384,11 +386,19 @@ public void setVersion(Version version) { this.version = version.name; } + public void setUUID(UUID uuid) { + this.uuid = uuid; + } + @Override public String toString() { return title; } + public UUID getUUID() { + return uuid; + } + @LauncherAPI public void verify() { // Version From 20913cdbc6d50075c8b2e3ee116c3ccae5b8b154 Mon Sep 17 00:00:00 2001 From: Gravit Date: Thu, 5 Dec 2019 02:24:19 +0700 Subject: [PATCH 107/192] =?UTF-8?q?[FIX]=20=D0=9D=D0=B5=D0=BA=D0=BE=D1=80?= =?UTF-8?q?=D1=80=D0=B5=D0=BA=D1=82=D0=BD=D1=8B=D0=B9=20UpdateRequest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launcher/request/update/UpdateRequest.java | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java index 29e25f15..3c8344bf 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java @@ -1,17 +1,18 @@ package pro.gravit.launcher.request.update; -import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.request.UpdateRequestEvent; import pro.gravit.launcher.request.Request; import pro.gravit.launcher.request.websockets.StandartClientWebSocketService; import pro.gravit.launcher.request.websockets.WebSocketRequest; import pro.gravit.utils.helper.LogHelper; -import java.nio.file.Path; -import java.util.Objects; public final class UpdateRequest extends Request implements WebSocketRequest { + public UpdateRequest(String dirName) { + this.dirName = dirName; + } + @Override public String getType() { return "update"; @@ -27,14 +28,5 @@ public UpdateRequestEvent requestDo(StandartClientWebSocketService service) thro // Instance @LauncherNetworkAPI - private transient final Path dir; - - public Path getDir() { - return dir; - } - - @LauncherAPI - public UpdateRequest(Path dir) { - this.dir = Objects.requireNonNull(dir, "dir"); - } + private final String dirName; } From b21c8b04c31a71cae274a9c2336f60953a98fe73 Mon Sep 17 00:00:00 2001 From: Gravit Date: Thu, 5 Dec 2019 02:25:53 +0700 Subject: [PATCH 108/192] =?UTF-8?q?[FIX]=20=D0=9D=D0=B5=D0=BA=D0=BE=D1=80?= =?UTF-8?q?=D1=80=D0=B5=D0=BA=D1=82=D0=BD=D1=8B=D0=B9=20UpdateRequest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launcher/client/LauncherUpdateController.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java b/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java index c66a7ee1..599dc121 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java @@ -21,6 +21,7 @@ public class LauncherUpdateController { public void postDiff(UpdateRequest request, UpdateRequestEvent e, HashedDir.Diff diff) throws IOException { + /* if (e.zip && e.fullDownload) return; LogHelper.info("Enabled HStore feature. Find"); AtomicReference lastEn = new AtomicReference<>(null); @@ -74,6 +75,7 @@ public void postDiff(UpdateRequest request, UpdateRequestEvent e, HashedDir.Diff } return HashedDir.WalkAction.CONTINUE; }); + */ } public Path tryFind(NewLauncherSettings.HashedStoreEntry en, HashedFile file) throws IOException { From f62b0377893706dd61f2aa99ddda3ea620fde66f Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Fri, 6 Dec 2019 16:45:07 +0100 Subject: [PATCH 109/192] =?UTF-8?q?[FIX]=20=D0=92=D1=81=D1=82=D1=80=D0=BE?= =?UTF-8?q?=D0=B5=D0=BD=D0=BD=D1=8B=D0=B9=20=D1=84=D0=B0=D0=B9=D0=BB=D1=81?= =?UTF-8?q?=D0=B5=D1=80=D0=B2=D0=B5=D1=80=20=D0=BD=D0=B5=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=B2=D0=B8=D1=81=D0=B8=D1=82=20=D0=BE=D1=82=20javax.activatio?= =?UTF-8?q?n=20=D0=BF=D1=80=D0=B8=20=D0=BE=D0=BF=D1=80=D0=B5=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B8=20mime-type.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../socket/handlers/fileserver/FileServerHandler.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/fileserver/FileServerHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/fileserver/FileServerHandler.java index 9b8c6eac..5c249cdc 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/fileserver/FileServerHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/fileserver/FileServerHandler.java @@ -7,12 +7,12 @@ import io.netty.handler.stream.ChunkedFile; import io.netty.util.CharsetUtil; -import javax.activation.MimetypesFileTypeMap; import java.io.File; import java.io.FileNotFoundException; import java.io.RandomAccessFile; import java.net.URI; import java.net.URISyntaxException; +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.text.SimpleDateFormat; @@ -30,6 +30,7 @@ public class FileServerHandler extends SimpleChannelInboundHandler Date: Fri, 6 Dec 2019 16:49:53 +0100 Subject: [PATCH 110/192] =?UTF-8?q?[ANY]=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B8?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index f986d6b7..bf7994eb 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit f986d6b73705742b60a0db7feef2d8daacc43a5a +Subproject commit bf7994eb6358c6440cb84846918afbc118fa3dae From 38580b23bcb70bd866573bf75e93074596f238cc Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 9 Dec 2019 00:56:16 +0700 Subject: [PATCH 111/192] =?UTF-8?q?[FEATURE][EXPERIMENTAL]=20=D0=98=D1=81?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D1=81=D0=B2=D0=BE=D0=B5=D0=B3=D0=BE=20ClassLoader'?= =?UTF-8?q?=D0=B0=20=D0=B2=D0=BC=D0=B5=D1=81=D1=82=D0=BE=20=D1=81=D0=B8?= =?UTF-8?q?=D1=81=D1=82=D0=B5=D0=BC=D0=BD=D0=BE=D0=B3=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Launcher/build.gradle | 2 +- .../launcher/client/ClientLauncher.java | 17 ++++++++++++-- .../gravit/utils/PublicURLClassLoader.java | 22 ++++++++++++++++++- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/Launcher/build.gradle b/Launcher/build.gradle index 3db21f40..b99e62a8 100644 --- a/Launcher/build.gradle +++ b/Launcher/build.gradle @@ -53,7 +53,7 @@ task javadocJar(type: Jar) { } dependencies { - pack project(':LauncherAuthlib') + pack project(':LauncherAPI') bundle 'com.github.oshi:oshi-core:3.13.0' pack 'io.netty:netty-codec-http:4.1.43.Final' pack 'org.ow2.asm:asm-tree:7.1' diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index c0ce62b8..23412318 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -292,6 +292,10 @@ private static void launch(ClientProfile profile, Params params) throws Throwabl LogHelper.debug("Args: " + copy); // Resolve main class and method Class mainClass = classLoader.loadClass(profile.getMainClass()); + for(URL u : classLoader.getURLs()) + { + LogHelper.info("ClassLoader URL: %s", u.toString()); + } MethodHandle mainMethod = MethodHandles.publicLookup().findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class)).asFixedArity(); Launcher.LAUNCHED.set(true); JVMHelper.fullGC(); @@ -468,12 +472,12 @@ public static void main(String... args) throws Throwable { LogHelper.debug("Verifying ClientLauncher sign and classpath"); LinkedList classPath = resolveClassPathList(params.clientDir, profile.getClassPath()); for (Path classpathURL : classPath) { - LauncherAgent.addJVMClassPath(classpathURL.normalize().toAbsolutePath()); + //LauncherAgent.addJVMClassPath(classpathURL.normalize().toAbsolutePath()); } profile.pushOptionalClassPath(cp -> { LinkedList optionalClassPath = resolveClassPathList(params.clientDir, cp); for (Path classpathURL : optionalClassPath) { - LauncherAgent.addJVMClassPath(classpathURL.normalize().toAbsolutePath()); + //LauncherAgent.addJVMClassPath(classpathURL.normalize().toAbsolutePath()); } }); URL[] classpathurls = resolveClassPath(params.clientDir, profile.getClassPath()); @@ -507,6 +511,8 @@ public static void main(String... args) throws Throwable { AuthService.uuid = params.pp.uuid; ClientService.instrumentation = LauncherAgent.inst; ClientService.classLoader = classLoader; + classLoader.addURL(IOHelper.getCodeSource(ClientLauncher.class).toUri().toURL()); + //classForName(classLoader, "com.google.common.collect.ForwardingMultimap"); ClientService.baseURLs = classpathurls; LogHelper.debug("Starting JVM and client WatchService"); FileNameMatcher assetMatcher = profile.getAssetUpdateMatcher(); @@ -532,6 +538,13 @@ public static void main(String... args) throws Throwable { launch(profile, params); } } + public static void classForName(ClassLoader loader, String name) + { + try { + Class.forName(name, false, loader); + } catch (ClassNotFoundException ignored) { + } + } private static URL[] resolveClassPath(Path clientDir, String... classPath) throws IOException { return resolveClassPathStream(clientDir, classPath).map(IOHelper::toURL).toArray(URL[]::new); diff --git a/LauncherCore/src/main/java/pro/gravit/utils/PublicURLClassLoader.java b/LauncherCore/src/main/java/pro/gravit/utils/PublicURLClassLoader.java index 6ea17422..0879d53a 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/PublicURLClassLoader.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/PublicURLClassLoader.java @@ -1,6 +1,8 @@ package pro.gravit.utils; import pro.gravit.launcher.LauncherAPI; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.JVMHelper; import java.net.URL; import java.net.URLClassLoader; @@ -66,7 +68,25 @@ public PublicURLClassLoader(URL[] urls, ClassLoader parent) { @Override public String findLibrary(String name) { - return nativePath.concat(name); + return nativePath.concat(IOHelper.PLATFORM_SEPARATOR).concat(getNativePrefix()).concat(name).concat(getNativeEx()); + } + public String getNativeEx() + { + if(JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) + return ".dll"; + else if(JVMHelper.OS_TYPE == JVMHelper.OS.LINUX) + return ".so"; + else if(JVMHelper.OS_TYPE == JVMHelper.OS.MACOSX) + return ".dylib"; + return ""; + } + public String getNativePrefix() + { + if(JVMHelper.OS_TYPE == JVMHelper.OS.LINUX) + return "lib"; + else if(JVMHelper.OS_TYPE == JVMHelper.OS.MACOSX) + return "lib"; + return ""; } @Override From 9ed4e37e22a332de098f9e74791936f94b6529dd Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 9 Dec 2019 00:56:48 +0700 Subject: [PATCH 112/192] =?UTF-8?q?[ANY]=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index f986d6b7..9ee94152 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit f986d6b73705742b60a0db7feef2d8daacc43a5a +Subproject commit 9ee94152da6ae8e3ea045484f60b2a2246b4e993 From efc3cd4a09e435fdcc2fd5a42696fff48a20e855 Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 9 Dec 2019 01:37:18 +0700 Subject: [PATCH 113/192] =?UTF-8?q?[FEATURE][EXPERIMENTAL]=20=D0=98=D1=81?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6=D0=BA?= =?UTF-8?q?=D0=B8=20proguard?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launcher/client/ClientClassLoader.java | 90 +++++++++++++++++++ .../launcher/client/ClientLauncher.java | 6 +- .../authlib/yggdrasil/CompatBridge.java | 3 +- .../YggdrasilGameProfileRepository.java | 5 +- .../gravit/utils/PublicURLClassLoader.java | 35 -------- 5 files changed, 95 insertions(+), 44 deletions(-) create mode 100644 Launcher/src/main/java/pro/gravit/launcher/client/ClientClassLoader.java diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientClassLoader.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientClassLoader.java new file mode 100644 index 00000000..682d0ec1 --- /dev/null +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientClassLoader.java @@ -0,0 +1,90 @@ +package pro.gravit.launcher.client; + +import pro.gravit.launcher.LauncherAPI; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.JVMHelper; + +import java.net.URL; +import java.net.URLClassLoader; + +public class ClientClassLoader extends URLClassLoader { + public String nativePath; + + /** + * Constructs a new URLClassLoader for the specified URLs using the + * default delegation parent {@code ClassLoader}. The URLs will + * be searched in the order specified for classes and resources after + * first searching in the parent class loader. Any URL that ends with + * a '/' is assumed to refer to a directory. Otherwise, the URL is + * assumed to refer to a JAR file which will be downloaded and opened + * as needed. + * + *

If there is a security manager, this method first + * calls the security manager's {@code checkCreateClassLoader} method + * to ensure creation of a class loader is allowed. + * + * @param urls the URLs from which to load classes and resources + * @throws SecurityException if a security manager exists and its + * {@code checkCreateClassLoader} method doesn't allow + * creation of a class loader. + * @throws NullPointerException if {@code urls} is {@code null}. + * @see SecurityManager#checkCreateClassLoader + */ + public ClientClassLoader(URL[] urls) { + super(urls); + } + + /** + * Constructs a new URLClassLoader for the given URLs. The URLs will be + * searched in the order specified for classes and resources after first + * searching in the specified parent class loader. Any {@code jar:} + * scheme URL is assumed to refer to a JAR file. Any {@code file:} scheme + * URL that ends with a '/' is assumed to refer to a directory. Otherwise, + * the URL is assumed to refer to a JAR file which will be downloaded and + * opened as needed. + * + *

If there is a security manager, this method first + * calls the security manager's {@code checkCreateClassLoader} method + * to ensure creation of a class loader is allowed. + * + * @param urls the URLs from which to load classes and resources + * @param parent the parent class loader for delegation + * @throws SecurityException if a security manager exists and its + * {@code checkCreateClassLoader} method doesn't allow + * creation of a class loader. + * @throws NullPointerException if {@code urls} is {@code null}. + * @see SecurityManager#checkCreateClassLoader + */ + public ClientClassLoader(URL[] urls, ClassLoader parent) { + super(urls, parent); + } + + @Override + public String findLibrary(String name) { + return nativePath.concat(IOHelper.PLATFORM_SEPARATOR).concat(getNativePrefix()).concat(name).concat(getNativeEx()); + } + public String getNativeEx() + { + if(JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) + return ".dll"; + else if(JVMHelper.OS_TYPE == JVMHelper.OS.LINUX) + return ".so"; + else if(JVMHelper.OS_TYPE == JVMHelper.OS.MACOSX) + return ".dylib"; + return ""; + } + public String getNativePrefix() + { + if(JVMHelper.OS_TYPE == JVMHelper.OS.LINUX) + return "lib"; + else if(JVMHelper.OS_TYPE == JVMHelper.OS.MACOSX) + return "lib"; + return ""; + } + + @Override + public void addURL(URL url) { + super.addURL(url); + } +} + diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index 23412318..4e85be4d 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -10,7 +10,6 @@ import pro.gravit.launcher.hasher.FileNameMatcher; import pro.gravit.launcher.hasher.HashedDir; import pro.gravit.launcher.hwid.HWIDProvider; -import pro.gravit.launcher.hwid.OshiHWIDProvider; import pro.gravit.launcher.managers.ClientGsonManager; import pro.gravit.launcher.managers.ClientHookManager; import pro.gravit.launcher.modules.events.PreConfigPhase; @@ -163,7 +162,7 @@ public void write(HOutput output) throws IOException { // Constants private static final Path NATIVES_DIR = IOHelper.toPath("natives"); private static final Path RESOURCEPACKS_DIR = IOHelper.toPath("resourcepacks"); - private static PublicURLClassLoader classLoader; + private static ClientClassLoader classLoader; public static class ClientUserProperties { @LauncherAPI @@ -481,10 +480,9 @@ public static void main(String... args) throws Throwable { } }); URL[] classpathurls = resolveClassPath(params.clientDir, profile.getClassPath()); - classLoader = new PublicURLClassLoader(classpathurls, ClassLoader.getSystemClassLoader()); + classLoader = new ClientClassLoader(classpathurls, ClassLoader.getSystemClassLoader()); Thread.currentThread().setContextClassLoader(classLoader); classLoader.nativePath = params.clientDir.resolve(NATIVES_DIR).toString(); - PublicURLClassLoader.systemclassloader = classLoader; // Start client with WatchService monitoring boolean digest = !profile.isUpdateFastCheck(); LogHelper.debug("Restore sessions"); diff --git a/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/CompatBridge.java b/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/CompatBridge.java index bc11fa25..7d35a319 100644 --- a/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/CompatBridge.java +++ b/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/CompatBridge.java @@ -7,7 +7,6 @@ import pro.gravit.launcher.request.uuid.BatchProfileByUsernameRequest; import pro.gravit.launcher.request.uuid.ProfileByUUIDRequest; import pro.gravit.launcher.request.uuid.ProfileByUsernameRequest; -import pro.gravit.launcher.serialize.SerializeLimits; import pro.gravit.utils.helper.LogHelper; import java.util.UUID; @@ -15,7 +14,7 @@ // Used to bypass Launcher's class name obfuscation and access API @LauncherAPI public class CompatBridge { - public static final int PROFILES_MAX_BATCH_SIZE = SerializeLimits.MAX_BATCH_SIZE; + public static final int PROFILES_MAX_BATCH_SIZE = 128; public static CompatProfile checkServer(String username, String serverID) throws Exception { LogHelper.debug("CompatBridge.checkServer, Username: '%s', Server ID: %s", username, serverID); diff --git a/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilGameProfileRepository.java b/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilGameProfileRepository.java index 9ccad1b2..7282a47f 100644 --- a/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilGameProfileRepository.java +++ b/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilGameProfileRepository.java @@ -6,7 +6,6 @@ import com.mojang.authlib.ProfileLookupCallback; import pro.gravit.launcher.profiles.PlayerProfile; import pro.gravit.launcher.request.uuid.BatchProfileByUsernameRequest; -import pro.gravit.launcher.serialize.SerializeLimits; import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.VerifyHelper; @@ -37,8 +36,8 @@ public YggdrasilGameProfileRepository() { public void findProfilesByNames(String[] usernames, Agent agent, ProfileLookupCallback callback) { int offset = 0; while (offset < usernames.length) { - String[] sliceUsernames = Arrays.copyOfRange(usernames, offset, Math.min(offset + SerializeLimits.MAX_BATCH_SIZE, usernames.length)); - offset += SerializeLimits.MAX_BATCH_SIZE; + String[] sliceUsernames = Arrays.copyOfRange(usernames, offset, Math.min(offset + 128, usernames.length)); + offset += 128; // Batch Username-To-UUID request PlayerProfile[] sliceProfiles; diff --git a/LauncherCore/src/main/java/pro/gravit/utils/PublicURLClassLoader.java b/LauncherCore/src/main/java/pro/gravit/utils/PublicURLClassLoader.java index 0879d53a..c5082afc 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/PublicURLClassLoader.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/PublicURLClassLoader.java @@ -1,21 +1,9 @@ package pro.gravit.utils; -import pro.gravit.launcher.LauncherAPI; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.JVMHelper; - import java.net.URL; import java.net.URLClassLoader; public class PublicURLClassLoader extends URLClassLoader { - @LauncherAPI - public static ClassLoader systemclassloader = ClassLoader.getSystemClassLoader(); - public String nativePath; - - @LauncherAPI - public static ClassLoader getSystemClassLoader() { - return systemclassloader; - } /** * Constructs a new URLClassLoader for the specified URLs using the @@ -66,29 +54,6 @@ public PublicURLClassLoader(URL[] urls, ClassLoader parent) { super(urls, parent); } - @Override - public String findLibrary(String name) { - return nativePath.concat(IOHelper.PLATFORM_SEPARATOR).concat(getNativePrefix()).concat(name).concat(getNativeEx()); - } - public String getNativeEx() - { - if(JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) - return ".dll"; - else if(JVMHelper.OS_TYPE == JVMHelper.OS.LINUX) - return ".so"; - else if(JVMHelper.OS_TYPE == JVMHelper.OS.MACOSX) - return ".dylib"; - return ""; - } - public String getNativePrefix() - { - if(JVMHelper.OS_TYPE == JVMHelper.OS.LINUX) - return "lib"; - else if(JVMHelper.OS_TYPE == JVMHelper.OS.MACOSX) - return "lib"; - return ""; - } - @Override public void addURL(URL url) { super.addURL(url); From 3eef6ac882df3d28b15c278e1594b2e9071e0506 Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 9 Dec 2019 02:21:05 +0700 Subject: [PATCH 114/192] =?UTF-8?q?[FEATURE][EXPERIMENTAL]=20=D0=A3=D0=B4?= =?UTF-8?q?=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20LauncherAPI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gravit/launchserver/defaults/proguard.cfg | 16 +- .../pro/gravit/launcher/JSApplication.java | 2 +- .../pro/gravit/launcher/LauncherAgent.java | 2 +- .../pro/gravit/launcher/LauncherEngine.java | 2 +- .../gravit/launcher/NewLauncherSettings.java | 13 +- .../launcher/client/ClientClassLoader.java | 1 - .../launcher/client/ClientLauncher.java | 46 ++-- .../pro/gravit/launcher/client/DirBridge.java | 29 ++- .../gravit/launcher/client/ServerPinger.java | 13 +- .../gravit/launcher/managers/HasherStore.java | 13 +- .../launcher/managers/SettingsManager.java | 17 +- .../pro/gravit/launcher/utils/DirWatcher.java | 7 +- .../gravit/launcher/ClientPermissions.java | 14 +- .../java/pro/gravit/launcher/Launcher.java | 32 +-- .../pro/gravit/launcher/LauncherConfig.java | 10 +- .../launcher/config/JsonConfigurable.java | 10 +- .../config/JsonConfigurableInterface.java | 29 ++- .../VerifySecureTokenRequestEvent.java | 4 +- .../pro/gravit/launcher/hwid/OshiHWID.java | 12 +- .../launcher/profiles/ClientProfile.java | 108 +++++----- .../launcher/profiles/PlayerProfile.java | 15 +- .../pro/gravit/launcher/profiles/Texture.java | 11 +- .../profiles/optional/OptionalDepend.java | 6 +- .../profiles/optional/OptionalFile.java | 44 ++-- .../profiles/optional/OptionalType.java | 11 +- .../pro/gravit/launcher/request/Request.java | 7 +- .../launcher/request/RequestException.java | 8 +- .../gravit/launcher/request/RequestType.java | 3 +- .../request/admin/ExecCommandRequest.java | 3 +- .../launcher/request/auth/AuthRequest.java | 7 +- .../request/auth/CheckServerRequest.java | 3 +- .../request/auth/JoinServerRequest.java | 3 +- .../request/update/LauncherRequest.java | 10 +- .../uuid/BatchProfileByUsernameRequest.java | 3 +- .../request/uuid/ProfileByUUIDRequest.java | 3 +- .../uuid/ProfileByUsernameRequest.java | 3 +- .../authlib/yggdrasil/CompatBridge.java | 3 +- .../authlib/yggdrasil/CompatProfile.java | 3 +- .../authlib/yggdrasil/LegacyBridge.java | 3 +- .../java/pro/gravit/launcher/LauncherAPI.java | 14 -- .../launcher/hasher/FileNameMatcher.java | 4 +- .../pro/gravit/launcher/hasher/HashedDir.java | 25 ++- .../gravit/launcher/hasher/HashedEntry.java | 9 +- .../gravit/launcher/hasher/HashedFile.java | 15 +- .../pro/gravit/launcher/serialize/HInput.java | 35 ++-- .../gravit/launcher/serialize/HOutput.java | 31 ++- .../launcher/serialize/SerializeLimits.java | 8 +- .../serialize/signed/DigestBytesHolder.java | 11 +- .../serialize/stream/EnumSerializer.java | 9 +- .../serialize/stream/StreamObject.java | 7 +- .../main/java/pro/gravit/utils/Version.java | 30 ++- .../pro/gravit/utils/helper/CommonHelper.java | 19 +- .../pro/gravit/utils/helper/IOHelper.java | 196 +++++++++--------- .../pro/gravit/utils/helper/JVMHelper.java | 26 ++- .../pro/gravit/utils/helper/LogHelper.java | 87 ++++---- .../gravit/utils/helper/SecurityHelper.java | 6 +- .../pro/gravit/utils/helper/VerifyHelper.java | 42 ++-- 57 files changed, 510 insertions(+), 593 deletions(-) delete mode 100644 LauncherCore/src/main/java/pro/gravit/launcher/LauncherAPI.java diff --git a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/proguard.cfg b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/proguard.cfg index 08b511c1..d3f335ad 100644 --- a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/proguard.cfg +++ b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/proguard.cfg @@ -16,29 +16,17 @@ -keepattributes Signature -adaptresourcefilecontents META-INF/MANIFEST.MF --keeppackagenames com.mojang.**,net.minecraftforge.fml.**,cpw.mods.fml.**,com.google.gson.**,pro.gravit.repackage.**,org.fusesource.**, pro.gravit.launcher.api.** +-keeppackagenames com.mojang.**,net.minecraftforge.fml.**,cpw.mods.fml.**,com.google.gson.**,pro.gravit.repackage.**,org.fusesource.**, pro.gravit.launcher.api.**, pro.gravit.utils.**, pro.gravit.launcher.request.**, pro.gravit.launcher.events.**, pro.gravit.launcher.profiles.** --keep class com.mojang.**,net.minecraftforge.fml.**,cpw.mods.fml.**,com.google.gson.**,pro.gravit.repackage.**,org.fusesource.**, pro.gravit.launcher.api.** { +-keep class com.mojang.**,net.minecraftforge.fml.**,cpw.mods.fml.**,com.google.gson.**,pro.gravit.repackage.**,org.fusesource.**, pro.gravit.launcher.api.**, pro.gravit.utils.**, pro.gravit.launcher.request.**, pro.gravit.launcher.events.**, pro.gravit.launcher.profiles.** { *; } --keepclassmembers @pro.gravit.launcher.LauncherAPI class ** { - ; - ; -} - -keepclassmembers @pro.gravit.launcher.LauncherNetworkAPI class ** { ; ; } --keepclassmembers class ** { - @pro.gravit.launcher.LauncherAPI - ; - @pro.gravit.launcher.LauncherAPI - ; -} - -keepclassmembers class ** { @pro.gravit.launcher.LauncherNetworkAPI ; diff --git a/Launcher/src/main/java/pro/gravit/launcher/JSApplication.java b/Launcher/src/main/java/pro/gravit/launcher/JSApplication.java index 47937e7c..550914d7 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/JSApplication.java +++ b/Launcher/src/main/java/pro/gravit/launcher/JSApplication.java @@ -7,7 +7,7 @@ public abstract class JSApplication extends Application { private static final AtomicReference INSTANCE = new AtomicReference<>(); - @LauncherAPI + public static JSApplication getInstance() { return INSTANCE.get(); } diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherAgent.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherAgent.java index 5309d878..ae8170cb 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherAgent.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherAgent.java @@ -10,7 +10,7 @@ import java.nio.file.Path; import java.util.jar.JarFile; -@LauncherAPI + public final class LauncherAgent { private static boolean isAgentStarted = false; public static Instrumentation inst; diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index ae9c10f8..7545e6ae 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -126,7 +126,7 @@ private LauncherEngine() { } - @LauncherAPI + public void start(String... args) throws Throwable { //Launcher.modulesManager = new ClientModuleManager(this); ClientPreGuiPhase event = new ClientPreGuiPhase(null); diff --git a/Launcher/src/main/java/pro/gravit/launcher/NewLauncherSettings.java b/Launcher/src/main/java/pro/gravit/launcher/NewLauncherSettings.java index b812b3c5..f95be120 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/NewLauncherSettings.java +++ b/Launcher/src/main/java/pro/gravit/launcher/NewLauncherSettings.java @@ -8,21 +8,17 @@ import java.util.*; public class NewLauncherSettings { - @LauncherAPI + @LauncherNetworkAPI public Map userSettings = new HashMap<>(); - @LauncherAPI + @LauncherNetworkAPI public List features = new ArrayList<>(); - @LauncherAPI + @LauncherNetworkAPI public String consoleUnlockKey; public static class HashedStoreEntry { - @LauncherAPI public final HashedDir hdir; - @LauncherAPI public final String name; - @LauncherAPI public final String fullPath; - @LauncherAPI public transient boolean needSave = false; public HashedStoreEntry(HashedDir hdir, String name, String fullPath) { @@ -32,10 +28,9 @@ public HashedStoreEntry(HashedDir hdir, String name, String fullPath) { } } - @LauncherAPI + @LauncherNetworkAPI public final transient List lastHDirs = new ArrayList<>(16); - @LauncherAPI public void putHDir(String name, Path path, HashedDir dir) { String fullPath = path.toAbsolutePath().toString(); lastHDirs.removeIf((e) -> e.fullPath.equals(fullPath) && e.name.equals(name)); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientClassLoader.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientClassLoader.java index 682d0ec1..4c007042 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientClassLoader.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientClassLoader.java @@ -1,6 +1,5 @@ package pro.gravit.launcher.client; -import pro.gravit.launcher.LauncherAPI; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.JVMHelper; diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index 4e85be4d..4d9e2aef 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -49,7 +49,7 @@ public final class ClientLauncher { - @LauncherAPI + public static int getClientJVMBits() { return LauncherGuardManager.guard.getClientJVMBits(); } @@ -71,30 +71,30 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO public static final class Params extends StreamObject { // Client paths - @LauncherAPI + public final Path assetDir; - @LauncherAPI + public final Path clientDir; // Client params - @LauncherAPI + public final PlayerProfile pp; - @LauncherAPI + public final String accessToken; - @LauncherAPI + public final boolean autoEnter; - @LauncherAPI + public final boolean fullScreen; - @LauncherAPI + public final int ram; - @LauncherAPI + public final int width; - @LauncherAPI + public final int height; - @LauncherAPI + public final long session; - @LauncherAPI + public Params(byte[] launcherDigest, Path assetDir, Path clientDir, PlayerProfile pp, String accessToken, boolean autoEnter, boolean fullScreen, int ram, int width, int height) { // Client paths @@ -111,7 +111,7 @@ public Params(byte[] launcherDigest, Path assetDir, Path clientDir, PlayerProfil this.session = Request.getSession(); } - @LauncherAPI + public Params(HInput input) throws Exception { session = input.readLong(); // Client paths @@ -165,13 +165,13 @@ public void write(HOutput output) throws IOException { private static ClientClassLoader classLoader; public static class ClientUserProperties { - @LauncherAPI + String[] skinURL; - @LauncherAPI + String[] skinDigest; - @LauncherAPI + String[] cloakURL; - @LauncherAPI + String[] cloakDigest; } @@ -233,7 +233,7 @@ private static void addClientArgs(Collection args, ClientProfile profile } } - @LauncherAPI + public static void setJavaBinPath(Path javaBinPath) { JavaBinPath = javaBinPath; } @@ -248,7 +248,7 @@ private static void addClientLegacyArgs(Collection args, ClientProfile p Collections.addAll(args, "--assetsDir", params.assetDir.toString()); } - @LauncherAPI + public static void checkJVMBitsAndVersion() { if (JVMHelper.JVM_BITS != JVMHelper.OS_BITS) { String error = String.format("У Вас установлена Java %d, но Ваша система определена как %d. Установите Java правильной разрядности", JVMHelper.JVM_BITS, JVMHelper.OS_BITS); @@ -266,7 +266,7 @@ public static void checkJVMBitsAndVersion() { } } - @LauncherAPI + public static boolean isLaunched() { return Launcher.LAUNCHED.get(); } @@ -321,7 +321,7 @@ public static void setClientStarted() { public static PlayerProfile playerProfile; - @LauncherAPI + public static Process launch( HashedDir assetHDir, HashedDir clientHDir, ClientProfile profile, Params params, boolean pipeOutput) throws Throwable { @@ -432,7 +432,7 @@ public ClientLaunchContext(Params params, ClientProfile profile, HashedDir asset } } - @LauncherAPI + public static void main(String... args) throws Throwable { LauncherEngine.IS_CLIENT.set(true); LauncherEngine engine = LauncherEngine.clientInstance(); @@ -570,7 +570,7 @@ private static void initGson(ClientModuleManager moduleManager) { Launcher.gsonManager.initGson(); } - @LauncherAPI + public static void setProfile(ClientProfile profile) { Launcher.profile = profile; LogHelper.debug("New Profile name: %s", profile.getTitle()); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/DirBridge.java b/Launcher/src/main/java/pro/gravit/launcher/client/DirBridge.java index f33fe32e..f9e4c40e 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/DirBridge.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/DirBridge.java @@ -1,7 +1,6 @@ package pro.gravit.launcher.client; import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.LauncherAPI; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.LogHelper; @@ -17,26 +16,26 @@ public class DirBridge { public static final String CUSTOMDIR_PROPERTY = "launcher.customdir"; public static final String USE_OPTDIR_PROPERTY = "launcher.useoptdir"; - @LauncherAPI + public static Path dir; - @LauncherAPI + public static Path dirStore; - @LauncherAPI + public static Path dirProjectStore; - @LauncherAPI + public static Path dirUpdates; - @LauncherAPI + public static Path defaultUpdatesDir; - @LauncherAPI + public static boolean useLegacyDir; - @LauncherAPI + public static void move(Path newDir) throws IOException { IOHelper.move(dirUpdates, newDir); dirUpdates = newDir; } - @LauncherAPI + public static Path getAppDataDir() throws IOException { boolean isCustomDir = Boolean.getBoolean(System.getProperty(USE_CUSTOMDIR_PROPERTY, "false")); if (isCustomDir) { @@ -66,12 +65,12 @@ public static Path getAppDataDir() throws IOException { } } - @LauncherAPI + public static Path getLauncherDir(String projectname) throws IOException { return getAppDataDir().resolve(projectname); } - @LauncherAPI + public static Path getStoreDir(String projectname) throws IOException { if (JVMHelper.OS_TYPE == JVMHelper.OS.LINUX) return getAppDataDir().resolve("store"); @@ -81,22 +80,22 @@ else if (JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) return getAppDataDir().resolve("minecraftStore"); } - @LauncherAPI + public static Path getProjectStoreDir(String projectname) throws IOException { return getStoreDir(projectname).resolve(projectname); } - @LauncherAPI + public static Path getGuardDir() { return dir.resolve("guard"); } - @LauncherAPI + public static Path getLegacyLauncherDir(String projectname) { return IOHelper.HOME_DIR.resolve(projectname); } - @LauncherAPI + public static void setUseLegacyDir(boolean b) { useLegacyDir = b; } diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ServerPinger.java b/Launcher/src/main/java/pro/gravit/launcher/client/ServerPinger.java index 44ef6ae7..43f689d0 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ServerPinger.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ServerPinger.java @@ -2,7 +2,6 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.profiles.ClientProfile; import pro.gravit.launcher.serialize.HInput; import pro.gravit.launcher.serialize.HOutput; @@ -24,11 +23,11 @@ public final class ServerPinger { private final JsonParser parser = new JsonParser(); public static final class Result { - @LauncherAPI + public final int onlinePlayers; - @LauncherAPI + public final int maxPlayers; - @LauncherAPI + public final String raw; public Result(int onlinePlayers, int maxPlayers, String raw) { @@ -39,7 +38,7 @@ public Result(int onlinePlayers, int maxPlayers, String raw) { this.raw = raw; } - @LauncherAPI + public boolean isOverfilled() { return onlinePlayers >= maxPlayers; } @@ -75,7 +74,7 @@ private static void writeUTF16String(HOutput output, String s) throws IOExceptio private Instant cacheTime = null; - @LauncherAPI + public ServerPinger(ClientProfile profile) { this.address = Objects.requireNonNull(profile.getServerSocketAddress(), "address"); this.version = Objects.requireNonNull(profile.getVersion(), "version"); @@ -194,7 +193,7 @@ private Result modernPing(HInput input, HOutput output) throws IOException { return new Result(online, max, response); } - @LauncherAPI + public Result ping() throws IOException { Instant now = Instant.now(); synchronized (cacheLock) { diff --git a/Launcher/src/main/java/pro/gravit/launcher/managers/HasherStore.java b/Launcher/src/main/java/pro/gravit/launcher/managers/HasherStore.java index 3dab3a92..57095622 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/managers/HasherStore.java +++ b/Launcher/src/main/java/pro/gravit/launcher/managers/HasherStore.java @@ -1,6 +1,5 @@ package pro.gravit.launcher.managers; -import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.hasher.FileNameMatcher; import pro.gravit.launcher.hasher.HashedDir; import pro.gravit.launcher.hasher.HashedEntry; @@ -19,15 +18,15 @@ public class HasherStore { public Map store; public static class HasherStoreEnity { - @LauncherAPI + public HashedDir hdir; - @LauncherAPI + public Path dir; - @LauncherAPI + public Collection shared; } - @LauncherAPI + public void addProfileUpdateDir(ClientProfile profile, Path dir, HashedDir hdir) { HasherStoreEnity e = new HasherStoreEnity(); e.hdir = hdir; @@ -37,7 +36,7 @@ public void addProfileUpdateDir(ClientProfile profile, Path dir, HashedDir hdir) store.put(profile.getTitle(), e); } - @LauncherAPI + public void copyCompareFilesTo(String name, Path targetDir, HashedDir targetHDir, String[] shared) { store.forEach((key, e) -> { if (key.equals(name)) return; @@ -47,7 +46,7 @@ public void copyCompareFilesTo(String name, Path targetDir, HashedDir targetHDir }); } - @LauncherAPI + public void recurseCopy(String filename, HashedEntry entry, String name, Path targetDir, Path sourceDir) { if (!IOHelper.isDir(targetDir)) { try { diff --git a/Launcher/src/main/java/pro/gravit/launcher/managers/SettingsManager.java b/Launcher/src/main/java/pro/gravit/launcher/managers/SettingsManager.java index edf1dfe6..4d560957 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/managers/SettingsManager.java +++ b/Launcher/src/main/java/pro/gravit/launcher/managers/SettingsManager.java @@ -1,6 +1,5 @@ package pro.gravit.launcher.managers; -import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.NewLauncherSettings; import pro.gravit.launcher.client.DirBridge; import pro.gravit.launcher.config.JsonConfigurable; @@ -32,26 +31,26 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) } - @LauncherAPI + public static NewLauncherSettings settings; public SettingsManager() { super(NewLauncherSettings.class, DirBridge.dir.resolve("settings.json")); } - @LauncherAPI + @Override public NewLauncherSettings getConfig() { return settings; } - @LauncherAPI + @Override public NewLauncherSettings getDefaultConfig() { return new NewLauncherSettings(); } - @LauncherAPI + @Override public void setConfig(NewLauncherSettings config) { settings = config; @@ -63,13 +62,13 @@ public void setConfig(NewLauncherSettings config) { } } - @LauncherAPI + public void loadHDirStore(Path storePath) throws IOException { Files.createDirectories(storePath); IOHelper.walk(storePath, new StoreFileVisitor(), false); } - @LauncherAPI + public void saveHDirStore(Path storeProjectPath) throws IOException { Files.createDirectories(storeProjectPath); for (NewLauncherSettings.HashedStoreEntry e : settings.lastHDirs) { @@ -84,12 +83,12 @@ public void saveHDirStore(Path storeProjectPath) throws IOException { } } - @LauncherAPI + public void loadHDirStore() throws IOException { loadHDirStore(DirBridge.dirStore); } - @LauncherAPI + public void saveHDirStore() throws IOException { saveHDirStore(DirBridge.dirProjectStore); } diff --git a/Launcher/src/main/java/pro/gravit/launcher/utils/DirWatcher.java b/Launcher/src/main/java/pro/gravit/launcher/utils/DirWatcher.java index 631ee137..ea0edbbf 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/utils/DirWatcher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/utils/DirWatcher.java @@ -1,6 +1,5 @@ package pro.gravit.launcher.utils; -import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.hasher.FileNameMatcher; import pro.gravit.launcher.hasher.HashedDir; import pro.gravit.launcher.hasher.HashedEntry; @@ -69,7 +68,7 @@ private static Deque toPath(Iterable path) { private final boolean digest; - @LauncherAPI + public DirWatcher(Path dir, HashedDir hdir, FileNameMatcher matcher, boolean digest) throws IOException { this.dir = Objects.requireNonNull(dir, "dir"); this.hdir = Objects.requireNonNull(hdir, "hdir"); @@ -83,7 +82,7 @@ public DirWatcher(Path dir, HashedDir hdir, FileNameMatcher matcher, boolean dig } @Override - @LauncherAPI + public void close() throws IOException { service.close(); } @@ -124,7 +123,7 @@ private void processLoop() throws IOException, InterruptedException { } @Override - @LauncherAPI + public void run() { try { processLoop(); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/ClientPermissions.java b/LauncherAPI/src/main/java/pro/gravit/launcher/ClientPermissions.java index 7201063c..db3ddd3a 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/ClientPermissions.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/ClientPermissions.java @@ -8,17 +8,17 @@ public class ClientPermissions { public static final ClientPermissions DEFAULT = new ClientPermissions(); - @LauncherAPI + @LauncherNetworkAPI public boolean canAdmin; - @LauncherAPI + @LauncherNetworkAPI public boolean canServer; - @LauncherAPI + @LauncherNetworkAPI public final boolean canUSR1; - @LauncherAPI + @LauncherNetworkAPI public final boolean canUSR2; - @LauncherAPI + @LauncherNetworkAPI public final boolean canUSR3; - @LauncherAPI + @LauncherNetworkAPI public boolean canBot; public ClientPermissions(HInput input) throws IOException { @@ -43,7 +43,7 @@ public ClientPermissions(long data) { canBot = (data & (1 << 5)) != 0; } - @LauncherAPI + public long toLong() { long result = 0; result |= !canAdmin ? 0 : 1; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/Launcher.java b/LauncherAPI/src/main/java/pro/gravit/launcher/Launcher.java index 70dafc79..b9796166 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/Launcher.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/Launcher.java @@ -20,42 +20,42 @@ public final class Launcher { // Authlib constants - @LauncherAPI + public static final String SKIN_URL_PROPERTY = "skinURL"; - @LauncherAPI + public static final String SKIN_DIGEST_PROPERTY = "skinDigest"; - @LauncherAPI + public static final String CLOAK_URL_PROPERTY = "cloakURL"; - @LauncherAPI + public static final String CLOAK_DIGEST_PROPERTY = "cloakDigest"; // Used to determine from clientside is launched from launcher public static final AtomicBoolean LAUNCHED = new AtomicBoolean(false); private static final AtomicReference CONFIG = new AtomicReference<>(); - @LauncherAPI + public static final int PROTOCOL_MAGIC_LEGACY = 0x724724_00 + 24; - @LauncherAPI + public static final int PROTOCOL_MAGIC = 0xA205B064; // e = 2.718281828 // Constants - @LauncherAPI + public static final String RUNTIME_DIR = "runtime"; - @LauncherAPI + public static final String GUARD_DIR = "guard"; - @LauncherAPI + public static final String CONFIG_FILE = "config.bin"; - @LauncherAPI + public static ClientProfile profile; - @LauncherAPI + public static final String INIT_SCRIPT_FILE = "init.js"; - @LauncherAPI + public static final String API_SCRIPT_FILE = "engine/api.js"; public static final String CONFIG_SCRIPT_FILE = "config.js"; private static final Pattern UUID_PATTERN = Pattern.compile("-", Pattern.LITERAL); public static GsonManager gsonManager; - @LauncherAPI + public static LauncherConfig getConfig() { LauncherConfig config = CONFIG.get(); if (config == null) { @@ -69,12 +69,12 @@ public static LauncherConfig getConfig() { return config; } - @LauncherAPI + public static void setConfig(LauncherConfig cfg) { CONFIG.set(cfg); } - @LauncherAPI + public static URL getResourceURL(String name) throws IOException { LauncherConfig config = getConfig(); byte[] validDigest = config.runtime.get(name); @@ -105,7 +105,7 @@ public static URL getResourceURL(String name, String prefix) throws IOException return url; } - @LauncherAPI + public static String toHash(UUID uuid) { return UUID_PATTERN.matcher(uuid.toString()).replaceAll(""); } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java b/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java index 037c541f..9efbb4b6 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java @@ -24,16 +24,16 @@ public static AutogenConfig getAutogenConfig() { // Instance public String address; - @LauncherAPI + public final String projectName; public final int clientPort; public String secretKeyClient; public String oemUnlockKey; public final LauncherTrustManager trustManager; - @LauncherAPI + public final ECPublicKey publicKey; - @LauncherAPI + public final Map runtime; public final boolean isWarningMissArchJava; public boolean isNettyEnabled; @@ -45,7 +45,7 @@ public static AutogenConfig getAutogenConfig() { public final String secureCheckSalt; public final String passwordEncryptKey; - @LauncherAPI + public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException { publicKey = SecurityHelper.toPublicECKey(input.readByteArray(SecurityHelper.CRYPTO_MAX_LENGTH)); secureCheckHash = config.secureCheckHash; @@ -84,7 +84,7 @@ public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException runtime = Collections.unmodifiableMap(localResources); } - @LauncherAPI + public LauncherConfig(String address, ECPublicKey publicKey, Map runtime, String projectName) { this.address = address; this.publicKey = publicKey; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/config/JsonConfigurable.java b/LauncherAPI/src/main/java/pro/gravit/launcher/config/JsonConfigurable.java index 9d7adec5..373fe21e 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/config/JsonConfigurable.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/config/JsonConfigurable.java @@ -1,7 +1,5 @@ package pro.gravit.launcher.config; -import pro.gravit.launcher.LauncherAPI; - import java.lang.reflect.Type; import java.nio.file.Path; @@ -9,7 +7,7 @@ public abstract class JsonConfigurable implements JsonConfigurableInterface { - @LauncherAPI + default void saveConfig() throws IOException { saveConfig(getPath()); } - @LauncherAPI + default void loadConfig() throws IOException { loadConfig(getPath()); } - @LauncherAPI + default void saveConfig(Gson gson, Path configPath) throws IOException { try (BufferedWriter writer = IOHelper.newWriter(configPath)) { gson.toJson(getConfig(), getType(), writer); } } - @LauncherAPI + default void loadConfig(Gson gson, Path configPath) throws IOException { if (generateConfigIfNotExists(configPath)) return; try (BufferedReader reader = IOHelper.newReader(configPath)) { @@ -41,29 +40,29 @@ default void loadConfig(Gson gson, Path configPath) throws IOException { } } - @LauncherAPI + default void saveConfig(Path configPath) throws IOException { saveConfig(Launcher.gsonManager.configGson, configPath); } - @LauncherAPI + default void loadConfig(Path configPath) throws IOException { loadConfig(Launcher.gsonManager.configGson, configPath); } - @LauncherAPI + default void resetConfig() throws IOException { setConfig(getDefaultConfig()); saveConfig(); } - @LauncherAPI + default void resetConfig(Path newPath) throws IOException { setConfig(getDefaultConfig()); saveConfig(newPath); } - @LauncherAPI + default boolean generateConfigIfNotExists(Path path) throws IOException { if (IOHelper.isFile(path)) return false; @@ -71,7 +70,7 @@ default boolean generateConfigIfNotExists(Path path) throws IOException { return true; } - @LauncherAPI + default boolean generateConfigIfNotExists() throws IOException { if (IOHelper.isFile(getPath())) return false; @@ -79,16 +78,16 @@ default boolean generateConfigIfNotExists() throws IOException { return true; } - @LauncherAPI + T getConfig(); - @LauncherAPI + T getDefaultConfig(); - @LauncherAPI + void setConfig(T config); - @LauncherAPI + Path getPath(); Type getType(); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/VerifySecureTokenRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/VerifySecureTokenRequestEvent.java index 12a6e7bb..276000b7 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/VerifySecureTokenRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/VerifySecureTokenRequestEvent.java @@ -1,10 +1,10 @@ package pro.gravit.launcher.events.request; -import pro.gravit.launcher.LauncherAPI; +import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.RequestEvent; public class VerifySecureTokenRequestEvent extends RequestEvent { - @LauncherAPI + @LauncherNetworkAPI public final boolean success; @Override diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/OshiHWID.java b/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/OshiHWID.java index 405a2f9c..5fbade47 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/OshiHWID.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/OshiHWID.java @@ -1,22 +1,22 @@ package pro.gravit.launcher.hwid; import com.google.gson.Gson; -import pro.gravit.launcher.LauncherAPI; +import pro.gravit.launcher.LauncherNetworkAPI; import java.util.Objects; import java.util.StringJoiner; public class OshiHWID implements HWID { public static Gson gson = new Gson(); - @LauncherAPI + @LauncherNetworkAPI public long totalMemory = 0; - @LauncherAPI + @LauncherNetworkAPI public String serialNumber; - @LauncherAPI + @LauncherNetworkAPI public String HWDiskSerial; - @LauncherAPI + @LauncherNetworkAPI public String processorID; - @LauncherAPI + @LauncherNetworkAPI public String macAddr; @Override diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java index 3530d993..92435b5a 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java @@ -1,6 +1,6 @@ package pro.gravit.launcher.profiles; -import pro.gravit.launcher.LauncherAPI; +import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.hasher.FileNameMatcher; import pro.gravit.launcher.hasher.HashedDir; import pro.gravit.launcher.profiles.optional.OptionalDepend; @@ -14,7 +14,7 @@ import java.util.*; public final class ClientProfile implements Comparable { - @LauncherAPI + public enum Version { MC125("1.2.5", 29), MC147("1.4.7", 51), @@ -73,54 +73,54 @@ public String toString() { private static final FileNameMatcher ASSET_MATCHER = new FileNameMatcher( new String[0], new String[]{"indexes", "objects"}, new String[0]); // Version - @LauncherAPI + @LauncherNetworkAPI private String version; - @LauncherAPI + @LauncherNetworkAPI private String assetIndex; - @LauncherAPI + @LauncherNetworkAPI private String dir; - @LauncherAPI + @LauncherNetworkAPI private String assetDir; // Client - @LauncherAPI + @LauncherNetworkAPI private int sortIndex; - @LauncherAPI + @LauncherNetworkAPI private UUID uuid; - @LauncherAPI + @LauncherNetworkAPI private String title; - @LauncherAPI + @LauncherNetworkAPI private String info; - @LauncherAPI + @LauncherNetworkAPI private String serverAddress; - @LauncherAPI + @LauncherNetworkAPI private int serverPort; // Updater and client watch service - @LauncherAPI + @LauncherNetworkAPI private final List update = new ArrayList<>(); - @LauncherAPI + @LauncherNetworkAPI private final List updateExclusions = new ArrayList<>(); - @LauncherAPI + @LauncherNetworkAPI private final List updateShared = new ArrayList<>(); - @LauncherAPI + @LauncherNetworkAPI private final List updateVerify = new ArrayList<>(); - @LauncherAPI + @LauncherNetworkAPI private final Set updateOptional = new HashSet<>(); - @LauncherAPI + @LauncherNetworkAPI private boolean updateFastCheck; - @LauncherAPI + @LauncherNetworkAPI private boolean useWhitelist; // Client launcher - @LauncherAPI + @LauncherNetworkAPI private String mainClass; - @LauncherAPI + @LauncherNetworkAPI private final List jvmArgs = new ArrayList<>(); - @LauncherAPI + @LauncherNetworkAPI private final List classPath = new ArrayList<>(); - @LauncherAPI + @LauncherNetworkAPI private final List clientArgs = new ArrayList<>(); - @LauncherAPI + @LauncherNetworkAPI private final List whitelist = new ArrayList<>(); @Override @@ -128,27 +128,27 @@ public int compareTo(ClientProfile o) { return Integer.compare(getSortIndex(), o.getSortIndex()); } - @LauncherAPI + public String getAssetIndex() { return assetIndex; } - @LauncherAPI + public FileNameMatcher getAssetUpdateMatcher() { return getVersion().compareTo(Version.MC1710) >= 0 ? ASSET_MATCHER : null; } - @LauncherAPI + public String[] getClassPath() { return classPath.toArray(new String[0]); } - @LauncherAPI + public String[] getClientArgs() { return clientArgs.toArray(new String[0]); } - @LauncherAPI + public String getDir() { return dir; } @@ -157,12 +157,12 @@ public void setDir(String dir) { this.dir = dir; } - @LauncherAPI + public String getAssetDir() { return assetDir; } - @LauncherAPI + public FileNameMatcher getClientUpdateMatcher(/*boolean excludeOptional*/) { String[] updateArray = update.toArray(new String[0]); String[] verifyArray = updateVerify.toArray(new String[0]); @@ -179,27 +179,27 @@ public FileNameMatcher getClientUpdateMatcher(/*boolean excludeOptional*/) { return new FileNameMatcher(updateArray, verifyArray, exclusionsArray); } - @LauncherAPI + public String[] getJvmArgs() { return jvmArgs.toArray(new String[0]); } - @LauncherAPI + public String getMainClass() { return mainClass; } - @LauncherAPI + public String getServerAddress() { return serverAddress; } - @LauncherAPI + public Set getOptional() { return updateOptional; } - @LauncherAPI + public void updateOptionalGraph() { for (OptionalFile file : updateOptional) { if (file.dependenciesFile != null) { @@ -217,19 +217,19 @@ public void updateOptionalGraph() { } } - @LauncherAPI + public OptionalFile getOptionalFile(String file, OptionalType type) { for (OptionalFile f : updateOptional) if (f.type.equals(type) && f.name.equals(file)) return f; return null; } - @LauncherAPI + public Collection getShared() { return updateShared; } - @LauncherAPI + public void markOptional(String name, OptionalType type) { OptionalFile file = getOptionalFile(name, type); if (file == null) { @@ -238,7 +238,7 @@ public void markOptional(String name, OptionalType type) { markOptional(file); } - @LauncherAPI + public void markOptional(OptionalFile file) { if (file.mark) return; @@ -257,7 +257,7 @@ public void markOptional(OptionalFile file) { } } - @LauncherAPI + public void unmarkOptional(String name, OptionalType type) { OptionalFile file = getOptionalFile(name, type); if (file == null) { @@ -266,7 +266,7 @@ public void unmarkOptional(String name, OptionalType type) { unmarkOptional(file); } - @LauncherAPI + public void unmarkOptional(OptionalFile file) { if (!file.mark) return; file.mark = false; @@ -330,58 +330,58 @@ public interface pushOptionalClassPathCallback { void run(String[] opt) throws IOException; } - @LauncherAPI + public int getServerPort() { return serverPort; } - @LauncherAPI + public InetSocketAddress getServerSocketAddress() { return InetSocketAddress.createUnresolved(getServerAddress(), getServerPort()); } - @LauncherAPI + public int getSortIndex() { return sortIndex; } - @LauncherAPI + public String getTitle() { return title; } - @LauncherAPI + public String getInfo() { return info; } - @LauncherAPI + public Version getVersion() { return Version.byName(version); } - @LauncherAPI + public boolean isUpdateFastCheck() { return updateFastCheck; } - @LauncherAPI + public boolean isWhitelistContains(String username) { if (!useWhitelist) return true; return whitelist.stream().anyMatch(profileCaseSensitive ? e -> e.equals(username) : e -> e.equalsIgnoreCase(username)); } - @LauncherAPI + public void setTitle(String title) { this.title = title; } - @LauncherAPI + public void setInfo(String info) { this.info = info; } - @LauncherAPI + public void setVersion(Version version) { this.version = version.name; } @@ -399,7 +399,7 @@ public UUID getUUID() { return uuid; } - @LauncherAPI + public void verify() { // Version getVersion(); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/PlayerProfile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/PlayerProfile.java index 94f419af..108f0829 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/PlayerProfile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/PlayerProfile.java @@ -1,6 +1,5 @@ package pro.gravit.launcher.profiles; -import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.serialize.HInput; import pro.gravit.launcher.serialize.HOutput; import pro.gravit.launcher.serialize.stream.StreamObject; @@ -12,26 +11,26 @@ import java.util.UUID; public final class PlayerProfile extends StreamObject { - @LauncherAPI + public static PlayerProfile newOfflineProfile(String username) { return new PlayerProfile(offlineUUID(username), username, null, null); } - @LauncherAPI + public static UUID offlineUUID(String username) { return UUID.nameUUIDFromBytes(IOHelper.encodeASCII("OfflinePlayer:" + username)); } - @LauncherAPI + public final UUID uuid; - @LauncherAPI + public final String username; - @LauncherAPI + public final Texture skin, cloak; - @LauncherAPI + public PlayerProfile(HInput input) throws IOException { uuid = input.readUUID(); username = VerifyHelper.verifyUsername(input.readString(64)); @@ -39,7 +38,7 @@ public PlayerProfile(HInput input) throws IOException { cloak = input.readBoolean() ? new Texture(input) : null; } - @LauncherAPI + public PlayerProfile(UUID uuid, String username, Texture skin, Texture cloak) { this.uuid = Objects.requireNonNull(uuid, "uuid"); this.username = VerifyHelper.verifyUsername(username); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/Texture.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/Texture.java index 84869e1d..e836b661 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/Texture.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/Texture.java @@ -1,6 +1,5 @@ package pro.gravit.launcher.profiles; -import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.serialize.HInput; import pro.gravit.launcher.serialize.HOutput; import pro.gravit.launcher.serialize.stream.StreamObject; @@ -17,18 +16,18 @@ public final class Texture extends StreamObject { private static final SecurityHelper.DigestAlgorithm DIGEST_ALGO = SecurityHelper.DigestAlgorithm.SHA256; // Instance - @LauncherAPI + public final String url; - @LauncherAPI + public final byte[] digest; - @LauncherAPI + public Texture(HInput input) throws IOException { url = IOHelper.verifyURL(input.readASCII(2048)); digest = input.readByteArray(-DIGEST_ALGO.bytes); } - @LauncherAPI + public Texture(String url, boolean cloak) throws IOException { this.url = IOHelper.verifyURL(url); @@ -45,7 +44,7 @@ public Texture(String url, boolean cloak) throws IOException { digest = SecurityHelper.digest(DIGEST_ALGO, new URL(url)); } - @LauncherAPI + public Texture(String url, byte[] digest) { this.url = IOHelper.verifyURL(url); this.digest = Objects.requireNonNull(digest, "digest"); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalDepend.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalDepend.java index dcae88b7..3283fc03 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalDepend.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalDepend.java @@ -1,10 +1,10 @@ package pro.gravit.launcher.profiles.optional; -import pro.gravit.launcher.LauncherAPI; +import pro.gravit.launcher.LauncherNetworkAPI; public class OptionalDepend { - @LauncherAPI + @LauncherNetworkAPI public String name; - @LauncherAPI + @LauncherNetworkAPI public OptionalType type; } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalFile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalFile.java index e4061f82..43d5f22a 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalFile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalFile.java @@ -1,6 +1,6 @@ package pro.gravit.launcher.profiles.optional; -import pro.gravit.launcher.LauncherAPI; +import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.serialize.HInput; import pro.gravit.launcher.serialize.HOutput; import pro.gravit.utils.helper.LogHelper; @@ -10,33 +10,33 @@ import java.util.Set; public class OptionalFile { - @LauncherAPI + @LauncherNetworkAPI public String[] list; - @LauncherAPI + @LauncherNetworkAPI public OptionalType type; - @LauncherAPI + @LauncherNetworkAPI public boolean mark; - @LauncherAPI + @LauncherNetworkAPI public final boolean visible = true; - @LauncherAPI + @LauncherNetworkAPI public String name; - @LauncherAPI + @LauncherNetworkAPI public String info; - @LauncherAPI + @LauncherNetworkAPI public OptionalDepend[] dependenciesFile; - @LauncherAPI + @LauncherNetworkAPI public OptionalDepend[] conflictFile; - @LauncherAPI + @LauncherNetworkAPI public transient OptionalFile[] dependencies; - @LauncherAPI + @LauncherNetworkAPI public transient OptionalFile[] conflict; - @LauncherAPI + @LauncherNetworkAPI public int subTreeLevel = 1; - @LauncherAPI + @LauncherNetworkAPI public boolean isPreset; - @LauncherAPI + @LauncherNetworkAPI public final long permissions = 0L; - @LauncherAPI + public transient Set dependenciesCount; @Override @@ -51,32 +51,32 @@ public int hashCode() { return Objects.hash(name); } - @LauncherAPI + public OptionalType getType() { return OptionalType.FILE; } - @LauncherAPI + public String getName() { return name; } - @LauncherAPI + public boolean isVisible() { return visible; } - @LauncherAPI + public boolean isMark() { return mark; } - @LauncherAPI + public long getPermissions() { return permissions; } - @LauncherAPI + public void writeType(HOutput output) throws IOException { switch (type) { @@ -98,7 +98,7 @@ public void writeType(HOutput output) throws IOException { } } - @LauncherAPI + public static OptionalType readType(HInput input) throws IOException { int t = input.readInt(); OptionalType type; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalType.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalType.java index 5965bdf3..875dc809 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalType.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalType.java @@ -1,15 +1,14 @@ package pro.gravit.launcher.profiles.optional; -import pro.gravit.launcher.LauncherAPI; +import pro.gravit.launcher.LauncherNetworkAPI; -@LauncherAPI public enum OptionalType { - @LauncherAPI + @LauncherNetworkAPI FILE, - @LauncherAPI + @LauncherNetworkAPI CLASSPATH, - @LauncherAPI + @LauncherNetworkAPI JVMARGS, - @LauncherAPI + @LauncherNetworkAPI CLIENTARGS } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java index b0d11608..b7ef97ce 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java @@ -1,7 +1,6 @@ package pro.gravit.launcher.request; import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.request.websockets.StandartClientWebSocketService; import pro.gravit.launcher.request.websockets.WebSocketRequest; @@ -24,14 +23,14 @@ public static long getSession() { return Request.session; } - @LauncherAPI + public static void requestError(String message) throws RequestException { throw new RequestException(message); } private transient final AtomicBoolean started = new AtomicBoolean(false); - @LauncherAPI + public R request() throws Exception { if (!started.compareAndSet(false, true)) throw new IllegalStateException("Request already started"); @@ -40,7 +39,7 @@ public R request() throws Exception { return requestDo(service); } - @LauncherAPI + public R request(StandartClientWebSocketService service) throws Exception { if (!started.compareAndSet(false, true)) throw new IllegalStateException("Request already started"); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/RequestException.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/RequestException.java index 5b2fe42f..93285c79 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/RequestException.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/RequestException.java @@ -1,23 +1,21 @@ package pro.gravit.launcher.request; -import pro.gravit.launcher.LauncherAPI; - import java.io.IOException; public final class RequestException extends IOException { private static final long serialVersionUID = 7558237657082664821L; - @LauncherAPI + public RequestException(String message) { super(message); } - @LauncherAPI + public RequestException(String message, Throwable exc) { super(message, exc); } - @LauncherAPI + public RequestException(Throwable exc) { super(exc); } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/RequestType.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/RequestType.java index 8c9ed549..1ed05a62 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/RequestType.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/RequestType.java @@ -1,6 +1,5 @@ package pro.gravit.launcher.request; -import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.serialize.HInput; import pro.gravit.launcher.serialize.stream.EnumSerializer; @@ -15,7 +14,7 @@ public enum RequestType implements EnumSerializer.Itf { CUSTOM(255); // Custom requests private static final EnumSerializer SERIALIZER = new EnumSerializer<>(RequestType.class); - @LauncherAPI + public static RequestType read(HInput input) throws IOException { return SERIALIZER.read(input); } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/admin/ExecCommandRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/admin/ExecCommandRequest.java index 802bd43b..69cf6f79 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/admin/ExecCommandRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/admin/ExecCommandRequest.java @@ -1,12 +1,11 @@ package pro.gravit.launcher.request.admin; -import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.events.request.ExecCommandRequestEvent; import pro.gravit.launcher.request.Request; import pro.gravit.launcher.request.websockets.WebSocketRequest; public class ExecCommandRequest extends Request implements WebSocketRequest { - @LauncherAPI + public final String cmd; public ExecCommandRequest(String cmd) { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/AuthRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/AuthRequest.java index 327a71d2..2d311294 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/AuthRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/AuthRequest.java @@ -1,6 +1,5 @@ package pro.gravit.launcher.request.auth; -import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.request.AuthRequestEvent; import pro.gravit.launcher.hwid.HWID; @@ -46,7 +45,7 @@ public enum ConnectTypes { PROXY } - @LauncherAPI + public AuthRequest(String login, byte[] password, HWID hwid) { this.login = VerifyHelper.verify(login, VerifyHelper.NOT_EMPTY, "Login can't be empty"); this.password = new AuthECPassword(password.clone()); @@ -57,7 +56,7 @@ public AuthRequest(String login, byte[] password, HWID hwid) { authType = ConnectTypes.CLIENT; } - @LauncherAPI + public AuthRequest(String login, byte[] password, HWID hwid, String auth_id) { this.login = VerifyHelper.verify(login, VerifyHelper.NOT_EMPTY, "Login can't be empty"); this.password = new AuthECPassword(password.clone()); @@ -68,7 +67,7 @@ public AuthRequest(String login, byte[] password, HWID hwid, String auth_id) { authType = ConnectTypes.CLIENT; } - @LauncherAPI + public AuthRequest(String login, byte[] password, HWID hwid, String customText, String auth_id) { this.login = VerifyHelper.verify(login, VerifyHelper.NOT_EMPTY, "Login can't be empty"); this.password = new AuthECPassword(password.clone()); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/CheckServerRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/CheckServerRequest.java index 6c918f4b..84e26e60 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/CheckServerRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/CheckServerRequest.java @@ -1,6 +1,5 @@ package pro.gravit.launcher.request.auth; -import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.request.CheckServerRequestEvent; import pro.gravit.launcher.request.Request; @@ -13,7 +12,7 @@ public final class CheckServerRequest extends Request i @LauncherNetworkAPI private final String serverID; - @LauncherAPI + public CheckServerRequest(String username, String serverID) { this.username = VerifyHelper.verifyUsername(username); this.serverID = VerifyHelper.verifyServerID(serverID); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/JoinServerRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/JoinServerRequest.java index f4ee91cf..031f78db 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/JoinServerRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/JoinServerRequest.java @@ -1,6 +1,5 @@ package pro.gravit.launcher.request.auth; -import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.request.JoinServerRequestEvent; import pro.gravit.launcher.request.Request; @@ -17,7 +16,7 @@ public final class JoinServerRequest extends Request imp @LauncherNetworkAPI private final String serverID; - @LauncherAPI + public JoinServerRequest(String username, String accessToken, String serverID) { this.username = VerifyHelper.verifyUsername(username); this.accessToken = accessToken; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/LauncherRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/LauncherRequest.java index 91109b14..1ba207ae 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/LauncherRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/LauncherRequest.java @@ -1,7 +1,6 @@ package pro.gravit.launcher.request.update; import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.request.LauncherRequestEvent; import pro.gravit.launcher.request.Request; @@ -30,16 +29,16 @@ public final class LauncherRequest extends Request impleme public final String secureSalt; @LauncherNetworkAPI public int launcher_type = EXE_BINARY ? 2 : 1; - @LauncherAPI + public static final Path BINARY_PATH = IOHelper.getCodeSource(Launcher.class); - @LauncherAPI + public static final Path C_BINARY_PATH = BINARY_PATH.getParent().resolve(IOHelper.getFileName(BINARY_PATH) + ".tmp"); - @LauncherAPI + public static final boolean EXE_BINARY = IOHelper.hasExtension(BINARY_PATH, "exe"); - @LauncherAPI + public static void update(LauncherRequestEvent result) throws IOException { List args = new ArrayList<>(8); args.add(IOHelper.resolveJavaBin(null).toString()); @@ -90,7 +89,6 @@ public LauncherRequestEvent requestDo(StandartClientWebSocketService service) th return result; } - @LauncherAPI public LauncherRequest() { Path launcherPath = IOHelper.getCodeSource(LauncherRequest.class); try { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/BatchProfileByUsernameRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/BatchProfileByUsernameRequest.java index cb46318f..356ade33 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/BatchProfileByUsernameRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/BatchProfileByUsernameRequest.java @@ -1,6 +1,5 @@ package pro.gravit.launcher.request.uuid; -import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.request.BatchProfileByUsernameRequestEvent; import pro.gravit.launcher.request.Request; @@ -22,7 +21,7 @@ static class Entry { @LauncherNetworkAPI private final Entry[] list; - @LauncherAPI + public BatchProfileByUsernameRequest(String... usernames) throws IOException { this.list = new Entry[usernames.length]; for (int i = 0; i < usernames.length; ++i) { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/ProfileByUUIDRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/ProfileByUUIDRequest.java index a5190965..14d0849e 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/ProfileByUUIDRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/ProfileByUUIDRequest.java @@ -1,6 +1,5 @@ package pro.gravit.launcher.request.uuid; -import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.request.ProfileByUUIDRequestEvent; import pro.gravit.launcher.request.Request; @@ -13,7 +12,7 @@ public final class ProfileByUUIDRequest extends Request path) { private final String[] exclusions; - @LauncherAPI + public FileNameMatcher(String[] update, String[] verify, String[] exclusions) { this.update = update; this.verify = verify; diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedDir.java b/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedDir.java index 1be50e9f..4eca5c70 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedDir.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedDir.java @@ -1,6 +1,5 @@ package pro.gravit.launcher.hasher; -import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.serialize.HInput; import pro.gravit.launcher.serialize.HOutput; @@ -19,9 +18,9 @@ public final class HashedDir extends HashedEntry { public static final class Diff { - @LauncherAPI + public final HashedDir mismatch; - @LauncherAPI + public final HashedDir extra; private Diff(HashedDir mismatch, HashedDir extra) { @@ -29,7 +28,7 @@ private Diff(HashedDir mismatch, HashedDir extra) { this.extra = extra; } - @LauncherAPI + public boolean isSame() { return mismatch.isEmpty() && extra.isEmpty(); } @@ -105,11 +104,11 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO @LauncherNetworkAPI private final Map map = new HashMap<>(32); - @LauncherAPI + public HashedDir() { } - @LauncherAPI + public HashedDir(HInput input) throws IOException { int entriesCount = input.readLength(0); for (int i = 0; i < entriesCount; i++) { @@ -134,19 +133,19 @@ public HashedDir(HInput input) throws IOException { } } - @LauncherAPI + public HashedDir(Path dir, FileNameMatcher matcher, boolean allowSymlinks, boolean digest) throws IOException { IOHelper.walk(dir, new HashFileVisitor(dir, matcher, allowSymlinks, digest), true); } - @LauncherAPI + public Diff diff(HashedDir other, FileNameMatcher matcher) { HashedDir mismatch = sideDiff(other, matcher, new LinkedList<>(), true); HashedDir extra = other.sideDiff(this, matcher, new LinkedList<>(), false); return new Diff(mismatch, extra); } - @LauncherAPI + public Diff compare(HashedDir other, FileNameMatcher matcher) { HashedDir mismatch = sideDiff(other, matcher, new LinkedList<>(), true); HashedDir extra = other.sideDiff(this, matcher, new LinkedList<>(), false); @@ -190,7 +189,7 @@ public void removeR(String name) { } } - @LauncherAPI + public HashedEntry getEntry(String name) { return map.get(name); } @@ -200,17 +199,17 @@ public Type getType() { return Type.DIR; } - @LauncherAPI + public boolean isEmpty() { return map.isEmpty(); } - @LauncherAPI + public Map map() { return Collections.unmodifiableMap(map); } - @LauncherAPI + public HashedEntry resolve(Iterable path) { HashedEntry current = this; for (String pathEntry : path) { diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedEntry.java b/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedEntry.java index 8ae689c1..9291307f 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedEntry.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedEntry.java @@ -1,6 +1,5 @@ package pro.gravit.launcher.hasher; -import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.serialize.HInput; import pro.gravit.launcher.serialize.stream.EnumSerializer; import pro.gravit.launcher.serialize.stream.StreamObject; @@ -8,7 +7,7 @@ import java.io.IOException; public abstract class HashedEntry extends StreamObject { - @LauncherAPI + public enum Type implements EnumSerializer.Itf { DIR(1), FILE(2); private static final EnumSerializer SERIALIZER = new EnumSerializer<>(Type.class); @@ -29,12 +28,12 @@ public int getNumber() { } } - @LauncherAPI + public boolean flag; // For external usage - @LauncherAPI + public abstract Type getType(); - @LauncherAPI + public abstract long size(); } diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedFile.java b/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedFile.java index d18b3405..e117596f 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedFile.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedFile.java @@ -1,6 +1,5 @@ package pro.gravit.launcher.hasher; -import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.serialize.HInput; import pro.gravit.launcher.serialize.HOutput; @@ -17,23 +16,23 @@ public final class HashedFile extends HashedEntry { public static final DigestAlgorithm DIGEST_ALGO = DigestAlgorithm.MD5; // Instance - @LauncherAPI + public final long size; @LauncherNetworkAPI private final byte[] digest; - @LauncherAPI + public HashedFile(HInput input) throws IOException { this(input.readVarLong(), input.readBoolean() ? input.readByteArray(-DIGEST_ALGO.bytes) : null); } - @LauncherAPI + public HashedFile(long size, byte[] digest) { this.size = VerifyHelper.verifyLong(size, VerifyHelper.L_NOT_NEGATIVE, "Illegal size: " + size); this.digest = digest == null ? null : DIGEST_ALGO.verify(digest).clone(); } - @LauncherAPI + public HashedFile(Path file, long size, boolean digest) throws IOException { this(size, digest ? SecurityHelper.digest(DIGEST_ALGO, file) : null); } @@ -43,12 +42,12 @@ public Type getType() { return Type.FILE; } - @LauncherAPI + public boolean isSame(HashedFile o) { return size == o.size && (digest == null || o.digest == null || Arrays.equals(digest, o.digest)); } - @LauncherAPI + public boolean isSame(Path file, boolean digest) throws IOException { if (size != IOHelper.readAttributes(file).size()) return false; @@ -60,7 +59,7 @@ public boolean isSame(Path file, boolean digest) throws IOException { return Arrays.equals(this.digest, actualDigest); } - @LauncherAPI + public boolean isSameDigest(byte[] digest) { return this.digest == null || digest == null || Arrays.equals(this.digest, digest); } diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/HInput.java b/LauncherCore/src/main/java/pro/gravit/launcher/serialize/HInput.java index 56367213..8e456425 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/HInput.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/serialize/HInput.java @@ -1,6 +1,5 @@ package pro.gravit.launcher.serialize; -import pro.gravit.launcher.LauncherAPI; import pro.gravit.utils.helper.IOHelper; import java.io.ByteArrayInputStream; @@ -12,15 +11,15 @@ import java.util.UUID; public final class HInput implements AutoCloseable { - @LauncherAPI + public final InputStream stream; - @LauncherAPI + public HInput(byte[] bytes) { stream = new ByteArrayInputStream(bytes); } - @LauncherAPI + public HInput(InputStream stream) { this.stream = Objects.requireNonNull(stream, "stream"); } @@ -30,17 +29,17 @@ public void close() throws IOException { stream.close(); } - @LauncherAPI + public String readASCII(int maxBytes) throws IOException { return IOHelper.decodeASCII(readByteArray(maxBytes)); } - @LauncherAPI + public BigInteger readBigInteger(int maxBytes) throws IOException { return new BigInteger(readByteArray(maxBytes)); } - @LauncherAPI + public boolean readBoolean() throws IOException { int b = readUnsignedByte(); switch (b) { @@ -53,41 +52,41 @@ public boolean readBoolean() throws IOException { } } - @LauncherAPI + public byte[] readByteArray(int max) throws IOException { byte[] bytes = new byte[readLength(max)]; IOHelper.read(stream, bytes); return bytes; } - @LauncherAPI + public int readInt() throws IOException { return (readUnsignedByte() << 24) + (readUnsignedByte() << 16) + (readUnsignedByte() << 8) + readUnsignedByte(); } - @LauncherAPI + public int readLength(int max) throws IOException { if (max < 0) return -max; return IOHelper.verifyLength(readVarInt(), max); } - @LauncherAPI + public long readLong() throws IOException { return (long) readInt() << 32 | readInt() & 0xFFFFFFFFL; } - @LauncherAPI + public short readShort() throws IOException { return (short) ((readUnsignedByte() << 8) + readUnsignedByte()); } - @LauncherAPI + public String readString(int maxBytes) throws IOException { return IOHelper.decode(readByteArray(maxBytes)); } - @LauncherAPI + public int readUnsignedByte() throws IOException { int b = stream.read(); if (b < 0) @@ -95,17 +94,17 @@ public int readUnsignedByte() throws IOException { return b; } - @LauncherAPI + public int readUnsignedShort() throws IOException { return Short.toUnsignedInt(readShort()); } - @LauncherAPI + public UUID readUUID() throws IOException { return new UUID(readLong(), readLong()); } - @LauncherAPI + public int readVarInt() throws IOException { int shift = 0; int result = 0; @@ -119,7 +118,7 @@ public int readVarInt() throws IOException { throw new IOException("VarInt too big"); } - @LauncherAPI + public long readVarLong() throws IOException { int shift = 0; long result = 0; diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/HOutput.java b/LauncherCore/src/main/java/pro/gravit/launcher/serialize/HOutput.java index 23669ce3..37ee3dc7 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/HOutput.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/serialize/HOutput.java @@ -1,6 +1,5 @@ package pro.gravit.launcher.serialize; -import pro.gravit.launcher.LauncherAPI; import pro.gravit.utils.helper.IOHelper; import java.io.Flushable; @@ -11,10 +10,10 @@ import java.util.UUID; public final class HOutput implements AutoCloseable, Flushable { - @LauncherAPI + public final OutputStream stream; - @LauncherAPI + public HOutput(OutputStream stream) { this.stream = Objects.requireNonNull(stream, "stream"); } @@ -29,28 +28,28 @@ public void flush() throws IOException { stream.flush(); } - @LauncherAPI + public void writeASCII(String s, int maxBytes) throws IOException { writeByteArray(IOHelper.encodeASCII(s), maxBytes); } - @LauncherAPI + public void writeBigInteger(BigInteger bi, int max) throws IOException { writeByteArray(bi.toByteArray(), max); } - @LauncherAPI + public void writeBoolean(boolean b) throws IOException { writeUnsignedByte(b ? 0b1 : 0b0); } - @LauncherAPI + public void writeByteArray(byte[] bytes, int max) throws IOException { writeLength(bytes.length, max); stream.write(bytes); } - @LauncherAPI + public void writeInt(int i) throws IOException { writeUnsignedByte(i >>> 24 & 0xFF); writeUnsignedByte(i >>> 16 & 0xFF); @@ -58,42 +57,42 @@ public void writeInt(int i) throws IOException { writeUnsignedByte(i & 0xFF); } - @LauncherAPI + public void writeLength(int length, int max) throws IOException { IOHelper.verifyLength(length, max); if (max >= 0) writeVarInt(length); } - @LauncherAPI + public void writeLong(long l) throws IOException { writeInt((int) (l >> 32)); writeInt((int) l); } - @LauncherAPI + public void writeShort(short s) throws IOException { writeUnsignedByte(s >>> 8 & 0xFF); writeUnsignedByte(s & 0xFF); } - @LauncherAPI + public void writeString(String s, int maxBytes) throws IOException { writeByteArray(IOHelper.encode(s), maxBytes); } - @LauncherAPI + public void writeUnsignedByte(int b) throws IOException { stream.write(b); } - @LauncherAPI + public void writeUUID(UUID uuid) throws IOException { writeLong(uuid.getMostSignificantBits()); writeLong(uuid.getLeastSignificantBits()); } - @LauncherAPI + public void writeVarInt(int i) throws IOException { while ((i & ~0x7FL) != 0) { writeUnsignedByte(i & 0x7F | 0x80); @@ -102,7 +101,7 @@ public void writeVarInt(int i) throws IOException { writeUnsignedByte(i); } - @LauncherAPI + public void writeVarLong(long l) throws IOException { while ((l & ~0x7FL) != 0) { writeUnsignedByte((int) l & 0x7F | 0x80); diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/SerializeLimits.java b/LauncherCore/src/main/java/pro/gravit/launcher/serialize/SerializeLimits.java index c1fae7cb..cd4f5551 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/SerializeLimits.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/serialize/SerializeLimits.java @@ -1,12 +1,10 @@ package pro.gravit.launcher.serialize; -import pro.gravit.launcher.LauncherAPI; - public class SerializeLimits { - @LauncherAPI + public static final int MAX_BATCH_SIZE = 128; - @LauncherAPI + public static final byte EXPECTED_BYTE = 0b01010101; - @LauncherAPI + public static final int MAX_DIGEST = 512; } diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/signed/DigestBytesHolder.java b/LauncherCore/src/main/java/pro/gravit/launcher/serialize/signed/DigestBytesHolder.java index e7af277d..34ae728f 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/signed/DigestBytesHolder.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/serialize/signed/DigestBytesHolder.java @@ -1,6 +1,5 @@ package pro.gravit.launcher.serialize.signed; -import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.serialize.HInput; import pro.gravit.launcher.serialize.HOutput; import pro.gravit.launcher.serialize.stream.StreamObject; @@ -14,7 +13,7 @@ public class DigestBytesHolder extends StreamObject { protected final byte[] bytes; private final byte[] digest; - @LauncherAPI + public DigestBytesHolder(byte[] bytes, byte[] digest, SecurityHelper.DigestAlgorithm algorithm) throws SignatureException { if (Arrays.equals(SecurityHelper.digest(algorithm, bytes), digest)) throw new SignatureException("Invalid digest"); @@ -22,23 +21,23 @@ public DigestBytesHolder(byte[] bytes, byte[] digest, SecurityHelper.DigestAlgor this.digest = digest.clone(); } - @LauncherAPI + public DigestBytesHolder(byte[] bytes, SecurityHelper.DigestAlgorithm algorithm) { this.bytes = bytes.clone(); this.digest = SecurityHelper.digest(algorithm, bytes); } - @LauncherAPI + public DigestBytesHolder(HInput input, SecurityHelper.DigestAlgorithm algorithm) throws IOException, SignatureException { this(input.readByteArray(0), input.readByteArray(-SecurityHelper.RSA_KEY_LENGTH), algorithm); } - @LauncherAPI + public final byte[] getBytes() { return bytes.clone(); } - @LauncherAPI + public final byte[] getDigest() { return digest.clone(); } diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/stream/EnumSerializer.java b/LauncherCore/src/main/java/pro/gravit/launcher/serialize/stream/EnumSerializer.java index ac6c283f..11cb8000 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/stream/EnumSerializer.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/serialize/stream/EnumSerializer.java @@ -1,6 +1,5 @@ package pro.gravit.launcher.serialize.stream; -import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.serialize.HInput; import pro.gravit.launcher.serialize.HOutput; import pro.gravit.launcher.serialize.stream.EnumSerializer.Itf; @@ -13,24 +12,24 @@ public final class EnumSerializer & Itf> { @FunctionalInterface public interface Itf { - @LauncherAPI + int getNumber(); } - @LauncherAPI + public static void write(HOutput output, Itf itf) throws IOException { output.writeVarInt(itf.getNumber()); } private final Map map = new HashMap<>(16); - @LauncherAPI + public EnumSerializer(Class clazz) { for (E e : clazz.getEnumConstants()) VerifyHelper.putIfAbsent(map, e.getNumber(), e, "Duplicate number for enum constant " + e.name()); } - @LauncherAPI + public E read(HInput input) throws IOException { int n = input.readVarInt(); return VerifyHelper.getMapValue(map, n, "Unknown enum number: " + n); diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/stream/StreamObject.java b/LauncherCore/src/main/java/pro/gravit/launcher/serialize/stream/StreamObject.java index 561d899f..1190cd26 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/stream/StreamObject.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/serialize/stream/StreamObject.java @@ -1,6 +1,5 @@ package pro.gravit.launcher.serialize.stream; -import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.serialize.HInput; import pro.gravit.launcher.serialize.HOutput; import pro.gravit.utils.helper.IOHelper; @@ -13,11 +12,11 @@ public abstract class StreamObject { @FunctionalInterface public interface Adapter { - @LauncherAPI + O convert(HInput input); } - @LauncherAPI + public final byte[] write() throws IOException { try (ByteArrayOutputStream array = IOHelper.newByteArrayOutput()) { try (HOutput output = new HOutput(array)) { @@ -27,6 +26,6 @@ public final byte[] write() throws IOException { } } - @LauncherAPI + public abstract void write(HOutput output) throws IOException; } diff --git a/LauncherCore/src/main/java/pro/gravit/utils/Version.java b/LauncherCore/src/main/java/pro/gravit/utils/Version.java index 78bc7b37..817dfe84 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/Version.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/Version.java @@ -1,19 +1,17 @@ package pro.gravit.utils; -import pro.gravit.launcher.LauncherAPI; - import java.util.*; public final class Version { - @LauncherAPI + public final int major; - @LauncherAPI + public final int minor; - @LauncherAPI + public final int patch; - @LauncherAPI + public final int build; - @LauncherAPI + public final Type release; public static final int MAJOR = 5; public static final int MINOR = 1; @@ -21,7 +19,7 @@ public final class Version { public static final int BUILD = 1; public static final Version.Type RELEASE = Type.DEV; - @LauncherAPI + public Version(int major, int minor, int patch) { this.major = major; this.minor = minor; @@ -30,7 +28,7 @@ public Version(int major, int minor, int patch) { release = Type.UNKNOWN; } - @LauncherAPI + public Version(int major, int minor, int patch, int build) { this.major = major; this.minor = minor; @@ -39,7 +37,7 @@ public Version(int major, int minor, int patch, int build) { release = Type.UNKNOWN; } - @LauncherAPI + public Version(int major, int minor, int patch, int build, Type release) { this.major = major; this.minor = minor; @@ -53,7 +51,7 @@ public static Version getVersion() { } @Override - @LauncherAPI + public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; @@ -64,30 +62,30 @@ public boolean equals(Object o) { build == that.build; } - @LauncherAPI + public String getVersionString() { return String.format("%d.%d.%d", major, minor, patch); } @Override - @LauncherAPI + public int hashCode() { return Objects.hash(major, minor, patch, build); } - @LauncherAPI + public String getReleaseStatus() { if (release.equals(Type.UNKNOWN)) return ""; return release.name().toLowerCase(Locale.ENGLISH); } @Override - @LauncherAPI + public String toString() { return String.format("%d.%d.%d-%d %s", major, minor, patch, build, getReleaseStatus()); } - @LauncherAPI + public enum Type { LTS, STABLE, diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/CommonHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/CommonHelper.java index 177aaabc..74963375 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/CommonHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/CommonHelper.java @@ -1,7 +1,6 @@ package pro.gravit.utils.helper; import com.google.gson.*; -import pro.gravit.launcher.LauncherAPI; import pro.gravit.utils.command.CommandException; import javax.script.ScriptEngine; @@ -16,9 +15,9 @@ import java.util.regex.Pattern; public final class CommonHelper { - @LauncherAPI + public static final ScriptEngineManager scriptManager = new ScriptEngineManager(); - @LauncherAPI + public static final ScriptEngineFactory nashornFactory = getEngineFactories(scriptManager); private static ScriptEngineFactory getEngineFactories(ScriptEngineManager manager) { @@ -28,19 +27,19 @@ private static ScriptEngineFactory getEngineFactories(ScriptEngineManager manage return null; } - @LauncherAPI + public static String low(String s) { return s.toLowerCase(Locale.US); } - @LauncherAPI + public static boolean multiMatches(Pattern[] pattern, String from) { for (Pattern p : pattern) if (p.matcher(from).matches()) return true; return false; } - @LauncherAPI + public static String multiReplace(Pattern[] pattern, String from, String replace) { Matcher m; String tmp = null; @@ -51,12 +50,12 @@ public static String multiReplace(Pattern[] pattern, String from, String replace return tmp != null ? tmp : from; } - @LauncherAPI + public static ScriptEngine newScriptEngine() { return nashornFactory.getScriptEngine(); } - @LauncherAPI + public static Thread newThread(String name, boolean daemon, Runnable runnable) { Thread thread = new Thread(runnable); thread.setDaemon(daemon); @@ -65,7 +64,7 @@ public static Thread newThread(String name, boolean daemon, Runnable runnable) { return thread; } - @LauncherAPI + public static String replace(String source, String... params) { for (int i = 0; i < params.length; i += 2) source = source.replace('%' + params[i] + '%', params[i + 1]); @@ -124,7 +123,7 @@ public static String[] parseCommand(CharSequence line) throws CommandException { return result.toArray(new String[0]); } - @LauncherAPI + public static GsonBuilder newBuilder() { return new GsonBuilder().registerTypeHierarchyAdapter(byte[].class, ByteArrayToBase64TypeAdapter.INSTANCE); diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java index c75bfe0d..f5defefe 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java @@ -1,7 +1,5 @@ package pro.gravit.utils.helper; -import pro.gravit.launcher.LauncherAPI; - import javax.imageio.ImageIO; import javax.imageio.ImageReader; import java.awt.image.BufferedImage; @@ -77,42 +75,42 @@ public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOExce } // Charset - @LauncherAPI + public static final Charset UNICODE_CHARSET = StandardCharsets.UTF_8; - @LauncherAPI + public static final Charset ASCII_CHARSET = StandardCharsets.US_ASCII; // Constants - @LauncherAPI + public static final int SOCKET_TIMEOUT = VerifyHelper.verifyInt( Integer.parseUnsignedInt(System.getProperty("launcher.socketTimeout", Integer.toString(30000))), VerifyHelper.POSITIVE, "launcher.socketTimeout can't be <= 0"); - @LauncherAPI + public static final int HTTP_TIMEOUT = VerifyHelper.verifyInt( Integer.parseUnsignedInt(System.getProperty("launcher.httpTimeout", Integer.toString(5000))), VerifyHelper.POSITIVE, "launcher.httpTimeout can't be <= 0"); - @LauncherAPI + public static final int BUFFER_SIZE = VerifyHelper.verifyInt( Integer.parseUnsignedInt(System.getProperty("launcher.bufferSize", Integer.toString(4096))), VerifyHelper.POSITIVE, "launcher.bufferSize can't be <= 0"); // Platform-dependent - @LauncherAPI + public static final String CROSS_SEPARATOR = "/"; - @LauncherAPI + public static final FileSystem FS = FileSystems.getDefault(); - @LauncherAPI + public static final String PLATFORM_SEPARATOR = FS.getSeparator(); // Увидел исключение на NetBSD beta добавил - @LauncherAPI + public static final boolean POSIX = FS.supportedFileAttributeViews().contains("posix") || FS.supportedFileAttributeViews().contains("Posix"); // Paths - @LauncherAPI + public static final Path JVM_DIR = Paths.get(System.getProperty("java.home")); - @LauncherAPI + public static final Path HOME_DIR = Paths.get(System.getProperty("user.home")); - @LauncherAPI + public static final Path WORKING_DIR = Paths.get(System.getProperty("user.dir")); // Open options - as arrays private static final OpenOption[] READ_OPTIONS = {StandardOpenOption.READ}; @@ -131,7 +129,7 @@ public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOExce private static final Pattern PLATFORM_SEPARATOR_PATTERN = Pattern.compile(PLATFORM_SEPARATOR, Pattern.LITERAL); public static final String USER_AGENT = System.getProperty("launcher.userAgentDefault", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); - @LauncherAPI + public static void close(AutoCloseable closeable) { try { closeable.close(); @@ -140,7 +138,7 @@ public static void close(AutoCloseable closeable) { } } - @LauncherAPI + public static void close(InputStream in) { try { in.close(); @@ -148,7 +146,7 @@ public static void close(InputStream in) { } } - @LauncherAPI + public static void close(OutputStream out) { try { out.flush(); @@ -157,7 +155,7 @@ public static void close(OutputStream out) { } } - @LauncherAPI + public static URL convertToURL(String url) { try { return new URL(url); @@ -166,70 +164,70 @@ public static URL convertToURL(String url) { } } - @LauncherAPI + public static void copy(Path source, Path target) throws IOException { createParentDirs(target); Files.copy(source, target, COPY_OPTIONS); } - @LauncherAPI + public static void createParentDirs(Path path) throws IOException { Path parent = path.getParent(); if (parent != null && !isDir(parent)) Files.createDirectories(parent); } - @LauncherAPI + public static String decode(byte[] bytes) { return new String(bytes, UNICODE_CHARSET); } - @LauncherAPI + public static String decodeASCII(byte[] bytes) { return new String(bytes, ASCII_CHARSET); } - @LauncherAPI + public static void deleteDir(Path dir, boolean self) throws IOException { walk(dir, new DeleteDirVisitor(dir, self), true); } - @LauncherAPI + public static byte[] encode(String s) { return s.getBytes(UNICODE_CHARSET); } - @LauncherAPI + public static byte[] encodeASCII(String s) { return s.getBytes(ASCII_CHARSET); } - @LauncherAPI + public static boolean exists(Path path) { return Files.exists(path, LINK_OPTIONS); } - @LauncherAPI + public static Path getCodeSource(Class clazz) { return Paths.get(toURI(clazz.getProtectionDomain().getCodeSource().getLocation())); } - @LauncherAPI + public static String getFileName(Path path) { return path.getFileName().toString(); } - @LauncherAPI + public static String getIP(SocketAddress address) { return ((InetSocketAddress) address).getAddress().getHostAddress(); } - @LauncherAPI + public static byte[] getResourceBytes(String name) throws IOException { return read(getResourceURL(name)); } - @LauncherAPI + public static URL getResourceURL(String name) throws NoSuchFileException { URL url = IOHelper.class.getResource('/' + name); if (url == null) @@ -237,35 +235,35 @@ public static URL getResourceURL(String name) throws NoSuchFileException { return url; } - @LauncherAPI + public static boolean hasExtension(Path file, String extension) { return getFileName(file).endsWith('.' + extension); } - @LauncherAPI + public static boolean isDir(Path path) { return Files.isDirectory(path, LINK_OPTIONS); } - @LauncherAPI + public static boolean isEmpty(Path dir) throws IOException { try (DirectoryStream stream = Files.newDirectoryStream(dir)) { return !stream.iterator().hasNext(); } } - @LauncherAPI + public static boolean isFile(Path path) { return Files.isRegularFile(path, LINK_OPTIONS); } - @LauncherAPI + public static boolean isValidFileName(String fileName) { return !fileName.equals(".") && !fileName.equals("..") && fileName.chars().noneMatch(ch -> ch == '/' || ch == '\\') && isValidPath(fileName); } - @LauncherAPI + public static boolean isValidPath(String path) { try { toPath(path); @@ -275,34 +273,34 @@ public static boolean isValidPath(String path) { } } - @LauncherAPI + public static boolean isValidTextureBounds(int width, int height, boolean cloak) { return width % 64 == 0 && (height << 1 == width || !cloak && height == width) && width <= 1024 || cloak && width % 22 == 0 && height % 17 == 0 && width / 22 == height / 17; } - @LauncherAPI + public static void move(Path source, Path target) throws IOException { createParentDirs(target); Files.move(source, target, COPY_OPTIONS); } - @LauncherAPI + public static byte[] newBuffer() { return new byte[BUFFER_SIZE]; } - @LauncherAPI + public static ByteArrayOutputStream newByteArrayOutput() { return new ByteArrayOutputStream(); } - @LauncherAPI + public static char[] newCharBuffer() { return new char[BUFFER_SIZE]; } - @LauncherAPI + public static URLConnection newConnection(URL url) throws IOException { URLConnection connection = url.openConnection(); if (connection instanceof HttpURLConnection) { @@ -316,7 +314,7 @@ public static URLConnection newConnection(URL url) throws IOException { return connection; } - @LauncherAPI + public static HttpURLConnection newConnectionPost(URL url) throws IOException { HttpURLConnection connection = (HttpURLConnection) newConnection(url); connection.setDoOutput(true); @@ -324,138 +322,138 @@ public static HttpURLConnection newConnectionPost(URL url) throws IOException { return connection; } - @LauncherAPI + public static Deflater newDeflater() { Deflater deflater = new Deflater(Deflater.DEFAULT_COMPRESSION, true); deflater.setStrategy(Deflater.DEFAULT_STRATEGY); return deflater; } - @LauncherAPI + public static Inflater newInflater() { return new Inflater(true); } - @LauncherAPI + public static InputStream newInput(Path file) throws IOException { return Files.newInputStream(file, READ_OPTIONS); } - @LauncherAPI + public static InputStream newBufferedInput(Path file) throws IOException { return new BufferedInputStream(Files.newInputStream(file, READ_OPTIONS)); } - @LauncherAPI + public static InputStream newInput(URL url) throws IOException { return newConnection(url).getInputStream(); } - @LauncherAPI + public static BufferedInputStream newBufferedInput(URL url) throws IOException { return new BufferedInputStream(newConnection(url).getInputStream()); } - @LauncherAPI + public static OutputStream newOutput(Path file) throws IOException { return newOutput(file, false); } - @LauncherAPI + public static OutputStream newBufferedOutput(Path file) throws IOException { return newBufferedOutput(file, false); } - @LauncherAPI + public static OutputStream newOutput(Path file, boolean append) throws IOException { createParentDirs(file); return Files.newOutputStream(file, append ? APPEND_OPTIONS : WRITE_OPTIONS); } - @LauncherAPI + public static OutputStream newBufferedOutput(Path file, boolean append) throws IOException { createParentDirs(file); return new BufferedOutputStream(Files.newOutputStream(file, append ? APPEND_OPTIONS : WRITE_OPTIONS)); } - @LauncherAPI + public static BufferedReader newReader(InputStream input) { return newReader(input, UNICODE_CHARSET); } - @LauncherAPI + public static BufferedReader newReader(InputStream input, Charset charset) { return new BufferedReader(new InputStreamReader(input, charset)); } - @LauncherAPI + public static BufferedReader newReader(Path file) throws IOException { return Files.newBufferedReader(file, UNICODE_CHARSET); } - @LauncherAPI + public static BufferedReader newReader(URL url) throws IOException { URLConnection connection = newConnection(url); String charset = connection.getContentEncoding(); return newReader(connection.getInputStream(), charset == null ? UNICODE_CHARSET : Charset.forName(charset)); } - @LauncherAPI + public static Socket newSocket() throws SocketException { Socket socket = new Socket(); setSocketFlags(socket); return socket; } - @LauncherAPI + public static BufferedWriter newWriter(FileDescriptor fd) { return newWriter(new FileOutputStream(fd)); } - @LauncherAPI + public static BufferedWriter newWriter(OutputStream output) { return new BufferedWriter(new OutputStreamWriter(output, UNICODE_CHARSET)); } - @LauncherAPI + public static BufferedWriter newWriter(Path file) throws IOException { return newWriter(file, false); } - @LauncherAPI + public static BufferedWriter newWriter(Path file, boolean append) throws IOException { createParentDirs(file); return Files.newBufferedWriter(file, UNICODE_CHARSET, append ? APPEND_OPTIONS : WRITE_OPTIONS); } - @LauncherAPI + public static ZipEntry newZipEntry(String name) { ZipEntry entry = new ZipEntry(name); entry.setTime(0); return entry; } - @LauncherAPI + public static ZipEntry newZipEntry(ZipEntry entry) { return newZipEntry(entry.getName()); } - @LauncherAPI + public static ZipInputStream newZipInput(InputStream input) { return new ZipInputStream(input, UNICODE_CHARSET); } - @LauncherAPI + public static ZipInputStream newZipInput(Path file) throws IOException { return newZipInput(newInput(file)); } - @LauncherAPI + public static ZipInputStream newZipInput(URL url) throws IOException { return newZipInput(newInput(url)); } - @LauncherAPI + public static byte[] read(InputStream input) throws IOException { try (ByteArrayOutputStream output = newByteArrayOutput()) { transfer(input, output); @@ -463,7 +461,7 @@ public static byte[] read(InputStream input) throws IOException { } } - @LauncherAPI + public static void read(InputStream input, byte[] bytes) throws IOException { int offset = 0; while (offset < bytes.length) { @@ -474,7 +472,7 @@ public static void read(InputStream input, byte[] bytes) throws IOException { } } - @LauncherAPI + public static byte[] read(Path file) throws IOException { long size = readAttributes(file).size(); if (size > Integer.MAX_VALUE) @@ -490,19 +488,19 @@ public static byte[] read(Path file) throws IOException { return bytes; } - @LauncherAPI + public static byte[] read(URL url) throws IOException { try (InputStream input = newInput(url)) { return read(input); } } - @LauncherAPI + public static BasicFileAttributes readAttributes(Path path) throws IOException { return Files.readAttributes(path, BasicFileAttributes.class, LINK_OPTIONS); } - @LauncherAPI + public static BufferedImage readTexture(Object input, boolean cloak) throws IOException { ImageReader reader = ImageIO.getImageReadersByMIMEType("image/png").next(); try { @@ -521,19 +519,19 @@ public static BufferedImage readTexture(Object input, boolean cloak) throws IOEx } } - @LauncherAPI + public static String request(URL url) throws IOException { return decode(read(url)).trim(); } - @LauncherAPI + public static InetSocketAddress resolve(InetSocketAddress address) { if (address.isUnresolved()) return new InetSocketAddress(address.getHostString(), address.getPort()); return address; } - @LauncherAPI + public static Path resolveIncremental(Path dir, String name, String extension) { Path original = dir.resolve(name + '.' + extension); if (!exists(original)) @@ -551,7 +549,7 @@ public static Path resolveIncremental(Path dir, String name, String extension) { } } - @LauncherAPI + public static Path resolveJavaBin(Path javaDir) { // Get Java binaries path Path javaBinDir = (javaDir == null ? JVM_DIR : javaDir).resolve("bin"); @@ -577,7 +575,7 @@ public static Path resolveJavaBin(Path javaDir) { throw new RuntimeException("Java binary wasn't found"); } - @LauncherAPI + public static void setSocketFlags(Socket socket) throws SocketException { // Set socket flags socket.setKeepAlive(false); @@ -594,34 +592,34 @@ public static void setSocketFlags(Socket socket) throws SocketException { socket.setPerformancePreferences(1, 0, 2); } - @LauncherAPI + public static String toAbsPathString(Path path) { return toAbsPath(path).toFile().getAbsolutePath(); } - @LauncherAPI + public static Path toAbsPath(Path path) { return path.normalize().toAbsolutePath(); } - @LauncherAPI + public static byte[] toByteArray(InputStream in) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(in.available()); IOHelper.transfer(in, out); return out.toByteArray(); } - @LauncherAPI + public static Path toPath(String path) { return Paths.get(CROSS_SEPARATOR_PATTERN.matcher(path).replaceAll(Matcher.quoteReplacement(PLATFORM_SEPARATOR))); } - @LauncherAPI + public static String toString(Path path) { return PLATFORM_SEPARATOR_PATTERN.matcher(path.toString()).replaceAll(Matcher.quoteReplacement(CROSS_SEPARATOR)); } - @LauncherAPI + public static URI toURI(URL url) { try { return url.toURI(); @@ -630,7 +628,7 @@ public static URI toURI(URL url) { } } - @LauncherAPI + public static URL toURL(Path path) { try { return path.toUri().toURL(); @@ -639,14 +637,14 @@ public static URL toURL(Path path) { } } - @LauncherAPI + public static void transfer(byte[] write, Path file, boolean append) throws IOException { try (OutputStream out = newOutput(file, append)) { out.write(write); } } - @LauncherAPI + public static long transfer(InputStream input, OutputStream output) throws IOException { long transferred = 0; byte[] buffer = newBuffer(); @@ -657,26 +655,26 @@ public static long transfer(InputStream input, OutputStream output) throws IOExc return transferred; } - @LauncherAPI + public static long transfer(InputStream input, Path file) throws IOException { return transfer(input, file, false); } - @LauncherAPI + public static long transfer(InputStream input, Path file, boolean append) throws IOException { try (OutputStream output = newOutput(file, append)) { return transfer(input, output); } } - @LauncherAPI + public static void transfer(Path file, OutputStream output) throws IOException { try (InputStream input = newInput(file)) { transfer(input, output); } } - @LauncherAPI + public static String urlDecode(String s) { try { return URLDecoder.decode(s, UNICODE_CHARSET.name()); @@ -685,7 +683,7 @@ public static String urlDecode(String s) { } } - @LauncherAPI + public static String urlEncode(String s) { try { return URLEncoder.encode(s, UNICODE_CHARSET.name()); @@ -694,25 +692,25 @@ public static String urlEncode(String s) { } } - @LauncherAPI + public static String verifyFileName(String fileName) { return VerifyHelper.verify(fileName, IOHelper::isValidFileName, String.format("Invalid file name: '%s'", fileName)); } - @LauncherAPI + public static int verifyLength(int length, int max) throws IOException { if (length < 0 || max < 0 && length != -max || max > 0 && length > max) throw new IOException("Illegal length: " + length); return length; } - @LauncherAPI + public static BufferedImage verifyTexture(BufferedImage skin, boolean cloak) { return VerifyHelper.verify(skin, i -> isValidTextureBounds(i.getWidth(), i.getHeight(), cloak), String.format("Invalid texture bounds: %dx%d", skin.getWidth(), skin.getHeight())); } - @LauncherAPI + public static String verifyURL(String url) { try { new URL(url).toURI(); @@ -722,12 +720,12 @@ public static String verifyURL(String url) { } } - @LauncherAPI + public static void walk(Path dir, FileVisitor visitor, boolean hidden) throws IOException { Files.walkFileTree(dir, WALK_OPTIONS, Integer.MAX_VALUE, hidden ? visitor : new SkipHiddenVisitor(visitor)); } - @LauncherAPI + public static void write(Path file, byte[] bytes) throws IOException { createParentDirs(file); Files.write(file, bytes, WRITE_OPTIONS); diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java index 2c40fa0d..edf607d9 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java @@ -1,7 +1,5 @@ package pro.gravit.utils.helper; -import pro.gravit.launcher.LauncherAPI; - import java.io.File; import java.lang.invoke.MethodHandles; import java.lang.management.ManagementFactory; @@ -16,7 +14,7 @@ import java.util.Map; public final class JVMHelper { - @LauncherAPI + public enum OS { MUSTDIE("mustdie"), LINUX("linux"), MACOSX("macosx"); @@ -43,16 +41,16 @@ public static OS byName(String name) { public static final OperatingSystemMXBean OPERATING_SYSTEM_MXBEAN = ManagementFactory.getOperatingSystemMXBean(); // System properties - @LauncherAPI + public static final OS OS_TYPE = OS.byName(OPERATING_SYSTEM_MXBEAN.getName()); - @LauncherAPI + public static final String OS_VERSION = OPERATING_SYSTEM_MXBEAN.getVersion(); - @LauncherAPI + public static final int OS_BITS = getCorrectOSArch(); - @LauncherAPI + public static final int JVM_BITS = Integer.parseInt(System.getProperty("sun.arch.data.model")); - @LauncherAPI + public static final SecurityManager SECURITY_MANAGER = System.getSecurityManager(); // Public static fields public static final Runtime RUNTIME = Runtime.getRuntime(); @@ -93,7 +91,7 @@ public static Class firstClass(String... names) throws ClassNotFoundException throw new ClassNotFoundException(Arrays.toString(names)); } - @LauncherAPI + public static void fullGC() { RUNTIME.gc(); RUNTIME.runFinalization(); @@ -146,27 +144,27 @@ private static int getCorrectOSArch() { return System.getProperty("os.arch").contains("64") ? 64 : 32; } - @LauncherAPI + public static String getEnvPropertyCaseSensitive(String name) { return System.getenv().get(name); } - @LauncherAPI + public static boolean isJVMMatchesSystemArch() { return JVM_BITS == OS_BITS; } - @LauncherAPI + public static String jvmProperty(String name, String value) { return String.format("-D%s=%s", name, value); } - @LauncherAPI + public static String systemToJvmProperty(String name) { return String.format("-D%s=%s", name, System.getProperties().getProperty(name)); } - @LauncherAPI + public static void addSystemPropertyToArgs(Collection args, String name) { String property = System.getProperty(name); if (property != null) diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/LogHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/LogHelper.java index 9767dafc..0c69ced6 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/LogHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/LogHelper.java @@ -3,7 +3,6 @@ import org.fusesource.jansi.Ansi; import org.fusesource.jansi.AnsiConsole; import org.fusesource.jansi.AnsiOutputStream; -import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.LauncherNetworkAPI; import java.io.*; @@ -20,15 +19,15 @@ import java.util.function.Supplier; public final class LogHelper { - @LauncherAPI + public static final String DEBUG_PROPERTY = "launcher.debug"; - @LauncherAPI + public static final String DEV_PROPERTY = "launcher.dev"; - @LauncherAPI + public static final String STACKTRACE_PROPERTY = "launcher.stacktrace"; - @LauncherAPI + public static final String NO_JANSI_PROPERTY = "launcher.noJAnsi"; - @LauncherAPI + public static final boolean JANSI; // Output settings @@ -63,22 +62,22 @@ public enum OutputTypes { private LogHelper() { } - @LauncherAPI + public static void addOutput(OutputEnity output) { OUTPUTS.add(Objects.requireNonNull(output, "output")); } - @LauncherAPI + public static void addExcCallback(Consumer output) { EXCEPTIONS_CALLBACKS.add(Objects.requireNonNull(output, "output")); } - @LauncherAPI + public static void addOutput(Output output, OutputTypes type) { OUTPUTS.add(new OutputEnity(Objects.requireNonNull(output, "output"), type)); } - @LauncherAPI + public static void addOutput(Path file) throws IOException { if (JANSI) { addOutput(new JAnsiOutput(IOHelper.newOutput(file, true)), OutputTypes.JANSI); @@ -87,89 +86,89 @@ public static void addOutput(Path file) throws IOException { } } - @LauncherAPI + public static void addOutput(Writer writer) { addOutput(new WriterOutput(writer), OutputTypes.PLAIN); } - @LauncherAPI + public static void debug(String message) { if (isDebugEnabled()) { log(Level.DEBUG, message, false); } } - @LauncherAPI + public static void dev(String message) { if (isDevEnabled()) { log(Level.DEV, message, false); } } - @LauncherAPI + public static void debug(String format, Object... args) { debug(String.format(format, args)); } - @LauncherAPI + public static void dev(String format, Object... args) { if (isDevEnabled()) { dev(String.format(format, args)); } } - @LauncherAPI + public static void error(Throwable exc) { EXCEPTIONS_CALLBACKS.forEach(e -> e.accept(exc)); error(isStacktraceEnabled() ? toString(exc) : exc.toString()); } - @LauncherAPI + public static void error(String message) { log(Level.ERROR, message, false); } - @LauncherAPI + public static void error(String format, Object... args) { error(String.format(format, args)); } - @LauncherAPI + public static void info(String message) { log(Level.INFO, message, false); } - @LauncherAPI + public static void info(String format, Object... args) { info(String.format(format, args)); } - @LauncherAPI + public static boolean isDebugEnabled() { return DEBUG_ENABLED.get(); } - @LauncherAPI + public static void setDebugEnabled(boolean debugEnabled) { DEBUG_ENABLED.set(debugEnabled); } - @LauncherAPI + public static boolean isStacktraceEnabled() { return STACKTRACE_ENABLED.get(); } - @LauncherAPI + public static boolean isDevEnabled() { return DEV_ENABLED.get(); } - @LauncherAPI + public static void setStacktraceEnabled(boolean stacktraceEnabled) { STACKTRACE_ENABLED.set(stacktraceEnabled); } - @LauncherAPI + public static void setDevEnabled(boolean stacktraceEnabled) { DEV_ENABLED.set(stacktraceEnabled); } @@ -178,7 +177,7 @@ public static String getDataTime() { return DATE_TIME_FORMATTER.format(LocalDateTime.now()); } - @LauncherAPI + public static void log(Level level, String message, boolean sub) { String dateTime = DATE_TIME_FORMATTER.format(LocalDateTime.now()); String jansiString = null, plainString = null, htmlString = null; @@ -211,12 +210,12 @@ public static void log(Level level, String message, boolean sub) { } } - @LauncherAPI + public static void rawLog(Supplier plainStr, Supplier jansiStr) { rawLog(plainStr, jansiStr, null); } - @LauncherAPI + public static void rawLog(Supplier plainStr, Supplier jansiStr, Supplier htmlStr) { String jansiString = null, plainString = null, htmlString = null; for (OutputEnity output : OUTPUTS) { @@ -248,7 +247,7 @@ public static void rawLog(Supplier plainStr, Supplier jansiStr, } } - @LauncherAPI + public static void printVersion(String product) { String jansiString = null, plainString = null; for (OutputEnity output : OUTPUTS) { @@ -272,7 +271,7 @@ public static void printVersion(String product) { } } - @LauncherAPI + public static void printLicense(String product) { String jansiString = null, plainString = null; for (OutputEnity output : OUTPUTS) { @@ -296,61 +295,61 @@ public static void printLicense(String product) { } } - @LauncherAPI + public static boolean removeOutput(OutputEnity output) { return OUTPUTS.remove(output); } - @LauncherAPI + public static boolean removeStdOutput() { return removeOutput(STD_OUTPUT); } - @LauncherAPI + public static void subDebug(String message) { if (isDebugEnabled()) { log(Level.DEBUG, message, true); } } - @LauncherAPI + public static void subDebug(String format, Object... args) { subDebug(String.format(format, args)); } - @LauncherAPI + public static void subInfo(String message) { log(Level.INFO, message, true); } - @LauncherAPI + public static void subInfo(String format, Object... args) { subInfo(String.format(format, args)); } - @LauncherAPI + public static void subWarning(String message) { log(Level.WARNING, message, true); } - @LauncherAPI + public static void subWarning(String format, Object... args) { subWarning(String.format(format, args)); } - @LauncherAPI + public static String toString(Throwable exc) { StringWriter sw = new StringWriter(); exc.printStackTrace(new PrintWriter(sw)); return sw.toString(); } - @LauncherAPI + public static void warning(String message) { log(Level.WARNING, message, false); } - @LauncherAPI + public static void warning(String format, Object... args) { warning(String.format(format, args)); } @@ -425,13 +424,13 @@ private static String formatLog(Level level, String message, String dateTime, bo } } - @LauncherAPI + @FunctionalInterface public interface Output { void println(String message); } - @LauncherAPI + public enum Level { DEV("DEV"), DEBUG("DEBUG"), INFO("INFO"), WARNING("WARN"), ERROR("ERROR"); public final String name; diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/SecurityHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/SecurityHelper.java index 29d4a1f2..062954d4 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/SecurityHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/SecurityHelper.java @@ -1,7 +1,5 @@ package pro.gravit.utils.helper; -import pro.gravit.launcher.LauncherAPI; - import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax.crypto.NoSuchPaddingException; @@ -266,12 +264,12 @@ public static byte[] randomBytes(Random random, int length) { return bytes; } - @LauncherAPI + public static String randomStringToken() { return randomStringToken(newRandom()); } - @LauncherAPI + public static String randomStringToken(Random random) { return toHex(randomToken(random)); } diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/VerifyHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/VerifyHelper.java index 4db1741b..82fa5ad0 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/VerifyHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/VerifyHelper.java @@ -1,7 +1,5 @@ package pro.gravit.utils.helper; -import pro.gravit.launcher.LauncherAPI; - import java.util.Map; import java.util.Objects; import java.util.function.DoublePredicate; @@ -11,95 +9,95 @@ import java.util.regex.Pattern; public final class VerifyHelper { - @LauncherAPI + public static final IntPredicate POSITIVE = i -> i > 0; - @LauncherAPI + public static final IntPredicate NOT_NEGATIVE = i -> i >= 0; - @LauncherAPI + public static final LongPredicate L_POSITIVE = l -> l > 0; - @LauncherAPI + public static final LongPredicate L_NOT_NEGATIVE = l -> l >= 0; - @LauncherAPI + public static final Predicate NOT_EMPTY = s -> !s.isEmpty(); - @LauncherAPI + public static final Pattern USERNAME_PATTERN = Pattern.compile(Boolean.parseBoolean(System.getProperty("username.russian", "true")) ? "[a-zA-Zа-яА-Я0-9_.\\-]{1,16}" : "[a-zA-Z0-9-_\\\\.]{1,16}"); private static final Pattern SERVERID_PATTERN = Pattern.compile("-?[0-9a-f]{1,40}"); - @LauncherAPI + public static V getMapValue(Map map, K key, String error) { return verify(map.get(key), Objects::nonNull, error); } - @LauncherAPI + public static boolean isValidIDName(String name) { return !name.isEmpty() && name.length() <= 255 && name.chars().allMatch(VerifyHelper::isValidIDNameChar); } - @LauncherAPI + public static boolean isValidIDNameChar(int ch) { return ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch >= '0' && ch <= '9' || ch == '-' || ch == '_'; } - @LauncherAPI + public static boolean isValidServerID(CharSequence serverID) { return SERVERID_PATTERN.matcher(serverID).matches(); } - @LauncherAPI + public static boolean isValidUsername(CharSequence username) { return USERNAME_PATTERN.matcher(username).matches(); } - @LauncherAPI + public static void putIfAbsent(Map map, K key, V value, String error) { verify(map.putIfAbsent(key, value), Objects::isNull, error); } - @LauncherAPI + public static IntPredicate range(int min, int max) { return i -> i >= min && i <= max; } - @LauncherAPI + public static T verify(T object, Predicate predicate, String error) { if (predicate.test(object)) return object; throw new IllegalArgumentException(error); } - @LauncherAPI + public static double verifyDouble(double d, DoublePredicate predicate, String error) { if (predicate.test(d)) return d; throw new IllegalArgumentException(error); } - @LauncherAPI + public static String verifyIDName(String name) { return verify(name, VerifyHelper::isValidIDName, String.format("Invalid name: '%s'", name)); } - @LauncherAPI + public static int verifyInt(int i, IntPredicate predicate, String error) { if (predicate.test(i)) return i; throw new IllegalArgumentException(error); } - @LauncherAPI + public static long verifyLong(long l, LongPredicate predicate, String error) { if (predicate.test(l)) return l; throw new IllegalArgumentException(error); } - @LauncherAPI + public static String verifyServerID(String serverID) { return verify(serverID, VerifyHelper::isValidServerID, String.format("Invalid server ID: '%s'", serverID)); } - @LauncherAPI + public static String verifyUsername(String username) { return verify(username, VerifyHelper::isValidUsername, String.format("Invalid username: '%s'", username)); } From 4dab77bda94313e9b36485c67a334c537043d8a4 Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 9 Dec 2019 02:35:57 +0700 Subject: [PATCH 115/192] =?UTF-8?q?[FIX]=20=D0=97=D0=B0=D0=B1=D1=8B=D1=82?= =?UTF-8?q?=D1=8B=D0=B5=20LauncherNetworkAPI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/pro/gravit/launcher/hasher/HashedEntry.java | 3 ++- .../src/main/java/pro/gravit/launcher/hasher/HashedFile.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedEntry.java b/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedEntry.java index 9291307f..f3105a9f 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedEntry.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedEntry.java @@ -1,5 +1,6 @@ package pro.gravit.launcher.hasher; +import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.serialize.HInput; import pro.gravit.launcher.serialize.stream.EnumSerializer; import pro.gravit.launcher.serialize.stream.StreamObject; @@ -28,7 +29,7 @@ public int getNumber() { } } - + @LauncherNetworkAPI public boolean flag; // For external usage diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedFile.java b/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedFile.java index e117596f..396265e7 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedFile.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedFile.java @@ -16,7 +16,7 @@ public final class HashedFile extends HashedEntry { public static final DigestAlgorithm DIGEST_ALGO = DigestAlgorithm.MD5; // Instance - + @LauncherNetworkAPI public final long size; @LauncherNetworkAPI private final byte[] digest; From a350b3bd77cf32a0ee53cce52161b84281dd93ec Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 9 Dec 2019 03:27:13 +0700 Subject: [PATCH 116/192] =?UTF-8?q?[FIX]=20=D0=9F=D0=B5=D1=80=D0=B5=D0=BC?= =?UTF-8?q?=D0=B5=D1=89=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BA=D1=80=D0=B8=D1=82?= =?UTF-8?q?=D0=B8=D1=87=D0=BD=D1=8B=D1=85=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81?= =?UTF-8?q?=D0=BE=D0=B2=20=D0=B2=20=D0=B1=D0=B5=D0=B7=D0=BE=D0=BF=D0=B0?= =?UTF-8?q?=D1=81=D1=82=D0=BD=D0=BE=D0=B5=20=D0=BC=D0=B5=D1=81=D1=82=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launchserver/LaunchServerStarter.java | 2 +- .../auth/handler/JsonAuthHandler.java | 2 +- .../auth/hwid/JsonHWIDHandler.java | 2 +- .../auth/provider/JsonAuthProvider.java | 2 +- .../manangers/CertificateManager.java | 2 +- .../launchserver/manangers/MirrorManager.java | 2 +- .../impl/LaunchServerModulesManager.java | 2 +- .../pro/gravit/launcher/LauncherEngine.java | 18 ++++++++++++---- .../launcher/client/ClientModuleManager.java | 2 +- .../pro/gravit/launcher/LauncherConfig.java | 1 - .../modules/impl/SimpleModuleManager.java | 11 +++++++--- .../{utils => launcher}/HTTPRequest.java | 21 +------------------ .../LauncherTrustManager.java | 2 +- .../pro/gravit/utils/helper/JVMHelper.java | 3 --- modules | 2 +- 15 files changed, 33 insertions(+), 41 deletions(-) rename LauncherCore/src/main/java/pro/gravit/{utils => launcher}/HTTPRequest.java (70%) rename LauncherCore/src/main/java/pro/gravit/{utils/verify => launcher}/LauncherTrustManager.java (99%) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java index ff31bb65..202b9787 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java @@ -27,7 +27,7 @@ import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.SecurityHelper; -import pro.gravit.utils.verify.LauncherTrustManager; +import pro.gravit.launcher.LauncherTrustManager; import java.io.BufferedReader; import java.io.BufferedWriter; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/JsonAuthHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/JsonAuthHandler.java index 41a0bb08..89604bc1 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/JsonAuthHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/JsonAuthHandler.java @@ -1,7 +1,7 @@ package pro.gravit.launchserver.auth.handler; import pro.gravit.launcher.Launcher; -import pro.gravit.utils.HTTPRequest; +import pro.gravit.launcher.HTTPRequest; import java.io.IOException; import java.net.URL; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/JsonHWIDHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/JsonHWIDHandler.java index ac2e796f..f23bebb0 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/JsonHWIDHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/JsonHWIDHandler.java @@ -4,7 +4,7 @@ import com.google.gson.JsonElement; import pro.gravit.launcher.hwid.HWID; import pro.gravit.launcher.hwid.OshiHWID; -import pro.gravit.utils.HTTPRequest; +import pro.gravit.launcher.HTTPRequest; import pro.gravit.utils.helper.LogHelper; import java.io.IOException; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/JsonAuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/JsonAuthProvider.java index 35e72088..2bdc5dd0 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/JsonAuthProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/JsonAuthProvider.java @@ -6,7 +6,7 @@ import pro.gravit.launcher.request.auth.AuthRequest; import pro.gravit.launcher.request.auth.password.AuthPlainPassword; import pro.gravit.launchserver.auth.AuthException; -import pro.gravit.utils.HTTPRequest; +import pro.gravit.launcher.HTTPRequest; import pro.gravit.utils.helper.SecurityHelper; import java.io.IOException; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/CertificateManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/CertificateManager.java index 71fad349..8744e7e6 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/CertificateManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/CertificateManager.java @@ -24,7 +24,7 @@ import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.SecurityHelper; -import pro.gravit.utils.verify.LauncherTrustManager; +import pro.gravit.launcher.LauncherTrustManager; import java.io.*; import java.math.BigInteger; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/MirrorManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/MirrorManager.java index 45a7a92c..cc63f029 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/MirrorManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/MirrorManager.java @@ -1,7 +1,7 @@ package pro.gravit.launchserver.manangers; import com.google.gson.JsonElement; -import pro.gravit.utils.HTTPRequest; +import pro.gravit.launcher.HTTPRequest; import pro.gravit.utils.HttpDownloader; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerModulesManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerModulesManager.java index 29508783..409435e9 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerModulesManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerModulesManager.java @@ -5,7 +5,7 @@ import pro.gravit.launcher.modules.impl.SimpleModuleManager; import pro.gravit.launchserver.LaunchServer; import pro.gravit.utils.helper.LogHelper; -import pro.gravit.utils.verify.LauncherTrustManager; +import pro.gravit.launcher.LauncherTrustManager; import java.nio.file.Path; import java.util.Arrays; diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index 7545e6ae..db38369d 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -14,10 +14,8 @@ import pro.gravit.launcher.request.Request; import pro.gravit.launcher.request.RequestException; import pro.gravit.launcher.request.auth.RestoreSessionRequest; -import pro.gravit.launcher.request.update.UpdateRequest; import pro.gravit.launcher.request.websockets.StandartClientWebSocketService; import pro.gravit.utils.helper.*; -import pro.gravit.utils.verify.LauncherTrustManager; import java.io.IOException; import java.nio.file.Path; @@ -27,16 +25,24 @@ import java.security.interfaces.ECPrivateKey; import java.security.interfaces.ECPublicKey; import java.security.spec.InvalidKeySpecException; +import java.util.Arrays; import java.util.Objects; import java.util.concurrent.atomic.AtomicBoolean; public class LauncherEngine { + //JVMHelper.getCertificates + public static X509Certificate[] getCertificates(Class clazz) { + Object[] signers = clazz.getSigners(); + if (signers == null) return null; + return Arrays.stream(signers).filter((c) -> c instanceof X509Certificate).map((c) -> (X509Certificate) c).toArray(X509Certificate[]::new); + } + public static final AtomicBoolean IS_CLIENT = new AtomicBoolean(false); public static void checkClass(Class clazz) throws SecurityException { LauncherTrustManager trustManager = Launcher.getConfig().trustManager; if (trustManager == null) return; - X509Certificate[] certificates = JVMHelper.getCertificates(clazz); + X509Certificate[] certificates = getCertificates(clazz); if (certificates == null) { throw new SecurityException(String.format("Class %s not signed", clazz.getName())); } @@ -54,7 +60,7 @@ public static void main(String... args) throws Throwable { JVMHelper.verifySystemProperties(Launcher.class, true); EnvHelper.checkDangerousParams(); //if(!LauncherAgent.isStarted()) throw new SecurityException("JavaAgent not set"); - JVMHelper.verifyNoAgent(); + verifyNoAgent(); LogHelper.printVersion("Launcher"); LogHelper.printLicense("Launcher"); LauncherEngine.checkClass(LauncherEngine.class); @@ -91,6 +97,10 @@ public static void initGson(ClientModuleManager modulesManager) { Launcher.gsonManager.initGson(); } + public static void verifyNoAgent() { + if (JVMHelper.RUNTIME_MXBEAN.getInputArguments().stream().filter(e -> e != null && !e.isEmpty()).anyMatch(e -> e.contains("javaagent"))) throw new SecurityException("JavaAgent found"); + } + public void readKeys() throws IOException, InvalidKeySpecException { if (privateKey != null || publicKey != null) return; Path dir = DirBridge.dir; diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientModuleManager.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientModuleManager.java index 6a6e62d0..3121f061 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientModuleManager.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientModuleManager.java @@ -3,7 +3,7 @@ import pro.gravit.launcher.Launcher; import pro.gravit.launcher.modules.LauncherModule; import pro.gravit.launcher.modules.impl.SimpleModuleManager; -import pro.gravit.utils.verify.LauncherTrustManager; +import pro.gravit.launcher.LauncherTrustManager; import java.nio.file.Path; import java.util.Collection; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java b/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java index 9efbb4b6..a755e529 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java @@ -5,7 +5,6 @@ import pro.gravit.launcher.serialize.stream.StreamObject; import pro.gravit.utils.helper.SecurityHelper; import pro.gravit.utils.helper.VerifyHelper; -import pro.gravit.utils.verify.LauncherTrustManager; import java.io.IOException; import java.security.cert.CertificateException; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java index 50766c4d..ce124b68 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java @@ -7,7 +7,7 @@ import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.LogHelper; -import pro.gravit.utils.verify.LauncherTrustManager; +import pro.gravit.launcher.LauncherTrustManager; import java.io.IOException; import java.lang.invoke.MethodHandles; @@ -169,11 +169,16 @@ public LauncherModule loadModule(Path file) throws IOException { return null; } } - + //JVMHelper.getCertificates + private static X509Certificate[] getCertificates(Class clazz) { + Object[] signers = clazz.getSigners(); + if (signers == null) return null; + return Arrays.stream(signers).filter((c) -> c instanceof X509Certificate).map((c) -> (X509Certificate) c).toArray(X509Certificate[]::new); + } public void checkModuleClass(Class clazz, LauncherTrustManager.CheckMode mode) throws SecurityException { if (trustManager == null) return; - X509Certificate[] certificates = JVMHelper.getCertificates(clazz); + X509Certificate[] certificates = getCertificates(clazz); if (certificates == null) { if (mode == LauncherTrustManager.CheckMode.EXCEPTION_IN_NOT_SIGNED) throw new SecurityException(String.format("Class %s not signed", clazz.getName())); diff --git a/LauncherCore/src/main/java/pro/gravit/utils/HTTPRequest.java b/LauncherCore/src/main/java/pro/gravit/launcher/HTTPRequest.java similarity index 70% rename from LauncherCore/src/main/java/pro/gravit/utils/HTTPRequest.java rename to LauncherCore/src/main/java/pro/gravit/launcher/HTTPRequest.java index 051601de..2b4bb42c 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/HTTPRequest.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/HTTPRequest.java @@ -1,4 +1,4 @@ -package pro.gravit.utils; +package pro.gravit.launcher; import com.google.gson.JsonElement; import com.google.gson.JsonParser; @@ -17,25 +17,6 @@ public final class HTTPRequest { private static final int TIMEOUT = 10000; private static final JsonParser parser = new JsonParser(); - public static int sendCrashreport(String strurl, byte[] data) throws IOException { - URL url = new URL(strurl); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod("POST"); - connection.setRequestProperty("Content-Type", - "application/x-www-form-urlencoded"); - connection.setRequestProperty("Content-Length", - Integer.toString(data.length)); - connection.setRequestProperty("Content-Language", "en-US"); - OutputStream outputStream = connection.getOutputStream(); - outputStream.write(data); - outputStream.close(); - return connection.getResponseCode(); - } - - public static int sendCrashreport(String strurl, String data) throws IOException { - return sendCrashreport(strurl, data.getBytes(IOHelper.UNICODE_CHARSET)); - } - public static JsonElement jsonRequest(JsonElement request, URL url) throws IOException { return jsonRequest(request, "POST", url); } diff --git a/LauncherCore/src/main/java/pro/gravit/utils/verify/LauncherTrustManager.java b/LauncherCore/src/main/java/pro/gravit/launcher/LauncherTrustManager.java similarity index 99% rename from LauncherCore/src/main/java/pro/gravit/utils/verify/LauncherTrustManager.java rename to LauncherCore/src/main/java/pro/gravit/launcher/LauncherTrustManager.java index b35fb07e..5710081a 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/verify/LauncherTrustManager.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/LauncherTrustManager.java @@ -1,4 +1,4 @@ -package pro.gravit.utils.verify; +package pro.gravit.launcher; import pro.gravit.utils.helper.LogHelper; diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java index edf607d9..ac532383 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java @@ -190,7 +190,4 @@ public static void verifySystemProperties(Class mainClass, boolean requireSys private JVMHelper() { } - public static void verifyNoAgent() { - if (RUNTIME_MXBEAN.getInputArguments().stream().filter(e -> e != null && !e.isEmpty()).anyMatch(e -> e.contains("javaagent"))) throw new SecurityException("JavaAgent found"); - } } diff --git a/modules b/modules index 9ee94152..9282291e 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 9ee94152da6ae8e3ea045484f60b2a2246b4e993 +Subproject commit 9282291e67d54aa617d32e78ef70a62b50a4c428 From 6f6cb960804b9093e014e98f724cbda04c10bcd8 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Mon, 9 Dec 2019 16:07:25 +0100 Subject: [PATCH 117/192] =?UTF-8?q?[FIX]=20=D0=9D=D0=BE=D1=80=D0=BC=D0=B0?= =?UTF-8?q?=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20=D1=84=D0=B8=D0=BA=D1=81=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20FileServer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../socket/handlers/ContentType.java | 26 +++++++++++++++ .../fileserver/FileServerHandler.java | 33 ++++++++----------- 2 files changed, 39 insertions(+), 20 deletions(-) create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/ContentType.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/ContentType.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/ContentType.java new file mode 100644 index 00000000..75d9a9e4 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/ContentType.java @@ -0,0 +1,26 @@ +package pro.gravit.launchserver.socket.handlers; + +import java.io.File; +import java.nio.file.Files; + +public enum ContentType { + NONE { + @Override + public String forPath(File p) { + return null; + } + + }, + NIO { + @Override + public String forPath(File p) { + try { + return Files.probeContentType(p.toPath()); + } catch (Throwable e) { + return null; + } + } + }; + + public abstract String forPath(File p); +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/fileserver/FileServerHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/fileserver/FileServerHandler.java index 5c249cdc..4e146bed 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/fileserver/FileServerHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/fileserver/FileServerHandler.java @@ -6,13 +6,14 @@ import io.netty.handler.codec.http.*; import io.netty.handler.stream.ChunkedFile; import io.netty.util.CharsetUtil; +import pro.gravit.launchserver.socket.handlers.ContentType; +import pro.gravit.utils.helper.VerifyHelper; import java.io.File; import java.io.FileNotFoundException; import java.io.RandomAccessFile; import java.net.URI; import java.net.URISyntaxException; -import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.text.SimpleDateFormat; @@ -25,12 +26,15 @@ public class FileServerHandler extends SimpleChannelInboundHandler { - public static final String HTTP_DATE_FORMAT = "EEE, dd MMM yyyy HH:mm:ss zzz"; - public static final String HTTP_DATE_GMT_TIMEZONE = "GMT"; + public static final SimpleDateFormat dateFormatter; public static final String READ = "r"; - public static final int HTTP_CACHE_SECONDS = 60; + static { + dateFormatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US); + dateFormatter.setTimeZone(TimeZone.getTimeZone("GMT")); + } + public static final int HTTP_CACHE_SECONDS = VerifyHelper.verifyInt(Integer.parseInt(System.getProperty("launcher.fileserver.cachesec", "60")), VerifyHelper.NOT_NEGATIVE, "HttpCache seconds should be positive"); private static final boolean OLD_ALGO = Boolean.parseBoolean(System.getProperty("launcher.fileserver.oldalgo", "true")); - private static final boolean TYPE_PROBE = Boolean.parseBoolean(System.getProperty("launcher.fileserver.typeprobe", "true")); + private static final ContentType TYPE_PROBE = Arrays.stream(ContentType.values()).filter(e -> e.name().toLowerCase(Locale.US).equals(System.getProperty("launcher.fileserver.typeprobe", "nio"))).findFirst().orElse(ContentType.NONE); private final Path base; private final boolean fullOut; private final boolean showHiddenFiles; @@ -88,7 +92,6 @@ public void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) thr // Cache Validation String ifModifiedSince = request.headers().get(HttpHeaderNames.IF_MODIFIED_SINCE); if (ifModifiedSince != null && !ifModifiedSince.isEmpty()) { - SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US); Date ifModifiedSinceDate = dateFormatter.parse(ifModifiedSince); // Only compare up to the second because the datetime format we send to the client @@ -234,11 +237,7 @@ private static void sendNotModified(ChannelHandlerContext ctx) { * @param response HTTP response */ private static void setDateHeader(FullHttpResponse response) { - SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US); - dateFormatter.setTimeZone(TimeZone.getTimeZone(HTTP_DATE_GMT_TIMEZONE)); - - Calendar time = new GregorianCalendar(); - response.headers().set(HttpHeaderNames.DATE, dateFormatter.format(time.getTime())); + response.headers().set(HttpHeaderNames.DATE, dateFormatter.format(new Date(System.currentTimeMillis()))); } /** @@ -248,9 +247,6 @@ private static void setDateHeader(FullHttpResponse response) { * @param fileToCache file to extract content type */ private static void setDateAndCacheHeaders(HttpResponse response, File fileToCache) { - SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US); - dateFormatter.setTimeZone(TimeZone.getTimeZone(HTTP_DATE_GMT_TIMEZONE)); - // Date header Calendar time = new GregorianCalendar(); response.headers().set(HttpHeaderNames.DATE, dateFormatter.format(time.getTime())); @@ -270,11 +266,8 @@ private static void setDateAndCacheHeaders(HttpResponse response, File fileToCac * @param file file to extract content type */ private static void setContentTypeHeader(HttpResponse response, File file) { - if (TYPE_PROBE) - try { - response.headers().set(HttpHeaderNames.CONTENT_TYPE, Files.probeContentType(file.toPath())); - } catch (Throwable e) { - // ignore - } + String contentType = TYPE_PROBE.forPath(file); + if (contentType != null) + response.headers().set(HttpHeaderNames.CONTENT_TYPE, contentType); } } From 73e0ed53bba888753da4e8d9f0468fa0a08eaddf Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 11 Dec 2019 07:53:47 +0700 Subject: [PATCH 118/192] =?UTF-8?q?[FEATURE]=20=D0=9E=D1=82=D0=BA=D0=BB?= =?UTF-8?q?=D1=8E=D1=87=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B8=D1=81=D0=BF=D0=BE?= =?UTF-8?q?=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20javaag?= =?UTF-8?q?ent=20=D0=BD=D0=B0=20=D1=81=D1=82=D0=BE=D1=80=D0=BE=D0=BD=D0=B5?= =?UTF-8?q?=20=D0=BA=D0=BB=D0=B8=D0=B5=D0=BD=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/pro/gravit/launcher/LauncherEngine.java | 3 --- .../pro/gravit/launcher/client/ClientLauncher.java | 11 +++-------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index db38369d..9ef2d841 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -75,9 +75,6 @@ public static void main(String... args) throws Throwable { HWIDProvider.registerHWIDs(); LauncherEngine.modulesManager.invokeEvent(new PreConfigPhase()); LauncherConfig config = Launcher.getConfig(); - if (config.environment.equals(LauncherConfig.LauncherEnvironment.PROD)) { - if (!LauncherAgent.isStarted()) throw new SecurityException("LauncherAgent must started"); - } long startTime = System.currentTimeMillis(); try { new LauncherEngine().start(args); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index 4d9e2aef..066b4aab 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -356,13 +356,12 @@ public static Process launch( } } // Add classpath and main class - String pathLauncher = IOHelper.getCodeSource(ClientLauncher.class).toString(); - context.pathLauncher = pathLauncher; + context.pathLauncher = IOHelper.getCodeSource(ClientLauncher.class).toString(); context.args.add(ClientLauncherWrapper.MAGIC_ARG); Collections.addAll(context.args, profile.getJvmArgs()); profile.pushOptionalJvmArgs(context.args); context.args.add("-Djava.library.path=".concat(params.clientDir.resolve(NATIVES_DIR).toString())); // Add Native Path - context.args.add("-javaagent:".concat(pathLauncher)); + //context.args.add("-javaagent:".concat(pathLauncher)); ClientHookManager.clientLaunchHook.hook(context); LauncherGuardManager.guard.addCustomParams(context); context.args.add(ClientLauncher.class.getName()); @@ -443,10 +442,7 @@ public static void main(String... args) throws Throwable { LauncherConfig.getAutogenConfig().initModules(); //INIT LauncherEngine.modulesManager.initModules(null); initGson(LauncherEngine.modulesManager); - if (!LauncherAgent.isStarted()) { - NativeJVMHalt.haltA(100); - return; - } + LauncherEngine.verifyNoAgent(); LauncherEngine.modulesManager.invokeEvent(new PreConfigPhase()); JVMHelper.verifySystemProperties(ClientLauncher.class, true); EnvHelper.checkDangerousParams(); @@ -507,7 +503,6 @@ public static void main(String... args) throws Throwable { }; AuthService.username = params.pp.username; AuthService.uuid = params.pp.uuid; - ClientService.instrumentation = LauncherAgent.inst; ClientService.classLoader = classLoader; classLoader.addURL(IOHelper.getCodeSource(ClientLauncher.class).toUri().toURL()); //classForName(classLoader, "com.google.common.collect.ForwardingMultimap"); From 117b95d3fcf6578e301824b87d91ceb86acaf6a2 Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 11 Dec 2019 07:59:04 +0700 Subject: [PATCH 119/192] =?UTF-8?q?[FIX]=20=D0=98=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20optional=20classpath?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launcher/client/ClientLauncher.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index 066b4aab..1f189cea 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -465,18 +465,14 @@ public static void main(String... args) throws Throwable { LauncherEngine.modulesManager.invokeEvent(new ClientLauncherInitPhase(context)); // Verify ClientLauncher sign and classpath LogHelper.debug("Verifying ClientLauncher sign and classpath"); - LinkedList classPath = resolveClassPathList(params.clientDir, profile.getClassPath()); - for (Path classpathURL : classPath) { - //LauncherAgent.addJVMClassPath(classpathURL.normalize().toAbsolutePath()); - } + URL[] classpath = resolveClassPath(params.clientDir, profile.getClassPath()); + classLoader = new ClientClassLoader(classpath, ClassLoader.getSystemClassLoader()); profile.pushOptionalClassPath(cp -> { LinkedList optionalClassPath = resolveClassPathList(params.clientDir, cp); for (Path classpathURL : optionalClassPath) { - //LauncherAgent.addJVMClassPath(classpathURL.normalize().toAbsolutePath()); + classLoader.addURL(classpathURL.normalize().toAbsolutePath().toUri().toURL()); } }); - URL[] classpathurls = resolveClassPath(params.clientDir, profile.getClassPath()); - classLoader = new ClientClassLoader(classpathurls, ClassLoader.getSystemClassLoader()); Thread.currentThread().setContextClassLoader(classLoader); classLoader.nativePath = params.clientDir.resolve(NATIVES_DIR).toString(); // Start client with WatchService monitoring @@ -506,7 +502,7 @@ public static void main(String... args) throws Throwable { ClientService.classLoader = classLoader; classLoader.addURL(IOHelper.getCodeSource(ClientLauncher.class).toUri().toURL()); //classForName(classLoader, "com.google.common.collect.ForwardingMultimap"); - ClientService.baseURLs = classpathurls; + ClientService.baseURLs = classpath; LogHelper.debug("Starting JVM and client WatchService"); FileNameMatcher assetMatcher = profile.getAssetUpdateMatcher(); FileNameMatcher clientMatcher = profile.getClientUpdateMatcher(); From 0922c18b22b000834b8a23936c08d8ca034d8a52 Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 11 Dec 2019 08:16:06 +0700 Subject: [PATCH 120/192] =?UTF-8?q?[FEATURE]=20AsyncDownloader=20=D1=82?= =?UTF-8?q?=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D1=81=D1=82=D0=B0=D0=BD=D0=B4?= =?UTF-8?q?=D0=B0=D1=80=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launcher/AsyncDownloader.java | 132 ++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 LauncherCore/src/main/java/pro/gravit/launcher/AsyncDownloader.java diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/AsyncDownloader.java b/LauncherCore/src/main/java/pro/gravit/launcher/AsyncDownloader.java new file mode 100644 index 00000000..a9707b2c --- /dev/null +++ b/LauncherCore/src/main/java/pro/gravit/launcher/AsyncDownloader.java @@ -0,0 +1,132 @@ +package pro.gravit.launcher; + +import pro.gravit.utils.helper.IOHelper; + +import java.io.EOFException; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.net.URLConnection; +import java.nio.file.Path; +import java.util.*; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionException; +import java.util.concurrent.Executor; + +public class AsyncDownloader { + public AsyncDownloader(Callback callback) { + this.callback = callback; + } + + public AsyncDownloader() { + callback = (ignored) -> {}; + } + + @FunctionalInterface + public interface Callback + { + void update(long diff); + } + public final Callback callback; + public static class SizedFile + { + public final String path; + public final long size; + + public SizedFile(String path, long size) { + this.path = path; + this.size = size; + } + } + public void downloadFile(URL url, Path target, long size) throws IOException + { + URLConnection connection = url.openConnection(); + try(InputStream input = connection.getInputStream()) + { + transfer(input, target, size); + } + } + public void downloadFile(URL url, Path target) throws IOException + { + URLConnection connection = url.openConnection(); + try(InputStream input = connection.getInputStream()) + { + IOHelper.transfer(input, target); + } + } + public void downloadListInOneThread(List files, String baseURL, Path targetDir) throws URISyntaxException, IOException { + URI baseUri = new URI(baseURL); + String scheme = baseUri.getScheme(); + String host = baseUri.getHost(); + int port = baseUri.getPort(); + if (port != -1) + host = host + ":" + port; + String path = baseUri.getPath(); + for(AsyncDownloader.SizedFile currentFile : files) + { + URL url = new URI(scheme,host,path + currentFile.path, "", "").toURL(); + downloadFile(url, targetDir.resolve(currentFile.path), currentFile.size); + } + } + public List> sortFiles(List files, int threads) + { + files.sort(Comparator.comparingLong((f) -> -f.size)); + List> result = new ArrayList<>(); + for(int i=0;i()); + long[] sizes = new long[threads]; + Arrays.fill(sizes, 0); + for(SizedFile file : files) + { + long min = Long.MAX_VALUE; + int minIndex = 0; + for(int i=0;i> files, String baseURL, Path targetDir, Executor executor) { + int threads = files.size(); + CompletableFuture[] futures = new CompletableFuture[threads]; + for(int i=0;i currentTasks = files.get(i); + futures[i] = CompletableFuture.runAsync(() -> { + try { + downloadListInOneThread(currentTasks, baseURL, targetDir); + } catch (URISyntaxException | IOException e) { + throw new CompletionException(e); + } + }, executor); + } + return futures; + } + + public void transfer(InputStream input, Path file, long size) throws IOException { + try (OutputStream fileOutput = IOHelper.newOutput(file)) { + long downloaded = 0L; + + // Download with digest update + byte[] bytes = IOHelper.newBuffer(); + while (downloaded < size) { + int remaining = (int) Math.min(size - downloaded, bytes.length); + int length = input.read(bytes, 0, remaining); + if (length < 0) + throw new EOFException(String.format("%d bytes remaining", size - downloaded)); + + // Update file + fileOutput.write(bytes, 0, length); + + // Update state + downloaded += length; + //totalDownloaded += length; + callback.update(length); + } + } + } +} From 2fc32aa1aac2f5b94be54be397fd36eb079989c3 Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 11 Dec 2019 09:15:24 +0700 Subject: [PATCH 121/192] [FEATURE] StdWebSocketService --- LaunchServerConsole/build.gradle | 20 --- .../launchserver/console/ConsoleMain.java | 43 ----- .../launchserver/console/ExecCommand.java | 24 --- .../launchserver/console/ExitCommand.java | 23 --- .../console/LogListenerCommand.java | 46 ------ .../pro/gravit/launcher/LauncherEngine.java | 4 +- .../launcher/console/admin/ExecCommand.java | 24 --- .../console/admin/LogListenerCommand.java | 46 ------ .../launcher/managers/ConsoleManager.java | 7 - .../gravit/launcher/request/PingRequest.java | 7 - .../pro/gravit/launcher/request/Request.java | 12 +- .../request/update/LauncherRequest.java | 6 +- .../request/update/UpdateRequest.java | 10 -- .../request/websockets/ClientJSONPoint.java | 12 ++ .../websockets/ClientWebSocketService.java | 20 ++- .../StandartClientWebSocketService.java | 151 ------------------ .../websockets/StdWebSocketService.java | 123 ++++++++++++++ .../request/websockets/WaitEventHandler.java | 44 ----- settings.gradle | 1 - 19 files changed, 155 insertions(+), 468 deletions(-) delete mode 100644 LaunchServerConsole/build.gradle delete mode 100644 LaunchServerConsole/src/main/java/pro/gravit/launchserver/console/ConsoleMain.java delete mode 100644 LaunchServerConsole/src/main/java/pro/gravit/launchserver/console/ExecCommand.java delete mode 100644 LaunchServerConsole/src/main/java/pro/gravit/launchserver/console/ExitCommand.java delete mode 100644 LaunchServerConsole/src/main/java/pro/gravit/launchserver/console/LogListenerCommand.java delete mode 100644 Launcher/src/main/java/pro/gravit/launcher/console/admin/ExecCommand.java delete mode 100644 Launcher/src/main/java/pro/gravit/launcher/console/admin/LogListenerCommand.java delete mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StandartClientWebSocketService.java create mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StdWebSocketService.java delete mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WaitEventHandler.java diff --git a/LaunchServerConsole/build.gradle b/LaunchServerConsole/build.gradle deleted file mode 100644 index 82076206..00000000 --- a/LaunchServerConsole/build.gradle +++ /dev/null @@ -1,20 +0,0 @@ -String mainClassName = "pro.gravit.launchserver.console.ConsoleMain" - - -repositories { - maven { - url "http://repo.spring.io/plugins-release/" - } -} - -sourceCompatibility = '1.8' -targetCompatibility = '1.8' - -jar { - from { configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) } } - manifest.attributes("Main-Class": mainClassName) -} - -dependencies { - compileOnly project(':ServerWrapper') -} diff --git a/LaunchServerConsole/src/main/java/pro/gravit/launchserver/console/ConsoleMain.java b/LaunchServerConsole/src/main/java/pro/gravit/launchserver/console/ConsoleMain.java deleted file mode 100644 index 572a8bed..00000000 --- a/LaunchServerConsole/src/main/java/pro/gravit/launchserver/console/ConsoleMain.java +++ /dev/null @@ -1,43 +0,0 @@ -package pro.gravit.launchserver.console; - -import pro.gravit.launcher.server.ServerWrapper; -import pro.gravit.utils.command.CommandHandler; -import pro.gravit.utils.command.JLineCommandHandler; -import pro.gravit.utils.command.StdCommandHandler; -import pro.gravit.utils.command.basic.HelpCommand; -import pro.gravit.utils.helper.LogHelper; - -import java.io.IOException; - -public class ConsoleMain { - public static CommandHandler commandHandler; - - public static void main(String[] args) throws IOException { - if (ServerWrapper.wrapper.config == null) { - LogHelper.warning("ServerWrapper not found"); - } - if (!ServerWrapper.wrapper.permissions.canAdmin) { - LogHelper.warning("Permission canAdmin not found"); - } - try { - Class.forName("org.jline.terminal.Terminal"); - - // JLine2 available - commandHandler = new JLineCommandHandler(); - LogHelper.info("JLine2 terminal enabled"); - } catch (ClassNotFoundException ignored) { - commandHandler = new StdCommandHandler(true); - LogHelper.warning("JLine2 isn't in classpath, using std"); - } - registerCommands(); - LogHelper.info("CommandHandler started. Use 'exit' to exit this console"); - commandHandler.run(); - } - - public static void registerCommands() { - commandHandler.registerCommand("help", new HelpCommand(commandHandler)); - commandHandler.registerCommand("exit", new ExitCommand()); - commandHandler.registerCommand("logListener", new LogListenerCommand()); - commandHandler.registerCommand("exec", new ExecCommand()); - } -} diff --git a/LaunchServerConsole/src/main/java/pro/gravit/launchserver/console/ExecCommand.java b/LaunchServerConsole/src/main/java/pro/gravit/launchserver/console/ExecCommand.java deleted file mode 100644 index b35c10ef..00000000 --- a/LaunchServerConsole/src/main/java/pro/gravit/launchserver/console/ExecCommand.java +++ /dev/null @@ -1,24 +0,0 @@ -package pro.gravit.launchserver.console; - -import pro.gravit.launcher.events.request.ExecCommandRequestEvent; -import pro.gravit.launcher.request.admin.ExecCommandRequest; -import pro.gravit.utils.command.Command; -import pro.gravit.utils.helper.LogHelper; - -public class ExecCommand extends Command { - @Override - public String getArgsDescription() { - return null; - } - - @Override - public String getUsageDescription() { - return null; - } - - @Override - public void invoke(String... args) throws Exception { - ExecCommandRequestEvent request = new ExecCommandRequest(String.join(" ")).request(); - if (!request.success) LogHelper.error("Error executing command"); - } -} diff --git a/LaunchServerConsole/src/main/java/pro/gravit/launchserver/console/ExitCommand.java b/LaunchServerConsole/src/main/java/pro/gravit/launchserver/console/ExitCommand.java deleted file mode 100644 index 01be5427..00000000 --- a/LaunchServerConsole/src/main/java/pro/gravit/launchserver/console/ExitCommand.java +++ /dev/null @@ -1,23 +0,0 @@ -package pro.gravit.launchserver.console; - -import pro.gravit.utils.command.Command; - -public class ExitCommand extends Command { - public ExitCommand() { - } - - @Override - public String getArgsDescription() { - return null; - } - - @Override - public String getUsageDescription() { - return null; - } - - @Override - public void invoke(String... args) { - System.exit(0); - } -} diff --git a/LaunchServerConsole/src/main/java/pro/gravit/launchserver/console/LogListenerCommand.java b/LaunchServerConsole/src/main/java/pro/gravit/launchserver/console/LogListenerCommand.java deleted file mode 100644 index adef0b69..00000000 --- a/LaunchServerConsole/src/main/java/pro/gravit/launchserver/console/LogListenerCommand.java +++ /dev/null @@ -1,46 +0,0 @@ -package pro.gravit.launchserver.console; - -import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.events.request.LogEvent; -import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.websockets.WebSocketRequest; -import pro.gravit.utils.command.Command; -import pro.gravit.utils.helper.LogHelper; - -public class LogListenerCommand extends Command { - public static class LogListenerRequest implements WebSocketRequest { - @LauncherNetworkAPI - public final LogHelper.OutputTypes outputType; - - public LogListenerRequest(LogHelper.OutputTypes outputType) { - this.outputType = outputType; - } - - @Override - public String getType() { - return "addLogListener"; - } - } - - @Override - public String getArgsDescription() { - return null; - } - - @Override - public String getUsageDescription() { - return null; - } - - @Override - public void invoke(String... args) throws Exception { - LogHelper.info("Send log listener request"); - Request.service.sendObject(new LogListenerRequest(LogHelper.JANSI ? LogHelper.OutputTypes.JANSI : LogHelper.OutputTypes.PLAIN)); - LogHelper.info("Add log handler"); - Request.service.registerHandler((result) -> { - if (result instanceof LogEvent) { - System.out.println(((LogEvent) result).string); - } - }); - } -} diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index 9ef2d841..9b3a3715 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -14,7 +14,7 @@ import pro.gravit.launcher.request.Request; import pro.gravit.launcher.request.RequestException; import pro.gravit.launcher.request.auth.RestoreSessionRequest; -import pro.gravit.launcher.request.websockets.StandartClientWebSocketService; +import pro.gravit.launcher.request.websockets.StdWebSocketService; import pro.gravit.utils.helper.*; import java.io.IOException; @@ -146,7 +146,7 @@ public void start(String... args) throws Throwable { if (Request.service == null) { String address = Launcher.getConfig().address; LogHelper.debug("Start async connection to %s", address); - Request.service = StandartClientWebSocketService.initWebSockets(address, true); + Request.service = StdWebSocketService.initWebSockets(address, true); Request.service.reconnectCallback = () -> { LogHelper.debug("WebSocket connect closed. Try reconnect"); diff --git a/Launcher/src/main/java/pro/gravit/launcher/console/admin/ExecCommand.java b/Launcher/src/main/java/pro/gravit/launcher/console/admin/ExecCommand.java deleted file mode 100644 index 03f2582b..00000000 --- a/Launcher/src/main/java/pro/gravit/launcher/console/admin/ExecCommand.java +++ /dev/null @@ -1,24 +0,0 @@ -package pro.gravit.launcher.console.admin; - -import pro.gravit.launcher.events.request.ExecCommandRequestEvent; -import pro.gravit.launcher.request.admin.ExecCommandRequest; -import pro.gravit.utils.command.Command; -import pro.gravit.utils.helper.LogHelper; - -public class ExecCommand extends Command { - @Override - public String getArgsDescription() { - return null; - } - - @Override - public String getUsageDescription() { - return null; - } - - @Override - public void invoke(String... args) throws Exception { - ExecCommandRequestEvent request = new ExecCommandRequest(String.join(" ", args)).request(); - if (!request.success) LogHelper.error("Error executing command"); - } -} diff --git a/Launcher/src/main/java/pro/gravit/launcher/console/admin/LogListenerCommand.java b/Launcher/src/main/java/pro/gravit/launcher/console/admin/LogListenerCommand.java deleted file mode 100644 index 8e80354d..00000000 --- a/Launcher/src/main/java/pro/gravit/launcher/console/admin/LogListenerCommand.java +++ /dev/null @@ -1,46 +0,0 @@ -package pro.gravit.launcher.console.admin; - -import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.events.request.LogEvent; -import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.websockets.WebSocketRequest; -import pro.gravit.utils.command.Command; -import pro.gravit.utils.helper.LogHelper; - -public class LogListenerCommand extends Command { - public static class LogListenerRequest implements WebSocketRequest { - @LauncherNetworkAPI - public final LogHelper.OutputTypes outputType; - - public LogListenerRequest(LogHelper.OutputTypes outputType) { - this.outputType = outputType; - } - - @Override - public String getType() { - return "addLogListener"; - } - } - - @Override - public String getArgsDescription() { - return null; - } - - @Override - public String getUsageDescription() { - return null; - } - - @Override - public void invoke(String... args) throws Exception { - LogHelper.info("Send log listener request"); - Request.service.sendObject(new LogListenerRequest(LogHelper.JANSI ? LogHelper.OutputTypes.JANSI : LogHelper.OutputTypes.PLAIN)); - LogHelper.info("Add log handler"); - Request.service.registerHandler((result) -> { - if (result instanceof LogEvent) { - LogHelper.rawLog(() -> ((LogEvent) result).string, () -> ((LogEvent) result).string, () -> ((LogEvent) result).string); - } - }); - } -} diff --git a/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java b/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java index 19098f36..6b87f2ec 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java +++ b/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java @@ -2,9 +2,6 @@ import pro.gravit.launcher.Launcher; import pro.gravit.launcher.console.UnlockCommand; -import pro.gravit.launcher.console.admin.ExecCommand; -import pro.gravit.launcher.console.admin.LogListenerCommand; -import pro.gravit.utils.command.BaseCommandCategory; import pro.gravit.utils.command.CommandHandler; import pro.gravit.utils.command.JLineCommandHandler; import pro.gravit.utils.command.StdCommandHandler; @@ -53,10 +50,6 @@ public static boolean checkUnlockKey(String key) { public static void unlock() { handler.registerCommand("debug", new DebugCommand()); - BaseCommandCategory admin = new BaseCommandCategory(); - admin.registerCommand("exec", new ExecCommand()); - admin.registerCommand("logListen", new LogListenerCommand()); - handler.registerCategory(new CommandHandler.Category(admin, "admin", "Server admin commands")); isConsoleUnlock = true; } } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/PingRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/PingRequest.java index b911b957..ee526029 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/PingRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/PingRequest.java @@ -1,14 +1,7 @@ package pro.gravit.launcher.request; -import pro.gravit.launcher.request.websockets.StandartClientWebSocketService; - public final class PingRequest extends Request { - @Override - protected WebSocketEvent requestDo(StandartClientWebSocketService service) { - return null; - } - @Override public String getType() { return null; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java index b7ef97ce..ecd9b17b 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java @@ -2,7 +2,7 @@ import pro.gravit.launcher.Launcher; import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.request.websockets.StandartClientWebSocketService; +import pro.gravit.launcher.request.websockets.StdWebSocketService; import pro.gravit.launcher.request.websockets.WebSocketRequest; import pro.gravit.utils.helper.SecurityHelper; @@ -13,7 +13,7 @@ public abstract class Request implements WebSocketRequ private static long session = SecurityHelper.secureRandom.nextLong(); @LauncherNetworkAPI public final UUID requestUUID = UUID.randomUUID(); - public static StandartClientWebSocketService service; + public static StdWebSocketService service; public static void setSession(long session) { Request.session = session; @@ -35,20 +35,20 @@ public R request() throws Exception { if (!started.compareAndSet(false, true)) throw new IllegalStateException("Request already started"); if (service == null) - service = StandartClientWebSocketService.initWebSockets(Launcher.getConfig().address, false); + service = StdWebSocketService.initWebSockets(Launcher.getConfig().address, false); return requestDo(service); } - public R request(StandartClientWebSocketService service) throws Exception { + public R request(StdWebSocketService service) throws Exception { if (!started.compareAndSet(false, true)) throw new IllegalStateException("Request already started"); return requestDo(service); } @SuppressWarnings("unchecked") - protected R requestDo(StandartClientWebSocketService service) throws Exception { - return (R) service.sendRequest(this); + protected R requestDo(StdWebSocketService service) throws Exception { + return service.requestSync(this); } } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/LauncherRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/LauncherRequest.java index 1ba207ae..225eda38 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/LauncherRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/LauncherRequest.java @@ -4,7 +4,7 @@ import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.request.LauncherRequestEvent; import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.websockets.StandartClientWebSocketService; +import pro.gravit.launcher.request.websockets.StdWebSocketService; import pro.gravit.launcher.request.websockets.WebSocketRequest; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.JVMHelper; @@ -83,8 +83,8 @@ public static void update(LauncherRequestEvent result) throws IOException { } @Override - public LauncherRequestEvent requestDo(StandartClientWebSocketService service) throws Exception { - LauncherRequestEvent result = (LauncherRequestEvent) service.sendRequest(this); + public LauncherRequestEvent requestDo(StdWebSocketService service) throws Exception { + LauncherRequestEvent result = super.request(service); if (result.needUpdate) update(result); return result; } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java index 3c8344bf..1b4502cc 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java @@ -3,9 +3,7 @@ import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.request.UpdateRequestEvent; import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.websockets.StandartClientWebSocketService; import pro.gravit.launcher.request.websockets.WebSocketRequest; -import pro.gravit.utils.helper.LogHelper; public final class UpdateRequest extends Request implements WebSocketRequest { @@ -18,14 +16,6 @@ public String getType() { return "update"; } - - - @Override - public UpdateRequestEvent requestDo(StandartClientWebSocketService service) throws Exception { - LogHelper.debug("Start update request"); - return (UpdateRequestEvent) service.sendRequest(this); - } - // Instance @LauncherNetworkAPI private final String dirName; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientJSONPoint.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientJSONPoint.java index c646a6a4..e91effcc 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientJSONPoint.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientJSONPoint.java @@ -76,6 +76,18 @@ public void open() throws Exception { ch = bootstrap.connect(uri.getHost(), port).sync().channel(); webSocketClientHandler.handshakeFuture().sync(); } + public void openAsync(Runnable onConnect) { + //System.out.println("WebSocket Client connecting"); + webSocketClientHandler = + new WebSocketClientHandler( + WebSocketClientHandshakerFactory.newHandshaker( + uri, WebSocketVersion.V13, null, false, EmptyHttpHeaders.INSTANCE, 12800000), this); + ChannelFuture future = bootstrap.connect(); + future.addListener((e) -> { + ch = future.channel(); + webSocketClientHandler.handshakeFuture().addListener((e1) -> onConnect.run()); + }); + } public ChannelFuture send(String text) { LogHelper.dev("Send: %s", text); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java index 3ec44934..45cac23c 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java @@ -22,18 +22,16 @@ import java.net.URISyntaxException; import java.util.HashSet; -public class ClientWebSocketService extends ClientJSONPoint { +public abstract class ClientWebSocketService extends ClientJSONPoint { public final Gson gson; public OnCloseCallback onCloseCallback; public final Boolean onConnect; public ReconnectCallback reconnectCallback; public static final ProviderMap results = new ProviderMap<>(); public static final ProviderMap requests = new ProviderMap<>(); - private HashSet handlers; public ClientWebSocketService(String address) throws SSLException { super(createURL(address)); - handlers = new HashSet<>(); this.gson = Launcher.gsonManager.gson; this.onConnect = true; } @@ -56,10 +54,9 @@ private static URI createURL(String address) { @Override void onMessage(String message) { WebSocketEvent result = gson.fromJson(message, WebSocketEvent.class); - for (EventHandler handler : handlers) { - handler.process(result); - } + eventHandle(result); } + public abstract void eventHandle(T event); @Override void onDisconnect() { @@ -113,10 +110,6 @@ public void registerResults() { results.register("signal", SignalEvent.class); } - public void registerHandler(EventHandler eventHandler) { - handlers.add(eventHandler); - } - public void waitIfNotConnected() { /*if(!isOpen() && !isClosed() && !isClosing()) { @@ -150,6 +143,11 @@ public void sendObject(Object obj, Type type) throws IOException { @FunctionalInterface public interface EventHandler { - void process(WebSocketEvent webSocketEvent); + /** + * @param event processing event + * @param event type + * @return false - continue, true - stop + */ + boolean eventHandle(T event); } } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StandartClientWebSocketService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StandartClientWebSocketService.java deleted file mode 100644 index 8af049ab..00000000 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StandartClientWebSocketService.java +++ /dev/null @@ -1,151 +0,0 @@ -package pro.gravit.launcher.request.websockets; - -import pro.gravit.launcher.events.ExceptionEvent; -import pro.gravit.launcher.events.request.ErrorRequestEvent; -import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.RequestException; -import pro.gravit.launcher.request.WebSocketEvent; -import pro.gravit.launcher.request.auth.AuthRequest; -import pro.gravit.utils.helper.JVMHelper; -import pro.gravit.utils.helper.LogHelper; - -import javax.net.ssl.SSLException; -import java.io.IOException; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; - -public class StandartClientWebSocketService extends ClientWebSocketService { - public final WaitEventHandler waitEventHandler = new WaitEventHandler(); - - public StandartClientWebSocketService(String address) throws SSLException { - super(address); - AuthRequest.registerProviders(); - } - - public class RequestFuture implements Future { - public final WaitEventHandler.ResultEvent event; - public boolean isCanceled = false; - - @SuppressWarnings("rawtypes") - public RequestFuture(WebSocketRequest request) throws IOException { - event = new WaitEventHandler.ResultEvent(); - event.type = request.getType(); - if (request instanceof Request) { - event.uuid = ((Request) request).requestUUID; - } - waitEventHandler.requests.add(event); - sendObject(request); - } - - @Override - public boolean cancel(boolean mayInterruptIfRunning) { - waitEventHandler.requests.remove(event); - isCanceled = true; - return true; - } - - @Override - public boolean isCancelled() { - return isCanceled; - } - - @Override - public boolean isDone() { - return event.ready; - } - - @Override - public WebSocketEvent get() throws InterruptedException, ExecutionException { - if (isCanceled) return null; - synchronized (event) { - while (!event.ready) { - event.wait(); - } - } - WebSocketEvent result = event.result; - waitEventHandler.requests.remove(event); - if (event.result.getType().equals("error")) { - ErrorRequestEvent errorRequestEvent = (ErrorRequestEvent) event.result; - throw new ExecutionException(new RequestException(errorRequestEvent.error)); - } - if (event.result.getType().equals("exception")) { - ExceptionEvent error = (ExceptionEvent) event.result; - throw new ExecutionException(new RequestException(String.format("LaunchServer fatal error: %s: %s", error.clazz, error.message))); - } - return result; - } - - @Override - public WebSocketEvent get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException { - if (isCanceled) return null; - synchronized (event) { - while (!event.ready) { - event.wait(timeout); - } - } - WebSocketEvent result = event.result; - waitEventHandler.requests.remove(event); - if (event.result.getType().equals("error")) { - ErrorRequestEvent errorRequestEvent = (ErrorRequestEvent) event.result; - throw new ExecutionException(new RequestException(errorRequestEvent.error)); - } - if (event.result.getType().equals("exception")) { - ExceptionEvent error = (ExceptionEvent) event.result; - throw new ExecutionException(new RequestException(String.format("LaunchServer fatal error: %s: %s", error.clazz, error.message))); - } - return result; - } - } - - public WebSocketEvent sendRequest(WebSocketRequest request) throws IOException, InterruptedException { - RequestFuture future = new RequestFuture(request); - WebSocketEvent result; - try { - result = future.get(); - } catch (ExecutionException e) { - throw (RequestException) e.getCause(); - } - return result; - } - - public RequestFuture asyncSendRequest(WebSocketRequest request) throws IOException { - return new RequestFuture(request); - } - - public static StandartClientWebSocketService initWebSockets(String address, boolean async) { - StandartClientWebSocketService service; - try { - service = new StandartClientWebSocketService(address); - } catch (SSLException e) { - throw new SecurityException(e); - } - service.registerResults(); - service.registerRequests(); - service.registerHandler(service.waitEventHandler); - if (!async) { - try { - service.open(); - LogHelper.debug("Connect to %s", address); - } catch (Exception e) { - e.printStackTrace(); - } - } else { - try { - service.open(); - } catch (Exception e) { - e.printStackTrace(); - } - } - JVMHelper.RUNTIME.addShutdownHook(new Thread(() -> { - try { - //if(service.isOpen()) - // service.closeBlocking(); - service.close(); - } catch (InterruptedException e) { - LogHelper.error(e); - } - })); - return service; - } -} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StdWebSocketService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StdWebSocketService.java new file mode 100644 index 00000000..21ba495d --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StdWebSocketService.java @@ -0,0 +1,123 @@ +package pro.gravit.launcher.request.websockets; + +import pro.gravit.launcher.events.ExceptionEvent; +import pro.gravit.launcher.events.RequestEvent; +import pro.gravit.launcher.events.request.ErrorRequestEvent; +import pro.gravit.launcher.request.Request; +import pro.gravit.launcher.request.RequestException; +import pro.gravit.launcher.request.WebSocketEvent; +import pro.gravit.utils.helper.JVMHelper; +import pro.gravit.utils.helper.LogHelper; + +import javax.net.ssl.SSLException; +import java.io.IOException; +import java.util.HashSet; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutionException; + +public class StdWebSocketService extends ClientWebSocketService { + private final ConcurrentHashMap futureMap = new ConcurrentHashMap<>(); + private final HashSet eventHandlers = new HashSet<>(); + public void registerEventHandler(EventHandler handler) + { + eventHandlers.add(handler); + } + public void processEventHandlers(T event) + { + for(EventHandler handler : eventHandlers) + { + if(handler.eventHandle(event)) return; + } + } + + public StdWebSocketService(String address) throws SSLException { + super(address); + } + @SuppressWarnings("unchecked") + public void eventHandle(T webSocketEvent) { + if(webSocketEvent instanceof RequestEvent) + { + RequestEvent event = (RequestEvent) webSocketEvent; + if(event.requestUUID == null) + { + LogHelper.warning("Request event type %s.requestUUID is null", event.getType() == null ? "null" : event.getType()); + return; + } + if(event.requestUUID.equals(RequestEvent.eventUUID)) + { + processEventHandlers(webSocketEvent); + return; + } + CompletableFuture future = futureMap.get(event.requestUUID); + if(future != null) { + if (event instanceof ErrorRequestEvent) { + future.completeExceptionally(new RequestException(((ErrorRequestEvent) event).error)); + } else if (event instanceof ExceptionEvent) { + future.completeExceptionally(new RequestException( + String.format("LaunchServer internal error: %s %s", ((ExceptionEvent) event).clazz, ((ExceptionEvent) event).message))); + } else + future.complete(event); + futureMap.remove(event.requestUUID); + } + else + { + processEventHandlers(event); + return; + } + } + // + processEventHandlers(webSocketEvent); + } + public CompletableFuture request(Request request) throws IOException { + CompletableFuture result = new CompletableFuture(); + futureMap.put(request.requestUUID, result); + sendObject(request, WebSocketRequest.class); + return result; + } + public T requestSync(Request request) throws IOException { + try { + return request(request).get(); + } catch (InterruptedException e) { + throw new RequestException("Request interrupted"); + } catch (ExecutionException e) { + Throwable cause = e.getCause(); + if(cause instanceof IOException) + throw (IOException) e.getCause(); + else + { + throw new RequestException(cause); + } + } + } + public static StdWebSocketService initWebSockets(String address, boolean async) { + StdWebSocketService service; + try { + service = new StdWebSocketService(address); + } catch (SSLException e) { + throw new SecurityException(e); + } + service.registerResults(); + service.registerRequests(); + if (!async) { + try { + service.open(); + } catch (Exception e) { + LogHelper.error(e); + } + } else { + service.openAsync(() -> {}); + } + JVMHelper.RUNTIME.addShutdownHook(new Thread(() -> { + try { + //if(service.isOpen()) + // service.closeBlocking(); + service.close(); + } catch (InterruptedException e) { + LogHelper.error(e); + } + })); + return service; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WaitEventHandler.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WaitEventHandler.java deleted file mode 100644 index ff9281fb..00000000 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WaitEventHandler.java +++ /dev/null @@ -1,44 +0,0 @@ -package pro.gravit.launcher.request.websockets; - -import pro.gravit.launcher.events.RequestEvent; -import pro.gravit.launcher.request.WebSocketEvent; -import pro.gravit.utils.helper.LogHelper; - -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; - -public class WaitEventHandler implements ClientWebSocketService.EventHandler { - public final Set requests = ConcurrentHashMap.newKeySet(); - - @Override - public void process(WebSocketEvent result) { - LogHelper.debug("Processing event %s type", result.getType()); - UUID checkUUID = null; - if (result instanceof RequestEvent) { - RequestEvent event = (RequestEvent) result; - checkUUID = event.requestUUID; - if (checkUUID != null) - LogHelper.debug("Event UUID: %s found", checkUUID.toString()); - } - for (ResultEvent r : requests) { - if (r.uuid != null) - LogHelper.debug("Request UUID found: %s", r.uuid.toString()); - if ((r.uuid != null && r.uuid.equals(checkUUID)) || (checkUUID == null && (r.type.equals(result.getType()) || result.getType().equals("error")))) { - LogHelper.debug("Event %s type", r.type); - synchronized (r) { - r.result = result; - r.ready = true; - r.notifyAll(); - } - } - } - } - - public static class ResultEvent { - public WebSocketEvent result; - public UUID uuid; - public String type; - public boolean ready; - } -} diff --git a/settings.gradle b/settings.gradle index ca469385..0cc99c8c 100644 --- a/settings.gradle +++ b/settings.gradle @@ -6,7 +6,6 @@ include 'LauncherAuthlib' include 'ServerWrapper' include 'LaunchServer' -include 'LaunchServerConsole' include 'modules' file('modules').eachDir { sub -> if (sub.name.endsWith('_module') || sub.name.endsWith('_swmodule') || sub.name.endsWith('_lmodule')) include 'modules:' + sub.name From 5e27db127ab22bd36f8f244a044e01a08f3edada Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 11 Dec 2019 10:24:26 +0700 Subject: [PATCH 122/192] =?UTF-8?q?[FEATURE]=20=D0=9F=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D0=BA=D0=B0=20=D1=81=D0=B5=D1=80=D1=82=D0=B8=D1=84?= =?UTF-8?q?=D0=B8=D0=BA=D0=B0=D1=82=D0=B0=20=D0=BD=D0=B0=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BE=20=D0=BF=D0=BE=D0=B4=D0=BF=D0=B8=D1=81=D1=8B?= =?UTF-8?q?=D0=B2=D0=B0=D1=82=D1=8C=20=D0=BF=D1=80=D0=B8=D0=BB=D0=BE=D0=B6?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../binary/tasks/CertificateAutogenTask.java | 3 +++ .../manangers/CertificateManager.java | 4 +--- .../pro/gravit/launcher/LauncherEngine.java | 4 +--- .../modules/impl/SimpleModuleManager.java | 4 +--- .../gravit/launcher/LauncherTrustManager.java | 22 +++++++++++++++++++ 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/CertificateAutogenTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/CertificateAutogenTask.java index feaddff3..5301903c 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/CertificateAutogenTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/CertificateAutogenTask.java @@ -1,8 +1,10 @@ package pro.gravit.launchserver.binary.tasks; +import org.bouncycastle.asn1.ASN1ObjectIdentifier; import org.bouncycastle.asn1.x500.X500Name; import org.bouncycastle.asn1.x500.X500NameBuilder; import org.bouncycastle.asn1.x500.style.BCStyle; +import org.bouncycastle.asn1.x509.Extension; import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; import org.bouncycastle.cert.X509CertificateHolder; import org.bouncycastle.cert.X509v3CertificateBuilder; @@ -58,6 +60,7 @@ public Path process(Path inputFile) throws IOException { Date.from(startDate.plusDays(3650).atZone(ZoneId.systemDefault()).toInstant()), new X500Name("CN=ca"), SubjectPublicKeyInfo.getInstance(server.publicKey.getEncoded())); + builder.addExtension(Extension.getInstance("1.3.6.1.5.5.7.3.3")); JcaContentSignerBuilder csBuilder = new JcaContentSignerBuilder("SHA256WITHECDSA"); ContentSigner signer = csBuilder.build(server.privateKey); bcCertificate = builder.build(signer); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/CertificateManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/CertificateManager.java index 8744e7e6..c0eb3603 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/CertificateManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/CertificateManager.java @@ -208,9 +208,7 @@ else if (mode == LauncherTrustManager.CheckMode.WARN_IN_NOT_SIGNED) return; } try { - trustManager.checkCertificate(certificates, (c, s) -> { - - }); + trustManager.checkCertificate(certificates, trustManager::stdCertificateChecker); } catch (CertificateException | NoSuchProviderException | NoSuchAlgorithmException | InvalidKeyException | SignatureException e) { throw new SecurityException(e); } diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index 9b3a3715..d8070087 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -47,9 +47,7 @@ public static void checkClass(Class clazz) throws SecurityException { throw new SecurityException(String.format("Class %s not signed", clazz.getName())); } try { - trustManager.checkCertificate(certificates, (c, s) -> { - - }); + trustManager.checkCertificate(certificates, trustManager::stdCertificateChecker); } catch (CertificateException | NoSuchProviderException | NoSuchAlgorithmException | InvalidKeyException | SignatureException e) { throw new SecurityException(e); } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java index ce124b68..af9c68a8 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java @@ -187,9 +187,7 @@ else if (mode == LauncherTrustManager.CheckMode.WARN_IN_NOT_SIGNED) return; } try { - trustManager.checkCertificate(certificates, (c, s) -> { - - }); + trustManager.checkCertificate(certificates, trustManager::stdCertificateChecker); } catch (CertificateException | NoSuchProviderException | NoSuchAlgorithmException | InvalidKeyException | SignatureException e) { throw new SecurityException(e); } diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/LauncherTrustManager.java b/LauncherCore/src/main/java/pro/gravit/launcher/LauncherTrustManager.java index 5710081a..23a280ff 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/LauncherTrustManager.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/LauncherTrustManager.java @@ -91,8 +91,30 @@ public void isCertificateCodeSign(X509Certificate certificate) List extended; try { extended = certificate.getExtendedKeyUsage(); + if(extended == null) throw new SecurityException("Certificate extendedKeyUsage null"); + boolean isCodeSign = false; + for(String s : extended) + { + if(s.equals("1.3.6.1.5.5.7.3.3")) + { + isCodeSign = true; + break; + } + } + if(!isCodeSign) throw new SecurityException("Certificate extendedKeyUsage codeSign checkFailed"); } catch (CertificateParsingException e) { throw new SecurityException(e); } } + public void isCertificateCA(X509Certificate certificate) + { + if(certificate.getBasicConstraints() <= 0) throw new SecurityException("This certificate not CA"); + } + public void stdCertificateChecker(X509Certificate cert, X509Certificate signer) + { + if(signer == null) + isCertificateCodeSign(cert); + else + isCertificateCA(cert); + } } From 4dcc1443f698823ca90f9e9e6e5762f12c56b77f Mon Sep 17 00:00:00 2001 From: Gravit Date: Thu, 12 Dec 2019 06:04:52 +0700 Subject: [PATCH 123/192] =?UTF-8?q?[FIX]=20=D0=98=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D1=81=D0=BF=D0=BE=D1=81=D0=BE=D0=B1=D0=BD=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D0=B8=20=D0=BA=D0=BB=D0=B8=D0=B5=D0=BD=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launcher/client/ClientLauncher.java | 1 - .../client/ClientSecurityManager.java | 29 ------------------- .../request/websockets/ClientJSONPoint.java | 2 +- .../gravit/launcher/LauncherTrustManager.java | 10 +++---- .../gravit/utils/UniversalJsonAdapter.java | 4 +++ 5 files changed, 10 insertions(+), 36 deletions(-) delete mode 100644 Launcher/src/main/java/pro/gravit/launcher/client/ClientSecurityManager.java diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index 1f189cea..57a23d37 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -448,7 +448,6 @@ public static void main(String... args) throws Throwable { EnvHelper.checkDangerousParams(); JVMHelper.checkStackTrace(ClientLauncher.class); LogHelper.printVersion("Client Launcher"); - //System.setSecurityManager(new ClientSecurityManager()); engine.readKeys(); HWIDProvider.registerHWIDs(); LauncherGuardManager.initGuard(true); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientSecurityManager.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientSecurityManager.java deleted file mode 100644 index 86fea872..00000000 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientSecurityManager.java +++ /dev/null @@ -1,29 +0,0 @@ -package pro.gravit.launcher.client; - -import java.security.Permission; - -public class ClientSecurityManager extends SecurityManager { - @Override - public void checkPermission(Permission perm) - { - String permName = perm.getName(); - if(permName == null) return; - if (permName.startsWith("exitVM")) - { - Class[] classContexts = getClassContext(); - String callingClass = classContexts.length > 3 ? classContexts[4].getName() : "none"; - if (!(callingClass.startsWith("pro.gravit."))) - { - throw new ExitTrappedException(); - } - } - } - - @Override - public void checkPermission(Permission perm, Object context) { - } - - public static class ExitTrappedException extends SecurityException { - private static final long serialVersionUID = 6929785890434102330L; - } -} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientJSONPoint.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientJSONPoint.java index e91effcc..488cf589 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientJSONPoint.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientJSONPoint.java @@ -82,7 +82,7 @@ public void openAsync(Runnable onConnect) { new WebSocketClientHandler( WebSocketClientHandshakerFactory.newHandshaker( uri, WebSocketVersion.V13, null, false, EmptyHttpHeaders.INSTANCE, 12800000), this); - ChannelFuture future = bootstrap.connect(); + ChannelFuture future = bootstrap.connect(uri.getHost(), port); future.addListener((e) -> { ch = future.channel(); webSocketClientHandler.handshakeFuture().addListener((e1) -> onConnect.run()); diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/LauncherTrustManager.java b/LauncherCore/src/main/java/pro/gravit/launcher/LauncherTrustManager.java index 23a280ff..6112f0dc 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/LauncherTrustManager.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/LauncherTrustManager.java @@ -40,7 +40,7 @@ public enum CheckMode { } public interface CertificateChecker { - void check(X509Certificate cert, X509Certificate signer) throws SecurityException; + void check(X509Certificate cert, X509Certificate signer, int number) throws SecurityException; } public void checkCertificate(X509Certificate[] certs, CertificateChecker checker) throws CertificateException, NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyException, SignatureException { @@ -61,7 +61,7 @@ public void checkCertificate(X509Certificate[] certs, CertificateChecker checker throw new CertificateException(String.format("Certificate %s is not signed by a trusted signer", cert.getSubjectDN().getName())); } } - checker.check(cert, signer); + checker.check(cert, signer, i); } Collections.addAll(trustCache, certs); } @@ -108,11 +108,11 @@ public void isCertificateCodeSign(X509Certificate certificate) } public void isCertificateCA(X509Certificate certificate) { - if(certificate.getBasicConstraints() <= 0) throw new SecurityException("This certificate not CA"); + if(certificate.getBasicConstraints() < 0) throw new SecurityException("This certificate not CA"); } - public void stdCertificateChecker(X509Certificate cert, X509Certificate signer) + public void stdCertificateChecker(X509Certificate cert, X509Certificate signer, int number) { - if(signer == null) + if(number == 0) isCertificateCodeSign(cert); else isCertificateCA(cert); diff --git a/LauncherCore/src/main/java/pro/gravit/utils/UniversalJsonAdapter.java b/LauncherCore/src/main/java/pro/gravit/utils/UniversalJsonAdapter.java index 093c271a..221df950 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/UniversalJsonAdapter.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/UniversalJsonAdapter.java @@ -46,6 +46,10 @@ public JsonElement serialize(R src, Type typeOfSrc, JsonSerializationContext con if (classPath == null && src instanceof TypeSerializeInterface) { classPath = ((TypeSerializeInterface) src).getType(); } + if(classPath == null) + { + LogHelper.warning("Class %s type null", src.getClass()); + } jo.add(PROP_NAME, new JsonPrimitive(classPath)); return jo; From a259527a20b6e4fac6baa0a258cc21a264dad8e5 Mon Sep 17 00:00:00 2001 From: Gravit Date: Fri, 13 Dec 2019 09:37:42 +0700 Subject: [PATCH 124/192] =?UTF-8?q?[FIX]=20=D0=A5=D0=B0=D0=BA=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20Forge?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/pro/gravit/launcher/client/ClientLauncher.java | 9 +++++++-- .../launcher/request/websockets/ClientJSONPoint.java | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index 57a23d37..046ebf9c 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -299,7 +299,12 @@ private static void launch(ClientProfile profile, Params params) throws Throwabl Launcher.LAUNCHED.set(true); JVMHelper.fullGC(); // Invoke main method - mainMethod.invokeWithArguments((Object) args.toArray(new String[0])); + try { + mainMethod.invokeWithArguments((Object) args.toArray(new String[0])); + } finally { + Request.service.close(); + } + } private static Process process = null; @@ -501,7 +506,7 @@ public static void main(String... args) throws Throwable { ClientService.classLoader = classLoader; classLoader.addURL(IOHelper.getCodeSource(ClientLauncher.class).toUri().toURL()); //classForName(classLoader, "com.google.common.collect.ForwardingMultimap"); - ClientService.baseURLs = classpath; + ClientService.baseURLs = classLoader.getURLs(); LogHelper.debug("Starting JVM and client WatchService"); FileNameMatcher assetMatcher = profile.getAssetUpdateMatcher(); FileNameMatcher clientMatcher = profile.getClientUpdateMatcher(); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientJSONPoint.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientJSONPoint.java index 488cf589..3249510b 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientJSONPoint.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientJSONPoint.java @@ -108,7 +108,7 @@ public void close() throws InterruptedException { ch.closeFuture().sync(); } - //group.shutdownGracefully(); + group.shutdownGracefully(); } public void eval(final String text) { From a125fd8e8fa72661da9ccdb45678c59a39ef9715 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 14 Dec 2019 12:13:55 +0700 Subject: [PATCH 125/192] =?UTF-8?q?[ANY]=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index 9282291e..3bee30b7 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 9282291e67d54aa617d32e78ef70a62b50a4c428 +Subproject commit 3bee30b78fb6a2e92fc97e3b6a257a8c4e9d4d54 From 3bfed5c3c7152645446c93e7391f7421b8262dfd Mon Sep 17 00:00:00 2001 From: Gravit Date: Tue, 17 Dec 2019 11:37:21 +0700 Subject: [PATCH 126/192] =?UTF-8?q?[FEATURE]=20=D0=A1=D0=BE=D0=B1=D1=8B?= =?UTF-8?q?=D1=82=D0=B8=D0=B5=20=D0=B7=D0=B0=D0=BA=D1=80=D1=8B=D1=82=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=BA=D0=BB=D0=B8=D0=B5=D0=BD=D1=82=D0=B0,=20=D1=81?= =?UTF-8?q?=D0=B5=D1=80=D0=B2=D0=B8=D1=81=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=BA=D0=B8=20exit/setSecurityManager?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launcher/LauncherEngine.java | 18 ++++++++++++- .../pro/gravit/launcher/api/AuthService.java | 2 ++ .../gravit/launcher/api/SystemService.java | 25 +++++++++++++++++++ .../launcher/client/ClientLauncher.java | 1 + .../client/events/ClientExitPhase.java | 11 ++++++++ .../launcher/profiles/ClientProfile.java | 12 +++++++++ 6 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 Launcher/src/main/java/pro/gravit/launcher/api/SystemService.java create mode 100644 Launcher/src/main/java/pro/gravit/launcher/client/events/ClientExitPhase.java diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index d8070087..f2c2421e 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -1,7 +1,9 @@ package pro.gravit.launcher; +import pro.gravit.launcher.api.SystemService; import pro.gravit.launcher.client.*; import pro.gravit.launcher.client.events.ClientEngineInitPhase; +import pro.gravit.launcher.client.events.ClientExitPhase; import pro.gravit.launcher.client.events.ClientPreGuiPhase; import pro.gravit.launcher.guard.LauncherGuardManager; import pro.gravit.launcher.gui.NoRuntimeProvider; @@ -10,11 +12,13 @@ import pro.gravit.launcher.managers.ClientGsonManager; import pro.gravit.launcher.managers.ClientHookManager; import pro.gravit.launcher.managers.ConsoleManager; +import pro.gravit.launcher.modules.events.ClosePhase; import pro.gravit.launcher.modules.events.PreConfigPhase; import pro.gravit.launcher.request.Request; import pro.gravit.launcher.request.RequestException; import pro.gravit.launcher.request.auth.RestoreSessionRequest; import pro.gravit.launcher.request.websockets.StdWebSocketService; +import pro.gravit.launcher.utils.NativeJVMHalt; import pro.gravit.utils.helper.*; import java.io.IOException; @@ -53,6 +57,18 @@ public static void checkClass(Class clazz) throws SecurityException { } } + public static void exitLauncher(int code) + { + modulesManager.invokeEvent(new ClientExitPhase(code)); + try { + System.exit(code); + } catch (Exception e) //Forge Security Manager? + { + NativeJVMHalt.haltA(code); + } + + } + public static void main(String... args) throws Throwable { JVMHelper.checkStackTrace(LauncherEngine.class); JVMHelper.verifySystemProperties(Launcher.class, true); @@ -84,7 +100,7 @@ public static void main(String... args) throws Throwable { LogHelper.debug("Launcher started in %dms", endTime - startTime); //Request.service.close(); //FunctionalBridge.close(); - System.exit(0); + SystemService.exit(0); } public static void initGson(ClientModuleManager modulesManager) { diff --git a/Launcher/src/main/java/pro/gravit/launcher/api/AuthService.java b/Launcher/src/main/java/pro/gravit/launcher/api/AuthService.java index 009b99cf..b6e08d02 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/api/AuthService.java +++ b/Launcher/src/main/java/pro/gravit/launcher/api/AuthService.java @@ -1,6 +1,7 @@ package pro.gravit.launcher.api; import pro.gravit.launcher.ClientPermissions; +import pro.gravit.launcher.profiles.ClientProfile; import java.util.UUID; @@ -8,6 +9,7 @@ public class AuthService { public static String username; public static ClientPermissions permissions = new ClientPermissions(); public static UUID uuid; + public static ClientProfile profile; public static boolean isAdmin() { return permissions.canAdmin; diff --git a/Launcher/src/main/java/pro/gravit/launcher/api/SystemService.java b/Launcher/src/main/java/pro/gravit/launcher/api/SystemService.java new file mode 100644 index 00000000..170cfaf4 --- /dev/null +++ b/Launcher/src/main/java/pro/gravit/launcher/api/SystemService.java @@ -0,0 +1,25 @@ +package pro.gravit.launcher.api; + +import pro.gravit.launcher.LauncherEngine; +import pro.gravit.launcher.profiles.ClientProfile; +import pro.gravit.utils.helper.LogHelper; + +public class SystemService { + private SystemService() { + throw new UnsupportedOperationException(); + } + public static void exit(int code) + { + LauncherEngine.exitLauncher(code); + } + public static void setSecurityManager(SecurityManager s) + { + LogHelper.debug("Try set security manager %s", s == null ? "null" : s.getClass().getName()); + if(AuthService.profile == null || AuthService.profile.securityManagerConfig == ClientProfile.SecurityManagerConfig.NONE) return; + if(AuthService.profile.securityManagerConfig == ClientProfile.SecurityManagerConfig.CLIENT) + { + System.setSecurityManager(s); + } + //TODO NEXT + } +} diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index 046ebf9c..9fe5a32e 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -463,6 +463,7 @@ public static void main(String... args) throws Throwable { HashedDir assetHDir = p.assetHDir, clientHDir = p.clientHDir; ClientLaunchContext context = new ClientLaunchContext(params, profile, assetHDir, clientHDir); Launcher.profile = profile; + AuthService.profile = profile; playerProfile = params.pp; Request.setSession(params.session); checkJVMBitsAndVersion(); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientExitPhase.java b/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientExitPhase.java new file mode 100644 index 00000000..230ea6d8 --- /dev/null +++ b/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientExitPhase.java @@ -0,0 +1,11 @@ +package pro.gravit.launcher.client.events; + +import pro.gravit.launcher.modules.events.ClosePhase; + +public class ClientExitPhase extends ClosePhase { + public final int code; + + public ClientExitPhase(int code) { + this.code = code; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java index 92435b5a..b5200379 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java @@ -69,6 +69,14 @@ public String toString() { } public static final boolean profileCaseSensitive = Boolean.getBoolean("launcher.clientProfile.caseSensitive"); + public enum SecurityManagerConfig + { + NONE, CLIENT, LAUNCHER, MIXED + } + public enum ClassLoaderConfig + { + AGENT, LAUNCHER + } private static final FileNameMatcher ASSET_MATCHER = new FileNameMatcher( new String[0], new String[]{"indexes", "objects"}, new String[0]); @@ -122,6 +130,10 @@ public String toString() { private final List clientArgs = new ArrayList<>(); @LauncherNetworkAPI private final List whitelist = new ArrayList<>(); + @LauncherNetworkAPI + public SecurityManagerConfig securityManagerConfig = SecurityManagerConfig.CLIENT; + @LauncherNetworkAPI + public ClassLoaderConfig classLoaderConfig = ClassLoaderConfig.LAUNCHER; @Override public int compareTo(ClientProfile o) { From dcf9a56c010dc34ea16baaa25afbc4a9c48c337f Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Tue, 17 Dec 2019 06:46:55 +0100 Subject: [PATCH 127/192] =?UTF-8?q?[ANY]=20=D0=A0=D0=B5=D1=84=D0=B0=D0=BA?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=B8=D0=BD=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../binary/tasks/CertificateAutogenTask.java | 1 - .../pro/gravit/launcher/LauncherEngine.java | 3 +-- .../gravit/launcher/NewLauncherSettings.java | 1 - .../launcher/client/ClientLauncher.java | 2 -- .../client/LauncherUpdateController.java | 5 +---- .../modules/impl/SimpleModuleManager.java | 1 - .../pro/gravit/launcher/request/Request.java | 1 - .../websockets/ClientWebSocketService.java | 1 - .../websockets/StdWebSocketService.java | 6 ++++-- .../pro/gravit/launcher/AsyncDownloader.java | 21 +++++++++++++------ .../java/pro/gravit/launcher/HTTPRequest.java | 2 -- modules | 2 +- 12 files changed, 22 insertions(+), 24 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/CertificateAutogenTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/CertificateAutogenTask.java index 5301903c..e26cd640 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/CertificateAutogenTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/CertificateAutogenTask.java @@ -1,6 +1,5 @@ package pro.gravit.launchserver.binary.tasks; -import org.bouncycastle.asn1.ASN1ObjectIdentifier; import org.bouncycastle.asn1.x500.X500Name; import org.bouncycastle.asn1.x500.X500NameBuilder; import org.bouncycastle.asn1.x500.style.BCStyle; diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index f2c2421e..e9c9a0e8 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -12,7 +12,6 @@ import pro.gravit.launcher.managers.ClientGsonManager; import pro.gravit.launcher.managers.ClientHookManager; import pro.gravit.launcher.managers.ConsoleManager; -import pro.gravit.launcher.modules.events.ClosePhase; import pro.gravit.launcher.modules.events.PreConfigPhase; import pro.gravit.launcher.request.Request; import pro.gravit.launcher.request.RequestException; @@ -88,7 +87,7 @@ public static void main(String... args) throws Throwable { ConsoleManager.initConsole(); HWIDProvider.registerHWIDs(); LauncherEngine.modulesManager.invokeEvent(new PreConfigPhase()); - LauncherConfig config = Launcher.getConfig(); + Launcher.getConfig(); // init config long startTime = System.currentTimeMillis(); try { new LauncherEngine().start(args); diff --git a/Launcher/src/main/java/pro/gravit/launcher/NewLauncherSettings.java b/Launcher/src/main/java/pro/gravit/launcher/NewLauncherSettings.java index f95be120..1c78e9c9 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/NewLauncherSettings.java +++ b/Launcher/src/main/java/pro/gravit/launcher/NewLauncherSettings.java @@ -2,7 +2,6 @@ import pro.gravit.launcher.client.UserSettings; import pro.gravit.launcher.hasher.HashedDir; -import pro.gravit.launcher.profiles.ClientProfile; import java.nio.file.Path; import java.util.*; diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index 9fe5a32e..2905bfd2 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -22,8 +22,6 @@ import pro.gravit.launcher.serialize.HOutput; import pro.gravit.launcher.serialize.stream.StreamObject; import pro.gravit.launcher.utils.DirWatcher; -import pro.gravit.launcher.utils.NativeJVMHalt; -import pro.gravit.utils.PublicURLClassLoader; import pro.gravit.utils.Version; import pro.gravit.utils.helper.*; import pro.gravit.utils.helper.JVMHelper.OS; diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java b/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java index 599dc121..74ebd59a 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java @@ -5,18 +5,15 @@ import pro.gravit.launcher.hasher.HashedDir; import pro.gravit.launcher.hasher.HashedEntry; import pro.gravit.launcher.hasher.HashedFile; -import pro.gravit.launcher.managers.SettingsManager; import pro.gravit.launcher.request.update.UpdateRequest; -import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; import java.io.File; import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.concurrent.atomic.AtomicReference; + @Deprecated public class LauncherUpdateController { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java index af9c68a8..6474c673 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java @@ -5,7 +5,6 @@ import pro.gravit.utils.PublicURLClassLoader; import pro.gravit.utils.Version; import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.LogHelper; import pro.gravit.launcher.LauncherTrustManager; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java index ecd9b17b..b941429a 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java @@ -46,7 +46,6 @@ public R request(StdWebSocketService service) throws Exception { return requestDo(service); } - @SuppressWarnings("unchecked") protected R requestDo(StdWebSocketService service) throws Exception { return service.requestSync(this); } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java index 45cac23c..5b896a35 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java @@ -20,7 +20,6 @@ import java.lang.reflect.Type; import java.net.URI; import java.net.URISyntaxException; -import java.util.HashSet; public abstract class ClientWebSocketService extends ClientJSONPoint { public final Gson gson; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StdWebSocketService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StdWebSocketService.java index 21ba495d..dfb5eecf 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StdWebSocketService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StdWebSocketService.java @@ -18,7 +18,8 @@ import java.util.concurrent.ExecutionException; public class StdWebSocketService extends ClientWebSocketService { - private final ConcurrentHashMap futureMap = new ConcurrentHashMap<>(); + @SuppressWarnings("rawtypes") + private final ConcurrentHashMap futureMap = new ConcurrentHashMap<>(); private final HashSet eventHandlers = new HashSet<>(); public void registerEventHandler(EventHandler handler) { @@ -50,7 +51,8 @@ public void eventHandle(T webSocketEvent) { processEventHandlers(webSocketEvent); return; } - CompletableFuture future = futureMap.get(event.requestUUID); + @SuppressWarnings("rawtypes") + CompletableFuture future = futureMap.get(event.requestUUID); if(future != null) { if (event instanceof ErrorRequestEvent) { future.completeExceptionally(new RequestException(((ErrorRequestEvent) event).error)); diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/AsyncDownloader.java b/LauncherCore/src/main/java/pro/gravit/launcher/AsyncDownloader.java index a9707b2c..4a024f88 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/AsyncDownloader.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/AsyncDownloader.java @@ -17,12 +17,13 @@ import java.util.concurrent.Executor; public class AsyncDownloader { + public static final Callback IGNORE = (ignored) -> {}; public AsyncDownloader(Callback callback) { this.callback = callback; } public AsyncDownloader() { - callback = (ignored) -> {}; + callback = IGNORE; } @FunctionalInterface @@ -33,11 +34,18 @@ public interface Callback public final Callback callback; public static class SizedFile { - public final String path; + public final String urlPath, filePath; public final long size; public SizedFile(String path, long size) { - this.path = path; + this.urlPath = path; + this.filePath = path; + this.size = size; + } + + public SizedFile(String urlPath, String filePath, long size) { + this.urlPath = urlPath; + this.filePath = filePath; this.size = size; } } @@ -67,8 +75,8 @@ public void downloadListInOneThread(List files, String baseURL, Path String path = baseUri.getPath(); for(AsyncDownloader.SizedFile currentFile : files) { - URL url = new URI(scheme,host,path + currentFile.path, "", "").toURL(); - downloadFile(url, targetDir.resolve(currentFile.path), currentFile.size); + URL url = new URI(scheme, host, path + currentFile.urlPath, "", "").toURL(); + downloadFile(url, targetDir.resolve(currentFile.filePath), currentFile.size); } } public List> sortFiles(List files, int threads) @@ -90,7 +98,8 @@ public List> sortFiles(List files, int threads) return result; } - public CompletableFuture[] runDownloadList(List> files, String baseURL, Path targetDir, Executor executor) { + @SuppressWarnings("rawtypes") + public CompletableFuture[] runDownloadList(List> files, String baseURL, Path targetDir, Executor executor) { int threads = files.size(); CompletableFuture[] futures = new CompletableFuture[threads]; for(int i=0;i Date: Tue, 17 Dec 2019 06:52:53 +0100 Subject: [PATCH 128/192] =?UTF-8?q?[FIX]=20=D0=92=D1=8B=D0=B2=D0=BE=D0=B4?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=B1=D0=BE=D0=BB=D1=8C=D1=88=D0=B5=20=D0=B2?= =?UTF-8?q?=D0=B0=D1=80=D0=BD=D0=B8=D0=BD=D0=B3=D0=BE=D0=B2=20=D0=B2=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BD=D1=81=D0=BE=D0=BB=D1=8C=20=D0=BF=D1=80=D0=B8?= =?UTF-8?q?=20=D1=81=D0=B1=D0=BE=D1=80=D0=BA=D0=B5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index d40d113b..e1c5c020 100644 --- a/build.gradle +++ b/build.gradle @@ -32,6 +32,7 @@ tasks.withType(JavaCompile) { options.encoding = "UTF-8" + options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" options.annotationProcessorPath = configurations.aptOnly options.incremental = true // one flag, and things will get MUCH faster } From 53c8a548f013490a9fe7a035373e27aa24dcf3d0 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Tue, 17 Dec 2019 06:56:37 +0100 Subject: [PATCH 129/192] =?UTF-8?q?[ANY]=20=D0=9D=D0=B5=D0=B1=D0=BE=D0=BB?= =?UTF-8?q?=D1=8C=D1=88=D0=BE=D0=B9=20=D1=80=D0=B5=D1=84=D0=B0=D0=BA=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=B8=D0=BD=D0=B3=20=D0=B2=20=D0=BA=D0=BE=D0=BD?= =?UTF-8?q?=D1=84=D0=B8=D0=B3=D0=B0=D1=85.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/pro/gravit/launcher/config/SimpleConfig.java | 9 ++++++--- .../pro/gravit/launcher/config/SimpleConfigurable.java | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfig.java b/LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfig.java index 507376d0..1dd9d94f 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfig.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfig.java @@ -1,5 +1,7 @@ package pro.gravit.launcher.config; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; import java.lang.reflect.Type; import java.nio.file.Path; @@ -18,11 +20,12 @@ public T getConfig() { return (T) this; } - @Override + @SuppressWarnings("unchecked") + @Override public T getDefaultConfig() { try { - return type.newInstance(); - } catch (InstantiationException | IllegalAccessException e) { + return (T) MethodHandles.publicLookup().findConstructor(type, MethodType.methodType(void.class)).invokeWithArguments(); + } catch (Throwable e) { return null; } } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfigurable.java b/LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfigurable.java index 5027e9eb..347dabd9 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfigurable.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfigurable.java @@ -1,5 +1,7 @@ package pro.gravit.launcher.config; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; import java.nio.file.Path; public class SimpleConfigurable extends JsonConfigurable { @@ -16,11 +18,12 @@ public T getConfig() { return config; } - @Override + @SuppressWarnings("unchecked") + @Override public T getDefaultConfig() { try { - return tClass.newInstance(); - } catch (InstantiationException | IllegalAccessException e) { + return (T) MethodHandles.publicLookup().findConstructor(tClass, MethodType.methodType(void.class)).invokeWithArguments(); + } catch (Throwable e) { return null; } } From a03bc919a0ad99209f8a6c57de4d02e77e0f8189 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Tue, 17 Dec 2019 13:37:08 +0100 Subject: [PATCH 130/192] =?UTF-8?q?[FIX]=20=D0=9F=D0=BE=D0=B4=D0=B4=D0=B5?= =?UTF-8?q?=D1=80=D0=B6=D0=BA=D0=B0=20=D0=BF=D0=B8=D0=BD=D0=B3=D0=B0=201.1?= =?UTF-8?q?5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/pro/gravit/launcher/profiles/ClientProfile.java | 3 ++- modules | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java index b5200379..d60a77f4 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java @@ -39,7 +39,8 @@ public enum Version { MC1141("1.14.1", 480), MC1142("1.14.2", 485), MC1143("1.14.3", 490), - MC1144("1.14.4", 498); + MC1144("1.14.4", 498), + MC115("1.15", 573); private static final Map VERSIONS; static { diff --git a/modules b/modules index c3ce7d13..f9d3362b 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit c3ce7d13bf9b31a6121b35198059d7289f855d0f +Subproject commit f9d3362bc3e354a32765871265b1e564d62909d5 From 011da08dc80b9a0831e7c98e8fbb3d06e66885ac Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Tue, 17 Dec 2019 15:40:23 +0100 Subject: [PATCH 131/192] =?UTF-8?q?[ANY]=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B8?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index f9d3362b..9a7a7bcf 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit f9d3362bc3e354a32765871265b1e564d62909d5 +Subproject commit 9a7a7bcf969179364d963336ccb77d6d9ddeb04f From c6dad02c9b13c0a716f5417f7a994960bc83adb1 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Tue, 17 Dec 2019 15:47:08 +0100 Subject: [PATCH 132/192] =?UTF-8?q?[ANY]=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B8?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index 9a7a7bcf..a3c8661d 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 9a7a7bcf969179364d963336ccb77d6d9ddeb04f +Subproject commit a3c8661d7e6f2af4fc64748945aec73dc55e0a7b From c6e6dd672f13b8b7b8877992fe163459bda57fdd Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Wed, 18 Dec 2019 17:02:56 +0100 Subject: [PATCH 133/192] =?UTF-8?q?[FIX]=20=D0=95=D1=89=D1=91=201=20=D1=81?= =?UTF-8?q?=D0=BF=D0=BE=D1=81=D0=BE=D0=B1=20=D0=BF=D1=80=D0=B8=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA=D0=B5=20=D0=B3=D1=80=D1=83?= =?UTF-8?q?=D0=BF=D0=BF=D1=8B=20URL=20(=D0=B2=20=D0=BE=D1=81=D0=BD=D0=BE?= =?UTF-8?q?=D0=B2=D0=BD=D0=BE=D0=BC=20=D0=B4=D0=BB=D1=8F=20=D0=BC=D0=BE?= =?UTF-8?q?=D0=B4=D1=83=D0=BB=D0=B5=D0=B9).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launcher/AsyncDownloader.java | 25 +++++++++++++++++++ modules | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/AsyncDownloader.java b/LauncherCore/src/main/java/pro/gravit/launcher/AsyncDownloader.java index 4a024f88..7cf0d447 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/AsyncDownloader.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/AsyncDownloader.java @@ -79,6 +79,13 @@ public void downloadListInOneThread(List files, String baseURL, Path downloadFile(url, targetDir.resolve(currentFile.filePath), currentFile.size); } } + public void downloadListInOneThreadSimple(List files, String baseURL, Path targetDir) throws URISyntaxException, IOException { + + for(AsyncDownloader.SizedFile currentFile : files) + { + downloadFile(new URL(baseURL + currentFile.urlPath), targetDir.resolve(currentFile.filePath), currentFile.size); + } + } public List> sortFiles(List files, int threads) { files.sort(Comparator.comparingLong((f) -> -f.size)); @@ -116,6 +123,24 @@ public CompletableFuture[] runDownloadList(List> files, String b return futures; } + @SuppressWarnings("rawtypes") + public CompletableFuture[] runDownloadListSimple(List> files, String baseURL, Path targetDir, Executor executor) { + int threads = files.size(); + CompletableFuture[] futures = new CompletableFuture[threads]; + for(int i=0;i currentTasks = files.get(i); + futures[i] = CompletableFuture.runAsync(() -> { + try { + downloadListInOneThreadSimple(currentTasks, baseURL, targetDir); + } catch (URISyntaxException | IOException e) { + throw new CompletionException(e); + } + }, executor); + } + return futures; + } + public void transfer(InputStream input, Path file, long size) throws IOException { try (OutputStream fileOutput = IOHelper.newOutput(file)) { long downloaded = 0L; diff --git a/modules b/modules index a3c8661d..dd140777 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit a3c8661d7e6f2af4fc64748945aec73dc55e0a7b +Subproject commit dd140777b7b27989a9e40b31590ca5345a963970 From 6f22ae3c7d01282f070faca80343332a512696ef Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Wed, 18 Dec 2019 17:16:48 +0100 Subject: [PATCH 134/192] =?UTF-8?q?[ANY]=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index dd140777..7880dc90 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit dd140777b7b27989a9e40b31590ca5345a963970 +Subproject commit 7880dc902b5354f055ef9a01d17cae17ba3fc9fc From f4dcd996396ac5e20c10552eb411a4182c18b446 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Wed, 18 Dec 2019 17:24:07 +0100 Subject: [PATCH 135/192] =?UTF-8?q?[FIX]=20=D0=98=D0=B3=D0=BD=D0=BE=D1=80?= =?UTF-8?q?=D0=B8=D1=80=D1=83=D0=B5=D0=BC=20Overflow=20(=D0=B2=D0=BE=D0=B7?= =?UTF-8?q?=D0=BC=D0=BE=D0=B6=D0=B5=D0=BD=20=D0=BD=D0=B0=20=D1=82=D1=8F?= =?UTF-8?q?=D0=B6=D1=91=D0=BB=D1=8B=D1=85=20=D1=81=D0=B1=D0=BE=D1=80=D0=BA?= =?UTF-8?q?=D0=B0=D1=85).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/pro/gravit/launcher/ClientLauncherWrapper.java | 2 ++ .../java/pro/gravit/launcher/client/ClientLauncher.java | 1 + .../pro/gravit/launcher/client/ClientProcessBuilder.java | 2 ++ .../src/main/java/pro/gravit/launcher/utils/DirWatcher.java | 6 ++++-- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java b/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java index 6ea83190..6e3cf58b 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java +++ b/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java @@ -3,6 +3,7 @@ import pro.gravit.launcher.client.ClientLauncher; import pro.gravit.launcher.client.ClientModuleManager; import pro.gravit.launcher.client.DirBridge; +import pro.gravit.launcher.utils.DirWatcher; import pro.gravit.utils.helper.EnvHelper; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.JVMHelper; @@ -59,6 +60,7 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep JVMHelper.addSystemPropertyToArgs(args, DirBridge.CUSTOMDIR_PROPERTY); JVMHelper.addSystemPropertyToArgs(args, DirBridge.USE_CUSTOMDIR_PROPERTY); JVMHelper.addSystemPropertyToArgs(args, DirBridge.USE_OPTDIR_PROPERTY); + JVMHelper.addSystemPropertyToArgs(args, DirWatcher.IGN_OVERFLOW); if (!noJava9check && !System.getProperty("java.version").startsWith("1.8")) { LogHelper.debug("Found Java 9+ ( %s )", System.getProperty("java.version")); args.add("--add-modules"); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index 2905bfd2..8a3fab23 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -351,6 +351,7 @@ public static Process launch( JVMHelper.addSystemPropertyToArgs(context.args, DirBridge.CUSTOMDIR_PROPERTY); JVMHelper.addSystemPropertyToArgs(context.args, DirBridge.USE_CUSTOMDIR_PROPERTY); JVMHelper.addSystemPropertyToArgs(context.args, DirBridge.USE_OPTDIR_PROPERTY); + JVMHelper.addSystemPropertyToArgs(context.args, DirWatcher.IGN_OVERFLOW); if (JVMHelper.OS_TYPE == OS.MUSTDIE) { if (JVMHelper.OS_VERSION.startsWith("10.")) { LogHelper.debug("MustDie 10 fix is applied"); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientProcessBuilder.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientProcessBuilder.java index c51b3938..0d579e7e 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientProcessBuilder.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientProcessBuilder.java @@ -5,6 +5,7 @@ import pro.gravit.launcher.hasher.HashedDir; import pro.gravit.launcher.managers.ClientHookManager; import pro.gravit.launcher.profiles.ClientProfile; +import pro.gravit.launcher.utils.DirWatcher; import pro.gravit.utils.helper.EnvHelper; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.JVMHelper; @@ -99,6 +100,7 @@ public ClientLauncherContext build() throws IOException { JVMHelper.addSystemPropertyToArgs(context.args, DirBridge.CUSTOMDIR_PROPERTY); JVMHelper.addSystemPropertyToArgs(context.args, DirBridge.USE_CUSTOMDIR_PROPERTY); JVMHelper.addSystemPropertyToArgs(context.args, DirBridge.USE_OPTDIR_PROPERTY); + JVMHelper.addSystemPropertyToArgs(context.args, DirWatcher.IGN_OVERFLOW); if (JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) { if (JVMHelper.OS_VERSION.startsWith("10.")) { LogHelper.debug("MustDie 10 fix is applied"); diff --git a/Launcher/src/main/java/pro/gravit/launcher/utils/DirWatcher.java b/Launcher/src/main/java/pro/gravit/launcher/utils/DirWatcher.java index ea0edbbf..a9590784 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/utils/DirWatcher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/utils/DirWatcher.java @@ -46,6 +46,9 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) th StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_DELETE }; + public static final String IGN_OVERFLOW = "launcher.dirwatcher.ignoreOverflows"; + private static final boolean PROP_IGN_OVERFLOW = Boolean.getBoolean(IGN_OVERFLOW); + private static void handleError(Throwable e) { LogHelper.error(e); NativeJVMHalt.haltA(-123); @@ -82,7 +85,6 @@ public DirWatcher(Path dir, HashedDir hdir, FileNameMatcher matcher, boolean dig } @Override - public void close() throws IOException { service.close(); } @@ -92,7 +94,7 @@ private void processKey(WatchKey key) throws IOException { for (WatchEvent event : key.pollEvents()) { Kind kind = event.kind(); if (kind.equals(StandardWatchEventKinds.OVERFLOW)) { - if (Boolean.getBoolean("launcher.dirwatcher.ignoreOverflows")) + if (PROP_IGN_OVERFLOW) continue; // Sometimes it's better to ignore than interrupt fair playing throw new IOException("Overflow"); } From 1e169ce55beac3c3bed8169864c96afe59de28d9 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Wed, 18 Dec 2019 20:01:38 +0100 Subject: [PATCH 136/192] =?UTF-8?q?[FIX]=20=D0=94=D0=B5=D1=84=D0=BE=D0=BB?= =?UTF-8?q?=D1=82=D0=BD=D0=BE=D0=B5=20=D0=B7=D0=BD=D0=B0=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20IGN=5FOVERFLOW.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/pro/gravit/launcher/utils/DirWatcher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Launcher/src/main/java/pro/gravit/launcher/utils/DirWatcher.java b/Launcher/src/main/java/pro/gravit/launcher/utils/DirWatcher.java index a9590784..37bc16fe 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/utils/DirWatcher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/utils/DirWatcher.java @@ -47,7 +47,7 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) th }; public static final String IGN_OVERFLOW = "launcher.dirwatcher.ignoreOverflows"; - private static final boolean PROP_IGN_OVERFLOW = Boolean.getBoolean(IGN_OVERFLOW); + private static final boolean PROP_IGN_OVERFLOW = Boolean.parseBoolean(System.getProperty(IGN_OVERFLOW, "true")); private static void handleError(Throwable e) { LogHelper.error(e); From b617e58a4c6ecf91791c52c957a456f4b88d6d60 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Thu, 19 Dec 2019 05:50:49 +0100 Subject: [PATCH 137/192] =?UTF-8?q?[ANY]=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B8?= =?UTF-8?q?=20[FEATURE]=20Sentry=20=D0=B8=D0=BD=D1=82=D0=B5=D0=B3=D1=80?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index 7880dc90..cad636fe 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 7880dc902b5354f055ef9a01d17cae17ba3fc9fc +Subproject commit cad636fe12143a3a89c1c7cbe2a6fac2f0608345 From decd3a8d049194d371360d15058c9b63d43df91d Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Thu, 19 Dec 2019 06:33:03 +0100 Subject: [PATCH 138/192] =?UTF-8?q?[ANY]=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B8?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index cad636fe..12cb8354 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit cad636fe12143a3a89c1c7cbe2a6fac2f0608345 +Subproject commit 12cb835489667b39453e874f43bd314a67f0719e From 5e923ec479669f90b80ec40664044fdeba643809 Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 23 Dec 2019 11:13:50 +0700 Subject: [PATCH 139/192] [FIX] GitLab CI --- .gitlab-ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 49de251e..b38f1740 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -30,6 +30,8 @@ build: - mv LaunchServer.jar ../../../artifacts/LaunchServer.jar - cd ../../../ServerWrapper/build/libs - mv ServerWrapper.jar ../../../artifacts/ServerWrapper.jar + - cd ../../../LauncherAuthlib/build/libs + - mv LauncherAuthlib.jar ../../../artifacts/LauncherAuthlib.jar - cd ../../../ - mv modules/*_module/build/libs/*.jar artifacts/modules - mv modules/*_swmodule/build/libs/*.jar artifacts/modules From 284f550a9f3ece2579b7fe69c12b9026fe0d3211 Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 23 Dec 2019 11:18:50 +0700 Subject: [PATCH 140/192] [FIX] CertificateAutogenTask --- .../launchserver/binary/tasks/CertificateAutogenTask.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/CertificateAutogenTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/CertificateAutogenTask.java index e26cd640..400d22da 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/CertificateAutogenTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/CertificateAutogenTask.java @@ -3,8 +3,7 @@ import org.bouncycastle.asn1.x500.X500Name; import org.bouncycastle.asn1.x500.X500NameBuilder; import org.bouncycastle.asn1.x500.style.BCStyle; -import org.bouncycastle.asn1.x509.Extension; -import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; +import org.bouncycastle.asn1.x509.*; import org.bouncycastle.cert.X509CertificateHolder; import org.bouncycastle.cert.X509v3CertificateBuilder; import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter; @@ -59,7 +58,8 @@ public Path process(Path inputFile) throws IOException { Date.from(startDate.plusDays(3650).atZone(ZoneId.systemDefault()).toInstant()), new X500Name("CN=ca"), SubjectPublicKeyInfo.getInstance(server.publicKey.getEncoded())); - builder.addExtension(Extension.getInstance("1.3.6.1.5.5.7.3.3")); + builder.addExtension(Extension.extendedKeyUsage, false, new ExtendedKeyUsage(KeyPurposeId.id_kp_codeSigning)); + builder.addExtension(Extension.keyUsage, false, new KeyUsage(1)); JcaContentSignerBuilder csBuilder = new JcaContentSignerBuilder("SHA256WITHECDSA"); ContentSigner signer = csBuilder.build(server.privateKey); bcCertificate = builder.build(signer); From f0ca39cde9e5589e6e4456d13f2ca5c97a6b0cbc Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Thu, 2 Jan 2020 10:37:33 +0300 Subject: [PATCH 141/192] =?UTF-8?q?[ANY]=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B8?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index 12cb8354..9cb09c54 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 12cb835489667b39453e874f43bd314a67f0719e +Subproject commit 9cb09c549abea86348597137e05a0ec29bc36b62 From 43e1533c872d716cc08dde531172f2e92e67504a Mon Sep 17 00:00:00 2001 From: Gravit Gravit Date: Thu, 2 Jan 2020 22:41:05 +0700 Subject: [PATCH 142/192] [FEATURE][EXPERIMENTAL] New Hibernate DAO --- .../auth/handler/HibernateAuthHandler.java | 18 ++-- .../HibernatePermissionsHandler.java | 6 +- .../auth/provider/HibernateAuthProvider.java | 2 +- .../command/dao/GetAllUsersCommand.java | 4 +- .../command/dao/GetUserCommand.java | 4 +- .../command/dao/RegisterCommand.java | 6 +- .../command/dao/SetUserPasswordCommand.java | 6 +- .../pro/gravit/launchserver/dao/HwidDAO.java | 19 ++++ .../pro/gravit/launchserver/dao/User.java | 76 +++----------- .../pro/gravit/launchserver/dao/UserDAO.java | 4 +- .../pro/gravit/launchserver/dao/UserHWID.java | 61 +----------- .../gravit/launchserver/dao/UserService.java | 51 ---------- .../dao/impl/DefaultUserDAOImpl.java | 56 ----------- .../dao/impl/HibernateHwidDAOImpl.java | 83 ++++++++++++++++ .../dao/impl/HibernateUserDAOImpl.java | 42 +++----- .../launchserver/dao/impl/UserHWIDImpl.java | 44 +++++++++ .../dao/impl/UserHibernateImpl.java | 99 +++++++++++++++++++ .../dao/provider/DaoProvider.java | 4 +- .../dao/provider/HibernateDaoProvider.java | 17 ++-- .../response/auth/RegisterResponse.java | 7 +- .../response/auth/SetPasswordResponse.java | 4 +- modules | 2 +- 22 files changed, 314 insertions(+), 301 deletions(-) create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/dao/HwidDAO.java delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserService.java delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/DefaultUserDAOImpl.java create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/HibernateHwidDAOImpl.java create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/UserHWIDImpl.java create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/UserHibernateImpl.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/HibernateAuthHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/HibernateAuthHandler.java index 6f688c0b..021eb3c3 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/HibernateAuthHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/HibernateAuthHandler.java @@ -7,31 +7,31 @@ public class HibernateAuthHandler extends CachedAuthHandler { @Override protected Entry fetchEntry(String username) { - User user = srv.config.dao.userService.findUserByUsername(username); + User user = srv.config.dao.userDAO.findByUsername(username); if (user == null) return null; - return new Entry(user.uuid, username, user.getAccessToken(), user.serverID); + return new Entry(user.getUuid(), username, user.getAccessToken(), user.getServerID()); } @Override protected Entry fetchEntry(UUID uuid) { - User user = srv.config.dao.userService.findUserByUUID(uuid); + User user = srv.config.dao.userDAO.findByUUID(uuid); if (user == null) return null; - return new Entry(user.uuid, user.username, user.getAccessToken(), user.serverID); + return new Entry(user.getUuid(), user.getUsername(), user.getAccessToken(), user.getServerID()); } @Override protected boolean updateAuth(UUID uuid, String username, String accessToken) { - User user = srv.config.dao.userService.findUserByUUID(uuid); + User user = srv.config.dao.userDAO.findByUUID(uuid); user.setAccessToken(accessToken); - srv.config.dao.userService.updateUser(user); + srv.config.dao.userDAO.update(user); return true; } @Override protected boolean updateServerID(UUID uuid, String serverID) { - User user = srv.config.dao.userService.findUserByUUID(uuid); - user.serverID = serverID; - srv.config.dao.userService.updateUser(user); + User user = srv.config.dao.userDAO.findByUUID(uuid); + user.setServerID(serverID); + srv.config.dao.userDAO.update(user); return true; } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/HibernatePermissionsHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/HibernatePermissionsHandler.java index 2cb030a2..15702db5 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/HibernatePermissionsHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/HibernatePermissionsHandler.java @@ -7,17 +7,17 @@ public class HibernatePermissionsHandler extends PermissionsHandler { @Override public ClientPermissions getPermissions(String username) { - User user = srv.config.dao.userService.findUserByUsername(username); + User user = srv.config.dao.userDAO.findByUsername(username); if (user == null) return ClientPermissions.DEFAULT; return user.getPermissions(); } @Override public void setPermissions(String username, ClientPermissions permissions) { - User user = srv.config.dao.userService.findUserByUsername(username); + User user = srv.config.dao.userDAO.findByUsername(username); if (user == null) return; user.setPermissions(permissions); - srv.config.dao.userService.updateUser(user); + srv.config.dao.userDAO.update(user); } @Override diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/HibernateAuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/HibernateAuthProvider.java index 89587633..4f041d98 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/HibernateAuthProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/HibernateAuthProvider.java @@ -13,7 +13,7 @@ public class HibernateAuthProvider extends AuthProvider { @Override public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface password, String ip) throws Exception { if (!(password instanceof AuthPlainPassword)) throw new AuthException("This password type not supported"); - User user = srv.config.dao.userService.findUserByUsername(login); + User user = srv.config.dao.userDAO.findByUsername(login); if (user == null && autoReg) { AuthHookManager.RegContext context = new AuthHookManager.RegContext(login, ((AuthPlainPassword) password).password, ip, false); if (srv.authHookManager.registraion.hook(context)) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/GetAllUsersCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/GetAllUsersCommand.java index bfb6cf59..0cf91d4d 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/GetAllUsersCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/GetAllUsersCommand.java @@ -23,8 +23,8 @@ public String getUsageDescription() { @Override public void invoke(String... args) { int count = 0; - for (User user : server.config.dao.userService.findAllUsers()) { - LogHelper.subInfo("[%s] UUID: %s", user.username, user.uuid.toString()); + for (User user : server.config.dao.userDAO.findAll()) { + LogHelper.subInfo("[%s] UUID: %s", user.getUsername(), user.getUuid().toString()); count++; } LogHelper.info("Print %d users", count); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/GetUserCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/GetUserCommand.java index 7b0ae432..3fe4fb1a 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/GetUserCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/GetUserCommand.java @@ -23,12 +23,12 @@ public String getUsageDescription() { @Override public void invoke(String... args) throws Exception { verifyArgs(args, 1); - User user = server.config.dao.userService.findUserByUsername(args[0]); + User user = server.config.dao.userDAO.findByUsername(args[0]); if (user == null) { LogHelper.error("User %s not found", args[0]); return; } - LogHelper.info("[%s] UUID: %s", user.username, user.uuid.toString()); + LogHelper.info("[%s] UUID: %s", user.getUsername(), user.getUuid().toString()); //for(UserHWID hwid : user.hwids) //{ // LogHelper.info("[%s] HWID: memory: %d | serial %s | hwdiskserial: %s | processorID %s | macAddr %s", user.username, hwid.totalMemory, hwid.serialNumber, hwid.HWDiskSerial, hwid.processorID, hwid.macAddr); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/RegisterCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/RegisterCommand.java index c970551a..7fabacc6 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/RegisterCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/RegisterCommand.java @@ -2,7 +2,7 @@ import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.command.Command; -import pro.gravit.launchserver.dao.User; +import pro.gravit.launchserver.dao.impl.UserHibernateImpl; import pro.gravit.utils.helper.LogHelper; import java.util.UUID; @@ -25,11 +25,11 @@ public String getUsageDescription() { @Override public void invoke(String... args) throws Exception { verifyArgs(args, 2); - User user = new User(); + UserHibernateImpl user = new UserHibernateImpl(); user.username = args[0]; user.setPassword(args[1]); user.uuid = UUID.randomUUID(); - server.config.dao.userService.saveUser(user); + server.config.dao.userDAO.save(user); LogHelper.info("User %s registered. UUID: %s", user.username, user.uuid.toString()); } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/SetUserPasswordCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/SetUserPasswordCommand.java index 8d0a6c47..d6a0a02e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/SetUserPasswordCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/SetUserPasswordCommand.java @@ -24,13 +24,13 @@ public String getUsageDescription() { @Override public void invoke(String... args) throws Exception { verifyArgs(args, 2); - User user = server.config.dao.userService.findUserByUsername(args[0]); + User user = server.config.dao.userDAO.findByUsername(args[0]); if (user == null) { LogHelper.error("User %s not found", args[1]); return; } user.setPassword(args[1]); - server.config.dao.userService.updateUser(user); - LogHelper.info("[%s] UUID: %s | New Password: %s", user.username, user.uuid.toString(), args[1]); + server.config.dao.userDAO.update(user); + LogHelper.info("[%s] UUID: %s | New Password: %s", user.getUsername(), user.getUuid().toString(), args[1]); } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/HwidDAO.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/HwidDAO.java new file mode 100644 index 00000000..9333d220 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/HwidDAO.java @@ -0,0 +1,19 @@ +package pro.gravit.launchserver.dao; + +import pro.gravit.launcher.hwid.HWID; + +import java.util.List; + +public interface HwidDAO { + UserHWID findById(long id); + + List findHWIDs(HWID hwid); + + void save(UserHWID user); + + void update(UserHWID user); + + void delete(UserHWID user); + + List findAll(); +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/User.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/User.java index 28da0d4c..23b1e900 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/User.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/User.java @@ -1,71 +1,19 @@ package pro.gravit.launchserver.dao; import pro.gravit.launcher.ClientPermissions; -import pro.gravit.utils.helper.LogHelper; -import pro.gravit.utils.helper.SecurityHelper; -import javax.persistence.*; -import java.nio.charset.StandardCharsets; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.Arrays; import java.util.UUID; -@Entity -@Table(name = "users") -public class User { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private long id; - @Column(unique = true) - public String username; - public String email; - @Column(unique = true) - public UUID uuid; - @Column(name = "password") - private byte[] password; - private String accessToken; - public String serverID; - private String password_salt; - public long permissions; - - public void setPassword(String password) { - password_salt = SecurityHelper.randomStringAESKey(); - MessageDigest digest; - try { - digest = MessageDigest.getInstance("SHA-256"); - } catch (NoSuchAlgorithmException e) { - LogHelper.error(e); - return; - } - this.password = digest.digest(password.concat(password_salt).getBytes(StandardCharsets.UTF_8)); - } - - public boolean verifyPassword(String password) { - MessageDigest digest; - try { - digest = MessageDigest.getInstance("SHA-256"); - } catch (NoSuchAlgorithmException e) { - LogHelper.error(e); - return false; - } - byte[] enpassword = digest.digest(password.concat(password_salt).getBytes(StandardCharsets.UTF_8)); - return Arrays.equals(enpassword, this.password); - } - - public ClientPermissions getPermissions() { - return new ClientPermissions(permissions); - } - - public void setPermissions(ClientPermissions permissions) { - this.permissions = permissions.toLong(); - } - - public String getAccessToken() { - return accessToken; - } - - public void setAccessToken(String accessToken) { - this.accessToken = accessToken; - } +public interface User { + String getUsername(); + ClientPermissions getPermissions(); + void setPermissions(ClientPermissions permissions); + boolean verifyPassword(String password); + void setPassword(String password); + String getAccessToken(); + void setAccessToken(String accessToken); + String getServerID(); + void setServerID(String serverID); + UUID getUuid(); + void setUuid(UUID uuid); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserDAO.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserDAO.java index 7a666c8f..85987e85 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserDAO.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserDAO.java @@ -1,6 +1,6 @@ package pro.gravit.launchserver.dao; -import pro.gravit.launcher.hwid.OshiHWID; +import pro.gravit.launcher.hwid.HWID; import java.util.List; import java.util.UUID; @@ -12,8 +12,6 @@ public interface UserDAO { User findByUUID(UUID uuid); - List findHWID(OshiHWID hwid); - void save(User user); void update(User user); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserHWID.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserHWID.java index 2c6fe8e3..da8f438c 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserHWID.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserHWID.java @@ -1,63 +1,8 @@ package pro.gravit.launchserver.dao; import pro.gravit.launcher.hwid.HWID; -import pro.gravit.launcher.hwid.OshiHWID; -import javax.persistence.*; -import java.util.function.Supplier; - -@Entity -@Table(name = "users_hwids") -public class UserHWID implements HWID { - private final transient Supplier oshiSupp = () -> { - OshiHWID hwid = new OshiHWID(); - hwid.HWDiskSerial = this.HWDiskSerial; - hwid.macAddr = this.macAddr; - hwid.processorID = this.processorID; - hwid.serialNumber = this.serialNumber; - hwid.totalMemory = this.totalMemory; - return hwid; - }; - private transient OshiHWID oshi = null; - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private long id; - - public final long totalMemory = 0; - public String serialNumber; - public String HWDiskSerial; - public String processorID; - public String macAddr; - - public boolean banned; - - public OshiHWID toHWID() { - if (oshi == null) oshi = oshiSupp.get(); - return oshi; - } - - @Override - public int getLevel() { - return toHWID().getLevel(); - } - - @Override - public int getAntiLevel() { - return 0; - } - - @Override - public int compare(HWID hwid) { - return toHWID().compare(hwid); - } - - @Override - public boolean isNull() { - return toHWID().isNull(); - } - - @Override - public void normalize() { - - } +public interface UserHWID { + boolean isBanned(); + HWID toHWID(); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserService.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserService.java deleted file mode 100644 index cdc7fb23..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserService.java +++ /dev/null @@ -1,51 +0,0 @@ -package pro.gravit.launchserver.dao; - -import java.util.List; -import java.util.UUID; - -public class UserService { - - private final UserDAO usersDao; - - public UserService(UserDAO usersDAO) { - this.usersDao = usersDAO; - } - - public User findUser(int id) { - return usersDao.findById(id); - } - - public User findUserByUsername(String username) { - return usersDao.findByUsername(username); - } - - public User findUserByUUID(UUID uuid) { - return usersDao.findByUUID(uuid); - } - - public User registerNewUser(String username, String password) { - User user = new User(); - user.username = username; - user.setPassword(password); - user.uuid = UUID.randomUUID(); - return user; - } - - public void saveUser(User user) { - usersDao.save(user); - } - - public void deleteUser(User user) { - usersDao.delete(user); - } - - public void updateUser(User user) { - usersDao.update(user); - } - - public List findAllUsers() { - return usersDao.findAll(); - } - - -} \ No newline at end of file diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/DefaultUserDAOImpl.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/DefaultUserDAOImpl.java deleted file mode 100644 index 0c2509e0..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/DefaultUserDAOImpl.java +++ /dev/null @@ -1,56 +0,0 @@ -package pro.gravit.launchserver.dao.impl; - -import pro.gravit.launcher.hwid.OshiHWID; -import pro.gravit.launchserver.LaunchServer; -import pro.gravit.launchserver.dao.User; -import pro.gravit.launchserver.dao.UserDAO; -import pro.gravit.launchserver.dao.UserHWID; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -public class DefaultUserDAOImpl implements UserDAO { - public DefaultUserDAOImpl(LaunchServer srv) { - } - - @Override - public User findById(int id) { - return null; - } - - @Override - public User findByUsername(String username) { - return null; - } - - @Override - public User findByUUID(UUID uuid) { - return null; - } - - @Override - public List findHWID(OshiHWID hwid) { - return new ArrayList<>(); - } - - @Override - public void save(User user) { - throw new UnsupportedOperationException(); - } - - @Override - public void update(User user) { - throw new UnsupportedOperationException(); - } - - @Override - public void delete(User user) { - throw new UnsupportedOperationException(); - } - - @Override - public List findAll() { - return new ArrayList<>(); - } -} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/HibernateHwidDAOImpl.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/HibernateHwidDAOImpl.java new file mode 100644 index 00000000..037e25cc --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/HibernateHwidDAOImpl.java @@ -0,0 +1,83 @@ +package pro.gravit.launchserver.dao.impl; + +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import pro.gravit.launcher.hwid.HWID; +import pro.gravit.launcher.hwid.OshiHWID; +import pro.gravit.launchserver.dao.HwidDAO; +import pro.gravit.launchserver.dao.User; +import pro.gravit.launchserver.dao.UserHWID; + +import javax.persistence.EntityManager; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import java.util.List; + +public class HibernateHwidDAOImpl implements HwidDAO { + private final SessionFactory factory; + + public HibernateHwidDAOImpl(SessionFactory factory) { + this.factory = factory; + } + + @Override + public List findHWIDs(HWID hwid) { + if(!(hwid instanceof OshiHWID)) throw new UnsupportedOperationException(); + OshiHWID oshiHWID = (OshiHWID) hwid; + EntityManager em = factory.createEntityManager(); + em.getTransaction().begin(); + CriteriaBuilder cb = em.getCriteriaBuilder(); + CriteriaQuery personCriteria = cb.createQuery(UserHWIDImpl.class); + Root rootUser = personCriteria.from(UserHWIDImpl.class); + personCriteria.select(rootUser).where( + cb.or( + cb.equal(rootUser.get("totalMemory"), oshiHWID.totalMemory), + cb.equal(rootUser.get("HWDiskSerial"), oshiHWID.HWDiskSerial), + cb.equal(rootUser.get("serialNumber"), oshiHWID.serialNumber), + cb.equal(rootUser.get("processorID"), oshiHWID.processorID), + cb.equal(rootUser.get("macAddr"), oshiHWID.macAddr) + ) + ); + List list = em.createQuery(personCriteria).getResultList(); + em.close(); + return list; + } + + public UserHWIDImpl findById(long id) { + try (Session s = factory.openSession()) { + return s.get(UserHWIDImpl.class, id); + } + } + public void save(UserHWID user) { + try (Session session = factory.openSession()) { + Transaction tx1 = session.beginTransaction(); + session.save(user); + tx1.commit(); + } + } + + public void update(UserHWID user) { + try (Session session = factory.openSession()) { + Transaction tx1 = session.beginTransaction(); + session.update(user); + tx1.commit(); + } + } + + public void delete(UserHWID user) { + try (Session session = factory.openSession()) { + Transaction tx1 = session.beginTransaction(); + session.delete(user); + tx1.commit(); + } + } + + @SuppressWarnings("unchecked") + public List findAll() { + try (Session s = factory.openSession()) { + return (List) s.createQuery("From user_hwids").list(); + } + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/HibernateUserDAOImpl.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/HibernateUserDAOImpl.java index a31e106e..03c8bd5a 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/HibernateUserDAOImpl.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/HibernateUserDAOImpl.java @@ -3,6 +3,7 @@ import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; +import pro.gravit.launcher.hwid.HWID; import pro.gravit.launcher.hwid.OshiHWID; import pro.gravit.launchserver.dao.User; import pro.gravit.launchserver.dao.UserDAO; @@ -22,57 +23,36 @@ public HibernateUserDAOImpl(SessionFactory factory) { this.factory = factory; } - public User findById(int id) { + public UserHibernateImpl findById(int id) { try (Session s = factory.openSession()) { - return s.get(User.class, id); + return s.get(UserHibernateImpl.class, id); } } - public User findByUsername(String username) { + public UserHibernateImpl findByUsername(String username) { EntityManager em = factory.createEntityManager(); em.getTransaction().begin(); CriteriaBuilder cb = em.getCriteriaBuilder(); - CriteriaQuery personCriteria = cb.createQuery(User.class); - Root rootUser = personCriteria.from(User.class); + CriteriaQuery personCriteria = cb.createQuery(UserHibernateImpl.class); + Root rootUser = personCriteria.from(UserHibernateImpl.class); personCriteria.select(rootUser).where(cb.equal(rootUser.get("username"), username)); - List ret = em.createQuery(personCriteria).getResultList(); + List ret = em.createQuery(personCriteria).getResultList(); em.close(); return ret.size() == 0 ? null : ret.get(0); } - public User findByUUID(UUID uuid) { + public UserHibernateImpl findByUUID(UUID uuid) { EntityManager em = factory.createEntityManager(); em.getTransaction().begin(); CriteriaBuilder cb = em.getCriteriaBuilder(); - CriteriaQuery personCriteria = cb.createQuery(User.class); - Root rootUser = personCriteria.from(User.class); + CriteriaQuery personCriteria = cb.createQuery(UserHibernateImpl.class); + Root rootUser = personCriteria.from(UserHibernateImpl.class); personCriteria.select(rootUser).where(cb.equal(rootUser.get("uuid"), uuid)); - List ret = em.createQuery(personCriteria).getResultList(); + List ret = em.createQuery(personCriteria).getResultList(); em.close(); return ret.size() == 0 ? null : ret.get(0); } - @Override - public List findHWID(OshiHWID hwid) { - EntityManager em = factory.createEntityManager(); - em.getTransaction().begin(); - CriteriaBuilder cb = em.getCriteriaBuilder(); - CriteriaQuery personCriteria = cb.createQuery(UserHWID.class); - Root rootUser = personCriteria.from(UserHWID.class); - personCriteria.select(rootUser).where( - cb.or( - cb.equal(rootUser.get("totalMemory"), hwid.totalMemory), - cb.equal(rootUser.get("HWDiskSerial"), hwid.HWDiskSerial), - cb.equal(rootUser.get("serialNumber"), hwid.serialNumber), - cb.equal(rootUser.get("processorID"), hwid.processorID), - cb.equal(rootUser.get("macAddr"), hwid.macAddr) - ) - ); - List ret = em.createQuery(personCriteria).getResultList(); - em.close(); - return ret; - } - public void save(User user) { try (Session session = factory.openSession()) { Transaction tx1 = session.beginTransaction(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/UserHWIDImpl.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/UserHWIDImpl.java new file mode 100644 index 00000000..7cc39c0e --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/UserHWIDImpl.java @@ -0,0 +1,44 @@ +package pro.gravit.launchserver.dao.impl; + +import pro.gravit.launcher.hwid.HWID; +import pro.gravit.launcher.hwid.OshiHWID; +import pro.gravit.launchserver.dao.UserHWID; + +import javax.persistence.*; +import java.util.function.Supplier; + +@Entity +@Table(name = "users_hwids") +public class UserHWIDImpl implements UserHWID { + private final transient Supplier oshiSupp = () -> { + OshiHWID hwid = new OshiHWID(); + hwid.HWDiskSerial = this.HWDiskSerial; + hwid.macAddr = this.macAddr; + hwid.processorID = this.processorID; + hwid.serialNumber = this.serialNumber; + hwid.totalMemory = this.totalMemory; + return hwid; + }; + private transient OshiHWID oshi = null; + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long id; + + public final long totalMemory = 0; + public String serialNumber; + public String HWDiskSerial; + public String processorID; + public String macAddr; + + public boolean banned; + + @Override + public boolean isBanned() { + return banned; + } + + public OshiHWID toHWID() { + if (oshi == null) oshi = oshiSupp.get(); + return oshi; + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/UserHibernateImpl.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/UserHibernateImpl.java new file mode 100644 index 00000000..6094d391 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/UserHibernateImpl.java @@ -0,0 +1,99 @@ +package pro.gravit.launchserver.dao.impl; + +import pro.gravit.launcher.ClientPermissions; +import pro.gravit.launchserver.dao.User; +import pro.gravit.utils.helper.LogHelper; +import pro.gravit.utils.helper.SecurityHelper; + +import javax.persistence.*; +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Arrays; +import java.util.UUID; + +@Entity +@Table(name = "users") +public class UserHibernateImpl implements User { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long id; + @Column(unique = true) + public String username; + public String email; + @Column(unique = true) + public UUID uuid; + @Column(name = "password") + private byte[] password; + private String accessToken; + public String serverID; + private String password_salt; + public long permissions; + + public void setPassword(String password) { + password_salt = SecurityHelper.randomStringAESKey(); + MessageDigest digest; + try { + digest = MessageDigest.getInstance("SHA-256"); + } catch (NoSuchAlgorithmException e) { + LogHelper.error(e); + return; + } + this.password = digest.digest(password.concat(password_salt).getBytes(StandardCharsets.UTF_8)); + } + + public boolean verifyPassword(String password) { + MessageDigest digest; + try { + digest = MessageDigest.getInstance("SHA-256"); + } catch (NoSuchAlgorithmException e) { + LogHelper.error(e); + return false; + } + byte[] enpassword = digest.digest(password.concat(password_salt).getBytes(StandardCharsets.UTF_8)); + return Arrays.equals(enpassword, this.password); + } + + public ClientPermissions getPermissions() { + return new ClientPermissions(permissions); + } + + public void setPermissions(ClientPermissions permissions) { + this.permissions = permissions.toLong(); + } + + public String getAccessToken() { + return accessToken; + } + + public void setAccessToken(String accessToken) { + this.accessToken = accessToken; + } + + @Override + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public UUID getUuid() { + return uuid; + } + + public void setUuid(UUID uuid) { + this.uuid = uuid; + } + + @Override + public String getServerID() { + return serverID; + } + + @Override + public void setServerID(String serverID) { + this.serverID = serverID; + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/provider/DaoProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/provider/DaoProvider.java index f794f720..927e9a6d 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/provider/DaoProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/provider/DaoProvider.java @@ -1,14 +1,14 @@ package pro.gravit.launchserver.dao.provider; import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launchserver.dao.HwidDAO; import pro.gravit.launchserver.dao.UserDAO; -import pro.gravit.launchserver.dao.UserService; import pro.gravit.utils.ProviderMap; public abstract class DaoProvider { public static final ProviderMap providers = new ProviderMap<>("DaoProvider"); public UserDAO userDAO; - public UserService userService; + public HwidDAO hwidDao; public static void registerProviders() { providers.register("hibernate", HibernateDaoProvider.class); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/provider/HibernateDaoProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/provider/HibernateDaoProvider.java index 82d9197f..7ca931bb 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/provider/HibernateDaoProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/provider/HibernateDaoProvider.java @@ -1,10 +1,11 @@ package pro.gravit.launchserver.dao.provider; +import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; import pro.gravit.launchserver.LaunchServer; -import pro.gravit.launchserver.dao.User; -import pro.gravit.launchserver.dao.UserHWID; -import pro.gravit.launchserver.dao.UserService; +import pro.gravit.launchserver.dao.impl.HibernateHwidDAOImpl; +import pro.gravit.launchserver.dao.impl.UserHibernateImpl; +import pro.gravit.launchserver.dao.impl.UserHWIDImpl; import pro.gravit.launchserver.dao.impl.HibernateUserDAOImpl; import pro.gravit.utils.helper.CommonHelper; @@ -19,13 +20,14 @@ public class HibernateDaoProvider extends DaoProvider { public String pool_size; public String hibernateConfig; public boolean parallelHibernateInit; + private transient SessionFactory sessionFactory; @Override public void init(LaunchServer server) { Runnable init = () -> { Configuration cfg = new Configuration() - .addAnnotatedClass(User.class) - .addAnnotatedClass(UserHWID.class) + .addAnnotatedClass(UserHibernateImpl.class) + .addAnnotatedClass(UserHWIDImpl.class) .setProperty("hibernate.connection.driver_class", driver) .setProperty("hibernate.connection.url", url) .setProperty("hibernate.connection.username", username) @@ -35,8 +37,9 @@ public void init(LaunchServer server) { cfg.setProperty("hibernate.dialect", dialect); if (hibernateConfig != null) cfg.configure(Paths.get(hibernateConfig).toFile()); - userDAO = new HibernateUserDAOImpl(cfg.buildSessionFactory()); - userService = new UserService(userDAO); + sessionFactory = cfg.buildSessionFactory(); + userDAO = new HibernateUserDAOImpl(sessionFactory); + hwidDao = new HibernateHwidDAOImpl(sessionFactory); }; if (parallelHibernateInit) CommonHelper.newThread("Hibernate Thread", true, init); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/RegisterResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/RegisterResponse.java index 2a008f48..e0567e48 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/RegisterResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/RegisterResponse.java @@ -2,6 +2,7 @@ import io.netty.channel.ChannelHandlerContext; import pro.gravit.launchserver.dao.User; +import pro.gravit.launchserver.dao.impl.UserHibernateImpl; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.SimpleResponse; @@ -24,17 +25,17 @@ public void execute(ChannelHandlerContext ctx, Client client) throws Exception { sendError("Hash invalid"); return; } - User checkUser = server.config.dao.userService.findUserByUsername(login); + User checkUser = server.config.dao.userDAO.findByUsername(login); if (checkUser != null) { sendError("User already register"); return; } - User user = new User(); + UserHibernateImpl user = new UserHibernateImpl(); user.username = login; user.email = email; user.setPassword(password); user.uuid = UUID.randomUUID(); - server.config.dao.userService.saveUser(user); + server.config.dao.userDAO.save(user); } @Override diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/SetPasswordResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/SetPasswordResponse.java index e79d5d1f..f1d9838e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/SetPasswordResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/SetPasswordResponse.java @@ -31,11 +31,11 @@ public void execute(ChannelHandlerContext ctx, Client client) { return; } if (username != null) { - User user = server.config.dao.userService.findUserByUsername(username); + User user = server.config.dao.userDAO.findByUsername(username); user.setPassword(newPassword); sendResult(new SetPasswordRequestEvent()); } else { - User user = server.config.dao.userService.findUserByUsername(client.username); + User user = server.config.dao.userDAO.findByUsername(client.username); if (user.verifyPassword(oldPassword)) { user.setPassword(newPassword); sendResult(new SetPasswordRequestEvent()); diff --git a/modules b/modules index 9cb09c54..12cb8354 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 9cb09c549abea86348597137e05a0ec29bc36b62 +Subproject commit 12cb835489667b39453e874f43bd314a67f0719e From 96930cbce37ef567487e396643486edab8f99b79 Mon Sep 17 00:00:00 2001 From: Gravit Gravit Date: Thu, 2 Jan 2020 22:55:24 +0700 Subject: [PATCH 143/192] [FIX] Autogen Certificate --- .../launchserver/auth/provider/HibernateAuthProvider.java | 2 +- .../launchserver/binary/tasks/CertificateAutogenTask.java | 2 +- .../src/main/java/pro/gravit/launcher/LauncherTrustManager.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/HibernateAuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/HibernateAuthProvider.java index 4f041d98..4f9e19f2 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/HibernateAuthProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/HibernateAuthProvider.java @@ -17,7 +17,7 @@ public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface p if (user == null && autoReg) { AuthHookManager.RegContext context = new AuthHookManager.RegContext(login, ((AuthPlainPassword) password).password, ip, false); if (srv.authHookManager.registraion.hook(context)) { - user = srv.config.dao.userService.registerNewUser(login, ((AuthPlainPassword) password).password); + //user = srv.config.dao.userService.registerNewUser(login, ((AuthPlainPassword) password).password); //TODO: FIX } else { throw new AuthException("Registration canceled. Try again later"); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/CertificateAutogenTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/CertificateAutogenTask.java index 400d22da..44c44bc4 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/CertificateAutogenTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/CertificateAutogenTask.java @@ -59,7 +59,7 @@ public Path process(Path inputFile) throws IOException { new X500Name("CN=ca"), SubjectPublicKeyInfo.getInstance(server.publicKey.getEncoded())); builder.addExtension(Extension.extendedKeyUsage, false, new ExtendedKeyUsage(KeyPurposeId.id_kp_codeSigning)); - builder.addExtension(Extension.keyUsage, false, new KeyUsage(1)); + //builder.addExtension(Extension.keyUsage, false, new KeyUsage(1)); JcaContentSignerBuilder csBuilder = new JcaContentSignerBuilder("SHA256WITHECDSA"); ContentSigner signer = csBuilder.build(server.privateKey); bcCertificate = builder.build(signer); diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/LauncherTrustManager.java b/LauncherCore/src/main/java/pro/gravit/launcher/LauncherTrustManager.java index 6112f0dc..ebfcf279 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/LauncherTrustManager.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/LauncherTrustManager.java @@ -87,7 +87,7 @@ public X509Certificate[] getTrusted() { public void isCertificateCodeSign(X509Certificate certificate) { - if(!certificate.getKeyUsage()[0]) throw new SecurityException("Certificate keyUsage \"digitalSignature\" check failed"); + //if(!certificate.getKeyUsage()[0]) throw new SecurityException("Certificate keyUsage \"digitalSignature\" check failed"); List extended; try { extended = certificate.getExtendedKeyUsage(); From 160219c36bfd75906c6d3351d044d1aafefe61fa Mon Sep 17 00:00:00 2001 From: Gravit Date: Fri, 3 Jan 2020 17:06:15 +0700 Subject: [PATCH 144/192] =?UTF-8?q?[ANY]=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index 12cb8354..9cb09c54 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 12cb835489667b39453e874f43bd314a67f0719e +Subproject commit 9cb09c549abea86348597137e05a0ec29bc36b62 From 7d5b912c3ca7df65afecc1060569bfb6eac87329 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 4 Jan 2020 21:17:24 +0700 Subject: [PATCH 145/192] [FEATURE] ClientService.nativesPath --- .../src/main/java/pro/gravit/launcher/api/ClientService.java | 1 + .../src/main/java/pro/gravit/launcher/client/ClientLauncher.java | 1 + 2 files changed, 2 insertions(+) diff --git a/Launcher/src/main/java/pro/gravit/launcher/api/ClientService.java b/Launcher/src/main/java/pro/gravit/launcher/api/ClientService.java index be931ec8..bbcb2245 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/api/ClientService.java +++ b/Launcher/src/main/java/pro/gravit/launcher/api/ClientService.java @@ -6,5 +6,6 @@ public class ClientService { public static Instrumentation instrumentation; public static ClassLoader classLoader; + public static String nativePath; public static URL[] baseURLs; } diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index 8a3fab23..cd2f642e 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -504,6 +504,7 @@ public static void main(String... args) throws Throwable { AuthService.username = params.pp.username; AuthService.uuid = params.pp.uuid; ClientService.classLoader = classLoader; + ClientService.nativePath = classLoader.nativePath; classLoader.addURL(IOHelper.getCodeSource(ClientLauncher.class).toUri().toURL()); //classForName(classLoader, "com.google.common.collect.ForwardingMultimap"); ClientService.baseURLs = classLoader.getURLs(); From 1ae7c80c7216febf65edb7a3d0629d629e2c82de Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 4 Jan 2020 21:54:17 +0700 Subject: [PATCH 146/192] =?UTF-8?q?[FIX]=20=D0=A4=D0=B8=D0=BA=D1=81=20?= =?UTF-8?q?=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8=20JavaFX=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B8=20=D0=B7=D0=B0=D0=BF=D1=83=D1=81=D0=BA=D0=B5=20=D0=BD?= =?UTF-8?q?=D0=B0=20Java=209+=20=D0=B1=D0=B5=D0=B7=20openjfx?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/pro/gravit/launcher/ClientLauncherWrapper.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java b/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java index 6e3cf58b..36781176 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java +++ b/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java @@ -63,8 +63,6 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep JVMHelper.addSystemPropertyToArgs(args, DirWatcher.IGN_OVERFLOW); if (!noJava9check && !System.getProperty("java.version").startsWith("1.8")) { LogHelper.debug("Found Java 9+ ( %s )", System.getProperty("java.version")); - args.add("--add-modules"); - args.add("javafx.base,javafx.fxml,javafx.controls,jdk.unsupported"); Path jvmDir = Paths.get(System.getProperty("java.home")); String pathToFx = System.getenv("PATH_TO_FX"); Path fxPath = pathToFx == null ? null : Paths.get(pathToFx); @@ -76,6 +74,8 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep tryAddModule(findPath, "javafx.controls", builder); String modulePath = builder.toString(); if (!modulePath.isEmpty()) { + args.add("--add-modules"); + args.add("javafx.base,javafx.fxml,javafx.controls,jdk.unsupported"); args.add("--module-path"); args.add(modulePath); } From 459f305f13cd5b8fccaa6077c1a1a5cbf9a804ba Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 4 Jan 2020 22:01:32 +0700 Subject: [PATCH 147/192] =?UTF-8?q?[FEATURE]=20=D0=92=D0=BE=D0=B7=D0=BC?= =?UTF-8?q?=D0=BE=D0=B6=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20=D1=81=D0=BB=D0=B5?= =?UTF-8?q?=D0=B6=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B7=D0=B0=20OptionalFile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/pro/gravit/launcher/profiles/ClientProfile.java | 2 ++ .../pro/gravit/launcher/profiles/optional/OptionalFile.java | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java index d60a77f4..2f3b7b6b 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java @@ -256,6 +256,7 @@ public void markOptional(OptionalFile file) { if (file.mark) return; file.mark = true; + file.notifyObservers(true); if (file.dependencies != null) { for (OptionalFile dep : file.dependencies) { if (dep.dependenciesCount == null) dep.dependenciesCount = new HashSet<>(); @@ -283,6 +284,7 @@ public void unmarkOptional(String name, OptionalType type) { public void unmarkOptional(OptionalFile file) { if (!file.mark) return; file.mark = false; + file.notifyObservers(false); if (file.dependenciesCount != null) { for (OptionalFile f : file.dependenciesCount) { if (f.isPreset) continue; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalFile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalFile.java index 43d5f22a..237deb22 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalFile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalFile.java @@ -7,9 +7,10 @@ import java.io.IOException; import java.util.Objects; +import java.util.Observable; import java.util.Set; -public class OptionalFile { +public class OptionalFile extends Observable { @LauncherNetworkAPI public String[] list; @LauncherNetworkAPI From 9351cc1de53e9d3294bdb73215fb4a2e15476bd3 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 4 Jan 2020 22:13:04 +0700 Subject: [PATCH 148/192] [FEATURE] OptionalTrigger --- .../profiles/optional/OptionalFile.java | 2 + .../profiles/optional/OptionalTrigger.java | 53 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalTrigger.java diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalFile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalFile.java index 237deb22..668ec186 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalFile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalFile.java @@ -24,6 +24,8 @@ public class OptionalFile extends Observable { @LauncherNetworkAPI public String info; @LauncherNetworkAPI + public OptionalTrigger[] triggers; + @LauncherNetworkAPI public OptionalDepend[] dependenciesFile; @LauncherNetworkAPI public OptionalDepend[] conflictFile; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalTrigger.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalTrigger.java new file mode 100644 index 00000000..0603aef4 --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalTrigger.java @@ -0,0 +1,53 @@ +package pro.gravit.launcher.profiles.optional; + +import pro.gravit.utils.helper.JVMHelper; + +public class OptionalTrigger { + public enum TriggerType + { + JAVA_VERSION, JAVA_BITS, OS_BITS, OS_TYPE + } + public TriggerType type; + public boolean need = true; + public long value; + public long compareMode = 0; + boolean isTriggered() + { + long test; + switch (type) + { + + case JAVA_VERSION: + test = JVMHelper.JVM_VERSION; + break; + case JAVA_BITS: + test = JVMHelper.JVM_BITS; + break; + case OS_BITS: + test = JVMHelper.OS_BITS; + break; + case OS_TYPE: + switch (JVMHelper.OS_TYPE) + { + + case MUSTDIE: + test = 0; + break; + case LINUX: + test = 1; + break; + case MACOSX: + test = 2; + break; + default: + return false; + } + break; + default: + return false; + } + if(compareMode == 0) return test == value; + else if(compareMode < 0) return test < value; + else return test > value; + } +} From 0dcd212d27839fba6b3a9873580d95fbcbd0007c Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Thu, 9 Jan 2020 15:35:33 +0100 Subject: [PATCH 149/192] =?UTF-8?q?[FIX]=20=D0=91=D0=BE=D0=BB=D0=B5=D0=B5?= =?UTF-8?q?=20=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=D1=8C=D0=BD=D0=BE=D0=B5?= =?UTF-8?q?=20=D0=BE=D0=BF=D1=80=D0=B5=D0=B4=D0=B5=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20ContentType.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launchserver/socket/handlers/ContentType.java | 10 ++++++++-- .../socket/handlers/fileserver/FileServerHandler.java | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/ContentType.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/ContentType.java index 75d9a9e4..a40ee7f1 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/ContentType.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/ContentType.java @@ -17,10 +17,16 @@ public String forPath(File p) { try { return Files.probeContentType(p.toPath()); } catch (Throwable e) { - return null; + return UNIVERSAL.forPath(p); } } + }, + UNIVERSAL { + @Override + public String forPath(File p) { + return "application/octet-stream"; + } + }; - public abstract String forPath(File p); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/fileserver/FileServerHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/fileserver/FileServerHandler.java index 4e146bed..04ca4018 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/fileserver/FileServerHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/fileserver/FileServerHandler.java @@ -34,7 +34,7 @@ public class FileServerHandler extends SimpleChannelInboundHandler e.name().toLowerCase(Locale.US).equals(System.getProperty("launcher.fileserver.typeprobe", "nio"))).findFirst().orElse(ContentType.NONE); + private static final ContentType TYPE_PROBE = Arrays.stream(ContentType.values()).filter(e -> e.name().toLowerCase(Locale.US).equals(System.getProperty("launcher.fileserver.typeprobe", "nio"))).findFirst().orElse(ContentType.UNIVERSAL); private final Path base; private final boolean fullOut; private final boolean showHiddenFiles; From 770a9a18ce6c9d1aa338243b5230ebd9a718d415 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Fri, 10 Jan 2020 14:55:16 +0100 Subject: [PATCH 150/192] =?UTF-8?q?[FIX]=20=D0=9F=D0=BE=D1=80=D1=82=D0=B8?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D1=84=D0=B8=D0=BA?= =?UTF-8?q?=D1=81=D0=BE=D0=B2=20=D1=81=20=D0=B2=D0=B5=D1=82=D0=BA=D0=B8=20?= =?UTF-8?q?hotfix/5.0.11?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../profile/ProfileByUUIDResponse.java | 4 ++ .../launchserver/defaults/profile1.14.4.cfg | 2 - .../launchserver/defaults/profile1.15.1.cfg | 38 +++++++++++++++++++ .../launcher/profiles/ClientProfile.java | 3 +- 4 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.15.1.cfg diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/profile/ProfileByUUIDResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/profile/ProfileByUUIDResponse.java index 72365891..ee5d9d7c 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/profile/ProfileByUUIDResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/profile/ProfileByUUIDResponse.java @@ -60,6 +60,10 @@ public void execute(ChannelHandlerContext ctx, Client client) throws Exception { return; } username = pair.handler.uuidToUsername(uuid); + if (username == null) { + sendError(String.format("ProfileByUUIDResponse: User with uuid %s not found or AuthProvider#uuidToUsername returned null", uuid)); + return; + } sendResult(new ProfileByUUIDRequestEvent(getProfile(uuid, username, this.client, client.auth.textureProvider))); } } diff --git a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.14.4.cfg b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.14.4.cfg index e5ca1b4b..0fac6e8b 100644 --- a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.14.4.cfg +++ b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.14.4.cfg @@ -23,8 +23,6 @@ "useWhitelist": false, "mainClass": "net.minecraft.client.main.Main", "jvmArgs": [ - "-Dfml.ignorePatchDiscrepancies=true", - "-Dfml.ignoreInvalidMinecraftCertificates=rue", "-XX:+UseConcMarkSweepGC", "-XX:+CMSIncrementalMode", "-XX:-UseAdaptiveSizePolicy", diff --git a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.15.1.cfg b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.15.1.cfg new file mode 100644 index 00000000..f265344f --- /dev/null +++ b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.15.1.cfg @@ -0,0 +1,38 @@ +{ + "version": "1.15.1", + "assetIndex": "1.15.1", + "assetDir": "asset1.15.1", + "dir": "HiTech", + "info": "Информация о сервере", + "sortIndex": 0, + "title": "xxxxxxxx", + "serverAddress": "localhost", + "serverPort": 25565, + "update": [ + "servers.dat" + ], + "updateExclusions": [], + "updateShared": [], + "updateVerify": [ + "libraries", + "natives", + "minecraft.jar" + ], + "updateOptional": [], + "updateFastCheck": true, + "useWhitelist": false, + "mainClass": "net.minecraft.client.main.Main", + "jvmArgs": [ + "-XX:+UseConcMarkSweepGC", + "-XX:+CMSIncrementalMode", + "-XX:-UseAdaptiveSizePolicy", + "-Xmn128M", + "-XX:+DisableAttachMechanism" + ], + "classPath": [ + "minecraft.jar", + "libraries" + ], + "clientArgs": [], + "whitelist": [] +} \ No newline at end of file diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java index 2f3b7b6b..10a25fa2 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java @@ -40,7 +40,8 @@ public enum Version { MC1142("1.14.2", 485), MC1143("1.14.3", 490), MC1144("1.14.4", 498), - MC115("1.15", 573); + MC115("1.15", 573), + MC1151("1.15.1", 575); private static final Map VERSIONS; static { From 64d57faa48d812ed183d4afcf2f918f6abdf5333 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Tue, 14 Jan 2020 17:32:29 +0100 Subject: [PATCH 151/192] =?UTF-8?q?[FIX]=20Launch4J=20-=20=D0=B4=D0=BE?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D0=BD=D0=B8=D1=82=D0=B5=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D1=8B=D0=B5=20=D0=BD=D0=B0=D1=81=D1=82=D1=80=D0=BE=D0=B9=D0=BA?= =?UTF-8?q?=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launchserver/binary/tasks/exe/Launch4JTask.java | 8 ++++---- .../gravit/launchserver/config/LaunchServerConfig.java | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/exe/Launch4JTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/exe/Launch4JTask.java index 08d743fb..fbbb3c43 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/exe/Launch4JTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/exe/Launch4JTask.java @@ -28,7 +28,7 @@ public void clear() { } // URL constants - private static final String DOWNLOAD_URL = "http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html"; // Oracle + public static final String DOWNLOAD_URL = "http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html"; // Oracle // JRE 8 // File constants private final Path faviconFile; @@ -80,8 +80,8 @@ private Path setConfig() { // Set file options config.setChdir("."); config.setErrTitle("JVM Error"); - config.setDownloadUrl(DOWNLOAD_URL); - + config.setDownloadUrl(server.config.launch4j.downloadUrl); + if (server.config.launch4j.supportURL != null) config.setSupportUrl(server.config.launch4j.supportURL); // Set boolean options config.setPriorityIndex(0); config.setHeaderType(Config.GUI_HEADER); @@ -90,7 +90,7 @@ private Path setConfig() { // Prepare JRE Jre jre = new Jre(); - jre.setMinVersion("1.8.0"); + jre.setMinVersion(server.config.launch4j.minVersion); if (server.config.launch4j.setMaxVersion) jre.setMaxVersion(server.config.launch4j.maxVersion); jre.setRuntimeBits(Jre.RUNTIME_BITS_64_AND_32); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java index e2f20159..a8d77215 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java @@ -16,6 +16,7 @@ import pro.gravit.launchserver.auth.protect.StdProtectHandler; import pro.gravit.launchserver.auth.provider.RejectAuthProvider; import pro.gravit.launchserver.auth.texture.RequestTextureProvider; +import pro.gravit.launchserver.binary.tasks.exe.Launch4JTask; import pro.gravit.launchserver.components.AuthLimiterComponent; import pro.gravit.launchserver.components.Component; import pro.gravit.launchserver.components.RegLimiterComponent; @@ -209,6 +210,9 @@ public static class ExeConf { public boolean enabled; public boolean setMaxVersion; public String maxVersion; + public String minVersion = "1.8.0"; + public String supportURL = null; + public String downloadUrl = Launch4JTask.DOWNLOAD_URL; public String productName; public String productVer; public String fileDesc; From ea6e131b60113841f3fa69696a974d0e63661b96 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Tue, 14 Jan 2020 18:01:59 +0100 Subject: [PATCH 152/192] =?UTF-8?q?[FEATURE]=20=D0=90=D0=BD=D0=BD=D0=BE?= =?UTF-8?q?=D1=82=D0=B0=D1=86=D0=B8=D1=8F=20LauncherInject=20=D0=B8=20?= =?UTF-8?q?=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D1=8C=20=D0=B5=D1=91=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?=D0=B7=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F.=20=D0=94=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=BD=D1=83=D0=B6=D0=B5=D0=BD=20Bui?= =?UTF-8?q?ldTask=20=D0=BF=D0=BE=20=D0=BF=D1=80=D0=B8=D0=BC=D0=B5=D1=80?= =?UTF-8?q?=D1=83=20Patcher`=D0=B0,=20=D0=BD=D0=BE=20=D1=81=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BD=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D0=B5=D0=B9=20=D0=B2=20?= =?UTF-8?q?=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=BD=D0=BE=D0=B4=D1=83=20=D0=B8?= =?UTF-8?q?=20=D0=BE=D0=B1=D1=80=D0=B0=D1=82=D0=BD=D0=BE.=20=D0=A7=D1=82?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0?= =?UTF-8?q?=20=D0=B4=D0=BE=D0=BB=D0=B6=D0=BD=D0=BE=20=D0=B1=D1=8B=D1=82?= =?UTF-8?q?=D1=8C=20=D1=81=20EXPAND=5FFRAMES,=20=D0=B0=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=BF=D0=B8=D1=81=D1=8C=20=D1=81=200=20(=D0=B1=D0=B5=D0=B7=20C?= =?UTF-8?q?OMPUTE=5FFRAMES).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launchserver/asm/InjectClassAcceptor.java | 51 +++++++++++++++++++ .../pro/gravit/launcher/LauncherInject.java | 13 +++++ 2 files changed, 64 insertions(+) create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java create mode 100644 LauncherCore/src/main/java/pro/gravit/launcher/LauncherInject.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java new file mode 100644 index 00000000..f8246e95 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java @@ -0,0 +1,51 @@ +package pro.gravit.launchserver.asm; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicReference; + +import org.objectweb.asm.AnnotationVisitor; +import org.objectweb.asm.Opcodes; +import org.objectweb.asm.Type; +import org.objectweb.asm.tree.AnnotationNode; +import org.objectweb.asm.tree.ClassNode; + +import pro.gravit.launcher.LauncherInject; + +public class InjectClassAcceptor { + public static final Class[] primitives = new Class[] { java.lang.Boolean.class, java.lang.Character.class, + java.lang.Byte.class, java.lang.Short.class, java.lang.Integer.class, java.lang.Long.class, + java.lang.Float.class, java.lang.Double.class, java.lang.String.class }; + + public static final List> zPrimitivesList = Arrays.asList(primitives); + public static final String INJ_DESC = Type.getDescriptor(LauncherInject.class); + + public static void visit(ClassNode cn, Map object) { + if (!object.values().stream().allMatch(zPrimitivesList::contains)) + throw new IllegalArgumentException("Only primitives in values..."); + cn.fields.stream().filter(e -> e.invisibleAnnotations != null) + .filter(e -> e.invisibleAnnotations.stream().anyMatch(f -> f.desc.equals(INJ_DESC))).forEach(e -> { + // Notice that fields that will be used with this algo should not have default + // value by = ...; + AnnotationNode n = e.invisibleAnnotations.stream().filter(f -> INJ_DESC.equals(f.desc)).findFirst() + .get(); + AtomicReference valueName = new AtomicReference<>(null); + n.accept(new AnnotationVisitor(Opcodes.ASM7) { + @Override + public void visit(final String name, final Object value) { + if ("value".equals(name)) { + if (value.getClass() != String.class) + throw new IllegalArgumentException( + "Invalid Annotation with value class " + e.getClass().getName()); + valueName.set(value.toString()); + } + } + }); + if (valueName.get() == null) + throw new IllegalArgumentException("Annotation should always contains 'value' key"); + if (object.containsKey(valueName.get())) + e.value = object.get(valueName.get()); + }); + } +} diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/LauncherInject.java b/LauncherCore/src/main/java/pro/gravit/launcher/LauncherInject.java new file mode 100644 index 00000000..b11647c1 --- /dev/null +++ b/LauncherCore/src/main/java/pro/gravit/launcher/LauncherInject.java @@ -0,0 +1,13 @@ +package pro.gravit.launcher; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.RetentionPolicy.CLASS; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +@Retention(CLASS) +@Target(FIELD) +public @interface LauncherInject { + public String value(); // target of inject +} From 567e2fefaf88fa9f208ddc723769bb4d3ac9b57d Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Sat, 18 Jan 2020 06:25:11 +0100 Subject: [PATCH 153/192] =?UTF-8?q?[FIX]=20=D0=A0=D0=B5=D1=84=D0=B0=D0=BA?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=B8=D0=BD=D0=B3=20=D0=B2=20=D0=BF=D0=B0?= =?UTF-8?q?=D0=BA=D0=B5=D1=82=D0=B5=20pro.gravit.launchserver.asm.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launchserver/asm/InjectClassAcceptor.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java index f8246e95..8146dc82 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java @@ -21,11 +21,14 @@ public class InjectClassAcceptor { public static final List> zPrimitivesList = Arrays.asList(primitives); public static final String INJ_DESC = Type.getDescriptor(LauncherInject.class); - public static void visit(ClassNode cn, Map object) { + public static void checkMap(Map object) { if (!object.values().stream().allMatch(zPrimitivesList::contains)) throw new IllegalArgumentException("Only primitives in values..."); + } + + public static void visit(ClassNode cn, Map object) { cn.fields.stream().filter(e -> e.invisibleAnnotations != null) - .filter(e -> e.invisibleAnnotations.stream().anyMatch(f -> f.desc.equals(INJ_DESC))).forEach(e -> { + .filter(e -> !e.invisibleAnnotations.isEmpty() && e.invisibleAnnotations.stream().anyMatch(f -> f.desc.equals(INJ_DESC))).forEach(e -> { // Notice that fields that will be used with this algo should not have default // value by = ...; AnnotationNode n = e.invisibleAnnotations.stream().filter(f -> INJ_DESC.equals(f.desc)).findFirst() From 036b593356eea9982f62fdd7964c7e5ec6a636e9 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 18 Jan 2020 13:31:30 +0700 Subject: [PATCH 154/192] =?UTF-8?q?[TEST]=20=D0=A2=D0=B5=D1=81=D1=82=D1=8B?= =?UTF-8?q?=20=D0=B4=D0=BB=D1=8F=20InjectClassAcceptor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launchserver/asm/InjectClassAcceptor.java | 2 +- .../launchserver/ASMTransformersTest.java | 66 +++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 LaunchServer/src/test/java/pro/gravit/launchserver/ASMTransformersTest.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java index 8146dc82..7cb5621b 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java @@ -22,7 +22,7 @@ public class InjectClassAcceptor { public static final String INJ_DESC = Type.getDescriptor(LauncherInject.class); public static void checkMap(Map object) { - if (!object.values().stream().allMatch(zPrimitivesList::contains)) + if (!zPrimitivesList.containsAll(object.values())) throw new IllegalArgumentException("Only primitives in values..."); } diff --git a/LaunchServer/src/test/java/pro/gravit/launchserver/ASMTransformersTest.java b/LaunchServer/src/test/java/pro/gravit/launchserver/ASMTransformersTest.java new file mode 100644 index 00000000..c776109d --- /dev/null +++ b/LaunchServer/src/test/java/pro/gravit/launchserver/ASMTransformersTest.java @@ -0,0 +1,66 @@ +package pro.gravit.launchserver; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.tree.ClassNode; +import org.objectweb.asm.tree.FieldNode; +import pro.gravit.launcher.LauncherInject; +import pro.gravit.launchserver.asm.InjectClassAcceptor; +import pro.gravit.utils.PublicURLClassLoader; +import pro.gravit.utils.helper.LogHelper; + +import java.io.InputStream; +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.Map; + +public class ASMTransformersTest { + public static class ASMClassLoader extends ClassLoader + { + public ASMClassLoader(ClassLoader parent) { + super(parent); + } + public void rawDefineClass(String name, byte[] bytes, int offset, int length) + { + defineClass(name, bytes, offset, length); + } + } + public static ASMClassLoader classLoader; + public static class TestClass + { + @LauncherInject(value = "testprop") + public static int test = 1; + } + @BeforeAll + public static void prepare() throws Exception { + classLoader = new ASMClassLoader(ASMTransformersTest.class.getClassLoader()); + } + InputStream getClass(Class clazz) + { + String className = clazz.getName(); + String classAsPath = className.replace('.', '/') + ".class"; + return clazz.getClassLoader().getResourceAsStream(classAsPath); + } + @Test + void testASM() throws Exception + { + ClassReader reader = new ClassReader(getClass(TestClass.class)); + ClassNode node = new ClassNode(); + reader.accept(node, ClassReader.SKIP_DEBUG); + node.name = "ASMTestClass"; + Map map = new HashMap<>(); + map.put("testprop", 1234); + InjectClassAcceptor.visit(node, map); + ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); + node.accept(writer); + byte[] bytes = writer.toByteArray(); + classLoader.rawDefineClass("ASMTestClass", bytes, 0, bytes.length); + Class clazz = classLoader.loadClass("ASMTestClass"); + Field field = clazz.getField("test"); + Object result = field.get(null); + Assertions.assertEquals(1234, (int) (Integer) result); + } +} From 495dba899d39a5f4a0f1354eabc89c3ddbab7535 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 18 Jan 2020 17:25:49 +0700 Subject: [PATCH 155/192] [FEATURE] ClientUnlockConsoleEvent --- .../client/events/ClientUnlockConsoleEvent.java | 12 ++++++++++++ .../pro/gravit/launcher/console/UnlockCommand.java | 7 +++++-- .../pro/gravit/launcher/managers/ConsoleManager.java | 10 +++++++++- 3 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 Launcher/src/main/java/pro/gravit/launcher/client/events/ClientUnlockConsoleEvent.java diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientUnlockConsoleEvent.java b/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientUnlockConsoleEvent.java new file mode 100644 index 00000000..2bf5ba5b --- /dev/null +++ b/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientUnlockConsoleEvent.java @@ -0,0 +1,12 @@ +package pro.gravit.launcher.client.events; + +import pro.gravit.launcher.modules.LauncherModule; +import pro.gravit.utils.command.CommandHandler; + +public class ClientUnlockConsoleEvent extends LauncherModule.Event { + public final CommandHandler handler; + + public ClientUnlockConsoleEvent(CommandHandler handler) { + this.handler = handler; + } +} diff --git a/Launcher/src/main/java/pro/gravit/launcher/console/UnlockCommand.java b/Launcher/src/main/java/pro/gravit/launcher/console/UnlockCommand.java index 73bc54a6..c6419756 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/console/UnlockCommand.java +++ b/Launcher/src/main/java/pro/gravit/launcher/console/UnlockCommand.java @@ -21,8 +21,11 @@ public void invoke(String... args) throws Exception { verifyArgs(args, 1); if (ConsoleManager.checkUnlockKey(args[0])) { LogHelper.info("Unlock successful"); - ConsoleManager.unlock(); - ConsoleManager.handler.unregisterCommand("unlock"); + if(!ConsoleManager.unlock()) + { + LogHelper.error("Console unlock canceled"); + return; + } LogHelper.info("Write unlock key"); SettingsManager.settings.consoleUnlockKey = args[0]; } else { diff --git a/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java b/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java index 6b87f2ec..24f2acdc 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java +++ b/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java @@ -1,6 +1,8 @@ package pro.gravit.launcher.managers; import pro.gravit.launcher.Launcher; +import pro.gravit.launcher.LauncherEngine; +import pro.gravit.launcher.client.events.ClientUnlockConsoleEvent; import pro.gravit.launcher.console.UnlockCommand; import pro.gravit.utils.command.CommandHandler; import pro.gravit.utils.command.JLineCommandHandler; @@ -48,8 +50,14 @@ public static boolean checkUnlockKey(String key) { return key.equals(Launcher.getConfig().oemUnlockKey); } - public static void unlock() { + public static boolean unlock() { + if(isConsoleUnlock) return true; + ClientUnlockConsoleEvent event = new ClientUnlockConsoleEvent(handler); + LauncherEngine.modulesManager.invokeEvent(event); + if(event.isCancel()) return false; handler.registerCommand("debug", new DebugCommand()); + handler.unregisterCommand("unlock"); isConsoleUnlock = true; + return true; } } From 5939ed758f7012e4ce799313a3b64c594d7da765 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 18 Jan 2020 17:33:18 +0700 Subject: [PATCH 156/192] =?UTF-8?q?[ANY]=20=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=83=D1=81=D1=82=D0=B0=D1=80=D0=B5=D0=B2?= =?UTF-8?q?=D1=88=D0=B8=D1=85=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launcher/client/ClientProcessBuilder.java | 153 ------------------ .../client/LauncherUpdateController.java | 104 ------------ .../launcher/managers/HasherManager.java | 9 -- .../gravit/launcher/managers/HasherStore.java | 68 -------- 4 files changed, 334 deletions(-) delete mode 100644 Launcher/src/main/java/pro/gravit/launcher/client/ClientProcessBuilder.java delete mode 100644 Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java delete mode 100644 Launcher/src/main/java/pro/gravit/launcher/managers/HasherManager.java delete mode 100644 Launcher/src/main/java/pro/gravit/launcher/managers/HasherStore.java diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientProcessBuilder.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientProcessBuilder.java deleted file mode 100644 index 0d579e7e..00000000 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientProcessBuilder.java +++ /dev/null @@ -1,153 +0,0 @@ -package pro.gravit.launcher.client; - -import pro.gravit.launcher.ClientLauncherWrapper; -import pro.gravit.launcher.guard.LauncherGuardManager; -import pro.gravit.launcher.hasher.HashedDir; -import pro.gravit.launcher.managers.ClientHookManager; -import pro.gravit.launcher.profiles.ClientProfile; -import pro.gravit.launcher.utils.DirWatcher; -import pro.gravit.utils.helper.EnvHelper; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.JVMHelper; -import pro.gravit.utils.helper.LogHelper; - -import java.io.IOException; -import java.nio.file.Path; -import java.util.Collections; -import java.util.List; - -import static pro.gravit.launcher.client.ClientLauncher.checkJVMBitsAndVersion; - -public class ClientProcessBuilder { - private HashedDir assetHDir; - private HashedDir clientHDir; - private ClientProfile profile; - private ClientLauncher.Params params; - private Path nativesDir = IOHelper.toPath("natives"); - private Path resourcepacksDir = IOHelper.toPath("resourcepacks"); - private boolean pipeOutput = false; - private boolean clientLaunchStarting = false; - public interface ParamsWriter - { - void write(ClientLauncherContext context); - } - private ParamsWriter paramsWriter; - - private static final String MAGICAL_INTEL_OPTION = "-XX:HeapDumpPath=ThisTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump"; - - public ClientProcessBuilder setAssetHDir(HashedDir assetHDir) { - this.assetHDir = assetHDir; - return this; - } - - public ClientProcessBuilder setClientHDir(HashedDir clientHDir) { - this.clientHDir = clientHDir; - return this; - } - - public ClientProcessBuilder setProfile(ClientProfile profile) { - this.profile = profile; - return this; - } - - public ClientProcessBuilder setParams(ClientLauncher.Params params) { - this.params = params; - return this; - } - - public ClientProcessBuilder setNativesDir(Path nativesDir) { - this.nativesDir = nativesDir; - return this; - } - - public ClientProcessBuilder setResourcepacksDir(Path resourcepacksDir) { - this.resourcepacksDir = resourcepacksDir; - return this; - } - - public ClientProcessBuilder setPipeOutput(boolean pipeOutput) { - this.pipeOutput = pipeOutput; - return this; - } - - public ClientProcessBuilder setParamsWriter(ParamsWriter paramsWriter) { - this.paramsWriter = paramsWriter; - return this; - } - - public ClientLauncherContext build() throws IOException { - LogHelper.debug("Writing ClientLauncher params"); - ClientLauncherContext context = new ClientLauncherContext(); - clientLaunchStarting = true; - checkJVMBitsAndVersion(); - LogHelper.debug("Resolving JVM binary"); - Path javaBin = LauncherGuardManager.getGuardJavaBinPath(); - context.javaBin = javaBin; - context.clientProfile = profile; - context.playerProfile = params.pp; - context.args.add(javaBin.toString()); - context.args.add(MAGICAL_INTEL_OPTION); - context.params = params; - if(paramsWriter != null) paramsWriter.write(context); - if (params.ram > 0) { - context.args.add("-Xms" + params.ram + 'M'); - context.args.add("-Xmx" + params.ram + 'M'); - } - context.args.add(JVMHelper.jvmProperty(LogHelper.DEBUG_PROPERTY, Boolean.toString(LogHelper.isDebugEnabled()))); - context.args.add(JVMHelper.jvmProperty(LogHelper.STACKTRACE_PROPERTY, Boolean.toString(LogHelper.isStacktraceEnabled()))); - context.args.add(JVMHelper.jvmProperty(LogHelper.DEV_PROPERTY, Boolean.toString(LogHelper.isDevEnabled()))); - context.args.add(JVMHelper.jvmProperty(LogHelper.NO_JANSI_PROPERTY, "true")); // Отключаем JAnsi для нормального вывода в DEBUG окно - JVMHelper.addSystemPropertyToArgs(context.args, DirBridge.CUSTOMDIR_PROPERTY); - JVMHelper.addSystemPropertyToArgs(context.args, DirBridge.USE_CUSTOMDIR_PROPERTY); - JVMHelper.addSystemPropertyToArgs(context.args, DirBridge.USE_OPTDIR_PROPERTY); - JVMHelper.addSystemPropertyToArgs(context.args, DirWatcher.IGN_OVERFLOW); - if (JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) { - if (JVMHelper.OS_VERSION.startsWith("10.")) { - LogHelper.debug("MustDie 10 fix is applied"); - context.args.add(JVMHelper.jvmProperty("os.name", "Windows 10")); - context.args.add(JVMHelper.jvmProperty("os.version", "10.0")); - } - } - // Add classpath and main class - String pathLauncher = IOHelper.getCodeSource(ClientLauncher.class).toString(); - context.pathLauncher = pathLauncher; - context.args.add(ClientLauncherWrapper.MAGIC_ARG); - Collections.addAll(context.args, profile.getJvmArgs()); - profile.pushOptionalJvmArgs(context.args); - context.args.add("-Djava.library.path=".concat(params.clientDir.resolve(nativesDir).toString())); // Add Native Path - context.args.add("-javaagent:".concat(pathLauncher)); - ClientHookManager.clientLaunchHook.hook(context); - LauncherGuardManager.guard.addCustomParams(context); - context.args.add(ClientLauncher.class.getName()); - ClientHookManager.clientLaunchFinallyHook.hook(context); - - // Print commandline debug message - LogHelper.debug("Commandline: " + context.args); - - // Build client process - LogHelper.debug("Launching client instance"); - ProcessBuilder builder = new ProcessBuilder(context.args); - context.builder = builder; - LauncherGuardManager.guard.addCustomEnv(context); - //else - //builder.environment().put("CLASSPATH", classPathString.toString()); - EnvHelper.addEnv(builder); - builder.directory(params.clientDir.toFile()); - builder.inheritIO(); - if (pipeOutput) { - builder.redirectErrorStream(true); - builder.redirectOutput(ProcessBuilder.Redirect.PIPE); - } - List command = builder.command(); - // Let's rock! - ClientHookManager.preStartHook.hook(context, builder); - context.process = builder.start(); - if (builder.command() != command) { - LogHelper.error("Something strange cheating..."); - System.exit(100); - return null; - } - ClientHookManager.postStartHook.hook(context, builder); - return context; - } -} diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java b/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java deleted file mode 100644 index 74ebd59a..00000000 --- a/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java +++ /dev/null @@ -1,104 +0,0 @@ -package pro.gravit.launcher.client; - -import pro.gravit.launcher.NewLauncherSettings; -import pro.gravit.launcher.events.request.UpdateRequestEvent; -import pro.gravit.launcher.hasher.HashedDir; -import pro.gravit.launcher.hasher.HashedEntry; -import pro.gravit.launcher.hasher.HashedFile; -import pro.gravit.launcher.request.update.UpdateRequest; -import pro.gravit.utils.helper.LogHelper; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.concurrent.atomic.AtomicReference; - -@Deprecated -public class LauncherUpdateController { - - public void postDiff(UpdateRequest request, UpdateRequestEvent e, HashedDir.Diff diff) throws IOException { - /* - if (e.zip && e.fullDownload) return; - LogHelper.info("Enabled HStore feature. Find"); - AtomicReference lastEn = new AtomicReference<>(null); - //ArrayList removed = new ArrayList<>(); - diff.mismatch.walk(File.separator, (path, name, entry) -> { - if (entry.getType() == HashedEntry.Type.DIR) { - Files.createDirectories(request.getDir().resolve(path)); - return HashedDir.WalkAction.CONTINUE; - } - HashedFile file = (HashedFile) entry; - //Первый экспериментальный способ - честно обходим все возможные Store - Path ret = null; - if (lastEn.get() == null) { - for (NewLauncherSettings.HashedStoreEntry en : SettingsManager.settings.lastHDirs) { - ret = tryFind(en, file); - if (ret != null) { - lastEn.set(en); - break; - } - } - } else { - ret = tryFind(lastEn.get(), file); - } - if (ret == null) { - for (NewLauncherSettings.HashedStoreEntry en : SettingsManager.settings.lastHDirs) { - ret = tryFind(en, file); - if (ret != null) { - lastEn.set(en); - break; - } - } - } - if (ret != null) { - //Еще раз проверим корректность хеша - //Возможно эта проверка избыточна - //if(file.isSame(ret, true)) - { - Path source = request.getDir().resolve(path); - if (LogHelper.isDebugEnabled()) { - LogHelper.debug("Copy file %s to %s", ret.toAbsolutePath().toString(), source.toAbsolutePath().toString()); - } - //Let's go! - Files.deleteIfExists(source); - Files.copy(ret, source); - try (InputStream input = IOHelper.newInput(ret)) { - IOHelper.transfer(input, source); - } - entry.flag = true; - //removed.add(path.replace('\\', '/')); - } - } - return HashedDir.WalkAction.CONTINUE; - }); - */ - } - - public Path tryFind(NewLauncherSettings.HashedStoreEntry en, HashedFile file) throws IOException { - AtomicReference ret = new AtomicReference<>(null); - en.hdir.walk(File.separator, (path, name, entry) -> { - if (entry.getType() == HashedEntry.Type.DIR) return HashedDir.WalkAction.CONTINUE; - HashedFile tfile = (HashedFile) entry; - if (tfile.isSame(file)) { - if (LogHelper.isDevEnabled()) { - LogHelper.dev("[DIR:%s] Found file %s in %s", en.name, name, path); - } - Path tdir = Paths.get(en.fullPath).resolve(path); - try { - if (tfile.isSame(tdir, true)) { - if (LogHelper.isDevEnabled()) { - LogHelper.dev("[DIR:%s] Confirmed file %s in %s", en.name, name, path); - } - ret.set(tdir); - return HashedDir.WalkAction.STOP; - } - } catch (IOException e) { - LogHelper.error("Check file error %s %s", e.getClass().getName(), e.getMessage()); - } - } - return HashedDir.WalkAction.CONTINUE; - }); - return ret.get(); - } -} diff --git a/Launcher/src/main/java/pro/gravit/launcher/managers/HasherManager.java b/Launcher/src/main/java/pro/gravit/launcher/managers/HasherManager.java deleted file mode 100644 index eaf8c4c5..00000000 --- a/Launcher/src/main/java/pro/gravit/launcher/managers/HasherManager.java +++ /dev/null @@ -1,9 +0,0 @@ -package pro.gravit.launcher.managers; - -public class HasherManager { - public static final HasherStore defaultStore = new HasherStore(); - - public static HasherStore getDefaultStore() { - return defaultStore; - } -} diff --git a/Launcher/src/main/java/pro/gravit/launcher/managers/HasherStore.java b/Launcher/src/main/java/pro/gravit/launcher/managers/HasherStore.java deleted file mode 100644 index 57095622..00000000 --- a/Launcher/src/main/java/pro/gravit/launcher/managers/HasherStore.java +++ /dev/null @@ -1,68 +0,0 @@ -package pro.gravit.launcher.managers; - -import pro.gravit.launcher.hasher.FileNameMatcher; -import pro.gravit.launcher.hasher.HashedDir; -import pro.gravit.launcher.hasher.HashedEntry; -import pro.gravit.launcher.profiles.ClientProfile; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.LogHelper; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Collection; -import java.util.LinkedList; -import java.util.Map; - -public class HasherStore { - public Map store; - - public static class HasherStoreEnity { - - public HashedDir hdir; - - public Path dir; - - public Collection shared; - } - - - public void addProfileUpdateDir(ClientProfile profile, Path dir, HashedDir hdir) { - HasherStoreEnity e = new HasherStoreEnity(); - e.hdir = hdir; - e.dir = dir; - e.shared = profile.getShared(); - - store.put(profile.getTitle(), e); - } - - - public void copyCompareFilesTo(String name, Path targetDir, HashedDir targetHDir, String[] shared) { - store.forEach((key, e) -> { - if (key.equals(name)) return; - FileNameMatcher nm = new FileNameMatcher(shared, null, null); - HashedDir compare = targetHDir.sideCompare(e.hdir, nm, new LinkedList<>(), true); - compare.map().forEach((arg1, arg2) -> recurseCopy(arg1, arg2, name, targetDir, e.dir)); - }); - } - - - public void recurseCopy(String filename, HashedEntry entry, String name, Path targetDir, Path sourceDir) { - if (!IOHelper.isDir(targetDir)) { - try { - Files.createDirectories(targetDir); - } catch (IOException e1) { - LogHelper.error(e1); - } - } - if (entry.getType().equals(HashedEntry.Type.DIR)) { - ((HashedDir) entry).map().forEach((arg1, arg2) -> recurseCopy(arg1, arg2, name, targetDir.resolve(filename), sourceDir.resolve(filename))); - } else if (entry.getType().equals(HashedEntry.Type.FILE)) { - try { - IOHelper.copy(sourceDir.resolve(filename), targetDir.resolve(filename)); - } catch (IOException e) { - LogHelper.error(e); - } - } - } -} From c075697316eb4911915d851e2565688017c59562 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 18 Jan 2020 18:04:46 +0700 Subject: [PATCH 157/192] =?UTF-8?q?[FEATURE]=20=D0=9D=D0=BE=D0=B2=D0=BE?= =?UTF-8?q?=D0=B5=20API=20=D0=B2=20JarHelper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gravit/launchserver/asm/NodeUtils.java | 3 +- .../binary/tasks/MainBuildTask.java | 7 +++-- .../launchserver/ASMTransformersTest.java | 9 ++---- .../pro/gravit/utils/helper/JarHelper.java | 28 +++++++++++++++++++ 4 files changed, 36 insertions(+), 11 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/NodeUtils.java b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/NodeUtils.java index 9919cde7..b85a27bd 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/NodeUtils.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/NodeUtils.java @@ -5,6 +5,7 @@ import org.objectweb.asm.Type; import org.objectweb.asm.tree.*; import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.JarHelper; import java.io.IOException; import java.io.InputStream; @@ -30,7 +31,7 @@ private NodeUtils() { } public static ClassNode forClass(Class cls, int flags) { - try (InputStream in = cls.getClassLoader().getResourceAsStream(cls.getName().replace('.', '/') + ".class")) { + try (InputStream in = JarHelper.getClassBytesStream(cls)) { ClassNode ret = new ClassNode(); new ClassReader(IOHelper.read(in)).accept(ret, flags); return ret; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java index 807e6993..99190a1a 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java @@ -13,6 +13,7 @@ import pro.gravit.launchserver.binary.BuildContext; import pro.gravit.launchserver.binary.LauncherConfigurator; import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.JarHelper; import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.SecurityHelper; @@ -120,10 +121,10 @@ public Path process(Path inputJar) throws IOException { Path outputJar = server.launcherBinary.nextPath("main"); try (ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(outputJar))) { ClassNode cn = new ClassNode(); - new ClassReader(IOHelper.getResourceBytes(AutogenConfig.class.getName().replace('.', '/').concat(".class"))).accept(cn, 0); + new ClassReader(JarHelper.getClassBytes(AutogenConfig.class)).accept(cn, 0); LauncherConfigurator launcherConfigurator = new LauncherConfigurator(cn); ClassNode cn1 = new ClassNode(); - new ClassReader(IOHelper.getResourceBytes(SecureAutogenConfig.class.getName().replace('.', '/').concat(".class"))).accept(cn1, 0); + new ClassReader(JarHelper.getClassBytes(SecureAutogenConfig.class)).accept(cn1, 0); ConfigGenerator secureConfigurator = new ConfigGenerator(cn1); BuildContext context = new BuildContext(output, launcherConfigurator, this); server.buildHookManager.hook(context); @@ -205,7 +206,7 @@ public Path process(Path inputJar) throws IOException { } // write additional classes for (Map.Entry ent : server.buildHookManager.getIncludeClass().entrySet()) { - output.putNextEntry(newZipEntry(ent.getKey().replace('.', '/').concat(".class"))); + output.putNextEntry(newZipEntry(JarHelper.getClassFile(ent.getKey()))); output.write(server.buildHookManager.classTransform(ent.getValue(), ent.getKey(), this)); } // map for guard diff --git a/LaunchServer/src/test/java/pro/gravit/launchserver/ASMTransformersTest.java b/LaunchServer/src/test/java/pro/gravit/launchserver/ASMTransformersTest.java index c776109d..f9909fd8 100644 --- a/LaunchServer/src/test/java/pro/gravit/launchserver/ASMTransformersTest.java +++ b/LaunchServer/src/test/java/pro/gravit/launchserver/ASMTransformersTest.java @@ -10,6 +10,7 @@ import pro.gravit.launcher.LauncherInject; import pro.gravit.launchserver.asm.InjectClassAcceptor; import pro.gravit.utils.PublicURLClassLoader; +import pro.gravit.utils.helper.JarHelper; import pro.gravit.utils.helper.LogHelper; import java.io.InputStream; @@ -38,16 +39,10 @@ public static class TestClass public static void prepare() throws Exception { classLoader = new ASMClassLoader(ASMTransformersTest.class.getClassLoader()); } - InputStream getClass(Class clazz) - { - String className = clazz.getName(); - String classAsPath = className.replace('.', '/') + ".class"; - return clazz.getClassLoader().getResourceAsStream(classAsPath); - } @Test void testASM() throws Exception { - ClassReader reader = new ClassReader(getClass(TestClass.class)); + ClassReader reader = new ClassReader(JarHelper.getClassBytes(TestClass.class)); ClassNode node = new ClassNode(); reader.accept(node, ClassReader.SKIP_DEBUG); node.name = "ASMTestClass"; diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/JarHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/JarHelper.java index ece54976..62500774 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/JarHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/JarHelper.java @@ -1,6 +1,7 @@ package pro.gravit.utils.helper; import java.io.IOException; +import java.io.InputStream; import java.nio.file.Path; import java.util.HashMap; import java.util.Map; @@ -74,4 +75,31 @@ public static void jarMap(Class clazz, Map map, boolean overw Path file = IOHelper.getCodeSource(clazz); jarMap(file, map, overwrite); } + + public static String getClassFile(Class clazz) + { + return getClassFile(clazz.getName()); + } + public static String getClassFile(String classname) + { + return classname.replace('.', '/').concat(".class"); + } + public static byte[] getClassBytes(Class clazz) throws IOException + { + return getClassBytes(clazz, clazz.getClassLoader()); + } + public static byte[] getClassBytes(Class clazz, ClassLoader classLoader) throws IOException + { + return IOHelper.read(classLoader.getResourceAsStream(getClassFile(clazz))); + } + public static InputStream getClassBytesStream(Class clazz) throws IOException + { + return getClassBytesStream(clazz, clazz.getClassLoader()); + } + public static InputStream getClassBytesStream(Class clazz, ClassLoader classLoader) throws IOException + { + return classLoader.getResourceAsStream(getClassFile(clazz)); + } + + } From 21196886096162e40114cc37b7754bf094577159 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 18 Jan 2020 19:43:53 +0700 Subject: [PATCH 158/192] =?UTF-8?q?[FEATURE][EXPERIMENTAL]=20=D0=9D=D0=BE?= =?UTF-8?q?=D0=B2=D0=BE=D0=B5=20API=20=D1=82=D1=80=D0=B0=D0=BD=D1=81=D1=84?= =?UTF-8?q?=D0=BE=D1=80=D0=BC=D0=B0=D1=86=D0=B8=D0=B8=20=D0=BA=D0=BB=D0=B0?= =?UTF-8?q?=D1=81=D1=81=D0=BE=D0=B2=20=D0=BF=D1=80=D0=B8=20=D1=81=D0=B1?= =?UTF-8?q?=D0=BE=D1=80=D0=BA=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launchserver/binary/BuildContext.java | 8 + .../tasks/AdditionalFixesApplyTask.java | 14 -- .../binary/tasks/MainBuildTask.java | 184 +++++++++++------- .../manangers/hook/BuildHookManager.java | 10 - 4 files changed, 126 insertions(+), 90 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BuildContext.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BuildContext.java index 5fa2ca7e..3f8f77a2 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BuildContext.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BuildContext.java @@ -29,6 +29,14 @@ public void pushFile(String filename, InputStream inputStream) throws IOExceptio ZipEntry zip = IOHelper.newZipEntry(filename); output.putNextEntry(zip); IOHelper.transfer(inputStream, output); + output.closeEntry(); + fileList.add(filename); + } + public void pushBytes(String filename, byte[] bytes) throws IOException { + ZipEntry zip = IOHelper.newZipEntry(filename); + output.putNextEntry(zip); + output.write(bytes); + output.closeEntry(); fileList.add(filename); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/AdditionalFixesApplyTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/AdditionalFixesApplyTask.java index b24262e0..eac0696f 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/AdditionalFixesApplyTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/AdditionalFixesApplyTask.java @@ -43,20 +43,6 @@ public Path process(Path inputFile) throws IOException { public static void apply(Path inputFile, Path addFile, ZipOutputStream output, LaunchServer srv, Predicate excluder, boolean needFixes) throws IOException { try (ClassMetadataReader reader = new ClassMetadataReader()) { reader.getCp().add(new JarFile(inputFile.toFile())); - List libs = srv.launcherBinary.coreLibs.stream().map(e -> { - try { - return new JarFile(e.toFile()); - } catch (IOException e1) { - throw new RuntimeException(e1); - } - }).collect(Collectors.toList()); - libs.addAll(srv.launcherBinary.addonLibs.stream().map(e -> { - try { - return new JarFile(e.toFile()); - } catch (IOException e1) { - throw new RuntimeException(e1); - } - }).collect(Collectors.toList())); try (ZipInputStream input = IOHelper.newZipInput(addFile)) { ZipEntry e = input.getNextEntry(); while (e != null) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java index 99190a1a..e06540f3 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java @@ -1,7 +1,10 @@ package pro.gravit.launchserver.binary.tasks; import org.objectweb.asm.ClassReader; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.tree.AnnotationNode; import org.objectweb.asm.tree.ClassNode; +import org.objectweb.asm.tree.FieldNode; import pro.gravit.launcher.AutogenConfig; import pro.gravit.launcher.Launcher; import pro.gravit.launcher.LauncherConfig; @@ -37,27 +40,80 @@ public class MainBuildTask implements LauncherBuildTask { private final LaunchServer server; public final ClassMetadataReader reader; + @FunctionalInterface + public interface Transformer { + byte[] transform(byte[] input, String classname, BuildContext context); + } - private final class RuntimeDirVisitor extends SimpleFileVisitor { + public interface ASMTransformer extends Transformer { + default byte[] transform(byte[] input, String classname, BuildContext context) + { + ClassReader reader = new ClassReader(input); + ClassNode cn = new ClassNode(); + reader.accept(cn, 0); + transform(cn, classname, context); + ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); + cn.accept(writer); + return writer.toByteArray(); + } + void transform(ClassNode cn, String classname, BuildContext context); + } + public abstract static class ASMAnnotationFieldProcessor implements ASMTransformer + { + private final String desc; + + protected ASMAnnotationFieldProcessor(String desc) { + this.desc = desc; + } + + @Override + public void transform(ClassNode cn, String classname, BuildContext context) { + for(FieldNode fn : cn.fields) + { + if(fn.invisibleAnnotations == null || fn.invisibleAnnotations.isEmpty()) continue; + AnnotationNode found = null; + for(AnnotationNode an : fn.invisibleAnnotations) + { + if(an == null) continue; + if(desc.equals(an.desc)) + { + found = an; + break; + } + } + if(found != null) + { + transformField(found, fn, cn, classname, context); + } + } + } + abstract public void transformField(AnnotationNode an, FieldNode fn, ClassNode cn, String classname, BuildContext context); + } + + private final static class RuntimeDirVisitor extends SimpleFileVisitor { private final ZipOutputStream output; - private final Map runtime; + private final Map hashs; + private final Path sourceDir; + private final String targetDir; - private RuntimeDirVisitor(ZipOutputStream output, Map runtime) { + private RuntimeDirVisitor(ZipOutputStream output, Map hashs, Path sourceDir, String targetDir) { this.output = output; - this.runtime = runtime; + this.hashs = hashs; + this.sourceDir = sourceDir; + this.targetDir = targetDir; } @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { - String dirName = IOHelper.toString(server.launcherBinary.runtimeDir.relativize(dir)); + String dirName = IOHelper.toString(sourceDir.relativize(dir)); output.putNextEntry(newEntry(dirName + '/')); return super.preVisitDirectory(dir, attrs); } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { - String fileName = IOHelper.toString(server.launcherBinary.runtimeDir.relativize(file)); - runtime.put(fileName, SecurityHelper.digest(SecurityHelper.DigestAlgorithm.MD5, file)); + String fileName = IOHelper.toString(sourceDir.relativize(file)); + hashs.put(fileName, SecurityHelper.digest(SecurityHelper.DigestAlgorithm.MD5, file)); // Create zip entry and transfer contents output.putNextEntry(newEntry(fileName)); @@ -66,45 +122,13 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO // Return result return super.visitFile(file, attrs); } - } - private final class GuardDirVisitor extends SimpleFileVisitor { - private final ZipOutputStream output; - private final Map guard; - - private GuardDirVisitor(ZipOutputStream output, Map guard) { - this.output = output; - this.guard = guard; - } - - @Override - public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { - String dirName = IOHelper.toString(server.launcherBinary.guardDir.relativize(dir)); - output.putNextEntry(newGuardEntry(dirName + '/')); - return super.preVisitDirectory(dir, attrs); - } - - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { - String fileName = IOHelper.toString(server.launcherBinary.guardDir.relativize(file)); - guard.put(fileName, SecurityHelper.digest(SecurityHelper.DigestAlgorithm.MD5, file)); - - // Create zip entry and transfer contents - output.putNextEntry(newGuardEntry(fileName)); - IOHelper.transfer(file, output); - - // Return result - return super.visitFile(file, attrs); + private ZipEntry newEntry(String fileName) { + return newZipEntry( targetDir + IOHelper.CROSS_SEPARATOR + fileName); } } - - private static ZipEntry newEntry(String fileName) { - return newZipEntry(Launcher.RUNTIME_DIR + IOHelper.CROSS_SEPARATOR + fileName); - } - - private static ZipEntry newGuardEntry(String fileName) { - return newZipEntry(Launcher.GUARD_DIR + IOHelper.CROSS_SEPARATOR + fileName); - } + public Set blacklist = new HashSet<>(); + public List transformers = new ArrayList<>(); public MainBuildTask(LaunchServer srv) { server = srv; @@ -171,13 +195,13 @@ public Path process(Path inputJar) throws IOException { LogHelper.error(e1); } }); - String zPath = launcherConfigurator.getZipEntryPath(); - String sPath = secureConfigurator.getZipEntryPath(); + context.pushBytes(launcherConfigurator.getZipEntryPath(), launcherConfigurator.getBytecode(reader)); + context.pushBytes(secureConfigurator.getZipEntryPath(), secureConfigurator.getBytecode(reader)); try (ZipInputStream input = new ZipInputStream(IOHelper.newInput(inputJar))) { ZipEntry e = input.getNextEntry(); while (e != null) { String filename = e.getName(); - if (server.buildHookManager.isContainsBlacklist(filename) || e.isDirectory() || zPath.equals(filename) || sPath.equals(filename)) { + if (e.isDirectory() || blacklist.contains(filename) || context.fileList.contains(filename)) { e = input.getNextEntry(); continue; } @@ -191,12 +215,8 @@ public Path process(Path inputJar) throws IOException { if (filename.endsWith(".class")) { String classname = filename.replace('/', '.').substring(0, filename.length() - ".class".length()); - byte[] bytes; - try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(2048)) { - IOHelper.transfer(input, outputStream); - bytes = outputStream.toByteArray(); - } - bytes = server.buildHookManager.classTransform(bytes, classname, this); + byte[] bytes = IOHelper.read(input); + bytes = transformClass(bytes, classname, context); output.write(bytes); } else IOHelper.transfer(input, output); @@ -204,17 +224,13 @@ public Path process(Path inputJar) throws IOException { e = input.getNextEntry(); } } - // write additional classes - for (Map.Entry ent : server.buildHookManager.getIncludeClass().entrySet()) { - output.putNextEntry(newZipEntry(JarHelper.getClassFile(ent.getKey()))); - output.write(server.buildHookManager.classTransform(ent.getValue(), ent.getKey(), this)); - } + // map for guard Map runtime = new HashMap<>(256); if (server.buildHookManager.buildRuntime()) { // Write launcher guard dir - IOHelper.walk(server.launcherBinary.runtimeDir, new RuntimeDirVisitor(output, runtime), false); - IOHelper.walk(server.launcherBinary.guardDir, new GuardDirVisitor(output, runtime), false); + IOHelper.walk(server.launcherBinary.runtimeDir, new RuntimeDirVisitor(output, runtime, server.launcherBinary.runtimeDir, "runtime"), false); + IOHelper.walk(server.launcherBinary.guardDir, new RuntimeDirVisitor(output, runtime, server.launcherBinary.guardDir, "guard"), false); } // Create launcher config file byte[] launcherConfigBytes; @@ -229,18 +245,54 @@ public Path process(Path inputJar) throws IOException { // Write launcher config file output.putNextEntry(newZipEntry(Launcher.CONFIG_FILE)); output.write(launcherConfigBytes); - ZipEntry e = newZipEntry(zPath); - output.putNextEntry(e); - output.write(launcherConfigurator.getBytecode(reader)); - - e = newZipEntry(sPath); - output.putNextEntry(e); - output.write(secureConfigurator.getBytecode(reader)); } reader.close(); return outputJar; } + public byte[] transformClass(byte[] bytes, String classname, BuildContext context) + { + byte[] result = bytes; + ClassReader cr = null; + ClassWriter writer = null; + ClassNode cn = null; + for(Transformer t : transformers) + { + if(t instanceof ASMTransformer) + { + ASMTransformer asmTransformer = (ASMTransformer) t; + if(cn == null) + { + cr = new ClassReader(result); + cn = new ClassNode(); + cr.accept(cn, 0); + } + asmTransformer.transform(cn, classname, context); + continue; + } + else if(cn != null) + { + writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); + cn.accept(writer); + result = writer.toByteArray(); + } + byte[] old_result = result; + result = t.transform(result, classname, context); + if(old_result != result) + { + cr = null; + cn = null; + } + } + if(cn != null) + { + writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); + cn.accept(writer); + result = writer.toByteArray(); + } + return result; + } + @Override public boolean allowDelete() { return true; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/hook/BuildHookManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/hook/BuildHookManager.java index 381b8ee9..db810c7d 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/hook/BuildHookManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/hook/BuildHookManager.java @@ -27,13 +27,11 @@ public interface Transformer { private final Set CLASS_TRANSFORMER; private final Set CLASS_BLACKLIST; private final Set MODULE_CLASS; - private final Map INCLUDE_CLASS; public BuildHookManager() { HOOKS = new HashSet<>(4); CLASS_BLACKLIST = new HashSet<>(4); MODULE_CLASS = new HashSet<>(4); - INCLUDE_CLASS = new HashMap<>(4); CLASS_TRANSFORMER = new HashSet<>(4); BUILDRUNTIME = true; autoRegisterIgnoredClass(AutogenConfig.class.getName()); @@ -56,14 +54,6 @@ public byte[] classTransform(byte[] clazz, String classname, MainBuildTask reade return result; } - public void registerIncludeClass(String classname, byte[] classdata) { - INCLUDE_CLASS.put(classname, classdata); - } - - public Map getIncludeClass() { - return INCLUDE_CLASS; - } - public boolean isContainsBlacklist(String clazz) { for (String classB : CLASS_BLACKLIST) { if (clazz.startsWith(classB)) return true; From 4260199de7d417c46c34a2cf0e41071287c26eb0 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 18 Jan 2020 19:51:40 +0700 Subject: [PATCH 159/192] =?UTF-8?q?[FIX]=20=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=83=D0=BF=D0=BE=D0=BC=D0=B8=D0=BD=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B9=20httpclient-x.x.x?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LauncherAuthlib/build.gradle | 1 - ServerWrapper/build.gradle | 1 - 2 files changed, 2 deletions(-) diff --git a/LauncherAuthlib/build.gradle b/LauncherAuthlib/build.gradle index 298105e2..c80e6841 100644 --- a/LauncherAuthlib/build.gradle +++ b/LauncherAuthlib/build.gradle @@ -3,7 +3,6 @@ dependencies { compile project(':LauncherAPI') - compileOnly 'org.apache.httpcomponents:httpclient:4.5.7' compileOnly 'com.google.guava:guava:26.0-jre' compile files('../compat/authlib/authlib-clean.jar') } diff --git a/ServerWrapper/build.gradle b/ServerWrapper/build.gradle index d32120f4..9db86cf6 100644 --- a/ServerWrapper/build.gradle +++ b/ServerWrapper/build.gradle @@ -38,7 +38,6 @@ task javadocJar(type: Jar) { dependencies { pack project(':LauncherAuthlib') - pack 'org.apache.httpcomponents:httpclient:4.5.10' pack 'io.netty:netty-codec-http:4.1.43.Final' } From 93436de104d71579e8e555d2aac35020275f5fac Mon Sep 17 00:00:00 2001 From: Gravit Date: Sun, 19 Jan 2020 11:38:36 +0700 Subject: [PATCH 160/192] =?UTF-8?q?[FEATURE]=20=D0=9D=D0=BE=D0=B2=D0=BE?= =?UTF-8?q?=D0=B5=20API=20=D1=81=D0=B1=D0=BE=D1=80=D0=BA=D0=B8=20=D0=BB?= =?UTF-8?q?=D0=B0=D1=83=D0=BD=D1=87=D0=B5=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launchserver/LaunchServer.java | 5 - .../launchserver/binary/BuildContext.java | 136 ++++++++++++++++- .../binary/tasks/MainBuildTask.java | 137 ++++++------------ .../manangers/hook/BuildHookManager.java | 99 ------------- .../config/JsonConfigurableInterface.java | 10 ++ modules | 2 +- 6 files changed, 189 insertions(+), 200 deletions(-) delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/manangers/hook/BuildHookManager.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java index d3967ea3..251d9374 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java @@ -18,7 +18,6 @@ import pro.gravit.launchserver.manangers.ReconfigurableManager; import pro.gravit.launchserver.manangers.SessionManager; import pro.gravit.launchserver.manangers.hook.AuthHookManager; -import pro.gravit.launchserver.manangers.hook.BuildHookManager; import pro.gravit.launchserver.modules.events.LaunchServerFullInitEvent; import pro.gravit.launchserver.modules.events.LaunchServerInitPhase; import pro.gravit.launchserver.modules.events.LaunchServerPostInitPhase; @@ -226,9 +225,6 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO public final CertificateManager certificateManager; - - public final BuildHookManager buildHookManager; - public final ProguardConf proguardConf; @@ -310,7 +306,6 @@ public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, La } // build hooks, anti-brutforce and other - buildHookManager = new BuildHookManager(); proguardConf = new ProguardConf(this); sessionManager = new SessionManager(); mirrorManager = new MirrorManager(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BuildContext.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BuildContext.java index 3f8f77a2..2adc9a08 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BuildContext.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BuildContext.java @@ -1,28 +1,91 @@ package pro.gravit.launchserver.binary; +import pro.gravit.launcher.Launcher; +import pro.gravit.launcher.serialize.HOutput; +import pro.gravit.launcher.serialize.stream.StreamObject; import pro.gravit.launchserver.binary.tasks.MainBuildTask; import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.JarHelper; +import pro.gravit.utils.helper.LogHelper; +import pro.gravit.utils.helper.SecurityHelper; import java.io.IOException; import java.io.InputStream; +import java.lang.reflect.Type; +import java.net.URL; +import java.nio.file.FileVisitResult; +import java.nio.file.Path; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; import java.util.HashSet; +import java.util.List; +import java.util.Map; import java.util.Set; +import java.util.function.Predicate; +import java.util.jar.JarFile; import java.util.zip.ZipEntry; +import java.util.zip.ZipException; import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; +import static pro.gravit.utils.helper.IOHelper.UNICODE_CHARSET; +import static pro.gravit.utils.helper.IOHelper.newZipEntry; + public class BuildContext { public final ZipOutputStream output; public final LauncherConfigurator config; - public final MainBuildTask data; + public final List readerClassPath; + public final MainBuildTask task; public final HashSet fileList; + public final HashSet clientModules; + + private final static class RuntimeDirVisitor extends SimpleFileVisitor { + private final ZipOutputStream output; + private final Map hashs; + private final Path sourceDir; + private final String targetDir; + + private RuntimeDirVisitor(ZipOutputStream output, Map hashs, Path sourceDir, String targetDir) { + this.output = output; + this.hashs = hashs; + this.sourceDir = sourceDir; + this.targetDir = targetDir; + } + + @Override + public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { + String dirName = IOHelper.toString(sourceDir.relativize(dir)); + output.putNextEntry(newEntry(dirName + '/')); + return super.preVisitDirectory(dir, attrs); + } + + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + String fileName = IOHelper.toString(sourceDir.relativize(file)); + if(hashs != null) + hashs.put(fileName, SecurityHelper.digest(SecurityHelper.DigestAlgorithm.MD5, file)); + + // Create zip entry and transfer contents + output.putNextEntry(newEntry(fileName)); + IOHelper.transfer(file, output); + + // Return result + return super.visitFile(file, attrs); + } + + private ZipEntry newEntry(String fileName) { + return newZipEntry( targetDir + IOHelper.CROSS_SEPARATOR + fileName); + } + } - public BuildContext(ZipOutputStream output, LauncherConfigurator config, MainBuildTask data) { + public BuildContext(ZipOutputStream output, LauncherConfigurator config, List readerClassPath, MainBuildTask task) { this.output = output; this.config = config; - this.data = data; + this.readerClassPath = readerClassPath; + this.task = task; fileList = new HashSet<>(1024); + clientModules = new HashSet<>(); } public void pushFile(String filename, InputStream inputStream) throws IOException { @@ -32,6 +95,26 @@ public void pushFile(String filename, InputStream inputStream) throws IOExceptio output.closeEntry(); fileList.add(filename); } + + public void pushFile(String filename, StreamObject object) throws IOException + { + ZipEntry zip = IOHelper.newZipEntry(filename); + output.putNextEntry(zip); + object.write(new HOutput(output)); + output.closeEntry(); + fileList.add(filename); + } + public void pushFile(String filename, Object object, Type type) throws IOException + { + String bytes = Launcher.gsonManager.gson.toJson(object, type); + pushBytes(filename, bytes.getBytes(UNICODE_CHARSET)); + } + + public void pushDir(Path dir, String targetDir, Map hashMap, boolean hidden) throws IOException + { + IOHelper.walk(dir, new RuntimeDirVisitor(output, hashMap, dir, targetDir), hidden); + } + public void pushBytes(String filename, byte[] bytes) throws IOException { ZipEntry zip = IOHelper.newZipEntry(filename); output.putNextEntry(zip); @@ -39,7 +122,7 @@ public void pushBytes(String filename, byte[] bytes) throws IOException { output.closeEntry(); fileList.add(filename); } - + @Deprecated public void pushJarFile(ZipInputStream input) throws IOException { ZipEntry e = input.getNextEntry(); while (e != null) { @@ -53,7 +136,7 @@ public void pushJarFile(ZipInputStream input) throws IOException { e = input.getNextEntry(); } } - + @Deprecated public void pushJarFile(ZipInputStream input, Set blacklist) throws IOException { ZipEntry e = input.getNextEntry(); while (e != null) { @@ -67,4 +150,47 @@ public void pushJarFile(ZipInputStream input, Set blacklist) throws IOEx e = input.getNextEntry(); } } + public void pushJarFile(Path jarfile, Predicate filter, Predicate needTransform) throws IOException + { + pushJarFile(jarfile.toUri().toURL(), filter, needTransform); + } + public void pushJarFile(URL jarfile, Predicate filter, Predicate needTransform) throws IOException + { + try (ZipInputStream input = new ZipInputStream(IOHelper.newInput(jarfile))) { + ZipEntry e = input.getNextEntry(); + while(e != null) + { + String filename = e.getName(); + if(e.isDirectory() || fileList.contains(filename) || filter.test(e)) + { + e = input.getNextEntry(); + continue; + } + try { + output.putNextEntry(IOHelper.newZipEntry(e)); + } catch (ZipException ex) { + LogHelper.warning("Write %s failed: %s", filename, ex.getMessage() == null ? "null" : ex.getMessage()); + e = input.getNextEntry(); + continue; + } + if (filename.endsWith(".class")) { + String classname = filename.replace('/', '.').substring(0, + filename.length() - ".class".length()); + if(!needTransform.test(classname)) + { + IOHelper.transfer(input, output); + } + else + { + byte[] bytes = IOHelper.read(input); + bytes = task.transformClass(bytes, classname, this); + output.write(bytes); + } + } else + IOHelper.transfer(input, output); + fileList.add(filename); + e = input.getNextEntry(); + } + } + } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java index e06540f3..dbb9ec3c 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java @@ -9,23 +9,20 @@ import pro.gravit.launcher.Launcher; import pro.gravit.launcher.LauncherConfig; import pro.gravit.launcher.SecureAutogenConfig; -import pro.gravit.launcher.serialize.HOutput; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.asm.ClassMetadataReader; import pro.gravit.launchserver.asm.ConfigGenerator; import pro.gravit.launchserver.binary.BuildContext; import pro.gravit.launchserver.binary.LauncherConfigurator; +import pro.gravit.utils.HookException; +import pro.gravit.utils.HookSet; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.JarHelper; import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.SecurityHelper; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.nio.file.FileVisitResult; import java.nio.file.Path; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.attribute.BasicFileAttributes; import java.security.cert.CertificateEncodingException; import java.util.*; import java.util.jar.JarFile; @@ -44,6 +41,38 @@ public class MainBuildTask implements LauncherBuildTask { public interface Transformer { byte[] transform(byte[] input, String classname, BuildContext context); } + public static class IOHookSet { + public final Set> list = new HashSet<>(); + + @FunctionalInterface + public interface IOHook { + /** + * @param context custom param + * False to continue processing hook + * @throws HookException The hook may return the error text throwing this exception + */ + void hook(R context) throws HookException, IOException; + } + + public void registerHook(IOHook hook) { + list.add(hook); + } + + public boolean unregisterHook(IOHook hook) { + return list.remove(hook); + } + + /** + * @param context custom param + * False to continue + * @throws HookException The hook may return the error text throwing this exception + */ + public void hook(R context) throws HookException, IOException { + for (IOHook hook : list) { + hook.hook(context); + } + } + } public interface ASMTransformer extends Transformer { default byte[] transform(byte[] input, String classname, BuildContext context) @@ -89,46 +118,10 @@ public void transform(ClassNode cn, String classname, BuildContext context) { } abstract public void transformField(AnnotationNode an, FieldNode fn, ClassNode cn, String classname, BuildContext context); } - - private final static class RuntimeDirVisitor extends SimpleFileVisitor { - private final ZipOutputStream output; - private final Map hashs; - private final Path sourceDir; - private final String targetDir; - - private RuntimeDirVisitor(ZipOutputStream output, Map hashs, Path sourceDir, String targetDir) { - this.output = output; - this.hashs = hashs; - this.sourceDir = sourceDir; - this.targetDir = targetDir; - } - - @Override - public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { - String dirName = IOHelper.toString(sourceDir.relativize(dir)); - output.putNextEntry(newEntry(dirName + '/')); - return super.preVisitDirectory(dir, attrs); - } - - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { - String fileName = IOHelper.toString(sourceDir.relativize(file)); - hashs.put(fileName, SecurityHelper.digest(SecurityHelper.DigestAlgorithm.MD5, file)); - - // Create zip entry and transfer contents - output.putNextEntry(newEntry(fileName)); - IOHelper.transfer(file, output); - - // Return result - return super.visitFile(file, attrs); - } - - private ZipEntry newEntry(String fileName) { - return newZipEntry( targetDir + IOHelper.CROSS_SEPARATOR + fileName); - } - } public Set blacklist = new HashSet<>(); public List transformers = new ArrayList<>(); + public IOHookSet preBuildHook = new IOHookSet<>(); + public IOHookSet postBuildHook = new IOHookSet<>(); public MainBuildTask(LaunchServer srv) { server = srv; @@ -150,8 +143,8 @@ public Path process(Path inputJar) throws IOException { ClassNode cn1 = new ClassNode(); new ClassReader(JarHelper.getClassBytes(SecureAutogenConfig.class)).accept(cn1, 0); ConfigGenerator secureConfigurator = new ConfigGenerator(cn1); - BuildContext context = new BuildContext(output, launcherConfigurator, this); - server.buildHookManager.hook(context); + BuildContext context = new BuildContext(output, launcherConfigurator, reader.getCp(), this); + preBuildHook.hook(context); launcherConfigurator.setStringField("address", server.config.netty.address); launcherConfigurator.setStringField("projectname", server.config.projectName); launcherConfigurator.setStringField("secretKeyClient", SecurityHelper.randomStringAESKey()); @@ -186,7 +179,7 @@ public Path process(Path inputJar) throws IOException { //LogHelper.debug("[checkSecure] %s: %s", launcherSalt, Arrays.toString(launcherSecureHash)); if (server.runtime.oemUnlockKey == null) server.runtime.oemUnlockKey = SecurityHelper.randomStringToken(); launcherConfigurator.setStringField("oemUnlockKey", server.runtime.oemUnlockKey); - server.buildHookManager.registerAllClientModuleClass(launcherConfigurator); + context.clientModules.forEach(launcherConfigurator::addModuleClass); reader.getCp().add(new JarFile(inputJar.toFile())); server.launcherBinary.coreLibs.forEach(e -> { try { @@ -197,54 +190,18 @@ public Path process(Path inputJar) throws IOException { }); context.pushBytes(launcherConfigurator.getZipEntryPath(), launcherConfigurator.getBytecode(reader)); context.pushBytes(secureConfigurator.getZipEntryPath(), secureConfigurator.getBytecode(reader)); - try (ZipInputStream input = new ZipInputStream(IOHelper.newInput(inputJar))) { - ZipEntry e = input.getNextEntry(); - while (e != null) { - String filename = e.getName(); - if (e.isDirectory() || blacklist.contains(filename) || context.fileList.contains(filename)) { - e = input.getNextEntry(); - continue; - } - try { - output.putNextEntry(IOHelper.newZipEntry(e)); - } catch (ZipException ex) { - LogHelper.error(ex); - e = input.getNextEntry(); - continue; - } - if (filename.endsWith(".class")) { - String classname = filename.replace('/', '.').substring(0, - filename.length() - ".class".length()); - byte[] bytes = IOHelper.read(input); - bytes = transformClass(bytes, classname, context); - output.write(bytes); - } else - IOHelper.transfer(input, output); - context.fileList.add(filename); - e = input.getNextEntry(); - } - } + + context.pushJarFile(inputJar, (e) -> blacklist.contains(e.getName()), (e) -> true); // map for guard Map runtime = new HashMap<>(256); - if (server.buildHookManager.buildRuntime()) { - // Write launcher guard dir - IOHelper.walk(server.launcherBinary.runtimeDir, new RuntimeDirVisitor(output, runtime, server.launcherBinary.runtimeDir, "runtime"), false); - IOHelper.walk(server.launcherBinary.guardDir, new RuntimeDirVisitor(output, runtime, server.launcherBinary.guardDir, "guard"), false); - } - // Create launcher config file - byte[] launcherConfigBytes; - try (ByteArrayOutputStream configArray = IOHelper.newByteArrayOutput()) { - try (HOutput configOutput = new HOutput(configArray)) { - new LauncherConfig(server.config.netty.address, server.publicKey, runtime, server.config.projectName) - .write(configOutput); - } - launcherConfigBytes = configArray.toByteArray(); - } + // Write launcher guard dir + context.pushDir(server.launcherBinary.runtimeDir, Launcher.RUNTIME_DIR, runtime, false); + context.pushDir(server.launcherBinary.guardDir, Launcher.GUARD_DIR, runtime, false); - // Write launcher config file - output.putNextEntry(newZipEntry(Launcher.CONFIG_FILE)); - output.write(launcherConfigBytes); + LauncherConfig launcherConfig = new LauncherConfig(server.config.netty.address, server.publicKey, runtime, server.config.projectName); + context.pushFile(Launcher.CONFIG_FILE, launcherConfig); + postBuildHook.hook(context); } reader.close(); return outputJar; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/hook/BuildHookManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/hook/BuildHookManager.java deleted file mode 100644 index db810c7d..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/hook/BuildHookManager.java +++ /dev/null @@ -1,99 +0,0 @@ -package pro.gravit.launchserver.manangers.hook; - -import pro.gravit.launcher.AutogenConfig; -import pro.gravit.launchserver.binary.BuildContext; -import pro.gravit.launchserver.binary.LauncherConfigurator; -import pro.gravit.launchserver.binary.tasks.MainBuildTask; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -public class BuildHookManager { - - @FunctionalInterface - public interface BuildHook { - void build(BuildContext context); - } - - @FunctionalInterface - public interface Transformer { - byte[] transform(byte[] input, String classname, MainBuildTask data); - } - - private boolean BUILDRUNTIME; - private final Set HOOKS; - private final Set CLASS_TRANSFORMER; - private final Set CLASS_BLACKLIST; - private final Set MODULE_CLASS; - - public BuildHookManager() { - HOOKS = new HashSet<>(4); - CLASS_BLACKLIST = new HashSet<>(4); - MODULE_CLASS = new HashSet<>(4); - CLASS_TRANSFORMER = new HashSet<>(4); - BUILDRUNTIME = true; - autoRegisterIgnoredClass(AutogenConfig.class.getName()); - registerIgnoredClass("META-INF/DEPENDENCIES"); - registerIgnoredClass("META-INF/LICENSE"); - registerIgnoredClass("META-INF/NOTICE"); - } - - public void autoRegisterIgnoredClass(String clazz) { - CLASS_BLACKLIST.add(clazz.replace('.', '/').concat(".class")); - } - - public boolean buildRuntime() { - return BUILDRUNTIME; - } - - public byte[] classTransform(byte[] clazz, String classname, MainBuildTask reader) { - byte[] result = clazz; - for (Transformer transformer : CLASS_TRANSFORMER) result = transformer.transform(result, classname, reader); - return result; - } - - public boolean isContainsBlacklist(String clazz) { - for (String classB : CLASS_BLACKLIST) { - if (clazz.startsWith(classB)) return true; - } - return false; - } - - public void hook(BuildContext context) { - for (BuildHook hook : HOOKS) hook.build(context); - } - - public void registerAllClientModuleClass(LauncherConfigurator cfg) { - for (String clazz : MODULE_CLASS) cfg.addModuleClass(clazz); - } - - public void registerClassTransformer(Transformer transformer) { - CLASS_TRANSFORMER.add(transformer); - } - - public void registerClientModuleClass(String clazz) { - MODULE_CLASS.add(clazz); - } - - public void unregisterClientModuleClass(String clazz) { - MODULE_CLASS.remove(clazz); - } - - public void clearClientModuleClassList() { - MODULE_CLASS.clear(); - } - - public void registerIgnoredClass(String clazz) { - CLASS_BLACKLIST.add(clazz); - } - - public void registerHook(BuildHook hook) { - HOOKS.add(hook); - } - - public void setBuildRuntime(boolean runtime) { - BUILDRUNTIME = runtime; - } -} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/config/JsonConfigurableInterface.java b/LauncherAPI/src/main/java/pro/gravit/launcher/config/JsonConfigurableInterface.java index 31ba780e..3bbe52e2 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/config/JsonConfigurableInterface.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/config/JsonConfigurableInterface.java @@ -29,6 +29,16 @@ default void saveConfig(Gson gson, Path configPath) throws IOException { } } + default String toJsonString(Gson gson) + { + return gson.toJson(getConfig(), getType()); + } + + default String toJsonString() + { + return toJsonString(Launcher.gsonManager.configGson); + } + default void loadConfig(Gson gson, Path configPath) throws IOException { if (generateConfigIfNotExists(configPath)) return; diff --git a/modules b/modules index 9cb09c54..5f6dc831 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 9cb09c549abea86348597137e05a0ec29bc36b62 +Subproject commit 5f6dc8312dcb91b92ee96040830a914d6038773d From f81cdf6440f3adafb22cdb3bddc35f998c6be05e Mon Sep 17 00:00:00 2001 From: Gravit Date: Sun, 19 Jan 2020 12:22:35 +0700 Subject: [PATCH 161/192] =?UTF-8?q?[FEATURE]=20=D0=A3=D0=B4=D0=B0=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20permissionsHandler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launchserver/LaunchServerStarter.java | 2 - .../launchserver/auth/AuthProviderPair.java | 6 +- .../permissions/ConfigPermissionsHandler.java | 26 ----- .../DefaultPermissionsHandler.java | 21 ---- .../HibernatePermissionsHandler.java | 27 ----- .../JsonFilePermissionsHandler.java | 109 ----------------- .../JsonLongFilePermissionsHandler.java | 110 ------------------ .../auth/permissions/PermissionsHandler.java | 30 ----- .../auth/provider/AcceptAuthProvider.java | 3 +- .../auth/provider/AuthProviderResult.java | 5 +- .../auth/provider/HibernateAuthProvider.java | 2 +- .../auth/provider/MySQLAuthProvider.java | 3 +- .../auth/provider/PostgreSQLAuthProvider.java | 2 +- .../auth/provider/RejectAuthProvider.java | 3 +- .../auth/provider/RequestAuthProvider.java | 3 +- .../command/handler/CommandHandler.java | 2 - .../service/GetPermissionsCommand.java | 30 ----- .../service/GivePermissionsCommand.java | 51 -------- .../config/LaunchServerConfig.java | 35 +----- .../manangers/LaunchServerGsonManager.java | 2 - .../socket/response/auth/AuthResponse.java | 2 +- .../pro/gravit/launcher/LauncherInject.java | 1 + modules | 2 +- 23 files changed, 21 insertions(+), 456 deletions(-) delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/ConfigPermissionsHandler.java delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/DefaultPermissionsHandler.java delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/HibernatePermissionsHandler.java delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/JsonLongFilePermissionsHandler.java delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/PermissionsHandler.java delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GetPermissionsCommand.java delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GivePermissionsCommand.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java index 202b9787..9dfe712f 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java @@ -7,7 +7,6 @@ import pro.gravit.launcher.request.auth.AuthRequest; import pro.gravit.launchserver.auth.handler.AuthHandler; import pro.gravit.launchserver.auth.hwid.HWIDHandler; -import pro.gravit.launchserver.auth.permissions.PermissionsHandler; import pro.gravit.launchserver.auth.protect.ProtectHandler; import pro.gravit.launchserver.auth.provider.AuthProvider; import pro.gravit.launchserver.auth.texture.TextureProvider; @@ -211,7 +210,6 @@ public static void registerAll() { AuthProvider.registerProviders(); TextureProvider.registerProviders(); HWIDHandler.registerHandlers(); - PermissionsHandler.registerHandlers(); Component.registerComponents(); ProtectHandler.registerHandlers(); WebSocketService.registerResponses(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java index 908c2f29..f3d136d7 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java @@ -2,6 +2,7 @@ import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.auth.handler.AuthHandler; +import pro.gravit.launchserver.auth.hwid.HWIDHandler; import pro.gravit.launchserver.auth.provider.AuthProvider; import pro.gravit.launchserver.auth.texture.TextureProvider; @@ -11,20 +12,23 @@ public class AuthProviderPair { public final AuthProvider provider; public final AuthHandler handler; public final TextureProvider textureProvider; + public final HWIDHandler hwid; public final String name; public String displayName; public final boolean isDefault = true; - public AuthProviderPair(AuthProvider provider, AuthHandler handler, TextureProvider textureProvider, String name) { + public AuthProviderPair(AuthProvider provider, AuthHandler handler, TextureProvider textureProvider, HWIDHandler hwid, String name) { this.provider = provider; this.handler = handler; this.textureProvider = textureProvider; + this.hwid = hwid; this.name = name; } public void init(LaunchServer srv) { provider.init(srv); handler.init(srv); + hwid.init(); } public void close() throws IOException { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/ConfigPermissionsHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/ConfigPermissionsHandler.java deleted file mode 100644 index c5b1772e..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/ConfigPermissionsHandler.java +++ /dev/null @@ -1,26 +0,0 @@ -package pro.gravit.launchserver.auth.permissions; - -import pro.gravit.launcher.ClientPermissions; - -public class ConfigPermissionsHandler extends PermissionsHandler { - public final boolean isAdmin = false; - public final boolean isServer = false; - - @Override - public ClientPermissions getPermissions(String username) { - ClientPermissions permissions = new ClientPermissions(); - permissions.canServer = isServer; - permissions.canAdmin = isAdmin; - return permissions; - } - - @Override - public void setPermissions(String username, ClientPermissions permissions) { - //Unsupported - } - - @Override - public void close() { - - } -} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/DefaultPermissionsHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/DefaultPermissionsHandler.java deleted file mode 100644 index cca7fc72..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/DefaultPermissionsHandler.java +++ /dev/null @@ -1,21 +0,0 @@ -package pro.gravit.launchserver.auth.permissions; - -import pro.gravit.launcher.ClientPermissions; - -public class DefaultPermissionsHandler extends PermissionsHandler { - - @Override - public ClientPermissions getPermissions(String username) { - return ClientPermissions.DEFAULT; - } - - @Override - public void setPermissions(String username, ClientPermissions permissions) { - //Unsupported - } - - @Override - public void close() { - - } -} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/HibernatePermissionsHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/HibernatePermissionsHandler.java deleted file mode 100644 index 15702db5..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/HibernatePermissionsHandler.java +++ /dev/null @@ -1,27 +0,0 @@ -package pro.gravit.launchserver.auth.permissions; - -import pro.gravit.launcher.ClientPermissions; -import pro.gravit.launchserver.dao.User; - -public class HibernatePermissionsHandler extends PermissionsHandler { - - @Override - public ClientPermissions getPermissions(String username) { - User user = srv.config.dao.userDAO.findByUsername(username); - if (user == null) return ClientPermissions.DEFAULT; - return user.getPermissions(); - } - - @Override - public void setPermissions(String username, ClientPermissions permissions) { - User user = srv.config.dao.userDAO.findByUsername(username); - if (user == null) return; - user.setPermissions(permissions); - srv.config.dao.userDAO.update(user); - } - - @Override - public void close() { - - } -} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java deleted file mode 100644 index 1ca4227e..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java +++ /dev/null @@ -1,109 +0,0 @@ -package pro.gravit.launchserver.auth.permissions; - -import com.google.gson.reflect.TypeToken; -import pro.gravit.launcher.ClientPermissions; -import pro.gravit.launcher.Launcher; -import pro.gravit.launchserver.LaunchServer; -import pro.gravit.launchserver.Reconfigurable; -import pro.gravit.utils.command.Command; -import pro.gravit.utils.command.SubCommand; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.LogHelper; - -import java.io.IOException; -import java.io.Reader; -import java.io.Writer; -import java.lang.reflect.Type; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.HashMap; -import java.util.Map; - -public class JsonFilePermissionsHandler extends PermissionsHandler implements Reconfigurable { - public final String filename = "permissions.json"; - public static Map map; - - - public void reload() { - map.clear(); - Path path = Paths.get(filename); - Type type = new TypeToken>() { - }.getType(); - try (Reader reader = IOHelper.newReader(path)) { - map = Launcher.gsonManager.gson.fromJson(reader, type); - } catch (IOException e) { - LogHelper.error(e); - } - } - - @Override - public void close() { - - } - - @Override - public Map getCommands() { - Map commands = new HashMap<>(); - SubCommand reload = new SubCommand() { - @Override - public void invoke(String... args) { - reload(); - } - }; - commands.put("reload", reload); - commands.put("save", new SubCommand() { - @Override - public void invoke(String... args) { - Path path = Paths.get(filename); - if (!IOHelper.exists(path)) { - try (Writer writer = IOHelper.newWriter(path)) { - Launcher.gsonManager.gson.toJson(map, writer); - } catch (IOException e) { - LogHelper.error(e); - } - } - } - }); - return commands; - } - - public static class Enity { - public String username; - public ClientPermissions permissions; - } - - @Override - public void init(LaunchServer server) { - super.init(server); - Type type = new TypeToken>() { - }.getType(); - Path path = Paths.get(filename); - if (!IOHelper.exists(path)) { - map = new HashMap<>(); - try (Writer writer = IOHelper.newWriter(path)) { - Launcher.gsonManager.gson.toJson(map, writer); - } catch (IOException e) { - LogHelper.error(e); - } - } - try (Reader reader = IOHelper.newReader(path)) { - map = Launcher.gsonManager.gson.fromJson(reader, type); - } catch (IOException e) { - LogHelper.error(e); - } - } - - @Override - public ClientPermissions getPermissions(String username) { - return map.getOrDefault(username, ClientPermissions.DEFAULT); - } - - @Override - public void setPermissions(String username, ClientPermissions permissions) { - map.put(username, permissions); - } - - public JsonFilePermissionsHandler() { - - } -} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/JsonLongFilePermissionsHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/JsonLongFilePermissionsHandler.java deleted file mode 100644 index c908777c..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/JsonLongFilePermissionsHandler.java +++ /dev/null @@ -1,110 +0,0 @@ -package pro.gravit.launchserver.auth.permissions; - -import com.google.gson.reflect.TypeToken; -import pro.gravit.launcher.ClientPermissions; -import pro.gravit.launcher.Launcher; -import pro.gravit.launchserver.LaunchServer; -import pro.gravit.launchserver.Reconfigurable; -import pro.gravit.utils.command.Command; -import pro.gravit.utils.command.SubCommand; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.LogHelper; - -import java.io.IOException; -import java.io.Reader; -import java.io.Writer; -import java.lang.reflect.Type; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.HashMap; -import java.util.Map; - -public class JsonLongFilePermissionsHandler extends PermissionsHandler implements Reconfigurable { - public final String filename = "permissions.json"; - public final long defaultPerms = 0L; - public static Map map; - - - public void reload() { - map.clear(); - Path path = Paths.get(filename); - Type type = new TypeToken>() { - }.getType(); - try (Reader reader = IOHelper.newReader(path)) { - map = Launcher.gsonManager.gson.fromJson(reader, type); - } catch (IOException e) { - LogHelper.error(e); - } - } - - @Override - public void close() { - - } - - @Override - public Map getCommands() { - Map commands = new HashMap<>(); - SubCommand reload = new SubCommand() { - @Override - public void invoke(String... args) { - reload(); - } - }; - commands.put("reload", reload); - commands.put("save", new SubCommand() { - @Override - public void invoke(String... args) { - Path path = Paths.get(filename); - if (!IOHelper.exists(path)) { - try (Writer writer = IOHelper.newWriter(path)) { - Launcher.gsonManager.gson.toJson(map, writer); - } catch (IOException e) { - LogHelper.error(e); - } - } - } - }); - return commands; - } - - public static class Enity { - public String username; - public ClientPermissions permissions; - } - - @Override - public void init(LaunchServer server) { - super.init(server); - Type type = new TypeToken>() { - }.getType(); - Path path = Paths.get(filename); - if (!IOHelper.exists(path)) { - map = new HashMap<>(); - try (Writer writer = IOHelper.newWriter(path)) { - Launcher.gsonManager.gson.toJson(map, writer); - } catch (IOException e) { - LogHelper.error(e); - } - } - try (Reader reader = IOHelper.newReader(path)) { - map = Launcher.gsonManager.gson.fromJson(reader, type); - } catch (IOException e) { - LogHelper.error(e); - } - } - - @Override - public ClientPermissions getPermissions(String username) { - return new ClientPermissions(map.getOrDefault(username, defaultPerms)); - } - - @Override - public void setPermissions(String username, ClientPermissions permissions) { - map.put(username, permissions.toLong()); - } - - public JsonLongFilePermissionsHandler() { - - } -} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/PermissionsHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/PermissionsHandler.java deleted file mode 100644 index 0ab6c4ae..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/permissions/PermissionsHandler.java +++ /dev/null @@ -1,30 +0,0 @@ -package pro.gravit.launchserver.auth.permissions; - -import pro.gravit.launcher.ClientPermissions; -import pro.gravit.launchserver.LaunchServer; -import pro.gravit.utils.ProviderMap; - -public abstract class PermissionsHandler implements AutoCloseable { - public static final ProviderMap providers = new ProviderMap<>("PermissionsHandler"); - protected transient LaunchServer srv; - private static boolean registredHandl = false; - - public static void registerHandlers() { - if (!registredHandl) { - providers.register("json", JsonFilePermissionsHandler.class); - providers.register("json-long", JsonLongFilePermissionsHandler.class); - providers.register("config", ConfigPermissionsHandler.class); - providers.register("default", DefaultPermissionsHandler.class); - providers.register("hibernate", HibernatePermissionsHandler.class); - registredHandl = true; - } - } - - public void init(LaunchServer server) { - this.srv = server; - } - - public abstract ClientPermissions getPermissions(String username); - - public abstract void setPermissions(String username, ClientPermissions permissions); -} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AcceptAuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AcceptAuthProvider.java index 6a820208..d5d9c7e2 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AcceptAuthProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AcceptAuthProvider.java @@ -1,5 +1,6 @@ package pro.gravit.launchserver.auth.provider; +import pro.gravit.launcher.ClientPermissions; import pro.gravit.launcher.request.auth.AuthRequest; import pro.gravit.utils.helper.SecurityHelper; @@ -7,7 +8,7 @@ public final class AcceptAuthProvider extends AuthProvider { @Override public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface password, String ip) { - return new AuthProviderResult(login, SecurityHelper.randomStringToken(), srv); // Same as login + return new AuthProviderResult(login, SecurityHelper.randomStringToken(), ClientPermissions.DEFAULT); // Same as login } @Override diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AuthProviderResult.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AuthProviderResult.java index 291835a1..630ddb1e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AuthProviderResult.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AuthProviderResult.java @@ -1,7 +1,6 @@ package pro.gravit.launchserver.auth.provider; import pro.gravit.launcher.ClientPermissions; -import pro.gravit.launchserver.LaunchServer; public class AuthProviderResult { @@ -9,10 +8,10 @@ public class AuthProviderResult { public final String accessToken; public final ClientPermissions permissions; - public AuthProviderResult(String username, String accessToken, LaunchServer server) { + public AuthProviderResult(String username, String accessToken) { this.username = username; this.accessToken = accessToken; - permissions = server.config.permissionsHandler.getPermissions(username); + permissions = ClientPermissions.DEFAULT; } public AuthProviderResult(String username, String accessToken, ClientPermissions permissions) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/HibernateAuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/HibernateAuthProvider.java index 4f9e19f2..8ce22cef 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/HibernateAuthProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/HibernateAuthProvider.java @@ -26,7 +26,7 @@ public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface p if (user == null) throw new AuthException("Username incorrect"); else throw new AuthException("Username or password incorrect"); } - return new AuthProviderResult(login, SecurityHelper.randomStringToken(), srv); + return new AuthProviderResult(login, SecurityHelper.randomStringToken(), user.getPermissions()); } @Override diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/MySQLAuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/MySQLAuthProvider.java index a5979f28..aae966bf 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/MySQLAuthProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/MySQLAuthProvider.java @@ -20,7 +20,6 @@ public final class MySQLAuthProvider extends AuthProvider { private String query; private String message; private String[] queryParams; - private boolean usePermission; @Override public void init(LaunchServer srv) { @@ -42,7 +41,7 @@ public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface p // Execute SQL query s.setQueryTimeout(MySQLSourceConfig.TIMEOUT); try (ResultSet set = s.executeQuery()) { - return set.next() ? new AuthProviderResult(set.getString(1), SecurityHelper.randomStringToken(), usePermission ? new ClientPermissions(set.getLong(2)) : srv.config.permissionsHandler.getPermissions(set.getString(1))) : authError(message); + return set.next() ? new AuthProviderResult(set.getString(1), SecurityHelper.randomStringToken(), new ClientPermissions(set.getLong(2))) : authError(message); } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/PostgreSQLAuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/PostgreSQLAuthProvider.java index 09390a3f..f85ea7ea 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/PostgreSQLAuthProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/PostgreSQLAuthProvider.java @@ -33,7 +33,7 @@ public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface p // Execute SQL query s.setQueryTimeout(PostgreSQLSourceConfig.TIMEOUT); try (ResultSet set = s.executeQuery()) { - return set.next() ? new AuthProviderResult(set.getString(1), SecurityHelper.randomStringToken(), usePermission ? new ClientPermissions(set.getLong(2)) : srv.config.permissionsHandler.getPermissions(set.getString(1))) : authError(message); + return set.next() ? new AuthProviderResult(set.getString(1), SecurityHelper.randomStringToken(), new ClientPermissions(set.getLong(2))) : authError(message); } } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/RejectAuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/RejectAuthProvider.java index 75882753..aaf60d3b 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/RejectAuthProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/RejectAuthProvider.java @@ -1,5 +1,6 @@ package pro.gravit.launchserver.auth.provider; +import pro.gravit.launcher.ClientPermissions; import pro.gravit.launcher.request.auth.AuthRequest; import pro.gravit.launchserver.Reconfigurable; import pro.gravit.launchserver.auth.AuthException; @@ -28,7 +29,7 @@ public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface p if (whitelist != null) { for (String username : whitelist) { if (login.equals(username)) { - return new AuthProviderResult(login, SecurityHelper.randomStringToken(), srv); + return new AuthProviderResult(login, SecurityHelper.randomStringToken(), ClientPermissions.DEFAULT); } } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/RequestAuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/RequestAuthProvider.java index 09ce4cbf..e0f489bb 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/RequestAuthProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/RequestAuthProvider.java @@ -19,7 +19,6 @@ public final class RequestAuthProvider extends AuthProvider { private String url; private transient Pattern pattern; private String response; - private boolean usePermission; @Override public void init(LaunchServer srv) { @@ -37,7 +36,7 @@ public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface p // Match username Matcher matcher = pattern.matcher(currentResponse); return matcher.matches() && matcher.groupCount() >= 1 ? - new AuthProviderResult(matcher.group("username"), SecurityHelper.randomStringToken(), usePermission ? new ClientPermissions(Long.parseLong(matcher.group("permission"))) : srv.config.permissionsHandler.getPermissions(login)) : + new AuthProviderResult(matcher.group("username"), SecurityHelper.randomStringToken(), new ClientPermissions(Long.parseLong(matcher.group("permission")))) : authError(currentResponse); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java index ab917f10..8a6c032e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java @@ -86,8 +86,6 @@ public static void registerCommands(pro.gravit.utils.command.CommandHandler hand service.registerCommand("multi", new MultiCommand(server)); service.registerCommand("notify", new NotifyCommand(server)); service.registerCommand("component", new ComponentCommand(server)); - service.registerCommand("givePermission", new GivePermissionsCommand(server)); - service.registerCommand("getPermissions", new GetPermissionsCommand(server)); service.registerCommand("clients", new ClientsCommand(server)); service.registerCommand("signJar", new SignJarCommand(server)); service.registerCommand("signDir", new SignDirCommand(server)); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GetPermissionsCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GetPermissionsCommand.java deleted file mode 100644 index 05302816..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GetPermissionsCommand.java +++ /dev/null @@ -1,30 +0,0 @@ -package pro.gravit.launchserver.command.service; - -import pro.gravit.launcher.ClientPermissions; -import pro.gravit.launchserver.LaunchServer; -import pro.gravit.launchserver.command.Command; -import pro.gravit.utils.helper.LogHelper; - -public class GetPermissionsCommand extends Command { - public GetPermissionsCommand(LaunchServer server) { - super(server); - } - - @Override - public String getArgsDescription() { - return "[username]"; - } - - @Override - public String getUsageDescription() { - return "print username permissions"; - } - - @Override - public void invoke(String... args) throws Exception { - verifyArgs(args, 1); - String username = args[0]; - ClientPermissions permissions = server.config.permissionsHandler.getPermissions(username); - LogHelper.info("Permissions %s: %s (long: %d)", username, permissions.toString(), permissions.toLong()); - } -} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GivePermissionsCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GivePermissionsCommand.java deleted file mode 100644 index 6539617d..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GivePermissionsCommand.java +++ /dev/null @@ -1,51 +0,0 @@ -package pro.gravit.launchserver.command.service; - -import pro.gravit.launcher.ClientPermissions; -import pro.gravit.launchserver.LaunchServer; -import pro.gravit.launchserver.command.Command; -import pro.gravit.utils.helper.LogHelper; - -public class GivePermissionsCommand extends Command { - public GivePermissionsCommand(LaunchServer server) { - super(server); - } - - @Override - public String getArgsDescription() { - return "[username] [permission] [true/false]"; - } - - @Override - public String getUsageDescription() { - return "give permissions"; - } - - @Override - public void invoke(String... args) throws Exception { - verifyArgs(args, 3); - String username = args[0]; - ClientPermissions permissions = server.config.permissionsHandler.getPermissions(username); - String permission = args[1]; - boolean isEnabled = Boolean.parseBoolean(args[2]); - switch (permission) { - case "admin": { - permissions.canAdmin = isEnabled; - break; - } - case "server": { - permissions.canServer = isEnabled; - break; - } - case "bot": { - permissions.canBot = isEnabled; - break; - } - default: { - LogHelper.error("Unknown permission: %s", permission); - return; - } - } - LogHelper.info("Write new permissions for %s", username); - server.config.permissionsHandler.setPermissions(username, permissions); - } -} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java index a8d77215..cc43b9e7 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java @@ -8,10 +8,6 @@ import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.auth.handler.MemoryAuthHandler; import pro.gravit.launchserver.auth.hwid.AcceptHWIDHandler; -import pro.gravit.launchserver.auth.hwid.HWIDHandler; -import pro.gravit.launchserver.auth.permissions.DefaultPermissionsHandler; -import pro.gravit.launchserver.auth.permissions.JsonFilePermissionsHandler; -import pro.gravit.launchserver.auth.permissions.PermissionsHandler; import pro.gravit.launchserver.auth.protect.ProtectHandler; import pro.gravit.launchserver.auth.protect.StdProtectHandler; import pro.gravit.launchserver.auth.provider.RejectAuthProvider; @@ -66,8 +62,6 @@ public AuthProviderPair getAuthProviderPair(String name) { public ProtectHandler protectHandler; - public PermissionsHandler permissionsHandler; - public AuthProviderPair getAuthProviderPair() { if (authDefault != null) return authDefault; for (AuthProviderPair pair : auth) { @@ -79,8 +73,6 @@ public AuthProviderPair getAuthProviderPair() { throw new IllegalStateException("Default AuthProviderPair not found"); } - public HWIDHandler hwidHandler; - public Map components; public ExeConf launch4j; @@ -123,9 +115,6 @@ public void verify() { if (!isOneDefault) { throw new IllegalStateException("No auth pairs declared by default."); } - if (permissionsHandler == null) { - throw new NullPointerException("PermissionsHandler must not be null"); - } if (env == null) { throw new NullPointerException("Env must not be null"); } @@ -139,8 +128,6 @@ public void init(LaunchServer.ReloadType type) { for (AuthProviderPair provider : auth) { provider.init(server); } - permissionsHandler.init(server); - hwidHandler.init(); if (dao != null) dao.init(server); if (protectHandler != null) { @@ -149,13 +136,12 @@ public void init(LaunchServer.ReloadType type) { if (components != null) { components.forEach((k, v) -> server.registerObject("component.".concat(k), v)); } - server.registerObject("permissionsHandler", permissionsHandler); - server.registerObject("hwidHandler", hwidHandler); if (!type.equals(LaunchServer.ReloadType.NO_AUTH)) { for (AuthProviderPair pair : auth) { server.registerObject("auth.".concat(pair.name).concat(".provider"), pair.provider); server.registerObject("auth.".concat(pair.name).concat(".handler"), pair.handler); server.registerObject("auth.".concat(pair.name).concat(".texture"), pair.textureProvider); + server.registerObject("auth.".concat(pair.name).concat(".hwid"), pair.hwid); } } @@ -165,13 +151,12 @@ public void init(LaunchServer.ReloadType type) { public void close(LaunchServer.ReloadType type) { try { - server.unregisterObject("permissionsHandler", permissionsHandler); - server.unregisterObject("hwidHandler", hwidHandler); if (!type.equals(LaunchServer.ReloadType.NO_AUTH)) { for (AuthProviderPair pair : auth) { server.unregisterObject("auth.".concat(pair.name).concat(".provider"), pair.provider); server.unregisterObject("auth.".concat(pair.name).concat(".handler"), pair.handler); server.unregisterObject("auth.".concat(pair.name).concat(".texture"), pair.textureProvider); + server.unregisterObject("auth.".concat(pair.name).concat(".hwid"), pair.hwid); } } if (type.equals(LaunchServer.ReloadType.FULL)) { @@ -194,16 +179,6 @@ public void close(LaunchServer.ReloadType type) { } catch (IOException e) { LogHelper.error(e); } - try { - hwidHandler.close(); - } catch (Exception e) { - LogHelper.error(e); - } - try { - permissionsHandler.close(); - } catch (Exception e) { - LogHelper.error(e); - } } public static class ExeConf { @@ -305,17 +280,13 @@ public static LaunchServerConfig getDefault(LaunchServer.LaunchServerEnv env) { newConfig.launch4j.maxVersion = "1.8.999"; newConfig.env = LauncherConfig.LauncherEnvironment.STD; newConfig.startScript = JVMHelper.OS_TYPE.equals(JVMHelper.OS.MUSTDIE) ? "." + File.separator + "start.bat" : "." + File.separator + "start.sh"; - newConfig.hwidHandler = new AcceptHWIDHandler(); newConfig.auth = new AuthProviderPair[]{new AuthProviderPair(new RejectAuthProvider("Настройте authProvider"), new MemoryAuthHandler(), new RequestTextureProvider("http://example.com/skins/%username%.png", "http://example.com/cloaks/%username%.png") - , "std")}; + , new AcceptHWIDHandler(), "std")}; newConfig.auth[0].displayName = "Default"; newConfig.protectHandler = new StdProtectHandler(); if (env.equals(LaunchServer.LaunchServerEnv.TEST)) - newConfig.permissionsHandler = new DefaultPermissionsHandler(); - else - newConfig.permissionsHandler = new JsonFilePermissionsHandler(); newConfig.binaryName = "Launcher"; newConfig.whitelistRejectString = "Вас нет в белом списке"; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java index bf39128f..13693bfe 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java @@ -10,7 +10,6 @@ import pro.gravit.launcher.request.auth.AuthRequest; import pro.gravit.launchserver.auth.handler.AuthHandler; import pro.gravit.launchserver.auth.hwid.HWIDHandler; -import pro.gravit.launchserver.auth.permissions.PermissionsHandler; import pro.gravit.launchserver.auth.protect.ProtectHandler; import pro.gravit.launchserver.auth.provider.AuthProvider; import pro.gravit.launchserver.auth.texture.TextureProvider; @@ -34,7 +33,6 @@ public void registerAdapters(GsonBuilder builder) { builder.registerTypeAdapter(AuthProvider.class, new UniversalJsonAdapter<>(AuthProvider.providers)); builder.registerTypeAdapter(TextureProvider.class, new UniversalJsonAdapter<>(TextureProvider.providers)); builder.registerTypeAdapter(AuthHandler.class, new UniversalJsonAdapter<>(AuthHandler.providers)); - builder.registerTypeAdapter(PermissionsHandler.class, new UniversalJsonAdapter<>(PermissionsHandler.providers)); builder.registerTypeAdapter(HWIDHandler.class, new UniversalJsonAdapter<>(HWIDHandler.providers)); builder.registerTypeAdapter(Component.class, new UniversalJsonAdapter<>(Component.providers)); builder.registerTypeAdapter(ProtectHandler.class, new UniversalJsonAdapter<>(ProtectHandler.providers)); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java index f50fc1fc..31832e91 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java @@ -97,7 +97,7 @@ public void execute(ChannelHandlerContext ctx, Client clientData) throws Excepti // throw new AuthException("You profile not found"); //} if (authType == ConnectTypes.CLIENT) - server.config.hwidHandler.check(hwid, aresult.username); + pair.hwid.check(hwid, aresult.username); server.authHookManager.postHook.hook(context, clientData); clientData.isAuth = true; clientData.permissions = aresult.permissions; diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/LauncherInject.java b/LauncherCore/src/main/java/pro/gravit/launcher/LauncherInject.java index b11647c1..cee89fe0 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/LauncherInject.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/LauncherInject.java @@ -10,4 +10,5 @@ @Target(FIELD) public @interface LauncherInject { public String value(); // target of inject + } diff --git a/modules b/modules index 5f6dc831..e84f2b9f 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 5f6dc8312dcb91b92ee96040830a914d6038773d +Subproject commit e84f2b9f96aab1036cf38c466d2ef3c797a2acfe From 952901742805813708066785649704e8bbadb949 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sun, 19 Jan 2020 13:50:48 +0700 Subject: [PATCH 162/192] =?UTF-8?q?[FEATURE]=20AuthProviderPair=20=D0=BB?= =?UTF-8?q?=D0=B8=D0=BD=D0=BA=D0=BE=D0=B2=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launchserver/auth/AuthProviderPair.java | 46 +++++++++++++++++-- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java index f3d136d7..592f9462 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java @@ -7,12 +7,15 @@ import pro.gravit.launchserver.auth.texture.TextureProvider; import java.io.IOException; +import java.util.HashMap; +import java.util.Map; public class AuthProviderPair { - public final AuthProvider provider; - public final AuthHandler handler; - public final TextureProvider textureProvider; - public final HWIDHandler hwid; + public AuthProvider provider; + public AuthHandler handler; + public TextureProvider textureProvider; + public HWIDHandler hwid; + public Map links; public final String name; public String displayName; public final boolean isDefault = true; @@ -26,10 +29,45 @@ public AuthProviderPair(AuthProvider provider, AuthHandler handler, TextureProvi } public void init(LaunchServer srv) { + if(links != null) link(srv); + if(provider == null) throw new NullPointerException(String.format("Auth %s provider null", name)); + if(handler == null) throw new NullPointerException(String.format("Auth %s handler null", name)); + if(textureProvider == null) throw new NullPointerException(String.format("Auth %s textureProvider null", name)); + if(hwid == null) throw new NullPointerException(String.format("Auth %s hwid null", name)); provider.init(srv); handler.init(srv); hwid.init(); } + public void link(LaunchServer srv) + { + links.forEach((k,v) -> { + AuthProviderPair pair = srv.config.getAuthProviderPair(v); + if(pair == null) + { + throw new NullPointerException(String.format("Auth %s link failed. Pair %s not found", name, v)); + } + if("provider".equals(k)) + { + if(pair.provider == null) throw new NullPointerException(String.format("Auth %s link failed. %s.provider is null", name, v)); + provider = pair.provider; + } + else if("handler".equals(k)) + { + if(pair.handler == null) throw new NullPointerException(String.format("Auth %s link failed. %s.handler is null", name, v)); + handler = pair.handler; + } + else if("textureProvider".equals(k)) + { + if(pair.textureProvider == null) throw new NullPointerException(String.format("Auth %s link failed. %s.textureProvider is null", name, v)); + textureProvider = pair.textureProvider; + } + else if("hwid".equals(k)) + { + if(pair.hwid == null) throw new NullPointerException(String.format("Auth %s link failed. %s.hwid is null", name, v)); + hwid = pair.hwid; + } + }); + } public void close() throws IOException { provider.close(); From 60b7a06fa33ab7b3a7aaf624e97aa0bd15369737 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sun, 19 Jan 2020 13:53:15 +0700 Subject: [PATCH 163/192] =?UTF-8?q?[FIX]=20final=20=D0=B2=20MysqlHWIDHandl?= =?UTF-8?q?er?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java index a68d210d..0c062974 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java @@ -37,10 +37,10 @@ public class MysqlHWIDHandler extends HWIDHandler { private String banMessage; - private final boolean compareMode = false; + private boolean compareMode = false; //Using queryHWID "queryHwids": "SELECT * FROM `users_hwids` WHERE `totalMemory` = ? or `serialNumber` = ? or `HWDiskSerial` = ? or `processorID` = ? or `MACAddr` = ?" - private final int compare = 50; //При наборе схожести в 50 очков - private final boolean oneCompareMode = false; + private int compare = 50; //При наборе схожести в 50 очков + private boolean oneCompareMode = false; /* //Добавить поля hwid в базу с пользователями From d4c4197e8eecb43191a97addc05dced4fd49f8dc Mon Sep 17 00:00:00 2001 From: Gravit Date: Sun, 19 Jan 2020 13:59:03 +0700 Subject: [PATCH 164/192] =?UTF-8?q?[ANY]=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index e84f2b9f..417a761c 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit e84f2b9f96aab1036cf38c466d2ef3c797a2acfe +Subproject commit 417a761cf52636316b0f39fc3e186cc52503c3fc From 6ec2c035cfd63d5ee84acf9658ed22786d66c87b Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 20 Jan 2020 12:21:59 +0700 Subject: [PATCH 165/192] =?UTF-8?q?[FIX]=20NPE=20=D0=B2=20ServerWrapper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/pro/gravit/launcher/server/ServerWrapper.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java index 3df2bc50..a81b9f1f 100644 --- a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java +++ b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java @@ -27,6 +27,7 @@ import java.net.URL; import java.nio.file.Path; import java.nio.file.Paths; +import java.security.AuthProvider; import java.security.interfaces.ECPublicKey; import java.security.spec.InvalidKeySpecException; import java.util.Arrays; @@ -104,6 +105,7 @@ public static void initGson(ServerWrapperModulesManager modulesManager) { public void run(String... args) throws Throwable { initGson(modulesManager); + AuthRequest.registerProviders(); if (args.length > 0 && args[0].equals("setup") && !disableSetup) { LogHelper.debug("Read ServerWrapperConfig.json"); loadConfig(); From ef6616dfda95fb61379a314c05c183001005cb39 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Wed, 22 Jan 2020 14:21:56 +0100 Subject: [PATCH 166/192] =?UTF-8?q?[FIX]=20InjectClassAcceptor,=20=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D0=B0=D0=BB=D1=81=D1=8F=20=D1=81=D0=B5=D1=80=D0=B8?= =?UTF-8?q?=D0=B0=D0=BB=D0=B8=D0=B7=20Map?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launchserver/asm/InjectClassAcceptor.java | 158 ++++++++++++++++-- .../pro/gravit/launchserver/dao/UserDAO.java | 2 - .../dao/impl/HibernateHwidDAOImpl.java | 1 - .../dao/impl/HibernateUserDAOImpl.java | 3 - .../launchserver/dao/impl/UserHWIDImpl.java | 1 - .../LauncherInjectionConstructor.java | 13 ++ 6 files changed, 157 insertions(+), 21 deletions(-) create mode 100644 LauncherCore/src/main/java/pro/gravit/launcher/LauncherInjectionConstructor.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java index 7cb5621b..be720dfb 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java @@ -1,33 +1,57 @@ package pro.gravit.launchserver.asm; import java.util.Arrays; +import java.util.Base64; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.Collectors; import org.objectweb.asm.AnnotationVisitor; import org.objectweb.asm.Opcodes; import org.objectweb.asm.Type; import org.objectweb.asm.tree.AnnotationNode; import org.objectweb.asm.tree.ClassNode; +import org.objectweb.asm.tree.FieldInsnNode; +import org.objectweb.asm.tree.FieldNode; +import org.objectweb.asm.tree.InsnList; +import org.objectweb.asm.tree.InsnNode; +import org.objectweb.asm.tree.LdcInsnNode; +import org.objectweb.asm.tree.MethodInsnNode; +import org.objectweb.asm.tree.MethodNode; +import org.objectweb.asm.tree.TypeInsnNode; +import org.objectweb.asm.tree.VarInsnNode; +import pro.gravit.launchserver.binary.BuildContext; +import pro.gravit.launchserver.binary.tasks.MainBuildTask; import pro.gravit.launcher.LauncherInject; +import pro.gravit.launcher.LauncherInjectionConstructor; -public class InjectClassAcceptor { - public static final Class[] primitives = new Class[] { java.lang.Boolean.class, java.lang.Character.class, - java.lang.Byte.class, java.lang.Short.class, java.lang.Integer.class, java.lang.Long.class, - java.lang.Float.class, java.lang.Double.class, java.lang.String.class }; +public class InjectClassAcceptor implements MainBuildTask.ASMTransformer { + private final Map values; - public static final List> zPrimitivesList = Arrays.asList(primitives); - public static final String INJ_DESC = Type.getDescriptor(LauncherInject.class); - - public static void checkMap(Map object) { - if (!zPrimitivesList.containsAll(object.values())) - throw new IllegalArgumentException("Only primitives in values..."); + public InjectClassAcceptor(Map values) { + this.values = values; } + private static final List> zPrimitivesList = Arrays.asList(java.lang.Boolean.class, java.lang.Character.class, + java.lang.Byte.class, java.lang.Short.class, java.lang.Integer.class, java.lang.Long.class, + java.lang.Float.class, java.lang.Double.class, java.lang.String.class); + private static final String INJ_DESC = Type.getDescriptor(LauncherInject.class); + private static final String INJ_C_DESC = Type.getDescriptor(LauncherInjectionConstructor.class); + private static final List cPrimitivesList = Arrays.asList("I", "V", "Z", "B", "C", "S", "D", "F", "J", Type.getDescriptor(String.class)); - public static void visit(ClassNode cn, Map object) { - cn.fields.stream().filter(e -> e.invisibleAnnotations != null) + private static void visit(ClassNode cn, Map object) { + MethodNode clinit = cn.methods.stream().filter(methodNode -> + "".equals(methodNode.name)).findFirst().orElseGet(() -> { + MethodNode ret = new MethodNode(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC | Opcodes.ACC_SYNTHETIC, "", "()V", null, null); + ret.instructions.add(new InsnNode(Opcodes.RETURN)); + cn.methods.add(ret); + return ret; + }); + List constructors = cn.methods.stream().filter(e -> "".equals(e.name)).collect(Collectors.toList()); + MethodNode init = constructors.stream().filter(e -> e.invisibleAnnotations.stream().filter(f -> INJ_C_DESC.equals(f.desc)).findFirst() + .isPresent()).findFirst().orElseGet(() -> constructors.stream().filter(e -> e.desc.equals("()V")).findFirst().orElse(null)); + cn.fields.stream().filter(e -> e.invisibleAnnotations != null) .filter(e -> !e.invisibleAnnotations.isEmpty() && e.invisibleAnnotations.stream().anyMatch(f -> f.desc.equals(INJ_DESC))).forEach(e -> { // Notice that fields that will be used with this algo should not have default // value by = ...; @@ -47,8 +71,114 @@ public void visit(final String name, final Object value) { }); if (valueName.get() == null) throw new IllegalArgumentException("Annotation should always contains 'value' key"); - if (object.containsKey(valueName.get())) - e.value = object.get(valueName.get()); + if (object.containsKey(valueName.get())) { + Object val = object.get(valueName.get()); + if ((e.access & Opcodes.ACC_STATIC) != 0) + if (cPrimitivesList.contains(e.desc) && zPrimitivesList.contains(val.getClass())) + e.value = val; + else { + List nodes = Arrays.stream(clinit.instructions.toArray()).filter(p -> p instanceof FieldInsnNode && p.getOpcode() == Opcodes.PUTSTATIC).map(p -> (FieldInsnNode) p) + .filter(p -> p.owner.equals(cn.name) && p.name.equals(e.name) && p.desc.equals(e.desc)).collect(Collectors.toList()); + InsnList injector = new InsnList(); + pushInjector(injector, val, e); + if (nodes.isEmpty()) { + injector.insert(new InsnNode(Opcodes.ICONST_0)); + injector.add(new FieldInsnNode(Opcodes.PUTSTATIC, cn.name, e.name, e.desc)); + Arrays.stream(clinit.instructions.toArray()).filter(p -> p.getOpcode() == Opcodes.RETURN).forEach(p -> clinit.instructions.insertBefore(p, injector)); + } else + for (FieldInsnNode node : nodes) clinit.instructions.insertBefore(node, injector); + } + else { + if (init == null) throw new IllegalArgumentException("Not found init in target: " + cn.name); + List nodes = Arrays.stream(init.instructions.toArray()).filter(p -> p instanceof FieldInsnNode && p.getOpcode() == Opcodes.PUTFIELD).map(p -> (FieldInsnNode) p) + .filter(p -> p.owner.equals(cn.name) && p.name.equals(e.name) && p.desc.equals(e.desc)).collect(Collectors.toList()); + InsnList injector = new InsnList(); + pushInjector(injector, val, e); + if (nodes.isEmpty()) { + injector.insert(new VarInsnNode(Opcodes.ALOAD, 0)); + injector.insert(new InsnNode(Opcodes.ICONST_0)); + injector.add(new FieldInsnNode(Opcodes.PUTSTATIC, cn.name, e.name, e.desc)); + Arrays.stream(init.instructions.toArray()).filter(p -> p.getOpcode() == Opcodes.RETURN).forEach(p -> clinit.instructions.insertBefore(p, injector)); + } else + for (FieldInsnNode node : nodes) init.instructions.insertBefore(node, injector); + } + } }); } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + private static void pushInjector(InsnList injector, Object val, FieldNode e) { + injector.add(new InsnNode(Opcodes.POP)); + if (e.desc.equals("Z")) { + if ((Boolean) val) injector.add(new InsnNode(Opcodes.ICONST_1)); + else injector.add(new InsnNode(Opcodes.ICONST_0)); + } else if (e.desc.equals("C")) { + injector.add(NodeUtils.push(((Number) val).intValue())); + injector.add(new InsnNode(Opcodes.I2C)); + } else if (e.desc.equals("B")) { + injector.add(NodeUtils.push(((Number) val).intValue())); + injector.add(new InsnNode(Opcodes.I2B)); + } else if (e.desc.equals("S")) { + injector.add(NodeUtils.push(((Number) val).intValue())); + injector.add(new InsnNode(Opcodes.I2S)); + } else if (e.desc.equals("I")) { + injector.add(NodeUtils.push(((Number) val).intValue())); + } else if (e.desc.equals("[B")) { + serializebArr(injector, (byte[]) val); + } else if (e.desc.equals("Ljava/util/List;")) { + if (((List) val).isEmpty()) { + injector.add(new TypeInsnNode(Opcodes.NEW, "java/util/ArrayList")); + injector.add(new InsnNode(Opcodes.DUP)); + injector.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/util/ArrayList", "", "()V")); + } else { + Class c = ((List) val).get(0).getClass(); + if (c == byte[].class) + serializeListbArr(injector, (List) val); + else if (c == String.class) + serializeListString(injector, (List) val); + else + throw new UnsupportedOperationException("Unsupported class" + c.getName()); + } + } else { + if (!cPrimitivesList.contains(e.desc) || !zPrimitivesList.contains(val.getClass())) + throw new UnsupportedOperationException("Unsupported class"); + injector.add(new LdcInsnNode(val)); + } + // TODO Map + } + + private static void serializebArr(InsnList injector, byte[] val) { + injector.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/util/Base64", "getDecoder", "()Ljava/util/Base64$Decoder;", false)); + injector.add(NodeUtils.getSafeStringInsnList(Base64.getEncoder().encodeToString(val))); + injector.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/util/Base64$Decoder", "decode", "(Ljava/lang/String;)[B", false)); + } + + private static void serializeListbArr(InsnList inj, List val) { + inj.add(new TypeInsnNode(Opcodes.NEW, "java/util/ArrayList")); + inj.add(new InsnNode(Opcodes.DUP)); // +1 + inj.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/util/ArrayList", "", "()V")); + for (byte[] value : val) { + inj.add(new InsnNode(Opcodes.DUP)); // +1-1 + serializebArr(inj, value); + inj.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", true)); + inj.add(new InsnNode(Opcodes.POP)); + } + } + + private static void serializeListString(InsnList inj, List val) { + inj.add(new TypeInsnNode(Opcodes.NEW, "java/util/ArrayList")); + inj.add(new InsnNode(Opcodes.DUP)); // +1 + inj.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/util/ArrayList", "", "()V")); + for (String value : val) { + inj.add(new InsnNode(Opcodes.DUP)); // +1-1 + inj.add(NodeUtils.getSafeStringInsnList(value)); + inj.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", true)); + inj.add(new InsnNode(Opcodes.POP)); + } + } + + @Override + public void transform(ClassNode cn, String classname, BuildContext context) { + visit(cn, values); + } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserDAO.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserDAO.java index 85987e85..aaec8520 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserDAO.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserDAO.java @@ -1,7 +1,5 @@ package pro.gravit.launchserver.dao; -import pro.gravit.launcher.hwid.HWID; - import java.util.List; import java.util.UUID; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/HibernateHwidDAOImpl.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/HibernateHwidDAOImpl.java index 037e25cc..97c29082 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/HibernateHwidDAOImpl.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/HibernateHwidDAOImpl.java @@ -6,7 +6,6 @@ import pro.gravit.launcher.hwid.HWID; import pro.gravit.launcher.hwid.OshiHWID; import pro.gravit.launchserver.dao.HwidDAO; -import pro.gravit.launchserver.dao.User; import pro.gravit.launchserver.dao.UserHWID; import javax.persistence.EntityManager; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/HibernateUserDAOImpl.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/HibernateUserDAOImpl.java index 03c8bd5a..e11fe09d 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/HibernateUserDAOImpl.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/HibernateUserDAOImpl.java @@ -3,11 +3,8 @@ import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; -import pro.gravit.launcher.hwid.HWID; -import pro.gravit.launcher.hwid.OshiHWID; import pro.gravit.launchserver.dao.User; import pro.gravit.launchserver.dao.UserDAO; -import pro.gravit.launchserver.dao.UserHWID; import javax.persistence.EntityManager; import javax.persistence.criteria.CriteriaBuilder; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/UserHWIDImpl.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/UserHWIDImpl.java index 7cc39c0e..8c1b14dd 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/UserHWIDImpl.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/UserHWIDImpl.java @@ -1,6 +1,5 @@ package pro.gravit.launchserver.dao.impl; -import pro.gravit.launcher.hwid.HWID; import pro.gravit.launcher.hwid.OshiHWID; import pro.gravit.launchserver.dao.UserHWID; diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/LauncherInjectionConstructor.java b/LauncherCore/src/main/java/pro/gravit/launcher/LauncherInjectionConstructor.java new file mode 100644 index 00000000..4f9d4b56 --- /dev/null +++ b/LauncherCore/src/main/java/pro/gravit/launcher/LauncherInjectionConstructor.java @@ -0,0 +1,13 @@ +package pro.gravit.launcher; + +import static java.lang.annotation.ElementType.CONSTRUCTOR; +import static java.lang.annotation.RetentionPolicy.CLASS; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +@Retention(CLASS) +@Target(CONSTRUCTOR) +public @interface LauncherInjectionConstructor { + +} From b4a75b9076cbaf5d3103749521a53073a011411f Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Wed, 22 Jan 2020 14:33:08 +0100 Subject: [PATCH 167/192] =?UTF-8?q?[FIX]=20=D0=9F=D0=BE=D0=B4=D0=B4=D0=B5?= =?UTF-8?q?=D1=80=D0=B6=D0=BA=D0=B0=20=D1=81=D0=B5=D1=80=D0=B8=D0=B0=D0=BB?= =?UTF-8?q?=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D0=B8=20=D1=81=20=D0=B0=D0=BD?= =?UTF-8?q?=D0=BD=D0=BE=D1=82=D0=B0=D1=86=D0=B8=D0=B5=D0=B9=20LauncherInje?= =?UTF-8?q?ct=20Map?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launchserver/asm/InjectClassAcceptor.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java index be720dfb..b680b94e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java @@ -139,12 +139,26 @@ else if (c == String.class) else throw new UnsupportedOperationException("Unsupported class" + c.getName()); } + } else if (e.desc.equals("Ljava/util/Map;")) { + serializeMap(injector, (Map) val); } else { if (!cPrimitivesList.contains(e.desc) || !zPrimitivesList.contains(val.getClass())) throw new UnsupportedOperationException("Unsupported class"); injector.add(new LdcInsnNode(val)); } - // TODO Map + } + + private static void serializeMap(InsnList inj, Map map) { + inj.add(new TypeInsnNode(Opcodes.NEW, "java/util/HashMap")); + inj.add(new InsnNode(Opcodes.DUP)); // +1 + inj.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/util/HashMap", "", "()V")); + map.forEach((k, v) -> { + inj.add(new InsnNode(Opcodes.DUP)); // +1-1 + inj.add(NodeUtils.getSafeStringInsnList(k)); + inj.add(NodeUtils.getSafeStringInsnList(v)); + inj.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, "java/util/Map", "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", true)); + inj.add(new InsnNode(Opcodes.POP)); + }); } private static void serializebArr(InsnList injector, byte[] val) { From 667fb21e9b22a01ddd745add7d9e645f4de45e33 Mon Sep 17 00:00:00 2001 From: Gravit Date: Fri, 24 Jan 2020 09:57:04 +0700 Subject: [PATCH 168/192] =?UTF-8?q?[FIX]=20=D0=A4=D0=B8=D0=BA=D1=81=D1=8B?= =?UTF-8?q?=20InjectClassAcceptor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launchserver/asm/InjectClassAcceptor.java | 5 +++-- .../pro/gravit/launchserver/binary/tasks/MainBuildTask.java | 5 +++++ .../java/pro/gravit/launchserver/ASMTransformersTest.java | 4 +++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java index b680b94e..a9bd36a7 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java @@ -49,14 +49,15 @@ private static void visit(ClassNode cn, Map object) { return ret; }); List constructors = cn.methods.stream().filter(e -> "".equals(e.name)).collect(Collectors.toList()); - MethodNode init = constructors.stream().filter(e -> e.invisibleAnnotations.stream().filter(f -> INJ_C_DESC.equals(f.desc)).findFirst() - .isPresent()).findFirst().orElseGet(() -> constructors.stream().filter(e -> e.desc.equals("()V")).findFirst().orElse(null)); + MethodNode init = constructors.stream().filter(e -> e != null && e.invisibleAnnotations != null && e.invisibleAnnotations.stream().anyMatch(f -> INJ_C_DESC.equals(f.desc))).findFirst() + .orElseGet(() -> constructors.stream().filter(e -> e.desc.equals("()V")).findFirst().orElse(null)); cn.fields.stream().filter(e -> e.invisibleAnnotations != null) .filter(e -> !e.invisibleAnnotations.isEmpty() && e.invisibleAnnotations.stream().anyMatch(f -> f.desc.equals(INJ_DESC))).forEach(e -> { // Notice that fields that will be used with this algo should not have default // value by = ...; AnnotationNode n = e.invisibleAnnotations.stream().filter(f -> INJ_DESC.equals(f.desc)).findFirst() .get(); + e.invisibleAnnotations.removeIf(f -> INJ_DESC.equals(f.desc)); AtomicReference valueName = new AtomicReference<>(null); n.accept(new AnnotationVisitor(Opcodes.ASM7) { @Override diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java index dbb9ec3c..9209667c 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java @@ -12,6 +12,7 @@ import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.asm.ClassMetadataReader; import pro.gravit.launchserver.asm.ConfigGenerator; +import pro.gravit.launchserver.asm.InjectClassAcceptor; import pro.gravit.launchserver.binary.BuildContext; import pro.gravit.launchserver.binary.LauncherConfigurator; import pro.gravit.utils.HookException; @@ -123,9 +124,13 @@ public void transform(ClassNode cn, String classname, BuildContext context) { public IOHookSet preBuildHook = new IOHookSet<>(); public IOHookSet postBuildHook = new IOHookSet<>(); + public Map properties = new HashMap<>(); + public MainBuildTask(LaunchServer srv) { server = srv; reader = new ClassMetadataReader(); + InjectClassAcceptor injectClassAcceptor = new InjectClassAcceptor(properties); + transformers.add(injectClassAcceptor); } @Override diff --git a/LaunchServer/src/test/java/pro/gravit/launchserver/ASMTransformersTest.java b/LaunchServer/src/test/java/pro/gravit/launchserver/ASMTransformersTest.java index f9909fd8..25223c62 100644 --- a/LaunchServer/src/test/java/pro/gravit/launchserver/ASMTransformersTest.java +++ b/LaunchServer/src/test/java/pro/gravit/launchserver/ASMTransformersTest.java @@ -8,6 +8,7 @@ import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.FieldNode; import pro.gravit.launcher.LauncherInject; +import pro.gravit.launcher.LauncherInjectionConstructor; import pro.gravit.launchserver.asm.InjectClassAcceptor; import pro.gravit.utils.PublicURLClassLoader; import pro.gravit.utils.helper.JarHelper; @@ -48,7 +49,8 @@ void testASM() throws Exception node.name = "ASMTestClass"; Map map = new HashMap<>(); map.put("testprop", 1234); - InjectClassAcceptor.visit(node, map); + InjectClassAcceptor injectClassAcceptor = new InjectClassAcceptor(map); + injectClassAcceptor.transform(node, "ASMTestClass", null); ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); node.accept(writer); byte[] bytes = writer.toByteArray(); From 83a3c963d3a64805deba354328654f282727641d Mon Sep 17 00:00:00 2001 From: Gravit Date: Fri, 24 Jan 2020 10:06:10 +0700 Subject: [PATCH 169/192] =?UTF-8?q?[FIX]=20=D0=A4=D0=B8=D0=BA=D1=81=D1=8B?= =?UTF-8?q?=20MainBuildTask?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gravit/launchserver/binary/tasks/MainBuildTask.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java index 9209667c..c17f8c05 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java @@ -13,6 +13,7 @@ import pro.gravit.launchserver.asm.ClassMetadataReader; import pro.gravit.launchserver.asm.ConfigGenerator; import pro.gravit.launchserver.asm.InjectClassAcceptor; +import pro.gravit.launchserver.asm.SafeClassWriter; import pro.gravit.launchserver.binary.BuildContext; import pro.gravit.launchserver.binary.LauncherConfigurator; import pro.gravit.utils.HookException; @@ -82,7 +83,7 @@ default byte[] transform(byte[] input, String classname, BuildContext context) ClassNode cn = new ClassNode(); reader.accept(cn, 0); transform(cn, classname, context); - ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); + SafeClassWriter writer = new SafeClassWriter(context.task.reader,ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); cn.accept(writer); return writer.toByteArray(); } @@ -234,7 +235,7 @@ public byte[] transformClass(byte[] bytes, String classname, BuildContext contex } else if(cn != null) { - writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); + writer = new SafeClassWriter(reader, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); cn.accept(writer); result = writer.toByteArray(); } @@ -248,7 +249,7 @@ else if(cn != null) } if(cn != null) { - writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); + writer = new SafeClassWriter(reader,ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); cn.accept(writer); result = writer.toByteArray(); } From d813e714dad1b88fafe958ec76516c7771a7696a Mon Sep 17 00:00:00 2001 From: Gravit Date: Thu, 30 Jan 2020 17:43:07 +0700 Subject: [PATCH 170/192] [FIX] InjectClassAcceptor fixes (by radioegor146) --- LaunchServer/build.gradle | 2 +- .../launchserver/asm/InjectClassAcceptor.java | 343 +++++++++--------- .../launchserver/ASMTransformersTest.java | 25 +- 3 files changed, 204 insertions(+), 166 deletions(-) diff --git a/LaunchServer/build.gradle b/LaunchServer/build.gradle index 5e6747a8..5cadc5a7 100644 --- a/LaunchServer/build.gradle +++ b/LaunchServer/build.gradle @@ -71,7 +71,7 @@ task cleanjar(type: Jar, dependsOn: jar) { dependencies { pack project(':LauncherAPI') - bundle 'org.ow2.asm:asm-commons:7.1' + bundle 'org.ow2.asm:asm-commons:7.3.1' bundle 'mysql:mysql-connector-java:8.0.16' bundle 'org.postgresql:postgresql:42.2.6' bundle 'org.jline:jline:3.13.1' diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java index a9bd36a7..4a7f171d 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java @@ -1,26 +1,13 @@ package pro.gravit.launchserver.asm; -import java.util.Arrays; -import java.util.Base64; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; import org.objectweb.asm.AnnotationVisitor; import org.objectweb.asm.Opcodes; import org.objectweb.asm.Type; -import org.objectweb.asm.tree.AnnotationNode; -import org.objectweb.asm.tree.ClassNode; -import org.objectweb.asm.tree.FieldInsnNode; -import org.objectweb.asm.tree.FieldNode; -import org.objectweb.asm.tree.InsnList; -import org.objectweb.asm.tree.InsnNode; -import org.objectweb.asm.tree.LdcInsnNode; -import org.objectweb.asm.tree.MethodInsnNode; -import org.objectweb.asm.tree.MethodNode; -import org.objectweb.asm.tree.TypeInsnNode; -import org.objectweb.asm.tree.VarInsnNode; +import org.objectweb.asm.tree.*; import pro.gravit.launchserver.binary.BuildContext; import pro.gravit.launchserver.binary.tasks.MainBuildTask; @@ -33,167 +20,197 @@ public class InjectClassAcceptor implements MainBuildTask.ASMTransformer { public InjectClassAcceptor(Map values) { this.values = values; } - private static final List> zPrimitivesList = Arrays.asList(java.lang.Boolean.class, java.lang.Character.class, + + private static final List> primitiveClasses = Arrays.asList(java.lang.Boolean.class, java.lang.Character.class, java.lang.Byte.class, java.lang.Short.class, java.lang.Integer.class, java.lang.Long.class, java.lang.Float.class, java.lang.Double.class, java.lang.String.class); - private static final String INJ_DESC = Type.getDescriptor(LauncherInject.class); - private static final String INJ_C_DESC = Type.getDescriptor(LauncherInjectionConstructor.class); - private static final List cPrimitivesList = Arrays.asList("I", "V", "Z", "B", "C", "S", "D", "F", "J", Type.getDescriptor(String.class)); - - private static void visit(ClassNode cn, Map object) { - MethodNode clinit = cn.methods.stream().filter(methodNode -> - "".equals(methodNode.name)).findFirst().orElseGet(() -> { - MethodNode ret = new MethodNode(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC | Opcodes.ACC_SYNTHETIC, "", "()V", null, null); - ret.instructions.add(new InsnNode(Opcodes.RETURN)); - cn.methods.add(ret); - return ret; - }); - List constructors = cn.methods.stream().filter(e -> "".equals(e.name)).collect(Collectors.toList()); - MethodNode init = constructors.stream().filter(e -> e != null && e.invisibleAnnotations != null && e.invisibleAnnotations.stream().anyMatch(f -> INJ_C_DESC.equals(f.desc))).findFirst() - .orElseGet(() -> constructors.stream().filter(e -> e.desc.equals("()V")).findFirst().orElse(null)); - cn.fields.stream().filter(e -> e.invisibleAnnotations != null) - .filter(e -> !e.invisibleAnnotations.isEmpty() && e.invisibleAnnotations.stream().anyMatch(f -> f.desc.equals(INJ_DESC))).forEach(e -> { - // Notice that fields that will be used with this algo should not have default - // value by = ...; - AnnotationNode n = e.invisibleAnnotations.stream().filter(f -> INJ_DESC.equals(f.desc)).findFirst() - .get(); - e.invisibleAnnotations.removeIf(f -> INJ_DESC.equals(f.desc)); - AtomicReference valueName = new AtomicReference<>(null); - n.accept(new AnnotationVisitor(Opcodes.ASM7) { - @Override - public void visit(final String name, final Object value) { - if ("value".equals(name)) { - if (value.getClass() != String.class) - throw new IllegalArgumentException( - "Invalid Annotation with value class " + e.getClass().getName()); - valueName.set(value.toString()); - } - } - }); - if (valueName.get() == null) - throw new IllegalArgumentException("Annotation should always contains 'value' key"); - if (object.containsKey(valueName.get())) { - Object val = object.get(valueName.get()); - if ((e.access & Opcodes.ACC_STATIC) != 0) - if (cPrimitivesList.contains(e.desc) && zPrimitivesList.contains(val.getClass())) - e.value = val; - else { - List nodes = Arrays.stream(clinit.instructions.toArray()).filter(p -> p instanceof FieldInsnNode && p.getOpcode() == Opcodes.PUTSTATIC).map(p -> (FieldInsnNode) p) - .filter(p -> p.owner.equals(cn.name) && p.name.equals(e.name) && p.desc.equals(e.desc)).collect(Collectors.toList()); - InsnList injector = new InsnList(); - pushInjector(injector, val, e); - if (nodes.isEmpty()) { - injector.insert(new InsnNode(Opcodes.ICONST_0)); - injector.add(new FieldInsnNode(Opcodes.PUTSTATIC, cn.name, e.name, e.desc)); - Arrays.stream(clinit.instructions.toArray()).filter(p -> p.getOpcode() == Opcodes.RETURN).forEach(p -> clinit.instructions.insertBefore(p, injector)); - } else - for (FieldInsnNode node : nodes) clinit.instructions.insertBefore(node, injector); - } - else { - if (init == null) throw new IllegalArgumentException("Not found init in target: " + cn.name); - List nodes = Arrays.stream(init.instructions.toArray()).filter(p -> p instanceof FieldInsnNode && p.getOpcode() == Opcodes.PUTFIELD).map(p -> (FieldInsnNode) p) - .filter(p -> p.owner.equals(cn.name) && p.name.equals(e.name) && p.desc.equals(e.desc)).collect(Collectors.toList()); - InsnList injector = new InsnList(); - pushInjector(injector, val, e); - if (nodes.isEmpty()) { - injector.insert(new VarInsnNode(Opcodes.ALOAD, 0)); - injector.insert(new InsnNode(Opcodes.ICONST_0)); - injector.add(new FieldInsnNode(Opcodes.PUTSTATIC, cn.name, e.name, e.desc)); - Arrays.stream(init.instructions.toArray()).filter(p -> p.getOpcode() == Opcodes.RETURN).forEach(p -> clinit.instructions.insertBefore(p, injector)); - } else - for (FieldInsnNode node : nodes) init.instructions.insertBefore(node, injector); - } - } + private static final String INJECTED_FIELD_DESC = Type.getDescriptor(LauncherInject.class); + private static final String INJECTED_CONSTRUCTOR_DESC = Type.getDescriptor(LauncherInjectionConstructor.class); + private static final List primitiveDescriptors = Arrays.asList(Type.INT_TYPE.getDescriptor(), + Type.VOID_TYPE.getDescriptor(), Type.BOOLEAN_TYPE.getDescriptor(), Type.BYTE_TYPE.getDescriptor(), + Type.CHAR_TYPE.getDescriptor(), Type.SHORT_TYPE.getDescriptor(), Type.DOUBLE_TYPE.getDescriptor(), + Type.FLOAT_TYPE.getDescriptor(), Type.LONG_TYPE.getDescriptor(), Type.getDescriptor(String.class)); + + private static void visit(ClassNode classNode, Map values) { + MethodNode clinitMethod = classNode.methods.stream().filter(methodNode -> "".equals(methodNode.name)) + .findFirst().orElseGet(() -> { + MethodNode newClinitMethod = new MethodNode(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC | Opcodes.ACC_SYNTHETIC, + "", "()V", null, null); + newClinitMethod.instructions.add(new InsnNode(Opcodes.RETURN)); + classNode.methods.add(newClinitMethod); + return newClinitMethod; }); + List constructors = classNode.methods.stream().filter(method -> "".equals(method.name)) + .collect(Collectors.toList()); + MethodNode initMethod = constructors.stream().filter(method -> method.invisibleAnnotations != null + && method.invisibleAnnotations.stream().anyMatch(annotation -> INJECTED_CONSTRUCTOR_DESC.equals(annotation.desc))).findFirst() + .orElseGet(() -> constructors.stream().filter(method -> method.desc.equals("()V")).findFirst().orElse(null)); + classNode.fields.forEach(field -> { + // Notice that fields that will be used with this algo should not have default + // value by = ...; + AnnotationNode valueAnnotation = field.invisibleAnnotations.stream() + .filter(annotation -> INJECTED_FIELD_DESC.equals(annotation.desc)).findFirst() + .orElse(null); + if (valueAnnotation == null) { + return; + } + field.invisibleAnnotations.remove(valueAnnotation); + AtomicReference valueName = new AtomicReference(null); + valueAnnotation.accept(new AnnotationVisitor(Opcodes.ASM7) { + @Override + public void visit(final String name, final Object value) { + if ("value".equals(name)) { + if (value.getClass() != String.class) + throw new IllegalArgumentException( + String.format("Invalid annotation with value class %s", field.getClass().getName())); + valueName.set(value.toString()); + } + } + }); + if (valueName.get() == null) { + throw new IllegalArgumentException("Annotation should always contains 'value' key"); + } + if (!values.containsKey(valueName.get())) { + return; + } + Object value = values.get(valueName.get()); + if ((field.access & Opcodes.ACC_STATIC) != 0) { + if (primitiveDescriptors.contains(field.desc) && primitiveClasses.contains(value.getClass())) { + field.value = value; + return; + } + List putStaticNodes = Arrays.stream(clinitMethod.instructions.toArray()) + .filter(node -> node instanceof FieldInsnNode && node.getOpcode() == Opcodes.PUTSTATIC).map(p -> (FieldInsnNode) p) + .filter(node -> node.owner.equals(classNode.name) && node.name.equals(field.name) && node.desc.equals(field.desc)).collect(Collectors.toList()); + InsnList setter = serializeValue(value); + if (putStaticNodes.isEmpty()) { + setter.add(new FieldInsnNode(Opcodes.PUTSTATIC, classNode.name, field.name, field.desc)); + Arrays.stream(clinitMethod.instructions.toArray()).filter(node -> node.getOpcode() == Opcodes.RETURN) + .forEach(node -> clinitMethod.instructions.insertBefore(node, setter)); + } else { + setter.insert(new InsnNode(Type.getType(field.desc).getSize() == 1 ? Opcodes.POP : Opcodes.POP2)); + for (FieldInsnNode fieldInsnNode : putStaticNodes) { + clinitMethod.instructions.insertBefore(fieldInsnNode, setter); + } + } + } else { + if (initMethod == null) { + throw new IllegalArgumentException(String.format("Not found init in target: %s", classNode.name)); + } + List putFieldNodes = Arrays.stream(initMethod.instructions.toArray()) + .filter(node -> node instanceof FieldInsnNode && node.getOpcode() == Opcodes.PUTFIELD).map(p -> (FieldInsnNode) p) + .filter(node -> node.owner.equals(classNode.name) && node.name.equals(field.name) && node.desc.equals(field.desc)).collect(Collectors.toList()); + InsnList setter = serializeValue(value); + if (putFieldNodes.isEmpty()) { + setter.insert(new VarInsnNode(Opcodes.ALOAD, 0)); + setter.add(new FieldInsnNode(Opcodes.PUTFIELD, classNode.name, field.name, field.desc)); + Arrays.stream(initMethod.instructions.toArray()) + .filter(node -> node.getOpcode() == Opcodes.RETURN) + .forEach(node -> initMethod.instructions.insertBefore(node, setter)); + } else { + setter.insert(new InsnNode(Type.getType(field.desc).getSize() == 1 ? Opcodes.POP : Opcodes.POP2)); + for (FieldInsnNode fieldInsnNode : putFieldNodes) { + initMethod.instructions.insertBefore(fieldInsnNode, setter); + } + } + } + }); } - @SuppressWarnings({ "rawtypes", "unchecked" }) - private static void pushInjector(InsnList injector, Object val, FieldNode e) { - injector.add(new InsnNode(Opcodes.POP)); - if (e.desc.equals("Z")) { - if ((Boolean) val) injector.add(new InsnNode(Opcodes.ICONST_1)); - else injector.add(new InsnNode(Opcodes.ICONST_0)); - } else if (e.desc.equals("C")) { - injector.add(NodeUtils.push(((Number) val).intValue())); - injector.add(new InsnNode(Opcodes.I2C)); - } else if (e.desc.equals("B")) { - injector.add(NodeUtils.push(((Number) val).intValue())); - injector.add(new InsnNode(Opcodes.I2B)); - } else if (e.desc.equals("S")) { - injector.add(NodeUtils.push(((Number) val).intValue())); - injector.add(new InsnNode(Opcodes.I2S)); - } else if (e.desc.equals("I")) { - injector.add(NodeUtils.push(((Number) val).intValue())); - } else if (e.desc.equals("[B")) { - serializebArr(injector, (byte[]) val); - } else if (e.desc.equals("Ljava/util/List;")) { - if (((List) val).isEmpty()) { - injector.add(new TypeInsnNode(Opcodes.NEW, "java/util/ArrayList")); - injector.add(new InsnNode(Opcodes.DUP)); - injector.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/util/ArrayList", "", "()V")); - } else { - Class c = ((List) val).get(0).getClass(); - if (c == byte[].class) - serializeListbArr(injector, (List) val); - else if (c == String.class) - serializeListString(injector, (List) val); - else - throw new UnsupportedOperationException("Unsupported class" + c.getName()); + private static Map, Serializer> serializers = new HashMap<>(); + + static { + serializers.put(List.class, new ListSerializer()); + serializers.put(Map.class, new MapSerializer()); + serializers.put(byte[].class, new ByteArraySerializer()); + } + + private interface Serializer { + InsnList serialize(T value); + } + + @SuppressWarnings("unchecked") + private static InsnList serializeValue(Object value) { + if (value == null) { + InsnList insnList = new InsnList(); + insnList.add(new InsnNode(Opcodes.ACONST_NULL)); + return insnList; + } + if (primitiveClasses.contains(value.getClass())) { + InsnList insnList = new InsnList(); + insnList.add(new LdcInsnNode(value)); + return insnList; + } + for (Map.Entry, Serializer> serializerEntry : serializers.entrySet()) { + if (serializerEntry.getKey().isInstance(value)) { + return ((Serializer) serializerEntry.getValue()).serialize(value); } - } else if (e.desc.equals("Ljava/util/Map;")) { - serializeMap(injector, (Map) val); - } else { - if (!cPrimitivesList.contains(e.desc) || !zPrimitivesList.contains(val.getClass())) - throw new UnsupportedOperationException("Unsupported class"); - injector.add(new LdcInsnNode(val)); + } + throw new UnsupportedOperationException(String.format("Serialization of type %s is not supported", + value.getClass())); + } + + private static class ListSerializer implements Serializer { + + @Override + public InsnList serialize(List value) { + InsnList insnList = new InsnList(); + insnList.add(new TypeInsnNode(Opcodes.NEW, Type.getInternalName(ArrayList.class))); + insnList.add(new InsnNode(Opcodes.DUP)); + insnList.add(NodeUtils.push(value.size())); + insnList.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, Type.getInternalName(ArrayList.class), "", + Type.getMethodDescriptor(Type.VOID_TYPE, Type.INT_TYPE), false)); + for (Object object : value) { + insnList.add(new InsnNode(Opcodes.DUP)); + insnList.add(serializeValue(object)); + insnList.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, Type.getInternalName(List.class), "add", + Type.getMethodDescriptor(Type.BOOLEAN_TYPE, Type.getType(Object.class)), true)); + insnList.add(new InsnNode(Opcodes.POP)); + } + return insnList; } } - private static void serializeMap(InsnList inj, Map map) { - inj.add(new TypeInsnNode(Opcodes.NEW, "java/util/HashMap")); - inj.add(new InsnNode(Opcodes.DUP)); // +1 - inj.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/util/HashMap", "", "()V")); - map.forEach((k, v) -> { - inj.add(new InsnNode(Opcodes.DUP)); // +1-1 - inj.add(NodeUtils.getSafeStringInsnList(k)); - inj.add(NodeUtils.getSafeStringInsnList(v)); - inj.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, "java/util/Map", "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", true)); - inj.add(new InsnNode(Opcodes.POP)); - }); + private static class MapSerializer implements Serializer { + + @Override + public InsnList serialize(Map value) { + InsnList insnList = new InsnList(); + insnList.add(new TypeInsnNode(Opcodes.NEW, Type.getInternalName(value.getClass()))); + insnList.add(new InsnNode(Opcodes.DUP)); + insnList.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, Type.getInternalName(value.getClass()), "", + Type.getMethodDescriptor(Type.VOID_TYPE), false)); + for (Object entryObject : value.entrySet()) { + Map.Entry entry = (Map.Entry) entryObject; + insnList.add(new InsnNode(Opcodes.DUP)); + insnList.add(serializeValue(entry.getKey())); + insnList.add(serializeValue(entry.getValue())); + insnList.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, Type.getInternalName(Map.class), "put", + Type.getMethodDescriptor(Type.getType(Object.class), Type.getType(Object.class), Type.getType(Object.class)), + true)); + insnList.add(new InsnNode(Opcodes.POP)); + } + return insnList; + } } - private static void serializebArr(InsnList injector, byte[] val) { - injector.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/util/Base64", "getDecoder", "()Ljava/util/Base64$Decoder;", false)); - injector.add(NodeUtils.getSafeStringInsnList(Base64.getEncoder().encodeToString(val))); - injector.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/util/Base64$Decoder", "decode", "(Ljava/lang/String;)[B", false)); - } + private static class ByteArraySerializer implements Serializer { - private static void serializeListbArr(InsnList inj, List val) { - inj.add(new TypeInsnNode(Opcodes.NEW, "java/util/ArrayList")); - inj.add(new InsnNode(Opcodes.DUP)); // +1 - inj.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/util/ArrayList", "", "()V")); - for (byte[] value : val) { - inj.add(new InsnNode(Opcodes.DUP)); // +1-1 - serializebArr(inj, value); - inj.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", true)); - inj.add(new InsnNode(Opcodes.POP)); - } - } - - private static void serializeListString(InsnList inj, List val) { - inj.add(new TypeInsnNode(Opcodes.NEW, "java/util/ArrayList")); - inj.add(new InsnNode(Opcodes.DUP)); // +1 - inj.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/util/ArrayList", "", "()V")); - for (String value : val) { - inj.add(new InsnNode(Opcodes.DUP)); // +1-1 - inj.add(NodeUtils.getSafeStringInsnList(value)); - inj.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", true)); - inj.add(new InsnNode(Opcodes.POP)); - } + @Override + public InsnList serialize(byte[] value) { + InsnList insnList = new InsnList(); + insnList.add(new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(Base64.class), + "getDecoder", Type.getMethodDescriptor(Type.getType(Base64.Decoder.class)), false)); + insnList.add(NodeUtils.getSafeStringInsnList(Base64.getEncoder().encodeToString(value))); + insnList.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Base64.Decoder.class), + "decode", Type.getMethodDescriptor(Type.getType(byte[].class), Type.getType(String.class)), + false)); + return insnList; + } } @Override - public void transform(ClassNode cn, String classname, BuildContext context) { - visit(cn, values); + public void transform(ClassNode classNode, String className, BuildContext context) { + visit(classNode, values); } -} +} \ No newline at end of file diff --git a/LaunchServer/src/test/java/pro/gravit/launchserver/ASMTransformersTest.java b/LaunchServer/src/test/java/pro/gravit/launchserver/ASMTransformersTest.java index 25223c62..6e63d794 100644 --- a/LaunchServer/src/test/java/pro/gravit/launchserver/ASMTransformersTest.java +++ b/LaunchServer/src/test/java/pro/gravit/launchserver/ASMTransformersTest.java @@ -16,7 +16,9 @@ import java.io.InputStream; import java.lang.reflect.Field; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; public class ASMTransformersTest { @@ -34,7 +36,11 @@ public void rawDefineClass(String name, byte[] bytes, int offset, int length) public static class TestClass { @LauncherInject(value = "testprop") - public static int test = 1; + public int test; + @LauncherInject(value = "testprop2") + public List s; + @LauncherInject(value = "testprop3") + public Map map; } @BeforeAll public static void prepare() throws Exception { @@ -49,6 +55,14 @@ void testASM() throws Exception node.name = "ASMTestClass"; Map map = new HashMap<>(); map.put("testprop", 1234); + List strings = new ArrayList<>(); + strings.add("a"); + strings.add("b"); + map.put("testprop2", strings); + Map byteMap = new HashMap<>(); + byteMap.put("a", "TEST A"); + byteMap.put("b", "TEST B"); + map.put("testprop3", byteMap); InjectClassAcceptor injectClassAcceptor = new InjectClassAcceptor(map); injectClassAcceptor.transform(node, "ASMTestClass", null); ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); @@ -56,8 +70,15 @@ void testASM() throws Exception byte[] bytes = writer.toByteArray(); classLoader.rawDefineClass("ASMTestClass", bytes, 0, bytes.length); Class clazz = classLoader.loadClass("ASMTestClass"); + Object instance = clazz.newInstance(); Field field = clazz.getField("test"); - Object result = field.get(null); + Object result = field.get(instance); Assertions.assertEquals(1234, (int) (Integer) result); + field = clazz.getField("s"); + result = field.get(instance); + Assertions.assertEquals(strings, result); + field = clazz.getField("map"); + result = field.get(instance); + Assertions.assertEquals(byteMap, result); } } From 7b1ddf5577d93a0fe7a6120e53828306ec3144d3 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Thu, 30 Jan 2020 14:50:37 +0100 Subject: [PATCH 171/192] =?UTF-8?q?[FIX]=20=D0=A1=D0=B5=D1=80=D0=B8=D0=B0?= =?UTF-8?q?=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20short,=20byte,=20c?= =?UTF-8?q?har,=20boolean?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launchserver/asm/InjectClassAcceptor.java | 43 +++++++++++++++---- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java index 4a7f171d..93d1ca7a 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java @@ -21,14 +21,11 @@ public InjectClassAcceptor(Map values) { this.values = values; } - private static final List> primitiveClasses = Arrays.asList(java.lang.Boolean.class, java.lang.Character.class, - java.lang.Byte.class, java.lang.Short.class, java.lang.Integer.class, java.lang.Long.class, + private static final List> primitiveLDCClasses = Arrays.asList(java.lang.Integer.class, java.lang.Long.class, java.lang.Float.class, java.lang.Double.class, java.lang.String.class); private static final String INJECTED_FIELD_DESC = Type.getDescriptor(LauncherInject.class); private static final String INJECTED_CONSTRUCTOR_DESC = Type.getDescriptor(LauncherInjectionConstructor.class); - private static final List primitiveDescriptors = Arrays.asList(Type.INT_TYPE.getDescriptor(), - Type.VOID_TYPE.getDescriptor(), Type.BOOLEAN_TYPE.getDescriptor(), Type.BYTE_TYPE.getDescriptor(), - Type.CHAR_TYPE.getDescriptor(), Type.SHORT_TYPE.getDescriptor(), Type.DOUBLE_TYPE.getDescriptor(), + private static final List primitiveLDCDescriptors = Arrays.asList(Type.INT_TYPE.getDescriptor(), Type.DOUBLE_TYPE.getDescriptor(), Type.FLOAT_TYPE.getDescriptor(), Type.LONG_TYPE.getDescriptor(), Type.getDescriptor(String.class)); private static void visit(ClassNode classNode, Map values) { @@ -75,7 +72,7 @@ public void visit(final String name, final Object value) { } Object value = values.get(valueName.get()); if ((field.access & Opcodes.ACC_STATIC) != 0) { - if (primitiveDescriptors.contains(field.desc) && primitiveClasses.contains(value.getClass())) { + if (primitiveLDCDescriptors.contains(field.desc) && primitiveLDCClasses.contains(value.getClass())) { field.value = value; return; } @@ -123,20 +120,47 @@ public void visit(final String name, final Object value) { serializers.put(List.class, new ListSerializer()); serializers.put(Map.class, new MapSerializer()); serializers.put(byte[].class, new ByteArraySerializer()); + serializers.put(Short.class, serializerClass(Opcodes.I2S)); + serializers.put(Byte.class, serializerClass(Opcodes.I2B)); + serializers.put(Boolean.class, (Serializer) e -> { + InsnList ret = new InsnList(); + ret.add(new InsnNode(e ? Opcodes.ICONST_1 : Opcodes.ICONST_0)); + return ret; + }); + serializers.put(Character.class, (Serializer) e -> { + InsnList ret = new InsnList(); + ret.add(NodeUtils.push((int) e.charValue())); + ret.add(new InsnNode(Opcodes.I2C)); + return ret; + }); } + private static Serializer serializerClass(int opcode) { + return new Serializer() { + @Override + public InsnList serialize(Number value) { + InsnList ret = new InsnList(); + ret.add(NodeUtils.push(((Number) value).intValue())); + ret.add(new InsnNode(opcode)); + return ret; + } + + }; + } + + @FunctionalInterface private interface Serializer { InsnList serialize(T value); } - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "rawtypes" }) private static InsnList serializeValue(Object value) { if (value == null) { InsnList insnList = new InsnList(); insnList.add(new InsnNode(Opcodes.ACONST_NULL)); return insnList; } - if (primitiveClasses.contains(value.getClass())) { + if (primitiveLDCClasses.contains(value.getClass())) { InsnList insnList = new InsnList(); insnList.add(new LdcInsnNode(value)); return insnList; @@ -150,6 +174,7 @@ private static InsnList serializeValue(Object value) { value.getClass())); } + @SuppressWarnings("rawtypes") private static class ListSerializer implements Serializer { @Override @@ -171,6 +196,7 @@ public InsnList serialize(List value) { } } + @SuppressWarnings("rawtypes") private static class MapSerializer implements Serializer { @Override @@ -195,7 +221,6 @@ public InsnList serialize(Map value) { } private static class ByteArraySerializer implements Serializer { - @Override public InsnList serialize(byte[] value) { InsnList insnList = new InsnList(); From ea87e58455873b410fb4de565a8dc661d5cbafe3 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Thu, 30 Jan 2020 14:53:21 +0100 Subject: [PATCH 172/192] =?UTF-8?q?[ANY]=20=D0=9E=D1=88=D0=B8=D0=B1=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BC=D0=BE=D0=B4=D0=B8=D1=84=D0=B8=D0=BA=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=B0=20=D0=BF=D0=BE=D0=BB=D1=8F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/pro/gravit/launchserver/asm/InjectClassAcceptor.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java index 93d1ca7a..fcba7a13 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java @@ -114,9 +114,10 @@ public void visit(final String name, final Object value) { }); } - private static Map, Serializer> serializers = new HashMap<>(); + private static final Map, Serializer> serializers; static { + serializers = new HashMap<>(); serializers.put(List.class, new ListSerializer()); serializers.put(Map.class, new MapSerializer()); serializers.put(byte[].class, new ByteArraySerializer()); From 32f76a395a9b401cff715deacc83bf826769d421 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Thu, 30 Jan 2020 15:59:50 +0100 Subject: [PATCH 173/192] =?UTF-8?q?[ANY]=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B8?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index 417a761c..e7162df3 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 417a761cf52636316b0f39fc3e186cc52503c3fc +Subproject commit e7162df352259e2e261a210b8b5cd85fdf722fa2 From 7979989724a7404f971a530c784697ee56373495 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Thu, 30 Jan 2020 16:11:39 +0100 Subject: [PATCH 174/192] =?UTF-8?q?[ANY]=20=D0=A3=D0=B4=D0=B0=D0=BB=D0=B8?= =?UTF-8?q?=D0=BB=20=D1=81=D1=82=D0=B0=D1=80=D1=8B=D0=B5=20usePermission?= =?UTF-8?q?=20+=20=D0=BF=D0=BE=D0=B4=D1=87=D0=B8=D1=81=D1=82=D0=B8=D0=BB?= =?UTF-8?q?=20=D0=B8=D0=BC=D0=BF=D0=BE=D1=80=D1=82=D1=8B.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/pro/gravit/launchserver/auth/AuthProviderPair.java | 1 - .../launchserver/auth/provider/PostgreSQLAuthProvider.java | 1 - .../java/pro/gravit/launchserver/binary/BuildContext.java | 1 - .../launchserver/binary/tasks/AdditionalFixesApplyTask.java | 2 -- .../pro/gravit/launchserver/binary/tasks/MainBuildTask.java | 6 ------ .../java/pro/gravit/launchserver/ASMTransformersTest.java | 5 ----- .../main/java/pro/gravit/launcher/server/ServerWrapper.java | 1 - modules | 2 +- 8 files changed, 1 insertion(+), 18 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java index 592f9462..5af479e3 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java @@ -7,7 +7,6 @@ import pro.gravit.launchserver.auth.texture.TextureProvider; import java.io.IOException; -import java.util.HashMap; import java.util.Map; public class AuthProviderPair { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/PostgreSQLAuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/PostgreSQLAuthProvider.java index f85ea7ea..3599f249 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/PostgreSQLAuthProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/PostgreSQLAuthProvider.java @@ -19,7 +19,6 @@ public final class PostgreSQLAuthProvider extends AuthProvider { private String query; private String message; private String[] queryParams; - private boolean usePermission; @Override public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface password, String ip) throws SQLException, AuthException { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BuildContext.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BuildContext.java index 2adc9a08..24692d17 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BuildContext.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BuildContext.java @@ -5,7 +5,6 @@ import pro.gravit.launcher.serialize.stream.StreamObject; import pro.gravit.launchserver.binary.tasks.MainBuildTask; import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.JarHelper; import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.SecurityHelper; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/AdditionalFixesApplyTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/AdditionalFixesApplyTask.java index eac0696f..fdbe43ed 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/AdditionalFixesApplyTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/AdditionalFixesApplyTask.java @@ -11,10 +11,8 @@ import java.io.IOException; import java.io.InputStream; import java.nio.file.Path; -import java.util.List; import java.util.function.Predicate; import java.util.jar.JarFile; -import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java index c17f8c05..41c66644 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java @@ -17,7 +17,6 @@ import pro.gravit.launchserver.binary.BuildContext; import pro.gravit.launchserver.binary.LauncherConfigurator; import pro.gravit.utils.HookException; -import pro.gravit.utils.HookSet; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.JarHelper; import pro.gravit.utils.helper.LogHelper; @@ -29,13 +28,8 @@ import java.util.*; import java.util.jar.JarFile; import java.util.stream.Collectors; -import java.util.zip.ZipEntry; -import java.util.zip.ZipException; -import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; -import static pro.gravit.utils.helper.IOHelper.newZipEntry; - public class MainBuildTask implements LauncherBuildTask { private final LaunchServer server; public final ClassMetadataReader reader; diff --git a/LaunchServer/src/test/java/pro/gravit/launchserver/ASMTransformersTest.java b/LaunchServer/src/test/java/pro/gravit/launchserver/ASMTransformersTest.java index 6e63d794..fe27cab0 100644 --- a/LaunchServer/src/test/java/pro/gravit/launchserver/ASMTransformersTest.java +++ b/LaunchServer/src/test/java/pro/gravit/launchserver/ASMTransformersTest.java @@ -6,15 +6,10 @@ import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.tree.ClassNode; -import org.objectweb.asm.tree.FieldNode; import pro.gravit.launcher.LauncherInject; -import pro.gravit.launcher.LauncherInjectionConstructor; import pro.gravit.launchserver.asm.InjectClassAcceptor; -import pro.gravit.utils.PublicURLClassLoader; import pro.gravit.utils.helper.JarHelper; -import pro.gravit.utils.helper.LogHelper; -import java.io.InputStream; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashMap; diff --git a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java index a81b9f1f..a003ef25 100644 --- a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java +++ b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java @@ -27,7 +27,6 @@ import java.net.URL; import java.nio.file.Path; import java.nio.file.Paths; -import java.security.AuthProvider; import java.security.interfaces.ECPublicKey; import java.security.spec.InvalidKeySpecException; import java.util.Arrays; diff --git a/modules b/modules index e7162df3..f4197b87 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit e7162df352259e2e261a210b8b5cd85fdf722fa2 +Subproject commit f4197b877313a01edd024cbdc8533515266f534f From 002477445c0bb935338b95aa59ae63f2520ed5ba Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Thu, 30 Jan 2020 16:46:13 +0100 Subject: [PATCH 175/192] =?UTF-8?q?[ANY]=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B8?= =?UTF-8?q?.=20[FEATURE]=20=D0=A1=D0=B8=D0=BD=D1=85=D1=80=D0=BE=D0=BD?= =?UTF-8?q?=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D0=BB=D0=B8=D1=88=D1=8C?= =?UTF-8?q?=20=D1=82=D1=80=D0=B5=D0=B1=D1=83=D0=B5=D0=BC=D1=8B=D1=85=20?= =?UTF-8?q?=D0=B4=D0=B8=D1=80=D0=B5=D0=BA=D1=82=D0=BE=D1=80=D0=B8=D0=B9=20?= =?UTF-8?q?=D0=B2=20AutoReHash.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index f4197b87..5464417b 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit f4197b877313a01edd024cbdc8533515266f534f +Subproject commit 5464417b18e27d7ae8ce91861e42f167e11b8215 From 554ca54c4a6d3215faade5bc6f45c6c12ea8108b Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Fri, 31 Jan 2020 19:07:33 +0100 Subject: [PATCH 176/192] =?UTF-8?q?[FEATURE]=20=D0=9F=D0=B5=D1=80=D0=B5?= =?UTF-8?q?=D1=85=D0=BE=D0=B4=20=D0=BD=D0=B0=20=D0=BD=D0=BE=D0=B2=D1=83?= =?UTF-8?q?=D1=8E=20=D1=81=D0=B8=D1=81=D1=82=D0=B5=D0=BC=D1=83=20props=20?= =?UTF-8?q?=D1=87=D0=B0=D1=81=D1=82=D1=8C=201=20(=D0=B1=D1=83=D0=B4=D0=B5?= =?UTF-8?q?=D1=82=20=D0=B5=D1=89=D1=91=20=D1=87=D0=B0=D1=81=D1=82=D1=8C=20?= =?UTF-8?q?2).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launchserver/asm/ConfigGenerator.java | 84 ------------------- .../launchserver/asm/InjectClassAcceptor.java | 5 ++ .../launchserver/binary/BuildContext.java | 4 +- .../binary/LauncherConfigurator.java | 56 ------------- .../binary/tasks/MainBuildTask.java | 40 ++++----- .../launcher/ClientLauncherWrapper.java | 2 +- .../pro/gravit/launcher/LauncherEngine.java | 2 +- .../launcher/client/ClientLauncher.java | 2 +- .../pro/gravit/launcher/AutogenConfig.java | 26 ------ .../pro/gravit/launcher/LauncherConfig.java | 77 ++++++++++------- .../gravit/launcher/SecureAutogenConfig.java | 48 ----------- .../gravit/launcher/server/ServerWrapper.java | 1 - 12 files changed, 69 insertions(+), 278 deletions(-) delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/asm/ConfigGenerator.java delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherConfigurator.java delete mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/AutogenConfig.java delete mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/SecureAutogenConfig.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ConfigGenerator.java b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ConfigGenerator.java deleted file mode 100644 index ab66442c..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ConfigGenerator.java +++ /dev/null @@ -1,84 +0,0 @@ -package pro.gravit.launchserver.asm; - -import org.objectweb.asm.ClassWriter; -import org.objectweb.asm.Opcodes; -import org.objectweb.asm.Type; -import org.objectweb.asm.tree.*; - -import java.util.Base64; -import java.util.List; - -public class ConfigGenerator { - protected static final String stringDesc = Type.getDescriptor(String.class); - protected static final String byteArrDesc = Type.getDescriptor(byte[].class); - protected static final String base64DecDesc = "(" + stringDesc + ")" + byteArrDesc; - protected final ClassNode configclass; - protected final MethodNode constructor; - - public ConfigGenerator(ClassNode configclass) { - this.configclass = configclass; - constructor = this.configclass.methods.stream().filter(e -> "".equals(e.name)).findFirst().get(); - constructor.instructions = new InsnList(); - constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); - constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, Type.getInternalName(Object.class), "", "()V")); - } - - public byte[] getBytecode(ClassMetadataReader reader) { - constructor.instructions.add(new InsnNode(Opcodes.RETURN)); - ClassWriter cw = new SafeClassWriter(reader, ClassWriter.COMPUTE_FRAMES); - configclass.accept(cw); - return cw.toByteArray(); - } - - public String getZipEntryPath() { - return configclass.name.concat(".class"); - } - - public void setStringField(String name, String value) { - constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); - constructor.instructions.add(NodeUtils.getSafeStringInsnList(value)); - constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, configclass.name, name, stringDesc)); - } - - public void setByteArrayField(String name, byte[] value) { - constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); - constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/util/Base64", "getDecoder", "()Ljava/util/Base64$Decoder;", false)); - constructor.instructions.add(NodeUtils.getSafeStringInsnList(Base64.getEncoder().encodeToString(value))); - constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/util/Base64$Decoder", "decode", base64DecDesc, false)); - constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, configclass.name, name, stringDesc)); - } - - public void setByteArrayListField(String name, List b) { - constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); - constructor.instructions.add(new TypeInsnNode(Opcodes.NEW, "java/util/ArrayList")); - constructor.instructions.add(new InsnNode(Opcodes.DUP)); // +1 - constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/util/ArrayList", "", "()V")); - for (byte[] value : b) { - constructor.instructions.add(new InsnNode(Opcodes.DUP)); // +1-1 - constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/util/Base64", "getDecoder", "()Ljava/util/Base64$Decoder;", false)); - constructor.instructions.add(NodeUtils.getSafeStringInsnList(Base64.getEncoder().encodeToString(value))); - constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/util/Base64$Decoder", "decode", base64DecDesc, false)); - constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", true)); - constructor.instructions.add(new InsnNode(Opcodes.POP)); - } - constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, configclass.name, name, "Ljava/util/List;")); - } - - public void setIntegerField(String name, int value) { - constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); - constructor.instructions.add(NodeUtils.push(value)); - constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, configclass.name, name, Type.INT_TYPE.getInternalName())); - } - - public void setLongField(String name, long value) { - constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); - constructor.instructions.add(new LdcInsnNode(value)); - constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, configclass.name, name, Type.INT_TYPE.getInternalName())); - } - - public void setBooleanField(String name, boolean b) { - constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); - constructor.instructions.add(new InsnNode(b ? Opcodes.ICONST_1 : Opcodes.ICONST_0)); - constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, configclass.name, name, Type.BOOLEAN_TYPE.getInternalName())); - } -} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java index fcba7a13..fc384a91 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java @@ -123,6 +123,11 @@ public void visit(final String name, final Object value) { serializers.put(byte[].class, new ByteArraySerializer()); serializers.put(Short.class, serializerClass(Opcodes.I2S)); serializers.put(Byte.class, serializerClass(Opcodes.I2B)); + serializers.put(Type.class, (Serializer) e -> { // ow.Type == java.lang.Class in LDC + InsnList ret = new InsnList(); + ret.add(new LdcInsnNode(e)); + return ret; + }); serializers.put(Boolean.class, (Serializer) e -> { InsnList ret = new InsnList(); ret.add(new InsnNode(e ? Opcodes.ICONST_1 : Opcodes.ICONST_0)); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BuildContext.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BuildContext.java index 24692d17..e4d43c2f 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BuildContext.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BuildContext.java @@ -32,7 +32,6 @@ public class BuildContext { public final ZipOutputStream output; - public final LauncherConfigurator config; public final List readerClassPath; public final MainBuildTask task; public final HashSet fileList; @@ -78,9 +77,8 @@ private ZipEntry newEntry(String fileName) { } - public BuildContext(ZipOutputStream output, LauncherConfigurator config, List readerClassPath, MainBuildTask task) { + public BuildContext(ZipOutputStream output, List readerClassPath, MainBuildTask task) { this.output = output; - this.config = config; this.readerClassPath = readerClassPath; this.task = task; fileList = new HashSet<>(1024); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherConfigurator.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherConfigurator.java deleted file mode 100644 index c09684a2..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherConfigurator.java +++ /dev/null @@ -1,56 +0,0 @@ -package pro.gravit.launchserver.binary; - -import org.objectweb.asm.Opcodes; -import org.objectweb.asm.Type; -import org.objectweb.asm.tree.*; -import pro.gravit.launcher.LauncherConfig; -import pro.gravit.launcher.modules.LauncherModule; -import pro.gravit.launchserver.asm.ClassMetadataReader; -import pro.gravit.launchserver.asm.ConfigGenerator; - -public class LauncherConfigurator extends ConfigGenerator { - private static final String modulesManagerName = "pro/gravit/launcher/modules/LauncherModulesManager"; - private static final String launcherName = "pro/gravit/launcher/LauncherEngine"; - private static final String modulesManagerDesc = "Lpro/gravit/launcher/client/ClientModuleManager;"; - private static final String registerModDesc = Type.getMethodDescriptor(Type.getType(LauncherModule.class), Type.getType(LauncherModule.class)); - private final MethodNode initModuleMethod; - - public LauncherConfigurator(ClassNode configclass) { - super(configclass); - initModuleMethod = configclass.methods.stream().filter(e -> "initModules".equals(e.name)).findFirst().get(); - initModuleMethod.instructions = new InsnList(); - } - - public void addModuleClass(String fullName) { - initModuleMethod.instructions.add(new FieldInsnNode(Opcodes.GETSTATIC, launcherName, "modulesManager", modulesManagerDesc)); - initModuleMethod.instructions.add(new TypeInsnNode(Opcodes.NEW, fullName.replace('.', '/'))); - initModuleMethod.instructions.add(new InsnNode(Opcodes.DUP)); - initModuleMethod.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, fullName.replace('.', '/'), "", "()V")); - initModuleMethod.instructions.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, modulesManagerName, "loadModule", registerModDesc)); - } - - @Override - public byte[] getBytecode(ClassMetadataReader reader) { - initModuleMethod.instructions.add(new InsnNode(Opcodes.RETURN)); - return super.getBytecode(reader); - } - - public void setEnv(LauncherConfig.LauncherEnvironment env) { - int i = 2; - switch (env) { - case DEV: - i = 0; - break; - case DEBUG: - i = 1; - break; - case STD: - i = 2; - break; - case PROD: - i = 3; - break; - } - setIntegerField("env", i); - } -} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java index 41c66644..81bba9cd 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java @@ -5,17 +5,13 @@ import org.objectweb.asm.tree.AnnotationNode; import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.FieldNode; -import pro.gravit.launcher.AutogenConfig; import pro.gravit.launcher.Launcher; import pro.gravit.launcher.LauncherConfig; -import pro.gravit.launcher.SecureAutogenConfig; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.asm.ClassMetadataReader; -import pro.gravit.launchserver.asm.ConfigGenerator; import pro.gravit.launchserver.asm.InjectClassAcceptor; import pro.gravit.launchserver.asm.SafeClassWriter; import pro.gravit.launchserver.binary.BuildContext; -import pro.gravit.launchserver.binary.LauncherConfigurator; import pro.gravit.utils.HookException; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.JarHelper; @@ -137,22 +133,17 @@ public String getName() { public Path process(Path inputJar) throws IOException { Path outputJar = server.launcherBinary.nextPath("main"); try (ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(outputJar))) { - ClassNode cn = new ClassNode(); - new ClassReader(JarHelper.getClassBytes(AutogenConfig.class)).accept(cn, 0); - LauncherConfigurator launcherConfigurator = new LauncherConfigurator(cn); - ClassNode cn1 = new ClassNode(); - new ClassReader(JarHelper.getClassBytes(SecureAutogenConfig.class)).accept(cn1, 0); - ConfigGenerator secureConfigurator = new ConfigGenerator(cn1); - BuildContext context = new BuildContext(output, launcherConfigurator, reader.getCp(), this); + BuildContext context = new BuildContext(output, reader.getCp(), this); preBuildHook.hook(context); - launcherConfigurator.setStringField("address", server.config.netty.address); - launcherConfigurator.setStringField("projectname", server.config.projectName); - launcherConfigurator.setStringField("secretKeyClient", SecurityHelper.randomStringAESKey()); - launcherConfigurator.setIntegerField("clientPort", 32148 + SecurityHelper.newRandom().nextInt(512)); - launcherConfigurator.setStringField("guardType", server.config.launcher.guardType); - launcherConfigurator.setBooleanField("isWarningMissArchJava", server.config.launcher.warningMissArchJava); - launcherConfigurator.setEnv(server.config.env); - launcherConfigurator.setStringField("passwordEncryptKey", server.runtime.passwordEncryptKey); + properties.clear(); + properties.put("launcher.address", server.config.netty.address); + properties.put("launcher.projectName", server.config.projectName); + properties.put("runtimeconfig.secretKeyClient", SecurityHelper.randomStringAESKey()); + properties.put("launcher.port", 32148 + SecurityHelper.newRandom().nextInt(512)); + properties.put("launcher.guardType", server.config.launcher.guardType); + properties.put("launcher.isWarningMissArchJava", server.config.launcher.warningMissArchJava); + properties.put("launchercore.env" ,server.config.env); + properties.put("runtimeconfig.passwordEncryptKey", server.runtime.passwordEncryptKey); List certificates = Arrays.stream(server.certificateManager.trustManager.getTrusted()).map(e -> { try { return e.getEncoded(); @@ -170,15 +161,15 @@ public Path process(Path inputJar) throws IOException { throw new InternalError(e); } } - secureConfigurator.setByteArrayListField("certificates", certificates); + properties.put("launchercore.certificates", certificates); String launcherSalt = SecurityHelper.randomStringToken(); byte[] launcherSecureHash = SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA256, server.runtime.clientCheckSecret.concat(".").concat(launcherSalt)); - launcherConfigurator.setStringField("secureCheckHash", Base64.getEncoder().encodeToString(launcherSecureHash)); - launcherConfigurator.setStringField("secureCheckSalt", launcherSalt); + properties.put("runtimeconfig.secureCheckHash", Base64.getEncoder().encodeToString(launcherSecureHash)); + properties.put("runtimeconfig.secureCheckSalt", launcherSalt); //LogHelper.debug("[checkSecure] %s: %s", launcherSalt, Arrays.toString(launcherSecureHash)); if (server.runtime.oemUnlockKey == null) server.runtime.oemUnlockKey = SecurityHelper.randomStringToken(); - launcherConfigurator.setStringField("oemUnlockKey", server.runtime.oemUnlockKey); + properties.put("runtimeconfig.oemUnlockKey", server.runtime.oemUnlockKey); context.clientModules.forEach(launcherConfigurator::addModuleClass); reader.getCp().add(new JarFile(inputJar.toFile())); server.launcherBinary.coreLibs.forEach(e -> { @@ -188,9 +179,6 @@ public Path process(Path inputJar) throws IOException { LogHelper.error(e1); } }); - context.pushBytes(launcherConfigurator.getZipEntryPath(), launcherConfigurator.getBytecode(reader)); - context.pushBytes(secureConfigurator.getZipEntryPath(), secureConfigurator.getBytecode(reader)); - context.pushJarFile(inputJar, (e) -> blacklist.contains(e.getName()), (e) -> true); // map for guard diff --git a/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java b/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java index 36781176..dbe125ce 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java +++ b/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java @@ -31,7 +31,7 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep EnvHelper.checkDangerousParams(); LauncherConfig config = Launcher.getConfig(); LauncherEngine.modulesManager = new ClientModuleManager(); - LauncherConfig.getAutogenConfig().initModules(); + LauncherConfig.initModules(); LogHelper.info("Launcher for project %s", config.projectName); if (config.environment.equals(LauncherConfig.LauncherEnvironment.PROD)) { diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index e9c9a0e8..e468542f 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -80,7 +80,7 @@ public static void main(String... args) throws Throwable { LauncherEngine.checkClass(LauncherAgent.class); LauncherEngine.checkClass(ClientLauncher.class); LauncherEngine.modulesManager = new ClientModuleManager(); - LauncherConfig.getAutogenConfig().initModules(); + LauncherConfig.initModules(); LauncherEngine.modulesManager.initModules(null); // Start Launcher initGson(LauncherEngine.modulesManager); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index cd2f642e..ecb96566 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -443,7 +443,7 @@ public static void main(String... args) throws Throwable { LauncherEngine.checkClass(LauncherAgent.class); LauncherEngine.checkClass(ClientLauncher.class); LauncherEngine.modulesManager = new ClientModuleManager(); - LauncherConfig.getAutogenConfig().initModules(); //INIT + LauncherConfig.initModules(); //INIT LauncherEngine.modulesManager.initModules(null); initGson(LauncherEngine.modulesManager); LauncherEngine.verifyNoAgent(); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/AutogenConfig.java b/LauncherAPI/src/main/java/pro/gravit/launcher/AutogenConfig.java deleted file mode 100644 index da1d710c..00000000 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/AutogenConfig.java +++ /dev/null @@ -1,26 +0,0 @@ -package pro.gravit.launcher; - -public class AutogenConfig { - public String projectname; - public String address; - public int clientPort; - public String guardType; - public String secretKeyClient; - public String oemUnlockKey; - public String secureCheckHash; - public String secureCheckSalt; - public String passwordEncryptKey; - public int env; - public boolean isWarningMissArchJava; - // 0 - Dev (дебаг включен по умолчанию, все сообщения) - // 1 - Debug (дебаг включен по умолчанию, основные сообщения) - // 2 - Std (дебаг выключен по умолчанию, основные сообщения) - // 3 - Production (дебаг выключен, минимальный объем сообщений, stacktrace не выводится) - - AutogenConfig() { - } - - public void initModules() { - - } -} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java b/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java index a755e529..33219b4c 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java @@ -13,20 +13,19 @@ import java.util.*; public final class LauncherConfig extends StreamObject { - private static final AutogenConfig config = new AutogenConfig(); - private static final SecureAutogenConfig secureConfig = new SecureAutogenConfig(); - - - public static AutogenConfig getAutogenConfig() { - return config; - } - - // Instance - public String address; - + @LauncherInject("launchercore.env") + private static final int cenv = -1; + @LauncherInject("launchercore.certificates") + private static final List secureConfigCertificates = null; + @LauncherInject("launcher.address") + public String address; + @LauncherInject("launcher.projectName") public final String projectName; + @LauncherInject("launcher.port") public final int clientPort; + @LauncherInject("runtimeconfig.secretKeyClient") public String secretKeyClient; + @LauncherInject("runtimeconfig.oemUnlockKey") public String oemUnlockKey; public final LauncherTrustManager trustManager; @@ -34,40 +33,43 @@ public static AutogenConfig getAutogenConfig() { public final Map runtime; + @LauncherInject("launcher.isWarningMissArchJava") public final boolean isWarningMissArchJava; - public boolean isNettyEnabled; public LauncherEnvironment environment; - + @LauncherInject("launcher.guardType") public final String guardType; - + @LauncherInject("runtimeconfig.secureCheckHash") public final String secureCheckHash; + @LauncherInject("runtimeconfig.secureCheckSalt") public final String secureCheckSalt; + @LauncherInject("runtimeconfig.passwordEncryptKey") public final String passwordEncryptKey; - + @SuppressWarnings("unused") + @LauncherInjectionConstructor public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException { publicKey = SecurityHelper.toPublicECKey(input.readByteArray(SecurityHelper.CRYPTO_MAX_LENGTH)); - secureCheckHash = config.secureCheckHash; - secureCheckSalt = config.secureCheckSalt; - passwordEncryptKey = config.passwordEncryptKey; - projectName = config.projectname; - clientPort = config.clientPort; - secretKeyClient = config.secretKeyClient; - oemUnlockKey = config.oemUnlockKey; + secureCheckHash = null; + secureCheckSalt = null; + passwordEncryptKey = null; + projectName = null; + clientPort = -1; + secretKeyClient = null; + oemUnlockKey = null; try { - trustManager = new LauncherTrustManager(secureConfig.certificates); + trustManager = new LauncherTrustManager(secureConfigCertificates); } catch (CertificateException e) { throw new IOException(e); } - isWarningMissArchJava = config.isWarningMissArchJava; - guardType = config.guardType; - address = config.address; + isWarningMissArchJava = false; + guardType = null; + address = null; LauncherEnvironment env; - if (config.env == 0) env = LauncherEnvironment.DEV; - else if (config.env == 1) env = LauncherEnvironment.DEBUG; - else if (config.env == 2) env = LauncherEnvironment.STD; - else if (config.env == 3) env = LauncherEnvironment.PROD; + if (cenv == 0) env = LauncherEnvironment.DEV; + else if (cenv == 1) env = LauncherEnvironment.DEBUG; + else if (cenv == 2) env = LauncherEnvironment.STD; + else if (cenv == 3) env = LauncherEnvironment.PROD; else env = LauncherEnvironment.STD; Launcher.applyLauncherEnv(env); environment = env; @@ -92,7 +94,6 @@ public LauncherConfig(String address, ECPublicKey publicKey, Map this.clientPort = 32148; guardType = "no"; isWarningMissArchJava = true; - isNettyEnabled = false; environment = LauncherEnvironment.STD; secureCheckSalt = null; secureCheckHash = null; @@ -116,4 +117,18 @@ public void write(HOutput output) throws IOException { public enum LauncherEnvironment { DEV, DEBUG, STD, PROD } + + public static void initModules() { + // TODO Fill + /* + * Old filler + public void addModuleClass(String fullName) { + initModuleMethod.instructions.add(new FieldInsnNode(Opcodes.GETSTATIC, launcherName, "modulesManager", modulesManagerDesc)); + initModuleMethod.instructions.add(new TypeInsnNode(Opcodes.NEW, fullName.replace('.', '/'))); + initModuleMethod.instructions.add(new InsnNode(Opcodes.DUP)); + initModuleMethod.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, fullName.replace('.', '/'), "", "()V")); + initModuleMethod.instructions.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, modulesManagerName, "loadModule", registerModDesc)); + } + */ + } } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/SecureAutogenConfig.java b/LauncherAPI/src/main/java/pro/gravit/launcher/SecureAutogenConfig.java deleted file mode 100644 index fc34057b..00000000 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/SecureAutogenConfig.java +++ /dev/null @@ -1,48 +0,0 @@ -package pro.gravit.launcher; - -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.util.List; - -public class SecureAutogenConfig { - public static final Charset KEY_CHARSET = StandardCharsets.US_ASCII; // ? Какая из них, но выбрать надо однозачно проверить методом тыка!!! - public final List certificates; - - public SecureAutogenConfig() { - //Пока не реализован SecureLauncherConfigurator - certificates = null;/*Arrays.asList( - ("-----BEGIN CERTIFICATE-----\n" + - "MIIFyjCCA7KgAwIBAgIRALnsjNjfvOTXfla3fX1fNEUwDQYJKoZIhvcNAQELBQAw\n" + - "WTELMAkGA1UEBhMCUlUxFzAVBgNVBAoTDkdyYXZpdFRydXN0IENBMRAwDgYDVQQL\n" + - "EwdSb290IENBMR8wHQYDVQQDExZHcmF2aXQgQ2VudHJhbCBSb290IENBMCAXDTE5\n" + - "MDYwOTAyNDIwMFoYDzIwNTEwNjA5MDI0MjAwWjBZMQswCQYDVQQGEwJSVTEXMBUG\n" + - "A1UEChMOR3Jhdml0VHJ1c3QgQ0ExEDAOBgNVBAsTB1Jvb3QgQ0ExHzAdBgNVBAMT\n" + - "FkdyYXZpdCBDZW50cmFsIFJvb3QgQ0EwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAw\n" + - "ggIKAoICAQDA3Qm9OH8Xz3YM3bKkZuQI7T/aL3ulMOdY5GFADYgHrOVZXVSJi/4P\n" + - "PruBsut4WXN6TGQdpJtNZ2kyWTYzENGTm/TMzBcIchor1M3JW5Uv/C0r5gSEU1uP\n" + - "DPe7oEpeKtb3FXML/pGoGpLv/sonTKky4AKZnK7B15bZ+oVZNwh7UKANpNrVA8k5\n" + - "0gb4BisFcegLidYL9Y00H1x5WzUxldQAA1IQuwdkL3NP0NPQrSVJ2Ka2EtebE2HP\n" + - "fXHtbftvvnvSWyh4CXAxTfEmJgut0gSPQPm9wVt6pIWWd4O0hHwVmxkKQidgnP6A\n" + - "+d05FnJGsBw0ztMCifIteqNiHF0D8E0GuSz6NtcuV47J3p43qkvKr2vPc8o6WMN8\n" + - "PAb0eVHc/AX8qqOwYQyHlj4M0SDhCltHeeYRWmuZmRFIIelv6VAocaQLlPQrhJNp\n" + - "feIzmXLy60a+84vpe/eQKQx+D8a1elarQkoHMxI7x/9AJvxcnJ4KuXc2rkiu3Zv9\n" + - "KMhixtkLc+pA6jY023U211v+c20RjTqwKIZoMFc7BZipoinAOn1bdsTzXlhOMv1O\n" + - "zj5WoW6DsQQONMZNyLQAkaX6SYZE/kQVJ9YMPhNdaXjxxzfrY05IrWAaWhtPbW8z\n" + - "5nb4/JyO+bJq3v2rav9p03s8P/lQ4k/0af5vOkGkEO0+YKx97ZP8FQIDAQABo4GK\n" + - "MIGHMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFFjMGCvHXAE/vGJih+Lfdo2s\n" + - "YnzsMAsGA1UdDwQEAwIBBjA1BgNVHR8ELjAsMCqgKKAmhiRodHRwOi8vY2EuZ3Jh\n" + - "dml0LnByby9jZW50cmFscm9vdC5jcmwwEQYJYIZIAYb4QgEBBAQDAgAHMA0GCSqG\n" + - "SIb3DQEBCwUAA4ICAQAexCGpThx85skEllva1UskmdlRh3rud9u59AUiwNZF0b0I\n" + - "+7eeyLNaLHarg2Zm30TSCF53ksyPTE5QNdmozs1fl3MddFqunkbUm4G6hwedZMSi\n" + - "4IXIb2QK3z3gZG5ZNdHaDG2u00Jdkc39h3jQFp1rpn4+0DcnYJAe+lw5G+XHURY2\n" + - "j15wcmUFp/Ywgw3pfCWmH5+rxq21e/LG8JiQrxekkFI2GUD+Qw7+Hq3o1Fgg3kfh\n" + - "Lg4B5WEbEICQ1FC+dHYHasEI3q3c96Qpqu2k3pO0l1fr6Cys+AGjoI2WrgXkGlmA\n" + - "F+Wi2ndoZbvspGAwxmrNMtLE3OYNuMXFF410QSPf4o9QqpGDC3a2mccTXb231a18\n" + - "5vDJixeZpuzEm5ECXg8j6aj53X3rtm7C8yfOsg5UTKJJj+pSNz4YTp91IDHm0nTP\n" + - "2KhrgS7jujgKdJn9xv07e/API3kLWkVmMwHBiaSCIaHOfAN0RJMQVV+YgnSp2sIa\n" + - "OATWgSKH0qTkleE/v7k+USs0a+KV8wmC5wwliqH+uLO++yIP/9bjDctyLulQX5Ee\n" + - "+EhD7tb1R/yyWY4uhkzlsr3N2Kl34aQAEBMn8Z1mHsyyu1FcbEaNLU8jcS3pHPVM\n" + - "gQRn3m1iDnQlFciAMxW0pW6mW/4xKYzhXk5BTSolnqMVylxHgWXuBwdDDQQVnQ==\n" + - "-----END CERTIFICATE-----").getBytes(KEY_CHARSET));*/ - } -} diff --git a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java index a003ef25..6093920d 100644 --- a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java +++ b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java @@ -196,7 +196,6 @@ public void updateLauncherConfig() { if(IOHelper.isFile(publicKeyFile)) publicKey = SecurityHelper.toPublicECKey(IOHelper.read(publicKeyFile)); cfg = new LauncherConfig(config.address, publicKey, new HashMap<>(), config.projectname); - cfg.isNettyEnabled = true; cfg.address = config.address; } catch (InvalidKeySpecException | IOException e) { LogHelper.error(e); From 6b7468e36634dc2fd67a0b1eba735cf6472b6a6f Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Fri, 31 Jan 2020 19:21:24 +0100 Subject: [PATCH 177/192] =?UTF-8?q?[FEATURE]=20=D0=9E=D0=BA=D0=BE=D0=BD?= =?UTF-8?q?=D1=87=D0=B0=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D0=B5=D1=85=D0=BE=D0=B4=20=D0=BD=D0=B0=20=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=D1=83=D1=8E=20=D1=81=D0=B8=D1=81=D1=82=D0=B5=D0=BC?= =?UTF-8?q?=D1=83=20props=20(=D1=87=D0=B0=D1=81=D1=82=D1=8C=202).=20=D0=A1?= =?UTF-8?q?=D0=BF=D0=B8=D1=81=D0=BE=D0=BA=20props(=D1=82=D0=B5=D0=BA=D1=83?= =?UTF-8?q?=D1=89=D0=B8=D0=B9=20=D1=82=D0=B8=D0=BF=20=D0=B8=20=D0=B7=D0=BD?= =?UTF-8?q?=D0=B0=D1=87=D0=B5=D0=BD=D0=B8=D0=B5):=20String=20launcher.proj?= =?UTF-8?q?ectName;=20//=20=D0=9D=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=B0=20String=20?= =?UTF-8?q?launcher.address;=20//=20=D0=90=D0=B4=D1=80=D0=B5=D1=81=20?= =?UTF-8?q?=D1=81=D0=B5=D1=80=D0=B2=D0=B5=D1=80=D0=B0=20int=20launcher.por?= =?UTF-8?q?t;=20//=20=D0=9F=D0=BE=D1=80=D1=82=20=D0=BA=D0=BB=D0=B8=D0=B5?= =?UTF-8?q?=D0=BD=D1=82=D0=B0=20(=D1=80=D0=B0=D0=BD=D0=B4=D0=BE=D0=BC)=20?= =?UTF-8?q?=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D1=83=D0=B5=D1=82?= =?UTF-8?q?=D1=81=D1=8F=20=D0=B4=D0=BB=D1=8F=20=D0=BF=D0=B5=D1=80=D0=B5?= =?UTF-8?q?=D0=B4=D0=B0=D1=87=D0=B8=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BC=D0=B5?= =?UTF-8?q?=D1=82=D1=80=D0=BE=D0=B2=20=D0=B7=D0=B0=D0=BF=D1=83=D1=81=D0=BA?= =?UTF-8?q?=D0=B0=20String=20launcher.guardType;=20//=20=D0=A2=D0=B8=D0=BF?= =?UTF-8?q?=20=D0=B7=D0=B0=D1=89=D0=B8=D1=82=D1=8B=20(java,=20wrapper,=20n?= =?UTF-8?q?o=20=D0=B8=20=D1=82.=20=D0=B4.)=20String=20runtimeconfig.secret?= =?UTF-8?q?KeyClient;=20//=20=D0=A1=D0=B5=D0=BA=D1=80=D0=B5=D1=82=D0=BD?= =?UTF-8?q?=D1=8B=D0=B9=20=D0=BA=D0=BB=D1=8E=D1=87=20String=20runtimeconfi?= =?UTF-8?q?g.oemUnlockKey;=20//=20=D0=9A=D0=BB=D1=8E=D1=87=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B7=D0=B1=D0=BB=D0=BE=D0=BA=D0=B8=D1=80=D0=BE=D0=B2=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=BA=D0=BE=D0=BD=D1=81=D0=BE=D0=BB=D0=B8=20=D0=B2?= =?UTF-8?q?=D0=B2=D0=BE=D0=B4=D0=B0=20=D0=BA=D0=BE=D0=BC=D0=B0=D0=BD=D0=B4?= =?UTF-8?q?=20=D0=B2=20=D0=BB=D0=B0=D1=83=D0=BD=D1=87=D0=B5=D1=80=D0=B5...?= =?UTF-8?q?=20String=20runtimeconfig.secureCheckHash;=20//=20=D0=9F=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B8=20=D0=B1=D0=B5=D0=B7=D0=BE?= =?UTF-8?q?=D0=BF=D0=B0=D1=81=D0=BD=D0=BE=D1=81=D1=82=D0=B8=20=D0=BB=D0=B0?= =?UTF-8?q?=D1=83=D0=BD=D1=87=D0=B5=D1=80=D0=B0=20(=D1=85=D0=B5=D1=88)=20S?= =?UTF-8?q?tring=20runtimeconfig.secureCheckSalt;=20//=20=D0=AD=D1=82?= =?UTF-8?q?=D0=BE=20=D0=B6=D0=B5=20=D0=BD=D0=BE=20=D1=81=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?...=20String=20runtimeconfig.passwordEncryptKey;=20//=20=D0=9A?= =?UTF-8?q?=D0=BB=D1=8E=D1=87=20=D0=B4=D0=BB=D1=8F=20=D1=88=D0=B8=D1=84?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=BA=D0=B8=20=D0=BF=D0=B0=D1=80=D0=BE=D0=BB?= =?UTF-8?q?=D1=8F...=20int=20launchercore.env;=20//=20=D0=A1=D1=80=D0=B5?= =?UTF-8?q?=D0=B4=D0=B0=20=D0=BB=D0=B0=D1=83=D0=BD=D1=87=D1=81=D0=B5=D1=80?= =?UTF-8?q?=D0=B2=D0=B5=D1=80=D0=B0=20(0=3DDEV,1=3DDEBUG,2=3DSTD,3=3DPROD,?= =?UTF-8?q?=20=D0=BE=D1=81=D1=82=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE=D0=B5=20=3D?= =?UTF-8?q?=20=D1=82=D0=B0=D0=BA=20=D0=B6=D0=B5=20STD)=20boolean=20launche?= =?UTF-8?q?r.isWarningMissArchJava;=20//=20=D0=92=D1=8B=D0=B2=D0=BE=D0=B4?= =?UTF-8?q?=D0=B8=D1=82=D1=8C=20=D0=BB=D0=B8=20=D0=BF=D1=80=D0=B5=D0=B4?= =?UTF-8?q?=D1=83=D0=BF=D1=80=D0=B5=D0=B6=D0=B4=D0=B5=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=BE=20os.bits!=3D=20java.bits=20List=20launchercore.?= =?UTF-8?q?certificates;=20//=20EC-=D1=81=D0=B5=D1=80=D1=82=D0=B8=D1=84?= =?UTF-8?q?=D0=B8=D0=BA=D0=B0=D1=82=D1=8B=20=D0=B2=20=D1=84=D0=BE=D1=80?= =?UTF-8?q?=D0=BC=D0=B0=D1=82=D0=B5=20byte[]=20List>=20launcher?= =?UTF-8?q?.modules;=20//=20=D0=A1=D0=BF=D0=B8=D1=81=D0=BE=D0=BA=20=D0=BA?= =?UTF-8?q?=D0=BB=D0=B0=D1=81=D1=81=D0=BE=D0=B2=20=D0=BC=D0=BE=D0=B4=D1=83?= =?UTF-8?q?=D0=BB=D0=B5=D0=B9=20=D0=BB=D0=B0=D1=83=D0=BD=D1=87=D0=B5=D1=80?= =?UTF-8?q?=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../binary/tasks/MainBuildTask.java | 4 +-- .../launcher/ClientLauncherWrapper.java | 2 +- .../pro/gravit/launcher/LauncherEngine.java | 2 +- .../launcher/client/ClientLauncher.java | 2 +- .../pro/gravit/launcher/LauncherConfig.java | 30 +++++++++++-------- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java index 81bba9cd..14c71088 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java @@ -2,6 +2,7 @@ import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.Type; import org.objectweb.asm.tree.AnnotationNode; import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.FieldNode; @@ -14,7 +15,6 @@ import pro.gravit.launchserver.binary.BuildContext; import pro.gravit.utils.HookException; import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.JarHelper; import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.SecurityHelper; @@ -170,7 +170,7 @@ public Path process(Path inputJar) throws IOException { //LogHelper.debug("[checkSecure] %s: %s", launcherSalt, Arrays.toString(launcherSecureHash)); if (server.runtime.oemUnlockKey == null) server.runtime.oemUnlockKey = SecurityHelper.randomStringToken(); properties.put("runtimeconfig.oemUnlockKey", server.runtime.oemUnlockKey); - context.clientModules.forEach(launcherConfigurator::addModuleClass); + properties.put("launcher.modules", context.clientModules.stream().map(e -> Type.getObjectType(e.replace('.', '/'))).collect(Collectors.toList())); reader.getCp().add(new JarFile(inputJar.toFile())); server.launcherBinary.coreLibs.forEach(e -> { try { diff --git a/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java b/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java index dbe125ce..1ea56772 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java +++ b/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java @@ -31,7 +31,7 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep EnvHelper.checkDangerousParams(); LauncherConfig config = Launcher.getConfig(); LauncherEngine.modulesManager = new ClientModuleManager(); - LauncherConfig.initModules(); + LauncherConfig.initModules(LauncherEngine.modulesManager); LogHelper.info("Launcher for project %s", config.projectName); if (config.environment.equals(LauncherConfig.LauncherEnvironment.PROD)) { diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index e468542f..301cd7b1 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -80,7 +80,7 @@ public static void main(String... args) throws Throwable { LauncherEngine.checkClass(LauncherAgent.class); LauncherEngine.checkClass(ClientLauncher.class); LauncherEngine.modulesManager = new ClientModuleManager(); - LauncherConfig.initModules(); + LauncherConfig.initModules(LauncherEngine.modulesManager); LauncherEngine.modulesManager.initModules(null); // Start Launcher initGson(LauncherEngine.modulesManager); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index ecb96566..db685b77 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -443,7 +443,7 @@ public static void main(String... args) throws Throwable { LauncherEngine.checkClass(LauncherAgent.class); LauncherEngine.checkClass(ClientLauncher.class); LauncherEngine.modulesManager = new ClientModuleManager(); - LauncherConfig.initModules(); //INIT + LauncherConfig.initModules(LauncherEngine.modulesManager); //INIT LauncherEngine.modulesManager.initModules(null); initGson(LauncherEngine.modulesManager); LauncherEngine.verifyNoAgent(); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java b/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java index 33219b4c..906fccb8 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java @@ -1,12 +1,17 @@ package pro.gravit.launcher; +import pro.gravit.launcher.modules.LauncherModule; +import pro.gravit.launcher.modules.LauncherModulesManager; import pro.gravit.launcher.serialize.HInput; import pro.gravit.launcher.serialize.HOutput; import pro.gravit.launcher.serialize.stream.StreamObject; +import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.SecurityHelper; import pro.gravit.utils.helper.VerifyHelper; import java.io.IOException; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; import java.security.cert.CertificateException; import java.security.interfaces.ECPublicKey; import java.security.spec.InvalidKeySpecException; @@ -17,6 +22,8 @@ public final class LauncherConfig extends StreamObject { private static final int cenv = -1; @LauncherInject("launchercore.certificates") private static final List secureConfigCertificates = null; + @LauncherInject("launcher.modules") + private static final List> modulesClasses = null; @LauncherInject("launcher.address") public String address; @LauncherInject("launcher.projectName") @@ -118,17 +125,16 @@ public enum LauncherEnvironment { DEV, DEBUG, STD, PROD } - public static void initModules() { - // TODO Fill - /* - * Old filler - public void addModuleClass(String fullName) { - initModuleMethod.instructions.add(new FieldInsnNode(Opcodes.GETSTATIC, launcherName, "modulesManager", modulesManagerDesc)); - initModuleMethod.instructions.add(new TypeInsnNode(Opcodes.NEW, fullName.replace('.', '/'))); - initModuleMethod.instructions.add(new InsnNode(Opcodes.DUP)); - initModuleMethod.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, fullName.replace('.', '/'), "", "()V")); - initModuleMethod.instructions.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, modulesManagerName, "loadModule", registerModDesc)); - } - */ + private static final MethodType VOID_TYPE = MethodType.methodType(void.class); + + public static void initModules(LauncherModulesManager modulesManager) { + for (Class clazz : modulesClasses) + try { + modulesManager.loadModule((LauncherModule) MethodHandles.publicLookup().findConstructor(clazz, VOID_TYPE).invokeWithArguments(Collections.emptyList())); + } catch (Throwable e) { + LogHelper.error(e); + } + // This method should be called once at exec time. + modulesClasses.clear(); } } From 2a7570b9b6f6bb247c13498ca24a96b746d99044 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Fri, 31 Jan 2020 19:27:06 +0100 Subject: [PATCH 178/192] =?UTF-8?q?[FEATURE]=20=D0=9F=D0=BE=D0=B4=D0=B4?= =?UTF-8?q?=D0=B5=D1=80=D0=B6=D0=BA=D0=B0=201.15.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launchserver/defaults/profile1.15.2.cfg | 38 +++++++++++++++++++ .../launcher/profiles/ClientProfile.java | 3 +- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.15.2.cfg diff --git a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.15.2.cfg b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.15.2.cfg new file mode 100644 index 00000000..d59a68be --- /dev/null +++ b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/profile1.15.2.cfg @@ -0,0 +1,38 @@ +{ + "version": "1.15.2", + "assetIndex": "1.15.2", + "assetDir": "asset1.15.2", + "dir": "HiTech", + "info": "Информация о сервере", + "sortIndex": 0, + "title": "xxxxxxxx", + "serverAddress": "localhost", + "serverPort": 25565, + "update": [ + "servers.dat" + ], + "updateExclusions": [], + "updateShared": [], + "updateVerify": [ + "libraries", + "natives", + "minecraft.jar" + ], + "updateOptional": [], + "updateFastCheck": true, + "useWhitelist": false, + "mainClass": "net.minecraft.client.main.Main", + "jvmArgs": [ + "-XX:+UseConcMarkSweepGC", + "-XX:+CMSIncrementalMode", + "-XX:-UseAdaptiveSizePolicy", + "-Xmn128M", + "-XX:+DisableAttachMechanism" + ], + "classPath": [ + "minecraft.jar", + "libraries" + ], + "clientArgs": [], + "whitelist": [] +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java index 10a25fa2..9f78774f 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java @@ -41,7 +41,8 @@ public enum Version { MC1143("1.14.3", 490), MC1144("1.14.4", 498), MC115("1.15", 573), - MC1151("1.15.1", 575); + MC1151("1.15.1", 575), + MC1152("1.15.2", 578); private static final Map VERSIONS; static { From ff5ed0eb27d0f6394ec8e6946f8e6b4bd9a83064 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Sat, 1 Feb 2020 06:30:04 +0100 Subject: [PATCH 179/192] =?UTF-8?q?[ANY]=20=D0=9D=D0=B5=D0=BC=D0=BD=D0=BE?= =?UTF-8?q?=D0=B3=D0=BE=20=D1=80=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=B8=D0=BD=D0=B3=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../binary/tasks/MainBuildTask.java | 81 ++++++++++--------- 1 file changed, 45 insertions(+), 36 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java index 14c71088..f54d5f57 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java @@ -134,43 +134,10 @@ public Path process(Path inputJar) throws IOException { Path outputJar = server.launcherBinary.nextPath("main"); try (ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(outputJar))) { BuildContext context = new BuildContext(output, reader.getCp(), this); + initProps(); preBuildHook.hook(context); - properties.clear(); - properties.put("launcher.address", server.config.netty.address); - properties.put("launcher.projectName", server.config.projectName); - properties.put("runtimeconfig.secretKeyClient", SecurityHelper.randomStringAESKey()); - properties.put("launcher.port", 32148 + SecurityHelper.newRandom().nextInt(512)); - properties.put("launcher.guardType", server.config.launcher.guardType); - properties.put("launcher.isWarningMissArchJava", server.config.launcher.warningMissArchJava); - properties.put("launchercore.env" ,server.config.env); - properties.put("runtimeconfig.passwordEncryptKey", server.runtime.passwordEncryptKey); - List certificates = Arrays.stream(server.certificateManager.trustManager.getTrusted()).map(e -> { - try { - return e.getEncoded(); - } catch (CertificateEncodingException e2) { - LogHelper.error(e2); - return new byte[0]; - } - }).collect(Collectors.toList()); - if(!server.config.sign.enabled) - { - CertificateAutogenTask task = server.launcherBinary.getTaskByClass(CertificateAutogenTask.class).get(); - try { - certificates.add(task.certificate.getEncoded()); - } catch (CertificateEncodingException e) { - throw new InternalError(e); - } - } - properties.put("launchercore.certificates", certificates); - String launcherSalt = SecurityHelper.randomStringToken(); - byte[] launcherSecureHash = SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA256, - server.runtime.clientCheckSecret.concat(".").concat(launcherSalt)); - properties.put("runtimeconfig.secureCheckHash", Base64.getEncoder().encodeToString(launcherSecureHash)); - properties.put("runtimeconfig.secureCheckSalt", launcherSalt); - //LogHelper.debug("[checkSecure] %s: %s", launcherSalt, Arrays.toString(launcherSecureHash)); - if (server.runtime.oemUnlockKey == null) server.runtime.oemUnlockKey = SecurityHelper.randomStringToken(); - properties.put("runtimeconfig.oemUnlockKey", server.runtime.oemUnlockKey); properties.put("launcher.modules", context.clientModules.stream().map(e -> Type.getObjectType(e.replace('.', '/'))).collect(Collectors.toList())); + postInitProps(); reader.getCp().add(new JarFile(inputJar.toFile())); server.launcherBinary.coreLibs.forEach(e -> { try { @@ -195,7 +162,49 @@ public Path process(Path inputJar) throws IOException { return outputJar; } - public byte[] transformClass(byte[] bytes, String classname, BuildContext context) + protected void postInitProps() { + List certificates = Arrays.stream(server.certificateManager.trustManager.getTrusted()).map(e -> { + try { + return e.getEncoded(); + } catch (CertificateEncodingException e2) { + LogHelper.error(e2); + return new byte[0]; + } + }).collect(Collectors.toList()); + if(!server.config.sign.enabled) + { + CertificateAutogenTask task = server.launcherBinary.getTaskByClass(CertificateAutogenTask.class).get(); + try { + certificates.add(task.certificate.getEncoded()); + } catch (CertificateEncodingException e) { + throw new InternalError(e); + } + } + properties.put("launchercore.certificates", certificates); + } + + protected void initProps() { + properties.clear(); + properties.put("launcher.address", server.config.netty.address); + properties.put("launcher.projectName", server.config.projectName); + properties.put("runtimeconfig.secretKeyClient", SecurityHelper.randomStringAESKey()); + properties.put("launcher.port", 32148 + SecurityHelper.newRandom().nextInt(512)); + properties.put("launcher.guardType", server.config.launcher.guardType); + properties.put("launcher.isWarningMissArchJava", server.config.launcher.warningMissArchJava); + properties.put("launchercore.env" ,server.config.env); + properties.put("runtimeconfig.passwordEncryptKey", server.runtime.passwordEncryptKey); + String launcherSalt = SecurityHelper.randomStringToken(); + byte[] launcherSecureHash = SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA256, + server.runtime.clientCheckSecret.concat(".").concat(launcherSalt)); + properties.put("runtimeconfig.secureCheckHash", Base64.getEncoder().encodeToString(launcherSecureHash)); + properties.put("runtimeconfig.secureCheckSalt", launcherSalt); + //LogHelper.debug("[checkSecure] %s: %s", launcherSalt, Arrays.toString(launcherSecureHash)); + if (server.runtime.oemUnlockKey == null) server.runtime.oemUnlockKey = SecurityHelper.randomStringToken(); + properties.put("runtimeconfig.oemUnlockKey", server.runtime.oemUnlockKey); + + } + + public byte[] transformClass(byte[] bytes, String classname, BuildContext context) { byte[] result = bytes; ClassReader cr = null; From 01b25aa6d8891982e0574023f8ccaba69928aa72 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Sat, 1 Feb 2020 06:42:41 +0100 Subject: [PATCH 180/192] =?UTF-8?q?[AMY]=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B8?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gravit/launchserver/binary/tasks/exe/Launch4JTask.java | 4 ---- modules | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/exe/Launch4JTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/exe/Launch4JTask.java index fbbb3c43..e636439a 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/exe/Launch4JTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/exe/Launch4JTask.java @@ -27,13 +27,9 @@ public void clear() { } } - // URL constants public static final String DOWNLOAD_URL = "http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html"; // Oracle - // JRE 8 - // File constants private final Path faviconFile; - // File constants private final LaunchServer server; public Launch4JTask(LaunchServer launchServer) { diff --git a/modules b/modules index 5464417b..0fbc3fb2 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 5464417b18e27d7ae8ce91861e42f167e11b8215 +Subproject commit 0fbc3fb26c505800a61976cdf1310cad6ab7808d From d68e1f781ecc7ed37d80dcbabba84c6d1a9c8d28 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Sat, 1 Feb 2020 18:17:16 +0100 Subject: [PATCH 181/192] =?UTF-8?q?[FIX]=20NPE=20=D0=B2=20InjectClassAccep?= =?UTF-8?q?tor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/pro/gravit/launchserver/asm/InjectClassAcceptor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java index fc384a91..a852851b 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java @@ -45,9 +45,9 @@ private static void visit(ClassNode classNode, Map values) { classNode.fields.forEach(field -> { // Notice that fields that will be used with this algo should not have default // value by = ...; - AnnotationNode valueAnnotation = field.invisibleAnnotations.stream() + AnnotationNode valueAnnotation = field.invisibleAnnotations != null ? field.invisibleAnnotations.stream() .filter(annotation -> INJECTED_FIELD_DESC.equals(annotation.desc)).findFirst() - .orElse(null); + .orElse(null) : null; if (valueAnnotation == null) { return; } From c714a1a5edd5ad47bcac56546afa604871b3262c Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Sat, 1 Feb 2020 18:59:16 +0100 Subject: [PATCH 182/192] [FIX] Definal --- .../gravit/launchserver/config/LaunchServerConfig.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java index cc43b9e7..312c900c 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java @@ -41,7 +41,7 @@ public LaunchServerConfig setLaunchServer(LaunchServer server) { public String binaryName; - public final boolean copyBinaries = true; + public boolean copyBinaries = true; public LauncherConfig.LauncherEnvironment env; @@ -241,10 +241,10 @@ public static class NettyConfig { public String downloadURL; public String launcherEXEURL; public String address; - public final Map bindings = new HashMap<>(); + public Map bindings = new HashMap<>(); public NettyPerformanceConfig performance; public NettyBindAddress[] binds; - public final LogLevel logLevel = LogLevel.DEBUG; + public LogLevel logLevel = LogLevel.DEBUG; } public static class NettyPerformanceConfig { @@ -254,8 +254,8 @@ public static class NettyPerformanceConfig { } public static class NettyBindAddress { - public final String address; - public final int port; + public String address; + public int port; public NettyBindAddress(String address, int port) { this.address = address; From bde9fd55f9e21cea2db7ac0fb8bfd3c509cf82bc Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Thu, 6 Feb 2020 17:27:39 +0100 Subject: [PATCH 183/192] =?UTF-8?q?[FIX]=20UOE=20=D0=B2=20=D1=81=D0=B5?= =?UTF-8?q?=D1=80=D0=B8=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D0=B8=20?= =?UTF-8?q?LauncherEnvironment.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../binary/tasks/MainBuildTask.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java index f54d5f57..2a4dd068 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java @@ -8,6 +8,7 @@ import org.objectweb.asm.tree.FieldNode; import pro.gravit.launcher.Launcher; import pro.gravit.launcher.LauncherConfig; +import pro.gravit.launcher.LauncherConfig.LauncherEnvironment; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.asm.ClassMetadataReader; import pro.gravit.launchserver.asm.InjectClassAcceptor; @@ -191,7 +192,22 @@ protected void initProps() { properties.put("launcher.port", 32148 + SecurityHelper.newRandom().nextInt(512)); properties.put("launcher.guardType", server.config.launcher.guardType); properties.put("launcher.isWarningMissArchJava", server.config.launcher.warningMissArchJava); - properties.put("launchercore.env" ,server.config.env); + int cenv = -1; + switch (server.config.env) { + case DEV: + cenv = 0; + break; + case DEBUG: + cenv = 1; + break; + case STD: + cenv = 2; + break; + case PROD: + cenv = 3; + break; + } + properties.put("launchercore.env", cenv); properties.put("runtimeconfig.passwordEncryptKey", server.runtime.passwordEncryptKey); String launcherSalt = SecurityHelper.randomStringToken(); byte[] launcherSecureHash = SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA256, From 0e4502d38f913317d4040406ed3992f4ea558f63 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Mon, 10 Feb 2020 19:10:08 +0100 Subject: [PATCH 184/192] =?UTF-8?q?[FIX]=20=D0=9D=D0=BE=D1=80=D0=BC=D0=B0?= =?UTF-8?q?=D0=BB=D1=8C=D0=BD=D0=B0=D1=8F=20=D1=81=D0=B5=D1=80=D0=B8=D0=B0?= =?UTF-8?q?=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20Enum.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launchserver/asm/InjectClassAcceptor.java | 2 ++ .../main/java/pro/gravit/launchserver/asm/NodeUtils.java | 7 +++++++ .../gravit/launchserver/binary/tasks/MainBuildTask.java | 1 - 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java index a852851b..fe5da412 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java @@ -171,6 +171,8 @@ private static InsnList serializeValue(Object value) { insnList.add(new LdcInsnNode(value)); return insnList; } + if (Enum.class.isInstance(value)) + return NodeUtils.makeValueEnumGetter((Enum)value); for (Map.Entry, Serializer> serializerEntry : serializers.entrySet()) { if (serializerEntry.getKey().isInstance(value)) { return ((Serializer) serializerEntry.getValue()).serialize(value); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/NodeUtils.java b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/NodeUtils.java index b85a27bd..1aabfbcf 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/NodeUtils.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/NodeUtils.java @@ -246,4 +246,11 @@ else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) ret.add(new LdcInsnNode(value)); return ret; } + + public static InsnList makeValueEnumGetter(@SuppressWarnings("rawtypes") Enum u) { + InsnList ret = new InsnList(); + Type e = Type.getType(u.getClass()); + ret.add(new FieldInsnNode(Opcodes.GETSTATIC, e.getInternalName(), u.name(), e.getDescriptor())); + return ret; + } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java index 2a4dd068..bbe656b9 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java @@ -8,7 +8,6 @@ import org.objectweb.asm.tree.FieldNode; import pro.gravit.launcher.Launcher; import pro.gravit.launcher.LauncherConfig; -import pro.gravit.launcher.LauncherConfig.LauncherEnvironment; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.asm.ClassMetadataReader; import pro.gravit.launchserver.asm.InjectClassAcceptor; From b57ad715393520db62e9b8e9ab14e70f003285c8 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Mon, 10 Feb 2020 19:12:47 +0100 Subject: [PATCH 185/192] =?UTF-8?q?[REFACTOR]=20=D0=A3=D0=B4=D0=B0=D0=BB?= =?UTF-8?q?=D1=91=D0=BD=20=D0=BA=D0=BE=D1=81=D1=82=D1=8B=D0=BB=D1=8C=20?= =?UTF-8?q?=D1=81=20=D1=81=D0=B5=D1=80=D0=B8=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D0=B5=D0=B9=20LauncherEnvironment.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../binary/tasks/MainBuildTask.java | 17 +---------------- .../pro/gravit/launcher/LauncherConfig.java | 14 +++----------- 2 files changed, 4 insertions(+), 27 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java index bbe656b9..5805c146 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java @@ -191,22 +191,7 @@ protected void initProps() { properties.put("launcher.port", 32148 + SecurityHelper.newRandom().nextInt(512)); properties.put("launcher.guardType", server.config.launcher.guardType); properties.put("launcher.isWarningMissArchJava", server.config.launcher.warningMissArchJava); - int cenv = -1; - switch (server.config.env) { - case DEV: - cenv = 0; - break; - case DEBUG: - cenv = 1; - break; - case STD: - cenv = 2; - break; - case PROD: - cenv = 3; - break; - } - properties.put("launchercore.env", cenv); + properties.put("launchercore.env", server.config.env); properties.put("runtimeconfig.passwordEncryptKey", server.runtime.passwordEncryptKey); String launcherSalt = SecurityHelper.randomStringToken(); byte[] launcherSecureHash = SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA256, diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java b/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java index 906fccb8..7461ecd4 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java @@ -18,8 +18,6 @@ import java.util.*; public final class LauncherConfig extends StreamObject { - @LauncherInject("launchercore.env") - private static final int cenv = -1; @LauncherInject("launchercore.certificates") private static final List secureConfigCertificates = null; @LauncherInject("launcher.modules") @@ -42,6 +40,7 @@ public final class LauncherConfig extends StreamObject { public final Map runtime; @LauncherInject("launcher.isWarningMissArchJava") public final boolean isWarningMissArchJava; + @LauncherInject("launchercore.env") public LauncherEnvironment environment; @LauncherInject("launcher.guardType") public final String guardType; @@ -52,7 +51,6 @@ public final class LauncherConfig extends StreamObject { @LauncherInject("runtimeconfig.passwordEncryptKey") public final String passwordEncryptKey; - @SuppressWarnings("unused") @LauncherInjectionConstructor public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException { publicKey = SecurityHelper.toPublicECKey(input.readByteArray(SecurityHelper.CRYPTO_MAX_LENGTH)); @@ -72,14 +70,8 @@ public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException isWarningMissArchJava = false; guardType = null; address = null; - LauncherEnvironment env; - if (cenv == 0) env = LauncherEnvironment.DEV; - else if (cenv == 1) env = LauncherEnvironment.DEBUG; - else if (cenv == 2) env = LauncherEnvironment.STD; - else if (cenv == 3) env = LauncherEnvironment.PROD; - else env = LauncherEnvironment.STD; - Launcher.applyLauncherEnv(env); - environment = env; + environment = LauncherEnvironment.STD; + Launcher.applyLauncherEnv(environment); // Read signed runtime int count = input.readLength(0); Map localResources = new HashMap<>(count); From adefda970e8258f83b1f74439efbb02c5dc6033d Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Mon, 10 Feb 2020 19:18:22 +0100 Subject: [PATCH 186/192] =?UTF-8?q?[FIX]=20=D0=91=D0=BE=D0=BB=D0=B5=D0=B5?= =?UTF-8?q?=20=D0=B1=D1=8B=D1=81=D1=82=D1=80=D0=BE=D0=B5=20=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=BB=D1=83=D1=87=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=B9=D0=B4=D0=B5=D1=80=D0=B0=20=D0=BF=D0=BE=20?= =?UTF-8?q?=D0=BD=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD=D0=B8=D0=B9...=20(=D0=BA?= =?UTF-8?q?=D0=BE=D0=BB=D0=BB=D0=B5=D0=BA=D1=86=D0=B8=D1=8F=20=D0=B2=20?= =?UTF-8?q?=D0=BA=D0=BE=D1=82=D0=BE=D1=80=D0=BE=D0=B9=20=D0=BE=D0=BD=20?= =?UTF-8?q?=D1=85=D1=80=D0=B0=D0=BD=D0=B8=D1=82=D1=81=D1=8F=20lasy=20fill)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launchserver/config/LaunchServerConfig.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java index 312c900c..73b62f03 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java @@ -52,12 +52,15 @@ public LaunchServerConfig setLaunchServer(LaunchServer server) { public DaoProvider dao; private transient AuthProviderPair authDefault; + private transient Map authPairs = null; public AuthProviderPair getAuthProviderPair(String name) { - for (AuthProviderPair pair : auth) { - if (pair.name.equals(name)) return pair; - } - return null; + if (authPairs == null) { + Map pairs = new HashMap<>(); + for (AuthProviderPair p : auth) pairs.put(p.name, p); + authPairs = pairs; + } + return authPairs.get(name); } public ProtectHandler protectHandler; @@ -125,6 +128,7 @@ public void verify() { public void init(LaunchServer.ReloadType type) { Launcher.applyLauncherEnv(env); + authPairs = null; for (AuthProviderPair provider : auth) { provider.init(server); } @@ -144,8 +148,6 @@ public void init(LaunchServer.ReloadType type) { server.registerObject("auth.".concat(pair.name).concat(".hwid"), pair.hwid); } } - - Arrays.stream(mirrors).forEach(server.mirrorManager::addMirror); } From dab4b21ae7d4d3a7678b7e6e8b059f1dd82d8543 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Mon, 10 Feb 2020 19:35:48 +0100 Subject: [PATCH 187/192] =?UTF-8?q?[FIX]=20=D0=9B=D0=B8=D1=88=D0=BD=D0=B8?= =?UTF-8?q?=D0=B9=20if.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gravit/launchserver/asm/InjectClassAcceptor.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java index fe5da412..66dcd9c8 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java @@ -14,6 +14,7 @@ import pro.gravit.launcher.LauncherInject; import pro.gravit.launcher.LauncherInjectionConstructor; +@SuppressWarnings("rawtypes") public class InjectClassAcceptor implements MainBuildTask.ASMTransformer { private final Map values; @@ -139,6 +140,7 @@ public void visit(final String name, final Object value) { ret.add(new InsnNode(Opcodes.I2C)); return ret; }); + serializers.put(Enum.class, (Serializer) value -> NodeUtils.makeValueEnumGetter(value)); } private static Serializer serializerClass(int opcode) { @@ -159,7 +161,7 @@ private interface Serializer { InsnList serialize(T value); } - @SuppressWarnings({ "unchecked", "rawtypes" }) + @SuppressWarnings("unchecked") private static InsnList serializeValue(Object value) { if (value == null) { InsnList insnList = new InsnList(); @@ -171,8 +173,6 @@ private static InsnList serializeValue(Object value) { insnList.add(new LdcInsnNode(value)); return insnList; } - if (Enum.class.isInstance(value)) - return NodeUtils.makeValueEnumGetter((Enum)value); for (Map.Entry, Serializer> serializerEntry : serializers.entrySet()) { if (serializerEntry.getKey().isInstance(value)) { return ((Serializer) serializerEntry.getValue()).serialize(value); @@ -182,9 +182,7 @@ private static InsnList serializeValue(Object value) { value.getClass())); } - @SuppressWarnings("rawtypes") private static class ListSerializer implements Serializer { - @Override public InsnList serialize(List value) { InsnList insnList = new InsnList(); @@ -204,9 +202,7 @@ public InsnList serialize(List value) { } } - @SuppressWarnings("rawtypes") private static class MapSerializer implements Serializer { - @Override public InsnList serialize(Map value) { InsnList insnList = new InsnList(); From f2c0815123c317318d009eb6ef9014406c794882 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Tue, 11 Feb 2020 06:08:35 +0100 Subject: [PATCH 188/192] =?UTF-8?q?[FIX]=20=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=85=D1=80=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20AuthProvider=20=D0=B2=20[]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launchserver/LaunchServer.java | 2 +- .../launchserver/auth/AuthProviderPair.java | 10 ++--- .../command/service/ServerStatusCommand.java | 2 +- .../config/LaunchServerConfig.java | 38 +++++++++---------- .../auth/GetAvailabilityAuthResponse.java | 2 +- 5 files changed, 25 insertions(+), 29 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java index 251d9374..c0a511f1 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java @@ -76,7 +76,7 @@ public interface LaunchServerConfigManager { public void reload(ReloadType type) throws Exception { config.close(type); - AuthProviderPair[] pairs = null; + Map pairs = null; if (type.equals(ReloadType.NO_AUTH)) { pairs = config.auth; } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java index 5af479e3..e9da8e5e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java @@ -15,20 +15,20 @@ public class AuthProviderPair { public TextureProvider textureProvider; public HWIDHandler hwid; public Map links; - public final String name; + public transient String name; public String displayName; public final boolean isDefault = true; - public AuthProviderPair(AuthProvider provider, AuthHandler handler, TextureProvider textureProvider, HWIDHandler hwid, String name) { + public AuthProviderPair(AuthProvider provider, AuthHandler handler, TextureProvider textureProvider, HWIDHandler hwid) { this.provider = provider; this.handler = handler; this.textureProvider = textureProvider; this.hwid = hwid; - this.name = name; } - public void init(LaunchServer srv) { - if(links != null) link(srv); + public void init(LaunchServer srv, String name) { + this.name = name; + if(links != null) link(srv); if(provider == null) throw new NullPointerException(String.format("Auth %s provider null", name)); if(handler == null) throw new NullPointerException(String.format("Auth %s handler null", name)); if(textureProvider == null) throw new NullPointerException(String.format("Auth %s textureProvider null", name)); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/ServerStatusCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/ServerStatusCommand.java index d5a270e5..f7c1b9cd 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/ServerStatusCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/ServerStatusCommand.java @@ -39,7 +39,7 @@ public void invoke(String... args) { commands += category.category.commandsMap().size(); } LogHelper.info("Sessions: %d | Commands: %d(%d categories)", server.sessionManager.getSessions().size(), commands, server.commandHandler.getCategories().size() + 1); - for (AuthProviderPair pair : server.config.auth) { + for (AuthProviderPair pair : server.config.auth.values()) { if (pair.handler instanceof CachedAuthHandler) { LogHelper.info("AuthHandler %s: EntryCache: %d | usernameCache: %d", pair.name, ((CachedAuthHandler) pair.handler).getEntryCache().size(), ((CachedAuthHandler) pair.handler).getUsernamesCache().size()); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java index 73b62f03..c405d378 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java @@ -47,27 +47,21 @@ public LaunchServerConfig setLaunchServer(LaunchServer server) { // Handlers & Providers - public AuthProviderPair[] auth; + public Map auth; public DaoProvider dao; private transient AuthProviderPair authDefault; - private transient Map authPairs = null; public AuthProviderPair getAuthProviderPair(String name) { - if (authPairs == null) { - Map pairs = new HashMap<>(); - for (AuthProviderPair p : auth) pairs.put(p.name, p); - authPairs = pairs; - } - return authPairs.get(name); + return auth.get(name); } public ProtectHandler protectHandler; public AuthProviderPair getAuthProviderPair() { if (authDefault != null) return authDefault; - for (AuthProviderPair pair : auth) { + for (AuthProviderPair pair : auth.values()) { if (pair.isDefault) { authDefault = pair; return pair; @@ -102,11 +96,12 @@ public void setEnv(LauncherConfig.LauncherEnvironment env) { public void verify() { - if (auth == null || auth[0] == null) { - throw new NullPointerException("AuthHandler must not be null"); + if (auth == null || auth.size() < 1) { + throw new NullPointerException("AuthProviderPair`s count should be at least one"); } + boolean isOneDefault = false; - for (AuthProviderPair pair : auth) { + for (AuthProviderPair pair : auth.values()) { if (pair.isDefault) { isOneDefault = true; break; @@ -128,9 +123,8 @@ public void verify() { public void init(LaunchServer.ReloadType type) { Launcher.applyLauncherEnv(env); - authPairs = null; - for (AuthProviderPair provider : auth) { - provider.init(server); + for (Map.Entry provider : auth.entrySet()) { + provider.getValue().init(server, provider.getKey()); } if (dao != null) dao.init(server); @@ -141,7 +135,7 @@ public void init(LaunchServer.ReloadType type) { components.forEach((k, v) -> server.registerObject("component.".concat(k), v)); } if (!type.equals(LaunchServer.ReloadType.NO_AUTH)) { - for (AuthProviderPair pair : auth) { + for (AuthProviderPair pair : auth.values()) { server.registerObject("auth.".concat(pair.name).concat(".provider"), pair.provider); server.registerObject("auth.".concat(pair.name).concat(".handler"), pair.handler); server.registerObject("auth.".concat(pair.name).concat(".texture"), pair.textureProvider); @@ -154,7 +148,7 @@ public void init(LaunchServer.ReloadType type) { public void close(LaunchServer.ReloadType type) { try { if (!type.equals(LaunchServer.ReloadType.NO_AUTH)) { - for (AuthProviderPair pair : auth) { + for (AuthProviderPair pair : auth.values()) { server.unregisterObject("auth.".concat(pair.name).concat(".provider"), pair.provider); server.unregisterObject("auth.".concat(pair.name).concat(".handler"), pair.handler); server.unregisterObject("auth.".concat(pair.name).concat(".texture"), pair.textureProvider); @@ -177,7 +171,7 @@ public void close(LaunchServer.ReloadType type) { LogHelper.error(e); } try { - for (AuthProviderPair p : auth) p.close(); + for (AuthProviderPair p : auth.values()) p.close(); } catch (IOException e) { LogHelper.error(e); } @@ -282,11 +276,13 @@ public static LaunchServerConfig getDefault(LaunchServer.LaunchServerEnv env) { newConfig.launch4j.maxVersion = "1.8.999"; newConfig.env = LauncherConfig.LauncherEnvironment.STD; newConfig.startScript = JVMHelper.OS_TYPE.equals(JVMHelper.OS.MUSTDIE) ? "." + File.separator + "start.bat" : "." + File.separator + "start.sh"; - newConfig.auth = new AuthProviderPair[]{new AuthProviderPair(new RejectAuthProvider("Настройте authProvider"), + newConfig.auth = new HashMap<>(); + AuthProviderPair a = new AuthProviderPair(new RejectAuthProvider("Настройте authProvider"), new MemoryAuthHandler(), new RequestTextureProvider("http://example.com/skins/%username%.png", "http://example.com/cloaks/%username%.png") - , new AcceptHWIDHandler(), "std")}; - newConfig.auth[0].displayName = "Default"; + , new AcceptHWIDHandler()); + a.displayName = "Default"; + newConfig.auth.put("std", a); newConfig.protectHandler = new StdProtectHandler(); if (env.equals(LaunchServer.LaunchServerEnv.TEST)) newConfig.binaryName = "Launcher"; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/GetAvailabilityAuthResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/GetAvailabilityAuthResponse.java index 79e63047..f617d67c 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/GetAvailabilityAuthResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/GetAvailabilityAuthResponse.java @@ -18,7 +18,7 @@ public String getType() { @Override public void execute(ChannelHandlerContext ctx, Client client) { List list = new ArrayList<>(); - for (AuthProviderPair pair : server.config.auth) { + for (AuthProviderPair pair : server.config.auth.values()) { list.add(new GetAvailabilityAuthRequestEvent.AuthAvailability(pair.name, pair.displayName, pair.provider.getFirstAuthType(), pair.provider.getSecondAuthType())); } sendResult(new GetAvailabilityAuthRequestEvent(list)); From cfc140d47c4288f8edbc20cd4b005bcf1adf24d5 Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 17 Feb 2020 08:35:02 +0700 Subject: [PATCH 189/192] [FIX] binaryName fixes and optimize InjectClassAcceptor --- .../java/pro/gravit/launchserver/asm/InjectClassAcceptor.java | 4 ++-- .../pro/gravit/launchserver/config/LaunchServerConfig.java | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java index 66dcd9c8..af5a62be 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java @@ -136,11 +136,11 @@ public void visit(final String name, final Object value) { }); serializers.put(Character.class, (Serializer) e -> { InsnList ret = new InsnList(); - ret.add(NodeUtils.push((int) e.charValue())); + ret.add(NodeUtils.push((int) e)); ret.add(new InsnNode(Opcodes.I2C)); return ret; }); - serializers.put(Enum.class, (Serializer) value -> NodeUtils.makeValueEnumGetter(value)); + serializers.put(Enum.class, (Serializer) NodeUtils::makeValueEnumGetter); } private static Serializer serializerClass(int opcode) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java index c405d378..45077405 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java @@ -284,7 +284,6 @@ public static LaunchServerConfig getDefault(LaunchServer.LaunchServerEnv env) { a.displayName = "Default"; newConfig.auth.put("std", a); newConfig.protectHandler = new StdProtectHandler(); - if (env.equals(LaunchServer.LaunchServerEnv.TEST)) newConfig.binaryName = "Launcher"; newConfig.whitelistRejectString = "Вас нет в белом списке"; From a3800958dbc1ef334c73bf8741a093f2095d9b57 Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 17 Feb 2020 08:51:59 +0700 Subject: [PATCH 190/192] [FIX] ConnectionTypes.SERVER deprecated --- .../gravit/launchserver/manangers/SessionManager.java | 3 +-- .../launchserver/socket/response/auth/AuthResponse.java | 9 ++++----- .../socket/response/auth/CheckServerResponse.java | 5 +++++ .../socket/response/auth/JoinServerResponse.java | 5 +++++ .../pro/gravit/launcher/request/auth/AuthRequest.java | 5 ++--- .../java/pro/gravit/launcher/server/ServerWrapper.java | 2 +- 6 files changed, 18 insertions(+), 11 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/SessionManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/SessionManager.java index 55b860f1..2601c110 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/SessionManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/SessionManager.java @@ -14,7 +14,6 @@ public class SessionManager implements NeedGarbageCollection { public static final long SESSION_TIMEOUT = 3 * 60 * 60 * 1000; // 3 часа - public static final boolean GARBAGE_SERVER = Boolean.parseBoolean(System.getProperty("launcher.garbageSessionsServer", "false")); private final Map clientSet = new HashMap<>(128); @@ -28,7 +27,7 @@ public void garbageCollection() { long time = System.currentTimeMillis(); clientSet.entrySet().removeIf(entry -> { Client c = entry.getValue(); - return (c.timestamp + SESSION_TIMEOUT < time) && ((c.type == AuthResponse.ConnectTypes.CLIENT) || ((c.type == AuthResponse.ConnectTypes.SERVER) && GARBAGE_SERVER)); + return (c.timestamp + SESSION_TIMEOUT < time); }); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java index 31832e91..0b454744 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java @@ -42,7 +42,10 @@ public class AuthResponse extends SimpleResponse { public HWID hwid; public enum ConnectTypes { - SERVER, CLIENT, API + @Deprecated + SERVER, + CLIENT, + API } @Override @@ -109,10 +112,6 @@ public void execute(ChannelHandlerContext ctx, Client clientData) throws Excepti clientData.username = login; result.accessToken = aresult.accessToken; result.permissions = clientData.permissions; - if (authType == ConnectTypes.SERVER && !clientData.permissions.canServer) { - AuthProvider.authError("authType: SERVER not allowed for this account"); - return; - } if (getSession) { if (clientData.session == 0) { clientData.session = random.nextLong(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/CheckServerResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/CheckServerResponse.java index bd49d359..a7b1baee 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/CheckServerResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/CheckServerResponse.java @@ -21,6 +21,11 @@ public String getType() { @Override public void execute(ChannelHandlerContext ctx, Client pClient) { + if(!pClient.isAuth || pClient.type == AuthResponse.ConnectTypes.CLIENT) + { + sendError("Permissions denied"); + return; + } CheckServerRequestEvent result = new CheckServerRequestEvent(); try { server.authHookManager.checkServerHook.hook(this, pClient); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/JoinServerResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/JoinServerResponse.java index 685e3c66..a577c3b0 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/JoinServerResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/JoinServerResponse.java @@ -20,6 +20,11 @@ public String getType() { @Override public void execute(ChannelHandlerContext ctx, Client client) { + if(!client.isAuth || client.type != AuthResponse.ConnectTypes.CLIENT) + { + sendError("Permissions denied"); + return; + } boolean success; try { server.authHookManager.joinServerHook.hook(this, client); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/AuthRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/AuthRequest.java index 2d311294..5ce3bc78 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/AuthRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/AuthRequest.java @@ -35,14 +35,13 @@ public interface AuthPasswordInterface { public boolean initProxy; public enum ConnectTypes { + @Deprecated @LauncherNetworkAPI SERVER, @LauncherNetworkAPI CLIENT, @LauncherNetworkAPI - BOT, - @LauncherNetworkAPI - PROXY + API } diff --git a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java index 6093920d..59a37e42 100644 --- a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java +++ b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java @@ -53,7 +53,7 @@ public ServerWrapper(Type type, Path configPath) { public boolean auth() { try { Launcher.getConfig(); - AuthRequest request = new AuthRequest(config.login, config.password, config.auth_id, AuthRequest.ConnectTypes.SERVER); + AuthRequest request = new AuthRequest(config.login, config.password, config.auth_id, AuthRequest.ConnectTypes.API); permissions = request.request().permissions; ProfilesRequestEvent result = new ProfilesRequest().request(); for (ClientProfile p : result.profiles) { From f8aab106097d2d2b357429b3304c59336331402b Mon Sep 17 00:00:00 2001 From: Gravit Date: Fri, 21 Feb 2020 11:17:16 +0700 Subject: [PATCH 191/192] [FIX] WARN non signed modules --- .../pro/gravit/launchserver/LaunchServerStarter.java | 8 ++++---- .../java/pro/gravit/launchserver/asm/NodeUtils.java | 11 +---------- .../pro/gravit/launchserver/binary/ProguardConf.java | 7 ++----- .../modules/impl/LaunchServerModulesManager.java | 1 + 4 files changed, 8 insertions(+), 19 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java index 9dfe712f..3e31b828 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java @@ -69,10 +69,10 @@ public static void main(String[] args) throws Exception { throw new IOException(e); } { - LauncherTrustManager.CheckMode mode = (Version.RELEASE == Version.Type.LTS || Version.RELEASE == Version.Type.STABLE) ? - (allowUnsigned ? LauncherTrustManager.CheckMode.WARN_IN_NOT_SIGNED : LauncherTrustManager.CheckMode.EXCEPTION_IN_NOT_SIGNED) : - (allowUnsigned ? LauncherTrustManager.CheckMode.NONE_IN_NOT_SIGNED : LauncherTrustManager.CheckMode.WARN_IN_NOT_SIGNED); - certificateManager.checkClass(LaunchServer.class, mode); + //LauncherTrustManager.CheckMode mode = (Version.RELEASE == Version.Type.LTS || Version.RELEASE == Version.Type.STABLE) ? + // (allowUnsigned ? LauncherTrustManager.CheckMode.WARN_IN_NOT_SIGNED : LauncherTrustManager.CheckMode.EXCEPTION_IN_NOT_SIGNED) : + // (allowUnsigned ? LauncherTrustManager.CheckMode.NONE_IN_NOT_SIGNED : LauncherTrustManager.CheckMode.WARN_IN_NOT_SIGNED); + certificateManager.checkClass(LaunchServer.class, LauncherTrustManager.CheckMode.NONE_IN_NOT_SIGNED); } LaunchServerRuntimeConfig runtimeConfig; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/NodeUtils.java b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/NodeUtils.java index 1aabfbcf..ea8f00f1 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/NodeUtils.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/NodeUtils.java @@ -5,6 +5,7 @@ import org.objectweb.asm.Type; import org.objectweb.asm.tree.*; import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.JarHelper; import java.io.IOException; @@ -16,17 +17,7 @@ import static org.objectweb.asm.Opcodes.*; public final class NodeUtils { - public static final boolean JAVA9; - static { - boolean java9 = false; - try { - Class.forName("java.lang.StackWalker"); - java9 = true; - } catch (final Throwable e) { - } - JAVA9 = java9; - } private NodeUtils() { } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/ProguardConf.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/ProguardConf.java index 9201cad4..7b3bf8fc 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/ProguardConf.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/ProguardConf.java @@ -2,10 +2,7 @@ import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.asm.NodeUtils; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.LogHelper; -import pro.gravit.utils.helper.SecurityHelper; -import pro.gravit.utils.helper.UnpackHelper; +import pro.gravit.utils.helper.*; import java.io.IOException; import java.io.OutputStreamWriter; @@ -61,7 +58,7 @@ public String[] buildConfig(Path inputJar, Path outputJar) { confStrs.add("-obfuscationdictionary \'" + words.toFile().getName() + "\'"); confStrs.add("-injar \'" + inputJar.toAbsolutePath() + "\'"); confStrs.add("-outjar \'" + outputJar.toAbsolutePath() + "\'"); - Collections.addAll(confStrs, NodeUtils.JAVA9 ? JAVA9_OPTS : JAVA8_OPTS); + Collections.addAll(confStrs, JVMHelper.JVM_VERSION >= 9 ? JAVA9_OPTS : JAVA8_OPTS); srv.launcherBinary.coreLibs.stream() .map(e -> "-libraryjars \'" + e.toAbsolutePath().toString() + "\'") .forEach(confStrs::add); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerModulesManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerModulesManager.java index 409435e9..cdc61bd8 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerModulesManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerModulesManager.java @@ -16,6 +16,7 @@ public class LaunchServerModulesManager extends SimpleModuleManager { public LaunchServerModulesManager(Path modulesDir, Path configDir, LauncherTrustManager trustManager) { super(modulesDir, configDir, trustManager); coreModule = new LaunchServerCoreModule(); + checkMode = LauncherTrustManager.CheckMode.NONE_IN_NOT_SIGNED; modules.add(coreModule); } From 76ecbaa19ed6faf0f9e8370797e7b14844854462 Mon Sep 17 00:00:00 2001 From: Gravit Date: Fri, 21 Feb 2020 11:31:36 +0700 Subject: [PATCH 192/192] [ANY] 5.1.0 beta --- LauncherCore/src/main/java/pro/gravit/utils/Version.java | 2 +- build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LauncherCore/src/main/java/pro/gravit/utils/Version.java b/LauncherCore/src/main/java/pro/gravit/utils/Version.java index 817dfe84..0f5b3f1e 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/Version.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/Version.java @@ -17,7 +17,7 @@ public final class Version { public static final int MINOR = 1; public static final int PATCH = 0; public static final int BUILD = 1; - public static final Version.Type RELEASE = Type.DEV; + public static final Version.Type RELEASE = Type.BETA; public Version(int major, int minor, int patch) { diff --git a/build.gradle b/build.gradle index e1c5c020..ddaddb54 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ id 'signing' } group = 'pro.gravit.launcher' -version = '5.1.0-SNAPSHOT' +version = '5.1.0' configure(subprojects.findAll { it.name != 'modules' }) { apply plugin: 'idea'