Path: blob/master/test/jdk/java/security/Security/signedfirst/DynStatic.java
66645 views
/*1* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22/*23* @test24* @bug 4504355 474426025* @summary problems if signed crypto provider is the most preferred provider26* @modules java.base/sun.security.tools.keytool27* jdk.jartool/sun.security.tools.jarsigner28* @library /test/lib29* @run main/othervm DynStatic30*/3132import java.io.File;33import java.nio.file.Path;34import java.nio.file.Paths;35import java.util.List;3637import jdk.test.lib.compiler.CompilerUtils;38import jdk.test.lib.process.ProcessTools;39import jdk.test.lib.util.JarUtils;4041public class DynStatic {4243private static final String TEST_SRC =44Paths.get(System.getProperty("test.src")).toString();45private static final Path TEST_CLASSES =46Paths.get(System.getProperty("test.classes"));4748private static final Path EXP_SRC_DIR = Paths.get(TEST_SRC, "com");49private static final Path EXP_DEST_DIR = Paths.get("build");50private static final Path DYN_SRC =51Paths.get(TEST_SRC, "DynSignedProvFirst.java");52private static final Path STATIC_SRC =53Paths.get(TEST_SRC, "StaticSignedProvFirst.java");5455private static final String STATIC_PROPS =56Paths.get(TEST_SRC, "Static.props").toString();5758public static void main(String[] args) throws Exception {5960// Compile the provider61CompilerUtils.compile(EXP_SRC_DIR, EXP_DEST_DIR);6263// Create a jar file containing the provider64JarUtils.createJarFile(Path.of("exp.jar"), EXP_DEST_DIR, "com");6566// Create a keystore67sun.security.tools.keytool.Main.main(68("-genkeypair -dname CN=Signer -keystore exp.ks -storepass "69+ "changeit -keypass changeit -keyalg rsa").split(" "));7071// Sign jar72sun.security.tools.jarsigner.Main.main(73"-storepass changeit -keystore exp.ks exp.jar mykey"74.split(" "));7576// Compile the DynSignedProvFirst test program77CompilerUtils.compile(DYN_SRC, TEST_CLASSES, "-classpath", "exp.jar");7879// Run the DynSignedProvFirst test program80ProcessTools.executeTestJvm("-classpath",81TEST_CLASSES.toString() + File.pathSeparator + "exp.jar",82"DynSignedProvFirst")83.shouldContain("test passed");8485// Compile the StaticSignedProvFirst test program86CompilerUtils.compile(STATIC_SRC, TEST_CLASSES, "-classpath", "exp.jar");8788// Run the StaticSignedProvFirst test program89ProcessTools.executeTestJvm("-classpath",90TEST_CLASSES.toString() + File.pathSeparator + "exp.jar",91"-Djava.security.properties=file:" + STATIC_PROPS,92"StaticSignedProvFirst")93.shouldContain("test passed");94}95}969798