From a8c407e2fb51fdbebd9e715c466ee82f2421cc3c Mon Sep 17 00:00:00 2001 From: Big Energy Date: Fri, 11 Oct 2019 17:52:30 +0300 Subject: [PATCH 01/11] =?UTF-8?q?[FIX]=20=D0=9F=D0=B5=D1=80=D0=B5=D0=BF?= =?UTF-8?q?=D1=83=D1=82=D0=B0=D0=BD=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B7?= =?UTF-8?q?=D1=80=D1=8F=D0=B4=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20=D0=B2=D1=80?= =?UTF-8?q?=D0=B0=D0=BF=D0=BF=D0=B5=D1=80=D0=B0=20(#343)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/pro/gravit/launcher/guard/LauncherGravitGuard.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 4052673a..30f24026 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherGravitGuard.java +++ b/Launcher/src/main/java/pro/gravit/launcher/guard/LauncherGravitGuard.java @@ -50,7 +50,7 @@ public int getClientJVMBits() { public void init(boolean clientInstance) { try { String projectName = Launcher.getConfig().projectname; - UnpackHelper.unpack(Launcher.getResourceURL("wrapper32.exe", "guard"), DirBridge.getGuardDir().resolve(projectName.concat("64.exe"))); + 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")); UnpackHelper.unpack(Launcher.getResourceURL("wrapper32.exe", "guard"), DirBridge.getGuardDir().resolve(projectName.concat("32.exe"))); From 897f799aac93b3d678c777d1e0d066c7174b8515 Mon Sep 17 00:00:00 2001 From: Gravit Date: Tue, 15 Oct 2019 13:52:28 +0700 Subject: [PATCH 02/11] =?UTF-8?q?[FIX]=20Mojang=20=D0=B0=D0=B2=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=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 | 5 ++--- modules | 2 +- 2 files changed, 3 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 9173eecf..ff1db902 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -114,7 +114,7 @@ public Params(byte[] launcherDigest, Path assetDir, Path clientDir, PlayerProfil this.clientDir = clientDir; // Client params this.pp = pp; - this.accessToken = SecurityHelper.verifyToken(accessToken); + this.accessToken = accessToken; this.autoEnter = autoEnter; this.fullScreen = fullScreen; this.ram = ram; @@ -132,8 +132,7 @@ public Params(HInput input) throws Exception { // Client params pp = new PlayerProfile(input); byte[] encryptedAccessToken = input.readByteArray(SecurityHelper.CRYPTO_MAX_LENGTH); - String accessTokenD = new String(SecurityHelper.decrypt(Launcher.getConfig().secretKeyClient.getBytes(), encryptedAccessToken)); - accessToken = SecurityHelper.verifyToken(accessTokenD); + accessToken = new String(SecurityHelper.decrypt(Launcher.getConfig().secretKeyClient.getBytes(), encryptedAccessToken)); autoEnter = input.readBoolean(); fullScreen = input.readBoolean(); ram = input.readVarInt(); diff --git a/modules b/modules index 1df96f6e..960e178b 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 1df96f6e28870a0c3a8cb547306b0eb64b65a75a +Subproject commit 960e178bc658835dc8aff93ee51e10e52bc7afb5 From ce28ac40578581779db6b49571269ec407ea2ddc Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 16 Oct 2019 16:38:44 +0700 Subject: [PATCH 03/11] =?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 04/11] =?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 05/11] =?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 06/11] =?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 07/11] =?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 08/11] =?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 09/11] =?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 10/11] =?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 11/11] =?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");