|
| 1 | +/* |
| 2 | + * Copyright (c) 2021, 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 | +/* |
| 25 | + * @test |
| 26 | + * @bug 8266400 |
| 27 | + * @summary Test importkeystore to a password less PKCS12 keystore |
| 28 | + * @library /test/lib |
| 29 | + */ |
| 30 | + |
| 31 | +import jdk.test.lib.SecurityTools; |
| 32 | +import jdk.test.lib.process.OutputAnalyzer; |
| 33 | + |
| 34 | +public class ImportToPwordlessPK12 { |
| 35 | + |
| 36 | + static OutputAnalyzer kt(String cmd, String ks) throws Exception { |
| 37 | + return SecurityTools.keytool("-storepass changeit " + cmd + |
| 38 | + " -keystore " + ks); |
| 39 | + } |
| 40 | + |
| 41 | + public static void main(String[] args) throws Exception { |
| 42 | + |
| 43 | + kt("-genkeypair -keyalg EC -alias testcert -dname CN=EE " + |
| 44 | + "-storetype jks -keypass pass123 ", "ks.jks"); |
| 45 | + |
| 46 | + /* |
| 47 | + * Test by setting the responses for source keystore password and |
| 48 | + * key password for alias |
| 49 | + */ |
| 50 | + SecurityTools.setResponse("changeit", "pass123"); |
| 51 | + SecurityTools.keytool("-importkeystore -srckeystore ks.jks " + |
| 52 | + "-destkeystore ks.p12 " + |
| 53 | + "-J-Dkeystore.pkcs12.macAlgorithm=NONE " + |
| 54 | + "-J-Dkeystore.pkcs12.certProtectionAlgorithm=NONE") |
| 55 | + .shouldHaveExitValue(0); |
| 56 | + |
| 57 | + SecurityTools.keytool("-list -keystore ks.p12 -debug") |
| 58 | + .shouldContain("Keystore type: PKCS12") |
| 59 | + .shouldContain("keystore contains 1 entry") |
| 60 | + .shouldNotContain("Enter keystore password:") |
| 61 | + .shouldHaveExitValue(0); |
| 62 | + |
| 63 | + kt("-genkeypair -keyalg EC -alias testcert -dname CN=EE " + |
| 64 | + "-storetype jks -keypass pass123 ", "ks1.jks"); |
| 65 | + |
| 66 | + // Test with all of options specified on command line |
| 67 | + SecurityTools.keytool("-importkeystore -srckeystore ks1.jks " + |
| 68 | + "-destkeystore ks1.p12 " + |
| 69 | + "-srcstorepass changeit " + |
| 70 | + "-srcalias testcert " + |
| 71 | + "-srckeypass pass123 " + |
| 72 | + "-J-Dkeystore.pkcs12.macAlgorithm=NONE " + |
| 73 | + "-J-Dkeystore.pkcs12.certProtectionAlgorithm=NONE") |
| 74 | + .shouldHaveExitValue(0); |
| 75 | + |
| 76 | + SecurityTools.keytool("-list -keystore ks1.p12 -debug") |
| 77 | + .shouldContain("Keystore type: PKCS12") |
| 78 | + .shouldContain("keystore contains 1 entry") |
| 79 | + .shouldNotContain("Enter keystore password:") |
| 80 | + .shouldHaveExitValue(0); |
| 81 | + } |
| 82 | +} |
0 commit comments