Path: blob/master/test/jdk/sun/security/tools/keytool/CloneKeyAskPassword.java
41152 views
/*1* Copyright (c) 2004, 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 617836626* @library /test/lib27* @summary confirm that keytool correctly finds (and clones) a private key28* when the user is prompted for the key's password.29*/3031import jdk.test.lib.Asserts;32import jdk.test.lib.SecurityTools;3334import java.io.File;35import java.nio.file.Files;36import java.nio.file.Path;37import java.security.KeyStore;3839public class CloneKeyAskPassword {40public static void main(String[] args) throws Exception {4142// Different storepass and keypass43Files.copy(Path.of(44System.getProperty("test.src"), "CloneKeyAskPassword.jks"),45Path.of("CloneKeyAskPassword.jks"));4647// Clone with original keypass48SecurityTools.setResponse("test456", "");49SecurityTools.keytool(50"-keyclone",51"-alias", "mykey",52"-dest", "myclone1",53"-keystore", "CloneKeyAskPassword.jks",54"-storepass", "test123").shouldHaveExitValue(0);5556// Clone with new keypass57SecurityTools.setResponse("test456", "test789", "test789");58SecurityTools.keytool(59"-keyclone",60"-alias", "mykey",61"-dest", "myclone2",62"-keystore", "CloneKeyAskPassword.jks",63"-storepass", "test123").shouldHaveExitValue(0);6465KeyStore ks = KeyStore.getInstance(66new File("CloneKeyAskPassword.jks"), "test123".toCharArray());67Asserts.assertNotNull(ks.getKey("myclone1", "test456".toCharArray()));68Asserts.assertNotNull(ks.getKey("myclone2", "test789".toCharArray()));69}70}717273