author | mbalao |
Tue, 12 Nov 2019 00:30:55 -0300 | |
changeset 59158 | 438337c846fb |
permissions | -rw-r--r-- |
59158
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
1 |
/* |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Red Hat, Inc. |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
3 |
* |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
4 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
5 |
* |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
6 |
* This code is free software; you can redistribute it and/or modify it |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
7 |
* under the terms of the GNU General Public License version 2 only, as |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
8 |
* published by the Free Software Foundation. |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
9 |
* |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
10 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
14 |
* accompanied this code). |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
15 |
* |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
16 |
* You should have received a copy of the GNU General Public License version |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
17 |
* 2 along with this work; if not, write to the Free Software Foundation, |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
18 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
19 |
* |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
20 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
21 |
* or visit www.oracle.com if you need additional information or have any |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
22 |
* questions. |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
23 |
*/ |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
24 |
|
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
25 |
/* |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
26 |
* @test |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
27 |
* @bug 8233404 |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
28 |
* @library /test/lib |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
29 |
* @run main/othervm/timeout=30 IterationCount HOST 200000 |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
30 |
* @run main/othervm/timeout=30 IterationCount HOST 200000 1 |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
31 |
* @run main/othervm/timeout=30 IterationCount HOST 200000 6000000 |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
32 |
* @run main/othervm/timeout=30 IterationCount HOST 200000 invalid |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
33 |
* @run main/othervm/timeout=30 IterationCount HOST 30000 30000 |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
34 |
* @run main/othervm/timeout=30 IterationCount OVERRIDE |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
35 |
* @author Martin Balao (mbalao@redhat.com) |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
36 |
*/ |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
37 |
|
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
38 |
import java.io.File; |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
39 |
import java.io.FileOutputStream; |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
40 |
import java.io.IOException; |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
41 |
import java.lang.reflect.Field; |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
42 |
import java.nio.file.FileVisitResult; |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
43 |
import java.nio.file.Files; |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
44 |
import java.nio.file.Path; |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
45 |
import java.nio.file.SimpleFileVisitor; |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
46 |
import java.nio.file.attribute.BasicFileAttributes; |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
47 |
import java.util.ArrayList; |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
48 |
import java.util.List; |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
49 |
|
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
50 |
import jdk.test.lib.process.OutputAnalyzer; |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
51 |
import jdk.test.lib.process.ProcessTools; |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
52 |
|
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
53 |
public class IterationCount { |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
54 |
private static final String clientStr = "CLIENT"; |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
55 |
private static final String javaBinPath = |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
56 |
System.getProperty("java.home", ".") + File.separator + "bin" + |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
57 |
File.separator + "java"; |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
58 |
|
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
59 |
public static void main(String[] args) throws Throwable { |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
60 |
if (args[0].equals("HOST")) { |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
61 |
String setValue = null; |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
62 |
if (args.length > 2) { |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
63 |
setValue = args[2]; |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
64 |
} |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
65 |
testSystem(args[1], setValue); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
66 |
testSecurity(args[1], setValue); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
67 |
} else if (args[0].equals(clientStr)) { |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
68 |
int expectedIterationCount = Integer.parseInt(args[1]); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
69 |
int currentIterationCount = getCurrentIterationCountValue(); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
70 |
System.out.println("Expected value: " + expectedIterationCount); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
71 |
System.out.println("Current value: " + currentIterationCount); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
72 |
if (currentIterationCount != expectedIterationCount) { |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
73 |
throw new Exception("Expected value different than current"); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
74 |
} |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
75 |
} else if (args[0].equals("OVERRIDE")) { |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
76 |
testSystemOverridesSecurity(); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
77 |
} |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
78 |
System.out.println("TEST PASS - OK"); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
79 |
} |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
80 |
|
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
81 |
private static List<String> getBasicCommand() { |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
82 |
List<String> cmd = new ArrayList<>(); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
83 |
cmd.add(javaBinPath); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
84 |
cmd.add("-cp"); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
85 |
cmd.add(System.getProperty("test.classes", ".")); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
86 |
return cmd; |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
87 |
} |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
88 |
|
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
89 |
private static void executeCommand(List<String> cmd, String expectedCount) |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
90 |
throws Throwable { |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
91 |
cmd.add(IterationCount.class.getName()); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
92 |
cmd.add(clientStr); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
93 |
cmd.add(expectedCount); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
94 |
OutputAnalyzer out = ProcessTools.executeCommand( |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
95 |
cmd.toArray(new String[cmd.size()])); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
96 |
out.shouldHaveExitValue(0); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
97 |
} |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
98 |
|
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
99 |
private static void testSystem(String expectedCount, String setValue) |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
100 |
throws Throwable { |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
101 |
System.out.println("Test setting " + |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
102 |
(setValue != null ? setValue : "nothing") + |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
103 |
" as a System property"); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
104 |
List<String> cmd = getBasicCommand(); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
105 |
if (setValue != null) { |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
106 |
cmd.add("-Djdk.jceks.iterationCount=" + setValue); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
107 |
} |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
108 |
executeCommand(cmd, expectedCount); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
109 |
System.out.println("............................."); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
110 |
} |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
111 |
|
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
112 |
private static void testSecurity(String expectedCount, String setValue) |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
113 |
throws Throwable { |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
114 |
testSecurity(expectedCount, setValue, getBasicCommand()); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
115 |
} |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
116 |
|
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
117 |
private static void testSecurity(String expectedCount, String setValue, |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
118 |
List<String> cmd) throws Throwable { |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
119 |
System.out.println("Test setting " + |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
120 |
(setValue != null ? setValue : "nothing") + |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
121 |
" as a Security property"); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
122 |
Path tmpDirPath = Files.createTempDirectory("tmpdir"); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
123 |
try { |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
124 |
if (setValue != null) { |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
125 |
String javaSecurityPath = tmpDirPath + |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
126 |
File.separator + "java.security"; |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
127 |
writeJavaSecurityProp(javaSecurityPath, setValue); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
128 |
cmd.add("-Djava.security.properties=" + javaSecurityPath); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
129 |
} |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
130 |
executeCommand(cmd, expectedCount); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
131 |
System.out.println("............................."); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
132 |
} finally { |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
133 |
deleteDir(tmpDirPath); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
134 |
} |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
135 |
} |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
136 |
|
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
137 |
private static void testSystemOverridesSecurity() throws Throwable { |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
138 |
System.out.println("Test that setting a System property overrides" + |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
139 |
" the Security one"); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
140 |
String systemValue = Integer.toString(30000); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
141 |
System.out.println("System value: " + systemValue); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
142 |
List<String> cmd = getBasicCommand(); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
143 |
cmd.add("-Djdk.jceks.iterationCount=" + systemValue); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
144 |
testSecurity(systemValue, Integer.toString(40000), cmd); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
145 |
} |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
146 |
|
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
147 |
private static void writeJavaSecurityProp(String javaSecurityPath, |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
148 |
String setValue) throws IOException { |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
149 |
try (FileOutputStream fos = new FileOutputStream( |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
150 |
new File(javaSecurityPath))) { |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
151 |
fos.write(("jdk.jceks.iterationCount=" + setValue).getBytes()); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
152 |
} |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
153 |
} |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
154 |
|
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
155 |
private static int getCurrentIterationCountValue() throws Exception { |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
156 |
Class<?> KeyProtectorClass = |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
157 |
Class.forName("com.sun.crypto.provider.KeyProtector"); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
158 |
Field iterationCountField = |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
159 |
KeyProtectorClass.getDeclaredField("ITERATION_COUNT"); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
160 |
iterationCountField.setAccessible(true); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
161 |
return iterationCountField.getInt(KeyProtectorClass); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
162 |
} |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
163 |
|
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
164 |
private static void deleteDir(Path directory) throws IOException { |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
165 |
Files.walkFileTree(directory, new SimpleFileVisitor<Path>() { |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
166 |
|
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
167 |
@Override |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
168 |
public FileVisitResult visitFile(Path file, |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
169 |
BasicFileAttributes attrs) throws IOException { |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
170 |
Files.delete(file); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
171 |
return FileVisitResult.CONTINUE; |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
172 |
} |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
173 |
|
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
174 |
@Override |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
175 |
public FileVisitResult postVisitDirectory(Path dir, IOException exc) |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
176 |
throws IOException { |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
177 |
Files.delete(dir); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
178 |
return FileVisitResult.CONTINUE; |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
179 |
} |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
180 |
}); |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
181 |
} |
438337c846fb
8233404: System property to set the number of PBE iterations in JCEKS keystores
mbalao
parents:
diff
changeset
|
182 |
} |