[FIX] Починка автообновления лаунчера.

This commit is contained in:
Zaxar163 2019-06-11 11:56:53 +03:00
parent abc990bded
commit af421c3e96
2 changed files with 25 additions and 3 deletions

View file

@ -5,6 +5,7 @@
import pro.gravit.launcher.serialize.signed.DigestBytesHolder; import pro.gravit.launcher.serialize.signed.DigestBytesHolder;
import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.LaunchServer;
import pro.gravit.utils.helper.CommonHelper;
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.SecurityHelper; import pro.gravit.utils.helper.SecurityHelper;
@ -40,9 +41,17 @@ public void init() {
public final boolean sync() throws IOException { public final boolean sync() throws IOException {
boolean exists = exists(); boolean exists = exists();
if (sign != null)
CommonHelper.removeExc(sign);
if (binary != null) {
CommonHelper.removeExc(binary.getBytes());
CommonHelper.removeExc(binary.getDigest());
}
binary = exists ? new DigestBytesHolder(IOHelper.read(syncBinaryFile), SecurityHelper.DigestAlgorithm.SHA512) : null; binary = exists ? new DigestBytesHolder(IOHelper.read(syncBinaryFile), SecurityHelper.DigestAlgorithm.SHA512) : null;
sign = exists ? SecurityHelper.sign(IOHelper.read(syncBinaryFile), server.privateKey) : null; sign = exists ? SecurityHelper.sign(IOHelper.read(syncBinaryFile), server.privateKey) : null;
CommonHelper.addExc(sign);
CommonHelper.addExc(binary.getBytes());
CommonHelper.addExc(binary.getDigest());
return exists; return exists;
} }

View file

@ -5,6 +5,8 @@
import java.util.Collection; import java.util.Collection;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Locale; import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -140,10 +142,21 @@ public static GsonBuilder newBuilder() {
ByteArrayToBase64TypeAdapter.INSTANCE); ByteArrayToBase64TypeAdapter.INSTANCE);
} }
public static void addExc(byte[] exclusion) {
JsonArray add = new JsonArray(exclusion.length);
for (byte b : exclusion) add.add(new JsonPrimitive(b));
ByteArrayToBase64TypeAdapter.exclusions.put(exclusion, add);
}
public static void removeExc(byte[] exclusion) {
ByteArrayToBase64TypeAdapter.exclusions.remove(exclusion);
}
private static class ByteArrayToBase64TypeAdapter implements JsonSerializer<byte[]>, JsonDeserializer<byte[]> { private static class ByteArrayToBase64TypeAdapter implements JsonSerializer<byte[]>, JsonDeserializer<byte[]> {
private static final ByteArrayToBase64TypeAdapter INSTANCE = new ByteArrayToBase64TypeAdapter(); private static final ByteArrayToBase64TypeAdapter INSTANCE = new ByteArrayToBase64TypeAdapter();
private Base64.Decoder decoder = Base64.getUrlDecoder(); private static final Map<byte[], JsonArray> exclusions = new ConcurrentHashMap<>();
private Base64.Encoder encoder = Base64.getUrlEncoder(); private final Base64.Decoder decoder = Base64.getUrlDecoder();
private final Base64.Encoder encoder = Base64.getUrlEncoder();
public byte[] deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { public byte[] deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
if (json.isJsonArray()) { if (json.isJsonArray()) {
JsonArray byteArr = json.getAsJsonArray(); JsonArray byteArr = json.getAsJsonArray();