Path: blob/master/test/jdk/sun/security/tools/keytool/fakecacerts/TrustedCRL.java
41154 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 824414826* @summary Test keytool -printcrl with -keystore and -trustcacerts options27* @library /test/lib28* @library /test/jdk/sun/security/util/module_patch29* @build java.base/sun.security.util.FilePaths30* @modules java.base/sun.security.util31* java.base/jdk.internal.misc32* @run main TrustedCRL33*/3435import jdk.test.lib.SecurityTools;36import jdk.test.lib.process.OutputAnalyzer;37import jdk.test.lib.security.KeyStoreUtils;3839import java.io.File;40import java.io.IOException;41import java.nio.file.Files;42import java.nio.file.Paths;4344public class TrustedCRL {4546// The --patch-module must be explicitly specified on the keytool47// command line because it's in a separate process48private static final String PATCH_OPTION;4950static {51String tmp = "";52for (String a : jdk.internal.misc.VM.getRuntimeArguments()) {53if (a.startsWith("--patch-module")) {54tmp = "-J" + a + " ";55break;56}57}58PATCH_OPTION = tmp;59}6061static OutputAnalyzer kt(String cmd) throws Exception {62return SecurityTools.keytool(cmd + " -keystore ks"63+ " -storepass changeit")64.shouldHaveExitValue(0);65}6667static OutputAnalyzer patchcmd(String cmd, String options)68throws Exception {69return kt(PATCH_OPTION + " -" + cmd + " " + options);70}7172static void rm(String s) throws IOException {73System.out.println("---------------------------------------------");74System.out.println("$ rm " + s);75Files.deleteIfExists(Paths.get(s));76}7778public static void main(String[] args) throws Exception {7980// Test -printcrl with root CA in cacerts keystore81kt("-genkeypair -alias myca -dname CN=CA -keyalg RSA"82+ " -keysize 1024 -sigalg SHA1withRSA");8384kt("-exportcert -alias myca -rfc -file ca.pem");8586// import root CA to mycacerts keystore87KeyStoreUtils.createCacerts("mycacerts", "ca.pem");8889kt("-gencrl -alias myca -id 0 -file ca.crl -sigalg MD5withRSA");9091patchcmd("printcrl", "-file ca.crl -trustcacerts")92.shouldMatch("Verified by.*in cacerts");9394// Test -printcrl with root CA in local keystore95kt("-gencrl -alias myca -id 0 -file ca.crl");9697kt("-printcrl -file ca.crl")98.shouldMatch("Verified by.*in keystore");99}100}101102103