author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 58489 | 2faeaa5933a6 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
*/ |
4 |
||
5 |
/* Copyright (c) 2002 Graz University of Technology. All rights reserved. |
|
6 |
* |
|
7 |
* Redistribution and use in source and binary forms, with or without |
|
8 |
* modification, are permitted provided that the following conditions are met: |
|
9 |
* |
|
10 |
* 1. Redistributions of source code must retain the above copyright notice, |
|
11 |
* this list of conditions and the following disclaimer. |
|
12 |
* |
|
13 |
* 2. Redistributions in binary form must reproduce the above copyright notice, |
|
14 |
* this list of conditions and the following disclaimer in the documentation |
|
15 |
* and/or other materials provided with the distribution. |
|
16 |
* |
|
17 |
* 3. The end-user documentation included with the redistribution, if any, must |
|
18 |
* include the following acknowledgment: |
|
19 |
* |
|
20 |
* "This product includes software developed by IAIK of Graz University of |
|
21 |
* Technology." |
|
22 |
* |
|
23 |
* Alternately, this acknowledgment may appear in the software itself, if |
|
24 |
* and wherever such third-party acknowledgments normally appear. |
|
25 |
* |
|
26 |
* 4. The names "Graz University of Technology" and "IAIK of Graz University of |
|
27 |
* Technology" must not be used to endorse or promote products derived from |
|
28 |
* this software without prior written permission. |
|
29 |
* |
|
30 |
* 5. Products derived from this software may not be called |
|
31 |
* "IAIK PKCS Wrapper", nor may "IAIK" appear in their name, without prior |
|
32 |
* written permission of Graz University of Technology. |
|
33 |
* |
|
34 |
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED |
|
35 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
36 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
37 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LICENSOR BE |
|
38 |
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, |
|
39 |
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
40 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, |
|
41 |
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
|
42 |
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
|
43 |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|
44 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
45 |
* POSSIBILITY OF SUCH DAMAGE. |
|
46 |
*/ |
|
47 |
||
48 |
#include "pkcs11wrapper.h" |
|
49 |
||
50 |
#include <stdio.h> |
|
51 |
#include <stdlib.h> |
|
52 |
#include <string.h> |
|
53 |
#include <assert.h> |
|
54 |
||
55 |
/* 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 |
} |
|
14414
f338be3ef659
8001579: Cleanup warnings in security native code
jzavgren
parents:
14342
diff
changeset
|
109 |
(*env)->SetLongField(env, pkcs11Implementation, pNativeDataID, ptr_to_jlong(moduleData)); |
2 | 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); |
|
14414
f338be3ef659
8001579: Cleanup warnings in security native code
jzavgren
parents:
14342
diff
changeset
|
123 |
return (ModuleData*)jlong_to_ptr(jData); |
2 | 124 |
} |
125 |
||
126 |
CK_FUNCTION_LIST_PTR getFunctionList(JNIEnv *env, jobject pkcs11Implementation) { |
|
127 |
ModuleData *moduleData; |
|
128 |
CK_FUNCTION_LIST_PTR ckpFunctions; |
|
129 |
||
130 |
moduleData = getModuleEntry(env, pkcs11Implementation); |
|
131 |
if (moduleData == NULL) { |
|
132 |
throwDisconnectedRuntimeException(env); |
|
133 |
return NULL; |
|
134 |
} |
|
135 |
ckpFunctions = moduleData->ckFunctionListPtr; |
|
136 |
return ckpFunctions; |
|
137 |
} |
|
138 |
||
139 |
||
140 |
/* |
|
141 |
* Returns 1, if the given pkcs11Implementation is in the list. |
|
142 |
* 0, otherwise. |
|
143 |
*/ |
|
144 |
int isModulePresent(JNIEnv *env, jobject pkcs11Implementation) { |
|
145 |
int present; |
|
146 |
||
147 |
ModuleData *moduleData = getModuleEntry(env, pkcs11Implementation); |
|
148 |
||
149 |
present = (moduleData != NULL) ? 1 : 0; |
|
150 |
||
151 |
return present ; |
|
152 |
} |
|
153 |
||
154 |
||
155 |
/* |
|
156 |
* Removes the entry for the given pkcs11Implementation from the list. Returns |
|
157 |
* the module's data, after the node was removed. If this function returns NULL |
|
158 |
* the pkcs11Implementation was not in the list. |
|
159 |
*/ |
|
160 |
ModuleData * removeModuleEntry(JNIEnv *env, jobject pkcs11Implementation) { |
|
161 |
ModuleData *moduleData = getModuleEntry(env, pkcs11Implementation); |
|
162 |
if (moduleData == NULL) { |
|
163 |
return NULL; |
|
164 |
} |
|
165 |
(*env)->SetLongField(env, pkcs11Implementation, pNativeDataID, 0); |
|
166 |
return moduleData; |
|
167 |
} |
|
168 |
||
169 |
/* |
|
170 |
* Removes all present entries from the list of modules and frees all |
|
171 |
* associated resources. This function is used for clean-up. |
|
172 |
*/ |
|
173 |
void removeAllModuleEntries(JNIEnv *env) { |
|
174 |
/* XXX empty */ |
|
175 |
} |
|
176 |
||
177 |
/* ************************************************************************** */ |
|
178 |
/* Below there follow the helper functions to support conversions between */ |
|
179 |
/* Java and Cryptoki types */ |
|
180 |
/* ************************************************************************** */ |
|
181 |
||
182 |
/* |
|
183 |
* function to convert a PKCS#11 return value into a PKCS#11Exception |
|
184 |
* |
|
185 |
* This function generates a PKCS#11Exception with the returnValue as the errorcode |
|
186 |
* if the returnValue is not CKR_OK. The functin returns 0, if the returnValue is |
|
187 |
* CKR_OK. Otherwise, it returns the returnValue as a jLong. |
|
188 |
* |
|
189 |
* @param env - used to call JNI funktions and to get the Exception class |
|
190 |
* @param returnValue - of the PKCS#11 function |
|
191 |
*/ |
|
192 |
jlong ckAssertReturnValueOK(JNIEnv *env, CK_RV returnValue) |
|
193 |
{ |
|
194 |
jclass jPKCS11ExceptionClass; |
|
195 |
jmethodID jConstructor; |
|
196 |
jthrowable jPKCS11Exception; |
|
3321
fed33393bc52
6823905: crash in sun.security.pkcs11.wrapper.PKCS11.C_Sign during stress-test
valeriep
parents:
2180
diff
changeset
|
197 |
jlong jErrorCode = 0L; |
2 | 198 |
|
3321
fed33393bc52
6823905: crash in sun.security.pkcs11.wrapper.PKCS11.C_Sign during stress-test
valeriep
parents:
2180
diff
changeset
|
199 |
if (returnValue != CKR_OK) { |
fed33393bc52
6823905: crash in sun.security.pkcs11.wrapper.PKCS11.C_Sign during stress-test
valeriep
parents:
2180
diff
changeset
|
200 |
jErrorCode = ckULongToJLong(returnValue); |
2 | 201 |
jPKCS11ExceptionClass = (*env)->FindClass(env, CLASS_PKCS11EXCEPTION); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
202 |
if (jPKCS11ExceptionClass != NULL) { |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
203 |
jConstructor = (*env)->GetMethodID(env, jPKCS11ExceptionClass, "<init>", "(J)V"); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
204 |
if (jConstructor != NULL) { |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
205 |
jPKCS11Exception = (jthrowable) (*env)->NewObject(env, jPKCS11ExceptionClass, jConstructor, jErrorCode); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
206 |
if (jPKCS11Exception != NULL) { |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
207 |
(*env)->Throw(env, jPKCS11Exception); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
208 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
209 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
210 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
211 |
(*env)->DeleteLocalRef(env, jPKCS11ExceptionClass); |
2 | 212 |
} |
3321
fed33393bc52
6823905: crash in sun.security.pkcs11.wrapper.PKCS11.C_Sign during stress-test
valeriep
parents:
2180
diff
changeset
|
213 |
return jErrorCode ; |
2 | 214 |
} |
215 |
||
10798
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
216 |
|
2 | 217 |
/* |
10798
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
218 |
* Throws a Java Exception by name |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
219 |
*/ |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
220 |
void throwByName(JNIEnv *env, const char *name, const char *msg) |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
221 |
{ |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
222 |
jclass cls = (*env)->FindClass(env, name); |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
223 |
|
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
224 |
if (cls != 0) /* Otherwise an exception has already been thrown */ |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
225 |
(*env)->ThrowNew(env, cls, msg); |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
226 |
} |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
227 |
|
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
228 |
/* |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
229 |
* Throws java.lang.OutOfMemoryError |
2 | 230 |
*/ |
10798
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
231 |
void throwOutOfMemoryError(JNIEnv *env, const char *msg) |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
232 |
{ |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
233 |
throwByName(env, "java/lang/OutOfMemoryError", msg); |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
234 |
} |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
235 |
|
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
236 |
/* |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
237 |
* Throws java.lang.NullPointerException |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
238 |
*/ |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
239 |
void throwNullPointerException(JNIEnv *env, const char *msg) |
2 | 240 |
{ |
10798
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
241 |
throwByName(env, "java/lang/NullPointerException", msg); |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
242 |
} |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
243 |
|
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
244 |
/* |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
245 |
* Throws java.io.IOException |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
246 |
*/ |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
247 |
void throwIOException(JNIEnv *env, const char *msg) |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
248 |
{ |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
249 |
throwByName(env, "java/io/IOException", msg); |
2 | 250 |
} |
251 |
||
252 |
/* |
|
253 |
* This function simply throws a PKCS#11RuntimeException with the given |
|
10798
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
254 |
* string as its message. |
2 | 255 |
* |
256 |
* @param env Used to call JNI funktions and to get the Exception class. |
|
257 |
* @param jmessage The message string of the Exception object. |
|
258 |
*/ |
|
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
|
259 |
void throwPKCS11RuntimeException(JNIEnv *env, const char *message) |
2 | 260 |
{ |
10798
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
261 |
throwByName(env, CLASS_PKCS11RUNTIMEEXCEPTION, message); |
2 | 262 |
} |
263 |
||
264 |
/* |
|
265 |
* This function simply throws a PKCS#11RuntimeException. The message says that |
|
266 |
* the object is not connected to the module. |
|
267 |
* |
|
268 |
* @param env Used to call JNI funktions and to get the Exception class. |
|
269 |
*/ |
|
270 |
void throwDisconnectedRuntimeException(JNIEnv *env) |
|
271 |
{ |
|
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
|
272 |
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
|
273 |
} |
2 | 274 |
|
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
|
275 |
/* 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
|
276 |
* |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
277 |
* @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
|
278 |
* @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
|
279 |
*/ |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
280 |
void freeCKAttributeArray(CK_ATTRIBUTE_PTR attrPtr, int len) { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
281 |
if (attrPtr != NULL) { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
282 |
int i; |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
283 |
for (i=0; i<len; i++) { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
284 |
if (attrPtr[i].pValue != NULL_PTR) { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
285 |
free(attrPtr[i].pValue); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
286 |
} |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
287 |
} |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
288 |
free(attrPtr); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
289 |
} |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
290 |
} |
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
|
291 |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
292 |
/* This function frees the specified CK_MECHANISM_PTR pointer and its |
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
293 |
* pParameter including mechanism-specific memory allocations. |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
294 |
* |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
295 |
* @param mechPtr pointer to the to-be-freed CK_MECHANISM structure. |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
296 |
*/ |
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
297 |
void freeCKMechanismPtr(CK_MECHANISM_PTR mechPtr) { |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
298 |
void *tmp; |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
299 |
CK_SSL3_MASTER_KEY_DERIVE_PARAMS *sslMkdTmp; |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
300 |
CK_SSL3_KEY_MAT_PARAMS* sslKmTmp; |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
301 |
CK_TLS12_MASTER_KEY_DERIVE_PARAMS *tlsMkdTmp; |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
302 |
CK_TLS12_KEY_MAT_PARAMS* tlsKmTmp; |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
303 |
|
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
304 |
if (mechPtr != NULL) { |
58489
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
305 |
TRACE2("DEBUG freeCKMechanismPtr: free pMech %p (mech 0x%lX)\n", |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
306 |
mechPtr, mechPtr->mechanism); |
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
307 |
if (mechPtr->pParameter != NULL) { |
58489
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
308 |
tmp = mechPtr->pParameter; |
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
309 |
switch (mechPtr->mechanism) { |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
310 |
case CKM_AES_GCM: |
58489
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
311 |
if (mechPtr->ulParameterLen == sizeof(CK_GCM_PARAMS_NO_IVBITS)) { |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
312 |
TRACE0("[ GCM_PARAMS w/o ulIvBits ]\n"); |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
313 |
free(((CK_GCM_PARAMS_NO_IVBITS*)tmp)->pIv); |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
314 |
free(((CK_GCM_PARAMS_NO_IVBITS*)tmp)->pAAD); |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
315 |
} else if (mechPtr->ulParameterLen == sizeof(CK_GCM_PARAMS)) { |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
316 |
TRACE0("[ GCM_PARAMS ]\n"); |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
317 |
free(((CK_GCM_PARAMS*)tmp)->pIv); |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
318 |
free(((CK_GCM_PARAMS*)tmp)->pAAD); |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
319 |
} |
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
320 |
break; |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
321 |
case CKM_AES_CCM: |
58489
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
322 |
TRACE0("[ CK_CCM_PARAMS ]\n"); |
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
323 |
free(((CK_CCM_PARAMS*)tmp)->pNonce); |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
324 |
free(((CK_CCM_PARAMS*)tmp)->pAAD); |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
325 |
break; |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
326 |
case CKM_TLS_PRF: |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
327 |
case CKM_NSS_TLS_PRF_GENERAL: |
58489
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
328 |
TRACE0("[ CK_TLS_PRF_PARAMS ]\n"); |
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
329 |
free(((CK_TLS_PRF_PARAMS*)tmp)->pSeed); |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
330 |
free(((CK_TLS_PRF_PARAMS*)tmp)->pLabel); |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
331 |
free(((CK_TLS_PRF_PARAMS*)tmp)->pulOutputLen); |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
332 |
free(((CK_TLS_PRF_PARAMS*)tmp)->pOutput); |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
333 |
break; |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
334 |
case CKM_SSL3_MASTER_KEY_DERIVE: |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
335 |
case CKM_TLS_MASTER_KEY_DERIVE: |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
336 |
case CKM_SSL3_MASTER_KEY_DERIVE_DH: |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
337 |
case CKM_TLS_MASTER_KEY_DERIVE_DH: |
58489
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
338 |
sslMkdTmp = tmp; |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
339 |
TRACE0("[ CK_SSL3_MASTER_KEY_DERIVE_PARAMS ]\n"); |
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
340 |
free(sslMkdTmp->RandomInfo.pClientRandom); |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
341 |
free(sslMkdTmp->RandomInfo.pServerRandom); |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
342 |
free(sslMkdTmp->pVersion); |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
343 |
break; |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
344 |
case CKM_SSL3_KEY_AND_MAC_DERIVE: |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
345 |
case CKM_TLS_KEY_AND_MAC_DERIVE: |
58489
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
346 |
sslKmTmp = tmp; |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
347 |
TRACE0("[ CK_SSL3_KEY_MAT_PARAMS ]\n"); |
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
348 |
free(sslKmTmp->RandomInfo.pClientRandom); |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
349 |
free(sslKmTmp->RandomInfo.pServerRandom); |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
350 |
if (sslKmTmp->pReturnedKeyMaterial != NULL) { |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
351 |
free(sslKmTmp->pReturnedKeyMaterial->pIVClient); |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
352 |
free(sslKmTmp->pReturnedKeyMaterial->pIVServer); |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
353 |
free(sslKmTmp->pReturnedKeyMaterial); |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
354 |
} |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
355 |
break; |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
356 |
case CKM_TLS12_MASTER_KEY_DERIVE: |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
357 |
case CKM_TLS12_MASTER_KEY_DERIVE_DH: |
58489
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
358 |
tlsMkdTmp = tmp; |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
359 |
TRACE0("[ CK_TLS12_MASTER_KEY_DERIVE_PARAMS ]\n"); |
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
360 |
free(tlsMkdTmp->RandomInfo.pClientRandom); |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
361 |
free(tlsMkdTmp->RandomInfo.pServerRandom); |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
362 |
free(tlsMkdTmp->pVersion); |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
363 |
break; |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
364 |
case CKM_TLS12_KEY_AND_MAC_DERIVE: |
58489
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
365 |
tlsKmTmp = tmp; |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
366 |
TRACE0("[ CK_TLS12_KEY_MAT_PARAMS ]\n"); |
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
367 |
free(tlsKmTmp->RandomInfo.pClientRandom); |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
368 |
free(tlsKmTmp->RandomInfo.pServerRandom); |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
369 |
if (tlsKmTmp->pReturnedKeyMaterial != NULL) { |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
370 |
free(tlsKmTmp->pReturnedKeyMaterial->pIVClient); |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
371 |
free(tlsKmTmp->pReturnedKeyMaterial->pIVServer); |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
372 |
free(tlsKmTmp->pReturnedKeyMaterial); |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
373 |
} |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
374 |
break; |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
375 |
case CKM_ECDH1_DERIVE: |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
376 |
case CKM_ECDH1_COFACTOR_DERIVE: |
58489
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
377 |
TRACE0("[ CK_ECDH1_DERIVE_PARAMS ]\n"); |
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
378 |
free(((CK_ECDH1_DERIVE_PARAMS *)tmp)->pSharedData); |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
379 |
free(((CK_ECDH1_DERIVE_PARAMS *)tmp)->pPublicData); |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
380 |
break; |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
381 |
case CKM_TLS_MAC: |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
382 |
case CKM_AES_CTR: |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
383 |
case CKM_RSA_PKCS_PSS: |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
384 |
case CKM_CAMELLIA_CTR: |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
385 |
// params do not contain pointers |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
386 |
break; |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
387 |
default: |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
388 |
// currently unsupported mechs by SunPKCS11 provider |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
389 |
// CKM_RSA_PKCS_OAEP, CKM_ECMQV_DERIVE, |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
390 |
// CKM_X9_42_*, CKM_KEA_DERIVE, CKM_RC2_*, CKM_RC5_*, |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
391 |
// CKM_SKIPJACK_*, CKM_KEY_WRAP_SET_OAEP, CKM_PKCS5_PBKD2, |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
392 |
// PBE mechs, WTLS mechs, CMS mechs, |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
393 |
// CKM_EXTRACT_KEY_FROM_KEY, CKM_OTP, CKM_KIP, |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
394 |
// CKM_DSA_PARAMETER_GEN?, CKM_GOSTR3410_* |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
395 |
// CK_any_CBC_ENCRYPT_DATA? |
58489
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
396 |
TRACE0("ERROR: UNSUPPORTED CK_MECHANISM\n"); |
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
397 |
break; |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
398 |
} |
58489
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
399 |
TRACE1("\t=> freed param %p\n", tmp); |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
400 |
free(tmp); |
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
401 |
} else { |
58489
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
402 |
TRACE0("\t=> param NULL\n"); |
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
403 |
} |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
404 |
free(mechPtr); |
58489
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
405 |
TRACE0("FINISHED\n"); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
406 |
} |
2 | 407 |
} |
408 |
||
58489
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
409 |
/* This function replaces the CK_GCM_PARAMS_NO_IVBITS structure associated |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
410 |
* with the specified CK_MECHANISM structure with CK_GCM_PARAMS |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
411 |
* structure. |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
412 |
* |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
413 |
* @param mechPtr pointer to the CK_MECHANISM structure containing |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
414 |
* the to-be-converted CK_GCM_PARAMS_NO_IVBITS structure. |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
415 |
* @return pointer to the CK_MECHANISM structure containing the |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
416 |
* converted CK_GCM_PARAMS structure or NULL if no conversion took place. |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
417 |
*/ |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
418 |
CK_MECHANISM_PTR updateGCMParams(JNIEnv *env, CK_MECHANISM_PTR mechPtr) { |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
419 |
CK_GCM_PARAMS* pGcmParams2 = NULL; |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
420 |
CK_GCM_PARAMS_NO_IVBITS* pParams = NULL; |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
421 |
if ((mechPtr->mechanism == CKM_AES_GCM) && |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
422 |
(mechPtr->pParameter != NULL_PTR) && |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
423 |
(mechPtr->ulParameterLen == sizeof(CK_GCM_PARAMS_NO_IVBITS))) { |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
424 |
pGcmParams2 = calloc(1, sizeof(CK_GCM_PARAMS)); |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
425 |
if (pGcmParams2 == NULL) { |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
426 |
throwOutOfMemoryError(env, 0); |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
427 |
return NULL; |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
428 |
} |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
429 |
pParams = (CK_GCM_PARAMS_NO_IVBITS*) mechPtr->pParameter; |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
430 |
pGcmParams2->pIv = pParams->pIv; |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
431 |
pGcmParams2->ulIvLen = pParams->ulIvLen; |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
432 |
pGcmParams2->ulIvBits = (pGcmParams2->ulIvLen << 3); |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
433 |
pGcmParams2->pAAD = pParams->pAAD; |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
434 |
pGcmParams2->ulAADLen = pParams->ulAADLen; |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
435 |
pGcmParams2->ulTagBits = pParams->ulTagBits; |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
436 |
TRACE1("DEBUG updateGCMParams: pMech %p\n", mechPtr); |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
437 |
TRACE2("\t=> GCM param w/o ulIvBits %p => GCM param %p\n", pParams, |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
438 |
pGcmParams2); |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
439 |
free(pParams); |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
440 |
mechPtr->pParameter = pGcmParams2; |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
441 |
mechPtr->ulParameterLen = sizeof(CK_GCM_PARAMS); |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
442 |
return mechPtr; |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
443 |
} else { |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
444 |
TRACE0("DEBUG updateGCMParams: no conversion done\n"); |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
445 |
} |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
446 |
return NULL; |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
447 |
} |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
58281
diff
changeset
|
448 |
|
2 | 449 |
/* |
450 |
* the following functions convert Java arrays to PKCS#11 array pointers and |
|
451 |
* their array length and vice versa |
|
452 |
* |
|
453 |
* void j<Type>ArrayToCK<Type>Array(JNIEnv *env, |
|
454 |
* const j<Type>Array jArray, |
|
455 |
* CK_<Type>_PTR *ckpArray, |
|
456 |
* CK_ULONG_PTR ckLength); |
|
457 |
* |
|
458 |
* j<Type>Array ck<Type>ArrayToJ<Type>Array(JNIEnv *env, |
|
459 |
* const CK_<Type>_PTR ckpArray, |
|
460 |
* CK_ULONG ckLength); |
|
461 |
* |
|
462 |
* PKCS#11 arrays consist always of a pointer to the beginning of the array and |
|
463 |
* the array length whereas Java arrays carry their array length. |
|
464 |
* |
|
465 |
* The Functions to convert a Java array to a PKCS#11 array are void functions. |
|
466 |
* Their arguments are the Java array object to convert, the reference to the |
|
467 |
* array pointer, where the new PKCS#11 array should be stored and the reference |
|
468 |
* to the array length where the PKCS#11 array length should be stored. These two |
|
469 |
* references must not be NULL_PTR. |
|
470 |
* |
|
471 |
* The functions first obtain the array length of the Java array and then allocate |
|
472 |
* the memory for the PKCS#11 array and set the array length. Then each element |
|
473 |
* gets converted depending on their type. After use the allocated memory of the |
|
474 |
* PKCS#11 array has to be explicitly freed. |
|
475 |
* |
|
476 |
* The Functions to convert a PKCS#11 array to a Java array get the PKCS#11 array |
|
477 |
* pointer and the array length and they return the new Java array object. The |
|
478 |
* Java array does not need to get freed after use. |
|
479 |
*/ |
|
480 |
||
481 |
/* |
|
482 |
* converts a jbooleanArray to a CK_BBOOL array. The allocated memory has to be freed after use! |
|
483 |
* |
|
484 |
* @param env - used to call JNI funktions to get the array informtaion |
|
485 |
* @param jArray - the Java array to convert |
|
486 |
* @param ckpArray - the reference, where the pointer to the new CK_BBOOL array will be stored |
|
487 |
* @param ckpLength - the reference, where the array length will be stored |
|
488 |
*/ |
|
489 |
void jBooleanArrayToCKBBoolArray(JNIEnv *env, const jbooleanArray jArray, CK_BBOOL **ckpArray, CK_ULONG_PTR ckpLength) |
|
490 |
{ |
|
491 |
jboolean* jpTemp; |
|
492 |
CK_ULONG i; |
|
493 |
||
494 |
if(jArray == NULL) { |
|
495 |
*ckpArray = NULL_PTR; |
|
496 |
*ckpLength = 0L; |
|
497 |
return; |
|
498 |
} |
|
499 |
*ckpLength = (*env)->GetArrayLength(env, jArray); |
|
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
500 |
jpTemp = (jboolean*) calloc(*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
|
501 |
if (jpTemp == NULL) { |
10798
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
502 |
throwOutOfMemoryError(env, 0); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
503 |
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
|
504 |
} |
2 | 505 |
(*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
|
506 |
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
|
507 |
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
|
508 |
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
|
509 |
} |
9994f4f08a59
6812738: SSL 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 |
|
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
511 |
*ckpArray = (CK_BBOOL*) calloc (*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
|
512 |
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
|
513 |
free(jpTemp); |
10798
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
514 |
throwOutOfMemoryError(env, 0); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
515 |
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
|
516 |
} |
2 | 517 |
for (i=0; i<(*ckpLength); i++) { |
518 |
(*ckpArray)[i] = jBooleanToCKBBool(jpTemp[i]); |
|
519 |
} |
|
520 |
free(jpTemp); |
|
521 |
} |
|
522 |
||
523 |
/* |
|
524 |
* converts a jbyteArray to a CK_BYTE array. The allocated memory has to be freed after use! |
|
525 |
* |
|
526 |
* @param env - used to call JNI funktions to get the array informtaion |
|
527 |
* @param jArray - the Java array to convert |
|
528 |
* @param ckpArray - the reference, where the pointer to the new CK_BYTE array will be stored |
|
529 |
* @param ckpLength - the reference, where the array length will be stored |
|
530 |
*/ |
|
531 |
void jByteArrayToCKByteArray(JNIEnv *env, const jbyteArray jArray, CK_BYTE_PTR *ckpArray, CK_ULONG_PTR ckpLength) |
|
532 |
{ |
|
533 |
jbyte* jpTemp; |
|
534 |
CK_ULONG i; |
|
535 |
||
536 |
if(jArray == NULL) { |
|
537 |
*ckpArray = NULL_PTR; |
|
538 |
*ckpLength = 0L; |
|
539 |
return; |
|
540 |
} |
|
541 |
*ckpLength = (*env)->GetArrayLength(env, jArray); |
|
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
542 |
jpTemp = (jbyte*) calloc(*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
|
543 |
if (jpTemp == NULL) { |
10798
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
544 |
throwOutOfMemoryError(env, 0); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
545 |
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
|
546 |
} |
2 | 547 |
(*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
|
548 |
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
|
549 |
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
|
550 |
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
|
551 |
} |
2 | 552 |
|
553 |
/* if CK_BYTE is the same size as jbyte, we save an additional copy */ |
|
554 |
if (sizeof(CK_BYTE) == sizeof(jbyte)) { |
|
555 |
*ckpArray = (CK_BYTE_PTR) jpTemp; |
|
556 |
} else { |
|
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
557 |
*ckpArray = (CK_BYTE_PTR) calloc (*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
|
558 |
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
|
559 |
free(jpTemp); |
10798
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
560 |
throwOutOfMemoryError(env, 0); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
561 |
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
|
562 |
} |
2 | 563 |
for (i=0; i<(*ckpLength); i++) { |
564 |
(*ckpArray)[i] = jByteToCKByte(jpTemp[i]); |
|
565 |
} |
|
566 |
free(jpTemp); |
|
567 |
} |
|
568 |
} |
|
569 |
||
570 |
/* |
|
571 |
* converts a jlongArray to a CK_ULONG array. The allocated memory has to be freed after use! |
|
572 |
* |
|
573 |
* @param env - used to call JNI funktions to get the array informtaion |
|
574 |
* @param jArray - the Java array to convert |
|
575 |
* @param ckpArray - the reference, where the pointer to the new CK_ULONG array will be stored |
|
576 |
* @param ckpLength - the reference, where the array length will be stored |
|
577 |
*/ |
|
578 |
void jLongArrayToCKULongArray(JNIEnv *env, const jlongArray jArray, CK_ULONG_PTR *ckpArray, CK_ULONG_PTR ckpLength) |
|
579 |
{ |
|
580 |
jlong* jTemp; |
|
581 |
CK_ULONG i; |
|
582 |
||
583 |
if(jArray == NULL) { |
|
584 |
*ckpArray = NULL_PTR; |
|
585 |
*ckpLength = 0L; |
|
586 |
return; |
|
587 |
} |
|
588 |
*ckpLength = (*env)->GetArrayLength(env, jArray); |
|
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
589 |
jTemp = (jlong*) calloc(*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
|
590 |
if (jTemp == NULL) { |
10798
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
591 |
throwOutOfMemoryError(env, 0); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
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 |
(*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
|
595 |
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
|
596 |
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
|
597 |
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
|
598 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
599 |
|
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
600 |
*ckpArray = (CK_ULONG_PTR) calloc(*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
|
601 |
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
|
602 |
free(jTemp); |
10798
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
603 |
throwOutOfMemoryError(env, 0); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
604 |
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
|
605 |
} |
2 | 606 |
for (i=0; i<(*ckpLength); i++) { |
607 |
(*ckpArray)[i] = jLongToCKULong(jTemp[i]); |
|
608 |
} |
|
609 |
free(jTemp); |
|
610 |
} |
|
611 |
||
612 |
/* |
|
613 |
* converts a jcharArray to a CK_CHAR array. The allocated memory has to be freed after use! |
|
614 |
* |
|
615 |
* @param env - used to call JNI funktions to get the array informtaion |
|
616 |
* @param jArray - the Java array to convert |
|
617 |
* @param ckpArray - the reference, where the pointer to the new CK_CHAR array will be stored |
|
618 |
* @param ckpLength - the reference, where the array length will be stored |
|
619 |
*/ |
|
620 |
void jCharArrayToCKCharArray(JNIEnv *env, const jcharArray jArray, CK_CHAR_PTR *ckpArray, CK_ULONG_PTR ckpLength) |
|
621 |
{ |
|
622 |
jchar* jpTemp; |
|
623 |
CK_ULONG i; |
|
624 |
||
625 |
if(jArray == NULL) { |
|
626 |
*ckpArray = NULL_PTR; |
|
627 |
*ckpLength = 0L; |
|
628 |
return; |
|
629 |
} |
|
630 |
*ckpLength = (*env)->GetArrayLength(env, jArray); |
|
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
631 |
jpTemp = (jchar*) calloc(*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
|
632 |
if (jpTemp == NULL) { |
10798
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
633 |
throwOutOfMemoryError(env, 0); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
634 |
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
|
635 |
} |
2 | 636 |
(*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
|
637 |
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
|
638 |
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
|
639 |
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
|
640 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
641 |
|
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
642 |
*ckpArray = (CK_CHAR_PTR) calloc (*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
|
643 |
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
|
644 |
free(jpTemp); |
10798
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
645 |
throwOutOfMemoryError(env, 0); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
646 |
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
|
647 |
} |
2 | 648 |
for (i=0; i<(*ckpLength); i++) { |
649 |
(*ckpArray)[i] = jCharToCKChar(jpTemp[i]); |
|
650 |
} |
|
651 |
free(jpTemp); |
|
652 |
} |
|
653 |
||
654 |
/* |
|
655 |
* converts a jcharArray to a CK_UTF8CHAR array. The allocated memory has to be freed after use! |
|
656 |
* |
|
657 |
* @param env - used to call JNI funktions to get the array informtaion |
|
658 |
* @param jArray - the Java array to convert |
|
659 |
* @param ckpArray - the reference, where the pointer to the new CK_UTF8CHAR array will be stored |
|
660 |
* @param ckpLength - the reference, where the array length will be stored |
|
661 |
*/ |
|
662 |
void jCharArrayToCKUTF8CharArray(JNIEnv *env, const jcharArray jArray, CK_UTF8CHAR_PTR *ckpArray, CK_ULONG_PTR ckpLength) |
|
663 |
{ |
|
664 |
jchar* jTemp; |
|
665 |
CK_ULONG i; |
|
666 |
||
667 |
if(jArray == NULL) { |
|
668 |
*ckpArray = NULL_PTR; |
|
669 |
*ckpLength = 0L; |
|
670 |
return; |
|
671 |
} |
|
672 |
*ckpLength = (*env)->GetArrayLength(env, jArray); |
|
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
673 |
jTemp = (jchar*) calloc(*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
|
674 |
if (jTemp == NULL) { |
10798
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
675 |
throwOutOfMemoryError(env, 0); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
676 |
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
|
677 |
} |
2 | 678 |
(*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
|
679 |
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
|
680 |
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
|
681 |
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
|
682 |
} |
9994f4f08a59
6812738: SSL 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 |
|
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
684 |
*ckpArray = (CK_UTF8CHAR_PTR) calloc(*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
|
685 |
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
|
686 |
free(jTemp); |
10798
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
687 |
throwOutOfMemoryError(env, 0); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
688 |
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
|
689 |
} |
2 | 690 |
for (i=0; i<(*ckpLength); i++) { |
691 |
(*ckpArray)[i] = jCharToCKUTF8Char(jTemp[i]); |
|
692 |
} |
|
693 |
free(jTemp); |
|
694 |
} |
|
695 |
||
696 |
/* |
|
697 |
* converts a jstring to a CK_CHAR array. The allocated memory has to be freed after use! |
|
698 |
* |
|
699 |
* @param env - used to call JNI funktions to get the array informtaion |
|
700 |
* @param jArray - the Java array to convert |
|
701 |
* @param ckpArray - the reference, where the pointer to the new CK_CHAR array will be stored |
|
702 |
* @param ckpLength - the reference, where the array length will be stored |
|
703 |
*/ |
|
704 |
void jStringToCKUTF8CharArray(JNIEnv *env, const jstring jArray, CK_UTF8CHAR_PTR *ckpArray, CK_ULONG_PTR ckpLength) |
|
705 |
{ |
|
706 |
const char* pCharArray; |
|
707 |
jboolean isCopy; |
|
708 |
||
709 |
if(jArray == NULL) { |
|
710 |
*ckpArray = NULL_PTR; |
|
711 |
*ckpLength = 0L; |
|
712 |
return; |
|
713 |
} |
|
714 |
||
715 |
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
|
716 |
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
|
717 |
|
40563
4bff68330f39
8074838: Resolve disabled warnings for libj2pkcs11
ascarpino
parents:
39142
diff
changeset
|
718 |
*ckpLength = (CK_ULONG) strlen(pCharArray); |
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
719 |
*ckpArray = (CK_UTF8CHAR_PTR) calloc(*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
|
720 |
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
|
721 |
(*env)->ReleaseStringUTFChars(env, (jstring) jArray, pCharArray); |
10798
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
722 |
throwOutOfMemoryError(env, 0); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
723 |
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
|
724 |
} |
2 | 725 |
strcpy((char*)*ckpArray, pCharArray); |
726 |
(*env)->ReleaseStringUTFChars(env, (jstring) jArray, pCharArray); |
|
727 |
} |
|
728 |
||
729 |
/* |
|
730 |
* converts a jobjectArray with Java Attributes to a CK_ATTRIBUTE array. The allocated memory |
|
731 |
* has to be freed after use! |
|
732 |
* |
|
733 |
* @param env - used to call JNI funktions to get the array informtaion |
|
734 |
* @param jArray - the Java Attribute array (template) to convert |
|
735 |
* @param ckpArray - the reference, where the pointer to the new CK_ATTRIBUTE array will be |
|
736 |
* stored |
|
737 |
* @param ckpLength - the reference, where the array length will be stored |
|
738 |
*/ |
|
739 |
void jAttributeArrayToCKAttributeArray(JNIEnv *env, jobjectArray jArray, CK_ATTRIBUTE_PTR *ckpArray, CK_ULONG_PTR ckpLength) |
|
740 |
{ |
|
741 |
CK_ULONG i; |
|
742 |
jlong jLength; |
|
743 |
jobject jAttribute; |
|
744 |
||
745 |
TRACE0("\nDEBUG: jAttributeArrayToCKAttributeArray"); |
|
746 |
if (jArray == NULL) { |
|
747 |
*ckpArray = NULL_PTR; |
|
748 |
*ckpLength = 0L; |
|
749 |
return; |
|
750 |
} |
|
751 |
jLength = (*env)->GetArrayLength(env, jArray); |
|
752 |
*ckpLength = jLongToCKULong(jLength); |
|
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
753 |
*ckpArray = (CK_ATTRIBUTE_PTR) calloc(*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
|
754 |
if (*ckpArray == NULL) { |
10798
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
755 |
throwOutOfMemoryError(env, 0); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
756 |
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
|
757 |
} |
58281
49836127542b
8231222: fix pkcs11 P11_DEBUG guarded native traces
mbaesken
parents:
57737
diff
changeset
|
758 |
TRACE1(", converting %lld attributes", (long long int) jLength); |
2 | 759 |
for (i=0; i<(*ckpLength); i++) { |
58281
49836127542b
8231222: fix pkcs11 P11_DEBUG guarded native traces
mbaesken
parents:
57737
diff
changeset
|
760 |
TRACE1(", getting %lu. attribute", i); |
2 | 761 |
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
|
762 |
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
|
763 |
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
|
764 |
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
|
765 |
} |
58281
49836127542b
8231222: fix pkcs11 P11_DEBUG guarded native traces
mbaesken
parents:
57737
diff
changeset
|
766 |
TRACE1(", jAttribute , converting %lu. attribute", i); |
2 | 767 |
(*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
|
768 |
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
|
769 |
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
|
770 |
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
|
771 |
} |
2 | 772 |
} |
773 |
TRACE0("FINISHED\n"); |
|
774 |
} |
|
775 |
||
776 |
/* |
|
777 |
* converts a CK_BYTE array and its length to a jbyteArray. |
|
778 |
* |
|
779 |
* @param env - used to call JNI funktions to create the new Java array |
|
780 |
* @param ckpArray - the pointer to the CK_BYTE array to convert |
|
781 |
* @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
|
782 |
* @return - the new Java byte array or NULL if error occurred |
2 | 783 |
*/ |
784 |
jbyteArray ckByteArrayToJByteArray(JNIEnv *env, const CK_BYTE_PTR ckpArray, CK_ULONG ckLength) |
|
785 |
{ |
|
786 |
CK_ULONG i; |
|
787 |
jbyte* jpTemp; |
|
788 |
jbyteArray jArray; |
|
789 |
||
790 |
/* if CK_BYTE is the same size as jbyte, we save an additional copy */ |
|
791 |
if (sizeof(CK_BYTE) == sizeof(jbyte)) { |
|
792 |
jpTemp = (jbyte*) ckpArray; |
|
793 |
} else { |
|
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
794 |
jpTemp = (jbyte*) calloc(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
|
795 |
if (jpTemp == NULL) { |
10798
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
796 |
throwOutOfMemoryError(env, 0); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
797 |
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
|
798 |
} |
2 | 799 |
for (i=0; i<ckLength; i++) { |
800 |
jpTemp[i] = ckByteToJByte(ckpArray[i]); |
|
801 |
} |
|
802 |
} |
|
803 |
||
804 |
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
|
805 |
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
|
806 |
(*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
|
807 |
} |
2 | 808 |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
809 |
if (sizeof(CK_BYTE) != sizeof(jbyte)) { free(jpTemp); } |
2 | 810 |
|
811 |
return jArray ; |
|
812 |
} |
|
813 |
||
814 |
/* |
|
815 |
* converts a CK_ULONG array and its length to a jlongArray. |
|
816 |
* |
|
817 |
* @param env - used to call JNI funktions to create the new Java array |
|
818 |
* @param ckpArray - the pointer to the CK_ULONG array to convert |
|
819 |
* @param ckpLength - the length of the array to convert |
|
820 |
* @return - the new Java long array |
|
821 |
*/ |
|
822 |
jlongArray ckULongArrayToJLongArray(JNIEnv *env, const CK_ULONG_PTR ckpArray, CK_ULONG ckLength) |
|
823 |
{ |
|
824 |
CK_ULONG i; |
|
825 |
jlong* jpTemp; |
|
826 |
jlongArray jArray; |
|
827 |
||
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
828 |
jpTemp = (jlong*) calloc(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
|
829 |
if (jpTemp == NULL) { |
10798
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
830 |
throwOutOfMemoryError(env, 0); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
831 |
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
|
832 |
} |
2 | 833 |
for (i=0; i<ckLength; i++) { |
834 |
jpTemp[i] = ckLongToJLong(ckpArray[i]); |
|
835 |
} |
|
836 |
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
|
837 |
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
|
838 |
(*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
|
839 |
} |
2 | 840 |
free(jpTemp); |
841 |
||
842 |
return jArray ; |
|
843 |
} |
|
844 |
||
845 |
/* |
|
846 |
* converts a CK_CHAR array and its length to a jcharArray. |
|
847 |
* |
|
848 |
* @param env - used to call JNI funktions to create the new Java array |
|
849 |
* @param ckpArray - the pointer to the CK_CHAR array to convert |
|
850 |
* @param ckpLength - the length of the array to convert |
|
851 |
* @return - the new Java char array |
|
852 |
*/ |
|
853 |
jcharArray ckCharArrayToJCharArray(JNIEnv *env, const CK_CHAR_PTR ckpArray, CK_ULONG ckLength) |
|
854 |
{ |
|
855 |
CK_ULONG i; |
|
856 |
jchar* jpTemp; |
|
857 |
jcharArray jArray; |
|
858 |
||
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
859 |
jpTemp = (jchar*) calloc(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
|
860 |
if (jpTemp == NULL) { |
10798
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
861 |
throwOutOfMemoryError(env, 0); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
862 |
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
|
863 |
} |
2 | 864 |
for (i=0; i<ckLength; i++) { |
865 |
jpTemp[i] = ckCharToJChar(ckpArray[i]); |
|
866 |
} |
|
867 |
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
|
868 |
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
|
869 |
(*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
|
870 |
} |
2 | 871 |
free(jpTemp); |
872 |
||
873 |
return jArray ; |
|
874 |
} |
|
875 |
||
876 |
/* |
|
877 |
* converts a CK_UTF8CHAR array and its length to a jcharArray. |
|
878 |
* |
|
879 |
* @param env - used to call JNI funktions to create the new Java array |
|
880 |
* @param ckpArray - the pointer to the CK_UTF8CHAR array to convert |
|
881 |
* @param ckpLength - the length of the array to convert |
|
882 |
* @return - the new Java char array |
|
883 |
*/ |
|
884 |
jcharArray ckUTF8CharArrayToJCharArray(JNIEnv *env, const CK_UTF8CHAR_PTR ckpArray, CK_ULONG ckLength) |
|
885 |
{ |
|
886 |
CK_ULONG i; |
|
887 |
jchar* jpTemp; |
|
888 |
jcharArray jArray; |
|
889 |
||
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
890 |
jpTemp = (jchar*) calloc(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
|
891 |
if (jpTemp == NULL) { |
10798
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
892 |
throwOutOfMemoryError(env, 0); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
893 |
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
|
894 |
} |
2 | 895 |
for (i=0; i<ckLength; i++) { |
896 |
jpTemp[i] = ckUTF8CharToJChar(ckpArray[i]); |
|
897 |
} |
|
898 |
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
|
899 |
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
|
900 |
(*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
|
901 |
} |
2 | 902 |
free(jpTemp); |
903 |
||
904 |
return jArray ; |
|
905 |
} |
|
906 |
||
907 |
/* |
|
908 |
* the following functions convert Java objects to PKCS#11 pointers and the |
|
909 |
* length in bytes and vice versa |
|
910 |
* |
|
911 |
* CK_<Type>_PTR j<Object>ToCK<Type>Ptr(JNIEnv *env, jobject jObject); |
|
912 |
* |
|
913 |
* jobject ck<Type>PtrToJ<Object>(JNIEnv *env, const CK_<Type>_PTR ckpValue); |
|
914 |
* |
|
915 |
* The functions that convert a Java object to a PKCS#11 pointer first allocate |
|
916 |
* the memory for the PKCS#11 pointer. Then they set each element corresponding |
|
917 |
* to the fields in the Java object to convert. After use the allocated memory of |
|
918 |
* the PKCS#11 pointer has to be explicitly freed. |
|
919 |
* |
|
920 |
* The functions to convert a PKCS#11 pointer to a Java object create a new Java |
|
921 |
* object first and than they set all fields in the object depending on the values |
|
922 |
* of the type or structure where the PKCS#11 pointer points to. |
|
923 |
*/ |
|
924 |
||
925 |
/* |
|
926 |
* converts a CK_BBOOL pointer to a Java boolean Object. |
|
927 |
* |
|
928 |
* @param env - used to call JNI funktions to create the new Java object |
|
929 |
* @param ckpValue - the pointer to the CK_BBOOL value |
|
930 |
* @return - the new Java boolean object with the boolean value |
|
931 |
*/ |
|
932 |
jobject ckBBoolPtrToJBooleanObject(JNIEnv *env, const CK_BBOOL *ckpValue) |
|
933 |
{ |
|
934 |
jclass jValueObjectClass; |
|
935 |
jmethodID jConstructor; |
|
936 |
jobject jValueObject; |
|
937 |
jboolean jValue; |
|
938 |
||
939 |
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
|
940 |
if (jValueObjectClass == NULL) { return NULL; } |
2 | 941 |
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
|
942 |
if (jConstructor == NULL) { return NULL; } |
2 | 943 |
jValue = ckBBoolToJBoolean(*ckpValue); |
944 |
jValueObject = (*env)->NewObject(env, jValueObjectClass, jConstructor, jValue); |
|
945 |
||
946 |
return jValueObject ; |
|
947 |
} |
|
948 |
||
949 |
/* |
|
950 |
* converts a CK_ULONG pointer to a Java long Object. |
|
951 |
* |
|
952 |
* @param env - used to call JNI funktions to create the new Java object |
|
953 |
* @param ckpValue - the pointer to the CK_ULONG value |
|
954 |
* @return - the new Java long object with the long value |
|
955 |
*/ |
|
956 |
jobject ckULongPtrToJLongObject(JNIEnv *env, const CK_ULONG_PTR ckpValue) |
|
957 |
{ |
|
958 |
jclass jValueObjectClass; |
|
959 |
jmethodID jConstructor; |
|
960 |
jobject jValueObject; |
|
961 |
jlong jValue; |
|
962 |
||
963 |
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
|
964 |
if (jValueObjectClass == NULL) { return NULL; } |
2 | 965 |
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
|
966 |
if (jConstructor == NULL) { return NULL; } |
2 | 967 |
jValue = ckULongToJLong(*ckpValue); |
968 |
jValueObject = (*env)->NewObject(env, jValueObjectClass, jConstructor, jValue); |
|
969 |
||
970 |
return jValueObject ; |
|
971 |
} |
|
972 |
||
973 |
/* |
|
974 |
* converts a Java boolean object into a pointer to a CK_BBOOL value. The memory has to be |
|
975 |
* freed after use! |
|
976 |
* |
|
977 |
* @param env - used to call JNI funktions to get the value out of the Java object |
|
978 |
* @param jObject - the "java/lang/Boolean" object to convert |
|
979 |
* @return - the pointer to the new CK_BBOOL value |
|
980 |
*/ |
|
981 |
CK_BBOOL* jBooleanObjectToCKBBoolPtr(JNIEnv *env, jobject jObject) |
|
982 |
{ |
|
983 |
jclass jObjectClass; |
|
984 |
jmethodID jValueMethod; |
|
985 |
jboolean jValue; |
|
986 |
CK_BBOOL *ckpValue; |
|
987 |
||
988 |
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
|
989 |
if (jObjectClass == NULL) { return NULL; } |
2 | 990 |
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
|
991 |
if (jValueMethod == NULL) { return NULL; } |
2 | 992 |
jValue = (*env)->CallBooleanMethod(env, jObject, jValueMethod); |
993 |
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
|
994 |
if (ckpValue == NULL) { |
10798
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
995 |
throwOutOfMemoryError(env, 0); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
996 |
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
|
997 |
} |
2 | 998 |
*ckpValue = jBooleanToCKBBool(jValue); |
999 |
||
1000 |
return ckpValue ; |
|
1001 |
} |
|
1002 |
||
1003 |
/* |
|
1004 |
* converts a Java byte object into a pointer to a CK_BYTE value. The memory has to be |
|
1005 |
* freed after use! |
|
1006 |
* |
|
1007 |
* @param env - used to call JNI funktions to get the value out of the Java object |
|
1008 |
* @param jObject - the "java/lang/Byte" object to convert |
|
1009 |
* @return - the pointer to the new CK_BYTE value |
|
1010 |
*/ |
|
1011 |
CK_BYTE_PTR jByteObjectToCKBytePtr(JNIEnv *env, jobject jObject) |
|
1012 |
{ |
|
1013 |
jclass jObjectClass; |
|
1014 |
jmethodID jValueMethod; |
|
1015 |
jbyte jValue; |
|
1016 |
CK_BYTE_PTR ckpValue; |
|
1017 |
||
1018 |
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
|
1019 |
if (jObjectClass == NULL) { return NULL; } |
2 | 1020 |
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
|
1021 |
if (jValueMethod == NULL) { return NULL; } |
2 | 1022 |
jValue = (*env)->CallByteMethod(env, jObject, jValueMethod); |
1023 |
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
|
1024 |
if (ckpValue == NULL) { |
10798
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
1025 |
throwOutOfMemoryError(env, 0); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1026 |
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
|
1027 |
} |
2 | 1028 |
*ckpValue = jByteToCKByte(jValue); |
1029 |
return ckpValue ; |
|
1030 |
} |
|
1031 |
||
1032 |
/* |
|
1033 |
* converts a Java integer object into a pointer to a CK_ULONG value. The memory has to be |
|
1034 |
* freed after use! |
|
1035 |
* |
|
1036 |
* @param env - used to call JNI funktions to get the value out of the Java object |
|
1037 |
* @param jObject - the "java/lang/Integer" object to convert |
|
1038 |
* @return - the pointer to the new CK_ULONG value |
|
1039 |
*/ |
|
1040 |
CK_ULONG* jIntegerObjectToCKULongPtr(JNIEnv *env, jobject jObject) |
|
1041 |
{ |
|
1042 |
jclass jObjectClass; |
|
1043 |
jmethodID jValueMethod; |
|
1044 |
jint jValue; |
|
1045 |
CK_ULONG *ckpValue; |
|
1046 |
||
1047 |
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
|
1048 |
if (jObjectClass == NULL) { return NULL; } |
2 | 1049 |
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
|
1050 |
if (jValueMethod == NULL) { return NULL; } |
2 | 1051 |
jValue = (*env)->CallIntMethod(env, jObject, jValueMethod); |
1052 |
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
|
1053 |
if (ckpValue == NULL) { |
10798
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
1054 |
throwOutOfMemoryError(env, 0); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1055 |
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
|
1056 |
} |
2 | 1057 |
*ckpValue = jLongToCKLong(jValue); |
1058 |
return ckpValue ; |
|
1059 |
} |
|
1060 |
||
1061 |
/* |
|
1062 |
* converts a Java long object into a pointer to a CK_ULONG value. The memory has to be |
|
1063 |
* freed after use! |
|
1064 |
* |
|
1065 |
* @param env - used to call JNI funktions to get the value out of the Java object |
|
1066 |
* @param jObject - the "java/lang/Long" object to convert |
|
1067 |
* @return - the pointer to the new CK_ULONG value |
|
1068 |
*/ |
|
1069 |
CK_ULONG* jLongObjectToCKULongPtr(JNIEnv *env, jobject jObject) |
|
1070 |
{ |
|
1071 |
jclass jObjectClass; |
|
1072 |
jmethodID jValueMethod; |
|
1073 |
jlong jValue; |
|
1074 |
CK_ULONG *ckpValue; |
|
1075 |
||
1076 |
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
|
1077 |
if (jObjectClass == NULL) { return NULL; } |
2 | 1078 |
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
|
1079 |
if (jValueMethod == NULL) { return NULL; } |
2 | 1080 |
jValue = (*env)->CallLongMethod(env, jObject, jValueMethod); |
1081 |
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
|
1082 |
if (ckpValue == NULL) { |
10798
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
1083 |
throwOutOfMemoryError(env, 0); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1084 |
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
|
1085 |
} |
2 | 1086 |
*ckpValue = jLongToCKULong(jValue); |
1087 |
||
1088 |
return ckpValue ; |
|
1089 |
} |
|
1090 |
||
1091 |
/* |
|
1092 |
* converts a Java char object into a pointer to a CK_CHAR value. The memory has to be |
|
1093 |
* freed after use! |
|
1094 |
* |
|
1095 |
* @param env - used to call JNI funktions to get the value out of the Java object |
|
1096 |
* @param jObject - the "java/lang/Char" object to convert |
|
1097 |
* @return - the pointer to the new CK_CHAR value |
|
1098 |
*/ |
|
1099 |
CK_CHAR_PTR jCharObjectToCKCharPtr(JNIEnv *env, jobject jObject) |
|
1100 |
{ |
|
1101 |
jclass jObjectClass; |
|
1102 |
jmethodID jValueMethod; |
|
1103 |
jchar jValue; |
|
1104 |
CK_CHAR_PTR ckpValue; |
|
1105 |
||
1106 |
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
|
1107 |
if (jObjectClass == NULL) { return NULL; } |
2 | 1108 |
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
|
1109 |
if (jValueMethod == NULL) { return NULL; } |
2 | 1110 |
jValue = (*env)->CallCharMethod(env, jObject, jValueMethod); |
1111 |
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
|
1112 |
if (ckpValue == NULL) { |
10798
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
1113 |
throwOutOfMemoryError(env, 0); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1114 |
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
|
1115 |
} |
2 | 1116 |
*ckpValue = jCharToCKChar(jValue); |
1117 |
||
1118 |
return ckpValue ; |
|
1119 |
} |
|
1120 |
||
1121 |
/* |
|
1122 |
* converts a Java object into a pointer to CK-type or a CK-structure with the length in Bytes. |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1123 |
* The memory of the returned pointer MUST BE FREED BY CALLER! |
2 | 1124 |
* |
1125 |
* @param env - used to call JNI funktions to get the Java classes and objects |
|
1126 |
* @param jObject - the Java object to convert |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1127 |
* @param ckpLength - pointer to the length (bytes) of the newly-allocated CK-value or CK-structure |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1128 |
* @return ckpObject - pointer to the newly-allocated CK-value or CK-structure |
2 | 1129 |
*/ |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1130 |
CK_VOID_PTR jObjectToPrimitiveCKObjectPtr(JNIEnv *env, jobject jObject, CK_ULONG *ckpLength) |
2 | 1131 |
{ |
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
|
1132 |
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
|
1133 |
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
|
1134 |
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
|
1135 |
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
|
1136 |
jclass jObjectClass, jClassClass; |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1137 |
CK_VOID_PTR ckpObject; |
2 | 1138 |
jmethodID jMethod; |
1139 |
jobject jClassObject; |
|
1140 |
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
|
1141 |
char *classNameString, *exceptionMsgPrefix, *exceptionMsg; |
2 | 1142 |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1143 |
TRACE0("\nDEBUG: jObjectToPrimitiveCKObjectPtr"); |
2 | 1144 |
if (jObject == NULL) { |
1145 |
*ckpLength = 0; |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1146 |
return NULL; |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1147 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1148 |
|
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1149 |
jLongClass = (*env)->FindClass(env, "java/lang/Long"); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1150 |
if (jLongClass == NULL) { return NULL; } |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1151 |
if ((*env)->IsInstanceOf(env, jObject, jLongClass)) { |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1152 |
ckpObject = jLongObjectToCKULongPtr(env, jObject); |
2 | 1153 |
*ckpLength = sizeof(CK_ULONG); |
58281
49836127542b
8231222: fix pkcs11 P11_DEBUG guarded native traces
mbaesken
parents:
57737
diff
changeset
|
1154 |
TRACE1("<converted long value %lu>", *((CK_ULONG *) ckpObject)); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1155 |
return ckpObject; |
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
|
1156 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1157 |
|
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1158 |
jBooleanClass = (*env)->FindClass(env, "java/lang/Boolean"); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1159 |
if (jBooleanClass == NULL) { return NULL; } |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1160 |
if ((*env)->IsInstanceOf(env, jObject, jBooleanClass)) { |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1161 |
ckpObject = jBooleanObjectToCKBBoolPtr(env, jObject); |
2 | 1162 |
*ckpLength = sizeof(CK_BBOOL); |
1163 |
TRACE0(" <converted boolean value "); |
|
58281
49836127542b
8231222: fix pkcs11 P11_DEBUG guarded native traces
mbaesken
parents:
57737
diff
changeset
|
1164 |
TRACE0((*((CK_BBOOL *) ckpObject) == TRUE) ? "TRUE>" : "FALSE>"); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1165 |
return ckpObject; |
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
|
1166 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1167 |
|
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1168 |
jByteArrayClass = (*env)->FindClass(env, "[B"); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1169 |
if (jByteArrayClass == NULL) { return NULL; } |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1170 |
if ((*env)->IsInstanceOf(env, jObject, jByteArrayClass)) { |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1171 |
jByteArrayToCKByteArray(env, jObject, (CK_BYTE_PTR*) &ckpObject, ckpLength); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1172 |
return ckpObject; |
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
|
1173 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1174 |
|
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1175 |
jCharArrayClass = (*env)->FindClass(env, "[C"); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1176 |
if (jCharArrayClass == NULL) { return NULL; } |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1177 |
if ((*env)->IsInstanceOf(env, jObject, jCharArrayClass)) { |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1178 |
jCharArrayToCKUTF8CharArray(env, jObject, (CK_UTF8CHAR_PTR*) &ckpObject, ckpLength); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1179 |
return ckpObject; |
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
|
1180 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1181 |
|
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1182 |
jByteClass = (*env)->FindClass(env, "java/lang/Byte"); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1183 |
if (jByteClass == NULL) { return NULL; } |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1184 |
if ((*env)->IsInstanceOf(env, jObject, jByteClass)) { |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1185 |
ckpObject = jByteObjectToCKBytePtr(env, jObject); |
2 | 1186 |
*ckpLength = sizeof(CK_BYTE); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1187 |
TRACE1("<converted byte value %X>", *((CK_BYTE *) ckpObject)); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1188 |
return ckpObject; |
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
|
1189 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1190 |
|
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1191 |
jDateClass = (*env)->FindClass(env, CLASS_DATE); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1192 |
if (jDateClass == NULL) { return NULL; } |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1193 |
if ((*env)->IsInstanceOf(env, jObject, jDateClass)) { |
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
1194 |
ckpObject = jDateObjectToCKDatePtr(env, jObject); |
2 | 1195 |
*ckpLength = sizeof(CK_DATE); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1196 |
TRACE3("<converted date value %.4s-%.2s-%.2s>", ((CK_DATE *) ckpObject)->year, |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1197 |
((CK_DATE *) ckpObject)->month, ((CK_DATE *) ckpObject)->day); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1198 |
return ckpObject; |
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
|
1199 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1200 |
|
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1201 |
jCharacterClass = (*env)->FindClass(env, "java/lang/Character"); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1202 |
if (jCharacterClass == NULL) { return NULL; } |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1203 |
if ((*env)->IsInstanceOf(env, jObject, jCharacterClass)) { |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1204 |
ckpObject = jCharObjectToCKCharPtr(env, jObject); |
2 | 1205 |
*ckpLength = sizeof(CK_UTF8CHAR); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1206 |
TRACE1("<converted char value %c>", *((CK_CHAR *) ckpObject)); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1207 |
return ckpObject; |
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
|
1208 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1209 |
|
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1210 |
jIntegerClass = (*env)->FindClass(env, "java/lang/Integer"); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1211 |
if (jIntegerClass == NULL) { return NULL; } |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1212 |
if ((*env)->IsInstanceOf(env, jObject, jIntegerClass)) { |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1213 |
ckpObject = jIntegerObjectToCKULongPtr(env, jObject); |
2 | 1214 |
*ckpLength = sizeof(CK_ULONG); |
58281
49836127542b
8231222: fix pkcs11 P11_DEBUG guarded native traces
mbaesken
parents:
57737
diff
changeset
|
1215 |
TRACE1("<converted integer value %lu>", *((CK_ULONG *) ckpObject)); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1216 |
return ckpObject; |
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
|
1217 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1218 |
|
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1219 |
jBooleanArrayClass = (*env)->FindClass(env, "[Z"); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1220 |
if (jBooleanArrayClass == NULL) { return NULL; } |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1221 |
if ((*env)->IsInstanceOf(env, jObject, jBooleanArrayClass)) { |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1222 |
jBooleanArrayToCKBBoolArray(env, jObject, (CK_BBOOL**) &ckpObject, ckpLength); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1223 |
return ckpObject; |
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
|
1224 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1225 |
|
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1226 |
jIntArrayClass = (*env)->FindClass(env, "[I"); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1227 |
if (jIntArrayClass == NULL) { return NULL; } |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1228 |
if ((*env)->IsInstanceOf(env, jObject, jIntArrayClass)) { |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1229 |
jLongArrayToCKULongArray(env, jObject, (CK_ULONG_PTR*) &ckpObject, ckpLength); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1230 |
return ckpObject; |
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
|
1231 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1232 |
|
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1233 |
jLongArrayClass = (*env)->FindClass(env, "[J"); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1234 |
if (jLongArrayClass == NULL) { return NULL; } |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1235 |
if ((*env)->IsInstanceOf(env, jObject, jLongArrayClass)) { |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1236 |
jLongArrayToCKULongArray(env, jObject, (CK_ULONG_PTR*) &ckpObject, ckpLength); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1237 |
return ckpObject; |
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
|
1238 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1239 |
|
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1240 |
jStringClass = (*env)->FindClass(env, "java/lang/String"); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1241 |
if (jStringClass == NULL) { return NULL; } |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1242 |
if ((*env)->IsInstanceOf(env, jObject, jStringClass)) { |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1243 |
jStringToCKUTF8CharArray(env, jObject, (CK_UTF8CHAR_PTR*) &ckpObject, ckpLength); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1244 |
return ckpObject; |
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
|
1245 |
} |
2 | 1246 |
|
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
|
1247 |
/* 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
|
1248 |
jObjectClass = (*env)->FindClass(env, "java/lang/Object"); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1249 |
if (jObjectClass == NULL) { return NULL; } |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1250 |
jMethod = (*env)->GetMethodID(env, jObjectClass, "getClass", "()Ljava/lang/Class;"); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1251 |
if (jMethod == NULL) { return NULL; } |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1252 |
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
|
1253 |
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
|
1254 |
jClassClass = (*env)->FindClass(env, "java/lang/Class"); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1255 |
if (jClassClass == NULL) { return NULL; } |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1256 |
jMethod = (*env)->GetMethodID(env, jClassClass, "getName", "()Ljava/lang/String;"); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1257 |
if (jMethod == NULL) { return NULL; } |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1258 |
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
|
1259 |
(*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
|
1260 |
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
|
1261 |
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
|
1262 |
(*env)->GetStringUTFChars(env, jClassNameString, NULL); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1263 |
if (classNameString == NULL) { return NULL; } |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1264 |
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
|
1265 |
exceptionMsg = (char *) |
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
1266 |
malloc(strlen(exceptionMsgPrefix) + strlen(classNameString) + 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
|
1267 |
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
|
1268 |
(*env)->ReleaseStringUTFChars(env, jClassNameString, classNameString); |
10798
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
1269 |
throwOutOfMemoryError(env, 0); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1270 |
return NULL; |
2 | 1271 |
} |
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
|
1272 |
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
|
1273 |
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
|
1274 |
(*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
|
1275 |
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
|
1276 |
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
|
1277 |
*ckpLength = 0; |
2 | 1278 |
|
1279 |
TRACE0("FINISHED\n"); |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
1280 |
return NULL; |
2 | 1281 |
} |
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
|
1282 |
|
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1283 |
#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
|
1284 |
|
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1285 |
#undef malloc |
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
1286 |
#undef calloc |
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
|
1287 |
#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
|
1288 |
|
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1289 |
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
|
1290 |
void *p = malloc(c); |
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
1291 |
fprintf(stdout, "malloc\t%08lX\t%lX\t%s:%d\n", ptr_to_jlong(p), c, file, line); |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
1292 |
fflush(stdout); |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
1293 |
return p; |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
1294 |
} |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
1295 |
|
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
1296 |
void *p11calloc(size_t c, size_t s, char *file, int line) { |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
1297 |
void *p = calloc(c, s); |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
1298 |
fprintf(stdout, "calloc\t%08lX\t%lX\t%lX\t%s:%d\n", ptr_to_jlong(p), c, s, file, line); |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
1299 |
fflush(stdout); |
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
|
1300 |
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
|
1301 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1302 |
|
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1303 |
void p11free(void *p, char *file, int line) { |
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
1304 |
fprintf(stdout, "free\t%08lX\t\t%s:%d\n", ptr_to_jlong(p), file, line); |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
1305 |
fflush(stdout); |
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
|
1306 |
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
|
1307 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1308 |
|
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
1309 |
#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
|
1310 |
|
39142
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
1311 |
// prints a message to stdout if debug output is enabled |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
1312 |
void printDebug(const char *format, ...) { |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
1313 |
if (debug == JNI_TRUE) { |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
1314 |
va_list args; |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
1315 |
fprintf(stdout, "sunpkcs11: "); |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
1316 |
va_start(args, format); |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
1317 |
vfprintf(stdout, format, args); |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
1318 |
va_end(args); |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
1319 |
fflush(stdout); |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
1320 |
} |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
1321 |
} |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
1322 |