1 /* 2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 import jdk.test.lib.SecurityTools; 25 import jdk.test.lib.process.OutputAnalyzer; 26 27 /** 28 * @test 29 * @bug 8212003 8214179 30 * @summary Deprecating the default keytool -keyalg option 31 * @library /test/lib 32 */ 33 34 public class DeprecateKeyalg { 35 36 private static final String COMMON = "-keystore ks -storetype jceks " 37 + "-storepass changeit -keypass changeit"; 38 main(String[] args)39 public static void main(String[] args) throws Throwable { 40 41 kt("-genkeypair -keyalg DSA -alias a -dname CN=A") 42 .shouldContain("Generating") 43 .shouldNotContain("-keyalg option must be specified"); 44 45 kt("-genkeypair -alias b -dname CN=B") 46 .shouldContain("Generating") 47 .shouldContain("default key algorithm (DSA)") 48 .shouldContain("-keyalg option must be specified"); 49 50 kt("-genseckey -keyalg DES -alias c") 51 .shouldContain("Generated") 52 .shouldNotContain("-keyalg option must be specified"); 53 54 kt("-genseckey -alias d") 55 .shouldContain("Generated") 56 .shouldContain("default key algorithm (DES)") 57 .shouldContain("-keyalg option must be specified"); 58 59 kt("-genkeypair -alias e -dname CN=e -keyalg EC -groupname brainpoolP256r1") 60 .shouldContain("Generating 256 bit EC (brainpoolP256r1) key pair"); 61 62 kt("-genkeypair -alias f -dname CN=f -keyalg EC") 63 .shouldContain("Generating 256 bit EC (secp256r1) key pair"); 64 65 kt("-genkeypair -alias g -dname CN=g -keyalg EC -keysize 384") 66 .shouldContain("Generating 384 bit EC (secp384r1) key pair"); 67 } 68 kt(String cmd)69 private static OutputAnalyzer kt(String cmd) throws Throwable { 70 return SecurityTools.keytool(COMMON + " " + cmd) 71 .shouldHaveExitValue(0); 72 } 73 } 74