Path: blob/master/test/jdk/sun/security/tools/jarsigner/CertPolicy.java
41152 views
/*1* Copyright (c) 2014, 2019, 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 803670926* @summary Java 7 jarsigner displays warning about cert policy tree27* @library /test/lib28*/2930import jdk.test.lib.SecurityTools;31import jdk.test.lib.process.OutputAnalyzer;32import jdk.test.lib.util.JarUtils;3334import java.io.FileOutputStream;35import java.io.PrintStream;36import java.nio.file.Files;37import java.nio.file.Path;38import java.util.List;3940public class CertPolicy {41static OutputAnalyzer keytool(String cmd) throws Exception {42return SecurityTools.keytool("-keypass changeit -storepass changeit "43+ "-keystore ks -keyalg rsa " + cmd);44}4546static OutputAnalyzer jarsigner(String cmd) throws Exception {47return SecurityTools.jarsigner("-storepass changeit -keystore ks " + cmd);48}4950public static void main(String[] args) throws Exception {5152keytool("-genkeypair -alias ca -dname CN=CA -ext bc");53keytool("-genkeypair -alias int -dname CN=Int");54keytool("-genkeypair -alias ee -dname CN=EE");5556// CertificatePolicies [[PolicyId: [1.2.3]], [PolicyId: [1.2.4]]]57// PolicyConstraints: [Require: 0; Inhibit: unspecified]58keytool("-certreq -alias int -file int.req");59keytool("-gencert -rfc -alias ca "60+ "-ext 2.5.29.32=300C300406022A03300406022A04 "61+ "-ext 2.5.29.36=3003800100 "62+ "-ext bc -infile int.req -outfile int.cert");63keytool("-import -alias int -file int.cert");6465// CertificatePolicies [[PolicyId: [1.2.3]]]66keytool("-certreq -alias ee -file ee.req");67keytool("-gencert -rfc -alias int -ext 2.5.29.32=3006300406022A03 "68+ "-infile ee.req -outfile ee.cert");69keytool("-import -alias ee -file ee.cert");7071Files.write(Path.of("cc"), List.of(72keytool("-export -alias ee -rfc").getOutput(),73keytool("-export -alias int -rfc").getOutput(),74keytool("-export -alias ca -rfc").getOutput()));7576keytool("-delete -alias int");7778JarUtils.createJarFile(Path.of("a.jar"), Path.of("."), Path.of("cc"));7980// Make sure the certchain in the signed jar contains all 3 certs81jarsigner("-strict -certchain cc a.jar ee -debug")82.shouldHaveExitValue(0);8384jarsigner("-strict -verify a.jar -debug")85.shouldHaveExitValue(0);86}87}888990