Skip to content

Commit eca2032

Browse files
committed
8365559: jarsigner shows files non-existent if signed with a weak algorithm
Reviewed-by: abarashev, wetmore
1 parent 95577ca commit eca2032

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

src/jdk.jartool/share/classes/sun/security/tools/jarsigner/Main.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,11 @@ void verifyJar(String jarName)
876876
sb.append('|');
877877
}
878878

879+
// If the file exists, remove it from all entries in entriesInSF
880+
for (var signed : entriesInSF.values()) {
881+
signed.remove(name);
882+
}
883+
879884
// When -certs provided, display info has extra empty
880885
// lines at the beginning and end.
881886
if (isSigned) {
@@ -890,9 +895,6 @@ void verifyJar(String jarName)
890895
sb.append('\n');
891896
}
892897
}
893-
for (var signed : entriesInSF.values()) {
894-
signed.remove(name);
895-
}
896898
} else if (showcerts && !verbose.equals("all")) {
897899
// Print no info for unsigned entries when -verbose:all,
898900
// to be consistent with old behavior.

test/jdk/sun/security/tools/jarsigner/RemovedFiles.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
2323

2424
/*
2525
* @test
26-
* @bug 8309841
26+
* @bug 8309841 8365559
2727
* @summary Jarsigner should print a warning if an entry is removed
2828
* @library /test/lib
2929
*/
@@ -40,8 +40,15 @@ public class RemovedFiles {
4040

4141
private static final String NONEXISTENT_ENTRIES_FOUND
4242
= "This jar contains signed entries for files that do not exist. See the -verbose output for more details.";
43+
private static final String WEAK_UNSIGNED
44+
= "The jar will be treated as unsigned, because it is signed with a weak algorithm that is now disabled";
4345

4446
public static void main(String[] args) throws Exception {
47+
t8309841();
48+
t8365559();
49+
}
50+
51+
static void t8309841() throws Exception {
4552
JarUtils.createJarFile(
4653
Path.of("a.jar"),
4754
Path.of("."),
@@ -89,6 +96,26 @@ public static void main(String[] args) throws Exception {
8996
SecurityTools.jarsigner("-verbose -verify b.jar")
9097
.shouldContain("Warning: nonexistent signed entries: [Hello]")
9198
.shouldContain(NONEXISTENT_ENTRIES_FOUND);
99+
}
100+
101+
static void t8365559() throws Exception {
102+
JarUtils.createJarFile(
103+
Path.of("c.jar"),
104+
Path.of("."),
105+
Files.writeString(Path.of("c"), "c"));
106+
SecurityTools.keytool("-genkeypair -storepass changeit -keystore ks -alias w -dname CN=w -keyalg ec");
92107

108+
// Sign the JAR using an already disabled signature algorithm SHA1withECDSA.
109+
// The file can still be signed but verification will treat it as unsigned.
110+
SecurityTools.jarsigner("-storepass changeit -keystore ks c.jar w -sigalg SHA1withECDSA")
111+
.shouldContain("the -sigalg option is considered a security risk and is disabled.");
112+
113+
SecurityTools.jarsigner("-verify c.jar")
114+
.shouldContain(WEAK_UNSIGNED)
115+
.shouldNotContain(NONEXISTENT_ENTRIES_FOUND);
116+
SecurityTools.jarsigner("-verify -verbose c.jar")
117+
.shouldContain(WEAK_UNSIGNED)
118+
.shouldNotContain(NONEXISTENT_ENTRIES_FOUND)
119+
.shouldNotContain("Warning: nonexistent signed entries:");
93120
}
94121
}

0 commit comments

Comments
 (0)