diff options
| author | Linnea Gräf <nea@nea.moe> | 2024-04-27 15:05:18 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-27 15:05:18 +0200 |
| commit | c266561e0cd048a7e0c2f8617a35bc1a827df318 (patch) | |
| tree | b1a457c0451857634c0feb64a515da0483018b35 /src/main/kotlin | |
| parent | 9547ebec0edd8c512f55f510acd93e180771e87a (diff) | |
| download | NotEnoughUpdates-c266561e0cd048a7e0c2f8617a35bc1a827df318.tar.gz NotEnoughUpdates-c266561e0cd048a7e0c2f8617a35bc1a827df318.tar.bz2 NotEnoughUpdates-c266561e0cd048a7e0c2f8617a35bc1a827df318.zip | |
Fix access transformer crash and invalid SSL context for auto updater (#1121)
Diffstat (limited to 'src/main/kotlin')
2 files changed, 22 insertions, 5 deletions
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/updater/AutoUpdater.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/updater/AutoUpdater.kt index b9ce28b2..a522cb47 100644 --- a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/updater/AutoUpdater.kt +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/updater/AutoUpdater.kt @@ -22,12 +22,10 @@ package io.github.moulberry.notenoughupdates.miscfeatures.updater import io.github.moulberry.notenoughupdates.NotEnoughUpdates import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent +import io.github.moulberry.notenoughupdates.util.ApiUtil import io.github.moulberry.notenoughupdates.util.MinecraftExecutor import io.github.moulberry.notenoughupdates.util.brigadier.thenExecute -import moe.nea.libautoupdate.CurrentVersion -import moe.nea.libautoupdate.PotentialUpdate -import moe.nea.libautoupdate.UpdateContext -import moe.nea.libautoupdate.UpdateTarget +import moe.nea.libautoupdate.* import net.minecraft.client.Minecraft import net.minecraft.event.ClickEvent import net.minecraft.util.ChatComponentText @@ -36,6 +34,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.gameevent.TickEvent import org.apache.logging.log4j.LogManager import java.util.concurrent.CompletableFuture +import javax.net.ssl.HttpsURLConnection @NEUAutoSubscribe object AutoUpdater { @@ -45,6 +44,15 @@ object AutoUpdater { CurrentVersion.ofTag(NotEnoughUpdates.VERSION.substringBefore("+")), "notenoughupdates" ) + + init { + UpdateUtils.patchConnection { + if (it is HttpsURLConnection) { + ApiUtil.patchHttpsRequest(it) + } + } + } + val logger = LogManager.getLogger("NEUUpdater") private var activePromise: CompletableFuture<*>? = null set(value) { @@ -80,6 +88,11 @@ object AutoUpdater { logger.info("Starting update check") val updateStream = config.updateStream.get() activePromise = updateContext.checkUpdate(updateStream.stream) + .thenApplyAsync({ + if (it.isUpdateAvailable) + (it.update as? SignedGithubUpdateData)?.verifyAnySignature() + it + }, MinecraftExecutor.OffThread) .thenAcceptAsync({ logger.info("Update check completed") if (updateState != UpdateState.NONE) { @@ -88,6 +101,10 @@ object AutoUpdater { } potentialUpdate = it if (it.isUpdateAvailable) { + if ((it.update as? SignedGithubUpdateData)?.verifyAnySignature() != true) { + logger.error("Found unsigned github update: ${it.update}") + return@thenAcceptAsync + } updateState = UpdateState.AVAILABLE Minecraft.getMinecraft().thePlayer?.addChatMessage(ChatComponentText("§e[NEU] §aNEU found a new update: ${it.update.versionName}. Click here to automatically install this update.").apply { this.chatStyle = this.chatStyle.setChatClickEvent( diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/updater/ConfigVersionGuiOption.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/updater/ConfigVersionGuiOption.kt index 3a920aec..da74ce22 100644 --- a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/updater/ConfigVersionGuiOption.kt +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/updater/ConfigVersionGuiOption.kt @@ -62,7 +62,7 @@ class ConfigVersionGuiOption(option: ProcessedOption) : GuiOptionEditor(option) GlStateManager.scale(2F, 2F, 1F) TextRenderUtils.drawStringCenteredScaledMaxWidth( "${if (AutoUpdater.updateState == AutoUpdater.UpdateState.NONE) GREEN else RED}${AutoUpdater.getCurrentVersion()}" + - if (nextVersion != null) "➜ ${GREEN}${nextVersion}" else "", + if (nextVersion != null && AutoUpdater.updateState != AutoUpdater.UpdateState.NONE) "➜ ${GREEN}${nextVersion}" else "", widthRemaining / 4F, 10F, true, |
