8162752: keytool -importkeystore should probe srcstoretype if not specified
Reviewed-by: mullan
--- a/jdk/src/java.base/share/classes/sun/security/tools/keytool/Main.java Sun Jul 31 09:37:02 2016 +0800
+++ b/jdk/src/java.base/share/classes/sun/security/tools/keytool/Main.java Sun Jul 31 09:40:17 2016 +0800
@@ -129,6 +129,7 @@
private Set<Pair <String, String>> providerClasses = null;
private String storetype = null;
private boolean hasStoretypeOption = false;
+ private boolean hasSrcStoretypeOption = false;
private String srcProviderName = null;
private String providerName = null;
private String pathlist = null;
@@ -492,7 +493,7 @@
passwords.add(srcstorePass);
} else if (collator.compare(flags, "-srcstoretype") == 0) {
srcstoretype = args[++i];
- hasStoretypeOption = true;
+ hasSrcStoretypeOption = true;
} else if (collator.compare(flags, "-srckeypass") == 0) {
srckeyPass = getPass(modifier, args[++i]);
passwords.add(srckeyPass);
@@ -1936,7 +1937,7 @@
try {
// Probe for keystore type when filename is available
if (srcksfile != null && is != null && srcProviderName == null &&
- hasStoretypeOption == false) {
+ hasSrcStoretypeOption == false) {
store = KeyStore.getInstance(srcksfile, srcstorePass);
} else {
if (srcProviderName == null) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/sun/security/tools/keytool/HasSrcStoretypeOption.java Sun Jul 31 09:40:17 2016 +0800
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8162752
+ * @summary keytool -importkeystore should probe srcstoretype if not specified
+ * @modules java.base/sun.security.tools.keytool
+ */
+
+import sun.security.tools.keytool.Main;
+
+public class HasSrcStoretypeOption {
+
+ public static void main(String[] args) throws Exception {
+ run("-genkeypair -alias a -dname CN=A -storetype jceks -keystore jce");
+ // When there is no -srcstoretype, it should be probed from the file
+ run("-importkeystore -srckeystore jce -destkeystore jks -deststoretype jks");
+ }
+
+ private static void run(String cmd) throws Exception {
+ cmd += " -debug -storepass changeit -keypass changeit -srcstorepass changeit";
+ Main.main(cmd.split(" "));
+ }
+}