author | ohair |
Tue, 25 May 2010 15:58:33 -0700 | |
changeset 5506 | 202f599c92aa |
parent 3321 | fed33393bc52 |
child 10798 | 413b731e1818 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 2003, 2009, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
*/ |
4 |
||
5 |
/* Copyright (c) 2002 Graz University of Technology. All rights reserved. |
|
6 |
* |
|
7 |
* Redistribution and use in source and binary forms, with or without |
|
8 |
* modification, are permitted provided that the following conditions are met: |
|
9 |
* |
|
10 |
* 1. Redistributions of source code must retain the above copyright notice, |
|
11 |
* this list of conditions and the following disclaimer. |
|
12 |
* |
|
13 |
* 2. Redistributions in binary form must reproduce the above copyright notice, |
|
14 |
* this list of conditions and the following disclaimer in the documentation |
|
15 |
* and/or other materials provided with the distribution. |
|
16 |
* |
|
17 |
* 3. The end-user documentation included with the redistribution, if any, must |
|
18 |
* include the following acknowledgment: |
|
19 |
* |
|
20 |
* "This product includes software developed by IAIK of Graz University of |
|
21 |
* Technology." |
|
22 |
* |
|
23 |
* Alternately, this acknowledgment may appear in the software itself, if |
|
24 |
* and wherever such third-party acknowledgments normally appear. |
|
25 |
* |
|
26 |
* 4. The names "Graz University of Technology" and "IAIK of Graz University of |
|
27 |
* Technology" must not be used to endorse or promote products derived from |
|
28 |
* this software without prior written permission. |
|
29 |
* |
|
30 |
* 5. Products derived from this software may not be called |
|
31 |
* "IAIK PKCS Wrapper", nor may "IAIK" appear in their name, without prior |
|
32 |
* written permission of Graz University of Technology. |
|
33 |
* |
|
34 |
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED |
|
35 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
36 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
37 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LICENSOR BE |
|
38 |
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, |
|
39 |
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
40 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, |
|
41 |
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
|
42 |
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
|
43 |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|
44 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
45 |
* POSSIBILITY OF SUCH DAMAGE. |
|
46 |
*/ |
|
47 |
||
48 |
#include "pkcs11wrapper.h" |
|
49 |
||
50 |
#include <stdio.h> |
|
51 |
#include <stdlib.h> |
|
52 |
#include <string.h> |
|
53 |
#include <assert.h> |
|
54 |
||
55 |
#include "sun_security_pkcs11_wrapper_PKCS11.h" |
|
56 |
||
57 |
/* declare file private functions */ |
|
58 |
||
59 |
void prefetchFields(JNIEnv *env, jclass thisClass); |
|
60 |
jobject ckInfoPtrToJInfo(JNIEnv *env, const CK_INFO_PTR ckpInfo); |
|
61 |
jobject ckSlotInfoPtrToJSlotInfo(JNIEnv *env, const CK_SLOT_INFO_PTR ckpSlotInfo); |
|
62 |
jobject ckTokenInfoPtrToJTokenInfo(JNIEnv *env, const CK_TOKEN_INFO_PTR ckpTokenInfo); |
|
63 |
jobject ckMechanismInfoPtrToJMechanismInfo(JNIEnv *env, const CK_MECHANISM_INFO_PTR ckpMechanismInfo); |
|
64 |
||
65 |
/* define variables */ |
|
66 |
||
67 |
jfieldID pNativeDataID; |
|
68 |
jfieldID mech_mechanismID; |
|
69 |
jfieldID mech_pParameterID; |
|
70 |
||
71 |
jclass jByteArrayClass; |
|
72 |
jclass jLongClass; |
|
73 |
||
74 |
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { |
|
75 |
return JNI_VERSION_1_4; |
|
76 |
} |
|
77 |
||
78 |
/* ************************************************************************** */ |
|
79 |
/* The native implementation of the methods of the PKCS11Implementation class */ |
|
80 |
/* ************************************************************************** */ |
|
81 |
||
82 |
/* |
|
83 |
* This method is used to do static initialization. This method is static and |
|
84 |
* synchronized. Summary: use this method like a static initialization block. |
|
85 |
* |
|
86 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
87 |
* Method: initializeLibrary |
|
88 |
* Signature: ()V |
|
89 |
*/ |
|
90 |
JNIEXPORT void JNICALL |
|
91 |
Java_sun_security_pkcs11_wrapper_PKCS11_initializeLibrary |
|
92 |
(JNIEnv *env, jclass thisClass) |
|
93 |
{ |
|
94 |
#ifndef NO_CALLBACKS |
|
95 |
if (notifyListLock == NULL) { |
|
96 |
notifyListLock = createLockObject(env); |
|
97 |
} |
|
98 |
#endif |
|
99 |
||
100 |
prefetchFields(env, thisClass); |
|
101 |
} |
|
102 |
||
103 |
jclass fetchClass(JNIEnv *env, const char *name) { |
|
104 |
jclass tmpClass = (*env)->FindClass(env, name); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
105 |
if (tmpClass == NULL) { return NULL; } |
2 | 106 |
return (*env)->NewGlobalRef(env, tmpClass); |
107 |
} |
|
108 |
||
109 |
void prefetchFields(JNIEnv *env, jclass thisClass) { |
|
110 |
jclass tmpClass; |
|
111 |
||
112 |
/* PKCS11 */ |
|
113 |
pNativeDataID = (*env)->GetFieldID(env, thisClass, "pNativeData", "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
|
114 |
if (pNativeDataID == NULL) { return; } |
2 | 115 |
|
116 |
/* CK_MECHANISM */ |
|
117 |
tmpClass = (*env)->FindClass(env, CLASS_MECHANISM); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
118 |
if (tmpClass == NULL) { return; } |
2 | 119 |
mech_mechanismID = (*env)->GetFieldID(env, tmpClass, "mechanism", "J"); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
120 |
if (mech_mechanismID == NULL) { return; } |
2 | 121 |
mech_pParameterID = (*env)->GetFieldID(env, tmpClass, "pParameter", |
122 |
"Ljava/lang/Object;"); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
123 |
if (mech_pParameterID == NULL) { return; } |
2 | 124 |
jByteArrayClass = fetchClass(env, "[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
|
125 |
if (jByteArrayClass == NULL) { return; } |
2 | 126 |
jLongClass = fetchClass(env, "java/lang/Long"); |
127 |
} |
|
128 |
||
129 |
/* This method is designed to do a clean-up. It releases all global resources |
|
130 |
* of this library. By now, this function is not called. Calling from |
|
131 |
* JNI_OnUnload would be an option, but some VMs do not support JNI_OnUnload. |
|
132 |
* |
|
133 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
134 |
* Method: finalizeLibrary |
|
135 |
* Signature: ()V |
|
136 |
*/ |
|
137 |
JNIEXPORT void JNICALL |
|
138 |
Java_sun_security_pkcs11_wrapper_PKCS11_finalizeLibrary |
|
139 |
(JNIEnv *env, jclass thisClass) |
|
140 |
{ |
|
141 |
/* XXX |
|
142 |
* remove all left lists and release the resources and the lock |
|
143 |
* objects that synchroniz access to these lists. |
|
144 |
* |
|
145 |
removeAllModuleEntries(env); |
|
146 |
if (moduleListHead == NULL) { * check, if we removed the last active module * |
|
147 |
* remove also the moduleListLock, it is no longer used * |
|
148 |
if (moduleListLock != NULL) { |
|
149 |
destroyLockObject(env, moduleListLock); |
|
150 |
moduleListLock = NULL; |
|
151 |
} |
|
152 |
#ifndef NO_CALLBACKS |
|
153 |
* remove all left notify callback entries * |
|
154 |
while (removeFirstNotifyEntry(env)); |
|
155 |
* remove also the notifyListLock, it is no longer used * |
|
156 |
if (notifyListLock != NULL) { |
|
157 |
destroyLockObject(env, notifyListLock); |
|
158 |
notifyListLock = NULL; |
|
159 |
} |
|
160 |
if (jInitArgsObject != NULL) { |
|
161 |
(*env)->DeleteGlobalRef(env, jInitArgsObject); |
|
162 |
} |
|
163 |
if (ckpGlobalInitArgs != NULL_PTR) { |
|
164 |
free(ckpGlobalInitArgs); |
|
165 |
} |
|
166 |
#endif * NO_CALLBACKS * |
|
167 |
} |
|
168 |
*/ |
|
169 |
} |
|
170 |
||
171 |
#ifdef P11_ENABLE_C_INITIALIZE |
|
172 |
/* |
|
173 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
174 |
* Method: C_Initialize |
|
175 |
* Signature: (Ljava/lang/Object;)V |
|
176 |
* Parametermapping: *PKCS11* |
|
177 |
* @param jobject jInitArgs CK_VOID_PTR pInitArgs |
|
178 |
*/ |
|
179 |
JNIEXPORT void JNICALL |
|
180 |
Java_sun_security_pkcs11_wrapper_PKCS11_C_1Initialize |
|
181 |
(JNIEnv *env, jobject obj, jobject jInitArgs) |
|
182 |
{ |
|
183 |
/* |
|
184 |
* Initalize Cryptoki |
|
185 |
*/ |
|
186 |
CK_C_INITIALIZE_ARGS_PTR ckpInitArgs; |
|
187 |
CK_RV rv; |
|
188 |
CK_FUNCTION_LIST_PTR ckpFunctions; |
|
189 |
||
190 |
TRACE0("DEBUG: initializing module... "); |
|
191 |
||
192 |
ckpFunctions = getFunctionList(env, obj); |
|
193 |
if (ckpFunctions == NULL) { |
|
194 |
TRACE0("failed getting module entry"); |
|
195 |
return; |
|
196 |
} |
|
197 |
||
198 |
ckpInitArgs = (jInitArgs != NULL) |
|
199 |
? makeCKInitArgsAdapter(env, jInitArgs) |
|
200 |
: NULL_PTR; |
|
201 |
||
202 |
rv = (*ckpFunctions->C_Initialize)(ckpInitArgs); |
|
203 |
||
204 |
free(ckpInitArgs); |
|
205 |
||
206 |
if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } |
|
207 |
||
208 |
TRACE0("FINISHED\n"); |
|
209 |
} |
|
210 |
#endif |
|
211 |
||
212 |
#ifdef P11_ENABLE_C_FINALIZE |
|
213 |
/* |
|
214 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
215 |
* Method: C_Finalize |
|
216 |
* Signature: (Ljava/lang/Object;)V |
|
217 |
* Parametermapping: *PKCS11* |
|
218 |
* @param jobject jReserved CK_VOID_PTR pReserved |
|
219 |
*/ |
|
220 |
JNIEXPORT void JNICALL |
|
221 |
Java_sun_security_pkcs11_wrapper_PKCS11_C_1Finalize |
|
222 |
(JNIEnv *env, jobject obj, jobject jReserved) |
|
223 |
{ |
|
224 |
/* |
|
225 |
* Finalize Cryptoki |
|
226 |
*/ |
|
227 |
CK_VOID_PTR ckpReserved; |
|
228 |
CK_RV rv; |
|
229 |
||
230 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
231 |
if (ckpFunctions == NULL) { return; } |
|
232 |
||
233 |
ckpReserved = jObjectToCKVoidPtr(jReserved); |
|
234 |
||
235 |
rv = (*ckpFunctions->C_Finalize)(ckpReserved); |
|
236 |
if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } |
|
237 |
} |
|
238 |
#endif |
|
239 |
||
240 |
#ifdef P11_ENABLE_C_GETINFO |
|
241 |
/* |
|
242 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
243 |
* Method: C_GetInfo |
|
244 |
* Signature: ()Lsun/security/pkcs11/wrapper/CK_INFO; |
|
245 |
* Parametermapping: *PKCS11* |
|
246 |
* @return jobject jInfoObject CK_INFO_PTR pInfo |
|
247 |
*/ |
|
248 |
JNIEXPORT jobject JNICALL |
|
249 |
Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetInfo |
|
250 |
(JNIEnv *env, jobject obj) |
|
251 |
{ |
|
252 |
CK_INFO ckLibInfo; |
|
253 |
jobject jInfoObject; |
|
254 |
CK_RV rv; |
|
255 |
||
256 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
257 |
if (ckpFunctions == NULL) { return NULL; } |
|
258 |
||
259 |
rv = (*ckpFunctions->C_GetInfo)(&ckLibInfo); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
260 |
if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
261 |
jInfoObject = ckInfoPtrToJInfo(env, &ckLibInfo); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
262 |
} |
2 | 263 |
return jInfoObject ; |
264 |
} |
|
265 |
||
266 |
/* |
|
267 |
* converts a pointer to a CK_INFO structure into a Java CK_INFO Object. |
|
268 |
* |
|
269 |
* @param env - used to call JNI funktions to create the new Java object |
|
270 |
* @param ckpInfo - the pointer to the CK_INFO structure |
|
271 |
* @return - the new Java CK_INFO object |
|
272 |
*/ |
|
273 |
jobject ckInfoPtrToJInfo(JNIEnv *env, const CK_INFO_PTR ckpInfo) |
|
274 |
{ |
|
275 |
jclass jInfoClass; |
|
276 |
jmethodID jCtrId; |
|
277 |
jobject jInfoObject; |
|
278 |
jobject jCryptokiVer; |
|
279 |
jcharArray jVendor; |
|
280 |
jlong jFlags; |
|
281 |
jcharArray jLibraryDesc; |
|
282 |
jobject jLibraryVer; |
|
283 |
||
284 |
/* load CK_INFO class */ |
|
285 |
jInfoClass = (*env)->FindClass(env, CLASS_INFO); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
286 |
if (jInfoClass == NULL) { return NULL; }; |
2 | 287 |
|
288 |
/* load CK_INFO constructor */ |
|
289 |
jCtrId = (*env)->GetMethodID |
|
290 |
(env, jInfoClass, "<init>", |
|
291 |
"(Lsun/security/pkcs11/wrapper/CK_VERSION;[CJ[CLsun/security/pkcs11/wrapper/CK_VERSION;)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
|
292 |
if (jCtrId == NULL) { return NULL; } |
2 | 293 |
|
294 |
/* prep all fields */ |
|
295 |
jCryptokiVer = ckVersionPtrToJVersion(env, &(ckpInfo->cryptokiVersion)); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
296 |
if (jCryptokiVer == NULL) { return NULL; } |
2 | 297 |
jVendor = |
298 |
ckUTF8CharArrayToJCharArray(env, &(ckpInfo->manufacturerID[0]), 32); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
299 |
if (jVendor == NULL) { return NULL; } |
2 | 300 |
jFlags = ckULongToJLong(ckpInfo->flags); |
301 |
jLibraryDesc = |
|
302 |
ckUTF8CharArrayToJCharArray(env, &(ckpInfo->libraryDescription[0]), 32); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
303 |
if (jLibraryDesc == NULL) { return NULL; } |
2 | 304 |
jLibraryVer = ckVersionPtrToJVersion(env, &(ckpInfo->libraryVersion)); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
305 |
if (jLibraryVer == NULL) { return NULL; } |
2 | 306 |
|
307 |
/* create new CK_INFO object */ |
|
308 |
jInfoObject = (*env)->NewObject(env, jInfoClass, jCtrId, jCryptokiVer, |
|
309 |
jVendor, jFlags, jLibraryDesc, jLibraryVer); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
310 |
if (jInfoObject == NULL) { return NULL; } |
2 | 311 |
|
312 |
/* free local references */ |
|
313 |
(*env)->DeleteLocalRef(env, jInfoClass); |
|
314 |
(*env)->DeleteLocalRef(env, jCryptokiVer); |
|
315 |
(*env)->DeleteLocalRef(env, jVendor); |
|
316 |
(*env)->DeleteLocalRef(env, jLibraryDesc); |
|
317 |
(*env)->DeleteLocalRef(env, jLibraryVer); |
|
318 |
||
319 |
return jInfoObject ; |
|
320 |
} |
|
321 |
#endif |
|
322 |
||
323 |
#ifdef P11_ENABLE_C_GETSLOTLIST |
|
324 |
/* |
|
325 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
326 |
* Method: C_GetSlotList |
|
327 |
* Signature: (Z)[J |
|
328 |
* Parametermapping: *PKCS11* |
|
329 |
* @param jboolean jTokenPresent CK_BBOOL tokenPresent |
|
330 |
* @return jlongArray jSlotList CK_SLOT_ID_PTR pSlotList |
|
331 |
* CK_ULONG_PTR pulCount |
|
332 |
*/ |
|
333 |
JNIEXPORT jlongArray JNICALL |
|
334 |
Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetSlotList |
|
335 |
(JNIEnv *env, jobject obj, jboolean jTokenPresent) |
|
336 |
{ |
|
337 |
CK_ULONG ckTokenNumber; |
|
338 |
CK_SLOT_ID_PTR ckpSlotList; |
|
339 |
CK_BBOOL ckTokenPresent; |
|
3321
fed33393bc52
6823905: crash in sun.security.pkcs11.wrapper.PKCS11.C_Sign during stress-test
valeriep
parents:
2180
diff
changeset
|
340 |
jlongArray jSlotList = NULL; |
2 | 341 |
CK_RV rv; |
342 |
||
343 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
344 |
if (ckpFunctions == NULL) { return NULL; } |
|
345 |
||
346 |
ckTokenPresent = jBooleanToCKBBool(jTokenPresent); |
|
347 |
||
348 |
rv = (*ckpFunctions->C_GetSlotList)(ckTokenPresent, NULL_PTR, |
|
349 |
&ckTokenNumber); |
|
350 |
if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return NULL ; } |
|
351 |
||
352 |
ckpSlotList = (CK_SLOT_ID_PTR) malloc(ckTokenNumber * sizeof(CK_SLOT_ID)); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
353 |
if (ckpSlotList == 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
|
354 |
JNU_ThrowOutOfMemoryError(env, 0); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
355 |
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
|
356 |
} |
2 | 357 |
|
358 |
rv = (*ckpFunctions->C_GetSlotList)(ckTokenPresent, ckpSlotList, |
|
359 |
&ckTokenNumber); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
360 |
if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
361 |
jSlotList = ckULongArrayToJLongArray(env, ckpSlotList, ckTokenNumber); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
362 |
} |
2 | 363 |
free(ckpSlotList); |
364 |
||
365 |
return jSlotList ; |
|
366 |
} |
|
367 |
#endif |
|
368 |
||
369 |
#ifdef P11_ENABLE_C_GETSLOTINFO |
|
370 |
/* |
|
371 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
372 |
* Method: C_GetSlotInfo |
|
373 |
* Signature: (J)Lsun/security/pkcs11/wrapper/CK_SLOT_INFO; |
|
374 |
* Parametermapping: *PKCS11* |
|
375 |
* @param jlong jSlotID CK_SLOT_ID slotID |
|
376 |
* @return jobject jSlotInfoObject CK_SLOT_INFO_PTR pInfo |
|
377 |
*/ |
|
378 |
JNIEXPORT jobject JNICALL |
|
379 |
Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetSlotInfo |
|
380 |
(JNIEnv *env, jobject obj, jlong jSlotID) |
|
381 |
{ |
|
382 |
CK_SLOT_ID ckSlotID; |
|
383 |
CK_SLOT_INFO ckSlotInfo; |
|
384 |
jobject jSlotInfoObject; |
|
385 |
CK_RV rv; |
|
386 |
||
387 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
388 |
if (ckpFunctions == NULL) { return NULL; } |
|
389 |
||
390 |
ckSlotID = jLongToCKULong(jSlotID); |
|
391 |
||
392 |
rv = (*ckpFunctions->C_GetSlotInfo)(ckSlotID, &ckSlotInfo); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
393 |
if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
394 |
jSlotInfoObject = ckSlotInfoPtrToJSlotInfo(env, &ckSlotInfo); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
395 |
} |
2 | 396 |
return jSlotInfoObject ; |
397 |
} |
|
398 |
||
399 |
/* |
|
400 |
* converts a pointer to a CK_SLOT_INFO structure into a Java CK_SLOT_INFO |
|
401 |
* Object. |
|
402 |
* |
|
403 |
* @param env - used to call JNI funktions to create the new Java object |
|
404 |
* @param ckpSlotInfo - the pointer to the CK_SLOT_INFO structure |
|
405 |
* @return - the new Java CK_SLOT_INFO object |
|
406 |
*/ |
|
407 |
jobject |
|
408 |
ckSlotInfoPtrToJSlotInfo |
|
409 |
(JNIEnv *env, const CK_SLOT_INFO_PTR ckpSlotInfo) |
|
410 |
{ |
|
411 |
jclass jSlotInfoClass; |
|
412 |
jmethodID jCtrId; |
|
413 |
jobject jSlotInfoObject; |
|
414 |
jcharArray jSlotDesc; |
|
415 |
jcharArray jVendor; |
|
416 |
jlong jFlags; |
|
417 |
jobject jHardwareVer; |
|
418 |
jobject jFirmwareVer; |
|
419 |
||
420 |
/* load CK_SLOT_INFO class */ |
|
421 |
jSlotInfoClass = (*env)->FindClass(env, CLASS_SLOT_INFO); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
422 |
if (jSlotInfoClass == NULL) { return NULL; }; |
2 | 423 |
|
424 |
/* load CK_SLOT_INFO constructor */ |
|
425 |
jCtrId = (*env)->GetMethodID |
|
426 |
(env, jSlotInfoClass, "<init>", |
|
427 |
"([C[CJLsun/security/pkcs11/wrapper/CK_VERSION;Lsun/security/pkcs11/wrapper/CK_VERSION;)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
|
428 |
if (jCtrId == NULL) { return NULL; } |
2 | 429 |
|
430 |
/* prep all fields */ |
|
431 |
jSlotDesc = |
|
432 |
ckUTF8CharArrayToJCharArray(env, &(ckpSlotInfo->slotDescription[0]), 64); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
433 |
if (jSlotDesc == NULL) { return NULL; } |
2 | 434 |
jVendor = |
435 |
ckUTF8CharArrayToJCharArray(env, &(ckpSlotInfo->manufacturerID[0]), 32); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
436 |
if (jVendor == NULL) { return NULL; } |
2 | 437 |
jFlags = ckULongToJLong(ckpSlotInfo->flags); |
438 |
jHardwareVer = ckVersionPtrToJVersion(env, &(ckpSlotInfo->hardwareVersion)); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
439 |
if (jHardwareVer == NULL) { return NULL; } |
2 | 440 |
jFirmwareVer = ckVersionPtrToJVersion(env, &(ckpSlotInfo->firmwareVersion)); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
441 |
if (jFirmwareVer == NULL) { return NULL; } |
2 | 442 |
|
443 |
/* create new CK_SLOT_INFO object */ |
|
444 |
jSlotInfoObject = (*env)->NewObject |
|
445 |
(env, jSlotInfoClass, jCtrId, jSlotDesc, jVendor, jFlags, |
|
446 |
jHardwareVer, jFirmwareVer); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
447 |
if (jSlotInfoObject == NULL) { return NULL; } |
2 | 448 |
|
449 |
/* free local references */ |
|
450 |
(*env)->DeleteLocalRef(env, jSlotInfoClass); |
|
451 |
(*env)->DeleteLocalRef(env, jSlotDesc); |
|
452 |
(*env)->DeleteLocalRef(env, jVendor); |
|
453 |
(*env)->DeleteLocalRef(env, jHardwareVer); |
|
454 |
(*env)->DeleteLocalRef(env, jFirmwareVer); |
|
455 |
||
456 |
return jSlotInfoObject ; |
|
457 |
} |
|
458 |
||
459 |
#endif |
|
460 |
||
461 |
#ifdef P11_ENABLE_C_GETTOKENINFO |
|
462 |
/* |
|
463 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
464 |
* Method: C_GetTokenInfo |
|
465 |
* Signature: (J)Lsun/security/pkcs11/wrapper/CK_TOKEN_INFO; |
|
466 |
* Parametermapping: *PKCS11* |
|
467 |
* @param jlong jSlotID CK_SLOT_ID slotID |
|
468 |
* @return jobject jInfoTokenObject CK_TOKEN_INFO_PTR pInfo |
|
469 |
*/ |
|
470 |
JNIEXPORT jobject JNICALL |
|
471 |
Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetTokenInfo |
|
472 |
(JNIEnv *env, jobject obj, jlong jSlotID) |
|
473 |
{ |
|
474 |
CK_SLOT_ID ckSlotID; |
|
475 |
CK_TOKEN_INFO ckTokenInfo; |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
476 |
jobject jInfoTokenObject = NULL; |
2 | 477 |
CK_RV rv; |
478 |
||
479 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
480 |
if (ckpFunctions == NULL) { return NULL; } |
|
481 |
||
482 |
ckSlotID = jLongToCKULong(jSlotID); |
|
483 |
||
484 |
rv = (*ckpFunctions->C_GetTokenInfo)(ckSlotID, &ckTokenInfo); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
485 |
if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
486 |
jInfoTokenObject = ckTokenInfoPtrToJTokenInfo(env, &ckTokenInfo); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
487 |
} |
2 | 488 |
return jInfoTokenObject ; |
489 |
} |
|
490 |
||
491 |
/* |
|
492 |
* converts a pointer to a CK_TOKEN_INFO structure into a Java CK_TOKEN_INFO |
|
493 |
* Object. |
|
494 |
* |
|
495 |
* @param env - used to call JNI funktions to create the new Java object |
|
496 |
* @param ckpTokenInfo - the pointer to the CK_TOKEN_INFO structure |
|
497 |
* @return - the new Java CK_TOKEN_INFO object |
|
498 |
*/ |
|
499 |
jobject |
|
500 |
ckTokenInfoPtrToJTokenInfo |
|
501 |
(JNIEnv *env, const CK_TOKEN_INFO_PTR ckpTokenInfo) |
|
502 |
{ |
|
503 |
jclass jTokenInfoClass; |
|
504 |
jmethodID jCtrId; |
|
505 |
jobject jTokenInfoObject; |
|
506 |
jcharArray jLabel; |
|
507 |
jcharArray jVendor; |
|
508 |
jcharArray jModel; |
|
509 |
jcharArray jSerialNo; |
|
510 |
jlong jFlags; |
|
511 |
jlong jMaxSnCnt; |
|
512 |
jlong jSnCnt; |
|
513 |
jlong jMaxRwSnCnt; |
|
514 |
jlong jRwSnCnt; |
|
515 |
jlong jMaxPinLen; |
|
516 |
jlong jMinPinLen; |
|
517 |
jlong jTotalPubMem; |
|
518 |
jlong jFreePubMem; |
|
519 |
jlong jTotalPrivMem; |
|
520 |
jlong jFreePrivMem; |
|
521 |
jobject jHardwareVer; |
|
522 |
jobject jFirmwareVer; |
|
523 |
jcharArray jUtcTime; |
|
524 |
||
525 |
/* load CK_TOKEN_INFO class */ |
|
526 |
jTokenInfoClass = (*env)->FindClass(env, CLASS_TOKEN_INFO); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
527 |
if (jTokenInfoClass == NULL) { return NULL; }; |
2 | 528 |
|
529 |
/* load CK_TOKEN_INFO constructor */ |
|
530 |
jCtrId = (*env)->GetMethodID |
|
531 |
(env, jTokenInfoClass, "<init>", |
|
532 |
"([C[C[C[CJJJJJJJJJJJLsun/security/pkcs11/wrapper/CK_VERSION;Lsun/security/pkcs11/wrapper/CK_VERSION;[C)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
|
533 |
if (jCtrId == NULL) { return NULL; }; |
2 | 534 |
|
535 |
/* prep all fields */ |
|
536 |
jLabel = ckUTF8CharArrayToJCharArray(env, &(ckpTokenInfo->label[0]), 32); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
537 |
if (jLabel == NULL) { return NULL; }; |
2 | 538 |
jVendor = |
539 |
ckUTF8CharArrayToJCharArray(env, &(ckpTokenInfo->manufacturerID[0]), 32); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
540 |
if (jVendor == NULL) { return NULL; }; |
2 | 541 |
jModel = ckUTF8CharArrayToJCharArray(env, &(ckpTokenInfo->model[0]), 16); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
542 |
if (jModel == NULL) { return NULL; }; |
2 | 543 |
jSerialNo = |
544 |
ckUTF8CharArrayToJCharArray(env, &(ckpTokenInfo->serialNumber[0]), 16); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
545 |
if (jSerialNo == NULL) { return NULL; }; |
2 | 546 |
jFlags = ckULongToJLong(ckpTokenInfo->flags); |
547 |
jMaxSnCnt = ckULongSpecialToJLong(ckpTokenInfo->ulMaxSessionCount); |
|
548 |
jSnCnt = ckULongSpecialToJLong(ckpTokenInfo->ulSessionCount); |
|
549 |
jMaxRwSnCnt = ckULongSpecialToJLong(ckpTokenInfo->ulMaxRwSessionCount); |
|
550 |
jRwSnCnt = ckULongSpecialToJLong(ckpTokenInfo->ulRwSessionCount); |
|
551 |
jMaxPinLen = ckULongToJLong(ckpTokenInfo->ulMaxPinLen); |
|
552 |
jMinPinLen = ckULongToJLong(ckpTokenInfo->ulMinPinLen); |
|
553 |
jTotalPubMem = ckULongSpecialToJLong(ckpTokenInfo->ulTotalPublicMemory); |
|
554 |
jFreePubMem = ckULongSpecialToJLong(ckpTokenInfo->ulFreePublicMemory); |
|
555 |
jTotalPrivMem = ckULongSpecialToJLong(ckpTokenInfo->ulTotalPrivateMemory); |
|
556 |
jFreePrivMem = ckULongSpecialToJLong(ckpTokenInfo->ulFreePrivateMemory); |
|
557 |
jHardwareVer = |
|
558 |
ckVersionPtrToJVersion(env, &(ckpTokenInfo->hardwareVersion)); |
|
2180
9994f4f08a59
6812738: SSL 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 |
if (jHardwareVer == NULL) { return NULL; } |
2 | 560 |
jFirmwareVer = |
561 |
ckVersionPtrToJVersion(env, &(ckpTokenInfo->firmwareVersion)); |
|
2180
9994f4f08a59
6812738: SSL 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 |
if (jFirmwareVer == NULL) { return NULL; } |
2 | 563 |
jUtcTime = |
564 |
ckUTF8CharArrayToJCharArray(env, &(ckpTokenInfo->utcTime[0]), 16); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
565 |
if (jUtcTime == NULL) { return NULL; } |
2 | 566 |
|
567 |
/* create new CK_TOKEN_INFO object */ |
|
568 |
jTokenInfoObject = |
|
569 |
(*env)->NewObject(env, jTokenInfoClass, jCtrId, jLabel, jVendor, jModel, |
|
570 |
jSerialNo, jFlags, |
|
571 |
jMaxSnCnt, jSnCnt, jMaxRwSnCnt, jRwSnCnt, |
|
572 |
jMaxPinLen, jMinPinLen, |
|
573 |
jTotalPubMem, jFreePubMem, jTotalPrivMem, jFreePrivMem, |
|
574 |
jHardwareVer, jFirmwareVer, jUtcTime); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
575 |
if (jTokenInfoObject == NULL) { return NULL; } |
2 | 576 |
|
577 |
/* free local references */ |
|
578 |
(*env)->DeleteLocalRef(env, jTokenInfoClass); |
|
579 |
(*env)->DeleteLocalRef(env, jLabel); |
|
580 |
(*env)->DeleteLocalRef(env, jVendor); |
|
581 |
(*env)->DeleteLocalRef(env, jModel); |
|
582 |
(*env)->DeleteLocalRef(env, jSerialNo); |
|
583 |
(*env)->DeleteLocalRef(env, jHardwareVer); |
|
584 |
(*env)->DeleteLocalRef(env, jFirmwareVer); |
|
585 |
||
586 |
return jTokenInfoObject ; |
|
587 |
} |
|
588 |
#endif |
|
589 |
||
590 |
#ifdef P11_ENABLE_C_WAITFORSLOTEVENT |
|
591 |
/* |
|
592 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
593 |
* Method: C_WaitForSlotEvent |
|
594 |
* Signature: (JLjava/lang/Object;)J |
|
595 |
* Parametermapping: *PKCS11* |
|
596 |
* @param jlong jFlags CK_FLAGS flags |
|
597 |
* @param jobject jReserved CK_VOID_PTR pReserved |
|
598 |
* @return jlong jSlotID CK_SLOT_ID_PTR pSlot |
|
599 |
*/ |
|
600 |
JNIEXPORT jlong JNICALL |
|
601 |
Java_sun_security_pkcs11_wrapper_PKCS11_C_1WaitForSlotEvent |
|
602 |
(JNIEnv *env, jobject obj, jlong jFlags, jobject jReserved) |
|
603 |
{ |
|
604 |
CK_FLAGS ckFlags; |
|
605 |
CK_SLOT_ID ckSlotID; |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
606 |
jlong jSlotID = 0L; |
2 | 607 |
CK_RV rv; |
608 |
||
609 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
610 |
if (ckpFunctions == NULL) { return 0L; } |
|
611 |
||
612 |
ckFlags = jLongToCKULong(jFlags); |
|
613 |
||
614 |
rv = (*ckpFunctions->C_WaitForSlotEvent)(ckFlags, &ckSlotID, NULL_PTR); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
615 |
if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
616 |
jSlotID = ckULongToJLong(ckSlotID); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
617 |
} |
2 | 618 |
|
619 |
return jSlotID ; |
|
620 |
} |
|
621 |
#endif |
|
622 |
||
623 |
#ifdef P11_ENABLE_C_GETMECHANISMLIST |
|
624 |
/* |
|
625 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
626 |
* Method: C_GetMechanismList |
|
627 |
* Signature: (J)[J |
|
628 |
* Parametermapping: *PKCS11* |
|
629 |
* @param jlong jSlotID CK_SLOT_ID slotID |
|
630 |
* @return jlongArray jMechanismList CK_MECHANISM_TYPE_PTR pMechanismList |
|
631 |
* CK_ULONG_PTR pulCount |
|
632 |
*/ |
|
633 |
JNIEXPORT jlongArray JNICALL |
|
634 |
Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetMechanismList |
|
635 |
(JNIEnv *env, jobject obj, jlong jSlotID) |
|
636 |
{ |
|
637 |
CK_SLOT_ID ckSlotID; |
|
638 |
CK_ULONG ckMechanismNumber; |
|
639 |
CK_MECHANISM_TYPE_PTR ckpMechanismList; |
|
3321
fed33393bc52
6823905: crash in sun.security.pkcs11.wrapper.PKCS11.C_Sign during stress-test
valeriep
parents:
2180
diff
changeset
|
640 |
jlongArray jMechanismList = NULL; |
2 | 641 |
CK_RV rv; |
642 |
||
643 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
644 |
if (ckpFunctions == NULL) { return NULL; } |
|
645 |
||
646 |
ckSlotID = jLongToCKULong(jSlotID); |
|
647 |
||
648 |
rv = (*ckpFunctions->C_GetMechanismList)(ckSlotID, NULL_PTR, |
|
649 |
&ckMechanismNumber); |
|
650 |
if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return NULL ; } |
|
651 |
||
652 |
ckpMechanismList = (CK_MECHANISM_TYPE_PTR) |
|
653 |
malloc(ckMechanismNumber * sizeof(CK_MECHANISM_TYPE)); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
654 |
if (ckpMechanismList == 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
|
655 |
JNU_ThrowOutOfMemoryError(env, 0); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
656 |
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
|
657 |
} |
2 | 658 |
|
659 |
rv = (*ckpFunctions->C_GetMechanismList)(ckSlotID, ckpMechanismList, |
|
660 |
&ckMechanismNumber); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
661 |
if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
662 |
jMechanismList = ckULongArrayToJLongArray(env, ckpMechanismList, |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
663 |
ckMechanismNumber); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
664 |
} |
2 | 665 |
free(ckpMechanismList); |
666 |
||
667 |
return jMechanismList ; |
|
668 |
} |
|
669 |
#endif |
|
670 |
||
671 |
#ifdef P11_ENABLE_C_GETMECHANISMINFO |
|
672 |
/* |
|
673 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
674 |
* Method: C_GetMechanismInfo |
|
675 |
* Signature: (JJ)Lsun/security/pkcs11/wrapper/CK_MECHANISM_INFO; |
|
676 |
* Parametermapping: *PKCS11* |
|
677 |
* @param jlong jSlotID CK_SLOT_ID slotID |
|
678 |
* @param jlong jType CK_MECHANISM_TYPE type |
|
679 |
* @return jobject jMechanismInfo CK_MECHANISM_INFO_PTR pInfo |
|
680 |
*/ |
|
681 |
JNIEXPORT jobject JNICALL |
|
682 |
Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetMechanismInfo |
|
683 |
(JNIEnv *env, jobject obj, jlong jSlotID, jlong jType) |
|
684 |
{ |
|
685 |
CK_SLOT_ID ckSlotID; |
|
686 |
CK_MECHANISM_TYPE ckMechanismType; |
|
687 |
CK_MECHANISM_INFO ckMechanismInfo; |
|
2180
9994f4f08a59
6812738: SSL 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 |
jobject jMechanismInfo = NULL; |
2 | 689 |
CK_RV rv; |
690 |
||
691 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
692 |
if (ckpFunctions == NULL) { return NULL; } |
|
693 |
||
694 |
ckSlotID = jLongToCKULong(jSlotID); |
|
695 |
ckMechanismType = jLongToCKULong(jType); |
|
696 |
||
697 |
rv = (*ckpFunctions->C_GetMechanismInfo)(ckSlotID, ckMechanismType, |
|
698 |
&ckMechanismInfo); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
699 |
if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
700 |
jMechanismInfo = ckMechanismInfoPtrToJMechanismInfo(env, &ckMechanismInfo); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
701 |
} |
2 | 702 |
return jMechanismInfo ; |
703 |
} |
|
704 |
||
705 |
/* |
|
706 |
* converts a pointer to a CK_MECHANISM_INFO structure into a Java |
|
707 |
* CK_MECHANISM_INFO Object. |
|
708 |
* |
|
709 |
* @param env - used to call JNI funktions to create the new Java object |
|
710 |
* @param ckpMechanismInfo - the pointer to the CK_MECHANISM_INFO structure |
|
711 |
* @return - the new Java CK_MECHANISM_INFO object |
|
712 |
*/ |
|
713 |
jobject |
|
714 |
ckMechanismInfoPtrToJMechanismInfo |
|
715 |
(JNIEnv *env, const CK_MECHANISM_INFO_PTR ckpMechanismInfo) |
|
716 |
{ |
|
717 |
||
718 |
jclass jMechanismInfoClass; |
|
719 |
jmethodID jCtrId; |
|
720 |
jobject jMechanismInfoObject; |
|
721 |
jlong jMinKeySize; |
|
722 |
jlong jMaxKeySize; |
|
723 |
jlong jFlags; |
|
724 |
||
725 |
/* load CK_MECHANISM_INFO class */ |
|
726 |
jMechanismInfoClass = (*env)->FindClass(env, CLASS_MECHANISM_INFO); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
727 |
if (jMechanismInfoClass == NULL) { return NULL; }; |
2 | 728 |
|
729 |
/* load CK_MECHANISM_INFO constructor */ |
|
730 |
jCtrId = (*env)->GetMethodID(env, jMechanismInfoClass, "<init>", "(JJJ)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
|
731 |
if (jCtrId == NULL) { return NULL; }; |
2 | 732 |
|
733 |
/* prep all fields */ |
|
734 |
jMinKeySize = ckULongToJLong(ckpMechanismInfo->ulMinKeySize); |
|
735 |
jMaxKeySize = ckULongToJLong(ckpMechanismInfo->ulMaxKeySize); |
|
736 |
jFlags = ckULongToJLong(ckpMechanismInfo->flags); |
|
737 |
||
738 |
/* create new CK_MECHANISM_INFO object */ |
|
739 |
jMechanismInfoObject = (*env)->NewObject(env, jMechanismInfoClass, jCtrId, |
|
740 |
jMinKeySize, jMaxKeySize, jFlags); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
741 |
if (jMechanismInfoObject == NULL) { return NULL; }; |
2 | 742 |
|
743 |
/* free local references */ |
|
744 |
(*env)->DeleteLocalRef(env, jMechanismInfoClass); |
|
745 |
||
746 |
return jMechanismInfoObject ; |
|
747 |
} |
|
748 |
#endif |
|
749 |
||
750 |
#ifdef P11_ENABLE_C_INITTOKEN |
|
751 |
/* |
|
752 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
753 |
* Method: C_InitToken |
|
754 |
* Signature: (J[C[C)V |
|
755 |
* Parametermapping: *PKCS11* |
|
756 |
* @param jlong jSlotID CK_SLOT_ID slotID |
|
757 |
* @param jcharArray jPin CK_CHAR_PTR pPin |
|
758 |
* CK_ULONG ulPinLen |
|
759 |
* @param jcharArray jLabel CK_UTF8CHAR_PTR pLabel |
|
760 |
*/ |
|
761 |
JNIEXPORT void JNICALL |
|
762 |
Java_sun_security_pkcs11_wrapper_PKCS11_C_1InitToken |
|
763 |
(JNIEnv *env, jobject obj, jlong jSlotID, jcharArray jPin, jcharArray jLabel) |
|
764 |
{ |
|
765 |
CK_SLOT_ID ckSlotID; |
|
766 |
CK_CHAR_PTR ckpPin = NULL_PTR; |
|
767 |
CK_UTF8CHAR_PTR ckpLabel = NULL_PTR; |
|
768 |
CK_ULONG ckPinLength; |
|
769 |
CK_ULONG ckLabelLength; |
|
770 |
CK_RV rv; |
|
771 |
||
772 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
773 |
if (ckpFunctions == NULL) { return; } |
|
774 |
||
775 |
ckSlotID = jLongToCKULong(jSlotID); |
|
776 |
jCharArrayToCKCharArray(env, jPin, &ckpPin, &ckPinLength); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
777 |
if ((*env)->ExceptionCheck(env)) { 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
|
778 |
/* ckLabelLength <= 32 !!! */ |
2 | 779 |
jCharArrayToCKUTF8CharArray(env, jLabel, &ckpLabel, &ckLabelLength); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
780 |
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
|
781 |
free(ckpPin); |
9994f4f08a59
6812738: SSL 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; |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
783 |
} |
2 | 784 |
|
785 |
rv = (*ckpFunctions->C_InitToken)(ckSlotID, ckpPin, ckPinLength, ckpLabel); |
|
786 |
TRACE1("InitToken return code: %d", rv); |
|
787 |
||
788 |
free(ckpPin); |
|
789 |
free(ckpLabel); |
|
790 |
||
791 |
if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } |
|
792 |
} |
|
793 |
#endif |
|
794 |
||
795 |
#ifdef P11_ENABLE_C_INITPIN |
|
796 |
/* |
|
797 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
798 |
* Method: C_InitPIN |
|
799 |
* Signature: (J[C)V |
|
800 |
* Parametermapping: *PKCS11* |
|
801 |
* @param jlong jSessionHandle CK_SESSION_HANDLE |
|
802 |
* @param jcharArray jPin CK_CHAR_PTR pPin |
|
803 |
* CK_ULONG ulPinLen |
|
804 |
*/ |
|
805 |
JNIEXPORT void JNICALL |
|
806 |
Java_sun_security_pkcs11_wrapper_PKCS11_C_1InitPIN |
|
807 |
(JNIEnv *env, jobject obj, jlong jSessionHandle, jcharArray jPin) |
|
808 |
{ |
|
809 |
CK_SESSION_HANDLE ckSessionHandle; |
|
810 |
CK_CHAR_PTR ckpPin = NULL_PTR; |
|
811 |
CK_ULONG ckPinLength; |
|
812 |
CK_RV rv; |
|
813 |
||
814 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
815 |
if (ckpFunctions == NULL) { return; } |
|
816 |
||
817 |
ckSessionHandle = jLongToCKULong(jSessionHandle); |
|
818 |
jCharArrayToCKCharArray(env, jPin, &ckpPin, &ckPinLength); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
819 |
if ((*env)->ExceptionCheck(env)) { return; } |
2 | 820 |
|
821 |
rv = (*ckpFunctions->C_InitPIN)(ckSessionHandle, ckpPin, ckPinLength); |
|
822 |
||
823 |
free(ckpPin); |
|
824 |
||
825 |
if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } |
|
826 |
} |
|
827 |
#endif |
|
828 |
||
829 |
#ifdef P11_ENABLE_C_SETPIN |
|
830 |
/* |
|
831 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
832 |
* Method: C_SetPIN |
|
833 |
* Signature: (J[C[C)V |
|
834 |
* Parametermapping: *PKCS11* |
|
835 |
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession |
|
836 |
* @param jcharArray jOldPin CK_CHAR_PTR pOldPin |
|
837 |
* CK_ULONG ulOldLen |
|
838 |
* @param jcharArray jNewPin CK_CHAR_PTR pNewPin |
|
839 |
* CK_ULONG ulNewLen |
|
840 |
*/ |
|
841 |
JNIEXPORT void JNICALL |
|
842 |
Java_sun_security_pkcs11_wrapper_PKCS11_C_1SetPIN |
|
843 |
(JNIEnv *env, jobject obj, jlong jSessionHandle, jcharArray jOldPin, |
|
844 |
jcharArray jNewPin) |
|
845 |
{ |
|
846 |
CK_SESSION_HANDLE ckSessionHandle; |
|
847 |
CK_CHAR_PTR ckpOldPin = NULL_PTR; |
|
848 |
CK_CHAR_PTR ckpNewPin = NULL_PTR; |
|
849 |
CK_ULONG ckOldPinLength; |
|
850 |
CK_ULONG ckNewPinLength; |
|
851 |
CK_RV rv; |
|
852 |
||
853 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
854 |
if (ckpFunctions == NULL) { return; } |
|
855 |
||
856 |
ckSessionHandle = jLongToCKULong(jSessionHandle); |
|
857 |
jCharArrayToCKCharArray(env, jOldPin, &ckpOldPin, &ckOldPinLength); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
858 |
if ((*env)->ExceptionCheck(env)) { return; } |
2 | 859 |
jCharArrayToCKCharArray(env, jNewPin, &ckpNewPin, &ckNewPinLength); |
2180
9994f4f08a59
6812738: SSL 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 ((*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
|
861 |
free(ckpOldPin); |
9994f4f08a59
6812738: SSL 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; |
9994f4f08a59
6812738: SSL 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 |
|
865 |
rv = (*ckpFunctions->C_SetPIN)(ckSessionHandle, ckpOldPin, ckOldPinLength, |
|
866 |
ckpNewPin, ckNewPinLength); |
|
867 |
||
868 |
free(ckpOldPin); |
|
869 |
free(ckpNewPin); |
|
870 |
||
871 |
if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } |
|
872 |
} |
|
873 |
#endif |