Path: blob/master/test/jdk/sun/security/tools/keytool/EmptySubject.java
41152 views
/*1* Copyright (c) 2009, 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 684702626* @summary keytool should be able to generate certreq and cert without subject name27* @library /test/lib28*/2930import jdk.test.lib.SecurityTools;31import jdk.test.lib.process.OutputAnalyzer;3233import java.util.ArrayList;34import java.util.Arrays;35import java.util.List;3637public class EmptySubject{38static final String KS = "emptysubject.jks";39public static void main(String[] args) throws Exception {40kt("-alias", "ca", "-dname", "CN=CA", "-genkeypair");41kt("-alias", "me", "-dname", "CN=Me", "-genkeypair");4243// When -dname is recognized, SAN must be specified, otherwise,44// -printcert fails.45kt("-alias", "me", "-certreq", "-dname", "", "-file", "me1.req")46.shouldHaveExitValue(0);47kt("-alias", "ca", "-gencert",48"-infile", "me1.req", "-outfile", "me1.crt")49.shouldHaveExitValue(0);50kt("-printcert", "-file", "me1.crt").shouldNotHaveExitValue(0);5152kt("-alias", "me", "-certreq", "-file", "me2.req")53.shouldHaveExitValue(0);54kt("-alias", "ca", "-gencert", "-dname", "",55"-infile", "me2.req", "-outfile", "me2.crt")56.shouldHaveExitValue(0);57kt("-printcert", "-file", "me2.crt").shouldNotHaveExitValue(0);5859kt("-alias", "me", "-certreq", "-dname", "", "-file", "me3.req")60.shouldHaveExitValue(0);61kt("-alias", "ca", "-gencert", "-ext", "san:c=email:[email protected]",62"-infile", "me3.req", "-outfile", "me3.crt")63.shouldHaveExitValue(0);64kt("-printcert", "-file", "me3.crt").shouldHaveExitValue(0);6566kt("-alias", "me", "-certreq", "-file", "me4.req")67.shouldHaveExitValue(0);68kt("-alias", "ca", "-gencert", "-dname", "",69"-ext", "san:c=email:[email protected]",70"-infile", "me4.req", "-outfile", "me4.crt")71.shouldHaveExitValue(0);72kt("-printcert", "-file", "me4.crt").shouldHaveExitValue(0);73}7475static OutputAnalyzer kt(String... s) throws Exception {76List<String> cmd = new ArrayList<>();77cmd.addAll(Arrays.asList(78"-storepass", "changeit",79"-keypass", "changeit",80"-keystore", KS,81"-keyalg", "rsa"));82cmd.addAll(Arrays.asList(s));83return SecurityTools.keytool(cmd);84}85}868788