LauncherUpdateResponse реализация

This commit is contained in:
Gravit 2018-10-02 19:19:57 +07:00
parent 2024018eb2
commit 275305b16c
5 changed files with 21 additions and 5 deletions

View file

@ -7,6 +7,7 @@
import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.IOHelper;
import ru.gravit.launcher.serialize.signed.SignedBytesHolder; import ru.gravit.launcher.serialize.signed.SignedBytesHolder;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.utils.helper.SecurityHelper;
public abstract class LauncherBinary { public abstract class LauncherBinary {
@LauncherAPI @LauncherAPI
@ -15,6 +16,7 @@ public abstract class LauncherBinary {
protected final Path binaryFile; protected final Path binaryFile;
protected final Path syncBinaryFile; protected final Path syncBinaryFile;
private volatile SignedBytesHolder binary; private volatile SignedBytesHolder binary;
private volatile byte[] hash;
@LauncherAPI @LauncherAPI
protected LauncherBinary(LaunchServer server, Path binaryFile) { protected LauncherBinary(LaunchServer server, Path binaryFile) {
@ -42,11 +44,16 @@ public final boolean exists() {
public final SignedBytesHolder getBytes() { public final SignedBytesHolder getBytes() {
return binary; return binary;
} }
@LauncherAPI
public final byte[] getHash() {
return hash;
}
@LauncherAPI @LauncherAPI
public final boolean sync() throws IOException { public final boolean sync() throws IOException {
boolean exists = exists(); boolean exists = exists();
binary = exists ? new SignedBytesHolder(IOHelper.read(syncBinaryFile), server.privateKey) : null; binary = exists ? new SignedBytesHolder(IOHelper.read(syncBinaryFile), server.privateKey) : null;
hash = SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA512,IOHelper.newInput(syncBinaryFile));
return exists; return exists;
} }
} }

View file

@ -3,6 +3,7 @@
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.command.Command; import ru.gravit.launchserver.command.Command;
import ru.gravit.launchserver.socket.NettyServerSocketHandler; import ru.gravit.launchserver.socket.NettyServerSocketHandler;
import ru.gravit.utils.helper.CommonHelper;
public class TestCommand extends Command { public class TestCommand extends Command {
public TestCommand(LaunchServer server) { public TestCommand(LaunchServer server) {
@ -27,7 +28,10 @@ public void invoke(String... args) throws Exception {
if (handler == null) if (handler == null)
handler = new NettyServerSocketHandler(server); handler = new NettyServerSocketHandler(server);
if (args[0].equals("start")) { if (args[0].equals("start")) {
handler.run(); CommonHelper.newThread("Netty Server",true,handler);
}
if (args[0].equals("stop")) {
handler.close();
} }
} }
} }

View file

@ -1,11 +1,15 @@
package ru.gravit.launchserver.socket.websocket.json.update; package ru.gravit.launchserver.socket.websocket.json.update;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.socket.Client; import ru.gravit.launchserver.socket.Client;
import ru.gravit.launchserver.socket.websocket.WebSocketService; import ru.gravit.launchserver.socket.websocket.WebSocketService;
import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface; import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface;
import ru.gravit.utils.Version; import ru.gravit.utils.Version;
import java.util.Arrays;
import java.util.Base64;
public class LauncherResponse implements JsonResponseInterface { public class LauncherResponse implements JsonResponseInterface {
public Version version; public Version version;
public String hash; public String hash;
@ -17,9 +21,10 @@ public String getType() {
@Override @Override
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception {
byte[] bytes = Base64.getDecoder().decode(hash);
if(launcher_type == 1) // JAR 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)); service.sendObject(ctx, new Result(false));
} else } else
@ -28,14 +33,14 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
} }
} else if(launcher_type == 2) } 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)); service.sendObject(ctx, new Result(false));
} else } else
{ {
service.sendObjectAndClose(ctx, new Result(true)); service.sendObjectAndClose(ctx, new Result(true));
} }
} } else service.sendObject(ctx, new WebSocketService.ErrorResult("Request launcher type error"));
} }
public class Result public class Result

View file

@ -4,7 +4,6 @@
dependencies { dependencies {
compile project(':libLauncher') compile project(':libLauncher')
compile 'javax.websocket:javax.websocket-client-api:1.1' 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' compileOnly 'com.google.guava:guava:26.0-jre'
compile files('../compat/authlib/authlib-clean.jar') compile files('../compat/authlib/authlib-clean.jar')
} }

View file

@ -5,4 +5,5 @@
compileOnly 'org.fusesource.jansi:jansi:1.17.1' compileOnly 'org.fusesource.jansi:jansi:1.17.1'
compileOnly 'org.javassist:javassist:3.23.1-GA' compileOnly 'org.javassist:javassist:3.23.1-GA'
compile 'com.eclipsesource.minimal-json:minimal-json:0.9.4' compile 'com.eclipsesource.minimal-json:minimal-json:0.9.4'
compile 'com.google.code.gson:gson:2.8.5'
} }