author | jjiang |
Wed, 15 Aug 2018 18:41:18 +0800 | |
changeset 51460 | 97e361fe3433 |
parent 47216 | 71c04702a3d5 |
child 58248 | e6231dbaa862 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
51460
97e361fe3433
8164639: Configure PKCS11 tests to use user-supplied NSS libraries
jjiang
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2005, 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 |
||
40975
680639c9b307
8165689: Fix module dependencies for sun/security/pkcs11/* tests
skovalev
parents:
35379
diff
changeset
|
24 |
/* |
2 | 25 |
* @test |
41123
66eaead2a150
8136355: CKM_SSL3_KEY_AND_MAC_DERIVE no longer available by default on Solaris 12
valeriep
parents:
40975
diff
changeset
|
26 |
* @bug 6316539 8136355 |
2 | 27 |
* @summary Known-answer-test for TlsKeyMaterial generator |
28 |
* @author Andreas Sterbenz |
|
51460
97e361fe3433
8164639: Configure PKCS11 tests to use user-supplied NSS libraries
jjiang
parents:
47216
diff
changeset
|
29 |
* @library /test/lib .. |
30820 | 30 |
* @modules java.base/sun.security.internal.spec |
43248
5e15de85a1a0
8172527: Rename jdk.crypto.token to jdk.crypto.cryptoki
ascarpino
parents:
42693
diff
changeset
|
31 |
* jdk.crypto.cryptoki |
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
32 |
* @run main/othervm TestKeyMaterial |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
33 |
* @run main/othervm TestKeyMaterial sm policy |
2 | 34 |
*/ |
35 |
||
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
36 |
import java.io.BufferedReader; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
37 |
import java.nio.file.Files; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
38 |
import java.nio.file.Paths; |
2 | 39 |
import java.security.Provider; |
41123
66eaead2a150
8136355: CKM_SSL3_KEY_AND_MAC_DERIVE no longer available by default on Solaris 12
valeriep
parents:
40975
diff
changeset
|
40 |
import java.security.InvalidAlgorithmParameterException; |
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
41 |
import java.util.Arrays; |
2 | 42 |
import javax.crypto.KeyGenerator; |
43 |
import javax.crypto.SecretKey; |
|
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
44 |
import javax.crypto.spec.IvParameterSpec; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
45 |
import javax.crypto.spec.SecretKeySpec; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
46 |
import sun.security.internal.spec.TlsKeyMaterialParameterSpec; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
47 |
import sun.security.internal.spec.TlsKeyMaterialSpec; |
2 | 48 |
|
49 |
public class TestKeyMaterial extends PKCS11Test { |
|
50 |
||
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
51 |
private static final int PREFIX_LENGTH = "km-master: ".length(); |
2 | 52 |
|
53 |
public static void main(String[] args) throws Exception { |
|
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
54 |
main(new TestKeyMaterial(), args); |
2 | 55 |
} |
56 |
||
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
57 |
@Override |
2 | 58 |
public void main(Provider provider) throws Exception { |
59 |
if (provider.getService("KeyGenerator", "SunTlsKeyMaterial") == null) { |
|
60 |
System.out.println("Provider does not support algorithm, skipping"); |
|
61 |
return; |
|
62 |
} |
|
63 |
||
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
64 |
try (BufferedReader reader = Files.newBufferedReader( |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
65 |
Paths.get(BASE, "keymatdata.txt"))) { |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
66 |
|
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
67 |
int n = 0; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
68 |
int lineNumber = 0; |
2 | 69 |
|
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
70 |
byte[] master = null; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
71 |
int major = 0; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
72 |
int minor = 0; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
73 |
byte[] clientRandom = null; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
74 |
byte[] serverRandom = null; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
75 |
String cipherAlgorithm = null; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
76 |
int keyLength = 0; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
77 |
int expandedKeyLength = 0; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
78 |
int ivLength = 0; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
79 |
int macLength = 0; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
80 |
byte[] clientCipherBytes = null; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
81 |
byte[] serverCipherBytes = null; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
82 |
byte[] clientIv = null; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
83 |
byte[] serverIv = null; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
84 |
byte[] clientMacBytes = null; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
85 |
byte[] serverMacBytes = null; |
2 | 86 |
|
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
87 |
while (true) { |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
88 |
String line = reader.readLine(); |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
89 |
lineNumber++; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
90 |
if (line == null) { |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
91 |
break; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
92 |
} |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
93 |
if (line.startsWith("km-") == false) { |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
94 |
continue; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
95 |
} |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
96 |
String data = line.substring(PREFIX_LENGTH); |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
97 |
if (line.startsWith("km-master:")) { |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
98 |
master = parse(data); |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
99 |
} else if (line.startsWith("km-major:")) { |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
100 |
major = Integer.parseInt(data); |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
101 |
} else if (line.startsWith("km-minor:")) { |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
102 |
minor = Integer.parseInt(data); |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
103 |
} else if (line.startsWith("km-crandom:")) { |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
104 |
clientRandom = parse(data); |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
105 |
} else if (line.startsWith("km-srandom:")) { |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
106 |
serverRandom = parse(data); |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
107 |
} else if (line.startsWith("km-cipalg:")) { |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
108 |
cipherAlgorithm = data; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
109 |
} else if (line.startsWith("km-keylen:")) { |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
110 |
keyLength = Integer.parseInt(data); |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
111 |
} else if (line.startsWith("km-explen:")) { |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
112 |
expandedKeyLength = Integer.parseInt(data); |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
113 |
} else if (line.startsWith("km-ivlen:")) { |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
114 |
ivLength = Integer.parseInt(data); |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
115 |
} else if (line.startsWith("km-maclen:")) { |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
116 |
macLength = Integer.parseInt(data); |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
117 |
} else if (line.startsWith("km-ccipkey:")) { |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
118 |
clientCipherBytes = parse(data); |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
119 |
} else if (line.startsWith("km-scipkey:")) { |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
120 |
serverCipherBytes = parse(data); |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
121 |
} else if (line.startsWith("km-civ:")) { |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
122 |
clientIv = parse(data); |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
123 |
} else if (line.startsWith("km-siv:")) { |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
124 |
serverIv = parse(data); |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
125 |
} else if (line.startsWith("km-cmackey:")) { |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
126 |
clientMacBytes = parse(data); |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
127 |
} else if (line.startsWith("km-smackey:")) { |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
128 |
serverMacBytes = parse(data); |
2 | 129 |
|
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
130 |
System.out.print("."); |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
131 |
n++; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
132 |
|
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
133 |
KeyGenerator kg = |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
134 |
KeyGenerator.getInstance("SunTlsKeyMaterial", provider); |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
135 |
SecretKey masterKey = |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
136 |
new SecretKeySpec(master, "TlsMasterSecret"); |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
137 |
TlsKeyMaterialParameterSpec spec = |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
138 |
new TlsKeyMaterialParameterSpec(masterKey, major, minor, |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
139 |
clientRandom, serverRandom, cipherAlgorithm, |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
140 |
keyLength, expandedKeyLength, ivLength, macLength, |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
141 |
null, -1, -1); |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
142 |
|
41123
66eaead2a150
8136355: CKM_SSL3_KEY_AND_MAC_DERIVE no longer available by default on Solaris 12
valeriep
parents:
40975
diff
changeset
|
143 |
try { |
66eaead2a150
8136355: CKM_SSL3_KEY_AND_MAC_DERIVE no longer available by default on Solaris 12
valeriep
parents:
40975
diff
changeset
|
144 |
kg.init(spec); |
66eaead2a150
8136355: CKM_SSL3_KEY_AND_MAC_DERIVE no longer available by default on Solaris 12
valeriep
parents:
40975
diff
changeset
|
145 |
TlsKeyMaterialSpec result = |
66eaead2a150
8136355: CKM_SSL3_KEY_AND_MAC_DERIVE no longer available by default on Solaris 12
valeriep
parents:
40975
diff
changeset
|
146 |
(TlsKeyMaterialSpec)kg.generateKey(); |
66eaead2a150
8136355: CKM_SSL3_KEY_AND_MAC_DERIVE no longer available by default on Solaris 12
valeriep
parents:
40975
diff
changeset
|
147 |
match(lineNumber, clientCipherBytes, |
66eaead2a150
8136355: CKM_SSL3_KEY_AND_MAC_DERIVE no longer available by default on Solaris 12
valeriep
parents:
40975
diff
changeset
|
148 |
result.getClientCipherKey(), cipherAlgorithm); |
66eaead2a150
8136355: CKM_SSL3_KEY_AND_MAC_DERIVE no longer available by default on Solaris 12
valeriep
parents:
40975
diff
changeset
|
149 |
match(lineNumber, serverCipherBytes, |
66eaead2a150
8136355: CKM_SSL3_KEY_AND_MAC_DERIVE no longer available by default on Solaris 12
valeriep
parents:
40975
diff
changeset
|
150 |
result.getServerCipherKey(), cipherAlgorithm); |
66eaead2a150
8136355: CKM_SSL3_KEY_AND_MAC_DERIVE no longer available by default on Solaris 12
valeriep
parents:
40975
diff
changeset
|
151 |
match(lineNumber, clientIv, result.getClientIv(), ""); |
66eaead2a150
8136355: CKM_SSL3_KEY_AND_MAC_DERIVE no longer available by default on Solaris 12
valeriep
parents:
40975
diff
changeset
|
152 |
match(lineNumber, serverIv, result.getServerIv(), ""); |
66eaead2a150
8136355: CKM_SSL3_KEY_AND_MAC_DERIVE no longer available by default on Solaris 12
valeriep
parents:
40975
diff
changeset
|
153 |
match(lineNumber, clientMacBytes, result.getClientMacKey(), ""); |
66eaead2a150
8136355: CKM_SSL3_KEY_AND_MAC_DERIVE no longer available by default on Solaris 12
valeriep
parents:
40975
diff
changeset
|
154 |
match(lineNumber, serverMacBytes, result.getServerMacKey(), ""); |
66eaead2a150
8136355: CKM_SSL3_KEY_AND_MAC_DERIVE no longer available by default on Solaris 12
valeriep
parents:
40975
diff
changeset
|
155 |
} catch (InvalidAlgorithmParameterException iape) { |
66eaead2a150
8136355: CKM_SSL3_KEY_AND_MAC_DERIVE no longer available by default on Solaris 12
valeriep
parents:
40975
diff
changeset
|
156 |
// SSLv3 support is removed in S12 |
66eaead2a150
8136355: CKM_SSL3_KEY_AND_MAC_DERIVE no longer available by default on Solaris 12
valeriep
parents:
40975
diff
changeset
|
157 |
if (major == 3 && minor == 0) { |
66eaead2a150
8136355: CKM_SSL3_KEY_AND_MAC_DERIVE no longer available by default on Solaris 12
valeriep
parents:
40975
diff
changeset
|
158 |
System.out.println("Skip testing SSLv3"); |
66eaead2a150
8136355: CKM_SSL3_KEY_AND_MAC_DERIVE no longer available by default on Solaris 12
valeriep
parents:
40975
diff
changeset
|
159 |
continue; |
66eaead2a150
8136355: CKM_SSL3_KEY_AND_MAC_DERIVE no longer available by default on Solaris 12
valeriep
parents:
40975
diff
changeset
|
160 |
} |
66eaead2a150
8136355: CKM_SSL3_KEY_AND_MAC_DERIVE no longer available by default on Solaris 12
valeriep
parents:
40975
diff
changeset
|
161 |
} |
66eaead2a150
8136355: CKM_SSL3_KEY_AND_MAC_DERIVE no longer available by default on Solaris 12
valeriep
parents:
40975
diff
changeset
|
162 |
} else { |
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
163 |
throw new Exception("Unknown line: " + line); |
41123
66eaead2a150
8136355: CKM_SSL3_KEY_AND_MAC_DERIVE no longer available by default on Solaris 12
valeriep
parents:
40975
diff
changeset
|
164 |
} |
2 | 165 |
} |
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
166 |
if (n == 0) { |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
167 |
throw new Exception("no tests"); |
2 | 168 |
} |
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
169 |
System.out.println(); |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
30820
diff
changeset
|
170 |
System.out.println("OK: " + n + " tests"); |
2 | 171 |
} |
172 |
} |
|
173 |
||
174 |
private static void stripParity(byte[] b) { |
|
175 |
for (int i = 0; i < b.length; i++) { |
|
176 |
b[i] &= 0xfe; |
|
177 |
} |
|
178 |
} |
|
179 |
||
7043 | 180 |
private static void match(int lineNumber, byte[] out, Object res, |
181 |
String cipherAlgorithm) throws Exception { |
|
2 | 182 |
if ((out == null) || (res == null)) { |
183 |
if (out != res) { |
|
184 |
throw new Exception("null mismatch line " + lineNumber); |
|
185 |
} else { |
|
186 |
return; |
|
187 |
} |
|
188 |
} |
|
189 |
byte[] b; |
|
190 |
if (res instanceof SecretKey) { |
|
191 |
b = ((SecretKey)res).getEncoded(); |
|
7043 | 192 |
if (cipherAlgorithm.equalsIgnoreCase("DES") || |
193 |
cipherAlgorithm.equalsIgnoreCase("DESede")) { |
|
2 | 194 |
// strip DES parity bits before comparision |
195 |
stripParity(out); |
|
196 |
stripParity(b); |
|
197 |
} |
|
198 |
} else if (res instanceof IvParameterSpec) { |
|
199 |
b = ((IvParameterSpec)res).getIV(); |
|
200 |
} else { |
|
201 |
throw new Exception(res.getClass().getName()); |
|
202 |
} |
|
203 |
if (Arrays.equals(out, b) == false) { |
|
204 |
System.out.println(); |
|
205 |
System.out.println("out: " + toString(out)); |
|
206 |
System.out.println("b: " + toString(b)); |
|
207 |
throw new Exception("mismatch line " + lineNumber); |
|
208 |
} |
|
209 |
} |
|
210 |
||
211 |
} |