Fix up jar sanity check code. FML validation of the jar works now and doesn't derp classloading.

This commit is contained in:
Christian 2013-07-14 13:11:32 -04:00
parent 8f2823709c
commit d0c2a8e62b

View file

@ -124,14 +124,15 @@ public class FMLSanityChecker implements IFMLCallHook
}
boolean goodMC = FMLLaunchHandler.side() == Side.SERVER; //Server is not signed, so assume it's good.
int certCount = 0;
try
{
Class cbr = Class.forName("net.minecraft.server.MinecraftServer",false, cl);
Class cbr = Class.forName("net.minecraft.client.ClientBrandRetriever",false, cl);
codeSource = cbr.getProtectionDomain().getCodeSource();
}
catch (Exception e)
{
// Probably a development environment
// Probably a development environment, or the server (the server is not signed)
goodMC = true;
}
if (fmlIsJar && !goodMC && codeSource.getLocation().getProtocol().equals("jar"))
@ -143,9 +144,10 @@ public class FMLSanityChecker implements IFMLCallHook
mcPath = URLDecoder.decode(mcPath, Charsets.UTF_8.name());
JarFile mcJarFile = new JarFile(mcPath,true);
mcJarFile.getManifest();
JarEntry serverEntry = mcJarFile.getJarEntry("net/minecraft/server/MinecraftServer.class");
ByteStreams.toByteArray(mcJarFile.getInputStream(serverEntry));
Certificate[] certificates = serverEntry.getCertificates();
JarEntry cbrEntry = mcJarFile.getJarEntry("net/minecraft/client/ClientBrandRetriever.class");
ByteStreams.toByteArray(mcJarFile.getInputStream(cbrEntry));
Certificate[] certificates = cbrEntry.getCertificates();
certCount = certificates != null ? certificates.length : 0;
if (certificates!=null)
{
@ -175,12 +177,16 @@ public class FMLSanityChecker implements IFMLCallHook
if (!Boolean.parseBoolean(System.getProperty("fml.ignoreInvalidMinecraftCertificates","false")))
{
FMLRelaunchLog.severe("For your safety, FML will not launch minecraft. You will need to fetch a clean version of the minecraft jar file");
FMLRelaunchLog.severe("Technical information: The class net.minecraft.client.ClientBrandRetriever should have been associated with the minecraft jar file, " +
"and should have returned us a valid, intact minecraft jar location. This did not work. Either you have modified the minecraft jar file (if so " +
"run the forge installer again), or you are using a base editing jar that is changing this class (and likely others too). If you REALLY " +
"want to run minecraft in this configuration, add the flag -Dfml.ignoreInvalidMinecraftCertificates=true to the 'JVM settings' in your launcher profile.");
System.exit(1);
}
else
{
FMLRelaunchLog.severe("FML has been ordered to ignore the invalid or missing minecraft certificate. THIS IS A VERY DANGEROUS THING TO DO");
FMLRelaunchLog.severe("FML has been ordered to ignore the invalid or missing minecraft certificate. This is very likely to cause a problem!");
FMLRelaunchLog.severe("Technical information: ClientBrandRetriever was at %s, there were %d certificates for it", codeSource.getLocation(), certCount);
}
}
if (!goodFML)
@ -218,7 +224,6 @@ public class FMLSanityChecker implements IFMLCallHook
cl = (LaunchClassLoader) data.get("classLoader");
File mcDir = (File)data.get("mcLocation");
FMLDeobfuscatingRemapper.INSTANCE.setup(mcDir, cl, (String) data.get("deobfuscationFileName"));
File binpatches = new File(mcDir,"binpatch");
ClassPatchManager.INSTANCE.setup(FMLLaunchHandler.side());
}