1
0
mirror of https://github.com/SKCraft/Launcher.git synced 2024-11-30 13:13:58 +01:00

Support downloading logging config files from the version manifest

This update is required to mitigate the log4j2 vulnerability
This commit is contained in:
Henry Le Grys 2021-12-10 13:55:23 +00:00
parent cd88effb59
commit 5fbf5598b4
3 changed files with 39 additions and 1 deletions

View File

@ -9,6 +9,7 @@ package com.skcraft.launcher.launch;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.Files;
import com.skcraft.concurrency.DefaultProgress;
import com.skcraft.concurrency.ProgressObservable;
@ -279,6 +280,16 @@ public class Runner implements Callable<Process>, ProgressObservable {
}
}
}
if (versionManifest.getLogging() != null) {
log.info("Logging config present, log4j2 bug likely mitigated");
VersionManifest.LoggingConfig config = versionManifest.getLogging().getClient();
File configFile = new File(launcher.getLibrariesDir(), config.getFile().getId());
StrSubstitutor loggingSub = new StrSubstitutor(ImmutableMap.of("path", configFile.getAbsolutePath()));
flags.add(loggingSub.replace(config.getArgument()));
}
}
/**

View File

@ -9,6 +9,7 @@ package com.skcraft.launcher.model.minecraft;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Splitter;
import com.skcraft.launcher.model.loader.SidedData;
import lombok.Data;
import java.util.*;
@ -28,6 +29,7 @@ public class VersionManifest {
private int minimumLauncherVersion;
private LinkedHashSet<Library> libraries;
private JavaVersion javaVersion;
private SidedData<LoggingConfig> logging;
private Map<String, Artifact> downloads = new HashMap<String, Artifact>();
public String getAssetId() {
@ -61,6 +63,7 @@ public class VersionManifest {
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public static class Artifact {
private String id;
private String url;
private int size;
@ -74,4 +77,11 @@ public class VersionManifest {
private String id;
private String url;
}
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public static class LoggingConfig {
private String argument;
private Artifact file;
}
}

View File

@ -25,6 +25,7 @@ import com.skcraft.launcher.model.modpack.Manifest;
import com.skcraft.launcher.model.modpack.ManifestEntry;
import com.skcraft.launcher.persistence.Persistence;
import com.skcraft.launcher.util.Environment;
import com.skcraft.launcher.util.FileUtils;
import com.skcraft.launcher.util.HttpRequest;
import com.skcraft.launcher.util.SharedLocale;
import lombok.NonNull;
@ -40,6 +41,7 @@ import java.util.logging.Level;
import static com.skcraft.launcher.LauncherUtils.checkInterrupted;
import static com.skcraft.launcher.LauncherUtils.concat;
import static com.skcraft.launcher.util.HttpRequest.url;
/**
* The base implementation of the various routines involved in downloading
@ -231,7 +233,7 @@ public abstract class BaseUpdater {
protected void installLibraries(@NonNull Installer installer,
@NonNull Manifest manifest,
@NonNull File librariesDir,
@NonNull List<URL> sources) throws InterruptedException {
@NonNull List<URL> sources) throws InterruptedException, IOException {
VersionManifest versionManifest = manifest.getVersionManifest();
Iterable<Library> allLibraries = versionManifest.getLibraries();
@ -271,6 +273,21 @@ public abstract class BaseUpdater {
}
}
}
// Fetch logging config
if (versionManifest.getLogging() != null) {
VersionManifest.LoggingConfig config = versionManifest.getLogging().getClient();
VersionManifest.Artifact file = config.getFile();
File targetFile = new File(librariesDir, file.getId());
if (!targetFile.exists() || !Objects.equals(config.getFile().getHash(), FileUtils.getShaHash(targetFile))) {
File tempFile = installer.getDownloader().download(url(file.getUrl()), file.getHash(), file.getSize(), file.getId());
log.info("Downloading logging config " + file.getId() + " from " + file.getUrl());
installer.queue(new FileMover(tempFile, targetFile));
}
}
}
private static void writeDataFile(File path, Object object) {