author | prr |
Fri, 25 May 2018 12:12:24 -0700 | |
changeset 50347 | b2f046ae8eb6 |
parent 48665 | 257d7610663f |
child 50731 | ed322b4cfe49 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
48547
7537c762d42d
8194864: Outputs more details for PKCS11 tests if the NSS lib version cannot be determined
jjiang
parents:
48248
diff
changeset
|
2 |
* Copyright (c) 2003, 2018, 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 |
||
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
27 |
import java.io.BufferedReader; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
28 |
import java.io.ByteArrayOutputStream; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
29 |
import java.io.File; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
30 |
import java.io.FileInputStream; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
31 |
import java.io.IOException; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
32 |
import java.io.InputStreamReader; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
33 |
import java.io.StringReader; |
48665
257d7610663f
8186098: sun/security/pkcs11/KeyStore/SecretKeysBasic.sh failed due to libnss3 version cannot be parsed
jjiang
parents:
48608
diff
changeset
|
34 |
import java.nio.charset.StandardCharsets; |
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
35 |
import java.security.AlgorithmParameters; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
36 |
import java.security.InvalidAlgorithmParameterException; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
37 |
import java.security.KeyPairGenerator; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
38 |
import java.security.NoSuchProviderException; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
39 |
import java.security.Provider; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
40 |
import java.security.ProviderException; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
41 |
import java.security.Security; |
21977
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
42 |
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
|
43 |
import java.security.spec.ECParameterSpec; |
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
44 |
import java.util.ArrayList; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
45 |
import java.util.Arrays; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
46 |
import java.util.HashMap; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
47 |
import java.util.Iterator; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
48 |
import java.util.List; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
49 |
import java.util.Map; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
50 |
import java.util.Properties; |
41556
0c49ded763a8
8168078: Remove permission to read all system properties granted to the jdk.crypto.ec module
mullan
parents:
41485
diff
changeset
|
51 |
import java.util.ServiceConfigurationError; |
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
52 |
import java.util.ServiceLoader; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
53 |
import java.util.Set; |
2 | 54 |
|
55 |
public abstract class PKCS11Test { |
|
56 |
||
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
57 |
private boolean enableSM = false; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
58 |
|
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
59 |
static final Properties props = System.getProperties(); |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
60 |
|
32635
d7e4ba3c2e0d
8048622: Enhance tests for PKCS11 keystores with NSS
asmotrak
parents:
32138
diff
changeset
|
61 |
static final String PKCS11 = "PKCS11"; |
d7e4ba3c2e0d
8048622: Enhance tests for PKCS11 keystores with NSS
asmotrak
parents:
32138
diff
changeset
|
62 |
|
2 | 63 |
// directory of the test source |
64 |
static final String BASE = System.getProperty("test.src", "."); |
|
65 |
||
66 |
static final char SEP = File.separatorChar; |
|
67 |
||
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
68 |
private static final String DEFAULT_POLICY = |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
69 |
BASE + SEP + ".." + SEP + "policy"; |
2 | 70 |
|
71 |
// directory corresponding to BASE in the /closed hierarchy |
|
72 |
static final String CLOSED_BASE; |
|
73 |
||
74 |
static { |
|
75 |
// hack |
|
76 |
String absBase = new File(BASE).getAbsolutePath(); |
|
77 |
int k = absBase.indexOf(SEP + "test" + SEP + "sun" + SEP); |
|
78 |
if (k < 0) k = 0; |
|
79 |
String p1 = absBase.substring(0, k + 6); |
|
80 |
String p2 = absBase.substring(k + 5); |
|
81 |
CLOSED_BASE = p1 + "closed" + p2; |
|
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
82 |
|
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
83 |
// set it as a system property to make it available in policy file |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
84 |
System.setProperty("closed.base", CLOSED_BASE); |
2 | 85 |
} |
86 |
||
19067
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
87 |
// NSS version info |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
88 |
public static enum ECCState { None, Basic, Extended }; |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
89 |
static double nss_version = -1; |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
90 |
static ECCState nss_ecc_status = ECCState.Extended; |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
91 |
|
19066 | 92 |
// The NSS library we need to search for in getNSSLibDir() |
93 |
// Default is "libsoftokn3.so", listed as "softokn3" |
|
94 |
// The other is "libnss3.so", listed as "nss3". |
|
95 |
static String nss_library = "softokn3"; |
|
96 |
||
24863
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
97 |
// 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
|
98 |
// 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
|
99 |
static double softoken3_version = -1; |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
100 |
static double nss3_version = -1; |
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
101 |
static Provider pkcs11; |
24863
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
102 |
|
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
103 |
// Goes through ServiceLoader instead of Provider.getInstance() since it |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
104 |
// works on all platforms |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
105 |
static { |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
106 |
ServiceLoader sl = ServiceLoader.load(java.security.Provider.class); |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
107 |
Iterator<Provider> iter = sl.iterator(); |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
108 |
Provider p = null; |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
109 |
boolean found = false; |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
110 |
while (iter.hasNext()) { |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
111 |
try { |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
112 |
p = iter.next(); |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
113 |
if (p.getName().equals("SunPKCS11")) { |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
114 |
found = true; |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
115 |
break; |
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
116 |
} |
41556
0c49ded763a8
8168078: Remove permission to read all system properties granted to the jdk.crypto.ec module
mullan
parents:
41485
diff
changeset
|
117 |
} catch (Exception | ServiceConfigurationError e) { |
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
118 |
// ignore and move on to the next one |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
119 |
} |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
120 |
} |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
121 |
// Nothing found through ServiceLoader; fall back to reflection |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
122 |
if (!found) { |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
123 |
try { |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
124 |
Class clazz = Class.forName("sun.security.pkcs11.SunPKCS11"); |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
125 |
p = (Provider) clazz.newInstance(); |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
126 |
} catch (Exception ex) { |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
127 |
ex.printStackTrace(); |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
128 |
} |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
129 |
} |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
130 |
pkcs11 = p; |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
131 |
} |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
132 |
|
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
133 |
/* |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
134 |
* Use Solaris SPARC 11.2 or later to avoid an intermittent failure |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
135 |
* when running SunPKCS11-Solaris (8044554) |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
136 |
*/ |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
137 |
static boolean isBadSolarisSparc(Provider p) { |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
138 |
if ("SunPKCS11-Solaris".equals(p.getName()) && badSolarisSparc) { |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
139 |
System.out.println("SunPKCS11-Solaris provider requires " + |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
140 |
"Solaris SPARC 11.2 or later, skipping"); |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
141 |
return true; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
142 |
} |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
143 |
return false; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
144 |
} |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
145 |
|
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
146 |
// Return a SunPKCS11 provider configured with the specified config file |
2 | 147 |
static Provider getSunPKCS11(String config) throws Exception { |
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
148 |
if (pkcs11 == null) { |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
149 |
throw new NoSuchProviderException("No PKCS11 provider available"); |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
150 |
} |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
151 |
return pkcs11.configure(config); |
2 | 152 |
} |
153 |
||
154 |
public abstract void main(Provider p) throws Exception; |
|
155 |
||
156 |
private void premain(Provider p) throws Exception { |
|
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
157 |
// set a security manager and policy before a test case runs, |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
158 |
// and disable them after the test case finished |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
159 |
try { |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
160 |
if (enableSM) { |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
161 |
System.setSecurityManager(new SecurityManager()); |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
162 |
} |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
163 |
long start = System.currentTimeMillis(); |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
164 |
System.out.printf( |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
165 |
"Running test with provider %s (security manager %s) ...%n", |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
166 |
p.getName(), enableSM ? "enabled" : "disabled"); |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
167 |
main(p); |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
168 |
long stop = System.currentTimeMillis(); |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
169 |
System.out.println("Completed test with provider " + p.getName() + |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
170 |
" (" + (stop - start) + " ms)."); |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
171 |
} finally { |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
172 |
if (enableSM) { |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
173 |
System.setSecurityManager(null); |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
174 |
} |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
175 |
} |
2 | 176 |
} |
177 |
||
178 |
public static void main(PKCS11Test test) throws Exception { |
|
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
179 |
main(test, null); |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
180 |
} |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
181 |
|
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
182 |
public static void main(PKCS11Test test, String[] args) throws Exception { |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
183 |
if (args != null) { |
37353
e8e684b89c81
8153545: sun/security/pkcs11/Provider/Login.sh fails on Linux
amjiang
parents:
36249
diff
changeset
|
184 |
if (args.length > 0) { |
e8e684b89c81
8153545: sun/security/pkcs11/Provider/Login.sh fails on Linux
amjiang
parents:
36249
diff
changeset
|
185 |
if ("sm".equals(args[0])) { |
e8e684b89c81
8153545: sun/security/pkcs11/Provider/Login.sh fails on Linux
amjiang
parents:
36249
diff
changeset
|
186 |
test.enableSM = true; |
e8e684b89c81
8153545: sun/security/pkcs11/Provider/Login.sh fails on Linux
amjiang
parents:
36249
diff
changeset
|
187 |
} else { |
e8e684b89c81
8153545: sun/security/pkcs11/Provider/Login.sh fails on Linux
amjiang
parents:
36249
diff
changeset
|
188 |
throw new RuntimeException("Unknown Command, use 'sm' as " |
e8e684b89c81
8153545: sun/security/pkcs11/Provider/Login.sh fails on Linux
amjiang
parents:
36249
diff
changeset
|
189 |
+ "first arguemtn to enable security manager"); |
e8e684b89c81
8153545: sun/security/pkcs11/Provider/Login.sh fails on Linux
amjiang
parents:
36249
diff
changeset
|
190 |
} |
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
191 |
} |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
192 |
if (test.enableSM) { |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
193 |
System.setProperty("java.security.policy", |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
194 |
(args.length > 1) ? BASE + SEP + args[1] |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
195 |
: DEFAULT_POLICY); |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
196 |
} |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
197 |
} |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
198 |
|
10328 | 199 |
Provider[] oldProviders = Security.getProviders(); |
200 |
try { |
|
201 |
System.out.println("Beginning test run " + test.getClass().getName() + "..."); |
|
202 |
testDefault(test); |
|
203 |
testNSS(test); |
|
204 |
testDeimos(test); |
|
205 |
} finally { |
|
19066 | 206 |
// NOTE: Do not place a 'return' in any finally block |
207 |
// as it will suppress exceptions and hide test failures. |
|
10328 | 208 |
Provider[] newProviders = Security.getProviders(); |
19066 | 209 |
boolean found = true; |
10328 | 210 |
// Do not restore providers if nothing changed. This is especailly |
211 |
// useful for ./Provider/Login.sh, where a SecurityManager exists. |
|
212 |
if (oldProviders.length == newProviders.length) { |
|
19066 | 213 |
found = false; |
10328 | 214 |
for (int i = 0; i<oldProviders.length; i++) { |
215 |
if (oldProviders[i] != newProviders[i]) { |
|
216 |
found = true; |
|
217 |
break; |
|
218 |
} |
|
219 |
} |
|
220 |
} |
|
19066 | 221 |
if (found) { |
222 |
for (Provider p: newProviders) { |
|
223 |
Security.removeProvider(p.getName()); |
|
224 |
} |
|
225 |
for (Provider p: oldProviders) { |
|
226 |
Security.addProvider(p); |
|
227 |
} |
|
10328 | 228 |
} |
229 |
} |
|
2 | 230 |
} |
231 |
||
232 |
public static void testDeimos(PKCS11Test test) throws Exception { |
|
233 |
if (new File("/opt/SUNWconn/lib/libpkcs11.so").isFile() == false || |
|
234 |
"true".equals(System.getProperty("NO_DEIMOS"))) { |
|
235 |
return; |
|
236 |
} |
|
237 |
String base = getBase(); |
|
238 |
String p11config = base + SEP + "nss" + SEP + "p11-deimos.txt"; |
|
239 |
Provider p = getSunPKCS11(p11config); |
|
240 |
test.premain(p); |
|
241 |
} |
|
242 |
||
243 |
public static void testDefault(PKCS11Test test) throws Exception { |
|
244 |
// run test for default configured PKCS11 providers (if any) |
|
245 |
||
246 |
if ("true".equals(System.getProperty("NO_DEFAULT"))) { |
|
247 |
return; |
|
248 |
} |
|
249 |
||
250 |
Provider[] providers = Security.getProviders(); |
|
251 |
for (int i = 0; i < providers.length; i++) { |
|
252 |
Provider p = providers[i]; |
|
253 |
if (p.getName().startsWith("SunPKCS11-")) { |
|
254 |
test.premain(p); |
|
255 |
} |
|
256 |
} |
|
257 |
} |
|
258 |
||
259 |
private static String PKCS11_BASE; |
|
12294
f313586fc3cc
7152582: PKCS11 tests should use the NSS libraries available in the OS
vinnie
parents:
12042
diff
changeset
|
260 |
static { |
f313586fc3cc
7152582: PKCS11 tests should use the NSS libraries available in the OS
vinnie
parents:
12042
diff
changeset
|
261 |
try { |
f313586fc3cc
7152582: PKCS11 tests should use the NSS libraries available in the OS
vinnie
parents:
12042
diff
changeset
|
262 |
PKCS11_BASE = getBase(); |
f313586fc3cc
7152582: PKCS11 tests should use the NSS libraries available in the OS
vinnie
parents:
12042
diff
changeset
|
263 |
} catch (Exception e) { |
f313586fc3cc
7152582: PKCS11 tests should use the NSS libraries available in the OS
vinnie
parents:
12042
diff
changeset
|
264 |
// ignore |
f313586fc3cc
7152582: PKCS11 tests should use the NSS libraries available in the OS
vinnie
parents:
12042
diff
changeset
|
265 |
} |
f313586fc3cc
7152582: PKCS11 tests should use the NSS libraries available in the OS
vinnie
parents:
12042
diff
changeset
|
266 |
} |
2 | 267 |
|
268 |
private final static String PKCS11_REL_PATH = "sun/security/pkcs11"; |
|
269 |
||
270 |
public static String getBase() throws Exception { |
|
271 |
if (PKCS11_BASE != null) { |
|
272 |
return PKCS11_BASE; |
|
273 |
} |
|
274 |
File cwd = new File(System.getProperty("test.src", ".")).getCanonicalFile(); |
|
275 |
while (true) { |
|
276 |
File file = new File(cwd, "TEST.ROOT"); |
|
277 |
if (file.isFile()) { |
|
278 |
break; |
|
279 |
} |
|
280 |
cwd = cwd.getParentFile(); |
|
281 |
if (cwd == null) { |
|
282 |
throw new Exception("Test root directory not found"); |
|
283 |
} |
|
284 |
} |
|
285 |
PKCS11_BASE = new File(cwd, PKCS11_REL_PATH.replace('/', SEP)).getAbsolutePath(); |
|
286 |
return PKCS11_BASE; |
|
287 |
} |
|
288 |
||
289 |
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
|
290 |
return getNSSLibDir(nss_library); |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
291 |
} |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
292 |
|
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
293 |
static String getNSSLibDir(String library) throws Exception { |
2 | 294 |
String osName = props.getProperty("os.name"); |
295 |
if (osName.startsWith("Win")) { |
|
296 |
osName = "Windows"; |
|
26958 | 297 |
} else if (osName.equals("Mac OS X")) { |
298 |
osName = "MacOSX"; |
|
2 | 299 |
} |
300 |
String osid = osName + "-" |
|
301 |
+ 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
|
302 |
String[] nssLibDirs = osMap.get(osid); |
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
303 |
if (nssLibDirs == null) { |
41485
15a87b8ccd06
8164322: Test sun/security/pkcs11/PKCS11Test.java shall be updated to run on ARM platforms
tidu
parents:
40942
diff
changeset
|
304 |
System.out.println("Warning: unsupported OS: " + osid |
15a87b8ccd06
8164322: Test sun/security/pkcs11/PKCS11Test.java shall be updated to run on ARM platforms
tidu
parents:
40942
diff
changeset
|
305 |
+ ", please initialize NSS librarys location firstly, skipping test"); |
2 | 306 |
return null; |
307 |
} |
|
13565
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
308 |
if (nssLibDirs.length == 0) { |
41485
15a87b8ccd06
8164322: Test sun/security/pkcs11/PKCS11Test.java shall be updated to run on ARM platforms
tidu
parents:
40942
diff
changeset
|
309 |
System.out.println("Warning: NSS not supported on this platform, skipping test"); |
2 | 310 |
return null; |
311 |
} |
|
13565
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
312 |
String nssLibDir = null; |
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
313 |
for (String dir : nssLibDirs) { |
19066 | 314 |
if (new File(dir).exists() && |
24863
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
315 |
new File(dir + System.mapLibraryName(library)).exists()) { |
13565
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
316 |
nssLibDir = dir; |
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
317 |
System.setProperty("pkcs11test.nss.libdir", nssLibDir); |
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
318 |
break; |
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
319 |
} |
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
320 |
} |
41485
15a87b8ccd06
8164322: Test sun/security/pkcs11/PKCS11Test.java shall be updated to run on ARM platforms
tidu
parents:
40942
diff
changeset
|
321 |
if (nssLibDir == null) { |
15a87b8ccd06
8164322: Test sun/security/pkcs11/PKCS11Test.java shall be updated to run on ARM platforms
tidu
parents:
40942
diff
changeset
|
322 |
System.out.println("Warning: can't find NSS librarys on this machine, skipping test"); |
15a87b8ccd06
8164322: Test sun/security/pkcs11/PKCS11Test.java shall be updated to run on ARM platforms
tidu
parents:
40942
diff
changeset
|
323 |
return null; |
15a87b8ccd06
8164322: Test sun/security/pkcs11/PKCS11Test.java shall be updated to run on ARM platforms
tidu
parents:
40942
diff
changeset
|
324 |
} |
12294
f313586fc3cc
7152582: PKCS11 tests should use the NSS libraries available in the OS
vinnie
parents:
12042
diff
changeset
|
325 |
return nssLibDir; |
2 | 326 |
} |
327 |
||
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
328 |
static boolean isBadNSSVersion(Provider p) { |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
329 |
if (isNSS(p) && badNSSVersion) { |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
330 |
System.out.println("NSS 3.11 has a DER issue that recent " + |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
331 |
"version do not."); |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
332 |
return true; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
333 |
} |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
334 |
return false; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
335 |
} |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
336 |
|
10328 | 337 |
protected static void safeReload(String lib) throws Exception { |
338 |
try { |
|
339 |
System.load(lib); |
|
340 |
} catch (UnsatisfiedLinkError e) { |
|
341 |
if (e.getMessage().contains("already loaded")) { |
|
342 |
return; |
|
343 |
} |
|
344 |
} |
|
345 |
} |
|
346 |
||
2 | 347 |
static boolean loadNSPR(String libdir) throws Exception { |
348 |
// load NSS softoken dependencies in advance to avoid resolver issues |
|
40942
7a81fdff5752
8077138: Some PKCS11 tests fail because NSS library is not initialized
jjiang
parents:
37353
diff
changeset
|
349 |
safeReload(libdir + System.mapLibraryName("nspr4")); |
7a81fdff5752
8077138: Some PKCS11 tests fail because NSS library is not initialized
jjiang
parents:
37353
diff
changeset
|
350 |
safeReload(libdir + System.mapLibraryName("plc4")); |
7a81fdff5752
8077138: Some PKCS11 tests fail because NSS library is not initialized
jjiang
parents:
37353
diff
changeset
|
351 |
safeReload(libdir + System.mapLibraryName("plds4")); |
12294
f313586fc3cc
7152582: PKCS11 tests should use the NSS libraries available in the OS
vinnie
parents:
12042
diff
changeset
|
352 |
safeReload(libdir + System.mapLibraryName("sqlite3")); |
f313586fc3cc
7152582: PKCS11 tests should use the NSS libraries available in the OS
vinnie
parents:
12042
diff
changeset
|
353 |
safeReload(libdir + System.mapLibraryName("nssutil3")); |
2 | 354 |
return true; |
355 |
} |
|
356 |
||
19067
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
357 |
// Check the provider being used is NSS |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
358 |
public static boolean isNSS(Provider p) { |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
359 |
return p.getName().toUpperCase().equals("SUNPKCS11-NSS"); |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
360 |
} |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
361 |
|
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
362 |
static double getNSSVersion() { |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
363 |
if (nss_version == -1) |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
364 |
getNSSInfo(); |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
365 |
return nss_version; |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
366 |
} |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
367 |
|
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
368 |
static ECCState getNSSECC() { |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
369 |
if (nss_version == -1) |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
370 |
getNSSInfo(); |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
371 |
return nss_ecc_status; |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
372 |
} |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
373 |
|
24863
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
374 |
public static double getLibsoftokn3Version() { |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
375 |
if (softoken3_version == -1) |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
376 |
return getNSSInfo("softokn3"); |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
377 |
return softoken3_version; |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
378 |
} |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
379 |
|
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
380 |
public static double getLibnss3Version() { |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
381 |
if (nss3_version == -1) |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
382 |
return getNSSInfo("nss3"); |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
383 |
return nss3_version; |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
384 |
} |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
385 |
|
19067
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
386 |
/* 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
|
387 |
static void getNSSInfo() { |
24863
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
388 |
getNSSInfo(nss_library); |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
389 |
} |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
390 |
|
48665
257d7610663f
8186098: sun/security/pkcs11/KeyStore/SecretKeysBasic.sh failed due to libnss3 version cannot be parsed
jjiang
parents:
48608
diff
changeset
|
391 |
// Try to parse the version for the specified library. |
257d7610663f
8186098: sun/security/pkcs11/KeyStore/SecretKeysBasic.sh failed due to libnss3 version cannot be parsed
jjiang
parents:
48608
diff
changeset
|
392 |
// Assuming the library contains either of the following patterns: |
257d7610663f
8186098: sun/security/pkcs11/KeyStore/SecretKeysBasic.sh failed due to libnss3 version cannot be parsed
jjiang
parents:
48608
diff
changeset
|
393 |
// $Header: NSS <version> |
257d7610663f
8186098: sun/security/pkcs11/KeyStore/SecretKeysBasic.sh failed due to libnss3 version cannot be parsed
jjiang
parents:
48608
diff
changeset
|
394 |
// Version: NSS <version> |
257d7610663f
8186098: sun/security/pkcs11/KeyStore/SecretKeysBasic.sh failed due to libnss3 version cannot be parsed
jjiang
parents:
48608
diff
changeset
|
395 |
// Here, <version> stands for NSS version. |
24863
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
396 |
static double getNSSInfo(String library) { |
36249
8b92e4bedbd4
8138653: Default key sizes for the AlgorithmParameterGenerator and KeyPairGenerator implementations should be upgraded
mullan
parents:
35379
diff
changeset
|
397 |
// look for two types of headers in NSS libraries |
8b92e4bedbd4
8138653: Default key sizes for the AlgorithmParameterGenerator and KeyPairGenerator implementations should be upgraded
mullan
parents:
35379
diff
changeset
|
398 |
String nssHeader1 = "$Header: NSS"; |
8b92e4bedbd4
8138653: Default key sizes for the AlgorithmParameterGenerator and KeyPairGenerator implementations should be upgraded
mullan
parents:
35379
diff
changeset
|
399 |
String nssHeader2 = "Version: NSS"; |
19067
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
400 |
boolean found = false; |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
401 |
String s = null; |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
402 |
int i = 0; |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
403 |
String libfile = ""; |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
404 |
|
24863
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
405 |
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
|
406 |
return softoken3_version; |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
407 |
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
|
408 |
return nss3_version; |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
409 |
|
19067
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
410 |
try { |
24863
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
411 |
libfile = getNSSLibDir() + System.mapLibraryName(library); |
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
412 |
try (FileInputStream is = new FileInputStream(libfile)) { |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
413 |
byte[] data = new byte[1000]; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
414 |
int read = 0; |
19067
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
415 |
|
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
416 |
while (is.available() > 0) { |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
417 |
if (read == 0) { |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
418 |
read = is.read(data, 0, 1000); |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
419 |
} else { |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
420 |
// Prepend last 100 bytes in case the header was split |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
421 |
// between the reads. |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
422 |
System.arraycopy(data, 900, data, 0, 100); |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
423 |
read = 100 + is.read(data, 100, 900); |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
424 |
} |
19067
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
425 |
|
48665
257d7610663f
8186098: sun/security/pkcs11/KeyStore/SecretKeysBasic.sh failed due to libnss3 version cannot be parsed
jjiang
parents:
48608
diff
changeset
|
426 |
s = new String(data, 0, read, StandardCharsets.US_ASCII); |
36249
8b92e4bedbd4
8138653: Default key sizes for the AlgorithmParameterGenerator and KeyPairGenerator implementations should be upgraded
mullan
parents:
35379
diff
changeset
|
427 |
i = s.indexOf(nssHeader1); |
8b92e4bedbd4
8138653: Default key sizes for the AlgorithmParameterGenerator and KeyPairGenerator implementations should be upgraded
mullan
parents:
35379
diff
changeset
|
428 |
if (i > 0 || (i = s.indexOf(nssHeader2)) > 0) { |
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
429 |
found = true; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
430 |
// If the nssHeader is before 920 we can break, otherwise |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
431 |
// we may not have the whole header so do another read. If |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
432 |
// no bytes are in the stream, that is ok, found is true. |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
433 |
if (i < 920) { |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
434 |
break; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
435 |
} |
19067
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
436 |
} |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
437 |
} |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
438 |
} |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
439 |
} catch (Exception e) { |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
440 |
e.printStackTrace(); |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
441 |
} |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
442 |
|
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
443 |
if (!found) { |
24863
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
444 |
System.out.println("lib" + library + |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
445 |
" 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
|
446 |
nss_version = 0.0; |
24863
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
447 |
return nss_version; |
19067
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
448 |
} |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
449 |
|
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
450 |
// the index after whitespace after nssHeader |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
451 |
int afterheader = s.indexOf("NSS", i) + 4; |
48665
257d7610663f
8186098: sun/security/pkcs11/KeyStore/SecretKeysBasic.sh failed due to libnss3 version cannot be parsed
jjiang
parents:
48608
diff
changeset
|
452 |
String version = String.valueOf(s.charAt(afterheader)); |
257d7610663f
8186098: sun/security/pkcs11/KeyStore/SecretKeysBasic.sh failed due to libnss3 version cannot be parsed
jjiang
parents:
48608
diff
changeset
|
453 |
for (char c = s.charAt(++afterheader); |
257d7610663f
8186098: sun/security/pkcs11/KeyStore/SecretKeysBasic.sh failed due to libnss3 version cannot be parsed
jjiang
parents:
48608
diff
changeset
|
454 |
c == '.' || (c >= '0' && c <= '9'); |
257d7610663f
8186098: sun/security/pkcs11/KeyStore/SecretKeysBasic.sh failed due to libnss3 version cannot be parsed
jjiang
parents:
48608
diff
changeset
|
455 |
c = s.charAt(++afterheader)) { |
257d7610663f
8186098: sun/security/pkcs11/KeyStore/SecretKeysBasic.sh failed due to libnss3 version cannot be parsed
jjiang
parents:
48608
diff
changeset
|
456 |
version += c; |
48547
7537c762d42d
8194864: Outputs more details for PKCS11 tests if the NSS lib version cannot be determined
jjiang
parents:
48248
diff
changeset
|
457 |
} |
7537c762d42d
8194864: Outputs more details for PKCS11 tests if the NSS lib version cannot be determined
jjiang
parents:
48248
diff
changeset
|
458 |
|
19067
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
459 |
// 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
|
460 |
String[] dot = version.split("\\."); |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
461 |
if (dot.length > 2) { |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
462 |
version = dot[0]+"."+dot[1]; |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
463 |
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
|
464 |
version += dot[j]; |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
465 |
} |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
466 |
} |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
467 |
|
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
468 |
// 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
|
469 |
try { |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
470 |
nss_version = Double.parseDouble(version); |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
471 |
} catch (NumberFormatException e) { |
48665
257d7610663f
8186098: sun/security/pkcs11/KeyStore/SecretKeysBasic.sh failed due to libnss3 version cannot be parsed
jjiang
parents:
48608
diff
changeset
|
472 |
System.out.println("===== Content start ====="); |
257d7610663f
8186098: sun/security/pkcs11/KeyStore/SecretKeysBasic.sh failed due to libnss3 version cannot be parsed
jjiang
parents:
48608
diff
changeset
|
473 |
System.out.println(s); |
257d7610663f
8186098: sun/security/pkcs11/KeyStore/SecretKeysBasic.sh failed due to libnss3 version cannot be parsed
jjiang
parents:
48608
diff
changeset
|
474 |
System.out.println("===== Content end ====="); |
24863
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
475 |
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
|
476 |
" version. Set to 0.0"); |
19067
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
477 |
e.printStackTrace(); |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
478 |
} |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
479 |
|
24863
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
480 |
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
|
481 |
|
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
482 |
// Check for ECC |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
483 |
if (s.indexOf("Basic") > 0) { |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
484 |
nss_ecc_status = ECCState.Basic; |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
485 |
System.out.println("ECC Basic."); |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
486 |
} else if (s.indexOf("Extended") > 0) { |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
487 |
nss_ecc_status = ECCState.Extended; |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
488 |
System.out.println("ECC Extended."); |
24863
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
489 |
} else { |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
490 |
System.out.println("ECC None."); |
19067
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
491 |
} |
24863
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
492 |
|
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
493 |
if (library.compareTo("softokn3") == 0) { |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
494 |
softoken3_version = nss_version; |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
495 |
} else if (library.compareTo("nss3") == 0) { |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
496 |
nss3_version = nss_version; |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
497 |
} |
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
498 |
|
bf6df3caafe4
8039212: SecretKeyBasic.sh needs to avoid NSS libnss3 and libsoftokn3 version mismatches
ascarpino
parents:
24629
diff
changeset
|
499 |
return nss_version; |
19067
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
500 |
} |
5271291b7121
8020424: The NSS version should be detected before running crypto tests
ascarpino
parents:
19066
diff
changeset
|
501 |
|
19066 | 502 |
// Used to set the nss_library file to search for libsoftokn3.so |
503 |
public static void useNSS() { |
|
504 |
nss_library = "nss3"; |
|
505 |
} |
|
506 |
||
2 | 507 |
public static void testNSS(PKCS11Test test) throws Exception { |
508 |
String libdir = getNSSLibDir(); |
|
509 |
if (libdir == null) { |
|
510 |
return; |
|
511 |
} |
|
512 |
String base = getBase(); |
|
513 |
||
514 |
if (loadNSPR(libdir) == false) { |
|
515 |
return; |
|
516 |
} |
|
517 |
||
19066 | 518 |
String libfile = libdir + System.mapLibraryName(nss_library); |
2 | 519 |
|
520 |
String customDBdir = System.getProperty("CUSTOM_DB_DIR"); |
|
521 |
String dbdir = (customDBdir != null) ? |
|
522 |
customDBdir : |
|
523 |
base + SEP + "nss" + SEP + "db"; |
|
524 |
// NSS always wants forward slashes for the config path |
|
525 |
dbdir = dbdir.replace('\\', '/'); |
|
526 |
||
527 |
String customConfig = System.getProperty("CUSTOM_P11_CONFIG"); |
|
528 |
String customConfigName = System.getProperty("CUSTOM_P11_CONFIG_NAME", "p11-nss.txt"); |
|
529 |
String p11config = (customConfig != null) ? |
|
530 |
customConfig : |
|
531 |
base + SEP + "nss" + SEP + customConfigName; |
|
532 |
||
533 |
System.setProperty("pkcs11test.nss.lib", libfile); |
|
534 |
System.setProperty("pkcs11test.nss.db", dbdir); |
|
535 |
Provider p = getSunPKCS11(p11config); |
|
536 |
test.premain(p); |
|
537 |
} |
|
538 |
||
21977
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
539 |
// Generate a vector of supported elliptic curves of a given provider |
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
540 |
static List<ECParameterSpec> getKnownCurves(Provider p) throws Exception { |
21977
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
541 |
int index; |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
542 |
int begin; |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
543 |
int end; |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
544 |
String curve; |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
545 |
|
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
546 |
List<ECParameterSpec> results = new ArrayList<>(); |
21977
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
547 |
// 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
|
548 |
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
|
549 |
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
|
550 |
|
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
551 |
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
|
552 |
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
|
553 |
"\"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
|
554 |
} |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
555 |
|
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
556 |
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
|
557 |
index = 0; |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
558 |
for (;;) { |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
559 |
// 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
|
560 |
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
|
561 |
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
|
562 |
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
|
563 |
break; |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
564 |
} |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
565 |
|
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
566 |
/* |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
567 |
* 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
|
568 |
* 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
|
569 |
*/ |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
570 |
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
|
571 |
begin++; |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
572 |
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
|
573 |
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
|
574 |
// 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
|
575 |
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
|
576 |
} |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
577 |
|
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
578 |
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
|
579 |
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
|
580 |
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
|
581 |
try { |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
582 |
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
|
583 |
kpg.initialize(e); |
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
584 |
kpg.generateKeyPair(); |
21977
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
585 |
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
|
586 |
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
|
587 |
} 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
|
588 |
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
|
589 |
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
|
590 |
} 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
|
591 |
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
|
592 |
ex.getMessage()); |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
593 |
} |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
594 |
} |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
595 |
|
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
596 |
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
|
597 |
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
|
598 |
} |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
599 |
|
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
600 |
return results; |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
601 |
} |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
602 |
|
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
603 |
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
|
604 |
throws Exception { |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
605 |
|
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
606 |
AlgorithmParameters parameters = |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
607 |
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
|
608 |
|
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
609 |
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
|
610 |
|
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
611 |
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
|
612 |
} |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
613 |
|
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
614 |
// Check support for a curve with a provided Vector of EC support |
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
615 |
boolean checkSupport(List<ECParameterSpec> supportedEC, |
21977
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
616 |
ECParameterSpec curve) { |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
617 |
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
|
618 |
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
|
619 |
return true; |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
620 |
} |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
621 |
} |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
622 |
return false; |
17f538f05b73
8027218: TEST_BUG: sun/security/pkcs11/ec tests fail because of ever-changing key size restrictions
ascarpino
parents:
19067
diff
changeset
|
623 |
} |
2 | 624 |
|
13565
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
625 |
private static final Map<String,String[]> osMap; |
2 | 626 |
|
12294
f313586fc3cc
7152582: PKCS11 tests should use the NSS libraries available in the OS
vinnie
parents:
12042
diff
changeset
|
627 |
// Location of the NSS libraries on each supported platform |
2 | 628 |
static { |
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
629 |
osMap = new HashMap<>(); |
13565
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
630 |
osMap.put("SunOS-sparc-32", new String[]{"/usr/lib/mps/"}); |
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
631 |
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
|
632 |
osMap.put("SunOS-x86-32", new String[]{"/usr/lib/mps/"}); |
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
633 |
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
|
634 |
osMap.put("Linux-i386-32", new String[]{ |
24629
97bddac495b7
8044038: Security tests fail on 32 bit linux platform
vinnie
parents:
21977
diff
changeset
|
635 |
"/usr/lib/i386-linux-gnu/", "/usr/lib32/", "/usr/lib/"}); |
13565
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
636 |
osMap.put("Linux-amd64-64", new String[]{ |
19066 | 637 |
"/usr/lib/x86_64-linux-gnu/", "/usr/lib/x86_64-linux-gnu/nss/", |
638 |
"/usr/lib64/"}); |
|
33493
442660a9b96f
8140514: [TESTBUG] enable sun/security/pkcs11 tests on Linux/ppc64
simonis
parents:
32635
diff
changeset
|
639 |
osMap.put("Linux-ppc64-64", new String[]{"/usr/lib64/"}); |
35248
b0665ea22f83
8073139: PPC64: User-visible arch directory and os.arch value on ppc64le cause issues with Java tooling
asmundak
parents:
33493
diff
changeset
|
640 |
osMap.put("Linux-ppc64le-64", new String[]{"/usr/lib64/"}); |
48601
391502ceeed9
8194869: [TESTBUG][aix, s390] Adapt tests to platforms.
goetz
parents:
48248
diff
changeset
|
641 |
osMap.put("Linux-s390x-64", new String[]{"/usr/lib64/"}); |
13565
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
642 |
osMap.put("Windows-x86-32", new String[]{ |
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
643 |
PKCS11_BASE + "/nss/lib/windows-i586/".replace('/', SEP)}); |
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
644 |
osMap.put("Windows-amd64-64", new String[]{ |
6298d600104f
7190945: pkcs11 problem loading NSS libs on Ubuntu
vinnie
parents:
13250
diff
changeset
|
645 |
PKCS11_BASE + "/nss/lib/windows-amd64/".replace('/', SEP)}); |
26958 | 646 |
osMap.put("MacOSX-x86_64-64", new String[]{ |
647 |
PKCS11_BASE + "/nss/lib/macosx-x86_64/"}); |
|
41485
15a87b8ccd06
8164322: Test sun/security/pkcs11/PKCS11Test.java shall be updated to run on ARM platforms
tidu
parents:
40942
diff
changeset
|
648 |
osMap.put("Linux-arm-32", new String[]{ |
15a87b8ccd06
8164322: Test sun/security/pkcs11/PKCS11Test.java shall be updated to run on ARM platforms
tidu
parents:
40942
diff
changeset
|
649 |
"/usr/lib/arm-linux-gnueabi/nss/", |
15a87b8ccd06
8164322: Test sun/security/pkcs11/PKCS11Test.java shall be updated to run on ARM platforms
tidu
parents:
40942
diff
changeset
|
650 |
"/usr/lib/arm-linux-gnueabihf/nss/"}); |
15a87b8ccd06
8164322: Test sun/security/pkcs11/PKCS11Test.java shall be updated to run on ARM platforms
tidu
parents:
40942
diff
changeset
|
651 |
osMap.put("Linux-aarch64-64", new String[]{ |
15a87b8ccd06
8164322: Test sun/security/pkcs11/PKCS11Test.java shall be updated to run on ARM platforms
tidu
parents:
40942
diff
changeset
|
652 |
"/usr/lib/aarch64-linux-gnu/nss/"}); |
2 | 653 |
} |
654 |
||
655 |
private final static char[] hexDigits = "0123456789abcdef".toCharArray(); |
|
656 |
||
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
657 |
static final boolean badNSSVersion = |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
658 |
getNSSVersion() >= 3.11 && getNSSVersion() < 3.12; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
659 |
|
42366
b1483ec50db1
8170523: Some PKCS11 test cases are ignored with security manager
mli
parents:
41556
diff
changeset
|
660 |
private static final String distro = distro(); |
b1483ec50db1
8170523: Some PKCS11 test cases are ignored with security manager
mli
parents:
41556
diff
changeset
|
661 |
|
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
662 |
static final boolean badSolarisSparc = |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
663 |
System.getProperty("os.name").equals("SunOS") && |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
664 |
System.getProperty("os.arch").equals("sparcv9") && |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
665 |
System.getProperty("os.version").compareTo("5.11") <= 0 && |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
666 |
getDistro().compareTo("11.2") < 0; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
667 |
|
2 | 668 |
public static String toString(byte[] b) { |
669 |
if (b == null) { |
|
670 |
return "(null)"; |
|
671 |
} |
|
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
672 |
StringBuilder sb = new StringBuilder(b.length * 3); |
2 | 673 |
for (int i = 0; i < b.length; i++) { |
674 |
int k = b[i] & 0xff; |
|
675 |
if (i != 0) { |
|
676 |
sb.append(':'); |
|
677 |
} |
|
678 |
sb.append(hexDigits[k >>> 4]); |
|
679 |
sb.append(hexDigits[k & 0xf]); |
|
680 |
} |
|
681 |
return sb.toString(); |
|
682 |
} |
|
683 |
||
684 |
public static byte[] parse(String s) { |
|
685 |
if (s.equals("(null)")) { |
|
686 |
return null; |
|
687 |
} |
|
688 |
try { |
|
689 |
int n = s.length(); |
|
690 |
ByteArrayOutputStream out = new ByteArrayOutputStream(n / 3); |
|
691 |
StringReader r = new StringReader(s); |
|
692 |
while (true) { |
|
693 |
int b1 = nextNibble(r); |
|
694 |
if (b1 < 0) { |
|
695 |
break; |
|
696 |
} |
|
697 |
int b2 = nextNibble(r); |
|
698 |
if (b2 < 0) { |
|
699 |
throw new RuntimeException("Invalid string " + s); |
|
700 |
} |
|
701 |
int b = (b1 << 4) | b2; |
|
702 |
out.write(b); |
|
703 |
} |
|
704 |
return out.toByteArray(); |
|
705 |
} catch (IOException e) { |
|
706 |
throw new RuntimeException(e); |
|
707 |
} |
|
708 |
} |
|
709 |
||
710 |
private static int nextNibble(StringReader r) throws IOException { |
|
711 |
while (true) { |
|
712 |
int ch = r.read(); |
|
713 |
if (ch == -1) { |
|
714 |
return -1; |
|
715 |
} else if ((ch >= '0') && (ch <= '9')) { |
|
716 |
return ch - '0'; |
|
717 |
} else if ((ch >= 'a') && (ch <= 'f')) { |
|
718 |
return ch - 'a' + 10; |
|
719 |
} else if ((ch >= 'A') && (ch <= 'F')) { |
|
720 |
return ch - 'A' + 10; |
|
721 |
} |
|
722 |
} |
|
723 |
} |
|
724 |
||
725 |
<T> T[] concat(T[] a, T[] b) { |
|
726 |
if ((b == null) || (b.length == 0)) { |
|
727 |
return a; |
|
728 |
} |
|
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
28403
diff
changeset
|
729 |
T[] r = Arrays.copyOf(a, a.length + b.length); |
2 | 730 |
System.arraycopy(b, 0, r, a.length, b.length); |
731 |
return r; |
|
732 |
} |
|
733 |
||
28403 | 734 |
/** |
735 |
* Returns supported algorithms of specified type. |
|
736 |
*/ |
|
737 |
static List<String> getSupportedAlgorithms(String type, String alg, |
|
738 |
Provider p) { |
|
739 |
// prepare a list of supported algorithms |
|
740 |
List<String> algorithms = new ArrayList<>(); |
|
741 |
Set<Provider.Service> services = p.getServices(); |
|
742 |
for (Provider.Service service : services) { |
|
743 |
if (service.getType().equals(type) |
|
744 |
&& service.getAlgorithm().startsWith(alg)) { |
|
745 |
algorithms.add(service.getAlgorithm()); |
|
746 |
} |
|
747 |
} |
|
748 |
return algorithms; |
|
749 |
} |
|
750 |
||
32138
23830562d3d1
8133318: Exclude intermittent failing PKCS11 tests on Solaris SPARC 11.1 and earlier
vinnie
parents:
31270
diff
changeset
|
751 |
/** |
23830562d3d1
8133318: Exclude intermittent failing PKCS11 tests on Solaris SPARC 11.1 and earlier
vinnie
parents:
31270
diff
changeset
|
752 |
* 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
|
753 |
*/ |
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
35248
diff
changeset
|
754 |
static String getDistro() { |
42366
b1483ec50db1
8170523: Some PKCS11 test cases are ignored with security manager
mli
parents:
41556
diff
changeset
|
755 |
return distro; |
b1483ec50db1
8170523: Some PKCS11 test cases are ignored with security manager
mli
parents:
41556
diff
changeset
|
756 |
} |
b1483ec50db1
8170523: Some PKCS11 test cases are ignored with security manager
mli
parents:
41556
diff
changeset
|
757 |
|
b1483ec50db1
8170523: Some PKCS11 test cases are ignored with security manager
mli
parents:
41556
diff
changeset
|
758 |
private static String distro() { |
48248
55b9b1e184c6
8165996: PKCS11 using NSS throws an error regarding secmod.db when NSS uses sqlite
weijun
parents:
47216
diff
changeset
|
759 |
if (props.getProperty("os.name").equals("SunOS")) { |
55b9b1e184c6
8165996: PKCS11 using NSS throws an error regarding secmod.db when NSS uses sqlite
weijun
parents:
47216
diff
changeset
|
760 |
try (BufferedReader in = |
55b9b1e184c6
8165996: PKCS11 using NSS throws an error regarding secmod.db when NSS uses sqlite
weijun
parents:
47216
diff
changeset
|
761 |
new BufferedReader(new InputStreamReader( |
55b9b1e184c6
8165996: PKCS11 using NSS throws an error regarding secmod.db when NSS uses sqlite
weijun
parents:
47216
diff
changeset
|
762 |
Runtime.getRuntime().exec("uname -v").getInputStream()))) { |
32138
23830562d3d1
8133318: Exclude intermittent failing PKCS11 tests on Solaris SPARC 11.1 and earlier
vinnie
parents:
31270
diff
changeset
|
763 |
|
48248
55b9b1e184c6
8165996: PKCS11 using NSS throws an error regarding secmod.db when NSS uses sqlite
weijun
parents:
47216
diff
changeset
|
764 |
return in.readLine(); |
55b9b1e184c6
8165996: PKCS11 using NSS throws an error regarding secmod.db when NSS uses sqlite
weijun
parents:
47216
diff
changeset
|
765 |
} catch (Exception e) { |
55b9b1e184c6
8165996: PKCS11 using NSS throws an error regarding secmod.db when NSS uses sqlite
weijun
parents:
47216
diff
changeset
|
766 |
throw new RuntimeException("Failed to determine distro.", e); |
55b9b1e184c6
8165996: PKCS11 using NSS throws an error regarding secmod.db when NSS uses sqlite
weijun
parents:
47216
diff
changeset
|
767 |
} |
55b9b1e184c6
8165996: PKCS11 using NSS throws an error regarding secmod.db when NSS uses sqlite
weijun
parents:
47216
diff
changeset
|
768 |
} else { |
55b9b1e184c6
8165996: PKCS11 using NSS throws an error regarding secmod.db when NSS uses sqlite
weijun
parents:
47216
diff
changeset
|
769 |
// Not used outside Solaris |
55b9b1e184c6
8165996: PKCS11 using NSS throws an error regarding secmod.db when NSS uses sqlite
weijun
parents:
47216
diff
changeset
|
770 |
return null; |
32138
23830562d3d1
8133318: Exclude intermittent failing PKCS11 tests on Solaris SPARC 11.1 and earlier
vinnie
parents:
31270
diff
changeset
|
771 |
} |
23830562d3d1
8133318: Exclude intermittent failing PKCS11 tests on Solaris SPARC 11.1 and earlier
vinnie
parents:
31270
diff
changeset
|
772 |
} |
32635
d7e4ba3c2e0d
8048622: Enhance tests for PKCS11 keystores with NSS
asmotrak
parents:
32138
diff
changeset
|
773 |
|
d7e4ba3c2e0d
8048622: Enhance tests for PKCS11 keystores with NSS
asmotrak
parents:
32138
diff
changeset
|
774 |
static byte[] generateData(int length) { |
d7e4ba3c2e0d
8048622: Enhance tests for PKCS11 keystores with NSS
asmotrak
parents:
32138
diff
changeset
|
775 |
byte data[] = new byte[length]; |
d7e4ba3c2e0d
8048622: Enhance tests for PKCS11 keystores with NSS
asmotrak
parents:
32138
diff
changeset
|
776 |
for (int i=0; i<data.length; i++) { |
d7e4ba3c2e0d
8048622: Enhance tests for PKCS11 keystores with NSS
asmotrak
parents:
32138
diff
changeset
|
777 |
data[i] = (byte) (i % 256); |
d7e4ba3c2e0d
8048622: Enhance tests for PKCS11 keystores with NSS
asmotrak
parents:
32138
diff
changeset
|
778 |
} |
d7e4ba3c2e0d
8048622: Enhance tests for PKCS11 keystores with NSS
asmotrak
parents:
32138
diff
changeset
|
779 |
return data; |
d7e4ba3c2e0d
8048622: Enhance tests for PKCS11 keystores with NSS
asmotrak
parents:
32138
diff
changeset
|
780 |
} |
2 | 781 |
} |