From f6e68082b71d91c8b7ed04c27e3215ec09cb5ceb Mon Sep 17 00:00:00 2001 From: coolGi Date: Mon, 17 Jul 2023 02:14:17 +0930 Subject: [PATCH] Added checking for the checksum of the update --- .../distanthorizons/core/jar/updater/SelfUpdater.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/com/seibel/distanthorizons/core/jar/updater/SelfUpdater.java b/core/src/main/java/com/seibel/distanthorizons/core/jar/updater/SelfUpdater.java index ec5b91592..d08f3efa3 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/jar/updater/SelfUpdater.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/jar/updater/SelfUpdater.java @@ -94,13 +94,22 @@ public class SelfUpdater { public static boolean updateMod(String minecraftVersion, File file) { try { LOGGER.info("Attempting to auto update " + ModInfo.READABLE_NAME); + Files.createDirectories(file.getParentFile().toPath()); WebDownloader.downloadAsFile(ModrinthGetter.getLatestDownloadForVersion(minecraftVersion), file); + + // Check if the checksum of the downloaded jar is correct (not required, but good to have to prevent corruption or interception) + if (!JarUtils.getFileChecksum(MessageDigest.getInstance("SHA"), file).equals(ModrinthGetter.getLatestShaForVersion(minecraftVersion))) { + LOGGER.warn("DH update checksum failed, aborting install"); + throw new Exception("Checksum failed"); + } + deleteOldOnClose = true; + LOGGER.info(ModInfo.READABLE_NAME + " successfully updated. It will apply on game's relaunch"); return true; } catch (Exception e) { - LOGGER.info("Failed to update "+ModInfo.READABLE_NAME+" to version "+ModrinthGetter.getLatestNameForVersion(minecraftVersion)); + LOGGER.warn("Failed to update "+ModInfo.READABLE_NAME+" to version "+ModrinthGetter.getLatestNameForVersion(minecraftVersion)); e.printStackTrace(); return false; }