Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/jdk.crypto.cryptoki/share/native/libj2pkcs11/pkcs11wrapper.h
41149 views
1
/*
2
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
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
/*
49
* pkcs11wrapper.h
50
* 18.05.2001
51
*
52
* declaration of all functions used by pkcs11wrapper.c
53
*
54
* @author Karl Scheibelhofer <[email protected]>
55
* @author Martin Schlaeffer <[email protected]>
56
*/
57
58
#ifndef _PKCS11WRAPPER_H
59
#define _PKCS11WRAPPER_H 1
60
61
/* disable asserts in product mode */
62
#ifndef DEBUG
63
#ifndef NDEBUG
64
#define NDEBUG
65
#endif
66
#endif
67
68
/* extra PKCS#11 constants not in the standard include files */
69
70
#define CKA_NETSCAPE_BASE (0x80000000 + 0x4E534350)
71
#define CKA_NETSCAPE_TRUST_BASE (CKA_NETSCAPE_BASE + 0x2000)
72
#define CKA_NETSCAPE_TRUST_SERVER_AUTH (CKA_NETSCAPE_TRUST_BASE + 8)
73
#define CKA_NETSCAPE_TRUST_CLIENT_AUTH (CKA_NETSCAPE_TRUST_BASE + 9)
74
#define CKA_NETSCAPE_TRUST_CODE_SIGNING (CKA_NETSCAPE_TRUST_BASE + 10)
75
#define CKA_NETSCAPE_TRUST_EMAIL_PROTECTION (CKA_NETSCAPE_TRUST_BASE + 11)
76
#define CKA_NETSCAPE_DB 0xD5A0DB00
77
#define CKM_NSS_TLS_PRF_GENERAL 0x80000373
78
79
/*
80
81
Define the PKCS#11 functions to include and exclude. Reduces the size
82
of the binary somewhat.
83
84
This list needs to be kept in sync with the mapfile and PKCS11.java
85
86
*/
87
88
#define P11_ENABLE_C_INITIALIZE
89
#define P11_ENABLE_C_FINALIZE
90
#define P11_ENABLE_C_GETINFO
91
#define P11_ENABLE_C_GETSLOTLIST
92
#define P11_ENABLE_C_GETSLOTINFO
93
#define P11_ENABLE_C_GETTOKENINFO
94
#define P11_ENABLE_C_GETMECHANISMLIST
95
#define P11_ENABLE_C_GETMECHANISMINFO
96
#undef P11_ENABLE_C_INITTOKEN
97
#undef P11_ENABLE_C_INITPIN
98
#undef P11_ENABLE_C_SETPIN
99
#define P11_ENABLE_C_OPENSESSION
100
#define P11_ENABLE_C_CLOSESESSION
101
#undef P11_ENABLE_C_CLOSEALLSESSIONS
102
#define P11_ENABLE_C_GETSESSIONINFO
103
#define P11_ENABLE_C_GETOPERATIONSTATE
104
#define P11_ENABLE_C_SETOPERATIONSTATE
105
#define P11_ENABLE_C_LOGIN
106
#define P11_ENABLE_C_LOGOUT
107
#define P11_ENABLE_C_CREATEOBJECT
108
#define P11_ENABLE_C_COPYOBJECT
109
#define P11_ENABLE_C_DESTROYOBJECT
110
#undef P11_ENABLE_C_GETOBJECTSIZE
111
#define P11_ENABLE_C_GETATTRIBUTEVALUE
112
#define P11_ENABLE_C_SETATTRIBUTEVALUE
113
#define P11_ENABLE_C_FINDOBJECTSINIT
114
#define P11_ENABLE_C_FINDOBJECTS
115
#define P11_ENABLE_C_FINDOBJECTSFINAL
116
#define P11_ENABLE_C_ENCRYPTINIT
117
#define P11_ENABLE_C_ENCRYPT
118
#define P11_ENABLE_C_ENCRYPTUPDATE
119
#define P11_ENABLE_C_ENCRYPTFINAL
120
#define P11_ENABLE_C_DECRYPTINIT
121
#define P11_ENABLE_C_DECRYPT
122
#define P11_ENABLE_C_DECRYPTUPDATE
123
#define P11_ENABLE_C_DECRYPTFINAL
124
#define P11_ENABLE_C_DIGESTINIT
125
#define P11_ENABLE_C_DIGEST
126
#define P11_ENABLE_C_DIGESTUPDATE
127
#define P11_ENABLE_C_DIGESTKEY
128
#define P11_ENABLE_C_DIGESTFINAL
129
#define P11_ENABLE_C_SIGNINIT
130
#define P11_ENABLE_C_SIGN
131
#define P11_ENABLE_C_SIGNUPDATE
132
#define P11_ENABLE_C_SIGNFINAL
133
#define P11_ENABLE_C_SIGNRECOVERINIT
134
#define P11_ENABLE_C_SIGNRECOVER
135
#define P11_ENABLE_C_VERIFYINIT
136
#define P11_ENABLE_C_VERIFY
137
#define P11_ENABLE_C_VERIFYUPDATE
138
#define P11_ENABLE_C_VERIFYFINAL
139
#define P11_ENABLE_C_VERIFYRECOVERINIT
140
#define P11_ENABLE_C_VERIFYRECOVER
141
#undef P11_ENABLE_C_DIGESTENCRYPTUPDATE
142
#undef P11_ENABLE_C_DECRYPTDIGESTUPDATE
143
#undef P11_ENABLE_C_SIGNENCRYPTUPDATE
144
#undef P11_ENABLE_C_DECRYPTVERIFYUPDATE
145
#define P11_ENABLE_C_GENERATEKEY
146
#define P11_ENABLE_C_GENERATEKEYPAIR
147
#define P11_ENABLE_C_WRAPKEY
148
#define P11_ENABLE_C_UNWRAPKEY
149
#define P11_ENABLE_C_DERIVEKEY
150
#define P11_ENABLE_C_SEEDRANDOM
151
#define P11_ENABLE_C_GENERATERANDOM
152
#undef P11_ENABLE_C_GETFUNCTIONSTATUS
153
#undef P11_ENABLE_C_CANCELFUNCTION
154
#undef P11_ENABLE_C_WAITFORSLOTEVENT
155
#define P11_ENABLE_GETNATIVEKEYINFO
156
#define P11_ENABLE_CREATENATIVEKEY
157
158
159
/* include the platform dependent part of the header */
160
#include "p11_md.h"
161
162
#include <jni.h>
163
#include <jni_util.h>
164
#include <stdarg.h>
165
166
#define MAX_STACK_BUFFER_LEN (4 * 1024)
167
#define MAX_HEAP_BUFFER_LEN (64 * 1024)
168
169
#define MAX_DIGEST_LEN (64)
170
171
#ifndef min
172
#define min(a, b) (((a) < (b)) ? (a) : (b))
173
#endif
174
175
#define ckBBoolToJBoolean(x) ((x == TRUE) ? JNI_TRUE : JNI_FALSE);
176
#define jBooleanToCKBBool(x) ((x == JNI_TRUE) ? TRUE : FALSE);
177
178
#define ckByteToJByte(x) ((jbyte) x)
179
#define jByteToCKByte(x) ((CK_BYTE) x)
180
181
#define ckLongToJLong(x) ((jlong) x)
182
#define jLongToCKLong(x) ((CK_LONG) x)
183
184
#define ckULongToJLong(x) ((jlong) x)
185
#define jLongToCKULong(x) ((CK_ULONG) x)
186
187
// For CK_UNAVAILABLE_INFORMATION, always return -1 to avoid 32/64 bit problems.
188
#define ckULongSpecialToJLong(x) (((x) == CK_UNAVAILABLE_INFORMATION) \
189
? (jlong)-1 : ((jlong) x))
190
191
#define ckCharToJChar(x) ((jchar) x)
192
#define jCharToCKChar(x) ((CK_CHAR) x)
193
194
#define ckUTF8CharToJChar(x) ((jchar) x)
195
#define jCharToCKUTF8Char(x) ((CK_UTF8CHAR) x)
196
197
#define ckFlageToJLong(x) ((jlong) x)
198
199
#define ckVoidPtrToJObject(x) ((jobject) x)
200
#define jObjectToCKVoidPtr(x) ((CK_VOID_PTR) x)
201
202
#define jIntToCKLong(x) ((CK_LONG) x)
203
#define jIntToCKULong(x) ((CK_ULONG) x)
204
#define ckLongToJInt(x) ((jint) x)
205
#define ckULongToJInt(x) ((jint) x)
206
#define ckULongToJSize(x) ((jsize) x)
207
#define unsignedIntToCKULong(x) ((CK_ULONG) x)
208
209
//#define TRACE0d(s) { printf(s); fflush(stdout); }
210
//#define TRACE1d(s, p1) { printf(s, p1); fflush(stdout); }
211
//#define TRACE2d(s, p1, p2) { printf(s, p1, p2); fflush(stdout); }
212
213
#ifdef P11_DEBUG
214
#define TRACE0(s) { printf(s); fflush(stdout); }
215
#define TRACE1(s, p1) { printf(s, p1); fflush(stdout); }
216
#define TRACE2(s, p1, p2) { printf(s, p1, p2); fflush(stdout); }
217
#define TRACE3(s, p1, p2, p3) { printf(s, p1, p2, p3); fflush(stdout); }
218
#else
219
#define TRACE0(s)
220
#define TRACE1(s, p1)
221
#define TRACE2(s, p1, p2)
222
#define TRACE3(s, p1, p2, p3)
223
#define TRACE_INTEND
224
#define TRACE_UNINTEND
225
#endif
226
227
/* debug output */
228
extern jboolean debug;
229
void printDebug(const char *format, ...);
230
231
#define CK_ASSERT_OK 0L
232
233
#define CLASS_P11PSSSIGNATURE "sun/security/pkcs11/P11PSSSignature"
234
235
#define CLASS_INFO "sun/security/pkcs11/wrapper/CK_INFO"
236
#define CLASS_VERSION "sun/security/pkcs11/wrapper/CK_VERSION"
237
#define CLASS_SLOT_INFO "sun/security/pkcs11/wrapper/CK_SLOT_INFO"
238
#define CLASS_TOKEN_INFO "sun/security/pkcs11/wrapper/CK_TOKEN_INFO"
239
#define CLASS_MECHANISM "sun/security/pkcs11/wrapper/CK_MECHANISM"
240
#define CLASS_MECHANISM_INFO "sun/security/pkcs11/wrapper/CK_MECHANISM_INFO"
241
#define CLASS_SESSION_INFO "sun/security/pkcs11/wrapper/CK_SESSION_INFO"
242
#define CLASS_ATTRIBUTE "sun/security/pkcs11/wrapper/CK_ATTRIBUTE"
243
#define CLASS_DATE "sun/security/pkcs11/wrapper/CK_DATE"
244
#define CLASS_PKCS11EXCEPTION "sun/security/pkcs11/wrapper/PKCS11Exception"
245
#define CLASS_PKCS11RUNTIMEEXCEPTION "sun/security/pkcs11/wrapper/PKCS11RuntimeException"
246
#define CLASS_FILE_NOT_FOUND_EXCEPTION "java/io/FileNotFoundException"
247
#define CLASS_C_INITIALIZE_ARGS "sun/security/pkcs11/wrapper/CK_C_INITIALIZE_ARGS"
248
#define CLASS_CREATEMUTEX "sun/security/pkcs11/wrapper/CK_CREATEMUTEX"
249
#define CLASS_DESTROYMUTEX "sun/security/pkcs11/wrapper/CK_DESTROYMUTEX"
250
#define CLASS_LOCKMUTEX "sun/security/pkcs11/wrapper/CK_LOCKMUTEX"
251
#define CLASS_UNLOCKMUTEX "sun/security/pkcs11/wrapper/CK_UNLOCKMUTEX"
252
#define CLASS_NOTIFY "sun/security/pkcs11/wrapper/CK_NOTIFY"
253
254
255
/* mechanism parameter classes */
256
#define CLASS_AES_CTR_PARAMS "sun/security/pkcs11/wrapper/CK_AES_CTR_PARAMS"
257
#define CLASS_GCM_PARAMS "sun/security/pkcs11/wrapper/CK_GCM_PARAMS"
258
#define CLASS_CCM_PARAMS "sun/security/pkcs11/wrapper/CK_CCM_PARAMS"
259
#define CLASS_SALSA20_CHACHA20_POLY1305_PARAMS \
260
"sun/security/pkcs11/wrapper/CK_SALSA20_CHACHA20_POLY1305_PARAMS"
261
#define CLASS_RSA_PKCS_PSS_PARAMS "sun/security/pkcs11/wrapper/CK_RSA_PKCS_PSS_PARAMS"
262
#define CLASS_RSA_PKCS_OAEP_PARAMS "sun/security/pkcs11/wrapper/CK_RSA_PKCS_OAEP_PARAMS"
263
264
#define CLASS_MAC_GENERAL_PARAMS "sun/security/pkcs11/wrapper/CK_MAC_GENERAL_PARAMS"
265
#define CLASS_PBE_PARAMS "sun/security/pkcs11/wrapper/CK_PBE_PARAMS"
266
#define PBE_INIT_VECTOR_SIZE 8
267
#define CLASS_PKCS5_PBKD2_PARAMS "sun/security/pkcs11/wrapper/CK_PKCS5_PBKD2_PARAMS"
268
#define CLASS_EXTRACT_PARAMS "sun/security/pkcs11/wrapper/CK_EXTRACT_PARAMS"
269
270
#define CLASS_ECDH1_DERIVE_PARAMS "sun/security/pkcs11/wrapper/CK_ECDH1_DERIVE_PARAMS"
271
#define CLASS_ECDH2_DERIVE_PARAMS "sun/security/pkcs11/wrapper/CK_ECDH2_DERIVE_PARAMS"
272
#define CLASS_X9_42_DH1_DERIVE_PARAMS "sun/security/pkcs11/wrapper/CK_X9_42_DH1_DERIVE_PARAMS"
273
#define CLASS_X9_42_DH2_DERIVE_PARAMS "sun/security/pkcs11/wrapper/CK_X9_42_DH2_DERIVE_PARAMS"
274
275
/*
276
#define CLASS_KEA_DERIVE_PARAMS "sun/security/pkcs11/wrapper/CK_KEA_DERIVE_PARAMS"
277
#define CLASS_RC2_PARAMS "sun/security/pkcs11/wrapper/CK_RC2_PARAMS"
278
#define CLASS_RC2_CBC_PARAMS "sun/security/pkcs11/wrapper/CK_RC2_CBC_PARAMS"
279
#define CLASS_RC2_MAC_GENERAL_PARAMS "sun/security/pkcs11/wrapper/CK_RC2_MAC_GENERAL_PARAMS"
280
#define CLASS_RC5_PARAMS "sun/security/pkcs11/wrapper/CK_RC5_PARAMS"
281
#define CLASS_RC5_CBC_PARAMS "sun/security/pkcs11/wrapper/CK_RC5_CBC_PARAMS"
282
#define CLASS_RC5_MAC_GENERAL_PARAMS "sun/security/pkcs11/wrapper/CK_RC5_MAC_GENERAL_PARAMS"
283
#define CLASS_SKIPJACK_PRIVATE_WRAP_PARAMS "sun/security/pkcs11/wrapper/CK_SKIPJACK_PRIVATE_WRAP_PARAMS"
284
#define CLASS_SKIPJACK_RELAYX_PARAMS "sun/security/pkcs11/wrapper/CK_SKIPJACK_RELAYX_PARAMS"
285
#define CLASS_KEY_WRAP_SET_OAEP_PARAMS "sun/security/pkcs11/wrapper/CK_KEY_WRAP_SET_OAEP_PARAMS"
286
#define CLASS_KEY_DERIVATION_STRING_DATA "sun/security/pkcs11/wrapper/CK_KEY_DERIVATION_STRING_DATA"
287
*/
288
289
#define CLASS_SSL3_RANDOM_DATA "sun/security/pkcs11/wrapper/CK_SSL3_RANDOM_DATA"
290
// CLASS_SSL3_RANDOM_DATA is used by CLASS_SSL3_MASTER_KEY_DERIVE_PARAMS
291
#define CLASS_SSL3_KEY_MAT_OUT "sun/security/pkcs11/wrapper/CK_SSL3_KEY_MAT_OUT"
292
// CLASS_SSL3_KEY_MAT_OUT is used by CLASS_SSL3_KEY_MAT_PARAMS and CK_TLS12_KEY_MAT_PARAMS
293
#define CLASS_SSL3_MASTER_KEY_DERIVE_PARAMS "sun/security/pkcs11/wrapper/CK_SSL3_MASTER_KEY_DERIVE_PARAMS"
294
#define CLASS_TLS12_MASTER_KEY_DERIVE_PARAMS "sun/security/pkcs11/wrapper/CK_TLS12_MASTER_KEY_DERIVE_PARAMS"
295
#define CLASS_SSL3_KEY_MAT_PARAMS "sun/security/pkcs11/wrapper/CK_SSL3_KEY_MAT_PARAMS"
296
#define CLASS_TLS12_KEY_MAT_PARAMS "sun/security/pkcs11/wrapper/CK_TLS12_KEY_MAT_PARAMS"
297
#define CLASS_TLS_PRF_PARAMS "sun/security/pkcs11/wrapper/CK_TLS_PRF_PARAMS"
298
#define CLASS_TLS_MAC_PARAMS "sun/security/pkcs11/wrapper/CK_TLS_MAC_PARAMS"
299
300
/* function to update the CK_NSS_GCM_PARAMS in mechanism pointer with
301
* CK_GCM_PARAMS
302
*/
303
CK_MECHANISM_PTR updateGCMParams(JNIEnv *env, CK_MECHANISM_PTR mechPtr);
304
305
/* function to convert a PKCS#11 return value other than CK_OK into a Java Exception
306
* or to throw a PKCS11RuntimeException
307
*/
308
309
jlong ckAssertReturnValueOK(JNIEnv *env, CK_RV returnValue);
310
jlong ckAssertReturnValueOK2(JNIEnv *env, CK_RV returnValue, const char *msg);
311
void throwOutOfMemoryError(JNIEnv *env, const char *message);
312
void throwNullPointerException(JNIEnv *env, const char *message);
313
void throwIOException(JNIEnv *env, const char *message);
314
void throwPKCS11RuntimeException(JNIEnv *env, const char *message);
315
void throwDisconnectedRuntimeException(JNIEnv *env);
316
317
/* functions to free CK structures and pointers
318
*/
319
void freeCKAttributeArray(CK_ATTRIBUTE_PTR attrPtr, int len);
320
void freeCKMechanismPtr(CK_MECHANISM_PTR mechPtr);
321
322
/* functions to convert Java arrays to a CK-type array and the array length */
323
324
void jBooleanArrayToCKBBoolArray(JNIEnv *env, const jbooleanArray jArray, CK_BBOOL **ckpArray, CK_ULONG_PTR ckLength);
325
void jByteArrayToCKByteArray(JNIEnv *env, const jbyteArray jArray, CK_BYTE_PTR *ckpArray, CK_ULONG_PTR ckLength);
326
void jLongArrayToCKULongArray(JNIEnv *env, const jlongArray jArray, CK_ULONG_PTR *ckpArray, CK_ULONG_PTR ckLength);
327
void jCharArrayToCKCharArray(JNIEnv *env, const jcharArray jArray, CK_CHAR_PTR *ckpArray, CK_ULONG_PTR ckLength);
328
void jCharArrayToCKUTF8CharArray(JNIEnv *env, const jcharArray jArray, CK_UTF8CHAR_PTR *ckpArray, CK_ULONG_PTR ckLength);
329
void jStringToCKUTF8CharArray(JNIEnv *env, const jstring jArray, CK_UTF8CHAR_PTR *ckpArray, CK_ULONG_PTR ckpLength);
330
void jAttributeArrayToCKAttributeArray(JNIEnv *env, jobjectArray jAArray, CK_ATTRIBUTE_PTR *ckpArray, CK_ULONG_PTR ckpLength);
331
/*void jObjectArrayToCKVoidPtrArray(JNIEnv *env, const jobjectArray jArray, CK_VOID_PTR_PTR ckpArray, CK_ULONG_PTR ckpLength); */
332
333
334
/* functions to convert a CK-type array and the array length to a Java array */
335
336
jbyteArray ckByteArrayToJByteArray(JNIEnv *env, const CK_BYTE_PTR ckpArray, CK_ULONG ckLength);
337
jlongArray ckULongArrayToJLongArray(JNIEnv *env, const CK_ULONG_PTR ckpArray, CK_ULONG ckLength);
338
jcharArray ckCharArrayToJCharArray(JNIEnv *env, const CK_CHAR_PTR ckpArray, CK_ULONG length);
339
jcharArray ckUTF8CharArrayToJCharArray(JNIEnv *env, const CK_UTF8CHAR_PTR ckpArray, CK_ULONG ckLength);
340
341
342
/* functions to convert a CK-type structure or a pointer to a CK-value to a Java object */
343
344
jobject ckBBoolPtrToJBooleanObject(JNIEnv *env, const CK_BBOOL* ckpValue);
345
jobject ckULongPtrToJLongObject(JNIEnv *env, const CK_ULONG_PTR ckpValue);
346
jobject ckDatePtrToJDateObject(JNIEnv *env, const CK_DATE *ckpValue);
347
jobject ckVersionPtrToJVersion(JNIEnv *env, const CK_VERSION_PTR ckpVersion);
348
jobject ckSessionInfoPtrToJSessionInfo(JNIEnv *env, const CK_SESSION_INFO_PTR ckpSessionInfo);
349
jobject ckAttributePtrToJAttribute(JNIEnv *env, const CK_ATTRIBUTE_PTR ckpAttribute);
350
351
352
/* function to convert the CK-value used by the CK_ATTRIBUTE structure to a Java object */
353
354
jobject ckAttributeValueToJObject(JNIEnv *env, const CK_ATTRIBUTE_PTR ckpAttribute);
355
356
357
/* functions to convert a Java object to a CK-type structure or a pointer to a CK-value */
358
359
CK_BBOOL* jBooleanObjectToCKBBoolPtr(JNIEnv *env, jobject jObject);
360
CK_BYTE_PTR jByteObjectToCKBytePtr(JNIEnv *env, jobject jObject);
361
CK_ULONG* jIntegerObjectToCKULongPtr(JNIEnv *env, jobject jObject);
362
CK_ULONG* jLongObjectToCKULongPtr(JNIEnv *env, jobject jObject);
363
CK_CHAR_PTR jCharObjectToCKCharPtr(JNIEnv *env, jobject jObject);
364
CK_VERSION_PTR jVersionToCKVersionPtr(JNIEnv *env, jobject jVersion);
365
CK_DATE * jDateObjectToCKDatePtr(JNIEnv *env, jobject jDate);
366
CK_ATTRIBUTE jAttributeToCKAttribute(JNIEnv *env, jobject jAttribute);
367
CK_MECHANISM_PTR jMechanismToCKMechanismPtr(JNIEnv *env, jobject jMechanism);
368
369
370
/* functions to convert Java objects used by the Mechanism and Attribute class to a CK-type structure */
371
CK_VOID_PTR jObjectToPrimitiveCKObjectPtr(JNIEnv *env, jobject jObject, CK_ULONG *ckpLength);
372
CK_VOID_PTR jMechParamToCKMechParamPtr(JNIEnv *env, jobject jParam, CK_MECHANISM_TYPE, CK_ULONG
373
*ckpLength);
374
375
376
/* functions to convert a specific Java mechanism parameter object to a CK-mechanism parameter pointer */
377
378
CK_RSA_PKCS_OAEP_PARAMS_PTR jRsaPkcsOaepParamToCKRsaPkcsOaepParamPtr(JNIEnv *env,
379
jobject jParam, CK_ULONG* pLength);
380
CK_PBE_PARAMS_PTR jPbeParamToCKPbeParamPtr(JNIEnv *env, jobject jParam, CK_ULONG* pLength);
381
CK_PKCS5_PBKD2_PARAMS_PTR jPkcs5Pbkd2ParamToCKPkcs5Pbkd2ParamPtr(JNIEnv *env, jobject jParam, CK_ULONG* pLength);
382
CK_SSL3_MASTER_KEY_DERIVE_PARAMS_PTR jSsl3MasterKeyDeriveParamToCKSsl3MasterKeyDeriveParamPtr(JNIEnv *env, jobject jParam, CK_ULONG* pLength);
383
CK_SSL3_KEY_MAT_PARAMS_PTR jSsl3KeyMatParamToCKSsl3KeyMatParamPtr(JNIEnv *env, jobject jParam, CK_ULONG* pLength);
384
CK_KEY_DERIVATION_STRING_DATA jKeyDerivationStringDataToCKKeyDerivationStringData(JNIEnv *env, jobject jParam);
385
CK_RSA_PKCS_PSS_PARAMS_PTR jRsaPkcsPssParamToCKRsaPkcsPssParamPtr(JNIEnv *env, jobject jParam, CK_ULONG* pLength);
386
CK_ECDH1_DERIVE_PARAMS_PTR jEcdh1DeriveParamToCKEcdh1DeriveParamPtr(JNIEnv *env, jobject jParam, CK_ULONG* pLength);
387
CK_ECDH2_DERIVE_PARAMS_PTR jEcdh2DeriveParamToCKEcdh2DeriveParamPtr(JNIEnv *env, jobject jParam, CK_ULONG* pLength);
388
CK_X9_42_DH1_DERIVE_PARAMS_PTR jX942Dh1DeriveParamToCKX942Dh1DeriveParamPtr(JNIEnv *env, jobject jParam, CK_ULONG* pLength);
389
CK_X9_42_DH2_DERIVE_PARAMS_PTR jX942Dh2DeriveParamToCKX942Dh2DeriveParamPtr(JNIEnv *env, jobject jParam, CK_ULONG* pLength);
390
391
/* functions to copy the returned values inside CK-mechanism back to Java object */
392
393
void copyBackPBEInitializationVector(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism);
394
void copyBackSetUnwrappedKey(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism);
395
void ssl3CopyBackClientVersion(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism);
396
void tls12CopyBackClientVersion(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism);
397
void ssl3CopyBackKeyMatParams(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism);
398
void tls12CopyBackKeyMatParams(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism);
399
400
401
/* functions to convert the InitArgs object for calling the right Java mutex functions */
402
403
CK_C_INITIALIZE_ARGS_PTR makeCKInitArgsAdapter(JNIEnv *env, jobject pInitArgs);
404
405
#ifndef NO_CALLBACKS /* if the library should not make callbacks; e.g. no javai.lib or jvm.lib available */
406
CK_RV callJCreateMutex(CK_VOID_PTR_PTR ppMutex);
407
CK_RV callJDestroyMutex(CK_VOID_PTR pMutex);
408
CK_RV callJLockMutex(CK_VOID_PTR pMutex);
409
CK_RV callJUnlockMutex(CK_VOID_PTR pMutex);
410
#endif /* NO_CALLBACKS */
411
412
void putModuleEntry(JNIEnv *env, jobject pkcs11Implementation, ModuleData *moduleData);
413
ModuleData * removeModuleEntry(JNIEnv *env, jobject pkcs11Implementation);
414
CK_FUNCTION_LIST_PTR getFunctionList(JNIEnv *env, jobject pkcs11Implementation);
415
416
/* A structure to encapsulate the required data for a Notify callback */
417
struct NotifyEncapsulation {
418
419
/* The object that implements the CK_NOTIFY interface and which should be
420
* notified.
421
*/
422
jobject jNotifyObject;
423
424
/* The data object to pass back to the Notify object upon callback. */
425
jobject jApplicationData;
426
};
427
typedef struct NotifyEncapsulation NotifyEncapsulation;
428
429
/* The function for handling notify callbacks. */
430
CK_RV notifyCallback(
431
CK_SESSION_HANDLE hSession, /* the session's handle */
432
CK_NOTIFICATION event,
433
CK_VOID_PTR pApplication /* passed to C_OpenSession */
434
);
435
436
437
/* A node of the list of notify callbacks. To be able to free the resources after use. */
438
struct NotifyListNode {
439
440
/* The handle of the session this notify object is attached to*/
441
CK_SESSION_HANDLE hSession;
442
443
/* Reference to the Notify encapsulation object that was passed to C_OpenSession. */
444
NotifyEncapsulation *notifyEncapsulation;
445
446
/* Pointer to the next node in the list. */
447
struct NotifyListNode *next;
448
449
};
450
typedef struct NotifyListNode NotifyListNode;
451
452
void putNotifyEntry(JNIEnv *env, CK_SESSION_HANDLE hSession, NotifyEncapsulation *notifyEncapsulation);
453
NotifyEncapsulation * removeNotifyEntry(JNIEnv *env, CK_SESSION_HANDLE hSession);
454
NotifyEncapsulation * removeFirstNotifyEntry(JNIEnv *env);
455
456
jobject createLockObject(JNIEnv *env);
457
void destroyLockObject(JNIEnv *env, jobject jLockObject);
458
459
extern jfieldID pNativeDataID;
460
extern jfieldID mech_mechanismID;
461
extern jfieldID mech_pParameterID;
462
extern jfieldID mech_pHandleID;
463
464
extern jclass jByteArrayClass;
465
extern jclass jLongClass;
466
467
#ifndef NO_CALLBACKS
468
extern NotifyListNode *notifyListHead;
469
extern jobject notifyListLock;
470
471
extern jobject jInitArgsObject;
472
extern CK_C_INITIALIZE_ARGS_PTR ckpGlobalInitArgs;
473
#endif /* NO_CALLBACKS */
474
475
#ifdef P11_MEMORYDEBUG
476
#include <stdlib.h>
477
478
/* Simple malloc/calloc/free dumper */
479
void *p11malloc(size_t c, char *file, int line);
480
void *p11calloc(size_t c, size_t s, char *file, int line);
481
void p11free(void *p, char *file, int line);
482
483
#define malloc(c) (p11malloc((c), __FILE__, __LINE__))
484
#define calloc(c, s) (p11calloc((c), (s), __FILE__, __LINE__))
485
#define free(c) (p11free((c), __FILE__, __LINE__))
486
487
#endif
488
489
#endif /* _PKCS11WRAPPER_H */
490
491