Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/jdk/java/security/Security/signedfirst/DynStatic.java
66645 views
1
/*
2
* Copyright (c) 2021, 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
* @test
25
* @bug 4504355 4744260
26
* @summary problems if signed crypto provider is the most preferred provider
27
* @modules java.base/sun.security.tools.keytool
28
* jdk.jartool/sun.security.tools.jarsigner
29
* @library /test/lib
30
* @run main/othervm DynStatic
31
*/
32
33
import java.io.File;
34
import java.nio.file.Path;
35
import java.nio.file.Paths;
36
import java.util.List;
37
38
import jdk.test.lib.compiler.CompilerUtils;
39
import jdk.test.lib.process.ProcessTools;
40
import jdk.test.lib.util.JarUtils;
41
42
public class DynStatic {
43
44
private static final String TEST_SRC =
45
Paths.get(System.getProperty("test.src")).toString();
46
private static final Path TEST_CLASSES =
47
Paths.get(System.getProperty("test.classes"));
48
49
private static final Path EXP_SRC_DIR = Paths.get(TEST_SRC, "com");
50
private static final Path EXP_DEST_DIR = Paths.get("build");
51
private static final Path DYN_SRC =
52
Paths.get(TEST_SRC, "DynSignedProvFirst.java");
53
private static final Path STATIC_SRC =
54
Paths.get(TEST_SRC, "StaticSignedProvFirst.java");
55
56
private static final String STATIC_PROPS =
57
Paths.get(TEST_SRC, "Static.props").toString();
58
59
public static void main(String[] args) throws Exception {
60
61
// Compile the provider
62
CompilerUtils.compile(EXP_SRC_DIR, EXP_DEST_DIR);
63
64
// Create a jar file containing the provider
65
JarUtils.createJarFile(Path.of("exp.jar"), EXP_DEST_DIR, "com");
66
67
// Create a keystore
68
sun.security.tools.keytool.Main.main(
69
("-genkeypair -dname CN=Signer -keystore exp.ks -storepass "
70
+ "changeit -keypass changeit -keyalg rsa").split(" "));
71
72
// Sign jar
73
sun.security.tools.jarsigner.Main.main(
74
"-storepass changeit -keystore exp.ks exp.jar mykey"
75
.split(" "));
76
77
// Compile the DynSignedProvFirst test program
78
CompilerUtils.compile(DYN_SRC, TEST_CLASSES, "-classpath", "exp.jar");
79
80
// Run the DynSignedProvFirst test program
81
ProcessTools.executeTestJvm("-classpath",
82
TEST_CLASSES.toString() + File.pathSeparator + "exp.jar",
83
"DynSignedProvFirst")
84
.shouldContain("test passed");
85
86
// Compile the StaticSignedProvFirst test program
87
CompilerUtils.compile(STATIC_SRC, TEST_CLASSES, "-classpath", "exp.jar");
88
89
// Run the StaticSignedProvFirst test program
90
ProcessTools.executeTestJvm("-classpath",
91
TEST_CLASSES.toString() + File.pathSeparator + "exp.jar",
92
"-Djava.security.properties=file:" + STATIC_PROPS,
93
"StaticSignedProvFirst")
94
.shouldContain("test passed");
95
}
96
}
97
98