author | asmotrak |
Mon, 14 Sep 2015 19:54:58 +0300 | |
changeset 32635 | d7e4ba3c2e0d |
parent 32138 | 23830562d3d1 |
child 33493 | 442660a9b96f |
permissions | -rw-r--r-- |
2 | 1 |
/* |
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
2 |
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
24 |
||
25 |
// common infrastructure for SunPKCS11 tests |
|
26 |
||
27 |
import java.io.*; |
|
28 |
import java.util.*; |
|
29 |
||
30 |
import java.security.*; |
|
21977
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
31 |
import java.security.spec.ECGenParameterSpec; |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
32 |
import java.security.spec.ECParameterSpec; |
2 | 33 |
|
34 |
public abstract class PKCS11Test { |
|
35 |
||
32635
d7e4ba3c2e0d
8048622: Enhance tests for PKCS11 keystores with NSS
asmotrak
parents:
32138
diff
changeset
|
36 |
static final String PKCS11 = "PKCS11"; |
d7e4ba3c2e0d
8048622: Enhance tests for PKCS11 keystores with NSS
asmotrak
parents:
32138
diff
changeset
|
37 |
|
2 | 38 |
// directory of the test source |
39 |
static final String BASE = System.getProperty("test.src", "."); |
|
40 |
||
41 |
static final char SEP = File.separatorChar; |
|
42 |
||
43 |
private final static String REL_CLOSED = "../../../../closed/sun/security/pkcs11".replace('/', SEP); |
|
44 |
||
45 |
// directory corresponding to BASE in the /closed hierarchy |
|
46 |
static final String CLOSED_BASE; |
|
47 |
||
48 |
static { |
|
49 |
// hack |
|
50 |
String absBase = new File(BASE).getAbsolutePath(); |
|
51 |
int k = absBase.indexOf(SEP + "test" + SEP + "sun" + SEP); |
|
52 |
if (k < 0) k = 0; |
|
53 |
String p1 = absBase.substring(0, k + 6); |
|
54 |
String p2 = absBase.substring(k + 5); |
|
55 |
CLOSED_BASE = p1 + "closed" + p2; |
|
56 |
} |
|
57 |
||
58 |
static String NSPR_PREFIX = ""; |
|
59 |
||
19067
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
60 |
// NSS version info |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
61 |
public static enum ECCState { None, Basic, Extended }; |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
62 |
static double nss_version = -1; |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
63 |
static ECCState nss_ecc_status = ECCState.Extended; |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
64 |
|
19066 | 65 |
// The NSS library we need to search for in getNSSLibDir() |
66 |
// Default is "libsoftokn3.so", listed as "softokn3" |
|
67 |
// The other is "libnss3.so", listed as "nss3". |
|
68 |
static String nss_library = "softokn3"; |
|
69 |
||
24863
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
70 |
// NSS versions of each library. It is simplier to keep nss_version |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
71 |
// for quick checking for generic testing than many if-else statements. |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
72 |
static double softoken3_version = -1; |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
73 |
static double nss3_version = -1; |
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
74 |
static Provider pkcs11; |
24863
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
75 |
|
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
76 |
// Goes through ServiceLoader instead of Provider.getInstance() since it |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
77 |
// works on all platforms |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
78 |
static { |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
79 |
ServiceLoader sl = ServiceLoader.load(java.security.Provider.class); |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
80 |
Iterator<Provider> iter = sl.iterator(); |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
81 |
Provider p = null; |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
82 |
boolean found = false; |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
83 |
while (iter.hasNext()) { |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
84 |
try { |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
85 |
p = iter.next(); |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
86 |
if (p.getName().equals("SunPKCS11")) { |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
87 |
found = true; |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
88 |
break; |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
89 |
}; |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
90 |
} catch (Exception e) { |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
91 |
// ignore and move on to the next one |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
92 |
} |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
93 |
} |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
94 |
// Nothing found through ServiceLoader; fall back to reflection |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
95 |
if (!found) { |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
96 |
try { |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
97 |
Class clazz = Class.forName("sun.security.pkcs11.SunPKCS11"); |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
98 |
p = (Provider) clazz.newInstance(); |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
99 |
} catch (Exception ex) { |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
100 |
ex.printStackTrace(); |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
101 |
} |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
102 |
} |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
103 |
pkcs11 = p; |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
104 |
} |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
105 |
|
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
106 |
// Return a SunPKCS11 provider configured with the specified config file |
2 | 107 |
static Provider getSunPKCS11(String config) throws Exception { |
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
108 |
if (pkcs11 == null) { |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
109 |
throw new NoSuchProviderException("No PKCS11 provider available"); |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
110 |
} |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
111 |
return pkcs11.configure(config); |
2 | 112 |
} |
113 |
||
114 |
public abstract void main(Provider p) throws Exception; |
|
115 |
||
116 |
private void premain(Provider p) throws Exception { |
|
117 |
long start = System.currentTimeMillis(); |
|
118 |
System.out.println("Running test with provider " + p.getName() + "..."); |
|
119 |
main(p); |
|
120 |
long stop = System.currentTimeMillis(); |
|
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
121 |
System.out.println("Completed test with provider " + p.getName() + |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
122 |
" (" + (stop - start) + " ms)."); |
2 | 123 |
} |
124 |
||
125 |
public static void main(PKCS11Test test) throws Exception { |
|
10328 | 126 |
Provider[] oldProviders = Security.getProviders(); |
127 |
try { |
|
128 |
System.out.println("Beginning test run " + test.getClass().getName() + "..."); |
|
129 |
testDefault(test); |
|
130 |
testNSS(test); |
|
131 |
testDeimos(test); |
|
132 |
} finally { |
|
19066 | 133 |
// NOTE: Do not place a 'return' in any finally block |
134 |
// as it will suppress exceptions and hide test failures. |
|
10328 | 135 |
Provider[] newProviders = Security.getProviders(); |
19066 | 136 |
boolean found = true; |
10328 | 137 |
// Do not restore providers if nothing changed. This is especailly |
138 |
// useful for ./Provider/Login.sh, where a SecurityManager exists. |
|
139 |
if (oldProviders.length == newProviders.length) { |
|
19066 | 140 |
found = false; |
10328 | 141 |
for (int i = 0; i<oldProviders.length; i++) { |
142 |
if (oldProviders[i] != newProviders[i]) { |
|
143 |
found = true; |
|
144 |
break; |
|
145 |
} |
|
146 |
} |
|
147 |
} |
|
19066 | 148 |
if (found) { |
149 |
for (Provider p: newProviders) { |
|
150 |
Security.removeProvider(p.getName()); |
|
151 |
} |
|
152 |
for (Provider p: oldProviders) { |
|
153 |
Security.addProvider(p); |
|
154 |
} |
|
10328 | 155 |
} |
156 |
} |
|
2 | 157 |
} |
158 |
||
159 |
public static void testDeimos(PKCS11Test test) throws Exception { |
|
160 |
if (new File("/opt/SUNWconn/lib/libpkcs11.so").isFile() == false || |
|
161 |
"true".equals(System.getProperty("NO_DEIMOS"))) { |
|
162 |
return; |
|
163 |
} |
|
164 |
String base = getBase(); |
|
165 |
String p11config = base + SEP + "nss" + SEP + "p11-deimos.txt"; |
|
166 |
Provider p = getSunPKCS11(p11config); |
|
167 |
test.premain(p); |
|
168 |
} |
|
169 |
||
170 |
public static void testDefault(PKCS11Test test) throws Exception { |
|
171 |
// run test for default configured PKCS11 providers (if any) |
|
172 |
||
173 |
if ("true".equals(System.getProperty("NO_DEFAULT"))) { |
|
174 |
return; |
|
175 |
} |
|
176 |
||
177 |
Provider[] providers = Security.getProviders(); |
|
178 |
for (int i = 0; i < providers.length; i++) { |
|
179 |
Provider p = providers[i]; |
|
180 |
if (p.getName().startsWith("SunPKCS11-")) { |
|
181 |
test.premain(p); |
|
182 |
} |
|
183 |
} |
|
184 |
} |
|
185 |
||
186 |
private static String PKCS11_BASE; |
|
12294
f313586fc3cc
7152582: PKCS11 tests should use the NSS libraries available in the OS
vinnie
parents:
12042
diff
changeset
|
187 |
static { |
f313586fc3cc
7152582: PKCS11 tests should use the NSS libraries available in the OS
vinnie
parents:
12042
diff
changeset
|
188 |
try { |
f313586fc3cc
7152582: PKCS11 tests should use the NSS libraries available in the OS
vinnie
parents:
12042
diff
changeset
|
189 |
PKCS11_BASE = getBase(); |
f313586fc3cc
7152582: PKCS11 tests should use the NSS libraries available in the OS
vinnie
parents:
12042
diff
changeset
|
190 |
} catch (Exception e) { |
f313586fc3cc
7152582: PKCS11 tests should use the NSS libraries available in the OS
vinnie
parents:
12042
diff
changeset
|
191 |
// ignore |
f313586fc3cc
7152582: PKCS11 tests should use the NSS libraries available in the OS
vinnie
parents:
12042
diff
changeset
|
192 |
} |
f313586fc3cc
7152582: PKCS11 tests should use the NSS libraries available in the OS
vinnie
parents:
12042
diff
changeset
|
193 |
} |
2 | 194 |
|
195 |
private final static String PKCS11_REL_PATH = "sun/security/pkcs11"; |
|
196 |
||
197 |
public static String getBase() throws Exception { |
|
198 |
if (PKCS11_BASE != null) { |
|
199 |
return PKCS11_BASE; |
|
200 |
} |
|
201 |
File cwd = new File(System.getProperty("test.src", ".")).getCanonicalFile(); |
|
202 |
while (true) { |
|
203 |
File file = new File(cwd, "TEST.ROOT"); |
|
204 |
if (file.isFile()) { |
|
205 |
break; |
|
206 |
} |
|
207 |
cwd = cwd.getParentFile(); |
|
208 |
if (cwd == null) { |
|
209 |
throw new Exception("Test root directory not found"); |
|
210 |
} |
|
211 |
} |
|
212 |
PKCS11_BASE = new File(cwd, PKCS11_REL_PATH.replace('/', SEP)).getAbsolutePath(); |
|
213 |
return PKCS11_BASE; |
|
214 |
} |
|
215 |
||
216 |
public static String getNSSLibDir() throws Exception { |
|
24863
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
217 |
return getNSSLibDir(nss_library); |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
218 |
} |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
219 |
|
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
220 |
static String getNSSLibDir(String library) throws Exception { |
2 | 221 |
Properties props = System.getProperties(); |
222 |
String osName = props.getProperty("os.name"); |
|
223 |
if (osName.startsWith("Win")) { |
|
224 |
osName = "Windows"; |
|
225 |
NSPR_PREFIX = "lib"; |
|
26958 | 226 |
} else if (osName.equals("Mac OS X")) { |
227 |
osName = "MacOSX"; |
|
2 | 228 |
} |
229 |
String osid = osName + "-" |
|
230 |
+ props.getProperty("os.arch") + "-" + props.getProperty("sun.arch.data.model"); |
|
13565
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
231 |
String[] nssLibDirs = osMap.get(osid); |
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
232 |
if (nssLibDirs == null) { |
2 | 233 |
System.out.println("Unsupported OS, skipping: " + osid); |
234 |
return null; |
|
235 |
} |
|
13565
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
236 |
if (nssLibDirs.length == 0) { |
2 | 237 |
System.out.println("NSS not supported on this platform, skipping test"); |
238 |
return null; |
|
239 |
} |
|
13565
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
240 |
String nssLibDir = null; |
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
241 |
for (String dir : nssLibDirs) { |
19066 | 242 |
if (new File(dir).exists() && |
24863
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
243 |
new File(dir + System.mapLibraryName(library)).exists()) { |
13565
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
244 |
nssLibDir = dir; |
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
245 |
System.setProperty("pkcs11test.nss.libdir", nssLibDir); |
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
246 |
break; |
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
247 |
} |
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
248 |
} |
12294
f313586fc3cc
7152582: PKCS11 tests should use the NSS libraries available in the OS
vinnie
parents:
12042
diff
changeset
|
249 |
return nssLibDir; |
2 | 250 |
} |
251 |
||
10328 | 252 |
protected static void safeReload(String lib) throws Exception { |
253 |
try { |
|
254 |
System.load(lib); |
|
255 |
} catch (UnsatisfiedLinkError e) { |
|
256 |
if (e.getMessage().contains("already loaded")) { |
|
257 |
return; |
|
258 |
} |
|
259 |
} |
|
260 |
} |
|
261 |
||
2 | 262 |
static boolean loadNSPR(String libdir) throws Exception { |
263 |
// load NSS softoken dependencies in advance to avoid resolver issues |
|
10328 | 264 |
safeReload(libdir + System.mapLibraryName(NSPR_PREFIX + "nspr4")); |
265 |
safeReload(libdir + System.mapLibraryName(NSPR_PREFIX + "plc4")); |
|
266 |
safeReload(libdir + System.mapLibraryName(NSPR_PREFIX + "plds4")); |
|
12294
f313586fc3cc
7152582: PKCS11 tests should use the NSS libraries available in the OS
vinnie
parents:
12042
diff
changeset
|
267 |
safeReload(libdir + System.mapLibraryName("sqlite3")); |
f313586fc3cc
7152582: PKCS11 tests should use the NSS libraries available in the OS
vinnie
parents:
12042
diff
changeset
|
268 |
safeReload(libdir + System.mapLibraryName("nssutil3")); |
2 | 269 |
return true; |
270 |
} |
|
271 |
||
19067
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
272 |
// Check the provider being used is NSS |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
273 |
public static boolean isNSS(Provider p) { |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
274 |
return p.getName().toUpperCase().equals("SUNPKCS11-NSS"); |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
275 |
} |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
276 |
|
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
277 |
static double getNSSVersion() { |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
278 |
if (nss_version == -1) |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
279 |
getNSSInfo(); |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
280 |
return nss_version; |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
281 |
} |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
282 |
|
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
283 |
static ECCState getNSSECC() { |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
284 |
if (nss_version == -1) |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
285 |
getNSSInfo(); |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
286 |
return nss_ecc_status; |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
287 |
} |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
288 |
|
24863
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
289 |
public static double getLibsoftokn3Version() { |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
290 |
if (softoken3_version == -1) |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
291 |
return getNSSInfo("softokn3"); |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
292 |
return softoken3_version; |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
293 |
} |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
294 |
|
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
295 |
public static double getLibnss3Version() { |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
296 |
if (nss3_version == -1) |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
297 |
return getNSSInfo("nss3"); |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
298 |
return nss3_version; |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
299 |
} |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
300 |
|
19067
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
301 |
/* Read the library to find out the verison */ |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
302 |
static void getNSSInfo() { |
24863
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
303 |
getNSSInfo(nss_library); |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
304 |
} |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
305 |
|
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
306 |
static double getNSSInfo(String library) { |
19067
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
307 |
String nssHeader = "$Header: NSS"; |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
308 |
boolean found = false; |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
309 |
String s = null; |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
310 |
int i = 0; |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
311 |
String libfile = ""; |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
312 |
|
24863
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
313 |
if (library.compareTo("softokn3") == 0 && softoken3_version > -1) |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
314 |
return softoken3_version; |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
315 |
if (library.compareTo("nss3") == 0 && nss3_version > -1) |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
316 |
return nss3_version; |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
317 |
|
19067
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
318 |
try { |
24863
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
319 |
libfile = getNSSLibDir() + System.mapLibraryName(library); |
19067
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
320 |
FileInputStream is = new FileInputStream(libfile); |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
321 |
byte[] data = new byte[1000]; |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
322 |
int read = 0; |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
323 |
|
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
324 |
while (is.available() > 0) { |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
325 |
if (read == 0) { |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
326 |
read = is.read(data, 0, 1000); |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
327 |
} else { |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
328 |
// Prepend last 100 bytes in case the header was split |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
329 |
// between the reads. |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
330 |
System.arraycopy(data, 900, data, 0, 100); |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
331 |
read = 100 + is.read(data, 100, 900); |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
332 |
} |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
333 |
|
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
334 |
s = new String(data, 0, read); |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
335 |
if ((i = s.indexOf(nssHeader)) > 0) { |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
336 |
found = true; |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
337 |
// If the nssHeader is before 920 we can break, otherwise |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
338 |
// we may not have the whole header so do another read. If |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
339 |
// no bytes are in the stream, that is ok, found is true. |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
340 |
if (i < 920) { |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
341 |
break; |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
342 |
} |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
343 |
} |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
344 |
} |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
345 |
|
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
346 |
is.close(); |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
347 |
|
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
348 |
} catch (Exception e) { |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
349 |
e.printStackTrace(); |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
350 |
} |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
351 |
|
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
352 |
if (!found) { |
24863
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
353 |
System.out.println("lib" + library + |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
354 |
" version not found, set to 0.0: " + libfile); |
19067
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
355 |
nss_version = 0.0; |
24863
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
356 |
return nss_version; |
19067
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
357 |
} |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
358 |
|
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
359 |
// the index after whitespace after nssHeader |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
360 |
int afterheader = s.indexOf("NSS", i) + 4; |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
361 |
String version = s.substring(afterheader, s.indexOf(' ', afterheader)); |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
362 |
|
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
363 |
// If a "dot dot" release, strip the extra dots for double parsing |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
364 |
String[] dot = version.split("\\."); |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
365 |
if (dot.length > 2) { |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
366 |
version = dot[0]+"."+dot[1]; |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
367 |
for (int j = 2; dot.length > j; j++) { |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
368 |
version += dot[j]; |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
369 |
} |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
370 |
} |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
371 |
|
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
372 |
// Convert to double for easier version value checking |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
373 |
try { |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
374 |
nss_version = Double.parseDouble(version); |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
375 |
} catch (NumberFormatException e) { |
24863
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
376 |
System.out.println("Failed to parse lib" + library + |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
377 |
" version. Set to 0.0"); |
19067
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
378 |
e.printStackTrace(); |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
379 |
} |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
380 |
|
24863
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
381 |
System.out.print("lib" + library + " version = "+version+". "); |
19067
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
382 |
|
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
383 |
// Check for ECC |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
384 |
if (s.indexOf("Basic") > 0) { |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
385 |
nss_ecc_status = ECCState.Basic; |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
386 |
System.out.println("ECC Basic."); |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
387 |
} else if (s.indexOf("Extended") > 0) { |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
388 |
nss_ecc_status = ECCState.Extended; |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
389 |
System.out.println("ECC Extended."); |
24863
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
390 |
} else { |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
391 |
System.out.println("ECC None."); |
19067
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
392 |
} |
24863
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
393 |
|
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
394 |
if (library.compareTo("softokn3") == 0) { |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
395 |
softoken3_version = nss_version; |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
396 |
} else if (library.compareTo("nss3") == 0) { |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
397 |
nss3_version = nss_version; |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
398 |
} |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
399 |
|
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
400 |
return nss_version; |
19067
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
401 |
} |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
402 |
|
19066 | 403 |
// Used to set the nss_library file to search for libsoftokn3.so |
404 |
public static void useNSS() { |
|
405 |
nss_library = "nss3"; |
|
406 |
} |
|
407 |
||
2 | 408 |
public static void testNSS(PKCS11Test test) throws Exception { |
409 |
String libdir = getNSSLibDir(); |
|
410 |
if (libdir == null) { |
|
411 |
return; |
|
412 |
} |
|
413 |
String base = getBase(); |
|
414 |
||
415 |
if (loadNSPR(libdir) == false) { |
|
416 |
return; |
|
417 |
} |
|
418 |
||
19066 | 419 |
String libfile = libdir + System.mapLibraryName(nss_library); |
2 | 420 |
|
421 |
String customDBdir = System.getProperty("CUSTOM_DB_DIR"); |
|
422 |
String dbdir = (customDBdir != null) ? |
|
423 |
customDBdir : |
|
424 |
base + SEP + "nss" + SEP + "db"; |
|
425 |
// NSS always wants forward slashes for the config path |
|
426 |
dbdir = dbdir.replace('\\', '/'); |
|
427 |
||
428 |
String customConfig = System.getProperty("CUSTOM_P11_CONFIG"); |
|
429 |
String customConfigName = System.getProperty("CUSTOM_P11_CONFIG_NAME", "p11-nss.txt"); |
|
430 |
String p11config = (customConfig != null) ? |
|
431 |
customConfig : |
|
432 |
base + SEP + "nss" + SEP + customConfigName; |
|
433 |
||
434 |
System.setProperty("pkcs11test.nss.lib", libfile); |
|
435 |
System.setProperty("pkcs11test.nss.db", dbdir); |
|
436 |
Provider p = getSunPKCS11(p11config); |
|
437 |
test.premain(p); |
|
438 |
} |
|
439 |
||
21977
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
440 |
// Generate a vector of supported elliptic curves of a given provider |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
441 |
static Vector<ECParameterSpec> getKnownCurves(Provider p) throws Exception { |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
442 |
int index; |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
443 |
int begin; |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
444 |
int end; |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
445 |
String curve; |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
446 |
KeyPair kp = null; |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
447 |
|
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
448 |
Vector<ECParameterSpec> results = new Vector<ECParameterSpec>(); |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
449 |
// Get Curves to test from SunEC. |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
450 |
String kcProp = Security.getProvider("SunEC"). |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
451 |
getProperty("AlgorithmParameters.EC SupportedCurves"); |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
452 |
|
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
453 |
if (kcProp == null) { |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
454 |
throw new RuntimeException( |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
455 |
"\"AlgorithmParameters.EC SupportedCurves property\" not found"); |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
456 |
} |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
457 |
|
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
458 |
System.out.println("Finding supported curves using list from SunEC\n"); |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
459 |
index = 0; |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
460 |
for (;;) { |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
461 |
// Each set of curve names is enclosed with brackets. |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
462 |
begin = kcProp.indexOf('[', index); |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
463 |
end = kcProp.indexOf(']', index); |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
464 |
if (begin == -1 || end == -1) { |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
465 |
break; |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
466 |
} |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
467 |
|
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
468 |
/* |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
469 |
* Each name is separated by a comma. |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
470 |
* Just get the first name in the set. |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
471 |
*/ |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
472 |
index = end + 1; |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
473 |
begin++; |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
474 |
end = kcProp.indexOf(',', begin); |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
475 |
if (end == -1) { |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
476 |
// Only one name in the set. |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
477 |
end = index -1; |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
478 |
} |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
479 |
|
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
480 |
curve = kcProp.substring(begin, end); |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
481 |
ECParameterSpec e = getECParameterSpec(p, curve); |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
482 |
System.out.print("\t "+ curve + ": "); |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
483 |
try { |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
484 |
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", p); |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
485 |
kpg.initialize(e); |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
486 |
kp = kpg.generateKeyPair(); |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
487 |
results.add(e); |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
488 |
System.out.println("Supported"); |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
489 |
} catch (ProviderException ex) { |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
490 |
System.out.println("Unsupported: PKCS11: " + |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
491 |
ex.getCause().getMessage()); |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
492 |
} catch (InvalidAlgorithmParameterException ex) { |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
493 |
System.out.println("Unsupported: Key Length: " + |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
494 |
ex.getMessage()); |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
495 |
} |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
496 |
} |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
497 |
|
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
498 |
if (results.size() == 0) { |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
499 |
throw new RuntimeException("No supported EC curves found"); |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
500 |
} |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
501 |
|
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
502 |
return results; |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
503 |
} |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
504 |
|
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
505 |
private static ECParameterSpec getECParameterSpec(Provider p, String name) |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
506 |
throws Exception { |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
507 |
|
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
508 |
AlgorithmParameters parameters = |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
509 |
AlgorithmParameters.getInstance("EC", p); |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
510 |
|
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
511 |
parameters.init(new ECGenParameterSpec(name)); |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
512 |
|
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
513 |
return parameters.getParameterSpec(ECParameterSpec.class); |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
514 |
} |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
515 |
|
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
516 |
// Check support for a curve with a provided Vector of EC support |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
517 |
boolean checkSupport(Vector<ECParameterSpec> supportedEC, |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
518 |
ECParameterSpec curve) { |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
519 |
boolean found = false; |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
520 |
for (ECParameterSpec ec: supportedEC) { |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
521 |
if (ec.equals(curve)) { |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
522 |
return true; |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
523 |
} |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
524 |
} |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
525 |
return false; |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
526 |
} |
2 | 527 |
|
13565
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
528 |
private static final Map<String,String[]> osMap; |
2 | 529 |
|
12294
f313586fc3cc
7152582: PKCS11 tests should use the NSS libraries available in the OS
vinnie
parents:
12042
diff
changeset
|
530 |
// Location of the NSS libraries on each supported platform |
2 | 531 |
static { |
13565
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
532 |
osMap = new HashMap<String,String[]>(); |
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
533 |
osMap.put("SunOS-sparc-32", new String[]{"/usr/lib/mps/"}); |
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
534 |
osMap.put("SunOS-sparcv9-64", new String[]{"/usr/lib/mps/64/"}); |
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
535 |
osMap.put("SunOS-x86-32", new String[]{"/usr/lib/mps/"}); |
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
536 |
osMap.put("SunOS-amd64-64", new String[]{"/usr/lib/mps/64/"}); |
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
537 |
osMap.put("Linux-i386-32", new String[]{ |
24629
97bddac495b7
8044038: Security tests fail on 32 bit linux platform
vinnie
parents:
21977
diff
changeset
|
538 |
"/usr/lib/i386-linux-gnu/", "/usr/lib32/", "/usr/lib/"}); |
13565
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
539 |
osMap.put("Linux-amd64-64", new String[]{ |
19066 | 540 |
"/usr/lib/x86_64-linux-gnu/", "/usr/lib/x86_64-linux-gnu/nss/", |
541 |
"/usr/lib64/"}); |
|
13565
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
542 |
osMap.put("Windows-x86-32", new String[]{ |
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
543 |
PKCS11_BASE + "/nss/lib/windows-i586/".replace('/', SEP)}); |
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
544 |
osMap.put("Windows-amd64-64", new String[]{ |
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
545 |
PKCS11_BASE + "/nss/lib/windows-amd64/".replace('/', SEP)}); |
26958 | 546 |
osMap.put("MacOSX-x86_64-64", new String[]{ |
547 |
PKCS11_BASE + "/nss/lib/macosx-x86_64/"}); |
|
2 | 548 |
} |
549 |
||
550 |
private final static char[] hexDigits = "0123456789abcdef".toCharArray(); |
|
551 |
||
552 |
public static String toString(byte[] b) { |
|
553 |
if (b == null) { |
|
554 |
return "(null)"; |
|
555 |
} |
|
556 |
StringBuffer sb = new StringBuffer(b.length * 3); |
|
557 |
for (int i = 0; i < b.length; i++) { |
|
558 |
int k = b[i] & 0xff; |
|
559 |
if (i != 0) { |
|
560 |
sb.append(':'); |
|
561 |
} |
|
562 |
sb.append(hexDigits[k >>> 4]); |
|
563 |
sb.append(hexDigits[k & 0xf]); |
|
564 |
} |
|
565 |
return sb.toString(); |
|
566 |
} |
|
567 |
||
568 |
public static byte[] parse(String s) { |
|
569 |
if (s.equals("(null)")) { |
|
570 |
return null; |
|
571 |
} |
|
572 |
try { |
|
573 |
int n = s.length(); |
|
574 |
ByteArrayOutputStream out = new ByteArrayOutputStream(n / 3); |
|
575 |
StringReader r = new StringReader(s); |
|
576 |
while (true) { |
|
577 |
int b1 = nextNibble(r); |
|
578 |
if (b1 < 0) { |
|
579 |
break; |
|
580 |
} |
|
581 |
int b2 = nextNibble(r); |
|
582 |
if (b2 < 0) { |
|
583 |
throw new RuntimeException("Invalid string " + s); |
|
584 |
} |
|
585 |
int b = (b1 << 4) | b2; |
|
586 |
out.write(b); |
|
587 |
} |
|
588 |
return out.toByteArray(); |
|
589 |
} catch (IOException e) { |
|
590 |
throw new RuntimeException(e); |
|
591 |
} |
|
592 |
} |
|
593 |
||
594 |
private static int nextNibble(StringReader r) throws IOException { |
|
595 |
while (true) { |
|
596 |
int ch = r.read(); |
|
597 |
if (ch == -1) { |
|
598 |
return -1; |
|
599 |
} else if ((ch >= '0') && (ch <= '9')) { |
|
600 |
return ch - '0'; |
|
601 |
} else if ((ch >= 'a') && (ch <= 'f')) { |
|
602 |
return ch - 'a' + 10; |
|
603 |
} else if ((ch >= 'A') && (ch <= 'F')) { |
|
604 |
return ch - 'A' + 10; |
|
605 |
} |
|
606 |
} |
|
607 |
} |
|
608 |
||
609 |
<T> T[] concat(T[] a, T[] b) { |
|
610 |
if ((b == null) || (b.length == 0)) { |
|
611 |
return a; |
|
612 |
} |
|
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
613 |
T[] r = Arrays.copyOf(a, a.length + b.length); |
2 | 614 |
System.arraycopy(b, 0, r, a.length, b.length); |
615 |
return r; |
|
616 |
} |
|
617 |
||
28403 | 618 |
/** |
619 |
* Returns supported algorithms of specified type. |
|
620 |
*/ |
|
621 |
static List<String> getSupportedAlgorithms(String type, String alg, |
|
622 |
Provider p) { |
|
623 |
// prepare a list of supported algorithms |
|
624 |
List<String> algorithms = new ArrayList<>(); |
|
625 |
Set<Provider.Service> services = p.getServices(); |
|
626 |
for (Provider.Service service : services) { |
|
627 |
if (service.getType().equals(type) |
|
628 |
&& service.getAlgorithm().startsWith(alg)) { |
|
629 |
algorithms.add(service.getAlgorithm()); |
|
630 |
} |
|
631 |
} |
|
632 |
return algorithms; |
|
633 |
} |
|
634 |
||
32138
23830562d3d1
8133318: Exclude intermittent failing PKCS11 tests on Solaris SPARC 11.1 and earlier
vinnie
parents:
31270
diff
changeset
|
635 |
/** |
23830562d3d1
8133318: Exclude intermittent failing PKCS11 tests on Solaris SPARC 11.1 and earlier
vinnie
parents:
31270
diff
changeset
|
636 |
* Get the identifier for the operating system distribution |
23830562d3d1
8133318: Exclude intermittent failing PKCS11 tests on Solaris SPARC 11.1 and earlier
vinnie
parents:
31270
diff
changeset
|
637 |
*/ |
23830562d3d1
8133318: Exclude intermittent failing PKCS11 tests on Solaris SPARC 11.1 and earlier
vinnie
parents:
31270
diff
changeset
|
638 |
public String getDistro() { |
23830562d3d1
8133318: Exclude intermittent failing PKCS11 tests on Solaris SPARC 11.1 and earlier
vinnie
parents:
31270
diff
changeset
|
639 |
|
23830562d3d1
8133318: Exclude intermittent failing PKCS11 tests on Solaris SPARC 11.1 and earlier
vinnie
parents:
31270
diff
changeset
|
640 |
try (BufferedReader in = |
23830562d3d1
8133318: Exclude intermittent failing PKCS11 tests on Solaris SPARC 11.1 and earlier
vinnie
parents:
31270
diff
changeset
|
641 |
new BufferedReader(new InputStreamReader( |
23830562d3d1
8133318: Exclude intermittent failing PKCS11 tests on Solaris SPARC 11.1 and earlier
vinnie
parents:
31270
diff
changeset
|
642 |
Runtime.getRuntime().exec("uname -v").getInputStream()))) { |
23830562d3d1
8133318: Exclude intermittent failing PKCS11 tests on Solaris SPARC 11.1 and earlier
vinnie
parents:
31270
diff
changeset
|
643 |
|
23830562d3d1
8133318: Exclude intermittent failing PKCS11 tests on Solaris SPARC 11.1 and earlier
vinnie
parents:
31270
diff
changeset
|
644 |
return in.readLine(); |
23830562d3d1
8133318: Exclude intermittent failing PKCS11 tests on Solaris SPARC 11.1 and earlier
vinnie
parents:
31270
diff
changeset
|
645 |
} catch (Exception e) { |
23830562d3d1
8133318: Exclude intermittent failing PKCS11 tests on Solaris SPARC 11.1 and earlier
vinnie
parents:
31270
diff
changeset
|
646 |
return ""; |
23830562d3d1
8133318: Exclude intermittent failing PKCS11 tests on Solaris SPARC 11.1 and earlier
vinnie
parents:
31270
diff
changeset
|
647 |
} |
23830562d3d1
8133318: Exclude intermittent failing PKCS11 tests on Solaris SPARC 11.1 and earlier
vinnie
parents:
31270
diff
changeset
|
648 |
} |
32635
d7e4ba3c2e0d
8048622: Enhance tests for PKCS11 keystores with NSS
asmotrak
parents:
32138
diff
changeset
|
649 |
|
d7e4ba3c2e0d
8048622: Enhance tests for PKCS11 keystores with NSS
asmotrak
parents:
32138
diff
changeset
|
650 |
static byte[] generateData(int length) { |
d7e4ba3c2e0d
8048622: Enhance tests for PKCS11 keystores with NSS
asmotrak
parents:
32138
diff
changeset
|
651 |
byte data[] = new byte[length]; |
d7e4ba3c2e0d
8048622: Enhance tests for PKCS11 keystores with NSS
asmotrak
parents:
32138
diff
changeset
|
652 |
for (int i=0; i<data.length; i++) { |
d7e4ba3c2e0d
8048622: Enhance tests for PKCS11 keystores with NSS
asmotrak
parents:
32138
diff
changeset
|
653 |
data[i] = (byte) (i % 256); |
d7e4ba3c2e0d
8048622: Enhance tests for PKCS11 keystores with NSS
asmotrak
parents:
32138
diff
changeset
|
654 |
} |
d7e4ba3c2e0d
8048622: Enhance tests for PKCS11 keystores with NSS
asmotrak
parents:
32138
diff
changeset
|
655 |
return data; |
d7e4ba3c2e0d
8048622: Enhance tests for PKCS11 keystores with NSS
asmotrak
parents:
32138
diff
changeset
|
656 |
} |
2 | 657 |
} |