-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for stripping Jar signatures when recompiling/remapping F…
…orge (#47) In "legacy" mode, we don't copy over the modding platform Jar unmodified, instead we remap and recompile the source files while copying over resources. This breaks the Jar signatures contained in the MANIFEST.MF, so we need to do the following: - Don't copy signature related resources (META-INF/*.{SF,RSA,EC,DSA}) - Filter out any digests from the MANIFEST.MF we copy (since the SHA-256 values will obviously differ after remapping/recompiling) - While we're at it, don't try to copy the bogus MANIFEST.MF from the source artifact
- Loading branch information
Showing
4 changed files
with
83 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/java/net/neoforged/neoform/runtime/actions/StripManifestDigestContentFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package net.neoforged.neoform.runtime.actions; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.util.Set; | ||
import java.util.jar.Attributes; | ||
import java.util.jar.Manifest; | ||
import java.util.zip.ZipEntry; | ||
|
||
/** | ||
* This content filter will strip signature related attributes from MANIFEST.MF entries. | ||
*/ | ||
public class StripManifestDigestContentFilter implements InjectFromZipFileSource.ContentFilter { | ||
// Theoretically, we'd need to check all digests that the VM supports, but we just go for the most common. | ||
// https://docs.oracle.com/en/java/javase/21/docs/specs/jar/jar.html | ||
private static final Set<Attributes.Name> SIGNATURE_ATTRIBUTES = Set.of( | ||
new Attributes.Name("Magic"), | ||
new Attributes.Name("SHA-256-Digest"), | ||
new Attributes.Name("SHA1-Digest") | ||
); | ||
|
||
public static final StripManifestDigestContentFilter INSTANCE = new StripManifestDigestContentFilter(); | ||
|
||
private StripManifestDigestContentFilter() { | ||
} | ||
|
||
@Override | ||
public void copy(ZipEntry entry, InputStream in, OutputStream out) throws IOException { | ||
if (!entry.getName().equals("META-INF/MANIFEST.MF")) { | ||
in.transferTo(out); | ||
} else { | ||
var manifest = new Manifest(in); | ||
|
||
var it = manifest.getEntries().values().iterator(); | ||
while (it.hasNext()) { | ||
// Remove all signing related attributes | ||
var entryAttrs = it.next(); | ||
entryAttrs.keySet().removeIf(SIGNATURE_ATTRIBUTES::contains); | ||
// Remove entries that no longer have attributes | ||
if (entryAttrs.isEmpty()) { | ||
it.remove(); | ||
} | ||
} | ||
|
||
manifest.write(out); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters