diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java index fbbe1527..c84edf41 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java @@ -41,7 +41,6 @@ import pro.gravit.launcher.managers.ConfigManager; import pro.gravit.launcher.managers.GarbageManager; import pro.gravit.launcher.profiles.ClientProfile; -import pro.gravit.launcher.serialize.signed.SignedObjectHolder; import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.auth.handler.AuthHandler; import pro.gravit.launchserver.auth.handler.MemoryAuthHandler; @@ -448,7 +447,7 @@ public static void main(String... args) throws Throwable { // Updates and profiles private volatile List profilesList; - public volatile Map> updatesDirMap; + public volatile Map updatesDirMap; public final Timer taskPool; @@ -808,12 +807,12 @@ public void setProfiles(List profilesList) { this.profilesList = Collections.unmodifiableList(profilesList); } - public SignedObjectHolder getUpdateDir(String name) { + public HashedDir getUpdateDir(String name) { return updatesDirMap.get(name); } - public Set>> getUpdateDirs() { + public Set> getUpdateDirs() { return updatesDirMap.entrySet(); } @@ -866,7 +865,7 @@ public void syncProfilesDir() throws IOException { public void syncUpdatesDir(Collection dirs) throws IOException { LogHelper.info("Syncing updates dir"); - Map> newUpdatesDirMap = new HashMap<>(16); + Map newUpdatesDirMap = new HashMap<>(16); try (DirectoryStream dirStream = Files.newDirectoryStream(updatesDir)) { for (final Path updateDir : dirStream) { if (Files.isHidden(updateDir)) @@ -882,7 +881,7 @@ public void syncUpdatesDir(Collection dirs) throws IOException { // Add from previous map (it's guaranteed to be non-null) if (dirs != null && !dirs.contains(name)) { - SignedObjectHolder hdir = updatesDirMap.get(name); + HashedDir hdir = updatesDirMap.get(name); if (hdir != null) { newUpdatesDirMap.put(name, hdir); continue; @@ -892,7 +891,7 @@ public void syncUpdatesDir(Collection dirs) throws IOException { // Sync and sign update dir LogHelper.info("Syncing '%s' update dir", name); HashedDir updateHDir = new HashedDir(updateDir, null, true, true); - newUpdatesDirMap.put(name, new SignedObjectHolder<>(updateHDir, privateKey)); + newUpdatesDirMap.put(name, updateHDir); } } updatesDirMap = Collections.unmodifiableMap(newUpdatesDirMap); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherBinary.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherBinary.java index c63ffd18..8f76d9a4 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherBinary.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherBinary.java @@ -11,7 +11,7 @@ public abstract class LauncherBinary { public final LaunchServer server; public final Path syncBinaryFile; - private volatile DigestBytesHolder binary; + private volatile byte[] digest; private volatile byte[] sign; protected LauncherBinary(LaunchServer server, Path binaryFile) { @@ -27,8 +27,8 @@ public final boolean exists() { } - public final DigestBytesHolder getBytes() { - return binary; + public final byte[] getDigest() { + return digest; } public final byte[] getSign() { @@ -40,7 +40,7 @@ public void init() { public final boolean sync() throws IOException { boolean exists = exists(); - binary = exists ? new DigestBytesHolder(IOHelper.read(syncBinaryFile), SecurityHelper.DigestAlgorithm.SHA512) : null; + digest = exists ? SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA512, IOHelper.read(syncBinaryFile)) : null; sign = exists ? SecurityHelper.sign(IOHelper.read(syncBinaryFile), server.privateKey) : null; return exists; 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 765374f1..9a9de042 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 @@ -29,7 +29,7 @@ public void execute(ChannelHandlerContext ctx, Client client) { bytes = digest; if (launcher_type == 1) // JAR { - byte[] hash = server.launcherBinary.getBytes().getDigest(); + byte[] hash = server.launcherBinary.getDigest(); if (hash == null) service.sendObjectAndClose(ctx, new LauncherRequestEvent(true, server.config.netty.launcherURL)); if (Arrays.equals(bytes, hash)) { client.checkSign = true; @@ -39,7 +39,7 @@ public void execute(ChannelHandlerContext ctx, Client client) { } } else if (launcher_type == 2) //EXE { - byte[] hash = server.launcherEXEBinary.getBytes().getDigest(); + byte[] hash = server.launcherEXEBinary.getDigest(); if (hash == null) sendResultAndClose(new LauncherRequestEvent(true, server.config.netty.launcherEXEURL)); if (Arrays.equals(bytes, hash)) { client.checkSign = true; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/UpdateListResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/UpdateListResponse.java index 118d72ed..2d10cc2b 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/UpdateListResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/UpdateListResponse.java @@ -6,7 +6,6 @@ import io.netty.channel.ChannelHandlerContext; import pro.gravit.launcher.events.request.UpdateListRequestEvent; import pro.gravit.launcher.hasher.HashedDir; -import pro.gravit.launcher.serialize.signed.SignedObjectHolder; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.SimpleResponse; @@ -24,7 +23,7 @@ public void execute(ChannelHandlerContext ctx, Client client) { return; } HashSet set = new HashSet<>(); - for (Map.Entry> entry : server.updatesDirMap.entrySet()) + for (Map.Entry entry : server.updatesDirMap.entrySet()) set.add(entry.getKey()); sendResult(new UpdateListRequestEvent(set)); } 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 6d4f8431..967b6f85 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 @@ -5,7 +5,6 @@ import pro.gravit.launcher.events.request.UpdateRequestEvent; import pro.gravit.launcher.hasher.HashedDir; import pro.gravit.launcher.profiles.ClientProfile; -import pro.gravit.launcher.serialize.signed.SignedObjectHolder; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.SimpleResponse; @@ -34,7 +33,7 @@ public void execute(ChannelHandlerContext ctx, Client client) { } } } - SignedObjectHolder dir = server.updatesDirMap.get(dirName); + HashedDir dir = server.updatesDirMap.get(dirName); if (dir == null) { service.sendObject(ctx, new ErrorRequestEvent(String.format("Directory %s not found", dirName))); return; @@ -46,6 +45,6 @@ public void execute(ChannelHandlerContext ctx, Client client) { url = bind.url; zip = bind.zip; } - service.sendObject(ctx, new UpdateRequestEvent(dir.object, url, zip)); + service.sendObject(ctx, new UpdateRequestEvent(dir, url, zip)); } } diff --git a/Launcher/runtime/engine/api.js b/Launcher/runtime/engine/api.js index 1c751f1d..3374a51d 100644 --- a/Launcher/runtime/engine/api.js +++ b/Launcher/runtime/engine/api.js @@ -41,8 +41,6 @@ var HInput = HInputClass.static; var HOutput = HOutputClass.static; var StreamObject = StreamObjectClass.static; var StreamObjectAdapter = StreamObjectAdapterClass.static; -var SignedBytesHolder = SignedBytesHolderClass.static; -var SignedObjectHolder = SignedObjectHolderClass.static; var EnumSerializer = EnumSerializerClass.static; var OptionalFile = OptionalFileClass.static; diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/FunctionalBridge.java b/Launcher/src/main/java/pro/gravit/launcher/client/FunctionalBridge.java index ec1e5474..faf56be5 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/FunctionalBridge.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/FunctionalBridge.java @@ -17,7 +17,6 @@ import pro.gravit.launcher.managers.HasherManager; import pro.gravit.launcher.managers.HasherStore; import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.serialize.signed.SignedObjectHolder; import pro.gravit.utils.helper.LogHelper; public class FunctionalBridge { @@ -33,12 +32,12 @@ public class FunctionalBridge { private static long cachedMemorySize = -1; @LauncherAPI - public static HashedDirRunnable offlineUpdateRequest(String dirName, Path dir, SignedObjectHolder hdir, FileNameMatcher matcher, boolean digest) { + public static HashedDirRunnable offlineUpdateRequest(String dirName, Path dir, HashedDir hdir, FileNameMatcher matcher, boolean digest) { return () -> { if (hdir == null) { Request.requestError(java.lang.String.format("Директории '%s' нет в кэше", dirName)); } - ClientLauncher.verifyHDir(dir, hdir.object, matcher, digest); + ClientLauncher.verifyHDir(dir, hdir, matcher, digest); return hdir; }; } @@ -100,7 +99,7 @@ public static void setAuthParams(AuthRequestEvent event) { @FunctionalInterface public interface HashedDirRunnable { - SignedObjectHolder run() throws Exception; + HashedDir run() throws Exception; } @LauncherAPI diff --git a/Launcher/src/main/java/pro/gravit/launcher/gui/JSRuntimeProvider.java b/Launcher/src/main/java/pro/gravit/launcher/gui/JSRuntimeProvider.java index 97c09d85..17738305 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/gui/JSRuntimeProvider.java +++ b/Launcher/src/main/java/pro/gravit/launcher/gui/JSRuntimeProvider.java @@ -49,8 +49,6 @@ import pro.gravit.launcher.request.uuid.ProfileByUsernameRequest; import pro.gravit.launcher.serialize.HInput; import pro.gravit.launcher.serialize.HOutput; -import pro.gravit.launcher.serialize.signed.SignedBytesHolder; -import pro.gravit.launcher.serialize.signed.SignedObjectHolder; import pro.gravit.launcher.serialize.stream.EnumSerializer; import pro.gravit.launcher.serialize.stream.StreamObject; import pro.gravit.utils.HTTPRequest; @@ -112,8 +110,6 @@ public static void addLauncherClassBindings(Map bindings) { bindings.put("HOutputClass", HOutput.class); bindings.put("StreamObjectClass", StreamObject.class); bindings.put("StreamObjectAdapterClass", StreamObject.Adapter.class); - bindings.put("SignedBytesHolderClass", SignedBytesHolder.class); - bindings.put("SignedObjectHolderClass", SignedObjectHolder.class); bindings.put("EnumSerializerClass", EnumSerializer.class); bindings.put("OptionalFileClass", OptionalFile.class); bindings.put("UserSettingsClass", UserSettings.class); diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/SerializeLimits.java b/LauncherCore/src/main/java/pro/gravit/launcher/serialize/SerializeLimits.java index eb9848e8..c1fae7cb 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/SerializeLimits.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/serialize/SerializeLimits.java @@ -3,24 +3,10 @@ import pro.gravit.launcher.LauncherAPI; public class SerializeLimits { - @LauncherAPI - public static final int MAX_LOGIN = 1024; - @LauncherAPI - public static final int MAX_CUSTOM_TEXT = 512; - @LauncherAPI - public static final int MAX_CLIENT = 128; - @LauncherAPI - public static final int MAX_SERVERID = 128; - @LauncherAPI - public static final int MAX_QUEUE_SIZE = 128; @LauncherAPI public static final int MAX_BATCH_SIZE = 128; @LauncherAPI public static final byte EXPECTED_BYTE = 0b01010101; @LauncherAPI public static final int MAX_DIGEST = 512; - @LauncherAPI - public static final int MAX_HWID_STR = 1024; - @LauncherAPI - public static final int MAX_COMMAND = 2048; } diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/signed/SignedBytesHolder.java b/LauncherCore/src/main/java/pro/gravit/launcher/serialize/signed/SignedBytesHolder.java deleted file mode 100644 index 071f2c0f..00000000 --- a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/signed/SignedBytesHolder.java +++ /dev/null @@ -1,51 +0,0 @@ -package pro.gravit.launcher.serialize.signed; - -import java.io.IOException; -import java.security.SignatureException; -import java.security.interfaces.RSAPrivateKey; -import java.security.interfaces.RSAPublicKey; - -import pro.gravit.launcher.LauncherAPI; -import pro.gravit.launcher.serialize.HInput; -import pro.gravit.launcher.serialize.HOutput; -import pro.gravit.launcher.serialize.stream.StreamObject; -import pro.gravit.utils.helper.SecurityHelper; - -public class SignedBytesHolder extends StreamObject { - protected final byte[] bytes; - private final byte[] sign; - - @LauncherAPI - public SignedBytesHolder(byte[] bytes, byte[] sign, RSAPublicKey publicKey) throws SignatureException { - SecurityHelper.verifySign(bytes, sign, publicKey); - this.bytes = bytes.clone(); - this.sign = sign.clone(); - } - - @LauncherAPI - public SignedBytesHolder(byte[] bytes, RSAPrivateKey privateKey) { - this.bytes = bytes.clone(); - sign = SecurityHelper.sign(bytes, privateKey); - } - - @LauncherAPI - public SignedBytesHolder(HInput input, RSAPublicKey publicKey) throws IOException, SignatureException { - this(input.readByteArray(0), input.readByteArray(-SecurityHelper.RSA_KEY_LENGTH), publicKey); - } - - @LauncherAPI - public final byte[] getBytes() { - return bytes.clone(); - } - - @LauncherAPI - public final byte[] getSign() { - return sign.clone(); - } - - @Override - public final void write(HOutput output) throws IOException { - output.writeByteArray(bytes, 0); - output.writeByteArray(sign, -SecurityHelper.RSA_KEY_LENGTH); - } -} diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/signed/SignedObjectHolder.java b/LauncherCore/src/main/java/pro/gravit/launcher/serialize/signed/SignedObjectHolder.java deleted file mode 100644 index c3567c33..00000000 --- a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/signed/SignedObjectHolder.java +++ /dev/null @@ -1,49 +0,0 @@ -package pro.gravit.launcher.serialize.signed; - -import java.io.IOException; -import java.security.SignatureException; -import java.security.interfaces.RSAPrivateKey; -import java.security.interfaces.RSAPublicKey; - -import pro.gravit.launcher.LauncherAPI; -import pro.gravit.launcher.serialize.HInput; -import pro.gravit.launcher.serialize.stream.StreamObject; - -public final class SignedObjectHolder extends SignedBytesHolder { - @LauncherAPI - public final O object; - - @LauncherAPI - public SignedObjectHolder(HInput input, RSAPublicKey publicKey, Adapter adapter) throws IOException, SignatureException { - super(input, publicKey); - object = newInstance(adapter); - } - - @LauncherAPI - public SignedObjectHolder(O object, RSAPrivateKey privateKey) throws IOException { - super(object.write(), privateKey); - this.object = object; - } - - @Override - public boolean equals(Object obj) { - return obj instanceof SignedObjectHolder && object.equals(((SignedObjectHolder) obj).object); - } - - @Override - public int hashCode() { - return object.hashCode(); - } - - @LauncherAPI - public O newInstance(Adapter adapter) throws IOException { - try (HInput input = new HInput(bytes)) { - return adapter.convert(input); - } - } - - @Override - public String toString() { - return object.toString(); - } -}