<html><head></head><body><div>Hi,</div><div><br></div><div>Following up [1], [2] and to some extent [3] find a new patch attached.</div><div><br></div><div>Apart from ManifestDigester having problems parsing manifests with \r for the line break, manifests without a trailing blank line are not processed correctly in all cases. As an example, look at the existing diffend.sh test which produces a jar diffend.new.jar file with an invalid signature on lines 88..93. Jarsigner fails to detect this and so does the test. The resulting manifest is missing a blank line after the main attributes section and looks like this:</div><div><br></div><div>Manifest-Version: 1.0</div><div>Created-By: 1.7.0-internal (Sun Microsystems Inc.)</div><div>Today: Monday</div><div>Name: 1</div><div>SHA1-Digest: 5fpE8rMcH7VTtgIec2DQfV2R/14=</div><div></div><div><br></div><div>Another speciality is that endOfSection contains a blank line if and only if that blank line is at the very end of the manifest file (or stream or byte array). This makes digestWorkaround useless in that case because digestWorkaround is then the same as digest without workaround. Initially I thought, the missing lines after the last section could be compensated by digestWorkaround which essentially produces a digest without the trailing blank line but digestWorkaround is not applied to main attributes and if successful would set SignatureFileVerifier.workaround flag that would remain set for subsequent digests which are processed in the order of the entries of the signature file which is hard to predict and certainly does not support to assume that the last manifest entry would be verified last.</div><div><br></div><div>As a starting point for further discussions, I'd like to suggest that jarsigner keeps main attributes without a trailing blank line if there are no files contained in the jar to sign. I wonder if this is worth it but at least I believe that this is the most backwards-compatible option possible. A trailing line is then added only when necessary and the resulting jarfile would be invalid without as in the example above with diffend.sh.</div><div><br></div><div>Any feedback and opinions welcome.</div><div><br></div><div>Regards,</div><div>Philipp</div><div><br></div><div><br></div><div>[1] <a href="https://mail.openjdk.java.net/pipermail/security-dev/2019-January/019200.html">https://mail.openjdk.java.net/pipermail/security-dev/2019-January/019200.html</a></div><div>[2] <a href="https://mail.openjdk.java.net/pipermail/security-dev/2019-January/019213.html">https://mail.openjdk.java.net/pipermail/security-dev/2019-January/019213.html</a></div><div>[3] <a href="https://mail.openjdk.java.net/pipermail/core-libs-dev/2019-February/058774.html">https://mail.openjdk.java.net/pipermail/core-libs-dev/2019-February/058774.html</a></div><div>[4] <a href="https://bugs.openjdk.java.net/browse/JDK-8217375">https://bugs.openjdk.java.net/browse/JDK-8217375</a></div><div><br></div></body></html>