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