[FEATURE] Удаление лишнего неиспользуемого кода сашка

This commit is contained in:
Gravit 2019-07-12 06:10:31 +07:00
parent 484e3b69bd
commit 1a8dd7c204
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
11 changed files with 18 additions and 142 deletions

View file

@ -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<ClientProfile> profilesList;
public volatile Map<String, SignedObjectHolder<HashedDir>> updatesDirMap;
public volatile Map<String, HashedDir> updatesDirMap;
public final Timer taskPool;
@ -808,12 +807,12 @@ public void setProfiles(List<ClientProfile> profilesList) {
this.profilesList = Collections.unmodifiableList(profilesList);
}
public SignedObjectHolder<HashedDir> getUpdateDir(String name) {
public HashedDir getUpdateDir(String name) {
return updatesDirMap.get(name);
}
public Set<Entry<String, SignedObjectHolder<HashedDir>>> getUpdateDirs() {
public Set<Entry<String, HashedDir>> getUpdateDirs() {
return updatesDirMap.entrySet();
}
@ -866,7 +865,7 @@ public void syncProfilesDir() throws IOException {
public void syncUpdatesDir(Collection<String> dirs) throws IOException {
LogHelper.info("Syncing updates dir");
Map<String, SignedObjectHolder<HashedDir>> newUpdatesDirMap = new HashMap<>(16);
Map<String, HashedDir> newUpdatesDirMap = new HashMap<>(16);
try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(updatesDir)) {
for (final Path updateDir : dirStream) {
if (Files.isHidden(updateDir))
@ -882,7 +881,7 @@ public void syncUpdatesDir(Collection<String> dirs) throws IOException {
// Add from previous map (it's guaranteed to be non-null)
if (dirs != null && !dirs.contains(name)) {
SignedObjectHolder<HashedDir> 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<String> 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);

View file

@ -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;

View file

@ -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;

View file

@ -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<String> set = new HashSet<>();
for (Map.Entry<String, SignedObjectHolder<HashedDir>> entry : server.updatesDirMap.entrySet())
for (Map.Entry<String, HashedDir> entry : server.updatesDirMap.entrySet())
set.add(entry.getKey());
sendResult(new UpdateListRequestEvent(set));
}

View file

@ -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<HashedDir> 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));
}
}

View file

@ -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;

View file

@ -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<HashedDir> 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<HashedDir> run() throws Exception;
HashedDir run() throws Exception;
}
@LauncherAPI

View file

@ -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<String, Object> 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);

View file

@ -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;
}

View file

@ -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);
}
}

View file

@ -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<O extends StreamObject> extends SignedBytesHolder {
@LauncherAPI
public final O object;
@LauncherAPI
public SignedObjectHolder(HInput input, RSAPublicKey publicKey, Adapter<O> 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<O> adapter) throws IOException {
try (HInput input = new HInput(bytes)) {
return adapter.convert(input);
}
}
@Override
public String toString() {
return object.toString();
}
}