jdk/src/share/native/sun/security/pkcs11/wrapper/p11_general.c
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 3321 fed33393bc52
child 10798 413b731e1818
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3321
diff changeset
     2
 * Copyright (c) 2003, 2009, Oracle and/or its affiliates. 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
#include "sun_security_pkcs11_wrapper_PKCS11.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
/* declare file private functions */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
void prefetchFields(JNIEnv *env, jclass thisClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
jobject ckInfoPtrToJInfo(JNIEnv *env, const CK_INFO_PTR ckpInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
jobject ckSlotInfoPtrToJSlotInfo(JNIEnv *env, const CK_SLOT_INFO_PTR ckpSlotInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
jobject ckTokenInfoPtrToJTokenInfo(JNIEnv *env, const CK_TOKEN_INFO_PTR ckpTokenInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
jobject ckMechanismInfoPtrToJMechanismInfo(JNIEnv *env, const CK_MECHANISM_INFO_PTR ckpMechanismInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
/* define variables */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
jfieldID pNativeDataID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
jfieldID mech_mechanismID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
jfieldID mech_pParameterID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
jclass jByteArrayClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
jclass jLongClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    return JNI_VERSION_1_4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
/* ************************************************************************** */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
/* The native implementation of the methods of the PKCS11Implementation class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
/* ************************************************************************** */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * This method is used to do static initialization. This method is static and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * synchronized. Summary: use this method like a static initialization block.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * Method:    initializeLibrary
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
Java_sun_security_pkcs11_wrapper_PKCS11_initializeLibrary
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
(JNIEnv *env, jclass thisClass)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
#ifndef NO_CALLBACKS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    if (notifyListLock == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        notifyListLock = createLockObject(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    prefetchFields(env, thisClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
jclass fetchClass(JNIEnv *env, const char *name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    jclass tmpClass = (*env)->FindClass(env, name);
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
   105
    if (tmpClass == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    return (*env)->NewGlobalRef(env, tmpClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
void prefetchFields(JNIEnv *env, jclass thisClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    jclass tmpClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /* PKCS11 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    pNativeDataID = (*env)->GetFieldID(env, thisClass, "pNativeData", "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
   114
    if (pNativeDataID == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /* CK_MECHANISM */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    tmpClass = (*env)->FindClass(env, CLASS_MECHANISM);
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
   118
    if (tmpClass == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    mech_mechanismID = (*env)->GetFieldID(env, tmpClass, "mechanism", "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
   120
    if (mech_mechanismID == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    mech_pParameterID = (*env)->GetFieldID(env, tmpClass, "pParameter",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                                           "Ljava/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
   123
    if (mech_pParameterID == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    jByteArrayClass = fetchClass(env, "[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
   125
    if (jByteArrayClass == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    jLongClass = fetchClass(env, "java/lang/Long");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
/* This method is designed to do a clean-up. It releases all global resources
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * of this library. By now, this function is not called. Calling from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * JNI_OnUnload would be an option, but some VMs do not support JNI_OnUnload.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * Method:    finalizeLibrary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
Java_sun_security_pkcs11_wrapper_PKCS11_finalizeLibrary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
(JNIEnv *env, jclass thisClass)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
/* XXX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    * remove all left lists and release the resources and the lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * objects that synchroniz access to these lists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    removeAllModuleEntries(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    if (moduleListHead == NULL) { * check, if we removed the last active module *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        * remove also the moduleListLock, it is no longer used *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        if (moduleListLock != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            destroyLockObject(env, moduleListLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            moduleListLock = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
#ifndef NO_CALLBACKS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        * remove all left notify callback entries *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        while (removeFirstNotifyEntry(env));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        * remove also the notifyListLock, it is no longer used *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        if (notifyListLock != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            destroyLockObject(env, notifyListLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            notifyListLock = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        if (jInitArgsObject != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            (*env)->DeleteGlobalRef(env, jInitArgsObject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        if (ckpGlobalInitArgs != NULL_PTR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            free(ckpGlobalInitArgs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
#endif * NO_CALLBACKS *
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
#ifdef P11_ENABLE_C_INITIALIZE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 * Method:    C_Initialize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 * Signature: (Ljava/lang/Object;)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 * @param   jobject jInitArgs           CK_VOID_PTR pInitArgs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
Java_sun_security_pkcs11_wrapper_PKCS11_C_1Initialize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
(JNIEnv *env, jobject obj, jobject jInitArgs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * Initalize Cryptoki
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    CK_C_INITIALIZE_ARGS_PTR ckpInitArgs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    CK_FUNCTION_LIST_PTR ckpFunctions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    TRACE0("DEBUG: initializing module... ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    if (ckpFunctions == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        TRACE0("failed getting module entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    ckpInitArgs = (jInitArgs != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                ? makeCKInitArgsAdapter(env, jInitArgs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                : NULL_PTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    rv = (*ckpFunctions->C_Initialize)(ckpInitArgs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    free(ckpInitArgs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    TRACE0("FINISHED\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
#ifdef P11_ENABLE_C_FINALIZE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
 * Method:    C_Finalize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
 * Signature: (Ljava/lang/Object;)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
 * @param   jobject jReserved           CK_VOID_PTR pReserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
Java_sun_security_pkcs11_wrapper_PKCS11_C_1Finalize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
(JNIEnv *env, jobject obj, jobject jReserved)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * Finalize Cryptoki
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    CK_VOID_PTR ckpReserved;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    if (ckpFunctions == NULL) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    ckpReserved = jObjectToCKVoidPtr(jReserved);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    rv = (*ckpFunctions->C_Finalize)(ckpReserved);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
#ifdef P11_ENABLE_C_GETINFO
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
 * Method:    C_GetInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
 * Signature: ()Lsun/security/pkcs11/wrapper/CK_INFO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
 * @return  jobject jInfoObject         CK_INFO_PTR pInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
JNIEXPORT jobject JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
(JNIEnv *env, jobject obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    CK_INFO ckLibInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    jobject jInfoObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    if (ckpFunctions == NULL) { return NULL; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    rv = (*ckpFunctions->C_GetInfo)(&ckLibInfo);
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
   260
    if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) {
9994f4f08a59 6812738: SSL 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
        jInfoObject = ckInfoPtrToJInfo(env, &ckLibInfo);
9994f4f08a59 6812738: SSL 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
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    return jInfoObject ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
 * converts a pointer to a CK_INFO structure into a Java CK_INFO Object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
 * @param env - used to call JNI funktions to create the new Java object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
 * @param ckpInfo - the pointer to the CK_INFO structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
 * @return - the new Java CK_INFO object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
jobject ckInfoPtrToJInfo(JNIEnv *env, const CK_INFO_PTR ckpInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    jclass jInfoClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    jmethodID jCtrId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    jobject jInfoObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    jobject jCryptokiVer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    jcharArray jVendor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    jlong jFlags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    jcharArray jLibraryDesc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    jobject jLibraryVer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    /* load CK_INFO class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    jInfoClass = (*env)->FindClass(env, CLASS_INFO);
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
   286
    if (jInfoClass == NULL) { return NULL; };
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    /* load CK_INFO constructor */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    jCtrId = (*env)->GetMethodID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
      (env, jInfoClass, "<init>",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
       "(Lsun/security/pkcs11/wrapper/CK_VERSION;[CJ[CLsun/security/pkcs11/wrapper/CK_VERSION;)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
   292
    if (jCtrId == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    /* prep all fields */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    jCryptokiVer = ckVersionPtrToJVersion(env, &(ckpInfo->cryptokiVersion));
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
   296
    if (jCryptokiVer == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    jVendor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
      ckUTF8CharArrayToJCharArray(env, &(ckpInfo->manufacturerID[0]), 32);
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
   299
    if (jVendor == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    jFlags = ckULongToJLong(ckpInfo->flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    jLibraryDesc =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
      ckUTF8CharArrayToJCharArray(env, &(ckpInfo->libraryDescription[0]), 32);
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
   303
    if (jLibraryDesc == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    jLibraryVer = ckVersionPtrToJVersion(env, &(ckpInfo->libraryVersion));
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
   305
    if (jLibraryVer == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    /* create new CK_INFO object */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    jInfoObject = (*env)->NewObject(env, jInfoClass, jCtrId, jCryptokiVer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                                    jVendor, jFlags, jLibraryDesc, jLibraryVer);
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
   310
    if (jInfoObject == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    /* free local references */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    (*env)->DeleteLocalRef(env, jInfoClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    (*env)->DeleteLocalRef(env, jCryptokiVer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    (*env)->DeleteLocalRef(env, jVendor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    (*env)->DeleteLocalRef(env, jLibraryDesc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    (*env)->DeleteLocalRef(env, jLibraryVer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    return jInfoObject ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
#ifdef P11_ENABLE_C_GETSLOTLIST
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
 * Method:    C_GetSlotList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
 * Signature: (Z)[J
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
 * @param   jboolean jTokenPresent      CK_BBOOL tokenPresent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
 * @return  jlongArray jSlotList        CK_SLOT_ID_PTR pSlotList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
 *                                      CK_ULONG_PTR pulCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
JNIEXPORT jlongArray JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetSlotList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
(JNIEnv *env, jobject obj, jboolean jTokenPresent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    CK_ULONG ckTokenNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    CK_SLOT_ID_PTR ckpSlotList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    CK_BBOOL ckTokenPresent;
3321
fed33393bc52 6823905: crash in sun.security.pkcs11.wrapper.PKCS11.C_Sign during stress-test
valeriep
parents: 2180
diff changeset
   340
    jlongArray jSlotList = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    if (ckpFunctions == NULL) { return NULL; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    ckTokenPresent = jBooleanToCKBBool(jTokenPresent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    rv = (*ckpFunctions->C_GetSlotList)(ckTokenPresent, NULL_PTR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                                        &ckTokenNumber);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return NULL ; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    ckpSlotList = (CK_SLOT_ID_PTR) malloc(ckTokenNumber * sizeof(CK_SLOT_ID));
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
   353
    if (ckpSlotList == 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
   354
        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
   355
        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
   356
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    rv = (*ckpFunctions->C_GetSlotList)(ckTokenPresent, ckpSlotList,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                                        &ckTokenNumber);
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
   360
    if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) {
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   361
        jSlotList = ckULongArrayToJLongArray(env, ckpSlotList, ckTokenNumber);
9994f4f08a59 6812738: SSL 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
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    free(ckpSlotList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    return jSlotList ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
#ifdef P11_ENABLE_C_GETSLOTINFO
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
 * Method:    C_GetSlotInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
 * Signature: (J)Lsun/security/pkcs11/wrapper/CK_SLOT_INFO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
 * @param   jlong jSlotID               CK_SLOT_ID slotID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
 * @return  jobject jSlotInfoObject     CK_SLOT_INFO_PTR pInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
JNIEXPORT jobject JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetSlotInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
(JNIEnv *env, jobject obj, jlong jSlotID)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    CK_SLOT_ID ckSlotID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    CK_SLOT_INFO ckSlotInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    jobject jSlotInfoObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    if (ckpFunctions == NULL) { return NULL; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    ckSlotID = jLongToCKULong(jSlotID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    rv = (*ckpFunctions->C_GetSlotInfo)(ckSlotID, &ckSlotInfo);
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
   393
    if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) {
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   394
        jSlotInfoObject = ckSlotInfoPtrToJSlotInfo(env, &ckSlotInfo);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   395
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    return jSlotInfoObject ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
 * converts a pointer to a CK_SLOT_INFO structure into a Java CK_SLOT_INFO
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
 * Object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
 * @param env - used to call JNI funktions to create the new Java object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
 * @param ckpSlotInfo - the pointer to the CK_SLOT_INFO structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
 * @return - the new Java CK_SLOT_INFO object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
jobject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
ckSlotInfoPtrToJSlotInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
(JNIEnv *env, const CK_SLOT_INFO_PTR ckpSlotInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    jclass jSlotInfoClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    jmethodID jCtrId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    jobject jSlotInfoObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    jcharArray jSlotDesc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    jcharArray jVendor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    jlong jFlags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    jobject jHardwareVer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    jobject jFirmwareVer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    /* load CK_SLOT_INFO class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    jSlotInfoClass = (*env)->FindClass(env, CLASS_SLOT_INFO);
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
   422
    if (jSlotInfoClass == NULL) { return NULL; };
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    /* load CK_SLOT_INFO constructor */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    jCtrId = (*env)->GetMethodID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
      (env, jSlotInfoClass, "<init>",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
       "([C[CJLsun/security/pkcs11/wrapper/CK_VERSION;Lsun/security/pkcs11/wrapper/CK_VERSION;)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
   428
    if (jCtrId == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    /* prep all fields */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    jSlotDesc =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
      ckUTF8CharArrayToJCharArray(env, &(ckpSlotInfo->slotDescription[0]), 64);
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
   433
    if (jSlotDesc == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    jVendor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
      ckUTF8CharArrayToJCharArray(env, &(ckpSlotInfo->manufacturerID[0]), 32);
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
   436
    if (jVendor == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    jFlags = ckULongToJLong(ckpSlotInfo->flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    jHardwareVer = ckVersionPtrToJVersion(env, &(ckpSlotInfo->hardwareVersion));
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
   439
    if (jHardwareVer == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    jFirmwareVer = ckVersionPtrToJVersion(env, &(ckpSlotInfo->firmwareVersion));
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
   441
    if (jFirmwareVer == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    /* create new CK_SLOT_INFO object */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    jSlotInfoObject = (*env)->NewObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
      (env, jSlotInfoClass, jCtrId, jSlotDesc, jVendor, jFlags,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
       jHardwareVer, jFirmwareVer);
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
   447
    if (jSlotInfoObject == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    /* free local references */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    (*env)->DeleteLocalRef(env, jSlotInfoClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    (*env)->DeleteLocalRef(env, jSlotDesc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    (*env)->DeleteLocalRef(env, jVendor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    (*env)->DeleteLocalRef(env, jHardwareVer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    (*env)->DeleteLocalRef(env, jFirmwareVer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    return jSlotInfoObject ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
#ifdef P11_ENABLE_C_GETTOKENINFO
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
 * Method:    C_GetTokenInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
 * Signature: (J)Lsun/security/pkcs11/wrapper/CK_TOKEN_INFO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
 * @param   jlong jSlotID               CK_SLOT_ID slotID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
 * @return  jobject jInfoTokenObject    CK_TOKEN_INFO_PTR pInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
JNIEXPORT jobject JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetTokenInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
(JNIEnv *env, jobject obj, jlong jSlotID)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    CK_SLOT_ID ckSlotID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    CK_TOKEN_INFO ckTokenInfo;
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
   476
    jobject jInfoTokenObject = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    if (ckpFunctions == NULL) { return NULL; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    ckSlotID = jLongToCKULong(jSlotID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    rv = (*ckpFunctions->C_GetTokenInfo)(ckSlotID, &ckTokenInfo);
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
   485
    if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) {
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   486
        jInfoTokenObject = ckTokenInfoPtrToJTokenInfo(env, &ckTokenInfo);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   487
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    return jInfoTokenObject ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
 * converts a pointer to a CK_TOKEN_INFO structure into a Java CK_TOKEN_INFO
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
 * Object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
 * @param env - used to call JNI funktions to create the new Java object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
 * @param ckpTokenInfo - the pointer to the CK_TOKEN_INFO structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
 * @return - the new Java CK_TOKEN_INFO object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
jobject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
ckTokenInfoPtrToJTokenInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
(JNIEnv *env, const CK_TOKEN_INFO_PTR ckpTokenInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    jclass jTokenInfoClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    jmethodID jCtrId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    jobject jTokenInfoObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    jcharArray jLabel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    jcharArray jVendor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    jcharArray jModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    jcharArray jSerialNo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    jlong jFlags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    jlong jMaxSnCnt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    jlong jSnCnt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    jlong jMaxRwSnCnt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    jlong jRwSnCnt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    jlong jMaxPinLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    jlong jMinPinLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    jlong jTotalPubMem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    jlong jFreePubMem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    jlong jTotalPrivMem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    jlong jFreePrivMem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    jobject jHardwareVer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    jobject jFirmwareVer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    jcharArray jUtcTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    /* load CK_TOKEN_INFO class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    jTokenInfoClass = (*env)->FindClass(env, CLASS_TOKEN_INFO);
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
   527
    if (jTokenInfoClass == NULL)  { return NULL; };
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    /* load CK_TOKEN_INFO constructor */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    jCtrId = (*env)->GetMethodID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
      (env, jTokenInfoClass, "<init>",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
       "([C[C[C[CJJJJJJJJJJJLsun/security/pkcs11/wrapper/CK_VERSION;Lsun/security/pkcs11/wrapper/CK_VERSION;[C)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
   533
    if (jCtrId == NULL)  { return NULL; };
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    /* prep all fields */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    jLabel = ckUTF8CharArrayToJCharArray(env, &(ckpTokenInfo->label[0]), 32);
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
   537
    if (jLabel == NULL)  { return NULL; };
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    jVendor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
      ckUTF8CharArrayToJCharArray(env, &(ckpTokenInfo->manufacturerID[0]), 32);
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
   540
    if (jVendor == NULL)  { return NULL; };
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    jModel = ckUTF8CharArrayToJCharArray(env, &(ckpTokenInfo->model[0]), 16);
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
   542
    if (jModel == NULL)  { return NULL; };
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    jSerialNo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
      ckUTF8CharArrayToJCharArray(env, &(ckpTokenInfo->serialNumber[0]), 16);
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
   545
    if (jSerialNo == NULL)  { return NULL; };
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    jFlags = ckULongToJLong(ckpTokenInfo->flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    jMaxSnCnt = ckULongSpecialToJLong(ckpTokenInfo->ulMaxSessionCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    jSnCnt = ckULongSpecialToJLong(ckpTokenInfo->ulSessionCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    jMaxRwSnCnt = ckULongSpecialToJLong(ckpTokenInfo->ulMaxRwSessionCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    jRwSnCnt = ckULongSpecialToJLong(ckpTokenInfo->ulRwSessionCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    jMaxPinLen = ckULongToJLong(ckpTokenInfo->ulMaxPinLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    jMinPinLen = ckULongToJLong(ckpTokenInfo->ulMinPinLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    jTotalPubMem = ckULongSpecialToJLong(ckpTokenInfo->ulTotalPublicMemory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    jFreePubMem = ckULongSpecialToJLong(ckpTokenInfo->ulFreePublicMemory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    jTotalPrivMem = ckULongSpecialToJLong(ckpTokenInfo->ulTotalPrivateMemory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    jFreePrivMem = ckULongSpecialToJLong(ckpTokenInfo->ulFreePrivateMemory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    jHardwareVer =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
      ckVersionPtrToJVersion(env, &(ckpTokenInfo->hardwareVersion));
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
   559
    if (jHardwareVer == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    jFirmwareVer =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
      ckVersionPtrToJVersion(env, &(ckpTokenInfo->firmwareVersion));
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
   562
    if (jFirmwareVer == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    jUtcTime =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
      ckUTF8CharArrayToJCharArray(env, &(ckpTokenInfo->utcTime[0]), 16);
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
   565
    if (jUtcTime == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    /* create new CK_TOKEN_INFO object */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    jTokenInfoObject =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
      (*env)->NewObject(env, jTokenInfoClass, jCtrId, jLabel, jVendor, jModel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                        jSerialNo, jFlags,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                        jMaxSnCnt, jSnCnt, jMaxRwSnCnt, jRwSnCnt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                        jMaxPinLen, jMinPinLen,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                        jTotalPubMem, jFreePubMem, jTotalPrivMem, jFreePrivMem,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                        jHardwareVer, jFirmwareVer, jUtcTime);
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
   575
    if (jTokenInfoObject == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    /* free local references */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    (*env)->DeleteLocalRef(env, jTokenInfoClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    (*env)->DeleteLocalRef(env, jLabel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    (*env)->DeleteLocalRef(env, jVendor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    (*env)->DeleteLocalRef(env, jModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    (*env)->DeleteLocalRef(env, jSerialNo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    (*env)->DeleteLocalRef(env, jHardwareVer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    (*env)->DeleteLocalRef(env, jFirmwareVer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    return jTokenInfoObject ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
#ifdef P11_ENABLE_C_WAITFORSLOTEVENT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
 * Method:    C_WaitForSlotEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
 * Signature: (JLjava/lang/Object;)J
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
 * @param   jlong jFlags                CK_FLAGS flags
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
 * @param   jobject jReserved           CK_VOID_PTR pReserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
 * @return  jlong jSlotID               CK_SLOT_ID_PTR pSlot
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
JNIEXPORT jlong JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
Java_sun_security_pkcs11_wrapper_PKCS11_C_1WaitForSlotEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
(JNIEnv *env, jobject obj, jlong jFlags, jobject jReserved)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    CK_FLAGS ckFlags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    CK_SLOT_ID ckSlotID;
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
   606
    jlong jSlotID = 0L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    if (ckpFunctions == NULL) { return 0L; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    ckFlags = jLongToCKULong(jFlags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    rv = (*ckpFunctions->C_WaitForSlotEvent)(ckFlags, &ckSlotID, NULL_PTR);
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 (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) {
9994f4f08a59 6812738: SSL 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
        jSlotID = ckULongToJLong(ckSlotID);
9994f4f08a59 6812738: SSL 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
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    return jSlotID ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
#ifdef P11_ENABLE_C_GETMECHANISMLIST
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
 * Method:    C_GetMechanismList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
 * Signature: (J)[J
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
 * @param   jlong jSlotID               CK_SLOT_ID slotID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
 * @return  jlongArray jMechanismList   CK_MECHANISM_TYPE_PTR pMechanismList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
 *                                      CK_ULONG_PTR pulCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
JNIEXPORT jlongArray JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetMechanismList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
(JNIEnv *env, jobject obj, jlong jSlotID)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    CK_SLOT_ID ckSlotID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    CK_ULONG ckMechanismNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    CK_MECHANISM_TYPE_PTR ckpMechanismList;
3321
fed33393bc52 6823905: crash in sun.security.pkcs11.wrapper.PKCS11.C_Sign during stress-test
valeriep
parents: 2180
diff changeset
   640
    jlongArray jMechanismList = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    if (ckpFunctions == NULL) { return NULL; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    ckSlotID = jLongToCKULong(jSlotID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    rv = (*ckpFunctions->C_GetMechanismList)(ckSlotID, NULL_PTR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                                             &ckMechanismNumber);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return NULL ; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    ckpMechanismList = (CK_MECHANISM_TYPE_PTR)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
      malloc(ckMechanismNumber * sizeof(CK_MECHANISM_TYPE));
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
   654
    if (ckpMechanismList == 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
   655
        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
   656
        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
   657
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    rv = (*ckpFunctions->C_GetMechanismList)(ckSlotID, ckpMechanismList,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                                             &ckMechanismNumber);
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
   661
    if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) {
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   662
        jMechanismList = ckULongArrayToJLongArray(env, ckpMechanismList,
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   663
                                                  ckMechanismNumber);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   664
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    free(ckpMechanismList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    return jMechanismList ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
#ifdef P11_ENABLE_C_GETMECHANISMINFO
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
 * Method:    C_GetMechanismInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
 * Signature: (JJ)Lsun/security/pkcs11/wrapper/CK_MECHANISM_INFO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
 * @param   jlong jSlotID               CK_SLOT_ID slotID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
 * @param   jlong jType                 CK_MECHANISM_TYPE type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
 * @return  jobject jMechanismInfo      CK_MECHANISM_INFO_PTR pInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
JNIEXPORT jobject JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetMechanismInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
(JNIEnv *env, jobject obj, jlong jSlotID, jlong jType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    CK_SLOT_ID ckSlotID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    CK_MECHANISM_TYPE ckMechanismType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
    CK_MECHANISM_INFO ckMechanismInfo;
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
    jobject jMechanismInfo = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    if (ckpFunctions == NULL) { return NULL; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    ckSlotID = jLongToCKULong(jSlotID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
    ckMechanismType = jLongToCKULong(jType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    rv = (*ckpFunctions->C_GetMechanismInfo)(ckSlotID, ckMechanismType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                                             &ckMechanismInfo);
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
   699
    if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) {
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   700
        jMechanismInfo = ckMechanismInfoPtrToJMechanismInfo(env, &ckMechanismInfo);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   701
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    return jMechanismInfo ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
 * converts a pointer to a CK_MECHANISM_INFO structure into a Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
 * CK_MECHANISM_INFO Object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
 * @param env - used to call JNI funktions to create the new Java object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
 * @param ckpMechanismInfo - the pointer to the CK_MECHANISM_INFO structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
 * @return - the new Java CK_MECHANISM_INFO object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
jobject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
ckMechanismInfoPtrToJMechanismInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
(JNIEnv *env, const CK_MECHANISM_INFO_PTR ckpMechanismInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    jclass jMechanismInfoClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    jmethodID jCtrId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    jobject jMechanismInfoObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    jlong jMinKeySize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    jlong jMaxKeySize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    jlong jFlags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    /* load CK_MECHANISM_INFO class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
    jMechanismInfoClass = (*env)->FindClass(env, CLASS_MECHANISM_INFO);
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
   727
    if (jMechanismInfoClass == NULL) { return NULL; };
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    /* load CK_MECHANISM_INFO constructor */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    jCtrId = (*env)->GetMethodID(env, jMechanismInfoClass, "<init>", "(JJJ)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
   731
    if (jCtrId == NULL) { return NULL; };
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    /* prep all fields */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
    jMinKeySize = ckULongToJLong(ckpMechanismInfo->ulMinKeySize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    jMaxKeySize = ckULongToJLong(ckpMechanismInfo->ulMaxKeySize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    jFlags = ckULongToJLong(ckpMechanismInfo->flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    /* create new CK_MECHANISM_INFO object */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    jMechanismInfoObject = (*env)->NewObject(env, jMechanismInfoClass, jCtrId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                                             jMinKeySize, jMaxKeySize, jFlags);
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
   741
    if (jMechanismInfoObject == NULL) { return NULL; };
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    /* free local references */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
    (*env)->DeleteLocalRef(env, jMechanismInfoClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    return jMechanismInfoObject ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
#ifdef P11_ENABLE_C_INITTOKEN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
 * Method:    C_InitToken
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
 * Signature: (J[C[C)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
 * @param   jlong jSlotID               CK_SLOT_ID slotID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
 * @param   jcharArray jPin             CK_CHAR_PTR pPin
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
 *                                      CK_ULONG ulPinLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
 * @param   jcharArray jLabel           CK_UTF8CHAR_PTR pLabel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
Java_sun_security_pkcs11_wrapper_PKCS11_C_1InitToken
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
(JNIEnv *env, jobject obj, jlong jSlotID, jcharArray jPin, jcharArray jLabel)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    CK_SLOT_ID ckSlotID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    CK_CHAR_PTR ckpPin = NULL_PTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    CK_UTF8CHAR_PTR ckpLabel = NULL_PTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    CK_ULONG ckPinLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
    CK_ULONG ckLabelLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    if (ckpFunctions == NULL) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    ckSlotID = jLongToCKULong(jSlotID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    jCharArrayToCKCharArray(env, jPin, &ckpPin, &ckPinLength);
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
   777
    if ((*env)->ExceptionCheck(env)) { 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
   778
    /* ckLabelLength <= 32 !!! */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
    jCharArrayToCKUTF8CharArray(env, jLabel, &ckpLabel, &ckLabelLength);
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
   780
    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
   781
        free(ckpPin);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   782
        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
   783
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    rv = (*ckpFunctions->C_InitToken)(ckSlotID, ckpPin, ckPinLength, ckpLabel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    TRACE1("InitToken return code: %d", rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
    free(ckpPin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    free(ckpLabel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
#ifdef P11_ENABLE_C_INITPIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
 * Method:    C_InitPIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
 * Signature: (J[C)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
 * @param   jcharArray jPin             CK_CHAR_PTR pPin
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
 *                                      CK_ULONG ulPinLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
Java_sun_security_pkcs11_wrapper_PKCS11_C_1InitPIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
(JNIEnv *env, jobject obj, jlong jSessionHandle, jcharArray jPin)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    CK_CHAR_PTR ckpPin = NULL_PTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    CK_ULONG ckPinLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    if (ckpFunctions == NULL) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    jCharArrayToCKCharArray(env, jPin, &ckpPin, &ckPinLength);
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
   819
    if ((*env)->ExceptionCheck(env)) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    rv = (*ckpFunctions->C_InitPIN)(ckSessionHandle, ckpPin, ckPinLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    free(ckpPin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
#ifdef P11_ENABLE_C_SETPIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
 * Method:    C_SetPIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
 * Signature: (J[C[C)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
 * @param   jcharArray jOldPin          CK_CHAR_PTR pOldPin
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
 *                                      CK_ULONG ulOldLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
 * @param   jcharArray jNewPin          CK_CHAR_PTR pNewPin
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
 *                                      CK_ULONG ulNewLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
Java_sun_security_pkcs11_wrapper_PKCS11_C_1SetPIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
(JNIEnv *env, jobject obj, jlong jSessionHandle, jcharArray jOldPin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
jcharArray jNewPin)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
    CK_CHAR_PTR ckpOldPin = NULL_PTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
    CK_CHAR_PTR ckpNewPin = NULL_PTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    CK_ULONG ckOldPinLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    CK_ULONG ckNewPinLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
    if (ckpFunctions == NULL) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    jCharArrayToCKCharArray(env, jOldPin, &ckpOldPin, &ckOldPinLength);
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
   858
    if ((*env)->ExceptionCheck(env)) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
    jCharArrayToCKCharArray(env, jNewPin, &ckpNewPin, &ckNewPinLength);
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
   860
    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
   861
        free(ckpOldPin);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   862
        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
   863
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
    rv = (*ckpFunctions->C_SetPIN)(ckSessionHandle, ckpOldPin, ckOldPinLength,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
                                   ckpNewPin, ckNewPinLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
    free(ckpOldPin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
    free(ckpNewPin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
    if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
#endif