mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-13 00:37:52 +00:00
Log a warning if a coremod does not follow best practices (#4146)
This commit is contained in:
1 parent
fb10d7cbd4
commit
cc25a58760
3 files changed
+47
-13
No files matched your search
@@ -19,6 +19,8 @@
|
||||
|
||||
package net.minecraftforge.fml.common;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.cert.Certificate;
|
||||
@@ -27,6 +29,21 @@ public class CertificateHelper {
|
||||
|
||||
private static final String HEXES = "0123456789abcdef";
|
||||
|
||||
public static ImmutableList<String> getFingerprints(Certificate[] certificates)
|
||||
{
|
||||
int len = 0;
|
||||
if (certificates != null)
|
||||
{
|
||||
len = certificates.length;
|
||||
}
|
||||
ImmutableList.Builder<String> certBuilder = ImmutableList.builder();
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
certBuilder.add(CertificateHelper.getFingerprint(certificates[i]));
|
||||
}
|
||||
return certBuilder.build();
|
||||
}
|
||||
|
||||
public static String getFingerprint(Certificate certificate)
|
||||
{
|
||||
if (certificate == null)
|
||||
|
||||
@@ -530,18 +530,7 @@ public class FMLModContainer implements ModContainer
|
||||
Class<?> clazz = Class.forName(className, true, modClassLoader);
|
||||
|
||||
Certificate[] certificates = clazz.getProtectionDomain().getCodeSource().getCertificates();
|
||||
int len = 0;
|
||||
if (certificates != null)
|
||||
{
|
||||
len = certificates.length;
|
||||
}
|
||||
Builder<String> certBuilder = ImmutableList.builder();
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
certBuilder.add(CertificateHelper.getFingerprint(certificates[i]));
|
||||
}
|
||||
|
||||
ImmutableList<String> certList = certBuilder.build();
|
||||
ImmutableList<String> certList = CertificateHelper.getFingerprints(certificates);
|
||||
sourceFingerprints = ImmutableSet.copyOf(certList);
|
||||
|
||||
String expectedFingerprint = (String)descriptor.get("certificateFingerprint");
|
||||
|
||||
@@ -29,6 +29,7 @@ import java.lang.reflect.Method;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.security.cert.Certificate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
@@ -46,6 +47,7 @@ import com.google.common.io.Files;
|
||||
import net.minecraft.launchwrapper.ITweaker;
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
import net.minecraftforge.fml.common.CertificateHelper;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.common.asm.ASMTransformerWrapper;
|
||||
import net.minecraftforge.fml.common.asm.transformers.ModAccessTransformer;
|
||||
@@ -408,7 +410,7 @@ public class CoreModManager {
|
||||
}
|
||||
else
|
||||
{
|
||||
FMLLog.log.trace("Found FMLCorePluginContainsFMLMod marker in {}, it will be examined later for regular @Mod instances",
|
||||
FMLLog.log.warn("Found FMLCorePluginContainsFMLMod marker in {}. This is not recommended, @Mods should be in a separate jar from the coremod.",
|
||||
coreMod.getName());
|
||||
candidateModFiles.add(coreMod.getName());
|
||||
}
|
||||
@@ -591,6 +593,32 @@ public class CoreModManager {
|
||||
SortingIndex index = coreModClazz.getAnnotation(IFMLLoadingPlugin.SortingIndex.class);
|
||||
int sortIndex = index != null ? index.value() : 0;
|
||||
|
||||
Certificate[] certificates = coreModClazz.getProtectionDomain().getCodeSource().getCertificates();
|
||||
ImmutableList<String> certList = CertificateHelper.getFingerprints(certificates);
|
||||
if (certList.isEmpty())
|
||||
{
|
||||
if (deobfuscatedEnvironment && Arrays.asList(rootPlugins).contains(coreModClass)) //This is probably a forge/mod dev environment - ignore missing forge certificates
|
||||
{
|
||||
FMLLog.log.info("Ignoring missing certificate for coremod {} ({}), we are in deobf and it's a forge core plugin", coreModName, coreModClass);
|
||||
}
|
||||
else if (deobfuscatedEnvironment && location == null) // This is probably a mod dev workspace
|
||||
{
|
||||
FMLLog.log.info("Ignoring missing certificate for coremod {} ({}), as this is a probably dev workspace", coreModName, coreModClass);
|
||||
}
|
||||
else // This is a probably a normal minecraft workspace - log at warn
|
||||
{
|
||||
FMLLog.log.warn("The coremod {} ({}) is not signed!", coreModName, coreModClass);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FMLLog.log.debug("Found signing certificates for coremod {} ({})", coreModName, coreModClass);
|
||||
for (String cert : certList)
|
||||
{
|
||||
FMLLog.log.debug("Found certificate {}", cert);
|
||||
}
|
||||
}
|
||||
|
||||
IFMLLoadingPlugin plugin = (IFMLLoadingPlugin) coreModClazz.newInstance();
|
||||
String accessTransformerClass = plugin.getAccessTransformerClass();
|
||||
if (accessTransformerClass != null)
|
||||
|
||||
Reference in new issue
Block a user