Path: blob/master/test/jdk/sun/security/tools/keytool/ImportToPwordlessPK12.java
41152 views
/*1* Copyright (c) 2021, 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 826640026* @summary Test importkeystore to a password less PKCS12 keystore27* @library /test/lib28*/2930import jdk.test.lib.SecurityTools;31import jdk.test.lib.process.OutputAnalyzer;3233public class ImportToPwordlessPK12 {3435static OutputAnalyzer kt(String cmd, String ks) throws Exception {36return SecurityTools.keytool("-storepass changeit " + cmd +37" -keystore " + ks);38}3940public static void main(String[] args) throws Exception {4142kt("-genkeypair -keyalg EC -alias testcert -dname CN=EE " +43"-storetype jks -keypass pass123 ", "ks.jks");4445/*46* Test by setting the responses for source keystore password and47* key password for alias48*/49SecurityTools.setResponse("changeit", "pass123");50SecurityTools.keytool("-importkeystore -srckeystore ks.jks " +51"-destkeystore ks.p12 " +52"-J-Dkeystore.pkcs12.macAlgorithm=NONE " +53"-J-Dkeystore.pkcs12.certProtectionAlgorithm=NONE")54.shouldHaveExitValue(0);5556SecurityTools.keytool("-list -keystore ks.p12 -debug")57.shouldContain("Keystore type: PKCS12")58.shouldContain("keystore contains 1 entry")59.shouldNotContain("Enter keystore password:")60.shouldHaveExitValue(0);6162kt("-genkeypair -keyalg EC -alias testcert -dname CN=EE " +63"-storetype jks -keypass pass123 ", "ks1.jks");6465// Test with all of options specified on command line66SecurityTools.keytool("-importkeystore -srckeystore ks1.jks " +67"-destkeystore ks1.p12 " +68"-srcstorepass changeit " +69"-srcalias testcert " +70"-srckeypass pass123 " +71"-J-Dkeystore.pkcs12.macAlgorithm=NONE " +72"-J-Dkeystore.pkcs12.certProtectionAlgorithm=NONE")73.shouldHaveExitValue(0);7475SecurityTools.keytool("-list -keystore ks1.p12 -debug")76.shouldContain("Keystore type: PKCS12")77.shouldContain("keystore contains 1 entry")78.shouldNotContain("Enter keystore password:")79.shouldHaveExitValue(0);80}81}828384