author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 55530 | 6aa047de311b |
permissions | -rw-r--r-- |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
1 |
/* |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
4 |
* |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
8 |
* |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
13 |
* accompanied this code). |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
14 |
* |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
18 |
* |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
21 |
* questions. |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
22 |
*/ |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
23 |
import java.security.*; |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
24 |
import java.security.interfaces.*; |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
25 |
import java.security.spec.*; |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
26 |
import java.util.stream.IntStream; |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
27 |
|
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
28 |
/** |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
29 |
* @test |
55530
6aa047de311b
8226651: Setting the mgfHash in CK_RSA_PKCS_PSS_PARAMS has no effect
valeriep
parents:
55332
diff
changeset
|
30 |
* @bug 8080462 8226651 |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
31 |
* @summary Generate a RSASSA-PSS signature and verify it using PKCS11 provider |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
32 |
* @library /test/lib .. |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
33 |
* @modules jdk.crypto.cryptoki |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
34 |
* @run main SignatureTestPSS |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
35 |
*/ |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
36 |
public class SignatureTestPSS extends PKCS11Test { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
37 |
|
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
38 |
// PKCS11 does not support RSASSA-PSS keys yet |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
39 |
private static final String KEYALG = "RSA"; |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
40 |
private static final String SIGALG = "RSASSA-PSS"; |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
41 |
|
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
42 |
private static final int[] KEYSIZES = { 2048, 3072 }; |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
43 |
private static final String[] DIGESTS = { "SHA-224", "SHA-256", |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
44 |
"SHA-384" , "SHA-512" }; |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
45 |
private Provider prov; |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
46 |
|
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
47 |
/** |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
48 |
* How much times signature updated. |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
49 |
*/ |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
50 |
private static final int UPDATE_TIMES_FIFTY = 50; |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
51 |
|
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
52 |
/** |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
53 |
* How much times signature initial updated. |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
54 |
*/ |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
55 |
private static final int UPDATE_TIMES_HUNDRED = 100; |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
56 |
|
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
57 |
public static void main(String[] args) throws Exception { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
58 |
main(new SignatureTestPSS(), args); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
59 |
} |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
60 |
|
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
61 |
@Override |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
62 |
public void main(Provider p) throws Exception { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
63 |
Signature sig; |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
64 |
try { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
65 |
sig = Signature.getInstance(SIGALG, p); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
66 |
} catch (NoSuchAlgorithmException e) { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
67 |
System.out.println("Skip testing RSASSA-PSS" + |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
68 |
" due to no support"); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
69 |
return; |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
70 |
} |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
71 |
this.prov = p; |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
72 |
for (int i : KEYSIZES) { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
73 |
runTest(i); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
74 |
} |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
75 |
} |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
76 |
|
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
77 |
private void runTest(int keySize) throws Exception { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
78 |
byte[] data = new byte[100]; |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
79 |
IntStream.range(0, data.length).forEach(j -> { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
80 |
data[j] = (byte) j; |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
81 |
}); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
82 |
System.out.println("[KEYSIZE = " + keySize + "]"); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
83 |
|
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
84 |
// create a key pair |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
85 |
KeyPair kpair = generateKeys(KEYALG, keySize); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
86 |
test(DIGESTS, kpair.getPrivate(), kpair.getPublic(), data); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
87 |
} |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
88 |
|
55530
6aa047de311b
8226651: Setting the mgfHash in CK_RSA_PKCS_PSS_PARAMS has no effect
valeriep
parents:
55332
diff
changeset
|
89 |
private void test(String[] digestAlgs, PrivateKey privKey, |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
90 |
PublicKey pubKey, byte[] data) throws RuntimeException { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
91 |
// For signature algorithm, create and verify a signature |
55530
6aa047de311b
8226651: Setting the mgfHash in CK_RSA_PKCS_PSS_PARAMS has no effect
valeriep
parents:
55332
diff
changeset
|
92 |
for (String hash : digestAlgs) { |
6aa047de311b
8226651: Setting the mgfHash in CK_RSA_PKCS_PSS_PARAMS has no effect
valeriep
parents:
55332
diff
changeset
|
93 |
for (String mgfHash : digestAlgs) { |
6aa047de311b
8226651: Setting the mgfHash in CK_RSA_PKCS_PSS_PARAMS has no effect
valeriep
parents:
55332
diff
changeset
|
94 |
try { |
6aa047de311b
8226651: Setting the mgfHash in CK_RSA_PKCS_PSS_PARAMS has no effect
valeriep
parents:
55332
diff
changeset
|
95 |
checkSignature(data, pubKey, privKey, hash, mgfHash); |
6aa047de311b
8226651: Setting the mgfHash in CK_RSA_PKCS_PSS_PARAMS has no effect
valeriep
parents:
55332
diff
changeset
|
96 |
} catch (NoSuchAlgorithmException | InvalidKeyException | |
6aa047de311b
8226651: Setting the mgfHash in CK_RSA_PKCS_PSS_PARAMS has no effect
valeriep
parents:
55332
diff
changeset
|
97 |
SignatureException | NoSuchProviderException ex) { |
6aa047de311b
8226651: Setting the mgfHash in CK_RSA_PKCS_PSS_PARAMS has no effect
valeriep
parents:
55332
diff
changeset
|
98 |
throw new RuntimeException(ex); |
6aa047de311b
8226651: Setting the mgfHash in CK_RSA_PKCS_PSS_PARAMS has no effect
valeriep
parents:
55332
diff
changeset
|
99 |
} catch (InvalidAlgorithmParameterException ex2) { |
6aa047de311b
8226651: Setting the mgfHash in CK_RSA_PKCS_PSS_PARAMS has no effect
valeriep
parents:
55332
diff
changeset
|
100 |
System.out.println("Skip test due to " + ex2); |
6aa047de311b
8226651: Setting the mgfHash in CK_RSA_PKCS_PSS_PARAMS has no effect
valeriep
parents:
55332
diff
changeset
|
101 |
} |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
102 |
} |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
103 |
}; |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
104 |
} |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
105 |
|
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
106 |
private KeyPair generateKeys(String keyalg, int size) |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
107 |
throws NoSuchAlgorithmException { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
108 |
KeyPairGenerator kpg = KeyPairGenerator.getInstance(keyalg, prov); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
109 |
kpg.initialize(size); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
110 |
return kpg.generateKeyPair(); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
111 |
} |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
112 |
|
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
113 |
private void checkSignature(byte[] data, PublicKey pub, |
55530
6aa047de311b
8226651: Setting the mgfHash in CK_RSA_PKCS_PSS_PARAMS has no effect
valeriep
parents:
55332
diff
changeset
|
114 |
PrivateKey priv, String hash, String mgfHash) |
6aa047de311b
8226651: Setting the mgfHash in CK_RSA_PKCS_PSS_PARAMS has no effect
valeriep
parents:
55332
diff
changeset
|
115 |
throws NoSuchAlgorithmException, InvalidKeyException, |
6aa047de311b
8226651: Setting the mgfHash in CK_RSA_PKCS_PSS_PARAMS has no effect
valeriep
parents:
55332
diff
changeset
|
116 |
SignatureException, NoSuchProviderException, |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
117 |
InvalidAlgorithmParameterException { |
55530
6aa047de311b
8226651: Setting the mgfHash in CK_RSA_PKCS_PSS_PARAMS has no effect
valeriep
parents:
55332
diff
changeset
|
118 |
System.out.println("Testing against " + hash + " and MGF1_" + mgfHash); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
119 |
Signature sig = Signature.getInstance(SIGALG, prov); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
120 |
AlgorithmParameterSpec params = new PSSParameterSpec( |
55530
6aa047de311b
8226651: Setting the mgfHash in CK_RSA_PKCS_PSS_PARAMS has no effect
valeriep
parents:
55332
diff
changeset
|
121 |
hash, "MGF1", new MGF1ParameterSpec(mgfHash), 0, 1); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
122 |
sig.setParameter(params); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
123 |
sig.initSign(priv); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
124 |
for (int i = 0; i < UPDATE_TIMES_HUNDRED; i++) { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
125 |
sig.update(data); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
126 |
} |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
127 |
byte[] signedData = sig.sign(); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
128 |
|
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
129 |
// Make sure signature verifies with original data |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
130 |
// do we need to call sig.setParameter(params) again? |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
131 |
sig.initVerify(pub); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
132 |
for (int i = 0; i < UPDATE_TIMES_HUNDRED; i++) { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
133 |
sig.update(data); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
134 |
} |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
135 |
if (!sig.verify(signedData)) { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
136 |
throw new RuntimeException("Failed to verify signature"); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
137 |
} |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
138 |
|
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
139 |
// Make sure signature does NOT verify when the original data |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
140 |
// has changed |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
141 |
sig.initVerify(pub); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
142 |
for (int i = 0; i < UPDATE_TIMES_FIFTY; i++) { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
143 |
sig.update(data); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
144 |
} |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
145 |
|
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
146 |
if (sig.verify(signedData)) { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
147 |
throw new RuntimeException("Failed to detect bad signature"); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
148 |
} |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
149 |
} |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
diff
changeset
|
150 |
} |