1
1
/*
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.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
23
23
24
24
/*
25
25
* @test
26
- * @bug 8309841
26
+ * @bug 8309841 8365559
27
27
* @summary Jarsigner should print a warning if an entry is removed
28
28
* @library /test/lib
29
29
*/
@@ -40,8 +40,15 @@ public class RemovedFiles {
40
40
41
41
private static final String NONEXISTENT_ENTRIES_FOUND
42
42
= "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" ;
43
45
44
46
public static void main (String [] args ) throws Exception {
47
+ t8309841 ();
48
+ t8365559 ();
49
+ }
50
+
51
+ static void t8309841 () throws Exception {
45
52
JarUtils .createJarFile (
46
53
Path .of ("a.jar" ),
47
54
Path .of ("." ),
@@ -89,6 +96,26 @@ public static void main(String[] args) throws Exception {
89
96
SecurityTools .jarsigner ("-verbose -verify b.jar" )
90
97
.shouldContain ("Warning: nonexistent signed entries: [Hello]" )
91
98
.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" );
92
107
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:" );
93
120
}
94
121
}
0 commit comments