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