Skip to content

Commit e003009

Browse files
committed
Fix missing jar entry certificates
Ensure that the source jar entry is closed before reading certificates and code signers from the entry. gh-19041
1 parent d73ee9d commit e003009

File tree

2 files changed

+9
-5
lines changed
  • spring-boot-project/spring-boot-tools/spring-boot-loader/src

2 files changed

+9
-5
lines changed

spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFileEntries.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,11 +353,12 @@ JarEntryCertification getCertification(JarEntry entry) throws IOException {
353353
try (JarInputStream certifiedJarStream = new JarInputStream(this.jarFile.getData().getInputStream())) {
354354
java.util.jar.JarEntry certifiedEntry = null;
355355
while ((certifiedEntry = certifiedJarStream.getNextJarEntry()) != null) {
356+
// Entry must be closed to trigger a read and set entry certificates
357+
certifiedJarStream.closeEntry();
356358
int index = getEntryIndex(certifiedEntry.getName());
357359
if (index != -1) {
358360
certifications[index] = JarEntryCertification.from(certifiedEntry);
359361
}
360-
certifiedJarStream.closeEntry();
361362
}
362363
}
363364
this.certifications = certifications;

spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/JarFileTests.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,13 @@ public void verifySignedJar() throws Exception {
385385
while (actualEntries.hasMoreElements()) {
386386
JarEntry actualEntry = actualEntries.nextElement();
387387
java.util.jar.JarEntry expectedEntry = expected.getJarEntry(actualEntry.getName());
388-
assertThat(actualEntry.getCertificates()).as(actualEntry.getName())
389-
.isEqualTo(expectedEntry.getCertificates());
390-
assertThat(actualEntry.getCodeSigners()).as(actualEntry.getName())
391-
.isEqualTo(expectedEntry.getCodeSigners());
388+
StreamUtils.drain(expected.getInputStream(expectedEntry));
389+
if (!actualEntry.getName().equals("META-INF/MANIFEST.MF")) {
390+
assertThat(actualEntry.getCertificates()).as(actualEntry.getName())
391+
.isEqualTo(expectedEntry.getCertificates());
392+
assertThat(actualEntry.getCodeSigners()).as(actualEntry.getName())
393+
.isEqualTo(expectedEntry.getCodeSigners());
394+
}
392395
}
393396
assertThat(stopWatch.getTotalTimeSeconds()).isLessThan(3.0);
394397
}

0 commit comments

Comments
 (0)