From f81e32122349e0dd79d1ec25ebe18988e69f04cc Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Sun, 1 Mar 2020 12:34:31 +0100 Subject: [PATCH 01/25] =?UTF-8?q?[FEATURE]=20=D0=A5=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D0=B8=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=B2=D0=B8=D1=81=D0=B8=D0=BC=D0=BE=D1=81=D1=82=D0=B5?= =?UTF-8?q?=D0=B9=20=D0=B2=20=D0=BE=D1=82=D0=B4=D0=B5=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D0=BE=D0=BC=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B5=20(=D1=87.=201)..?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LaunchServer/build.gradle | 52 +++++++++++++++++++----------------- Launcher/build.gradle | 6 ++--- LauncherAPI/build.gradle | 4 +-- LauncherAuthlib/build.gradle | 2 +- LauncherCore/build.gradle | 14 +++++----- ServerWrapper/build.gradle | 2 +- build.gradle | 2 ++ props.gradle | 17 ++++++++++++ 8 files changed, 60 insertions(+), 39 deletions(-) create mode 100644 props.gradle diff --git a/LaunchServer/build.gradle b/LaunchServer/build.gradle index 84875664..cf91ce83 100644 --- a/LaunchServer/build.gradle +++ b/LaunchServer/build.gradle @@ -28,10 +28,10 @@ } jar { - dependsOn parent.childProjects.Launcher.tasks.build + dependsOn parent.childProjects.Launcher.tasks.assemble from { configurations.pack.collect { it.isDirectory() ? it : zipTree(it) } } - from(parent.childProjects.Launcher.tasks.shadowJar.archivePath) - from(parent.childProjects.Launcher.tasks.genRuntimeJS.archivePath) + from(parent.childProjects.Launcher.tasks.shadowJar) + from(parent.childProjects.Launcher.tasks.genRuntimeJS) manifest.attributes("Main-Class": mainClassName, "Premain-Class": mainAgentName, "Can-Redefine-Classes": "true", @@ -71,24 +71,22 @@ task cleanjar(type: Jar, dependsOn: jar) { dependencies { pack project(':LauncherAPI') - 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' - 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.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' + bundle group: 'org.fusesource.jansi', name:'jansi', version: rootProject['verJansi'] + bundle group: 'org.jline', name: 'jline', version: rootProject['verJline'] + bundle group: 'org.jline', name: 'jline-reader', version: rootProject['verJline'] + bundle group: 'org.jline', name: 'jline-terminal', version: rootProject['verJline'] + bundle group: 'org.bouncycastle', name: 'bcpkix-jdk15on', version: rootProject['verBcpkix'] + bundle group: 'org.ow2.asm', name: 'asm-commons', version: rootProject['verAsm'] + bundle group: 'io.netty', name: 'netty-all', version: rootProject['verNetty'] + bundle group: 'org.slf4j', name: 'slf4j-simple', version: rootProject['verSlf4j'] + bundle group: 'org.slf4j', name: 'slf4j-api', version: rootProject['verSlf4j'] + bundle group: 'org.hibernate', name: 'hibernate-core', version: rootProject['verHibernate'] + bundle group: 'mysql', name: 'mysql-connector-java', version: rootProject['verMySQLConn'] + bundle group: 'org.postgresql', name: 'postgresql', version: rootProject['verPostgreSQLConn'] + bundle group: 'net.sf.proguard', name: 'proguard-base', version: rootProject['verProguard'] + testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter', version: rootProject['verJunit'] + //TODO rewrite hikari 'io.micrometer:micrometer-core:1.0.6' hikari('com.zaxxer:HikariCP:3.4.1') { exclude group: 'javassist' @@ -101,6 +99,7 @@ pack project(':LauncherAPI') exclude group: 'net.java.abeille' exclude group: 'foxtrot' exclude group: 'com.jgoodies' + exclude group: 'org.slf4j' } launch4jCJ('net.sf.launch4j:launch4j:3.12:workdir-win32') { @@ -110,13 +109,15 @@ pack project(':LauncherAPI') launch4jCJ('net.sf.launch4j:launch4j:3.12:workdir-linux') { exclude group: '*' } + // Rewrite end. - compileOnlyA 'com.google.guava:guava:26.0-jre' - compileOnlyA 'log4j:log4j:1.2.17' // Do not update (laggy dep). + compileOnly group: 'com.google.guava', name: 'guava', version: rootProject['verGuavaC'] + // Do not update (laggy deps). + compileOnlyA 'log4j:log4j:1.2.17' compileOnlyA 'org.apache.logging.log4j:log4j-core:2.11.2' - testImplementation 'org.junit.jupiter:junit-jupiter:5.4.1' } +//TODO rewrite task hikari(type: Copy) { duplicatesStrategy = 'EXCLUDE' into "$buildDir/libs/libraries/hikaricp" @@ -152,10 +153,11 @@ task launch4jA(type: Copy) { fcp.mode = 0755 } } +// Rewrite end. task dumpLibs(type: Copy) { duplicatesStrategy = 'EXCLUDE' - dependsOn tasks.hikari, tasks.launch4jM, tasks.launch4jA + dependsOn tasks.hikari, tasks.launch4jM, tasks.launch4jA //TODO rewrite this into "$buildDir/libs/libraries" from configurations.bundleOnly } @@ -173,7 +175,7 @@ task bundle(type: Zip) { destinationDirectory = file("$buildDir") from(tasks.dumpLibs.destinationDir) { into 'libraries' } from(tasks.dumpCompileOnlyLibs.destinationDir) { into 'launcher-libraries-compile' } - from tasks.jar.archivePath + from tasks.jar from(parent.childProjects.Launcher.tasks.dumpLibs) { into 'launcher-libraries' } } diff --git a/Launcher/build.gradle b/Launcher/build.gradle index 918ace4a..3b08c43e 100644 --- a/Launcher/build.gradle +++ b/Launcher/build.gradle @@ -53,9 +53,9 @@ task javadocJar(type: Jar) { dependencies { 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' + bundle group: 'com.github.oshi', name: 'oshi-core', version: rootProject['verOshiCore'] + pack group: 'io.netty', name: 'netty-codec-http', version: rootProject['verNetty'] + pack group: 'org.ow2.asm', name: 'asm-tree', version: rootProject['verAsm'] } task genRuntimeJS(type: Zip) { diff --git a/LauncherAPI/build.gradle b/LauncherAPI/build.gradle index 3cb0f2c7..0b33f0bd 100644 --- a/LauncherAPI/build.gradle +++ b/LauncherAPI/build.gradle @@ -3,8 +3,8 @@ dependencies { api project(':LauncherCore') - compileOnly 'io.netty:netty-codec-http:4.1.43.Final' - testImplementation 'org.junit.jupiter:junit-jupiter:5.4.1' + compileOnly group: 'io.netty', name: 'netty-codec-http', version: rootProject['verNetty'] + testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter', version: rootProject['verJunit'] } test { diff --git a/LauncherAuthlib/build.gradle b/LauncherAuthlib/build.gradle index b0be2cb6..4e0a33d5 100644 --- a/LauncherAuthlib/build.gradle +++ b/LauncherAuthlib/build.gradle @@ -3,6 +3,6 @@ dependencies { api project(':LauncherAPI') - compileOnly 'com.google.guava:guava:26.0-jre' + compileOnly group: 'com.google.guava', name: 'guava', version: rootProject['verGuavaC'] api files('../compat/authlib/authlib-clean.jar') } diff --git a/LauncherCore/build.gradle b/LauncherCore/build.gradle index 40e2fe6e..6b9212af 100644 --- a/LauncherCore/build.gradle +++ b/LauncherCore/build.gradle @@ -2,13 +2,13 @@ targetCompatibility = '1.8' dependencies { - compileOnly 'org.fusesource.jansi:jansi:1.18' - compileOnly 'org.jline:jline:3.11.0' - compileOnly 'org.jline:jline-reader:3.11.0' - compileOnly 'org.jline:jline-terminal:3.11.0' - compileOnly 'org.bouncycastle:bcprov-jdk15:1.46' - api 'com.google.code.gson:gson:2.8.5' - testImplementation 'org.junit.jupiter:junit-jupiter:5.4.1' + compileOnly group: 'org.fusesource.jansi', name:'jansi', version: rootProject['verJansi'] + compileOnly group: 'org.jline', name: 'jline', version: rootProject['verJline'] + compileOnly group: 'org.jline', name: 'jline-reader', version: rootProject['verJline'] + compileOnly group: 'org.jline', name: 'jline-terminal', version: rootProject['verJline'] + compileOnly group: 'org.bouncycastle', name: 'bcprov-jdk15', version: rootProject['verBcprov'] + api group: 'com.google.code.gson', name: 'gson', version: rootProject['verGson'] + testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter', version: rootProject['verJunit'] } test { diff --git a/ServerWrapper/build.gradle b/ServerWrapper/build.gradle index 0c801681..d35d9f6b 100644 --- a/ServerWrapper/build.gradle +++ b/ServerWrapper/build.gradle @@ -38,7 +38,7 @@ task javadocJar(type: Jar) { dependencies { pack project(':LauncherAuthlib') - pack 'io.netty:netty-codec-http:4.1.43.Final' + pack group: 'io.netty', name: 'netty-codec-http', version: rootProject['verNetty'] } shadowJar { diff --git a/build.gradle b/build.gradle index 458b395f..280068d2 100644 --- a/build.gradle +++ b/build.gradle @@ -7,6 +7,8 @@ group = 'pro.gravit.launcher' version = '5.1.1-SNAPSHOT' +apply from: 'props.gradle' + configure(subprojects.findAll { it.name != 'modules' }) { apply plugin: 'idea' apply plugin: 'eclipse' diff --git a/props.gradle b/props.gradle new file mode 100644 index 00000000..a59f7f53 --- /dev/null +++ b/props.gradle @@ -0,0 +1,17 @@ +project.ext { + verAsm = '7.1' + verNetty = '4.1.43.Final' + verOshiCore = '3.13.0' + verJunit = '5.4.1' + verGuavaC = '26.0-jre' + verJansi = '1.18' + verJline = '3.11.0' + verBcprov = '1.46' + verGson = '2.8.5' + verBcpkix = '1.61' + verSlf4j = '1.7.25' + verMySQLConn = '8.0.16' + verPostgreSQLConn = '42.2.6' + verProguard = '6.2.0' + verHibernate = '5.4.9.Final' +} From 665ed6a4f7ef50517480ac281f3dcf0f6b294ecb Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Wed, 11 Mar 2020 15:58:20 +0100 Subject: [PATCH 02/25] =?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 55982085..2edb2c72 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 559820852c231b7045b2c12fabbde1261485a75e +Subproject commit 2edb2c7259d5a7dba3fa82c503f88a8a0e171840 From 84543b85f35fc4165e56003a149b669d516e45f3 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Wed, 11 Mar 2020 16:28:22 +0100 Subject: [PATCH 03/25] [FIX] Hikari and launch4j resolving. --- LaunchServer/build.gradle | 38 ++++++------------- .../launchserver/ASMTransformersTest.java | 24 ++++++------ 2 files changed, 23 insertions(+), 39 deletions(-) diff --git a/LaunchServer/build.gradle b/LaunchServer/build.gradle index cf91ce83..21d39219 100644 --- a/LaunchServer/build.gradle +++ b/LaunchServer/build.gradle @@ -22,9 +22,8 @@ hikari pack launch4j - launch4jCJ bundleOnly.extendsFrom bundle - api.extendsFrom bundle, hikari, pack, launch4jCJ, launch4j + api.extendsFrom bundle, hikari, pack, launch4j } jar { @@ -86,7 +85,6 @@ pack project(':LauncherAPI') bundle group: 'net.sf.proguard', name: 'proguard-base', version: rootProject['verProguard'] testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter', version: rootProject['verJunit'] - //TODO rewrite hikari 'io.micrometer:micrometer-core:1.0.6' hikari('com.zaxxer:HikariCP:3.4.1') { exclude group: 'javassist' @@ -102,14 +100,13 @@ pack project(':LauncherAPI') exclude group: 'org.slf4j' } - launch4jCJ('net.sf.launch4j:launch4j:3.12:workdir-win32') { + launch4j('net.sf.launch4j:launch4j:3.12:workdir-win32') { exclude group: '*' } - launch4jCJ('net.sf.launch4j:launch4j:3.12:workdir-linux') { + launch4j('net.sf.launch4j:launch4j:3.12:workdir-linux') { exclude group: '*' } - // Rewrite end. compileOnly group: 'com.google.guava', name: 'guava', version: rootProject['verGuavaC'] // Do not update (laggy deps). @@ -117,23 +114,24 @@ pack project(':LauncherAPI') compileOnlyA 'org.apache.logging.log4j:log4j-core:2.11.2' } -//TODO rewrite task hikari(type: Copy) { duplicatesStrategy = 'EXCLUDE' into "$buildDir/libs/libraries/hikaricp" from configurations.hikari } -task launch4jM(type: Copy) { +task launch4j(type: Copy) { duplicatesStrategy = 'EXCLUDE' into "$buildDir/libs/libraries/launch4j" - from(configurations.launch4jCJ.collect { it.isDirectory() ? it : zipTree(it) }) + from(configurations.launch4j.collect { it.isDirectory() ? it : (it.getName().contains("workdir") ? zipTree(it) : it) }) includeEmptyDirs false eachFile { FileCopyDetails fcp -> if (fcp.relativePath.pathString.startsWith("launch4j-")) { - def segments = fcp.relativePath.segments - def pathSegments = segments[1..-1] as String[] - fcp.relativePath = new RelativePath(!fcp.file.isDirectory(), pathSegments) + if (fcp.relativePath.pathString.contains("workdir")) { + def segments = fcp.relativePath.segments + def pathSegments = segments[1..-1] as String[] + fcp.relativePath = new RelativePath(!fcp.file.isDirectory(), pathSegments) + } fcp.mode = 0755 } else { fcp.exclude() @@ -141,23 +139,9 @@ task launch4jM(type: Copy) { } } -task launch4jA(type: Copy) { - duplicatesStrategy = 'EXCLUDE' - into "$buildDir/libs/libraries/launch4j" - from(configurations.launch4j) - includeEmptyDirs false - eachFile { FileCopyDetails fcp -> - if (fcp.name.startsWith("launch4j")) { - fcp.name = "launch4j.jar" - } - fcp.mode = 0755 - } -} -// Rewrite end. - task dumpLibs(type: Copy) { duplicatesStrategy = 'EXCLUDE' - dependsOn tasks.hikari, tasks.launch4jM, tasks.launch4jA //TODO rewrite this + dependsOn tasks.hikari, tasks.launch4j into "$buildDir/libs/libraries" from configurations.bundleOnly } diff --git a/LaunchServer/src/test/java/pro/gravit/launchserver/ASMTransformersTest.java b/LaunchServer/src/test/java/pro/gravit/launchserver/ASMTransformersTest.java index fe27cab0..f1f620ce 100644 --- a/LaunchServer/src/test/java/pro/gravit/launchserver/ASMTransformersTest.java +++ b/LaunchServer/src/test/java/pro/gravit/launchserver/ASMTransformersTest.java @@ -10,6 +10,8 @@ import pro.gravit.launchserver.asm.InjectClassAcceptor; import pro.gravit.utils.helper.JarHelper; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashMap; @@ -38,11 +40,11 @@ public static class TestClass public Map map; } @BeforeAll - public static void prepare() throws Exception { + public static void prepare() throws Throwable { classLoader = new ASMClassLoader(ASMTransformersTest.class.getClassLoader()); } @Test - void testASM() throws Exception + void testASM() throws Throwable { ClassReader reader = new ClassReader(JarHelper.getClassBytes(TestClass.class)); ClassNode node = new ClassNode(); @@ -65,15 +67,13 @@ 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(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); + Object instance = MethodHandles.publicLookup().findConstructor(clazz, MethodType.methodType(void.class)).invoke(); + Assertions.assertEquals(1234, (int) + MethodHandles.publicLookup().findGetter(clazz, "test", int.class).invoke(instance)); + Assertions.assertEquals(strings, (List) + MethodHandles.publicLookup().findGetter(clazz, "s", List.class).invoke(instance)); + + Assertions.assertEquals(byteMap, (Map) + MethodHandles.publicLookup().findGetter(clazz, "map", Map.class).invoke(instance)); } } From b8f25e669efce852abb18e8e0ed7f25a8c753bdf Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Wed, 11 Mar 2020 16:40:27 +0100 Subject: [PATCH 04/25] =?UTF-8?q?[FIX]=20Gradle=20=D1=87=D0=B0=D1=81=D1=82?= =?UTF-8?q?=D1=8C=202/3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LaunchServer/build.gradle | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/LaunchServer/build.gradle b/LaunchServer/build.gradle index 21d39219..d1569f29 100644 --- a/LaunchServer/build.gradle +++ b/LaunchServer/build.gradle @@ -99,14 +99,8 @@ pack project(':LauncherAPI') exclude group: 'com.jgoodies' exclude group: 'org.slf4j' } - - launch4j('net.sf.launch4j:launch4j:3.12:workdir-win32') { - exclude group: '*' - } - - launch4j('net.sf.launch4j:launch4j:3.12:workdir-linux') { - exclude group: '*' - } + launch4j('net.sf.launch4j:launch4j:3.12:workdir-win32') { transitive = false } + launch4j('net.sf.launch4j:launch4j:3.12:workdir-linux') { transitive = false } compileOnly group: 'com.google.guava', name: 'guava', version: rootProject['verGuavaC'] // Do not update (laggy deps). @@ -123,19 +117,16 @@ task hikari(type: Copy) { task launch4j(type: Copy) { duplicatesStrategy = 'EXCLUDE' into "$buildDir/libs/libraries/launch4j" - from(configurations.launch4j.collect { it.isDirectory() ? it : (it.getName().contains("workdir") ? zipTree(it) : it) }) + from(configurations.launch4j.collect { it.isDirectory() ? it : ((it.getName().startsWith("launch4j") && it.getName().contains("workdir")) ? zipTree(it) : it) }) includeEmptyDirs false eachFile { FileCopyDetails fcp -> - if (fcp.relativePath.pathString.startsWith("launch4j-")) { - if (fcp.relativePath.pathString.contains("workdir")) { + if (fcp.relativePath.pathString.startsWith("launch4j-") && + fcp.relativePath.pathString.contains("workdir")) { def segments = fcp.relativePath.segments def pathSegments = segments[1..-1] as String[] fcp.relativePath = new RelativePath(!fcp.file.isDirectory(), pathSegments) } fcp.mode = 0755 - } else { - fcp.exclude() - } } } @@ -166,7 +157,7 @@ task bundle(type: Zip) { task dumpClientLibs(type: Copy) { dependsOn parent.childProjects.Launcher.tasks.build into "$buildDir/libs/launcher-libraries" - from parent.childProjects.Launcher.tasks.dumpLibs.destinationDir + from parent.childProjects.Launcher.tasks.dumpLibs } assemble.dependsOn tasks.dumpLibs, tasks.dumpCompileOnlyLibs, tasks.dumpClientLibs, tasks.bundle, tasks.cleanjar From d278712183cb2ff2c0be9a916a21d64120e42096 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Thu, 12 Mar 2020 06:36:09 +0100 Subject: [PATCH 05/25] =?UTF-8?q?[FIX]=20=D0=A1=D0=BA=D1=80=D0=B8=D0=BF?= =?UTF-8?q?=D1=82=D1=8B=20=D1=81=D0=B1=D0=BE=D1=80=D0=BA=D0=B8.=20=D0=A7?= =?UTF-8?q?=D0=B0=D1=81=D1=82=D1=8C=203/3.=20=D0=95=D1=89=D1=91=20=D0=BE?= =?UTF-8?q?=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8=D0=BB=20=D0=B3=D0=B4=D0=B5=20?= =?UTF-8?q?=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE=20=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D1=81=D0=B8=D0=B8=20=D0=B1=D0=B8=D0=B1=D0=BB=D0=B8=D0=BE?= =?UTF-8?q?=D1=82=D0=B5=D0=BA.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LaunchServer/build.gradle | 12 ++++++------ props.gradle | 5 +++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/LaunchServer/build.gradle b/LaunchServer/build.gradle index d1569f29..ea5dcb76 100644 --- a/LaunchServer/build.gradle +++ b/LaunchServer/build.gradle @@ -92,17 +92,17 @@ pack project(':LauncherAPI') exclude group: 'org.slf4j' } - launch4j('net.sf.launch4j:launch4j:3.12') { + launch4j('net.sf.launch4j:launch4j:' + rootProject['verLaunch4j']) { exclude group: 'org.apache.ant' exclude group: 'net.java.abeille' exclude group: 'foxtrot' exclude group: 'com.jgoodies' exclude group: 'org.slf4j' } - launch4j('net.sf.launch4j:launch4j:3.12:workdir-win32') { transitive = false } - launch4j('net.sf.launch4j:launch4j:3.12:workdir-linux') { transitive = false } + launch4j('net.sf.launch4j:launch4j:' + rootProject['verLaunch4j'] + ':workdir-win32') { transitive = false } + launch4j('net.sf.launch4j:launch4j:' + rootProject['verLaunch4j'] + 'workdir-linux') { transitive = false } - compileOnly group: 'com.google.guava', name: 'guava', version: rootProject['verGuavaC'] + compileOnlyA group: 'com.google.guava', name: 'guava', version: rootProject['verGuavaC'] // Do not update (laggy deps). compileOnlyA 'log4j:log4j:1.2.17' compileOnlyA 'org.apache.logging.log4j:log4j-core:2.11.2' @@ -125,7 +125,7 @@ task launch4j(type: Copy) { def segments = fcp.relativePath.segments def pathSegments = segments[1..-1] as String[] fcp.relativePath = new RelativePath(!fcp.file.isDirectory(), pathSegments) - } + } else if (fcp.relativePath.pathString.contains("META-INF")) fcp.exclude() fcp.mode = 0755 } } @@ -150,7 +150,7 @@ task bundle(type: Zip) { destinationDirectory = file("$buildDir") from(tasks.dumpLibs.destinationDir) { into 'libraries' } from(tasks.dumpCompileOnlyLibs.destinationDir) { into 'launcher-libraries-compile' } - from tasks.jar + from(tasks.jar) from(parent.childProjects.Launcher.tasks.dumpLibs) { into 'launcher-libraries' } } diff --git a/props.gradle b/props.gradle index a59f7f53..2140b970 100644 --- a/props.gradle +++ b/props.gradle @@ -1,8 +1,8 @@ project.ext { - verAsm = '7.1' + verAsm = '7.2' verNetty = '4.1.43.Final' verOshiCore = '3.13.0' - verJunit = '5.4.1' + verJunit = '5.6.0' verGuavaC = '26.0-jre' verJansi = '1.18' verJline = '3.11.0' @@ -13,5 +13,6 @@ verMySQLConn = '8.0.16' verPostgreSQLConn = '42.2.6' verProguard = '6.2.0' + verLaunch4j = '3.12' verHibernate = '5.4.9.Final' } From e26a15d26ad0eae7a14b87741fa2c398299c40a1 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sun, 15 Mar 2020 23:16:31 +0700 Subject: [PATCH 06/25] [ANY] 5.1.2 --- 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 eeb67e46..f55f4bef 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/Version.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/Version.java @@ -15,9 +15,9 @@ public final class Version { public final Type release; public static final int MAJOR = 5; public static final int MINOR = 1; - public static final int PATCH = 1; - public static final int BUILD = 2; - public static final Version.Type RELEASE = Type.BETA; + public static final int PATCH = 2; + public static final int BUILD = 1; + public static final Version.Type RELEASE = Type.DEV; public Version(int major, int minor, int patch) { diff --git a/build.gradle b/build.gradle index 80e39138..2583ada3 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ id 'org.openjfx.javafxplugin' version '0.0.7' apply false } group = 'pro.gravit.launcher' -version = '5.1.1' +version = '5.1.2-SNAPSHOT' configure(subprojects.findAll { it.name != 'modules' }) { apply plugin: 'idea' From 602a20325c6cff3ba3bde94105f5f31e13b44944 Mon Sep 17 00:00:00 2001 From: Gravit Date: Tue, 17 Mar 2020 03:10:43 +0700 Subject: [PATCH 07/25] [ANY] Try new gitlab ci --- .gitlab-ci.yml | 52 +++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b38f1740..4836650f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,41 +1,41 @@ -image: docker:latest -services: - - docker:dind - -variables: - DOCKER_DRIVER: overlay2 - CI_VERSION: '6.6.$CI_PIPELINE_IID' +image: gradle:jdk11 stages: - build - test + - deploy +before_script: + - apt-get -y update + - 'which zip || ( apt-get -y install zip )' + - 'which git || ( apt-get -y install git )' + - export GRADLE_USER_HOME=`pwd`/.gradle + - chmod +x gradlew + - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )' + - eval $(ssh-agent -s) + - echo "$SSH_PRIVATE_KEY" | base64 -d | ssh-add - > /dev/null + - mkdir -p ~/.ssh + - chmod 700 ~/.ssh + - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config + - git submodule sync + - git submodule update --init --recursive build: - image: gradle:jdk11 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 script: - ./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 + - cp LaunchServer.jar ../../../artifacts/LaunchServer.jar - cd ../../../ServerWrapper/build/libs - - mv ServerWrapper.jar ../../../artifacts/ServerWrapper.jar + - cp ServerWrapper.jar ../../../artifacts/ServerWrapper.jar - cd ../../../LauncherAuthlib/build/libs - - mv LauncherAuthlib.jar ../../../artifacts/LauncherAuthlib.jar + - cp LauncherAuthlib.jar ../../../artifacts/LauncherAuthlib.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 + - cp modules/*_module/build/libs/*.jar artifacts/modules + - cp modules/*_swmodule/build/libs/*.jar artifacts/modules + - cp modules/*_lmodule/build/libs/*.jar artifacts/modules cache: paths: - .gradle @@ -45,7 +45,11 @@ build: - artifacts test: - image: gradle:jdk11 stage: test script: - - ./gradlew check \ No newline at end of file + - ./gradlew check + +deploy-demo: + stage: deploy + script: + - ssh $SSH_USER@$SSH_HOST 'echo HELLO WORLD' \ No newline at end of file From 747e5fec0c6ca2960a9b77d465b24ab0bdae0179 Mon Sep 17 00:00:00 2001 From: Gravit Date: Tue, 17 Mar 2020 03:46:38 +0700 Subject: [PATCH 08/25] [ANY] Try new gitlab ci --- .gitlab-ci.yml | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4836650f..e4538f66 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,6 +4,8 @@ stages: - build - test - deploy +variables: + GRADLE_OPTS: "-Dorg.gradle.daemon=false" before_script: - apt-get -y update @@ -18,11 +20,13 @@ before_script: - chmod 700 ~/.ssh - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config - git submodule sync - - git submodule update --init --recursive + - mv modules modules_cache || true + - git submodule update --init --recursive --force + - cp -a modules_cache/* modules/ || true build: stage: build script: - - ./gradlew assemble + - gradle assemble after_script: - mkdir -p artifacts/modules - cd LaunchServer/build/libs/ @@ -39,6 +43,12 @@ build: cache: paths: - .gradle + - LaunchServer/build + - Launcher/build + - LauncherCore/build + - LauncherAPI/build + - LauncherAuthlib/build + - modules/*_*module/build artifacts: expire_in: 6 week paths: @@ -47,9 +57,28 @@ build: test: stage: test script: - - ./gradlew check + - gradle check + cache: + paths: + - .gradle + - LaunchServer/build + - Launcher/build + - LauncherCore/build + - LauncherAPI/build + - LauncherAuthlib/build + - modules/*_*module/build deploy-demo: stage: deploy script: - - ssh $SSH_USER@$SSH_HOST 'echo HELLO WORLD' \ No newline at end of file + - gradle build + - eval $(ssh $SSH_USER@$SSH_HOST 'cd $SSH_DIR && cat deploy.sh') + cache: + paths: + - .gradle + - LaunchServer/build + - Launcher/build + - LauncherCore/build + - LauncherAPI/build + - LauncherAuthlib/build + - modules/*_*module/build \ No newline at end of file From dc97bbb74362d4342f832749028a3ebb5da9e2e9 Mon Sep 17 00:00:00 2001 From: Gravit Date: Tue, 17 Mar 2020 05:15:46 +0700 Subject: [PATCH 09/25] [ANY] Final gitlab ci --- .gitlab-ci.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e4538f66..95b726b1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -41,6 +41,7 @@ build: - cp modules/*_swmodule/build/libs/*.jar artifacts/modules - cp modules/*_lmodule/build/libs/*.jar artifacts/modules cache: + key: "$CI_COMMIT_REF_NAME" paths: - .gradle - LaunchServer/build @@ -59,6 +60,8 @@ test: script: - gradle check cache: + key: "$CI_COMMIT_REF_NAME" + policy: pull paths: - .gradle - LaunchServer/build @@ -74,6 +77,8 @@ deploy-demo: - gradle build - eval $(ssh $SSH_USER@$SSH_HOST 'cd $SSH_DIR && cat deploy.sh') cache: + key: "$CI_COMMIT_REF_NAME" + policy: pull paths: - .gradle - LaunchServer/build From c2154b8a7c6d8c7195e7c5b904be507c674645fb Mon Sep 17 00:00:00 2001 From: Gravit Date: Tue, 17 Mar 2020 05:32:30 +0700 Subject: [PATCH 10/25] [ANY] Final gitlab CI --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 95b726b1..794e62e6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -73,6 +73,7 @@ test: deploy-demo: stage: deploy + only: [dev] script: - gradle build - eval $(ssh $SSH_USER@$SSH_HOST 'cd $SSH_DIR && cat deploy.sh') From eddfd61c060a053548f7947856d512fe1b82b6e3 Mon Sep 17 00:00:00 2001 From: Gravit Date: Fri, 20 Mar 2020 06:52:36 +0700 Subject: [PATCH 11/25] =?UTF-8?q?[FIX][EXPERIMENTAL]=20=D0=92=D1=8B=D1=80?= =?UTF-8?q?=D0=B5=D0=B7=D0=B0=D0=BD=D0=B8=D0=B5=20HwidHandler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launchserver/LaunchServerStarter.java | 4 - .../launchserver/auth/AuthProviderPair.java | 12 +- .../auth/hwid/AcceptHWIDHandler.java | 40 --- .../launchserver/auth/hwid/HWIDException.java | 23 -- .../launchserver/auth/hwid/HWIDHandler.java | 80 ------ .../auth/hwid/JsonFileHWIDHandler.java | 113 -------- .../auth/hwid/JsonHWIDHandler.java | 148 ---------- .../auth/hwid/MemoryHWIDHandler.java | 92 ------ .../auth/hwid/MysqlHWIDHandler.java | 268 ------------------ .../command/basic/TestCommand.java | 5 - .../config/LaunchServerConfig.java | 5 +- .../pro/gravit/launchserver/dao/HwidDAO.java | 19 -- .../pro/gravit/launchserver/dao/UserHWID.java | 8 - .../dao/impl/HibernateHwidDAOImpl.java | 82 ------ .../launchserver/dao/impl/UserHWIDImpl.java | 43 --- .../dao/provider/DaoProvider.java | 2 - .../dao/provider/HibernateDaoProvider.java | 4 - .../manangers/LaunchServerGsonManager.java | 5 - .../socket/response/auth/AuthResponse.java | 15 +- .../pro/gravit/launcher/LauncherEngine.java | 2 - .../launcher/client/ClientLauncher.java | 3 - .../launcher/hwid/OshiHWIDProvider.java | 129 --------- .../launcher/managers/ClientGsonManager.java | 3 - .../java/pro/gravit/launcher/hwid/HWID.java | 1 + .../gravit/launcher/hwid/HWIDCheckHelper.java | 63 ---- .../gravit/launcher/hwid/HWIDProvider.java | 12 - .../launcher/hwid/LauncherHWIDInterface.java | 6 - .../java/pro/gravit/launcher/hwid/NoHWID.java | 29 -- .../pro/gravit/launcher/hwid/OshiHWID.java | 105 ------- .../launcher/request/auth/AuthRequest.java | 27 +- 30 files changed, 8 insertions(+), 1340 deletions(-) delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/AcceptHWIDHandler.java delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/HWIDException.java delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/HWIDHandler.java delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/JsonFileHWIDHandler.java delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/JsonHWIDHandler.java delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/MemoryHWIDHandler.java delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/dao/HwidDAO.java delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserHWID.java delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/HibernateHwidDAOImpl.java delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/UserHWIDImpl.java delete mode 100644 Launcher/src/main/java/pro/gravit/launcher/hwid/OshiHWIDProvider.java delete mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWIDCheckHelper.java delete mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWIDProvider.java delete mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/hwid/LauncherHWIDInterface.java delete mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/hwid/NoHWID.java delete mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/hwid/OshiHWID.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java index 16d2fc44..c6660187 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java @@ -2,11 +2,9 @@ import org.bouncycastle.jce.provider.BouncyCastleProvider; import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.hwid.HWIDProvider; import pro.gravit.launcher.modules.events.PreConfigPhase; 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.protect.ProtectHandler; import pro.gravit.launchserver.auth.provider.AuthProvider; import pro.gravit.launchserver.auth.texture.TextureProvider; @@ -208,11 +206,9 @@ public static void registerAll() { AuthHandler.registerHandlers(); AuthProvider.registerProviders(); TextureProvider.registerProviders(); - HWIDHandler.registerHandlers(); Component.registerComponents(); ProtectHandler.registerHandlers(); WebSocketService.registerResponses(); - HWIDProvider.registerHWIDs(); DaoProvider.registerProviders(); AuthRequest.registerProviders(); } 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 e9da8e5e..fd0cc5c2 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java @@ -2,7 +2,6 @@ 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; @@ -13,17 +12,15 @@ public class AuthProviderPair { public AuthProvider provider; public AuthHandler handler; public TextureProvider textureProvider; - public HWIDHandler hwid; public Map links; public transient String name; public String displayName; public final boolean isDefault = true; - public AuthProviderPair(AuthProvider provider, AuthHandler handler, TextureProvider textureProvider, HWIDHandler hwid) { + public AuthProviderPair(AuthProvider provider, AuthHandler handler, TextureProvider textureProvider) { this.provider = provider; this.handler = handler; this.textureProvider = textureProvider; - this.hwid = hwid; } public void init(LaunchServer srv, String name) { @@ -32,10 +29,8 @@ public void init(LaunchServer srv, String name) { 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) { @@ -60,11 +55,6 @@ 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; - } }); } 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 deleted file mode 100644 index bed24943..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/AcceptHWIDHandler.java +++ /dev/null @@ -1,40 +0,0 @@ -package pro.gravit.launchserver.auth.hwid; - -import pro.gravit.launcher.hwid.HWID; - -import java.util.ArrayList; -import java.util.List; - -public class AcceptHWIDHandler extends HWIDHandler { - - @Override - public void ban(List hwid) { - //SKIP - } - - @Override - public void check0(HWID hwid, String username) { - //SKIP - } - - @Override - public void close() { - //SKIP - } - - @Override - public void init() { - - } - - @Override - public List getHwid(String username) { - return new ArrayList<>(); - } - - @Override - public void unban(List hwid) { - //SKIP - } - -} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/HWIDException.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/HWIDException.java deleted file mode 100644 index 697880da..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/HWIDException.java +++ /dev/null @@ -1,23 +0,0 @@ -package pro.gravit.launchserver.auth.hwid; - -public class HWIDException extends Exception { - /** - * - */ - private static final long serialVersionUID = -5307315891121889972L; - - public HWIDException() { - } - - public HWIDException(String s) { - super(s); - } - - public HWIDException(String s, Throwable throwable) { - super(s, throwable); - } - - public HWIDException(Throwable throwable) { - super(throwable); - } -} 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 deleted file mode 100644 index 9fc786cf..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/HWIDHandler.java +++ /dev/null @@ -1,80 +0,0 @@ -package pro.gravit.launchserver.auth.hwid; - -import pro.gravit.launcher.hwid.HWID; -import pro.gravit.launchserver.Reconfigurable; -import pro.gravit.utils.ProviderMap; -import pro.gravit.utils.command.Command; -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; - - - public static void registerHandlers() { - if (!registredHandl) { - providers.register("accept", AcceptHWIDHandler.class); - providers.register("mysql", MysqlHWIDHandler.class); - providers.register("json", JsonHWIDHandler.class); - providers.register("jsonfile", JsonFileHWIDHandler.class); - providers.register("memory", MemoryHWIDHandler.class); - registredHandl = true; - } - } - - @Override - public Map getCommands() { - Map commands = new HashMap<>(); - commands.put("ban", new SubCommand() { - @Override - public void invoke(String... args) throws Exception { - List target = getHwid(args[0]); - ban(target); - } - }); - commands.put("unban", new SubCommand() { - @Override - public void invoke(String... args) throws Exception { - List target = getHwid(args[0]); - unban(target); - } - }); - commands.put("gethwid", new SubCommand() { - @Override - public void invoke(String... args) throws Exception { - List target = getHwid(args[0]); - for (HWID hwid : target) { - if (hwid == null) { - LogHelper.error("[%s] HWID: null", args[0]); - continue; - } - LogHelper.info("[%s] HWID: %s", args[0], hwid.toString()); - } - } - }); - return commands; - } - - public abstract void ban(List hwid) throws HWIDException; - - public void check(HWID hwid, String username) throws HWIDException { - if (hwid == null || hwid.isNull()) return; - check0(hwid, username); - } - - public abstract void check0(HWID hwid, String username) throws HWIDException; - - @Override - public abstract void close() throws Exception; - - public abstract void init(); - - public abstract List getHwid(String username) throws HWIDException; - - public abstract void unban(List hwid) throws HWIDException; -} 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 deleted file mode 100644 index 0c34076c..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/JsonFileHWIDHandler.java +++ /dev/null @@ -1,113 +0,0 @@ -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; -import java.lang.reflect.Type; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.LinkedList; -import java.util.List; -import java.util.Objects; - -public class JsonFileHWIDHandler extends HWIDHandler { - public static class Entry { - public final HWID hwid; - public String username; - public boolean isBanned = false; - - public Entry(HWID hwid) { - this.hwid = hwid; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Entry entry = (Entry) o; - return Objects.equals(hwid, entry.hwid); - } - - @Override - public int hashCode() { - return Objects.hash(hwid); - } - } - - public final String filename = "hwids.json"; - public 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; - break; - } - } - } - } - - @Override - public void init() { - Path path = Paths.get(filename); - Type type = new TypeToken>() { - }.getType(); - try (Reader reader = IOHelper.newReader(path)) { - list = Launcher.gsonManager.gson.fromJson(reader, type); - } catch (IOException e) { - LogHelper.error(e); - } - } - - @Override - public void check0(HWID hwid, String username) throws HWIDException { - boolean isOne = false; - for (Entry e : list) { - if (e.hwid.equals(hwid)) { - isOne = true; - if (e.isBanned) throw new HWIDException(banMessage); - } - } - if (!isOne) { - list.add(new Entry(hwid)); - } - } - - @Override - public void close() throws Exception { - Path path = Paths.get(filename); - try (Writer writer = IOHelper.newWriter(path)) { - Launcher.gsonManager.configGson.toJson(list, writer); - } - } - - @Override - public List getHwid(String username) { - LinkedList hwids = new LinkedList<>(); - for (Entry e : list) { - if (e.username.equals(username)) hwids.add(e.hwid); - } - return hwids; - } - - @Override - public void unban(List hwid) { - for (Entry e : list) { - for (HWID banHWID : hwid) { - 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 deleted file mode 100644 index f23bebb0..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/JsonHWIDHandler.java +++ /dev/null @@ -1,148 +0,0 @@ -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.launcher.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; - -public final class JsonHWIDHandler extends HWIDHandler { - private static final Gson gson = new Gson(); - - private URL url; - private URL urlBan; - private URL urlUnBan; - private URL urlGet; - private String apiKey; - - public static class banRequest { - public banRequest(OshiHWID hwid) { - this.hwid = hwid; - } - - final OshiHWID hwid; - String apiKey; - - public banRequest(OshiHWID hwid, String apiKey) { - this.hwid = hwid; - this.apiKey = apiKey; - } - } - - public static class checkRequest { - public checkRequest(String username, OshiHWID hwid) { - this.username = username; - this.hwid = hwid; - } - - final String username; - final OshiHWID hwid; - String apiKey; - - public checkRequest(String username, OshiHWID hwid, String apiKey) { - this.username = username; - this.hwid = hwid; - this.apiKey = apiKey; - } - } - - public static class Result { - String error; - } - - public static class BannedResult { - boolean isBanned; - String error; - } - - public static class HWIDRequest { - public HWIDRequest(String username) { - this.username = username; - } - - final String username; - String apiKey; - - public HWIDRequest(String username, String apiKey) { - this.username = username; - this.apiKey = apiKey; - } - } - - @Override - public void ban(List l_hwid) throws HWIDException { - for (HWID hwid : l_hwid) { - banRequest request = new banRequest((OshiHWID) hwid, apiKey); - try { - JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), urlBan); - Result r = gson.fromJson(result, Result.class); - if (r.error != null) throw new HWIDException(r.error); - } catch (IOException e) { - LogHelper.error(e); - throw new HWIDException("HWID service error"); - } - } - } - - @Override - public void check0(HWID hwid, String username) throws HWIDException { - checkRequest request = new checkRequest(username, (OshiHWID) hwid, apiKey); - try { - JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), url); - BannedResult r = gson.fromJson(result, BannedResult.class); - if (r.error != null) throw new HWIDException(r.error); - boolean isBanned = r.isBanned; - if (isBanned) throw new HWIDException("You will BANNED!"); - } catch (IOException e) { - LogHelper.error(e); - throw new HWIDException("HWID service error"); - } - } - - @Override - public void close() { - // pass - } - - @Override - public void init() { - - } - - @Override - public List getHwid(String username) throws HWIDException { - ArrayList hwids = new ArrayList<>(); - HWIDRequest request = new HWIDRequest(username, apiKey); - try { - JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), urlGet); - OshiHWID[] r = gson.fromJson(result, OshiHWID[].class); - hwids.addAll(Arrays.asList(r)); - } catch (IOException e) { - LogHelper.error(e); - throw new HWIDException("HWID service error"); - } - return hwids; - } - - @Override - public void unban(List l_hwid) throws HWIDException { - for (HWID hwid : l_hwid) { - banRequest request = new banRequest((OshiHWID) hwid, apiKey); - try { - JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), urlUnBan); - Result r = gson.fromJson(result, Result.class); - if (r.error != null) throw new HWIDException(r.error); - } catch (IOException e) { - LogHelper.error(e); - throw new HWIDException("HWID service error"); - } - } - } -} 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 deleted file mode 100644 index 6bcbd194..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/MemoryHWIDHandler.java +++ /dev/null @@ -1,92 +0,0 @@ -package pro.gravit.launchserver.auth.hwid; - -import pro.gravit.launcher.hwid.HWID; - -import java.util.LinkedList; -import java.util.List; -import java.util.Objects; - -public class MemoryHWIDHandler extends HWIDHandler { - public static class Entry { - public final HWID hwid; - public String username; - public boolean isBanned = false; - - public Entry(HWID hwid) { - this.hwid = hwid; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Entry entry = (Entry) o; - return Objects.equals(hwid, entry.hwid); - } - - @Override - public int hashCode() { - return Objects.hash(hwid); - } - } - - 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; - break; - } - } - } - } - - @Override - public void check0(HWID hwid, String username) throws HWIDException { - boolean isOne = false; - for (Entry e : list) { - if (e.hwid.equals(hwid)) { - isOne = true; - if (e.isBanned) throw new HWIDException(banMessage); - } - } - if (!isOne) { - list.add(new Entry(hwid)); - } - } - - @Override - public void close() { - - } - - @Override - public void init() { - - } - - @Override - public List getHwid(String username) { - LinkedList hwids = new LinkedList<>(); - for (Entry e : list) { - if (e.username.equals(username)) hwids.add(e.hwid); - } - return hwids; - } - - @Override - public void unban(List hwid) { - for (Entry e : list) { - for (HWID banHWID : hwid) { - 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 deleted file mode 100644 index 0c062974..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java +++ /dev/null @@ -1,268 +0,0 @@ -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; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; - -public class MysqlHWIDHandler extends HWIDHandler { - private MySQLSourceConfig mySQLHolder; - - private String tableUsers; - private String tableHwids; - - private String userFieldHwid; - private String userFieldLogin; - - private String hwidFieldTotalMemory; - private String hwidFieldSerialNumber; - private String hwidFieldHWDiskSerial; - private String hwidFieldProcessorID; - private String hwidFieldBanned; - private String hwidFieldMAC; - - private String queryHwids; - private String[] paramsHwids; - - private String queryBan; - private String[] paramsBan; - - private String banMessage; - - private 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; - - /* - //Добавить поля hwid в базу с пользователями - - //Создание таблицы для хранения HWID - CREATE TABLE `fc_user_hwids` ( - `id` int(16) NOT NULL, - `totalMemory` varchar(32) NOT NULL, - `serialNumber` varchar(64) NOT NULL, - `HWDiskSerial` varchar(64) NOT NULL, - `processorID` varchar(64) NOT NULL, - `MACAddr` varchar(64) NOT NULL, - `isBanned` tinyint(1) NOT NULL DEFAULT '0' - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - - ALTER TABLE `fc_user_hwids` ADD UNIQUE KEY `id` (`id`); - - ALTER TABLE `fc_user_hwids` MODIFY `id` int(16) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2; - */ - - @Override - public void check0(HWID hwid, String username) throws HWIDException { - if (hwid instanceof OshiHWID) { - OshiHWID oshiHWID = (OshiHWID) hwid; - try (Connection c = mySQLHolder.getConnection()) { - - PreparedStatement s = c.prepareStatement(String.format("SELECT %s, %s FROM `%s` WHERE `%s` = ? LIMIT 1", - userFieldHwid, userFieldLogin, tableUsers, userFieldLogin)); - s.setString(1, username); - - // Execute SQL query - s.setQueryTimeout(MySQLSourceConfig.TIMEOUT); - try (ResultSet set = s.executeQuery()) { - if (set.next()) { - int hwid_id = set.getInt(userFieldHwid); - if (hwid_id == 0) { - onUpdateInfo(oshiHWID, username, c); - } else { - onCheckInfo(oshiHWID, username, c); - } - } - } - } catch (SQLException e) { - e.printStackTrace(); - } - } - } - - public void onUpdateInfo(OshiHWID hwid, String username, Connection c) throws HWIDException { - try (PreparedStatement a = c.prepareStatement(queryHwids)) { - - String[] replaceParams = {"totalMemory", String.valueOf(hwid.totalMemory), "serialNumber", hwid.serialNumber, "HWDiskSerial", hwid.HWDiskSerial, "processorID", hwid.processorID, "MAC", hwid.macAddr}; - for (int i = 0; i < paramsHwids.length; i++) { - a.setString(i + 1, CommonHelper.replace(paramsHwids[i], replaceParams)); - } - - ResultSet set = a.executeQuery(); - PreparedStatement ps; - if (set.next()) { - int id = set.getInt("id"); - boolean isBanned = set.getBoolean(hwidFieldBanned); - - ps = c.prepareStatement(String.format("UPDATE `%s` SET `%s` = ? WHERE `%s` = ?", - tableUsers, userFieldHwid, userFieldLogin)); - ps.setInt(1, id); - ps.setString(2, username); - - ps.setQueryTimeout(MySQLSourceConfig.TIMEOUT); - ps.executeUpdate(); - - if (isBanned) { - throw new HWIDException(banMessage); - } - } else { - ps = c.prepareStatement(String.format("INSERT INTO `%s` (`%s`, `%s`, `%s`, `%s`, `%s`) VALUES (?, ?, ?, ?, ?);", - tableHwids, hwidFieldTotalMemory, hwidFieldSerialNumber, hwidFieldHWDiskSerial, hwidFieldProcessorID, hwidFieldMAC)); - ps.setString(1, String.valueOf(hwid.totalMemory)); - ps.setString(2, hwid.serialNumber); - ps.setString(3, hwid.HWDiskSerial); - ps.setString(4, hwid.processorID); - ps.setString(5, hwid.macAddr); - ps.setQueryTimeout(MySQLSourceConfig.TIMEOUT); - ps.executeUpdate(); - - ps = c.prepareStatement(String.format("UPDATE `%s` SET `%s` = LAST_INSERT_ID() WHERE `%s` = ?;", - tableUsers, userFieldHwid, userFieldLogin)); - ps.setString(1, username); - ps.setQueryTimeout(MySQLSourceConfig.TIMEOUT); - ps.executeUpdate(); - } - } catch (SQLException e) { - e.printStackTrace(); - } - } - - public void onCheckInfo(OshiHWID hwid, String username, Connection c) throws HWIDException { - try (PreparedStatement a = c.prepareStatement(queryHwids)) { - String[] replaceParams = {"totalMemory", String.valueOf(hwid.totalMemory), "serialNumber", hwid.serialNumber, "HWDiskSerial", hwid.HWDiskSerial, "processorID", hwid.processorID, "MAC", hwid.macAddr}; - for (int i = 0; i < paramsHwids.length; i++) { - a.setString(i + 1, CommonHelper.replace(paramsHwids[i], replaceParams)); - } - ResultSet set = a.executeQuery(); - boolean isOne = false; - while (set.next()) { - if (!oneCompareMode) isOne = true; - if (compareMode) { - OshiHWID db_hwid = new OshiHWID(); - db_hwid.serialNumber = set.getString(hwidFieldSerialNumber); - db_hwid.processorID = set.getString(hwidFieldProcessorID); - db_hwid.HWDiskSerial = set.getString(hwidFieldHWDiskSerial); - 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()); - } - int compare_point = hwid.compare(db_hwid); - if (compare_point < compare) continue; - else { - if (LogHelper.isDevEnabled()) { - LogHelper.debug("User %s hwid check: found compare %d in %d", username, compare_point, set.getInt("id")); - } - } - } - if (oneCompareMode) isOne = true; - boolean isBanned = set.getBoolean(hwidFieldBanned); - if (isBanned) { - throw new HWIDException(banMessage); - } - } - if (isOne) { - onUpdateInfo(hwid, username, c); - } - } catch (SQLException e) { - e.printStackTrace(); - } - } - - public void setIsBanned(HWID hwid, boolean isBanned) { - if (LogHelper.isDebugEnabled()) { - LogHelper.debug("%s Request HWID: %s", isBanned ? "Ban" : "UnBan", hwid.toString()); - } - if (hwid instanceof OshiHWID) { - OshiHWID oshiHWID = (OshiHWID) hwid; - try (Connection c = mySQLHolder.getConnection()) { - try (PreparedStatement a = c.prepareStatement(queryBan)) { - String[] replaceParamsUpd = {"totalMemory", String.valueOf(oshiHWID.totalMemory), "serialNumber", oshiHWID.serialNumber, "HWDiskSerial", oshiHWID.HWDiskSerial, "processorID", oshiHWID.processorID, "MAC", oshiHWID.macAddr, "isBanned", isBanned ? "1" : "0"}; - for (int i = 0; i < paramsBan.length; i++) { - a.setString(i + 1, CommonHelper.replace(paramsBan[i], replaceParamsUpd)); - } - a.setQueryTimeout(MySQLSourceConfig.TIMEOUT); - a.executeUpdate(); - } catch (SQLException e) { - e.printStackTrace(); - } - } catch (SQLException e) { - e.printStackTrace(); - } - - } - } - - @Override - public void ban(List list) { - for (HWID hwid : list) { - setIsBanned(hwid, true); - } - } - - @Override - public void unban(List list) { - for (HWID hwid : list) { - setIsBanned(hwid, false); - } - } - - @Override - public List getHwid(String username) { - ArrayList list = new ArrayList<>(); - try (Connection c = mySQLHolder.getConnection()) { - if (LogHelper.isDebugEnabled()) { - LogHelper.debug("Try find HWID from username %s", username); - } - PreparedStatement s = c.prepareStatement(String.format("SELECT %s, %s FROM `%s` WHERE `%s` = ? LIMIT 1", userFieldHwid, userFieldLogin, tableUsers, userFieldLogin)); - s.setString(1, username); - - // Execute SQL query - s.setQueryTimeout(MySQLSourceConfig.TIMEOUT); - - try (ResultSet set = s.executeQuery()) { - if (set.next()) { - int hwid_id = set.getInt(userFieldHwid); - if (hwid_id != 0) { - s = c.prepareStatement(String.format("SELECT * FROM `%s` WHERE `id` = ? LIMIT 1", tableHwids)); - s.setInt(1, hwid_id); - ResultSet rs = s.executeQuery(); - if (rs.next()) { - OshiHWID oshiHWID = new OshiHWID(); - oshiHWID.totalMemory = Long.parseLong(rs.getString(hwidFieldTotalMemory)); - oshiHWID.serialNumber = rs.getString(hwidFieldSerialNumber); - oshiHWID.HWDiskSerial = rs.getString(hwidFieldHWDiskSerial); - oshiHWID.processorID = rs.getString(hwidFieldProcessorID); - oshiHWID.macAddr = rs.getString(hwidFieldMAC); - list.add(oshiHWID); - } - } - } else { - LogHelper.error(new HWIDException("HWID not found")); - } - } - } catch (SQLException e) { - e.printStackTrace(); - } - return list; - } - - @Override - public void close() { - mySQLHolder.close(); - } - - @Override - public void init() { - - } -} 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 e269c37c..8d3d310a 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,12 +1,10 @@ package pro.gravit.launchserver.command.basic; 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; import java.nio.file.Paths; import java.security.KeyPair; @@ -56,8 +54,5 @@ 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/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java index 45077405..5e43c476 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java @@ -7,7 +7,6 @@ import pro.gravit.launchserver.LaunchServer; 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.protect.ProtectHandler; import pro.gravit.launchserver.auth.protect.StdProtectHandler; import pro.gravit.launchserver.auth.provider.RejectAuthProvider; @@ -139,7 +138,6 @@ public void init(LaunchServer.ReloadType type) { 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); } } Arrays.stream(mirrors).forEach(server.mirrorManager::addMirror); @@ -152,7 +150,6 @@ public void close(LaunchServer.ReloadType type) { 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)) { @@ -280,7 +277,7 @@ public static LaunchServerConfig getDefault(LaunchServer.LaunchServerEnv env) { 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()); + ); a.displayName = "Default"; newConfig.auth.put("std", a); newConfig.protectHandler = new StdProtectHandler(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/HwidDAO.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/HwidDAO.java deleted file mode 100644 index 9333d220..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/HwidDAO.java +++ /dev/null @@ -1,19 +0,0 @@ -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/UserHWID.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserHWID.java deleted file mode 100644 index da8f438c..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserHWID.java +++ /dev/null @@ -1,8 +0,0 @@ -package pro.gravit.launchserver.dao; - -import pro.gravit.launcher.hwid.HWID; - -public interface UserHWID { - boolean isBanned(); - HWID toHWID(); -} 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 deleted file mode 100644 index 97c29082..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/HibernateHwidDAOImpl.java +++ /dev/null @@ -1,82 +0,0 @@ -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.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/UserHWIDImpl.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/UserHWIDImpl.java deleted file mode 100644 index 8c1b14dd..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/UserHWIDImpl.java +++ /dev/null @@ -1,43 +0,0 @@ -package pro.gravit.launchserver.dao.impl; - -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/provider/DaoProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/provider/DaoProvider.java index 927e9a6d..9921ac47 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,12 @@ 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.utils.ProviderMap; public abstract class DaoProvider { public static final ProviderMap providers = new ProviderMap<>("DaoProvider"); public UserDAO userDAO; - 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 7ca931bb..88be2ad5 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 @@ -3,9 +3,7 @@ import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; import pro.gravit.launchserver.LaunchServer; -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; @@ -27,7 +25,6 @@ public void init(LaunchServer server) { Runnable init = () -> { Configuration cfg = new Configuration() .addAnnotatedClass(UserHibernateImpl.class) - .addAnnotatedClass(UserHWIDImpl.class) .setProperty("hibernate.connection.driver_class", driver) .setProperty("hibernate.connection.url", url) .setProperty("hibernate.connection.username", username) @@ -39,7 +36,6 @@ public void init(LaunchServer server) { cfg.configure(Paths.get(hibernateConfig).toFile()); 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/manangers/LaunchServerGsonManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java index 13693bfe..4fde86f7 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java @@ -1,15 +1,12 @@ 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; import pro.gravit.launcher.modules.events.PreGsonPhase; import pro.gravit.launcher.request.JsonResultSerializeAdapter; import pro.gravit.launcher.request.WebSocketEvent; 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.protect.ProtectHandler; import pro.gravit.launchserver.auth.provider.AuthProvider; import pro.gravit.launchserver.auth.texture.TextureProvider; @@ -33,11 +30,9 @@ 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(HWIDHandler.class, new UniversalJsonAdapter<>(HWIDHandler.providers)); builder.registerTypeAdapter(Component.class, new UniversalJsonAdapter<>(Component.providers)); builder.registerTypeAdapter(ProtectHandler.class, new UniversalJsonAdapter<>(ProtectHandler.providers)); builder.registerTypeAdapter(DaoProvider.class, new UniversalJsonAdapter<>(DaoProvider.providers)); - builder.registerTypeAdapter(HWID.class, new UniversalJsonAdapter<>(HWIDProvider.hwids)); builder.registerTypeAdapter(WebSocketServerResponse.class, new UniversalJsonAdapter<>(WebSocketService.providers)); builder.registerTypeAdapter(WebSocketEvent.class, new JsonResultSerializeAdapter()); builder.registerTypeAdapter(AuthRequest.AuthPasswordInterface.class, new UniversalJsonAdapter<>(AuthRequest.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 0b454744..fb5c731c 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 @@ -2,15 +2,12 @@ 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; 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; import pro.gravit.launchserver.auth.provider.AuthProvider; import pro.gravit.launchserver.auth.provider.AuthProviderResult; import pro.gravit.launchserver.socket.Client; @@ -39,7 +36,6 @@ public class AuthResponse extends SimpleResponse { public String auth_id; public ConnectTypes authType; - public HWID hwid; public enum ConnectTypes { @Deprecated @@ -69,7 +65,6 @@ 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); @@ -78,7 +73,7 @@ public void execute(ChannelHandlerContext ctx, Client clientData) throws Excepti sendError("auth_id incorrect"); return; } - AuthContext context = new AuthContext(clientData, login, client, hwid, ip, authType); + AuthContext context = new AuthContext(clientData, login, client, ip, authType); AuthProvider provider = pair.provider; server.authHookManager.preHook.hook(context, clientData); provider.preAuth(login, password, ip); @@ -99,8 +94,6 @@ public void execute(ChannelHandlerContext ctx, Client clientData) throws Excepti //if (clientData.profile == null) { // throw new AuthException("You profile not found"); //} - if (authType == ConnectTypes.CLIENT) - pair.hwid.check(hwid, aresult.username); server.authHookManager.postHook.hook(context, clientData); clientData.isAuth = true; clientData.permissions = aresult.permissions; @@ -128,17 +121,16 @@ public void execute(ChannelHandlerContext ctx, Client clientData) throws Excepti } clientData.type = authType; sendResult(result); - } catch (AuthException | HWIDException | HookException e) { + } catch (AuthException | HookException e) { sendError(e.getMessage()); } } public static class AuthContext { - public AuthContext(Client client, String login, String profileName, HWID hwid, String ip, ConnectTypes authType) { + public AuthContext(Client client, String login, String profileName, String ip, ConnectTypes authType) { this.client = client; this.login = login; this.profileName = profileName; - this.hwid = hwid; this.ip = ip; this.authType = authType; } @@ -147,7 +139,6 @@ public AuthContext(Client client, String login, String profileName, HWID hwid, S @Deprecated public int password_length; //Use AuthProvider for get password public final String profileName; - public final HWID hwid; public final String ip; public final ConnectTypes authType; public final Client client; diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index 1b68a380..2759dc37 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -7,7 +7,6 @@ import pro.gravit.launcher.guard.LauncherGuardManager; import pro.gravit.launcher.gui.NoRuntimeProvider; import pro.gravit.launcher.gui.RuntimeProvider; -import pro.gravit.launcher.hwid.HWIDProvider; import pro.gravit.launcher.managers.ClientGsonManager; import pro.gravit.launcher.managers.ClientHookManager; import pro.gravit.launcher.managers.ConsoleManager; @@ -83,7 +82,6 @@ public static void main(String... args) throws Throwable { // Start Launcher initGson(LauncherEngine.modulesManager); ConsoleManager.initConsole(); - HWIDProvider.registerHWIDs(); LauncherEngine.modulesManager.invokeEvent(new PreConfigPhase()); Launcher.getConfig(); // init config long startTime = System.currentTimeMillis(); 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 d91eb126..8e9a4593 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -3,14 +3,12 @@ import pro.gravit.launcher.*; import pro.gravit.launcher.api.AuthService; import pro.gravit.launcher.api.ClientService; -import pro.gravit.launcher.api.SystemService; import pro.gravit.launcher.client.events.ClientLaunchPhase; import pro.gravit.launcher.client.events.ClientLauncherInitPhase; import pro.gravit.launcher.client.events.ClientLauncherPostInitPhase; import pro.gravit.launcher.guard.LauncherGuardManager; import pro.gravit.launcher.hasher.FileNameMatcher; import pro.gravit.launcher.hasher.HashedDir; -import pro.gravit.launcher.hwid.HWIDProvider; import pro.gravit.launcher.managers.ClientGsonManager; import pro.gravit.launcher.managers.ClientHookManager; import pro.gravit.launcher.modules.events.PreConfigPhase; @@ -457,7 +455,6 @@ public static void main(String... args) throws Throwable { JVMHelper.checkStackTrace(ClientLauncher.class); LogHelper.printVersion("Client Launcher"); engine.readKeys(); - HWIDProvider.registerHWIDs(); LauncherGuardManager.initGuard(true); LogHelper.debug("Reading ClientLauncher params"); ParamContainer p = container.read(); diff --git a/Launcher/src/main/java/pro/gravit/launcher/hwid/OshiHWIDProvider.java b/Launcher/src/main/java/pro/gravit/launcher/hwid/OshiHWIDProvider.java deleted file mode 100644 index 4ab5cd6d..00000000 --- a/Launcher/src/main/java/pro/gravit/launcher/hwid/OshiHWIDProvider.java +++ /dev/null @@ -1,129 +0,0 @@ -package pro.gravit.launcher.hwid; - -import oshi.SystemInfo; -import oshi.hardware.*; -import pro.gravit.utils.helper.LogHelper; - -import java.net.NetworkInterface; - -public class OshiHWIDProvider implements LauncherHWIDInterface { - public SystemInfo systemInfo; - public HardwareAbstractionLayer hardware; - public boolean noHWID; - - public OshiHWIDProvider() { - try { - systemInfo = new SystemInfo(); - noHWID = false; - } catch (Throwable e) { - LogHelper.error(e); - noHWID = true; - } - } - - public String getSerial() { - try { - if (hardware == null) hardware = systemInfo.getHardware(); - return hardware.getComputerSystem().getSerialNumber(); - } catch (Exception e) { - LogHelper.error(e); - return ""; - } - - } - - public String getProcessorID() { - try { - if (hardware == null) hardware = systemInfo.getHardware(); - return hardware.getProcessor().getProcessorID(); - } catch (Exception e) { - LogHelper.error(e); - return ""; - } - - } - - public String getHWDisk() { - try { - if (hardware == null) hardware = systemInfo.getHardware(); - HWDiskStore store = null; - long size = 0; - for (HWDiskStore s : hardware.getDiskStores()) { - if (size < s.getSize()) { - store = s; - size = s.getSize(); - } - } - return store == null ? "" : store.getSerial(); - } catch (Exception e) { - LogHelper.error(e); - return ""; - } - } - - public String getMacAddr() { - for (NetworkIF networkIF : hardware.getNetworkIFs()) { - if (networkIF.getNetworkInterface().isVirtual()) continue; - for (String ipv4 : networkIF.getIPv4addr()) { - if (ipv4.startsWith("127.")) continue; - if (ipv4.startsWith("10.")) continue; - return networkIF.getMacaddr(); - } - } - return ""; - } - - public long getTotalMemory() { - if (noHWID) return 1024 << 20; - if (hardware == null) hardware = systemInfo.getHardware(); - return hardware.getMemory().getTotal(); - } - - public long getAvailableMemory() { - if (noHWID) return -1; - if (hardware == null) hardware = systemInfo.getHardware(); - return hardware.getMemory().getAvailable(); - } - - public void printHardwareInformation() { - try { - if (hardware == null) hardware = systemInfo.getHardware(); - ComputerSystem computerSystem = hardware.getComputerSystem(); - LogHelper.debug("ComputerSystem Model: %s Serial: %s", computerSystem.getModel(), computerSystem.getSerialNumber()); - for (HWDiskStore s : hardware.getDiskStores()) { - LogHelper.debug("HWDiskStore Serial: %s Model: %s Size: %d", s.getSerial(), s.getModel(), s.getSize()); - } - for (UsbDevice s : hardware.getUsbDevices(true)) { - LogHelper.debug("USBDevice Serial: %s Name: %s", s.getSerialNumber(), s.getName()); - } - for (NetworkIF networkIF : hardware.getNetworkIFs()) { - LogHelper.debug("Network Interface: %s mac: %s", networkIF.getName(), networkIF.getMacaddr()); - NetworkInterface network = networkIF.getNetworkInterface(); - if (network.isLoopback() || network.isVirtual()) continue; - LogHelper.debug("Network Interface display: %s name: %s", network.getDisplayName(), network.getName()); - for (String ipv4 : networkIF.getIPv4addr()) { - if (ipv4.startsWith("127.")) continue; - if (ipv4.startsWith("10.")) continue; - LogHelper.subDebug("IPv4: %s", ipv4); - } - } - CentralProcessor processor = hardware.getProcessor(); - LogHelper.debug("Processor Model: %s ID: %s", processor.getModel(), processor.getProcessorID()); - } catch (Throwable e) { - LogHelper.error(e); - } - - } - - @Override - public HWID getHWID() { - OshiHWID hwid = new OshiHWID(); - hwid.serialNumber = getSerial(); - hwid.totalMemory = getTotalMemory(); - hwid.HWDiskSerial = getHWDisk(); - hwid.processorID = getProcessorID(); - hwid.macAddr = getMacAddr(); - printHardwareInformation(); - return hwid; - } -} 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 9986b66e..ef917aae 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/managers/ClientGsonManager.java +++ b/Launcher/src/main/java/pro/gravit/launcher/managers/ClientGsonManager.java @@ -3,8 +3,6 @@ import com.google.gson.GsonBuilder; import pro.gravit.launcher.client.ClientModuleManager; import pro.gravit.launcher.client.UserSettings; -import pro.gravit.launcher.hwid.HWID; -import pro.gravit.launcher.hwid.HWIDProvider; import pro.gravit.launcher.modules.events.PreGsonPhase; import pro.gravit.launcher.request.websockets.ClientWebSocketService; import pro.gravit.utils.UniversalJsonAdapter; @@ -20,7 +18,6 @@ public ClientGsonManager(ClientModuleManager moduleManager) { public void registerAdapters(GsonBuilder builder) { super.registerAdapters(builder); builder.registerTypeAdapter(UserSettings.class, new UniversalJsonAdapter<>(UserSettings.providers)); - builder.registerTypeAdapter(HWID.class, new UniversalJsonAdapter<>(HWIDProvider.hwids)); ClientWebSocketService.appendTypeAdapters(builder); moduleManager.invokeEvent(new PreGsonPhase(builder)); } 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 b107e716..458353e1 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWID.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWID.java @@ -1,5 +1,6 @@ package pro.gravit.launcher.hwid; +@Deprecated public interface HWID { int getLevel(); //Уровень доверия, насколько уникальные значения diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWIDCheckHelper.java b/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWIDCheckHelper.java deleted file mode 100644 index 39249b2a..00000000 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWIDCheckHelper.java +++ /dev/null @@ -1,63 +0,0 @@ -package pro.gravit.launcher.hwid; - -import pro.gravit.utils.helper.LogHelper; - -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 - { - combo++; - } else { - combo = 1; - } - lastChar = c; - if (maxCombo < combo) - maxCombo = combo; - 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; - } - } - } - //Считаем результат - 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; - } - - 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 deleted file mode 100644 index ae82c808..00000000 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWIDProvider.java +++ /dev/null @@ -1,12 +0,0 @@ -package pro.gravit.launcher.hwid; - -import pro.gravit.utils.ProviderMap; - -public class HWIDProvider { - public static final ProviderMap hwids = new ProviderMap<>(); - - 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/LauncherHWIDInterface.java b/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/LauncherHWIDInterface.java deleted file mode 100644 index fb962b11..00000000 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/LauncherHWIDInterface.java +++ /dev/null @@ -1,6 +0,0 @@ -package pro.gravit.launcher.hwid; - -@FunctionalInterface -public interface LauncherHWIDInterface { - HWID getHWID(); -} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/NoHWID.java b/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/NoHWID.java deleted file mode 100644 index 853ec6e2..00000000 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/NoHWID.java +++ /dev/null @@ -1,29 +0,0 @@ -package pro.gravit.launcher.hwid; - -public class NoHWID implements HWID { - - @Override - public int getLevel() { - return 0; - } - - @Override - public int getAntiLevel() { - return 0; - } - - @Override - public int compare(HWID hwid) { - return 0; - } - - @Override - 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 deleted file mode 100644 index 5fbade47..00000000 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/OshiHWID.java +++ /dev/null @@ -1,105 +0,0 @@ -package pro.gravit.launcher.hwid; - -import com.google.gson.Gson; -import pro.gravit.launcher.LauncherNetworkAPI; - -import java.util.Objects; -import java.util.StringJoiner; - -public class OshiHWID implements HWID { - public static Gson gson = new Gson(); - @LauncherNetworkAPI - public long totalMemory = 0; - @LauncherNetworkAPI - public String serialNumber; - @LauncherNetworkAPI - public String HWDiskSerial; - @LauncherNetworkAPI - public String processorID; - @LauncherNetworkAPI - public String macAddr; - - @Override - public int getLevel() //Уровень доверия, насколько уникальные значения - { - int result = 0; - 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 += 15; - 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) { - int rate = 0; - OshiHWID oshi = (OshiHWID) hwid; - if (Math.abs(oshi.totalMemory - totalMemory) < 1024 * 1024) rate += 5; - 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; - } - return 0; - } - - @Override - 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; - if (o == null || getClass() != o.getClass()) return false; - OshiHWID oshiHWID = (OshiHWID) o; - return totalMemory == oshiHWID.totalMemory && - Objects.equals(serialNumber, oshiHWID.serialNumber) && - Objects.equals(HWDiskSerial, oshiHWID.HWDiskSerial) && - Objects.equals(processorID, oshiHWID.processorID) && - Objects.equals(macAddr, oshiHWID.macAddr); - } - - @Override - public int hashCode() { - return Objects.hash(totalMemory, serialNumber, HWDiskSerial, processorID, macAddr); - } - - @Override - public String toString() { - return new StringJoiner(", ", OshiHWID.class.getSimpleName() + "[", "]") - .add("totalMemory=" + totalMemory) - .add("serialNumber='" + serialNumber + "'") - .add("HWDiskSerial='" + HWDiskSerial + "'") - .add("processorID='" + processorID + "'") - .add("macAddr='" + macAddr + "'") - .toString(); - } -} 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 5ce3bc78..90af57d5 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 @@ -24,10 +24,6 @@ public interface AuthPasswordInterface { @LauncherNetworkAPI private final String auth_id; @LauncherNetworkAPI - private final HWID hwid; - @LauncherNetworkAPI - private final String customText; - @LauncherNetworkAPI private final boolean getSession; @LauncherNetworkAPI private final ConnectTypes authType; @@ -45,34 +41,19 @@ public enum ConnectTypes { } - public AuthRequest(String login, byte[] password, HWID hwid) { + public AuthRequest(String login, byte[] password) { this.login = VerifyHelper.verify(login, VerifyHelper.NOT_EMPTY, "Login can't be empty"); this.password = new AuthECPassword(password.clone()); - this.hwid = hwid; - customText = ""; auth_id = ""; getSession = true; authType = ConnectTypes.CLIENT; } - + @Deprecated 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()); - this.hwid = hwid; this.auth_id = auth_id; - customText = ""; - getSession = true; - authType = ConnectTypes.CLIENT; - } - - - 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()); - this.hwid = hwid; - this.auth_id = auth_id; - this.customText = customText; getSession = true; authType = ConnectTypes.CLIENT; } @@ -82,8 +63,6 @@ public AuthRequest(String login, byte[] encryptedPassword, String auth_id, Conne this.password = new AuthECPassword(encryptedPassword.clone()); this.auth_id = auth_id; this.authType = authType; - this.hwid = null; - this.customText = ""; this.getSession = false; } @@ -92,8 +71,6 @@ public AuthRequest(String login, String password, String auth_id, ConnectTypes a this.password = new AuthPlainPassword(password); this.auth_id = auth_id; this.authType = authType; - this.hwid = null; - this.customText = ""; this.getSession = false; } From 8875146be3fe6bfcbbd8b5ca9794e9683d4b78fe Mon Sep 17 00:00:00 2001 From: Gravit Date: Fri, 20 Mar 2020 07:43:02 +0700 Subject: [PATCH 12/25] [FEATURE] feature support --- .../GetAvailabilityAuthRequestEvent.java | 17 +++++++++++++++++ .../launcher/request/auth/AuthRequest.java | 7 +++++++ 2 files changed, 24 insertions(+) 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 684d0485..36d89dfa 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 @@ -40,12 +40,29 @@ public enum AuthType OTHER } } + public enum ServerFeature + { + FEATURE_SUPPORT(1); + public final int val; + + ServerFeature(int val) { + this.val = val; + } + } @LauncherNetworkAPI public final List list; + @LauncherNetworkAPI + public final long features; public GetAvailabilityAuthRequestEvent(List list) { this.list = list; + this.features = ServerFeature.FEATURE_SUPPORT.val; + } + + public GetAvailabilityAuthRequestEvent(List list, long features) { + this.list = list; + this.features = features; } @Override 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 90af57d5..db0331eb 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 @@ -49,6 +49,13 @@ public AuthRequest(String login, byte[] password) { authType = ConnectTypes.CLIENT; } + public AuthRequest(String login, byte[] password, String auth_id) { + this.login = VerifyHelper.verify(login, VerifyHelper.NOT_EMPTY, "Login can't be empty"); + this.password = new AuthECPassword(password.clone()); + this.auth_id = auth_id; + getSession = true; + authType = ConnectTypes.CLIENT; + } @Deprecated public AuthRequest(String login, byte[] password, HWID hwid, String auth_id) { this.login = VerifyHelper.verify(login, VerifyHelper.NOT_EMPTY, "Login can't be empty"); From 8dddb08255bc11a375aaa43765b1add2a313c405 Mon Sep 17 00:00:00 2001 From: Gravit Date: Fri, 20 Mar 2020 08:44:24 +0700 Subject: [PATCH 13/25] [FEATURE][EXPERIMENTAL] SecureLevel --- .../auth/protect/AdvancedProtectHandler.java | 44 +++++++++++++++++++ .../auth/protect/ProtectHandler.java | 1 + .../interfaces/SecureProtectHandler.java | 23 ++++++++++ .../gravit/launchserver/socket/Client.java | 5 +++ .../launchserver/socket/WebSocketService.java | 8 ++-- .../secure/GetSecureLevelInfoResponse.java | 35 +++++++++++++++ .../secure/GetSecureTokenResponse.java | 20 --------- .../secure/VerifySecureLevelKeyResponse.java | 41 +++++++++++++++++ .../secure/VerifySecureTokenResponse.java | 22 ---------- .../GetSecureLevelInfoRequestEvent.java | 17 +++++++ .../request/GetSecureTokenRequestEvent.java | 18 -------- .../VerifySecureLevelKeyRequestEvent.java | 10 +++++ .../VerifySecureTokenRequestEvent.java | 18 -------- .../secure/GetSecureLevelInfoRequest.java | 11 +++++ .../secure/VerifySecureLevelKeyRequest.java | 19 ++++++++ .../websockets/ClientWebSocketService.java | 5 ++- 16 files changed, 213 insertions(+), 84 deletions(-) create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/AdvancedProtectHandler.java create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/interfaces/SecureProtectHandler.java create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/GetSecureLevelInfoResponse.java delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/GetSecureTokenResponse.java create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/VerifySecureLevelKeyResponse.java delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/VerifySecureTokenResponse.java create mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetSecureLevelInfoRequestEvent.java delete mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetSecureTokenRequestEvent.java create mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/events/request/VerifySecureLevelKeyRequestEvent.java delete mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/events/request/VerifySecureTokenRequestEvent.java create mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/GetSecureLevelInfoRequest.java create mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/VerifySecureLevelKeyRequest.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/AdvancedProtectHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/AdvancedProtectHandler.java new file mode 100644 index 00000000..d4932430 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/AdvancedProtectHandler.java @@ -0,0 +1,44 @@ +package pro.gravit.launchserver.auth.protect; + +import pro.gravit.launcher.events.request.GetSecureLevelInfoRequestEvent; +import pro.gravit.launchserver.auth.protect.interfaces.SecureProtectHandler; +import pro.gravit.launchserver.socket.Client; +import pro.gravit.launchserver.socket.response.auth.AuthResponse; +import pro.gravit.utils.helper.SecurityHelper; + +public class AdvancedProtectHandler extends ProtectHandler implements SecureProtectHandler { + @Override + public String generateSecureToken(AuthResponse.AuthContext context) { + return SecurityHelper.randomStringToken(); + } + + @Override + public String generateClientSecureToken() { + return SecurityHelper.randomStringToken(); + } + + @Override + public boolean verifyClientSecureToken(String token, String secureKey) { + return true; + } + + @Override + public boolean allowGetAccessToken(AuthResponse.AuthContext context) { + return (context.authType == AuthResponse.ConnectTypes.CLIENT) && context.client.isSecure; + } + + @Override + public void checkLaunchServerLicense() { + + } + + @Override + public GetSecureLevelInfoRequestEvent onGetSecureLevelInfo(GetSecureLevelInfoRequestEvent event) { + return event; + } + + @Override + public boolean allowGetSecureLevelInfo(Client client) { + return client.isSecure; + } +} 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 5707c281..40777ec9 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 @@ -12,6 +12,7 @@ public static void registerHandlers() { if (!registredHandl) { providers.register("none", NoProtectHandler.class); providers.register("std", StdProtectHandler.class); + providers.register("advanced", AdvancedProtectHandler.class); registredHandl = true; } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/interfaces/SecureProtectHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/interfaces/SecureProtectHandler.java new file mode 100644 index 00000000..1fd49654 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/interfaces/SecureProtectHandler.java @@ -0,0 +1,23 @@ +package pro.gravit.launchserver.auth.protect.interfaces; + +import pro.gravit.launcher.events.request.GetSecureLevelInfoRequestEvent; +import pro.gravit.launchserver.socket.Client; +import pro.gravit.utils.helper.SecurityHelper; + +import java.security.SignatureException; +import java.security.interfaces.ECPublicKey; +import java.security.spec.InvalidKeySpecException; + +public interface SecureProtectHandler { + default byte[] generateSecureLevelKey() + { + return SecurityHelper.randomBytes(128); + } + default void verifySecureLevelKey(byte[] publicKey, byte[] signature) throws InvalidKeySpecException, SignatureException { + if(publicKey == null || signature == null) throw new InvalidKeySpecException(); + ECPublicKey pubKey = SecurityHelper.toPublicECKey(publicKey); + SecurityHelper.newECVerifySignature(pubKey).update(signature); + } + GetSecureLevelInfoRequestEvent onGetSecureLevelInfo(GetSecureLevelInfoRequestEvent event); + boolean allowGetSecureLevelInfo(Client client); +} 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 a6ee1cd8..c3a2a323 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/Client.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/Client.java @@ -19,6 +19,7 @@ public class Client { public ClientPermissions permissions; public String username; public String verifyToken; + public TrustLevel trustLevel; public transient LogHelper.OutputEnity logOutput; public transient AuthProviderPair auth; @@ -48,4 +49,8 @@ public enum Type { SERVER, USER } + public static class TrustLevel + { + public byte[] verifySecureKey; + } } 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 3c060a60..2005c7d8 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java @@ -21,8 +21,8 @@ import pro.gravit.launchserver.socket.response.profile.BatchProfileByUsername; import pro.gravit.launchserver.socket.response.profile.ProfileByUUIDResponse; import pro.gravit.launchserver.socket.response.profile.ProfileByUsername; -import pro.gravit.launchserver.socket.response.secure.GetSecureTokenResponse; -import pro.gravit.launchserver.socket.response.secure.VerifySecureTokenResponse; +import pro.gravit.launchserver.socket.response.secure.GetSecureLevelInfoResponse; +import pro.gravit.launchserver.socket.response.secure.VerifySecureLevelKeyResponse; import pro.gravit.launchserver.socket.response.update.LauncherResponse; import pro.gravit.launchserver.socket.response.update.UpdateListResponse; import pro.gravit.launchserver.socket.response.update.UpdateResponse; @@ -123,12 +123,12 @@ public static void registerResponses() { providers.register("batchProfileByUsername", BatchProfileByUsername.class); providers.register("profileByUsername", ProfileByUsername.class); providers.register("profileByUUID", ProfileByUUIDResponse.class); - providers.register("getSecureToken", GetSecureTokenResponse.class); - providers.register("verifySecureToken", VerifySecureTokenResponse.class); providers.register("getAvailabilityAuth", GetAvailabilityAuthResponse.class); providers.register("register", RegisterResponse.class); providers.register("setPassword", SetPasswordResponse.class); providers.register("exit", ExitResponse.class); + providers.register("getSecureLevelInfo", GetSecureLevelInfoResponse.class); + providers.register("verifySecureLevelKey", VerifySecureLevelKeyResponse.class); } public void sendObject(ChannelHandlerContext ctx, Object obj) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/GetSecureLevelInfoResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/GetSecureLevelInfoResponse.java new file mode 100644 index 00000000..5380ffa6 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/GetSecureLevelInfoResponse.java @@ -0,0 +1,35 @@ +package pro.gravit.launchserver.socket.response.secure; + +import io.netty.channel.ChannelHandlerContext; +import pro.gravit.launcher.events.request.GetSecureLevelInfoRequestEvent; +import pro.gravit.launchserver.auth.protect.interfaces.SecureProtectHandler; +import pro.gravit.launchserver.socket.Client; +import pro.gravit.launchserver.socket.response.SimpleResponse; + +public class GetSecureLevelInfoResponse extends SimpleResponse { + @Override + public String getType() { + return "getSecureLevelInfo"; + } + + @Override + public void execute(ChannelHandlerContext ctx, Client client) throws Exception { + if(!(server.config.protectHandler instanceof SecureProtectHandler)) + { + GetSecureLevelInfoRequestEvent response = new GetSecureLevelInfoRequestEvent(null); + response.enabled = false; + sendResult(response); + } + SecureProtectHandler secureProtectHandler = (SecureProtectHandler) server.config.protectHandler; + if(!secureProtectHandler.allowGetSecureLevelInfo(client)) + { + sendError("Permissions denied"); + return; + } + if(client.trustLevel == null) client.trustLevel = new Client.TrustLevel(); + if(client.trustLevel.verifySecureKey == null) client.trustLevel.verifySecureKey = secureProtectHandler.generateSecureLevelKey(); + GetSecureLevelInfoRequestEvent response = new GetSecureLevelInfoRequestEvent(client.trustLevel.verifySecureKey); + response.enabled = true; + sendResult(secureProtectHandler.onGetSecureLevelInfo(response)); + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/GetSecureTokenResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/GetSecureTokenResponse.java deleted file mode 100644 index 9beb1ec5..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/GetSecureTokenResponse.java +++ /dev/null @@ -1,20 +0,0 @@ -package pro.gravit.launchserver.socket.response.secure; - -import io.netty.channel.ChannelHandlerContext; -import pro.gravit.launcher.events.request.GetSecureTokenRequestEvent; -import pro.gravit.launchserver.socket.Client; -import pro.gravit.launchserver.socket.response.SimpleResponse; - -public class GetSecureTokenResponse extends SimpleResponse { - @Override - public String getType() { - return "getSecureToken"; - } - - @Override - public void execute(ChannelHandlerContext ctx, Client client) { - String secureToken = server.config.protectHandler.generateClientSecureToken(); - client.verifyToken = secureToken; - sendResult(new GetSecureTokenRequestEvent(secureToken)); - } -} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/VerifySecureLevelKeyResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/VerifySecureLevelKeyResponse.java new file mode 100644 index 00000000..14ad3afc --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/VerifySecureLevelKeyResponse.java @@ -0,0 +1,41 @@ +package pro.gravit.launchserver.socket.response.secure; + +import io.netty.channel.ChannelHandlerContext; +import pro.gravit.launcher.events.request.VerifySecureLevelKeyRequestEvent; +import pro.gravit.launchserver.auth.protect.interfaces.SecureProtectHandler; +import pro.gravit.launchserver.socket.Client; +import pro.gravit.launchserver.socket.response.SimpleResponse; + +import java.security.SignatureException; +import java.security.spec.InvalidKeySpecException; + +public class VerifySecureLevelKeyResponse extends SimpleResponse { + public byte[] publicKey; + public byte[] signature; + @Override + public String getType() { + return "verifySecureLevelKey"; + } + + @Override + public void execute(ChannelHandlerContext ctx, Client client) throws Exception { + if(!(server.config.protectHandler instanceof SecureProtectHandler)) + { + sendError("This method not allowed"); + return; + } + SecureProtectHandler secureProtectHandler = (SecureProtectHandler) server.config.protectHandler; + try { + secureProtectHandler.verifySecureLevelKey(publicKey, signature); + } catch (InvalidKeySpecException e) + { + sendError("Invalid public key"); + return; + } catch (SignatureException e) + { + sendError("Invalid signature"); + return; + } + sendResult(new VerifySecureLevelKeyRequestEvent()); + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/VerifySecureTokenResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/VerifySecureTokenResponse.java deleted file mode 100644 index e59170c5..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/VerifySecureTokenResponse.java +++ /dev/null @@ -1,22 +0,0 @@ -package pro.gravit.launchserver.socket.response.secure; - -import io.netty.channel.ChannelHandlerContext; -import pro.gravit.launcher.events.request.VerifySecureTokenRequestEvent; -import pro.gravit.launchserver.socket.Client; -import pro.gravit.launchserver.socket.response.SimpleResponse; - -public class VerifySecureTokenResponse extends SimpleResponse { - public String secureToken; - - @Override - public String getType() { - return "verifySecureToken"; - } - - @Override - public void execute(ChannelHandlerContext ctx, Client client) { - boolean success = server.config.protectHandler.verifyClientSecureToken(secureToken, client.verifyToken); - if (success) client.isSecure = true; - sendResult(new VerifySecureTokenRequestEvent(success)); - } -} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetSecureLevelInfoRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetSecureLevelInfoRequestEvent.java new file mode 100644 index 00000000..bd5bbf6e --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetSecureLevelInfoRequestEvent.java @@ -0,0 +1,17 @@ +package pro.gravit.launcher.events.request; + +import pro.gravit.launcher.events.RequestEvent; + +public class GetSecureLevelInfoRequestEvent extends RequestEvent { + public final byte[] verifySecureKey; + public boolean enabled; + + public GetSecureLevelInfoRequestEvent(byte[] verifySecureKey) { + this.verifySecureKey = verifySecureKey; + } + + @Override + public String getType() { + return "getSecureLevelInfo"; + } +} 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 deleted file mode 100644 index e221b76c..00000000 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetSecureTokenRequestEvent.java +++ /dev/null @@ -1,18 +0,0 @@ -package pro.gravit.launcher.events.request; - -import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.events.RequestEvent; - -public class GetSecureTokenRequestEvent extends RequestEvent { - @LauncherNetworkAPI - public final String secureToken; - - @Override - public String getType() { - return "GetSecureToken"; - } - - public GetSecureTokenRequestEvent(String secureToken) { - this.secureToken = secureToken; - } -} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/VerifySecureLevelKeyRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/VerifySecureLevelKeyRequestEvent.java new file mode 100644 index 00000000..785c3f53 --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/VerifySecureLevelKeyRequestEvent.java @@ -0,0 +1,10 @@ +package pro.gravit.launcher.events.request; + +import pro.gravit.launcher.events.RequestEvent; + +public class VerifySecureLevelKeyRequestEvent extends RequestEvent { + @Override + public String getType() { + return "verifySecureLevelKey"; + } +} 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 deleted file mode 100644 index 276000b7..00000000 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/VerifySecureTokenRequestEvent.java +++ /dev/null @@ -1,18 +0,0 @@ -package pro.gravit.launcher.events.request; - -import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.events.RequestEvent; - -public class VerifySecureTokenRequestEvent extends RequestEvent { - @LauncherNetworkAPI - public final boolean success; - - @Override - public String getType() { - return "verifySecureToken"; - } - - public VerifySecureTokenRequestEvent(boolean success) { - this.success = success; - } -} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/GetSecureLevelInfoRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/GetSecureLevelInfoRequest.java new file mode 100644 index 00000000..47eb594e --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/GetSecureLevelInfoRequest.java @@ -0,0 +1,11 @@ +package pro.gravit.launcher.request.secure; + +import pro.gravit.launcher.events.request.GetSecureLevelInfoRequestEvent; +import pro.gravit.launcher.request.Request; + +public class GetSecureLevelInfoRequest extends Request { + @Override + public String getType() { + return "getSecureLevelInfo"; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/VerifySecureLevelKeyRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/VerifySecureLevelKeyRequest.java new file mode 100644 index 00000000..b1d0bdb9 --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/VerifySecureLevelKeyRequest.java @@ -0,0 +1,19 @@ +package pro.gravit.launcher.request.secure; + +import pro.gravit.launcher.events.request.VerifySecureLevelKeyRequestEvent; +import pro.gravit.launcher.request.Request; + +public class VerifySecureLevelKeyRequest extends Request { + public final byte[] publicKey; + public final byte[] signature; + + public VerifySecureLevelKeyRequest(byte[] publicKey, byte[] signature) { + this.publicKey = publicKey; + this.signature = signature; + } + + @Override + public String getType() { + return "verifySecureLevelKey"; + } +} 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 c6604048..1d5da0d6 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 @@ -11,6 +11,7 @@ import pro.gravit.launcher.hasher.HashedEntryAdapter; import pro.gravit.launcher.request.WebSocketEvent; import pro.gravit.launcher.request.auth.AuthRequest; +import pro.gravit.launcher.request.secure.VerifySecureLevelKeyRequest; import pro.gravit.utils.ProviderMap; import pro.gravit.utils.UniversalJsonAdapter; import pro.gravit.utils.helper.LogHelper; @@ -97,8 +98,6 @@ public void registerResults() { results.register("error", ErrorRequestEvent.class); results.register("update", UpdateRequestEvent.class); results.register("restoreSession", RestoreSessionRequestEvent.class); - results.register("getSecureToken", GetSecureTokenRequestEvent.class); - results.register("verifySecureToken", VerifySecureTokenRequestEvent.class); results.register("log", LogEvent.class); results.register("cmdExec", ExecCommandRequestEvent.class); results.register("getAvailabilityAuth", GetAvailabilityAuthRequestEvent.class); @@ -108,6 +107,8 @@ public void registerResults() { results.register("notification", NotificationEvent.class); results.register("signal", SignalEvent.class); results.register("exit", ExitRequestEvent.class); + results.register("getSecureLevelInfo", GetSecureLevelInfoRequestEvent.class); + results.register("verifySecureLevelKey", VerifySecureLevelKeyRequestEvent.class); } public void waitIfNotConnected() { From c57cb907008c65c0c290f524cca459f0298b0720 Mon Sep 17 00:00:00 2001 From: Gravit Date: Fri, 20 Mar 2020 09:23:09 +0700 Subject: [PATCH 14/25] [FEATURE][EXPERIMENTAL] SecurityReport --- .../auth/protect/AdvancedProtectHandler.java | 14 ---- .../auth/protect/NoProtectHandler.java | 14 ---- .../auth/protect/ProtectHandler.java | 6 -- .../auth/protect/StdProtectHandler.java | 15 ---- .../interfaces/SecureProtectHandler.java | 6 ++ .../security/SecurityReportModuleEvent.java | 18 +++++ .../modules/impl/LaunchServerCoreModule.java | 5 ++ .../launchserver/socket/WebSocketService.java | 2 + .../secure/SecurityReportResponse.java | 32 ++++++++ .../request/SecurityReportRequestEvent.java | 36 +++++++++ .../request/secure/SecurityReportRequest.java | 74 +++++++++++++++++++ .../websockets/ClientWebSocketService.java | 1 + 12 files changed, 174 insertions(+), 49 deletions(-) create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/security/SecurityReportModuleEvent.java create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/SecurityReportResponse.java create mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/events/request/SecurityReportRequestEvent.java create mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/SecurityReportRequest.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/AdvancedProtectHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/AdvancedProtectHandler.java index d4932430..17005bf0 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/AdvancedProtectHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/AdvancedProtectHandler.java @@ -7,20 +7,6 @@ import pro.gravit.utils.helper.SecurityHelper; public class AdvancedProtectHandler extends ProtectHandler implements SecureProtectHandler { - @Override - public String generateSecureToken(AuthResponse.AuthContext context) { - return SecurityHelper.randomStringToken(); - } - - @Override - public String generateClientSecureToken() { - return SecurityHelper.randomStringToken(); - } - - @Override - public boolean verifyClientSecureToken(String token, String secureKey) { - return true; - } @Override public boolean allowGetAccessToken(AuthResponse.AuthContext context) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/NoProtectHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/NoProtectHandler.java index 7985c744..6480fc79 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/NoProtectHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/NoProtectHandler.java @@ -4,20 +4,6 @@ import pro.gravit.utils.helper.SecurityHelper; public class NoProtectHandler extends ProtectHandler { - @Override - public String generateSecureToken(AuthResponse.AuthContext context) { - return SecurityHelper.randomStringToken(); - } - - @Override - public String generateClientSecureToken() { - return SecurityHelper.randomStringToken(); - } - - @Override - public boolean verifyClientSecureToken(String token, String secureKey) { - return true; - } @Override public boolean allowGetAccessToken(AuthResponse.AuthContext context) { 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 40777ec9..8bdaadc3 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 @@ -17,12 +17,6 @@ public static void registerHandlers() { } } - public abstract String generateSecureToken(AuthResponse.AuthContext context); //Генерация токена для передачи его в LauncherGuardInterface - - public abstract String generateClientSecureToken(); - - public abstract boolean verifyClientSecureToken(String token, String secureKey); - public abstract boolean allowGetAccessToken(AuthResponse.AuthContext context); public abstract void checkLaunchServerLicense(); //Выдает SecurityException при ошибке проверки лицензии 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 1b165ea4..380413e0 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 @@ -6,21 +6,6 @@ public class StdProtectHandler extends ProtectHandler { public final boolean checkSecure = true; - @Override - public String generateSecureToken(AuthResponse.AuthContext context) { - return SecurityHelper.randomStringToken(); - } - - @Override - public String generateClientSecureToken() { - return SecurityHelper.randomStringToken(); - } - - @Override - public boolean verifyClientSecureToken(String token, String secureKey) { - return true; - } - @Override public boolean allowGetAccessToken(AuthResponse.AuthContext context) { return (context.authType == AuthResponse.ConnectTypes.CLIENT) && (!checkSecure || context.client.isSecure); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/interfaces/SecureProtectHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/interfaces/SecureProtectHandler.java index 1fd49654..5170d869 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/interfaces/SecureProtectHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/interfaces/SecureProtectHandler.java @@ -1,7 +1,9 @@ package pro.gravit.launchserver.auth.protect.interfaces; import pro.gravit.launcher.events.request.GetSecureLevelInfoRequestEvent; +import pro.gravit.launcher.events.request.SecurityReportRequestEvent; import pro.gravit.launchserver.socket.Client; +import pro.gravit.launchserver.socket.response.secure.SecurityReportResponse; import pro.gravit.utils.helper.SecurityHelper; import java.security.SignatureException; @@ -20,4 +22,8 @@ default void verifySecureLevelKey(byte[] publicKey, byte[] signature) throws Inv } GetSecureLevelInfoRequestEvent onGetSecureLevelInfo(GetSecureLevelInfoRequestEvent event); boolean allowGetSecureLevelInfo(Client client); + default SecurityReportRequestEvent onSecurityReport(SecurityReportResponse report, Client client) + { + return new SecurityReportRequestEvent(); + } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/security/SecurityReportModuleEvent.java b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/security/SecurityReportModuleEvent.java new file mode 100644 index 00000000..8fb01c62 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/security/SecurityReportModuleEvent.java @@ -0,0 +1,18 @@ +package pro.gravit.launchserver.modules.events.security; + +import pro.gravit.launcher.events.request.SecurityReportRequestEvent; +import pro.gravit.launcher.modules.LauncherModule; +import pro.gravit.launchserver.socket.Client; +import pro.gravit.launchserver.socket.response.secure.SecurityReportResponse; + +public class SecurityReportModuleEvent extends LauncherModule.Event { + public final SecurityReportRequestEvent event; + public final SecurityReportResponse response; + public final Client client; + + public SecurityReportModuleEvent(SecurityReportRequestEvent event, SecurityReportResponse response, Client client) { + this.event = event; + this.response = response; + this.client = client; + } +} 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 9c35208a..6e54d9bb 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 @@ -19,4 +19,9 @@ public void init(LauncherInitContext initContext) { public void testEvent(InitPhase event) { //LogHelper.debug("[LaunchServerCore] Event LaunchServerInitPhase passed"); } + + @Override + public boolean registerEvent(EventHandler handle, Class tClass) { + return super.registerEvent(handle, tClass); + } } 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 2005c7d8..00b1b1b7 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java @@ -22,6 +22,7 @@ import pro.gravit.launchserver.socket.response.profile.ProfileByUUIDResponse; import pro.gravit.launchserver.socket.response.profile.ProfileByUsername; import pro.gravit.launchserver.socket.response.secure.GetSecureLevelInfoResponse; +import pro.gravit.launchserver.socket.response.secure.SecurityReportResponse; import pro.gravit.launchserver.socket.response.secure.VerifySecureLevelKeyResponse; import pro.gravit.launchserver.socket.response.update.LauncherResponse; import pro.gravit.launchserver.socket.response.update.UpdateListResponse; @@ -129,6 +130,7 @@ public static void registerResponses() { providers.register("exit", ExitResponse.class); providers.register("getSecureLevelInfo", GetSecureLevelInfoResponse.class); providers.register("verifySecureLevelKey", VerifySecureLevelKeyResponse.class); + providers.register("securityReport", SecurityReportResponse.class); } public void sendObject(ChannelHandlerContext ctx, Object obj) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/SecurityReportResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/SecurityReportResponse.java new file mode 100644 index 00000000..da5f5138 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/SecurityReportResponse.java @@ -0,0 +1,32 @@ +package pro.gravit.launchserver.socket.response.secure; + +import io.netty.channel.ChannelHandlerContext; +import pro.gravit.launcher.events.request.SecurityReportRequestEvent; +import pro.gravit.launchserver.auth.protect.interfaces.SecureProtectHandler; +import pro.gravit.launchserver.modules.events.security.SecurityReportModuleEvent; +import pro.gravit.launchserver.socket.Client; +import pro.gravit.launchserver.socket.response.SimpleResponse; + +public class SecurityReportResponse extends SimpleResponse { + public String reportType; + public String smallData; + public String largeData; + public byte[] smallBytes; + public byte[] largeBytes; + @Override + public String getType() { + return "securityReport"; + } + + @Override + public void execute(ChannelHandlerContext ctx, Client client) throws Exception { + if(!(server.config.protectHandler instanceof SecureProtectHandler)) + { + sendError("Method not allowed"); + } + SecureProtectHandler secureProtectHandler = (SecureProtectHandler) server.config.protectHandler; + SecurityReportRequestEvent event = secureProtectHandler.onSecurityReport(this, client); + server.modulesManager.invokeEvent(new SecurityReportModuleEvent(event, this, client)); + sendResult(event); + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/SecurityReportRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/SecurityReportRequestEvent.java new file mode 100644 index 00000000..7dec5d4f --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/SecurityReportRequestEvent.java @@ -0,0 +1,36 @@ +package pro.gravit.launcher.events.request; + +import pro.gravit.launcher.events.RequestEvent; + +public class SecurityReportRequestEvent extends RequestEvent { + public SecurityReportRequestEvent(ReportAction action) { + this.action = action; + this.otherAction = null; + } + + public SecurityReportRequestEvent(String otherAction) { + this.action = ReportAction.OTHER; + this.otherAction = otherAction; + } + + public SecurityReportRequestEvent() { + this.action = ReportAction.NONE; + this.otherAction = null; + } + + public enum ReportAction + { + NONE, + LOGOUT, + EXIT, + CRASH, + OTHER + } + public final ReportAction action; + public final String otherAction; + + @Override + public String getType() { + return "securityReport"; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/SecurityReportRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/SecurityReportRequest.java new file mode 100644 index 00000000..92cd43c6 --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/SecurityReportRequest.java @@ -0,0 +1,74 @@ +package pro.gravit.launcher.request.secure; + +import pro.gravit.launcher.events.request.SecurityReportRequestEvent; +import pro.gravit.launcher.request.Request; + +public final class SecurityReportRequest extends Request { + public final String reportType; + public final String smallData; + public final String largeData; + public final byte[] smallBytes; + public final byte[] largeBytes; + + public SecurityReportRequest(String reportType, String smallData, String largeData, byte[] smallBytes, byte[] largeBytes) { + this.reportType = reportType; + this.smallData = smallData; + this.largeData = largeData; + this.smallBytes = smallBytes; + this.largeBytes = largeBytes; + } + public SecurityReportRequest(String reportType, String smallData, String largeData, byte[] smallBytes) { + this.reportType = reportType; + this.smallData = smallData; + this.largeData = largeData; + this.smallBytes = smallBytes; + this.largeBytes = null; + } + public SecurityReportRequest(String reportType, String smallData, String largeData) { + this.reportType = reportType; + this.smallData = smallData; + this.largeData = largeData; + this.smallBytes = null; + this.largeBytes = null; + } + public SecurityReportRequest(String reportType, String smallData, byte[] smallBytes) { + this.reportType = reportType; + this.smallData = smallData; + this.largeData = null; + this.smallBytes = smallBytes; + this.largeBytes = null; + } + public SecurityReportRequest(String reportType, byte[] smallBytes, byte[] largeBytes) { + this.reportType = reportType; + this.smallData = null; + this.largeData = null; + this.smallBytes = smallBytes; + this.largeBytes = largeBytes; + } + public SecurityReportRequest(String reportType, byte[] smallBytes) { + this.reportType = reportType; + this.smallData = null; + this.largeData = null; + this.smallBytes = smallBytes; + this.largeBytes = null; + } + public SecurityReportRequest(String reportType, String smallData) { + this.reportType = reportType; + this.smallData = smallData; + this.largeData = null; + this.smallBytes = null; + this.largeBytes = null; + } + public SecurityReportRequest(String reportType) { + this.reportType = reportType; + this.smallData = null; + this.largeData = null; + this.smallBytes = null; + this.largeBytes = null; + } + + @Override + public String getType() { + return "securityReport"; + } +} 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 1d5da0d6..4e74f253 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 @@ -109,6 +109,7 @@ public void registerResults() { results.register("exit", ExitRequestEvent.class); results.register("getSecureLevelInfo", GetSecureLevelInfoRequestEvent.class); results.register("verifySecureLevelKey", VerifySecureLevelKeyRequestEvent.class); + results.register("securityReport", SecurityReportRequestEvent.class); } public void waitIfNotConnected() { From 7527251841788ee815bd66d4bb25468b8ddda739 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sun, 22 Mar 2020 03:24:18 +0700 Subject: [PATCH 15/25] [FIX] Delete deprecated Client params --- .../launchserver/auth/protect/AdvancedProtectHandler.java | 4 ++-- .../gravit/launchserver/auth/protect/StdProtectHandler.java | 2 +- .../gravit/launchserver/command/service/ClientsCommand.java | 2 +- .../main/java/pro/gravit/launchserver/socket/Client.java | 2 -- .../launchserver/socket/response/auth/ExitResponse.java | 3 --- .../socket/response/update/LauncherResponse.java | 6 ++---- 6 files changed, 6 insertions(+), 13 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/AdvancedProtectHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/AdvancedProtectHandler.java index 17005bf0..bb057204 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/AdvancedProtectHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/AdvancedProtectHandler.java @@ -10,7 +10,7 @@ public class AdvancedProtectHandler extends ProtectHandler implements SecureProt @Override public boolean allowGetAccessToken(AuthResponse.AuthContext context) { - return (context.authType == AuthResponse.ConnectTypes.CLIENT) && context.client.isSecure; + return (context.authType == AuthResponse.ConnectTypes.CLIENT) && context.client.checkSign; } @Override @@ -25,6 +25,6 @@ public GetSecureLevelInfoRequestEvent onGetSecureLevelInfo(GetSecureLevelInfoReq @Override public boolean allowGetSecureLevelInfo(Client client) { - return client.isSecure; + return client.checkSign; } } 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 380413e0..0a06e4e3 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 @@ -8,7 +8,7 @@ public class StdProtectHandler extends ProtectHandler { @Override public boolean allowGetAccessToken(AuthResponse.AuthContext context) { - return (context.authType == AuthResponse.ConnectTypes.CLIENT) && (!checkSecure || context.client.isSecure); + return (context.authType == AuthResponse.ConnectTypes.CLIENT) && (!checkSecure || context.client.checkSign); } @Override 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 80ed2ef3..6d52c664 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 @@ -34,7 +34,7 @@ public void invoke(String... args) { LogHelper.info("Channel %s | connectUUID %s | checkSign %s", ip, frameHandler.getConnectUUID(), client.checkSign ? "true" : "false"); else { 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", + LogHelper.subInfo("Data: checkSign %s | auth_id %s", client.checkSign ? "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/Client.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/Client.java index c3a2a323..205ac55c 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/Client.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/Client.java @@ -15,10 +15,8 @@ public class Client { public ClientProfile profile; public boolean isAuth; public boolean checkSign; - public boolean isSecure; public ClientPermissions permissions; public String username; - public String verifyToken; public TrustLevel trustLevel; public transient LogHelper.OutputEnity logOutput; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/ExitResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/ExitResponse.java index 07af9fff..91d98be7 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/ExitResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/ExitResponse.java @@ -36,7 +36,6 @@ public void execute(ChannelHandlerContext ctx, Client client) throws Exception { return; } Client newClient = new Client(0); - newClient.isSecure = client.isSecure; newClient.checkSign = client.checkSign; handler.setClient(newClient); if(client.session != 0) server.sessionManager.removeClient(client.session); @@ -56,7 +55,6 @@ public void execute(ChannelHandlerContext ctx, Client client) throws Exception { if(chClient.session != client.session) return; } Client newCusClient = new Client(0); - newCusClient.isSecure = chClient.isSecure; newCusClient.checkSign = chClient.checkSign; wsHandler.setClient(newCusClient); if(chClient.session != 0) server.sessionManager.removeClient(chClient.session); @@ -76,7 +74,6 @@ public void execute(ChannelHandlerContext ctx, Client client) throws Exception { Client chClient = wsHandler.getClient(); if(!chClient.isAuth || !username.equals(chClient.username)) return; Client newCusClient = new Client(0); - newCusClient.isSecure = chClient.isSecure; newCusClient.checkSign = chClient.checkSign; wsHandler.setClient(newCusClient); if(chClient.session != 0) server.sessionManager.removeClient(chClient.session); 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 63f10afb..ef7bc7b1 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 @@ -36,9 +36,8 @@ public void execute(ChannelHandlerContext ctx, Client client) { byte[] hash = server.launcherBinary.getDigest(); if (hash == null) service.sendObjectAndClose(ctx, new LauncherRequestEvent(true, server.config.netty.launcherURL)); - if (Arrays.equals(bytes, hash)) { + if (Arrays.equals(bytes, hash) && checkSecure(secureHash, secureSalt)) { client.checkSign = true; - client.isSecure = checkSecure(secureHash, secureSalt); sendResult(new LauncherRequestEvent(false, server.config.netty.launcherURL)); } else { sendResultAndClose(new LauncherRequestEvent(true, server.config.netty.launcherURL)); @@ -47,9 +46,8 @@ public void execute(ChannelHandlerContext ctx, Client client) { { byte[] hash = server.launcherEXEBinary.getDigest(); if (hash == null) sendResultAndClose(new LauncherRequestEvent(true, server.config.netty.launcherEXEURL)); - if (Arrays.equals(bytes, hash)) { + if (Arrays.equals(bytes, hash) && checkSecure(secureHash, secureSalt)) { client.checkSign = true; - client.isSecure = checkSecure(secureHash, secureSalt); sendResult(new LauncherRequestEvent(false, server.config.netty.launcherEXEURL)); } else { sendResultAndClose(new LauncherRequestEvent(true, server.config.netty.launcherEXEURL)); From 56b933bd3ae1a21b9a1f24bc04ac0dd7f12e6ce6 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sun, 22 Mar 2020 03:36:52 +0700 Subject: [PATCH 16/25] [FIX] VerifySecureLevelKey --- .../auth/protect/interfaces/SecureProtectHandler.java | 7 +++++-- .../java/pro/gravit/launchserver/socket/Client.java | 2 ++ .../response/secure/GetSecureLevelInfoResponse.java | 2 +- .../response/secure/VerifySecureLevelKeyResponse.java | 10 ++++++++-- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/interfaces/SecureProtectHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/interfaces/SecureProtectHandler.java index 5170d869..bf342170 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/interfaces/SecureProtectHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/interfaces/SecureProtectHandler.java @@ -6,6 +6,7 @@ import pro.gravit.launchserver.socket.response.secure.SecurityReportResponse; import pro.gravit.utils.helper.SecurityHelper; +import java.security.Signature; import java.security.SignatureException; import java.security.interfaces.ECPublicKey; import java.security.spec.InvalidKeySpecException; @@ -15,10 +16,12 @@ default byte[] generateSecureLevelKey() { return SecurityHelper.randomBytes(128); } - default void verifySecureLevelKey(byte[] publicKey, byte[] signature) throws InvalidKeySpecException, SignatureException { + default void verifySecureLevelKey(byte[] publicKey, byte[] data, byte[] signature) throws InvalidKeySpecException, SignatureException { if(publicKey == null || signature == null) throw new InvalidKeySpecException(); ECPublicKey pubKey = SecurityHelper.toPublicECKey(publicKey); - SecurityHelper.newECVerifySignature(pubKey).update(signature); + Signature sign = SecurityHelper.newECVerifySignature(pubKey); + sign.update(data); + sign.verify(signature); } GetSecureLevelInfoRequestEvent onGetSecureLevelInfo(GetSecureLevelInfoRequestEvent event); boolean allowGetSecureLevelInfo(Client client); 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 205ac55c..763cd165 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/Client.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/Client.java @@ -50,5 +50,7 @@ public enum Type { public static class TrustLevel { public byte[] verifySecureKey; + public boolean keyChecked; + public byte[] publicKey; } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/GetSecureLevelInfoResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/GetSecureLevelInfoResponse.java index 5380ffa6..a99d8801 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/GetSecureLevelInfoResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/GetSecureLevelInfoResponse.java @@ -23,7 +23,7 @@ public void execute(ChannelHandlerContext ctx, Client client) throws Exception { SecureProtectHandler secureProtectHandler = (SecureProtectHandler) server.config.protectHandler; if(!secureProtectHandler.allowGetSecureLevelInfo(client)) { - sendError("Permissions denied"); + sendError("Access denied"); return; } if(client.trustLevel == null) client.trustLevel = new Client.TrustLevel(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/VerifySecureLevelKeyResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/VerifySecureLevelKeyResponse.java index 14ad3afc..519e64a6 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/VerifySecureLevelKeyResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/VerifySecureLevelKeyResponse.java @@ -19,14 +19,14 @@ public String getType() { @Override public void execute(ChannelHandlerContext ctx, Client client) throws Exception { - if(!(server.config.protectHandler instanceof SecureProtectHandler)) + if(!(server.config.protectHandler instanceof SecureProtectHandler) || client.trustLevel == null || client.trustLevel.verifySecureKey == null) { sendError("This method not allowed"); return; } SecureProtectHandler secureProtectHandler = (SecureProtectHandler) server.config.protectHandler; try { - secureProtectHandler.verifySecureLevelKey(publicKey, signature); + secureProtectHandler.verifySecureLevelKey(publicKey, client.trustLevel.verifySecureKey, signature); } catch (InvalidKeySpecException e) { sendError("Invalid public key"); @@ -35,7 +35,13 @@ public void execute(ChannelHandlerContext ctx, Client client) throws Exception { { sendError("Invalid signature"); return; + } catch (SecurityException e) + { + sendError(e.getMessage()); + return; } + client.trustLevel.keyChecked = true; + client.trustLevel.publicKey = publicKey; sendResult(new VerifySecureLevelKeyRequestEvent()); } } From 58a208a3f51881fb7b34d4d233d1a8fcb1199a86 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sun, 22 Mar 2020 03:48:48 +0700 Subject: [PATCH 17/25] =?UTF-8?q?[FIX]=20=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20whitelist=20=D0=BF=D1=80=D0=BE=D1=84=D0=B8?= =?UTF-8?q?=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gravit/launchserver/config/LaunchServerConfig.java | 2 -- .../socket/response/auth/AuthResponse.java | 9 --------- .../socket/response/auth/SetProfileResponse.java | 4 ---- .../socket/response/update/UpdateResponse.java | 9 --------- .../pro/gravit/launcher/profiles/ClientProfile.java | 10 ---------- 5 files changed, 34 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 5e43c476..c71cf184 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java @@ -74,7 +74,6 @@ public AuthProviderPair getAuthProviderPair() { public ExeConf launch4j; public NettyConfig netty; - public String whitelistRejectString; public LauncherConf launcher; public CertificateConf certificate; public JarSignerConf sign; @@ -282,7 +281,6 @@ public static LaunchServerConfig getDefault(LaunchServer.LaunchServerEnv env) { newConfig.auth.put("std", a); newConfig.protectHandler = new StdProtectHandler(); newConfig.binaryName = "Launcher"; - newConfig.whitelistRejectString = "Вас нет в белом списке"; newConfig.netty = new NettyConfig(); newConfig.netty.fileServerEnabled = true; 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 fb5c731c..f2454f29 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 @@ -82,15 +82,6 @@ public void execute(ChannelHandlerContext ctx, Client clientData) throws Excepti AuthProvider.authError(String.format("Illegal result: '%s'", aresult.username)); return; } - Collection profiles = server.getProfiles(); - for (ClientProfile p : profiles) { - if (p.getTitle().equals(client)) { - if (!p.isWhitelistContains(login)) { - throw new AuthException(server.config.whitelistRejectString); - } - clientData.profile = p; - } - } //if (clientData.profile == null) { // throw new AuthException("You profile not found"); //} 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 5f4ce7b3..54111cac 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 @@ -31,10 +31,6 @@ public void execute(ChannelHandlerContext ctx, Client client) { Collection profiles = server.getProfiles(); for (ClientProfile p : profiles) { if (p.getTitle().equals(this.client)) { - if (!p.isWhitelistContains(client.username)) { - sendError(server.config.whitelistRejectString); - return; - } client.profile = p; sendResult(new SetProfileRequestEvent(p)); return; 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 9904f1d0..c3b4846b 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 @@ -24,15 +24,6 @@ public void execute(ChannelHandlerContext ctx, Client client) { sendError("Access denied"); return; } - if (!client.permissions.canAdmin) { - for (ClientProfile p : server.getProfiles()) { - if (!client.profile.getTitle().equals(p.getTitle())) continue; - if (!p.isWhitelistContains(client.username)) { - sendError("You don't download this folder"); - return; - } - } - } HashedDir dir = server.updatesDirMap.get(dirName); if (dir == null) { sendError(String.format("Directory %s not found", dirName)); 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 9f78774f..b954fab0 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java @@ -120,8 +120,6 @@ public enum ClassLoaderConfig private final Set updateOptional = new HashSet<>(); @LauncherNetworkAPI private boolean updateFastCheck; - @LauncherNetworkAPI - private boolean useWhitelist; // Client launcher @LauncherNetworkAPI private String mainClass; @@ -132,8 +130,6 @@ public enum ClassLoaderConfig @LauncherNetworkAPI 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; @@ -383,12 +379,6 @@ public boolean isUpdateFastCheck() { } - public boolean isWhitelistContains(String username) { - if (!useWhitelist) return true; - return whitelist.stream().anyMatch(profileCaseSensitive ? e -> e.equals(username) : e -> e.equalsIgnoreCase(username)); - } - - public void setTitle(String title) { this.title = title; } From 9ccaf3b1d786fe17d97da39c136c971f45d7e547 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sun, 22 Mar 2020 04:16:15 +0700 Subject: [PATCH 18/25] =?UTF-8?q?[FIX]=20=D0=90=D0=BB=D1=8C=D1=82=D0=B5?= =?UTF-8?q?=D1=80=D0=BD=D0=B0=D1=82=D0=B8=D0=B2=D0=B0=20whitelist=20=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D1=84=D0=B8=D0=BB=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/protect/StdProtectHandler.java | 36 +++++++++++++++++-- .../interfaces/ProfilesProtectHandler.java | 23 ++++++++++++ .../response/auth/ProfilesResponse.java | 30 ++++++++++++++-- .../response/auth/SetProfileResponse.java | 10 +++--- .../response/update/UpdateResponse.java | 3 +- 5 files changed, 91 insertions(+), 11 deletions(-) create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/interfaces/ProfilesProtectHandler.java 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 0a06e4e3..d11fd0ba 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 @@ -1,18 +1,48 @@ package pro.gravit.launchserver.auth.protect; +import pro.gravit.launcher.profiles.ClientProfile; +import pro.gravit.launchserver.auth.protect.interfaces.ProfilesProtectHandler; +import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.auth.AuthResponse; import pro.gravit.utils.helper.SecurityHelper; -public class StdProtectHandler extends ProtectHandler { - public final boolean checkSecure = true; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +public class StdProtectHandler extends ProtectHandler implements ProfilesProtectHandler { + public Map> profileWhitelist = new HashMap<>(); + public List allowUpdates = new ArrayList<>(); @Override public boolean allowGetAccessToken(AuthResponse.AuthContext context) { - return (context.authType == AuthResponse.ConnectTypes.CLIENT) && (!checkSecure || context.client.checkSign); + return (context.authType == AuthResponse.ConnectTypes.CLIENT) && context.client.checkSign; } @Override public void checkLaunchServerLicense() { } + + @Override + public boolean canGetProfile(ClientProfile profile, Client client) { + return canChangeProfile(profile, client); + } + + @Override + public boolean canChangeProfile(ClientProfile profile, Client client) { + return client.isAuth && client.username != null && isWhitelisted(profile.getTitle(), client.username); + } + + @Override + public boolean canGetUpdates(String updatesDirName, Client client) { + return client.profile != null && ( client.profile.getDir().equals(updatesDirName) || client.profile.getAssetDir().equals(updatesDirName) || allowUpdates.contains(updatesDirName)); + } + + public boolean isWhitelisted(String profileTitle, String username) + { + List allowedUsername = profileWhitelist.get(profileTitle); + if(allowedUsername == null) return true; + return allowedUsername.contains(username); + } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/interfaces/ProfilesProtectHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/interfaces/ProfilesProtectHandler.java new file mode 100644 index 00000000..534cde65 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/interfaces/ProfilesProtectHandler.java @@ -0,0 +1,23 @@ +package pro.gravit.launchserver.auth.protect.interfaces; + +import pro.gravit.launcher.profiles.ClientProfile; +import pro.gravit.launchserver.socket.Client; + +public interface ProfilesProtectHandler { + default boolean canGetProfiles(Client client) + { + return true; + } + default boolean canGetProfile(ClientProfile profile, Client client) + { + return true; + } + default boolean canChangeProfile(ClientProfile profile, Client client) + { + return client.isAuth; + } + default boolean canGetUpdates(String updatesDirName, Client client) + { + return true; + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/ProfilesResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/ProfilesResponse.java index 5c00006e..cd426cd7 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/ProfilesResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/ProfilesResponse.java @@ -3,9 +3,14 @@ import io.netty.channel.ChannelHandlerContext; import pro.gravit.launcher.events.request.ErrorRequestEvent; import pro.gravit.launcher.events.request.ProfilesRequestEvent; +import pro.gravit.launcher.profiles.ClientProfile; +import pro.gravit.launchserver.auth.protect.interfaces.ProfilesProtectHandler; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.SimpleResponse; +import java.util.ArrayList; +import java.util.List; + public class ProfilesResponse extends SimpleResponse { @Override public String getType() { @@ -14,10 +19,29 @@ public String getType() { @Override public void execute(ChannelHandlerContext ctx, Client client) { - if (!client.checkSign && !client.isAuth) { - service.sendObject(ctx, new ErrorRequestEvent("Access denied")); + if (server.config.protectHandler instanceof ProfilesProtectHandler && !((ProfilesProtectHandler) server.config.protectHandler).canGetProfiles(client)) { + sendError("Access denied"); return; } - sendResult(new ProfilesRequestEvent(server.getProfiles())); + + List profileList; + List serverProfiles = server.getProfiles(); + if (server.config.protectHandler instanceof ProfilesProtectHandler) + { + ProfilesProtectHandler protectHandler = (ProfilesProtectHandler) server.config.protectHandler; + profileList = new ArrayList<>(4); + for(ClientProfile profile : serverProfiles) + { + if(protectHandler.canGetProfile(profile, client)) + { + profileList.add(profile); + } + } + } + else + { + profileList = serverProfiles; + } + sendResult(new ProfilesRequestEvent(profileList)); } } 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 54111cac..5488d739 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 @@ -3,6 +3,7 @@ import io.netty.channel.ChannelHandlerContext; import pro.gravit.launcher.events.request.SetProfileRequestEvent; import pro.gravit.launcher.profiles.ClientProfile; +import pro.gravit.launchserver.auth.protect.interfaces.ProfilesProtectHandler; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.SimpleResponse; import pro.gravit.utils.HookException; @@ -19,10 +20,6 @@ public String getType() { @Override public void execute(ChannelHandlerContext ctx, Client client) { - if (!client.isAuth) { - sendError("Access denied"); - return; - } try { server.authHookManager.setProfileHook.hook(this, client); } catch (HookException e) { @@ -31,6 +28,11 @@ public void execute(ChannelHandlerContext ctx, Client client) { Collection profiles = server.getProfiles(); for (ClientProfile p : profiles) { if (p.getTitle().equals(this.client)) { + if (server.config.protectHandler instanceof ProfilesProtectHandler && + ((ProfilesProtectHandler) server.config.protectHandler).canChangeProfile(p, client)) { + sendError("Access denied"); + return; + } client.profile = p; sendResult(new SetProfileRequestEvent(p)); return; 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 c3b4846b..68a21a6d 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 @@ -4,6 +4,7 @@ import pro.gravit.launcher.events.request.UpdateRequestEvent; import pro.gravit.launcher.hasher.HashedDir; import pro.gravit.launcher.profiles.ClientProfile; +import pro.gravit.launchserver.auth.protect.interfaces.ProfilesProtectHandler; import pro.gravit.launchserver.config.LaunchServerConfig; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.SimpleResponse; @@ -20,7 +21,7 @@ public String getType() { @Override public void execute(ChannelHandlerContext ctx, Client client) { - if (!client.isAuth || client.type != AuthResponse.ConnectTypes.CLIENT || client.profile == null) { + if (server.config.protectHandler instanceof ProfilesProtectHandler && ((ProfilesProtectHandler) server.config.protectHandler).canGetUpdates(dirName, client)) { sendError("Access denied"); return; } From c7468eba1486438e0df247efdda575696fdad811 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sun, 22 Mar 2020 07:44:18 +0700 Subject: [PATCH 19/25] =?UTF-8?q?[FEATURE][EXPERIMENTAL]=20=D0=9D=D0=BE?= =?UTF-8?q?=D0=B2=D0=BE=D0=B5=20API=20=D0=B7=D0=B0=D0=BF=D1=83=D1=81=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BF=D1=80=D0=BE=D1=86=D0=B5=D1=81=D1=81=D0=B0=20?= =?UTF-8?q?=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 --- .../gravit/launchserver/defaults/proguard.cfg | 1 - .../pro/gravit/launcher/LauncherEngine.java | 1 + .../client/ClientLauncherEntryPoint.java | 261 ++++++++++++++++++ .../client/ClientLauncherProcess.java | 257 +++++++++++++++++ .../launcher/profiles/ClientProfile.java | 7 + 5 files changed, 526 insertions(+), 1 deletion(-) create mode 100644 Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java create mode 100644 Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.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 d3f335ad..23797bd8 100644 --- a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/proguard.cfg +++ b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/proguard.cfg @@ -9,7 +9,6 @@ -target 8 -forceprocessing --overloadaggressively -repackageclasses 'pro.gravit.launcher' -keepattributes SourceFile,LineNumberTable,*Annotation* -renamesourcefileattribute SourceFile diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index 2759dc37..aaaaff5b 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -39,6 +39,7 @@ public static X509Certificate[] getCertificates(Class clazz) { } public static final AtomicBoolean IS_CLIENT = new AtomicBoolean(false); + public static ClientLauncherProcess.ClientParams clientParams; public static void checkClass(Class clazz) throws SecurityException { LauncherTrustManager trustManager = Launcher.getConfig().trustManager; diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java new file mode 100644 index 00000000..12302ff0 --- /dev/null +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java @@ -0,0 +1,261 @@ +package pro.gravit.launcher.client; + +import pro.gravit.launcher.Launcher; +import pro.gravit.launcher.LauncherAgent; +import pro.gravit.launcher.LauncherConfig; +import pro.gravit.launcher.LauncherEngine; +import pro.gravit.launcher.api.AuthService; +import pro.gravit.launcher.api.ClientService; +import pro.gravit.launcher.client.events.ClientLaunchPhase; +import pro.gravit.launcher.client.events.ClientLauncherInitPhase; +import pro.gravit.launcher.client.events.ClientLauncherPostInitPhase; +import pro.gravit.launcher.guard.LauncherGuardManager; +import pro.gravit.launcher.hasher.FileNameMatcher; +import pro.gravit.launcher.hasher.HashedDir; +import pro.gravit.launcher.managers.ClientGsonManager; +import pro.gravit.launcher.modules.events.PreConfigPhase; +import pro.gravit.launcher.patches.FMLPatcher; +import pro.gravit.launcher.profiles.ClientProfile; +import pro.gravit.launcher.request.Request; +import pro.gravit.launcher.request.RequestException; +import pro.gravit.launcher.request.auth.RestoreSessionRequest; +import pro.gravit.launcher.serialize.HInput; +import pro.gravit.launcher.utils.DirWatcher; +import pro.gravit.utils.helper.*; + +import javax.swing.*; +import java.io.IOException; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; +import java.net.*; +import java.nio.file.FileVisitResult; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; +import java.security.spec.InvalidKeySpecException; +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class ClientLauncherEntryPoint { + private ClientLauncherProcess.ClientParams readParams(SocketAddress address) throws IOException { + try (Socket socket = IOHelper.newSocket()) + { + socket.connect(address); + try(HInput input = new HInput(socket.getInputStream())) + { + byte[] serialized = input.readByteArray(0); + ClientLauncherProcess.ClientParams params = Launcher.gsonManager.gson.fromJson(new String(serialized, IOHelper.UNICODE_CHARSET), ClientLauncherProcess.ClientParams.class); + params.clientHDir = new HashedDir(input); + params.assetHDir = new HashedDir(input); + params.javaHDir = new HashedDir(input); + return params; + } + } + } + private static ClientClassLoader classLoader; + public 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.initModules(LauncherEngine.modulesManager); //INIT + LauncherEngine.modulesManager.initModules(null); + initGson(LauncherEngine.modulesManager); + LauncherEngine.verifyNoAgent(); + LauncherEngine.modulesManager.invokeEvent(new PreConfigPhase()); + JVMHelper.verifySystemProperties(ClientLauncher.class, true); + EnvHelper.checkDangerousParams(); + JVMHelper.checkStackTrace(ClientLauncher.class); + LogHelper.printVersion("Client Launcher"); + engine.readKeys(); + LauncherGuardManager.initGuard(true); + LogHelper.debug("Reading ClientLauncher params"); + ClientLauncherProcess.ClientParams params = readParams(new InetSocketAddress("127.0.0.1", Launcher.getConfig().clientPort)); + ClientProfile profile = params.profile; + Launcher.profile = profile; + AuthService.profile = profile; + LauncherEngine.clientParams = params; + Request.setSession(params.session); + checkJVMBitsAndVersion(); + LauncherEngine.modulesManager.invokeEvent(new ClientLauncherInitPhase(null)); + + Path clientDir = Paths.get(params.clientDir); + Path assetDir = Paths.get(params.assetDir); + + // Verify ClientLauncher sign and classpath + LogHelper.debug("Verifying ClientLauncher sign and classpath"); + List classpath = new LinkedList<>(); + resolveClassPathStream(clientDir, params.profile.getClassPath()).map(IOHelper::toURL).collect(Collectors.toCollection(() -> classpath)); + + params.profile.pushOptionalClassPath((opt) -> { + resolveClassPathStream(clientDir, opt).map(IOHelper::toURL).collect(Collectors.toCollection(() -> classpath)); + }); + classLoader = new ClientClassLoader(classpath.toArray(new URL[0]), ClassLoader.getSystemClassLoader()); + Thread.currentThread().setContextClassLoader(classLoader); + classLoader.nativePath = clientDir.resolve("natives").toString(); + // Start client with WatchService monitoring + boolean digest = !profile.isUpdateFastCheck(); + LogHelper.debug("Restore sessions"); + RestoreSessionRequest request = new RestoreSessionRequest(Request.getSession()); + request.request(); + Request.service.reconnectCallback = () -> + { + LogHelper.debug("WebSocket connect closed. Try reconnect"); + try { + Request.service.open(); + LogHelper.debug("Connect to %s", Launcher.getConfig().address); + } catch (Exception e) { + LogHelper.error(e); + throw new RequestException(String.format("Connect error: %s", e.getMessage() != null ? e.getMessage() : "null")); + } + try { + RestoreSessionRequest request1 = new RestoreSessionRequest(Request.getSession()); + request1.request(); + } catch (Exception e) { + LogHelper.error(e); + } + }; + AuthService.username = params.playerProfile.username; + AuthService.uuid = params.playerProfile.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(); + LogHelper.debug("Starting JVM and client WatchService"); + FileNameMatcher assetMatcher = profile.getAssetUpdateMatcher(); + FileNameMatcher clientMatcher = profile.getClientUpdateMatcher(); + try (DirWatcher assetWatcher = new DirWatcher(assetDir, params.assetHDir, assetMatcher, digest); + DirWatcher clientWatcher = new DirWatcher(clientDir, params.clientHDir, clientMatcher, digest)) { + // Verify current state of all dirs + //verifyHDir(IOHelper.JVM_DIR, jvmHDir.object, null, digest); + //for (OptionalFile s : Launcher.profile.getOptional()) { + // if (params.updateOptional.contains(s)) s.mark = true; + // else hdir.removeR(s.file); + //} + Launcher.profile.pushOptionalFile(params.clientHDir, false); + // Start WatchService, and only then client + CommonHelper.newThread("Asset Directory Watcher", true, assetWatcher).start(); + CommonHelper.newThread("Client Directory Watcher", true, clientWatcher).start(); + verifyHDir(assetDir, params.assetHDir, assetMatcher, digest); + verifyHDir(clientDir, params.clientHDir, clientMatcher, digest); + launch(profile, params); + } + } + private static void initGson(ClientModuleManager moduleManager) { + Launcher.gsonManager = new ClientGsonManager(moduleManager); + Launcher.gsonManager.initGson(); + } + public static void verifyHDir(Path dir, HashedDir hdir, FileNameMatcher matcher, boolean digest) throws IOException { + //if (matcher != null) + // matcher = matcher.verifyOnly(); + + // Hash directory and compare (ignore update-only matcher entries, it will break offline-mode) + HashedDir currentHDir = new HashedDir(dir, matcher, true, digest); + HashedDir.Diff diff = hdir.diff(currentHDir, matcher); + if (!diff.isSame()) { + /*AtomicBoolean isFoundFile = new AtomicBoolean(false); + diff.extra.walk(File.separator, (e,k,v) -> { + if(v.getType().equals(HashedEntry.Type.FILE)) { LogHelper.error("Extra file %s", e); isFoundFile.set(true); } + else LogHelper.error("Extra %s", e); + }); + diff.mismatch.walk(File.separator, (e,k,v) -> { + if(v.getType().equals(HashedEntry.Type.FILE)) { LogHelper.error("Mismatch file %s", e); isFoundFile.set(true); } + else LogHelper.error("Mismatch %s", e); + }); + if(isFoundFile.get())*/ + throw new SecurityException(String.format("Forbidden modification: '%s'", IOHelper.getFileName(dir))); + } + } + 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); + LogHelper.error(error); + if (Launcher.getConfig().isWarningMissArchJava) + JOptionPane.showMessageDialog(null, error); + } + String jvmVersion = JVMHelper.RUNTIME_MXBEAN.getVmVersion(); + LogHelper.info(jvmVersion); + if (jvmVersion.startsWith("10.") || jvmVersion.startsWith("9.") || jvmVersion.startsWith("11.")) { + String error = String.format("У Вас установлена Java %s. Для правильной работы необходима Java 8", JVMHelper.RUNTIME_MXBEAN.getVmVersion()); + LogHelper.error(error); + if (Launcher.getConfig().isWarningMissArchJava) + JOptionPane.showMessageDialog(null, error); + } + } + private static LinkedList resolveClassPathList(Path clientDir, String... classPath) throws IOException { + return resolveClassPathStream(clientDir, classPath).collect(Collectors.toCollection(LinkedList::new)); + } + + 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.replace(IOHelper.CROSS_SEPARATOR, IOHelper.PLATFORM_SEPARATOR))); + if (IOHelper.isDir(path)) { // Recursive walking and adding + IOHelper.walk(path, new ClassPathFileVisitor(builder), false); + continue; + } + builder.accept(path); + } + return builder.build(); + } + private static final class ClassPathFileVisitor extends SimpleFileVisitor { + private final Stream.Builder result; + + private ClassPathFileVisitor(Stream.Builder result) { + this.result = result; + } + + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + if (IOHelper.hasExtension(file, "jar") || IOHelper.hasExtension(file, "zip")) + result.accept(file); + return super.visitFile(file, attrs); + } + } + private static void launch(ClientProfile profile, ClientLauncherProcess.ClientParams params) throws Throwable { + // Add client args + Collection args = new LinkedList<>(); + if (profile.getVersion().compareTo(ClientProfile.Version.MC164) >= 0) + params.addClientArgs(args); + else { + params.addClientLegacyArgs(args); + System.setProperty("minecraft.applet.TargetDirectory", params.clientDir); + } + Collections.addAll(args, profile.getClientArgs()); + 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))) { + copy.set(i + 1, "censored"); + } + } + 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()); + } + FMLPatcher.apply(); + MethodHandle mainMethod = MethodHandles.publicLookup().findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class)).asFixedArity(); + Launcher.LAUNCHED.set(true); + JVMHelper.fullGC(); + // Invoke main method + try { + mainMethod.invokeWithArguments((Object) args.toArray(new String[0])); + LogHelper.debug("Main exit successful"); + } catch (Throwable e) { + LogHelper.error(e); + throw e; + } finally { + LauncherEngine.exitLauncher(0); + } + + } +} diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java new file mode 100644 index 00000000..ce35f58a --- /dev/null +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java @@ -0,0 +1,257 @@ +package pro.gravit.launcher.client; + +import pro.gravit.launcher.Launcher; +import pro.gravit.launcher.guard.LauncherGuardManager; +import pro.gravit.launcher.hasher.HashedDir; +import pro.gravit.launcher.profiles.ClientProfile; +import pro.gravit.launcher.profiles.PlayerProfile; +import pro.gravit.launcher.request.Request; +import pro.gravit.launcher.serialize.HOutput; +import pro.gravit.utils.Version; +import pro.gravit.utils.helper.EnvHelper; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.JVMHelper; +import pro.gravit.utils.helper.SecurityHelper; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.net.InetSocketAddress; +import java.net.ServerSocket; +import java.net.Socket; +import java.net.SocketAddress; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.*; + +public class ClientLauncherProcess { + private transient Process process; + private final transient Boolean[] waitWriteParams = new Boolean[1]; + public final Path executeFile; + public final Path workDir; + public final Path javaDir; + public final ClientParams params = new ClientParams(); + public final List jvmArgs = new LinkedList<>(); + public final List systemClientArgs = new LinkedList<>(); + public final List systemClassPath = new LinkedList<>(); + public final Map systemEnv = new HashMap<>(); + public final String mainClass; + public boolean isStarted; + + public ClientLauncherProcess(Path executeFile, Path workDir, Path javaDir, String mainClass) { + this.executeFile = executeFile; + this.workDir = workDir; + this.javaDir = javaDir; + this.mainClass = mainClass; + } + + public ClientLauncherProcess(Path clientDir, Path assetDir, + ClientProfile profile, PlayerProfile playerProfile, String accessToken, + HashedDir clientHDir, HashedDir assetHDir, HashedDir jvmHDir) { + this(clientDir, assetDir, clientDir.resolve("resourcepacks"), profile, playerProfile, accessToken, clientHDir, assetHDir, jvmHDir); + } + + public ClientLauncherProcess(Path clientDir, Path assetDir, Path resourcePackDir, + ClientProfile profile, PlayerProfile playerProfile, String accessToken, + HashedDir clientHDir, HashedDir assetHDir, HashedDir jvmHDir) { + this.executeFile = LauncherGuardManager.getGuardJavaBinPath(); + this.workDir = clientDir.toAbsolutePath(); + this.javaDir = Paths.get(System.getProperty("java.home")); + this.mainClass = ClientLauncherEntryPoint.class.getName(); + this.params.clientDir = this.workDir.toString(); + this.params.resourcePackDir = resourcePackDir.toAbsolutePath().toString(); + this.params.assetDir = assetDir.toAbsolutePath().toString(); + this.params.profile = profile; + this.params.playerProfile = playerProfile; + this.params.accessToken = accessToken; + this.params.assetHDir = assetHDir; + this.params.clientHDir = clientHDir; + this.params.javaHDir = jvmHDir; + applyClientProfile(); + } + private void applyClientProfile() + { + this.systemClassPath.add(IOHelper.getCodeSource(ClientLauncherEntryPoint.class).toAbsolutePath().toString()); + Collections.addAll(this.jvmArgs, this.params.profile.getJvmArgs()); + this.systemEnv.put("JAVA_HOME", javaDir.toString()); + Collections.addAll(this.systemClassPath, this.params.profile.getAlternativeClassPath()); + if (params.ram > 0) { + this.jvmArgs.add("-Xms" + params.ram + 'M'); + this.jvmArgs.add("-Xmx" + params.ram + 'M'); + } + this.params.session = Request.getSession(); + } + + + public static class ClientParams + { + public String assetDir; + + public String clientDir; + + public String resourcePackDir; + + // Client params + + public PlayerProfile playerProfile; + + public ClientProfile profile; + + public String accessToken; + + //==Minecraft params== + + public boolean autoEnter; + + public boolean fullScreen; + + public int ram; + + public int width; + + public int height; + + //======== + + public long session; + + public transient HashedDir assetHDir; + + public transient HashedDir clientHDir; + + public transient HashedDir javaHDir; + + public void addClientArgs(Collection args) + { + if (profile.getVersion().compareTo(ClientProfile.Version.MC164) >= 0) + addModernClientArgs(args); + else + addClientLegacyArgs(args); + } + + + public void addClientLegacyArgs(Collection args) { + args.add(playerProfile.username); + args.add(accessToken); + + // Add args for tweaker + Collections.addAll(args, "--version", profile.getVersion().name); + Collections.addAll(args, "--gameDir", clientDir.toString()); + Collections.addAll(args, "--assetsDir", assetDir.toString()); + } + + private void addModernClientArgs(Collection args) { + + // Add version-dependent args + ClientProfile.Version version = profile.getVersion(); + Collections.addAll(args, "--username", playerProfile.username); + if (version.compareTo(ClientProfile.Version.MC172) >= 0) { + Collections.addAll(args, "--uuid", Launcher.toHash(playerProfile.uuid)); + Collections.addAll(args, "--accessToken", accessToken); + + // Add 1.7.10+ args (user properties, asset index) + if (version.compareTo(ClientProfile.Version.MC1710) >= 0) { + // Add user properties + Collections.addAll(args, "--userType", "mojang"); + ClientLauncher.ClientUserProperties properties = new ClientLauncher.ClientUserProperties(); + if (playerProfile.skin != null) { + properties.skinURL = new String[]{playerProfile.skin.url}; + properties.skinDigest = new String[]{SecurityHelper.toHex(playerProfile.skin.digest)}; + } + if (playerProfile.cloak != null) { + properties.cloakURL = new String[]{playerProfile.cloak.url}; + properties.cloakDigest = new String[]{SecurityHelper.toHex(playerProfile.cloak.digest)}; + } + Collections.addAll(args, "--userProperties", Launcher.gsonManager.gson.toJson(properties)); + + // Add asset index + Collections.addAll(args, "--assetIndex", profile.getAssetIndex()); + } + } else + Collections.addAll(args, "--session", accessToken); + + // Add version and dirs args + Collections.addAll(args, "--version", profile.getVersion().name); + Collections.addAll(args, "--gameDir", clientDir); + Collections.addAll(args, "--assetsDir", assetDir); + Collections.addAll(args, "--resourcePackDir", resourcePackDir); + if (version.compareTo(ClientProfile.Version.MC194) >= 0) + Collections.addAll(args, "--versionType", "Launcher v" + Version.getVersion().getVersionString()); + + // Add server args + if (autoEnter) { + Collections.addAll(args, "--server", profile.getServerAddress()); + Collections.addAll(args, "--port", Integer.toString(profile.getServerPort())); + } + profile.pushOptionalClientArgs(args); + // Add window size args + if (fullScreen) + Collections.addAll(args, "--fullscreen", Boolean.toString(true)); + if (width > 0 && height > 0) { + Collections.addAll(args, "--width", Integer.toString(width)); + Collections.addAll(args, "--height", Integer.toString(height)); + } + } + } + public void start(boolean pipeOutput) throws IOException, InterruptedException { + if(isStarted) throw new IllegalStateException("Process already started"); + List processArgs = new LinkedList<>(); + processArgs.add(executeFile.toString()); + processArgs.addAll(jvmArgs); + processArgs.add("-cp"); + //ADD CLASSPATH + processArgs.add(String.join(getPathSeparator(), systemClassPath)); + processArgs.addAll(systemClientArgs); + synchronized (waitWriteParams) + { + if(!waitWriteParams[0]) + { + waitWriteParams.wait(1000); + } + } + ProcessBuilder processBuilder = new ProcessBuilder(processArgs); + EnvHelper.addEnv(processBuilder); + processBuilder.environment().putAll(systemEnv); + processBuilder.directory(workDir.toFile()); + processBuilder.inheritIO(); + if (pipeOutput) { + processBuilder.redirectErrorStream(true); + processBuilder.redirectOutput(ProcessBuilder.Redirect.PIPE); + } + process = processBuilder.start(); + isStarted = true; + } + public void runWriteParams(SocketAddress address) throws IOException + { + try(ServerSocket serverSocket = new ServerSocket()) + { + serverSocket.bind(address); + synchronized (waitWriteParams) + { + waitWriteParams[0] = true; + waitWriteParams.notifyAll(); + } + Socket socket = serverSocket.accept(); + try(HOutput output = new HOutput(socket.getOutputStream())) + { + byte[] serializedMainParams = Launcher.gsonManager.gson.toJson(params).getBytes(IOHelper.UNICODE_CHARSET); + output.writeByteArray(serializedMainParams, 0); + params.clientHDir.write(output); + params.assetHDir.write(output); + params.javaHDir.write(output); + } + } + } + + public Process getProcess() { + return process; + } + + public static String getPathSeparator() + { + if(JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) + return ";"; + else + return ":"; + } +} 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 b954fab0..8f1ce9a3 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java @@ -128,6 +128,8 @@ public enum ClassLoaderConfig @LauncherNetworkAPI private final List classPath = new ArrayList<>(); @LauncherNetworkAPI + private final List altClassPath = new ArrayList<>(); + @LauncherNetworkAPI private final List clientArgs = new ArrayList<>(); @LauncherNetworkAPI public SecurityManagerConfig securityManagerConfig = SecurityManagerConfig.CLIENT; @@ -154,6 +156,10 @@ public String[] getClassPath() { return classPath.toArray(new String[0]); } + public String[] getAlternativeClassPath() { + return classPath.toArray(new String[0]); + } + public String[] getClientArgs() { return clientArgs.toArray(new String[0]); @@ -196,6 +202,7 @@ public String[] getJvmArgs() { } + public String getMainClass() { return mainClass; } From fbfb074e0a10b98449ade85031d56d8face0f284 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sun, 22 Mar 2020 08:30:29 +0700 Subject: [PATCH 20/25] =?UTF-8?q?[FIX]=20=D0=9A=D1=80=D0=B8=D1=82=D0=B8?= =?UTF-8?q?=D1=87=D0=B5=D1=81=D0=BA=D0=B8=D0=B5=20=D1=84=D0=B8=D0=BA=D1=81?= =?UTF-8?q?=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../socket/response/auth/SetProfileResponse.java | 2 +- .../socket/response/update/UpdateResponse.java | 2 +- .../launcher/client/ClientLauncherEntryPoint.java | 8 ++++---- .../launcher/client/ClientLauncherProcess.java | 14 +++++++------- .../gravit/launcher/profiles/ClientProfile.java | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) 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 5488d739..51f4e131 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 @@ -29,7 +29,7 @@ public void execute(ChannelHandlerContext ctx, Client client) { for (ClientProfile p : profiles) { if (p.getTitle().equals(this.client)) { if (server.config.protectHandler instanceof ProfilesProtectHandler && - ((ProfilesProtectHandler) server.config.protectHandler).canChangeProfile(p, client)) { + !((ProfilesProtectHandler) server.config.protectHandler).canChangeProfile(p, client)) { sendError("Access denied"); return; } 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 68a21a6d..10e7a43d 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 @@ -21,7 +21,7 @@ public String getType() { @Override public void execute(ChannelHandlerContext ctx, Client client) { - if (server.config.protectHandler instanceof ProfilesProtectHandler && ((ProfilesProtectHandler) server.config.protectHandler).canGetUpdates(dirName, client)) { + if (server.config.protectHandler instanceof ProfilesProtectHandler && !((ProfilesProtectHandler) server.config.protectHandler).canGetUpdates(dirName, client)) { sendError("Access denied"); return; } diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java index 12302ff0..d9d6e0ee 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java @@ -40,7 +40,7 @@ import java.util.stream.Stream; public class ClientLauncherEntryPoint { - private ClientLauncherProcess.ClientParams readParams(SocketAddress address) throws IOException { + private static ClientLauncherProcess.ClientParams readParams(SocketAddress address) throws IOException { try (Socket socket = IOHelper.newSocket()) { socket.connect(address); @@ -56,7 +56,7 @@ private ClientLauncherProcess.ClientParams readParams(SocketAddress address) thr } } private static ClientClassLoader classLoader; - public void main(String[] args) throws Throwable { + public static void main(String[] args) throws Throwable { LauncherEngine.IS_CLIENT.set(true); LauncherEngine engine = LauncherEngine.clientInstance(); LauncherEngine.checkClass(LauncherEngine.class); @@ -68,9 +68,9 @@ public void main(String[] args) throws Throwable { initGson(LauncherEngine.modulesManager); LauncherEngine.verifyNoAgent(); LauncherEngine.modulesManager.invokeEvent(new PreConfigPhase()); - JVMHelper.verifySystemProperties(ClientLauncher.class, true); + JVMHelper.verifySystemProperties(ClientLauncherEntryPoint.class, true); EnvHelper.checkDangerousParams(); - JVMHelper.checkStackTrace(ClientLauncher.class); + JVMHelper.checkStackTrace(ClientLauncherEntryPoint.class); LogHelper.printVersion("Client Launcher"); engine.readKeys(); LauncherGuardManager.initGuard(true); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java index ce35f58a..5c3bc532 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java @@ -8,10 +8,7 @@ import pro.gravit.launcher.request.Request; import pro.gravit.launcher.serialize.HOutput; import pro.gravit.utils.Version; -import pro.gravit.utils.helper.EnvHelper; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.JVMHelper; -import pro.gravit.utils.helper.SecurityHelper; +import pro.gravit.utils.helper.*; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -26,7 +23,7 @@ public class ClientLauncherProcess { private transient Process process; - private final transient Boolean[] waitWriteParams = new Boolean[1]; + private final transient Boolean[] waitWriteParams = new Boolean[] {false}; public final Path executeFile; public final Path workDir; public final Path javaDir; @@ -136,8 +133,8 @@ public void addClientLegacyArgs(Collection args) { // Add args for tweaker Collections.addAll(args, "--version", profile.getVersion().name); - Collections.addAll(args, "--gameDir", clientDir.toString()); - Collections.addAll(args, "--assetsDir", assetDir.toString()); + Collections.addAll(args, "--gameDir", clientDir); + Collections.addAll(args, "--assetsDir", assetDir); } private void addModernClientArgs(Collection args) { @@ -201,6 +198,7 @@ public void start(boolean pipeOutput) throws IOException, InterruptedException { processArgs.add("-cp"); //ADD CLASSPATH processArgs.add(String.join(getPathSeparator(), systemClassPath)); + processArgs.add(mainClass); processArgs.addAll(systemClientArgs); synchronized (waitWriteParams) { @@ -209,6 +207,8 @@ public void start(boolean pipeOutput) throws IOException, InterruptedException { waitWriteParams.wait(1000); } } + if(LogHelper.isDebugEnabled()) + LogHelper.debug("Commandline: %s", Arrays.toString(processArgs.toArray())); ProcessBuilder processBuilder = new ProcessBuilder(processArgs); EnvHelper.addEnv(processBuilder); processBuilder.environment().putAll(systemEnv); 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 8f1ce9a3..94a1d0d1 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java @@ -157,7 +157,7 @@ public String[] getClassPath() { } public String[] getAlternativeClassPath() { - return classPath.toArray(new String[0]); + return altClassPath.toArray(new String[0]); } From 00478527e5598930c265ca19531e24311121b0e7 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sun, 22 Mar 2020 08:40:14 +0700 Subject: [PATCH 21/25] =?UTF-8?q?[FIX]=20=D0=A7=D0=B0=D1=81=D1=82=D0=B8?= =?UTF-8?q?=D1=87=D0=BD=D0=BE=D0=B5=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D1=83=D0=BF=D0=BE=D0=BC=D0=B8=D0=BD=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B9=20ClientLauncher?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/pro/gravit/launcher/ClientLauncherWrapper.java | 2 +- .../src/main/java/pro/gravit/launcher/LauncherEngine.java | 2 +- .../pro/gravit/launcher/client/ClientLauncherEntryPoint.java | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java b/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java index 1ea56772..21bdbc27 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java +++ b/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java @@ -53,7 +53,7 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep Path javaBin = IOHelper.resolveJavaBin(Paths.get(System.getProperty("java.home"))); List args = new LinkedList<>(); args.add(javaBin.toString()); - String pathLauncher = IOHelper.getCodeSource(ClientLauncher.class).toString(); + String pathLauncher = IOHelper.getCodeSource(LauncherEngine.class).toString(); args.add(JVMHelper.jvmProperty(LogHelper.DEBUG_PROPERTY, Boolean.toString(LogHelper.isDebugEnabled()))); args.add(JVMHelper.jvmProperty(LogHelper.STACKTRACE_PROPERTY, Boolean.toString(LogHelper.isStacktraceEnabled()))); args.add(JVMHelper.jvmProperty(LogHelper.DEV_PROPERTY, Boolean.toString(LogHelper.isDevEnabled()))); diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index aaaaff5b..e788bf37 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -76,7 +76,7 @@ public static void main(String... args) throws Throwable { LogHelper.printLicense("Launcher"); LauncherEngine.checkClass(LauncherEngine.class); LauncherEngine.checkClass(LauncherAgent.class); - LauncherEngine.checkClass(ClientLauncher.class); + LauncherEngine.checkClass(ClientLauncherEntryPoint.class); LauncherEngine.modulesManager = new ClientModuleManager(); LauncherConfig.initModules(LauncherEngine.modulesManager); LauncherEngine.modulesManager.initModules(null); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java index d9d6e0ee..45d0ce95 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java @@ -61,7 +61,7 @@ public static void main(String[] args) throws Throwable { LauncherEngine engine = LauncherEngine.clientInstance(); LauncherEngine.checkClass(LauncherEngine.class); LauncherEngine.checkClass(LauncherAgent.class); - LauncherEngine.checkClass(ClientLauncher.class); + LauncherEngine.checkClass(ClientLauncherEntryPoint.class); LauncherEngine.modulesManager = new ClientModuleManager(); LauncherConfig.initModules(LauncherEngine.modulesManager); //INIT LauncherEngine.modulesManager.initModules(null); @@ -124,7 +124,7 @@ public static void main(String[] args) throws Throwable { AuthService.uuid = params.playerProfile.uuid; ClientService.classLoader = classLoader; ClientService.nativePath = classLoader.nativePath; - classLoader.addURL(IOHelper.getCodeSource(ClientLauncher.class).toUri().toURL()); + classLoader.addURL(IOHelper.getCodeSource(ClientLauncherEntryPoint.class).toUri().toURL()); //classForName(classLoader, "com.google.common.collect.ForwardingMultimap"); ClientService.baseURLs = classLoader.getURLs(); LogHelper.debug("Starting JVM and client WatchService"); From 69bd5f3c661356af19d92013d7a59d29ed2ffbdd Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 23 Mar 2020 04:11:51 +0700 Subject: [PATCH 22/25] [FIX] ClassCastException --- .../socket/response/secure/GetSecureLevelInfoResponse.java | 1 + 1 file changed, 1 insertion(+) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/GetSecureLevelInfoResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/GetSecureLevelInfoResponse.java index a99d8801..294c4f00 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/GetSecureLevelInfoResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/GetSecureLevelInfoResponse.java @@ -19,6 +19,7 @@ public void execute(ChannelHandlerContext ctx, Client client) throws Exception { GetSecureLevelInfoRequestEvent response = new GetSecureLevelInfoRequestEvent(null); response.enabled = false; sendResult(response); + return; } SecureProtectHandler secureProtectHandler = (SecureProtectHandler) server.config.protectHandler; if(!secureProtectHandler.allowGetSecureLevelInfo(client)) From 98b096dff56ac447341ef01f97a8e7fc101b03f8 Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 25 Mar 2020 13:33:53 +0700 Subject: [PATCH 23/25] [FIX] More fixes --- .../client/ClientLauncherEntryPoint.java | 1 + .../client/ClientLauncherProcess.java | 1 + .../launcher/profiles/ClientProfile.java | 22 ++----------- .../profiles/optional/OptionalFile.java | 33 ++++++++++++++++--- .../profiles/optional/OptionalTrigger.java | 2 +- 5 files changed, 33 insertions(+), 26 deletions(-) diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java index 45d0ce95..f08b1fc5 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java @@ -228,6 +228,7 @@ private static void launch(ClientProfile profile, ClientLauncherProcess.ClientPa System.setProperty("minecraft.applet.TargetDirectory", params.clientDir); } Collections.addAll(args, profile.getClientArgs()); + profile.pushOptionalClientArgs(args); List copy = new ArrayList<>(args); for (int i = 0, l = copy.size(); i < l; i++) { String s = copy.get(i); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java index 5c3bc532..1a7bb5ba 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java @@ -70,6 +70,7 @@ private void applyClientProfile() { this.systemClassPath.add(IOHelper.getCodeSource(ClientLauncherEntryPoint.class).toAbsolutePath().toString()); Collections.addAll(this.jvmArgs, this.params.profile.getJvmArgs()); + this.params.profile.pushOptionalJvmArgs(this.jvmArgs); this.systemEnv.put("JAVA_HOME", javaDir.toString()); Collections.addAll(this.systemClassPath, this.params.profile.getAlternativeClassPath()); if (params.ram > 0) { 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 94a1d0d1..c24186d0 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java @@ -248,20 +248,11 @@ public Collection getShared() { } - public void markOptional(String name, OptionalType type) { - OptionalFile file = getOptionalFile(name, type); - if (file == null) { - throw new SecurityException(String.format("Optional %s not found in optionalList", name)); - } - markOptional(file); - } - - public void markOptional(OptionalFile file) { if (file.mark) return; file.mark = true; - file.notifyObservers(true); + file.watchEvent(true); if (file.dependencies != null) { for (OptionalFile dep : file.dependencies) { if (dep.dependenciesCount == null) dep.dependenciesCount = new HashSet<>(); @@ -277,19 +268,10 @@ public void markOptional(OptionalFile file) { } - public void unmarkOptional(String name, OptionalType type) { - OptionalFile file = getOptionalFile(name, type); - if (file == null) { - throw new SecurityException(String.format("Optional %s not found in optionalList", name)); - } - unmarkOptional(file); - } - - public void unmarkOptional(OptionalFile file) { if (!file.mark) return; file.mark = false; - file.notifyObservers(false); + file.watchEvent(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 668ec186..0f73ec9f 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 @@ -6,11 +6,11 @@ import pro.gravit.utils.helper.LogHelper; import java.io.IOException; -import java.util.Objects; -import java.util.Observable; -import java.util.Set; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.BiConsumer; -public class OptionalFile extends Observable { +public class OptionalFile { @LauncherNetworkAPI public String[] list; @LauncherNetworkAPI @@ -18,7 +18,7 @@ public class OptionalFile extends Observable { @LauncherNetworkAPI public boolean mark; @LauncherNetworkAPI - public final boolean visible = true; + public boolean visible = true; @LauncherNetworkAPI public String name; @LauncherNetworkAPI @@ -125,4 +125,27 @@ public static OptionalType readType(HInput input) throws IOException { } return type; } + private volatile transient Collection> watchList = null; + public void registerWatcher(BiConsumer watcher) + { + if(watchList == null) watchList = ConcurrentHashMap.newKeySet(); + watchList.add(watcher); + } + public void removeWatcher(BiConsumer watcher) + { + if(watchList == null) return; + watchList.remove(watcher); + } + public void clearAllWatchers() + { + if(watchList == null) return; + watchList.clear(); + } + public void watchEvent(boolean isMark) + { + if(watchList == null) return; + watchList.forEach((e) -> { + e.accept(this, isMark); + }); + } } 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 index 0603aef4..8e94ce09 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalTrigger.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalTrigger.java @@ -11,7 +11,7 @@ public enum TriggerType public boolean need = true; public long value; public long compareMode = 0; - boolean isTriggered() + public boolean isTriggered() { long test; switch (type) From 924f3dd95899108b9807bb28bf38cee199c7c1b6 Mon Sep 17 00:00:00 2001 From: Gravit Date: Fri, 27 Mar 2020 08:47:40 +0700 Subject: [PATCH 24/25] =?UTF-8?q?[FIX]=20=D0=98=D0=BC=D0=B5=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=D0=BE=D0=B2=20LauncherModu?= =?UTF-8?q?leLoader?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gravit/launcher/managers/SimpleModulesConfigManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 8c185f16..4e954886 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/managers/SimpleModulesConfigManager.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/managers/SimpleModulesConfigManager.java @@ -22,7 +22,7 @@ public Path getModuleConfig(String moduleName) { @Override public Path getModuleConfig(String moduleName, String configName) { - return getModuleConfigDir(moduleName).resolve(moduleName.concat(configName.concat(".json"))); + return getModuleConfigDir(moduleName).resolve(configName.concat(".json")); } public Path getModuleConfigDir(String moduleName) { From 64bc2eb3c8513e55f8ff0db954c4a70274920433 Mon Sep 17 00:00:00 2001 From: Gravit Date: Fri, 27 Mar 2020 10:12:22 +0700 Subject: [PATCH 25/25] [ANY] 5.1.2 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 f55f4bef..d0323266 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 = 2; 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 d61a815a..b97a4969 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ id 'org.openjfx.javafxplugin' version '0.0.7' apply false } group = 'pro.gravit.launcher' -version = '5.1.2-SNAPSHOT' +version = '5.1.2' apply from: 'props.gradle'