From 5fbf5598b4b7e1a4dbc465ed2aa5ac3469483ca6 Mon Sep 17 00:00:00 2001 From: Henry Le Grys Date: Fri, 10 Dec 2021 13:55:23 +0000 Subject: [PATCH] Support downloading logging config files from the version manifest This update is required to mitigate the log4j2 vulnerability --- .../com/skcraft/launcher/launch/Runner.java | 11 +++++++++++ .../model/minecraft/VersionManifest.java | 10 ++++++++++ .../skcraft/launcher/update/BaseUpdater.java | 19 ++++++++++++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/launcher/src/main/java/com/skcraft/launcher/launch/Runner.java b/launcher/src/main/java/com/skcraft/launcher/launch/Runner.java index 588a365..0fcbd87 100644 --- a/launcher/src/main/java/com/skcraft/launcher/launch/Runner.java +++ b/launcher/src/main/java/com/skcraft/launcher/launch/Runner.java @@ -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, 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())); + } } /** diff --git a/launcher/src/main/java/com/skcraft/launcher/model/minecraft/VersionManifest.java b/launcher/src/main/java/com/skcraft/launcher/model/minecraft/VersionManifest.java index f270ca4..dd3cf63 100644 --- a/launcher/src/main/java/com/skcraft/launcher/model/minecraft/VersionManifest.java +++ b/launcher/src/main/java/com/skcraft/launcher/model/minecraft/VersionManifest.java @@ -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 libraries; private JavaVersion javaVersion; + private SidedData logging; private Map downloads = new HashMap(); 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; + } } diff --git a/launcher/src/main/java/com/skcraft/launcher/update/BaseUpdater.java b/launcher/src/main/java/com/skcraft/launcher/update/BaseUpdater.java index cfb3d4f..fac401d 100644 --- a/launcher/src/main/java/com/skcraft/launcher/update/BaseUpdater.java +++ b/launcher/src/main/java/com/skcraft/launcher/update/BaseUpdater.java @@ -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 sources) throws InterruptedException { + @NonNull List sources) throws InterruptedException, IOException { VersionManifest versionManifest = manifest.getVersionManifest(); Iterable 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) {