Path: blob/master/test/jdk/sun/security/tools/jarsigner/EnableRevocation.java
41152 views
/*1* Copyright (c) 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 824206026* @summary Add a test to enable revocation check in jarsigner27* @library /test/lib28*/2930import jdk.test.lib.SecurityTools;31import jdk.test.lib.process.OutputAnalyzer;32import jdk.test.lib.util.JarUtils;3334import java.nio.file.Path;3536public class EnableRevocation {3738static OutputAnalyzer kt(String cmd, String ks) throws Exception {39return SecurityTools.keytool("-storepass changeit " + cmd +40" -keystore " + ks);41}4243static void gencert(String owner, String cmd) throws Exception {44kt("-certreq -alias " + owner + " -file tmp.req", "ks");45kt("-gencert -infile tmp.req -outfile tmp.cert " + cmd, "ks");46kt("-importcert -alias " + owner + " -file tmp.cert", "ks");47}4849public static void main(String[] args) throws Exception {5051kt("-genkeypair -keyalg rsa -alias ca -dname CN=CA -ext bc:c", "ks");52kt("-genkeypair -keyalg rsa -alias ca1 -dname CN=CA1", "ks");53kt("-genkeypair -keyalg rsa -alias e1 -dname CN=E1", "ks");5455gencert("ca1", "-alias ca -ext san=dns:ca1 -ext bc:c " +56"-ext crldp=URI:http://localhost:7000/crl.pem " +57"-ext aia=ocsp:URI:http://localhost:7200");5859gencert("e1", "-alias ca1 -ext san=dns:e1 " +60"-ext crldp=URI:http://localhost:7000/crl.pem " +61"-ext aia=ocsp:URI:http://localhost:7100");6263JarUtils.createJarFile(Path.of("a.jar"), Path.of("."), Path.of("ks"));6465//Signing with -revCheck option66SecurityTools.jarsigner("-keystore ks -storepass changeit " +67"-signedjar signeda.jar " +68"-sigalg SHA256withRSA " +69" a.jar e1 -revCheck")70.shouldContain("Contacting OCSP server at")71.shouldContain("Downloading CRL from")72.shouldHaveExitValue(0);7374kt("-exportcert -alias ca -rfc -file cacert", "ks");75kt("-importcert -noprompt -file cacert", "caks");7677// Verifying with -revCheck option78SecurityTools.jarsigner("-verify -certs signeda.jar " +79"-keystore caks -storepass changeit -verbose -debug -revCheck")80.shouldContain("Contacting OCSP server at")81.shouldContain("Downloading CRL from")82.shouldHaveExitValue(0);8384// Verifying with -revCheck and -strict options85SecurityTools.jarsigner("-verify -certs signeda.jar " +86"-keystore caks -storepass changeit " +87"-strict -verbose -debug -revCheck")88.shouldContain("Contacting OCSP server at")89.shouldContain("Downloading CRL from")90.shouldHaveExitValue(4);91}92}939495