author | valeriep |
Tue, 03 Mar 2009 19:50:59 -0800 | |
changeset 2180 | 9994f4f08a59 |
parent 2 | 90ce3da70b43 |
child 3321 | fed33393bc52 |
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; |
|
197 |
jlong jErrorCode; |
|
198 |
||
199 |
if (returnValue == CKR_OK) { |
|
200 |
return 0L ; |
|
201 |
} else { |
|
202 |
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
|
203 |
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
|
204 |
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
|
205 |
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
|
206 |
jErrorCode = ckULongToJLong(returnValue); |
9994f4f08a59
6812738: SSL 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 |
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
|
208 |
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
|
209 |
(*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
|
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 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
212 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
213 |
(*env)->DeleteLocalRef(env, jPKCS11ExceptionClass); |
2 | 214 |
return jErrorCode ; |
215 |
} |
|
216 |
} |
|
217 |
||
218 |
/* |
|
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
|
219 |
* This function simply throws an IOException |
2 | 220 |
* |
221 |
* @param env Used to call JNI funktions and to get the Exception class. |
|
222 |
* @param message The message string of the Exception object. |
|
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 |
void throwIOException(JNIEnv *env, const char *message) |
2 | 225 |
{ |
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
|
226 |
JNU_ThrowByName(env, CLASS_IO_EXCEPTION, message); |
2 | 227 |
} |
228 |
||
229 |
/* |
|
230 |
* This function simply throws a PKCS#11RuntimeException with the given |
|
231 |
* string as its message. If the message is NULL, the exception is created |
|
232 |
* using the default constructor. |
|
233 |
* |
|
234 |
* @param env Used to call JNI funktions and to get the Exception class. |
|
235 |
* @param jmessage The message string of the Exception object. |
|
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 |
void throwPKCS11RuntimeException(JNIEnv *env, const char *message) |
2 | 238 |
{ |
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
|
239 |
JNU_ThrowByName(env, CLASS_PKCS11RUNTIMEEXCEPTION, message); |
2 | 240 |
} |
241 |
||
242 |
/* |
|
243 |
* This function simply throws a PKCS#11RuntimeException. The message says that |
|
244 |
* the object is not connected to the module. |
|
245 |
* |
|
246 |
* @param env Used to call JNI funktions and to get the Exception class. |
|
247 |
*/ |
|
248 |
void throwDisconnectedRuntimeException(JNIEnv *env) |
|
249 |
{ |
|
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
|
250 |
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
|
251 |
} |
2 | 252 |
|
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
|
253 |
/* 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
|
254 |
* |
9994f4f08a59
6812738: SSL 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 |
* @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
|
256 |
* @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
|
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 |
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
|
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 |
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
|
261 |
|
9994f4f08a59
6812738: SSL 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 |
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
|
263 |
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
|
264 |
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
|
265 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
266 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
267 |
free(attrPtr); |
2 | 268 |
} |
269 |
||
270 |
/* |
|
271 |
* the following functions convert Java arrays to PKCS#11 array pointers and |
|
272 |
* their array length and vice versa |
|
273 |
* |
|
274 |
* void j<Type>ArrayToCK<Type>Array(JNIEnv *env, |
|
275 |
* const j<Type>Array jArray, |
|
276 |
* CK_<Type>_PTR *ckpArray, |
|
277 |
* CK_ULONG_PTR ckLength); |
|
278 |
* |
|
279 |
* j<Type>Array ck<Type>ArrayToJ<Type>Array(JNIEnv *env, |
|
280 |
* const CK_<Type>_PTR ckpArray, |
|
281 |
* CK_ULONG ckLength); |
|
282 |
* |
|
283 |
* PKCS#11 arrays consist always of a pointer to the beginning of the array and |
|
284 |
* the array length whereas Java arrays carry their array length. |
|
285 |
* |
|
286 |
* The Functions to convert a Java array to a PKCS#11 array are void functions. |
|
287 |
* Their arguments are the Java array object to convert, the reference to the |
|
288 |
* array pointer, where the new PKCS#11 array should be stored and the reference |
|
289 |
* to the array length where the PKCS#11 array length should be stored. These two |
|
290 |
* references must not be NULL_PTR. |
|
291 |
* |
|
292 |
* The functions first obtain the array length of the Java array and then allocate |
|
293 |
* the memory for the PKCS#11 array and set the array length. Then each element |
|
294 |
* gets converted depending on their type. After use the allocated memory of the |
|
295 |
* PKCS#11 array has to be explicitly freed. |
|
296 |
* |
|
297 |
* The Functions to convert a PKCS#11 array to a Java array get the PKCS#11 array |
|
298 |
* pointer and the array length and they return the new Java array object. The |
|
299 |
* Java array does not need to get freed after use. |
|
300 |
*/ |
|
301 |
||
302 |
/* |
|
303 |
* converts a jbooleanArray to a CK_BBOOL array. The allocated memory has to be freed after use! |
|
304 |
* |
|
305 |
* @param env - used to call JNI funktions to get the array informtaion |
|
306 |
* @param jArray - the Java array to convert |
|
307 |
* @param ckpArray - the reference, where the pointer to the new CK_BBOOL array will be stored |
|
308 |
* @param ckpLength - the reference, where the array length will be stored |
|
309 |
*/ |
|
310 |
void jBooleanArrayToCKBBoolArray(JNIEnv *env, const jbooleanArray jArray, CK_BBOOL **ckpArray, CK_ULONG_PTR ckpLength) |
|
311 |
{ |
|
312 |
jboolean* jpTemp; |
|
313 |
CK_ULONG i; |
|
314 |
||
315 |
if(jArray == NULL) { |
|
316 |
*ckpArray = NULL_PTR; |
|
317 |
*ckpLength = 0L; |
|
318 |
return; |
|
319 |
} |
|
320 |
*ckpLength = (*env)->GetArrayLength(env, jArray); |
|
321 |
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
|
322 |
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
|
323 |
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
|
324 |
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
|
325 |
} |
2 | 326 |
(*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
|
327 |
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
|
328 |
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
|
329 |
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
|
330 |
} |
9994f4f08a59
6812738: SSL 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 |
|
2 | 332 |
*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
|
333 |
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
|
334 |
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
|
335 |
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
|
336 |
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
|
337 |
} |
2 | 338 |
for (i=0; i<(*ckpLength); i++) { |
339 |
(*ckpArray)[i] = jBooleanToCKBBool(jpTemp[i]); |
|
340 |
} |
|
341 |
free(jpTemp); |
|
342 |
} |
|
343 |
||
344 |
/* |
|
345 |
* converts a jbyteArray to a CK_BYTE array. The allocated memory has to be freed after use! |
|
346 |
* |
|
347 |
* @param env - used to call JNI funktions to get the array informtaion |
|
348 |
* @param jArray - the Java array to convert |
|
349 |
* @param ckpArray - the reference, where the pointer to the new CK_BYTE array will be stored |
|
350 |
* @param ckpLength - the reference, where the array length will be stored |
|
351 |
*/ |
|
352 |
void jByteArrayToCKByteArray(JNIEnv *env, const jbyteArray jArray, CK_BYTE_PTR *ckpArray, CK_ULONG_PTR ckpLength) |
|
353 |
{ |
|
354 |
jbyte* jpTemp; |
|
355 |
CK_ULONG i; |
|
356 |
||
357 |
if(jArray == NULL) { |
|
358 |
*ckpArray = NULL_PTR; |
|
359 |
*ckpLength = 0L; |
|
360 |
return; |
|
361 |
} |
|
362 |
*ckpLength = (*env)->GetArrayLength(env, jArray); |
|
363 |
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
|
364 |
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
|
365 |
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
|
366 |
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
|
367 |
} |
2 | 368 |
(*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
|
369 |
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
|
370 |
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
|
371 |
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
|
372 |
} |
2 | 373 |
|
374 |
/* if CK_BYTE is the same size as jbyte, we save an additional copy */ |
|
375 |
if (sizeof(CK_BYTE) == sizeof(jbyte)) { |
|
376 |
*ckpArray = (CK_BYTE_PTR) jpTemp; |
|
377 |
} else { |
|
378 |
*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
|
379 |
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
|
380 |
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
|
381 |
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
|
382 |
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
|
383 |
} |
2 | 384 |
for (i=0; i<(*ckpLength); i++) { |
385 |
(*ckpArray)[i] = jByteToCKByte(jpTemp[i]); |
|
386 |
} |
|
387 |
free(jpTemp); |
|
388 |
} |
|
389 |
} |
|
390 |
||
391 |
/* |
|
392 |
* converts a jlongArray to a CK_ULONG array. The allocated memory has to be freed after use! |
|
393 |
* |
|
394 |
* @param env - used to call JNI funktions to get the array informtaion |
|
395 |
* @param jArray - the Java array to convert |
|
396 |
* @param ckpArray - the reference, where the pointer to the new CK_ULONG array will be stored |
|
397 |
* @param ckpLength - the reference, where the array length will be stored |
|
398 |
*/ |
|
399 |
void jLongArrayToCKULongArray(JNIEnv *env, const jlongArray jArray, CK_ULONG_PTR *ckpArray, CK_ULONG_PTR ckpLength) |
|
400 |
{ |
|
401 |
jlong* jTemp; |
|
402 |
CK_ULONG i; |
|
403 |
||
404 |
if(jArray == NULL) { |
|
405 |
*ckpArray = NULL_PTR; |
|
406 |
*ckpLength = 0L; |
|
407 |
return; |
|
408 |
} |
|
409 |
*ckpLength = (*env)->GetArrayLength(env, jArray); |
|
410 |
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
|
411 |
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
|
412 |
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
|
413 |
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
|
414 |
} |
2 | 415 |
(*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
|
416 |
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
|
417 |
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
|
418 |
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
|
419 |
} |
9994f4f08a59
6812738: SSL 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 |
|
2 | 421 |
*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
|
422 |
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
|
423 |
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
|
424 |
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
|
425 |
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
|
426 |
} |
2 | 427 |
for (i=0; i<(*ckpLength); i++) { |
428 |
(*ckpArray)[i] = jLongToCKULong(jTemp[i]); |
|
429 |
} |
|
430 |
free(jTemp); |
|
431 |
} |
|
432 |
||
433 |
/* |
|
434 |
* converts a jcharArray to a CK_CHAR array. The allocated memory has to be freed after use! |
|
435 |
* |
|
436 |
* @param env - used to call JNI funktions to get the array informtaion |
|
437 |
* @param jArray - the Java array to convert |
|
438 |
* @param ckpArray - the reference, where the pointer to the new CK_CHAR array will be stored |
|
439 |
* @param ckpLength - the reference, where the array length will be stored |
|
440 |
*/ |
|
441 |
void jCharArrayToCKCharArray(JNIEnv *env, const jcharArray jArray, CK_CHAR_PTR *ckpArray, CK_ULONG_PTR ckpLength) |
|
442 |
{ |
|
443 |
jchar* jpTemp; |
|
444 |
CK_ULONG i; |
|
445 |
||
446 |
if(jArray == NULL) { |
|
447 |
*ckpArray = NULL_PTR; |
|
448 |
*ckpLength = 0L; |
|
449 |
return; |
|
450 |
} |
|
451 |
*ckpLength = (*env)->GetArrayLength(env, jArray); |
|
452 |
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
|
453 |
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
|
454 |
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
|
455 |
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
|
456 |
} |
2 | 457 |
(*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
|
458 |
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
|
459 |
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
|
460 |
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
|
461 |
} |
9994f4f08a59
6812738: SSL 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 |
|
2 | 463 |
*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
|
464 |
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
|
465 |
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
|
466 |
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
|
467 |
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
|
468 |
} |
2 | 469 |
for (i=0; i<(*ckpLength); i++) { |
470 |
(*ckpArray)[i] = jCharToCKChar(jpTemp[i]); |
|
471 |
} |
|
472 |
free(jpTemp); |
|
473 |
} |
|
474 |
||
475 |
/* |
|
476 |
* converts a jcharArray to a CK_UTF8CHAR array. The allocated memory has to be freed after use! |
|
477 |
* |
|
478 |
* @param env - used to call JNI funktions to get the array informtaion |
|
479 |
* @param jArray - the Java array to convert |
|
480 |
* @param ckpArray - the reference, where the pointer to the new CK_UTF8CHAR array will be stored |
|
481 |
* @param ckpLength - the reference, where the array length will be stored |
|
482 |
*/ |
|
483 |
void jCharArrayToCKUTF8CharArray(JNIEnv *env, const jcharArray jArray, CK_UTF8CHAR_PTR *ckpArray, CK_ULONG_PTR ckpLength) |
|
484 |
{ |
|
485 |
jchar* jTemp; |
|
486 |
CK_ULONG i; |
|
487 |
||
488 |
if(jArray == NULL) { |
|
489 |
*ckpArray = NULL_PTR; |
|
490 |
*ckpLength = 0L; |
|
491 |
return; |
|
492 |
} |
|
493 |
*ckpLength = (*env)->GetArrayLength(env, jArray); |
|
494 |
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
|
495 |
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
|
496 |
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
|
497 |
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
|
498 |
} |
2 | 499 |
(*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
|
500 |
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
|
501 |
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
|
502 |
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
|
503 |
} |
9994f4f08a59
6812738: SSL 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 |
|
2 | 505 |
*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
|
506 |
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
|
507 |
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
|
508 |
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
|
509 |
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
|
510 |
} |
2 | 511 |
for (i=0; i<(*ckpLength); i++) { |
512 |
(*ckpArray)[i] = jCharToCKUTF8Char(jTemp[i]); |
|
513 |
} |
|
514 |
free(jTemp); |
|
515 |
} |
|
516 |
||
517 |
/* |
|
518 |
* converts a jstring to a CK_CHAR array. The allocated memory has to be freed after use! |
|
519 |
* |
|
520 |
* @param env - used to call JNI funktions to get the array informtaion |
|
521 |
* @param jArray - the Java array to convert |
|
522 |
* @param ckpArray - the reference, where the pointer to the new CK_CHAR array will be stored |
|
523 |
* @param ckpLength - the reference, where the array length will be stored |
|
524 |
*/ |
|
525 |
void jStringToCKUTF8CharArray(JNIEnv *env, const jstring jArray, CK_UTF8CHAR_PTR *ckpArray, CK_ULONG_PTR ckpLength) |
|
526 |
{ |
|
527 |
const char* pCharArray; |
|
528 |
jboolean isCopy; |
|
529 |
||
530 |
if(jArray == NULL) { |
|
531 |
*ckpArray = NULL_PTR; |
|
532 |
*ckpLength = 0L; |
|
533 |
return; |
|
534 |
} |
|
535 |
||
536 |
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
|
537 |
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
|
538 |
|
2 | 539 |
*ckpLength = strlen(pCharArray); |
540 |
*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
|
541 |
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
|
542 |
(*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
|
543 |
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
|
544 |
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
|
545 |
} |
2 | 546 |
strcpy((char*)*ckpArray, pCharArray); |
547 |
(*env)->ReleaseStringUTFChars(env, (jstring) jArray, pCharArray); |
|
548 |
} |
|
549 |
||
550 |
/* |
|
551 |
* converts a jobjectArray with Java Attributes to a CK_ATTRIBUTE array. The allocated memory |
|
552 |
* has to be freed after use! |
|
553 |
* |
|
554 |
* @param env - used to call JNI funktions to get the array informtaion |
|
555 |
* @param jArray - the Java Attribute array (template) to convert |
|
556 |
* @param ckpArray - the reference, where the pointer to the new CK_ATTRIBUTE array will be |
|
557 |
* stored |
|
558 |
* @param ckpLength - the reference, where the array length will be stored |
|
559 |
*/ |
|
560 |
void jAttributeArrayToCKAttributeArray(JNIEnv *env, jobjectArray jArray, CK_ATTRIBUTE_PTR *ckpArray, CK_ULONG_PTR ckpLength) |
|
561 |
{ |
|
562 |
CK_ULONG i; |
|
563 |
jlong jLength; |
|
564 |
jobject jAttribute; |
|
565 |
||
566 |
TRACE0("\nDEBUG: jAttributeArrayToCKAttributeArray"); |
|
567 |
if (jArray == NULL) { |
|
568 |
*ckpArray = NULL_PTR; |
|
569 |
*ckpLength = 0L; |
|
570 |
return; |
|
571 |
} |
|
572 |
jLength = (*env)->GetArrayLength(env, jArray); |
|
573 |
*ckpLength = jLongToCKULong(jLength); |
|
574 |
*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
|
575 |
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
|
576 |
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
|
577 |
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
|
578 |
} |
2 | 579 |
TRACE1(", converting %d attibutes", jLength); |
580 |
for (i=0; i<(*ckpLength); i++) { |
|
581 |
TRACE1(", getting %d. attibute", i); |
|
582 |
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
|
583 |
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
|
584 |
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
|
585 |
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
|
586 |
} |
2 | 587 |
TRACE1(", jAttribute = %d", jAttribute); |
588 |
TRACE1(", converting %d. attibute", i); |
|
589 |
(*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
|
590 |
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
|
591 |
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
|
592 |
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
|
593 |
} |
2 | 594 |
} |
595 |
TRACE0("FINISHED\n"); |
|
596 |
} |
|
597 |
||
598 |
/* |
|
599 |
* converts a CK_BYTE array and its length to a jbyteArray. |
|
600 |
* |
|
601 |
* @param env - used to call JNI funktions to create the new Java array |
|
602 |
* @param ckpArray - the pointer to the CK_BYTE array to convert |
|
603 |
* @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
|
604 |
* @return - the new Java byte array or NULL if error occurred |
2 | 605 |
*/ |
606 |
jbyteArray ckByteArrayToJByteArray(JNIEnv *env, const CK_BYTE_PTR ckpArray, CK_ULONG ckLength) |
|
607 |
{ |
|
608 |
CK_ULONG i; |
|
609 |
jbyte* jpTemp; |
|
610 |
jbyteArray jArray; |
|
611 |
||
612 |
/* if CK_BYTE is the same size as jbyte, we save an additional copy */ |
|
613 |
if (sizeof(CK_BYTE) == sizeof(jbyte)) { |
|
614 |
jpTemp = (jbyte*) ckpArray; |
|
615 |
} else { |
|
616 |
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
|
617 |
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
|
618 |
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
|
619 |
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
|
620 |
} |
2 | 621 |
for (i=0; i<ckLength; i++) { |
622 |
jpTemp[i] = ckByteToJByte(ckpArray[i]); |
|
623 |
} |
|
624 |
} |
|
625 |
||
626 |
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
|
627 |
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
|
628 |
(*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
|
629 |
} |
2 | 630 |
|
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
|
631 |
if (sizeof(CK_BYTE) != sizeof(jbyte)) { free(jpTemp); } |
2 | 632 |
|
633 |
return jArray ; |
|
634 |
} |
|
635 |
||
636 |
/* |
|
637 |
* converts a CK_ULONG array and its length to a jlongArray. |
|
638 |
* |
|
639 |
* @param env - used to call JNI funktions to create the new Java array |
|
640 |
* @param ckpArray - the pointer to the CK_ULONG array to convert |
|
641 |
* @param ckpLength - the length of the array to convert |
|
642 |
* @return - the new Java long array |
|
643 |
*/ |
|
644 |
jlongArray ckULongArrayToJLongArray(JNIEnv *env, const CK_ULONG_PTR ckpArray, CK_ULONG ckLength) |
|
645 |
{ |
|
646 |
CK_ULONG i; |
|
647 |
jlong* jpTemp; |
|
648 |
jlongArray jArray; |
|
649 |
||
650 |
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
|
651 |
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
|
652 |
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
|
653 |
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
|
654 |
} |
2 | 655 |
for (i=0; i<ckLength; i++) { |
656 |
jpTemp[i] = ckLongToJLong(ckpArray[i]); |
|
657 |
} |
|
658 |
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
|
659 |
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
|
660 |
(*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
|
661 |
} |
2 | 662 |
free(jpTemp); |
663 |
||
664 |
return jArray ; |
|
665 |
} |
|
666 |
||
667 |
/* |
|
668 |
* converts a CK_CHAR array and its length to a jcharArray. |
|
669 |
* |
|
670 |
* @param env - used to call JNI funktions to create the new Java array |
|
671 |
* @param ckpArray - the pointer to the CK_CHAR array to convert |
|
672 |
* @param ckpLength - the length of the array to convert |
|
673 |
* @return - the new Java char array |
|
674 |
*/ |
|
675 |
jcharArray ckCharArrayToJCharArray(JNIEnv *env, const CK_CHAR_PTR ckpArray, CK_ULONG ckLength) |
|
676 |
{ |
|
677 |
CK_ULONG i; |
|
678 |
jchar* jpTemp; |
|
679 |
jcharArray jArray; |
|
680 |
||
681 |
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
|
682 |
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
|
683 |
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
|
684 |
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
|
685 |
} |
2 | 686 |
for (i=0; i<ckLength; i++) { |
687 |
jpTemp[i] = ckCharToJChar(ckpArray[i]); |
|
688 |
} |
|
689 |
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
|
690 |
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
|
691 |
(*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
|
692 |
} |
2 | 693 |
free(jpTemp); |
694 |
||
695 |
return jArray ; |
|
696 |
} |
|
697 |
||
698 |
/* |
|
699 |
* converts a CK_UTF8CHAR array and its length to a jcharArray. |
|
700 |
* |
|
701 |
* @param env - used to call JNI funktions to create the new Java array |
|
702 |
* @param ckpArray - the pointer to the CK_UTF8CHAR array to convert |
|
703 |
* @param ckpLength - the length of the array to convert |
|
704 |
* @return - the new Java char array |
|
705 |
*/ |
|
706 |
jcharArray ckUTF8CharArrayToJCharArray(JNIEnv *env, const CK_UTF8CHAR_PTR ckpArray, CK_ULONG ckLength) |
|
707 |
{ |
|
708 |
CK_ULONG i; |
|
709 |
jchar* jpTemp; |
|
710 |
jcharArray jArray; |
|
711 |
||
712 |
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
|
713 |
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
|
714 |
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
|
715 |
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
|
716 |
} |
2 | 717 |
for (i=0; i<ckLength; i++) { |
718 |
jpTemp[i] = ckUTF8CharToJChar(ckpArray[i]); |
|
719 |
} |
|
720 |
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
|
721 |
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
|
722 |
(*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
|
723 |
} |
2 | 724 |
free(jpTemp); |
725 |
||
726 |
return jArray ; |
|
727 |
} |
|
728 |
||
729 |
/* |
|
730 |
* the following functions convert Java objects to PKCS#11 pointers and the |
|
731 |
* length in bytes and vice versa |
|
732 |
* |
|
733 |
* CK_<Type>_PTR j<Object>ToCK<Type>Ptr(JNIEnv *env, jobject jObject); |
|
734 |
* |
|
735 |
* jobject ck<Type>PtrToJ<Object>(JNIEnv *env, const CK_<Type>_PTR ckpValue); |
|
736 |
* |
|
737 |
* The functions that convert a Java object to a PKCS#11 pointer first allocate |
|
738 |
* the memory for the PKCS#11 pointer. Then they set each element corresponding |
|
739 |
* to the fields in the Java object to convert. After use the allocated memory of |
|
740 |
* the PKCS#11 pointer has to be explicitly freed. |
|
741 |
* |
|
742 |
* The functions to convert a PKCS#11 pointer to a Java object create a new Java |
|
743 |
* object first and than they set all fields in the object depending on the values |
|
744 |
* of the type or structure where the PKCS#11 pointer points to. |
|
745 |
*/ |
|
746 |
||
747 |
/* |
|
748 |
* converts a CK_BBOOL pointer to a Java boolean Object. |
|
749 |
* |
|
750 |
* @param env - used to call JNI funktions to create the new Java object |
|
751 |
* @param ckpValue - the pointer to the CK_BBOOL value |
|
752 |
* @return - the new Java boolean object with the boolean value |
|
753 |
*/ |
|
754 |
jobject ckBBoolPtrToJBooleanObject(JNIEnv *env, const CK_BBOOL *ckpValue) |
|
755 |
{ |
|
756 |
jclass jValueObjectClass; |
|
757 |
jmethodID jConstructor; |
|
758 |
jobject jValueObject; |
|
759 |
jboolean jValue; |
|
760 |
||
761 |
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
|
762 |
if (jValueObjectClass == NULL) { return NULL; } |
2 | 763 |
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
|
764 |
if (jConstructor == NULL) { return NULL; } |
2 | 765 |
jValue = ckBBoolToJBoolean(*ckpValue); |
766 |
jValueObject = (*env)->NewObject(env, jValueObjectClass, jConstructor, jValue); |
|
767 |
||
768 |
return jValueObject ; |
|
769 |
} |
|
770 |
||
771 |
/* |
|
772 |
* converts a CK_ULONG pointer to a Java long Object. |
|
773 |
* |
|
774 |
* @param env - used to call JNI funktions to create the new Java object |
|
775 |
* @param ckpValue - the pointer to the CK_ULONG value |
|
776 |
* @return - the new Java long object with the long value |
|
777 |
*/ |
|
778 |
jobject ckULongPtrToJLongObject(JNIEnv *env, const CK_ULONG_PTR ckpValue) |
|
779 |
{ |
|
780 |
jclass jValueObjectClass; |
|
781 |
jmethodID jConstructor; |
|
782 |
jobject jValueObject; |
|
783 |
jlong jValue; |
|
784 |
||
785 |
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
|
786 |
if (jValueObjectClass == NULL) { return NULL; } |
2 | 787 |
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
|
788 |
if (jConstructor == NULL) { return NULL; } |
2 | 789 |
jValue = ckULongToJLong(*ckpValue); |
790 |
jValueObject = (*env)->NewObject(env, jValueObjectClass, jConstructor, jValue); |
|
791 |
||
792 |
return jValueObject ; |
|
793 |
} |
|
794 |
||
795 |
/* |
|
796 |
* converts a Java boolean object into a pointer to a CK_BBOOL value. The memory has to be |
|
797 |
* freed after use! |
|
798 |
* |
|
799 |
* @param env - used to call JNI funktions to get the value out of the Java object |
|
800 |
* @param jObject - the "java/lang/Boolean" object to convert |
|
801 |
* @return - the pointer to the new CK_BBOOL value |
|
802 |
*/ |
|
803 |
CK_BBOOL* jBooleanObjectToCKBBoolPtr(JNIEnv *env, jobject jObject) |
|
804 |
{ |
|
805 |
jclass jObjectClass; |
|
806 |
jmethodID jValueMethod; |
|
807 |
jboolean jValue; |
|
808 |
CK_BBOOL *ckpValue; |
|
809 |
||
810 |
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
|
811 |
if (jObjectClass == NULL) { return NULL; } |
2 | 812 |
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
|
813 |
if (jValueMethod == NULL) { return NULL; } |
2 | 814 |
jValue = (*env)->CallBooleanMethod(env, jObject, jValueMethod); |
815 |
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
|
816 |
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
|
817 |
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
|
818 |
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
|
819 |
} |
2 | 820 |
*ckpValue = jBooleanToCKBBool(jValue); |
821 |
||
822 |
return ckpValue ; |
|
823 |
} |
|
824 |
||
825 |
/* |
|
826 |
* converts a Java byte object into a pointer to a CK_BYTE value. The memory has to be |
|
827 |
* freed after use! |
|
828 |
* |
|
829 |
* @param env - used to call JNI funktions to get the value out of the Java object |
|
830 |
* @param jObject - the "java/lang/Byte" object to convert |
|
831 |
* @return - the pointer to the new CK_BYTE value |
|
832 |
*/ |
|
833 |
CK_BYTE_PTR jByteObjectToCKBytePtr(JNIEnv *env, jobject jObject) |
|
834 |
{ |
|
835 |
jclass jObjectClass; |
|
836 |
jmethodID jValueMethod; |
|
837 |
jbyte jValue; |
|
838 |
CK_BYTE_PTR ckpValue; |
|
839 |
||
840 |
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
|
841 |
if (jObjectClass == NULL) { return NULL; } |
2 | 842 |
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
|
843 |
if (jValueMethod == NULL) { return NULL; } |
2 | 844 |
jValue = (*env)->CallByteMethod(env, jObject, jValueMethod); |
845 |
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
|
846 |
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
|
847 |
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
|
848 |
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
|
849 |
} |
2 | 850 |
*ckpValue = jByteToCKByte(jValue); |
851 |
return ckpValue ; |
|
852 |
} |
|
853 |
||
854 |
/* |
|
855 |
* converts a Java integer object into a pointer to a CK_ULONG value. The memory has to be |
|
856 |
* freed after use! |
|
857 |
* |
|
858 |
* @param env - used to call JNI funktions to get the value out of the Java object |
|
859 |
* @param jObject - the "java/lang/Integer" object to convert |
|
860 |
* @return - the pointer to the new CK_ULONG value |
|
861 |
*/ |
|
862 |
CK_ULONG* jIntegerObjectToCKULongPtr(JNIEnv *env, jobject jObject) |
|
863 |
{ |
|
864 |
jclass jObjectClass; |
|
865 |
jmethodID jValueMethod; |
|
866 |
jint jValue; |
|
867 |
CK_ULONG *ckpValue; |
|
868 |
||
869 |
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
|
870 |
if (jObjectClass == NULL) { return NULL; } |
2 | 871 |
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
|
872 |
if (jValueMethod == NULL) { return NULL; } |
2 | 873 |
jValue = (*env)->CallIntMethod(env, jObject, jValueMethod); |
874 |
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
|
875 |
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
|
876 |
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
|
877 |
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
|
878 |
} |
2 | 879 |
*ckpValue = jLongToCKLong(jValue); |
880 |
return ckpValue ; |
|
881 |
} |
|
882 |
||
883 |
/* |
|
884 |
* converts a Java long object into a pointer to a CK_ULONG value. The memory has to be |
|
885 |
* freed after use! |
|
886 |
* |
|
887 |
* @param env - used to call JNI funktions to get the value out of the Java object |
|
888 |
* @param jObject - the "java/lang/Long" object to convert |
|
889 |
* @return - the pointer to the new CK_ULONG value |
|
890 |
*/ |
|
891 |
CK_ULONG* jLongObjectToCKULongPtr(JNIEnv *env, jobject jObject) |
|
892 |
{ |
|
893 |
jclass jObjectClass; |
|
894 |
jmethodID jValueMethod; |
|
895 |
jlong jValue; |
|
896 |
CK_ULONG *ckpValue; |
|
897 |
||
898 |
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
|
899 |
if (jObjectClass == NULL) { return NULL; } |
2 | 900 |
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
|
901 |
if (jValueMethod == NULL) { return NULL; } |
2 | 902 |
jValue = (*env)->CallLongMethod(env, jObject, jValueMethod); |
903 |
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
|
904 |
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
|
905 |
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
|
906 |
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
|
907 |
} |
2 | 908 |
*ckpValue = jLongToCKULong(jValue); |
909 |
||
910 |
return ckpValue ; |
|
911 |
} |
|
912 |
||
913 |
/* |
|
914 |
* converts a Java char object into a pointer to a CK_CHAR value. The memory has to be |
|
915 |
* freed after use! |
|
916 |
* |
|
917 |
* @param env - used to call JNI funktions to get the value out of the Java object |
|
918 |
* @param jObject - the "java/lang/Char" object to convert |
|
919 |
* @return - the pointer to the new CK_CHAR value |
|
920 |
*/ |
|
921 |
CK_CHAR_PTR jCharObjectToCKCharPtr(JNIEnv *env, jobject jObject) |
|
922 |
{ |
|
923 |
jclass jObjectClass; |
|
924 |
jmethodID jValueMethod; |
|
925 |
jchar jValue; |
|
926 |
CK_CHAR_PTR ckpValue; |
|
927 |
||
928 |
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
|
929 |
if (jObjectClass == NULL) { return NULL; } |
2 | 930 |
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
|
931 |
if (jValueMethod == NULL) { return NULL; } |
2 | 932 |
jValue = (*env)->CallCharMethod(env, jObject, jValueMethod); |
933 |
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
|
934 |
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
|
935 |
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
|
936 |
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
|
937 |
} |
2 | 938 |
*ckpValue = jCharToCKChar(jValue); |
939 |
||
940 |
return ckpValue ; |
|
941 |
} |
|
942 |
||
943 |
/* |
|
944 |
* converts a Java object into a pointer to CK-type or a CK-structure with the length in Bytes. |
|
945 |
* The memory of *ckpObjectPtr to be freed after use! This function is only used by |
|
946 |
* jAttributeToCKAttribute by now. |
|
947 |
* |
|
948 |
* @param env - used to call JNI funktions to get the Java classes and objects |
|
949 |
* @param jObject - the Java object to convert |
|
950 |
* @param ckpObjectPtr - the reference of the new pointer to the new CK-value or CK-structure |
|
951 |
* @param ckpLength - the reference of the length in bytes of the new CK-value or CK-structure |
|
952 |
*/ |
|
953 |
void jObjectToPrimitiveCKObjectPtrPtr(JNIEnv *env, jobject jObject, CK_VOID_PTR *ckpObjectPtr, CK_ULONG *ckpLength) |
|
954 |
{ |
|
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
|
955 |
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
|
956 |
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
|
957 |
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
|
958 |
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
|
959 |
jclass jObjectClass, jClassClass; |
2 | 960 |
CK_VOID_PTR ckpVoid = *ckpObjectPtr; |
961 |
jmethodID jMethod; |
|
962 |
jobject jClassObject; |
|
963 |
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
|
964 |
char *classNameString, *exceptionMsgPrefix, *exceptionMsg; |
2 | 965 |
|
966 |
TRACE0("\nDEBUG: jObjectToPrimitiveCKObjectPtrPtr"); |
|
967 |
if (jObject == NULL) { |
|
968 |
*ckpObjectPtr = NULL; |
|
969 |
*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
|
970 |
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
|
971 |
} |
9994f4f08a59
6812738: SSL 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 |
|
9994f4f08a59
6812738: SSL 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 |
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
|
974 |
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
|
975 |
if ((*env)->IsInstanceOf(env, jObject, jLongClass)) { |
2 | 976 |
*ckpObjectPtr = jLongObjectToCKULongPtr(env, jObject); |
977 |
*ckpLength = sizeof(CK_ULONG); |
|
978 |
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
|
979 |
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
|
980 |
} |
9994f4f08a59
6812738: SSL 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 |
|
9994f4f08a59
6812738: SSL 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 |
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
|
983 |
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
|
984 |
if ((*env)->IsInstanceOf(env, jObject, jBooleanClass)) { |
2 | 985 |
*ckpObjectPtr = jBooleanObjectToCKBBoolPtr(env, jObject); |
986 |
*ckpLength = sizeof(CK_BBOOL); |
|
987 |
TRACE0(" <converted boolean value "); |
|
988 |
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
|
989 |
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
|
990 |
} |
9994f4f08a59
6812738: SSL 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 |
|
9994f4f08a59
6812738: SSL 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 |
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
|
993 |
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
|
994 |
if ((*env)->IsInstanceOf(env, jObject, jByteArrayClass)) { |
2 | 995 |
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
|
996 |
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
|
997 |
} |
9994f4f08a59
6812738: SSL 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 |
|
9994f4f08a59
6812738: SSL 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 |
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
|
1000 |
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
|
1001 |
if ((*env)->IsInstanceOf(env, jObject, jCharArrayClass)) { |
2 | 1002 |
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
|
1003 |
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
|
1004 |
} |
9994f4f08a59
6812738: SSL 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 |
|
9994f4f08a59
6812738: SSL 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 |
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
|
1007 |
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
|
1008 |
if ((*env)->IsInstanceOf(env, jObject, jByteClass)) { |
2 | 1009 |
*ckpObjectPtr = jByteObjectToCKBytePtr(env, jObject); |
1010 |
*ckpLength = sizeof(CK_BYTE); |
|
1011 |
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
|
1012 |
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
|
1013 |
} |
9994f4f08a59
6812738: SSL 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 |
|
9994f4f08a59
6812738: SSL 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 |
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
|
1016 |
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
|
1017 |
if ((*env)->IsInstanceOf(env, jObject, jDateClass)) { |
2 | 1018 |
*ckpObjectPtr = jDateObjectPtrToCKDatePtr(env, jObject); |
1019 |
*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
|
1020 |
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
|
1021 |
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
|
1022 |
} |
9994f4f08a59
6812738: SSL 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 |
|
9994f4f08a59
6812738: SSL 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 |
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
|
1025 |
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
|
1026 |
if ((*env)->IsInstanceOf(env, jObject, jCharacterClass)) { |
2 | 1027 |
*ckpObjectPtr = jCharObjectToCKCharPtr(env, jObject); |
1028 |
*ckpLength = sizeof(CK_UTF8CHAR); |
|
1029 |
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
|
1030 |
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
|
1031 |
} |
9994f4f08a59
6812738: SSL 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 |
|
9994f4f08a59
6812738: SSL 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 |
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
|
1034 |
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
|
1035 |
if ((*env)->IsInstanceOf(env, jObject, jIntegerClass)) { |
2 | 1036 |
*ckpObjectPtr = jIntegerObjectToCKULongPtr(env, jObject); |
1037 |
*ckpLength = sizeof(CK_ULONG); |
|
1038 |
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
|
1039 |
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
|
1040 |
} |
9994f4f08a59
6812738: SSL 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 |
|
9994f4f08a59
6812738: SSL 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 |
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
|
1043 |
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
|
1044 |
if ((*env)->IsInstanceOf(env, jObject, jBooleanArrayClass)) { |
2 | 1045 |
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
|
1046 |
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
|
1047 |
} |
9994f4f08a59
6812738: SSL 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 |
|
9994f4f08a59
6812738: SSL 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 |
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
|
1050 |
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
|
1051 |
if ((*env)->IsInstanceOf(env, jObject, jIntArrayClass)) { |
2 | 1052 |
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
|
1053 |
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
|
1054 |
} |
9994f4f08a59
6812738: SSL 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 |
|
9994f4f08a59
6812738: SSL 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 |
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
|
1057 |
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
|
1058 |
if ((*env)->IsInstanceOf(env, jObject, jLongArrayClass)) { |
2 | 1059 |
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
|
1060 |
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
|
1061 |
} |
9994f4f08a59
6812738: SSL 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 |
|
9994f4f08a59
6812738: SSL 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 |
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
|
1064 |
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
|
1065 |
if ((*env)->IsInstanceOf(env, jObject, jStringClass)) { |
2 | 1066 |
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
|
1067 |
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
|
1068 |
} |
2 | 1069 |
|
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
|
1070 |
/* 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
|
1071 |
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
|
1072 |
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
|
1073 |
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
|
1074 |
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
|
1075 |
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
|
1076 |
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
|
1077 |
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
|
1078 |
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
|
1079 |
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
|
1080 |
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
|
1081 |
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
|
1082 |
(*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
|
1083 |
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
|
1084 |
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
|
1085 |
(*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
|
1086 |
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
|
1087 |
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
|
1088 |
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
|
1089 |
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
|
1090 |
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
|
1091 |
(*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
|
1092 |
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
|
1093 |
return; |
2 | 1094 |
} |
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
|
1095 |
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
|
1096 |
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
|
1097 |
(*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
|
1098 |
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
|
1099 |
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
|
1100 |
*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
|
1101 |
*ckpLength = 0; |
2 | 1102 |
|
1103 |
TRACE0("FINISHED\n"); |
|
1104 |
} |
|
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
|
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 |
#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
|
1107 |
|
9994f4f08a59
6812738: SSL 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 |
#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
|
1109 |
#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
|
1110 |
|
9994f4f08a59
6812738: SSL 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 |
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
|
1112 |
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
|
1113 |
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
|
1114 |
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
|
1115 |
} |
9994f4f08a59
6812738: SSL 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 |
|
9994f4f08a59
6812738: SSL 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 |
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
|
1118 |
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
|
1119 |
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
|
1120 |
} |
9994f4f08a59
6812738: SSL 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 |
|
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1122 |
#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
|
1123 |