1 /* Copyright (c) 2002 Graz University of Technology. All rights reserved.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are met:
5 *
6 * 1. Redistributions of source code must retain the above copyright notice,
7 * this list of conditions and the following disclaimer.
8 *
9 * 2. Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12 *
13 * 3. The end-user documentation included with the redistribution, if any, must
14 * include the following acknowledgment:
15 *
16 * "This product includes software developed by IAIK of Graz University of
17 * Technology."
18 *
19 * Alternately, this acknowledgment may appear in the software itself, if
20 * and wherever such third-party acknowledgments normally appear.
21 *
22 * 4. The names "Graz University of Technology" and "IAIK of Graz University of
23 * Technology" must not be used to endorse or promote products derived from
24 * this software without prior written permission.
25 *
26 * 5. Products derived from this software may not be called
27 * "IAIK PKCS Wrapper", nor may "IAIK" appear in their name, without prior
28 * written permission of Graz University of Technology.
29 *
30 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
31 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
32 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
33 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LICENSOR BE
34 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
35 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
36 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
37 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
38 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
39 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
40 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGE.
42 */
43
44 /*
45 * pkcs11wrapper.h
46 * 18.05.2001
47 *
48 * declaration of all functions used by pkcs11wrapper.c
49 *
50 * @author Karl Scheibelhofer <Karl.Scheibelhofer@iaik.at>
51 * @author Martin Schl�ffer <schlaeff@sbox.tugraz.at>
52 */
53
54
55 /* incldue the platform dependent part of the header */
56 #include "platform.h"
57
58 #include "pkcs11.h"
59 #include "jni.h"
60 #include "iaik_pkcs_pkcs11_wrapper_PKCS11Implementation.h"
61
62 #include <time.h>
63
64 #define ckBBoolToJBoolean(x) (x == TRUE) ? JNI_TRUE : JNI_FALSE;
65 #define jBooleanToCKBBool(x) (x == JNI_TRUE) ? TRUE : FALSE;
66
67 #define ckByteToJByte(x) (jbyte) x
68 /*#define ckBytePtrToJBytePtr(x) (jbyte *) x */
69 #define jByteToCKByte(x) (CK_BYTE) x
70 /*#define jBytePtrToCKBytePtr(x) (CK_BYTE *) x */
71
72 #define ckLongToJLong(x) (jlong) x
73 /*#define ckLongPtrToJLongPtr(x) (jlong *) x */
74 #define jLongToCKLong(x) (CK_LONG) x
75 /*#define jLongPtrToCKLongPtr(x) (CK_LONG *) x */
76
77 #define ckULongToJLong(x) (jlong) x
78 /*#define ckULongPtrToJLongPtr(x) (jlong *) x */
79 #define jLongToCKULong(x) (CK_ULONG) x
80 /*#define jLongPtrToCKULongPtr(x) (CK_ULONG *) x */
81
82 #define ckCharToJChar(x) (jchar) x
83 /*#define ckCharPtrToJCharPtr(x) (jchar *) x */
84 #define jCharToCKChar(x) (CK_CHAR) x
85 /*#define jCharPtrToCKCharPtr(x) (CK_CHAR *) x */
86
87 #define ckUTF8CharToJChar(x) (jchar) x
88 /*#define ckUTF8CharPtrToJCharPtr(x) (jchar *) x */
89 #define jCharToCKUTF8Char(x) (CK_UTF8CHAR) x
90 /*#define jCharPtrToCKUTF8CharPtr(x) (CK_UTF8CHAR *) x */
91
92 #define ckFlageToJLong(x) (jlong) x
93 /*#define ckFlagsPtrToJLongPtr(x) (jlong *) x */
94 /*#define jLongToCKFlags(x) (CK_FLAGS) x */
95 /*#define jLongPtrToCKFlagsPtr(x) (CK_FLAGS *) x */
96
97 #define ckVoidPtrToJObject(x) (jobject) x
98 #define jObjectToCKVoidPtr(x) (CK_VOID_PTR) x
99
100 #define jIntToCKLong(x) (CK_LONG) x
101 #define jIntToCKULong(x) (CK_ULONG) x
102 #define ckLongToJInt(x) (jint) x
103 #define ckULongToJInt(x) (jint) x
104 #define ckULongToJSize(x) (jsize) x
105 #define unsignedIntToCKULong(x) (CK_ULONG) x
106
107 /*
108 * These are tags used for the logger.
109 */
110 #define tag_call "CALL"
111 #define tag_debug "DEBUG"
112 #define tag_info "INFO"
113 #define tag_error "ERROR"
114
115 /*
116 * This methods prints log entries with the following format:
117 * <timestamp> <tag>: <message> (<method>)
118 */
119 #ifdef DEBUG
timeStamp()120 void timeStamp() {
121 char stamp[20];
122 time_t now;
123 struct tm *noww;
124 now = time(NULL);
125 noww = localtime(&now);
126 strftime(stamp, 20, "%x %X", noww);
127 stamp[19] = '\0';
128 printf("%s ", stamp);
129 }
130 #define buffer_size = 50;
131 #define TRACE0(tag, method, message) { timeStamp(); printf("%6s: ", tag); printf(message); printf(" (in %s)\n", method); fflush(stdout); }
132 #define TRACE1(tag, method, message, p1) { timeStamp(); printf("%6s: ", tag); printf(message, p1); printf(" (in %s)\n", method); fflush(stdout); }
133 #define TRACE2(tag, method, message, p1, p2) { timeStamp(); printf("%6s: ", tag); printf(message, p1, p2); printf(" (in %s)\n", method); fflush(stdout); }
134 #define TRACE3(tag, method, message, p1, p2, p3) { timeStamp(); printf("%6s: ", tag); printf(message, p1, p2, p3); printf(" (in %s)\n", method); fflush(stdout); }
135 #else
136 #define TRACE0(tag, method, message)
137 #define TRACE1(tag, method, message, p1)
138 #define TRACE2(tag, method, message, p1, p2)
139 #define TRACE3(tag, method, message, p1, p2, p3)
140 #define TRACE_INTEND
141 #define TRACE_UNINTEND
142 #endif
143
144 #define CK_ASSERT_OK 0L
145
146 #define CLASS_INFO "iaik/pkcs/pkcs11/wrapper/CK_INFO"
147 #define CLASS_VERSION "iaik/pkcs/pkcs11/wrapper/CK_VERSION"
148 #define CLASS_SLOT_INFO "iaik/pkcs/pkcs11/wrapper/CK_SLOT_INFO"
149 #define CLASS_TOKEN_INFO "iaik/pkcs/pkcs11/wrapper/CK_TOKEN_INFO"
150 #define CLASS_MECHANISM "iaik/pkcs/pkcs11/wrapper/CK_MECHANISM"
151 #define CLASS_MECHANISM_INFO "iaik/pkcs/pkcs11/wrapper/CK_MECHANISM_INFO"
152 #define CLASS_SESSION_INFO "iaik/pkcs/pkcs11/wrapper/CK_SESSION_INFO"
153 #define CLASS_ATTRIBUTE "iaik/pkcs/pkcs11/wrapper/CK_ATTRIBUTE"
154 #define CLASS_DATE "iaik/pkcs/pkcs11/wrapper/CK_DATE"
155 #define CLASS_PKCS11EXCEPTION "iaik/pkcs/pkcs11/wrapper/PKCS11Exception"
156 #define CLASS_PKCS11RUNTIMEEXCEPTION "iaik/pkcs/pkcs11/wrapper/PKCS11RuntimeException"
157 #define CLASS_FILE_NOT_FOUND_EXCEPTION "java/io/FileNotFoundException"
158 #define CLASS_OUT_OF_MEMORY_ERROR "java/lang/OutOfMemoryError"
159 #define CLASS_IO_EXCEPTION "java/io/IOException"
160 #define CLASS_C_INITIALIZE_ARGS "iaik/pkcs/pkcs11/wrapper/CK_C_INITIALIZE_ARGS"
161 #define CLASS_CREATEMUTEX "iaik/pkcs/pkcs11/wrapper/CK_CREATEMUTEX"
162 #define CLASS_DESTROYMUTEX "iaik/pkcs/pkcs11/wrapper/CK_DESTROYMUTEX"
163 #define CLASS_LOCKMUTEX "iaik/pkcs/pkcs11/wrapper/CK_LOCKMUTEX"
164 #define CLASS_UNLOCKMUTEX "iaik/pkcs/pkcs11/wrapper/CK_UNLOCKMUTEX"
165 #define CLASS_NOTIFY "iaik/pkcs/pkcs11/wrapper/CK_NOTIFY"
166
167
168 /* mechanism parameter classes */
169
170 #define CLASS_RSA_PKCS_OAEP_PARAMS "iaik/pkcs/pkcs11/wrapper/CK_RSA_PKCS_OAEP_PARAMS"
171 #define CLASS_KEA_DERIVE_PARAMS "iaik/pkcs/pkcs11/wrapper/CK_KEA_DERIVE_PARAMS"
172 #define CLASS_RC2_PARAMS "iaik/pkcs/pkcs11/wrapper/CK_RC2_PARAMS"
173 #define CLASS_RC2_CBC_PARAMS "iaik/pkcs/pkcs11/wrapper/CK_RC2_CBC_PARAMS"
174 #define CLASS_RC2_MAC_GENERAL_PARAMS "iaik/pkcs/pkcs11/wrapper/CK_RC2_MAC_GENERAL_PARAMS"
175 #define CLASS_RC5_PARAMS "iaik/pkcs/pkcs11/wrapper/CK_RC5_PARAMS"
176 #define CLASS_RC5_CBC_PARAMS "iaik/pkcs/pkcs11/wrapper/CK_RC5_CBC_PARAMS"
177 #define CLASS_RC5_MAC_GENERAL_PARAMS "iaik/pkcs/pkcs11/wrapper/CK_RC5_MAC_GENERAL_PARAMS"
178 #define CLASS_MAC_GENERAL_PARAMS "iaik/pkcs/pkcs11/wrapper/CK_MAC_GENERAL_PARAMS"
179 #define CLASS_SKIPJACK_PRIVATE_WRAP_PARAMS "iaik/pkcs/pkcs11/wrapper/CK_SKIPJACK_PRIVATE_WRAP_PARAMS"
180 #define CLASS_SKIPJACK_RELAYX_PARAMS "iaik/pkcs/pkcs11/wrapper/CK_SKIPJACK_RELAYX_PARAMS"
181 #define CLASS_PBE_PARAMS "iaik/pkcs/pkcs11/wrapper/CK_PBE_PARAMS"
182 #define PBE_INIT_VECTOR_SIZE 8
183 #define CLASS_PKCS5_PBKD2_PARAMS "iaik/pkcs/pkcs11/wrapper/CK_PKCS5_PBKD2_PARAMS"
184 #define CLASS_KEY_WRAP_SET_OAEP_PARAMS "iaik/pkcs/pkcs11/wrapper/CK_KEY_WRAP_SET_OAEP_PARAMS"
185 #define CLASS_KEY_DERIVATION_STRING_DATA "iaik/pkcs/pkcs11/wrapper/CK_KEY_DERIVATION_STRING_DATA"
186 #define CLASS_SSL3_RANDOM_DATA "iaik/pkcs/pkcs11/wrapper/CK_SSL3_RANDOM_DATA"
187 /* CLASS_SSL3_RANDOM_DATA is used by CLASS_SSL3_MASTER_KEY_DERIVE_PARAMS */
188 #define CLASS_SSL3_KEY_MAT_OUT "iaik/pkcs/pkcs11/wrapper/CK_SSL3_KEY_MAT_OUT"
189 /* CLASS_SSL3_KEY_MAT_OUT is used by CLASS_SSL3_KEY_MAT_PARAMS */
190 #define CLASS_SSL3_MASTER_KEY_DERIVE_PARAMS "iaik/pkcs/pkcs11/wrapper/CK_SSL3_MASTER_KEY_DERIVE_PARAMS"
191 #define CLASS_SSL3_KEY_MAT_PARAMS "iaik/pkcs/pkcs11/wrapper/CK_SSL3_KEY_MAT_PARAMS"
192 #define CLASS_EXTRACT_PARAMS "iaik/pkcs/pkcs11/wrapper/CK_EXTRACT_PARAMS"
193
194 #define CLASS_RSA_PKCS_PSS_PARAMS "iaik/pkcs/pkcs11/wrapper/CK_RSA_PKCS_PSS_PARAMS"
195 #define CLASS_ECDH1_DERIVE_PARAMS "iaik/pkcs/pkcs11/wrapper/CK_ECDH1_DERIVE_PARAMS"
196 #define CLASS_ECDH2_DERIVE_PARAMS "iaik/pkcs/pkcs11/wrapper/CK_ECDH2_DERIVE_PARAMS"
197 #define CLASS_X9_42_DH1_DERIVE_PARAMS "iaik/pkcs/pkcs11/wrapper/CK_X9_42_DH1_DERIVE_PARAMS"
198 #define CLASS_X9_42_DH2_DERIVE_PARAMS "iaik/pkcs/pkcs11/wrapper/CK_X9_42_DH2_DERIVE_PARAMS"
199
200 #define CLASS_DES_CBC_ENCRYPT_DATA_PARAMS "iaik/pkcs/pkcs11/wrapper/CK_DES_CBC_ENCRYPT_DATA_PARAMS"
201 #define CLASS_AES_CBC_ENCRYPT_DATA_PARAMS "iaik/pkcs/pkcs11/wrapper/CK_AES_CBC_ENCRYPT_DATA_PARAMS"
202
203 #define CLASS_NAME(clazz) "L"clazz";"
204
205 /* function to convert a PKCS#11 return value other than CK_OK into a Java Exception
206 * or to throw a PKCS11RuntimeException
207 */
208
209 jlong ckAssertReturnValueOK(JNIEnv *env, CK_RV returnValue, char* callerMethodName);
210 void throwOutOfMemoryError(JNIEnv *env);
211 void throwPKCS11RuntimeException(JNIEnv *env, jstring jmessage);
212 void throwFileNotFoundException(JNIEnv *env, jstring jmessage);
213 void throwIOException(JNIEnv *env, const char *message);
214 void throwIOExceptionUnicodeMessage(JNIEnv *env, const unsigned short *message);
215 void throwDisconnectedRuntimeException(JNIEnv *env);
216
217 /* funktions to convert Java arrays to a CK-type array and the array length */
218
219 int jBooleanArrayToCKBBoolArray(JNIEnv *env, const jbooleanArray jArray, CK_BBOOL **ckpArray, CK_ULONG_PTR ckLength);
220 int jByteArrayToCKByteArray(JNIEnv *env, const jbyteArray jArray, CK_BYTE_PTR *ckpArray, CK_ULONG_PTR ckLength);
221 int jLongArrayToCKULongArray(JNIEnv *env, const jlongArray jArray, CK_ULONG_PTR *ckpArray, CK_ULONG_PTR ckLength);
222 int jCharArrayToCKCharArray(JNIEnv *env, const jcharArray jArray, CK_CHAR_PTR *ckpArray, CK_ULONG_PTR ckLength);
223 int jCharArrayToCKUTF8CharArray(JNIEnv *env, const jcharArray jArray, CK_UTF8CHAR_PTR *ckpArray, CK_ULONG_PTR ckLength);
224 int jStringToCKUTF8CharArray(JNIEnv *env, const jstring jArray, CK_UTF8CHAR_PTR *ckpArray, CK_ULONG_PTR ckpLength);
225 int jAttributeArrayToCKAttributeArray(JNIEnv *env, jobjectArray jAArray, CK_ATTRIBUTE_PTR *ckpArray, CK_ULONG_PTR ckpLength);
226 /*void jObjectArrayToCKVoidPtrArray(JNIEnv *env, const jobjectArray jArray, CK_VOID_PTR_PTR ckpArray, CK_ULONG_PTR ckpLength); */
227
228
229 /* funktions to convert a CK-type array and the array length to a Java array */
230
231 jcharArray ckByteArrayToJByteArray(JNIEnv *env, const CK_BYTE_PTR ckpArray, CK_ULONG ckLength);
232 jlongArray ckULongArrayToJLongArray(JNIEnv *env, const CK_ULONG_PTR ckpArray, CK_ULONG ckLength);
233 jcharArray ckCharArrayToJCharArray(JNIEnv *env, const CK_CHAR_PTR ckpArray, CK_ULONG length);
234 jcharArray ckUTF8CharArrayToJCharArray(JNIEnv *env, const CK_UTF8CHAR_PTR ckpArray, CK_ULONG ckLength);
235
236
237 /* funktions to convert a CK-type structure or a pointer to a CK-value to a Java object */
238
239 jobject ckBBoolPtrToJBooleanObject(JNIEnv *env, const CK_BBOOL* ckpValue);
240 jobject ckULongPtrToJLongObject(JNIEnv *env, const CK_ULONG_PTR ckpValue);
241 jobject ckDatePtrToJDateObject(JNIEnv *env, const CK_DATE *ckpValue);
242 jobject ckVersionPtrToJVersion(JNIEnv *env, const CK_VERSION_PTR ckpVersion);
243 jobject ckInfoPtrToJInfo(JNIEnv *env, const CK_INFO_PTR ckpInfo);
244 jobject ckSlotInfoPtrToJSlotInfo(JNIEnv *env, const CK_SLOT_INFO_PTR ckpSlotInfo);
245 jobject ckTokenInfoPtrToJTokenInfo(JNIEnv *env, const CK_TOKEN_INFO_PTR ckpTokenInfo);
246 jobject ckSessionInfoPtrToJSessionInfo(JNIEnv *env, const CK_SESSION_INFO_PTR ckpSessionInfo);
247 jobject ckMechanismInfoPtrToJMechanismInfo(JNIEnv *env, const CK_MECHANISM_INFO_PTR ckpMechanismInfo);
248 jobject ckAttributePtrToJAttribute(JNIEnv *env, const CK_ATTRIBUTE_PTR ckpAttribute);
249 jobject ckAttributeArrayToJAttributeArray(JNIEnv *env, const CK_ATTRIBUTE_PTR ckpArray, CK_ULONG ckLength);
250
251
252 /* funktion to convert the CK-value used by the CK_ATTRIBUTE structure to a Java object */
253
254 jobject ckAttributeValueToJObject(JNIEnv *env, const CK_ATTRIBUTE_PTR ckpAttribute);
255
256
257 /* funktions to convert a Java object to a CK-type structure or a pointer to a CK-value */
258
259 CK_BBOOL* jBooleanObjectToCKBBoolPtr(JNIEnv *env, jobject jObject);
260 CK_BYTE_PTR jByteObjectToCKBytePtr(JNIEnv *env, jobject jObject);
261 CK_ULONG* jIntegerObjectToCKULongPtr(JNIEnv *env, jobject jObject);
262 CK_ULONG* jLongObjectToCKULongPtr(JNIEnv *env, jobject jObject);
263 CK_CHAR_PTR jCharObjectToCKCharPtr(JNIEnv *env, jobject jObject);
264 CK_VERSION_PTR jVersionToCKVersionPtr(JNIEnv *env, jobject jVersion);
265 CK_DATE * jDateObjectPtrToCKDatePtr(JNIEnv *env, jobject jDate);
266 CK_ATTRIBUTE jAttributeToCKAttribute(JNIEnv *env, jobject jAttribute);
267 CK_MECHANISM jMechanismToCKMechanism(JNIEnv *env, jobject jMechanism);
268
269
270 /* funktions to convert Java objects used by the Mechanism and Attribute class to a CK-type structure */
271
272 void jObjectToPrimitiveCKObjectPtrPtr(JNIEnv *env, jobject jObject, CK_VOID_PTR *ckpObjectPtr, CK_ULONG *pLength);
273 void jMechanismParameterToCKMechanismParameter(JNIEnv *env, jobject jParam, CK_VOID_PTR *ckpParamPtr, CK_ULONG *ckpLength);
274 void freeCKMechanismParameter(CK_MECHANISM_PTR mechanism);
275
276
277 /* functions to convert a specific Java mechanism parameter object to a CK-mechanism parameter structure */
278
279 CK_RSA_PKCS_OAEP_PARAMS jRsaPkcsOaepParamToCKRsaPkcsOaepParam(JNIEnv *env, jobject jParam);
280 CK_KEA_DERIVE_PARAMS jKeaDeriveParamToCKKeaDeriveParam(JNIEnv *env, jobject jParam);
281 CK_RC2_CBC_PARAMS jRc2CbcParamToCKRc2CbcParam(JNIEnv *env, jobject jParam);
282 CK_RC2_MAC_GENERAL_PARAMS jRc2MacGeneralParamToCKRc2MacGeneralParam(JNIEnv *env, jobject jParam);
283 CK_RC5_PARAMS jRc5ParamToCKRc5Param(JNIEnv *env, jobject jParam);
284 CK_RC5_CBC_PARAMS jRc5CbcParamToCKRc5CbcParam(JNIEnv *env, jobject jParam);
285 CK_RC5_MAC_GENERAL_PARAMS jRc5MacGeneralParamToCKRc5MacGeneralParam(JNIEnv *env, jobject jParam);
286 CK_SKIPJACK_PRIVATE_WRAP_PARAMS jSkipjackPrivateWrapParamToCKSkipjackPrivateWrapParam(JNIEnv *env, jobject jParam);
287 CK_SKIPJACK_RELAYX_PARAMS jSkipjackRelayxParamToCKSkipjackRelayxParam(JNIEnv *env, jobject jParam);
288 CK_PBE_PARAMS jPbeParamToCKPbeParam(JNIEnv *env, jobject jParam);
289 void copyBackPBEInitializationVector(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism);
290 CK_PKCS5_PBKD2_PARAMS jPkcs5Pbkd2ParamToCKPkcs5Pbkd2Param(JNIEnv *env, jobject jParam);
291 CK_KEY_WRAP_SET_OAEP_PARAMS jKeyWrapSetOaepParamToCKKeyWrapSetOaepParam(JNIEnv *env, jobject jParam);
292 void copyBackSetUnwrappedKey(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism);
293 CK_SSL3_MASTER_KEY_DERIVE_PARAMS jSsl3MasterKeyDeriveParamToCKSsl3MasterKeyDeriveParam(JNIEnv *env, jobject jParam);
294 void copyBackClientVersion(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism);
295 CK_SSL3_KEY_MAT_PARAMS jSsl3KeyMatParamToCKSsl3KeyMatParam(JNIEnv *env, jobject jParam);
296 void copyBackSSLKeyMatParams(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism);
297 CK_KEY_DERIVATION_STRING_DATA jKeyDerivationStringDataToCKKeyDerivationStringData(JNIEnv *env, jobject jParam);
298 CK_RSA_PKCS_PSS_PARAMS jRsaPkcsPssParamToCKRsaPkcsPssParam(JNIEnv *env, jobject jParam);
299 CK_ECDH1_DERIVE_PARAMS jEcdh1DeriveParamToCKEcdh1DeriveParam(JNIEnv *env, jobject jParam);
300 CK_ECDH2_DERIVE_PARAMS jEcdh2DeriveParamToCKEcdh2DeriveParam(JNIEnv *env, jobject jParam);
301 CK_X9_42_DH1_DERIVE_PARAMS jX942Dh1DeriveParamToCKX942Dh1DeriveParam(JNIEnv *env, jobject jParam);
302 CK_X9_42_DH2_DERIVE_PARAMS jX942Dh2DeriveParamToCKX942Dh2DeriveParam(JNIEnv *env, jobject jParam);
303
304 CK_DES_CBC_ENCRYPT_DATA_PARAMS jDesCbcEncryptDataParamToCKDesCbcEncryptData(JNIEnv *env, jobject jParam);
305 CK_AES_CBC_ENCRYPT_DATA_PARAMS jAesCbcEncryptDataParamToCKAesCbcEncryptData(JNIEnv *env, jobject jParam);
306
307 /* functions to convert the InitArgs object for calling the right Java mutex functions */
308
309 CK_C_INITIALIZE_ARGS_PTR makeCKInitArgsAdapter(JNIEnv *env, jobject pInitArgs);
310
311 #ifndef NO_CALLBACKS /* if the library should not make callbacks; e.g. no javai.lib or jvm.lib available */
312 CK_RV callJCreateMutex(CK_VOID_PTR_PTR ppMutex);
313 CK_RV callJDestroyMutex(CK_VOID_PTR pMutex);
314 CK_RV callJLockMutex(CK_VOID_PTR pMutex);
315 CK_RV callJUnlockMutex(CK_VOID_PTR pMutex);
316 #endif /* NO_CALLBACKS */
317
318
319 /* A node of the list of connected modules */
320 struct ModuleListNode {
321
322 /* Reference to the object that implements the PKCS11 interface. */
323 jobject pkcs11Implementation;
324
325 /* Reference to this PKCS11 object's data. */
326 ModuleData *moduleData;
327
328 /* Pointer to the next node in the list. */
329 struct ModuleListNode *next;
330
331 };
332 typedef struct ModuleListNode ModuleListNode;
333
334
335 void putModuleEntry(JNIEnv *env, jobject pkcs11Implementation, ModuleData *moduleData);
336 ModuleData * getModuleEntry(JNIEnv *env, jobject pkcs11Implementation);
337 int isModulePresent(JNIEnv *env, jobject pkcs11Implementation);
338 ModuleData * removeModuleEntry(JNIEnv *env, jobject pkcs11Implementation);
339 void removeAllModuleEntries(JNIEnv *env);
340 int equals(JNIEnv *env, jobject thisObject, jobject otherObject);
341
342
343 /* A structure to encapsulate the required data for a Notify callback */
344 struct NotifyEncapsulation {
345
346 /* The object that implements the CK_NOTIFY interface and which should be
347 * notified.
348 */
349 jobject jNotifyObject;
350
351 /* The data object to pass back to the Notify object upon callback. */
352 jobject jApplicationData;
353 };
354 typedef struct NotifyEncapsulation NotifyEncapsulation;
355
356 /* The function for handling notify callbacks. */
357 CK_RV notifyCallback(
358 CK_SESSION_HANDLE hSession, /* the session's handle */
359 CK_NOTIFICATION event,
360 CK_VOID_PTR pApplication /* passed to C_OpenSession */
361 );
362
363
364 /* A node of the list of notify callbacks. To be able to free the resources after use. */
365 struct NotifyListNode {
366
367 /* The handle of the session this notify object is attached to*/
368 CK_SESSION_HANDLE hSession;
369
370 /* Reference to the Notify encapsulation object that was passed to C_OpenSession. */
371 NotifyEncapsulation *notifyEncapsulation;
372
373 /* Pointer to the next node in the list. */
374 struct NotifyListNode *next;
375
376 };
377 typedef struct NotifyListNode NotifyListNode;
378
379 void putNotifyEntry(JNIEnv *env, CK_SESSION_HANDLE hSession, NotifyEncapsulation *notifyEncapsulation);
380 NotifyEncapsulation * removeNotifyEntry(JNIEnv *env, CK_SESSION_HANDLE hSession);
381 NotifyEncapsulation * removeFirstNotifyEntry(JNIEnv *env);
382
383 jobject createLockObject(JNIEnv *env);
384 void destroyLockObject(JNIEnv *env, jobject jLockObject);
385