Commit e0030094 authored by Phillip Webb's avatar Phillip Webb

Fix missing jar entry certificates

Ensure that the source jar entry is closed before reading
certificates and code signers from the entry.

gh-19041
parent d73ee9d5
...@@ -353,11 +353,12 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable<JarEntry> { ...@@ -353,11 +353,12 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable<JarEntry> {
try (JarInputStream certifiedJarStream = new JarInputStream(this.jarFile.getData().getInputStream())) { try (JarInputStream certifiedJarStream = new JarInputStream(this.jarFile.getData().getInputStream())) {
java.util.jar.JarEntry certifiedEntry = null; java.util.jar.JarEntry certifiedEntry = null;
while ((certifiedEntry = certifiedJarStream.getNextJarEntry()) != null) { while ((certifiedEntry = certifiedJarStream.getNextJarEntry()) != null) {
// Entry must be closed to trigger a read and set entry certificates
certifiedJarStream.closeEntry();
int index = getEntryIndex(certifiedEntry.getName()); int index = getEntryIndex(certifiedEntry.getName());
if (index != -1) { if (index != -1) {
certifications[index] = JarEntryCertification.from(certifiedEntry); certifications[index] = JarEntryCertification.from(certifiedEntry);
} }
certifiedJarStream.closeEntry();
} }
} }
this.certifications = certifications; this.certifications = certifications;
......
...@@ -385,10 +385,13 @@ public class JarFileTests { ...@@ -385,10 +385,13 @@ public class JarFileTests {
while (actualEntries.hasMoreElements()) { while (actualEntries.hasMoreElements()) {
JarEntry actualEntry = actualEntries.nextElement(); JarEntry actualEntry = actualEntries.nextElement();
java.util.jar.JarEntry expectedEntry = expected.getJarEntry(actualEntry.getName()); java.util.jar.JarEntry expectedEntry = expected.getJarEntry(actualEntry.getName());
assertThat(actualEntry.getCertificates()).as(actualEntry.getName()) StreamUtils.drain(expected.getInputStream(expectedEntry));
.isEqualTo(expectedEntry.getCertificates()); if (!actualEntry.getName().equals("META-INF/MANIFEST.MF")) {
assertThat(actualEntry.getCodeSigners()).as(actualEntry.getName()) assertThat(actualEntry.getCertificates()).as(actualEntry.getName())
.isEqualTo(expectedEntry.getCodeSigners()); .isEqualTo(expectedEntry.getCertificates());
assertThat(actualEntry.getCodeSigners()).as(actualEntry.getName())
.isEqualTo(expectedEntry.getCodeSigners());
}
} }
assertThat(stopWatch.getTotalTimeSeconds()).isLessThan(3.0); assertThat(stopWatch.getTotalTimeSeconds()).isLessThan(3.0);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment