author | sundar |
Mon, 31 Aug 2015 17:51:02 +0530 | |
changeset 32434 | 769b3d81ae69 |
parent 25859 | 3317bb8137f4 |
child 39142 | bf48a9f13cf2 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
14342
8435a30053c1
7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents:
10798
diff
changeset
|
2 |
* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
*/ |
4 |
||
5 |
/* Copyright (c) 2002 Graz University of Technology. All rights reserved. |
|
6 |
* |
|
7 |
* Redistribution and use in source and binary forms, with or without |
|
8 |
* modification, are permitted provided that the following conditions are met: |
|
9 |
* |
|
10 |
* 1. Redistributions of source code must retain the above copyright notice, |
|
11 |
* this list of conditions and the following disclaimer. |
|
12 |
* |
|
13 |
* 2. Redistributions in binary form must reproduce the above copyright notice, |
|
14 |
* this list of conditions and the following disclaimer in the documentation |
|
15 |
* and/or other materials provided with the distribution. |
|
16 |
* |
|
17 |
* 3. The end-user documentation included with the redistribution, if any, must |
|
18 |
* include the following acknowledgment: |
|
19 |
* |
|
20 |
* "This product includes software developed by IAIK of Graz University of |
|
21 |
* Technology." |
|
22 |
* |
|
23 |
* Alternately, this acknowledgment may appear in the software itself, if |
|
24 |
* and wherever such third-party acknowledgments normally appear. |
|
25 |
* |
|
26 |
* 4. The names "Graz University of Technology" and "IAIK of Graz University of |
|
27 |
* Technology" must not be used to endorse or promote products derived from |
|
28 |
* this software without prior written permission. |
|
29 |
* |
|
30 |
* 5. Products derived from this software may not be called |
|
31 |
* "IAIK PKCS Wrapper", nor may "IAIK" appear in their name, without prior |
|
32 |
* written permission of Graz University of Technology. |
|
33 |
* |
|
34 |
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED |
|
35 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
36 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
37 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LICENSOR BE |
|
38 |
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, |
|
39 |
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
40 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, |
|
41 |
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
|
42 |
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
|
43 |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|
44 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
45 |
* POSSIBILITY OF SUCH DAMAGE. |
|
46 |
*/ |
|
47 |
||
48 |
#include "pkcs11wrapper.h" |
|
49 |
||
50 |
#include <stdio.h> |
|
51 |
#include <stdlib.h> |
|
52 |
#include <string.h> |
|
53 |
#include <assert.h> |
|
54 |
||
55 |
#include "sun_security_pkcs11_wrapper_PKCS11.h" |
|
56 |
||
57 |
#ifdef P11_ENABLE_C_GENERATEKEY |
|
58 |
/* |
|
59 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
60 |
* Method: C_GenerateKey |
|
61 |
* Signature: (JLsun/security/pkcs11/wrapper/CK_MECHANISM;[Lsun/security/pkcs11/wrapper/CK_ATTRIBUTE;)J |
|
62 |
* Parametermapping: *PKCS11* |
|
63 |
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession |
|
64 |
* @param jobject jMechanism CK_MECHANISM_PTR pMechanism |
|
65 |
* @param jobjectArray jTemplate CK_ATTRIBUTE_PTR pTemplate |
|
66 |
* CK_ULONG ulCount |
|
67 |
* @return jlong jKeyHandle CK_OBJECT_HANDLE_PTR phKey |
|
68 |
*/ |
|
69 |
JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1GenerateKey |
|
70 |
(JNIEnv *env, jobject obj, jlong jSessionHandle, jobject jMechanism, jobjectArray jTemplate) |
|
71 |
{ |
|
72 |
CK_SESSION_HANDLE ckSessionHandle; |
|
73 |
CK_MECHANISM ckMechanism; |
|
74 |
CK_ATTRIBUTE_PTR ckpAttributes = NULL_PTR; |
|
75 |
CK_ULONG ckAttributesLength; |
|
3321
fed33393bc52
6823905: crash in sun.security.pkcs11.wrapper.PKCS11.C_Sign during stress-test
valeriep
parents:
2180
diff
changeset
|
76 |
CK_OBJECT_HANDLE ckKeyHandle = 0; |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
77 |
jlong jKeyHandle = 0L; |
2 | 78 |
CK_RV rv; |
79 |
||
80 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
81 |
if (ckpFunctions == NULL) { return 0L; } |
|
82 |
||
83 |
ckSessionHandle = jLongToCKULong(jSessionHandle); |
|
84 |
jMechanismToCKMechanism(env, jMechanism, &ckMechanism); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
85 |
if ((*env)->ExceptionCheck(env)) { return 0L ; } |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
86 |
|
2 | 87 |
jAttributeArrayToCKAttributeArray(env, jTemplate, &ckpAttributes, &ckAttributesLength); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
88 |
if ((*env)->ExceptionCheck(env)) { |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
89 |
if (ckMechanism.pParameter != NULL_PTR) { |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
90 |
free(ckMechanism.pParameter); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
91 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
92 |
return 0L; |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
93 |
} |
2 | 94 |
|
95 |
rv = (*ckpFunctions->C_GenerateKey)(ckSessionHandle, &ckMechanism, ckpAttributes, ckAttributesLength, &ckKeyHandle); |
|
96 |
||
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
97 |
if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
98 |
jKeyHandle = ckULongToJLong(ckKeyHandle); |
2 | 99 |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
100 |
/* cheack, if we must give a initialization vector back to Java */ |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
101 |
switch (ckMechanism.mechanism) { |
2 | 102 |
case CKM_PBE_MD2_DES_CBC: |
103 |
case CKM_PBE_MD5_DES_CBC: |
|
104 |
case CKM_PBE_MD5_CAST_CBC: |
|
105 |
case CKM_PBE_MD5_CAST3_CBC: |
|
106 |
case CKM_PBE_MD5_CAST128_CBC: |
|
107 |
/* case CKM_PBE_MD5_CAST5_CBC: the same as CKM_PBE_MD5_CAST128_CBC */ |
|
108 |
case CKM_PBE_SHA1_CAST128_CBC: |
|
109 |
/* case CKM_PBE_SHA1_CAST5_CBC: the same as CKM_PBE_SHA1_CAST128_CBC */ |
|
110 |
/* we must copy back the initialization vector to the jMechanism object */ |
|
111 |
copyBackPBEInitializationVector(env, &ckMechanism, jMechanism); |
|
112 |
break; |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
113 |
} |
2 | 114 |
} |
115 |
||
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
116 |
if (ckMechanism.pParameter != NULL_PTR) { |
2 | 117 |
free(ckMechanism.pParameter); |
118 |
} |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
119 |
freeCKAttributeArray(ckpAttributes, ckAttributesLength); |
2 | 120 |
|
121 |
return jKeyHandle ; |
|
122 |
} |
|
123 |
#endif |
|
124 |
||
125 |
#ifdef P11_ENABLE_C_GENERATEKEYPAIR |
|
126 |
/* |
|
127 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
128 |
* Method: C_GenerateKeyPair |
|
129 |
* Signature: (JLsun/security/pkcs11/wrapper/CK_MECHANISM;[Lsun/security/pkcs11/wrapper/CK_ATTRIBUTE;[Lsun/security/pkcs11/wrapper/CK_ATTRIBUTE;)[J |
|
130 |
* Parametermapping: *PKCS11* |
|
131 |
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession |
|
132 |
* @param jobject jMechanism CK_MECHANISM_PTR pMechanism |
|
133 |
* @param jobjectArray jPublicKeyTemplate CK_ATTRIBUTE_PTR pPublicKeyTemplate |
|
134 |
* CK_ULONG ulPublicKeyAttributeCount |
|
135 |
* @param jobjectArray jPrivateKeyTemplate CK_ATTRIBUTE_PTR pPrivateKeyTemplate |
|
136 |
* CK_ULONG ulPrivateKeyAttributeCount |
|
137 |
* @return jlongArray jKeyHandles CK_OBJECT_HANDLE_PTR phPublicKey |
|
138 |
* CK_OBJECT_HANDLE_PTR phPublicKey |
|
139 |
*/ |
|
140 |
JNIEXPORT jlongArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1GenerateKeyPair |
|
141 |
(JNIEnv *env, jobject obj, jlong jSessionHandle, jobject jMechanism, |
|
142 |
jobjectArray jPublicKeyTemplate, jobjectArray jPrivateKeyTemplate) |
|
143 |
{ |
|
144 |
CK_SESSION_HANDLE ckSessionHandle; |
|
145 |
CK_MECHANISM ckMechanism; |
|
146 |
CK_ATTRIBUTE_PTR ckpPublicKeyAttributes = NULL_PTR; |
|
147 |
CK_ATTRIBUTE_PTR ckpPrivateKeyAttributes = NULL_PTR; |
|
148 |
CK_ULONG ckPublicKeyAttributesLength; |
|
149 |
CK_ULONG ckPrivateKeyAttributesLength; |
|
150 |
CK_OBJECT_HANDLE_PTR ckpPublicKeyHandle; /* pointer to Public Key */ |
|
151 |
CK_OBJECT_HANDLE_PTR ckpPrivateKeyHandle; /* pointer to Private Key */ |
|
152 |
CK_OBJECT_HANDLE_PTR ckpKeyHandles; /* pointer to array with Public and Private Key */ |
|
3321
fed33393bc52
6823905: crash in sun.security.pkcs11.wrapper.PKCS11.C_Sign during stress-test
valeriep
parents:
2180
diff
changeset
|
153 |
jlongArray jKeyHandles = NULL; |
2 | 154 |
CK_RV rv; |
155 |
||
156 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
157 |
if (ckpFunctions == NULL) { return NULL; } |
|
158 |
||
159 |
ckSessionHandle = jLongToCKULong(jSessionHandle); |
|
160 |
jMechanismToCKMechanism(env, jMechanism, &ckMechanism); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
161 |
if ((*env)->ExceptionCheck(env)) { return NULL; } |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
162 |
|
2 | 163 |
ckpKeyHandles = (CK_OBJECT_HANDLE_PTR) malloc(2 * sizeof(CK_OBJECT_HANDLE)); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
164 |
if (ckpKeyHandles == NULL) { |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
165 |
if (ckMechanism.pParameter != NULL_PTR) { |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
166 |
free(ckMechanism.pParameter); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
167 |
} |
10798
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
168 |
throwOutOfMemoryError(env, 0); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
169 |
return NULL; |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
170 |
} |
2 | 171 |
ckpPublicKeyHandle = ckpKeyHandles; /* first element of array is Public Key */ |
172 |
ckpPrivateKeyHandle = (ckpKeyHandles + 1); /* second element of array is Private Key */ |
|
173 |
||
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
174 |
jAttributeArrayToCKAttributeArray(env, jPublicKeyTemplate, &ckpPublicKeyAttributes, &ckPublicKeyAttributesLength); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
175 |
if ((*env)->ExceptionCheck(env)) { |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
176 |
if (ckMechanism.pParameter != NULL_PTR) { |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
177 |
free(ckMechanism.pParameter); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
178 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
179 |
free(ckpKeyHandles); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
180 |
return NULL; |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
181 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
182 |
|
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
183 |
jAttributeArrayToCKAttributeArray(env, jPrivateKeyTemplate, &ckpPrivateKeyAttributes, &ckPrivateKeyAttributesLength); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
184 |
if ((*env)->ExceptionCheck(env)) { |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
185 |
if (ckMechanism.pParameter != NULL_PTR) { |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
186 |
free(ckMechanism.pParameter); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
187 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
188 |
free(ckpKeyHandles); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
189 |
freeCKAttributeArray(ckpPublicKeyAttributes, ckPublicKeyAttributesLength); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
190 |
return NULL; |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
191 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
192 |
|
2 | 193 |
rv = (*ckpFunctions->C_GenerateKeyPair)(ckSessionHandle, &ckMechanism, |
194 |
ckpPublicKeyAttributes, ckPublicKeyAttributesLength, |
|
195 |
ckpPrivateKeyAttributes, ckPrivateKeyAttributesLength, |
|
196 |
ckpPublicKeyHandle, ckpPrivateKeyHandle); |
|
197 |
||
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
198 |
if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
199 |
jKeyHandles = ckULongArrayToJLongArray(env, ckpKeyHandles, 2); |
2 | 200 |
} |
201 |
||
202 |
if(ckMechanism.pParameter != NULL_PTR) { |
|
203 |
free(ckMechanism.pParameter); |
|
204 |
} |
|
205 |
free(ckpKeyHandles); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
206 |
freeCKAttributeArray(ckpPublicKeyAttributes, ckPublicKeyAttributesLength); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
207 |
freeCKAttributeArray(ckpPrivateKeyAttributes, ckPrivateKeyAttributesLength); |
2 | 208 |
|
209 |
return jKeyHandles ; |
|
210 |
} |
|
211 |
#endif |
|
212 |
||
213 |
#ifdef P11_ENABLE_C_WRAPKEY |
|
214 |
/* |
|
215 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
216 |
* Method: C_WrapKey |
|
217 |
* Signature: (JLsun/security/pkcs11/wrapper/CK_MECHANISM;JJ)[B |
|
218 |
* Parametermapping: *PKCS11* |
|
219 |
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession |
|
220 |
* @param jobject jMechanism CK_MECHANISM_PTR pMechanism |
|
221 |
* @param jlong jWrappingKeyHandle CK_OBJECT_HANDLE hWrappingKey |
|
222 |
* @param jlong jKeyHandle CK_OBJECT_HANDLE hKey |
|
223 |
* @return jbyteArray jWrappedKey CK_BYTE_PTR pWrappedKey |
|
224 |
* CK_ULONG_PTR pulWrappedKeyLen |
|
225 |
*/ |
|
226 |
JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1WrapKey |
|
227 |
(JNIEnv *env, jobject obj, jlong jSessionHandle, jobject jMechanism, jlong jWrappingKeyHandle, jlong jKeyHandle) |
|
228 |
{ |
|
229 |
CK_SESSION_HANDLE ckSessionHandle; |
|
230 |
CK_MECHANISM ckMechanism; |
|
231 |
CK_OBJECT_HANDLE ckWrappingKeyHandle; |
|
232 |
CK_OBJECT_HANDLE ckKeyHandle; |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
233 |
jbyteArray jWrappedKey = NULL; |
2 | 234 |
CK_RV rv; |
235 |
CK_BYTE BUF[MAX_STACK_BUFFER_LEN]; |
|
236 |
CK_BYTE_PTR ckpWrappedKey = BUF; |
|
237 |
CK_ULONG ckWrappedKeyLength = MAX_STACK_BUFFER_LEN; |
|
238 |
||
239 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
240 |
if (ckpFunctions == NULL) { return NULL; } |
|
241 |
||
242 |
ckSessionHandle = jLongToCKULong(jSessionHandle); |
|
243 |
jMechanismToCKMechanism(env, jMechanism, &ckMechanism); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
244 |
if ((*env)->ExceptionCheck(env)) { return NULL; } |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
245 |
|
2 | 246 |
ckWrappingKeyHandle = jLongToCKULong(jWrappingKeyHandle); |
247 |
ckKeyHandle = jLongToCKULong(jKeyHandle); |
|
248 |
||
249 |
rv = (*ckpFunctions->C_WrapKey)(ckSessionHandle, &ckMechanism, ckWrappingKeyHandle, ckKeyHandle, ckpWrappedKey, &ckWrappedKeyLength); |
|
250 |
if (rv == CKR_BUFFER_TOO_SMALL) { |
|
251 |
ckpWrappedKey = (CK_BYTE_PTR) malloc(ckWrappedKeyLength); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
252 |
if (ckpWrappedKey == NULL) { |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
253 |
if (ckMechanism.pParameter != NULL_PTR) { |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
254 |
free(ckMechanism.pParameter); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
255 |
} |
10798
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
256 |
throwOutOfMemoryError(env, 0); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
257 |
return NULL; |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
258 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
259 |
|
2 | 260 |
rv = (*ckpFunctions->C_WrapKey)(ckSessionHandle, &ckMechanism, ckWrappingKeyHandle, ckKeyHandle, ckpWrappedKey, &ckWrappedKeyLength); |
261 |
} |
|
262 |
if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { |
|
263 |
jWrappedKey = ckByteArrayToJByteArray(env, ckpWrappedKey, ckWrappedKeyLength); |
|
264 |
} |
|
265 |
||
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
266 |
if (ckpWrappedKey != BUF) { free(ckpWrappedKey); } |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
267 |
if (ckMechanism.pParameter != NULL_PTR) { |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
268 |
free(ckMechanism.pParameter); |
2 | 269 |
} |
270 |
return jWrappedKey ; |
|
271 |
} |
|
272 |
#endif |
|
273 |
||
274 |
#ifdef P11_ENABLE_C_UNWRAPKEY |
|
275 |
/* |
|
276 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
277 |
* Method: C_UnwrapKey |
|
278 |
* Signature: (JLsun/security/pkcs11/wrapper/CK_MECHANISM;J[B[Lsun/security/pkcs11/wrapper/CK_ATTRIBUTE;)J |
|
279 |
* Parametermapping: *PKCS11* |
|
280 |
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession |
|
281 |
* @param jobject jMechanism CK_MECHANISM_PTR pMechanism |
|
282 |
* @param jlong jUnwrappingKeyHandle CK_OBJECT_HANDLE hUnwrappingKey |
|
283 |
* @param jbyteArray jWrappedKey CK_BYTE_PTR pWrappedKey |
|
284 |
* CK_ULONG_PTR pulWrappedKeyLen |
|
285 |
* @param jobjectArray jTemplate CK_ATTRIBUTE_PTR pTemplate |
|
286 |
* CK_ULONG ulCount |
|
287 |
* @return jlong jKeyHandle CK_OBJECT_HANDLE_PTR phKey |
|
288 |
*/ |
|
289 |
JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1UnwrapKey |
|
290 |
(JNIEnv *env, jobject obj, jlong jSessionHandle, jobject jMechanism, jlong jUnwrappingKeyHandle, |
|
291 |
jbyteArray jWrappedKey, jobjectArray jTemplate) |
|
292 |
{ |
|
293 |
CK_SESSION_HANDLE ckSessionHandle; |
|
294 |
CK_MECHANISM ckMechanism; |
|
295 |
CK_OBJECT_HANDLE ckUnwrappingKeyHandle; |
|
296 |
CK_BYTE_PTR ckpWrappedKey = NULL_PTR; |
|
297 |
CK_ULONG ckWrappedKeyLength; |
|
298 |
CK_ATTRIBUTE_PTR ckpAttributes = NULL_PTR; |
|
299 |
CK_ULONG ckAttributesLength; |
|
3321
fed33393bc52
6823905: crash in sun.security.pkcs11.wrapper.PKCS11.C_Sign during stress-test
valeriep
parents:
2180
diff
changeset
|
300 |
CK_OBJECT_HANDLE ckKeyHandle = 0; |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
301 |
jlong jKeyHandle = 0L; |
2 | 302 |
CK_RV rv; |
303 |
||
304 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
305 |
if (ckpFunctions == NULL) { return 0L; } |
|
306 |
||
307 |
ckSessionHandle = jLongToCKULong(jSessionHandle); |
|
308 |
jMechanismToCKMechanism(env, jMechanism, &ckMechanism); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
309 |
if ((*env)->ExceptionCheck(env)) { return 0L; } |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
310 |
|
2 | 311 |
ckUnwrappingKeyHandle = jLongToCKULong(jUnwrappingKeyHandle); |
312 |
jByteArrayToCKByteArray(env, jWrappedKey, &ckpWrappedKey, &ckWrappedKeyLength); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
313 |
if ((*env)->ExceptionCheck(env)) { |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
314 |
if (ckMechanism.pParameter != NULL_PTR) { |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
315 |
free(ckMechanism.pParameter); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
316 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
317 |
return 0L; |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
318 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
319 |
|
2 | 320 |
jAttributeArrayToCKAttributeArray(env, jTemplate, &ckpAttributes, &ckAttributesLength); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
321 |
if ((*env)->ExceptionCheck(env)) { |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
322 |
if (ckMechanism.pParameter != NULL_PTR) { |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
323 |
free(ckMechanism.pParameter); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
324 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
325 |
free(ckpWrappedKey); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
326 |
return 0L; |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
327 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
328 |
|
2 | 329 |
|
330 |
rv = (*ckpFunctions->C_UnwrapKey)(ckSessionHandle, &ckMechanism, ckUnwrappingKeyHandle, |
|
331 |
ckpWrappedKey, ckWrappedKeyLength, |
|
332 |
ckpAttributes, ckAttributesLength, &ckKeyHandle); |
|
333 |
||
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
334 |
if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
335 |
jKeyHandle = ckLongToJLong(ckKeyHandle); |
2 | 336 |
|
337 |
#if 0 |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
338 |
/* cheack, if we must give a initialization vector back to Java */ |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
339 |
if (ckMechanism.mechanism == CKM_KEY_WRAP_SET_OAEP) { |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
340 |
/* we must copy back the unwrapped key info to the jMechanism object */ |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
341 |
copyBackSetUnwrappedKey(env, &ckMechanism, jMechanism); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
342 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
343 |
#endif |
2 | 344 |
} |
345 |
||
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
346 |
if (ckMechanism.pParameter != NULL_PTR) { |
2 | 347 |
free(ckMechanism.pParameter); |
348 |
} |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
349 |
freeCKAttributeArray(ckpAttributes, ckAttributesLength); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
350 |
free(ckpWrappedKey); |
2 | 351 |
|
352 |
return jKeyHandle ; |
|
353 |
} |
|
354 |
#endif |
|
355 |
||
356 |
#ifdef P11_ENABLE_C_DERIVEKEY |
|
357 |
||
358 |
void freeMasterKeyDeriveParams(CK_MECHANISM_PTR ckMechanism) { |
|
359 |
CK_SSL3_MASTER_KEY_DERIVE_PARAMS *params = (CK_SSL3_MASTER_KEY_DERIVE_PARAMS *) ckMechanism->pParameter; |
|
360 |
if (params == NULL) { |
|
361 |
return; |
|
362 |
} |
|
363 |
||
364 |
if (params->RandomInfo.pClientRandom != NULL) { |
|
365 |
free(params->RandomInfo.pClientRandom); |
|
366 |
} |
|
367 |
if (params->RandomInfo.pServerRandom != NULL) { |
|
368 |
free(params->RandomInfo.pServerRandom); |
|
369 |
} |
|
370 |
if (params->pVersion != NULL) { |
|
371 |
free(params->pVersion); |
|
372 |
} |
|
373 |
} |
|
374 |
||
375 |
void freeEcdh1DeriveParams(CK_MECHANISM_PTR ckMechanism) { |
|
376 |
CK_ECDH1_DERIVE_PARAMS *params = (CK_ECDH1_DERIVE_PARAMS *) ckMechanism->pParameter; |
|
377 |
if (params == NULL) { |
|
378 |
return; |
|
379 |
} |
|
380 |
||
381 |
if (params->pSharedData != NULL) { |
|
382 |
free(params->pSharedData); |
|
383 |
} |
|
384 |
if (params->pPublicData != NULL) { |
|
385 |
free(params->pPublicData); |
|
386 |
} |
|
387 |
} |
|
388 |
||
389 |
/* |
|
390 |
* Copy back the PRF output to Java. |
|
391 |
*/ |
|
392 |
void copyBackTLSPrfParams(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism) |
|
393 |
{ |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
394 |
jclass jMechanismClass, jTLSPrfParamsClass; |
2 | 395 |
CK_TLS_PRF_PARAMS *ckTLSPrfParams; |
396 |
jobject jTLSPrfParams; |
|
397 |
jfieldID fieldID; |
|
398 |
CK_MECHANISM_TYPE ckMechanismType; |
|
399 |
jlong jMechanismType; |
|
400 |
CK_BYTE_PTR output; |
|
401 |
jobject jOutput; |
|
402 |
jint jLength; |
|
403 |
jbyte* jBytes; |
|
404 |
int i; |
|
405 |
||
406 |
/* get mechanism */ |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
407 |
jMechanismClass = (*env)->FindClass(env, CLASS_MECHANISM); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
408 |
if (jMechanismClass == NULL) { return; } |
2 | 409 |
fieldID = (*env)->GetFieldID(env, jMechanismClass, "mechanism", "J"); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
410 |
if (fieldID == NULL) { return; } |
2 | 411 |
jMechanismType = (*env)->GetLongField(env, jMechanism, fieldID); |
412 |
ckMechanismType = jLongToCKULong(jMechanismType); |
|
413 |
if (ckMechanismType != ckMechanism->mechanism) { |
|
414 |
/* we do not have maching types, this should not occur */ |
|
415 |
return; |
|
416 |
} |
|
417 |
||
418 |
/* get the native CK_TLS_PRF_PARAMS */ |
|
419 |
ckTLSPrfParams = (CK_TLS_PRF_PARAMS *) ckMechanism->pParameter; |
|
420 |
if (ckTLSPrfParams != NULL_PTR) { |
|
421 |
/* get the Java CK_TLS_PRF_PARAMS object (pParameter) */ |
|
422 |
fieldID = (*env)->GetFieldID(env, jMechanismClass, "pParameter", "Ljava/lang/Object;"); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
423 |
if (fieldID == NULL) { return; } |
2 | 424 |
jTLSPrfParams = (*env)->GetObjectField(env, jMechanism, fieldID); |
425 |
||
426 |
/* copy back the client IV */ |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
427 |
jTLSPrfParamsClass = (*env)->FindClass(env, CLASS_TLS_PRF_PARAMS); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
428 |
if (jTLSPrfParamsClass == NULL) { return; } |
2 | 429 |
fieldID = (*env)->GetFieldID(env, jTLSPrfParamsClass, "pOutput", "[B"); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
430 |
if (fieldID == NULL) { return; } |
2 | 431 |
jOutput = (*env)->GetObjectField(env, jTLSPrfParams, fieldID); |
432 |
output = ckTLSPrfParams->pOutput; |
|
433 |
||
434 |
// Note: we assume that the token returned exactly as many bytes as we |
|
435 |
// requested. Anything else would not make sense. |
|
436 |
if (jOutput != NULL) { |
|
437 |
jLength = (*env)->GetArrayLength(env, jOutput); |
|
438 |
jBytes = (*env)->GetByteArrayElements(env, jOutput, NULL); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
439 |
if (jBytes == NULL) { return; } |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
440 |
|
2 | 441 |
/* copy the bytes to the Java buffer */ |
442 |
for (i=0; i < jLength; i++) { |
|
443 |
jBytes[i] = ckByteToJByte(output[i]); |
|
444 |
} |
|
445 |
/* copy back the Java buffer to the object */ |
|
446 |
(*env)->ReleaseByteArrayElements(env, jOutput, jBytes, 0); |
|
447 |
} |
|
448 |
||
449 |
// free malloc'd data |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
450 |
free(ckTLSPrfParams->pSeed); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
451 |
free(ckTLSPrfParams->pLabel); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
452 |
free(ckTLSPrfParams->pulOutputLen); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
453 |
free(ckTLSPrfParams->pOutput); |
2 | 454 |
} |
455 |
} |
|
456 |
||
457 |
/* |
|
458 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
459 |
* Method: C_DeriveKey |
|
460 |
* Signature: (JLsun/security/pkcs11/wrapper/CK_MECHANISM;J[Lsun/security/pkcs11/wrapper/CK_ATTRIBUTE;)J |
|
461 |
* Parametermapping: *PKCS11* |
|
462 |
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession |
|
463 |
* @param jobject jMechanism CK_MECHANISM_PTR pMechanism |
|
464 |
* @param jlong jBaseKeyHandle CK_OBJECT_HANDLE hBaseKey |
|
465 |
* @param jobjectArray jTemplate CK_ATTRIBUTE_PTR pTemplate |
|
466 |
* CK_ULONG ulCount |
|
467 |
* @return jlong jKeyHandle CK_OBJECT_HANDLE_PTR phKey |
|
468 |
*/ |
|
469 |
JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DeriveKey |
|
470 |
(JNIEnv *env, jobject obj, jlong jSessionHandle, jobject jMechanism, jlong jBaseKeyHandle, jobjectArray jTemplate) |
|
471 |
{ |
|
472 |
CK_SESSION_HANDLE ckSessionHandle; |
|
473 |
CK_MECHANISM ckMechanism; |
|
474 |
CK_OBJECT_HANDLE ckBaseKeyHandle; |
|
475 |
CK_ATTRIBUTE_PTR ckpAttributes = NULL_PTR; |
|
476 |
CK_ULONG ckAttributesLength; |
|
477 |
CK_OBJECT_HANDLE ckKeyHandle = 0; |
|
3321
fed33393bc52
6823905: crash in sun.security.pkcs11.wrapper.PKCS11.C_Sign during stress-test
valeriep
parents:
2180
diff
changeset
|
478 |
jlong jKeyHandle = 0L; |
2 | 479 |
CK_RV rv; |
480 |
CK_OBJECT_HANDLE_PTR phKey = &ckKeyHandle; |
|
481 |
||
482 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
483 |
if (ckpFunctions == NULL) { return 0L; } |
|
484 |
||
485 |
ckSessionHandle = jLongToCKULong(jSessionHandle); |
|
486 |
jMechanismToCKMechanism(env, jMechanism, &ckMechanism); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
487 |
if ((*env)->ExceptionCheck(env)) { return 0L; } |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
488 |
|
2 | 489 |
ckBaseKeyHandle = jLongToCKULong(jBaseKeyHandle); |
490 |
jAttributeArrayToCKAttributeArray(env, jTemplate, &ckpAttributes, &ckAttributesLength); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
491 |
if ((*env)->ExceptionCheck(env)) { |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
492 |
if (ckMechanism.pParameter != NULL_PTR) { |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
493 |
free(ckMechanism.pParameter); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
494 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
495 |
return 0L; |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
496 |
} |
2 | 497 |
|
498 |
switch (ckMechanism.mechanism) { |
|
499 |
case CKM_SSL3_KEY_AND_MAC_DERIVE: |
|
500 |
case CKM_TLS_KEY_AND_MAC_DERIVE: |
|
501 |
case CKM_TLS_PRF: |
|
502 |
// these mechanism do not return a key handle via phKey |
|
503 |
// set to NULL in case pedantic implementations check for it |
|
504 |
phKey = NULL; |
|
505 |
break; |
|
506 |
default: |
|
507 |
// empty |
|
508 |
break; |
|
509 |
} |
|
510 |
||
511 |
rv = (*ckpFunctions->C_DeriveKey)(ckSessionHandle, &ckMechanism, ckBaseKeyHandle, |
|
512 |
ckpAttributes, ckAttributesLength, phKey); |
|
513 |
||
514 |
jKeyHandle = ckLongToJLong(ckKeyHandle); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
515 |
|
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
516 |
freeCKAttributeArray(ckpAttributes, ckAttributesLength); |
2 | 517 |
|
518 |
switch (ckMechanism.mechanism) { |
|
519 |
case CKM_SSL3_MASTER_KEY_DERIVE: |
|
520 |
case CKM_TLS_MASTER_KEY_DERIVE: |
|
521 |
/* we must copy back the client version */ |
|
522 |
copyBackClientVersion(env, &ckMechanism, jMechanism); |
|
523 |
freeMasterKeyDeriveParams(&ckMechanism); |
|
524 |
break; |
|
525 |
case CKM_SSL3_MASTER_KEY_DERIVE_DH: |
|
526 |
case CKM_TLS_MASTER_KEY_DERIVE_DH: |
|
527 |
freeMasterKeyDeriveParams(&ckMechanism); |
|
528 |
break; |
|
529 |
case CKM_SSL3_KEY_AND_MAC_DERIVE: |
|
530 |
case CKM_TLS_KEY_AND_MAC_DERIVE: |
|
531 |
/* we must copy back the unwrapped key info to the jMechanism object */ |
|
532 |
copyBackSSLKeyMatParams(env, &ckMechanism, jMechanism); |
|
533 |
break; |
|
534 |
case CKM_TLS_PRF: |
|
535 |
copyBackTLSPrfParams(env, &ckMechanism, jMechanism); |
|
536 |
break; |
|
537 |
case CKM_ECDH1_DERIVE: |
|
538 |
freeEcdh1DeriveParams(&ckMechanism); |
|
539 |
break; |
|
540 |
default: |
|
541 |
// empty |
|
542 |
break; |
|
543 |
} |
|
544 |
||
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
545 |
if (ckMechanism.pParameter != NULL_PTR) { |
2 | 546 |
free(ckMechanism.pParameter); |
547 |
} |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
548 |
if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return 0L ; } |
2 | 549 |
|
550 |
return jKeyHandle ; |
|
551 |
} |
|
552 |
||
553 |
/* |
|
554 |
* Copy back the client version information from the native |
|
555 |
* structure to the Java object. This is only used for the |
|
556 |
* CKM_SSL3_MASTER_KEY_DERIVE mechanism when used for deriving a key. |
|
557 |
* |
|
558 |
*/ |
|
559 |
void copyBackClientVersion(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism) |
|
560 |
{ |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
561 |
jclass jMechanismClass, jSSL3MasterKeyDeriveParamsClass, jVersionClass; |
2 | 562 |
CK_SSL3_MASTER_KEY_DERIVE_PARAMS *ckSSL3MasterKeyDeriveParams; |
563 |
CK_VERSION *ckVersion; |
|
564 |
jfieldID fieldID; |
|
565 |
CK_MECHANISM_TYPE ckMechanismType; |
|
566 |
jlong jMechanismType; |
|
567 |
jobject jSSL3MasterKeyDeriveParams; |
|
568 |
jobject jVersion; |
|
569 |
||
570 |
/* get mechanism */ |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
571 |
jMechanismClass = (*env)->FindClass(env, CLASS_MECHANISM); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
572 |
if (jMechanismClass == NULL) { return; } |
2 | 573 |
fieldID = (*env)->GetFieldID(env, jMechanismClass, "mechanism", "J"); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
574 |
if (fieldID == NULL) { return; } |
2 | 575 |
jMechanismType = (*env)->GetLongField(env, jMechanism, fieldID); |
576 |
ckMechanismType = jLongToCKULong(jMechanismType); |
|
577 |
if (ckMechanismType != ckMechanism->mechanism) { |
|
578 |
/* we do not have maching types, this should not occur */ |
|
579 |
return; |
|
580 |
} |
|
581 |
||
582 |
/* get the native CK_SSL3_MASTER_KEY_DERIVE_PARAMS */ |
|
583 |
ckSSL3MasterKeyDeriveParams = (CK_SSL3_MASTER_KEY_DERIVE_PARAMS *) ckMechanism->pParameter; |
|
584 |
if (ckSSL3MasterKeyDeriveParams != NULL_PTR) { |
|
585 |
/* get the native CK_VERSION */ |
|
586 |
ckVersion = ckSSL3MasterKeyDeriveParams->pVersion; |
|
587 |
if (ckVersion != NULL_PTR) { |
|
588 |
/* get the Java CK_SSL3_MASTER_KEY_DERIVE_PARAMS (pParameter) */ |
|
589 |
fieldID = (*env)->GetFieldID(env, jMechanismClass, "pParameter", "Ljava/lang/Object;"); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
590 |
if (fieldID == NULL) { return; } |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
591 |
|
2 | 592 |
jSSL3MasterKeyDeriveParams = (*env)->GetObjectField(env, jMechanism, fieldID); |
593 |
||
594 |
/* get the Java CK_VERSION */ |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
595 |
jSSL3MasterKeyDeriveParamsClass = (*env)->FindClass(env, CLASS_SSL3_MASTER_KEY_DERIVE_PARAMS); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
596 |
if (jSSL3MasterKeyDeriveParamsClass == NULL) { return; } |
2 | 597 |
fieldID = (*env)->GetFieldID(env, jSSL3MasterKeyDeriveParamsClass, "pVersion", "L"CLASS_VERSION";"); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
598 |
if (fieldID == NULL) { return; } |
2 | 599 |
jVersion = (*env)->GetObjectField(env, jSSL3MasterKeyDeriveParams, fieldID); |
600 |
||
601 |
/* now copy back the version from the native structure to the Java structure */ |
|
602 |
||
603 |
/* copy back the major version */ |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
604 |
jVersionClass = (*env)->FindClass(env, CLASS_VERSION); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
605 |
if (jVersionClass == NULL) { return; } |
2 | 606 |
fieldID = (*env)->GetFieldID(env, jVersionClass, "major", "B"); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
607 |
if (fieldID == NULL) { return; } |
2 | 608 |
(*env)->SetByteField(env, jVersion, fieldID, ckByteToJByte(ckVersion->major)); |
609 |
||
610 |
/* copy back the minor version */ |
|
611 |
fieldID = (*env)->GetFieldID(env, jVersionClass, "minor", "B"); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
612 |
if (fieldID == NULL) { return; } |
2 | 613 |
(*env)->SetByteField(env, jVersion, fieldID, ckByteToJByte(ckVersion->minor)); |
614 |
} |
|
615 |
} |
|
616 |
} |
|
617 |
||
618 |
||
619 |
/* |
|
620 |
* Copy back the derived keys and initialization vectors from the native |
|
621 |
* structure to the Java object. This is only used for the |
|
622 |
* CKM_SSL3_KEY_AND_MAC_DERIVE mechanism when used for deriving a key. |
|
623 |
* |
|
624 |
*/ |
|
625 |
void copyBackSSLKeyMatParams(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism) |
|
626 |
{ |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
627 |
jclass jMechanismClass, jSSL3KeyMatParamsClass, jSSL3KeyMatOutClass; |
2 | 628 |
CK_SSL3_KEY_MAT_PARAMS *ckSSL3KeyMatParam; |
629 |
CK_SSL3_KEY_MAT_OUT *ckSSL3KeyMatOut; |
|
630 |
jfieldID fieldID; |
|
631 |
CK_MECHANISM_TYPE ckMechanismType; |
|
632 |
jlong jMechanismType; |
|
633 |
CK_BYTE_PTR iv; |
|
634 |
jobject jSSL3KeyMatParam; |
|
635 |
jobject jSSL3KeyMatOut; |
|
636 |
jobject jIV; |
|
637 |
jint jLength; |
|
638 |
jbyte* jBytes; |
|
639 |
int i; |
|
640 |
||
641 |
/* get mechanism */ |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
642 |
jMechanismClass= (*env)->FindClass(env, CLASS_MECHANISM); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
643 |
if (jMechanismClass == NULL) { return; } |
2 | 644 |
fieldID = (*env)->GetFieldID(env, jMechanismClass, "mechanism", "J"); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
645 |
if (fieldID == NULL) { return; } |
2 | 646 |
jMechanismType = (*env)->GetLongField(env, jMechanism, fieldID); |
647 |
ckMechanismType = jLongToCKULong(jMechanismType); |
|
648 |
if (ckMechanismType != ckMechanism->mechanism) { |
|
649 |
/* we do not have maching types, this should not occur */ |
|
650 |
return; |
|
651 |
} |
|
652 |
||
653 |
/* get the native CK_SSL3_KEY_MAT_PARAMS */ |
|
654 |
ckSSL3KeyMatParam = (CK_SSL3_KEY_MAT_PARAMS *) ckMechanism->pParameter; |
|
655 |
if (ckSSL3KeyMatParam != NULL_PTR) { |
|
656 |
// free malloc'd data |
|
657 |
if (ckSSL3KeyMatParam->RandomInfo.pClientRandom != NULL) { |
|
658 |
free(ckSSL3KeyMatParam->RandomInfo.pClientRandom); |
|
659 |
} |
|
660 |
if (ckSSL3KeyMatParam->RandomInfo.pServerRandom != NULL) { |
|
661 |
free(ckSSL3KeyMatParam->RandomInfo.pServerRandom); |
|
662 |
} |
|
663 |
||
664 |
/* get the native CK_SSL3_KEY_MAT_OUT */ |
|
665 |
ckSSL3KeyMatOut = ckSSL3KeyMatParam->pReturnedKeyMaterial; |
|
666 |
if (ckSSL3KeyMatOut != NULL_PTR) { |
|
667 |
/* get the Java CK_SSL3_KEY_MAT_PARAMS (pParameter) */ |
|
668 |
fieldID = (*env)->GetFieldID(env, jMechanismClass, "pParameter", "Ljava/lang/Object;"); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
669 |
if (fieldID == NULL) { return; } |
2 | 670 |
jSSL3KeyMatParam = (*env)->GetObjectField(env, jMechanism, fieldID); |
671 |
||
672 |
/* get the Java CK_SSL3_KEY_MAT_OUT */ |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
673 |
jSSL3KeyMatParamsClass = (*env)->FindClass(env, CLASS_SSL3_KEY_MAT_PARAMS); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
674 |
if (jSSL3KeyMatParamsClass == NULL) { return; } |
2 | 675 |
fieldID = (*env)->GetFieldID(env, jSSL3KeyMatParamsClass, "pReturnedKeyMaterial", "L"CLASS_SSL3_KEY_MAT_OUT";"); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
676 |
if (fieldID == NULL) { return; } |
2 | 677 |
jSSL3KeyMatOut = (*env)->GetObjectField(env, jSSL3KeyMatParam, fieldID); |
678 |
||
679 |
/* now copy back all the key handles and the initialization vectors */ |
|
680 |
/* copy back client MAC secret handle */ |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
681 |
jSSL3KeyMatOutClass = (*env)->FindClass(env, CLASS_SSL3_KEY_MAT_OUT); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
682 |
if (jSSL3KeyMatOutClass == NULL) { return; } |
2 | 683 |
fieldID = (*env)->GetFieldID(env, jSSL3KeyMatOutClass, "hClientMacSecret", "J"); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
684 |
if (fieldID == NULL) { return; } |
2 | 685 |
(*env)->SetLongField(env, jSSL3KeyMatOut, fieldID, ckULongToJLong(ckSSL3KeyMatOut->hClientMacSecret)); |
686 |
||
687 |
/* copy back server MAC secret handle */ |
|
688 |
fieldID = (*env)->GetFieldID(env, jSSL3KeyMatOutClass, "hServerMacSecret", "J"); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
689 |
if (fieldID == NULL) { return; } |
2 | 690 |
(*env)->SetLongField(env, jSSL3KeyMatOut, fieldID, ckULongToJLong(ckSSL3KeyMatOut->hServerMacSecret)); |
691 |
||
692 |
/* copy back client secret key handle */ |
|
693 |
fieldID = (*env)->GetFieldID(env, jSSL3KeyMatOutClass, "hClientKey", "J"); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
694 |
if (fieldID == NULL) { return; } |
2 | 695 |
(*env)->SetLongField(env, jSSL3KeyMatOut, fieldID, ckULongToJLong(ckSSL3KeyMatOut->hClientKey)); |
696 |
||
697 |
/* copy back server secret key handle */ |
|
698 |
fieldID = (*env)->GetFieldID(env, jSSL3KeyMatOutClass, "hServerKey", "J"); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
699 |
if (fieldID == NULL) { return; } |
2 | 700 |
(*env)->SetLongField(env, jSSL3KeyMatOut, fieldID, ckULongToJLong(ckSSL3KeyMatOut->hServerKey)); |
701 |
||
702 |
/* copy back the client IV */ |
|
703 |
fieldID = (*env)->GetFieldID(env, jSSL3KeyMatOutClass, "pIVClient", "[B"); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
704 |
if (fieldID == NULL) { return; } |
2 | 705 |
jIV = (*env)->GetObjectField(env, jSSL3KeyMatOut, fieldID); |
706 |
iv = ckSSL3KeyMatOut->pIVClient; |
|
707 |
||
708 |
if (jIV != NULL) { |
|
709 |
jLength = (*env)->GetArrayLength(env, jIV); |
|
710 |
jBytes = (*env)->GetByteArrayElements(env, jIV, NULL); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
711 |
if (jBytes == NULL) { return; } |
2 | 712 |
/* copy the bytes to the Java buffer */ |
713 |
for (i=0; i < jLength; i++) { |
|
714 |
jBytes[i] = ckByteToJByte(iv[i]); |
|
715 |
} |
|
716 |
/* copy back the Java buffer to the object */ |
|
717 |
(*env)->ReleaseByteArrayElements(env, jIV, jBytes, 0); |
|
718 |
} |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
719 |
// free malloc'd data |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
720 |
free(ckSSL3KeyMatOut->pIVClient); |
2 | 721 |
|
722 |
/* copy back the server IV */ |
|
723 |
fieldID = (*env)->GetFieldID(env, jSSL3KeyMatOutClass, "pIVServer", "[B"); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
724 |
if (fieldID == NULL) { return; } |
2 | 725 |
jIV = (*env)->GetObjectField(env, jSSL3KeyMatOut, fieldID); |
726 |
iv = ckSSL3KeyMatOut->pIVServer; |
|
727 |
||
728 |
if (jIV != NULL) { |
|
729 |
jLength = (*env)->GetArrayLength(env, jIV); |
|
730 |
jBytes = (*env)->GetByteArrayElements(env, jIV, NULL); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
731 |
if (jBytes == NULL) { return; } |
2 | 732 |
/* copy the bytes to the Java buffer */ |
733 |
for (i=0; i < jLength; i++) { |
|
734 |
jBytes[i] = ckByteToJByte(iv[i]); |
|
735 |
} |
|
736 |
/* copy back the Java buffer to the object */ |
|
737 |
(*env)->ReleaseByteArrayElements(env, jIV, jBytes, 0); |
|
738 |
} |
|
739 |
// free malloc'd data |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
740 |
free(ckSSL3KeyMatOut->pIVServer); |
2 | 741 |
free(ckSSL3KeyMatOut); |
742 |
} |
|
743 |
} |
|
744 |
} |
|
745 |
||
746 |
#endif |