Skip to content

Commit 9f4a9fe

Browse files
committed
8312434: SPECjvm2008/xml.transform with CDS fails with "can't seal package nu.xom"
Reviewed-by: iklam, matsaave
1 parent 7c169a4 commit 9f4a9fe

File tree

6 files changed

+111
-49
lines changed

6 files changed

+111
-49
lines changed

src/hotspot/share/cds/filemap.cpp

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ void SharedClassPathEntry::copy_from(SharedClassPathEntry* ent, ClassLoaderData*
354354
_from_class_path_attr = ent->_from_class_path_attr;
355355
set_name(ent->name(), CHECK);
356356

357-
if (ent->is_jar() && !ent->is_signed() && ent->manifest() != nullptr) {
357+
if (ent->is_jar() && ent->manifest() != nullptr) {
358358
Array<u1>* buf = MetadataFactory::new_array<u1>(loader_data,
359359
ent->manifest_size(),
360360
CHECK);
@@ -608,29 +608,6 @@ class ManifestStream: public ResourceObj {
608608
buf[len] = 0;
609609
return buf;
610610
}
611-
612-
// The return value indicates if the JAR is signed or not
613-
bool check_is_signed() {
614-
u1* attr = _current;
615-
bool isSigned = false;
616-
while (_current < _buffer_end) {
617-
if (*_current == '\n') {
618-
*_current = '\0';
619-
u1* value = (u1*)strchr((char*)attr, ':');
620-
if (value != nullptr) {
621-
assert(*(value+1) == ' ', "Unrecognized format" );
622-
if (strstr((char*)attr, "-Digest") != nullptr) {
623-
isSigned = true;
624-
break;
625-
}
626-
}
627-
*_current = '\n'; // restore
628-
attr = _current + 1;
629-
}
630-
_current ++;
631-
}
632-
return isSigned;
633-
}
634611
};
635612

636613
void FileMapInfo::update_jar_manifest(ClassPathEntry *cpe, SharedClassPathEntry* ent, TRAPS) {
@@ -643,18 +620,14 @@ void FileMapInfo::update_jar_manifest(ClassPathEntry *cpe, SharedClassPathEntry*
643620
if (manifest != nullptr) {
644621
ManifestStream* stream = new ManifestStream((u1*)manifest,
645622
manifest_size);
646-
if (stream->check_is_signed()) {
647-
ent->set_is_signed();
648-
} else {
649-
// Copy the manifest into the shared archive
650-
manifest = ClassLoaderExt::read_raw_manifest(THREAD, cpe, &manifest_size);
651-
Array<u1>* buf = MetadataFactory::new_array<u1>(loader_data,
652-
manifest_size,
653-
CHECK);
654-
char* p = (char*)(buf->data());
655-
memcpy(p, manifest, manifest_size);
656-
ent->set_manifest(buf);
657-
}
623+
// Copy the manifest into the shared archive
624+
manifest = ClassLoaderExt::read_raw_manifest(THREAD, cpe, &manifest_size);
625+
Array<u1>* buf = MetadataFactory::new_array<u1>(loader_data,
626+
manifest_size,
627+
CHECK);
628+
char* p = (char*)(buf->data());
629+
memcpy(p, manifest, manifest_size);
630+
ent->set_manifest(buf);
658631
}
659632
}
660633

src/hotspot/share/cds/filemap.hpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ class SharedClassPathEntry : public MetaspaceObj {
5353
enum {
5454
modules_image_entry,
5555
jar_entry,
56-
signed_jar_entry,
5756
dir_entry,
5857
non_existent_entry,
5958
unknown_entry
@@ -90,10 +89,6 @@ class SharedClassPathEntry : public MetaspaceObj {
9089
bool is_dir() const { return _type == dir_entry; }
9190
bool is_modules_image() const { return _type == modules_image_entry; }
9291
bool is_jar() const { return _type == jar_entry; }
93-
bool is_signed() const { return _type == signed_jar_entry; }
94-
void set_is_signed() {
95-
_type = signed_jar_entry;
96-
}
9792
bool from_class_path_attr() { return _from_class_path_attr; }
9893
time_t timestamp() const { return _timestamp; }
9994
const char* name() const;

test/hotspot/jtreg/runtime/cds/appcds/JarBuilder.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2023, 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
@@ -259,21 +259,36 @@ public static void compileModule(Path src,
259259
}
260260
}
261261

262+
static final String keyTool = JDKToolFinder.getJDKTool("keytool");
263+
static final String jarSigner = JDKToolFinder.getJDKTool("jarsigner");
262264

263-
public static void signJar() throws Exception {
264-
String keyTool = JDKToolFinder.getJDKTool("keytool");
265-
String jarSigner = JDKToolFinder.getJDKTool("jarsigner");
265+
public static void signJarWithDisabledAlgorithm(String jarName) throws Exception {
266+
String keyName = "key_with_disabled_alg";
267+
executeProcess(keyTool,
268+
"-genkey", "-keystore", "./keystore", "-alias", keyName,
269+
"-storepass", "abc123", "-keypass", "abc123", "-keyalg", "dsa",
270+
"-sigalg", "SHA1withDSA", "-keysize", "512", "-dname", "CN=jvmtest2")
271+
.shouldHaveExitValue(0);
266272

273+
doSigning(jarName, keyName);
274+
}
275+
276+
public static void signJar(String jarName) throws Exception {
277+
String keyName = "mykey";
267278
executeProcess(keyTool,
268-
"-genkey", "-keystore", "./keystore", "-alias", "mykey",
279+
"-genkey", "-keystore", "./keystore", "-alias", keyName,
269280
"-storepass", "abc123", "-keypass", "abc123", "-keyalg", "dsa",
270281
"-dname", "CN=jvmtest")
271282
.shouldHaveExitValue(0);
272283

284+
doSigning(jarName, keyName);
285+
}
286+
287+
private static void doSigning(String jarName, String keyName) throws Exception {
273288
executeProcess(jarSigner,
274289
"-keystore", "./keystore", "-storepass", "abc123", "-keypass",
275-
"abc123", "-signedjar", getJarFilePath("signed_hello"),
276-
getJarFilePath("hello"), "mykey")
290+
"abc123", "-signedjar", getJarFilePath("signed_" + jarName),
291+
getJarFilePath(jarName), keyName)
277292
.shouldHaveExitValue(0);
278293
}
279294

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (c) 2023, 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+
/*
26+
* @test
27+
* @bug 8312434
28+
* @summary A jar file containing classes in the same package. Sign the jar file with
29+
* a disabled algorithm. The jar will be treated as unsigned.
30+
* Dump only one class into the CDS archive. During runtime, load the class
31+
* stored in the archive and then load another class not from the archive
32+
* but from the same pacakge. Loading of the second class should not result
33+
* in sealing violation.
34+
*
35+
* @requires vm.cds
36+
* @library /test/lib
37+
* @compile test-classes/GenericTestApp.java test-classes/pkg/ClassInPackage.java test-classes/C2.java
38+
* @run driver jdk.test.lib.helpers.ClassFileInstaller -jar WhiteBox.jar jdk.test.whitebox.WhiteBox
39+
* @run driver SealingViolation
40+
*/
41+
42+
import jdk.test.lib.helpers.ClassFileInstaller;
43+
import jdk.test.lib.process.OutputAnalyzer;
44+
45+
public class SealingViolation {
46+
public static void main(String[] args) throws Exception {
47+
String[] classList = {"pkg/ClassInPackage"};
48+
String appJar = ClassFileInstaller.writeJar("pkg-classes-sealed.jar",
49+
ClassFileInstaller.Manifest.fromSourceFile("test-classes/pkg/package_seal.mf"),
50+
"GenericTestApp", "pkg/ClassInPackage", "pkg/C2");
51+
52+
JarBuilder.signJarWithDisabledAlgorithm("pkg-classes-sealed");
53+
String signedJar = TestCommon.getTestJar("pkg-classes-sealed.jar");
54+
55+
// GenericTestApp requires WhiteBox
56+
String wbJar = ClassFileInstaller.getJarPath("WhiteBox.jar");
57+
String bootclasspath = "-Xbootclasspath/a:" + wbJar;
58+
59+
OutputAnalyzer output = TestCommon.dump(signedJar, classList, bootclasspath,
60+
"-Xlog:cds+class=debug");
61+
output.shouldMatch("cds.class.*klasses.*app pkg.ClassInPackage")
62+
.shouldHaveExitValue(0);
63+
64+
output = TestCommon.exec(signedJar, "-Xlog:cds=debug,class+load",
65+
bootclasspath,
66+
"-XX:+UnlockDiagnosticVMOptions",
67+
"-XX:+WhiteBoxAPI",
68+
"GenericTestApp",
69+
"assertShared:pkg.ClassInPackage",
70+
"assertNotShared:pkg.C2");
71+
output.shouldHaveExitValue(0);
72+
}
73+
}

test/hotspot/jtreg/runtime/cds/appcds/SignedJar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
public class SignedJar {
3939
public static void main(String[] args) throws Exception {
4040
String unsignedJar = JarBuilder.getOrCreateHelloJar();
41-
JarBuilder.signJar();
41+
JarBuilder.signJar("hello");
4242

4343
// Test class exists in signed JAR
4444
String signedJar = TestCommon.getTestJar("signed_hello.jar");
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Manifest-Version: 1.0
2+
Created-By: 1.9.0-internal (Oracle Corporation)
3+
4+
Name: pkg/
5+
Sealed: true
6+

0 commit comments

Comments
 (0)