author | mchung |
Wed, 14 Dec 2016 10:51:13 -0800 | |
changeset 42693 | 6645de32a866 |
parent 40975 | 680639c9b307 |
child 43248 | 5e15de85a1a0 |
permissions | -rw-r--r-- |
12201
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
1 |
/* |
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
12201
diff
changeset
|
2 |
* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved. |
12201
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
4 |
* |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
8 |
* |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
13 |
* accompanied this code). |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
14 |
* |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
18 |
* |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
21 |
* questions. |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
22 |
*/ |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
23 |
|
40975
680639c9b307
8165689: Fix module dependencies for sun/security/pkcs11/* tests
skovalev
parents:
35379
diff
changeset
|
24 |
/* |
12201
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
25 |
* @test |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
26 |
* @bug 7146728 |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
27 |
* @summary Interop test for DH with secret that has a leading 0x00 byte |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
28 |
* @library .. |
42693 | 29 |
* @modules jdk.crypto.token |
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
12201
diff
changeset
|
30 |
* @run main/othervm TestInterop |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
12201
diff
changeset
|
31 |
* @run main/othervm TestInterop sm |
12201
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
32 |
*/ |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
33 |
import java.math.BigInteger; |
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
12201
diff
changeset
|
34 |
import java.security.KeyFactory; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
12201
diff
changeset
|
35 |
import java.security.PrivateKey; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
12201
diff
changeset
|
36 |
import java.security.Provider; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
12201
diff
changeset
|
37 |
import java.security.PublicKey; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
12201
diff
changeset
|
38 |
import java.util.Arrays; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
12201
diff
changeset
|
39 |
import javax.crypto.KeyAgreement; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
12201
diff
changeset
|
40 |
import javax.crypto.spec.DHPrivateKeySpec; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
12201
diff
changeset
|
41 |
import javax.crypto.spec.DHPublicKeySpec; |
12201
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
42 |
|
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
43 |
public class TestInterop extends PKCS11Test { |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
44 |
|
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
45 |
private final static BigInteger p = new BigInteger |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
46 |
("171718397966129586011229151993178480901904202533705695869569760169920539" |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
47 |
+ "80807543778874708672297590042574075430109846864794139516459381007417046" |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
48 |
+ "27996080624930219892858374168155487210358743785481212360509485282294161" |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
49 |
+ "39585571568998066586304075565145536350296006867635076744949977849997684" |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
50 |
+ "222020336013226588207303"); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
51 |
|
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
52 |
private final static BigInteger g = new BigInteger("2"); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
53 |
|
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
54 |
private final static BigInteger ya = new BigInteger |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
55 |
("687709211571508809414670982463565909269384277848448625781941269577397703" |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
56 |
+ "73675199968849153119146758339814638228795348558483510369322822476757204" |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
57 |
+ "22158455966026517829008713407587339322132253724742557954802911059639161" |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
58 |
+ "24827916158465757962384625410294483756242900146397201260757102085985457" |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
59 |
+ "09397033481077351036224"); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
60 |
|
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
61 |
private final static BigInteger xa = new BigInteger |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
62 |
("104917367119952955556289227181599819745346393858545449202252025137706135" |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
63 |
+ "98100778613457655440586438263591136003106529323555991109623536177695714" |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
64 |
+ "66884181531401472902830508361532232717792847436112280721439936797741371" |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
65 |
+ "245140912614191507"); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
66 |
|
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
67 |
private final static BigInteger yb = new BigInteger |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
68 |
("163887874871842952463100699681506173424091615364591742415764095471629919" |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
69 |
+ "08421025296419917755446931473037086355546823601999684501737493240373415" |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
70 |
+ "65608293667837249198973539289354492348897732633852665609611113031379864" |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
71 |
+ "58514616034107537409230452318065341748503347627733368519091332060477528" |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
72 |
+ "173423377887175351037810"); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
73 |
|
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
74 |
private final static BigInteger xb = new BigInteger |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
75 |
("127757517533485947079959908591028646859165238853082197617179368337276371" |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
76 |
+ "51601819447716934542027725311863797141734616730248519214531856941516613" |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
77 |
+ "30313414180008978013330410484011186019824874948204261839391153650949864" |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
78 |
+ "429505597086564709"); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
79 |
|
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
12201
diff
changeset
|
80 |
@Override |
12201
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
81 |
public void main(Provider prov) throws Exception { |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
82 |
if (prov.getService("KeyAgreement", "DH") == null) { |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
83 |
System.out.println("DH not supported, skipping"); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
84 |
return; |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
85 |
} |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
86 |
try { |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
87 |
System.out.println("testing generateSecret()"); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
88 |
|
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
89 |
DHPublicKeySpec publicSpec; |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
90 |
DHPrivateKeySpec privateSpec; |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
91 |
KeyFactory kf = KeyFactory.getInstance("DH"); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
92 |
KeyAgreement ka = KeyAgreement.getInstance("DH", prov); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
93 |
KeyAgreement kbSunJCE = KeyAgreement.getInstance("DH", "SunJCE"); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
94 |
DHPrivateKeySpec privSpecA = new DHPrivateKeySpec(xa, p, g); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
95 |
DHPublicKeySpec pubSpecA = new DHPublicKeySpec(ya, p, g); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
96 |
PrivateKey privA = kf.generatePrivate(privSpecA); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
97 |
PublicKey pubA = kf.generatePublic(pubSpecA); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
98 |
|
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
99 |
DHPrivateKeySpec privSpecB = new DHPrivateKeySpec(xb, p, g); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
100 |
DHPublicKeySpec pubSpecB = new DHPublicKeySpec(yb, p, g); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
101 |
PrivateKey privB = kf.generatePrivate(privSpecB); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
102 |
PublicKey pubB = kf.generatePublic(pubSpecB); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
103 |
|
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
104 |
ka.init(privA); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
105 |
ka.doPhase(pubB, true); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
106 |
byte[] n1 = ka.generateSecret(); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
107 |
|
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
108 |
kbSunJCE.init(privB); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
109 |
kbSunJCE.doPhase(pubA, true); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
110 |
byte[] n2 = kbSunJCE.generateSecret(); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
111 |
|
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
112 |
if (Arrays.equals(n1, n2) == false) { |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
113 |
throw new Exception("values mismatch!"); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
114 |
} else { |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
115 |
System.out.println("values: same"); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
116 |
} |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
117 |
|
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
118 |
System.out.println("testing generateSecret(byte[], int)"); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
119 |
byte[] n3 = new byte[n1.length]; |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
120 |
ka.init(privB); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
121 |
ka.doPhase(pubA, true); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
122 |
int n3Len = ka.generateSecret(n3, 0); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
123 |
if (n3Len != n3.length) { |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
124 |
throw new Exception("PKCS11 Length mismatch!"); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
125 |
} else System.out.println("PKCS11 Length: ok"); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
126 |
byte[] n4 = new byte[n2.length]; |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
127 |
kbSunJCE.init(privA); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
128 |
kbSunJCE.doPhase(pubB, true); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
129 |
int n4Len = kbSunJCE.generateSecret(n4, 0); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
130 |
if (n4Len != n4.length) { |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
131 |
throw new Exception("SunJCE Length mismatch!"); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
132 |
} else System.out.println("SunJCE Length: ok"); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
133 |
|
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
134 |
if (Arrays.equals(n3, n4) == false) { |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
135 |
throw new Exception("values mismatch! "); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
136 |
} else { |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
137 |
System.out.println("values: same"); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
138 |
} |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
139 |
} catch (Exception ex) { |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
140 |
System.out.println("Unexpected ex: " + ex); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
141 |
ex.printStackTrace(); |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
142 |
throw ex; |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
143 |
} |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
144 |
} |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
145 |
|
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
146 |
public static void main(String[] args) throws Exception { |
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
12201
diff
changeset
|
147 |
main(new TestInterop(), args); |
12201
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
148 |
} |
d77ed23f4992
7146728: Inconsistent length for the generated secret using DH key agreement impl from SunJCE and PKCS11
valeriep
parents:
diff
changeset
|
149 |
} |