From e8126f565dd4f5bf4c57a82f7e7ce5649863d120 Mon Sep 17 00:00:00 2001 From: Gravit Date: Tue, 2 Oct 2018 19:39:54 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20LauncherResponse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ru/gravit/launchserver/binary/LauncherBinary.java | 2 +- .../socket/websocket/json/update/LauncherResponse.java | 10 +++++++--- 2 files changed, 8 insertions(+), 4 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 9ede059a..558e75ec 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/LauncherBinary.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/LauncherBinary.java @@ -53,7 +53,7 @@ public final byte[] getHash() { 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)); + hash = exists ? SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA512,IOHelper.newInput(syncBinaryFile)) : null; return exists; } } 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 ee82ef42..b983e9f4 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 @@ -24,16 +24,20 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client byte[] bytes = Base64.getDecoder().decode(hash); if(launcher_type == 1) // JAR { - if(Arrays.equals(bytes, LaunchServer.server.launcherBinary.getHash())) //REPLACE REAL HASH + byte[] hash = LaunchServer.server.launcherBinary.getHash(); + if(hash == null) service.sendObjectAndClose(ctx, new Result(true)); + if(Arrays.equals(bytes, hash)) //REPLACE REAL HASH { service.sendObject(ctx, new Result(false)); } else { service.sendObjectAndClose(ctx, new Result(true)); } - } else if(launcher_type == 2) + } else if(launcher_type == 2) //EXE { - if(Arrays.equals(bytes, LaunchServer.server.launcherEXEBinary.getHash())) //REPLACE REAL HASH + byte[] hash = LaunchServer.server.launcherEXEBinary.getHash(); + if(hash == null) service.sendObjectAndClose(ctx, new Result(true)); + if(Arrays.equals(bytes, hash)) //REPLACE REAL HASH { service.sendObject(ctx, new Result(false)); } else