From a28a7068b09b40d456e0910dac7acd5b6bf3c721 Mon Sep 17 00:00:00 2001 From: ROM Date: Sat, 29 Jan 2022 17:47:32 -0600 Subject: [PATCH] modJar signing --- build.gradle | 62 ++++++- gradle/artifacts.gradle | 31 ---- gradle/maven.gradle | 154 +++++++----------- gradle/resources.gradle | 4 +- .../mods/galacticraft/core/Constants.java | 6 +- .../galacticraft/core/GalacticraftCore.java | 13 +- .../planets/GalacticraftPlanets.java | 19 ++- .../mods/miccore/MicdoodlePlugin.java | 3 +- 8 files changed, 143 insertions(+), 149 deletions(-) delete mode 100644 gradle/artifacts.gradle diff --git a/build.gradle b/build.gradle index d7cfc9a10c..8f80bca651 100644 --- a/build.gradle +++ b/build.gradle @@ -65,13 +65,7 @@ ext { } } -FileCollection collection = layout.files { file('gradle').listFiles() } -FileCollection scripts = collection.filter { File f -> - f.name.endsWith('.gradle') || !f.directory -} -scripts.collect { relativePath(it) }.each { String s -> - apply from: "$s".replace("\\", "/") -} +apply from: 'gradle/minecraft.gradle' task generateChangelog(type: se.bjurr.gitchangelog.plugin.gradle.GitChangelogTask) { group = 'script-tasks' @@ -83,3 +77,57 @@ task generateChangelog(type: se.bjurr.gitchangelog.plugin.gradle.GitChangelogTas templateContent = file('changelog.mustache').getText('UTF-8'); } +import net.minecraftforge.gradle.common.tasks.SignJar + +task signJar(type: SignJar) { + + onlyIf { + project.hasProperty('keyStore') + } + + keyStore = project.findProperty('keyStore') + alias = project.findProperty('keyStoreAlias') + storePass = project.findProperty('keyStorePass') + keyPass = project.findProperty('keyStoreKeyPass') + inputFile = jar.archivePath + outputFile = jar.archivePath +} + +jar { + manifest.from(MANIFEST) + + afterEvaluate { project.getTasks().getByName('reobfJar').finalizedBy(signJar) } +} + +jar.finalizedBy('reobfJar') + +task sourcesJar(type: Jar, dependsOn: classes) { + classifier = 'sources' + from sourceSets.main.allSource + manifest.from(MANIFEST) +} + +task apiJar(type: Jar) { + classifier "api" + include 'micdoodle8/mods/galacticraft/api/**' + from sourceSets.main.allJava + from sourceSets.main.output + manifest.from(MANIFEST) +} + +task deobfJar(type: Jar) { + classifier = 'deobf' + from sourceSets.main.output + manifest.from(MANIFEST) +} + +artifacts { + archives deobfJar + archives sourcesJar + archives apiJar +} + +apply from: 'gradle/maven.gradle' +apply from: 'gradle/resources.gradle' + +build.dependsOn signJar \ No newline at end of file diff --git a/gradle/artifacts.gradle b/gradle/artifacts.gradle deleted file mode 100644 index d11c872d6e..0000000000 --- a/gradle/artifacts.gradle +++ /dev/null @@ -1,31 +0,0 @@ -jar { - manifest.from(MANIFEST) -} - -jar.finalizedBy('reobfJar') - -task sourcesJar(type: Jar, dependsOn: classes) { - classifier = 'sources' - from sourceSets.main.allSource - manifest.from(MANIFEST) -} - -task apiJar(type: Jar) { - classifier "api" - include 'micdoodle8/mods/galacticraft/api/**' - from sourceSets.main.allJava - from sourceSets.main.output - manifest.from(MANIFEST) -} - -task deobfJar(type: Jar) { - classifier = 'deobf' - from sourceSets.main.output - manifest.from(MANIFEST) -} - -artifacts { - archives deobfJar - archives sourcesJar - archives apiJar -} \ No newline at end of file diff --git a/gradle/maven.gradle b/gradle/maven.gradle index bd07dbb84a..a35ac6c0d0 100644 --- a/gradle/maven.gradle +++ b/gradle/maven.gradle @@ -1,110 +1,53 @@ apply plugin: "maven-publish" apply plugin: 'signing' -task buildAllJars(type: GradleBuild) { - group = 'script-tasks' - description = 'Builds all Jars for Galacticraft' - tasks = [ - 'build', - 'coreJar', - 'miccoreJar', - 'planetsJar', - 'fullBuild', - 'apiJar', - 'coreDevJar', - 'planetsDevJar', - 'miccoreDevJar' - ] -} - -task buildMainJars(type: GradleBuild) { - group = 'script-tasks' - description = 'Builds the main Jars for Galacticraft' - tasks = [ - 'build', - 'coreJar', - 'miccoreJar', - 'planetsJar', - 'fullBuild' - ] -} - -task buildDevJars(type: GradleBuild) { - group = 'script-tasks' - description = 'Builds the dev Jars for Galacticraft' - tasks = [ - 'build', - 'apiJar', - 'coreDevJar', - 'planetsDevJar', - 'miccoreDevJar', - 'fullBuild' - ] -} - -clean { - File buildDir = file('build') - FileCollection collection = layout.files { buildDir.listFiles() } - FileCollection cache = collection.filter { File f -> - !f.name.equals('fg_cache') - } - cache.collect { relativePath(it) } - delete = [] - delete cache -} - -tasks.named('wrapper') { - distributionType = Wrapper.DistributionType.ALL -} - publishing { publications { - coreDev(MavenPublication) { + Galacticraft(MavenPublication) { groupId 'micdoodle8.mods' - artifactId 'galacticraft-core' - version project.version + artifactId 'galacticraft' + version project.version.split("-")[1] - artifact coreJar - - artifact coreDevJar { - classifier 'deobf' - } - } - planetsDev(MavenPublication) { - groupId 'micdoodle8.mods' - artifactId 'galacticraft-planets' - version project.version - - artifact planetsJar - - artifact planetsDevJar { - classifier 'deobf' - } - } - miccoreDev(MavenPublication) { - groupId 'micdoodle8.mods' - artifactId 'micdoodlecore' - version project.version + artifact jar + artifact deobfJar + artifact sourcesJar + artifact apiJar + + pom { + name = 'Galacticraft' + description = 'An advanced space exploration mod for Minecraft' + url = 'https://github.com/TeamGalacticraft/Galacticraft-Legacy' + scm { + url = 'https://github.com/TeamGalacticraft/Galacticraft-Legacy' + connection = 'scm:git:git://github.com/TeamGalacticraft/Galacticraft-Legacy.git' + developerConnection = 'scm:git:git@github.com:TeamGalacticraft/Galacticraft-Legacy.git' + } + issueManagement { + system = 'github' + url = 'https://github.com/TeamGalacticraft/Galacticraft-Legacy/issues' + } - artifact miccoreJar - - artifact miccoreDevJar { - classifier 'deobf' - } - } - apiDev(MavenPublication) { - groupId 'micdoodle8.mods' - artifactId 'galacticraft-api' - version project.version - - artifact apiJar + licenses { + license { + name = 'custom' + url = 'https://github.com/TeamGalacticraft/Galacticraft-Legacy/blob/master/LICENSE.txt' + } + } + } } } repositories { - mavenLocal() - maven { - url "file:///${project.buildDir}/repo" - } + maven { + name = 'external' + url = 'https://maven.galacticraft.dev/releases' + authentication { + basic(BasicAuthentication) + } + credentials { + username = System.getenv('MAVEN_USER') + password = System.getenv('MAVEN_PASSWORD') + } + } } signing { @@ -113,3 +56,22 @@ publishing { } } } + +tasks.register('PublishToGalacticraftMaven') { + group = 'script-tasks' + description = 'Publishes the Galacticraft publication to the Galacticraft Maven repository.' + dependsOn tasks.withType(PublishToMavenRepository).matching { + it.repository == publishing.repositories.external + + def ver = it.publication.version + def group = it.publication.groupId + def artifact = it.publication.artifactId + + println('************************************************************************') + println('') + println(" compile " + group + ":" + group + ":" + ver) + println(" imlementation " + group + ":" + group + ":" + ver) + println('') + println('************************************************************************') + } +} diff --git a/gradle/resources.gradle b/gradle/resources.gradle index c4796194e7..73da935c91 100644 --- a/gradle/resources.gradle +++ b/gradle/resources.gradle @@ -1,6 +1,6 @@ def resourceTargets = [ 'mcmod.info' ] def intoTargets = [ "$rootDir/out/production/resources/", "$rootDir/out/production/${project.name}.main/", "$rootDir/bin/main/" ] -def replaceProperties = [ mod_version: version.toString().split("-")[1], minecraft_version: mc_version ] +def replaceProperties = [ mod_version: version.toString().split("-")[1], minecraft_version: MC_VERSION ] processResources { inputs.properties replaceProperties @@ -23,7 +23,7 @@ processResources { } } -def modFileTokens = [ gcVersion: version.toString().split("-")[1] ] +def modFileTokens = [ gcVersion: version.toString().split("-")[1], sha1: project.findProperty('signSHA1') ] def included = [ "micdoodle8/mods/galacticraft/core/Constants.java" ] def includedPaths = included.collect { java.nio.file.Paths.get(it) } def expandedSrc = new File(project.buildDir, 'expandedSrc') diff --git a/src/main/java/micdoodle8/mods/galacticraft/core/Constants.java b/src/main/java/micdoodle8/mods/galacticraft/core/Constants.java index 0a2ae3528f..b16e1bbe12 100644 --- a/src/main/java/micdoodle8/mods/galacticraft/core/Constants.java +++ b/src/main/java/micdoodle8/mods/galacticraft/core/Constants.java @@ -9,6 +9,8 @@ public class Constants public static final String MOD_ID_PLANETS = "galacticraftplanets"; public static final String MOD_NAME_SIMPLE = "Galacticraft"; + public static final String FINGERPRINT = "${sha1}"; + // public static final int LOCALMAJVERSION = 4; // public static final int LOCALMINVERSION = 0; // public static final int LOCALPATCHVERSION = 2; @@ -19,10 +21,10 @@ public class Constants @Deprecated @ForRemoval(deadline = "4.1.0") - public static final String DEPENDENCIES_FORGE = "required-after:forge@[14.23.5.2860,); "; // Keep the space at the end! + public static final String DEPENDENCIES_FORGE = "required-after:forge@[14.23.5.2847,); "; // Keep the space at the end! @Deprecated @ForRemoval(deadline = "4.1.0") - public static final String DEPENDENCIES_MICCORE = "required-after:micdoodlecore; "; //Keep the space at the end! + public static final String DEPENDENCIES_MICCORE = "required-after:micdoodlecore; "; //Keep the space at the end! @Deprecated @ForRemoval(deadline = "4.1.0") public static final String DEPENDENCIES_MODS = "after:ic2; after:tconstruct; after:mantle;"; diff --git a/src/main/java/micdoodle8/mods/galacticraft/core/GalacticraftCore.java b/src/main/java/micdoodle8/mods/galacticraft/core/GalacticraftCore.java index b56d66a9d7..4a0569f7d0 100644 --- a/src/main/java/micdoodle8/mods/galacticraft/core/GalacticraftCore.java +++ b/src/main/java/micdoodle8/mods/galacticraft/core/GalacticraftCore.java @@ -174,6 +174,7 @@ import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.Mod.Instance; import net.minecraftforge.fml.common.SidedProxy; +import net.minecraftforge.fml.common.event.FMLFingerprintViolationEvent; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLInterModComms; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; @@ -194,15 +195,14 @@ import net.minecraftforge.server.permission.DefaultPermissionLevel; import net.minecraftforge.server.permission.PermissionAPI; -//@formatter:off @Mod(modid = Constants.MOD_ID_CORE, name = GalacticraftCore.NAME, version = Constants.VERSION, dependencies = "required-after:forge@[14.23.5.2860,);", useMetadata = true, acceptedMinecraftVersions = "[1.12, 1.13)", - guiFactory = "micdoodle8.mods.galacticraft.core.client.gui.screen.ConfigGuiFactoryCore") -//@formatter:on + guiFactory = "micdoodle8.mods.galacticraft.core.client.gui.screen.ConfigGuiFactoryCore", + certificateFingerprint = Constants.FINGERPRINT) public class GalacticraftCore { @@ -259,6 +259,13 @@ public GalacticraftCore() FluidRegistry.enableUniversalBucket(); } + @EventHandler + public void onFingerprintViolation(FMLFingerprintViolationEvent event) + { + if (!GCCoreUtil.isDeobfuscated()) + logger.warn("Invalid fingerprint detected! The file " + event.getSource().getName() + " may have been tampered with. This version will NOT be supported by the author!"); + } + @EventHandler public void preInit(FMLPreInitializationEvent event) { diff --git a/src/main/java/micdoodle8/mods/galacticraft/planets/GalacticraftPlanets.java b/src/main/java/micdoodle8/mods/galacticraft/planets/GalacticraftPlanets.java index 1e5c269638..75a9811fa4 100644 --- a/src/main/java/micdoodle8/mods/galacticraft/planets/GalacticraftPlanets.java +++ b/src/main/java/micdoodle8/mods/galacticraft/planets/GalacticraftPlanets.java @@ -28,6 +28,7 @@ import net.minecraftforge.fml.common.Mod.Instance; import net.minecraftforge.fml.common.ModMetadata; import net.minecraftforge.fml.common.SidedProxy; +import net.minecraftforge.fml.common.event.FMLFingerprintViolationEvent; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; @@ -37,15 +38,14 @@ import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.relauncher.Side; -@Mod( - modid = Constants.MOD_ID_PLANETS, +@Mod(modid = Constants.MOD_ID_PLANETS, name = GalacticraftPlanets.NAME, version = Constants.VERSION, dependencies = "required-after:galacticraftcore;", useMetadata = false, acceptedMinecraftVersions = "[1.12, 1.13)", - guiFactory = "micdoodle8.mods.galacticraft.planets.ConfigGuiFactoryPlanets" - ) + guiFactory = "micdoodle8.mods.galacticraft.planets.ConfigGuiFactoryPlanets", + certificateFingerprint = Constants.FINGERPRINT) public class GalacticraftPlanets { @@ -65,14 +65,21 @@ public class GalacticraftPlanets public static PlanetsProxy proxy; public static Map> propOrder = new TreeMap<>(); - + public static GalacticLog logger; - + public GalacticraftPlanets() { logger = new GalacticLog(this); } + @EventHandler + public void onFingerprintViolation(FMLFingerprintViolationEvent event) + { + if (!GCCoreUtil.isDeobfuscated()) + logger.warn("Invalid fingerprint detected! The file " + event.getSource().getName() + " may have been tampered with. This version will NOT be supported by the author!"); + } + @EventHandler public void preInit(FMLPreInitializationEvent event) { diff --git a/src/main/java/micdoodle8/mods/miccore/MicdoodlePlugin.java b/src/main/java/micdoodle8/mods/miccore/MicdoodlePlugin.java index 8a3968d756..adb8834a35 100644 --- a/src/main/java/micdoodle8/mods/miccore/MicdoodlePlugin.java +++ b/src/main/java/micdoodle8/mods/miccore/MicdoodlePlugin.java @@ -14,8 +14,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -@IFMLLoadingPlugin.TransformerExclusions(value = -{"micdoodle8.mods.miccore"}) +@IFMLLoadingPlugin.TransformerExclusions(value = {"micdoodle8.mods.miccore"}) @MCVersion("1.12.2") public class MicdoodlePlugin implements IFMLLoadingPlugin, IFMLCallHook {