From 275305b16c76039b6a107e7f181a2ddfa9e44013 Mon Sep 17 00:00:00 2001 From: Gravit Date: Tue, 2 Oct 2018 19:19:57 +0700 Subject: [PATCH] =?UTF-8?q?LauncherUpdateResponse=20=D1=80=D0=B5=D0=B0?= =?UTF-8?q?=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ru/gravit/launchserver/binary/LauncherBinary.java | 7 +++++++ .../launchserver/command/basic/TestCommand.java | 6 +++++- .../websocket/json/update/LauncherResponse.java | 11 ++++++++--- LauncherAPI/build.gradle | 1 - libLauncher/build.gradle | 1 + 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/LauncherBinary.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/LauncherBinary.java index 9fdabd81..9ede059a 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/LauncherBinary.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/LauncherBinary.java @@ -7,6 +7,7 @@ import ru.gravit.utils.helper.IOHelper; import ru.gravit.launcher.serialize.signed.SignedBytesHolder; import ru.gravit.launchserver.LaunchServer; +import ru.gravit.utils.helper.SecurityHelper; public abstract class LauncherBinary { @LauncherAPI @@ -15,6 +16,7 @@ public abstract class LauncherBinary { protected final Path binaryFile; protected final Path syncBinaryFile; private volatile SignedBytesHolder binary; + private volatile byte[] hash; @LauncherAPI protected LauncherBinary(LaunchServer server, Path binaryFile) { @@ -42,11 +44,16 @@ public final boolean exists() { public final SignedBytesHolder getBytes() { return binary; } + @LauncherAPI + public final byte[] getHash() { + return hash; + } @LauncherAPI public final boolean sync() throws IOException { boolean exists = exists(); binary = exists ? new SignedBytesHolder(IOHelper.read(syncBinaryFile), server.privateKey) : null; + hash = SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA512,IOHelper.newInput(syncBinaryFile)); return exists; } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/TestCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/TestCommand.java index 55d17d06..30972bed 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/TestCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/TestCommand.java @@ -3,6 +3,7 @@ import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.command.Command; import ru.gravit.launchserver.socket.NettyServerSocketHandler; +import ru.gravit.utils.helper.CommonHelper; public class TestCommand extends Command { public TestCommand(LaunchServer server) { @@ -27,7 +28,10 @@ public void invoke(String... args) throws Exception { if (handler == null) handler = new NettyServerSocketHandler(server); if (args[0].equals("start")) { - handler.run(); + CommonHelper.newThread("Netty Server",true,handler); + } + if (args[0].equals("stop")) { + handler.close(); } } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/LauncherResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/LauncherResponse.java index 60beb0aa..ee82ef42 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/LauncherResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/LauncherResponse.java @@ -1,11 +1,15 @@ package ru.gravit.launchserver.socket.websocket.json.update; import io.netty.channel.ChannelHandlerContext; +import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.socket.Client; import ru.gravit.launchserver.socket.websocket.WebSocketService; import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface; import ru.gravit.utils.Version; +import java.util.Arrays; +import java.util.Base64; + public class LauncherResponse implements JsonResponseInterface { public Version version; public String hash; @@ -17,9 +21,10 @@ public String getType() { @Override public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { + byte[] bytes = Base64.getDecoder().decode(hash); if(launcher_type == 1) // JAR { - if(hash.equals("1")) //REPLACE REAL HASH + if(Arrays.equals(bytes, LaunchServer.server.launcherBinary.getHash())) //REPLACE REAL HASH { service.sendObject(ctx, new Result(false)); } else @@ -28,14 +33,14 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client } } else if(launcher_type == 2) { - if(hash.equals("2")) //REPLACE REAL HASH + if(Arrays.equals(bytes, LaunchServer.server.launcherEXEBinary.getHash())) //REPLACE REAL HASH { service.sendObject(ctx, new Result(false)); } else { service.sendObjectAndClose(ctx, new Result(true)); } - } + } else service.sendObject(ctx, new WebSocketService.ErrorResult("Request launcher type error")); } public class Result diff --git a/LauncherAPI/build.gradle b/LauncherAPI/build.gradle index cb326418..e7f413a1 100644 --- a/LauncherAPI/build.gradle +++ b/LauncherAPI/build.gradle @@ -4,7 +4,6 @@ dependencies { compile project(':libLauncher') compile 'javax.websocket:javax.websocket-client-api:1.1' - compileOnly 'com.google.code.gson:gson:2.8.5' compileOnly 'com.google.guava:guava:26.0-jre' compile files('../compat/authlib/authlib-clean.jar') } diff --git a/libLauncher/build.gradle b/libLauncher/build.gradle index 6ba0fda7..c5ee7b1e 100644 --- a/libLauncher/build.gradle +++ b/libLauncher/build.gradle @@ -5,4 +5,5 @@ compileOnly 'org.fusesource.jansi:jansi:1.17.1' compileOnly 'org.javassist:javassist:3.23.1-GA' compile 'com.eclipsesource.minimal-json:minimal-json:0.9.4' + compile 'com.google.code.gson:gson:2.8.5' }