Path: blob/master/test/jdk/sun/security/tools/keytool/UnknownAndUnparseable.java
41152 views
/*1* Copyright (c) 2012, 2013, 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 719220226* @summary Make sure keytool prints both unknown and unparseable extensions27* @modules java.base/sun.security.tools.keytool28* java.base/sun.security.util29* java.base/sun.security.x50930* @compile -XDignore.symbol.file UnknownAndUnparseable.java31* @run main UnknownAndUnparseable32*/3334import java.io.ByteArrayOutputStream;35import java.io.File;36import java.io.PrintStream;37import sun.security.x509.PKIXExtensions;3839public class UnknownAndUnparseable {40public static void main(String[] args) throws Exception {4142String s = "-keystore ks -storepass changeit -keypass changeit -debug ";43new File("ks").delete();4445// Create a cert with an unknown extension: 1.2.3.4, and an invalid46// KeyUsage extension47String genkey = s48+ "-genkeypair -alias a -dname CN=A -ext 1.2.3.4=1234 -keyalg rsa "49+ "-ext " + PKIXExtensions.KeyUsage_Id.toString() + "=5678";50sun.security.tools.keytool.Main.main(genkey.split(" "));5152// Get the list output to a string53String list = s + "-list -v";54ByteArrayOutputStream bout = new ByteArrayOutputStream();55PrintStream oldOut = System.out;56System.setOut(new PrintStream(bout));57sun.security.tools.keytool.Main.main(list.split(" "));58System.setOut(oldOut);59String out = bout.toString();60System.out.println(out);6162if (!out.contains("1.2.3.4")) {63throw new Exception("Unknown extension 1.2.3.4 is not listed");64}65if (!out.contains("0000: 12 34")) {66throw new Exception("Unknown extension 1.2.3.4 has no content");67}68if (!out.contains("Unparseable KeyUsage")) {69throw new Exception("Unparseable KeyUsage is not listed");70}71if (!out.contains("0000: 56 78")) {72throw new Exception("Unparseable KeyUsage has no content");73}74}75}767778