jdk/src/share/native/sun/security/pkcs11/wrapper/p11_util.c
author valeriep
Wed, 22 Jul 2009 17:52:21 -0700
changeset 3321 fed33393bc52
parent 2180 9994f4f08a59
child 5506 202f599c92aa
permissions -rw-r--r--
6823905: crash in sun.security.pkcs11.wrapper.PKCS11.C_Sign during stress-test Summary: Initialize relevant return value to NULL Reviewed-by: vinnie
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
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
     2
 * Portions Copyright 2003-2009 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
/* Copyright  (c) 2002 Graz University of Technology. All rights reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * Redistribution and use in  source and binary forms, with or without
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * modification, are permitted  provided that the following conditions are met:
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * 1. Redistributions of  source code must retain the above copyright notice,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *    this list of conditions and the following disclaimer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * 2. Redistributions in  binary form must reproduce the above copyright notice,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *    this list of conditions and the following disclaimer in the documentation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *    and/or other materials provided with the distribution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * 3. The end-user documentation included with the redistribution, if any, must
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *    include the following acknowledgment:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *    "This product includes software developed by IAIK of Graz University of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 *     Technology."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 *    Alternately, this acknowledgment may appear in the software itself, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 *    and wherever such third-party acknowledgments normally appear.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * 4. The names "Graz University of Technology" and "IAIK of Graz University of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *    Technology" must not be used to endorse or promote products derived from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *    this software without prior written permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * 5. Products derived from this software may not be called
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *    "IAIK PKCS Wrapper", nor may "IAIK" appear in their name, without prior
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *    written permission of Graz University of Technology.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *  THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LICENSOR BE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *  POSSIBILITY  OF SUCH DAMAGE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
#include "pkcs11wrapper.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
#include <stdio.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
#include <assert.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
/* declare file private functions */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
ModuleData * getModuleEntry(JNIEnv *env, jobject pkcs11Implementation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
int isModulePresent(JNIEnv *env, jobject pkcs11Implementation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
void removeAllModuleEntries(JNIEnv *env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
/* ************************************************************************** */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
/* Functions for keeping track of currently active and loaded modules         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
/* ************************************************************************** */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * Create a new object for locking.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
jobject createLockObject(JNIEnv *env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    jclass jObjectClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    jobject jLockObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    jmethodID jConstructor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    jObjectClass = (*env)->FindClass(env, "java/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
    76
    if (jObjectClass == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    jConstructor = (*env)->GetMethodID(env, jObjectClass, "<init>", "()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
    78
    if (jConstructor == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    jLockObject = (*env)->NewObject(env, jObjectClass, jConstructor);
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
    80
    if (jLockObject == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    jLockObject = (*env)->NewGlobalRef(env, jLockObject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    return jLockObject ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * Create a new object for locking.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
void destroyLockObject(JNIEnv *env, jobject jLockObject) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    if (jLockObject != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        (*env)->DeleteGlobalRef(env, jLockObject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * Add the given pkcs11Implementation object to the list of present modules.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * Attach the given data to the entry. If the given pkcs11Implementation is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * already in the lsit, just override its old module data with the new one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * None of the arguments can be NULL. If one of the arguments is NULL, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * function does nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
void putModuleEntry(JNIEnv *env, jobject pkcs11Implementation, ModuleData *moduleData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    if (pkcs11Implementation == NULL_PTR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        return ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    if (moduleData == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        return ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    (*env)->SetLongField(env, pkcs11Implementation, pNativeDataID, (jlong)moduleData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * Get the module data of the entry for the given pkcs11Implementation. Returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * NULL, if the pkcs11Implementation is not in the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
ModuleData * getModuleEntry(JNIEnv *env, jobject pkcs11Implementation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    jlong jData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    if (pkcs11Implementation == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    jData = (*env)->GetLongField(env, pkcs11Implementation, pNativeDataID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    return (ModuleData*)jData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
CK_FUNCTION_LIST_PTR getFunctionList(JNIEnv *env, jobject pkcs11Implementation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    ModuleData *moduleData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    CK_FUNCTION_LIST_PTR ckpFunctions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    moduleData = getModuleEntry(env, pkcs11Implementation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    if (moduleData == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        throwDisconnectedRuntimeException(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    ckpFunctions = moduleData->ckFunctionListPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    return ckpFunctions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * Returns 1, if the given pkcs11Implementation is in the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * 0, otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
int isModulePresent(JNIEnv *env, jobject pkcs11Implementation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    int present;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    ModuleData *moduleData = getModuleEntry(env, pkcs11Implementation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    present = (moduleData != NULL) ? 1 : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    return present ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 * Removes the entry for the given pkcs11Implementation from the list. Returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 * the module's data, after the node was removed. If this function returns NULL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 * the pkcs11Implementation was not in the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
ModuleData * removeModuleEntry(JNIEnv *env, jobject pkcs11Implementation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    ModuleData *moduleData = getModuleEntry(env, pkcs11Implementation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    if (moduleData == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    (*env)->SetLongField(env, pkcs11Implementation, pNativeDataID, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    return moduleData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 * Removes all present entries from the list of modules and frees all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 * associated resources. This function is used for clean-up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
void removeAllModuleEntries(JNIEnv *env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /* XXX empty */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
/* ************************************************************************** */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
/* Below there follow the helper functions to support conversions between     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
/* Java and Cryptoki types                                                    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
/* ************************************************************************** */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
 * function to convert a PKCS#11 return value into a PKCS#11Exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 * This function generates a PKCS#11Exception with the returnValue as the errorcode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
 * if the returnValue is not CKR_OK. The functin returns 0, if the returnValue is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
 * CKR_OK. Otherwise, it returns the returnValue as a jLong.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
 * @param env - used to call JNI funktions and to get the Exception class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
 * @param returnValue - of the PKCS#11 function
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
jlong ckAssertReturnValueOK(JNIEnv *env, CK_RV returnValue)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    jclass jPKCS11ExceptionClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    jmethodID jConstructor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    jthrowable jPKCS11Exception;
3321
fed33393bc52 6823905: crash in sun.security.pkcs11.wrapper.PKCS11.C_Sign during stress-test
valeriep
parents: 2180
diff changeset
   197
    jlong jErrorCode = 0L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
3321
fed33393bc52 6823905: crash in sun.security.pkcs11.wrapper.PKCS11.C_Sign during stress-test
valeriep
parents: 2180
diff changeset
   199
    if (returnValue != CKR_OK) {
fed33393bc52 6823905: crash in sun.security.pkcs11.wrapper.PKCS11.C_Sign during stress-test
valeriep
parents: 2180
diff changeset
   200
        jErrorCode = ckULongToJLong(returnValue);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        jPKCS11ExceptionClass = (*env)->FindClass(env, CLASS_PKCS11EXCEPTION);
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
   202
        if (jPKCS11ExceptionClass != 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
   203
            jConstructor = (*env)->GetMethodID(env, jPKCS11ExceptionClass, "<init>", "(J)V");
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
   204
            if (jConstructor != 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
   205
                jPKCS11Exception = (jthrowable) (*env)->NewObject(env, jPKCS11ExceptionClass, jConstructor, jErrorCode);
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
   206
                if (jPKCS11Exception != 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
   207
                    (*env)->Throw(env, jPKCS11Exception);
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
   208
                }
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
   209
            }
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
   210
        }
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
   211
        (*env)->DeleteLocalRef(env, jPKCS11ExceptionClass);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
3321
fed33393bc52 6823905: crash in sun.security.pkcs11.wrapper.PKCS11.C_Sign during stress-test
valeriep
parents: 2180
diff changeset
   213
    return jErrorCode ;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
/*
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
   217
 * This function simply throws an IOException
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
 * @param env Used to call JNI funktions and to get the Exception class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
 * @param message The message string of the Exception object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
 */
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
   222
void throwIOException(JNIEnv *env, const char *message)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
{
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
   224
    JNU_ThrowByName(env, CLASS_IO_EXCEPTION, message);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
 * This function simply throws a PKCS#11RuntimeException with the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
 * string as its message. If the message is NULL, the exception is created
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
 * using the default constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
 * @param env Used to call JNI funktions and to get the Exception class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
 * @param jmessage The message string of the Exception object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
 */
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
   235
void throwPKCS11RuntimeException(JNIEnv *env, const char *message)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
{
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
   237
    JNU_ThrowByName(env, CLASS_PKCS11RUNTIMEEXCEPTION, message);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
 * This function simply throws a PKCS#11RuntimeException. The message says that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
 * the object is not connected to the module.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
 * @param env Used to call JNI funktions and to get the Exception class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
void throwDisconnectedRuntimeException(JNIEnv *env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
{
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
   248
    throwPKCS11RuntimeException(env, "This object is not connected to a module.");
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
   249
}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
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
   251
/* This function frees the specified CK_ATTRIBUTE array.
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
   252
 *
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
   253
 * @param attrPtr pointer to the to-be-freed CK_ATTRIBUTE array.
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
   254
 * @param len the length of the array
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
   255
 */
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
   256
void freeCKAttributeArray(CK_ATTRIBUTE_PTR attrPtr, int len)
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
   257
{
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
   258
    int i;
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
   259
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
    for (i=0; i<len; i++) {
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
        if (attrPtr[i].pValue != NULL_PTR) {
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
            free(attrPtr[i].pValue);
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
   263
        }
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
   264
    }
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
   265
    free(attrPtr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
 * the following functions convert Java arrays to PKCS#11 array pointers and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
 * their array length and vice versa
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
 * void j<Type>ArrayToCK<Type>Array(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
 *                                  const j<Type>Array jArray,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
 *                                  CK_<Type>_PTR *ckpArray,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
 *                                  CK_ULONG_PTR ckLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
 * j<Type>Array ck<Type>ArrayToJ<Type>Array(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
 *                                          const CK_<Type>_PTR ckpArray,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
 *                                          CK_ULONG ckLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
 * PKCS#11 arrays consist always of a pointer to the beginning of the array and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
 * the array length whereas Java arrays carry their array length.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
 * The Functions to convert a Java array to a PKCS#11 array are void functions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
 * Their arguments are the Java array object to convert, the reference to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
 * array pointer, where the new PKCS#11 array should be stored and the reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
 * to the array length where the PKCS#11 array length should be stored. These two
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
 * references must not be NULL_PTR.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
 * The functions first obtain the array length of the Java array and then allocate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
 * the memory for the PKCS#11 array and set the array length. Then each element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
 * gets converted depending on their type. After use the allocated memory of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
 * PKCS#11 array has to be explicitly freed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
 * The Functions to convert a PKCS#11 array to a Java array get the PKCS#11 array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
 * pointer and the array length and they return the new Java array object. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
 * Java array does not need to get freed after use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
 * converts a jbooleanArray to a CK_BBOOL array. The allocated memory has to be freed after use!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
 * @param env - used to call JNI funktions to get the array informtaion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
 * @param jArray - the Java array to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
 * @param ckpArray - the reference, where the pointer to the new CK_BBOOL array will be stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
 * @param ckpLength - the reference, where the array length will be stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
void jBooleanArrayToCKBBoolArray(JNIEnv *env, const jbooleanArray jArray, CK_BBOOL **ckpArray, CK_ULONG_PTR ckpLength)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    jboolean* jpTemp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    CK_ULONG i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    if(jArray == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        *ckpArray = NULL_PTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        *ckpLength = 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    *ckpLength = (*env)->GetArrayLength(env, jArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    jpTemp = (jboolean*) malloc((*ckpLength) * sizeof(jboolean));
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
   320
    if (jpTemp == 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
   321
        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
   322
        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
   323
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    (*env)->GetBooleanArrayRegion(env, jArray, 0, *ckpLength, jpTemp);
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
   325
    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
   326
        free(jpTemp);
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
   327
        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
   328
    }
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
   329
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    *ckpArray = (CK_BBOOL*) malloc ((*ckpLength) * sizeof(CK_BBOOL));
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
   331
    if (*ckpArray == 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
   332
        free(jpTemp);
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
   333
        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
   334
        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
   335
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    for (i=0; i<(*ckpLength); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        (*ckpArray)[i] = jBooleanToCKBBool(jpTemp[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    free(jpTemp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
 * converts a jbyteArray to a CK_BYTE array. The allocated memory has to be freed after use!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
 * @param env - used to call JNI funktions to get the array informtaion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
 * @param jArray - the Java array to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
 * @param ckpArray - the reference, where the pointer to the new CK_BYTE array will be stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
 * @param ckpLength - the reference, where the array length will be stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
void jByteArrayToCKByteArray(JNIEnv *env, const jbyteArray jArray, CK_BYTE_PTR *ckpArray, CK_ULONG_PTR ckpLength)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    jbyte* jpTemp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    CK_ULONG i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    if(jArray == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        *ckpArray = NULL_PTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        *ckpLength = 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    *ckpLength = (*env)->GetArrayLength(env, jArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    jpTemp = (jbyte*) malloc((*ckpLength) * sizeof(jbyte));
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
   362
    if (jpTemp == 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
   363
        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
   364
        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
   365
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    (*env)->GetByteArrayRegion(env, jArray, 0, *ckpLength, jpTemp);
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
   367
    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
   368
        free(jpTemp);
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
   369
        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
   370
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    /* if CK_BYTE is the same size as jbyte, we save an additional copy */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    if (sizeof(CK_BYTE) == sizeof(jbyte)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        *ckpArray = (CK_BYTE_PTR) jpTemp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        *ckpArray = (CK_BYTE_PTR) malloc ((*ckpLength) * sizeof(CK_BYTE));
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
   377
        if (*ckpArray == 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
   378
            free(jpTemp);
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
   379
            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
   380
            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
   381
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        for (i=0; i<(*ckpLength); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            (*ckpArray)[i] = jByteToCKByte(jpTemp[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        free(jpTemp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
 * converts a jlongArray to a CK_ULONG array. The allocated memory has to be freed after use!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
 * @param env - used to call JNI funktions to get the array informtaion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
 * @param jArray - the Java array to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
 * @param ckpArray - the reference, where the pointer to the new CK_ULONG array will be stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
 * @param ckpLength - the reference, where the array length will be stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
void jLongArrayToCKULongArray(JNIEnv *env, const jlongArray jArray, CK_ULONG_PTR *ckpArray, CK_ULONG_PTR ckpLength)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    jlong* jTemp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    CK_ULONG i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    if(jArray == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        *ckpArray = NULL_PTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        *ckpLength = 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    *ckpLength = (*env)->GetArrayLength(env, jArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    jTemp = (jlong*) malloc((*ckpLength) * sizeof(jlong));
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
   409
    if (jTemp == 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
   410
        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
   411
        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
   412
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    (*env)->GetLongArrayRegion(env, jArray, 0, *ckpLength, jTemp);
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
   414
    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
   415
        free(jTemp);
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
   416
        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
   417
    }
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
   418
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    *ckpArray = (CK_ULONG_PTR) malloc (*ckpLength * sizeof(CK_ULONG));
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
   420
    if (*ckpArray == 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
   421
        free(jTemp);
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
        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
   423
        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
   424
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    for (i=0; i<(*ckpLength); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        (*ckpArray)[i] = jLongToCKULong(jTemp[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    free(jTemp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
 * converts a jcharArray to a CK_CHAR array. The allocated memory has to be freed after use!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
 * @param env - used to call JNI funktions to get the array informtaion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
 * @param jArray - the Java array to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
 * @param ckpArray - the reference, where the pointer to the new CK_CHAR array will be stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
 * @param ckpLength - the reference, where the array length will be stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
void jCharArrayToCKCharArray(JNIEnv *env, const jcharArray jArray, CK_CHAR_PTR *ckpArray, CK_ULONG_PTR ckpLength)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    jchar* jpTemp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    CK_ULONG i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    if(jArray == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        *ckpArray = NULL_PTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        *ckpLength = 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    *ckpLength = (*env)->GetArrayLength(env, jArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    jpTemp = (jchar*) malloc((*ckpLength) * sizeof(jchar));
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
   451
    if (jpTemp == 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
   452
        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
   453
        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
   454
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    (*env)->GetCharArrayRegion(env, jArray, 0, *ckpLength, jpTemp);
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
   456
    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
   457
        free(jpTemp);
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
   458
        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
   459
    }
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
   460
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    *ckpArray = (CK_CHAR_PTR) malloc (*ckpLength * sizeof(CK_CHAR));
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
   462
    if (*ckpArray == 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
   463
        free(jpTemp);
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
   464
        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
   465
        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
   466
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    for (i=0; i<(*ckpLength); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        (*ckpArray)[i] = jCharToCKChar(jpTemp[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    free(jpTemp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
 * converts a jcharArray to a CK_UTF8CHAR array. The allocated memory has to be freed after use!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
 * @param env - used to call JNI funktions to get the array informtaion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
 * @param jArray - the Java array to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
 * @param ckpArray - the reference, where the pointer to the new CK_UTF8CHAR array will be stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
 * @param ckpLength - the reference, where the array length will be stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
void jCharArrayToCKUTF8CharArray(JNIEnv *env, const jcharArray jArray, CK_UTF8CHAR_PTR *ckpArray, CK_ULONG_PTR ckpLength)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    jchar* jTemp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    CK_ULONG i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    if(jArray == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        *ckpArray = NULL_PTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        *ckpLength = 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    *ckpLength = (*env)->GetArrayLength(env, jArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    jTemp = (jchar*) malloc((*ckpLength) * sizeof(jchar));
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
   493
    if (jTemp == 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
   494
        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
   495
        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
   496
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    (*env)->GetCharArrayRegion(env, jArray, 0, *ckpLength, jTemp);
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
   498
    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
   499
        free(jTemp);
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
   500
        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
   501
    }
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
   502
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    *ckpArray = (CK_UTF8CHAR_PTR) malloc (*ckpLength * sizeof(CK_UTF8CHAR));
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
   504
    if (*ckpArray == 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
   505
        free(jTemp);
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
   506
        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
   507
        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
   508
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    for (i=0; i<(*ckpLength); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        (*ckpArray)[i] = jCharToCKUTF8Char(jTemp[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    free(jTemp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
 * converts a jstring to a CK_CHAR array. The allocated memory has to be freed after use!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
 * @param env - used to call JNI funktions to get the array informtaion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
 * @param jArray - the Java array to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
 * @param ckpArray - the reference, where the pointer to the new CK_CHAR array will be stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
 * @param ckpLength - the reference, where the array length will be stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
void jStringToCKUTF8CharArray(JNIEnv *env, const jstring jArray, CK_UTF8CHAR_PTR *ckpArray, CK_ULONG_PTR ckpLength)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    const char* pCharArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    jboolean isCopy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    if(jArray == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        *ckpArray = NULL_PTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        *ckpLength = 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    pCharArray = (*env)->GetStringUTFChars(env, jArray, &isCopy);
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
   535
    if (pCharArray == NULL) { 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
   536
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    *ckpLength = strlen(pCharArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    *ckpArray = (CK_UTF8CHAR_PTR) malloc((*ckpLength + 1) * sizeof(CK_UTF8CHAR));
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
   539
    if (*ckpArray == 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
   540
        (*env)->ReleaseStringUTFChars(env, (jstring) jArray, pCharArray);
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
   541
        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
   542
        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
   543
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    strcpy((char*)*ckpArray, pCharArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    (*env)->ReleaseStringUTFChars(env, (jstring) jArray, pCharArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
 * converts a jobjectArray with Java Attributes to a CK_ATTRIBUTE array. The allocated memory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
 * has to be freed after use!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
 * @param env - used to call JNI funktions to get the array informtaion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
 * @param jArray - the Java Attribute array (template) to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
 * @param ckpArray - the reference, where the pointer to the new CK_ATTRIBUTE array will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
 *                   stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
 * @param ckpLength - the reference, where the array length will be stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
void jAttributeArrayToCKAttributeArray(JNIEnv *env, jobjectArray jArray, CK_ATTRIBUTE_PTR *ckpArray, CK_ULONG_PTR ckpLength)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    CK_ULONG i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    jlong jLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    jobject jAttribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    TRACE0("\nDEBUG: jAttributeArrayToCKAttributeArray");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    if (jArray == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        *ckpArray = NULL_PTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        *ckpLength = 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    jLength = (*env)->GetArrayLength(env, jArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    *ckpLength = jLongToCKULong(jLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    *ckpArray = (CK_ATTRIBUTE_PTR) malloc(*ckpLength * sizeof(CK_ATTRIBUTE));
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
   573
    if (*ckpArray == 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
   574
        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
   575
        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
   576
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    TRACE1(", converting %d attibutes", jLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    for (i=0; i<(*ckpLength); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        TRACE1(", getting %d. attibute", i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        jAttribute = (*env)->GetObjectArrayElement(env, jArray, i);
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
   581
        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
   582
            freeCKAttributeArray(*ckpArray, i);
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
   583
            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
   584
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        TRACE1(", jAttribute = %d", jAttribute);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        TRACE1(", converting %d. attibute", i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        (*ckpArray)[i] = jAttributeToCKAttribute(env, jAttribute);
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
   588
        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
   589
            freeCKAttributeArray(*ckpArray, i);
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
   590
            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
   591
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    TRACE0("FINISHED\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
 * converts a CK_BYTE array and its length to a jbyteArray.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
 * @param env - used to call JNI funktions to create the new Java array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
 * @param ckpArray - the pointer to the CK_BYTE array to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
 * @param ckpLength - the length of the array to convert
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
   602
 * @return - the new Java byte array or NULL if error occurred
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
jbyteArray ckByteArrayToJByteArray(JNIEnv *env, const CK_BYTE_PTR ckpArray, CK_ULONG ckLength)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    CK_ULONG i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    jbyte* jpTemp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    jbyteArray jArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    /* if CK_BYTE is the same size as jbyte, we save an additional copy */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    if (sizeof(CK_BYTE) == sizeof(jbyte)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        jpTemp = (jbyte*) ckpArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        jpTemp = (jbyte*) malloc((ckLength) * sizeof(jbyte));
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 (jpTemp == 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
   616
            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
   617
            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
   618
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        for (i=0; i<ckLength; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            jpTemp[i] = ckByteToJByte(ckpArray[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    jArray = (*env)->NewByteArray(env, ckULongToJSize(ckLength));
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
   625
    if (jArray != 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
   626
        (*env)->SetByteArrayRegion(env, jArray, 0, ckULongToJSize(ckLength), jpTemp);
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
   627
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
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
   629
    if (sizeof(CK_BYTE) != sizeof(jbyte)) { free(jpTemp); }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    return jArray ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
 * converts a CK_ULONG array and its length to a jlongArray.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
 * @param env - used to call JNI funktions to create the new Java array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
 * @param ckpArray - the pointer to the CK_ULONG array to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
 * @param ckpLength - the length of the array to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
 * @return - the new Java long array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
jlongArray ckULongArrayToJLongArray(JNIEnv *env, const CK_ULONG_PTR ckpArray, CK_ULONG ckLength)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    CK_ULONG i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    jlong* jpTemp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    jlongArray jArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    jpTemp = (jlong*) malloc((ckLength) * sizeof(jlong));
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
   649
    if (jpTemp == 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
   650
        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
   651
        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
   652
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    for (i=0; i<ckLength; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        jpTemp[i] = ckLongToJLong(ckpArray[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    jArray = (*env)->NewLongArray(env, ckULongToJSize(ckLength));
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
   657
    if (jArray != 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
   658
        (*env)->SetLongArrayRegion(env, jArray, 0, ckULongToJSize(ckLength), jpTemp);
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
   659
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    free(jpTemp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    return jArray ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
 * converts a CK_CHAR array and its length to a jcharArray.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
 * @param env - used to call JNI funktions to create the new Java array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
 * @param ckpArray - the pointer to the CK_CHAR array to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
 * @param ckpLength - the length of the array to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
 * @return - the new Java char array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
jcharArray ckCharArrayToJCharArray(JNIEnv *env, const CK_CHAR_PTR ckpArray, CK_ULONG ckLength)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    CK_ULONG i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    jchar* jpTemp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    jcharArray jArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    jpTemp = (jchar*) malloc(ckLength * sizeof(jchar));
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
   680
    if (jpTemp == 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
   681
        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
   682
        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
   683
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    for (i=0; i<ckLength; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        jpTemp[i] = ckCharToJChar(ckpArray[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
    jArray = (*env)->NewCharArray(env, ckULongToJSize(ckLength));
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
    if (jArray != 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
   689
        (*env)->SetCharArrayRegion(env, jArray, 0, ckULongToJSize(ckLength), jpTemp);
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
   690
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    free(jpTemp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    return jArray ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
 * converts a CK_UTF8CHAR array and its length to a jcharArray.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
 * @param env - used to call JNI funktions to create the new Java array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
 * @param ckpArray - the pointer to the CK_UTF8CHAR array to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
 * @param ckpLength - the length of the array to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
 * @return - the new Java char array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
jcharArray ckUTF8CharArrayToJCharArray(JNIEnv *env, const CK_UTF8CHAR_PTR ckpArray, CK_ULONG ckLength)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    CK_ULONG i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    jchar* jpTemp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    jcharArray jArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    jpTemp = (jchar*) malloc(ckLength * sizeof(jchar));
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
   711
    if (jpTemp == 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
   712
        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
   713
        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
   714
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
    for (i=0; i<ckLength; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        jpTemp[i] = ckUTF8CharToJChar(ckpArray[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    jArray = (*env)->NewCharArray(env, ckULongToJSize(ckLength));
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
   719
    if (jArray != 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
   720
        (*env)->SetCharArrayRegion(env, jArray, 0, ckULongToJSize(ckLength), jpTemp);
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
   721
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    free(jpTemp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    return jArray ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
 * the following functions convert Java objects to PKCS#11 pointers and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
 * length in bytes and vice versa
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
 * CK_<Type>_PTR j<Object>ToCK<Type>Ptr(JNIEnv *env, jobject jObject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
 * jobject ck<Type>PtrToJ<Object>(JNIEnv *env, const CK_<Type>_PTR ckpValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
 * The functions that convert a Java object to a PKCS#11 pointer first allocate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
 * the memory for the PKCS#11 pointer. Then they set each element corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
 * to the fields in the Java object to convert. After use the allocated memory of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
 * the PKCS#11 pointer has to be explicitly freed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
 * The functions to convert a PKCS#11 pointer to a Java object create a new Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
 * object first and than they set all fields in the object depending on the values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
 * of the type or structure where the PKCS#11 pointer points to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
 * converts a CK_BBOOL pointer to a Java boolean Object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
 * @param env - used to call JNI funktions to create the new Java object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
 * @param ckpValue - the pointer to the CK_BBOOL value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
 * @return - the new Java boolean object with the boolean value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
jobject ckBBoolPtrToJBooleanObject(JNIEnv *env, const CK_BBOOL *ckpValue)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    jclass jValueObjectClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    jmethodID jConstructor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
    jobject jValueObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    jboolean jValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    jValueObjectClass = (*env)->FindClass(env, "java/lang/Boolean");
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
   760
    if (jValueObjectClass == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    jConstructor = (*env)->GetMethodID(env, jValueObjectClass, "<init>", "(Z)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
   762
    if (jConstructor == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    jValue = ckBBoolToJBoolean(*ckpValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    jValueObject = (*env)->NewObject(env, jValueObjectClass, jConstructor, jValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    return jValueObject ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
 * converts a CK_ULONG pointer to a Java long Object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
 * @param env - used to call JNI funktions to create the new Java object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
 * @param ckpValue - the pointer to the CK_ULONG value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
 * @return - the new Java long object with the long value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
jobject ckULongPtrToJLongObject(JNIEnv *env, const CK_ULONG_PTR ckpValue)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    jclass jValueObjectClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
    jmethodID jConstructor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    jobject jValueObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
    jlong jValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    jValueObjectClass = (*env)->FindClass(env, "java/lang/Long");
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
   784
    if (jValueObjectClass == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    jConstructor = (*env)->GetMethodID(env, jValueObjectClass, "<init>", "(J)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
   786
    if (jConstructor == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
    jValue = ckULongToJLong(*ckpValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
    jValueObject = (*env)->NewObject(env, jValueObjectClass, jConstructor, jValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
    return jValueObject ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
 * converts a Java boolean object into a pointer to a CK_BBOOL value. The memory has to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
 * freed after use!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
 * @param env - used to call JNI funktions to get the value out of the Java object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
 * @param jObject - the "java/lang/Boolean" object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
 * @return - the pointer to the new CK_BBOOL value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
CK_BBOOL* jBooleanObjectToCKBBoolPtr(JNIEnv *env, jobject jObject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    jclass jObjectClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    jmethodID jValueMethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    jboolean jValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    CK_BBOOL *ckpValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    jObjectClass = (*env)->FindClass(env, "java/lang/Boolean");
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
   809
    if (jObjectClass == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    jValueMethod = (*env)->GetMethodID(env, jObjectClass, "booleanValue", "()Z");
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
   811
    if (jValueMethod == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    jValue = (*env)->CallBooleanMethod(env, jObject, jValueMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    ckpValue = (CK_BBOOL *) malloc(sizeof(CK_BBOOL));
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
   814
    if (ckpValue == 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
   815
        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
   816
        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
   817
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    *ckpValue = jBooleanToCKBBool(jValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
    return ckpValue ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
 * converts a Java byte object into a pointer to a CK_BYTE value. The memory has to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
 * freed after use!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
 * @param env - used to call JNI funktions to get the value out of the Java object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
 * @param jObject - the "java/lang/Byte" object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
 * @return - the pointer to the new CK_BYTE value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
CK_BYTE_PTR jByteObjectToCKBytePtr(JNIEnv *env, jobject jObject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
    jclass jObjectClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    jmethodID jValueMethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
    jbyte jValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
    CK_BYTE_PTR ckpValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
    jObjectClass = (*env)->FindClass(env, "java/lang/Byte");
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
   839
    if (jObjectClass == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    jValueMethod = (*env)->GetMethodID(env, jObjectClass, "byteValue", "()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
   841
    if (jValueMethod == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
    jValue = (*env)->CallByteMethod(env, jObject, jValueMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    ckpValue = (CK_BYTE_PTR) malloc(sizeof(CK_BYTE));
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
   844
    if (ckpValue == 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
   845
        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
   846
        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
   847
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
    *ckpValue = jByteToCKByte(jValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    return ckpValue ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
 * converts a Java integer object into a pointer to a CK_ULONG value. The memory has to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
 * freed after use!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
 * @param env - used to call JNI funktions to get the value out of the Java object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
 * @param jObject - the "java/lang/Integer" object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
 * @return - the pointer to the new CK_ULONG value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
CK_ULONG* jIntegerObjectToCKULongPtr(JNIEnv *env, jobject jObject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
    jclass jObjectClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
    jmethodID jValueMethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
    jint jValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
    CK_ULONG *ckpValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
    jObjectClass = (*env)->FindClass(env, "java/lang/Integer");
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
   868
    if (jObjectClass == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
    jValueMethod = (*env)->GetMethodID(env, jObjectClass, "intValue", "()I");
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
   870
    if (jValueMethod == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
    jValue = (*env)->CallIntMethod(env, jObject, jValueMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
    ckpValue = (CK_ULONG *) malloc(sizeof(CK_ULONG));
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
   873
    if (ckpValue == 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
   874
        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
   875
        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
   876
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
    *ckpValue = jLongToCKLong(jValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
    return ckpValue ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
 * converts a Java long object into a pointer to a CK_ULONG value. The memory has to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
 * freed after use!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
 * @param env - used to call JNI funktions to get the value out of the Java object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
 * @param jObject - the "java/lang/Long" object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
 * @return - the pointer to the new CK_ULONG value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
CK_ULONG* jLongObjectToCKULongPtr(JNIEnv *env, jobject jObject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
    jclass jObjectClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    jmethodID jValueMethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
    jlong jValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
    CK_ULONG *ckpValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
    jObjectClass = (*env)->FindClass(env, "java/lang/Long");
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
   897
    if (jObjectClass == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
    jValueMethod = (*env)->GetMethodID(env, jObjectClass, "longValue", "()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
   899
    if (jValueMethod == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
    jValue = (*env)->CallLongMethod(env, jObject, jValueMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
    ckpValue = (CK_ULONG *) malloc(sizeof(CK_ULONG));
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
   902
    if (ckpValue == 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
   903
        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
   904
        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
   905
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
    *ckpValue = jLongToCKULong(jValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
    return ckpValue ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
 * converts a Java char object into a pointer to a CK_CHAR value. The memory has to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
 * freed after use!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
 * @param env - used to call JNI funktions to get the value out of the Java object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
 * @param jObject - the "java/lang/Char" object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
 * @return - the pointer to the new CK_CHAR value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
CK_CHAR_PTR jCharObjectToCKCharPtr(JNIEnv *env, jobject jObject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
    jclass jObjectClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
    jmethodID jValueMethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
    jchar jValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
    CK_CHAR_PTR ckpValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
    jObjectClass = (*env)->FindClass(env, "java/lang/Char");
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
   927
    if (jObjectClass == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
    jValueMethod = (*env)->GetMethodID(env, jObjectClass, "charValue", "()C");
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
   929
    if (jValueMethod == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
    jValue = (*env)->CallCharMethod(env, jObject, jValueMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
    ckpValue = (CK_CHAR_PTR) malloc(sizeof(CK_CHAR));
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
   932
    if (ckpValue == 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
   933
        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
   934
        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
   935
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
    *ckpValue = jCharToCKChar(jValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
    return ckpValue ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
 * converts a Java object into a pointer to CK-type or a CK-structure with the length in Bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
 * The memory of *ckpObjectPtr to be freed after use! This function is only used by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
 * jAttributeToCKAttribute by now.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
 * @param env - used to call JNI funktions to get the Java classes and objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
 * @param jObject - the Java object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
 * @param ckpObjectPtr - the reference of the new pointer to the new CK-value or CK-structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
 * @param ckpLength - the reference of the length in bytes of the new CK-value or CK-structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
void jObjectToPrimitiveCKObjectPtrPtr(JNIEnv *env, jobject jObject, CK_VOID_PTR *ckpObjectPtr, CK_ULONG *ckpLength)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
{
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
   953
    jclass jLongClass, jBooleanClass, jByteArrayClass, jCharArrayClass;
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
   954
    jclass jByteClass, jDateClass, jCharacterClass, jIntegerClass;
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
   955
    jclass jBooleanArrayClass, jIntArrayClass, jLongArrayClass;
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
   956
    jclass jStringClass;
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
   957
    jclass jObjectClass, jClassClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
    CK_VOID_PTR ckpVoid = *ckpObjectPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
    jmethodID jMethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
    jobject jClassObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
    jstring jClassNameString;
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
   962
    char *classNameString, *exceptionMsgPrefix, *exceptionMsg;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
    TRACE0("\nDEBUG: jObjectToPrimitiveCKObjectPtrPtr");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
    if (jObject == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        *ckpObjectPtr = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        *ckpLength = 0;
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
   968
        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
   969
    }
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
   970
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
   971
    jLongClass = (*env)->FindClass(env, "java/lang/Long");
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
   972
    if (jLongClass == NULL) { 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
   973
    if ((*env)->IsInstanceOf(env, jObject, jLongClass)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        *ckpObjectPtr = jLongObjectToCKULongPtr(env, jObject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        *ckpLength = sizeof(CK_ULONG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        TRACE1("<converted long value %X>", *((CK_ULONG *) *ckpObjectPtr));
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
   977
        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
   978
    }
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
   979
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
   980
    jBooleanClass = (*env)->FindClass(env, "java/lang/Boolean");
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
   981
    if (jBooleanClass == NULL) { 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
   982
    if ((*env)->IsInstanceOf(env, jObject, jBooleanClass)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        *ckpObjectPtr = jBooleanObjectToCKBBoolPtr(env, jObject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
        *ckpLength = sizeof(CK_BBOOL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
        TRACE0(" <converted boolean value ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        TRACE0((*((CK_BBOOL *) *ckpObjectPtr) == TRUE) ? "TRUE>" : "FALSE>");
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
   987
        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
   988
    }
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
   989
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
   990
    jByteArrayClass = (*env)->FindClass(env, "[B");
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
   991
    if (jByteArrayClass == NULL) { 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
   992
    if ((*env)->IsInstanceOf(env, jObject, jByteArrayClass)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
        jByteArrayToCKByteArray(env, jObject, (CK_BYTE_PTR*)ckpObjectPtr, ckpLength);
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
   994
        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
   995
    }
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
   996
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
   997
    jCharArrayClass = (*env)->FindClass(env, "[C");
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
   998
    if (jCharArrayClass == NULL) { 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
   999
    if ((*env)->IsInstanceOf(env, jObject, jCharArrayClass)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
        jCharArrayToCKUTF8CharArray(env, jObject, (CK_UTF8CHAR_PTR*)ckpObjectPtr, ckpLength);
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
  1001
        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
  1002
    }
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
  1003
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
  1004
    jByteClass = (*env)->FindClass(env, "java/lang/Byte");
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
  1005
    if (jByteClass == NULL) { 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
  1006
    if ((*env)->IsInstanceOf(env, jObject, jByteClass)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        *ckpObjectPtr = jByteObjectToCKBytePtr(env, jObject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
        *ckpLength = sizeof(CK_BYTE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
        TRACE1("<converted byte value %X>", *((CK_BYTE *) *ckpObjectPtr));
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
  1010
        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
  1011
    }
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
  1012
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
  1013
    jDateClass = (*env)->FindClass(env, CLASS_DATE);
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
  1014
    if (jDateClass == NULL) { 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
  1015
    if ((*env)->IsInstanceOf(env, jObject, jDateClass)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        *ckpObjectPtr = jDateObjectPtrToCKDatePtr(env, jObject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
        *ckpLength = sizeof(CK_DATE);
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
  1018
        TRACE3("<converted date value %.4s-%.2s-%.2s>", (*((CK_DATE *) *ckpObjectPtr)).year, (*((CK_DATE *) *ckpObjectPtr)).month, (*((CK_DATE *) *ckpObjectPtr)).day);
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
  1019
        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
  1020
    }
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
  1021
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
  1022
    jCharacterClass = (*env)->FindClass(env, "java/lang/Character");
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
  1023
    if (jCharacterClass == NULL) { 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
  1024
    if ((*env)->IsInstanceOf(env, jObject, jCharacterClass)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
        *ckpObjectPtr = jCharObjectToCKCharPtr(env, jObject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
        *ckpLength = sizeof(CK_UTF8CHAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
        TRACE1("<converted char value %c>", *((CK_CHAR *) *ckpObjectPtr));
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
  1028
        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
  1029
    }
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
  1030
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
  1031
    jIntegerClass = (*env)->FindClass(env, "java/lang/Integer");
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
  1032
    if (jIntegerClass == NULL) { 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
  1033
    if ((*env)->IsInstanceOf(env, jObject, jIntegerClass)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
        *ckpObjectPtr = jIntegerObjectToCKULongPtr(env, jObject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
        *ckpLength = sizeof(CK_ULONG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
        TRACE1("<converted integer value %X>", *((CK_ULONG *) *ckpObjectPtr));
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
  1037
        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
  1038
    }
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
  1039
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
  1040
    jBooleanArrayClass = (*env)->FindClass(env, "[Z");
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
  1041
    if (jBooleanArrayClass == NULL) { 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
  1042
    if ((*env)->IsInstanceOf(env, jObject, jBooleanArrayClass)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        jBooleanArrayToCKBBoolArray(env, jObject, (CK_BBOOL**)ckpObjectPtr, ckpLength);
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
  1044
        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
  1045
    }
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
  1046
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
  1047
    jIntArrayClass = (*env)->FindClass(env, "[I");
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
  1048
    if (jIntArrayClass == NULL) { 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
  1049
    if ((*env)->IsInstanceOf(env, jObject, jIntArrayClass)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
        jLongArrayToCKULongArray(env, jObject, (CK_ULONG_PTR*)ckpObjectPtr, ckpLength);
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
  1051
        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
  1052
    }
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
  1053
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
  1054
    jLongArrayClass = (*env)->FindClass(env, "[J");
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
  1055
    if (jLongArrayClass == NULL) { 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
  1056
    if ((*env)->IsInstanceOf(env, jObject, jLongArrayClass)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        jLongArrayToCKULongArray(env, jObject, (CK_ULONG_PTR*)ckpObjectPtr, ckpLength);
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
  1058
        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
  1059
    }
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
  1060
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
  1061
    jStringClass = (*env)->FindClass(env, "java/lang/String");
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
  1062
    if (jStringClass == NULL) { 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
  1063
    if ((*env)->IsInstanceOf(env, jObject, jStringClass)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
        jStringToCKUTF8CharArray(env, jObject, (CK_UTF8CHAR_PTR*)ckpObjectPtr, ckpLength);
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
  1065
        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
  1066
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
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
  1068
    /* type of jObject unknown, throw PKCS11RuntimeException */
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
  1069
    jObjectClass = (*env)->FindClass(env, "java/lang/Object");
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
  1070
    if (jObjectClass == NULL) { 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
  1071
    jMethod = (*env)->GetMethodID(env, jObjectClass, "getClass", "()Ljava/lang/Class;");
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
  1072
    if (jMethod == NULL) { 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
  1073
    jClassObject = (*env)->CallObjectMethod(env, jObject, jMethod);
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
  1074
    assert(jClassObject != 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
  1075
    jClassClass = (*env)->FindClass(env, "java/lang/Class");
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
  1076
    if (jClassClass == NULL) { 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
  1077
    jMethod = (*env)->GetMethodID(env, jClassClass, "getName", "()Ljava/lang/String;");
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
  1078
    if (jMethod == NULL) { 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
  1079
    jClassNameString = (jstring)
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
  1080
        (*env)->CallObjectMethod(env, jClassObject, jMethod);
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
  1081
    assert(jClassNameString != 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
  1082
    classNameString = (char*)
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
  1083
        (*env)->GetStringUTFChars(env, jClassNameString, 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
  1084
    if (classNameString == NULL) { 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
  1085
    exceptionMsgPrefix = "Java object of this class cannot be converted to native PKCS#11 type: ";
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
  1086
    exceptionMsg = (char *)
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
  1087
        malloc((strlen(exceptionMsgPrefix) + strlen(classNameString) + 1));
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
  1088
    if (exceptionMsg == 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
  1089
        (*env)->ReleaseStringUTFChars(env, jClassNameString, classNameString);
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
  1090
        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
  1091
        return;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
    }
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
  1093
    strcpy(exceptionMsg, exceptionMsgPrefix);
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
  1094
    strcat(exceptionMsg, classNameString);
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
  1095
    (*env)->ReleaseStringUTFChars(env, jClassNameString, classNameString);
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
  1096
    throwPKCS11RuntimeException(env, exceptionMsg);
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
  1097
    free(exceptionMsg);
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
  1098
    *ckpObjectPtr = 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
  1099
    *ckpLength = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
    TRACE0("FINISHED\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
}
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
  1103
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
  1104
#ifdef P11_MEMORYDEBUG
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
  1105
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
  1106
#undef malloc
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
  1107
#undef free
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
  1108
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
  1109
void *p11malloc(size_t c, char *file, int line) {
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
  1110
    void *p = malloc(c);
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
  1111
    printf("malloc\t%08x\t%d\t%s:%d\n", p, c, file, line); fflush(stdout);
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
  1112
    return p;
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
  1113
}
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
  1114
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
  1115
void p11free(void *p, char *file, int line) {
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
  1116
    printf("free\t%08x\t\t%s:%d\n", p, file, line); fflush(stdout);
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
  1117
    free(p);
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
  1118
}
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
  1119
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
  1120
#endif
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
  1121