diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java index c9dc6487..27e06a7b 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java @@ -124,9 +124,8 @@ protected void initProps() { server.runtime.clientCheckSecret.concat(".").concat(launcherSalt)); properties.put("runtimeconfig.secureCheckHash", Base64.getEncoder().encodeToString(launcherSecureHash)); properties.put("runtimeconfig.secureCheckSalt", launcherSalt); - //LogHelper.debug("[checkSecure] %s: %s", launcherSalt, Arrays.toString(launcherSecureHash)); - if (server.runtime.oemUnlockKey == null) server.runtime.oemUnlockKey = SecurityHelper.randomStringToken(); - properties.put("runtimeconfig.oemUnlockKey", server.runtime.oemUnlockKey); + if (server.runtime.unlockSecret == null) server.runtime.unlockSecret = SecurityHelper.randomStringToken(); + properties.put("runtimeconfig.unlockSecret", server.runtime.unlockSecret); } 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 1b40186f..33fb67a1 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java @@ -45,7 +45,7 @@ public final class LaunchServerConfig { public static LaunchServerConfig getDefault(LaunchServer.LaunchServerEnv env) { LaunchServerConfig newConfig = new LaunchServerConfig(); - newConfig.mirrors = new String[]{"https://mirror.gravit.pro/5.2.x/", "https://gravit-launcher-mirror.storage.googleapis.com/"}; + newConfig.mirrors = new String[]{"https://mirror.gravit.pro/5.3.x/", "https://gravit-launcher-mirror.storage.googleapis.com/"}; newConfig.launch4j = new LaunchServerConfig.ExeConf(); newConfig.launch4j.enabled = false; newConfig.launch4j.copyright = "© GravitLauncher Team"; @@ -168,9 +168,9 @@ public void verify() { boolean updateMirror = Boolean.getBoolean("launchserver.config.disableUpdateMirror"); if(!updateMirror) { for(int i=0;i < mirrors.length;++i) { - if("https://mirror.gravit.pro/".equals(mirrors[i])) { - logger.warn("Replace mirror 'https://mirror.gravit.pro/' to 'https://mirror.gravit.pro/5.2.x/'. If you really need to use original url, use '-Dlaunchserver.config.disableUpdateMirror=true'"); - mirrors[i] = "https://mirror.gravit.pro/5.2.x/"; + if("https://mirror.gravit.pro/5.2.x/".equals(mirrors[i])) { + logger.warn("Replace mirror 'https://mirror.gravit.pro/5.2.x/' to 'https://mirror.gravit.pro/5.3.x/'. If you really need to use original url, use '-Dlaunchserver.config.disableUpdateMirror=true'"); + mirrors[i] = "https://mirror.gravit.pro/5.3.x/"; } } } @@ -278,8 +278,6 @@ public static class LauncherConf { public static class NettyConfig { public boolean fileServerEnabled; - @Deprecated - public boolean sendExceptionEnabled; public boolean ipForwarding; public boolean disableWebApiInterface; public boolean showHiddenFiles; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerRuntimeConfig.java b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerRuntimeConfig.java index b8458c7c..0f9c9c53 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerRuntimeConfig.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerRuntimeConfig.java @@ -8,7 +8,7 @@ public class LaunchServerRuntimeConfig { private transient final Logger logger = LogManager.getLogger(); public String passwordEncryptKey; public String runtimeEncryptKey; - public String oemUnlockKey; + public String unlockSecret; public String registerApiKey; public String clientCheckSecret; diff --git a/Launcher/build.gradle b/Launcher/build.gradle index e8ca4f7f..53223965 100644 --- a/Launcher/build.gradle +++ b/Launcher/build.gradle @@ -50,6 +50,7 @@ task javadocJar(type: Jar) { dependencies { pack project(':LauncherAPI') bundle group: 'com.github.oshi', name: 'oshi-core', version: rootProject['verOshiCore'] + bundle "pro.gravit.utils.enfs:enfs:1.0.0-SNAPSHOT" pack group: 'io.netty', name: 'netty-codec-http', version: rootProject['verNetty'] } diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index 50e8120e..1921c8a2 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -84,11 +84,14 @@ public static void checkClass(Class clazz) throws SecurityException { } } - public static void exitLauncher(int code) { + public static void beforeExit(int code) { try { modulesManager.invokeEvent(new ClientExitPhase(code)); } catch (Throwable ignored) { } + } + + public static void forceExit(int code) { try { System.exit(code); } catch (Throwable e) //Forge Security Manager? @@ -97,6 +100,11 @@ public static void exitLauncher(int code) { } } + public static void exitLauncher(int code) { + beforeExit(code); + forceExit(code); + } + public static void main(String... args) throws Throwable { JVMHelper.checkStackTrace(LauncherEngine.class); JVMHelper.verifySystemProperties(Launcher.class, true); diff --git a/Launcher/src/main/java/pro/gravit/launcher/debug/DebugMain.java b/Launcher/src/main/java/pro/gravit/launcher/debug/DebugMain.java index 27b1348b..6c03bd9e 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/debug/DebugMain.java +++ b/Launcher/src/main/java/pro/gravit/launcher/debug/DebugMain.java @@ -26,7 +26,7 @@ public class DebugMain { public static final AtomicBoolean IS_DEBUG = new AtomicBoolean(false); public static String webSocketURL = System.getProperty("launcherdebug.websocket", "ws://localhost:9274/api"); public static String projectName = System.getProperty("launcherdebug.projectname", "Minecraft"); - public static String unlockKey = System.getProperty("launcherdebug.unlockkey", "0000"); + public static String unlockSecret = System.getProperty("launcherdebug.unlocksecret", ""); public static boolean offlineMode = Boolean.getBoolean("launcherdebug.offlinemode"); public static String[] moduleClasses = System.getProperty("launcherdebug.modules", "").split(","); public static String[] moduleFiles = System.getProperty("launcherdebug.modulefiles", "").split(","); @@ -39,7 +39,7 @@ public static void main(String[] args) throws Throwable { LogHelper.info("Launcher start in DEBUG mode (Only for developers)"); LogHelper.debug("Initialization LauncherConfig"); LauncherConfig config = new LauncherConfig(webSocketURL, new HashMap<>(), projectName, environment, new DebugLauncherTrustManager(DebugLauncherTrustManager.TrustDebugMode.TRUST_ALL)); - config.oemUnlockKey = unlockKey; + config.unlockSecret = unlockSecret; Launcher.setConfig(config); Launcher.applyLauncherEnv(environment); LauncherEngine.modulesManager = new ClientModuleManager(); diff --git a/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java b/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java index 641be710..bffca63e 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java +++ b/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java @@ -49,7 +49,7 @@ public static void registerCommands() { } public static boolean checkUnlockKey(String key) { - return key.equals(Launcher.getConfig().oemUnlockKey); + return key.equals(Launcher.getConfig().unlockSecret); } public static boolean unlock() { diff --git a/Launcher/src/main/java/pro/gravit/launcher/utils/LauncherUpdater.java b/Launcher/src/main/java/pro/gravit/launcher/utils/LauncherUpdater.java new file mode 100644 index 00000000..4ec30e05 --- /dev/null +++ b/Launcher/src/main/java/pro/gravit/launcher/utils/LauncherUpdater.java @@ -0,0 +1,65 @@ +package pro.gravit.launcher.utils; + +import pro.gravit.launcher.Launcher; +import pro.gravit.launcher.LauncherEngine; +import pro.gravit.launcher.events.request.LauncherRequestEvent; +import pro.gravit.launcher.request.update.LauncherRequest; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.LogHelper; +import pro.gravit.utils.helper.SecurityHelper; + +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardOpenOption; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class LauncherUpdater { + public static void nothing() { + + } + private static Path getLauncherPath() { + Path pathToCore = IOHelper.getCodeSource(IOHelper.class); + Path pathToApi = IOHelper.getCodeSource(LauncherRequest.class); + Path pathToSelf = IOHelper.getCodeSource(LauncherUpdater.class); + if(pathToCore.equals(pathToApi) && pathToCore.equals(pathToSelf)) { + return pathToCore; + } else { + throw new SecurityException("Found split-jar launcher"); + } + } + + public static Path prepareUpdate(URL url) throws Exception { + Path pathToLauncher = getLauncherPath(); + Path tempFile = Files.createTempFile("launcher-update-", ".jar"); + URLConnection connection = url.openConnection(); + try (InputStream in = connection.getInputStream()) { + IOHelper.transfer(in, tempFile); + } + if (Arrays.equals(SecurityHelper.digest(SecurityHelper.DigestAlgorithm.MD5, tempFile), + SecurityHelper.digest(SecurityHelper.DigestAlgorithm.MD5, pathToLauncher))) + throw new IOException("Invalid update (launcher needs update, but link has old launcher), check LaunchServer config..."); + return tempFile; + } + + public static void restart() { + List args = new ArrayList<>(8); + args.add(IOHelper.resolveJavaBin(null).toString()); + args.add("-jar"); + args.add(IOHelper.getCodeSource(LauncherUpdater.class).toString()); + ProcessBuilder builder = new ProcessBuilder(args.toArray(new String[0])); + builder.inheritIO(); + try { + builder.start(); + } catch (IOException e) { + LogHelper.error(e); + } + LauncherEngine.forceExit(0); + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java b/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java index f613b4eb..290d64e3 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java @@ -46,8 +46,8 @@ public final class LauncherConfig extends StreamObject { public final String address; @LauncherInject("runtimeconfig.secretKeyClient") public String secretKeyClient; - @LauncherInject("runtimeconfig.oemUnlockKey") - public String oemUnlockKey; + @LauncherInject("runtimeconfig.unlockSecret") + public String unlockSecret; @LauncherInject("launchercore.env") public LauncherEnvironment environment; @@ -63,7 +63,6 @@ public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException projectName = null; clientPort = -1; secretKeyClient = null; - oemUnlockKey = null; try { trustManager = new LauncherTrustManager(secureConfigCertificates); } catch (CertificateException e) { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/LauncherRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/LauncherRequest.java index 68f55dac..cc79cb9d 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/LauncherRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/LauncherRequest.java @@ -23,7 +23,6 @@ public final class LauncherRequest extends Request implements WebSocketRequest { public static final Path BINARY_PATH = IOHelper.getCodeSource(Launcher.class); - public static final Path C_BINARY_PATH = BINARY_PATH.getParent().resolve(IOHelper.getFileName(BINARY_PATH) + ".tmp"); public static final boolean EXE_BINARY = IOHelper.hasExtension(BINARY_PATH, "exe"); @LauncherNetworkAPI public final String secureHash; @@ -46,53 +45,9 @@ public LauncherRequest() { secureSalt = Launcher.getConfig().secureCheckSalt; } - public static void update(LauncherRequestEvent result) throws IOException { - List args = new ArrayList<>(8); - args.add(IOHelper.resolveJavaBin(null).toString()); - if (LogHelper.isDebugEnabled()) - args.add(JVMHelper.jvmProperty(LogHelper.DEBUG_PROPERTY, Boolean.toString(LogHelper.isDebugEnabled()))); - args.add("-jar"); - args.add(BINARY_PATH.toString()); - ProcessBuilder builder = new ProcessBuilder(args.toArray(new String[0])); - builder.inheritIO(); - - // Rewrite and start new instance - if (result.binary != null) - IOHelper.write(BINARY_PATH, result.binary); - else { - /*URLConnection connection = IOHelper.newConnection(new URL(result.url)); - connection.setDoOutput(true); - connection.connect(); - try (OutputStream stream = connection.getOutputStream()) { - IOHelper.transfer(BINARY_PATH, stream); - }*/ - try { - Files.deleteIfExists(C_BINARY_PATH); - URL url = new URL(result.url); - URLConnection connection = url.openConnection(); - try (InputStream in = connection.getInputStream()) { - IOHelper.transfer(in, C_BINARY_PATH); - } - try (InputStream in = IOHelper.newInput(C_BINARY_PATH)) { - IOHelper.transfer(in, BINARY_PATH); - } - Files.deleteIfExists(C_BINARY_PATH); - } catch (Throwable e) { - LogHelper.error(e); - } - } - builder.start(); - - // Kill current instance - JVMHelper.RUNTIME.exit(255); - throw new AssertionError("Why Launcher wasn't restarted?!"); - } - @Override public LauncherRequestEvent requestDo(RequestService service) throws Exception { - LauncherRequestEvent result = super.request(service); - if (result.needUpdate) update(result); - return result; + return super.request(service); } @Override diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 41d9927a..249e5832 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index d7e66b5c..8fad3f5a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 1b6c7873..a69d9cb6 100755 --- a/gradlew +++ b/gradlew @@ -205,6 +205,12 @@ set -- \ org.gradle.wrapper.GradleWrapperMain \ "$@" +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/gradlew.bat b/gradlew.bat index 107acd32..f127cfd4 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,7 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -75,13 +75,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal