Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/tools/keytool/CloneKeyAskPassword.java
41152 views
1
/*
2
* Copyright (c) 2004, 2019, 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 6178366
27
* @library /test/lib
28
* @summary confirm that keytool correctly finds (and clones) a private key
29
* when the user is prompted for the key's password.
30
*/
31
32
import jdk.test.lib.Asserts;
33
import jdk.test.lib.SecurityTools;
34
35
import java.io.File;
36
import java.nio.file.Files;
37
import java.nio.file.Path;
38
import java.security.KeyStore;
39
40
public class CloneKeyAskPassword {
41
public static void main(String[] args) throws Exception {
42
43
// Different storepass and keypass
44
Files.copy(Path.of(
45
System.getProperty("test.src"), "CloneKeyAskPassword.jks"),
46
Path.of("CloneKeyAskPassword.jks"));
47
48
// Clone with original keypass
49
SecurityTools.setResponse("test456", "");
50
SecurityTools.keytool(
51
"-keyclone",
52
"-alias", "mykey",
53
"-dest", "myclone1",
54
"-keystore", "CloneKeyAskPassword.jks",
55
"-storepass", "test123").shouldHaveExitValue(0);
56
57
// Clone with new keypass
58
SecurityTools.setResponse("test456", "test789", "test789");
59
SecurityTools.keytool(
60
"-keyclone",
61
"-alias", "mykey",
62
"-dest", "myclone2",
63
"-keystore", "CloneKeyAskPassword.jks",
64
"-storepass", "test123").shouldHaveExitValue(0);
65
66
KeyStore ks = KeyStore.getInstance(
67
new File("CloneKeyAskPassword.jks"), "test123".toCharArray());
68
Asserts.assertNotNull(ks.getKey("myclone1", "test456".toCharArray()));
69
Asserts.assertNotNull(ks.getKey("myclone2", "test789".toCharArray()));
70
}
71
}
72
73