J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Portions Copyright 2003-2006 Sun Microsystems, Inc. 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 <Karl.Scheibelhofer@iaik.at> |
| 55 | * @author Martin Schlaeffer <schlaeff@sbox.tugraz.at> |
| 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 | |
| 70 | #define CKA_NETSCAPE_TRUST_SERVER_AUTH (CKA_NETSCAPE_TRUST_BASE + 8) |
| 71 | #define CKA_NETSCAPE_TRUST_CLIENT_AUTH (CKA_NETSCAPE_TRUST_BASE + 9) |
| 72 | #define CKA_NETSCAPE_TRUST_CODE_SIGNING (CKA_NETSCAPE_TRUST_BASE + 10) |
| 73 | #define CKA_NETSCAPE_TRUST_EMAIL_PROTECTION (CKA_NETSCAPE_TRUST_BASE + 11) |
| 74 | |
| 75 | /* |
| 76 | |
| 77 | Define the PKCS#11 functions to include and exclude. Reduces the size |
| 78 | of the binary somewhat. |
| 79 | |
| 80 | This list needs to be kept in sync with the mapfile and PKCS11.java |
| 81 | |
| 82 | */ |
| 83 | |
| 84 | #define P11_ENABLE_C_INITIALIZE |
| 85 | #define P11_ENABLE_C_FINALIZE |
| 86 | #define P11_ENABLE_C_GETINFO |
| 87 | #define P11_ENABLE_C_GETSLOTLIST |
| 88 | #define P11_ENABLE_C_GETSLOTINFO |
| 89 | #define P11_ENABLE_C_GETTOKENINFO |
| 90 | #define P11_ENABLE_C_GETMECHANISMLIST |
| 91 | #define P11_ENABLE_C_GETMECHANISMINFO |
| 92 | #undef P11_ENABLE_C_INITTOKEN |
| 93 | #undef P11_ENABLE_C_INITPIN |
| 94 | #undef P11_ENABLE_C_SETPIN |
| 95 | #define P11_ENABLE_C_OPENSESSION |
| 96 | #define P11_ENABLE_C_CLOSESESSION |
| 97 | #undef P11_ENABLE_C_CLOSEALLSESSIONS |
| 98 | #define P11_ENABLE_C_GETSESSIONINFO |
| 99 | #undef P11_ENABLE_C_GETOPERATIONSTATE |
| 100 | #undef P11_ENABLE_C_SETOPERATIONSTATE |
| 101 | #define P11_ENABLE_C_LOGIN |
| 102 | #define P11_ENABLE_C_LOGOUT |
| 103 | #define P11_ENABLE_C_CREATEOBJECT |
| 104 | #define P11_ENABLE_C_COPYOBJECT |
| 105 | #define P11_ENABLE_C_DESTROYOBJECT |
| 106 | #undef P11_ENABLE_C_GETOBJECTSIZE |
| 107 | #define P11_ENABLE_C_GETATTRIBUTEVALUE |
| 108 | #define P11_ENABLE_C_SETATTRIBUTEVALUE |
| 109 | #define P11_ENABLE_C_FINDOBJECTSINIT |
| 110 | #define P11_ENABLE_C_FINDOBJECTS |
| 111 | #define P11_ENABLE_C_FINDOBJECTSFINAL |
| 112 | #define P11_ENABLE_C_ENCRYPTINIT |
| 113 | #define P11_ENABLE_C_ENCRYPT |
| 114 | #define P11_ENABLE_C_ENCRYPTUPDATE |
| 115 | #define P11_ENABLE_C_ENCRYPTFINAL |
| 116 | #define P11_ENABLE_C_DECRYPTINIT |
| 117 | #define P11_ENABLE_C_DECRYPT |
| 118 | #define P11_ENABLE_C_DECRYPTUPDATE |
| 119 | #define P11_ENABLE_C_DECRYPTFINAL |
| 120 | #define P11_ENABLE_C_DIGESTINIT |
| 121 | #define P11_ENABLE_C_DIGEST |
| 122 | #define P11_ENABLE_C_DIGESTUPDATE |
| 123 | #define P11_ENABLE_C_DIGESTKEY |
| 124 | #define P11_ENABLE_C_DIGESTFINAL |
| 125 | #define P11_ENABLE_C_SIGNINIT |
| 126 | #define P11_ENABLE_C_SIGN |
| 127 | #define P11_ENABLE_C_SIGNUPDATE |
| 128 | #define P11_ENABLE_C_SIGNFINAL |
| 129 | #define P11_ENABLE_C_SIGNRECOVERINIT |
| 130 | #define P11_ENABLE_C_SIGNRECOVER |
| 131 | #define P11_ENABLE_C_VERIFYINIT |
| 132 | #define P11_ENABLE_C_VERIFY |
| 133 | #define P11_ENABLE_C_VERIFYUPDATE |
| 134 | #define P11_ENABLE_C_VERIFYFINAL |
| 135 | #define P11_ENABLE_C_VERIFYRECOVERINIT |
| 136 | #define P11_ENABLE_C_VERIFYRECOVER |
| 137 | #undef P11_ENABLE_C_DIGESTENCRYPTUPDATE |
| 138 | #undef P11_ENABLE_C_DECRYPTDIGESTUPDATE |
| 139 | #undef P11_ENABLE_C_SIGNENCRYPTUPDATE |
| 140 | #undef P11_ENABLE_C_DECRYPTVERIFYUPDATE |
| 141 | #define P11_ENABLE_C_GENERATEKEY |
| 142 | #define P11_ENABLE_C_GENERATEKEYPAIR |
| 143 | #define P11_ENABLE_C_WRAPKEY |
| 144 | #define P11_ENABLE_C_UNWRAPKEY |
| 145 | #define P11_ENABLE_C_DERIVEKEY |
| 146 | #define P11_ENABLE_C_SEEDRANDOM |
| 147 | #define P11_ENABLE_C_GENERATERANDOM |
| 148 | #undef P11_ENABLE_C_GETFUNCTIONSTATUS |
| 149 | #undef P11_ENABLE_C_CANCELFUNCTION |
| 150 | #undef P11_ENABLE_C_WAITFORSLOTEVENT |
| 151 | |
| 152 | /* include the platform dependent part of the header */ |
| 153 | #include "p11_md.h" |
| 154 | |
| 155 | #include "pkcs11.h" |
| 156 | #include <jni.h> |
| 157 | |
| 158 | #define MAX_STACK_BUFFER_LEN (4 * 1024) |
| 159 | #define MAX_HEAP_BUFFER_LEN (64 * 1024) |
| 160 | |
| 161 | #define MAX_DIGEST_LEN (64) |
| 162 | |
| 163 | #ifndef min |
| 164 | #define min(a, b) (((a) < (b)) ? (a) : (b)) |
| 165 | #endif |
| 166 | |
| 167 | #define ckBBoolToJBoolean(x) ((x == TRUE) ? JNI_TRUE : JNI_FALSE); |
| 168 | #define jBooleanToCKBBool(x) ((x == JNI_TRUE) ? TRUE : FALSE); |
| 169 | |
| 170 | #define ckByteToJByte(x) ((jbyte) x) |
| 171 | #define jByteToCKByte(x) ((CK_BYTE) x) |
| 172 | |
| 173 | #define ckLongToJLong(x) ((jlong) x) |
| 174 | #define jLongToCKLong(x) ((CK_LONG) x) |
| 175 | |
| 176 | #define ckULongToJLong(x) ((jlong) x) |
| 177 | #define jLongToCKULong(x) ((CK_ULONG) x) |
| 178 | |
| 179 | // For CK_UNAVAILABLE_INFORMATION, always return -1 to avoid 32/64 bit problems. |
| 180 | #define ckULongSpecialToJLong(x) (((x) == CK_UNAVAILABLE_INFORMATION) \ |
| 181 | ? (jlong)-1 : ((jlong) x)) |
| 182 | |
| 183 | #define ckCharToJChar(x) ((jchar) x) |
| 184 | #define jCharToCKChar(x) ((CK_CHAR) x) |
| 185 | |
| 186 | #define ckUTF8CharToJChar(x) ((jchar) x) |
| 187 | #define jCharToCKUTF8Char(x) ((CK_UTF8CHAR) x) |
| 188 | |
| 189 | #define ckFlageToJLong(x) ((jlong) x) |
| 190 | |
| 191 | #define ckVoidPtrToJObject(x) ((jobject) x) |
| 192 | #define jObjectToCKVoidPtr(x) ((CK_VOID_PTR) x) |
| 193 | |
| 194 | #define jIntToCKLong(x) ((CK_LONG) x) |
| 195 | #define jIntToCKULong(x) ((CK_ULONG) x) |
| 196 | #define ckLongToJInt(x) ((jint) x) |
| 197 | #define ckULongToJInt(x) ((jint) x) |
| 198 | #define ckULongToJSize(x) ((jsize) x) |
| 199 | #define unsignedIntToCKULong(x) ((CK_ULONG) x) |
| 200 | |
| 201 | #ifdef P11_DEBUG |
| 202 | #define TRACE0(s) { printf(s); fflush(stdout); } |
| 203 | #define TRACE1(s, p1) { printf(s, p1); fflush(stdout); } |
| 204 | #define TRACE2(s, p1, p2) { printf(s, p1, p2); fflush(stdout); } |
| 205 | #define TRACE3(s, p1, p2, p3) { printf(s, p1, p2, p3); fflush(stdout); } |
| 206 | #else |
| 207 | #define TRACE0(s) |
| 208 | #define TRACE1(s, p1) |
| 209 | #define TRACE2(s, p1, p2) |
| 210 | #define TRACE3(s, p1, p2, p3) |
| 211 | #define TRACE_INTEND |
| 212 | #define TRACE_UNINTEND |
| 213 | #endif |
| 214 | |
| 215 | #define CK_ASSERT_OK 0L |
| 216 | |
| 217 | #define CLASS_INFO "sun/security/pkcs11/wrapper/CK_INFO" |
| 218 | #define CLASS_VERSION "sun/security/pkcs11/wrapper/CK_VERSION" |
| 219 | #define CLASS_SLOT_INFO "sun/security/pkcs11/wrapper/CK_SLOT_INFO" |
| 220 | #define CLASS_TOKEN_INFO "sun/security/pkcs11/wrapper/CK_TOKEN_INFO" |
| 221 | #define CLASS_MECHANISM "sun/security/pkcs11/wrapper/CK_MECHANISM" |
| 222 | #define CLASS_MECHANISM_INFO "sun/security/pkcs11/wrapper/CK_MECHANISM_INFO" |
| 223 | #define CLASS_SESSION_INFO "sun/security/pkcs11/wrapper/CK_SESSION_INFO" |
| 224 | #define CLASS_ATTRIBUTE "sun/security/pkcs11/wrapper/CK_ATTRIBUTE" |
| 225 | #define CLASS_DATE "sun/security/pkcs11/wrapper/CK_DATE" |
| 226 | #define CLASS_PKCS11EXCEPTION "sun/security/pkcs11/wrapper/PKCS11Exception" |
| 227 | #define CLASS_PKCS11RUNTIMEEXCEPTION "sun/security/pkcs11/wrapper/PKCS11RuntimeException" |
| 228 | #define CLASS_FILE_NOT_FOUND_EXCEPTION "java/io/FileNotFoundException" |
| 229 | #define CLASS_IO_EXCEPTION "java/io/IOException" |
| 230 | #define CLASS_C_INITIALIZE_ARGS "sun/security/pkcs11/wrapper/CK_C_INITIALIZE_ARGS" |
| 231 | #define CLASS_CREATEMUTEX "sun/security/pkcs11/wrapper/CK_CREATEMUTEX" |
| 232 | #define CLASS_DESTROYMUTEX "sun/security/pkcs11/wrapper/CK_DESTROYMUTEX" |
| 233 | #define CLASS_LOCKMUTEX "sun/security/pkcs11/wrapper/CK_LOCKMUTEX" |
| 234 | #define CLASS_UNLOCKMUTEX "sun/security/pkcs11/wrapper/CK_UNLOCKMUTEX" |
| 235 | #define CLASS_NOTIFY "sun/security/pkcs11/wrapper/CK_NOTIFY" |
| 236 | |
| 237 | |
| 238 | /* mechanism parameter classes */ |
| 239 | |
| 240 | #define CLASS_RSA_PKCS_OAEP_PARAMS "sun/security/pkcs11/wrapper/CK_RSA_PKCS_OAEP_PARAMS" |
| 241 | #define CLASS_MAC_GENERAL_PARAMS "sun/security/pkcs11/wrapper/CK_MAC_GENERAL_PARAMS" |
| 242 | #define CLASS_PBE_PARAMS "sun/security/pkcs11/wrapper/CK_PBE_PARAMS" |
| 243 | #define PBE_INIT_VECTOR_SIZE 8 |
| 244 | #define CLASS_PKCS5_PBKD2_PARAMS "sun/security/pkcs11/wrapper/CK_PKCS5_PBKD2_PARAMS" |
| 245 | #define CLASS_EXTRACT_PARAMS "sun/security/pkcs11/wrapper/CK_EXTRACT_PARAMS" |
| 246 | |
| 247 | #define CLASS_RSA_PKCS_PSS_PARAMS "sun/security/pkcs11/wrapper/CK_RSA_PKCS_PSS_PARAMS" |
| 248 | #define CLASS_ECDH1_DERIVE_PARAMS "sun/security/pkcs11/wrapper/CK_ECDH1_DERIVE_PARAMS" |
| 249 | #define CLASS_ECDH2_DERIVE_PARAMS "sun/security/pkcs11/wrapper/CK_ECDH2_DERIVE_PARAMS" |
| 250 | #define CLASS_X9_42_DH1_DERIVE_PARAMS "sun/security/pkcs11/wrapper/CK_X9_42_DH1_DERIVE_PARAMS" |
| 251 | #define CLASS_X9_42_DH2_DERIVE_PARAMS "sun/security/pkcs11/wrapper/CK_X9_42_DH2_DERIVE_PARAMS" |
| 252 | |
| 253 | /* |
| 254 | #define CLASS_KEA_DERIVE_PARAMS "sun/security/pkcs11/wrapper/CK_KEA_DERIVE_PARAMS" |
| 255 | #define CLASS_RC2_PARAMS "sun/security/pkcs11/wrapper/CK_RC2_PARAMS" |
| 256 | #define CLASS_RC2_CBC_PARAMS "sun/security/pkcs11/wrapper/CK_RC2_CBC_PARAMS" |
| 257 | #define CLASS_RC2_MAC_GENERAL_PARAMS "sun/security/pkcs11/wrapper/CK_RC2_MAC_GENERAL_PARAMS" |
| 258 | #define CLASS_RC5_PARAMS "sun/security/pkcs11/wrapper/CK_RC5_PARAMS" |
| 259 | #define CLASS_RC5_CBC_PARAMS "sun/security/pkcs11/wrapper/CK_RC5_CBC_PARAMS" |
| 260 | #define CLASS_RC5_MAC_GENERAL_PARAMS "sun/security/pkcs11/wrapper/CK_RC5_MAC_GENERAL_PARAMS" |
| 261 | #define CLASS_SKIPJACK_PRIVATE_WRAP_PARAMS "sun/security/pkcs11/wrapper/CK_SKIPJACK_PRIVATE_WRAP_PARAMS" |
| 262 | #define CLASS_SKIPJACK_RELAYX_PARAMS "sun/security/pkcs11/wrapper/CK_SKIPJACK_RELAYX_PARAMS" |
| 263 | #define CLASS_KEY_WRAP_SET_OAEP_PARAMS "sun/security/pkcs11/wrapper/CK_KEY_WRAP_SET_OAEP_PARAMS" |
| 264 | #define CLASS_KEY_DERIVATION_STRING_DATA "sun/security/pkcs11/wrapper/CK_KEY_DERIVATION_STRING_DATA" |
| 265 | */ |
| 266 | |
| 267 | #define CLASS_SSL3_RANDOM_DATA "sun/security/pkcs11/wrapper/CK_SSL3_RANDOM_DATA" |
| 268 | // CLASS_SSL3_RANDOM_DATA is used by CLASS_SSL3_MASTER_KEY_DERIVE_PARAMS |
| 269 | #define CLASS_SSL3_KEY_MAT_OUT "sun/security/pkcs11/wrapper/CK_SSL3_KEY_MAT_OUT" |
| 270 | // CLASS_SSL3_KEY_MAT_OUT is used by CLASS_SSL3_KEY_MAT_PARAMS |
| 271 | #define CLASS_SSL3_MASTER_KEY_DERIVE_PARAMS "sun/security/pkcs11/wrapper/CK_SSL3_MASTER_KEY_DERIVE_PARAMS" |
| 272 | #define CLASS_SSL3_KEY_MAT_PARAMS "sun/security/pkcs11/wrapper/CK_SSL3_KEY_MAT_PARAMS" |
| 273 | #define CLASS_TLS_PRF_PARAMS "sun/security/pkcs11/wrapper/CK_TLS_PRF_PARAMS" |
| 274 | |
| 275 | /* function to convert a PKCS#11 return value other than CK_OK into a Java Exception |
| 276 | * or to throw a PKCS11RuntimeException |
| 277 | */ |
| 278 | |
| 279 | jlong ckAssertReturnValueOK(JNIEnv *env, CK_RV returnValue); |
| 280 | void throwPKCS11RuntimeException(JNIEnv *env, jstring jmessage); |
| 281 | void throwFileNotFoundException(JNIEnv *env, jstring jmessage); |
| 282 | void throwIOException(JNIEnv *env, const char *message); |
| 283 | void throwIOExceptionUnicodeMessage(JNIEnv *env, const short *message); |
| 284 | void throwDisconnectedRuntimeException(JNIEnv *env); |
| 285 | |
| 286 | /* funktions to convert Java arrays to a CK-type array and the array length */ |
| 287 | |
| 288 | void jBooleanArrayToCKBBoolArray(JNIEnv *env, const jbooleanArray jArray, CK_BBOOL **ckpArray, CK_ULONG_PTR ckLength); |
| 289 | void jByteArrayToCKByteArray(JNIEnv *env, const jbyteArray jArray, CK_BYTE_PTR *ckpArray, CK_ULONG_PTR ckLength); |
| 290 | void jLongArrayToCKULongArray(JNIEnv *env, const jlongArray jArray, CK_ULONG_PTR *ckpArray, CK_ULONG_PTR ckLength); |
| 291 | void jCharArrayToCKCharArray(JNIEnv *env, const jcharArray jArray, CK_CHAR_PTR *ckpArray, CK_ULONG_PTR ckLength); |
| 292 | void jCharArrayToCKUTF8CharArray(JNIEnv *env, const jcharArray jArray, CK_UTF8CHAR_PTR *ckpArray, CK_ULONG_PTR ckLength); |
| 293 | void jStringToCKUTF8CharArray(JNIEnv *env, const jstring jArray, CK_UTF8CHAR_PTR *ckpArray, CK_ULONG_PTR ckpLength); |
| 294 | void jAttributeArrayToCKAttributeArray(JNIEnv *env, jobjectArray jAArray, CK_ATTRIBUTE_PTR *ckpArray, CK_ULONG_PTR ckpLength); |
| 295 | /*void jObjectArrayToCKVoidPtrArray(JNIEnv *env, const jobjectArray jArray, CK_VOID_PTR_PTR ckpArray, CK_ULONG_PTR ckpLength); */ |
| 296 | |
| 297 | |
| 298 | /* funktions to convert a CK-type array and the array length to a Java array */ |
| 299 | |
| 300 | jcharArray ckByteArrayToJByteArray(JNIEnv *env, const CK_BYTE_PTR ckpArray, CK_ULONG ckLength); |
| 301 | jlongArray ckULongArrayToJLongArray(JNIEnv *env, const CK_ULONG_PTR ckpArray, CK_ULONG ckLength); |
| 302 | jcharArray ckCharArrayToJCharArray(JNIEnv *env, const CK_CHAR_PTR ckpArray, CK_ULONG length); |
| 303 | jcharArray ckUTF8CharArrayToJCharArray(JNIEnv *env, const CK_UTF8CHAR_PTR ckpArray, CK_ULONG ckLength); |
| 304 | |
| 305 | |
| 306 | /* funktions to convert a CK-type structure or a pointer to a CK-value to a Java object */ |
| 307 | |
| 308 | jobject ckBBoolPtrToJBooleanObject(JNIEnv *env, const CK_BBOOL* ckpValue); |
| 309 | jobject ckULongPtrToJLongObject(JNIEnv *env, const CK_ULONG_PTR ckpValue); |
| 310 | jobject ckDatePtrToJDateObject(JNIEnv *env, const CK_DATE *ckpValue); |
| 311 | jobject ckVersionPtrToJVersion(JNIEnv *env, const CK_VERSION_PTR ckpVersion); |
| 312 | jobject ckSessionInfoPtrToJSessionInfo(JNIEnv *env, const CK_SESSION_INFO_PTR ckpSessionInfo); |
| 313 | jobject ckAttributePtrToJAttribute(JNIEnv *env, const CK_ATTRIBUTE_PTR ckpAttribute); |
| 314 | |
| 315 | |
| 316 | /* funktion to convert the CK-value used by the CK_ATTRIBUTE structure to a Java object */ |
| 317 | |
| 318 | jobject ckAttributeValueToJObject(JNIEnv *env, const CK_ATTRIBUTE_PTR ckpAttribute); |
| 319 | |
| 320 | |
| 321 | /* funktions to convert a Java object to a CK-type structure or a pointer to a CK-value */ |
| 322 | |
| 323 | CK_BBOOL* jBooleanObjectToCKBBoolPtr(JNIEnv *env, jobject jObject); |
| 324 | CK_BYTE_PTR jByteObjectToCKBytePtr(JNIEnv *env, jobject jObject); |
| 325 | CK_ULONG* jIntegerObjectToCKULongPtr(JNIEnv *env, jobject jObject); |
| 326 | CK_ULONG* jLongObjectToCKULongPtr(JNIEnv *env, jobject jObject); |
| 327 | CK_CHAR_PTR jCharObjectToCKCharPtr(JNIEnv *env, jobject jObject); |
| 328 | CK_VERSION_PTR jVersionToCKVersionPtr(JNIEnv *env, jobject jVersion); |
| 329 | CK_DATE * jDateObjectPtrToCKDatePtr(JNIEnv *env, jobject jDate); |
| 330 | CK_ATTRIBUTE jAttributeToCKAttribute(JNIEnv *env, jobject jAttribute); |
| 331 | /*CK_MECHANISM jMechanismToCKMechanism(JNIEnv *env, jobject jMechanism);*/ |
| 332 | void jMechanismToCKMechanism(JNIEnv *env, jobject jMechanism, CK_MECHANISM_PTR ckMechanismPtr); |
| 333 | |
| 334 | |
| 335 | /* funktions to convert Java objects used by the Mechanism and Attribute class to a CK-type structure */ |
| 336 | |
| 337 | void jObjectToPrimitiveCKObjectPtrPtr(JNIEnv *env, jobject jObject, CK_VOID_PTR *ckpObjectPtr, CK_ULONG *pLength); |
| 338 | void jMechanismParameterToCKMechanismParameter(JNIEnv *env, jobject jParam, CK_VOID_PTR *ckpParamPtr, CK_ULONG *ckpLength); |
| 339 | |
| 340 | |
| 341 | /* functions to convert a specific Java mechanism parameter object to a CK-mechanism parameter structure */ |
| 342 | |
| 343 | CK_RSA_PKCS_OAEP_PARAMS jRsaPkcsOaepParamToCKRsaPkcsOaepParam(JNIEnv *env, jobject jParam); |
| 344 | CK_KEA_DERIVE_PARAMS jKeaDeriveParamToCKKeaDeriveParam(JNIEnv *env, jobject jParam); |
| 345 | CK_RC2_CBC_PARAMS jRc2CbcParamToCKRc2CbcParam(JNIEnv *env, jobject jParam); |
| 346 | CK_RC2_MAC_GENERAL_PARAMS jRc2MacGeneralParamToCKRc2MacGeneralParam(JNIEnv *env, jobject jParam); |
| 347 | CK_RC5_PARAMS jRc5ParamToCKRc5Param(JNIEnv *env, jobject jParam); |
| 348 | CK_RC5_CBC_PARAMS jRc5CbcParamToCKRc5CbcParam(JNIEnv *env, jobject jParam); |
| 349 | CK_RC5_MAC_GENERAL_PARAMS jRc5MacGeneralParamToCKRc5MacGeneralParam(JNIEnv *env, jobject jParam); |
| 350 | CK_SKIPJACK_PRIVATE_WRAP_PARAMS jSkipjackPrivateWrapParamToCKSkipjackPrivateWrapParam(JNIEnv *env, jobject jParam); |
| 351 | CK_SKIPJACK_RELAYX_PARAMS jSkipjackRelayxParamToCKSkipjackRelayxParam(JNIEnv *env, jobject jParam); |
| 352 | CK_PBE_PARAMS jPbeParamToCKPbeParam(JNIEnv *env, jobject jParam); |
| 353 | void copyBackPBEInitializationVector(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism); |
| 354 | CK_PKCS5_PBKD2_PARAMS jPkcs5Pbkd2ParamToCKPkcs5Pbkd2Param(JNIEnv *env, jobject jParam); |
| 355 | CK_KEY_WRAP_SET_OAEP_PARAMS jKeyWrapSetOaepParamToCKKeyWrapSetOaepParam(JNIEnv *env, jobject jParam); |
| 356 | void copyBackSetUnwrappedKey(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism); |
| 357 | CK_SSL3_MASTER_KEY_DERIVE_PARAMS jSsl3MasterKeyDeriveParamToCKSsl3MasterKeyDeriveParam(JNIEnv *env, jobject jParam); |
| 358 | void copyBackClientVersion(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism); |
| 359 | CK_SSL3_KEY_MAT_PARAMS jSsl3KeyMatParamToCKSsl3KeyMatParam(JNIEnv *env, jobject jParam); |
| 360 | void copyBackSSLKeyMatParams(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism); |
| 361 | CK_KEY_DERIVATION_STRING_DATA jKeyDerivationStringDataToCKKeyDerivationStringData(JNIEnv *env, jobject jParam); |
| 362 | CK_RSA_PKCS_PSS_PARAMS jRsaPkcsPssParamToCKRsaPkcsPssParam(JNIEnv *env, jobject jParam); |
| 363 | CK_ECDH1_DERIVE_PARAMS jEcdh1DeriveParamToCKEcdh1DeriveParam(JNIEnv *env, jobject jParam); |
| 364 | CK_ECDH2_DERIVE_PARAMS jEcdh2DeriveParamToCKEcdh2DeriveParam(JNIEnv *env, jobject jParam); |
| 365 | CK_X9_42_DH1_DERIVE_PARAMS jX942Dh1DeriveParamToCKX942Dh1DeriveParam(JNIEnv *env, jobject jParam); |
| 366 | CK_X9_42_DH2_DERIVE_PARAMS jX942Dh2DeriveParamToCKX942Dh2DeriveParam(JNIEnv *env, jobject jParam); |
| 367 | |
| 368 | |
| 369 | /* functions to convert the InitArgs object for calling the right Java mutex functions */ |
| 370 | |
| 371 | CK_C_INITIALIZE_ARGS_PTR makeCKInitArgsAdapter(JNIEnv *env, jobject pInitArgs); |
| 372 | |
| 373 | #ifndef NO_CALLBACKS /* if the library should not make callbacks; e.g. no javai.lib or jvm.lib available */ |
| 374 | CK_RV callJCreateMutex(CK_VOID_PTR_PTR ppMutex); |
| 375 | CK_RV callJDestroyMutex(CK_VOID_PTR pMutex); |
| 376 | CK_RV callJLockMutex(CK_VOID_PTR pMutex); |
| 377 | CK_RV callJUnlockMutex(CK_VOID_PTR pMutex); |
| 378 | #endif /* NO_CALLBACKS */ |
| 379 | |
| 380 | void putModuleEntry(JNIEnv *env, jobject pkcs11Implementation, ModuleData *moduleData); |
| 381 | ModuleData * removeModuleEntry(JNIEnv *env, jobject pkcs11Implementation); |
| 382 | CK_FUNCTION_LIST_PTR getFunctionList(JNIEnv *env, jobject pkcs11Implementation); |
| 383 | |
| 384 | /* A structure to encapsulate the required data for a Notify callback */ |
| 385 | struct NotifyEncapsulation { |
| 386 | |
| 387 | /* The object that implements the CK_NOTIFY interface and which should be |
| 388 | * notified. |
| 389 | */ |
| 390 | jobject jNotifyObject; |
| 391 | |
| 392 | /* The data object to pass back to the Notify object upon callback. */ |
| 393 | jobject jApplicationData; |
| 394 | }; |
| 395 | typedef struct NotifyEncapsulation NotifyEncapsulation; |
| 396 | |
| 397 | /* The function for handling notify callbacks. */ |
| 398 | CK_RV notifyCallback( |
| 399 | CK_SESSION_HANDLE hSession, /* the session's handle */ |
| 400 | CK_NOTIFICATION event, |
| 401 | CK_VOID_PTR pApplication /* passed to C_OpenSession */ |
| 402 | ); |
| 403 | |
| 404 | |
| 405 | /* A node of the list of notify callbacks. To be able to free the resources after use. */ |
| 406 | struct NotifyListNode { |
| 407 | |
| 408 | /* The handle of the session this notify object is attached to*/ |
| 409 | CK_SESSION_HANDLE hSession; |
| 410 | |
| 411 | /* Reference to the Notify encapsulation object that was passed to C_OpenSession. */ |
| 412 | NotifyEncapsulation *notifyEncapsulation; |
| 413 | |
| 414 | /* Pointer to the next node in the list. */ |
| 415 | struct NotifyListNode *next; |
| 416 | |
| 417 | }; |
| 418 | typedef struct NotifyListNode NotifyListNode; |
| 419 | |
| 420 | void putNotifyEntry(JNIEnv *env, CK_SESSION_HANDLE hSession, NotifyEncapsulation *notifyEncapsulation); |
| 421 | NotifyEncapsulation * removeNotifyEntry(JNIEnv *env, CK_SESSION_HANDLE hSession); |
| 422 | NotifyEncapsulation * removeFirstNotifyEntry(JNIEnv *env); |
| 423 | |
| 424 | jobject createLockObject(JNIEnv *env); |
| 425 | void destroyLockObject(JNIEnv *env, jobject jLockObject); |
| 426 | |
| 427 | extern jfieldID pNativeDataID; |
| 428 | extern jfieldID mech_mechanismID; |
| 429 | extern jfieldID mech_pParameterID; |
| 430 | |
| 431 | extern jclass jByteArrayClass; |
| 432 | extern jclass jLongClass; |
| 433 | |
| 434 | #ifndef NO_CALLBACKS |
| 435 | extern NotifyListNode *notifyListHead; |
| 436 | extern jobject notifyListLock; |
| 437 | |
| 438 | extern jobject jInitArgsObject; |
| 439 | extern CK_C_INITIALIZE_ARGS_PTR ckpGlobalInitArgs; |
| 440 | #endif /* NO_CALLBACKS */ |