Skip to content

Commit b84ffae

Browse files
committed
8229775: Incorrect warning when jar was signed with -sectionsonly
Reviewed-by: mullan
1 parent 63baaf7 commit b84ffae

2 files changed

Lines changed: 63 additions & 3 deletions

File tree

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,12 @@ void verifyJar(String jarName)
685685
Vector<JarEntry> entriesVec = new Vector<>();
686686
byte[] buffer = new byte[8192];
687687

688+
String suffix1 = "-Digest-Manifest";
689+
String suffix2 = "-Digest-" + ManifestDigester.MF_MAIN_ATTRS;
690+
691+
int suffixLength1 = suffix1.length();
692+
int suffixLength2 = suffix2.length();
693+
688694
Enumeration<JarEntry> entries = jf.entries();
689695
while (entries.hasMoreElements()) {
690696
JarEntry je = entries.nextElement();
@@ -701,9 +707,14 @@ void verifyJar(String jarName)
701707
boolean found = false;
702708
for (Object obj : sf.getMainAttributes().keySet()) {
703709
String key = obj.toString();
704-
if (key.endsWith("-Digest-Manifest")) {
705-
digestMap.put(alias,
706-
key.substring(0, key.length() - 16));
710+
if (key.endsWith(suffix1)) {
711+
digestMap.put(alias, key.substring(
712+
0, key.length() - suffixLength1));
713+
found = true;
714+
break;
715+
} else if (key.endsWith(suffix2)) {
716+
digestMap.put(alias, key.substring(
717+
0, key.length() - suffixLength2));
707718
found = true;
708719
break;
709720
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8229775
27+
* @summary Incorrect warning when jar was signed with -sectionsonly
28+
* @library /test/lib
29+
*/
30+
31+
import jdk.test.lib.SecurityTools;
32+
import jdk.test.lib.util.JarUtils;
33+
34+
import java.nio.file.Files;
35+
import java.nio.file.Path;
36+
37+
public class SectionsOnly {
38+
public static void main(String[] args) throws Exception {
39+
String common = "-storepass changeit -keypass changeit -keystore ks ";
40+
SecurityTools.keytool(common
41+
+ "-keyalg rsa -genkeypair -alias me -dname CN=Me");
42+
JarUtils.createJarFile(Path.of("so.jar"), Path.of("."),
43+
Files.write(Path.of("so.txt"), new byte[0]));
44+
SecurityTools.jarsigner(common + "-sectionsonly so.jar me");
45+
SecurityTools.jarsigner(common + "-verify -verbose so.jar")
46+
.shouldNotContain("Unparsable signature-related file")
47+
.shouldHaveExitValue(0);
48+
}
49+
}

0 commit comments

Comments
 (0)