Path: blob/master/test/jdk/sun/security/tools/jarsigner/DefaultOptions.java
41152 views
/*1* Copyright (c) 2014, 2020, 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*/2223/*24* @test25* @bug 804983426* @summary Two security tools tests do not run with only JRE27* @library /test/lib28*/2930import jdk.test.lib.Asserts;31import jdk.test.lib.SecurityTools;32import jdk.test.lib.process.OutputAnalyzer;33import jdk.test.lib.process.ProcessTools;34import jdk.test.lib.util.JarUtils;3536import java.nio.file.Files;37import java.nio.file.Path;38import java.util.List;39import java.util.jar.JarFile;4041public class DefaultOptions {4243static OutputAnalyzer jarsigner(String cmd) throws Throwable {44ProcessBuilder pb = SecurityTools.getProcessBuilder(45"jarsigner", List.of(cmd.trim().split("\\s+")));46pb.environment().put("PASS", "changeit");47return ProcessTools.executeCommand(pb);48}4950static OutputAnalyzer keytool(String cmd) throws Throwable {51cmd = "-storepass:env PASS -keypass:env PASS -keystore ks " + cmd;52ProcessBuilder pb = SecurityTools.getProcessBuilder(53"keytool", List.of(cmd.trim().split("\\s+")));54pb.environment().put("PASS", "changeit");55return ProcessTools.executeCommand(pb);56}5758public static void main(String[] args) throws Throwable {59keytool("-genkeypair -dname CN=A -alias a -keyalg rsa")60.shouldHaveExitValue(0);61keytool("-genkeypair -dname CN=CA -alias ca -keyalg rsa -ext bc:c")62.shouldHaveExitValue(0);63keytool("-alias a -certreq -file a.req");64keytool("-alias ca -gencert -infile a.req -outfile a.cert");65keytool("-alias a -import -file a.cert").shouldHaveExitValue(0);6667Files.write(Path.of("js.conf"), List.of(68"jarsigner.all = -keystore ${user.dir}/ks -storepass:env PASS "69+ "-debug -strict",70"jarsigner.sign = -digestalg SHA-512",71"jarsigner.verify = -verbose:summary"));7273JarUtils.createJarFile(Path.of("a.jar"), Path.of("."),74Path.of("ks"), Path.of("js.conf"));7576jarsigner("-conf js.conf a.jar a").shouldHaveExitValue(0);77jarsigner("-conf js.conf -verify a.jar").shouldHaveExitValue(0)78.shouldContain("and 1 more");7980try (JarFile jf = new JarFile("a.jar")) {81Asserts.assertTrue(jf.getManifest().getAttributes("ks").keySet()82.stream()83.anyMatch(s -> s.toString().contains("SHA-512-Digest")));84}85}86}878889