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