author | valeriep |
Wed, 22 Jul 2009 17:52:21 -0700 | |
changeset 3321 | fed33393bc52 |
parent 2180 | 9994f4f08a59 |
child 5506 | 202f599c92aa |
permissions | -rw-r--r-- |
2 | 1 |
/* |
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
|
2 |
* Portions Copyright 2003-2009 Sun Microsystems, Inc. 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 |
/* declare file private functions */ |
|
56 |
||
57 |
ModuleData * getModuleEntry(JNIEnv *env, jobject pkcs11Implementation); |
|
58 |
int isModulePresent(JNIEnv *env, jobject pkcs11Implementation); |
|
59 |
void removeAllModuleEntries(JNIEnv *env); |
|
60 |
||
61 |
||
62 |
/* ************************************************************************** */ |
|
63 |
/* Functions for keeping track of currently active and loaded modules */ |
|
64 |
/* ************************************************************************** */ |
|
65 |
||
66 |
||
67 |
/* |
|
68 |
* Create a new object for locking. |
|
69 |
*/ |
|
70 |
jobject createLockObject(JNIEnv *env) { |
|
71 |
jclass jObjectClass; |
|
72 |
jobject jLockObject; |
|
73 |
jmethodID jConstructor; |
|
74 |
||
75 |
jObjectClass = (*env)->FindClass(env, "java/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
|
76 |
if (jObjectClass == NULL) { return NULL; } |
2 | 77 |
jConstructor = (*env)->GetMethodID(env, jObjectClass, "<init>", "()V"); |
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
|
78 |
if (jConstructor == NULL) { return NULL; } |
2 | 79 |
jLockObject = (*env)->NewObject(env, jObjectClass, jConstructor); |
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
|
80 |
if (jLockObject == NULL) { return NULL; } |
2 | 81 |
jLockObject = (*env)->NewGlobalRef(env, jLockObject); |
82 |
||
83 |
return jLockObject ; |
|
84 |
} |
|
85 |
||
86 |
/* |
|
87 |
* Create a new object for locking. |
|
88 |
*/ |
|
89 |
void destroyLockObject(JNIEnv *env, jobject jLockObject) { |
|
90 |
if (jLockObject != NULL) { |
|
91 |
(*env)->DeleteGlobalRef(env, jLockObject); |
|
92 |
} |
|
93 |
} |
|
94 |
||
95 |
/* |
|
96 |
* Add the given pkcs11Implementation object to the list of present modules. |
|
97 |
* Attach the given data to the entry. If the given pkcs11Implementation is |
|
98 |
* already in the lsit, just override its old module data with the new one. |
|
99 |
* None of the arguments can be NULL. If one of the arguments is NULL, this |
|
100 |
* function does nothing. |
|
101 |
*/ |
|
102 |
void putModuleEntry(JNIEnv *env, jobject pkcs11Implementation, ModuleData *moduleData) { |
|
103 |
if (pkcs11Implementation == NULL_PTR) { |
|
104 |
return ; |
|
105 |
} |
|
106 |
if (moduleData == NULL) { |
|
107 |
return ; |
|
108 |
} |
|
109 |
(*env)->SetLongField(env, pkcs11Implementation, pNativeDataID, (jlong)moduleData); |
|
110 |
} |
|
111 |
||
112 |
||
113 |
/* |
|
114 |
* Get the module data of the entry for the given pkcs11Implementation. Returns |
|
115 |
* NULL, if the pkcs11Implementation is not in the list. |
|
116 |
*/ |
|
117 |
ModuleData * getModuleEntry(JNIEnv *env, jobject pkcs11Implementation) { |
|
118 |
jlong jData; |
|
119 |
if (pkcs11Implementation == NULL) { |
|
120 |
return NULL; |
|
121 |
} |
|
122 |
jData = (*env)->GetLongField(env, pkcs11Implementation, pNativeDataID); |
|
123 |
return (ModuleData*)jData; |
|
124 |
} |
|
125 |
||
126 |
CK_FUNCTION_LIST_PTR getFunctionList(JNIEnv *env, jobject pkcs11Implementation) { |
|
127 |
ModuleData *moduleData; |
|
128 |
CK_FUNCTION_LIST_PTR ckpFunctions; |
|
129 |
||
130 |
moduleData = getModuleEntry(env, pkcs11Implementation); |
|
131 |
if (moduleData == NULL) { |
|
132 |
throwDisconnectedRuntimeException(env); |
|
133 |
return NULL; |
|
134 |
} |
|
135 |
ckpFunctions = moduleData->ckFunctionListPtr; |
|
136 |
return ckpFunctions; |
|
137 |
} |
|
138 |
||
139 |
||
140 |
/* |
|
141 |
* Returns 1, if the given pkcs11Implementation is in the list. |
|
142 |
* 0, otherwise. |
|
143 |
*/ |
|
144 |
int isModulePresent(JNIEnv *env, jobject pkcs11Implementation) { |
|
145 |
int present; |
|
146 |
||
147 |
ModuleData *moduleData = getModuleEntry(env, pkcs11Implementation); |
|
148 |
||
149 |
present = (moduleData != NULL) ? 1 : 0; |
|
150 |
||
151 |
return present ; |
|
152 |
} |
|
153 |
||
154 |
||
155 |
/* |
|
156 |
* Removes the entry for the given pkcs11Implementation from the list. Returns |
|
157 |
* the module's data, after the node was removed. If this function returns NULL |
|
158 |
* the pkcs11Implementation was not in the list. |
|
159 |
*/ |
|
160 |
ModuleData * removeModuleEntry(JNIEnv *env, jobject pkcs11Implementation) { |
|
161 |
ModuleData *moduleData = getModuleEntry(env, pkcs11Implementation); |
|
162 |
if (moduleData == NULL) { |
|
163 |
return NULL; |
|
164 |
} |
|
165 |
(*env)->SetLongField(env, pkcs11Implementation, pNativeDataID, 0); |
|
166 |
return moduleData; |
|
167 |
} |
|
168 |
||
169 |
/* |
|
170 |
* Removes all present entries from the list of modules and frees all |
|
171 |
* associated resources. This function is used for clean-up. |
|
172 |
*/ |
|
173 |
void removeAllModuleEntries(JNIEnv *env) { |
|
174 |
/* XXX empty */ |
|
175 |
} |
|
176 |
||
177 |
/* ************************************************************************** */ |
|
178 |
/* Below there follow the helper functions to support conversions between */ |
|
179 |
/* Java and Cryptoki types */ |
|
180 |
/* ************************************************************************** */ |
|
181 |
||
182 |
/* |
|
183 |
* function to convert a PKCS#11 return value into a PKCS#11Exception |
|
184 |
* |
|
185 |
* This function generates a PKCS#11Exception with the returnValue as the errorcode |
|
186 |
* if the returnValue is not CKR_OK. The functin returns 0, if the returnValue is |
|
187 |
* CKR_OK. Otherwise, it returns the returnValue as a jLong. |
|
188 |
* |
|
189 |
* @param env - used to call JNI funktions and to get the Exception class |
|
190 |
* @param returnValue - of the PKCS#11 function |
|
191 |
*/ |
|
192 |
jlong ckAssertReturnValueOK(JNIEnv *env, CK_RV returnValue) |
|
193 |
{ |
|
194 |
jclass jPKCS11ExceptionClass; |
|
195 |
jmethodID jConstructor; |
|
196 |
jthrowable jPKCS11Exception; |
|
3321
fed33393bc52
6823905: crash in sun.security.pkcs11.wrapper.PKCS11.C_Sign during stress-test
valeriep
parents:
2180
diff
changeset
|
197 |
jlong jErrorCode = 0L; |
2 | 198 |
|
3321
fed33393bc52
6823905: crash in sun.security.pkcs11.wrapper.PKCS11.C_Sign during stress-test
valeriep
parents:
2180
diff
changeset
|
199 |
if (returnValue != CKR_OK) { |
fed33393bc52
6823905: crash in sun.security.pkcs11.wrapper.PKCS11.C_Sign during stress-test
valeriep
parents:
2180
diff
changeset
|
200 |
jErrorCode = ckULongToJLong(returnValue); |
2 | 201 |
jPKCS11ExceptionClass = (*env)->FindClass(env, CLASS_PKCS11EXCEPTION); |
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
|
202 |
if (jPKCS11ExceptionClass != 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
|
203 |
jConstructor = (*env)->GetMethodID(env, jPKCS11ExceptionClass, "<init>", "(J)V"); |
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
|
204 |
if (jConstructor != 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
|
205 |
jPKCS11Exception = (jthrowable) (*env)->NewObject(env, jPKCS11ExceptionClass, jConstructor, jErrorCode); |
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 |
if (jPKCS11Exception != 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
|
207 |
(*env)->Throw(env, jPKCS11Exception); |
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
|
208 |
} |
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
|
209 |
} |
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
|
210 |
} |
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
|
211 |
(*env)->DeleteLocalRef(env, jPKCS11ExceptionClass); |
2 | 212 |
} |
3321
fed33393bc52
6823905: crash in sun.security.pkcs11.wrapper.PKCS11.C_Sign during stress-test
valeriep
parents:
2180
diff
changeset
|
213 |
return jErrorCode ; |
2 | 214 |
} |
215 |
||
216 |
/* |
|
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
|
217 |
* This function simply throws an IOException |
2 | 218 |
* |
219 |
* @param env Used to call JNI funktions and to get the Exception class. |
|
220 |
* @param message The message string of the Exception object. |
|
221 |
*/ |
|
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
|
222 |
void throwIOException(JNIEnv *env, const char *message) |
2 | 223 |
{ |
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
|
224 |
JNU_ThrowByName(env, CLASS_IO_EXCEPTION, message); |
2 | 225 |
} |
226 |
||
227 |
/* |
|
228 |
* This function simply throws a PKCS#11RuntimeException with the given |
|
229 |
* string as its message. If the message is NULL, the exception is created |
|
230 |
* using the default constructor. |
|
231 |
* |
|
232 |
* @param env Used to call JNI funktions and to get the Exception class. |
|
233 |
* @param jmessage The message string of the Exception object. |
|
234 |
*/ |
|
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
|
235 |
void throwPKCS11RuntimeException(JNIEnv *env, const char *message) |
2 | 236 |
{ |
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
|
237 |
JNU_ThrowByName(env, CLASS_PKCS11RUNTIMEEXCEPTION, message); |
2 | 238 |
} |
239 |
||
240 |
/* |
|
241 |
* This function simply throws a PKCS#11RuntimeException. The message says that |
|
242 |
* the object is not connected to the module. |
|
243 |
* |
|
244 |
* @param env Used to call JNI funktions and to get the Exception class. |
|
245 |
*/ |
|
246 |
void throwDisconnectedRuntimeException(JNIEnv *env) |
|
247 |
{ |
|
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
|
248 |
throwPKCS11RuntimeException(env, "This object is not connected to a module."); |
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
|
249 |
} |
2 | 250 |
|
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
|
251 |
/* This function frees the specified CK_ATTRIBUTE array. |
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 |
* |
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 |
* @param attrPtr pointer to the to-be-freed CK_ATTRIBUTE array. |
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 |
* @param len the length of the array |
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 |
*/ |
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
|
256 |
void freeCKAttributeArray(CK_ATTRIBUTE_PTR attrPtr, int len) |
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 |
{ |
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 |
int i; |
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 |
|
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
|
260 |
for (i=0; i<len; i++) { |
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
|
261 |
if (attrPtr[i].pValue != 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
|
262 |
free(attrPtr[i].pValue); |
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
|
263 |
} |
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
|
264 |
} |
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
|
265 |
free(attrPtr); |
2 | 266 |
} |
267 |
||
268 |
/* |
|
269 |
* the following functions convert Java arrays to PKCS#11 array pointers and |
|
270 |
* their array length and vice versa |
|
271 |
* |
|
272 |
* void j<Type>ArrayToCK<Type>Array(JNIEnv *env, |
|
273 |
* const j<Type>Array jArray, |
|
274 |
* CK_<Type>_PTR *ckpArray, |
|
275 |
* CK_ULONG_PTR ckLength); |
|
276 |
* |
|
277 |
* j<Type>Array ck<Type>ArrayToJ<Type>Array(JNIEnv *env, |
|
278 |
* const CK_<Type>_PTR ckpArray, |
|
279 |
* CK_ULONG ckLength); |
|
280 |
* |
|
281 |
* PKCS#11 arrays consist always of a pointer to the beginning of the array and |
|
282 |
* the array length whereas Java arrays carry their array length. |
|
283 |
* |
|
284 |
* The Functions to convert a Java array to a PKCS#11 array are void functions. |
|
285 |
* Their arguments are the Java array object to convert, the reference to the |
|
286 |
* array pointer, where the new PKCS#11 array should be stored and the reference |
|
287 |
* to the array length where the PKCS#11 array length should be stored. These two |
|
288 |
* references must not be NULL_PTR. |
|
289 |
* |
|
290 |
* The functions first obtain the array length of the Java array and then allocate |
|
291 |
* the memory for the PKCS#11 array and set the array length. Then each element |
|
292 |
* gets converted depending on their type. After use the allocated memory of the |
|
293 |
* PKCS#11 array has to be explicitly freed. |
|
294 |
* |
|
295 |
* The Functions to convert a PKCS#11 array to a Java array get the PKCS#11 array |
|
296 |
* pointer and the array length and they return the new Java array object. The |
|
297 |
* Java array does not need to get freed after use. |
|
298 |
*/ |
|
299 |
||
300 |
/* |
|
301 |
* converts a jbooleanArray to a CK_BBOOL array. The allocated memory has to be freed after use! |
|
302 |
* |
|
303 |
* @param env - used to call JNI funktions to get the array informtaion |
|
304 |
* @param jArray - the Java array to convert |
|
305 |
* @param ckpArray - the reference, where the pointer to the new CK_BBOOL array will be stored |
|
306 |
* @param ckpLength - the reference, where the array length will be stored |
|
307 |
*/ |
|
308 |
void jBooleanArrayToCKBBoolArray(JNIEnv *env, const jbooleanArray jArray, CK_BBOOL **ckpArray, CK_ULONG_PTR ckpLength) |
|
309 |
{ |
|
310 |
jboolean* jpTemp; |
|
311 |
CK_ULONG i; |
|
312 |
||
313 |
if(jArray == NULL) { |
|
314 |
*ckpArray = NULL_PTR; |
|
315 |
*ckpLength = 0L; |
|
316 |
return; |
|
317 |
} |
|
318 |
*ckpLength = (*env)->GetArrayLength(env, jArray); |
|
319 |
jpTemp = (jboolean*) malloc((*ckpLength) * sizeof(jboolean)); |
|
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
|
320 |
if (jpTemp == 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
|
321 |
JNU_ThrowOutOfMemoryError(env, 0); |
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 |
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
|
323 |
} |
2 | 324 |
(*env)->GetBooleanArrayRegion(env, jArray, 0, *ckpLength, jpTemp); |
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
|
325 |
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
|
326 |
free(jpTemp); |
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 |
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
|
328 |
} |
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
|
329 |
|
2 | 330 |
*ckpArray = (CK_BBOOL*) malloc ((*ckpLength) * sizeof(CK_BBOOL)); |
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
|
331 |
if (*ckpArray == 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
|
332 |
free(jpTemp); |
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
|
333 |
JNU_ThrowOutOfMemoryError(env, 0); |
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 |
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
|
335 |
} |
2 | 336 |
for (i=0; i<(*ckpLength); i++) { |
337 |
(*ckpArray)[i] = jBooleanToCKBBool(jpTemp[i]); |
|
338 |
} |
|
339 |
free(jpTemp); |
|
340 |
} |
|
341 |
||
342 |
/* |
|
343 |
* converts a jbyteArray to a CK_BYTE array. The allocated memory has to be freed after use! |
|
344 |
* |
|
345 |
* @param env - used to call JNI funktions to get the array informtaion |
|
346 |
* @param jArray - the Java array to convert |
|
347 |
* @param ckpArray - the reference, where the pointer to the new CK_BYTE array will be stored |
|
348 |
* @param ckpLength - the reference, where the array length will be stored |
|
349 |
*/ |
|
350 |
void jByteArrayToCKByteArray(JNIEnv *env, const jbyteArray jArray, CK_BYTE_PTR *ckpArray, CK_ULONG_PTR ckpLength) |
|
351 |
{ |
|
352 |
jbyte* jpTemp; |
|
353 |
CK_ULONG i; |
|
354 |
||
355 |
if(jArray == NULL) { |
|
356 |
*ckpArray = NULL_PTR; |
|
357 |
*ckpLength = 0L; |
|
358 |
return; |
|
359 |
} |
|
360 |
*ckpLength = (*env)->GetArrayLength(env, jArray); |
|
361 |
jpTemp = (jbyte*) malloc((*ckpLength) * sizeof(jbyte)); |
|
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
|
362 |
if (jpTemp == 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
|
363 |
JNU_ThrowOutOfMemoryError(env, 0); |
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
|
364 |
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
|
365 |
} |
2 | 366 |
(*env)->GetByteArrayRegion(env, jArray, 0, *ckpLength, jpTemp); |
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
|
367 |
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
|
368 |
free(jpTemp); |
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
|
369 |
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
|
370 |
} |
2 | 371 |
|
372 |
/* if CK_BYTE is the same size as jbyte, we save an additional copy */ |
|
373 |
if (sizeof(CK_BYTE) == sizeof(jbyte)) { |
|
374 |
*ckpArray = (CK_BYTE_PTR) jpTemp; |
|
375 |
} else { |
|
376 |
*ckpArray = (CK_BYTE_PTR) malloc ((*ckpLength) * sizeof(CK_BYTE)); |
|
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
|
377 |
if (*ckpArray == 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
|
378 |
free(jpTemp); |
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
|
379 |
JNU_ThrowOutOfMemoryError(env, 0); |
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
|
380 |
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
|
381 |
} |
2 | 382 |
for (i=0; i<(*ckpLength); i++) { |
383 |
(*ckpArray)[i] = jByteToCKByte(jpTemp[i]); |
|
384 |
} |
|
385 |
free(jpTemp); |
|
386 |
} |
|
387 |
} |
|
388 |
||
389 |
/* |
|
390 |
* converts a jlongArray to a CK_ULONG array. The allocated memory has to be freed after use! |
|
391 |
* |
|
392 |
* @param env - used to call JNI funktions to get the array informtaion |
|
393 |
* @param jArray - the Java array to convert |
|
394 |
* @param ckpArray - the reference, where the pointer to the new CK_ULONG array will be stored |
|
395 |
* @param ckpLength - the reference, where the array length will be stored |
|
396 |
*/ |
|
397 |
void jLongArrayToCKULongArray(JNIEnv *env, const jlongArray jArray, CK_ULONG_PTR *ckpArray, CK_ULONG_PTR ckpLength) |
|
398 |
{ |
|
399 |
jlong* jTemp; |
|
400 |
CK_ULONG i; |
|
401 |
||
402 |
if(jArray == NULL) { |
|
403 |
*ckpArray = NULL_PTR; |
|
404 |
*ckpLength = 0L; |
|
405 |
return; |
|
406 |
} |
|
407 |
*ckpLength = (*env)->GetArrayLength(env, jArray); |
|
408 |
jTemp = (jlong*) malloc((*ckpLength) * sizeof(jlong)); |
|
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
|
409 |
if (jTemp == 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
|
410 |
JNU_ThrowOutOfMemoryError(env, 0); |
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
|
411 |
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
|
412 |
} |
2 | 413 |
(*env)->GetLongArrayRegion(env, jArray, 0, *ckpLength, jTemp); |
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
|
414 |
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
|
415 |
free(jTemp); |
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
|
416 |
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
|
417 |
} |
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
|
418 |
|
2 | 419 |
*ckpArray = (CK_ULONG_PTR) malloc (*ckpLength * sizeof(CK_ULONG)); |
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
|
420 |
if (*ckpArray == 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
|
421 |
free(jTemp); |
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
|
422 |
JNU_ThrowOutOfMemoryError(env, 0); |
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 |
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
|
424 |
} |
2 | 425 |
for (i=0; i<(*ckpLength); i++) { |
426 |
(*ckpArray)[i] = jLongToCKULong(jTemp[i]); |
|
427 |
} |
|
428 |
free(jTemp); |
|
429 |
} |
|
430 |
||
431 |
/* |
|
432 |
* converts a jcharArray to a CK_CHAR array. The allocated memory has to be freed after use! |
|
433 |
* |
|
434 |
* @param env - used to call JNI funktions to get the array informtaion |
|
435 |
* @param jArray - the Java array to convert |
|
436 |
* @param ckpArray - the reference, where the pointer to the new CK_CHAR array will be stored |
|
437 |
* @param ckpLength - the reference, where the array length will be stored |
|
438 |
*/ |
|
439 |
void jCharArrayToCKCharArray(JNIEnv *env, const jcharArray jArray, CK_CHAR_PTR *ckpArray, CK_ULONG_PTR ckpLength) |
|
440 |
{ |
|
441 |
jchar* jpTemp; |
|
442 |
CK_ULONG i; |
|
443 |
||
444 |
if(jArray == NULL) { |
|
445 |
*ckpArray = NULL_PTR; |
|
446 |
*ckpLength = 0L; |
|
447 |
return; |
|
448 |
} |
|
449 |
*ckpLength = (*env)->GetArrayLength(env, jArray); |
|
450 |
jpTemp = (jchar*) malloc((*ckpLength) * sizeof(jchar)); |
|
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
|
451 |
if (jpTemp == 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
|
452 |
JNU_ThrowOutOfMemoryError(env, 0); |
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 |
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
|
454 |
} |
2 | 455 |
(*env)->GetCharArrayRegion(env, jArray, 0, *ckpLength, jpTemp); |
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
|
456 |
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
|
457 |
free(jpTemp); |
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
|
458 |
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
|
459 |
} |
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
|
460 |
|
2 | 461 |
*ckpArray = (CK_CHAR_PTR) malloc (*ckpLength * sizeof(CK_CHAR)); |
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
|
462 |
if (*ckpArray == 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
|
463 |
free(jpTemp); |
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
|
464 |
JNU_ThrowOutOfMemoryError(env, 0); |
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
|
465 |
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
|
466 |
} |
2 | 467 |
for (i=0; i<(*ckpLength); i++) { |
468 |
(*ckpArray)[i] = jCharToCKChar(jpTemp[i]); |
|
469 |
} |
|
470 |
free(jpTemp); |
|
471 |
} |
|
472 |
||
473 |
/* |
|
474 |
* converts a jcharArray to a CK_UTF8CHAR array. The allocated memory has to be freed after use! |
|
475 |
* |
|
476 |
* @param env - used to call JNI funktions to get the array informtaion |
|
477 |
* @param jArray - the Java array to convert |
|
478 |
* @param ckpArray - the reference, where the pointer to the new CK_UTF8CHAR array will be stored |
|
479 |
* @param ckpLength - the reference, where the array length will be stored |
|
480 |
*/ |
|
481 |
void jCharArrayToCKUTF8CharArray(JNIEnv *env, const jcharArray jArray, CK_UTF8CHAR_PTR *ckpArray, CK_ULONG_PTR ckpLength) |
|
482 |
{ |
|
483 |
jchar* jTemp; |
|
484 |
CK_ULONG i; |
|
485 |
||
486 |
if(jArray == NULL) { |
|
487 |
*ckpArray = NULL_PTR; |
|
488 |
*ckpLength = 0L; |
|
489 |
return; |
|
490 |
} |
|
491 |
*ckpLength = (*env)->GetArrayLength(env, jArray); |
|
492 |
jTemp = (jchar*) malloc((*ckpLength) * sizeof(jchar)); |
|
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
|
493 |
if (jTemp == 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
|
494 |
JNU_ThrowOutOfMemoryError(env, 0); |
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; |
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 |
(*env)->GetCharArrayRegion(env, jArray, 0, *ckpLength, jTemp); |
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
|
498 |
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
|
499 |
free(jTemp); |
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
|
500 |
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
|
501 |
} |
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
|
502 |
|
2 | 503 |
*ckpArray = (CK_UTF8CHAR_PTR) malloc (*ckpLength * sizeof(CK_UTF8CHAR)); |
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
|
504 |
if (*ckpArray == 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
|
505 |
free(jTemp); |
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
|
506 |
JNU_ThrowOutOfMemoryError(env, 0); |
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
|
507 |
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
|
508 |
} |
2 | 509 |
for (i=0; i<(*ckpLength); i++) { |
510 |
(*ckpArray)[i] = jCharToCKUTF8Char(jTemp[i]); |
|
511 |
} |
|
512 |
free(jTemp); |
|
513 |
} |
|
514 |
||
515 |
/* |
|
516 |
* converts a jstring to a CK_CHAR array. The allocated memory has to be freed after use! |
|
517 |
* |
|
518 |
* @param env - used to call JNI funktions to get the array informtaion |
|
519 |
* @param jArray - the Java array to convert |
|
520 |
* @param ckpArray - the reference, where the pointer to the new CK_CHAR array will be stored |
|
521 |
* @param ckpLength - the reference, where the array length will be stored |
|
522 |
*/ |
|
523 |
void jStringToCKUTF8CharArray(JNIEnv *env, const jstring jArray, CK_UTF8CHAR_PTR *ckpArray, CK_ULONG_PTR ckpLength) |
|
524 |
{ |
|
525 |
const char* pCharArray; |
|
526 |
jboolean isCopy; |
|
527 |
||
528 |
if(jArray == NULL) { |
|
529 |
*ckpArray = NULL_PTR; |
|
530 |
*ckpLength = 0L; |
|
531 |
return; |
|
532 |
} |
|
533 |
||
534 |
pCharArray = (*env)->GetStringUTFChars(env, jArray, &isCopy); |
|
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
|
535 |
if (pCharArray == 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
|
536 |
|
2 | 537 |
*ckpLength = strlen(pCharArray); |
538 |
*ckpArray = (CK_UTF8CHAR_PTR) malloc((*ckpLength + 1) * sizeof(CK_UTF8CHAR)); |
|
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
|
539 |
if (*ckpArray == 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
|
540 |
(*env)->ReleaseStringUTFChars(env, (jstring) jArray, pCharArray); |
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
|
541 |
JNU_ThrowOutOfMemoryError(env, 0); |
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
|
542 |
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
|
543 |
} |
2 | 544 |
strcpy((char*)*ckpArray, pCharArray); |
545 |
(*env)->ReleaseStringUTFChars(env, (jstring) jArray, pCharArray); |
|
546 |
} |
|
547 |
||
548 |
/* |
|
549 |
* converts a jobjectArray with Java Attributes to a CK_ATTRIBUTE array. The allocated memory |
|
550 |
* has to be freed after use! |
|
551 |
* |
|
552 |
* @param env - used to call JNI funktions to get the array informtaion |
|
553 |
* @param jArray - the Java Attribute array (template) to convert |
|
554 |
* @param ckpArray - the reference, where the pointer to the new CK_ATTRIBUTE array will be |
|
555 |
* stored |
|
556 |
* @param ckpLength - the reference, where the array length will be stored |
|
557 |
*/ |
|
558 |
void jAttributeArrayToCKAttributeArray(JNIEnv *env, jobjectArray jArray, CK_ATTRIBUTE_PTR *ckpArray, CK_ULONG_PTR ckpLength) |
|
559 |
{ |
|
560 |
CK_ULONG i; |
|
561 |
jlong jLength; |
|
562 |
jobject jAttribute; |
|
563 |
||
564 |
TRACE0("\nDEBUG: jAttributeArrayToCKAttributeArray"); |
|
565 |
if (jArray == NULL) { |
|
566 |
*ckpArray = NULL_PTR; |
|
567 |
*ckpLength = 0L; |
|
568 |
return; |
|
569 |
} |
|
570 |
jLength = (*env)->GetArrayLength(env, jArray); |
|
571 |
*ckpLength = jLongToCKULong(jLength); |
|
572 |
*ckpArray = (CK_ATTRIBUTE_PTR) malloc(*ckpLength * sizeof(CK_ATTRIBUTE)); |
|
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
|
573 |
if (*ckpArray == 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
|
574 |
JNU_ThrowOutOfMemoryError(env, 0); |
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
|
575 |
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
|
576 |
} |
2 | 577 |
TRACE1(", converting %d attibutes", jLength); |
578 |
for (i=0; i<(*ckpLength); i++) { |
|
579 |
TRACE1(", getting %d. attibute", i); |
|
580 |
jAttribute = (*env)->GetObjectArrayElement(env, jArray, i); |
|
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
|
581 |
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
|
582 |
freeCKAttributeArray(*ckpArray, i); |
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
|
583 |
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
|
584 |
} |
2 | 585 |
TRACE1(", jAttribute = %d", jAttribute); |
586 |
TRACE1(", converting %d. attibute", i); |
|
587 |
(*ckpArray)[i] = jAttributeToCKAttribute(env, jAttribute); |
|
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
|
588 |
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
|
589 |
freeCKAttributeArray(*ckpArray, i); |
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 |
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 |
} |
593 |
TRACE0("FINISHED\n"); |
|
594 |
} |
|
595 |
||
596 |
/* |
|
597 |
* converts a CK_BYTE array and its length to a jbyteArray. |
|
598 |
* |
|
599 |
* @param env - used to call JNI funktions to create the new Java array |
|
600 |
* @param ckpArray - the pointer to the CK_BYTE array to convert |
|
601 |
* @param ckpLength - the length of the array to convert |
|
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
|
602 |
* @return - the new Java byte array or NULL if error occurred |
2 | 603 |
*/ |
604 |
jbyteArray ckByteArrayToJByteArray(JNIEnv *env, const CK_BYTE_PTR ckpArray, CK_ULONG ckLength) |
|
605 |
{ |
|
606 |
CK_ULONG i; |
|
607 |
jbyte* jpTemp; |
|
608 |
jbyteArray jArray; |
|
609 |
||
610 |
/* if CK_BYTE is the same size as jbyte, we save an additional copy */ |
|
611 |
if (sizeof(CK_BYTE) == sizeof(jbyte)) { |
|
612 |
jpTemp = (jbyte*) ckpArray; |
|
613 |
} else { |
|
614 |
jpTemp = (jbyte*) malloc((ckLength) * sizeof(jbyte)); |
|
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
|
615 |
if (jpTemp == 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
|
616 |
JNU_ThrowOutOfMemoryError(env, 0); |
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
|
617 |
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
|
618 |
} |
2 | 619 |
for (i=0; i<ckLength; i++) { |
620 |
jpTemp[i] = ckByteToJByte(ckpArray[i]); |
|
621 |
} |
|
622 |
} |
|
623 |
||
624 |
jArray = (*env)->NewByteArray(env, ckULongToJSize(ckLength)); |
|
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
|
625 |
if (jArray != 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
|
626 |
(*env)->SetByteArrayRegion(env, jArray, 0, ckULongToJSize(ckLength), jpTemp); |
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 |
} |
2 | 628 |
|
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
|
629 |
if (sizeof(CK_BYTE) != sizeof(jbyte)) { free(jpTemp); } |
2 | 630 |
|
631 |
return jArray ; |
|
632 |
} |
|
633 |
||
634 |
/* |
|
635 |
* converts a CK_ULONG array and its length to a jlongArray. |
|
636 |
* |
|
637 |
* @param env - used to call JNI funktions to create the new Java array |
|
638 |
* @param ckpArray - the pointer to the CK_ULONG array to convert |
|
639 |
* @param ckpLength - the length of the array to convert |
|
640 |
* @return - the new Java long array |
|
641 |
*/ |
|
642 |
jlongArray ckULongArrayToJLongArray(JNIEnv *env, const CK_ULONG_PTR ckpArray, CK_ULONG ckLength) |
|
643 |
{ |
|
644 |
CK_ULONG i; |
|
645 |
jlong* jpTemp; |
|
646 |
jlongArray jArray; |
|
647 |
||
648 |
jpTemp = (jlong*) malloc((ckLength) * sizeof(jlong)); |
|
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
|
649 |
if (jpTemp == 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
|
650 |
JNU_ThrowOutOfMemoryError(env, 0); |
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
|
651 |
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
|
652 |
} |
2 | 653 |
for (i=0; i<ckLength; i++) { |
654 |
jpTemp[i] = ckLongToJLong(ckpArray[i]); |
|
655 |
} |
|
656 |
jArray = (*env)->NewLongArray(env, ckULongToJSize(ckLength)); |
|
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
|
657 |
if (jArray != 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
|
658 |
(*env)->SetLongArrayRegion(env, jArray, 0, ckULongToJSize(ckLength), jpTemp); |
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
|
659 |
} |
2 | 660 |
free(jpTemp); |
661 |
||
662 |
return jArray ; |
|
663 |
} |
|
664 |
||
665 |
/* |
|
666 |
* converts a CK_CHAR array and its length to a jcharArray. |
|
667 |
* |
|
668 |
* @param env - used to call JNI funktions to create the new Java array |
|
669 |
* @param ckpArray - the pointer to the CK_CHAR array to convert |
|
670 |
* @param ckpLength - the length of the array to convert |
|
671 |
* @return - the new Java char array |
|
672 |
*/ |
|
673 |
jcharArray ckCharArrayToJCharArray(JNIEnv *env, const CK_CHAR_PTR ckpArray, CK_ULONG ckLength) |
|
674 |
{ |
|
675 |
CK_ULONG i; |
|
676 |
jchar* jpTemp; |
|
677 |
jcharArray jArray; |
|
678 |
||
679 |
jpTemp = (jchar*) malloc(ckLength * sizeof(jchar)); |
|
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
|
680 |
if (jpTemp == 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
|
681 |
JNU_ThrowOutOfMemoryError(env, 0); |
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 |
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
|
683 |
} |
2 | 684 |
for (i=0; i<ckLength; i++) { |
685 |
jpTemp[i] = ckCharToJChar(ckpArray[i]); |
|
686 |
} |
|
687 |
jArray = (*env)->NewCharArray(env, ckULongToJSize(ckLength)); |
|
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
|
688 |
if (jArray != 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
|
689 |
(*env)->SetCharArrayRegion(env, jArray, 0, ckULongToJSize(ckLength), jpTemp); |
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
|
690 |
} |
2 | 691 |
free(jpTemp); |
692 |
||
693 |
return jArray ; |
|
694 |
} |
|
695 |
||
696 |
/* |
|
697 |
* converts a CK_UTF8CHAR array and its length to a jcharArray. |
|
698 |
* |
|
699 |
* @param env - used to call JNI funktions to create the new Java array |
|
700 |
* @param ckpArray - the pointer to the CK_UTF8CHAR array to convert |
|
701 |
* @param ckpLength - the length of the array to convert |
|
702 |
* @return - the new Java char array |
|
703 |
*/ |
|
704 |
jcharArray ckUTF8CharArrayToJCharArray(JNIEnv *env, const CK_UTF8CHAR_PTR ckpArray, CK_ULONG ckLength) |
|
705 |
{ |
|
706 |
CK_ULONG i; |
|
707 |
jchar* jpTemp; |
|
708 |
jcharArray jArray; |
|
709 |
||
710 |
jpTemp = (jchar*) malloc(ckLength * sizeof(jchar)); |
|
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 (jpTemp == 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
|
712 |
JNU_ThrowOutOfMemoryError(env, 0); |
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
|
713 |
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
|
714 |
} |
2 | 715 |
for (i=0; i<ckLength; i++) { |
716 |
jpTemp[i] = ckUTF8CharToJChar(ckpArray[i]); |
|
717 |
} |
|
718 |
jArray = (*env)->NewCharArray(env, ckULongToJSize(ckLength)); |
|
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 |
if (jArray != 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
|
720 |
(*env)->SetCharArrayRegion(env, jArray, 0, ckULongToJSize(ckLength), jpTemp); |
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
|
721 |
} |
2 | 722 |
free(jpTemp); |
723 |
||
724 |
return jArray ; |
|
725 |
} |
|
726 |
||
727 |
/* |
|
728 |
* the following functions convert Java objects to PKCS#11 pointers and the |
|
729 |
* length in bytes and vice versa |
|
730 |
* |
|
731 |
* CK_<Type>_PTR j<Object>ToCK<Type>Ptr(JNIEnv *env, jobject jObject); |
|
732 |
* |
|
733 |
* jobject ck<Type>PtrToJ<Object>(JNIEnv *env, const CK_<Type>_PTR ckpValue); |
|
734 |
* |
|
735 |
* The functions that convert a Java object to a PKCS#11 pointer first allocate |
|
736 |
* the memory for the PKCS#11 pointer. Then they set each element corresponding |
|
737 |
* to the fields in the Java object to convert. After use the allocated memory of |
|
738 |
* the PKCS#11 pointer has to be explicitly freed. |
|
739 |
* |
|
740 |
* The functions to convert a PKCS#11 pointer to a Java object create a new Java |
|
741 |
* object first and than they set all fields in the object depending on the values |
|
742 |
* of the type or structure where the PKCS#11 pointer points to. |
|
743 |
*/ |
|
744 |
||
745 |
/* |
|
746 |
* converts a CK_BBOOL pointer to a Java boolean Object. |
|
747 |
* |
|
748 |
* @param env - used to call JNI funktions to create the new Java object |
|
749 |
* @param ckpValue - the pointer to the CK_BBOOL value |
|
750 |
* @return - the new Java boolean object with the boolean value |
|
751 |
*/ |
|
752 |
jobject ckBBoolPtrToJBooleanObject(JNIEnv *env, const CK_BBOOL *ckpValue) |
|
753 |
{ |
|
754 |
jclass jValueObjectClass; |
|
755 |
jmethodID jConstructor; |
|
756 |
jobject jValueObject; |
|
757 |
jboolean jValue; |
|
758 |
||
759 |
jValueObjectClass = (*env)->FindClass(env, "java/lang/Boolean"); |
|
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
|
760 |
if (jValueObjectClass == NULL) { return NULL; } |
2 | 761 |
jConstructor = (*env)->GetMethodID(env, jValueObjectClass, "<init>", "(Z)V"); |
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
|
762 |
if (jConstructor == NULL) { return NULL; } |
2 | 763 |
jValue = ckBBoolToJBoolean(*ckpValue); |
764 |
jValueObject = (*env)->NewObject(env, jValueObjectClass, jConstructor, jValue); |
|
765 |
||
766 |
return jValueObject ; |
|
767 |
} |
|
768 |
||
769 |
/* |
|
770 |
* converts a CK_ULONG pointer to a Java long Object. |
|
771 |
* |
|
772 |
* @param env - used to call JNI funktions to create the new Java object |
|
773 |
* @param ckpValue - the pointer to the CK_ULONG value |
|
774 |
* @return - the new Java long object with the long value |
|
775 |
*/ |
|
776 |
jobject ckULongPtrToJLongObject(JNIEnv *env, const CK_ULONG_PTR ckpValue) |
|
777 |
{ |
|
778 |
jclass jValueObjectClass; |
|
779 |
jmethodID jConstructor; |
|
780 |
jobject jValueObject; |
|
781 |
jlong jValue; |
|
782 |
||
783 |
jValueObjectClass = (*env)->FindClass(env, "java/lang/Long"); |
|
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
|
784 |
if (jValueObjectClass == NULL) { return NULL; } |
2 | 785 |
jConstructor = (*env)->GetMethodID(env, jValueObjectClass, "<init>", "(J)V"); |
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
|
786 |
if (jConstructor == NULL) { return NULL; } |
2 | 787 |
jValue = ckULongToJLong(*ckpValue); |
788 |
jValueObject = (*env)->NewObject(env, jValueObjectClass, jConstructor, jValue); |
|
789 |
||
790 |
return jValueObject ; |
|
791 |
} |
|
792 |
||
793 |
/* |
|
794 |
* converts a Java boolean object into a pointer to a CK_BBOOL value. The memory has to be |
|
795 |
* freed after use! |
|
796 |
* |
|
797 |
* @param env - used to call JNI funktions to get the value out of the Java object |
|
798 |
* @param jObject - the "java/lang/Boolean" object to convert |
|
799 |
* @return - the pointer to the new CK_BBOOL value |
|
800 |
*/ |
|
801 |
CK_BBOOL* jBooleanObjectToCKBBoolPtr(JNIEnv *env, jobject jObject) |
|
802 |
{ |
|
803 |
jclass jObjectClass; |
|
804 |
jmethodID jValueMethod; |
|
805 |
jboolean jValue; |
|
806 |
CK_BBOOL *ckpValue; |
|
807 |
||
808 |
jObjectClass = (*env)->FindClass(env, "java/lang/Boolean"); |
|
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
|
809 |
if (jObjectClass == NULL) { return NULL; } |
2 | 810 |
jValueMethod = (*env)->GetMethodID(env, jObjectClass, "booleanValue", "()Z"); |
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
|
811 |
if (jValueMethod == NULL) { return NULL; } |
2 | 812 |
jValue = (*env)->CallBooleanMethod(env, jObject, jValueMethod); |
813 |
ckpValue = (CK_BBOOL *) malloc(sizeof(CK_BBOOL)); |
|
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
|
814 |
if (ckpValue == 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
|
815 |
JNU_ThrowOutOfMemoryError(env, 0); |
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
|
816 |
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
|
817 |
} |
2 | 818 |
*ckpValue = jBooleanToCKBBool(jValue); |
819 |
||
820 |
return ckpValue ; |
|
821 |
} |
|
822 |
||
823 |
/* |
|
824 |
* converts a Java byte object into a pointer to a CK_BYTE value. The memory has to be |
|
825 |
* freed after use! |
|
826 |
* |
|
827 |
* @param env - used to call JNI funktions to get the value out of the Java object |
|
828 |
* @param jObject - the "java/lang/Byte" object to convert |
|
829 |
* @return - the pointer to the new CK_BYTE value |
|
830 |
*/ |
|
831 |
CK_BYTE_PTR jByteObjectToCKBytePtr(JNIEnv *env, jobject jObject) |
|
832 |
{ |
|
833 |
jclass jObjectClass; |
|
834 |
jmethodID jValueMethod; |
|
835 |
jbyte jValue; |
|
836 |
CK_BYTE_PTR ckpValue; |
|
837 |
||
838 |
jObjectClass = (*env)->FindClass(env, "java/lang/Byte"); |
|
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
|
839 |
if (jObjectClass == NULL) { return NULL; } |
2 | 840 |
jValueMethod = (*env)->GetMethodID(env, jObjectClass, "byteValue", "()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
|
841 |
if (jValueMethod == NULL) { return NULL; } |
2 | 842 |
jValue = (*env)->CallByteMethod(env, jObject, jValueMethod); |
843 |
ckpValue = (CK_BYTE_PTR) malloc(sizeof(CK_BYTE)); |
|
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
|
844 |
if (ckpValue == 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
|
845 |
JNU_ThrowOutOfMemoryError(env, 0); |
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
|
846 |
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
|
847 |
} |
2 | 848 |
*ckpValue = jByteToCKByte(jValue); |
849 |
return ckpValue ; |
|
850 |
} |
|
851 |
||
852 |
/* |
|
853 |
* converts a Java integer object into a pointer to a CK_ULONG value. The memory has to be |
|
854 |
* freed after use! |
|
855 |
* |
|
856 |
* @param env - used to call JNI funktions to get the value out of the Java object |
|
857 |
* @param jObject - the "java/lang/Integer" object to convert |
|
858 |
* @return - the pointer to the new CK_ULONG value |
|
859 |
*/ |
|
860 |
CK_ULONG* jIntegerObjectToCKULongPtr(JNIEnv *env, jobject jObject) |
|
861 |
{ |
|
862 |
jclass jObjectClass; |
|
863 |
jmethodID jValueMethod; |
|
864 |
jint jValue; |
|
865 |
CK_ULONG *ckpValue; |
|
866 |
||
867 |
jObjectClass = (*env)->FindClass(env, "java/lang/Integer"); |
|
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
|
868 |
if (jObjectClass == NULL) { return NULL; } |
2 | 869 |
jValueMethod = (*env)->GetMethodID(env, jObjectClass, "intValue", "()I"); |
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
|
870 |
if (jValueMethod == NULL) { return NULL; } |
2 | 871 |
jValue = (*env)->CallIntMethod(env, jObject, jValueMethod); |
872 |
ckpValue = (CK_ULONG *) malloc(sizeof(CK_ULONG)); |
|
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
|
873 |
if (ckpValue == 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
|
874 |
JNU_ThrowOutOfMemoryError(env, 0); |
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
|
875 |
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
|
876 |
} |
2 | 877 |
*ckpValue = jLongToCKLong(jValue); |
878 |
return ckpValue ; |
|
879 |
} |
|
880 |
||
881 |
/* |
|
882 |
* converts a Java long object into a pointer to a CK_ULONG value. The memory has to be |
|
883 |
* freed after use! |
|
884 |
* |
|
885 |
* @param env - used to call JNI funktions to get the value out of the Java object |
|
886 |
* @param jObject - the "java/lang/Long" object to convert |
|
887 |
* @return - the pointer to the new CK_ULONG value |
|
888 |
*/ |
|
889 |
CK_ULONG* jLongObjectToCKULongPtr(JNIEnv *env, jobject jObject) |
|
890 |
{ |
|
891 |
jclass jObjectClass; |
|
892 |
jmethodID jValueMethod; |
|
893 |
jlong jValue; |
|
894 |
CK_ULONG *ckpValue; |
|
895 |
||
896 |
jObjectClass = (*env)->FindClass(env, "java/lang/Long"); |
|
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
|
897 |
if (jObjectClass == NULL) { return NULL; } |
2 | 898 |
jValueMethod = (*env)->GetMethodID(env, jObjectClass, "longValue", "()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
|
899 |
if (jValueMethod == NULL) { return NULL; } |
2 | 900 |
jValue = (*env)->CallLongMethod(env, jObject, jValueMethod); |
901 |
ckpValue = (CK_ULONG *) malloc(sizeof(CK_ULONG)); |
|
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
|
902 |
if (ckpValue == 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
|
903 |
JNU_ThrowOutOfMemoryError(env, 0); |
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
|
904 |
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
|
905 |
} |
2 | 906 |
*ckpValue = jLongToCKULong(jValue); |
907 |
||
908 |
return ckpValue ; |
|
909 |
} |
|
910 |
||
911 |
/* |
|
912 |
* converts a Java char object into a pointer to a CK_CHAR value. The memory has to be |
|
913 |
* freed after use! |
|
914 |
* |
|
915 |
* @param env - used to call JNI funktions to get the value out of the Java object |
|
916 |
* @param jObject - the "java/lang/Char" object to convert |
|
917 |
* @return - the pointer to the new CK_CHAR value |
|
918 |
*/ |
|
919 |
CK_CHAR_PTR jCharObjectToCKCharPtr(JNIEnv *env, jobject jObject) |
|
920 |
{ |
|
921 |
jclass jObjectClass; |
|
922 |
jmethodID jValueMethod; |
|
923 |
jchar jValue; |
|
924 |
CK_CHAR_PTR ckpValue; |
|
925 |
||
926 |
jObjectClass = (*env)->FindClass(env, "java/lang/Char"); |
|
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
|
927 |
if (jObjectClass == NULL) { return NULL; } |
2 | 928 |
jValueMethod = (*env)->GetMethodID(env, jObjectClass, "charValue", "()C"); |
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
|
929 |
if (jValueMethod == NULL) { return NULL; } |
2 | 930 |
jValue = (*env)->CallCharMethod(env, jObject, jValueMethod); |
931 |
ckpValue = (CK_CHAR_PTR) malloc(sizeof(CK_CHAR)); |
|
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
|
932 |
if (ckpValue == 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
|
933 |
JNU_ThrowOutOfMemoryError(env, 0); |
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
|
934 |
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
|
935 |
} |
2 | 936 |
*ckpValue = jCharToCKChar(jValue); |
937 |
||
938 |
return ckpValue ; |
|
939 |
} |
|
940 |
||
941 |
/* |
|
942 |
* converts a Java object into a pointer to CK-type or a CK-structure with the length in Bytes. |
|
943 |
* The memory of *ckpObjectPtr to be freed after use! This function is only used by |
|
944 |
* jAttributeToCKAttribute by now. |
|
945 |
* |
|
946 |
* @param env - used to call JNI funktions to get the Java classes and objects |
|
947 |
* @param jObject - the Java object to convert |
|
948 |
* @param ckpObjectPtr - the reference of the new pointer to the new CK-value or CK-structure |
|
949 |
* @param ckpLength - the reference of the length in bytes of the new CK-value or CK-structure |
|
950 |
*/ |
|
951 |
void jObjectToPrimitiveCKObjectPtrPtr(JNIEnv *env, jobject jObject, CK_VOID_PTR *ckpObjectPtr, CK_ULONG *ckpLength) |
|
952 |
{ |
|
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
|
953 |
jclass jLongClass, jBooleanClass, jByteArrayClass, jCharArrayClass; |
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
|
954 |
jclass jByteClass, jDateClass, jCharacterClass, jIntegerClass; |
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
|
955 |
jclass jBooleanArrayClass, jIntArrayClass, jLongArrayClass; |
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
|
956 |
jclass jStringClass; |
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
|
957 |
jclass jObjectClass, jClassClass; |
2 | 958 |
CK_VOID_PTR ckpVoid = *ckpObjectPtr; |
959 |
jmethodID jMethod; |
|
960 |
jobject jClassObject; |
|
961 |
jstring jClassNameString; |
|
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
|
962 |
char *classNameString, *exceptionMsgPrefix, *exceptionMsg; |
2 | 963 |
|
964 |
TRACE0("\nDEBUG: jObjectToPrimitiveCKObjectPtrPtr"); |
|
965 |
if (jObject == NULL) { |
|
966 |
*ckpObjectPtr = NULL; |
|
967 |
*ckpLength = 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
|
968 |
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
|
969 |
} |
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
|
970 |
|
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
|
971 |
jLongClass = (*env)->FindClass(env, "java/lang/Long"); |
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
|
972 |
if (jLongClass == 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
|
973 |
if ((*env)->IsInstanceOf(env, jObject, jLongClass)) { |
2 | 974 |
*ckpObjectPtr = jLongObjectToCKULongPtr(env, jObject); |
975 |
*ckpLength = sizeof(CK_ULONG); |
|
976 |
TRACE1("<converted long value %X>", *((CK_ULONG *) *ckpObjectPtr)); |
|
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
|
977 |
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
|
978 |
} |
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
|
979 |
|
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
|
980 |
jBooleanClass = (*env)->FindClass(env, "java/lang/Boolean"); |
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
|
981 |
if (jBooleanClass == 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
|
982 |
if ((*env)->IsInstanceOf(env, jObject, jBooleanClass)) { |
2 | 983 |
*ckpObjectPtr = jBooleanObjectToCKBBoolPtr(env, jObject); |
984 |
*ckpLength = sizeof(CK_BBOOL); |
|
985 |
TRACE0(" <converted boolean value "); |
|
986 |
TRACE0((*((CK_BBOOL *) *ckpObjectPtr) == TRUE) ? "TRUE>" : "FALSE>"); |
|
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
|
987 |
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
|
988 |
} |
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
|
989 |
|
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
|
990 |
jByteArrayClass = (*env)->FindClass(env, "[B"); |
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
|
991 |
if (jByteArrayClass == 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
|
992 |
if ((*env)->IsInstanceOf(env, jObject, jByteArrayClass)) { |
2 | 993 |
jByteArrayToCKByteArray(env, jObject, (CK_BYTE_PTR*)ckpObjectPtr, ckpLength); |
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
|
994 |
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
|
995 |
} |
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
|
996 |
|
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
|
997 |
jCharArrayClass = (*env)->FindClass(env, "[C"); |
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
|
998 |
if (jCharArrayClass == 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
|
999 |
if ((*env)->IsInstanceOf(env, jObject, jCharArrayClass)) { |
2 | 1000 |
jCharArrayToCKUTF8CharArray(env, jObject, (CK_UTF8CHAR_PTR*)ckpObjectPtr, ckpLength); |
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
|
1001 |
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
|
1002 |
} |
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
|
1003 |
|
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
|
1004 |
jByteClass = (*env)->FindClass(env, "java/lang/Byte"); |
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
|
1005 |
if (jByteClass == 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
|
1006 |
if ((*env)->IsInstanceOf(env, jObject, jByteClass)) { |
2 | 1007 |
*ckpObjectPtr = jByteObjectToCKBytePtr(env, jObject); |
1008 |
*ckpLength = sizeof(CK_BYTE); |
|
1009 |
TRACE1("<converted byte value %X>", *((CK_BYTE *) *ckpObjectPtr)); |
|
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
|
1010 |
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
|
1011 |
} |
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
|
1012 |
|
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
|
1013 |
jDateClass = (*env)->FindClass(env, CLASS_DATE); |
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
|
1014 |
if (jDateClass == 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
|
1015 |
if ((*env)->IsInstanceOf(env, jObject, jDateClass)) { |
2 | 1016 |
*ckpObjectPtr = jDateObjectPtrToCKDatePtr(env, jObject); |
1017 |
*ckpLength = sizeof(CK_DATE); |
|
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
|
1018 |
TRACE3("<converted date value %.4s-%.2s-%.2s>", (*((CK_DATE *) *ckpObjectPtr)).year, (*((CK_DATE *) *ckpObjectPtr)).month, (*((CK_DATE *) *ckpObjectPtr)).day); |
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
|
1019 |
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
|
1020 |
} |
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
|
1021 |
|
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
|
1022 |
jCharacterClass = (*env)->FindClass(env, "java/lang/Character"); |
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
|
1023 |
if (jCharacterClass == 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
|
1024 |
if ((*env)->IsInstanceOf(env, jObject, jCharacterClass)) { |
2 | 1025 |
*ckpObjectPtr = jCharObjectToCKCharPtr(env, jObject); |
1026 |
*ckpLength = sizeof(CK_UTF8CHAR); |
|
1027 |
TRACE1("<converted char value %c>", *((CK_CHAR *) *ckpObjectPtr)); |
|
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
|
1028 |
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
|
1029 |
} |
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
|
1030 |
|
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
|
1031 |
jIntegerClass = (*env)->FindClass(env, "java/lang/Integer"); |
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
|
1032 |
if (jIntegerClass == 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
|
1033 |
if ((*env)->IsInstanceOf(env, jObject, jIntegerClass)) { |
2 | 1034 |
*ckpObjectPtr = jIntegerObjectToCKULongPtr(env, jObject); |
1035 |
*ckpLength = sizeof(CK_ULONG); |
|
1036 |
TRACE1("<converted integer value %X>", *((CK_ULONG *) *ckpObjectPtr)); |
|
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
|
1037 |
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
|
1038 |
} |
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
|
1039 |
|
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
|
1040 |
jBooleanArrayClass = (*env)->FindClass(env, "[Z"); |
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
|
1041 |
if (jBooleanArrayClass == 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
|
1042 |
if ((*env)->IsInstanceOf(env, jObject, jBooleanArrayClass)) { |
2 | 1043 |
jBooleanArrayToCKBBoolArray(env, jObject, (CK_BBOOL**)ckpObjectPtr, ckpLength); |
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
|
1044 |
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
|
1045 |
} |
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
|
1046 |
|
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
|
1047 |
jIntArrayClass = (*env)->FindClass(env, "[I"); |
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
|
1048 |
if (jIntArrayClass == 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
|
1049 |
if ((*env)->IsInstanceOf(env, jObject, jIntArrayClass)) { |
2 | 1050 |
jLongArrayToCKULongArray(env, jObject, (CK_ULONG_PTR*)ckpObjectPtr, ckpLength); |
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
|
1051 |
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
|
1052 |
} |
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
|
1053 |
|
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
|
1054 |
jLongArrayClass = (*env)->FindClass(env, "[J"); |
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
|
1055 |
if (jLongArrayClass == 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
|
1056 |
if ((*env)->IsInstanceOf(env, jObject, jLongArrayClass)) { |
2 | 1057 |
jLongArrayToCKULongArray(env, jObject, (CK_ULONG_PTR*)ckpObjectPtr, ckpLength); |
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
|
1058 |
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
|
1059 |
} |
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
|
1060 |
|
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
|
1061 |
jStringClass = (*env)->FindClass(env, "java/lang/String"); |
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
|
1062 |
if (jStringClass == 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
|
1063 |
if ((*env)->IsInstanceOf(env, jObject, jStringClass)) { |
2 | 1064 |
jStringToCKUTF8CharArray(env, jObject, (CK_UTF8CHAR_PTR*)ckpObjectPtr, ckpLength); |
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
|
1065 |
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
|
1066 |
} |
2 | 1067 |
|
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
|
1068 |
/* type of jObject unknown, throw PKCS11RuntimeException */ |
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
|
1069 |
jObjectClass = (*env)->FindClass(env, "java/lang/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
|
1070 |
if (jObjectClass == 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
|
1071 |
jMethod = (*env)->GetMethodID(env, jObjectClass, "getClass", "()Ljava/lang/Class;"); |
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
|
1072 |
if (jMethod == 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
|
1073 |
jClassObject = (*env)->CallObjectMethod(env, jObject, jMethod); |
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
|
1074 |
assert(jClassObject != 0); |
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
|
1075 |
jClassClass = (*env)->FindClass(env, "java/lang/Class"); |
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
|
1076 |
if (jClassClass == 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
|
1077 |
jMethod = (*env)->GetMethodID(env, jClassClass, "getName", "()Ljava/lang/String;"); |
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
|
1078 |
if (jMethod == 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
|
1079 |
jClassNameString = (jstring) |
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
|
1080 |
(*env)->CallObjectMethod(env, jClassObject, jMethod); |
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
|
1081 |
assert(jClassNameString != 0); |
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
|
1082 |
classNameString = (char*) |
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
|
1083 |
(*env)->GetStringUTFChars(env, jClassNameString, 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
|
1084 |
if (classNameString == 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
|
1085 |
exceptionMsgPrefix = "Java object of this class cannot be converted to native PKCS#11 type: "; |
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
|
1086 |
exceptionMsg = (char *) |
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
|
1087 |
malloc((strlen(exceptionMsgPrefix) + strlen(classNameString) + 1)); |
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
|
1088 |
if (exceptionMsg == 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
|
1089 |
(*env)->ReleaseStringUTFChars(env, jClassNameString, classNameString); |
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
|
1090 |
JNU_ThrowOutOfMemoryError(env, 0); |
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
|
1091 |
return; |
2 | 1092 |
} |
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
|
1093 |
strcpy(exceptionMsg, exceptionMsgPrefix); |
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
|
1094 |
strcat(exceptionMsg, classNameString); |
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
|
1095 |
(*env)->ReleaseStringUTFChars(env, jClassNameString, classNameString); |
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
|
1096 |
throwPKCS11RuntimeException(env, exceptionMsg); |
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
|
1097 |
free(exceptionMsg); |
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
|
1098 |
*ckpObjectPtr = 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
|
1099 |
*ckpLength = 0; |
2 | 1100 |
|
1101 |
TRACE0("FINISHED\n"); |
|
1102 |
} |
|
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
|
1103 |
|
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
|
1104 |
#ifdef P11_MEMORYDEBUG |
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
|
1105 |
|
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
|
1106 |
#undef malloc |
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
|
1107 |
#undef free |
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
|
1108 |
|
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
|
1109 |
void *p11malloc(size_t c, char *file, int line) { |
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
|
1110 |
void *p = malloc(c); |
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
|
1111 |
printf("malloc\t%08x\t%d\t%s:%d\n", p, c, file, line); fflush(stdout); |
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
|
1112 |
return p; |
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
|
1113 |
} |
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
|
1114 |
|
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
|
1115 |
void p11free(void *p, char *file, int line) { |
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
|
1116 |
printf("free\t%08x\t\t%s:%d\n", p, file, line); fflush(stdout); |
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
|
1117 |
free(p); |
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
|
1118 |
} |
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
|
1119 |
|
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
|
1120 |
#endif |
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
|
1121 |